diff --git a/source/glest_game/game/commander.cpp b/source/glest_game/game/commander.cpp index 0f230b0b..1abe099f 100644 --- a/source/glest_game/game/commander.cpp +++ b/source/glest_game/game/commander.cpp @@ -90,14 +90,16 @@ CommandResult Commander::tryGiveCommand(const Selection *selection, const Comman } } - NetworkCommand networkCommand(this->world,nctGiveCommand, unitId, - useCommandtype->getId(), usePos, unitType->getId(), - (targetUnit != NULL ? targetUnit->getId() : -1), - facing, tryQueue, commandStateType,commandStateValue); + if(useCommandtype != NULL) { + NetworkCommand networkCommand(this->world,nctGiveCommand, unitId, + useCommandtype->getId(), usePos, unitType->getId(), + (targetUnit != NULL ? targetUnit->getId() : -1), + facing, tryQueue, commandStateType,commandStateValue); - //every unit is ordered to a the position - CommandResult result= pushNetworkCommand(&networkCommand); - results.push_back(result); + //every unit is ordered to a the position + CommandResult result= pushNetworkCommand(&networkCommand); + results.push_back(result); + } } return computeResult(results); diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index 362b80d1..72a919bf 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -810,19 +810,19 @@ void UnitUpdater::updateRepair(Unit *unit) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] rct = %p\n",__FILE__,__FUNCTION__,__LINE__,rct); - Unit *repaired= map->getCell(command->getPos())->getUnit(fLand); - bool nextToRepaired= repaired!=NULL && map->isNextTo(unit->getPos(), repaired); + Unit *repaired = map->getCell(command->getPos())->getUnit(fLand); + bool nextToRepaired = repaired != NULL && map->isNextTo(unit->getPos(), repaired); Unit *peerUnitBuilder = NULL; if(repaired == NULL) { peerUnitBuilder = findPeerUnitBuilder(unit); - if(peerUnitBuilder != NULL) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] peerUnitBuilder = %p\n",__FILE__,__FUNCTION__,__LINE__,peerUnitBuilder); - // command->getPos()-Vec2i(1) - //nextToRepaired= map->isNextTo(unit->getPos(), command->getPos()-Vec2i(1)); - nextToRepaired= (unit->getPos() == (command->getPos()-Vec2i(1))); + Vec2i buildPos = map->findBestBuildApproach(unit->getPos(), command->getPos(), peerUnitBuilder->getCurrCommand()->getUnitType()); + + //nextToRepaired= (unit->getPos() == (command->getPos()-Vec2i(1))); + nextToRepaired = (unit->getPos() == buildPos); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] peerUnitBuilder = %p, nextToRepaired = %d\n",__FILE__,__FUNCTION__,__LINE__,peerUnitBuilder,nextToRepaired);