sources » ScenarioClass » GenerateStartingUnits_B
// this generates starting units for all houses at once
// only fires when mpmodes are not initialized (no idea when that is)
void ScenarioClass::GenerateStartingUnits_B() {
DynamicVectorClass<TechnoTypeClass*> vec_Eligible;
int StartingUnits = GameSettings->StartingUnitCount;
if(GameSettings->Bases) {
--StartingUnits;
}
int totalCost = 0, totalCount = 0;
foreach(vec_UnitTypes as Veh) {
if(Veh->AllowedToStartInMultiplayer
&& !Rules->BaseUnit.Contains(Veh)
) {
totalCost += Veh->GetCost();
++totalCount;
}
}
foreach(vec_InfantryTypes as Inf) {
if(Inf->AllowedToStartInMultiplayer) {
totalCost += Inf->GetCost();
++totalCount;
}
}
int AmountForHouse = StartingUnits * totalCost / totalCount; // ???
foreach(vec_Houses as House) {
if(House->Country->MultiplayPassive) {
continue;
}
DynamicVectorClass<InfantryTypeClass*> vec_Inf;
DynamicVectorClass<UnitTypeClass*> vec_Veh;
int houseBitfield = 1 << OwnerHouse->CountryIndex;
foreach(vec_UnitTypes as Veh) {
if(Veh->AllowedToStartInMultiplayer
&& (houseBitfield & Veh->Owners)
&& Veh->TechLevel <= House->TechLevel
&& !Rules->BaseUnit.Contains(Veh)
) {
vec_Veh.Append(Veh);
}
}
foreach(vec_InfantryTypes as Inf) {
if(Inf->AllowedToStartInMultiplayer
&& (houseBitfield & Inf->Owners)
&& Inf->TechLevel <= House->TechLevel
) {
vec_Inf.Append(Inf);
}
}
if(GameSettings->Bases) {
UnitTypeClass *Base = House->FindFirstAccessibleTechnoTypeFromArray(Rules->BaseUnit);
UnitClass *BaseUnit = Base->CreateInstance(House);
if(BaseUnit->Put(House->BaseCell) || BaseUnit->PlaceNearby(House->BaseCell, 1)) {
if(Scenario->Flags & FLAG_CTF_GAME) { // ???
House->UnitCarryingOurFlag = BaseUnit;
}
} else {
delete BaseUnit;
}
}
int switchingCost = AmountForHouse * 2 / 3;
int RemainingCost = AmountForHouse;
int SpentCost = 0;
do {
TechnoTypeClass *randUnit;
if(SpentCost >= switchingCost || vec_Veh.Length <= 0) {
randUnit = vec_InfantryTypes[Random_Ranged(0, vec_Inf.Length - 1)];
} else {
randUnit = vec_UnitTypes[Random_Ranged(0, vec_Veh.Length - 1)];
}
TechnoClass * Instance = randUnit->CreateInstance(OwnerHouse);
if(Instance->PlaceNearby(OwnerHouse->GetHomeCell, 4)) {
SpentCost += randUnit->GetCost();
if(this->Flags & FLAG_INITIALVETERAN) {
Instance->SetVeteran();
}
Instance->ForceMission(OwnerHouse->IsHumanControlled ? MISSION_GUARD : MISSION_AREA_GUARD);
} else {
RemainingCost -= randUnit->GetCost(); // not refunded!
delete Instance;
}
} while (SpentCost < RemainingCost);
}
}