コード例 #1
0
CombatGroup*
CombatGroup::Clone(bool deep)
{
	CombatGroup* clone = new(__FILE__,__LINE__)
	CombatGroup(type, id, name, iff, enemy_intel);

	clone->combatant  = combatant;
	clone->region     = region;
	clone->location   = location;
	clone->value      = value;
	clone->expanded   = expanded;

	for (int i = 0; i < units.size(); i++) {
		CombatUnit* u = new(__FILE__,__LINE__) CombatUnit(*units[i]);
		u->SetCombatGroup(clone);
		clone->units.append(u);
	}

	if (deep) {
		for (int i = 0; i < components.size(); i++) {
			CombatGroup* g = components[i]->Clone(deep);
			clone->AddComponent(g);

			if (g->Type() == FIGHTER_SQUADRON   ||
					g->Type() == INTERCEPT_SQUADRON ||
					g->Type() == ATTACK_SQUADRON    ||
					g->Type() == LCA_SQUADRON) {

				if (units.size() > 0) {
					CombatUnit* carrier = units[0];

					for (int u = 0; u < g->GetUnits().size(); u++) {
						CombatUnit* unit = g->GetUnits()[u];

						if (unit->Type() >= Ship::FIGHTER ||
								unit->Type() <= Ship::LCA) {
							unit->SetCarrier(carrier);
							unit->SetRegion(carrier->GetRegion());
						}
					}
				}
			}
		}
	}

	return clone;
}
コード例 #2
0
CombatGroup*
CombatGroup::FindCarrier()
{
	CombatGroup* p = GetParent();

	while (p         != 0                           && 
	p->Type() != CombatGroup::CARRIER_GROUP  &&
	p->Type() != CombatGroup::STATION        &&
	p->Type() != CombatGroup::STARBASE)
	p = p->GetParent();

	if (p && p->GetUnits().size())
	return p;

	return 0;
}