From 7347dc95459e86e0381a227866ba9c043bdaf2f7 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sat, 8 Jan 2011 21:53:05 +0000 Subject: [PATCH] - bugfix for multi-build queued commands --- source/glest_game/game/commander.cpp | 34 +++++++------- source/glest_game/gui/gui.cpp | 55 +++++++++++----------- source/glest_game/type_instances/unit.cpp | 56 ++++++++++++----------- source/glest_game/types/command_type.cpp | 8 ++-- source/glest_game/world/unit_updater.cpp | 46 +++++++++++++++++-- 5 files changed, 120 insertions(+), 79 deletions(-) diff --git a/source/glest_game/game/commander.cpp b/source/glest_game/game/commander.cpp index 5c5ad942d..31070517c 100644 --- a/source/glest_game/game/commander.cpp +++ b/source/glest_game/game/commander.cpp @@ -144,17 +144,17 @@ CommandResult Commander::tryGiveCommand(const Unit* unit, const CommandType *com CommandResult Commander::tryGiveCommand(const Selection *selection, CommandClass commandClass, const Vec2i &pos, const Unit *targetUnit, bool tryQueue) const{ - if(!selection->isEmpty()){ + if(selection->isEmpty() == false) { Vec2i refPos, currPos; CommandResultContainer results; refPos= world->getMap()->computeRefPos(selection); //give orders to all selected units - for(int i=0; igetCount(); ++i){ + for(int i = 0; i < selection->getCount(); ++i) { const Unit *unit= selection->getUnit(i); const CommandType *ct= unit->getType()->getFirstCtOfClass(commandClass); - if(ct!=NULL){ + if(ct != NULL) { int targetId= targetUnit==NULL? Unit::invalidId: targetUnit->getId(); int unitId= selection->getUnit(i)->getId(); Vec2i currPos= world->getMap()->computeDestPos(refPos, selection->getUnit(i)->getPos(), pos); @@ -204,7 +204,7 @@ CommandResult Commander::tryGiveCommand(const Selection *selection, } //auto command -CommandResult Commander::tryGiveCommand(const Selection *selection, const Vec2i &pos, const Unit *targetUnit, bool tryQueue) const{ +CommandResult Commander::tryGiveCommand(const Selection *selection, const Vec2i &pos, const Unit *targetUnit, bool tryQueue) const { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); CommandResult result = crFailUndefined; @@ -279,19 +279,19 @@ void Commander::trySetMeetingPoint(const Unit* unit, const Vec2i &pos)const{ // ==================== PRIVATE ==================== -CommandResult Commander::computeResult(const CommandResultContainer &results) const{ - switch(results.size()){ - case 0: - return crFailUndefined; - case 1: - return results.front(); - default: - for(int i=0; iminQuadSize){ computeSelected(false,false); } @@ -395,12 +395,12 @@ void Gui::giveOneClickOrders(){ activeCommandClass= ccStop; } -void Gui::giveDefaultOrders(int x, int y){ +void Gui::giveDefaultOrders(int x, int y) { //compute target const Unit *targetUnit= NULL; Vec2i targetPos; - if(!computeTarget(Vec2i(x, y), targetPos, targetUnit)){ + if(computeTarget(Vec2i(x, y), targetPos, targetUnit) == false) { console->addStdMessage("InvalidPosition"); return; } @@ -411,7 +411,7 @@ void Gui::givePreparedDefaultOrders(int x, int y){ giveDefaultOrders(x, y, NULL,false); } -void Gui::giveDefaultOrders(int x, int y,const Unit *targetUnit, bool paintMouse3d){ +void Gui::giveDefaultOrders(int x, int y,const Unit *targetUnit, bool paintMouse3d) { bool queueKeyDown = isKeyDown(queueCommandKey); Vec2i targetPos=Vec2i(x, y); //give order @@ -419,7 +419,7 @@ void Gui::giveDefaultOrders(int x, int y,const Unit *targetUnit, bool paintMouse //graphical result addOrdersResultToConsole(activeCommandClass, result); - if(result == crSuccess || result == crSomeFailed){ + if(result == crSuccess || result == crSomeFailed) { if(paintMouse3d) mouse3d.enable(); @@ -435,7 +435,7 @@ void Gui::giveDefaultOrders(int x, int y,const Unit *targetUnit, bool paintMouse resetState(); } -void Gui::giveTwoClickOrders(int x, int y , bool prepared){ +void Gui::giveTwoClickOrders(int x, int y , bool prepared) { CommandResult result; @@ -445,9 +445,8 @@ void Gui::giveTwoClickOrders(int x, int y , bool prepared){ if(prepared){ targetPos=Vec2i(x, y); } - else - { - if(!computeTarget(Vec2i(x, y), targetPos, targetUnit)){ + else { + if(computeTarget(Vec2i(x, y), targetPos, targetUnit) == false) { console->addStdMessage("InvalidPosition"); return; } @@ -455,17 +454,17 @@ void Gui::giveTwoClickOrders(int x, int y , bool prepared){ bool queueKeyDown = isKeyDown(queueCommandKey); //give orders to the units of this faction - if(!selectingBuilding){ - if(selection.isUniform()){ + if(selectingBuilding == false) { + if(selection.isUniform()) { result= commander->tryGiveCommand(&selection, activeCommandType, targetPos, targetUnit,queueKeyDown); } - else{ + else { result= commander->tryGiveCommand(&selection, activeCommandClass, targetPos, targetUnit,queueKeyDown); } } - else{ + else { //selecting building result= commander->tryGiveCommand(&selection, activeCommandType, posObjWorld, choosenBuildingType, @@ -474,12 +473,12 @@ void Gui::giveTwoClickOrders(int x, int y , bool prepared){ //graphical result addOrdersResultToConsole(activeCommandClass, result); - if(result == crSuccess || result == crSomeFailed){ - if(!prepared){ + if(result == crSuccess || result == crSomeFailed) { + if(prepared == false) { mouse3d.enable(); } - if(random.randRange(0, 1)==0){ + if(random.randRange(0, 1) == 0) { SoundRenderer::getInstance().playFx( selection.getFrontUnit()->getType()->getCommandSound(), selection.getFrontUnit()->getCurrVector(), @@ -488,14 +487,14 @@ void Gui::giveTwoClickOrders(int x, int y , bool prepared){ } } -void Gui::centerCameraOnSelection(){ - if(!selection.isEmpty()){ +void Gui::centerCameraOnSelection() { + if(selection.isEmpty() == false) { Vec3f refPos= selection.getRefPos(); gameCamera->centerXZ(refPos.x, refPos.z); } } -void Gui::selectInterestingUnit(InterestingUnitType iut){ +void Gui::selectInterestingUnit(InterestingUnitType iut) { const Faction* thisFaction= world->getThisFaction(); const Unit* previousUnit= NULL; bool previousFound= true; @@ -916,7 +915,7 @@ void Gui::computeSelected(bool doubleClick, bool force){ } selectingBuilding= false; activeCommandType= NULL; - + //select all units of the same type if double click if(doubleClick && units.size()==1){ const Unit *refUnit= units.front(); @@ -930,15 +929,15 @@ void Gui::computeSelected(bool doubleClick, bool force){ } } } - + bool shiftDown= isKeyDown(vkShift); bool controlDown= isKeyDown(vkControl); - + if(!shiftDown && !controlDown){ SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] about to call selection.clear()\n",__FILE__,__FUNCTION__,__LINE__); selection.clear(); } - + if(!controlDown){ SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] about to call selection.select(units)\n",__FILE__,__FUNCTION__,__LINE__); selection.select(units); @@ -950,25 +949,25 @@ void Gui::computeSelected(bool doubleClick, bool force){ } } -bool Gui::computeTarget(const Vec2i &screenPos, Vec2i &targetPos, const Unit *&targetUnit){ +bool Gui::computeTarget(const Vec2i &screenPos, Vec2i &targetPos, const Unit *&targetUnit) { Selection::UnitContainer uc; Renderer &renderer= Renderer::getInstance(); renderer.computeSelected(uc, screenPos, screenPos); validPosObjWorld= false; - if(!uc.empty()){ + if(uc.empty() == false) { targetUnit= uc.front(); targetPos= targetUnit->getPos(); return true; } - else{ + else { targetUnit= NULL; - if(renderer.computePosition(screenPos, targetPos)){ + if(renderer.computePosition(screenPos, targetPos)) { validPosObjWorld= true; posObjWorld= targetPos; return true; } - else{ + else { return false; } } diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 59f9b91c2..df5784988 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -498,13 +498,13 @@ bool Unit::isInteresting(InterestingUnitType iut) const { throw runtime_error(szBuf); } - switch(iut){ + switch(iut) { case iutIdleHarvester: - if(type->hasCommandClass(ccHarvest)){ - if(!commands.empty()){ + if(type->hasCommandClass(ccHarvest)) { + if(commands.empty() == false) { const CommandType *ct= commands.front()->getCommandType(); - if(ct!=NULL){ - return ct->getClass()==ccStop; + if(ct != NULL){ + return ct->getClass() == ccStop; } } } @@ -698,7 +698,7 @@ bool Unit::anyCommand(bool validateCommandtype) const { } //return current command, assert that there is always one command -Command *Unit::getCurrCommand() const{ +Command *Unit::getCurrCommand() const { if(commands.empty() == false) { return commands.front(); } @@ -706,13 +706,13 @@ Command *Unit::getCurrCommand() const{ } void Unit::replaceCurrCommand(Command *cmd) { - assert(!commands.empty()); + assert(commands.empty() == false); commands.front() = cmd; this->setCurrentUnitTitle(""); } //returns the size of the commands -unsigned int Unit::getCommandSize() const{ +unsigned int Unit::getCommandSize() const { return commands.size(); } @@ -749,25 +749,21 @@ CommandResult Unit::giveCommand(Command *command, bool tryQueue) { chrono.start(); assert(command != NULL); - assert(command->getCommandType() != NULL); - //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Unit id = %d name = %s, Command [%s] tryQueue = %d\n", - // __FILE__,__FUNCTION__, __LINE__,this->id,(this->type != NULL ? this->type->getName().c_str() : "null"), (command != NULL ? command->toString().c_str() : "null"),tryQueue); - - //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - const int command_priority = command->getPriority(); if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); - if(command->getCommandType()->isQueuable(tryQueue)){ - + if(command->getCommandType()->isQueuable(tryQueue)) { if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] Command is Queable\n",__FILE__,__FUNCTION__,__LINE__); //Delete all lower-prioirty commands for (list::iterator i = commands.begin(); i != commands.end();) { if ((*i)->getPriority() < command_priority) { + SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] Deleting lower priority command [%s]\n",__FILE__,__FUNCTION__,__LINE__,(*i)->toString().c_str()); + deleteQueuedCommand(*i); i = commands.erase(i); } @@ -781,8 +777,10 @@ CommandResult Unit::giveCommand(Command *command, bool tryQueue) { //cancel current command if it is not queuable SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - if(!commands.empty() && !commands.back()->getCommandType()->isQueueAppendable()){ + if(commands.empty() == false && + commands.back()->getCommandType()->isQueueAppendable() == false) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] Cancel command because last one is NOT queable [%s]\n",__FILE__,__FUNCTION__,__LINE__,commands.back()->toString().c_str()); cancelCommand(); } @@ -792,6 +790,8 @@ CommandResult Unit::giveCommand(Command *command, bool tryQueue) { else { //empty command queue SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] Clear commands because current is NOT queable.\n",__FILE__,__FUNCTION__,__LINE__); + clearCommands(); if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); @@ -804,6 +804,7 @@ CommandResult Unit::giveCommand(Command *command, bool tryQueue) { //check command SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); CommandResult result= checkCommand(command); + SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] checkCommand returned: [%d]\n",__FILE__,__FUNCTION__,__LINE__,result); if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); @@ -840,7 +841,7 @@ CommandResult Unit::finishCommand() { retryCurrCommandCount=0; this->setCurrentUnitTitle(""); //is empty? - if(commands.empty()){ + if(commands.empty()) { return crFailUndefined; } @@ -849,7 +850,7 @@ CommandResult Unit::finishCommand() { commands.erase(commands.begin()); this->unitPath->clear(); - while (!commands.empty()) { + while (commands.empty() == false) { if (commands.front()->getUnit() != NULL && livingUnitsp.find(commands.front()->getUnit()) == livingUnitsp.end()) { delete commands.front(); commands.erase(commands.begin()); @@ -1298,7 +1299,7 @@ string Unit::getDesc() const { } //command info - if(!commands.empty()){ + if(commands.empty() == false) { str+= "\n" + commands.front()->getCommandType()->getName(); if(commands.size()>1){ str+="\n"+lang.get("OrdersOnQueue")+": "+intToStr(commands.size()); @@ -1437,7 +1438,7 @@ void Unit::updateTarget(){ void Unit::clearCommands() { this->setCurrentUnitTitle(""); this->unitPath->clear(); - while(!commands.empty()){ + while(commands.empty() == false) { undoCommand(commands.back()); delete commands.back(); commands.pop_back(); @@ -1445,8 +1446,7 @@ void Unit::clearCommands() { } void Unit::deleteQueuedCommand(Command *command) { - if(getCurrCommand()==command) - { + if(getCurrCommand() == command) { this->setCurrentUnitTitle(""); this->unitPath->clear(); } @@ -1465,15 +1465,17 @@ CommandResult Unit::checkCommand(Command *command) const { } //if not operative or has not command type => fail - if(!isOperative() || command->getUnit()==this || !getType()->hasCommandType(command->getCommandType())|| !this->getFaction()->reqsOk(command->getCommandType())){ + if(isOperative() == false || + command->getUnit() == this || + getType()->hasCommandType(command->getCommandType()) == false || + this->getFaction()->reqsOk(command->getCommandType()) == false) { return crFailUndefined; } SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); //if pos is not inside the world (if comand has not a pos, pos is (0, 0) and is inside world - if(!map->isInside(command->getPos())) { - + if(map->isInside(command->getPos()) == false) { return crFailUndefined; } @@ -1500,7 +1502,7 @@ CommandResult Unit::checkCommand(Command *command) const { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); //build command specific, check resources and requirements for building - if(command->getCommandType()->getClass()==ccBuild) { + if(command->getCommandType()->getClass() == ccBuild) { const UnitType *builtUnit= command->getUnitType(); if(builtUnit == NULL) { diff --git a/source/glest_game/types/command_type.cpp b/source/glest_game/types/command_type.cpp index a99fd9ad9..1464435de 100644 --- a/source/glest_game/types/command_type.cpp +++ b/source/glest_game/types/command_type.cpp @@ -314,7 +314,7 @@ string AttackStoppedCommandType::getDesc(const TotalUpgrade *totalUpgrade) const return str; } -string AttackStoppedCommandType::toString() const{ +string AttackStoppedCommandType::toString() const { Lang &lang= Lang::getInstance(); return lang.get("AttackStopped"); } @@ -325,12 +325,12 @@ string AttackStoppedCommandType::toString() const{ // ===================================================== //varios -BuildCommandType::BuildCommandType(){ +BuildCommandType::BuildCommandType() { commandTypeClass= ccBuild; clicks= cTwo; } -BuildCommandType::~BuildCommandType(){ +BuildCommandType::~BuildCommandType() { deleteValues(builtSounds.getSounds().begin(), builtSounds.getSounds().end()); deleteValues(startSounds.getSounds().begin(), startSounds.getSounds().end()); } @@ -606,7 +606,7 @@ string ProduceCommandType::getDesc(const TotalUpgrade *totalUpgrade) const{ } str+= "\n" + getProducedUnit()->getReqDesc(); - + return str; } diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index a4e10453d..035fc3fb8 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -187,7 +187,9 @@ void UnitUpdater::updateUnitCommand(Unit *unit) { //if unit has command process it if(unit->anyCommand()) { - CommandClass cc=unit->getCurrCommand()->getCommandType()->commandTypeClass; + SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] unit [%s] has command [%s]\n",__FILE__,__FUNCTION__,__LINE__,unit->toString().c_str(), unit->getCurrCommand()->toString().c_str()); + + CommandClass cc = unit->getCurrCommand()->getCommandType()->commandTypeClass; unit->getCurrCommand()->getCommandType()->update(this, unit); } @@ -195,7 +197,7 @@ void UnitUpdater::updateUnitCommand(Unit *unit) { //if no commands stop and add stop command if(unit->anyCommand() == false && unit->isOperative()) { - //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); unit->setCurrSkill(scStop); if(unit->getType()->hasCommandClass(ccStop)) { @@ -445,6 +447,7 @@ void UnitUpdater::updateBuild(Unit *unit) { chrono.start(); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] unit [%s] will build using command [%s]\n",__FILE__,__FUNCTION__,__LINE__,unit->toString().c_str(), unit->getCurrCommand()->toString().c_str()); Command *command= unit->getCurrCommand(); const BuildCommandType *bct= static_cast(command->getCommandType()); @@ -454,6 +457,7 @@ void UnitUpdater::updateBuild(Unit *unit) { if(unit->getCurrSkill()->getClass() != scBuild) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); //if not building const UnitType *ut= command->getUnitType(); @@ -486,6 +490,7 @@ void UnitUpdater::updateBuild(Unit *unit) { } SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] tsValue = %d\n",__FILE__,__FUNCTION__,__LINE__,tsValue); switch (tsValue) { case tsMoving: @@ -517,6 +522,8 @@ void UnitUpdater::updateBuild(Unit *unit) { throw runtime_error("detected unsupported pathfinder type!"); } + SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] canOccupyCell = %d\n",__FILE__,__FUNCTION__,__LINE__,canOccupyCell); + if (canOccupyCell == true) { const UnitType *builtUnitType= command->getUnitType(); CardinalDir facing = command->getFacing(); @@ -594,6 +601,7 @@ void UnitUpdater::updateBuild(Unit *unit) { } SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] got BuildingNoPlace\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] got BuildingNoPlace\n",__FILE__,__FUNCTION__,__LINE__); } } break; @@ -603,6 +611,7 @@ void UnitUpdater::updateBuild(Unit *unit) { unit->cancelCommand(); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] got tsBlocked\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] got tsBlocked\n",__FILE__,__FUNCTION__,__LINE__); } break; } @@ -611,6 +620,7 @@ void UnitUpdater::updateBuild(Unit *unit) { } else { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] tsArrived unit = %s\n",__FILE__,__FUNCTION__,__LINE__,unit->toString().c_str()); + SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] tsArrived unit = %s\n",__FILE__,__FUNCTION__,__LINE__,unit->toString().c_str()); //if building Unit *builtUnit = map->getCell(unit->getTargetPos())->getUnit(fLand); @@ -622,13 +632,17 @@ void UnitUpdater::updateBuild(Unit *unit) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] builtUnit = %s\n",__FILE__,__FUNCTION__,__LINE__,builtUnit->toString().c_str()); } + SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] builtUnit = [%p]\n",__FILE__,__FUNCTION__,__LINE__,builtUnit); + //if unit is killed while building then u==NULL; if(builtUnit != NULL && builtUnit != command->getUnit()) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] builtUnit is not the command's unit!\n",__FILE__,__FUNCTION__,__LINE__); unit->setCurrSkill(scStop); } else if(builtUnit == NULL || builtUnit->isBuilt()) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] builtUnit is NULL or ALREADY built\n",__FILE__,__FUNCTION__,__LINE__); unit->finishCommand(); unit->setCurrSkill(scStop); @@ -636,6 +650,7 @@ void UnitUpdater::updateBuild(Unit *unit) { } else if(builtUnit == NULL || builtUnit->repair()) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); //building finished unit->finishCommand(); @@ -1063,7 +1078,9 @@ Unit * UnitUpdater::findPeerUnitBuilder(Unit *unit) { if(command != NULL) { const RepairCommandType *rct= dynamic_cast(command->getCommandType()); if(rct != NULL && command->getStateType() == cst_linkedUnit) { - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] looking for command->getStateValue() = %d\n",__FILE__,__FUNCTION__,__LINE__,command->getStateValue()); + + Unit *firstLinkedPeerRepairer = NULL; for(int i = 0; i < unit->getFaction()->getUnitCount(); ++i) { Unit *peerUnit = unit->getFaction()->getUnit(i); @@ -1084,13 +1101,36 @@ Unit * UnitUpdater::findPeerUnitBuilder(Unit *unit) { break; } } + else { + SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] **peer NOT building**, peerUnit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,peerUnit->toString().c_str()); + + if(firstLinkedPeerRepairer == NULL) { + const RepairCommandType *prct = dynamic_cast(peerCommand->getCommandType()); + if(prct != NULL) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + + if(command->getStateValue() == peerUnit->getId()) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + + firstLinkedPeerRepairer = peerUnit; + break; + } + } + } + } } } } + + if(foundUnitBuilder == NULL) { + foundUnitBuilder = firstLinkedPeerRepairer; + } } } } + SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] returning foundUnitBuilder = [%s]\n",__FILE__,__FUNCTION__,__LINE__,(foundUnitBuilder != NULL ? foundUnitBuilder->toString().c_str() : "null")); + return foundUnitBuilder; }