Skip to content

Commit aea76b7

Browse files
committed
stockflow: make sure that manager order amounts are integers
Fixes DFHack#1044
1 parent fa1adbb commit aea76b7

1 file changed

Lines changed: 14 additions & 13 deletions

File tree

plugins/lua/stockflow.lua

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,12 @@ function collect_orders()
140140
stockpile = stockpile,
141141
entry = entry,
142142
}
143-
143+
144144
found = true
145145
break
146146
end
147147
end
148-
148+
149149
if not found then
150150
print("Unmatched stockflow entry for stockpile #"..stockpile.stockpile_number..": "..entry.value.." ("..order_number..")")
151151
end
@@ -174,7 +174,7 @@ function reaction_entry(reactions, job_type, values, name)
174174
-- We could warn about it; in any case, don't add it to the list.
175175
return
176176
end
177-
177+
178178
local order = df.manager_order:new()
179179
-- These defaults differ from the newly created order's.
180180
order:assign{
@@ -420,7 +420,7 @@ function collect_reactions()
420420
local name = string.gsub(reaction.name, "^.", string.upper)
421421
reaction_entry(result, job_types.CustomReaction, {reaction_name = reaction.code}, name)
422422
end
423-
423+
424424
-- Reactions generated by the game.
425425
for _, reaction in ipairs(df.global.world.raws.reactions) do
426426
if reaction.source_enid == entity.id then
@@ -751,15 +751,15 @@ function collect_reactions()
751751
{job_types.MakeBracelet, "Make", "Bracelet"},
752752
{job_types.MakeEarring, "Make", "Earring"},
753753
}, mat)
754-
754+
755755
if not mat.cloth then
756756
material_reactions(result, {
757757
{job_types.MakeCrown, "Make", "Crown"},
758758
{job_types.MakeFigurine, "Make", "Figurine"},
759759
{job_types.MakeRing, "Make", "Ring"},
760760
{job_types.MakeGem, "Make Large", "Gem"},
761761
}, mat)
762-
762+
763763
if not mat.short then
764764
material_reactions(result, {
765765
{job_types.MakeScepter, "Make", "Scepter"},
@@ -798,29 +798,29 @@ screen = gui.FramedScreen {
798798

799799
function screen:onRenderBody(dc)
800800
-- Emulates the built-in manager screen.
801-
801+
802802
if not (self.page_size == self.frame_rect.height - ExtraLines) then
803803
-- The screen size has changed.
804804
self:refilter()
805805
end
806-
806+
807807
-- Top instruction line.
808808
dc:seek(1, 1):string("Type in parts of the name to narrow your search. ", COLOR_WHITE)
809809
dc:key("LEAVESCREEN"):string(" to abort.", COLOR_WHITE)
810-
810+
811811
-- Search term, if any.
812812
dc:seek(1, FirstRow + self.page_size + 1):string(self.search_string, COLOR_LIGHTCYAN)
813-
813+
814814
-- Bottom instruction line.
815815
dc:seek(1, FirstRow + self.page_size + 2)
816816
dc:key("STANDARDSCROLL_UP"):key("STANDARDSCROLL_DOWN")
817817
dc:key("STANDARDSCROLL_PAGEUP"):key("STANDARDSCROLL_PAGEDOWN")
818818
dc:key("STANDARDSCROLL_LEFT"):key("STANDARDSCROLL_RIGHT")
819819
dc:string(": Select", COLOR_WHITE)
820-
820+
821821
dc:seek(CenterCol, FirstRow + self.page_size + 2)
822822
dc:key("SETUPGAME_SAVE_PROFILE_ABORT"):string(": No order", COLOR_WHITE)
823-
823+
824824
-- Reaction lines.
825825
for _, item in ipairs(self.displayed) do
826826
dc:seek(item.x, item.y):string(item.name, item.color)
@@ -954,7 +954,7 @@ function screen:refilter()
954954
-- * Yellow: At least one word starts with at least one search term
955955
-- * Grey: Each search term is found in the middle of a word
956956
self.page_size = self.frame_rect.height - ExtraLines
957-
957+
958958
local filtered = {}
959959
local needles = splitstring(self.search_string, " ")
960960
for key, value in ipairs(reaction_list) do
@@ -1094,6 +1094,7 @@ end
10941094
-- Place a new copy of the order onto the manager's queue.
10951095
function create_orders(order, amount)
10961096
local new_order = order:new()
1097+
amount = math.floor(amount)
10971098
new_order.amount_left = amount
10981099
new_order.amount_total = amount
10991100
-- Todo: Create in a validated state if the fortress is small enough?

0 commit comments

Comments
 (0)