- 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();
if(map->canMove(unit, unit->getPos(), pos)) {
unit->setTargetPos(pos);
return tsOnTheWay;
return tsMoving;
}
}
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)) {
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<UnitPathBasic *>(path) != NULL) {
UnitPathBasic *basicPath = dynamic_cast<UnitPathBasic *>(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;

View File

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

View File

@ -152,6 +152,9 @@ public:
virtual void clear() {list<Vec2i>::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<Vec2i>::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

View File

@ -14,21 +14,22 @@
#include <algorithm>
#include <cassert>
#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:

View File

@ -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);