From ff586afd0df3aff5bac193615b41205851f80c32 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Wed, 21 Jul 2010 22:05:50 +0000 Subject: [PATCH] - some final updates to get the new pathfinder working after adding multi-pathing support --- source/glest_game/ai/path_finder.cpp | 8 ++-- source/glest_game/game/game_constants.h | 1 - source/glest_game/type_instances/unit.h | 3 ++ source/glest_game/world/unit_updater.cpp | 51 ++++++++++++++---------- source/glest_game/world/unit_updater.h | 5 ++- 5 files changed, 39 insertions(+), 29 deletions(-) diff --git a/source/glest_game/ai/path_finder.cpp b/source/glest_game/ai/path_finder.cpp index db21189a..f0b280d7 100644 --- a/source/glest_game/ai/path_finder.cpp +++ b/source/glest_game/ai/path_finder.cpp @@ -72,7 +72,7 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos){ Vec2i pos= basicPath->pop(); if(map->canMove(unit, unit->getPos(), pos)) { unit->setTargetPos(pos); - return tsOnTheWay; + return tsMoving; } } else if(dynamic_cast(path) != NULL) { @@ -82,7 +82,7 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos){ if(map->canMove(unit, unit->getPos(), pos)) { advPath->pop(); unit->setTargetPos(pos); - return tsOnTheWay; + return tsMoving; } } else { @@ -100,7 +100,7 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos){ case tsArrived: unit->setCurrSkill(scStop); break; - case tsOnTheWay: + case tsMoving: { if(dynamic_cast(path) != NULL) { UnitPathBasic *basicPath = dynamic_cast(path); @@ -229,7 +229,7 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos){ } else { //on the way - ts= tsOnTheWay; + ts= tsMoving; //build next pointers Node *currNode= lastNode; diff --git a/source/glest_game/game/game_constants.h b/source/glest_game/game/game_constants.h index 8d7f1290..7b58e989 100644 --- a/source/glest_game/game/game_constants.h +++ b/source/glest_game/game/game_constants.h @@ -30,7 +30,6 @@ enum TravelState { tsArrived, tsMoving, tsBlocked, - tsOnTheWay, tsImpossible }; diff --git a/source/glest_game/type_instances/unit.h b/source/glest_game/type_instances/unit.h index 5656443b..9ed7edb4 100644 --- a/source/glest_game/type_instances/unit.h +++ b/source/glest_game/type_instances/unit.h @@ -152,6 +152,9 @@ public: virtual void clear() {list::clear(); blockCount = 0;} /**< clear the path */ virtual void incBlockCount() {++blockCount;} /**< increment block counter */ virtual void push(const Vec2i &pos) {push_front(pos);} /**< push onto front of path */ + bool empty() const {return list::empty();} /**< is path empty */ + void push(Vec2i &pos) {push_front(pos);} /**< push onto front of path */ + #if 0 // old style, to work with original PathFinder diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index 7214171a..0b711083 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -14,21 +14,22 @@ #include #include -#include "sound.h" -#include "upgrade.h" -#include "unit.h" -#include "particle_type.h" +#include "cartographer.h" #include "core_data.h" #include "config.h" -#include "renderer.h" -#include "sound_renderer.h" #include "game.h" -#include "path_finder.h" -#include "object.h" #include "faction.h" #include "network_manager.h" -#include "cartographer.h" +#include "object.h" +#include "particle_type.h" +#include "path_finder.h" +#include "renderer.h" #include "route_planner.h" +#include "sound.h" +#include "sound_renderer.h" +#include "upgrade.h" +#include "unit.h" + #include "leak_dumper.h" using namespace Shared::Graphics; @@ -52,10 +53,12 @@ void UnitUpdater::init(Game *game){ this->console= game->getConsole(); this->scriptManager= game->getScriptManager(); this->routePlanner = NULL; + this->pathFinder = NULL; switch(this->game->getGameSettings()->getPathFinderType()) { case pfBasic: - pathFinder.init(map); + pathFinder = new PathFinder(); + pathFinder->init(map); break; case pfRoutePlanner: routePlanner = world->getRoutePlanner(); @@ -65,6 +68,10 @@ void UnitUpdater::init(Game *game){ } } +UnitUpdater::~UnitUpdater() { + delete pathFinder; + pathFinder = NULL; +} // ==================== progress skills ==================== @@ -203,7 +210,7 @@ void UnitUpdater::updateMove(Unit *unit){ TravelState tsValue = tsImpossible; switch(this->game->getGameSettings()->getPathFinderType()) { case pfBasic: - tsValue = pathFinder.findPath(unit, pos); + tsValue = pathFinder->findPath(unit, pos); break; case pfRoutePlanner: tsValue = routePlanner->findPath(unit, pos); @@ -213,7 +220,7 @@ void UnitUpdater::updateMove(Unit *unit){ } switch (tsValue) { - case tsOnTheWay: + case tsMoving: unit->setCurrSkill(mct->getMoveSkillType()); break; @@ -264,7 +271,7 @@ void UnitUpdater::updateAttack(Unit *unit){ TravelState tsValue = tsImpossible; switch(this->game->getGameSettings()->getPathFinderType()) { case pfBasic: - tsValue = pathFinder.findPath(unit, pos); + tsValue = pathFinder->findPath(unit, pos); break; case pfRoutePlanner: tsValue = routePlanner->findPath(unit, pos); @@ -275,7 +282,7 @@ void UnitUpdater::updateAttack(Unit *unit){ //if unit arrives destPos order has ended switch (tsValue){ - case tsOnTheWay: + case tsMoving: unit->setCurrSkill(act->getMoveSkillType()); break; case tsBlocked: @@ -322,7 +329,7 @@ void UnitUpdater::updateBuild(Unit *unit){ TravelState tsValue = tsImpossible; switch(this->game->getGameSettings()->getPathFinderType()) { case pfBasic: - tsValue = pathFinder.findPath(unit, command->getPos()-Vec2i(1)); + tsValue = pathFinder->findPath(unit, command->getPos()-Vec2i(1)); break; case pfRoutePlanner: tsValue = routePlanner->findPathToBuildSite(unit, ut, command->getPos(), command->getFacing()); @@ -332,7 +339,7 @@ void UnitUpdater::updateBuild(Unit *unit){ } switch (tsValue) { - case tsOnTheWay: + case tsMoving: unit->setCurrSkill(bct->getMoveSkillType()); break; @@ -506,8 +513,8 @@ void UnitUpdater::updateHarvest(Unit *unit){ TravelState tsValue = tsImpossible; switch(this->game->getGameSettings()->getPathFinderType()) { case pfBasic: - tsValue = pathFinder.findPath(unit, command->getPos()); - if (tsValue == tsOnTheWay) { + tsValue = pathFinder->findPath(unit, command->getPos()); + if (tsValue == tsMoving) { unit->setCurrSkill(hct->getMoveSkillType()); } break; @@ -537,7 +544,7 @@ void UnitUpdater::updateHarvest(Unit *unit){ TravelState tsValue = tsImpossible; switch(this->game->getGameSettings()->getPathFinderType()) { case pfBasic: - tsValue = pathFinder.findPath(unit, store->getCenteredPos()); + tsValue = pathFinder->findPath(unit, store->getCenteredPos()); break; case pfRoutePlanner: tsValue = routePlanner->findPathToStore(unit, store); @@ -547,7 +554,7 @@ void UnitUpdater::updateHarvest(Unit *unit){ } switch(tsValue) { - case tsOnTheWay: + case tsMoving: unit->setCurrSkill(hct->getMoveLoadedSkillType()); break; default: @@ -657,7 +664,7 @@ void UnitUpdater::updateRepair(Unit *unit){ TravelState ts; switch(this->game->getGameSettings()->getPathFinderType()) { case pfBasic: - ts = pathFinder.findPath(unit, command->getPos()); + ts = pathFinder->findPath(unit, command->getPos()); break; case pfRoutePlanner: if (repaired && !repaired->getType()->isMobile()) { @@ -672,7 +679,7 @@ void UnitUpdater::updateRepair(Unit *unit){ } switch(ts) { - case tsOnTheWay: + case tsMoving: unit->setCurrSkill(rct->getMoveSkillType()); break; case tsBlocked: diff --git a/source/glest_game/world/unit_updater.h b/source/glest_game/world/unit_updater.h index 2f3c9ee3..5a14bd5f 100644 --- a/source/glest_game/world/unit_updater.h +++ b/source/glest_game/world/unit_updater.h @@ -13,7 +13,6 @@ #define _GLEST_GAME_UNITUPDATER_H_ #include "gui.h" -#include "path_finder.h" #include "particle.h" #include "randomgen.h" @@ -25,6 +24,7 @@ namespace Glest{ namespace Game{ class Unit; class Map; class ScriptManager; +class PathFinder; class RoutePlanner; // ===================================================== @@ -54,13 +54,14 @@ private: World *world; Console *console; ScriptManager *scriptManager; - PathFinder pathFinder; + PathFinder *pathFinder; RoutePlanner *routePlanner; Game *game; RandomGen random; public: void init(Game *game); + ~UnitUpdater(); //update skills void updateUnit(Unit *unit);