- some final updates to get the new pathfinder working after adding multi-pathing support

This commit is contained in:
Mark Vejvoda 2010-07-21 22:05:50 +00:00
parent 77ee50b681
commit ff586afd0d
5 changed files with 39 additions and 29 deletions

View File

@ -72,7 +72,7 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos){
Vec2i pos= basicPath->pop(); Vec2i pos= basicPath->pop();
if(map->canMove(unit, unit->getPos(), pos)) { if(map->canMove(unit, unit->getPos(), pos)) {
unit->setTargetPos(pos); unit->setTargetPos(pos);
return tsOnTheWay; return tsMoving;
} }
} }
else if(dynamic_cast<UnitPath *>(path) != NULL) { else if(dynamic_cast<UnitPath *>(path) != NULL) {
@ -82,7 +82,7 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos){
if(map->canMove(unit, unit->getPos(), pos)) { if(map->canMove(unit, unit->getPos(), pos)) {
advPath->pop(); advPath->pop();
unit->setTargetPos(pos); unit->setTargetPos(pos);
return tsOnTheWay; return tsMoving;
} }
} }
else { else {
@ -100,7 +100,7 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos){
case tsArrived: case tsArrived:
unit->setCurrSkill(scStop); unit->setCurrSkill(scStop);
break; break;
case tsOnTheWay: case tsMoving:
{ {
if(dynamic_cast<UnitPathBasic *>(path) != NULL) { if(dynamic_cast<UnitPathBasic *>(path) != NULL) {
UnitPathBasic *basicPath = dynamic_cast<UnitPathBasic *>(path); UnitPathBasic *basicPath = dynamic_cast<UnitPathBasic *>(path);
@ -229,7 +229,7 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos){
} }
else { else {
//on the way //on the way
ts= tsOnTheWay; ts= tsMoving;
//build next pointers //build next pointers
Node *currNode= lastNode; Node *currNode= lastNode;

View File

@ -30,7 +30,6 @@ enum TravelState {
tsArrived, tsArrived,
tsMoving, tsMoving,
tsBlocked, tsBlocked,
tsOnTheWay,
tsImpossible tsImpossible
}; };

View File

@ -152,6 +152,9 @@ public:
virtual void clear() {list<Vec2i>::clear(); blockCount = 0;} /**< clear the path */ virtual void clear() {list<Vec2i>::clear(); blockCount = 0;} /**< clear the path */
virtual void incBlockCount() {++blockCount;} /**< increment block counter */ virtual void incBlockCount() {++blockCount;} /**< increment block counter */
virtual void push(const Vec2i &pos) {push_front(pos);} /**< push onto front of path */ virtual void push(const Vec2i &pos) {push_front(pos);} /**< push onto front of path */
bool empty() const {return list<Vec2i>::empty();} /**< is path empty */
void push(Vec2i &pos) {push_front(pos);} /**< push onto front of path */
#if 0 #if 0
// old style, to work with original PathFinder // old style, to work with original PathFinder

View File

@ -14,21 +14,22 @@
#include <algorithm> #include <algorithm>
#include <cassert> #include <cassert>
#include "sound.h" #include "cartographer.h"
#include "upgrade.h"
#include "unit.h"
#include "particle_type.h"
#include "core_data.h" #include "core_data.h"
#include "config.h" #include "config.h"
#include "renderer.h"
#include "sound_renderer.h"
#include "game.h" #include "game.h"
#include "path_finder.h"
#include "object.h"
#include "faction.h" #include "faction.h"
#include "network_manager.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 "route_planner.h"
#include "sound.h"
#include "sound_renderer.h"
#include "upgrade.h"
#include "unit.h"
#include "leak_dumper.h" #include "leak_dumper.h"
using namespace Shared::Graphics; using namespace Shared::Graphics;
@ -52,10 +53,12 @@ void UnitUpdater::init(Game *game){
this->console= game->getConsole(); this->console= game->getConsole();
this->scriptManager= game->getScriptManager(); this->scriptManager= game->getScriptManager();
this->routePlanner = NULL; this->routePlanner = NULL;
this->pathFinder = NULL;
switch(this->game->getGameSettings()->getPathFinderType()) { switch(this->game->getGameSettings()->getPathFinderType()) {
case pfBasic: case pfBasic:
pathFinder.init(map); pathFinder = new PathFinder();
pathFinder->init(map);
break; break;
case pfRoutePlanner: case pfRoutePlanner:
routePlanner = world->getRoutePlanner(); routePlanner = world->getRoutePlanner();
@ -65,6 +68,10 @@ void UnitUpdater::init(Game *game){
} }
} }
UnitUpdater::~UnitUpdater() {
delete pathFinder;
pathFinder = NULL;
}
// ==================== progress skills ==================== // ==================== progress skills ====================
@ -203,7 +210,7 @@ void UnitUpdater::updateMove(Unit *unit){
TravelState tsValue = tsImpossible; TravelState tsValue = tsImpossible;
switch(this->game->getGameSettings()->getPathFinderType()) { switch(this->game->getGameSettings()->getPathFinderType()) {
case pfBasic: case pfBasic:
tsValue = pathFinder.findPath(unit, pos); tsValue = pathFinder->findPath(unit, pos);
break; break;
case pfRoutePlanner: case pfRoutePlanner:
tsValue = routePlanner->findPath(unit, pos); tsValue = routePlanner->findPath(unit, pos);
@ -213,7 +220,7 @@ void UnitUpdater::updateMove(Unit *unit){
} }
switch (tsValue) { switch (tsValue) {
case tsOnTheWay: case tsMoving:
unit->setCurrSkill(mct->getMoveSkillType()); unit->setCurrSkill(mct->getMoveSkillType());
break; break;
@ -264,7 +271,7 @@ void UnitUpdater::updateAttack(Unit *unit){
TravelState tsValue = tsImpossible; TravelState tsValue = tsImpossible;
switch(this->game->getGameSettings()->getPathFinderType()) { switch(this->game->getGameSettings()->getPathFinderType()) {
case pfBasic: case pfBasic:
tsValue = pathFinder.findPath(unit, pos); tsValue = pathFinder->findPath(unit, pos);
break; break;
case pfRoutePlanner: case pfRoutePlanner:
tsValue = routePlanner->findPath(unit, pos); tsValue = routePlanner->findPath(unit, pos);
@ -275,7 +282,7 @@ void UnitUpdater::updateAttack(Unit *unit){
//if unit arrives destPos order has ended //if unit arrives destPos order has ended
switch (tsValue){ switch (tsValue){
case tsOnTheWay: case tsMoving:
unit->setCurrSkill(act->getMoveSkillType()); unit->setCurrSkill(act->getMoveSkillType());
break; break;
case tsBlocked: case tsBlocked:
@ -322,7 +329,7 @@ void UnitUpdater::updateBuild(Unit *unit){
TravelState tsValue = tsImpossible; TravelState tsValue = tsImpossible;
switch(this->game->getGameSettings()->getPathFinderType()) { switch(this->game->getGameSettings()->getPathFinderType()) {
case pfBasic: case pfBasic:
tsValue = pathFinder.findPath(unit, command->getPos()-Vec2i(1)); tsValue = pathFinder->findPath(unit, command->getPos()-Vec2i(1));
break; break;
case pfRoutePlanner: case pfRoutePlanner:
tsValue = routePlanner->findPathToBuildSite(unit, ut, command->getPos(), command->getFacing()); tsValue = routePlanner->findPathToBuildSite(unit, ut, command->getPos(), command->getFacing());
@ -332,7 +339,7 @@ void UnitUpdater::updateBuild(Unit *unit){
} }
switch (tsValue) { switch (tsValue) {
case tsOnTheWay: case tsMoving:
unit->setCurrSkill(bct->getMoveSkillType()); unit->setCurrSkill(bct->getMoveSkillType());
break; break;
@ -506,8 +513,8 @@ void UnitUpdater::updateHarvest(Unit *unit){
TravelState tsValue = tsImpossible; TravelState tsValue = tsImpossible;
switch(this->game->getGameSettings()->getPathFinderType()) { switch(this->game->getGameSettings()->getPathFinderType()) {
case pfBasic: case pfBasic:
tsValue = pathFinder.findPath(unit, command->getPos()); tsValue = pathFinder->findPath(unit, command->getPos());
if (tsValue == tsOnTheWay) { if (tsValue == tsMoving) {
unit->setCurrSkill(hct->getMoveSkillType()); unit->setCurrSkill(hct->getMoveSkillType());
} }
break; break;
@ -537,7 +544,7 @@ void UnitUpdater::updateHarvest(Unit *unit){
TravelState tsValue = tsImpossible; TravelState tsValue = tsImpossible;
switch(this->game->getGameSettings()->getPathFinderType()) { switch(this->game->getGameSettings()->getPathFinderType()) {
case pfBasic: case pfBasic:
tsValue = pathFinder.findPath(unit, store->getCenteredPos()); tsValue = pathFinder->findPath(unit, store->getCenteredPos());
break; break;
case pfRoutePlanner: case pfRoutePlanner:
tsValue = routePlanner->findPathToStore(unit, store); tsValue = routePlanner->findPathToStore(unit, store);
@ -547,7 +554,7 @@ void UnitUpdater::updateHarvest(Unit *unit){
} }
switch(tsValue) { switch(tsValue) {
case tsOnTheWay: case tsMoving:
unit->setCurrSkill(hct->getMoveLoadedSkillType()); unit->setCurrSkill(hct->getMoveLoadedSkillType());
break; break;
default: default:
@ -657,7 +664,7 @@ void UnitUpdater::updateRepair(Unit *unit){
TravelState ts; TravelState ts;
switch(this->game->getGameSettings()->getPathFinderType()) { switch(this->game->getGameSettings()->getPathFinderType()) {
case pfBasic: case pfBasic:
ts = pathFinder.findPath(unit, command->getPos()); ts = pathFinder->findPath(unit, command->getPos());
break; break;
case pfRoutePlanner: case pfRoutePlanner:
if (repaired && !repaired->getType()->isMobile()) { if (repaired && !repaired->getType()->isMobile()) {
@ -672,7 +679,7 @@ void UnitUpdater::updateRepair(Unit *unit){
} }
switch(ts) { switch(ts) {
case tsOnTheWay: case tsMoving:
unit->setCurrSkill(rct->getMoveSkillType()); unit->setCurrSkill(rct->getMoveSkillType());
break; break;
case tsBlocked: case tsBlocked:

View File

@ -13,7 +13,6 @@
#define _GLEST_GAME_UNITUPDATER_H_ #define _GLEST_GAME_UNITUPDATER_H_
#include "gui.h" #include "gui.h"
#include "path_finder.h"
#include "particle.h" #include "particle.h"
#include "randomgen.h" #include "randomgen.h"
@ -25,6 +24,7 @@ namespace Glest{ namespace Game{
class Unit; class Unit;
class Map; class Map;
class ScriptManager; class ScriptManager;
class PathFinder;
class RoutePlanner; class RoutePlanner;
// ===================================================== // =====================================================
@ -54,13 +54,14 @@ private:
World *world; World *world;
Console *console; Console *console;
ScriptManager *scriptManager; ScriptManager *scriptManager;
PathFinder pathFinder; PathFinder *pathFinder;
RoutePlanner *routePlanner; RoutePlanner *routePlanner;
Game *game; Game *game;
RandomGen random; RandomGen random;
public: public:
void init(Game *game); void init(Game *game);
~UnitUpdater();
//update skills //update skills
void updateUnit(Unit *unit); void updateUnit(Unit *unit);