void MsnPkgDlg::DrawPackages() { if (mission) { if (pkg_list) { pkg_list->ClearItems(); int i = 0; int elem_index = 0; ListIter<MissionElement> elem = mission->GetElements(); while (++elem) { // display this element? if (elem->GetIFF() == mission->Team() && !elem->IsSquadron() && elem->Region() == mission->GetRegion() && elem->GetDesign()->type < Ship::STATION) { char txt[256]; if (elem->Player() > 0) { sprintf_s(txt, "==>"); if (pkg_index < 0) pkg_index = elem_index; } else { strcpy_s(txt, " "); } pkg_list->AddItemWithData(txt, elem->ElementID()); pkg_list->SetItemText(i, 1, elem->Name()); pkg_list->SetItemText(i, 2, elem->RoleName()); const ShipDesign* design = elem->GetDesign(); if (elem->Count() > 1) sprintf_s(txt, "%d %s", elem->Count(), design->abrv); else sprintf_s(txt, "%s %s", design->abrv, design->name); pkg_list->SetItemText(i, 3, txt); i++; } elem_index++; } } } }
int CombatGroup::CountUnits() const { int n = 0; CombatGroup* g = (CombatGroup*) this; ListIter<CombatUnit> unit = g->units; while (++unit) n += unit->Count() - unit->DeadCount(); CombatGroup* pThis = ((CombatGroup*) this); pThis->live_comp.clear(); ListIter<CombatGroup> iter = g->components; while (++iter) { CombatGroup* comp = iter.value(); if (!comp->IsReserve()) { int unit_count = comp->CountUnits(); if (unit_count > 0) pThis->live_comp.append(comp); n += unit_count; } } return n; }
CombatUnit* CombatGroup::GetNextUnit() { if (units.size() > 0) { List<CombatUnit> live; ListIter<CombatUnit> unit = units; while (++unit) { if (unit->Count() - unit->DeadCount() > 0) live.append(unit.value()); } if (live.size() > 0) { return live[unit_index++ % live.size()]; } } if (components.size() > 0) { return components[unit_index % components.size()]->GetNextUnit(); } return 0; }
CombatUnit* CombatGroup::GetRandomUnit() { CombatUnit* result = 0; List<CombatUnit> live; ListIter<CombatUnit> unit = units; while (++unit) { if (unit->Count() - unit->DeadCount() > 0) live.append(unit.value()); } if (live.size() > 0) { int ntries = 5; while (!result && ntries-- > 0) { int index = rand() % live.size(); result = live[index]; int ship_class = result->GetShipClass(); if (ship_class >= Ship::CRUISER && ship_class <= Ship::FARCASTER) result = 0; } } if (!result) { ListIter<CombatGroup> comp = components; while (++comp && !result) { CombatUnit* u = comp->GetRandomUnit(); if (u) result = u; } } return result; }