From 72828c39a319c7f7ed1087b975de8d22cb66859f Mon Sep 17 00:00:00 2001 From: titison Date: Mon, 28 Jul 2014 17:03:36 +0200 Subject: [PATCH 1/2] Added to booleans 1. selectable | if this is false, you cant select the unit. 2. commandable | if this is false, you cant give the units commands. I advise to set a non-selectable unit to non-commandable too if you want to make a normal unit morph into it. --- source/glest_game/gui/selection.cpp | 13 ++++++++++++- source/glest_game/types/unit_type.cpp | 12 ++++++++++++ source/glest_game/types/unit_type.h | 4 ++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/source/glest_game/gui/selection.cpp b/source/glest_game/gui/selection.cpp index 8e20633b..53fac478 100644 --- a/source/glest_game/gui/selection.cpp +++ b/source/glest_game/gui/selection.cpp @@ -71,6 +71,16 @@ bool Selection::select(Unit *unit) { return false; } + //check if selectable + if(unit->getType()->isSelectable() == false) { + return false; + } + + //check if selectable + if(unit->getType()->isCommandable() == false && isEmpty() == false) { + return false; + } + //check if multisel if(unit->getType()->getMultiSelect() == false && isEmpty() == false) { return false; @@ -181,7 +191,8 @@ bool Selection::isCommandable() const { return isEmpty() == false && isEnemy() == false && - (selectedUnits.size() == 1 && selectedUnits.front()->isAlive() == false) == false; + (selectedUnits.size() == 1 && selectedUnits.front()->isAlive() == false) == false && + selectedUnits.front()->getType()->isCommandable(); } bool Selection::isCancelable() const { diff --git a/source/glest_game/types/unit_type.cpp b/source/glest_game/types/unit_type.cpp index 39129206..f45fe5ba 100644 --- a/source/glest_game/types/unit_type.cpp +++ b/source/glest_game/types/unit_type.cpp @@ -89,6 +89,8 @@ UnitType::UnitType() : ProducibleType() { lightColor= Vec3f(0.f); light= false; multiSelect= false; + selectable= true; + commandable= true; armorType= NULL; rotatedBuildPos=0; @@ -333,6 +335,14 @@ void UnitType::loaddd(int id,const string &dir, const TechTree *techTree, //multi selection multiSelect= parametersNode->getChild("multi-selection")->getAttribute("value")->getBoolValue(); + //selectable + if(parametersNode->hasChild("selectable")){ + selectable= parametersNode->getChild("selectable")->getAttribute("value")->getBoolValue(); + } + //commandable + if(parametersNode->hasChild("commandable")){ + commandable= parametersNode->getChild("commandable")->getAttribute("value")->getBoolValue(); + } //cellmap allowEmptyCellMap = false; const XmlNode *cellMapNode= parametersNode->getChild("cellmap"); @@ -1240,6 +1250,8 @@ std::string UnitType::toString() const { result += " light = " + intToStr(light); result += " lightColor = " + lightColor.getString(); result += " multiSelect = " + intToStr(multiSelect); + result += " selectable = " + intToStr(selectable); + result += " commandable = " + intToStr(commandable); result += " sight = " + intToStr(sight); result += " size = " + intToStr(size); result += " height = " + intToStr(height); diff --git a/source/glest_game/types/unit_type.h b/source/glest_game/types/unit_type.h index 1738406d..30e11cf1 100644 --- a/source/glest_game/types/unit_type.h +++ b/source/glest_game/types/unit_type.h @@ -171,6 +171,8 @@ private: bool light; Vec3f lightColor; bool multiSelect; + bool selectable; + bool commandable; int sight; int size; //size in cells int renderSize; //size to render in cells @@ -255,6 +257,8 @@ public: inline bool getRotationAllowed() const {return rotationAllowed;} inline Vec3f getLightColor() const {return lightColor;} inline bool getMultiSelect() const {return multiSelect;} + inline bool isSelectable() const {return selectable;} + inline bool isCommandable() const {return commandable;} inline int getSight() const {return sight;} inline int getSize() const {return size;} inline int getRenderSize() const {return renderSize;} From 850a9a7dc0276a375a1feeed0537a46e6a3b858a Mon Sep 17 00:00:00 2001 From: titison Date: Thu, 7 Aug 2014 21:00:27 +0200 Subject: [PATCH 2/2] -AI can't command non-commandable units anymore -Removed non-selectable --- source/glest_game/ai/ai.cpp | 86 ++++++++++++++------------- source/glest_game/gui/selection.cpp | 7 +-- source/glest_game/types/unit_type.cpp | 6 -- source/glest_game/types/unit_type.h | 2 - 4 files changed, 45 insertions(+), 56 deletions(-) diff --git a/source/glest_game/ai/ai.cpp b/source/glest_game/ai/ai.cpp index 1d35d37e..1ba96b7a 100644 --- a/source/glest_game/ai/ai.cpp +++ b/source/glest_game/ai/ai.cpp @@ -531,7 +531,7 @@ bool Ai::findAbleUnit(int *unitIndex, CommandClass ability, bool idleOnly){ *unitIndex= -1; for(int i=0; igetMyUnitCount(); ++i){ const Unit *unit= aiInterface->getMyUnit(i); - if(unit->getType()->hasCommandClass(ability)){ + if(unit->getType()->isCommandable() && unit->getType()->hasCommandClass(ability)){ if(!idleOnly || !unit->anyCommand() || unit->getCurrCommand()->getCommandType()->getClass()==ccStop){ units.push_back(i); } @@ -553,55 +553,57 @@ vector Ai::findUnitsHarvestingResourceType(const ResourceType *rt) { Map *map= aiInterface->getMap(); for(int i = 0; i < aiInterface->getMyUnitCount(); ++i) { const Unit *unit= aiInterface->getMyUnit(i); - if(unit->getType()->hasCommandClass(ccHarvest)) { - if(unit->anyCommand() && unit->getCurrCommand()->getCommandType()->getClass() == ccHarvest) { - Command *command= unit->getCurrCommand(); - const HarvestCommandType *hct= dynamic_cast(command->getCommandType()); - if(hct != NULL) { - const Vec2i unitTargetPos = unit->getTargetPos(); - SurfaceCell *sc= map->getSurfaceCell(Map::toSurfCoords(unitTargetPos)); - Resource *r= sc->getResource(); - if (r != NULL && r->getType() == rt) { - units.push_back(i); - } - } - } - } - else if(unit->getType()->hasCommandClass(ccProduce)) { - if(unit->anyCommand() && unit->getCurrCommand()->getCommandType()->getClass() == ccProduce) { - Command *command= unit->getCurrCommand(); - const ProduceCommandType *pct= dynamic_cast(command->getCommandType()); - if(pct != NULL) { - const UnitType *ut = pct->getProducedUnit(); - if(ut != NULL) { - const Resource *r = ut->getCost(rt); - if(r != NULL) { - if (r != NULL && r->getAmount() < 0) { - units.push_back(i); - } + if(unit->getType()->isCommandable()) { + if(unit->getType()->hasCommandClass(ccHarvest)) { + if(unit->anyCommand() && unit->getCurrCommand()->getCommandType()->getClass() == ccHarvest) { + Command *command= unit->getCurrCommand(); + const HarvestCommandType *hct= dynamic_cast(command->getCommandType()); + if(hct != NULL) { + const Vec2i unitTargetPos = unit->getTargetPos(); + SurfaceCell *sc= map->getSurfaceCell(Map::toSurfCoords(unitTargetPos)); + Resource *r= sc->getResource(); + if (r != NULL && r->getType() == rt) { + units.push_back(i); } - } - } + } + } } - } - else if(unit->getType()->hasCommandClass(ccBuild)) { - if(unit->anyCommand() && unit->getCurrCommand()->getCommandType()->getClass() == ccBuild) { - Command *command= unit->getCurrCommand(); - const BuildCommandType *bct= dynamic_cast(command->getCommandType()); - if(bct != NULL) { - for(int j = 0; j < bct->getBuildingCount(); ++j) { - const UnitType *ut = bct->getBuilding(j); + else if(unit->getType()->hasCommandClass(ccProduce)) { + if(unit->anyCommand() && unit->getCurrCommand()->getCommandType()->getClass() == ccProduce) { + Command *command= unit->getCurrCommand(); + const ProduceCommandType *pct= dynamic_cast(command->getCommandType()); + if(pct != NULL) { + const UnitType *ut = pct->getProducedUnit(); if(ut != NULL) { const Resource *r = ut->getCost(rt); if(r != NULL) { if (r != NULL && r->getAmount() < 0) { units.push_back(i); - break; } } } - } - } + } + } + } + else if(unit->getType()->hasCommandClass(ccBuild)) { + if(unit->anyCommand() && unit->getCurrCommand()->getCommandType()->getClass() == ccBuild) { + Command *command= unit->getCurrCommand(); + const BuildCommandType *bct= dynamic_cast(command->getCommandType()); + if(bct != NULL) { + for(int j = 0; j < bct->getBuildingCount(); ++j) { + const UnitType *ut = bct->getBuilding(j); + if(ut != NULL) { + const Resource *r = ut->getCost(rt); + if(r != NULL) { + if (r != NULL && r->getAmount() < 0) { + units.push_back(i); + break; + } + } + } + } + } + } } } } @@ -614,7 +616,7 @@ vector Ai::findUnitsDoingCommand(CommandClass currentCommand) { for(int i = 0; i < aiInterface->getMyUnitCount(); ++i) { const Unit *unit= aiInterface->getMyUnit(i); - if(unit->getType()->hasCommandClass(currentCommand)) { + if(unit->getType()->isCommandable() && unit->getType()->hasCommandClass(currentCommand)) { if(unit->anyCommand() && unit->getCurrCommand()->getCommandType()->getClass() == currentCommand) { units.push_back(i); } @@ -630,7 +632,7 @@ bool Ai::findAbleUnit(int *unitIndex, CommandClass ability, CommandClass current *unitIndex= -1; for(int i=0; igetMyUnitCount(); ++i){ const Unit *unit= aiInterface->getMyUnit(i); - if(unit->getType()->hasCommandClass(ability)){ + if(unit->getType()->isCommandable() && unit->getType()->hasCommandClass(ability)){ if(unit->anyCommand() && unit->getCurrCommand()->getCommandType()->getClass()==currentCommand){ units.push_back(i); } diff --git a/source/glest_game/gui/selection.cpp b/source/glest_game/gui/selection.cpp index 53fac478..57a0129e 100644 --- a/source/glest_game/gui/selection.cpp +++ b/source/glest_game/gui/selection.cpp @@ -71,12 +71,7 @@ bool Selection::select(Unit *unit) { return false; } - //check if selectable - if(unit->getType()->isSelectable() == false) { - return false; - } - - //check if selectable + //check if commandable if(unit->getType()->isCommandable() == false && isEmpty() == false) { return false; } diff --git a/source/glest_game/types/unit_type.cpp b/source/glest_game/types/unit_type.cpp index f45fe5ba..7fbdccf8 100644 --- a/source/glest_game/types/unit_type.cpp +++ b/source/glest_game/types/unit_type.cpp @@ -89,7 +89,6 @@ UnitType::UnitType() : ProducibleType() { lightColor= Vec3f(0.f); light= false; multiSelect= false; - selectable= true; commandable= true; armorType= NULL; rotatedBuildPos=0; @@ -335,10 +334,6 @@ void UnitType::loaddd(int id,const string &dir, const TechTree *techTree, //multi selection multiSelect= parametersNode->getChild("multi-selection")->getAttribute("value")->getBoolValue(); - //selectable - if(parametersNode->hasChild("selectable")){ - selectable= parametersNode->getChild("selectable")->getAttribute("value")->getBoolValue(); - } //commandable if(parametersNode->hasChild("commandable")){ commandable= parametersNode->getChild("commandable")->getAttribute("value")->getBoolValue(); @@ -1250,7 +1245,6 @@ std::string UnitType::toString() const { result += " light = " + intToStr(light); result += " lightColor = " + lightColor.getString(); result += " multiSelect = " + intToStr(multiSelect); - result += " selectable = " + intToStr(selectable); 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 30e11cf1..fee7f903 100644 --- a/source/glest_game/types/unit_type.h +++ b/source/glest_game/types/unit_type.h @@ -171,7 +171,6 @@ private: bool light; Vec3f lightColor; bool multiSelect; - bool selectable; bool commandable; int sight; int size; //size in cells @@ -257,7 +256,6 @@ public: inline bool getRotationAllowed() const {return rotationAllowed;} inline Vec3f getLightColor() const {return lightColor;} inline bool getMultiSelect() const {return multiSelect;} - inline bool isSelectable() const {return selectable;} inline bool isCommandable() const {return commandable;} inline int getSight() const {return sight;} inline int getSize() const {return size;}