--old old script made to update the hist_fig_less migrants and second citizens gain from messing with animal entity tokens
--this script uses code from dfhack's spawn unit code mostly the histfig data stuff and I guess the nemesis record stuff looking at it now.
-- this is a run to patch citizens script and not automated
-- uhh stability warning on what it does to histfigs and any future issues that comes from it down the line.
ui=df.global.plotinfo
local function allocateNewChunk(hist_entity)
hist_entity.save_file_id = df.global.unit_chunk_next_id
df.global.unit_chunk_next_id = df.global.unit_chunk_next_id+1
hist_entity.next_member_idx = 0
print("allocating chunk:",hist_entity.save_file_id)
end
local function allocateIds(nemesis_record,hist_entity)
if hist_entity.next_member_idx == 100 then
allocateNewChunk(hist_entity)
end
nemesis_record.save_file_id = hist_entity.save_file_id
nemesis_record.member_idx = hist_entity.next_member_idx
hist_entity.next_member_idx = hist_entity.next_member_idx+1
end
function createFigure(unit,he,he_group)
local hf = df.historical_figure:new()
hf.id = df.global.hist_figure_next_id
df.global.hist_figure_next_id = df.global.hist_figure_next_id+1
hf.unit_id = unit.id
hf.nemesis_id = -1
hf.race = unit.race
hf.caste = unit.caste
hf.profession = unit.profession
hf.sex = unit.sex
hf.name:assign(unit.name)
hf.appeared_year = df.global.cur_year
hf.born_year = unit.birth_year
hf.born_seconds = unit.birth_time
hf.curse_year = unit.curse_year
hf.curse_seconds = unit.curse_time
hf.birth_year_bias = unit.birth_year_bias
hf.birth_time_bias = unit.birth_time_bias
hf.old_year = unit.old_year
hf.old_seconds = unit.old_time
hf.died_year = -1
hf.died_seconds = -1
hf.civ_id = unit.civ_id
hf.population_id = unit.population_id
hf.breed_id = -1
hf.cultural_identity = unit.cultural_identity
hf.family_head_id = -1
df.global.world.history.figures:insert("#", hf)
hf.info = df.historical_figure_info:new()
hf.info.whereabouts = df.historical_figure_info.T_whereabouts:new()
hf.info.whereabouts.death_condition_parameter_1 = -1
hf.info.whereabouts.death_condition_parameter_2 = -1
-- set values that seem related to state and do event
--change_state(hf, dfg.plotinfo.site_id, region_pos)
--let's skip skills for now
--local skills = df.historical_figure_info.T_skills:new() -- skills snap shot
-- ...
-- note that innate skills are automaticaly set by DF
hf.info.skills = {new=true}
if he then
he.histfig_ids:insert('#', hf.id)
he.hist_figures:insert('#', hf)
hf.entity_links:insert("#",{new=df.histfig_entity_link_memberst,entity_id=unit.civ_id,link_strength=100})
--add entity event
local hf_event_id = df.global.hist_event_next_id
df.global.hist_event_next_id = df.global.hist_event_next_id+1
df.global.world.history.events:insert("#",{new=df.history_event_add_hf_entity_linkst,year=unit.birth_year,
seconds=unit.birth_time,id=hf_event_id,civ=hf.civ_id,histfig=hf.id,link_type=0})
end
if he_group and he_group ~= he then
he_group.histfig_ids:insert('#', hf.id)
he_group.hist_figures:insert('#', hf)
hf.entity_links:insert("#",{new=df.histfig_entity_link_memberst,entity_id=he_group.id,link_strength=100})
end
local soul = unit.status.current_soul
if soul then
hf.orientation_flags:assign(soul.orientation_flags)
end
unit.flags1.important_historical_figure = true
unit.flags2.important_historical_figure = true
unit.hist_figure_id = hf.id
unit.hist_figure_id2 = hf.id
return hf
end
function createNemesis(unit,civ_id,group_id)
local id = df.global.nemesis_next_id
local nem = df.nemesis_record:new()
nem.id = id
nem.unit_id = unit.id
nem.unit = unit
nem.flags:resize(31)
nem.unk10 = -1
nem.unk11 = -1
nem.unk12 = -1
df.global.world.nemesis.all:insert("#",nem)
df.global.nemesis_next_id = id+1
unit.general_refs:insert("#",{new = df.general_ref_is_nemesisst, nemesis_id = id})
nem.save_file_id = -1
local he
if civ_id and civ_id ~= -1 then
he = df.historical_entity.find(civ_id)
he.nemesis_ids:insert("#",id)
he.nemesis:insert("#",nem)
allocateIds(nem,he)
end
local he_group
if group_id and group_id ~= -1 then
he_group = df.historical_entity.find(group_id)
end
if he_group then
he_group.nemesis_ids:insert("#",id)
he_group.nemesis:insert("#",nem)
end
nem.figure = unit.hist_figure_id ~= -1 and df.historical_figure.find(unit.hist_figure_id) or createFigure(unit,he,he_group) -- the histfig check is there just in case this function is called by another script to create nemesis data for a historical figure which somehow lacks it
nem.figure.nemesis_id = id
return nem
end
function sigh()
for k,v in pairs(df.global.world.units.active) do
local HF=df.global.world.history.figures
local HO=df.global.plotinfo.civ_id
local EN=df.global.world.entities.all[HO]
local HP=df.global.plotinfo.group_id
if v.hist_figure_id==-1 and v.civ_id==df.global.plotinfo.civ_id then
createNemesis(v,HO,HP)
--createFigure(v,EN,HP)
print(k)
end
end
end
for k,v in pairs(df.global.world.units.active) do
local HFN=df.global.world.history.figures
local HN=df.global.plotinfo.civ_id
sigh()
if v.hist_figure_id==-1 then break else
for c,q in pairs(HFN[v.hist_figure_id].entity_links) do
if q.entity_id==df.global.plotinfo.civ_id and v.population_id==-1 and q.entity_id~=df.global.plotinfo.group_id then
print(v.hist_figure_id)
HFN[v.hist_figure_id].entity_links:insert("#",{new=df.histfig_entity_link_memberst})
HFN[v.hist_figure_id].entity_links[c].entity_id=df.global.plotinfo.group_id
HFN[v.hist_figure_id].entity_links[c].link_strength=100
end
end
end
end
ok so this script is an update to the 3 year old version that probably doesn't work well in DF50 due to the ui to plotinfo change said script also been updated to include uhh 3 year old spawn unit coding for making histfigs and nemesis records as that's a good source to draw from.
this is mostly a modder tool to help with sapient historical-figureless citizen scenario that animal entity tokens do with multi-cultural forts. This script for df50 mostly gives them noble access and means to join squads as I think df50 already gives them labor access.
should note this will not help the 'oops main civ is cats and now no one a noble' issue that one would require a separate custom script for appointing a civ unit to a noble position.
local contain={}
function unretirewagon(curx,cury,curz)
for de,oe in pairs(df.global.world.buildings.other.WAGON) do
if oe.name == 'Nomad' then
local vector=df.global.world.items.all -- load all items
for i = 0, #vector-1 do -- look into all items offsets
local curpos=vector[i].pos --get its coordinates
local cx=curpos.x
local cy=curpos.y
local cz=curpos.z
if cx==oe.centerx and cy==oe.centery and cz==oe.z then --compare them
dfhack.items.moveToBuilding(vector[i],oe) --return index
end
end
end
end
end
unretirewagon()
here's another wagon script that stores items directly in the center of the wagon back into the wagon for events of retiring and unretiring while nomading, it works with void forts and normal stationary forts ... as so long you name the wagon 'Nomad' ... or delete the if line of code checking if a wagon is named nomad.