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.ui.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 HI=df.global.ui.civ_id
local EN=df.global.world.entities.all[HI]
local HP=df.global.ui.group_id
if v.hist_figure_id==-1 and v.civ_id==df.global.ui.civ_id then
createNemesis(v,HI,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.ui.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.ui.civ_id and v.population_id==-1 and q.entity_id~=df.global.ui.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.ui.group_id
HFN[v.hist_figure_id].entity_links[c].link_strength=100
end
end
end
end
ok so spent a deep amount of time trying to solve the animal token sapient migrants not having labors in a fort with this.
mostly solving the historical figure and nemesis issue of the previous script with dipping into create-unit's script for functions.
so now this script will allow one to play around with the animal tokens with sapient beings and build a multi-culture fort... also a side effect of this was buying new members for the fort.
tested this with my 'normal cat main civ race, ALL demon secondary citizens' entity the infurn which gives off an weird feeling of starting with one or two workers and a bunch of cats to slowly buying and building a community made up of different types of demons and their cat traders.