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

Method setOwner

library/modules/Buildings.cpp:325–366  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

323}
324
325bool Buildings::setOwner(df::building_civzonest *bld, df::unit *unit)
326{
327 CHECK_NULL_POINTER(bld);
328
329 auto unit_id = unit ? unit->id : -1;
330
331 if (bld->assigned_unit_id == unit_id)
332 return true;
333
334 if (bld->assigned_unit_id != -1)
335 {
336 if (auto old_unit = df::unit::find(bld->assigned_unit_id))
337 {
338 auto& blist = old_unit->owned_buildings;
339 vector_erase_at(blist, linear_index(blist, bld));
340
341 if (auto spouse = df::unit::find(old_unit->relationship_ids[df::unit_relationship_type::Spouse]))
342 {
343 auto& blist = spouse->owned_buildings;
344 vector_erase_at(blist, linear_index(blist, bld));
345 }
346 }
347 }
348
349 bld->assigned_unit_id = unit_id;
350
351 if (unit)
352 {
353 unit->owned_buildings.push_back(bld);
354
355 if (auto spouse = df::unit::find(unit->relationship_ids[df::unit_relationship_type::Spouse]))
356 {
357 auto &blist = spouse->owned_buildings;
358 if (bld->canUseSpouseRoom() && linear_index(blist, bld) < 0)
359 blist.push_back(bld);
360 }
361 }
362
363 Units::get_cached_unit_by_global_id(unit_id, bld->owner_unit_cached_index);
364
365 return true;
366}
367
368df::building *Buildings::findAtTile(df::coord pos)
369{

Callers

nothing calls this directly

Calls 3

vector_erase_atFunction · 0.85
findFunction · 0.50
linear_indexFunction · 0.50

Tested by

no test coverage detected