void CSelectedUnits::PossibleCommandChange(CUnit* sender) { GML_RECMUTEX_LOCK(sel); // PossibleCommandChange if (sender == NULL || selectedUnits.find(sender) != selectedUnits.end()) possibleCommandsChanged = true; }
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::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::PossibleCommandChange(CUnit* sender) { if(sender==0 || selectedUnits.find(sender)!=selectedUnits.end()) possibleCommandsChanged=true; }
bool CSelectedUnits::IsUnitSelected(const CUnit* unit) const { return (selectedUnits.find(const_cast<CUnit*>(unit)) != selectedUnits.end()); }