From 9319ebfba0f2890605f9ba3541b9a4955316bf18 Mon Sep 17 00:00:00 2001 From: AtomicChicken Date: Tue, 19 Apr 2016 15:47:05 +0200 Subject: [PATCH 01/10] Update item-trigger.lua Fixed an error caused by item-trigger attempting to handle item types which lack a subtype, whilst simultaneously adding support for such items. --- scripts/modtools/item-trigger.lua | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/scripts/modtools/item-trigger.lua b/scripts/modtools/item-trigger.lua index 78c8a4332..cf00ed749 100644 --- a/scripts/modtools/item-trigger.lua +++ b/scripts/modtools/item-trigger.lua @@ -64,10 +64,18 @@ function processTrigger(command) dfhack.run_command(table.unpack(command2)) end +function getitemType(item) +if item:getSubtype() ~= -1 then +itemType = dfhack.items.getSubtypeDef(item:getType(),item:getSubtype()).id +else itemType = df.item_type[item:getType()] +end +return itemType +end + function handler(table) local itemMat = dfhack.matinfo.decode(table.item) local itemMatStr = itemMat:getToken() - local itemType = dfhack.items.getSubtypeDef(table.item:getType(),table.item:getSubtype()).id + local itemType = getitemType(table.item) table.itemMat = itemMat table.itemType = itemType @@ -177,6 +185,7 @@ arguments: trigger the command for items of this type examples: ITEM_WEAPON_PICK + RING -onStrike trigger the command when someone strikes someone with an appropriate weapon -onEquip @@ -243,6 +252,7 @@ if not args.command then end if args.itemType then + if dfhack.items.findType(args.itemType) == -1 then local temp for _,itemdef in ipairs(df.global.world.raws.itemdefs.all) do if itemdef.id == args.itemType then @@ -254,6 +264,7 @@ if args.itemType then error 'Could not find item type.' end args.itemType = temp + end end local numConditions = (args.material and 1 or 0) + (args.itemType and 1 or 0) + (args.contaminant and 1 or 0) From acac839371d1d15d20c0316575721e8e1e8fae1c Mon Sep 17 00:00:00 2001 From: PeridexisErrant Date: Wed, 20 Apr 2016 11:08:02 +1000 Subject: [PATCH 02/10] Replace fixdiplomats, fixmerchants with scripts --- NEWS.rst | 2 + docs/Plugins.rst | 12 -- plugins/CMakeLists.txt | 1 - plugins/fixpositions.cpp | 244 -------------------------------------- scripts/fix/diplomats.lua | 100 ++++++++++++++++ scripts/fix/merchants.lua | 95 +++++++++++++++ 6 files changed, 197 insertions(+), 257 deletions(-) delete mode 100644 plugins/fixpositions.cpp create mode 100644 scripts/fix/diplomats.lua create mode 100644 scripts/fix/merchants.lua diff --git a/NEWS.rst b/NEWS.rst index 54954029b..751daceb3 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -112,6 +112,8 @@ Misc Improvements - `createitem`: Can now create items anywhere without specifying a unit, as long as a unit exists on the map - `devel/export-dt-ini`: Updated for 0.42.06 - `devel/find-offsets`: Automated several more scans +- `fix/diplomats`: replaces ``fixdiplomats`` +- `fix/merchants`: replaces ``fixmerchants`` - `gui/gm-editor`: Now supports finding some items with a numeric ID (with ``i``) - `lua`: Now supports some built-in variables like `gui/gm-editor`, e.g. ``unit``, ``screen`` - `remotefortressreader`: Can now trigger keyboard events diff --git a/docs/Plugins.rst b/docs/Plugins.rst index 4e1886e8d..0c4a3237b 100644 --- a/docs/Plugins.rst +++ b/docs/Plugins.rst @@ -180,18 +180,6 @@ Bugfixes .. contents:: :local: -fixdiplomats -============ -Adds a Diplomat position to all Elven civilizations, allowing them to negotiate -tree cutting quotas - and you to violate them and start wars. -This was vanilla behaviour until ``0.31.12``, in which the "bug" was "fixed". - -fixmerchants -============ -Adds the Guild Representative position to all Human civilizations, -allowing them to make trade agreements. This was the default behaviour in -``0.28.181.40d`` and earlier. - .. _fix-unit-occupancy: fix-unit-occupancy diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index dd1c6344f..cc0de019f 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -99,7 +99,6 @@ if (BUILD_SUPPORTED) DFHACK_PLUGIN(fastdwarf fastdwarf.cpp) DFHACK_PLUGIN(filltraffic filltraffic.cpp) DFHACK_PLUGIN(fix-armory fix-armory.cpp) - DFHACK_PLUGIN(fixpositions fixpositions.cpp) DFHACK_PLUGIN(fix-unit-occupancy fix-unit-occupancy.cpp) DFHACK_PLUGIN(fixveins fixveins.cpp) DFHACK_PLUGIN(flows flows.cpp) diff --git a/plugins/fixpositions.cpp b/plugins/fixpositions.cpp deleted file mode 100644 index e136ee0a9..000000000 --- a/plugins/fixpositions.cpp +++ /dev/null @@ -1,244 +0,0 @@ -// Fix Entity Positions - make sure Elves have diplomats and Humans have guild representatives - -#include "Core.h" -#include -#include -#include - -#include -#include "df/world.h" -#include "df/historical_entity.h" -#include "df/entity_raw.h" -#include "df/entity_position.h" -#include "df/entity_position_responsibility.h" -#include "df/entity_position_assignment.h" - -using std::string; -using std::vector; -using namespace DFHack; -using namespace df::enums; - -DFHACK_PLUGIN("fixpositions"); -REQUIRE_GLOBAL(world); - -command_result df_fixdiplomats (color_ostream &out, vector ¶meters) -{ - if (!parameters.empty()) - return CR_WRONG_USAGE; - - CoreSuspender suspend; - - int checked = 0, fixed = 0; - for (int i = 0; i < world->entities.all.size(); i++) - { - df::historical_entity *ent = world->entities.all[i]; - // only work with civilizations - ignore groups and religions - if (ent->type != 0) - continue; - // only add diplomats for tree cap diplomacy - if (!ent->entity_raw->flags.is_set(entity_raw_flags::TREE_CAP_DIPLOMACY)) - continue; - checked++; - - bool update = true; - df::entity_position *pos = NULL; - // see if we need to add a new position or modify an existing one - for (int j = 0; j < ent->positions.own.size(); j++) - { - pos = ent->positions.own[j]; - if (pos->responsibilities[entity_position_responsibility::MAKE_INTRODUCTIONS] && - pos->responsibilities[entity_position_responsibility::MAKE_PEACE_AGREEMENTS] && - pos->responsibilities[entity_position_responsibility::MAKE_TOPIC_AGREEMENTS]) - { - // a diplomat position exists with the proper responsibilities - skip to the end - update = false; - break; - } - // Diplomat position already exists, but has the wrong options - modify it instead of creating a new one - if (pos->code == "DIPLOMAT") - break; - pos = NULL; - } - if (update) - { - // either there's no diplomat, or there is one and it's got the wrong responsibilities - if (!pos) - { - // there was no diplomat - create it - pos = new df::entity_position; - ent->positions.own.push_back(pos); - - pos->code = "DIPLOMAT"; - pos->id = ent->positions.next_position_id++; - pos->flags.set(entity_position_flags::DO_NOT_CULL); - pos->flags.set(entity_position_flags::MENIAL_WORK_EXEMPTION); - pos->flags.set(entity_position_flags::SLEEP_PRETENSION); - pos->flags.set(entity_position_flags::PUNISHMENT_EXEMPTION); - pos->flags.set(entity_position_flags::ACCOUNT_EXEMPT); - pos->flags.set(entity_position_flags::DUTY_BOUND); - pos->flags.set(entity_position_flags::COLOR); - pos->flags.set(entity_position_flags::HAS_RESPONSIBILITIES); - pos->flags.set(entity_position_flags::IS_DIPLOMAT); - pos->flags.set(entity_position_flags::IS_LEADER); - // not sure what these flags do, but the game sets them for a valid diplomat - pos->flags.set(entity_position_flags::unk_12); - pos->flags.set(entity_position_flags::unk_1a); - pos->flags.set(entity_position_flags::unk_1b); - pos->name[0] = "Diplomat"; - pos->name[1] = "Diplomats"; - pos->precedence = 70; - pos->color[0] = 7; - pos->color[1] = 0; - pos->color[2] = 1; - } - // assign responsibilities - pos->responsibilities[entity_position_responsibility::MAKE_INTRODUCTIONS] = true; - pos->responsibilities[entity_position_responsibility::MAKE_PEACE_AGREEMENTS] = true; - pos->responsibilities[entity_position_responsibility::MAKE_TOPIC_AGREEMENTS] = true; - } - - // make sure the diplomat position, whether we created it or not, is set up for proper assignment - bool assign = true; - for (int j = 0; j < ent->positions.assignments.size(); j++) - { - if (ent->positions.assignments[j]->position_id == pos->id) - { - // it is - nothing more to do here - assign = false; - break; - } - } - if (assign) - { - // it isn't - set it up - df::entity_position_assignment *asn = new df::entity_position_assignment; - ent->positions.assignments.push_back(asn); - - asn->id = ent->positions.next_assignment_id++; - asn->position_id = pos->id; - asn->flags.extend(0x1F); // make room for 32 flags - asn->flags.set(0); // and set the first one - } - if (update || assign) - fixed++; - } - out.print("Fixed %d of %d civilizations to enable tree cap diplomacy.\n", fixed, checked); - return CR_OK; -} - -command_result df_fixmerchants (color_ostream &out, vector ¶meters) -{ - if (!parameters.empty()) - return CR_WRONG_USAGE; - - CoreSuspender suspend; - - int checked = 0, fixed = 0; - for (int i = 0; i < world->entities.all.size(); i++) - { - df::historical_entity *ent = world->entities.all[i]; - // only work with civilizations - ignore groups and religions - if (ent->type != 0) - continue; - // only add guild reps for merchant nobility - if (!ent->entity_raw->flags.is_set(entity_raw_flags::MERCHANT_NOBILITY)) - continue; - checked++; - - bool update = true; - df::entity_position *pos = NULL; - // see if we need to add a new position or modify an existing one - for (int j = 0; j < ent->positions.own.size(); j++) - { - pos = ent->positions.own[j]; - if (pos->responsibilities[entity_position_responsibility::TRADE]) - { - // a guild rep exists with the proper responsibilities - skip to the end - update = false; - break; - } - // Guild Representative position already exists, but has the wrong options - modify it instead of creating a new one - if (pos->code == "GUILD_REPRESENTATIVE") - break; - pos = NULL; - } - if (update) - { - // either there's no guild rep, or there is one and it's got the wrong responsibilities - if (!pos) - { - // there was no guild rep - create it - pos = new df::entity_position; - ent->positions.own.push_back(pos); - - pos->code = "GUILD_REPRESENTATIVE"; - pos->id = ent->positions.next_position_id++; - pos->flags.set(entity_position_flags::DO_NOT_CULL); - pos->flags.set(entity_position_flags::MENIAL_WORK_EXEMPTION); - pos->flags.set(entity_position_flags::SLEEP_PRETENSION); - pos->flags.set(entity_position_flags::PUNISHMENT_EXEMPTION); - pos->flags.set(entity_position_flags::ACCOUNT_EXEMPT); - pos->flags.set(entity_position_flags::DUTY_BOUND); - pos->flags.set(entity_position_flags::COLOR); - pos->flags.set(entity_position_flags::HAS_RESPONSIBILITIES); - pos->flags.set(entity_position_flags::IS_DIPLOMAT); - pos->flags.set(entity_position_flags::IS_LEADER); - // not sure what these flags do, but the game sets them for a valid guild rep - pos->flags.set(entity_position_flags::unk_12); - pos->flags.set(entity_position_flags::unk_1a); - pos->flags.set(entity_position_flags::unk_1b); - pos->name[0] = "Guild Representative"; - pos->name[1] = "Guild Representatives"; - pos->precedence = 40; - pos->color[0] = 7; - pos->color[1] = 0; - pos->color[2] = 1; - } - // assign responsibilities - pos->responsibilities[entity_position_responsibility::TRADE] = true; - } - - // make sure the guild rep position, whether we created it or not, is set up for proper assignment - bool assign = true; - for (int j = 0; j < ent->positions.assignments.size(); j++) - { - if (ent->positions.assignments[j]->position_id == pos->id) - { - // it is - nothing more to do here - assign = false; - break; - } - } - if (assign) - { - // it isn't - set it up - df::entity_position_assignment *asn = new df::entity_position_assignment; - ent->positions.assignments.push_back(asn); - - asn->id = ent->positions.next_assignment_id++; - asn->position_id = pos->id; - asn->flags.extend(0x1F); // make room for 32 flags - asn->flags.set(0); // and set the first one - } - if (update || assign) - fixed++; - } - out.print("Fixed %d of %d civilizations to enable merchant nobility.\n", fixed, checked); - return CR_OK; -} - -DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) -{ - commands.push_back(PluginCommand( - "fixdiplomats", "Add Diplomat position to Elven civilizations for tree cap diplomacy.", - df_fixdiplomats, false)); - commands.push_back(PluginCommand( - "fixmerchants", "Add Guild Representative position to Human civilizations for merchant nobility.", - df_fixmerchants, false)); - return CR_OK; -} - -DFhackCExport command_result plugin_shutdown ( color_ostream &out ) -{ - return CR_OK; -} diff --git a/scripts/fix/diplomats.lua b/scripts/fix/diplomats.lua new file mode 100644 index 000000000..b1bcfe70b --- /dev/null +++ b/scripts/fix/diplomats.lua @@ -0,0 +1,100 @@ +-- Add Elven diplomats to negotiate tree caps +--[[=begin + +fix/diplomats +============= +Adds a Diplomat position to all Elven civilizations, allowing them to negotiate +tree cutting quotas - and you to violate them and start wars. +This was vanilla behaviour until ``0.31.12``, in which the "bug" was "fixed". + +=end]] + + +function update_pos(pos, ent) + pos = df.entity_position:new() + ent.positions.own:insert('#', pos) + + pos.code = "DIPLOMAT" + pos.id = ent.positions.next_position_id + 1 + pos.flags.DO_NOT_CULL = true + pos.flags.MENIAL_WORK_EXEMPTION = true + pos.flags.SLEEP_PRETENSION = true + pos.flags.PUNISHMENT_EXEMPTION = true + pos.flags.ACCOUNT_EXEMPT = true + pos.flags.DUTY_BOUND = true + pos.flags.COLOR = true + pos.flags.HAS_RESPONSIBILITIES = true + pos.flags.IS_DIPLOMAT = true + pos.flags.IS_LEADER = true + -- not sure what these flags do, but the game sets them for a valid diplomat + pos.flags.unk_12 = true + pos.flags.unk_1a = true + pos.flags.unk_1b = true + pos.name[0] = "Diplomat" + pos.name[1] = "Diplomats" + pos.precedence = 70 + pos.color[0] = 7 + pos.color[1] = 0 + pos.color[2] = 1 + + return pos +end + + + +checked = 0 +fixed = 0 + +for _,ent in pairs(df.global.world.entities.all) do + if ent.type == 0 and ent.entity_raw.flags.TREE_CAP_DIPLOMACY then + checked = checked + 1 + + update = true + -- see if we need to add a new position or modify an existing one + for _,pos in pairs(ent.positions.own) do + if pos.responsibilities.MAKE_INTRODUCTIONS and + pos.responsibilities.MAKE_PEACE_AGREEMENTS and + pos.responsibilities.MAKE_TOPIC_AGREEMENTS then + -- a diplomat position exists with the proper responsibilities - skip to the end + update = false + break + end + -- Diplomat position already exists, but has the wrong options - modify it instead of creating a new one + if pos.code == "DIPLOMAT" then break end + pos = nil + end + if update then + -- either there's no diplomat, or there is one and it's got the wrong responsibilities + if not pos then + pos = add_guild_rep(pos, ent) + end + -- assign responsibilities + pos.responsibilities.MAKE_INTRODUCTIONS = true + pos.responsibilities.MAKE_PEACE_AGREEMENTS = true + pos.responsibilities.MAKE_TOPIC_AGREEMENTS = true + end + -- make sure the diplomat position, whether we created it or not, is set up for proper assignment + assign = true + for _,p in pairs(ent.positions.assignments) do + if p.position_id == pos.id then -- it is - nothing more to do here + assign = false + break + end + end + if assign then -- it isn't - set it up + asn = df.entity_position_assignment:new() + ent.positions.assignments:insert('#', asn); + + asn.id = ent.positions.next_assignment_id + ent.positions.next_assignment_id = asn.id + 1 + asn.position_id = pos.id + asn.flags:resize(math.max(32, #asn.flags)) -- make room for 32 flags + asn.flags[0] = true -- and set the first one + end + if update or assign then + fixed = fixed + 1 + end + end +end + +print("Enabled tree cap diplomacy for "..fixed.." of "..checked.." civilizations.") diff --git a/scripts/fix/merchants.lua b/scripts/fix/merchants.lua new file mode 100644 index 000000000..ae25ec9b2 --- /dev/null +++ b/scripts/fix/merchants.lua @@ -0,0 +1,95 @@ +-- Allow humans to make trade agreements +--[[=begin + +fix/merchants +============= +Adds the Guild Representative position to all Human civilizations, +allowing them to make trade agreements. This was the default behaviour in +``0.28.181.40d`` and earlier. + +=end]] +checked = 0 +fixed = 0 + +function add_guild_rep(pos, ent) + -- there was no guild rep - create it + pos = df.entity_position:new() + ent.positions.own:insert('#', pos) + + pos.code = "GUILD_REPRESENTATIVE" + pos.id = ent.positions.next_position_id + 1 + pos.flags.DO_NOT_CULL = true + pos.flags.MENIAL_WORK_EXEMPTION = true + pos.flags.SLEEP_PRETENSION = true + pos.flags.PUNISHMENT_EXEMPTION = true + pos.flags.ACCOUNT_EXEMPT = true + pos.flags.DUTY_BOUND = true + pos.flags.COLOR = true + pos.flags.HAS_RESPONSIBILITIES = true + pos.flags.IS_DIPLOMAT = true + pos.flags.IS_LEADER = true + -- not sure what these flags do, but the game sets them for a valid guild rep + pos.flags.unk_12 = true + pos.flags.unk_1a = true + pos.flags.unk_1b = true + pos.name[0] = "Guild Representative" + pos.name[1] = "Guild Representatives" + pos.precedence = 40 + pos.color[0] = 7 + pos.color[1] = 0 + pos.color[2] = 1 + return pos +end + + +for _,ent in pairs(df.global.world.entities.all) do + if ent.type == 0 and ent.entity_raw.flags.MERCHANT_NOBILITY then + checked = checked + 1 + + update = true + -- see if we need to add a new position or modify an existing one + for _,pos in pairs(ent.positions.own) do + if pos.responsibilities.TRADE then + -- a guild rep exists with the proper responsibilities - skip to the end + update = false + break + end + -- Guild Representative position already exists, but has the wrong options - modify it instead of creating a new one + if pos.code == "GUILD_REPRESENTATIVE" then break end + pos = nil + end + if update then + -- either there's no guild rep, or there is one and it's got the wrong responsibilities + if not pos then + pos = add_guild_rep(pos, ent) + end + -- assign responsibilities + pos.responsibilities.ESTABLISH_COLONY_TRADE_AGREEMENTS = true + end + + -- make sure the guild rep position, whether we created it or not, is set up for proper assignment + assign = true + for _,p in pairs(ent.positions.assignments) do + if p.position_id == pos.id then -- it is - nothing more to do here + assign = false + break + end + end + if assign then + -- it isn't - set it up + asn = df.entity_position_assignment:new() + ent.positions.assignments:insert('#', asn) + + asn.id = ent.positions.next_assignment_id + ent.positions.next_assignment_id = asn.id + 1 + asn.position_id = pos.id + asn.flags:resize(math.max(32, #asn.flags)) -- make room for 32 flags + asn.flags[0] = true -- and set the first one + end + if update or assign then + fixed = fixed + 1 + end + end +end + +print("Added merchant nobility for "..fixed.." of "..checked.." civilizations.") From 0d8a80c2ecf1c7af2962aa69d1da31afe8274e4d Mon Sep 17 00:00:00 2001 From: AtomicChicken Date: Wed, 20 Apr 2016 11:08:49 +0200 Subject: [PATCH 03/10] Update item-trigger.lua added proper indentation --- scripts/modtools/item-trigger.lua | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/scripts/modtools/item-trigger.lua b/scripts/modtools/item-trigger.lua index cf00ed749..1e973d6aa 100644 --- a/scripts/modtools/item-trigger.lua +++ b/scripts/modtools/item-trigger.lua @@ -65,11 +65,12 @@ function processTrigger(command) end function getitemType(item) -if item:getSubtype() ~= -1 then -itemType = dfhack.items.getSubtypeDef(item:getType(),item:getSubtype()).id -else itemType = df.item_type[item:getType()] -end -return itemType + if item:getSubtype() ~= -1 then + itemType = dfhack.items.getSubtypeDef(item:getType(),item:getSubtype()).id + else + itemType = df.item_type[item:getType()] + end + return itemType end function handler(table) From 68267d2ab3cac1b70550f364d9a11a6abf8fa3f9 Mon Sep 17 00:00:00 2001 From: AtomicChicken Date: Wed, 20 Apr 2016 12:05:48 +0200 Subject: [PATCH 04/10] Update item-trigger.lua whitespace removed --- scripts/modtools/item-trigger.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/modtools/item-trigger.lua b/scripts/modtools/item-trigger.lua index 1e973d6aa..378937961 100644 --- a/scripts/modtools/item-trigger.lua +++ b/scripts/modtools/item-trigger.lua @@ -65,10 +65,10 @@ function processTrigger(command) end function getitemType(item) - if item:getSubtype() ~= -1 then + if item:getSubtype() ~= -1 then itemType = dfhack.items.getSubtypeDef(item:getType(),item:getSubtype()).id - else - itemType = df.item_type[item:getType()] + else + itemType = df.item_type[item:getType()] end return itemType end From 3ee829f05b8876362baa446233c6340bc2df405f Mon Sep 17 00:00:00 2001 From: Warmist Date: Sat, 30 Apr 2016 22:10:01 +0300 Subject: [PATCH 05/10] Allow to insert ints and other simple types. Also allow inserting of same base type as the container. Also simplify it a bit. --- scripts/gui/gm-editor.lua | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/scripts/gui/gm-editor.lua b/scripts/gui/gm-editor.lua index 9012cbd55..c8cdf5d3d 100644 --- a/scripts/gui/gm-editor.lua +++ b/scripts/gui/gm-editor.lua @@ -211,22 +211,26 @@ function GmEditorUi:find_id() end function GmEditorUi:insertNew(typename) local tp=typename - if typename== nil then - dialog.showInputPrompt("Class type","Input class type:",COLOR_WHITE,"",self:callback("insertNew")) - return - end - local ntype=df[tp] - if ntype== nil then - dialog.showMessage("Error!","Type '"..tp.." not found",COLOR_LIGHTRED) + if typename == nil then + dialog.showInputPrompt("Class type","Input class type or leave empty for auto and '*' for new ptr type auto:",COLOR_WHITE,"",self:callback("insertNew")) return end local trg=self:currentTarget() if trg.target and trg.target._kind and trg.target._kind=="container" then - local thing=ntype:new() - dfhack.call_with_finalizer(1,false,df.delete,thing,function (tscreen,target,to_insert) - target:insert("#",to_insert); tscreen:updateTarget(true,true);end,self,trg.target,thing) - + if tp == "" then + trg.target:resize(#trg.target+1) + elseif tp== "*" then + trg.target:insert("#",{new=true}) + else + local ntype=df[tp] + if ntype== nil then + dialog.showMessage("Error!","Type '"..tp.." not found",COLOR_RED) + return + end + trg.target:insert("#",{new=ntype}) + end + self:updateTarget(true,true) end end function GmEditorUi:deleteSelected(key) From 523638a89912f493f2740133b028d78b718c9284 Mon Sep 17 00:00:00 2001 From: Warmist Date: Sat, 30 Apr 2016 22:13:38 +0300 Subject: [PATCH 06/10] Add news entry --- NEWS.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS.rst b/NEWS.rst index 3bf4c4276..ddefbf985 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -33,6 +33,10 @@ Changelog DFHack future ============= +Lua +--- +- `gui/gm-editor` it's now possible to insert default types to containers. For primitive types leave the type entry empty, for references use ``*``. + DFHack 0.42.06-r1 ================= From a5a61ce6b0ef2b97eb04c338888e60f774eb5d86 Mon Sep 17 00:00:00 2001 From: Warmist Date: Sat, 30 Apr 2016 23:01:48 +0300 Subject: [PATCH 07/10] I think i got the perfect message now. --- scripts/gui/gm-editor.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/gui/gm-editor.lua b/scripts/gui/gm-editor.lua index c8cdf5d3d..9b03ba279 100644 --- a/scripts/gui/gm-editor.lua +++ b/scripts/gui/gm-editor.lua @@ -212,7 +212,7 @@ end function GmEditorUi:insertNew(typename) local tp=typename if typename == nil then - dialog.showInputPrompt("Class type","Input class type or leave empty for auto and '*' for new ptr type auto:",COLOR_WHITE,"",self:callback("insertNew")) + dialog.showInputPrompt("Class type","You can:\n * Enter type name (without 'df.')\n * Leave empty for default type and 'nil' value\n * Enter '*' for default type and 'new' constructed pointer value",COLOR_WHITE,"",self:callback("insertNew")) return end From ce3c9d06a00e3b6102f0b022173b37553fdd9b44 Mon Sep 17 00:00:00 2001 From: Matsor Browncoat Date: Sun, 1 May 2016 19:50:03 +0200 Subject: [PATCH 08/10] Fixed quality in gui/create-item with -multi. When -multi option is selected, gui/create-item doesn't set quality neither on stackable nor unstackable items. Fixed this quirk. No refactoring or optimizations. Just moved a variable and added code inside the createItem function. --- scripts/gui/create-item.lua | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/gui/create-item.lua b/scripts/gui/create-item.lua index d22f68904..a2c38247a 100644 --- a/scripts/gui/create-item.lua +++ b/scripts/gui/create-item.lua @@ -117,7 +117,7 @@ local function getMatFilter(itemtype) return itemTypes[df.item_type[itemtype]] or getRestrictiveMatFilter(itemtype) end -local function createItem(mat,itemType,quality,creator,description) +local function createItem(mat,itemType,quality,creator,description,amount) local item=df.item.find(dfhack.items.createItem(itemType[1], itemType[2], mat[1], mat[2], creator)) assert(item, 'failed to create item') quality = math.max(0, math.min(5, quality - 1)) @@ -125,6 +125,9 @@ local function createItem(mat,itemType,quality,creator,description) if df.item_type[itemType[1]]=='SLAB' then item.description=description end + if tonumber(amount) > 1 then + item:setStackSize(amount) + end end local function qualityTable() @@ -207,11 +210,10 @@ function hackWish(unit) if not amountok then return end if mattype and itemtype then if df.item_type.attrs[itemtype].is_stackable then - local proper_item=df.item.find(dfhack.items.createItem(itemtype, itemsubtype, mattype, matindex, unit)) - proper_item:setStackSize(amount) + createItem({mattype,matindex},{itemtype,itemsubtype},quality,unit,description,amount) else for i=1,amount do - dfhack.items.createItem(itemtype, itemsubtype, mattype, matindex, unit) + createItem({mattype,matindex},{itemtype,itemsubtype},quality,unit,description,1) end end return true @@ -219,7 +221,7 @@ function hackWish(unit) return false else if mattype and itemtype then - createItem({mattype,matindex},{itemtype,itemsubtype},quality,unit,description) + createItem({mattype,matindex},{itemtype,itemsubtype},quality,unit,description,1) return true end return false From dde7d151b73144d812f28894442b2e73552256dc Mon Sep 17 00:00:00 2001 From: Warmist Date: Sun, 8 May 2016 09:39:28 +0300 Subject: [PATCH 09/10] Fix few bugs with fix/diplomats.lua and fix/merchants.lua --- scripts/fix/diplomats.lua | 38 ++++++++++++++++++++++---------------- scripts/fix/merchants.lua | 39 ++++++++++++++++++++++++--------------- 2 files changed, 46 insertions(+), 31 deletions(-) diff --git a/scripts/fix/diplomats.lua b/scripts/fix/diplomats.lua index b1bcfe70b..5c2138f65 100644 --- a/scripts/fix/diplomats.lua +++ b/scripts/fix/diplomats.lua @@ -10,12 +10,14 @@ This was vanilla behaviour until ``0.31.12``, in which the "bug" was "fixed". =end]] -function update_pos(pos, ent) - pos = df.entity_position:new() +function update_pos(ent) + local pos = df.entity_position:new() ent.positions.own:insert('#', pos) pos.code = "DIPLOMAT" pos.id = ent.positions.next_position_id + 1 + ent.positions.next_position_id = ent.positions.next_position_id + 1 + pos.flags.DO_NOT_CULL = true pos.flags.MENIAL_WORK_EXEMPTION = true pos.flags.SLEEP_PRETENSION = true @@ -42,14 +44,15 @@ end -checked = 0 -fixed = 0 +local checked = 0 +local fixed = 0 for _,ent in pairs(df.global.world.entities.all) do - if ent.type == 0 and ent.entity_raw.flags.TREE_CAP_DIPLOMACY then + if ent.type == df.historical_entity_type.Civilization and ent.entity_raw.flags.TREE_CAP_DIPLOMACY then checked = checked + 1 update = true + local found_position -- see if we need to add a new position or modify an existing one for _,pos in pairs(ent.positions.own) do if pos.responsibilities.MAKE_INTRODUCTIONS and @@ -57,37 +60,40 @@ for _,ent in pairs(df.global.world.entities.all) do pos.responsibilities.MAKE_TOPIC_AGREEMENTS then -- a diplomat position exists with the proper responsibilities - skip to the end update = false + found_position=pos break end -- Diplomat position already exists, but has the wrong options - modify it instead of creating a new one - if pos.code == "DIPLOMAT" then break end - pos = nil + if pos.code == "DIPLOMAT" then + found_position=pos + break + end end if update then -- either there's no diplomat, or there is one and it's got the wrong responsibilities - if not pos then - pos = add_guild_rep(pos, ent) + if not found_position then + found_position = add_guild_rep( ent ) end -- assign responsibilities - pos.responsibilities.MAKE_INTRODUCTIONS = true - pos.responsibilities.MAKE_PEACE_AGREEMENTS = true - pos.responsibilities.MAKE_TOPIC_AGREEMENTS = true + found_position.responsibilities.MAKE_INTRODUCTIONS = true + found_position.responsibilities.MAKE_PEACE_AGREEMENTS = true + found_position.responsibilities.MAKE_TOPIC_AGREEMENTS = true end -- make sure the diplomat position, whether we created it or not, is set up for proper assignment - assign = true + local assign = true for _,p in pairs(ent.positions.assignments) do - if p.position_id == pos.id then -- it is - nothing more to do here + if p.position_id == found_position.id then -- it is - nothing more to do here assign = false break end end if assign then -- it isn't - set it up - asn = df.entity_position_assignment:new() + local asn = df.entity_position_assignment:new() ent.positions.assignments:insert('#', asn); asn.id = ent.positions.next_assignment_id ent.positions.next_assignment_id = asn.id + 1 - asn.position_id = pos.id + asn.position_id = found_position.id asn.flags:resize(math.max(32, #asn.flags)) -- make room for 32 flags asn.flags[0] = true -- and set the first one end diff --git a/scripts/fix/merchants.lua b/scripts/fix/merchants.lua index ae25ec9b2..09a158f48 100644 --- a/scripts/fix/merchants.lua +++ b/scripts/fix/merchants.lua @@ -8,16 +8,17 @@ allowing them to make trade agreements. This was the default behaviour in ``0.28.181.40d`` and earlier. =end]] -checked = 0 -fixed = 0 -function add_guild_rep(pos, ent) + +function add_guild_rep(ent) -- there was no guild rep - create it - pos = df.entity_position:new() + local pos = df.entity_position:new() ent.positions.own:insert('#', pos) pos.code = "GUILD_REPRESENTATIVE" pos.id = ent.positions.next_position_id + 1 + ent.positions.next_position_id = ent.positions.next_position_id + 1 + pos.flags.DO_NOT_CULL = true pos.flags.MENIAL_WORK_EXEMPTION = true pos.flags.SLEEP_PRETENSION = true @@ -38,51 +39,59 @@ function add_guild_rep(pos, ent) pos.color[0] = 7 pos.color[1] = 0 pos.color[2] = 1 + return pos end +local checked = 0 +local fixed = 0 for _,ent in pairs(df.global.world.entities.all) do - if ent.type == 0 and ent.entity_raw.flags.MERCHANT_NOBILITY then + if ent.type == df.historical_entity_type.Civilization and ent.entity_raw.flags.MERCHANT_NOBILITY then checked = checked + 1 update = true -- see if we need to add a new position or modify an existing one + local found_position for _,pos in pairs(ent.positions.own) do - if pos.responsibilities.TRADE then + if pos.responsibilities.TRADE and pos.responsibilities.ESTABLISH_COLONY_TRADE_AGREEMENTS then -- a guild rep exists with the proper responsibilities - skip to the end update = false + found_position=pos break end -- Guild Representative position already exists, but has the wrong options - modify it instead of creating a new one - if pos.code == "GUILD_REPRESENTATIVE" then break end - pos = nil + if pos.code == "GUILD_REPRESENTATIVE" then + found_position=pos + break + end end if update then -- either there's no guild rep, or there is one and it's got the wrong responsibilities - if not pos then - pos = add_guild_rep(pos, ent) + if not found_position then + found_position = add_guild_rep(ent) end -- assign responsibilities - pos.responsibilities.ESTABLISH_COLONY_TRADE_AGREEMENTS = true + found_position.responsibilities.ESTABLISH_COLONY_TRADE_AGREEMENTS = true + found_position.responsibilities.TRADE=true end -- make sure the guild rep position, whether we created it or not, is set up for proper assignment - assign = true + local assign = true for _,p in pairs(ent.positions.assignments) do - if p.position_id == pos.id then -- it is - nothing more to do here + if p.position_id == found_position.id then -- it is - nothing more to do here assign = false break end end if assign then -- it isn't - set it up - asn = df.entity_position_assignment:new() + local asn = df.entity_position_assignment:new() ent.positions.assignments:insert('#', asn) asn.id = ent.positions.next_assignment_id ent.positions.next_assignment_id = asn.id + 1 - asn.position_id = pos.id + asn.position_id = found_position.id asn.flags:resize(math.max(32, #asn.flags)) -- make room for 32 flags asn.flags[0] = true -- and set the first one end From c283e85fd559794d5f13bd28035c948a7029761e Mon Sep 17 00:00:00 2001 From: Warmist Date: Sun, 8 May 2016 12:10:36 +0300 Subject: [PATCH 10/10] Fix whitespace --- scripts/fix/diplomats.lua | 4 ++-- scripts/fix/merchants.lua | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/fix/diplomats.lua b/scripts/fix/diplomats.lua index 5c2138f65..4e8c6daf7 100644 --- a/scripts/fix/diplomats.lua +++ b/scripts/fix/diplomats.lua @@ -64,9 +64,9 @@ for _,ent in pairs(df.global.world.entities.all) do break end -- Diplomat position already exists, but has the wrong options - modify it instead of creating a new one - if pos.code == "DIPLOMAT" then + if pos.code == "DIPLOMAT" then found_position=pos - break + break end end if update then diff --git a/scripts/fix/merchants.lua b/scripts/fix/merchants.lua index 09a158f48..ae3ef4233 100644 --- a/scripts/fix/merchants.lua +++ b/scripts/fix/merchants.lua @@ -61,9 +61,9 @@ for _,ent in pairs(df.global.world.entities.all) do break end -- Guild Representative position already exists, but has the wrong options - modify it instead of creating a new one - if pos.code == "GUILD_REPRESENTATIVE" then + if pos.code == "GUILD_REPRESENTATIVE" then found_position=pos - break + break end end if update then