void CAttackHandler::UpdateAir() { if (airUnits.size() == 0) return; /* if enemy is dead, attacking = false every blue moon, do an air raid on most valuable thingy */ assert(!(airIsAttacking && airTarget == -1)); if (airIsAttacking && (airUnits.size() == 0 || ai->cheat->GetUnitDef(airTarget) == NULL)) { airTarget = -1; airIsAttacking = false; } if (ai->cb->GetCurrentFrame() % (60*30*5) == 0 //5 mins || (ai->cb->GetCurrentFrame() % (30*30) == 0 && airUnits.size() > 8)) { //30 secs && 8+ units //L("AH: trying to attack with air units."); int numOfEnemies = ai->cheat->GetEnemyUnits(unitArray); int bestID = -1; float bestFound = -1.0; for (int i = 0; i < numOfEnemies; i++) { int enemy = unitArray[i]; if (enemy != -1 && ai->cheat->GetUnitDef(enemy) != NULL && ai->cheat->GetUnitDef(enemy)->metalCost > bestFound) { bestID = enemy; bestFound = ai->cheat->GetUnitDef(enemy)->metalCost; } } //L("AH: selected the enemy: " << bestID); if (bestID != -1 && ai->cheat->GetUnitDef(bestID)) { //give the order for (list<int>::iterator it = airUnits.begin(); it != airUnits.end(); it++) { CUNIT* u = ai->MyUnits[*it]; u->Attack(bestID); } airIsAttacking = true; airTarget = bestID; ai->cb->SendTextMsg("AH: air group is attacking", 0); } } //TODO: units currently being built. (while the others are off attacking) if (ai->cb->GetCurrentFrame() % 1800 == 0) { airPatrolOrdersGiven = false; } if (!airPatrolOrdersGiven && !airIsAttacking) { //L("AH: updating air patrol routes"); // assert(false); //get / make up some outer base perimeter points vector<float3> outerMeans; const int num = 3; outerMeans.reserve(num); if (kMeansK > 1) { int counter = 0; counter += kMeansK / 8; //offsetting the outermost one for (int i = 0; i < num; i++) { outerMeans.push_back(kMeansBase[counter]); if (counter < kMeansK-1) counter++; } } else { //theres just 1 kmeans and we need three for (int i = 0; i < num; i++) { outerMeans.push_back(kMeansBase[0] + float3(250*i, 0, 0)); } } assert(outerMeans.size() == num); //give the patrol orders to the outer means for (list<int>::iterator it = airUnits.begin(); it != airUnits.end(); it++) { CUNIT* u = ai->MyUnits[*it]; u->Move(outerMeans[0] + float3(0,50,0)); //do this first in case theyre in the enemy base for (int i = 0; i < num; i++) { u->PatrolShift(outerMeans[i]); } } airPatrolOrdersGiven = true; } }