Okay, I've made a bit of progress on these population links, but mostly for units that are associated with an official "map feature" (such as a river, cavern layer, or deep special tube). "Not from a map feature" has its own population indexes that I can't find. Caves might be a third system.
When it comes to the steep DF learning curve, things go deeper than just the UI. It's turtles scaling learning cliffs
all the way down.
We start with a unit
u that is associated with some map feature. You can get its associated region, feature and index (datatype
world_population_ref) from
u.animal.population.
region_x
region_y
feature_idx
cave_id
population_idxThat
feature_idx should appear
once as a value in the
df.global.world.features.feature_local_idx array.
* You want the index
f_i that has
feature_idx as its value. You'll also need the population index directly from the unit.
df.global.world.features.map_features[f_i].feature.population[u.animal.population.population_idx] will have a
world_population record for your creature.
So far so good. We could certainly augment
create-unit.lua to append a new item into this feature's population list (with a bit of complication when a feature spans more than one depth level). The real problem is that there is a flat array in
df.global.world.populations of
local_population records, each of which has a
world_population_ref in it. I have no idea how that list gets built, where its next_index hides, if feature-associated critters belong there, etc. No combination of flags on
create-unit seems to push its creature onto
df.global.world.populations, but I've confirmed that any non-feature-related naturally occurring critters on the map are there. I can't find anything that stores the associated index in the
df.global.world.populations array.
Some arrays in DF's innards are self-maintaining, others need a global variable to hold the next index. Appending a record onto
df.global.world.populations can be done when spawning non-feature-related critters, but it seems like something somewhere ought to point to that record. (In any case, the list should be scanned in case the spawned creature should be part of an existing population.)
Note that the spawned creature behaves just fine if the
region_x and
region_y are on the map, even with -1 for the
population_idx. A creature spawned with the marauder tag generated its own MarauderMill idle activity, attained a name when it killed someone, and everything. I just don't know if a dangling
population_idx of -1 is going to cause problems later.
function wild(uid)
local u = df.unit.find(uid)
local caste=df.creature_raw.find(u.race).caste[u.caste]
if not(caste.flags.CAN_SPEAK and caste.flags.CAN_LEARN) then
u.animal.population.region_x = df.global.world.world_data.active_site[0].pos.x
u.animal.population.region_y = df.global.world.world_data.active_site[0].pos.y
u.animal.population.unk_28 = -1
u.animal.population.population_idx = -1 -- Eventually want to make a real population
u.animal.population.depth = -1 -- Eventually this should be a parameter
u.animal.leave_countdown = 99999
u.flags2.roaming_wilderness_population_source = true
u.flags2.roaming_wilderness_population_source_not_a_map_feature = true
-- region = df.global.world.map.map_blocks[df.global.world.map.x_count_block*x+y]
end
end
* Items with a -1 here will have a valid entry in the
.feature_global_idx array instead. In this case I think you're looking for
u.animal.population.cave_id as the value, but I didn't get a chance to verify that.