From 5f16b486d72dc01d66236b6ba22cfba1702b535e Mon Sep 17 00:00:00 2001 From: James McCulloch Date: Wed, 14 Jul 2010 06:54:43 +0000 Subject: [PATCH] * fix for build command (problems with some cellmaps) * fix for repair command (problems if top-left cell of repairee is blocked) --- source/glest_game/world/map.cpp | 16 ++++++++++++++++ source/glest_game/world/map.h | 2 ++ source/glest_game/world/unit_updater.cpp | 13 ++++++++++--- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/source/glest_game/world/map.cpp b/source/glest_game/world/map.cpp index ec26b565..9c538639 100644 --- a/source/glest_game/world/map.cpp +++ b/source/glest_game/world/map.cpp @@ -339,6 +339,22 @@ bool Map::isAproxFreeCells(const Vec2i &pos, int size, Field field, int teamInde return true; } +bool Map::canOccupy(const Vec2i &pos, Field field, const UnitType *ut, CardinalDir facing) { + if (ut->hasCellMap()) { + for (int y=0; y < ut->getSize(); ++y) { + for (int x=0; x < ut->getSize(); ++x) { + if (ut->getCellMapCell(x, y, facing)) { + if (!isFreeCell(pos + Vec2i(x, y), field)) { + return false; + } + } + } + } + return true; + } else { + return isFreeCells(pos, ut->getSize(), field); + } +} // ==================== unit placement ==================== diff --git a/source/glest_game/world/map.h b/source/glest_game/world/map.h index 24797fb7..e4476a5e 100755 --- a/source/glest_game/world/map.h +++ b/source/glest_game/world/map.h @@ -206,6 +206,8 @@ public: bool isFreeCellsOrHasUnit(const Vec2i &pos, int size, Field field, const Unit *unit) const; bool isAproxFreeCells(const Vec2i &pos, int size, Field field, int teamIndex) const; + bool canOccupy(const Vec2i &pos, Field field, const UnitType *ut, CardinalDir facing); + //unit placement bool aproxCanMove(const Unit *unit, const Vec2i &pos1, const Vec2i &pos2) const; bool canMove(const Unit *unit, const Vec2i &pos1, const Vec2i &pos2) const; diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index baa06112..96b65bd8 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -294,8 +294,9 @@ void UnitUpdater::updateBuild(Unit *unit){ case PathFinder::tsArrived: //if arrived destination - assert(command->getUnitType()!=NULL); - if(map->isFreeCells(command->getPos(), ut->getSize(), fLand)){ + assert(ut); + if (map->canOccupy(command->getPos(), ut->getField(), ut, command->getFacing())) { + //if(map->isFreeCells(command->getPos(), ut->getSize(), fLand)){ const UnitType *builtUnitType= command->getUnitType(); CardinalDir facing = command->getFacing(); Unit *builtUnit= new Unit(world->getNextUnitId(unit->getFaction()), command->getPos(), builtUnitType, unit->getFaction(), world->getMap(), facing); @@ -510,7 +511,13 @@ void UnitUpdater::updateRepair(Unit *unit){ unit->setCurrSkill(rct->getRepairSkillType()); } else{ - switch(routePlanner->findPath(unit, command->getPos())){ + TravelState ts; + if (repaired && !repaired->getType()->isMobile()) { + ts = routePlanner->findPathToBuildSite(unit, repaired->getType(), repaired->getPos(), repaired->getModelFacing()); + } else { + ts = routePlanner->findPath(unit, command->getPos()); + } + switch(ts) { case PathFinder::tsOnTheWay: unit->setCurrSkill(rct->getMoveSkillType()); break;