From d18bd3e2a5b152867224d5b67869bc7bd035f2d3 Mon Sep 17 00:00:00 2001 From: Eric Wald Date: Sun, 15 Mar 2015 14:08:47 -0600 Subject: [PATCH 1/7] Preventing a stockflow error message in Arena mode --- NEWS | 1 + plugins/lua/stockflow.lua | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/NEWS b/NEWS index 0fac0e72c..859e77c74 100644 --- a/NEWS +++ b/NEWS @@ -19,6 +19,7 @@ DFHack Future hack-wish: Made items stack properly. modtools/skill-change: made level granularity work properly. show-unit-syndromes should work + stockflow: Fixed error message in Arena mode zone: Stopped crash when scrolling cage owner list New Plugins New Scripts diff --git a/plugins/lua/stockflow.lua b/plugins/lua/stockflow.lua index 44a9e054c..b0464d52c 100644 --- a/plugins/lua/stockflow.lua +++ b/plugins/lua/stockflow.lua @@ -387,6 +387,12 @@ function collect_reactions() -- Not all reactions are allowed to the civilization. -- That includes "Make sharp rock" by default. local entity = df.historical_entity.find(df.global.ui.civ_id) + if not entity then + -- No global civilization; arena mode? + -- Anyway, skip remaining reactions, since many depend on the civ. + return result + end + for _, reaction_id in ipairs(entity.entity_raw.workshops.permitted_reaction_id) do local reaction = df.global.world.raws.reactions[reaction_id] local name = string.gsub(reaction.name, "^.", string.upper) From 11d65b4f2d12897d33aa1f1b51697a9cd5a41f2f Mon Sep 17 00:00:00 2001 From: Eric Wald Date: Thu, 16 Oct 2014 14:18:50 -0600 Subject: [PATCH 2/7] Always clear reactions when loading. This removes a minor potential for memory leaks. --- plugins/lua/stockflow.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/lua/stockflow.lua b/plugins/lua/stockflow.lua index b0464d52c..36af33583 100644 --- a/plugins/lua/stockflow.lua +++ b/plugins/lua/stockflow.lua @@ -31,9 +31,10 @@ CenterCol = 38 -- Populate the reaction and stockpile order lists. -- To be called whenever a world is loaded. function initialize_world() + -- Clear old reactions, just in case. + clear_caches() reaction_list = collect_reactions() saved_orders = collect_orders() - jobs_to_create = {} end -- Clear all caches. From 81c2a6e79f7598e9b98fbe6b00ac6d8c6d56352a Mon Sep 17 00:00:00 2001 From: Eric Wald Date: Sun, 15 Mar 2015 16:02:29 -0600 Subject: [PATCH 3/7] Refactoring a table insert into reaction_entry. --- plugins/lua/stockflow.lua | 128 +++++++++++++++++++------------------- 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/plugins/lua/stockflow.lua b/plugins/lua/stockflow.lua index 36af33583..c5889f121 100644 --- a/plugins/lua/stockflow.lua +++ b/plugins/lua/stockflow.lua @@ -149,7 +149,7 @@ function select_order(stockpile) screen:show() end -function reaction_entry(job_type, values, name) +function reaction_entry(reactions, job_type, values, name) local order = df.manager_order:new() -- These defaults differ from the newly created order's. order:assign{ @@ -165,10 +165,10 @@ function reaction_entry(job_type, values, name) order:assign(values) end - return { + table.insert(reactions, { name = name or df.job_type.attrs[job_type].caption, order = order, - } + }) end function resource_reactions(reactions, job_type, mat_info, keys, items, options) @@ -191,7 +191,7 @@ function resource_reactions(reactions, job_type, mat_info, keys, items, options) end values.item_subtype = itemid - table.insert(reactions, reaction_entry(job_type, values, start.." "..mat_info.adjective..item_name)) + reaction_entry(reactions, job_type, values, start.." "..mat_info.adjective..item_name) end end end @@ -204,7 +204,7 @@ function material_reactions(reactions, itemtypes, mat_info) line = line.." "..row[3] end - table.insert(reactions, reaction_entry(row[1], mat_info.management, line)) + reaction_entry(reactions, row[1], mat_info.management, line) end end @@ -252,11 +252,11 @@ function collect_reactions() materials.leather.clothing_flag = "LEATHER" -- Collection and Entrapment - table.insert(result, reaction_entry(job_types.CollectWebs)) - table.insert(result, reaction_entry(job_types.CollectSand)) - table.insert(result, reaction_entry(job_types.CollectClay)) - table.insert(result, reaction_entry(job_types.CatchLiveLandAnimal)) - table.insert(result, reaction_entry(job_types.CatchLiveFish)) + reaction_entry(result, job_types.CollectWebs) + reaction_entry(result, job_types.CollectSand) + reaction_entry(result, job_types.CollectClay) + reaction_entry(result, job_types.CatchLiveLandAnimal) + reaction_entry(result, job_types.CatchLiveFish) -- Cutting, encrusting, and metal extraction. local rock_types = df.global.world.raws.inorganics @@ -264,36 +264,36 @@ function collect_reactions() local material = rock_types[rock_id].material local rock_name = material.state_adj.Solid if material.flags.IS_STONE or material.flags.IS_GEM then - table.insert(result, reaction_entry(job_types.CutGems, { + reaction_entry(result, job_types.CutGems, { mat_type = 0, mat_index = rock_id, - }, "Cut "..rock_name)) + }, "Cut "..rock_name) - table.insert(result, reaction_entry(job_types.EncrustWithGems, { + reaction_entry(result, job_types.EncrustWithGems, { mat_type = 0, mat_index = rock_id, item_category = {finished_goods = true}, - }, "Encrust Finished Goods With "..rock_name)) + }, "Encrust Finished Goods With "..rock_name) - table.insert(result, reaction_entry(job_types.EncrustWithGems, { + reaction_entry(result, job_types.EncrustWithGems, { mat_type = 0, mat_index = rock_id, item_category = {furniture = true}, - }, "Encrust Furniture With "..rock_name)) + }, "Encrust Furniture With "..rock_name) - table.insert(result, reaction_entry(job_types.EncrustWithGems, { + reaction_entry(result, job_types.EncrustWithGems, { mat_type = 0, mat_index = rock_id, item_category = {ammo = true}, - }, "Encrust Ammo With "..rock_name)) + }, "Encrust Ammo With "..rock_name) end if #rock_types[rock_id].metal_ore.mat_index > 0 then - table.insert(result, reaction_entry(job_types.SmeltOre, {mat_type = 0, mat_index = rock_id}, "Smelt "..rock_name.." Ore")) + reaction_entry(result, job_types.SmeltOre, {mat_type = 0, mat_index = rock_id}, "Smelt "..rock_name.." Ore") end if #rock_types[rock_id].thread_metal.mat_index > 0 then - table.insert(result, reaction_entry(job_types.ExtractMetalStrands, {mat_type = 0, mat_index = rock_id})) + reaction_entry(result, job_types.ExtractMetalStrands, {mat_type = 0, mat_index = rock_id}) end end @@ -311,28 +311,28 @@ function collect_reactions() management = {mat_type = glass_id}, }) - table.insert(result, reaction_entry(job_types.CutGlass, {mat_type = glass_id}, "Cut "..glass_name)) + reaction_entry(result, job_types.CutGlass, {mat_type = glass_id}, "Cut "..glass_name) - table.insert(result, reaction_entry(job_types.EncrustWithGlass, { + reaction_entry(result, job_types.EncrustWithGlass, { mat_type = glass_id, item_category = {finished_goods = true}, - }, "Encrust Finished Goods With "..glass_name)) + }, "Encrust Finished Goods With "..glass_name) - table.insert(result, reaction_entry(job_types.EncrustWithGlass, { + reaction_entry(result, job_types.EncrustWithGlass, { mat_type = glass_id, item_category = {furniture = true}, - }, "Encrust Furniture With "..glass_name)) + }, "Encrust Furniture With "..glass_name) - table.insert(result, reaction_entry(job_types.EncrustWithGlass, { + reaction_entry(result, job_types.EncrustWithGlass, { mat_type = glass_id, item_category = {ammo = true}, - }, "Encrust Ammo With "..glass_name)) + }, "Encrust Ammo With "..glass_name) end end -- Dyeing - table.insert(result, reaction_entry(job_types.DyeThread)) - table.insert(result, reaction_entry(job_types.DyeCloth)) + reaction_entry(result, job_types.DyeThread) + reaction_entry(result, job_types.DyeCloth) -- Sew Image local cloth_mats = {materials.cloth, materials.silk, materials.yarn, materials.leather} @@ -344,45 +344,45 @@ function collect_reactions() material_reactions(result, {{job_types.DecorateWith, "Decorate With"}}, spec) end - table.insert(result, reaction_entry(job_types.MakeTotem)) - table.insert(result, reaction_entry(job_types.ButcherAnimal)) - table.insert(result, reaction_entry(job_types.MillPlants)) - table.insert(result, reaction_entry(job_types.MakePotashFromLye)) - table.insert(result, reaction_entry(job_types.MakePotashFromAsh)) + reaction_entry(result, job_types.MakeTotem) + reaction_entry(result, job_types.ButcherAnimal) + reaction_entry(result, job_types.MillPlants) + reaction_entry(result, job_types.MakePotashFromLye) + reaction_entry(result, job_types.MakePotashFromAsh) -- Kitchen - table.insert(result, reaction_entry(job_types.PrepareMeal, {mat_type = 2}, "Prepare Easy Meal")) - table.insert(result, reaction_entry(job_types.PrepareMeal, {mat_type = 3}, "Prepare Fine Meal")) - table.insert(result, reaction_entry(job_types.PrepareMeal, {mat_type = 4}, "Prepare Lavish Meal")) + reaction_entry(result, job_types.PrepareMeal, {mat_type = 2}, "Prepare Easy Meal") + reaction_entry(result, job_types.PrepareMeal, {mat_type = 3}, "Prepare Fine Meal") + reaction_entry(result, job_types.PrepareMeal, {mat_type = 4}, "Prepare Lavish Meal") if v34 then -- Brew Drink - table.insert(result, reaction_entry(job_types.BrewDrink)) + reaction_entry(result, job_types.BrewDrink) end -- Weaving - table.insert(result, reaction_entry(job_types.WeaveCloth, {material_category = {plant = true}}, "Weave Thread into Cloth")) - table.insert(result, reaction_entry(job_types.WeaveCloth, {material_category = {silk = true}}, "Weave Thread into Silk")) - table.insert(result, reaction_entry(job_types.WeaveCloth, {material_category = {yarn = true}}, "Weave Yarn into Cloth")) + reaction_entry(result, job_types.WeaveCloth, {material_category = {plant = true}}, "Weave Thread into Cloth") + reaction_entry(result, job_types.WeaveCloth, {material_category = {silk = true}}, "Weave Thread into Silk") + reaction_entry(result, job_types.WeaveCloth, {material_category = {yarn = true}}, "Weave Yarn into Cloth") -- Extracts, farmer's workshop, and wood burning - table.insert(result, reaction_entry(job_types.ExtractFromPlants)) - table.insert(result, reaction_entry(job_types.ExtractFromRawFish)) - table.insert(result, reaction_entry(job_types.ExtractFromLandAnimal)) - table.insert(result, reaction_entry(job_types.PrepareRawFish)) - table.insert(result, reaction_entry(job_types.MakeCheese)) - table.insert(result, reaction_entry(job_types.MilkCreature)) - table.insert(result, reaction_entry(job_types.ShearCreature)) - table.insert(result, reaction_entry(job_types.SpinThread)) - table.insert(result, reaction_entry(job_types.MakeLye)) - table.insert(result, reaction_entry(job_types.ProcessPlants)) + reaction_entry(result, job_types.ExtractFromPlants) + reaction_entry(result, job_types.ExtractFromRawFish) + reaction_entry(result, job_types.ExtractFromLandAnimal) + reaction_entry(result, job_types.PrepareRawFish) + reaction_entry(result, job_types.MakeCheese) + reaction_entry(result, job_types.MilkCreature) + reaction_entry(result, job_types.ShearCreature) + reaction_entry(result, job_types.SpinThread) + reaction_entry(result, job_types.MakeLye) + reaction_entry(result, job_types.ProcessPlants) if v34 then - table.insert(result, reaction_entry(job_types.ProcessPlantsBag)) + reaction_entry(result, job_types.ProcessPlantsBag) end - table.insert(result, reaction_entry(job_types.ProcessPlantsVial)) - table.insert(result, reaction_entry(job_types.ProcessPlantsBarrel)) - table.insert(result, reaction_entry(job_types.MakeCharcoal)) - table.insert(result, reaction_entry(job_types.MakeAsh)) + reaction_entry(result, job_types.ProcessPlantsVial) + reaction_entry(result, job_types.ProcessPlantsBarrel) + reaction_entry(result, job_types.MakeCharcoal) + reaction_entry(result, job_types.MakeAsh) -- Reactions defined in the raws. -- Not all reactions are allowed to the civilization. @@ -397,7 +397,7 @@ function collect_reactions() for _, reaction_id in ipairs(entity.entity_raw.workshops.permitted_reaction_id) do local reaction = df.global.world.raws.reactions[reaction_id] local name = string.gsub(reaction.name, "^.", string.upper) - table.insert(result, reaction_entry(job_types.CustomReaction, {reaction_name = reaction.code}, name)) + reaction_entry(result, job_types.CustomReaction, {reaction_name = reaction.code}, name) end -- Metal forging @@ -412,7 +412,7 @@ function collect_reactions() } if material.flags.IS_METAL then - table.insert(result, reaction_entry(job_types.StudWith, mat_flags.management, "Stud With "..rock_name)) + reaction_entry(result, job_types.StudWith, mat_flags.management, "Stud With "..rock_name) if material.flags.ITEMS_WEAPON then -- Todo: Are these really the right flags to check? @@ -525,7 +525,7 @@ function collect_reactions() end -- Traction Bench - table.insert(result, reaction_entry(job_types.ConstructTractionBench)) + reaction_entry(result, job_types.ConstructTractionBench) -- Non-metal weapons resource_reactions(result, job_types.MakeWeapon, materials.wood, entity.resources.weapon_type, itemdefs.weapons, { @@ -649,7 +649,7 @@ function collect_reactions() end -- Bed, specified as wooden. - table.insert(result, reaction_entry(job_types.ConstructBed, materials.wood.management)) + reaction_entry(result, job_types.ConstructBed, materials.wood.management) -- Windows for _, mat_info in ipairs(glasses) do @@ -659,7 +659,7 @@ function collect_reactions() end -- Rock Mechanisms - table.insert(result, reaction_entry(job_types.ConstructMechanisms, materials.rock.management)) + reaction_entry(result, job_types.ConstructMechanisms, materials.rock.management) resource_reactions(result, job_types.AssembleSiegeAmmo, materials.wood, entity.resources.siegeammo_type, itemdefs.siege_ammo, { verb = "Assemble", @@ -718,8 +718,8 @@ function collect_reactions() end -- Siege engine parts - table.insert(result, reaction_entry(job_types.ConstructCatapultParts, materials.wood.management)) - table.insert(result, reaction_entry(job_types.ConstructBallistaParts, materials.wood.management)) + reaction_entry(result, job_types.ConstructCatapultParts, materials.wood.management) + reaction_entry(result, job_types.ConstructBallistaParts, materials.wood.management) for _, mat in ipairs{materials.wood, materials.bone} do resource_reactions(result, job_types.MakeAmmo, mat, entity.resources.ammo_type, itemdefs.ammo, { @@ -736,7 +736,7 @@ function collect_reactions() end -- Melt a Metal Object - table.insert(result, reaction_entry(job_types.MeltMetalObject)) + reaction_entry(result, job_types.MeltMetalObject) return result end From 6bfaa8d35d464017902d27eb824b7d8160278571 Mon Sep 17 00:00:00 2001 From: Eric Wald Date: Thu, 16 Oct 2014 16:01:57 -0600 Subject: [PATCH 4/7] Better way to handle obsolete job types. --- NEWS | 1 + plugins/lua/stockflow.lua | 19 +++++++++---------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/NEWS b/NEWS index 859e77c74..3ee1cba2d 100644 --- a/NEWS +++ b/NEWS @@ -20,6 +20,7 @@ DFHack Future modtools/skill-change: made level granularity work properly. show-unit-syndromes should work stockflow: Fixed error message in Arena mode + stockflow: No longer checks the DF version zone: Stopped crash when scrolling cage owner list New Plugins New Scripts diff --git a/plugins/lua/stockflow.lua b/plugins/lua/stockflow.lua index c5889f121..ccc15ea4e 100644 --- a/plugins/lua/stockflow.lua +++ b/plugins/lua/stockflow.lua @@ -150,6 +150,12 @@ function select_order(stockpile) end function reaction_entry(reactions, job_type, values, name) + if not job_type then + -- Perhaps df.job_type.something returned nil for an unknown job type. + -- 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{ @@ -227,9 +233,6 @@ function collect_reactions() -- Even that list doesn't seem to include their names. local result = {} - -- A few task types are obsolete in newer DF versions. - local v34 = string.match(dfhack.getDFVersion(), "v0.34") - -- Caching the enumeration might not be important, but saves lookups. local job_types = df.job_type @@ -355,10 +358,8 @@ function collect_reactions() reaction_entry(result, job_types.PrepareMeal, {mat_type = 3}, "Prepare Fine Meal") reaction_entry(result, job_types.PrepareMeal, {mat_type = 4}, "Prepare Lavish Meal") - if v34 then - -- Brew Drink - reaction_entry(result, job_types.BrewDrink) - end + -- Brew Drink + reaction_entry(result, job_types.BrewDrink) -- Weaving reaction_entry(result, job_types.WeaveCloth, {material_category = {plant = true}}, "Weave Thread into Cloth") @@ -376,9 +377,7 @@ function collect_reactions() reaction_entry(result, job_types.SpinThread) reaction_entry(result, job_types.MakeLye) reaction_entry(result, job_types.ProcessPlants) - if v34 then - reaction_entry(result, job_types.ProcessPlantsBag) - end + reaction_entry(result, job_types.ProcessPlantsBag) reaction_entry(result, job_types.ProcessPlantsVial) reaction_entry(result, job_types.ProcessPlantsBarrel) reaction_entry(result, job_types.MakeCharcoal) From 23707db1d33be0d2c6b34390c4f7801122aaf2cf Mon Sep 17 00:00:00 2001 From: Eric Wald Date: Sun, 15 Mar 2015 16:26:38 -0600 Subject: [PATCH 5/7] Fixed ballistic arrow head orders --- NEWS | 1 + plugins/lua/stockflow.lua | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 3ee1cba2d..0eec7c3af 100644 --- a/NEWS +++ b/NEWS @@ -21,6 +21,7 @@ DFHack Future show-unit-syndromes should work stockflow: Fixed error message in Arena mode stockflow: No longer checks the DF version + stockflow: Fixed ballistic arrow head orders zone: Stopped crash when scrolling cage owner list New Plugins New Scripts diff --git a/plugins/lua/stockflow.lua b/plugins/lua/stockflow.lua index ccc15ea4e..745427656 100644 --- a/plugins/lua/stockflow.lua +++ b/plugins/lua/stockflow.lua @@ -420,7 +420,7 @@ function collect_reactions() }) -- Is this entirely disconnected from the entity? - material_reactions(result, {{MakeBallistaArrowHead, "Forge", "Ballista Arrow Head"}}, mat_flags) + material_reactions(result, {{job_types.MakeBallistaArrowHead, "Forge", "Ballista Arrow Head"}}, mat_flags) resource_reactions(result, job_types.MakeTrapComponent, mat_flags, entity.resources.trapcomp_type, itemdefs.trapcomps, { adjective = true, From 4f963233f4f92cf8d1598fd3da61d657d96084a7 Mon Sep 17 00:00:00 2001 From: Eric Wald Date: Fri, 20 Mar 2015 19:23:04 -0600 Subject: [PATCH 6/7] Enticing the bookkeeper to work more often --- NEWS | 1 + plugins/stockflow.cpp | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/NEWS b/NEWS index 0eec7c3af..61ad7db2a 100644 --- a/NEWS +++ b/NEWS @@ -22,6 +22,7 @@ DFHack Future stockflow: Fixed error message in Arena mode stockflow: No longer checks the DF version stockflow: Fixed ballistic arrow head orders + stockflow: Now convinces the bookkeeper to update records more often zone: Stopped crash when scrolling cage owner list New Plugins New Scripts diff --git a/plugins/stockflow.cpp b/plugins/stockflow.cpp index abbda87af..34dfc1bd7 100644 --- a/plugins/stockflow.cpp +++ b/plugins/stockflow.cpp @@ -81,12 +81,21 @@ public: } } - if (found && !bookkeeping) { - command_method("start_bookkeeping", out); - bookkeeping = true; - } else if (bookkeeping && !found) { - command_method("finish_bookkeeping", out); - bookkeeping = false; + if (found) { + // Entice the bookkeeper to spend less time update records. + ui->bookkeeper_precision += ui->bookkeeper_precision >> 3; + if (!bookkeeping) { + command_method("start_bookkeeping", out); + bookkeeping = true; + } + } else { + // Entice the bookkeeper to update records more often. + ui->bookkeeper_precision -= ui->bookkeeper_precision >> 5; + ui->bookkeeper_cooldown -= ui->bookkeeper_cooldown >> 2; + if (bookkeeping) { + command_method("finish_bookkeeping", out); + bookkeeping = false; + } } } From ebb3dc48bf3cb3e460cd4eef1645425b8565f6b4 Mon Sep 17 00:00:00 2001 From: Eric Wald Date: Sun, 22 Mar 2015 20:46:46 -0600 Subject: [PATCH 7/7] Allowing whitespace-only lines. --- travis/lint.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/travis/lint.py b/travis/lint.py index 5d16eca70..23c30449e 100644 --- a/travis/lint.py +++ b/travis/lint.py @@ -74,7 +74,7 @@ class TrailingWhitespaceLinter(Linter): msg = 'Contains trailing whitespace' def check_line(self, line): line = line.replace('\r', '') - return not line.endswith(' ') and not line.endswith('\t') + return not line.strip() or not line.endswith(' ') and not line.endswith('\t') def fix_line(self, line): return line.rstrip('\t ')