From a71c3d239fbde71d3dc102296f16eca25db2b1c5 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Tue, 12 Feb 2013 03:41:59 +0000 Subject: [PATCH] - added unit auto repair a buidling if the meeting point is on that building --- source/glest_game/type_instances/unit.cpp | 28 ++++++++++++++++++----- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 7e27dc71..fb015a6f 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -1796,27 +1796,43 @@ const CommandType *Unit::computeCommandType(const Vec2i &pos, const Unit *target throw megaglest_runtime_error(szBuf); } - if(targetUnit!=NULL){ + if(targetUnit != NULL) { //attack enemies - if(!isAlly(targetUnit)){ + if(isAlly(targetUnit) == false) { commandType= type->getFirstAttackCommand(targetUnit->getCurrField()); } - //repair allies else{ commandType= type->getFirstRepairCommand(targetUnit->getType()); } } - else{ + else { //check harvest command Resource *resource= sc->getResource(); - if(resource!=NULL){ + if(resource != NULL) { commandType= type->getFirstHarvestCommand(resource->getType(),this->getFaction()); } } + // Check if we want to help build (repair) any buildings instead of just moving + if(targetUnit == NULL && commandType == NULL) { + const Vec2i unitTargetPos = pos; + Cell *cell= map->getCell(unitTargetPos); + if(cell != NULL && cell->getUnit(this->getCurrField()) != NULL) { + Unit *targetUnit = cell->getUnit(this->getCurrField()); + if(targetUnit != NULL && targetUnit->getFactionIndex() == this->getFactionIndex() && + (targetUnit->isBuilt() == false || targetUnit->isDamaged() == true)) { + const RepairCommandType *rct= this->getType()->getFirstRepairCommand(targetUnit->getType()); + if(rct != NULL) { + commandType= type->getFirstRepairCommand(targetUnit->getType()); + //printf("************ Unit will repair building built = %d, repair = %d\n",targetUnit->isBuilt(),targetUnit->isDamaged()); + } + } + } + } + //default command is move command - if(commandType==NULL){ + if(commandType == NULL) { commandType= type->getFirstCtOfClass(ccMove); }