Skip to content

Commit

Permalink
fix #5545
Browse files Browse the repository at this point in the history
  • Loading branch information
rtri committed May 10, 2017
1 parent 2bd59c4 commit 1b07a99
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions rts/Game/UI/SelectionKeyHandler.cpp
Expand Up @@ -226,7 +226,7 @@ void CSelectionKeyHandler::DoSelection(std::string selectString)
} else if (s == "Visible") {
if (!gu->spectatingFullSelect) {
// team units in viewport
for (CUnit* unit: teamHandler->Team(gu->myTeam)->units){
for (CUnit* unit: teamHandler->Team(gu->myTeam)->units) {
if (camera->InView(unit->midPos, unit->radius))
selection.push_back(unit);
}
Expand All @@ -243,11 +243,14 @@ void CSelectionKeyHandler::DoSelection(std::string selectString)
// FromMouseC uses a cylinder shaped volume for selection,
// so the heights of the units do not matter.
const bool cylindrical = (s == "FromMouseC");

ReadDelimiter(selectString);
float maxDist=atof(ReadToken(selectString).c_str());

float dist = CGround::LineGroundCol(camera->GetPos(), camera->GetPos() + mouse->dir * 8000, false);
const float maxDist = atof(ReadToken(selectString).c_str());
const float dist = CGround::LineGroundCol(camera->GetPos(), camera->GetPos() + mouse->dir * 8000, false);

float3 mp = camera->GetPos() + mouse->dir * dist;

if (cylindrical)
mp.y = 0.0f;

Expand All @@ -263,7 +266,7 @@ void CSelectionKeyHandler::DoSelection(std::string selectString)
}
} else {
// all units in mouse range
for (CUnit *unit: unitHandler->GetActiveUnits()) {
for (CUnit* unit: unitHandler->GetActiveUnits()) {
float3 up = unit->pos;

if (cylindrical)
Expand All @@ -273,7 +276,7 @@ void CSelectionKeyHandler::DoSelection(std::string selectString)
selection.push_back(unit);
}
}
} else if(s == "PrevSelection") {
} else if (s == "PrevSelection") {
const auto& selUnits = selectedUnitsHandler.selectedUnits;

for (const int unitID: selUnits) {
Expand All @@ -292,7 +295,7 @@ void CSelectionKeyHandler::DoSelection(std::string selectString)
if (filter == "+")
break;

filter = ReadToken(selectString);
filter = std::move(ReadToken(selectString));

bool _not = false;

Expand All @@ -303,15 +306,18 @@ void CSelectionKeyHandler::DoSelection(std::string selectString)
}

Filter::Map& filters = Filter::all();
Filter::Map::iterator f = filters.find(s);
Filter::Map::iterator f = filters.find(filter);

if (f != filters.end()) {
f->second->Prepare();

for (int i = 0; i < f->second->numArgs; ++i) {
ReadDelimiter(selectString);
f->second->SetParam(i, ReadToken(selectString));
}

auto ui = selection.begin();

while (ui != selection.end()) {
if (f->second->ShouldIncludeUnit(*ui) ^ _not) {
++ui;
Expand Down Expand Up @@ -347,7 +353,7 @@ void CSelectionKeyHandler::DoSelection(std::string selectString)
if (selection.empty())
return;
if (++selectNumber >= selection.size())
selectNumber=0;
selectNumber = 0;

CUnit* sel = nullptr;
int a = 0;
Expand All @@ -359,6 +365,7 @@ void CSelectionKeyHandler::DoSelection(std::string selectString)

selectedUnitsHandler.AddUnit(sel);
camHandler->CameraTransition(0.8f);

if (camHandler->GetCurrentControllerNum() != CCameraHandler::CAMERA_MODE_FIRSTPERSON) {
camHandler->GetCurrentController().SetPos(sel->pos);
} else {
Expand Down Expand Up @@ -391,7 +398,7 @@ void CSelectionKeyHandler::DoSelection(std::string selectString)
selectedUnitsHandler.AddUnit(*ui);
}

selectNumber+=num;
selectNumber += num;
return;
}

Expand Down

0 comments on commit 1b07a99

Please sign in to comment.