Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makeown-plus #1212

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
53 changes: 51 additions & 2 deletions makeown.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

local utils = require('utils')

-- List of professions to convert From-To
local convert_professions = {}
convert_professions[df.profession.MERCHANT] = df.profession.TRADER
convert_professions[df.profession.THIEF] = df.profession.STANDARD
Crystalwarrior marked this conversation as resolved.
Show resolved Hide resolved

local function get_translation(race_id)
local race_name = df.global.world.raws.creatures.all[race_id].creature_id
for _,translation in ipairs(df.global.world.raws.language.translations) do
Expand Down Expand Up @@ -76,8 +81,41 @@ local function fix_unit(unit)

unit.civ_id = df.global.plotinfo.civ_id;

if unit.profession == df.profession.MERCHANT then unit.profession = df.profession.TRADER end
if unit.profession2 == df.profession.MERCHANT then unit.profession2 = df.profession.TRADER end
if convert_professions[unit.profession] then unit.profession2 = df.profession.STANDARD end
if convert_professions[unit.profession2] then unit.profession2 = df.profession.STANDARD end
Crystalwarrior marked this conversation as resolved.
Show resolved Hide resolved
end

local function fix_army(unit)
-- Disassociate them from their army controller
if unit.enemy.army_controller then
myk002 marked this conversation as resolved.
Show resolved Hide resolved
if unit.enemy.army_controller.commander_hf == unit.hist_figure_id then
unit.enemy.army_controller.commander_hf = -1
end
unit.enemy.army_controller_id = -1
unit.enemy.army_controller = nil
end

if unit.enemy.enemy_status_slot ~= -1 then
local status_cache = df.global.world.enemy_status_cache
local status_slot = unit.enemy.enemy_status_slot

unit.enemy.enemy_status_slot = -1
status_cache.slot_used[status_slot] = false

for index, _ in pairs(status_cache.rel_map[status_slot]) do
status_cache.rel_map[status_slot][index] = -1
end

for index, _ in pairs(status_cache.rel_map) do
status_cache.rel_map[index][status_slot] = -1
end

-- TODO: what if there were status slots taken above status_slot?
-- does everything need to be moved down by one?
if status_cache.next_slot > status_slot then
status_cache.next_slot = status_slot
end
end
myk002 marked this conversation as resolved.
Show resolved Hide resolved
end

local function add_to_entity(hf, eid)
Expand Down Expand Up @@ -193,6 +231,14 @@ local function fix_histfig(unit)
entity_link(hf, eid, true, false, k)
::continue::
end
-- If you're makeown-ing an enemy of your civilization or group, people will feel vengeful without this
if df.histfig_entity_link_enemyst:is_instance(el) then
local eid = el.entity_id
if eid == civ_id or eid == group_id then
hf.entity_links:erase(k)
el:delete()
end
end
end

-- add them to our civ/site if they aren't already
Expand All @@ -205,6 +251,7 @@ function make_own(unit)
dfhack.units.makeown(unit)

fix_unit(unit)
fix_army(unit)
fix_histfig(unit)
fix_clothing_ownership(unit)

Expand All @@ -215,6 +262,8 @@ function make_own(unit)
else
unit.flags1.tame = true
unit.training_level = df.animal_training_level.Domesticated
-- No more "vengeful" spam when civilizing Giants!
unit.enemy.caste_flags.LARGE_PREDATOR = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this "stick"? I thought unit.enemy.caste_flags gets overwritten with actual race caste flags (plus syndrome flags) periodically

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yah it doesn't stick, might as well remove it

end
end

Expand Down