void CSelectedUnits::PossibleCommandChange(CUnit* sender) { GML_RECMUTEX_LOCK(sel); // PossibleCommandChange if (sender == NULL || selectedUnits.find(sender) != selectedUnits.end()) possibleCommandsChanged = true; }
void CSelectedUnits::Draw() { glDisable(GL_DEPTH_TEST ); //glEnable(GL_BLEND); //glColor4f(0,0.8f,0,0.4f); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glColor3f(0,1.0f,0); set<CUnit*>::iterator ui; glBegin(GL_QUADS); if(selectedGroup!=-1){ for(ui=grouphandler->groups[selectedGroup]->units.begin();ui!=grouphandler->groups[selectedGroup]->units.end();++ui){ float3 pos((*ui)->pos+(*ui)->speed*gu->timeOffset); glVertexf3(pos+float3((*ui)->xsize*4,0,(*ui)->ysize*4)); glVertexf3(pos+float3(-(*ui)->xsize*4,0,(*ui)->ysize*4)); glVertexf3(pos+float3(-(*ui)->xsize*4,0,-(*ui)->ysize*4)); glVertexf3(pos+float3((*ui)->xsize*4,0,-(*ui)->ysize*4)); } } else { for(ui=selectedUnits.begin();ui!=selectedUnits.end();++ui){ float3 pos((*ui)->pos+(*ui)->speed*gu->timeOffset); glVertexf3(pos+float3((*ui)->xsize*4,0,(*ui)->ysize*4)); glVertexf3(pos+float3(-(*ui)->xsize*4,0,(*ui)->ysize*4)); glVertexf3(pos+float3(-(*ui)->xsize*4,0,-(*ui)->ysize*4)); glVertexf3(pos+float3((*ui)->xsize*4,0,-(*ui)->ysize*4)); } } glEnd(); glEnable(GL_DEPTH_TEST ); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); //glDisable(GL_BLEND); }
void CSelectedUnits::DrawCommands(void) { glDisable(GL_TEXTURE_2D); glDisable(GL_DEPTH_TEST); lineDrawer.Configure(cmdColors.UseColorRestarts(), cmdColors.UseRestartColor(), cmdColors.restart, cmdColors.RestartAlpha()); glBlendFunc((GLenum)cmdColors.QueuedBlendSrc(), (GLenum)cmdColors.QueuedBlendDst()); glEnable(GL_BLEND); glLineWidth(cmdColors.QueuedLineWidth()); set<CUnit*>::iterator ui; if(selectedGroup!=-1){ for(ui=grouphandler->groups[selectedGroup]->units.begin();ui!=grouphandler->groups[selectedGroup]->units.end();++ui){ (*ui)->commandAI->DrawCommands(); } } else { for(ui=selectedUnits.begin();ui!=selectedUnits.end();++ui){ (*ui)->commandAI->DrawCommands(); } } glLineWidth(1.0f); glEnable(GL_DEPTH_TEST); }
void CSelectedUnits::SetCommandPage(int page) { if(selectedGroup!=-1 && grouphandler->groups[selectedGroup]->ai){ grouphandler->groups[selectedGroup]->lastCommandPage=page; } if(!selectedUnits.empty()) (*selectedUnits.begin())->commandAI->lastSelectedCommandPage=page; }
void CSelectedUnits::SetCommandPage(int page) { GML_RECMUTEX_LOCK(sel); // SetCommandPage - called from CGame::Draw --> RunLayoutCommand --> LayoutIcons --> RevertToCmdDesc CUnitSet::iterator ui; for (ui = selectedUnits.begin(); ui != selectedUnits.end(); ++ui) { (*ui)->commandAI->lastSelectedCommandPage = page; } }
std::string CSelectedUnits::GetTooltip(void) { std::string s; if(selectedGroup!=-1 && grouphandler->groups[selectedGroup]->ai){ s="Group selected"; } else if(!selectedUnits.empty()){ // show the player name instead of unit name if it has FBI tag showPlayerName if((*selectedUnits.begin())->unitDef->showPlayerName) { s=gs->players[gs->Team((*selectedUnits.begin())->team)->leader]->playerName.c_str(); } else { s=(*selectedUnits.begin())->tooltip; } } if(selectedUnits.empty()){ return s; } char tmp[500]; float maxHealth=0,curHealth=0,cost=0,exp=0,range=0,metalMake=0,metalUse=0,energyMake=0,energyUse=0,maxfuel=0,curfuel=0,numfuel=0; for(set<CUnit*>::iterator ui=selectedUnits.begin();ui!=selectedUnits.end();++ui){ maxHealth+=(*ui)->maxHealth; curHealth+=(*ui)->health; exp+=(*ui)->experience; cost+=(*ui)->metalCost+(*ui)->energyCost/60; range+=(*ui)->maxRange; metalMake+=(*ui)->metalMake; metalUse+=(*ui)->metalUse; energyMake+=(*ui)->energyMake; energyUse+=(*ui)->energyUse; maxfuel+=(*ui)->unitDef->maxFuel; curfuel+=(*ui)->currentFuel; if((*ui)->unitDef->maxFuel > 0) numfuel++; } float num=selectedUnits.size(); sprintf(tmp,"\nHealth %.0f/%.0f",curHealth,maxHealth); s+=tmp; if(maxfuel>0){ sprintf(tmp," Fuel %.0f/%.0f",curfuel/numfuel,maxfuel/numfuel); s+=tmp; } sprintf(tmp,"\nExperience %.2f Cost %.0f Range %.0f \n\xff\xd3\xdb\xffMetal: \xff\x50\xff\x50%.1f\xff\x90\x90\x90/\xff\xff\x50\x01-%.1f\xff\xd3\xdb\xff Energy: \xff\x50\xff\x50%.1f\xff\x90\x90\x90/\xff\xff\x50\x01-%.1f", exp/num,cost,range/num, metalMake, metalUse, energyMake, energyUse); s += tmp; if (gs->cheatEnabled && (selectedUnits.size() == 1)) { CUnit* unit = *selectedUnits.begin(); SNPRINTF(tmp, sizeof(tmp), "\xff\xc0\xc0\xff [TechLevel %i]", unit->unitDef->techLevel); s += tmp; } return s; }
void CSelectedUnits::SendSelection(void) { // first, convert CUnit* to unit IDs. std::vector<short> selectedUnitIDs(selectedUnits.size()); std::vector<short>::iterator i = selectedUnitIDs.begin(); CUnitSet::const_iterator ui = selectedUnits.begin(); for(; ui != selectedUnits.end(); ++i, ++ui) *i = (*ui)->id; net->Send(CBaseNetProtocol::Get().SendSelect(gu->myPlayerNum, selectedUnitIDs)); selectionChanged=false; }
void CSelectedUnits::SendSelection(void) { // first, convert CUnit* to unit IDs. std::vector<short> selectedUnitIDs(selectedUnits.size()); std::vector<short>::iterator i = selectedUnitIDs.begin(); std::set<CUnit*>::const_iterator ui = selectedUnits.begin(); for(; ui != selectedUnits.end(); ++i, ++ui) *i = (*ui)->id; net->SendSTLData<unsigned char, std::vector<short> >(NETMSG_SELECT, gu->myPlayerNum, selectedUnitIDs); selectionChanged=false; }
void CSelectedUnits::SetCommandPage(int page) { if(selectedGroup!=-1 && grouphandlers[gu->myTeam]->groups[selectedGroup]->ai){ grouphandlers[gu->myTeam]->groups[selectedGroup]->lastCommandPage=page; } CUnitSet::iterator ui; for (ui = selectedUnits.begin(); ui != selectedUnits.end(); ++ui) { (*ui)->commandAI->lastSelectedCommandPage = page; } }
void CSelectedUnits::ClearSelected() { set<CUnit*>::iterator ui; ENTER_MIXED; for(ui=selectedUnits.begin();ui!=selectedUnits.end();++ui){ (*ui)->commandAI->selected=false; DeleteDeathDependence(*ui); } ENTER_UNSYNCED; selectedUnits.clear(); selectionChanged=true; possibleCommandsChanged=true; selectedGroup=-1; }
void CSelectedUnits::ClearSelected() { GML_RECMUTEX_LOCK(sel); // ClearSelected CUnitSet::iterator ui; for(ui=selectedUnits.begin();ui!=selectedUnits.end();++ui){ (*ui)->commandAI->selected=false; DeleteDeathDependence(*ui); } selectedUnits.clear(); selectionChanged=true; possibleCommandsChanged=true; selectedGroup=-1; }
void CSelectedUnits::AddUnit(CUnit* unit) { // if unit is being transported by eg. Hulk or Atlas // then we should not be able to select it if (unit->transporter != NULL && !unit->transporter->unitDef->isFirePlatform) { return; } if (unit->noSelect) { return; } selectedUnits.insert(unit); AddDeathDependence(unit); selectionChanged = true; possibleCommandsChanged = true; if (!(unit->group) || unit->group->id != selectedGroup) selectedGroup = -1; PUSH_CODE_MODE; ENTER_MIXED; unit->commandAI->selected = true; POP_CODE_MODE; }
void CSelectedUnits::AddUnit(CUnit* unit) { // if unit is being transported by eg. Hulk or Atlas // then we should not be able to select it CTransportUnit *trans=unit->GetTransporter(); if (trans != NULL && !trans->unitDef->isFirePlatform) { return; } if (unit->noSelect) { return; } GML_RECMUTEX_LOCK(sel); // AddUnit selectedUnits.insert(unit); AddDeathDependence(unit); selectionChanged = true; possibleCommandsChanged = true; if (!(unit->group) || unit->group->id != selectedGroup) selectedGroup = -1; unit->commandAI->selected = true; }
void CSelectedUnits::DrawCommands(void) { glDisable(GL_TEXTURE_2D); glDisable(GL_DEPTH_TEST); set<CUnit*>::iterator ui; if(selectedGroup!=-1){ for(ui=grouphandler->groups[selectedGroup]->units.begin();ui!=grouphandler->groups[selectedGroup]->units.end();++ui){ (*ui)->commandAI->DrawCommands(); } } else { for(ui=selectedUnits.begin();ui!=selectedUnits.end();++ui){ (*ui)->commandAI->DrawCommands(); } } glEnable(GL_DEPTH_TEST); }
void CSelectedUnits::HandleSingleUnitClickSelection(CUnit* unit, bool doInViewTest) { GML_RECMUTEX_LOCK(sel); // SelectUnits //FIXME make modular? const CMouseHandler::ButtonPressEvt& bp = mouse->buttons[SDL_BUTTON_LEFT]; if (unit == NULL) return; if (unit->team != gu->myTeam && !gu->spectatingFullSelect && !gs->godMode) return; if (bp.lastRelease < (gu->gameTime - mouse->doubleClickTime)) { if (keyInput->IsKeyPressed(SDLK_LCTRL) && (selectedUnits.find(unit) != selectedUnits.end())) { RemoveUnit(unit); } else { AddUnit(unit); } } else { //double click, select all units of same type (on screen, unless CTRL is pressed) int team, lastTeam; if (gu->spectatingFullSelect || gs->godMode) { team = 0; lastTeam = teamHandler->ActiveTeams() - 1; } else { team = gu->myTeam; lastTeam = gu->myTeam; } for (; team <= lastTeam; team++) { CUnitSet::iterator ui; CUnitSet& teamUnits = teamHandler->Team(team)->units; for (ui = teamUnits.begin(); ui != teamUnits.end(); ++ui) { if ((*ui)->unitDef->id == unit->unitDef->id) { if (!doInViewTest || keyInput->IsKeyPressed(SDLK_LCTRL) || camera->InView((*ui)->midPos)) { AddUnit(*ui); } } } } } #if (PLAY_SOUNDS == 1) Channels::UnitReply.PlayRandomSample(unit->unitDef->sounds.select, unit); #endif }
void CSelectedUnits::DependentDied(CObject *o) { GML_RECMUTEX_LOCK(sel); // DependentDied - maybe superfluous, too late anyway selectedUnits.erase((CUnit*)o); selectionChanged=true; possibleCommandsChanged=true; }
void CSelectedUnits::HandleUnitBoxSelection(const float4& planeRight, const float4& planeLeft, const float4& planeTop, const float4& planeBottom) { GML_RECMUTEX_LOCK(sel); // SelectUnits CUnit* unit = NULL; int addedunits = 0; int team, lastTeam; if (gu->spectatingFullSelect || gs->godMode) { // any team's units can be *selected* // (whether they can be given orders // depends on our ability to play god) team = 0; lastTeam = teamHandler->ActiveTeams() - 1; } else { team = gu->myTeam; lastTeam = gu->myTeam; } for (; team <= lastTeam; team++) { CUnitSet& teamUnits = teamHandler->Team(team)->units; for (CUnitSet::iterator ui = teamUnits.begin(); ui != teamUnits.end(); ++ui) { const float4 vec((*ui)->midPos, 1.0f); if (vec.dot4(planeRight) < 0.0f && vec.dot4(planeLeft) < 0.0f && vec.dot4(planeTop) < 0.0f && vec.dot4(planeBottom) < 0.0f) { if (keyInput->IsKeyPressed(SDLK_LCTRL) && (selectedUnits.find(*ui) != selectedUnits.end())) { RemoveUnit(*ui); } else { AddUnit(*ui); unit = *ui; addedunits++; } } } } #if (PLAY_SOUNDS == 1) if (addedunits >= 2) { Channels::UserInterface.PlaySample(soundMultiselID); } else if (addedunits == 1) { Channels::UnitReply.PlayRandomSample(unit->unitDef->sounds.select, unit); } #endif }
void CSelectedUnits::SendCommand(const Command& c) { if (selectionChanged) { // send new selection GML_RECMUTEX_LOCK(sel); // SendSelection // first, convert CUnit* to unit IDs. std::vector<short> selectedUnitIDs(selectedUnits.size()); std::vector<short>::iterator i = selectedUnitIDs.begin(); CUnitSet::const_iterator ui = selectedUnits.begin(); for(; ui != selectedUnits.end(); ++i, ++ui) { *i = (*ui)->id; } net->Send(CBaseNetProtocol::Get().SendSelect(gu->myPlayerNum, selectedUnitIDs)); selectionChanged = false; } net->Send(CBaseNetProtocol::Get().SendCommand(gu->myPlayerNum, c.GetID(), c.options, c.params)); }
void CSelectedUnits::RemoveUnit(CUnit* unit) { GML_RECMUTEX_LOCK(sel); // RemoveUnit if (selectedUnits.erase(unit)) DeleteDeathDependence(unit, DEPENDENCE_SELECTED); selectionChanged = true; possibleCommandsChanged = true; selectedGroup = -1; unit->isSelected = false; }
void CSelectedUnits::RemoveUnit(CUnit* unit) { GML_RECMUTEX_LOCK(sel); // RemoveUnit selectedUnits.erase(unit); DeleteDeathDependence(unit); selectionChanged=true; possibleCommandsChanged=true; selectedGroup=-1; unit->commandAI->selected=false; }
int CSelectedUnits::GetDefaultCmd(CUnit* unit, CFeature* feature) { // NOTE: the unitDef->aihint value is being ignored int luaCmd; if (eventHandler.DefaultCommand(unit, feature, luaCmd)) { return luaCmd; } if ((selectedGroup != -1) && grouphandlers[gu->myTeam]->groups[selectedGroup]->ai) { return grouphandlers[gu->myTeam]->groups[selectedGroup]->GetDefaultCmd(unit, feature); } // return the default if there are no units selected CUnitSet::const_iterator ui = selectedUnits.begin(); if (ui == selectedUnits.end()) { return CMD_STOP; } // setup the locals for IsBetterLeader() targetUnit = unit; targetFeature = feature; if (targetUnit) { targetIsEnemy = !gs->Ally(gu->myAllyTeam, targetUnit->allyteam); } // find the best leader to pick the command const CUnit* leaderUnit = *ui; const UnitDef* leaderDef = leaderUnit->unitDef; for (++ui; ui != selectedUnits.end(); ++ui) { const CUnit* testUnit = *ui; const UnitDef* testDef = testUnit->unitDef; if (testDef != leaderDef) { if (IsBetterLeader(testDef, leaderDef)) { leaderDef = testDef; leaderUnit = testUnit; } } } return (leaderUnit->commandAI->GetDefaultCmd(unit, feature)); }
// CALLINFO: // CGame::Draw --> DrawCommands // CMiniMap::DrawForReal --> DrawCommands void CSelectedUnits::DrawCommands() { glDisable(GL_TEXTURE_2D); glDisable(GL_DEPTH_TEST); lineDrawer.Configure(cmdColors.UseColorRestarts(), cmdColors.UseRestartColor(), cmdColors.restart, cmdColors.RestartAlpha()); lineDrawer.SetupLineStipple(); glEnable(GL_BLEND); glBlendFunc((GLenum)cmdColors.QueuedBlendSrc(), (GLenum)cmdColors.QueuedBlendDst()); glLineWidth(cmdColors.QueuedLineWidth()); GML_RECMUTEX_LOCK(sel); // DrawCommands GML_RECMUTEX_LOCK(group); // DrawCommands GML_STDMUTEX_LOCK(cai); // DrawCommands CUnitSet::iterator ui; if (selectedGroup != -1) { CUnitSet& groupUnits = grouphandlers[gu->myTeam]->groups[selectedGroup]->units; for(ui = groupUnits.begin(); ui != groupUnits.end(); ++ui) { (*ui)->commandAI->DrawCommands(); } } else { for(ui = selectedUnits.begin(); ui != selectedUnits.end(); ++ui) { (*ui)->commandAI->DrawCommands(); } } // draw the commands from AIs grouphandlers[gu->myTeam]->DrawCommands(); waitCommandsAI.DrawCommands(); glLineWidth(1.0f); glEnable(GL_DEPTH_TEST); }
void CSelectedUnits::RemoveUnit(CUnit* unit) { selectedUnits.erase(unit); DeleteDeathDependence(unit); selectionChanged=true; possibleCommandsChanged=true; selectedGroup=-1; PUSH_CODE_MODE; ENTER_MIXED; unit->commandAI->selected=false; POP_CODE_MODE; }
int CSelectedUnits::GetDefaultCmd(CUnit *unit,CFeature* feature) { if(selectedGroup!=-1 && grouphandler->groups[selectedGroup]->ai){ return grouphandler->groups[selectedGroup]->GetDefaultCmd(unit,feature); } int cmd=CMD_STOP; int lowestHint=10000;//find better way to decide CUnit* selected=0; int i = 0; for(set<CUnit*>::iterator ui=selectedUnits.begin();ui!=selectedUnits.end();++ui){ if((!(*ui)->immobile || (i==selectedUnits.size() - 1 && lowestHint == 10000)) && (*ui)->aihint<lowestHint) { selected=*ui; lowestHint=(*ui)->aihint; } i++; } if(selected) cmd=selected->commandAI->GetDefaultCmd(unit,feature); return cmd; }
void CSelectedUnits::Draw() { glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); // for line smoothing glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glLineWidth(cmdColors.UnitBoxLineWidth()); glColor4fv(cmdColors.unitBox); glBegin(GL_QUADS); set<CUnit*>::iterator ui; if(selectedGroup!=-1){ for(ui=grouphandler->groups[selectedGroup]->units.begin();ui!=grouphandler->groups[selectedGroup]->units.end();++ui){ if((*ui)->isIcon) continue; float3 pos((*ui)->pos+(*ui)->speed*gu->timeOffset); glVertexf3(pos+float3((*ui)->xsize*4,0,(*ui)->ysize*4)); glVertexf3(pos+float3(-(*ui)->xsize*4,0,(*ui)->ysize*4)); glVertexf3(pos+float3(-(*ui)->xsize*4,0,-(*ui)->ysize*4)); glVertexf3(pos+float3((*ui)->xsize*4,0,-(*ui)->ysize*4)); } } else { for(ui=selectedUnits.begin();ui!=selectedUnits.end();++ui){ if((*ui)->isIcon) continue; float3 pos((*ui)->pos+(*ui)->speed*gu->timeOffset); glVertexf3(pos+float3((*ui)->xsize*4,0,(*ui)->ysize*4)); glVertexf3(pos+float3(-(*ui)->xsize*4,0,(*ui)->ysize*4)); glVertexf3(pos+float3(-(*ui)->xsize*4,0,-(*ui)->ysize*4)); glVertexf3(pos+float3((*ui)->xsize*4,0,-(*ui)->ysize*4)); } } glEnd(); glLineWidth(1.0f); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glDisable(GL_BLEND); glEnable(GL_DEPTH_TEST); }
void CSelectedUnits::AddUnit(CUnit* unit) { selectedUnits.insert(unit); AddDeathDependence(unit); selectionChanged=true; possibleCommandsChanged=true; if(!(unit->group) || unit->group->id != selectedGroup) selectedGroup=-1; PUSH_CODE_MODE; ENTER_MIXED; unit->commandAI->selected=true; POP_CODE_MODE; }
// CALLINFO: // DrawMapStuff --> CGuiHandler::GetDefaultCommand --> GetDefaultCmd // CMouseHandler::DrawCursor --> DrawCentroidCursor --> CGuiHandler::GetDefaultCommand --> GetDefaultCmd // LuaUnsyncedRead::GetDefaultCommand --> CGuiHandler::GetDefaultCommand --> GetDefaultCmd int CSelectedUnits::GetDefaultCmd(const CUnit* unit, const CFeature* feature) { int luaCmd; if (eventHandler.DefaultCommand(unit, feature, luaCmd)) { return luaCmd; } GML_RECMUTEX_LOCK(sel); // GetDefaultCmd // return the default if there are no units selected CUnitSet::const_iterator ui = selectedUnits.begin(); if (ui == selectedUnits.end()) { return CMD_STOP; } // setup the locals for IsBetterLeader() targetUnit = unit; targetFeature = feature; if (targetUnit) { targetIsEnemy = !teamHandler->Ally(gu->myAllyTeam, targetUnit->allyteam); } // find the best leader to pick the command const CUnit* leaderUnit = *ui; const UnitDef* leaderDef = leaderUnit->unitDef; for (++ui; ui != selectedUnits.end(); ++ui) { const CUnit* testUnit = *ui; const UnitDef* testDef = testUnit->unitDef; if (testDef != leaderDef) { if (IsBetterLeader(testDef, leaderDef)) { leaderDef = testDef; leaderUnit = testUnit; } } } return (leaderUnit->commandAI->GetDefaultCmd(unit, feature)); }
void CSelectedUnits::SelectGroup(int num) { ClearSelected(); selectedGroup=num; CGroup* group=grouphandler->groups[num]; set<CUnit*>::iterator ui; ENTER_MIXED; for(ui=group->units.begin();ui!=group->units.end();++ui){ (*ui)->commandAI->selected=true; selectedUnits.insert(*ui); AddDeathDependence(*ui); } ENTER_UNSYNCED; possibleCommandsChanged=true; selectionChanged=true; }
void CSelectedUnits::SelectGroup(int num) { GML_RECMUTEX_LOCK(grpsel); // SelectGroup - not needed? only reading group ClearSelected(); selectedGroup=num; CGroup* group=grouphandlers[gu->myTeam]->groups[num]; CUnitSet::iterator ui; for (ui = group->units.begin(); ui != group->units.end(); ++ui) { if (!(*ui)->noSelect) { (*ui)->commandAI->selected = true; selectedUnits.insert(*ui); AddDeathDependence(*ui); } } selectionChanged = true; possibleCommandsChanged = true; }
CSelectedUnits::AvailableCommandsStruct CSelectedUnits::GetAvailableCommands() { GML_RECMUTEX_LOCK(sel); // GetAvailableCommands GML_RECMUTEX_LOCK(group); // GetAvailableCommands possibleCommandsChanged = false; int commandPage = 1000; int foundGroup = -2; int foundGroup2 = -2; map<int, int> states; for (CUnitSet::iterator ui = selectedUnits.begin(); ui != selectedUnits.end(); ++ui) { vector<CommandDescription>* c = &(*ui)->commandAI->GetPossibleCommands(); vector<CommandDescription>::iterator ci; for (ci = c->begin(); ci != c->end(); ++ci) { states[ci->id] = ci->disabled ? 2 : 1; } if ((*ui)->commandAI->lastSelectedCommandPage < commandPage) { commandPage = (*ui)->commandAI->lastSelectedCommandPage; } if (foundGroup == -2 && (*ui)->group) { foundGroup = (*ui)->group->id; } if (!(*ui)->group || foundGroup!=(*ui)->group->id) { foundGroup = -1; } if (foundGroup2 == -2 && (*ui)->group) { foundGroup2 = (*ui)->group->id; } if (foundGroup2 >= 0 && (*ui)->group && (*ui)->group->id != foundGroup2) { foundGroup2 = -1; } } vector<CommandDescription> groupCommands; vector<CommandDescription> commands ; // load the first set (separating build and non-build commands) for (CUnitSet::iterator ui = selectedUnits.begin(); ui != selectedUnits.end(); ++ui) { vector<CommandDescription>* c = &(*ui)->commandAI->GetPossibleCommands(); vector<CommandDescription>::iterator ci; for (ci = c->begin(); ci != c->end(); ++ci) { if (buildIconsFirst) { if (ci->id >= 0) { continue; } } else { if (ci->id < 0) { continue; } } if (ci->showUnique && selectedUnits.size() > 1) { continue; } if (states[ci->id] > 0) { commands.push_back(*ci); states[ci->id] = 0; } } } if (!buildIconsFirst && !gs->noHelperAIs) { vector<CommandDescription>::iterator ci; for(ci = groupCommands.begin(); ci != groupCommands.end(); ++ci) { commands.push_back(*ci); } } // load the second set (all those that have not already been included) for (CUnitSet::iterator ui = selectedUnits.begin(); ui != selectedUnits.end(); ++ui) { vector<CommandDescription>* c = &(*ui)->commandAI->GetPossibleCommands(); vector<CommandDescription>::iterator ci; for (ci = c->begin(); ci != c->end(); ++ci) { if (buildIconsFirst) { if (ci->id < 0) { continue; } } else { if (ci->id >= 0) { continue; } } if (ci->showUnique && selectedUnits.size() > 1) { continue; } if (states[ci->id] > 0) { commands.push_back(*ci); states[ci->id] = 0; } } } if (buildIconsFirst && !gs->noHelperAIs) { vector<CommandDescription>::iterator ci; for (ci = groupCommands.begin(); ci != groupCommands.end(); ++ci) { commands.push_back(*ci); } } AvailableCommandsStruct ac; ac.commandPage = commandPage; ac.commands = commands; return ac; }