Select only operative or non operative units with property "uniformSelecion"

This commit is contained in:
titiger 2017-03-05 00:43:37 +01:00
parent e60cbb4dec
commit 4bf3e55dfc
2 changed files with 16 additions and 13 deletions

View File

@ -1156,7 +1156,7 @@ void Gui::computeSelected(bool doubleClick, bool force){
for(int i=0; i<world->getFaction(factionIndex)->getUnitCount(); ++i){ for(int i=0; i<world->getFaction(factionIndex)->getUnitCount(); ++i){
Unit *unit= world->getFaction(factionIndex)->getUnit(i); Unit *unit= world->getFaction(factionIndex)->getUnit(i);
if(unit->getPos().dist(refUnit->getPosNotThreadSafe())<doubleClickSelectionRadius && if(unit->getPos().dist(refUnit->getPosNotThreadSafe())<doubleClickSelectionRadius &&
unit->getType()==refUnit->getType()) unit->getType()==refUnit->getType() && unit->isOperative()==refUnit->isOperative() )
{ {
units.push_back(unit); units.push_back(unit);
} }

View File

@ -83,15 +83,16 @@ bool Selection::select(Unit *unit, bool addToSelection) {
//check if multitypesel //check if multitypesel
if(selectedUnits.size() > 0) { if(selectedUnits.size() > 0) {
if(selectedUnits.front()->getType()->getUniformSelect() == true && selectedUnits.front()->getType() != unit->getType()) { bool isUnifromSelectOK = ( selectedUnits.front()->getType() == unit->getType() && unit->isOperative() == selectedUnits.front()->isOperative());
if(selectedUnits.front()->getType()->getUniformSelect() == true && !isUnifromSelectOK ) {
if(addToSelection) if(addToSelection)
return false; return false;
else else
clear(); clear();
} }
}
if(selectedUnits.size() > 0) { if (unit->getType()->getUniformSelect() == true
if(unit->getType()->getUniformSelect() == true && selectedUnits.front()->getType() != unit->getType()) { && !isUnifromSelectOK ) {
return false; return false;
} }
} }
@ -286,17 +287,19 @@ bool Selection::addUnitToGroup(int groupIndex,Unit *unit) {
} }
// check for uniformselect units // check for uniformselect units
if((int)groups[groupIndex].size()>0 ){ if((int)groups[groupIndex].size()>0 ) {
Unit* unitInGroup=groups[groupIndex][0]; Unit* unitInGroup=groups[groupIndex][0];
if( unit->getType()->getUniformSelect() && unitInGroup->getType() != unit->getType()) { if( unit->getType()->getUniformSelect() || unitInGroup->getType()->getUniformSelect() ) {
//dont add uniform selection unit if( unit->isOperative() != unitInGroup->isOperative()) {
//dont add units that are not in same operative state
return false; return false;
} }
if( unitInGroup->getType()->getUniformSelect() && unitInGroup->getType() != unit->getType()){ if( unitInGroup->getType() != unit->getType()){
//dont add another unit to a group of uniform selection units //dont add another unit to a group of uniform selection units
return false; return false;
} }
} }
}
if(unit != NULL && !groupIsFull) { if(unit != NULL && !groupIsFull) {
groups[groupIndex].push_back(unit); groups[groupIndex].push_back(unit);