From 81783e3f1bbe8797ca0a3b46a8051170dff799b4 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sun, 26 Dec 2010 04:38:03 +0000 Subject: [PATCH] - bugfix for multi-build, now units look for best cell to build but ALSO that the cell is not occupied by another unit --- source/glest_game/world/map.cpp | 13 ++++++++----- source/glest_game/world/map.h | 3 +-- source/glest_game/world/unit_updater.cpp | 17 +++++++---------- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/source/glest_game/world/map.cpp b/source/glest_game/world/map.cpp index 6de08ddf..33aed314 100644 --- a/source/glest_game/world/map.cpp +++ b/source/glest_game/world/map.cpp @@ -737,9 +737,9 @@ const Unit * Map::findClosestUnitToPos(const Selection *selection, Vec2i origina return closestUnit; } -Vec2i Map::findBestBuildApproach(Vec2i unitBuilderPos, Vec2i originalBuildPos, - const UnitType *ut) const { - Vec2i pos = originalBuildPos; +Vec2i Map::findBestBuildApproach(const Unit *unit, Vec2i originalBuildPos,const UnitType *ut) const { + Vec2i unitBuilderPos = unit->getPos(); + Vec2i pos = originalBuildPos; float bestRange = -1; @@ -752,8 +752,11 @@ Vec2i Map::findBestBuildApproach(Vec2i unitBuilderPos, Vec2i originalBuildPos, if(isInUnitTypeCells(ut, originalBuildPos,testPos) == false) { float distance = unitBuilderPos.dist(testPos); if(bestRange < 0 || bestRange > distance) { - bestRange = distance; - pos = testPos; + // Check if the cell is occupied by another unit + if(isFreeCellOrHasUnit(testPos, unit->getType()->getField(), unit) == true) { + bestRange = distance; + pos = testPos; + } } } } diff --git a/source/glest_game/world/map.h b/source/glest_game/world/map.h index a7c97909..86d6a967 100755 --- a/source/glest_game/world/map.h +++ b/source/glest_game/world/map.h @@ -228,8 +228,7 @@ public: const UnitType *ut) const; bool isInUnitTypeCells(const UnitType *ut, const Vec2i &pos,const Vec2i &testPos) const; bool isNextToUnitTypeCells(const UnitType *ut, const Vec2i &pos,const Vec2i &testPos) const; - Vec2i findBestBuildApproach(Vec2i unitBuilderPos, Vec2i originalBuildPos, - const UnitType *ut) const; + Vec2i findBestBuildApproach(const Unit *unit, Vec2i originalBuildPos,const UnitType *ut) const; std::pair getUnitDistanceToPos(const Unit *unit,Vec2i pos,const UnitType *ut); //misc diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index 46cf8326..f9214885 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -88,7 +88,7 @@ UnitUpdater::~UnitUpdater() { delete pathFinder; pathFinder = NULL; - + while(attackWarnings.empty() == false) { AttackWarningData* awd=attackWarnings.back(); attackWarnings.pop_back(); @@ -191,10 +191,7 @@ void UnitUpdater::updateUnitCommand(Unit *unit) { if(unit->isOperative() && (!(cc==ccStop || cc==ccAttack)) ) {//stop and attack already check for themselves Unit *sighted; - if(unit->getTeam()==world->getThisTeamIndex()){ - // check only needed for alarm sound, so its enough to check teammates units - attackerOnSight(unit, &sighted); - } + attackerOnSight(unit, &sighted); } unit->getCurrCommand()->getCommandType()->update(this, unit); } @@ -404,7 +401,7 @@ void UnitUpdater::updateAttack(Unit *unit) { if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); - + if(command->getUnit()!=NULL && !command->getUnit()->isAlive() && unit->getCommandSize()>1) {// don't run over to dead body if there is still something to do in the queue unit->finishCommand(); @@ -480,7 +477,7 @@ void UnitUpdater::updateBuild(Unit *unit) { case pfBasic: { //Vec2i buildPos = (command->getPos()-Vec2i(1)); - Vec2i buildPos = map->findBestBuildApproach(unit->getPos(), command->getPos(), ut); + Vec2i buildPos = map->findBestBuildApproach(unit, command->getPos(), ut); //Vec2i buildPos = (command->getPos() + Vec2i(ut->getSize() / 2)); if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true) { @@ -1176,7 +1173,7 @@ void UnitUpdater::updateRepair(Unit *unit) { else { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - Vec2i buildPos = map->findBestBuildApproach(unit->getPos(), command->getPos(), peerUnitBuilder->getCurrCommand()->getUnitType()); + Vec2i buildPos = map->findBestBuildApproach(unit, command->getPos(), peerUnitBuilder->getCurrCommand()->getUnitType()); //nextToRepaired= (unit->getPos() == (command->getPos()-Vec2i(1))); nextToRepaired = (unit->getPos() == buildPos); @@ -1794,8 +1791,8 @@ bool UnitUpdater::unitOnRange(const Unit *unit, int range, Unit **rangedPtr, } } - - if( result && + + if( result && unit->getTeam()==world->getThisTeamIndex() && //must be in local players team. !(unit->isAlly(enemySeen))) {