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

Function ListUnits

library/RemoteTools.cpp:571–612  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

569}
570
571static command_result ListUnits(color_ostream &stream,
572 const ListUnitsIn *in, ListUnitsOut *out)
573{
574 auto mask = in->has_mask() ? &in->mask() : NULL;
575
576 if (in->id_list_size() > 0)
577 {
578 for (int i = 0; i < in->id_list_size(); i++)
579 {
580 auto unit = df::unit::find(in->id_list(i));
581 if (unit)
582 describeUnit(out->add_value(), unit, mask);
583 }
584 }
585
586 if (in->scan_all())
587 {
588 auto &vec = df::unit::get_vector();
589
590 for (size_t i = 0; i < vec.size(); i++)
591 {
592 auto unit = vec[i];
593
594 if (!Units::isActive(unit) && !Units::isKilled(unit))
595 continue;
596 if (in->has_race() && unit->race != in->race())
597 continue;
598 if (in->has_civ_id() && unit->civ_id != in->civ_id())
599 continue;
600 if (in->has_dead() && Units::isDead(unit) != in->dead())
601 continue;
602 if (in->has_alive() && Units::isAlive(unit) != in->alive())
603 continue;
604 if (in->has_sane() && Units::isSane(unit) != in->sane())
605 continue;
606
607 describeUnit(out->add_value(), unit, mask);
608 }
609 }
610
611 return out->value_size() ? CR_OK : CR_NOT_FOUND;
612}
613
614static command_result ListSquads(color_ostream &stream,
615 const ListSquadsIn *in, ListSquadsOut *out)

Callers

nothing calls this directly

Calls 4

add_valueMethod · 0.80
value_sizeMethod · 0.80
findFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected