void AiForceManager::CheckUnits(int *counter) { int attacking[UnitTypeMax]; const int *unit_types_count = AiPlayer->Player->UnitTypesAiActiveCount; memset(attacking, 0, sizeof(attacking)); // Look through the forces what is missing. for (unsigned int i = 0; i < forces.size(); ++i) { const AiForce &force = forces[i]; if (force.State > AiForceAttackingState_Free && force.IsAttacking()) { for (unsigned int j = 0; j < force.Size(); ++j) { const CUnit *unit = force.Units[j]; attacking[unit->Type->Slot]++; } } } // create missing units for (unsigned int i = 0; i < forces.size(); ++i) { AiForce &force = forces[i]; // No troops for attacking force if (force.State == AiForceAttackingState_Free || force.IsAttacking()) { continue; } for (unsigned int j = 0; j < force.UnitTypes.size(); ++j) { const AiUnitType &aiut = force.UnitTypes[j]; const unsigned int t = aiut.Type->Slot; const int wantedCount = aiut.Want; int e = unit_types_count[t]; if (t < AiHelpers.Equiv.size()) { for (unsigned int j = 0; j < AiHelpers.Equiv[t].size(); ++j) { e += unit_types_count[AiHelpers.Equiv[t][j]->Slot]; } } const int requested = wantedCount - (e + counter[t] - attacking[t]); if (requested > 0) { // Request it. AiAddUnitTypeRequest(*aiut.Type, requested); counter[t] += requested; force.Completed = false; } counter[t] -= wantedCount; } } }
/** ** Check if everything is fine, send new requests to resource manager. */ static void AiCheckUnits() { // Count the already made build requests. int counter[UnitTypeMax]; AiGetBuildRequestsCount(*AiPlayer, counter); // Remove non active units. const int unitCount = AiPlayer->Player->GetUnitCount(); for (int i = 0; i < unitCount; ++i) { const CUnit &unit = AiPlayer->Player->GetUnit(i); if (!unit.Active) { counter[unit.Type->Slot]--; } } const int *unit_types_count = AiPlayer->Player->UnitTypesCount; // Look if some unit-types are missing. int n = AiPlayer->UnitTypeRequests.size(); for (int i = 0; i < n; ++i) { const unsigned int t = AiPlayer->UnitTypeRequests[i].Type->Slot; const int x = AiPlayer->UnitTypeRequests[i].Count; // Add equivalent units int e = unit_types_count[t]; if (t < AiHelpers.Equiv.size()) { for (unsigned int j = 0; j < AiHelpers.Equiv[t].size(); ++j) { e += unit_types_count[AiHelpers.Equiv[t][j]->Slot]; } } const int requested = x - e - counter[t]; if (requested > 0) { // Request it. AiAddUnitTypeRequest(*AiPlayer->UnitTypeRequests[i].Type, requested); counter[t] += requested; } counter[t] -= x; } AiPlayer->Force.CheckUnits(counter); // Look if some upgrade-to are missing. n = AiPlayer->UpgradeToRequests.size(); for (int i = 0; i < n; ++i) { const unsigned int t = AiPlayer->UpgradeToRequests[i]->Slot; const int x = 1; // Add equivalent units int e = unit_types_count[t]; if (t < AiHelpers.Equiv.size()) { for (unsigned int j = 0; j < AiHelpers.Equiv[t].size(); ++j) { e += unit_types_count[AiHelpers.Equiv[t][j]->Slot]; } } const int requested = x - e - counter[t]; if (requested > 0) { // Request it. AiAddUpgradeToRequest(*AiPlayer->UpgradeToRequests[i]); counter[t] += requested; } counter[t] -= x; } // Look if some researches are missing. n = (int)AiPlayer->ResearchRequests.size(); for (int i = 0; i < n; ++i) { if (UpgradeIdAllowed(*AiPlayer->Player, AiPlayer->ResearchRequests[i]->ID) == 'A') { AiAddResearchRequest(AiPlayer->ResearchRequests[i]); } } }
/** ** Check if everything is fine, send new requests to resource manager. */ static void AiCheckUnits() { int counter[UnitTypeMax]; int attacking[UnitTypeMax]; const int *unit_types_count; int i; memset(counter, 0, sizeof(counter)); memset(attacking, 0, sizeof(attacking)); // // Count the already made build requests. // for (i = 0; i < (int)AiPlayer->UnitTypeBuilt.size(); ++i) { AiBuildQueue *queue = &AiPlayer->UnitTypeBuilt[i]; counter[queue->Type->Slot] += queue->Want; } unit_types_count = AiPlayer->Player->UnitTypesCount; // // Look if some unit-types are missing. // for (i = 0; i < (int)AiPlayer->UnitTypeRequests.size(); ++i) { int slot = AiPlayer->UnitTypeRequests[i].Type->Slot; int count = AiPlayer->UnitTypeRequests[i].Count; int e; // // Add equivalent units // e = unit_types_count[slot]; if (slot < (int)AiHelpers.Equiv.size()) { for (int j = 0; j < (int)AiHelpers.Equiv[slot].size(); ++j) { e += unit_types_count[AiHelpers.Equiv[slot][j]->Slot]; } } if (count > e + counter[slot]) { // Request it. AiAddUnitTypeRequest(AiPlayer->UnitTypeRequests[i].Type, count - e - counter[slot]); counter[slot] += count - e - counter[slot]; } counter[slot] -= count; } // // Look through the forces what is missing. // for (i = AI_MAX_FORCES; i < AI_MAX_ATTACKING_FORCES; ++i) { for (int j = 0; j < (int)AiPlayer->Force[i].Units.size(); ++j) { attacking[AiPlayer->Force[i].Units[j]->Type->Slot]++; } } // // create missing units // for (i = 0; i < AI_MAX_FORCES; ++i) { // No troops for attacking force if (!AiPlayer->Force[i].Defending && AiPlayer->Force[i].Attacking) { continue; } for (int j = 0; j < (int)AiPlayer->Force[i].UnitTypes.size(); ++j) { const AiUnitType *aiut = &AiPlayer->Force[i].UnitTypes[j]; int slot = aiut->Type->Slot; int want = aiut->Want; if (want > unit_types_count[slot] + counter[slot] - attacking[slot]) { // Request it. AiAddUnitTypeRequest(aiut->Type, want - (unit_types_count[slot] + counter[slot] - attacking[slot])); counter[slot] += want - (unit_types_count[slot] + counter[slot] - attacking[slot]); AiPlayer->Force[i].Completed = false; } counter[slot] -= want; } } }