bool CCommandAI::ExecuteStateCommand(const Command& c) { switch (c.id) { case CMD_FIRE_STATE: { owner->fireState = (int)c.params[0]; SetCommandDescParam0(c); selectedUnits.PossibleCommandChange(owner); return true; } case CMD_MOVE_STATE: { owner->moveState = (int)c.params[0]; SetCommandDescParam0(c); selectedUnits.PossibleCommandChange(owner); return true; } case CMD_REPEAT: { repeatOrders = !!c.params[0]; SetCommandDescParam0(c); selectedUnits.PossibleCommandChange(owner); return true; } case CMD_TRAJECTORY: { owner->useHighTrajectory = !!c.params[0]; SetCommandDescParam0(c); selectedUnits.PossibleCommandChange(owner); return true; } case CMD_ONOFF: { if (c.params[0] == 1) { owner->Activate(); } else if (c.params[0] == 0) { owner->Deactivate(); } SetCommandDescParam0(c); selectedUnits.PossibleCommandChange(owner); return true; } case CMD_CLOAK: { if (c.params[0] == 1) { owner->wantCloak = true; } else if(c.params[0]==0) { owner->wantCloak = false; owner->curCloakTimeout = gs->frameNum + owner->cloakTimeout; } SetCommandDescParam0(c); selectedUnits.PossibleCommandChange(owner); return true; } case CMD_STOCKPILE: { int change = 1; if (c.options & RIGHT_MOUSE_KEY) { change *= -1; } if (c.options & SHIFT_KEY) { change *= 5; } if (c.options & CONTROL_KEY) { change *= 20; } stockpileWeapon->numStockpileQued += change; if (stockpileWeapon->numStockpileQued < 0) { stockpileWeapon->numStockpileQued = 0; } UpdateStockpileIcon(); return true; } } return false; }
void CCommandAI::GiveCommand(Command& c) { switch(c.id) { case CMD_FIRE_STATE: { if(c.params.empty()) return; owner->fireState=(int)c.params[0]; for(vector<CommandDescription>::iterator cdi=possibleCommands.begin();cdi!=possibleCommands.end();++cdi){ if(cdi->id==CMD_FIRE_STATE){ char t[10]; SNPRINTF(t, 10, "%d", (int)c.params[0]); cdi->params[0]=t; break; } } return; } case CMD_MOVE_STATE: { if(c.params.empty()) return; owner->moveState=(int)c.params[0]; for(vector<CommandDescription>::iterator cdi=possibleCommands.begin();cdi!=possibleCommands.end();++cdi){ if(cdi->id==CMD_MOVE_STATE){ char t[10]; SNPRINTF(t, 10, "%d", (int)c.params[0]); cdi->params[0]=t; break; } } return; } case CMD_REPEAT: { if(c.params.empty()) return; repeatOrders=!!c.params[0]; for(vector<CommandDescription>::iterator cdi=possibleCommands.begin();cdi!=possibleCommands.end();++cdi){ if(cdi->id==CMD_REPEAT){ char t[10]; SNPRINTF(t, 10, "%d", (int)c.params[0]); cdi->params[0]=t; break; } } return; } case CMD_TRAJECTORY: { if(c.params.empty() || owner->unitDef->highTrajectoryType<2) return; owner->useHighTrajectory=!!c.params[0]; for(vector<CommandDescription>::iterator cdi=possibleCommands.begin();cdi!=possibleCommands.end();++cdi){ if(cdi->id==CMD_TRAJECTORY){ char t[10]; SNPRINTF(t, 10, "%d", (int)c.params[0]); cdi->params[0]=t; break; } } return; } case CMD_ONOFF:{ if(c.params.empty() || !owner->unitDef->onoffable || owner->beingBuilt) return; if(c.params[0]==1){ owner->Activate(); } else if(c.params[0]==0) { owner->Deactivate(); } for(vector<CommandDescription>::iterator cdi=possibleCommands.begin();cdi!=possibleCommands.end();++cdi){ if(cdi->id==CMD_ONOFF){ char t[10]; SNPRINTF(t, 10, "%d", (int)c.params[0]); cdi->params[0]=t; break; } } return; } case CMD_CLOAK:{ if(c.params.empty() || !owner->unitDef->canCloak) return; if(c.params[0]==1){ owner->wantCloak=true; } else if(c.params[0]==0) { owner->wantCloak=false; owner->curCloakTimeout=gs->frameNum+owner->cloakTimeout; } for(vector<CommandDescription>::iterator cdi=possibleCommands.begin();cdi!=possibleCommands.end();++cdi){ if(cdi->id==CMD_CLOAK){ char t[10]; SNPRINTF(t, 10, "%d", (int)c.params[0]); cdi->params[0]=t; break; } } return; } case CMD_STOCKPILE:{ if(!stockpileWeapon) return; int change=1; if(c.options & RIGHT_MOUSE_KEY) change*=-1; if(c.options & CONTROL_KEY) change*=20; if(c.options & SHIFT_KEY) change*=5; stockpileWeapon->numStockpileQued+=change; if(stockpileWeapon->numStockpileQued<0) stockpileWeapon->numStockpileQued=0; UpdateStockpileIcon(); return; } case CMD_SELFD:{ if(owner->selfDCountdown){ owner->selfDCountdown=0; } else { owner->selfDCountdown = owner->unitDef->selfDCountdown*2+1; } return;} } if(!(c.options & SHIFT_KEY)){ if(!commandQue.empty()){ if(commandQue.front().id==CMD_ATTACK || commandQue.front().id==CMD_AREA_ATTACK || commandQue.front().id==CMD_DGUN) { owner->AttackUnit(0,true); } if((c.id==CMD_STOP || c.id==CMD_WAIT) && commandQue.front().id==CMD_WAIT) commandQue.pop_front(); else commandQue.clear(); } inCommand=false; if(orderTarget){ DeleteDeathDependence(orderTarget); orderTarget=0; } } if(c.id == CMD_PATROL){ std::deque<Command>::iterator ci = commandQue.begin(); for(; ci != commandQue.end() && ci->id!=CMD_PATROL; ci++); if(ci==commandQue.end()){ if(commandQue.empty()){ Command c2; c2.id = CMD_PATROL; c2.params.push_back(owner->pos.x); c2.params.push_back(owner->pos.y); c2.params.push_back(owner->pos.z); c2.options = c.options; commandQue.push_back(c2); } else { do{ ci--; if(ci->params.size() >=3){ Command c2; c2.id = CMD_PATROL; c2.params = ci->params; c2.options = c.options; commandQue.push_back(c2); ci=commandQue.begin(); } else if(ci==commandQue.begin()){ Command c2; c2.id = CMD_PATROL; c2.params.push_back(owner->pos.x); c2.params.push_back(owner->pos.y); c2.params.push_back(owner->pos.z); c2.options = c.options; commandQue.push_back(c2); } }while(ci!=commandQue.begin()); } } } std::deque<Command>::iterator ci = CCommandAI::GetCancelQueued(c); if(c.id<0 && ci != commandQue.end()){ do{ if(ci == commandQue.begin()){ commandQue.erase(ci); Command c2; c2.id = CMD_STOP; commandQue.push_front(c2); SlowUpdate(); } else { commandQue.erase(ci); } ci = CCommandAI::GetCancelQueued(c); }while(ci != commandQue.end()); return; } else if(ci != commandQue.end()){ if(ci == commandQue.begin()){ commandQue.erase(ci); Command c2; c2.id = CMD_STOP; commandQue.push_front(c2); SlowUpdate(); } else { commandQue.erase(ci); } ci = CCommandAI::GetCancelQueued(c); return; } if(!this->GetOverlapQueued(c).empty()){ return; } if(c.id==CMD_ATTACK && owner->weapons.empty() && owner->unitDef->canKamikaze==false){ //avoid weaponless units moving to 0 distance when given attack order Command c2; c2.id=CMD_STOP; commandQue.push_back(c2); return; } commandQue.push_back(c); if(commandQue.size()==1 && !owner->beingBuilt) SlowUpdate(); }
void CCommandAI::StockpileChanged(CWeapon* weapon) { UpdateStockpileIcon(); }
bool CCommandAI::ExecuteStateCommand(const Command& c) { switch (c.GetID()) { case CMD_FIRE_STATE: { owner->fireState = (int)c.params[0]; SetCommandDescParam0(c); selectedUnitsHandler.PossibleCommandChange(owner); return true; } case CMD_MOVE_STATE: { owner->moveState = (int)c.params[0]; SetCommandDescParam0(c); selectedUnitsHandler.PossibleCommandChange(owner); return true; } case CMD_REPEAT: { if (c.params[0] == 1) { repeatOrders = true; } else if(c.params[0] == 0) { repeatOrders = false; } else { // cause some code parts need it to be either 0 or 1, // we can not accept any other values as valid return false; } SetCommandDescParam0(c); selectedUnitsHandler.PossibleCommandChange(owner); return true; } case CMD_TRAJECTORY: { owner->useHighTrajectory = !!c.params[0]; SetCommandDescParam0(c); selectedUnitsHandler.PossibleCommandChange(owner); return true; } case CMD_ONOFF: { if (c.params[0] == 1) { owner->Activate(); } else if (c.params[0] == 0) { owner->Deactivate(); } else { // cause some code parts need it to be either 0 or 1, // we can not accept any other values as valid return false; } SetCommandDescParam0(c); selectedUnitsHandler.PossibleCommandChange(owner); return true; } case CMD_CLOAK: { if (c.params[0] == 1) { owner->wantCloak = true; } else if(c.params[0] == 0) { owner->wantCloak = false; owner->curCloakTimeout = gs->frameNum + owner->cloakTimeout; } else { // cause some code parts need it to be either 0 or 1, // we can not accept any other values as valid return false; } SetCommandDescParam0(c); selectedUnitsHandler.PossibleCommandChange(owner); return true; } case CMD_STOCKPILE: { int change = 1; if (c.options & RIGHT_MOUSE_KEY) { change *= -1; } if (c.options & SHIFT_KEY) { change *= 5; } if (c.options & CONTROL_KEY) { change *= 20; } stockpileWeapon->numStockpileQued += change; if (stockpileWeapon->numStockpileQued < 0) { stockpileWeapon->numStockpileQued = 0; } UpdateStockpileIcon(); return true; } } // this is a custom lua command, calling CommandFallback // and ignoring the result as this can't stay in the queue if (nonQueingCommands.find(c.GetID()) != nonQueingCommands.end()) { eventHandler.CommandFallback(owner, c); return true; } return false; }