MCPcopy Create free account
hub / github.com/DFHack/dfhack / delete_assigned_unit_links

Function delete_assigned_unit_links

library/modules/Buildings.cpp:1284–1298  ·  view source on GitHub ↗

unit owned_building pointers are known-bad as of 50.05 and dangle on zone delete do not use anything that touches anything other than the pointer value this means also that if dwarf fortress reuses a memory allocation, we will end up with duplicates this vector is also not sorted by id it also turns out that multiple units eg (solely?) spouses can point to one room

Source from the content-addressed store, hash-verified

1282//this vector is also not sorted by id
1283//it also turns out that multiple units eg (solely?) spouses can point to one room
1284static void delete_assigned_unit_links(df::building_civzonest* zone)
1285{
1286 //not clear if this is always true
1287 /*if (zone->assigned_unit_id == -1)
1288 return;*/
1289
1290 for (df::unit* unit : world->units.active)
1291 {
1292 for (int i=(int)unit->owned_buildings.size() - 1; i >= 0; i--)
1293 {
1294 if (unit->owned_buildings[i] == zone)
1295 unit->owned_buildings.erase(unit->owned_buildings.begin() + i);
1296 }
1297 }
1298}
1299
1300static void on_civzone_delete(df::building_civzonest* civzone)
1301{

Callers 1

on_civzone_deleteFunction · 0.85

Calls 3

sizeMethod · 0.45
eraseMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected