void CCommandAI::GiveCommandReal(const Command& c) { if (!AllowedCommand(c)) { return; } GiveAllowedCommand(c); }
void CBuilderCAI::GiveCommandReal(const Command& c, bool fromSynced) { if (!AllowedCommand(c, fromSynced)) return; // don't guard yourself if ((c.GetID() == CMD_GUARD) && (c.params.size() == 1) && ((int)c.params[0] == owner->id)) { return; } // stop building/reclaiming/... if the new command is not queued, i.e. replaces our current activity // FIXME should happen just before CMobileCAI::GiveCommandReal? (the new cmd can still be skipped!) if ((c.GetID() != CMD_WAIT && c.GetID() != CMD_SET_WANTED_MAX_SPEED) && !(c.options & SHIFT_KEY)) { if (nonQueingCommands.find(c.GetID()) == nonQueingCommands.end()) { building = false; static_cast<CBuilder*>(owner)->StopBuild(); } } if (buildOptions.find(c.GetID()) != buildOptions.end()) { if (c.params.size() < 3) return; BuildInfo bi; bi.pos = c.GetPos(0); if (c.params.size() == 4) bi.buildFacing = abs((int)c.params[3]) % NUM_FACINGS; bi.def = unitDefHandler->GetUnitDefByID(-c.GetID()); bi.pos = CGameHelper::Pos2BuildPos(bi, true); // We are a static building, check if the buildcmd is in range if (!owner->unitDef->canmove) { if (!IsInBuildRange(bi.pos, GetBuildOptionRadius(bi.def, c.GetID()))) { return; } } const CUnit* nanoFrame = NULL; // check if the buildpos is blocked if (IsBuildPosBlocked(bi, &nanoFrame)) return; // if it is a nanoframe help to finish it if (nanoFrame != NULL) { Command c2(CMD_REPAIR, c.options | INTERNAL_ORDER, nanoFrame->id); CMobileCAI::GiveCommandReal(c2, fromSynced); CMobileCAI::GiveCommandReal(c, fromSynced); return; } } else { if (c.GetID() < 0) return; } CMobileCAI::GiveCommandReal(c, fromSynced); }
void CBuilderCAI::GiveCommandReal(const Command& c, bool fromSynced) { if (!AllowedCommand(c)) return; if ((c.id == CMD_GUARD) && (c.params.size() == 1) && ((int)c.params[0] == owner->id)) { return; } if(!(c.options & SHIFT_KEY) && nonQueingCommands.find(c.id)==nonQueingCommands.end() && c.id != CMD_WAIT) { building=false; CBuilder* fac=(CBuilder*)owner; fac->StopBuild(); } map<int,string>::iterator boi = buildOptions.find(c.id); if (boi != buildOptions.end()) { if (c.params.size() < 3) { return; } BuildInfo bi; bi.pos = float3(c.params[0],c.params[1],c.params[2]); if(c.params.size()==4) bi.buildFacing=int(c.params[3]); bi.def = unitDefHandler->GetUnitByName(boi->second); bi.pos=helper->Pos2BuildPos(bi); if (!owner->unitDef->canmove) { const CBuilder* builder = (CBuilder*)owner; const float dist = f3Len(builder->pos - bi.pos); const float radius = GetUnitDefRadius(bi.def, c.id); if (dist > (builder->buildDistance + radius - 8.0f)) { return; } } CFeature* feature; if(!uh->TestUnitBuildSquare(bi,feature,owner->allyteam)) { if (!feature && owner->unitDef->canAssist) { int yardxpos=int(bi.pos.x+4)/SQUARE_SIZE; int yardypos=int(bi.pos.z+4)/SQUARE_SIZE; CSolidObject* s; CUnit* u; if((s=groundBlockingObjectMap->GroundBlocked(yardypos*gs->mapx+yardxpos)) && (u=dynamic_cast<CUnit*>(s)) && u->beingBuilt && (u->buildProgress == 0.0f) && (!u->soloBuilder || (u->soloBuilder == owner))) { Command c2; c2.id = CMD_REPAIR; c2.params.push_back(u->id); c2.options = c.options | INTERNAL_ORDER; CMobileCAI::GiveCommandReal(c2); CMobileCAI::GiveCommandReal(c); } } return; } } CMobileCAI::GiveCommandReal(c); }
void CCommandAI::GiveCommandReal(const Command& c, bool fromSynced) { if (!AllowedCommand(c, fromSynced)) { return; } GiveAllowedCommand(c, fromSynced); }
void CMobileCAI::GiveCommand(const Command &c) { if (!AllowedCommand(c)) return; if(owner->unitDef->canfly && c.id==CMD_AUTOREPAIRLEVEL){ if(!dynamic_cast<CTAAirMoveType*>(owner->moveType)) return; if(c.params.empty()) return; switch((int)c.params[0]){ case 0: ((CTAAirMoveType*)owner->moveType)->repairBelowHealth=0; break; case 1: ((CTAAirMoveType*)owner->moveType)->repairBelowHealth=0.3f; break; case 2: ((CTAAirMoveType*)owner->moveType)->repairBelowHealth=0.5f; break; } for(vector<CommandDescription>::iterator cdi=possibleCommands.begin();cdi!=possibleCommands.end();++cdi){ if(cdi->id==CMD_AUTOREPAIRLEVEL){ char t[10]; SNPRINTF(t,10,"%d", (int)c.params[0]); cdi->params[0]=t; break; } } selectedUnits.PossibleCommandChange(owner); return; } if(!(c.options & SHIFT_KEY) && nonQueingCommands.find(c.id)==nonQueingCommands.end()){ tempOrder=false; StopSlowGuard(); } CCommandAI::GiveAllowedCommand(c); }
void CFactoryCAI::GiveCommandReal(const Command& c, bool fromSynced) { // move is always allowed for factories (passed to units it produces) if ((c.id == CMD_SET_WANTED_MAX_SPEED) || ((c.id != CMD_MOVE) && !AllowedCommand(c))) { return; } map<int, BuildOption>::iterator boi = buildOptions.find(c.id); // not a build order so queue it to built units if (boi == buildOptions.end()) { if ((nonQueingCommands.find(c.id) != nonQueingCommands.end()) || (c.id == CMD_INSERT) || (c.id == CMD_REMOVE) || (!(c.options & SHIFT_KEY) && ((c.id == CMD_WAIT) || (c.id == CMD_SELFD)))) { CCommandAI::GiveAllowedCommand(c); return; } if (!(c.options & SHIFT_KEY)) { waitCommandsAI.ClearUnitQueue(owner, newUnitCommands); newUnitCommands.clear(); } if (c.id != CMD_STOP) { if ((c.id == CMD_WAIT) || (c.id == CMD_SELFD)) { if (!newUnitCommands.empty() && (newUnitCommands.back().id == c.id)) { if (c.id == CMD_WAIT) { waitCommandsAI.RemoveWaitCommand(owner, c); } newUnitCommands.pop_back(); } else { newUnitCommands.push_back(c); } } else { bool dummy; if (CancelCommands(c, newUnitCommands, dummy) > 0) { return; } else { if (GetOverlapQueued(c, newUnitCommands).empty()) { newUnitCommands.push_back(c); } else { return; } } } } // the first new-unit build order can not be WAIT or SELFD while (!newUnitCommands.empty()) { const int id = newUnitCommands.front().id; if ((id == CMD_WAIT) || (id == CMD_SELFD)) { if (c.id == CMD_WAIT) { waitCommandsAI.RemoveWaitCommand(owner, c); } newUnitCommands.pop_front(); } else { break; } } return; } BuildOption &bo = boi->second; int numItems = 1; if (c.options & SHIFT_KEY) { numItems *= 5; } if (c.options & CONTROL_KEY) { numItems *= 20; } if (c.options & RIGHT_MOUSE_KEY) { bo.numQued -= numItems; if (bo.numQued < 0) { bo.numQued = 0; } int numToErase = numItems; if (c.options & ALT_KEY) { for (unsigned int cmdNum = 0; cmdNum < commandQue.size() && numToErase; ++cmdNum) { if (commandQue[cmdNum].id == c.id) { commandQue[cmdNum].id = CMD_STOP; numToErase--; } } } else { for (int cmdNum = commandQue.size() - 1; cmdNum != -1 && numToErase; --cmdNum) { if (commandQue[cmdNum].id == c.id) { commandQue[cmdNum].id = CMD_STOP; numToErase--; } } } UpdateIconName(c.id,bo); SlowUpdate(); } else { if (c.options & ALT_KEY) { for (int a = 0; a < numItems; ++a) { if (repeatOrders) { Command nc(c); nc.options |= DONT_REPEAT; if (commandQue.empty()) { commandQue.push_front(nc); } else { commandQue.insert(commandQue.begin()+1, nc); } } else { commandQue.push_front(c); } } if (!repeatOrders) { building=false; CFactory* fac = (CFactory*)owner; fac->StopBuild(); } } else { for (int a = 0; a < numItems; ++a) { commandQue.push_back(c); } } bo.numQued += numItems; UpdateIconName(c.id, bo); SlowUpdate(); } }
void CCommandAI::ExecuteInsert(const Command& c, bool fromSynced) { if (c.params.size() < 3) { return; } // make the command Command newCmd; newCmd.id = (int)c.params[1]; newCmd.options = (unsigned char)c.params[2]; for (int p = 3; p < (int)c.params.size(); p++) { newCmd.params.push_back(c.params[p]); } // validate the command if (!AllowedCommand(newCmd, fromSynced)) { return; } CCommandQueue* queue = &commandQue; bool facBuildQueue = false; CFactoryCAI* facCAI = dynamic_cast<CFactoryCAI*>(this); if (facCAI) { if (c.options & CONTROL_KEY) { // check the build order const map<int, CFactoryCAI::BuildOption>& bOpts = facCAI->buildOptions; if ((newCmd.id != CMD_STOP) && (newCmd.id != CMD_WAIT) && ((newCmd.id >= 0) || (bOpts.find(newCmd.id) == bOpts.end()))) { return; } facBuildQueue = true; } else { // use the new commands queue = &facCAI->newUnitCommands; } } // FIXME: handle CMD_LOOPBACKATTACK, etc... CCommandQueue::iterator insertIt = queue->begin(); if (c.options & ALT_KEY) { // treat param0 as a position int pos = (int)c.params[0]; const unsigned int qsize = queue->size(); if (pos < 0) { pos = qsize + pos + 1; // convert the negative index if (pos < 0) { pos = 0; } } if (pos > qsize) { pos = qsize; } std::advance(insertIt, pos); } else { // treat param0 as a command tag const unsigned int tag = (unsigned int)c.params[0]; CCommandQueue::iterator ci; bool found = false; for (ci = queue->begin(); ci != queue->end(); ++ci) { const Command& qc = *ci; if (qc.tag == tag) { insertIt = ci; found = true; break; } } if (!found) { return; } if ((c.options & RIGHT_MOUSE_KEY) && (insertIt != queue->end())) { insertIt++; // insert after the tagged command } } if (facBuildQueue) { facCAI->InsertBuildCommand(insertIt, newCmd); if (!owner->stunned) { SlowUpdate(); } return; } // shutdown the current order if the insertion is at the beginning if (!queue->empty() && (insertIt == queue->begin())) { inCommand = false; targetDied = false; unimportantMove = false; orderTarget = NULL; const Command& cmd = commandQue.front(); eoh->CommandFinished(*owner, cmd); eventHandler.UnitCmdDone(owner, cmd.id, cmd.tag); } queue->insert(insertIt, newCmd); if (!owner->stunned) { SlowUpdate(); } return; }
void CBuilderCAI::GiveCommandReal(const Command& c, bool fromSynced) { if (!AllowedCommand(c, fromSynced)) return; // don't guard yourself if ((c.GetID() == CMD_GUARD) && (c.params.size() == 1) && ((int)c.params[0] == owner->id)) { return; } // stop current build if the new command is a not queued and replaces the current buidcmd //FIXME should happen just before CMobileCAI::GiveCommandReal? (the new cmd can still be skipped!) if (!(c.options & SHIFT_KEY) && nonQueingCommands.find(c.GetID()) == nonQueingCommands.end() && c.GetID() != CMD_WAIT) { building = false; ((CBuilder*) owner)->StopBuild(); } map<int,string>::iterator boi = buildOptions.find(c.GetID()); if (boi != buildOptions.end()) { if (c.params.size() < 3) { return; } BuildInfo bi; bi.pos = c.GetPos(0); if (c.params.size() == 4) bi.buildFacing = abs((int)c.params[3]) % NUM_FACINGS; bi.def = unitDefHandler->GetUnitDefByName(boi->second); bi.pos = helper->Pos2BuildPos(bi, true); // We are a static building, check if the buildcmd is in range if (!owner->unitDef->canmove) { const float radius = GetBuildOptionRadius(bi.def, c.GetID()); if (!IsInBuildRange(bi.pos, radius)) { return; } } // check if the buildpos is blocked if it is a nanoframe help to finish it //FIXME finish it just if it is of the same unitdef? CFeature* feature = NULL; if (!uh->TestUnitBuildSquare(bi, feature, owner->allyteam, true)) { if (!feature && owner->unitDef->canAssist) { const int yardxpos = int(bi.pos.x + 4) / SQUARE_SIZE; const int yardypos = int(bi.pos.z + 4) / SQUARE_SIZE; const CSolidObject* s = groundBlockingObjectMap->GroundBlocked(yardxpos, yardypos); const CUnit* u = dynamic_cast<const CUnit*>(s); if ( (u != NULL) && u->beingBuilt && (u->buildProgress == 0.0f) && (!u->soloBuilder || (u->soloBuilder == owner)) ) { Command c2(CMD_REPAIR, c.options | INTERNAL_ORDER); c2.params.push_back(u->id); CMobileCAI::GiveCommandReal(c2); CMobileCAI::GiveCommandReal(c); } } return; } } CMobileCAI::GiveCommandReal(c); }
void CMobileCAI::GiveCommandReal(const Command &c, bool fromSynced) { if (!AllowedCommand(c, fromSynced)) return; if (owner->unitDef->canfly && c.id == CMD_AUTOREPAIRLEVEL) { if (c.params.empty()) { return; } AAirMoveType* airMT = GetAirMoveType<AAirMoveType>(owner); if (!airMT) return; switch ((int) c.params[0]) { case 0: { airMT->repairBelowHealth = 0.0f; break; } case 1: { airMT->repairBelowHealth = 0.3f; break; } case 2: { airMT->repairBelowHealth = 0.5f; break; } case 3: { airMT->repairBelowHealth = 0.8f; break; } } for (vector<CommandDescription>::iterator cdi = possibleCommands.begin(); cdi != possibleCommands.end(); ++cdi) { if (cdi->id == CMD_AUTOREPAIRLEVEL) { char t[10]; SNPRINTF(t, 10, "%d", (int) c.params[0]); cdi->params[0] = t; break; } } selectedUnits.PossibleCommandChange(owner); return; } if (owner->unitDef->canfly && c.id == CMD_IDLEMODE) { if (c.params.empty()) { return; } AAirMoveType* airMT = GetAirMoveType<AAirMoveType>(owner); if (!airMT) return; switch ((int) c.params[0]) { case 0: { airMT->autoLand = false; airMT->Takeoff(); break; } case 1: { airMT->autoLand = true; break; } } for (vector<CommandDescription>::iterator cdi = possibleCommands.begin(); cdi != possibleCommands.end(); ++cdi) { if (cdi->id == CMD_IDLEMODE) { char t[10]; SNPRINTF(t, 10, "%d", (int) c.params[0]); cdi->params[0] = t; break; } } selectedUnits.PossibleCommandChange(owner); return; } if (!(c.options & SHIFT_KEY) && nonQueingCommands.find(c.id) == nonQueingCommands.end()) { tempOrder = false; StopSlowGuard(); } CCommandAI::GiveAllowedCommand(c); }
void CAirCAI::GiveCommandReal(const Command &c) { // take care not to allow aircraft to be ordered to move out of the map if (c.id != CMD_MOVE && !AllowedCommand(c)) return; else if (c.id == CMD_MOVE && c.params.size() >= 3 && (c.params[0] < 0.f || c.params[2] < 0.f || c.params[0] > gs->mapx*SQUARE_SIZE || c.params[2] > gs->mapy*SQUARE_SIZE)) return; if (c.id == CMD_SET_WANTED_MAX_SPEED) { return; } if (c.id == CMD_AUTOREPAIRLEVEL) { if (c.params.empty()) { return; } CAirMoveType* airMT; if (owner->usingScriptMoveType) { airMT = (CAirMoveType*)owner->prevMoveType; } else { airMT = (CAirMoveType*)owner->moveType; } switch((int)c.params[0]){ case 0: { airMT->repairBelowHealth = 0.0f; break; } case 1: { airMT->repairBelowHealth = 0.3f; break; } case 2: { airMT->repairBelowHealth = 0.5f; break; } case 3: { airMT->repairBelowHealth = 0.8f; break; } } for(vector<CommandDescription>::iterator cdi = possibleCommands.begin(); cdi != possibleCommands.end(); ++cdi){ if(cdi->id==CMD_AUTOREPAIRLEVEL){ char t[10]; SNPRINTF(t,10,"%d", (int)c.params[0]); cdi->params[0]=t; break; } } selectedUnits.PossibleCommandChange(owner); return; } if (c.id == CMD_IDLEMODE) { if (c.params.empty()) { return; } CAirMoveType* airMT; if (owner->usingScriptMoveType) { airMT = (CAirMoveType*)owner->prevMoveType; } else { airMT = (CAirMoveType*)owner->moveType; } switch((int)c.params[0]){ case 0: { airMT->autoLand = false; break; } case 1: { airMT->autoLand = true; break; } } for(vector<CommandDescription>::iterator cdi = possibleCommands.begin(); cdi != possibleCommands.end(); ++cdi){ if(cdi->id == CMD_IDLEMODE){ char t[10]; SNPRINTF(t, 10, "%d", (int)c.params[0]); cdi->params[0] = t; break; } } selectedUnits.PossibleCommandChange(owner); return; } if (c.id == CMD_LOOPBACKATTACK) { if (c.params.empty()) { return; } CAirMoveType* airMT; if (owner->usingScriptMoveType) { airMT = (CAirMoveType*)owner->prevMoveType; } else { airMT = (CAirMoveType*)owner->moveType; } switch((int)c.params[0]){ case 0: { airMT->loopbackAttack = false; break; } case 1: { airMT->loopbackAttack = true; break; } } for(vector<CommandDescription>::iterator cdi = possibleCommands.begin(); cdi != possibleCommands.end(); ++cdi){ if(cdi->id == CMD_LOOPBACKATTACK){ char t[10]; SNPRINTF(t, 10, "%d", (int)c.params[0]); cdi->params[0] = t; break; } } selectedUnits.PossibleCommandChange(owner); return; } if (!(c.options & SHIFT_KEY) && nonQueingCommands.find(c.id) == nonQueingCommands.end()) { activeCommand=0; tempOrder=false; } if (c.id == CMD_AREA_ATTACK && c.params.size() < 4){ Command c2 = c; c2.id = CMD_ATTACK; CCommandAI::GiveAllowedCommand(c2); return; } CCommandAI::GiveAllowedCommand(c); }
void CFactoryCAI::GiveCommandReal(const Command& c, bool fromSynced) { const int cmdID = c.GetID(); // move is always allowed for factories (passed to units it produces) if ((cmdID == CMD_SET_WANTED_MAX_SPEED) || ((cmdID != CMD_MOVE) && !AllowedCommand(c, fromSynced))) { return; } map<int, BuildOption>::iterator boi = buildOptions.find(cmdID); // not a build order (or a build order we do not support, eg. if multiple // factories of different types were selected) so queue it to built units if (boi == buildOptions.end()) { if (cmdID < 0) return; if ((nonQueingCommands.find(cmdID) != nonQueingCommands.end()) || (cmdID == CMD_INSERT) || (cmdID == CMD_REMOVE) || (!(c.options & SHIFT_KEY) && ((cmdID == CMD_WAIT) || (cmdID == CMD_SELFD)))) { CCommandAI::GiveAllowedCommand(c); return; } if (!(c.options & SHIFT_KEY)) { waitCommandsAI.ClearUnitQueue(owner, newUnitCommands); CCommandAI::ClearCommandDependencies(); newUnitCommands.clear(); } CCommandAI::AddCommandDependency(c); if (cmdID != CMD_STOP) { if ((cmdID == CMD_WAIT) || (cmdID == CMD_SELFD)) { if (!newUnitCommands.empty() && (newUnitCommands.back().GetID() == cmdID)) { if (cmdID == CMD_WAIT) { waitCommandsAI.RemoveWaitCommand(owner, c); } newUnitCommands.pop_back(); } else { newUnitCommands.push_back(c); } } else { bool dummy; if (CancelCommands(c, newUnitCommands, dummy) > 0) { return; } else { if (GetOverlapQueued(c, newUnitCommands).empty()) { newUnitCommands.push_back(c); } else { return; } } } } // the first new-unit build order can not be WAIT or SELFD while (!newUnitCommands.empty()) { const Command& newUnitCommand = newUnitCommands.front(); const int id = newUnitCommand.GetID(); if ((id == CMD_WAIT) || (id == CMD_SELFD)) { if (cmdID == CMD_WAIT) { waitCommandsAI.RemoveWaitCommand(owner, c); } newUnitCommands.pop_front(); } else { break; } } return; } BuildOption& bo = boi->second; int numItems = 1; if (c.options & SHIFT_KEY) { numItems *= 5; } if (c.options & CONTROL_KEY) { numItems *= 20; } if (c.options & RIGHT_MOUSE_KEY) { bo.numQued -= numItems; bo.numQued = std::max(bo.numQued, 0); int numToErase = numItems; if (c.options & ALT_KEY) { for (unsigned int cmdNum = 0; cmdNum < commandQue.size() && numToErase; ++cmdNum) { if (commandQue[cmdNum].GetID() == cmdID) { commandQue[cmdNum] = Command(CMD_STOP); numToErase--; } } } else { for (int cmdNum = commandQue.size() - 1; cmdNum != -1 && numToErase; --cmdNum) { if (commandQue[cmdNum].GetID() == cmdID) { commandQue[cmdNum] = Command(CMD_STOP); numToErase--; } } } UpdateIconName(cmdID, bo); SlowUpdate(); } else { if (c.options & ALT_KEY) { for (int a = 0; a < numItems; ++a) { if (repeatOrders) { Command nc(c); nc.options |= INTERNAL_ORDER; if (commandQue.empty()) { commandQue.push_front(nc); } else { commandQue.insert(commandQue.begin()+1, nc); } } else { commandQue.push_front(c); } } if (!repeatOrders) { CFactory* fac = static_cast<CFactory*>(owner); fac->StopBuild(); } } else { for (int a = 0; a < numItems; ++a) { commandQue.push_back(c); } } bo.numQued += numItems; UpdateIconName(cmdID, bo); SlowUpdate(); } }
void CAirCAI::GiveCommandReal(const Command& c, bool fromSynced) { // take care not to allow aircraft to be ordered to move out of the map if ((c.GetID() != CMD_MOVE) && !AllowedCommand(c, true)) { return; } else if (c.GetID() == CMD_MOVE && c.params.size() >= 3 && (c.params[0] < 0.0f || c.params[2] < 0.0f || c.params[0] > gs->mapx*SQUARE_SIZE || c.params[2] > gs->mapy*SQUARE_SIZE)) { return; } if (c.GetID() == CMD_SET_WANTED_MAX_SPEED) { return; } { CStrafeAirMoveType* airMT = GetStrafeAirMoveType(owner); if (c.GetID() == CMD_AUTOREPAIRLEVEL) { if (c.params.empty()) return; switch ((int) c.params[0]) { case 0: { airMT->SetRepairBelowHealth(0.0f); break; } case 1: { airMT->SetRepairBelowHealth(0.3f); break; } case 2: { airMT->SetRepairBelowHealth(0.5f); break; } case 3: { airMT->SetRepairBelowHealth(0.8f); break; } } for (unsigned int n = 0; n < possibleCommands.size(); n++) { if (possibleCommands[n].id != CMD_AUTOREPAIRLEVEL) continue; possibleCommands[n].params[0] = IntToString(int(c.params[0]), "%d"); break; } selectedUnitsHandler.PossibleCommandChange(owner); return; } if (c.GetID() == CMD_IDLEMODE) { if (c.params.empty()) return; switch ((int) c.params[0]) { case 0: { airMT->autoLand = false; break; } case 1: { airMT->autoLand = true; break; } } for (unsigned int n = 0; n < possibleCommands.size(); n++) { if (possibleCommands[n].id != CMD_IDLEMODE) continue; possibleCommands[n].params[0] = IntToString(int(c.params[0]), "%d"); break; } selectedUnitsHandler.PossibleCommandChange(owner); return; } if (c.GetID() == CMD_LOOPBACKATTACK) { if (c.params.empty()) return; switch ((int) c.params[0]) { case 0: { airMT->loopbackAttack = false; break; } case 1: { airMT->loopbackAttack = true; break; } } for (unsigned int n = 0; n < possibleCommands.size(); n++) { if (possibleCommands[n].id != CMD_LOOPBACKATTACK) continue; possibleCommands[n].params[0] = IntToString(int(c.params[0]), "%d"); break; } selectedUnitsHandler.PossibleCommandChange(owner); return; } } if (!(c.options & SHIFT_KEY) && nonQueingCommands.find(c.GetID()) == nonQueingCommands.end()) { activeCommand = 0; tempOrder = false; } if (c.GetID() == CMD_AREA_ATTACK && c.params.size() < 4) { Command c2(CMD_ATTACK, c.options); c2.params = c.params; CCommandAI::GiveAllowedCommand(c2); return; } CCommandAI::GiveAllowedCommand(c); }
void CAirCAI::GiveCommand(const Command &c) { if (c.id != CMD_MOVE && !AllowedCommand(c)) return; if (c.id == CMD_SET_WANTED_MAX_SPEED) { return; } if(c.id == CMD_AUTOREPAIRLEVEL){ if(c.params.empty()) return; switch((int)c.params[0]){ case 0: ((CAirMoveType*)owner->moveType)->repairBelowHealth=0; break; case 1: ((CAirMoveType*)owner->moveType)->repairBelowHealth=0.3f; break; case 2: ((CAirMoveType*)owner->moveType)->repairBelowHealth=0.5f; break; } for(vector<CommandDescription>::iterator cdi = possibleCommands.begin(); cdi != possibleCommands.end(); ++cdi){ if(cdi->id==CMD_AUTOREPAIRLEVEL){ char t[10]; SNPRINTF(t,10,"%d", (int)c.params[0]); cdi->params[0]=t; break; } } selectedUnits.PossibleCommandChange(owner); return; } if(c.id == CMD_LOOPBACKATTACK){ if(c.params.empty()) return; switch((int)c.params[0]){ case 0: ((CAirMoveType*)owner->moveType)->loopbackAttack = false; break; case 1: ((CAirMoveType*)owner->moveType)->loopbackAttack = true; break; } for(vector<CommandDescription>::iterator cdi = possibleCommands.begin(); cdi != possibleCommands.end(); ++cdi){ if(cdi->id == CMD_LOOPBACKATTACK){ char t[10]; SNPRINTF(t, 10, "%d", (int)c.params[0]); cdi->params[0] = t; break; } } selectedUnits.PossibleCommandChange(owner); return; } if(!(c.options & SHIFT_KEY) && nonQueingCommands.find(c.id) == nonQueingCommands.end()){ activeCommand=0; tempOrder=false; } if(c.id == CMD_AREA_ATTACK && c.params.size() < 4){ Command c2 = c; c2.id = CMD_ATTACK; CCommandAI::GiveAllowedCommand(c2); return; } CCommandAI::GiveAllowedCommand(c); }