Skip to content

Commit

Permalink
stockflow: make sure that manager order amounts are integers
Browse files Browse the repository at this point in the history
  • Loading branch information
lethosor committed Mar 18, 2017
1 parent fa1adbb commit aea76b7
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions plugins/lua/stockflow.lua
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,12 @@ function collect_orders()
stockpile = stockpile,
entry = entry,
}

found = true
break
end
end

if not found then
print("Unmatched stockflow entry for stockpile #"..stockpile.stockpile_number..": "..entry.value.." ("..order_number..")")
end
Expand Down Expand Up @@ -174,7 +174,7 @@ function reaction_entry(reactions, job_type, values, name)
-- We could warn about it; in any case, don't add it to the list.
return
end

local order = df.manager_order:new()
-- These defaults differ from the newly created order's.
order:assign{
Expand Down Expand Up @@ -420,7 +420,7 @@ function collect_reactions()
local name = string.gsub(reaction.name, "^.", string.upper)
reaction_entry(result, job_types.CustomReaction, {reaction_name = reaction.code}, name)
end

-- Reactions generated by the game.
for _, reaction in ipairs(df.global.world.raws.reactions) do
if reaction.source_enid == entity.id then
Expand Down Expand Up @@ -751,15 +751,15 @@ function collect_reactions()
{job_types.MakeBracelet, "Make", "Bracelet"},
{job_types.MakeEarring, "Make", "Earring"},
}, mat)

if not mat.cloth then
material_reactions(result, {
{job_types.MakeCrown, "Make", "Crown"},
{job_types.MakeFigurine, "Make", "Figurine"},
{job_types.MakeRing, "Make", "Ring"},
{job_types.MakeGem, "Make Large", "Gem"},
}, mat)

if not mat.short then
material_reactions(result, {
{job_types.MakeScepter, "Make", "Scepter"},
Expand Down Expand Up @@ -798,29 +798,29 @@ screen = gui.FramedScreen {

function screen:onRenderBody(dc)
-- Emulates the built-in manager screen.

if not (self.page_size == self.frame_rect.height - ExtraLines) then
-- The screen size has changed.
self:refilter()
end

-- Top instruction line.
dc:seek(1, 1):string("Type in parts of the name to narrow your search. ", COLOR_WHITE)
dc:key("LEAVESCREEN"):string(" to abort.", COLOR_WHITE)

-- Search term, if any.
dc:seek(1, FirstRow + self.page_size + 1):string(self.search_string, COLOR_LIGHTCYAN)

-- Bottom instruction line.
dc:seek(1, FirstRow + self.page_size + 2)
dc:key("STANDARDSCROLL_UP"):key("STANDARDSCROLL_DOWN")
dc:key("STANDARDSCROLL_PAGEUP"):key("STANDARDSCROLL_PAGEDOWN")
dc:key("STANDARDSCROLL_LEFT"):key("STANDARDSCROLL_RIGHT")
dc:string(": Select", COLOR_WHITE)

dc:seek(CenterCol, FirstRow + self.page_size + 2)
dc:key("SETUPGAME_SAVE_PROFILE_ABORT"):string(": No order", COLOR_WHITE)

-- Reaction lines.
for _, item in ipairs(self.displayed) do
dc:seek(item.x, item.y):string(item.name, item.color)
Expand Down Expand Up @@ -954,7 +954,7 @@ function screen:refilter()
-- * Yellow: At least one word starts with at least one search term
-- * Grey: Each search term is found in the middle of a word
self.page_size = self.frame_rect.height - ExtraLines

local filtered = {}
local needles = splitstring(self.search_string, " ")
for key, value in ipairs(reaction_list) do
Expand Down Expand Up @@ -1094,6 +1094,7 @@ end
-- Place a new copy of the order onto the manager's queue.
function create_orders(order, amount)
local new_order = order:new()
amount = math.floor(amount)
new_order.amount_left = amount
new_order.amount_total = amount
-- Todo: Create in a validated state if the fortress is small enough?
Expand Down

0 comments on commit aea76b7

Please sign in to comment.