Merge pull request #23 from titison/feature/unit_control

non commandable units
This commit is contained in:
titiger 2014-08-08 01:22:51 +02:00
commit e5d2bbbf9e
4 changed files with 59 additions and 43 deletions

View File

@ -531,7 +531,7 @@ bool Ai::findAbleUnit(int *unitIndex, CommandClass ability, bool idleOnly){
*unitIndex= -1; *unitIndex= -1;
for(int i=0; i<aiInterface->getMyUnitCount(); ++i){ for(int i=0; i<aiInterface->getMyUnitCount(); ++i){
const Unit *unit= aiInterface->getMyUnit(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){ if(!idleOnly || !unit->anyCommand() || unit->getCurrCommand()->getCommandType()->getClass()==ccStop){
units.push_back(i); units.push_back(i);
} }
@ -553,6 +553,7 @@ vector<int> Ai::findUnitsHarvestingResourceType(const ResourceType *rt) {
Map *map= aiInterface->getMap(); Map *map= aiInterface->getMap();
for(int i = 0; i < aiInterface->getMyUnitCount(); ++i) { for(int i = 0; i < aiInterface->getMyUnitCount(); ++i) {
const Unit *unit= aiInterface->getMyUnit(i); const Unit *unit= aiInterface->getMyUnit(i);
if(unit->getType()->isCommandable()) {
if(unit->getType()->hasCommandClass(ccHarvest)) { if(unit->getType()->hasCommandClass(ccHarvest)) {
if(unit->anyCommand() && unit->getCurrCommand()->getCommandType()->getClass() == ccHarvest) { if(unit->anyCommand() && unit->getCurrCommand()->getCommandType()->getClass() == ccHarvest) {
Command *command= unit->getCurrCommand(); Command *command= unit->getCurrCommand();
@ -605,6 +606,7 @@ vector<int> Ai::findUnitsHarvestingResourceType(const ResourceType *rt) {
} }
} }
} }
}
return units; return units;
} }
@ -614,7 +616,7 @@ vector<int> Ai::findUnitsDoingCommand(CommandClass currentCommand) {
for(int i = 0; i < aiInterface->getMyUnitCount(); ++i) { for(int i = 0; i < aiInterface->getMyUnitCount(); ++i) {
const Unit *unit= aiInterface->getMyUnit(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) { if(unit->anyCommand() && unit->getCurrCommand()->getCommandType()->getClass() == currentCommand) {
units.push_back(i); units.push_back(i);
} }
@ -630,7 +632,7 @@ bool Ai::findAbleUnit(int *unitIndex, CommandClass ability, CommandClass current
*unitIndex= -1; *unitIndex= -1;
for(int i=0; i<aiInterface->getMyUnitCount(); ++i){ for(int i=0; i<aiInterface->getMyUnitCount(); ++i){
const Unit *unit= aiInterface->getMyUnit(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){ if(unit->anyCommand() && unit->getCurrCommand()->getCommandType()->getClass()==currentCommand){
units.push_back(i); units.push_back(i);
} }

View File

@ -71,6 +71,11 @@ bool Selection::select(Unit *unit) {
return false; return false;
} }
//check if commandable
if(unit->getType()->isCommandable() == false && isEmpty() == false) {
return false;
}
//check if multisel //check if multisel
if(unit->getType()->getMultiSelect() == false && isEmpty() == false) { if(unit->getType()->getMultiSelect() == false && isEmpty() == false) {
return false; return false;
@ -181,7 +186,8 @@ bool Selection::isCommandable() const {
return return
isEmpty() == false && isEmpty() == false &&
isEnemy() == 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 { bool Selection::isCancelable() const {

View File

@ -89,6 +89,7 @@ UnitType::UnitType() : ProducibleType() {
lightColor= Vec3f(0.f); lightColor= Vec3f(0.f);
light= false; light= false;
multiSelect= false; multiSelect= false;
commandable= true;
armorType= NULL; armorType= NULL;
rotatedBuildPos=0; rotatedBuildPos=0;
@ -333,6 +334,10 @@ void UnitType::loaddd(int id,const string &dir, const TechTree *techTree,
//multi selection //multi selection
multiSelect= parametersNode->getChild("multi-selection")->getAttribute("value")->getBoolValue(); multiSelect= parametersNode->getChild("multi-selection")->getAttribute("value")->getBoolValue();
//commandable
if(parametersNode->hasChild("commandable")){
commandable= parametersNode->getChild("commandable")->getAttribute("value")->getBoolValue();
}
//cellmap //cellmap
allowEmptyCellMap = false; allowEmptyCellMap = false;
const XmlNode *cellMapNode= parametersNode->getChild("cellmap"); const XmlNode *cellMapNode= parametersNode->getChild("cellmap");
@ -1240,6 +1245,7 @@ std::string UnitType::toString() const {
result += " light = " + intToStr(light); result += " light = " + intToStr(light);
result += " lightColor = " + lightColor.getString(); result += " lightColor = " + lightColor.getString();
result += " multiSelect = " + intToStr(multiSelect); result += " multiSelect = " + intToStr(multiSelect);
result += " commandable = " + intToStr(commandable);
result += " sight = " + intToStr(sight); result += " sight = " + intToStr(sight);
result += " size = " + intToStr(size); result += " size = " + intToStr(size);
result += " height = " + intToStr(height); result += " height = " + intToStr(height);

View File

@ -171,6 +171,7 @@ private:
bool light; bool light;
Vec3f lightColor; Vec3f lightColor;
bool multiSelect; bool multiSelect;
bool commandable;
int sight; int sight;
int size; //size in cells int size; //size in cells
int renderSize; //size to render in cells int renderSize; //size to render in cells
@ -255,6 +256,7 @@ public:
inline bool getRotationAllowed() const {return rotationAllowed;} inline bool getRotationAllowed() const {return rotationAllowed;}
inline Vec3f getLightColor() const {return lightColor;} inline Vec3f getLightColor() const {return lightColor;}
inline bool getMultiSelect() const {return multiSelect;} inline bool getMultiSelect() const {return multiSelect;}
inline bool isCommandable() const {return commandable;}
inline int getSight() const {return sight;} inline int getSight() const {return sight;}
inline int getSize() const {return size;} inline int getSize() const {return size;}
inline int getRenderSize() const {return renderSize;} inline int getRenderSize() const {return renderSize;}