Skip to content

Commit

Permalink
Replace fixdiplomats, fixmerchants with scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
PeridexisErrant committed Apr 20, 2016
1 parent 50f2851 commit acac839
Show file tree
Hide file tree
Showing 6 changed files with 197 additions and 257 deletions.
2 changes: 2 additions & 0 deletions NEWS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 0 additions & 12 deletions docs/Plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
244 changes: 0 additions & 244 deletions plugins/fixpositions.cpp

This file was deleted.

100 changes: 100 additions & 0 deletions scripts/fix/diplomats.lua
Original file line number Diff line number Diff line change
@@ -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.")
Loading

0 comments on commit acac839

Please sign in to comment.