Skip to content
Permalink
Browse files
Uniformselection
Added uniform selection of units.
Uniform means you can select multiple units, but only of the same type.
To make a unit uniform-selectable you need to add
```<uniform-selection value="true"/>```
to the ```<parameters>``` tag of a unit.
  • Loading branch information
titison committed Aug 23, 2016
1 parent 3639e11 commit 74ed3d73bed73bbf3c6586c3e182576a9954ae8e
Showing with 32 additions and 0 deletions.
  1. +23 −0 source/glest_game/gui/selection.cpp
  2. +7 −0 source/glest_game/types/unit_type.cpp
  3. +2 −0 source/glest_game/types/unit_type.h
@@ -81,6 +81,16 @@ bool Selection::select(Unit *unit) {
return false;
}

//check if multitypesel
if(selectedUnits.size() > 0) {
if(selectedUnits.front()->getType()->getUniformSelect() == true && selectedUnits.front()->getType() != unit->getType()) {
return false;
}
if(unit->getType()->getUniformSelect() == true && selectedUnits.front()->getType() != unit->getType()) {
return false;
}
}

//check if enemy
if(canSelectUnitFactionCheck(unit) == false && isEmpty() == false) {
return false;
@@ -270,6 +280,19 @@ bool Selection::addUnitToGroup(int groupIndex,Unit *unit) {
}
}

// check for uniformselect units
if((int)groups[groupIndex].size()>0 ){
Unit* unitInGroup=groups[groupIndex][0];
if( unit->getType()->getUniformSelect() && unitInGroup->getType() != unit->getType()) {
//dont add uniform selection unit
return false;
}
if( unitInGroup->getType()->getUniformSelect() && unitInGroup->getType() != unit->getType()){
//dont add another unit to a group of uniform selection units
return false;
}
}

if(unit != NULL && !groupIsFull) {
groups[groupIndex].push_back(unit);
return true;
@@ -93,6 +93,7 @@ UnitType::UnitType() : ProducibleType() {
healthbarthickness=-1.0f;
healthbarVisible=hbvUndefined;
multiSelect= false;
uniformSelect= false;
commandable= true;
armorType= NULL;
rotatedBuildPos=0;
@@ -356,6 +357,11 @@ void UnitType::loaddd(int id,const string &dir, const TechTree *techTree,
//multi selection
multiSelect= parametersNode->getChild("multi-selection")->getAttribute("value")->getBoolValue();

//uniform selection
if(parametersNode->hasChild("uniform-selection")) {
uniformSelect= parametersNode->getChild("uniform-selection")->getAttribute("value")->getBoolValue();
}

//commandable
if(parametersNode->hasChild("commandable")){
commandable= parametersNode->getChild("commandable")->getAttribute("value")->getBoolValue();
@@ -1307,6 +1313,7 @@ std::string UnitType::toString() const {
result += " light = " + intToStr(light);
result += " lightColor = " + lightColor.getString();
result += " multiSelect = " + intToStr(multiSelect);
result += " uniformSelect = " + intToStr(uniformSelect);
result += " commandable = " + intToStr(commandable);
result += " sight = " + intToStr(sight);
result += " size = " + intToStr(size);
@@ -192,6 +192,7 @@ class UnitType: public ProducibleType, public ValueCheckerVault {
float healthbarthickness;
int healthbarVisible;
bool multiSelect;
bool uniformSelect;
bool commandable;
int sight;
int size; //size in cells
@@ -283,6 +284,7 @@ class UnitType: public ProducibleType, public ValueCheckerVault {
inline float getHealthbarThickness() const {return healthbarthickness;}
inline int getHealthbarVisible() const {return healthbarVisible;}
inline bool getMultiSelect() const {return multiSelect;}
inline bool getUniformSelect() const {return uniformSelect;}
inline bool isCommandable() const {return commandable;}
inline int getSight() const {return sight;}
inline int getSize() const {return size;}

0 comments on commit 74ed3d7

Please sign in to comment.