Date: Fri, 31 May 2013 15:48:08 -0600
Subject: [PATCH 03/34] Repairing the new menu option list in the Readme files.
---
Readme.html | 7 +++++--
Readme.rst | 4 ++--
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/Readme.html b/Readme.html
index ba89a442e..7c00ef047 100644
--- a/Readme.html
+++ b/Readme.html
@@ -2141,8 +2141,11 @@ instantly duplicates the job.
- While enabled, the 'q' menu of each stockpile will have two new options:
-- j: Select a job to order, from an interface like the manager's screen.
-J: Cycle between several options for how many such jobs to order.
+
+- j: Select a job to order, from an interface like the manager's screen.
+- J: Cycle between several options for how many such jobs to order.
+
+
Whenever the bookkeeper updates stockpile records, new work orders will
be placed on the manager's queue for each such selection, reduced by the
diff --git a/Readme.rst b/Readme.rst
index dbef32f26..6d39ec845 100644
--- a/Readme.rst
+++ b/Readme.rst
@@ -1333,8 +1333,8 @@ Usage:
Display whether the plugin is enabled.
While enabled, the 'q' menu of each stockpile will have two new options:
- j: Select a job to order, from an interface like the manager's screen.
- J: Cycle between several options for how many such jobs to order.
+ * j: Select a job to order, from an interface like the manager's screen.
+ * J: Cycle between several options for how many such jobs to order.
Whenever the bookkeeper updates stockpile records, new work orders will
be placed on the manager's queue for each such selection, reduced by the
From 5fb87c2ea941a8517763ee5cce708afd4d836704 Mon Sep 17 00:00:00 2001
From: Eric Wald
Date: Fri, 18 Apr 2014 21:58:20 -0600
Subject: [PATCH 04/34] Now accepts the new enable/disable commands.
---
plugins/stockflow.cpp | 33 ++++++++++++++++++++++++++++++---
1 file changed, 30 insertions(+), 3 deletions(-)
diff --git a/plugins/stockflow.cpp b/plugins/stockflow.cpp
index 72e804507..b96faa47f 100644
--- a/plugins/stockflow.cpp
+++ b/plugins/stockflow.cpp
@@ -1,7 +1,7 @@
/*
* Stockflow plugin.
* For best effect, place "stockflow enable" in your dfhack.init configuration,
- * or set `enabled` to true by default.
+ * or set AUTOENABLE to true.
*/
#include "uicommon.h"
@@ -24,7 +24,13 @@ using df::building_stockpilest;
DFHACK_PLUGIN("stockflow");
+#define AUTOENABLE false
+#ifdef DFHACK_PLUGIN_IS_ENABLED
+DFHACK_PLUGIN_IS_ENABLED(enabled);
+#else
bool enabled = false;
+#endif
+
const char *tagline = "Allows the fortress bookkeeper to queue jobs through the manager.";
const char *usage = (
" stockflow enable\n"
@@ -371,13 +377,34 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan
return CR_OK;
}
+DFhackCExport command_result plugin_enable(color_ostream& out, bool enable) {
+ /* Accept the "enable stockflow"/"disable stockflow" syntax, where available. */
+ /* Same as "stockflow enable"/"stockflow disable" except without the status line. */
+ if (enable != enabled) {
+ if (!apply_hooks(out, enable)) {
+ return CR_FAILURE;
+ }
+
+ enabled = enable;
+ }
+
+ return CR_OK;
+}
+
DFhackCExport command_result plugin_init(color_ostream &out, std::vector &commands) {
helper.init();
- if (enabled) apply_hooks(out, true);
+ if (AUTOENABLE) {
+ if (!apply_hooks(out, true)) {
+ return CR_FAILURE;
+ }
+
+ enabled = true;
+ }
+
commands.push_back(PluginCommand(name, tagline, stockflow_cmd, false, usage));
return CR_OK;
}
DFhackCExport command_result plugin_shutdown(color_ostream &out) {
- return CR_OK;
+ return plugin_enable(out, false);
}
From 723cfcf28e7427dd7218397c8b8189d0b69170e7 Mon Sep 17 00:00:00 2001
From: Eric Wald
Date: Sun, 4 May 2014 12:35:10 -0600
Subject: [PATCH 05/34] Attempting to repair an order object leak.
Now frees manager_order objects in the reaction_list when the plugin is disabled or the world unloaded. However, there may still be orders leaked elsewhere.
---
plugins/lua/stockflow.lua | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/plugins/lua/stockflow.lua b/plugins/lua/stockflow.lua
index 510298a06..d2add16c9 100644
--- a/plugins/lua/stockflow.lua
+++ b/plugins/lua/stockflow.lua
@@ -30,6 +30,10 @@ end
-- Clear all caches.
-- Called when a world is loaded, or when the plugin is disabled.
function clear_caches()
+ -- Free the C++ objects in the reaction list.
+ for _, value in ipairs(reaction_list) do
+ value.order:delete()
+ end
reaction_list = {}
saved_orders = {}
jobs_to_create = {}
From 2d5f7e40220bfe4b88c8f7de18a2260c20da8665 Mon Sep 17 00:00:00 2001
From: Eric Wald
Date: Sun, 4 May 2014 12:52:59 -0600
Subject: [PATCH 06/34] Magic number reduction: Persistent storage
Replaces explicit indices into the ints field of Stockflow persistent storage objects with enumerated values.
---
plugins/lua/stockflow.lua | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/plugins/lua/stockflow.lua b/plugins/lua/stockflow.lua
index d2add16c9..c18138ced 100644
--- a/plugins/lua/stockflow.lua
+++ b/plugins/lua/stockflow.lua
@@ -19,6 +19,12 @@ triggers = {
{name = "Never"},
}
+entry_ints = {
+ stockpile_id = 1,
+ order_number = 2,
+ trigger_number = 3,
+}
+
-- Populate the reaction and stockpile order lists.
-- To be called whenever a world is loaded.
function initialize_world()
@@ -40,7 +46,7 @@ function clear_caches()
end
function trigger_name(cache)
- local trigger = triggers[cache.entry.ints[3]]
+ local trigger = triggers[cache.entry.ints[entry_ints.trigger_number]]
return trigger and trigger.name or "Never"
end
@@ -97,7 +103,7 @@ end
function toggle_trigger(sp)
local saved = saved_orders[sp.id]
if saved then
- saved.entry.ints[3] = (saved.entry.ints[3] % #triggers) + 1
+ saved.entry.ints[entry_ints.trigger_number] = (saved.entry.ints[entry_ints.trigger_number] % #triggers) + 1
saved.entry:save()
end
end
@@ -108,7 +114,7 @@ function collect_orders()
if entries then
local stockpiles = df.global.world.buildings.other.STOCKPILE
for _, entry in ipairs(entries) do
- local spid = entry.ints[1]
+ local spid = entry.ints[entry_ints.stockpile_id]
local stockpile = utils.binsearch(stockpiles, spid, "id")
if stockpile then
-- Todo: What if entry.value ~= reaction_list[order_number].name?
@@ -846,7 +852,7 @@ function store_order(stockpile, order_number)
local saved = saved_orders[stockpile.id]
if saved then
saved.entry.value = name
- saved.entry.ints[2] = order_number
+ saved.entry.ints[entry_ints.order_number] = order_number
saved.entry:save()
else
saved_orders[stockpile.id] = {
@@ -977,9 +983,9 @@ end
function check_stockpiles(verbose)
local result = {}
for _, spec in pairs(saved_orders) do
- local trigger = triggers[spec.entry.ints[3]]
+ local trigger = triggers[spec.entry.ints[entry_ints.trigger_number]]
if trigger and trigger.divisor then
- local reaction = spec.entry.ints[2]
+ local reaction = spec.entry.ints[entry_ints.order_number]
local filled, empty = check_pile(spec.stockpile, verbose)
local amount = trigger.filled and filled or empty
amount = (amount - (amount % trigger.divisor)) / trigger.divisor
From bdb22235af87be0f8561c23ac3cea6711e943ee6 Mon Sep 17 00:00:00 2001
From: Eric Wald
Date: Sun, 4 May 2014 15:02:12 -0600
Subject: [PATCH 07/34] Magic number reduction: Job types
---
plugins/lua/stockflow.lua | 361 ++++++++++++++++++++------------------
1 file changed, 189 insertions(+), 172 deletions(-)
diff --git a/plugins/lua/stockflow.lua b/plugins/lua/stockflow.lua
index c18138ced..6e893a660 100644
--- a/plugins/lua/stockflow.lua
+++ b/plugins/lua/stockflow.lua
@@ -19,6 +19,12 @@ triggers = {
{name = "Never"},
}
+-- There must be a better way get the value of an enum.
+job_types = {}
+for key, value in ipairs(df.job_type) do
+ job_types[value] = key
+end
+
entry_ints = {
stockpile_id = 1,
order_number = 2,
@@ -197,11 +203,11 @@ end
function clothing_reactions(reactions, mat_info, filter)
local resources = df.global.world.entities.all[df.global.ui.civ_id].resources
local itemdefs = df.global.world.raws.itemdefs
- resource_reactions(reactions, 101, mat_info, resources.armor_type, itemdefs.armor, {permissible = filter})
- resource_reactions(reactions, 103, mat_info, resources.pants_type, itemdefs.pants, {permissible = filter})
- resource_reactions(reactions, 117, mat_info, resources.gloves_type, itemdefs.gloves, {permissible = filter})
- resource_reactions(reactions, 102, mat_info, resources.helm_type, itemdefs.helms, {permissible = filter})
- resource_reactions(reactions, 118, mat_info, resources.shoes_type, itemdefs.shoes, {permissible = filter})
+ resource_reactions(reactions, job_types.MakeArmor, mat_info, resources.armor_type, itemdefs.armor, {permissible = filter})
+ resource_reactions(reactions, job_types.MakePants, mat_info, resources.pants_type, itemdefs.pants, {permissible = filter})
+ resource_reactions(reactions, job_types.MakeGloves, mat_info, resources.gloves_type, itemdefs.gloves, {permissible = filter})
+ resource_reactions(reactions, job_types.MakeHelm, mat_info, resources.helm_type, itemdefs.helms, {permissible = filter})
+ resource_reactions(reactions, job_types.MakeShoes, mat_info, resources.shoes_type, itemdefs.shoes, {permissible = filter})
end
-- Find the reaction types that should be listed in the management interface.
@@ -230,10 +236,12 @@ function collect_reactions()
materials.tooth.adjective = "ivory/tooth"
materials.leather.clothing_flag = "LEATHER"
- local jobs = {12, 22, 219, 31, 32}
- for _, job_id in ipairs(jobs) do
- table.insert(result, reaction_entry(job_id))
- end
+ -- 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))
-- Cutting, encrusting, and metal extraction.
local rock_types = df.global.world.raws.inorganics
@@ -241,21 +249,24 @@ 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(85, {mat_type = 0, mat_index = rock_id}, "Cut "..rock_name))
+ table.insert(result, reaction_entry(job_types.CutGems, {
+ mat_type = 0,
+ mat_index = rock_id,
+ }, "Cut "..rock_name))
- table.insert(result, reaction_entry(87, {
+ table.insert(result, reaction_entry(job_types.EncrustWithGems, {
mat_type = 0,
mat_index = rock_id,
item_category = {finished_goods = true},
}, "Encrust Finished Goods With "..rock_name))
- table.insert(result, reaction_entry(87, {
+ table.insert(result, reaction_entry(job_types.EncrustWithGems, {
mat_type = 0,
mat_index = rock_id,
item_category = {furniture = true},
}, "Encrust Furniture With "..rock_name))
- table.insert(result, reaction_entry(87, {
+ table.insert(result, reaction_entry(job_types.EncrustWithGems, {
mat_type = 0,
mat_index = rock_id,
item_category = {ammo = true},
@@ -263,11 +274,11 @@ function collect_reactions()
end
if #rock_types[rock_id].metal_ore.mat_index > 0 then
- table.insert(result, reaction_entry(90, {mat_type = 0, mat_index = rock_id}, "Smelt "..rock_name.." Ore"))
+ table.insert(result, reaction_entry(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(92, {mat_type = 0, mat_index = rock_id}))
+ table.insert(result, reaction_entry(job_types.ExtractMetalStrands, {mat_type = 0, mat_index = rock_id}))
end
end
@@ -285,19 +296,19 @@ function collect_reactions()
management = {mat_type = glass_id},
})
- table.insert(result, reaction_entry(86, {mat_type = glass_id}, "Cut "..glass_name))
+ table.insert(result, reaction_entry(job_types.CutGlass, {mat_type = glass_id}, "Cut "..glass_name))
- table.insert(result, reaction_entry(88, {
+ table.insert(result, reaction_entry(job_types.EncrustWithGlass, {
mat_type = glass_id,
item_category = {finished_goods = true},
}, "Encrust Finished Goods With "..glass_name))
- table.insert(result, reaction_entry(88, {
+ table.insert(result, reaction_entry(job_types.EncrustWithGlass, {
mat_type = glass_id,
item_category = {furniture = true},
}, "Encrust Furniture With "..glass_name))
- table.insert(result, reaction_entry(88, {
+ table.insert(result, reaction_entry(job_types.EncrustWithGlass, {
mat_type = glass_id,
item_category = {ammo = true},
}, "Encrust Ammo With "..glass_name))
@@ -305,48 +316,54 @@ function collect_reactions()
end
-- Dyeing
- table.insert(result, reaction_entry(192))
- table.insert(result, reaction_entry(193))
+ table.insert(result, reaction_entry(job_types.DyeThread))
+ table.insert(result, reaction_entry(job_types.DyeCloth))
-- Sew Image
cloth_mats = {materials.cloth, materials.silk, materials.yarn, materials.leather}
for _, material in ipairs(cloth_mats) do
- material_reactions(result, {{194, "Sew", "Image"}}, material)
+ material_reactions(result, {{job_types.SewImage, "Sew", "Image"}}, material)
end
for _, spec in ipairs{materials.bone, materials.shell, materials.tooth, materials.horn, materials.pearl} do
- material_reactions(result, {{132, "Decorate With"}}, spec)
+ material_reactions(result, {{job_types.DecorateWith, "Decorate With"}}, spec)
end
- -- Make Totem
- table.insert(result, reaction_entry(130))
- -- Butcher an Animal
- table.insert(result, reaction_entry(105))
- -- Mill Plants
- table.insert(result, reaction_entry(107))
- -- Make Potash From Lye
- table.insert(result, reaction_entry(189))
- -- Make Potash From Ash
- table.insert(result, reaction_entry(191))
+ 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))
-- Kitchen
- table.insert(result, reaction_entry(115, {mat_type = 2}, "Prepare Easy Meal"))
- table.insert(result, reaction_entry(115, {mat_type = 3}, "Prepare Fine Meal"))
- table.insert(result, reaction_entry(115, {mat_type = 4}, "Prepare Lavish Meal"))
+ 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"))
-- Brew Drink
- table.insert(result, reaction_entry(150))
+ table.insert(result, reaction_entry(job_types.BrewDrink))
-- Weaving
- table.insert(result, reaction_entry(116, {material_category = {plant = true}}, "Weave Thread into Cloth"))
- table.insert(result, reaction_entry(116, {material_category = {silk = true}}, "Weave Thread into Silk"))
- table.insert(result, reaction_entry(116, {material_category = {yarn = true}}, "Weave Yarn into Cloth"))
+ 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"))
-- Extracts, farmer's workshop, and wood burning
- local jobs = {151, 152, 153, 106, 110, 109, 214, 215, 188, 111, 112, 113, 114, 186, 187}
- for _, job_id in ipairs(jobs) do
- table.insert(result, reaction_entry(job_id))
- end
+ 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))
+ table.insert(result, reaction_entry(job_types.ProcessPlantsBag))
+ 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))
-- Reactions defined in the raws.
-- Not all reactions are allowed to the civilization.
@@ -355,7 +372,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(211, {reaction_name = reaction.code}, name))
+ table.insert(result, reaction_entry(job_types.CustomReaction, {reaction_name = reaction.code}, name))
end
-- Metal forging
@@ -370,52 +387,52 @@ function collect_reactions()
}
if material.flags.IS_METAL then
- table.insert(result, reaction_entry(104, mat_flags.management, "Stud With "..rock_name))
+ table.insert(result, reaction_entry(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?
- resource_reactions(result, 97, mat_flags, entity.resources.weapon_type, itemdefs.weapons, {
+ resource_reactions(result, job_types.MakeWeapon, mat_flags, entity.resources.weapon_type, itemdefs.weapons, {
permissible = (function(itemdef) return itemdef.skill_ranged == -1 end),
})
-- Is this entirely disconnected from the entity?
- material_reactions(result, {{135, "Forge", "Ballista Arrow Head"}}, mat_flags)
+ material_reactions(result, {{MakeBallistaArrowHead, "Forge", "Ballista Arrow Head"}}, mat_flags)
- resource_reactions(result, 142, mat_flags, entity.resources.trapcomp_type, itemdefs.trapcomps, {
+ resource_reactions(result, job_types.MakeTrapComponent, mat_flags, entity.resources.trapcomp_type, itemdefs.trapcomps, {
adjective = true,
})
- resource_reactions(result, 136, mat_flags, entity.resources.siegeammo_type, itemdefs.siege_ammo, {
+ resource_reactions(result, job_types.AssembleSiegeAmmo, mat_flags, entity.resources.siegeammo_type, itemdefs.siege_ammo, {
verb = "Assemble",
})
end
if material.flags.ITEMS_WEAPON_RANGED then
- resource_reactions(result, 97, mat_flags, entity.resources.weapon_type, itemdefs.weapons, {
+ resource_reactions(result, job_types.MakeWeapon, mat_flags, entity.resources.weapon_type, itemdefs.weapons, {
permissible = (function(itemdef) return itemdef.skill_ranged >= 0 end),
})
end
if material.flags.ITEMS_DIGGER then
-- Todo: Ranged or training digging weapons?
- resource_reactions(result, 97, mat_flags, entity.resources.digger_type, itemdefs.weapons, {
+ resource_reactions(result, job_types.MakeWeapon, mat_flags, entity.resources.digger_type, itemdefs.weapons, {
})
end
if material.flags.ITEMS_AMMO then
- resource_reactions(result, 131, mat_flags, entity.resources.ammo_type, itemdefs.ammo, {
+ resource_reactions(result, job_types.MakeAmmo, mat_flags, entity.resources.ammo_type, itemdefs.ammo, {
name_field = "name_plural",
})
end
if material.flags.ITEMS_ANVIL then
- material_reactions(result, {{98, "Forge", "Anvil"}}, mat_flags)
+ material_reactions(result, {{job_types.ForgeAnvil, "Forge", "Anvil"}}, mat_flags)
end
if material.flags.ITEMS_ARMOR then
local metalclothing = (function(itemdef) return itemdef.props.flags.METAL end)
clothing_reactions(result, mat_flags, metalclothing)
- resource_reactions(result, 119, mat_flags, entity.resources.shield_type, itemdefs.shields, {
+ resource_reactions(result, job_types.MakeShield, mat_flags, entity.resources.shield_type, itemdefs.shields, {
})
end
@@ -425,14 +442,14 @@ function collect_reactions()
end
if material.flags.ITEMS_HARD then
- resource_reactions(result, 218, mat_flags, entity.resources.tool_type, itemdefs.tools, {
+ resource_reactions(result, job_types.MakeTool, mat_flags, entity.resources.tool_type, itemdefs.tools, {
permissible = (function(itemdef) return itemdef.flags.HARD_MAT end),
capitalize = true,
})
end
if material.flags.ITEMS_METAL then
- resource_reactions(result, 218, mat_flags, entity.resources.tool_type, itemdefs.tools, {
+ resource_reactions(result, job_types.MakeTool, mat_flags, entity.resources.tool_type, itemdefs.tools, {
permissible = (function(itemdef) return itemdef.flags.METAL_MAT end),
capitalize = true,
})
@@ -440,198 +457,198 @@ function collect_reactions()
if material.flags.ITEMS_HARD then
material_reactions(result, {
- {69, "Construct", "Door"},
- {70, "Construct", "Floodgate"},
- {200, "Construct", "Hatch Cover"},
- {201, "Construct", "Grate"},
- {72, "Construct", "Throne"},
- {73, "Construct", "Sarcophagus"},
- {74, "Construct", "Table"},
- {205, "Construct", "Splint"},
- {206, "Construct", "Crutch"},
- {77, "Construct", "Armor Stand"},
- {78, "Construct", "Weapon Rack"},
- {79, "Construct", "Cabinet"},
- {123, "Forge", "Goblet"},
- {124, "Forge", "Instrument"},
- {125, "Forge", "Toy"},
- {80, "Construct", "Statue"},
- {81, "Construct", "Blocks"},
- {126, "Forge", "Animal Trap"},
- {127, "Forge", "Barrel"},
- {128, "Forge", "Bucket"},
- {76, "Construct", "Bin"},
- {195, "Forge", "Pipe Section"},
- {120, "Forge", "Cage"},
- {84, "Mint", "Coins"},
- {75, "Construct", "Chest"},
- {122, "Forge", "Flask"},
- {121, "Forge", "Chain"},
- {83, "Make", "Crafts"},
+ {job_types.ConstructDoor, "Construct", "Door"},
+ {job_types.ConstructFloodgate, "Construct", "Floodgate"},
+ {job_types.ConstructHatchCover, "Construct", "Hatch Cover"},
+ {job_types.ConstructGrate, "Construct", "Grate"},
+ {job_types.ConstructThrone, "Construct", "Throne"},
+ {job_types.ConstructCoffin, "Construct", "Sarcophagus"},
+ {job_types.ConstructTable, "Construct", "Table"},
+ {job_types.ConstructSplint, "Construct", "Splint"},
+ {job_types.ConstructCrutch, "Construct", "Crutch"},
+ {job_types.ConstructArmorStand, "Construct", "Armor Stand"},
+ {job_types.ConstructWeaponRack, "Construct", "Weapon Rack"},
+ {job_types.ConstructCabinet, "Construct", "Cabinet"},
+ {job_types.MakeGoblet, "Forge", "Goblet"},
+ {job_types.MakeInstrument, "Forge", "Instrument"},
+ {job_types.MakeToy, "Forge", "Toy"},
+ {job_types.ConstructStatue, "Construct", "Statue"},
+ {job_types.ConstructBlocks, "Construct", "Blocks"},
+ {job_types.MakeAnimalTrap, "Forge", "Animal Trap"},
+ {job_types.MakeBarrel, "Forge", "Barrel"},
+ {job_types.MakeBucket, "Forge", "Bucket"},
+ {job_types.ConstructBin, "Construct", "Bin"},
+ {job_types.MakePipeSection, "Forge", "Pipe Section"},
+ {job_types.MakeCage, "Forge", "Cage"},
+ {job_types.MintCoins, "Mint", "Coins"},
+ {job_types.ConstructChest, "Construct", "Chest"},
+ {job_types.MakeFlask, "Forge", "Flask"},
+ {job_types.MakeChain, "Forge", "Chain"},
+ {job_types.MakeCrafts, "Make", "Crafts"},
}, mat_flags)
end
if material.flags.ITEMS_SOFT then
material_reactions(result, {
- {133, "Make", "Backpack"},
- {134, "Make", "Quiver"},
- {99, "Construct", "Catapult Parts"},
- {100, "Construct", "Ballista Parts"},
+ {job_types.MakeBackpack, "Make", "Backpack"},
+ {job_types.MakeQuiver, "Make", "Quiver"},
+ {job_types.ConstructCatapultParts, "Construct", "Catapult Parts"},
+ {job_types.ConstructBallistaParts, "Construct", "Ballista Parts"},
}, mat_flags)
end
end
end
-- Traction Bench
- table.insert(result, reaction_entry(207))
+ table.insert(result, reaction_entry(job_types.ConstructTractionBench))
-- Non-metal weapons
- resource_reactions(result, 97, materials.wood, entity.resources.weapon_type, itemdefs.weapons, {
+ resource_reactions(result, job_types.MakeWeapon, materials.wood, entity.resources.weapon_type, itemdefs.weapons, {
permissible = (function(itemdef) return itemdef.skill_ranged >= 0 end),
})
- resource_reactions(result, 97, materials.wood, entity.resources.training_weapon_type, itemdefs.weapons, {
+ resource_reactions(result, job_types.MakeWeapon, materials.wood, entity.resources.training_weapon_type, itemdefs.weapons, {
})
- resource_reactions(result, 97, materials.bone, entity.resources.weapon_type, itemdefs.weapons, {
+ resource_reactions(result, job_types.MakeWeapon, materials.bone, entity.resources.weapon_type, itemdefs.weapons, {
permissible = (function(itemdef) return itemdef.skill_ranged >= 0 end),
})
- resource_reactions(result, 97, materials.rock, entity.resources.weapon_type, itemdefs.weapons, {
+ resource_reactions(result, job_types.MakeWeapon, materials.rock, entity.resources.weapon_type, itemdefs.weapons, {
permissible = (function(itemdef) return itemdef.flags.CAN_STONE end),
})
-- Wooden items
-- Closely related to the ITEMS_HARD list.
material_reactions(result, {
- {69, "Construct", "Door"},
- {70, "Construct", "Floodgate"},
- {200, "Construct", "Hatch Cover"},
- {201, "Construct", "Grate"},
- {72, "Construct", "Chair"},
- {73, "Construct", "Casket"},
- {74, "Construct", "Table"},
- {77, "Construct", "Armor Stand"},
- {78, "Construct", "Weapon Rack"},
- {79, "Construct", "Cabinet"},
- {123, "Make", "Cup"},
- {124, "Make", "Instrument"},
+ {job_types.ConstructDoor, "Construct", "Door"},
+ {job_types.ConstructFloodgate, "Construct", "Floodgate"},
+ {job_types.ConstructHatchCover, "Construct", "Hatch Cover"},
+ {job_types.ConstructGrate, "Construct", "Grate"},
+ {job_types.ConstructThrone, "Construct", "Chair"},
+ {job_types.ConstructCoffin, "Construct", "Casket"},
+ {job_types.ConstructTable, "Construct", "Table"},
+ {job_types.ConstructArmorStand, "Construct", "Armor Stand"},
+ {job_types.ConstructWeaponRack, "Construct", "Weapon Rack"},
+ {job_types.ConstructCabinet, "Construct", "Cabinet"},
+ {job_types.MakeGoblet, "Make", "Cup"},
+ {job_types.MakeInstrument, "Make", "Instrument"},
}, materials.wood)
- resource_reactions(result, 218, materials.wood, entity.resources.tool_type, itemdefs.tools, {
+ resource_reactions(result, job_types.MakeTool, materials.wood, entity.resources.tool_type, itemdefs.tools, {
-- permissible = (function(itemdef) return itemdef.flags.WOOD_MAT end),
capitalize = true,
})
material_reactions(result, {
- {125, "Make", "Toy"},
- {81, "Construct", "Blocks"},
- {205, "Construct", "Splint"},
- {206, "Construct", "Crutch"},
- {126, "Make", "Animal Trap"},
- {127, "Make", "Barrel"},
- {128, "Make", "Bucket"},
- {76, "Construct", "Bin"},
- {120, "Make", "Cage"},
- {195, "Make", "Pipe Section"},
+ {job_types.MakeToy, "Make", "Toy"},
+ {job_types.ConstructBlocks, "Construct", "Blocks"},
+ {job_types.ConstructSplint, "Construct", "Splint"},
+ {job_types.ConstructCrutch, "Construct", "Crutch"},
+ {job_types.MakeAnimalTrap, "Make", "Animal Trap"},
+ {job_types.MakeBarrel, "Make", "Barrel"},
+ {job_types.MakeBucket, "Make", "Bucket"},
+ {job_types.ConstructBin, "Construct", "Bin"},
+ {job_types.MakeCage, "Make", "Cage"},
+ {job_types.MakePipeSection, "Make", "Pipe Section"},
}, materials.wood)
- resource_reactions(result, 142, materials.wood, entity.resources.trapcomp_type, itemdefs.trapcomps, {
+ resource_reactions(result, job_types.MakeTrapComponent, materials.wood, entity.resources.trapcomp_type, itemdefs.trapcomps, {
permissible = (function(itemdef) return itemdef.flags.WOOD end),
adjective = true,
})
-- Rock items
material_reactions(result, {
- {69, "Construct", "Door"},
- {70, "Construct", "Floodgate"},
- {200, "Construct", "Hatch Cover"},
- {201, "Construct", "Grate"},
- {72, "Construct", "Throne"},
- {73, "Construct", "Coffin"},
- {74, "Construct", "Table"},
- {77, "Construct", "Armor Stand"},
- {78, "Construct", "Weapon Rack"},
- {79, "Construct", "Cabinet"},
- {123, "Make", "Mug"},
- {124, "Make", "Instrument"},
+ {job_types.ConstructDoor, "Construct", "Door"},
+ {job_types.ConstructFloodgate, "Construct", "Floodgate"},
+ {job_types.ConstructHatchCover, "Construct", "Hatch Cover"},
+ {job_types.ConstructGrate, "Construct", "Grate"},
+ {job_types.ConstructThrone, "Construct", "Throne"},
+ {job_types.ConstructCoffin, "Construct", "Coffin"},
+ {job_types.ConstructTable, "Construct", "Table"},
+ {job_types.ConstructArmorStand, "Construct", "Armor Stand"},
+ {job_types.ConstructWeaponRack, "Construct", "Weapon Rack"},
+ {job_types.ConstructCabinet, "Construct", "Cabinet"},
+ {job_types.MakeGoblet, "Make", "Mug"},
+ {job_types.MakeInstrument, "Make", "Instrument"},
}, materials.rock)
- resource_reactions(result, 218, materials.rock, entity.resources.tool_type, itemdefs.tools, {
+ resource_reactions(result, job_types.MakeTool, materials.rock, entity.resources.tool_type, itemdefs.tools, {
permissible = (function(itemdef) return itemdef.flags.HARD_MAT end),
capitalize = true,
})
material_reactions(result, {
- {125, "Make", "Toy"},
- {203, "Construct", "Quern"},
- {204, "Construct", "Millstone"},
- {212, "Construct", "Slab"},
- {80, "Construct", "Statue"},
- {81, "Construct", "Blocks"},
+ {job_types.MakeToy, "Make", "Toy"},
+ {job_types.ConstructQuern, "Construct", "Quern"},
+ {job_types.ConstructMillstone, "Construct", "Millstone"},
+ {job_types.ConstructSlab, "Construct", "Slab"},
+ {job_types.ConstructStatue, "Construct", "Statue"},
+ {job_types.ConstructBlocks, "Construct", "Blocks"},
}, materials.rock)
-- Glass items
for _, mat_info in ipairs(glasses) do
material_reactions(result, {
- {69, "Construct", "Portal"},
- {70, "Construct", "Floodgate"},
- {200, "Construct", "Hatch Cover"},
- {201, "Construct", "Grate"},
- {72, "Construct", "Throne"},
- {73, "Construct", "Coffin"},
- {74, "Construct", "Table"},
- {77, "Construct", "Armor Stand"},
- {78, "Construct", "Weapon Rack"},
- {79, "Construct", "Cabinet"},
- {123, "Make", "Goblet"},
- {124, "Make", "Instrument"},
+ {job_types.ConstructDoor, "Construct", "Portal"},
+ {job_types.ConstructFloodgate, "Construct", "Floodgate"},
+ {job_types.ConstructHatchCover, "Construct", "Hatch Cover"},
+ {job_types.ConstructGrate, "Construct", "Grate"},
+ {job_types.ConstructThrone, "Construct", "Throne"},
+ {job_types.ConstructCoffin, "Construct", "Coffin"},
+ {job_types.ConstructTable, "Construct", "Table"},
+ {job_types.ConstructArmorStand, "Construct", "Armor Stand"},
+ {job_types.ConstructWeaponRack, "Construct", "Weapon Rack"},
+ {job_types.ConstructCabinet, "Construct", "Cabinet"},
+ {job_types.MakeGoblet, "Make", "Goblet"},
+ {job_types.MakeInstrument, "Make", "Instrument"},
}, mat_info)
- resource_reactions(result, 218, mat_info, entity.resources.tool_type, itemdefs.tools, {
+ resource_reactions(result, job_types.MakeTool, mat_info, entity.resources.tool_type, itemdefs.tools, {
permissible = (function(itemdef) return itemdef.flags.HARD_MAT end),
capitalize = true,
})
material_reactions(result, {
- {125, "Make", "Toy"},
- {80, "Construct", "Statue"},
- {81, "Construct", "Blocks"},
- {120, "Make", "Terrarium"},
- {195, "Make", "Tube"},
+ {job_types.MakeToy, "Make", "Toy"},
+ {job_types.ConstructStatue, "Construct", "Statue"},
+ {job_types.ConstructBlocks, "Construct", "Blocks"},
+ {job_types.MakeCage, "Make", "Terrarium"},
+ {job_types.MakePipeSection, "Make", "Tube"},
}, mat_info)
- resource_reactions(result, 142, mat_info, entity.resources.trapcomp_type, itemdefs.trapcomps, {
+ resource_reactions(result, job_types.MakeTrapComponent, mat_info, entity.resources.trapcomp_type, itemdefs.trapcomps, {
adjective = true,
})
end
-- Bed, specified as wooden.
- table.insert(result, reaction_entry(71, materials.wood.management))
+ table.insert(result, reaction_entry(job_types.ConstructBed, materials.wood.management))
-- Windows
for _, mat_info in ipairs(glasses) do
material_reactions(result, {
- {129, "Make", "Window"},
+ {job_types.MakeWindow, "Make", "Window"},
}, mat_info)
end
-- Rock Mechanisms
- table.insert(result, reaction_entry(141, materials.rock.management))
+ table.insert(result, reaction_entry(job_types.ConstructMechanisms, materials.rock.management))
- resource_reactions(result, 136, materials.wood, entity.resources.siegeammo_type, itemdefs.siege_ammo, {
+ resource_reactions(result, job_types.AssembleSiegeAmmo, materials.wood, entity.resources.siegeammo_type, itemdefs.siege_ammo, {
verb = "Assemble",
})
for _, mat_info in ipairs(glasses) do
material_reactions(result, {
- {82, "Make Raw", nil},
+ {job_types.MakeRawGlass, "Make Raw", nil},
}, mat_info)
end
material_reactions(result, {
- {133, "Make", "Backpack"},
- {134, "Make", "Quiver"},
+ {job_types.MakeBackpack, "Make", "Backpack"},
+ {job_types.MakeQuiver, "Make", "Quiver"},
}, materials.leather)
for _, material in ipairs(cloth_mats) do
@@ -649,12 +666,12 @@ function collect_reactions()
}
for _, boxmat in ipairs(boxmats) do
for _, mat in ipairs(boxmat.mats) do
- material_reactions(result, {{75, "Construct", boxmat.box}}, mat)
+ material_reactions(result, {{job_types.ConstructChest, "Construct", boxmat.box}}, mat)
if boxmat.chain then
- material_reactions(result, {{121, "Make", boxmat.chain}}, mat)
+ material_reactions(result, {{job_types.MakeChain, "Make", boxmat.chain}}, mat)
end
if boxmat.flask then
- material_reactions(result, {{122, "Make", boxmat.flask}}, mat)
+ material_reactions(result, {{job_types.MakeFlask, "Make", boxmat.flask}}, mat)
end
end
end
@@ -672,15 +689,15 @@ function collect_reactions()
materials.pearl,
materials.yarn,
} do
- material_reactions(result, {{83, "Make", "Crafts"}}, mat)
+ material_reactions(result, {{job_types.MakeCrafts, "Make", "Crafts"}}, mat)
end
-- Siege engine parts
- table.insert(result, reaction_entry(99, materials.wood.management))
- table.insert(result, reaction_entry(100, materials.wood.management))
+ table.insert(result, reaction_entry(job_types.ConstructCatapultParts, materials.wood.management))
+ table.insert(result, reaction_entry(job_types.ConstructBallistaParts, materials.wood.management))
for _, mat in ipairs{materials.wood, materials.bone} do
- resource_reactions(result, 131, mat, entity.resources.ammo_type, itemdefs.ammo, {
+ resource_reactions(result, job_types.MakeAmmo, mat, entity.resources.ammo_type, itemdefs.ammo, {
name_field = "name_plural",
})
end
@@ -690,11 +707,11 @@ function collect_reactions()
clothing_reactions(result, materials.shell, (function(itemdef) return itemdef.props.flags[4] end))
for _, mat in ipairs{materials.wood, materials.leather} do
- resource_reactions(result, 119, mat, entity.resources.shield_type, itemdefs.shields, {})
+ resource_reactions(result, job_types.MakeShield, mat, entity.resources.shield_type, itemdefs.shields, {})
end
-- Melt a Metal Object
- table.insert(result, reaction_entry(91))
+ table.insert(result, reaction_entry(job_types.MeltMetalObject))
return result
end
From 767badbfb9bd36017eaf56f7f91f16bcb970d4ea Mon Sep 17 00:00:00 2001
From: Eric Wald
Date: Sun, 4 May 2014 15:13:25 -0600
Subject: [PATCH 08/34] Magic number reduction: Clothing flags
Bone and shell are used to construct BARRED and SCALED armor/clothing items, for some reason.
---
plugins/lua/stockflow.lua | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/plugins/lua/stockflow.lua b/plugins/lua/stockflow.lua
index 6e893a660..a9390bef7 100644
--- a/plugins/lua/stockflow.lua
+++ b/plugins/lua/stockflow.lua
@@ -703,8 +703,8 @@ function collect_reactions()
end
-- BARRED and SCALED as flag names don't quite seem to fit, here.
- clothing_reactions(result, materials.bone, (function(itemdef) return itemdef.props.flags[3] end))
- clothing_reactions(result, materials.shell, (function(itemdef) return itemdef.props.flags[4] end))
+ clothing_reactions(result, materials.bone, (function(itemdef) return itemdef.props.flags.BARRED end))
+ clothing_reactions(result, materials.shell, (function(itemdef) return itemdef.props.flags.SCALED end))
for _, mat in ipairs{materials.wood, materials.leather} do
resource_reactions(result, job_types.MakeShield, mat, entity.resources.shield_type, itemdefs.shields, {})
From 4fc850445d55acbc646723110be9165361fc49b5 Mon Sep 17 00:00:00 2001
From: Eric Wald
Date: Sun, 4 May 2014 15:28:53 -0600
Subject: [PATCH 09/34] Magic Number Reduction: Display placement constants
---
plugins/lua/stockflow.lua | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/plugins/lua/stockflow.lua b/plugins/lua/stockflow.lua
index a9390bef7..e8ac9db9a 100644
--- a/plugins/lua/stockflow.lua
+++ b/plugins/lua/stockflow.lua
@@ -31,6 +31,10 @@ entry_ints = {
trigger_number = 3,
}
+PageSize = 16
+FirstRow = 4
+CenterCol = 39
+
-- Populate the reaction and stockpile order lists.
-- To be called whenever a world is loaded.
function initialize_world()
@@ -720,7 +724,6 @@ screen = gui.FramedScreen {
frame_title = "Select Stockpile Order",
}
-PageSize = 16
function screen:onRenderBody(dc)
-- Emulates the built-in manager screen.
dc:seek(1, 1):string("Type in parts of the name to narrow your search. ", COLOR_WHITE)
@@ -840,9 +843,9 @@ function screen:refilter()
end
local x = 1
- local y = 4 + n
+ local y = FirstRow + n
if n >= PageSize then
- x = 39
+ x = CenterCol
y = y - PageSize
end
From 144eff4cf2db2ae5d87a1aef304217f457cd6475 Mon Sep 17 00:00:00 2001
From: Eric Wald
Date: Sun, 4 May 2014 15:36:42 -0600
Subject: [PATCH 10/34] Clearing the center column.
The official order selection screen has an extra space to the left of the orders on the right-hand side.
---
plugins/lua/stockflow.lua | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/plugins/lua/stockflow.lua b/plugins/lua/stockflow.lua
index e8ac9db9a..ec52c3deb 100644
--- a/plugins/lua/stockflow.lua
+++ b/plugins/lua/stockflow.lua
@@ -33,7 +33,7 @@ entry_ints = {
PageSize = 16
FirstRow = 4
-CenterCol = 39
+CenterCol = 38
-- Populate the reaction and stockpile order lists.
-- To be called whenever a world is loaded.
@@ -838,6 +838,7 @@ function screen:refilter()
local displayed = {}
for n = 0, PageSize*2 - 1 do
local item = filtered[start + n]
+ local name = item.name
if not item then
break
end
@@ -847,6 +848,7 @@ function screen:refilter()
if n >= PageSize then
x = CenterCol
y = y - PageSize
+ name = " "..name
end
local color = COLOR_CYAN
@@ -857,7 +859,7 @@ function screen:refilter()
displayed[n + 1] = {
x = x,
y = y,
- name = item.name,
+ name = name,
color = color,
}
end
From a516811bb1e6e7efe88ecd06b567df89162cfa0f Mon Sep 17 00:00:00 2001
From: lethosor
Date: Tue, 13 May 2014 16:41:55 -0400
Subject: [PATCH 11/34] Only allow 3dveins to be run in fortress mode
Prevents crash from running in arena mode
---
plugins/3dveins.cpp | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/plugins/3dveins.cpp b/plugins/3dveins.cpp
index 432d93cf6..c9e15aae5 100644
--- a/plugins/3dveins.cpp
+++ b/plugins/3dveins.cpp
@@ -42,6 +42,7 @@ using namespace MapExtras;
using namespace DFHack::Random;
using df::global::world;
+using df::global::gametype;
command_result cmd_3dveins(color_ostream &out, std::vector & parameters);
@@ -1573,6 +1574,12 @@ command_result cmd_3dveins(color_ostream &con, std::vector & parame
return CR_FAILURE;
}
+ if (*gametype != game_type::DWARF_MAIN && *gametype != game_type::DWARF_RECLAIM)
+ {
+ con.printerr("Must be used in fortress mode!\n");
+ return CR_FAILURE;
+ }
+
VeinGenerator generator(con);
con.print("Collecting statistics...\n");
From d52a07ef76d3620a7f1eca680bba1cf69f465bd8 Mon Sep 17 00:00:00 2001
From: lethosor
Date: Wed, 14 May 2014 18:56:30 -0400
Subject: [PATCH 12/34] Dismiss previous command prompt before creating a new
one
---
plugins/command-prompt.cpp | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/plugins/command-prompt.cpp b/plugins/command-prompt.cpp
index d7a8e230c..19460f19b 100644
--- a/plugins/command-prompt.cpp
+++ b/plugins/command-prompt.cpp
@@ -7,6 +7,7 @@
#include
#include
+#include
#include
#include
@@ -166,6 +167,10 @@ void viewscreen_commandpromptst::feed(std::set *events)
DFHACK_PLUGIN("command-prompt");
command_result show_prompt(color_ostream &out, std::vector & parameters)
{
+ if (Gui::getCurFocus() == "dfhack/commandprompt")
+ {
+ Screen::dismiss(Gui::getCurViewscreen(true));
+ }
std::string params;
for(size_t i=0;i
Date: Thu, 15 May 2014 15:51:03 -0400
Subject: [PATCH 13/34] Fix handling of newline characters in command-prompt
output
---
plugins/command-prompt.cpp | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/plugins/command-prompt.cpp b/plugins/command-prompt.cpp
index 19460f19b..a5903f2b3 100644
--- a/plugins/command-prompt.cpp
+++ b/plugins/command-prompt.cpp
@@ -56,9 +56,14 @@ public:
df::global::gps->display_frames=show_fps;
}
- void add_response(color_value v,std::string s)
+ void add_response(color_value v, std::string s)
{
- responses.push_back(std::make_pair(v,s));
+ std::stringstream ss(s);
+ std::string part;
+ while (std::getline(ss, part))
+ {
+ responses.push_back(std::make_pair(v, part));
+ }
}
protected:
std::list > responses;
From 9b1d393c1ca925ac6514d664e9b03a8c9bf676f0 Mon Sep 17 00:00:00 2001
From: lethosor
Date: Thu, 15 May 2014 17:30:42 -0400
Subject: [PATCH 14/34] Append newline to each section of output
---
plugins/command-prompt.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/plugins/command-prompt.cpp b/plugins/command-prompt.cpp
index a5903f2b3..5e84db831 100644
--- a/plugins/command-prompt.cpp
+++ b/plugins/command-prompt.cpp
@@ -62,7 +62,7 @@ public:
std::string part;
while (std::getline(ss, part))
{
- responses.push_back(std::make_pair(v, part));
+ responses.push_back(std::make_pair(v, part + '\n'));
}
}
protected:
From 293a535aa4c47bd17a17d00fc7cdf10be92d6780 Mon Sep 17 00:00:00 2001
From: lethosor
Date: Fri, 16 May 2014 20:42:18 -0400
Subject: [PATCH 15/34] Fix crash with mouse input in search plugin
---
plugins/search.cpp | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/plugins/search.cpp b/plugins/search.cpp
index e0213bf06..72001275c 100644
--- a/plugins/search.cpp
+++ b/plugins/search.cpp
@@ -180,6 +180,10 @@ public:
{
// Query typing mode
+ if (input->empty())
+ {
+ return false;
+ }
df::interface_key last_token = *input->rbegin();
if (last_token >= interface_key::STRING_A032 && last_token <= interface_key::STRING_A126)
{
From d9dc7f31c2330d614cd874acc32b261948286a36 Mon Sep 17 00:00:00 2001
From: Lethosor
Date: Sat, 17 May 2014 13:48:48 -0400
Subject: [PATCH 16/34] Fix typo
---
Readme.rst | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Readme.rst b/Readme.rst
index 7491c4a0c..8a3ce97c5 100644
--- a/Readme.rst
+++ b/Readme.rst
@@ -2947,7 +2947,7 @@ in-game help.
gui/mod-manager
===============
-A way to simply install and remove small mods. It looks for specially formated mods in
+A way to simply install and remove small mods. It looks for specially formatted mods in
df subfolder 'mods'. Mods are not included, for example mods see: `github mini mod repository `_
.. image:: images/mod-manager.png
From 76ec3ba58c6c942abbfbac25ba71c826344ed324 Mon Sep 17 00:00:00 2001
From: Ben Lubar
Date: Sat, 17 May 2014 18:40:15 -0500
Subject: [PATCH 17/34] Fix English names containing the word "the"
See DFHack/dfhack#245
---
plugins/ruby/ruby.rb | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/plugins/ruby/ruby.rb b/plugins/ruby/ruby.rb
index 47924dcdf..f3504e44a 100644
--- a/plugins/ruby/ruby.rb
+++ b/plugins/ruby/ruby.rb
@@ -210,9 +210,17 @@ module DFHack
out.last << wl.words[name.words[1]].forms[name.parts_of_speech[1]] if name.words[1] >= 0
end
if name.words[5] >= 0
- out << 'the '
+ out << 'the'
out.last.capitalize! if out.length == 1
- (2..5).each { |i| out.last << wl.words[name.words[i]].forms[name.parts_of_speech[i]] if name.words[i] >= 0 }
+ out << wl.words[name.words[2]].forms[name.parts_of_speech[2]] if name.words[2] >= 0
+ out << wl.words[name.words[3]].forms[name.parts_of_speech[3]] if name.words[3] >= 0
+ if name.words[4] >= 0
+ out << wl.words[name.words[4]].forms[name.parts_of_speech[4]]
+ out << '-'
+ else
+ out << ''
+ end
+ out.last << wl.words[name.words[5]].forms[name.parts_of_speech[5]]
end
if name.words[6] >= 0
out << 'of'
From d1aee8949137ae34ea43d5771b99e267367091c8 Mon Sep 17 00:00:00 2001
From: Ben Lubar
Date: Sun, 18 May 2014 13:01:07 -0500
Subject: [PATCH 18/34] remove space before hyphen
---
plugins/ruby/ruby.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/plugins/ruby/ruby.rb b/plugins/ruby/ruby.rb
index f3504e44a..edce8ac84 100644
--- a/plugins/ruby/ruby.rb
+++ b/plugins/ruby/ruby.rb
@@ -216,7 +216,7 @@ module DFHack
out << wl.words[name.words[3]].forms[name.parts_of_speech[3]] if name.words[3] >= 0
if name.words[4] >= 0
out << wl.words[name.words[4]].forms[name.parts_of_speech[4]]
- out << '-'
+ out.last << '-'
else
out << ''
end
From e483e7439f4852e65bc5d104fdbb27b77533b514 Mon Sep 17 00:00:00 2001
From: Quietust
Date: Thu, 22 May 2014 08:18:01 -0500
Subject: [PATCH 19/34] Fix problems with NONE for item types and subtypes
---
library/modules/Items.cpp | 2 +
plugins/createitem.cpp | 139 ++++++++++++++++++++------------------
2 files changed, 74 insertions(+), 67 deletions(-)
diff --git a/library/modules/Items.cpp b/library/modules/Items.cpp
index 38d63d867..f25140217 100644
--- a/library/modules/Items.cpp
+++ b/library/modules/Items.cpp
@@ -234,6 +234,8 @@ ITEMDEF_VECTORS
#undef ITEM
default:
+ if (items[1] == "NONE")
+ return true;
break;
}
diff --git a/plugins/createitem.cpp b/plugins/createitem.cpp
index 6442e818a..89c2ade36 100644
--- a/plugins/createitem.cpp
+++ b/plugins/createitem.cpp
@@ -26,8 +26,10 @@
#include "df/reaction_product_itemst.h"
#include "df/tool_uses.h"
-using namespace std;
+using std::string;
+using std::vector;
using namespace DFHack;
+using namespace df::enums;
using df::global::world;
using df::global::ui;
@@ -71,8 +73,8 @@ bool makeItem (df::reaction_product_itemst *prod, df::unit *unit, bool second_it
vector out_items;
vector in_reag;
vector in_items;
- bool is_gloves = (prod->item_type == df::item_type::GLOVES);
- bool is_shoes = (prod->item_type == df::item_type::SHOES);
+ bool is_gloves = (prod->item_type == item_type::GLOVES);
+ bool is_shoes = (prod->item_type == item_type::SHOES);
df::item *container = NULL;
df::building *building = NULL;
@@ -81,9 +83,9 @@ bool makeItem (df::reaction_product_itemst *prod, df::unit *unit, bool second_it
if (dest_building != -1)
building = df::building::find(dest_building);
- prod->produce(unit, &out_items, &in_reag, &in_items, 1, df::job_skill::NONE,
+ prod->produce(unit, &out_items, &in_reag, &in_items, 1, job_skill::NONE,
df::historical_entity::find(unit->civ_id),
- ((*gametype == df::game_type::DWARF_MAIN) || (*gametype == df::game_type::DWARF_RECLAIM)) ? df::world_site::find(ui->site_id) : NULL);
+ ((*gametype == game_type::DWARF_MAIN) || (*gametype == game_type::DWARF_RECLAIM)) ? df::world_site::find(ui->site_id) : NULL);
if (!out_items.size())
return false;
// if we asked to make shoes and we got twice as many as we asked, then we're okay
@@ -130,7 +132,7 @@ bool makeItem (df::reaction_product_itemst *prod, df::unit *unit, bool second_it
command_result df_createitem (color_ostream &out, vector & parameters)
{
string item_str, material_str;
- df::item_type item_type = df::item_type::NONE;
+ df::item_type item_type = item_type::NONE;
int16_t item_subtype = -1;
int16_t mat_type = -1;
int32_t mat_index = -1;
@@ -156,23 +158,23 @@ command_result df_createitem (color_ostream &out, vector & parameters)
}
switch (item->getType())
{
- case df::item_type::FLASK:
- case df::item_type::BARREL:
- case df::item_type::BUCKET:
- case df::item_type::ANIMALTRAP:
- case df::item_type::BOX:
- case df::item_type::BIN:
- case df::item_type::BACKPACK:
- case df::item_type::QUIVER:
+ case item_type::FLASK:
+ case item_type::BARREL:
+ case item_type::BUCKET:
+ case item_type::ANIMALTRAP:
+ case item_type::BOX:
+ case item_type::BIN:
+ case item_type::BACKPACK:
+ case item_type::QUIVER:
break;
- case df::item_type::TOOL:
- if (item->hasToolUse(df::tool_uses::LIQUID_CONTAINER))
+ case item_type::TOOL:
+ if (item->hasToolUse(tool_uses::LIQUID_CONTAINER))
break;
- if (item->hasToolUse(df::tool_uses::FOOD_STORAGE))
+ if (item->hasToolUse(tool_uses::FOOD_STORAGE))
break;
- if (item->hasToolUse(df::tool_uses::SMALL_OBJECT_STORAGE))
+ if (item->hasToolUse(tool_uses::SMALL_OBJECT_STORAGE))
break;
- if (item->hasToolUse(df::tool_uses::TRACK_CART))
+ if (item->hasToolUse(tool_uses::TRACK_CART))
break;
default:
out.printerr("The selected item cannot be used for item storage!\n");
@@ -195,22 +197,22 @@ command_result df_createitem (color_ostream &out, vector & parameters)
}
switch (building->getType())
{
- case df::building_type::Coffin:
- case df::building_type::Furnace:
- case df::building_type::TradeDepot:
- case df::building_type::Shop:
- case df::building_type::Box:
- case df::building_type::Weaponrack:
- case df::building_type::Armorstand:
- case df::building_type::Workshop:
- case df::building_type::Cabinet:
- case df::building_type::SiegeEngine:
- case df::building_type::Trap:
- case df::building_type::AnimalTrap:
- case df::building_type::Cage:
- case df::building_type::Wagon:
- case df::building_type::NestBox:
- case df::building_type::Hive:
+ case building_type::Coffin:
+ case building_type::Furnace:
+ case building_type::TradeDepot:
+ case building_type::Shop:
+ case building_type::Box:
+ case building_type::Weaponrack:
+ case building_type::Armorstand:
+ case building_type::Workshop:
+ case building_type::Cabinet:
+ case building_type::SiegeEngine:
+ case building_type::Trap:
+ case building_type::AnimalTrap:
+ case building_type::Cage:
+ case building_type::Wagon:
+ case building_type::NestBox:
+ case building_type::Hive:
break;
default:
out.printerr("The selected building cannot be used for item storage!\n");
@@ -252,28 +254,31 @@ command_result df_createitem (color_ostream &out, vector & parameters)
MaterialInfo material;
vector tokens;
- if (!item.find(item_str))
+ if (item.find(item_str))
{
- out.printerr("Unrecognized item type!\n");
+ item_type = item.type;
+ item_subtype = item.subtype;
+ }
+ if (item_type == item_type::NONE)
+ {
+ out.printerr("You must specify a valid item type to create!\n");
return CR_FAILURE;
}
- item_type = item.type;
- item_subtype = item.subtype;
switch (item.type)
{
- case df::item_type::INSTRUMENT:
- case df::item_type::TOY:
- case df::item_type::WEAPON:
- case df::item_type::ARMOR:
- case df::item_type::SHOES:
- case df::item_type::SHIELD:
- case df::item_type::HELM:
- case df::item_type::GLOVES:
- case df::item_type::AMMO:
- case df::item_type::PANTS:
- case df::item_type::SIEGEAMMO:
- case df::item_type::TRAPCOMP:
- case df::item_type::TOOL:
+ case item_type::INSTRUMENT:
+ case item_type::TOY:
+ case item_type::WEAPON:
+ case item_type::ARMOR:
+ case item_type::SHOES:
+ case item_type::SHIELD:
+ case item_type::HELM:
+ case item_type::GLOVES:
+ case item_type::AMMO:
+ case item_type::PANTS:
+ case item_type::SIEGEAMMO:
+ case item_type::TRAPCOMP:
+ case item_type::TOOL:
if (item_subtype == -1)
{
out.printerr("You must specify a subtype!\n");
@@ -289,12 +294,12 @@ command_result df_createitem (color_ostream &out, vector & parameters)
mat_index = material.index;
break;
- case df::item_type::REMAINS:
- case df::item_type::FISH:
- case df::item_type::FISH_RAW:
- case df::item_type::VERMIN:
- case df::item_type::PET:
- case df::item_type::EGG:
+ case item_type::REMAINS:
+ case item_type::FISH:
+ case item_type::FISH_RAW:
+ case item_type::VERMIN:
+ case item_type::PET:
+ case item_type::EGG:
split_string(&tokens, material_str, ":");
if (tokens.size() != 2)
{
@@ -331,9 +336,9 @@ command_result df_createitem (color_ostream &out, vector & parameters)
}
break;
- case df::item_type::CORPSE:
- case df::item_type::CORPSEPIECE:
- case df::item_type::FOOD:
+ case item_type::CORPSE:
+ case item_type::CORPSEPIECE:
+ case item_type::FOOD:
out.printerr("Cannot create that type of item!\n");
return CR_FAILURE;
break;
@@ -376,16 +381,16 @@ command_result df_createitem (color_ostream &out, vector & parameters)
prod->count = count;
switch (item_type)
{
- case df::item_type::BAR:
- case df::item_type::POWDER_MISC:
- case df::item_type::LIQUID_MISC:
- case df::item_type::DRINK:
+ case item_type::BAR:
+ case item_type::POWDER_MISC:
+ case item_type::LIQUID_MISC:
+ case item_type::DRINK:
prod->product_dimension = 150;
break;
- case df::item_type::THREAD:
+ case item_type::THREAD:
prod->product_dimension = 15000;
break;
- case df::item_type::CLOTH:
+ case item_type::CLOTH:
prod->product_dimension = 10000;
break;
default:
From 1fcaac9d2ec39ebc9f32657c867589162dffd0b8 Mon Sep 17 00:00:00 2001
From: lethosor
Date: Sun, 25 May 2014 21:52:16 -0400
Subject: [PATCH 20/34] OS X Console: Implement back/forward one word escape
sequences
---
library/Console-darwin.cpp | 36 ++++++++++++++++++++++++++++++++++--
1 file changed, 34 insertions(+), 2 deletions(-)
diff --git a/library/Console-darwin.cpp b/library/Console-darwin.cpp
index 86cd657a1..081d4833e 100644
--- a/library/Console-darwin.cpp
+++ b/library/Console-darwin.cpp
@@ -478,14 +478,46 @@ namespace DFHack
break;
case 27: // escape sequence
lock->unlock();
- if(!read_char(seq[0]) || !read_char(seq[1]))
+ if (!read_char(seq[0]))
{
lock->lock();
return -2;
}
lock->lock();
- if(seq[0] == '[')
+ if (seq[0] == 'b')
{
+ // Back one word
+ if (raw_cursor == 0)
+ break;
+ raw_cursor--;
+ while (raw_cursor > 0 && !isalnum(raw_buffer[raw_cursor]))
+ raw_cursor--;
+ while (raw_cursor > 0 && isalnum(raw_buffer[raw_cursor]))
+ raw_cursor--;
+ if (!isalnum(raw_buffer[raw_cursor]))
+ raw_cursor++;
+ prompt_refresh();
+ }
+ else if (seq[0] == 'f')
+ {
+ // Forward one word
+ int len = raw_buffer.size();
+ if (raw_cursor == len)
+ break;
+ raw_cursor++;
+ while (raw_cursor <= len && !isalnum(raw_buffer[raw_cursor]))
+ raw_cursor++;
+ while (raw_cursor <= len && isalnum(raw_buffer[raw_cursor]))
+ raw_cursor++;
+ prompt_refresh();
+ }
+ else if(seq[0] == '[')
+ {
+ if (!read_char(seq[1]))
+ {
+ lock->lock();
+ return -2;
+ }
if (seq[1] == 'D')
{
left_arrow:
From 58b9c02ce5dc518c0904cc405fe8128d7d1592f6 Mon Sep 17 00:00:00 2001
From: lethosor
Date: Sun, 25 May 2014 22:10:40 -0400
Subject: [PATCH 21/34] Migrate esc-b/f sequences to Linux
---
library/Console-linux.cpp | 36 ++++++++++++++++++++++++++++++++++--
1 file changed, 34 insertions(+), 2 deletions(-)
diff --git a/library/Console-linux.cpp b/library/Console-linux.cpp
index f32fa1c2a..a49b5dbdd 100644
--- a/library/Console-linux.cpp
+++ b/library/Console-linux.cpp
@@ -480,14 +480,46 @@ namespace DFHack
break;
case 27: // escape sequence
lock->unlock();
- if(!read_char(seq[0]) || !read_char(seq[1]))
+ if (!read_char(seq[0]))
{
lock->lock();
return -2;
}
lock->lock();
- if(seq[0] == '[')
+ if (seq[0] == 'b')
{
+ // Back one word
+ if (raw_cursor == 0)
+ break;
+ raw_cursor--;
+ while (raw_cursor > 0 && !isalnum(raw_buffer[raw_cursor]))
+ raw_cursor--;
+ while (raw_cursor > 0 && isalnum(raw_buffer[raw_cursor]))
+ raw_cursor--;
+ if (!isalnum(raw_buffer[raw_cursor]))
+ raw_cursor++;
+ prompt_refresh();
+ }
+ else if (seq[0] == 'f')
+ {
+ // Forward one word
+ int len = raw_buffer.size();
+ if (raw_cursor == len)
+ break;
+ raw_cursor++;
+ while (raw_cursor <= len && !isalnum(raw_buffer[raw_cursor]))
+ raw_cursor++;
+ while (raw_cursor <= len && isalnum(raw_buffer[raw_cursor]))
+ raw_cursor++;
+ prompt_refresh();
+ }
+ else if(seq[0] == '[')
+ {
+ if (!read_char(seq[1]))
+ {
+ lock->lock();
+ return -2;
+ }
if (seq[1] == 'D')
{
left_arrow:
From d320fe71d11274d33c1d8ff3f59e8122478fdb4c Mon Sep 17 00:00:00 2001
From: lethosor
Date: Sun, 25 May 2014 23:39:34 -0400
Subject: [PATCH 22/34] Implement extended arrow key sequences
---
library/Console-darwin.cpp | 69 ++++++++++++++++++++++++++------------
1 file changed, 48 insertions(+), 21 deletions(-)
diff --git a/library/Console-darwin.cpp b/library/Console-darwin.cpp
index 081d4833e..f36973d5c 100644
--- a/library/Console-darwin.cpp
+++ b/library/Console-darwin.cpp
@@ -305,6 +305,33 @@ namespace DFHack
}
/// beep. maybe?
//void beep (void);
+ void back_word()
+ {
+ if (raw_cursor == 0)
+ return;
+ raw_cursor--;
+ while (raw_cursor > 0 && !isalnum(raw_buffer[raw_cursor]))
+ raw_cursor--;
+ while (raw_cursor > 0 && isalnum(raw_buffer[raw_cursor]))
+ raw_cursor--;
+ if (!isalnum(raw_buffer[raw_cursor]) && raw_cursor != 0)
+ raw_cursor++;
+ prompt_refresh();
+ }
+ void forward_word()
+ {
+ int len = raw_buffer.size();
+ if (raw_cursor == len)
+ return;
+ raw_cursor++;
+ while (raw_cursor <= len && !isalnum(raw_buffer[raw_cursor]))
+ raw_cursor++;
+ while (raw_cursor <= len && isalnum(raw_buffer[raw_cursor]))
+ raw_cursor++;
+ if (raw_cursor > len)
+ raw_cursor = len;
+ prompt_refresh();
+ }
/// A simple line edit (raw mode)
int lineedit(const std::string& prompt, std::string& output, recursive_mutex * lock, CommandHistory & ch)
{
@@ -486,30 +513,11 @@ namespace DFHack
lock->lock();
if (seq[0] == 'b')
{
- // Back one word
- if (raw_cursor == 0)
- break;
- raw_cursor--;
- while (raw_cursor > 0 && !isalnum(raw_buffer[raw_cursor]))
- raw_cursor--;
- while (raw_cursor > 0 && isalnum(raw_buffer[raw_cursor]))
- raw_cursor--;
- if (!isalnum(raw_buffer[raw_cursor]))
- raw_cursor++;
- prompt_refresh();
+ back_word();
}
else if (seq[0] == 'f')
{
- // Forward one word
- int len = raw_buffer.size();
- if (raw_cursor == len)
- break;
- raw_cursor++;
- while (raw_cursor <= len && !isalnum(raw_buffer[raw_cursor]))
- raw_cursor++;
- while (raw_cursor <= len && isalnum(raw_buffer[raw_cursor]))
- raw_cursor++;
- prompt_refresh();
+ forward_word();
}
else if(seq[0] == '[')
{
@@ -577,6 +585,7 @@ namespace DFHack
else if (seq[1] > '0' && seq[1] < '7')
{
// extended escape
+ unsigned char seq3[3];
lock->unlock();
if(!read_char(seq2))
{
@@ -593,6 +602,24 @@ namespace DFHack
prompt_refresh();
}
}
+ if (!read_char(seq3[0]) || !read_char(seq3[1]))
+ {
+ lock->lock();
+ return -2;
+ }
+ if (seq2 == ';')
+ {
+ // Format: esc [ n ; n DIRECTION
+ // Ignore first character (second "n")
+ if (seq3[1] == 'C')
+ {
+ forward_word();
+ }
+ else if (seq3[1] == 'D')
+ {
+ back_word();
+ }
+ }
}
}
break;
From bdca1ee7095ddc2dd5c6e4f8d84812cf69b774a6 Mon Sep 17 00:00:00 2001
From: lethosor
Date: Mon, 26 May 2014 10:03:28 -0400
Subject: [PATCH 23/34] Linux: Extended back/forward word sequences
---
library/Console-linux.cpp | 69 +++++++++++++++++++++++++++------------
1 file changed, 48 insertions(+), 21 deletions(-)
diff --git a/library/Console-linux.cpp b/library/Console-linux.cpp
index a49b5dbdd..d4005af3c 100644
--- a/library/Console-linux.cpp
+++ b/library/Console-linux.cpp
@@ -307,6 +307,33 @@ namespace DFHack
}
/// beep. maybe?
//void beep (void);
+ void back_word()
+ {
+ if (raw_cursor == 0)
+ return;
+ raw_cursor--;
+ while (raw_cursor > 0 && !isalnum(raw_buffer[raw_cursor]))
+ raw_cursor--;
+ while (raw_cursor > 0 && isalnum(raw_buffer[raw_cursor]))
+ raw_cursor--;
+ if (!isalnum(raw_buffer[raw_cursor]) && raw_cursor != 0)
+ raw_cursor++;
+ prompt_refresh();
+ }
+ void forward_word()
+ {
+ int len = raw_buffer.size();
+ if (raw_cursor == len)
+ return;
+ raw_cursor++;
+ while (raw_cursor <= len && !isalnum(raw_buffer[raw_cursor]))
+ raw_cursor++;
+ while (raw_cursor <= len && isalnum(raw_buffer[raw_cursor]))
+ raw_cursor++;
+ if (raw_cursor > len)
+ raw_cursor = len;
+ prompt_refresh();
+ }
/// A simple line edit (raw mode)
int lineedit(const std::string& prompt, std::string& output, recursive_mutex * lock, CommandHistory & ch)
{
@@ -488,30 +515,11 @@ namespace DFHack
lock->lock();
if (seq[0] == 'b')
{
- // Back one word
- if (raw_cursor == 0)
- break;
- raw_cursor--;
- while (raw_cursor > 0 && !isalnum(raw_buffer[raw_cursor]))
- raw_cursor--;
- while (raw_cursor > 0 && isalnum(raw_buffer[raw_cursor]))
- raw_cursor--;
- if (!isalnum(raw_buffer[raw_cursor]))
- raw_cursor++;
- prompt_refresh();
+ back_word();
}
else if (seq[0] == 'f')
{
- // Forward one word
- int len = raw_buffer.size();
- if (raw_cursor == len)
- break;
- raw_cursor++;
- while (raw_cursor <= len && !isalnum(raw_buffer[raw_cursor]))
- raw_cursor++;
- while (raw_cursor <= len && isalnum(raw_buffer[raw_cursor]))
- raw_cursor++;
- prompt_refresh();
+ forward_word();
}
else if(seq[0] == '[')
{
@@ -579,6 +587,7 @@ namespace DFHack
else if (seq[1] > '0' && seq[1] < '7')
{
// extended escape
+ unsigned char seq3[3];
lock->unlock();
if(!read_char(seq2))
{
@@ -595,6 +604,24 @@ namespace DFHack
prompt_refresh();
}
}
+ if (!read_char(seq3[0]) || !read_char(seq3[1]))
+ {
+ lock->lock();
+ return -2;
+ }
+ if (seq2 == ';')
+ {
+ // Format: esc [ n ; n DIRECTION
+ // Ignore first character (second "n")
+ if (seq3[1] == 'C')
+ {
+ forward_word();
+ }
+ else if (seq3[1] == 'D')
+ {
+ back_word();
+ }
+ }
}
}
break;
From 99659e7e00c13fcce107152ed8cdbd05a0fd9e15 Mon Sep 17 00:00:00 2001
From: Warmist
Date: Mon, 26 May 2014 18:16:32 +0300
Subject: [PATCH 24/34] cmd-prompt needs to work on ANY screen. This fixes it.
---
plugins/command-prompt.cpp | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/plugins/command-prompt.cpp b/plugins/command-prompt.cpp
index 5e84db831..3cdd83ab3 100644
--- a/plugins/command-prompt.cpp
+++ b/plugins/command-prompt.cpp
@@ -182,10 +182,14 @@ command_result show_prompt(color_ostream &out, std::vector & param
Screen::show(new viewscreen_commandpromptst(params));
return CR_OK;
}
+bool hotkey_allow_all(df::viewscreen *top)
+{
+ return true;
+}
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands)
{
commands.push_back(PluginCommand(
- "command-prompt","Shows a command prompt on window.",show_prompt,false,
+ "command-prompt","Shows a command prompt on window.",show_prompt,hotkey_allow_all,
"command-prompt [entry] - shows a cmd prompt in df window. Entry is used for default prefix (e.g. ':lua')"
));
return CR_OK;
From 49bbd41bc38392cefaed869e89428a5cc0e74b91 Mon Sep 17 00:00:00 2001
From: Warmist
Date: Mon, 2 Jun 2014 17:57:59 +0300
Subject: [PATCH 25/34] Added a way to change the mod install directory (and
changed the default to hack/mods) and added simpler way to add to init.lua
---
scripts/gui/mod-manager.lua | 52 +++++++++++++++++++++++++++++++++----
1 file changed, 47 insertions(+), 5 deletions(-)
diff --git a/scripts/gui/mod-manager.lua b/scripts/gui/mod-manager.lua
index 6d56d88a6..210109807 100644
--- a/scripts/gui/mod-manager.lua
+++ b/scripts/gui/mod-manager.lua
@@ -1,8 +1,29 @@
+-- a graphical mod manager for df
local gui=require 'gui'
local widgets=require 'gui.widgets'
local entity_file=dfhack.getDFPath().."/raw/objects/entity_default.txt"
local init_file=dfhack.getDFPath().."/raw/init.lua"
+local mod_dir=dfhack.getDFPath().."/hack/mods"
+--[[ mod format: lua script that defines:
+ name - a name that is displayed in list
+ author - mod author, also displayed
+ description - mod description
+ OPTIONAL:
+ raws_list - a list (table) of file names that need to be copied over to df raws
+ patch_entity - a chunk of text to patch entity TODO: add settings to which entities to add
+ patch_init - a chunk of lua to add to lua init
+ patch_dofile - a list (table) of files to add to lua init as "dofile"
+ patch_files - a table of files to patch:
+ filename - a filename (in raws folder) to patch
+ patch - what to add
+ after - a string after which to insert
+ MORE OPTIONAL:
+ guard - a token that is used in raw files to find editions and remove them on uninstall
+ guard_init - a token for lua file
+ [pre|post]_(un)install - callback functions. Can trigger more complicated behavior
+]]
+
function fileExists(filename)
local file=io.open(filename,"rb")
if file==nil then
@@ -12,6 +33,10 @@ function fileExists(filename)
return true
end
end
+if not fileExists(init_file) then
+ local initFile=io.open(initFileName,"a")
+ initFile:close()
+end
function copyFile(from,to) --oh so primitive
local filefrom=io.open(from,"rb")
local fileto=io.open(to,"w+b")
@@ -27,6 +52,16 @@ function patchInit(initFileName,patch_guard,code)
code,patch_guard[2]))
initFile:close()
end
+function patchDofile( initFileName,patch_guard,dofile_list )
+ local initFile=io.open(initFileName,"a")
+ initFile:write(patch_guard[1].."\n")
+ for _,v in ipairs(dofile_list) do
+ local fixed_path=mod_dir:gsub("\\","/")
+ initFile:write(string.format("dofile('%s/%s')\n",fixed_path,v))
+ end
+ initFile:write(patch_guard[2].."\n")
+ initFile:close()
+end
function patchFile(file_name,patch_guard,after_string,code)
local input_lines=patch_guard[1].."\n"..code.."\n"..patch_guard[2]
@@ -109,15 +144,19 @@ manager=defclass(manager,gui.FramedScreen)
function manager:init(args)
self.mods={}
local mods=self.mods
- local mlist=dfhack.internal.getDir("mods")
+ local mlist=dfhack.internal.getDir(mod_dir)
+
+ if #mlist==0 then
+ qerror("Mod directory not found! Are you sure it is in:"..mod_dir)
+ end
for k,v in ipairs(mlist) do
if v~="." and v~=".." then
- local f,modData=pcall(dofile,"mods/".. v .. "/init.lua")
+ local f,modData=pcall(dofile,mod_dir.."/".. v .. "/init.lua")
if f then
mods[modData.name]=modData
modData.guard=modData.guard or {">>"..modData.name.." patch","<
Date: Tue, 3 Jun 2014 12:24:45 +0400
Subject: [PATCH 26/34] Fix obvious issues in stockflow.
- Duplicate definition of a function now in uicommon.h
- Assertion failure due to missing core suspend claim.
- Incorrect way of accessing the civ entity.
- Accessing nil objects in the lua module if filter matches nothing.
- Lua module breaking on reload('plugins.stockflow').
---
plugins/lua/stockflow.lua | 28 +++++++++++++---------------
plugins/stockflow.cpp | 19 +------------------
2 files changed, 14 insertions(+), 33 deletions(-)
diff --git a/plugins/lua/stockflow.lua b/plugins/lua/stockflow.lua
index ec52c3deb..489a72705 100644
--- a/plugins/lua/stockflow.lua
+++ b/plugins/lua/stockflow.lua
@@ -1,11 +1,11 @@
local _ENV = mkmodule('plugins.stockflow')
-gui = require "gui"
-utils = require "utils"
+local gui = require "gui"
+local utils = require "utils"
-reaction_list = {}
-saved_orders = {}
-jobs_to_create = {}
+reaction_list = reaction_list or {}
+saved_orders = saved_orders or {}
+jobs_to_create = jobs_to_create or {}
triggers = {
{filled = false, divisor = 1, name = "Per empty space"},
@@ -19,11 +19,7 @@ triggers = {
{name = "Never"},
}
--- There must be a better way get the value of an enum.
-job_types = {}
-for key, value in ipairs(df.job_type) do
- job_types[value] = key
-end
+local job_types = df.job_type
entry_ints = {
stockpile_id = 1,
@@ -205,7 +201,7 @@ function material_reactions(reactions, itemtypes, mat_info)
end
function clothing_reactions(reactions, mat_info, filter)
- local resources = df.global.world.entities.all[df.global.ui.civ_id].resources
+ local resources = df.historical_entity.find(df.global.ui.civ_id).resources
local itemdefs = df.global.world.raws.itemdefs
resource_reactions(reactions, job_types.MakeArmor, mat_info, resources.armor_type, itemdefs.armor, {permissible = filter})
resource_reactions(reactions, job_types.MakePants, mat_info, resources.pants_type, itemdefs.pants, {permissible = filter})
@@ -372,7 +368,7 @@ function collect_reactions()
-- Reactions defined in the raws.
-- Not all reactions are allowed to the civilization.
-- That includes "Make sharp rock" by default.
- local entity = df.global.world.entities.all[df.global.ui.civ_id]
+ local entity = df.historical_entity.find(df.global.ui.civ_id)
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)
@@ -740,8 +736,10 @@ function screen:onInput(keys)
self:dismiss()
elseif keys.SELECT then
self:dismiss()
- local selected = self.reactions[self.position].index
- store_order(self.stockpile, selected)
+ local selected = self.reactions[self.position]
+ if selected then
+ store_order(self.stockpile, selected.index)
+ end
elseif keys.STANDARDSCROLL_UP then
self.position = self.position - 1
elseif keys.STANDARDSCROLL_DOWN then
@@ -838,10 +836,10 @@ function screen:refilter()
local displayed = {}
for n = 0, PageSize*2 - 1 do
local item = filtered[start + n]
- local name = item.name
if not item then
break
end
+ local name = item.name
local x = 1
local y = FirstRow + n
diff --git a/plugins/stockflow.cpp b/plugins/stockflow.cpp
index b96faa47f..adff25a04 100644
--- a/plugins/stockflow.cpp
+++ b/plugins/stockflow.cpp
@@ -51,20 +51,6 @@ const char *usage = (
"number of identical orders already in the queue.\n"
);
-/*
- * Stockpile Access
- */
-static building_stockpilest *get_selected_stockpile() {
- if (!Gui::dwarfmode_hotkey(Core::getTopViewscreen()) ||
- ui->main.mode != ui_sidebar_mode::QueryBuilding)
- {
- return nullptr;
- }
-
- return virtual_cast(world->selected_building);
-}
-
-
/*
* Lua interface.
* Currently calls out to Lua functions, but never back in.
@@ -134,10 +120,6 @@ public:
bool stockpile_method(const char *method, building_stockpilest *sp) {
// Combines the select_order and toggle_trigger method calls,
// because they share the same signature.
-
- // Suspension is necessary for toggle_trigger,
- // but may be overkill for select_order.
- // Both are used from hooks, so CoreSuspender is prohibited.
CoreSuspendClaimer suspend;
auto L = Lua::Core::State;
@@ -168,6 +150,7 @@ public:
auto L = Lua::Core::State;
color_ostream_proxy out(Core::getInstance().getConsole());
+ CoreSuspendClaimer suspend;
Lua::StackUnwinder top(L);
if (!lua_checkstack(L, 2))
From 0a0358a8c1d873c72c851cf07e43afb3947dcaf9 Mon Sep 17 00:00:00 2001
From: Alexander Gavrilov
Date: Tue, 3 Jun 2014 12:17:03 +0400
Subject: [PATCH 27/34] Update structures
---
library/xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/library/xml b/library/xml
index e0407d8bb..93f89c7c5 160000
--- a/library/xml
+++ b/library/xml
@@ -1 +1 @@
-Subproject commit e0407d8bbbc965dbb62826d481f27940972ffd66
+Subproject commit 93f89c7c56f366ac8f68e883c9f853a76e12f00a
From 4034df3560c72ff312e5fd44b28c6278da202342 Mon Sep 17 00:00:00 2001
From: Anuradha Dissanayake
Date: Wed, 5 Feb 2014 23:35:53 +1300
Subject: [PATCH 28/34] Fix incorrect plugin name in version check
---
plugins/autotrade.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/plugins/autotrade.cpp b/plugins/autotrade.cpp
index e31fccdbc..5eacbf2d7 100644
--- a/plugins/autotrade.cpp
+++ b/plugins/autotrade.cpp
@@ -502,7 +502,7 @@ static command_result autotrade_cmd(color_ostream &out, vector & parame
{
if (parameters.size() == 1 && toLower(parameters[0])[0] == 'v')
{
- out << "Building Plan" << endl << "Version: " << PLUGIN_VERSION << endl;
+ out << "Autotrade" << endl << "Version: " << PLUGIN_VERSION << endl;
}
}
From df244aa7a4310ce26f165a14bceecd26e6ece794 Mon Sep 17 00:00:00 2001
From: Anuradha Dissanayake
Date: Sun, 1 Jun 2014 22:13:36 +1200
Subject: [PATCH 29/34] Disable mouse query when linking levers.
Update mousequery plugin version.
---
plugins/mousequery.cpp | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/plugins/mousequery.cpp b/plugins/mousequery.cpp
index 9cc6bb783..0fe337017 100644
--- a/plugins/mousequery.cpp
+++ b/plugins/mousequery.cpp
@@ -28,7 +28,7 @@ using namespace df::enums::ui_sidebar_mode;
DFHACK_PLUGIN("mousequery");
-#define PLUGIN_VERSION 0.17
+#define PLUGIN_VERSION 0.18
static int32_t last_clicked_x, last_clicked_y, last_clicked_z;
static int32_t last_pos_x, last_pos_y, last_pos_z;
@@ -539,6 +539,13 @@ struct mousequery_hook : public df::viewscreen_dwarfmodest
if (mx < 1 || mx > right_margin - 2 || my < 1 || my > gps->dimy - 2)
mpos_valid = false;
+ // Check if in lever binding mode
+ if (Gui::getFocusString(Core::getTopViewscreen()) ==
+ "dwarfmode/QueryBuilding/Some/Lever/AddJob")
+ {
+ return;
+ }
+
if (mpos_valid)
{
if (mpos.x != last_move_pos.x || mpos.y != last_move_pos.y || mpos.z != last_move_pos.z)
From 23acf276b4b9bd0201f90b8fab9a2dbb22212099 Mon Sep 17 00:00:00 2001
From: Quietust
Date: Tue, 3 Jun 2014 08:58:31 -0500
Subject: [PATCH 30/34] Silence warning C4800 on Windows
---
plugins/reveal.cpp | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/plugins/reveal.cpp b/plugins/reveal.cpp
index 91ab75686..9bd63e47e 100644
--- a/plugins/reveal.cpp
+++ b/plugins/reveal.cpp
@@ -449,22 +449,22 @@ command_result revflood(color_ostream &out, vector & params)
}
if(sides)
{
- flood.push(foo(DFCoord(current.x + 1, current.y ,current.z),0));
- flood.push(foo(DFCoord(current.x + 1, current.y + 1 ,current.z),0));
- flood.push(foo(DFCoord(current.x, current.y + 1 ,current.z),0));
- flood.push(foo(DFCoord(current.x - 1, current.y + 1 ,current.z),0));
- flood.push(foo(DFCoord(current.x - 1, current.y ,current.z),0));
- flood.push(foo(DFCoord(current.x - 1, current.y - 1 ,current.z),0));
- flood.push(foo(DFCoord(current.x, current.y - 1 ,current.z),0));
- flood.push(foo(DFCoord(current.x + 1, current.y - 1 ,current.z),0));
+ flood.push(foo(DFCoord(current.x + 1, current.y ,current.z),false));
+ flood.push(foo(DFCoord(current.x + 1, current.y + 1 ,current.z),false));
+ flood.push(foo(DFCoord(current.x, current.y + 1 ,current.z),false));
+ flood.push(foo(DFCoord(current.x - 1, current.y + 1 ,current.z),false));
+ flood.push(foo(DFCoord(current.x - 1, current.y ,current.z),false));
+ flood.push(foo(DFCoord(current.x - 1, current.y - 1 ,current.z),false));
+ flood.push(foo(DFCoord(current.x, current.y - 1 ,current.z),false));
+ flood.push(foo(DFCoord(current.x + 1, current.y - 1 ,current.z),false));
}
if(above)
{
- flood.push(foo(DFCoord(current.x, current.y ,current.z + 1),1));
+ flood.push(foo(DFCoord(current.x, current.y ,current.z + 1),true));
}
if(below)
{
- flood.push(foo(DFCoord(current.x, current.y ,current.z - 1),0));
+ flood.push(foo(DFCoord(current.x, current.y ,current.z - 1),false));
}
}
MCache->WriteAll();
From a1f9b1d1c4fd4f8c3a085e0353d79dc6f4b3886a Mon Sep 17 00:00:00 2001
From: Quietust
Date: Fri, 6 Jun 2014 14:24:57 -0500
Subject: [PATCH 31/34] Sync with structures change
---
plugins/strangemood.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/plugins/strangemood.cpp b/plugins/strangemood.cpp
index 35d1e15b8..81840b67b 100644
--- a/plugins/strangemood.cpp
+++ b/plugins/strangemood.cpp
@@ -126,7 +126,7 @@ int getCreatedMetalBars (int32_t idx)
return 0;
}
-void selectWord (const df::world_raws::T_language::T_word_table &table, int32_t &word, df::enum_field &part, int mode)
+void selectWord (const df::language_word_table &table, int32_t &word, df::enum_field &part, int mode)
{
if (table.parts[mode].size())
{
@@ -142,7 +142,7 @@ void selectWord (const df::world_raws::T_language::T_word_table &table, int32_t
}
}
-void generateName(df::language_name &output, int language, int mode, const df::world_raws::T_language::T_word_table &table1, const df::world_raws::T_language::T_word_table &table2)
+void generateName(df::language_name &output, int language, int mode, const df::language_word_table &table1, const df::language_word_table &table2)
{
for (int i = 0; i < 100; i++)
{
From 0e3fb79f0e620a2e7cc4c8557b6f2d795e24e919 Mon Sep 17 00:00:00 2001
From: Alexander Gavrilov
Date: Tue, 10 Jun 2014 12:52:17 +0400
Subject: [PATCH 32/34] Update structures
---
library/xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/library/xml b/library/xml
index 93f89c7c5..851f52d5e 160000
--- a/library/xml
+++ b/library/xml
@@ -1 +1 @@
-Subproject commit 93f89c7c56f366ac8f68e883c9f853a76e12f00a
+Subproject commit 851f52d5e9eae6fc81adadd10e53bd2cc42bfd21
From 08b4279c4dc5334658a43f6a1a6eba7bb1095ac1 Mon Sep 17 00:00:00 2001
From: Alexander Gavrilov
Date: Tue, 10 Jun 2014 13:10:10 +0400
Subject: [PATCH 33/34] Document better how to access fields of the interposed
class.
---
library/include/VTableInterpose.h | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/library/include/VTableInterpose.h b/library/include/VTableInterpose.h
index f93eb4176..ec950bfe2 100644
--- a/library/include/VTableInterpose.h
+++ b/library/include/VTableInterpose.h
@@ -42,12 +42,16 @@ namespace DFHack
struct my_hack : df::someclass {
typedef df::someclass interpose_base;
- DEFINE_VMETHOD_INTERPOSE(void, foo, (int arg)) {
+ // You may define additional methods here, but NOT non-static fields
+
+ DEFINE_VMETHOD_INTERPOSE(int, foo, (int arg)) {
// If needed by the code, claim the suspend lock.
// DO NOT USE THE USUAL CoreSuspender, OR IT WILL DEADLOCK!
// CoreSuspendClaimer suspend;
...
- INTERPOSE_NEXT(foo)(arg) // call the original
+ ... this->field ... // access fields of the df::someclass object
+ ...
+ int orig_retval = INTERPOSE_NEXT(foo)(arg); // call the original method
...
}
};
From da6219e5a187e9fd58e2a3a820968a9b5bcd0af9 Mon Sep 17 00:00:00 2001
From: Alexander Gavrilov
Date: Tue, 10 Jun 2014 13:32:15 +0400
Subject: [PATCH 34/34] Mention a couple of features in NEWS
---
NEWS | 2 ++
1 file changed, 2 insertions(+)
diff --git a/NEWS b/NEWS
index 757a9277f..75c751900 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,7 @@ DFHack future
- support for multiple raw/init.d/*.lua init scripts in one save.
- eventful now has a more friendly way of making custom sidebars
- new plugin: building-hacks. Allows to add custom functionality and/or animations to buildings.
+ - on Linux and OSX the console now supports moving the cursor back and forward by a whole word.
New scripts:
- gui/mod-manager: allows installing/uninstalling mods into df from df/mods directory.
@@ -28,6 +29,7 @@ DFHack future
New plugins:
- rendermax: replace the renderer with something else. Most interesting is "rendermax light"- a lighting engine for df.
+ - stockflow (by eswald): queues manager jobs of the configured type based on the state of a stockpile.
Misc improvements:
- digfort: improved csv parsing, add start() comment handling