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

Method removeFromSquad

library/modules/Military.cpp:478–534  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

476}
477
478bool Military::removeFromSquad(int32_t unit_id)
479{
480 // based on unitst::remove_squad_info
481 df::unit *unit = df::unit::find(unit_id);
482 if (unit == nullptr || unit->military.squad_id == -1 || unit->military.squad_position == -1)
483 return false;
484
485 // abort individual training
486 if (unit->individual_drills.size())
487 unit->flags3.bits.verify_personal_training = true;
488
489 int32_t squad_id = unit->military.squad_id;
490 int32_t squad_pos = unit->military.squad_position;
491
492 df::squad* squad = df::squad::find(squad_id);
493
494 if (squad)
495 {
496 df::squad_position* pos = vector_get(squad->positions, squad_pos);
497 if (pos)
498 {
499 // based on unitst::remove_squad_activity_info
500 FOR_ENUM_ITEMS(squad_event_type, i)
501 {
502 auto activity_entry = df::activity_entry::find(pos->activities[i]);
503 if (activity_entry)
504 {
505 auto activity_event = binsearch_in_vector(activity_entry->events, &df::activity_event::event_id, pos->events[i]);
506 if (activity_event)
507 {
508 activity_event->removeParticipant(unit->hist_figure_id, unit->id, false);
509 pos->activities[i] = -1;
510 pos->events[i] = -1;
511 }
512 }
513 }
514
515 // remove from squad position
516 pos->occupant = -1;
517 }
518 }
519 // remove from unit information
520 unit->military.squad_id = -1;
521 unit->military.squad_position = -1;
522
523 // remove entity squad link
524 df::historical_figure* hf = df::historical_figure::find(unit->hist_figure_id);
525 if (hf == nullptr || squad == nullptr)
526 return false;
527
528 if (squad_pos == 0) // is unit a commander?
529 remove_officer_entity_link(hf, squad);
530 else
531 remove_soldier_entity_link(hf, squad);
532
533 return true;
534}

Callers

nothing calls this directly

Calls 5

vector_getFunction · 0.85
findFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected