void CMobileCAI::SlowUpdate() { if (gs->paused) // Commands issued may invoke SlowUpdate when paused return; if (dynamic_cast<AAirMoveType*>(owner->moveType)) { LandRepairIfNeeded() || RefuelIfNeeded(); } if (!commandQue.empty() && commandQue.front().timeOut < gs->frameNum) { StopMove(); FinishCommand(); return; } if (commandQue.empty()) { MobileAutoGenerateTarget(); //the attack order could terminate directly and thus cause a loop if (commandQue.empty() || commandQue.front().GetID() == CMD_ATTACK) { return; } } if (!slowGuard) { // when slow-guarding, regulate speed through {Start,Stop}SlowGuard SlowUpdateMaxSpeed(); } Execute(); }
void CMobileCAI::SlowUpdate() { if(gs->paused) // Commands issued may invoke SlowUpdate when paused return; bool wantToLand = false; if (dynamic_cast<AAirMoveType*>(owner->moveType)) { wantToLand = LandRepairIfNeeded(); if (!wantToLand && owner->unitDef->maxFuel > 0) { wantToLand = RefuelIfNeeded(); } } if (!commandQue.empty() && commandQue.front().timeOut < gs->frameNum) { StopMove(); FinishCommand(); return; } if (commandQue.empty()) { IdleCheck(); //the attack order could terminate directly and thus cause a loop if(commandQue.empty() || commandQue.front().id == CMD_ATTACK) { return; } } // treat any following CMD_SET_WANTED_MAX_SPEED commands as options // to the current command (and ignore them when it's their turn) if (commandQue.size() >= 2 && !slowGuard) { CCommandQueue::iterator it = commandQue.begin(); it++; const Command& c = *it; if ((c.id == CMD_SET_WANTED_MAX_SPEED) && (c.params.size() >= 1)) { const float defMaxSpeed = owner->maxSpeed; const float newMaxSpeed = std::min(c.params[0], defMaxSpeed); if (newMaxSpeed > 0) owner->moveType->SetMaxSpeed(newMaxSpeed); } } Execute(); }
void CAirCAI::SlowUpdate() { if(gs->paused) // Commands issued may invoke SlowUpdate when paused return; if (!commandQue.empty() && commandQue.front().timeOut < gs->frameNum) { FinishCommand(); return; } if (owner->usingScriptMoveType) { return; // avoid the invalid (CAirMoveType*) cast } AAirMoveType* myPlane=(AAirMoveType*) owner->moveType; bool wantToRefuel = LandRepairIfNeeded(); if(!wantToRefuel && owner->unitDef->maxFuel > 0){ wantToRefuel = RefuelIfNeeded(); } if(commandQue.empty()){ if(myPlane->aircraftState == AAirMoveType::AIRCRAFT_FLYING && !owner->unitDef->DontLand() && myPlane->autoLand) { StopMove(); // myPlane->SetState(AAirMoveType::AIRCRAFT_LANDING); } if(owner->unitDef->canAttack && owner->fireState >= FIRESTATE_FIREATWILL && owner->moveState != MOVESTATE_HOLDPOS && owner->maxRange > 0) { if (myPlane->IsFighter()) { float testRad=1000 * owner->moveState; CUnit* enemy=helper->GetClosestEnemyAircraft( owner->pos + (owner->speed * 10), testRad, owner->allyteam); if(IsValidTarget(enemy)) { Command nc; nc.id = CMD_ATTACK; nc.params.push_back(enemy->id); nc.options = 0; commandQue.push_front(nc); inCommand = false; return; } } const float searchRadius = 500 * owner->moveState; CUnit* enemy = helper->GetClosestValidTarget( owner->pos + (owner->speed * 20), searchRadius, owner->allyteam, this); if (enemy != NULL) { Command nc; nc.id = CMD_ATTACK; nc.params.push_back(enemy->id); nc.options = 0; commandQue.push_front(nc); inCommand = false; return; } } return; } Command& c = commandQue.front(); if (c.id == CMD_WAIT) { if ((myPlane->aircraftState == AAirMoveType::AIRCRAFT_FLYING) && !owner->unitDef->DontLand() && myPlane->autoLand) { StopMove(); // myPlane->SetState(AAirMoveType::AIRCRAFT_LANDING); } return; } if (c.id != CMD_STOP && c.id != CMD_AUTOREPAIRLEVEL && c.id != CMD_IDLEMODE && c.id != CMD_SET_WANTED_MAX_SPEED) { myPlane->Takeoff(); } if (wantToRefuel) { switch (c.id) { case CMD_AREA_ATTACK: case CMD_ATTACK: case CMD_FIGHT: return; } } switch(c.id){ case CMD_AREA_ATTACK:{ ExecuteAreaAttack(c); return; } default:{ CMobileCAI::Execute(); return; } } }
void CAirCAI::SlowUpdate() { // Commands issued may invoke SlowUpdate when paused if (gs->paused) return; if (!commandQue.empty() && (commandQue.front().timeOut < gs->frameNum)) { FinishCommand(); return; } // avoid the invalid (CStrafeAirMoveType*) cast if (owner->UsingScriptMoveType()) return; const bool wantToRefuel = (LandRepairIfNeeded() || RefuelIfNeeded()); #if (AUTO_GENERATE_ATTACK_ORDERS == 1) if (commandQue.empty()) { if (!AirAutoGenerateTarget(GetStrafeAirMoveType(owner))) { // if no target found, queue is still empty so bail now return; } } #endif // FIXME: check owner->UsingScriptMoveType() and skip rest if true? AAirMoveType* myPlane = GetStrafeAirMoveType(owner); Command& c = commandQue.front(); if (c.GetID() == CMD_WAIT) { if ((myPlane->aircraftState == AAirMoveType::AIRCRAFT_FLYING) && !owner->unitDef->DontLand() && myPlane->autoLand) { StopMove(); } return; } if (c.GetID() != CMD_STOP && c.GetID() != CMD_AUTOREPAIRLEVEL && c.GetID() != CMD_IDLEMODE && c.GetID() != CMD_SET_WANTED_MAX_SPEED) { myPlane->Takeoff(); } if (wantToRefuel) { switch (c.GetID()) { case CMD_AREA_ATTACK: case CMD_ATTACK: case CMD_FIGHT: return; } } switch (c.GetID()) { case CMD_AREA_ATTACK: { ExecuteAreaAttack(c); return; } default: { CMobileCAI::Execute(); return; } } }