From 74ed3d73bed73bbf3c6586c3e182576a9954ae8e Mon Sep 17 00:00:00 2001 From: titison Date: Tue, 23 Aug 2016 14:46:44 +0200 Subject: [PATCH] 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 `````` to the `````` tag of a unit. --- source/glest_game/gui/selection.cpp | 23 +++++++++++++++++++++++ source/glest_game/types/unit_type.cpp | 7 +++++++ source/glest_game/types/unit_type.h | 2 ++ 3 files changed, 32 insertions(+) diff --git a/source/glest_game/gui/selection.cpp b/source/glest_game/gui/selection.cpp index 109164db..3429fff1 100644 --- a/source/glest_game/gui/selection.cpp +++ b/source/glest_game/gui/selection.cpp @@ -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; diff --git a/source/glest_game/types/unit_type.cpp b/source/glest_game/types/unit_type.cpp index 776f13c1..e2babacb 100644 --- a/source/glest_game/types/unit_type.cpp +++ b/source/glest_game/types/unit_type.cpp @@ -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); diff --git a/source/glest_game/types/unit_type.h b/source/glest_game/types/unit_type.h index eca85e91..27604710 100644 --- a/source/glest_game/types/unit_type.h +++ b/source/glest_game/types/unit_type.h @@ -192,6 +192,7 @@ private: float healthbarthickness; int healthbarVisible; bool multiSelect; + bool uniformSelect; bool commandable; int sight; int size; //size in cells @@ -283,6 +284,7 @@ public: 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;}