mirror of
https://github.com/glest/glest-source.git
synced 2025-02-25 04:02:30 +01:00
- some code cleanup related to supporting multiple path finders
This commit is contained in:
parent
bca03b0c0c
commit
74b6fc8139
@ -1,7 +1,7 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Martio Figueroa
|
||||
// Copyright (C) 2001-2008 Martiño Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
@ -68,7 +68,8 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos){
|
||||
if(dynamic_cast<UnitPathBasic *>(path) != NULL) {
|
||||
if(!path->isEmpty()) {
|
||||
//route cache
|
||||
Vec2i pos= path->pop();
|
||||
UnitPathBasic *basicPath = dynamic_cast<UnitPathBasic *>(path);
|
||||
Vec2i pos= basicPath->pop();
|
||||
if(map->canMove(unit, unit->getPos(), pos)) {
|
||||
unit->setTargetPos(pos);
|
||||
return tsOnTheWay;
|
||||
@ -81,12 +82,15 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos){
|
||||
//route cache
|
||||
Vec2i pos= advPath->peek();
|
||||
if(map->canMove(unit, unit->getPos(), pos)){
|
||||
path->pop();
|
||||
advPath->pop();
|
||||
unit->setTargetPos(pos);
|
||||
return tsOnTheWay;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw runtime_error("unsupported or missing path finder detected!");
|
||||
}
|
||||
}
|
||||
|
||||
//route cache miss
|
||||
@ -101,7 +105,8 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos){
|
||||
case tsOnTheWay:
|
||||
{
|
||||
if(dynamic_cast<UnitPathBasic *>(path) != NULL) {
|
||||
Vec2i pos= path->pop();
|
||||
UnitPathBasic *basicPath = dynamic_cast<UnitPathBasic *>(path);
|
||||
Vec2i pos= basicPath->pop();
|
||||
if(map->canMove(unit, unit->getPos(), pos)) {
|
||||
unit->setTargetPos(pos);
|
||||
}
|
||||
@ -122,6 +127,9 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos){
|
||||
return tsBlocked;
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw runtime_error("unsupported or missing path finder detected!");
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Martio Figueroa
|
||||
// Copyright (C) 2001-2008 Martiño Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
|
@ -404,6 +404,9 @@ bool RoutePlanner::refinePath(Unit *unit) {
|
||||
|
||||
UnitPathInterface *unitpath = unit->getPath();
|
||||
UnitPath *advPath = dynamic_cast<UnitPath *>(unitpath);
|
||||
if(advPath == NULL) {
|
||||
throw runtime_error("Invalid or NULL unit path pointer!");
|
||||
}
|
||||
|
||||
UnitPath &path = *advPath;
|
||||
assert(!wpPath.empty());
|
||||
@ -443,6 +446,9 @@ void RoutePlanner::smoothPath(Unit *unit) {
|
||||
PF_TRACE();
|
||||
UnitPathInterface *path = unit->getPath();
|
||||
UnitPath *advPath = dynamic_cast<UnitPath *>(path);
|
||||
if(advPath == NULL) {
|
||||
throw runtime_error("Invalid or NULL unit path pointer!");
|
||||
}
|
||||
|
||||
if (advPath->size() < 3) {
|
||||
return;
|
||||
@ -517,6 +523,9 @@ TravelState RoutePlanner::doRouteCache(Unit *unit) {
|
||||
|
||||
UnitPathInterface *unitpath = unit->getPath();
|
||||
UnitPath *advPath = dynamic_cast<UnitPath *>(unitpath);
|
||||
if(advPath == NULL) {
|
||||
throw runtime_error("Invalid or NULL unit path pointer!");
|
||||
}
|
||||
|
||||
UnitPath &path = *advPath;
|
||||
WaypointPath &wpPath = *unit->getWaypointPath();
|
||||
@ -554,6 +563,9 @@ TravelState RoutePlanner::doQuickPathSearch(Unit *unit, const Vec2i &target) {
|
||||
|
||||
UnitPathInterface *unitpath = unit->getPath();
|
||||
UnitPath *advPath = dynamic_cast<UnitPath *>(unitpath);
|
||||
if(advPath == NULL) {
|
||||
throw runtime_error("Invalid or NULL unit path pointer!");
|
||||
}
|
||||
|
||||
UnitPath &path = *advPath;
|
||||
// IF_DEBUG_EDITION( clearOpenClosed(unit->getPos(), target); )
|
||||
@ -584,6 +596,10 @@ TravelState RoutePlanner::findAerialPath(Unit *unit, const Vec2i &targetPos) {
|
||||
AnnotatedMap *aMap = world->getCartographer()->getMasterMap();
|
||||
UnitPathInterface *unitpath = unit->getPath();
|
||||
UnitPath *advPath = dynamic_cast<UnitPath *>(unitpath);
|
||||
if(advPath == NULL) {
|
||||
throw runtime_error("Invalid or NULL unit path pointer!");
|
||||
}
|
||||
|
||||
UnitPath &path = *advPath;
|
||||
PosGoal goal(targetPos);
|
||||
MoveCost cost(unit, aMap);
|
||||
@ -624,6 +640,10 @@ TravelState RoutePlanner::findPathToLocation(Unit *unit, const Vec2i &finalPos)
|
||||
PF_TRACE();
|
||||
UnitPathInterface *unitpath = unit->getPath();
|
||||
UnitPath *advPath = dynamic_cast<UnitPath *>(unitpath);
|
||||
if(advPath == NULL) {
|
||||
throw runtime_error("Invalid or NULL unit path pointer!");
|
||||
}
|
||||
|
||||
UnitPath &path = *advPath;
|
||||
WaypointPath &wpPath = *unit->getWaypointPath();
|
||||
|
||||
@ -737,6 +757,10 @@ TravelState RoutePlanner::customGoalSearch(PMap1Goal &goal, Unit *unit, const Ve
|
||||
|
||||
UnitPathInterface *unitpath = unit->getPath();
|
||||
UnitPath *advPath = dynamic_cast<UnitPath *>(unitpath);
|
||||
if(advPath == NULL) {
|
||||
throw runtime_error("Invalid or NULL unit path pointer!");
|
||||
}
|
||||
|
||||
UnitPath &path = *advPath;
|
||||
WaypointPath &wpPath = *unit->getWaypointPath();
|
||||
const Vec2i &start = unit->getPos();
|
||||
@ -775,6 +799,10 @@ TravelState RoutePlanner::findPathToGoal(Unit *unit, PMap1Goal &goal, const Vec2
|
||||
PF_TRACE();
|
||||
UnitPathInterface *unitpath = unit->getPath();
|
||||
UnitPath *advPath = dynamic_cast<UnitPath *>(unitpath);
|
||||
if(advPath == NULL) {
|
||||
throw runtime_error("Invalid or NULL unit path pointer!");
|
||||
}
|
||||
|
||||
UnitPath &path = *advPath;
|
||||
WaypointPath &wpPath = *unit->getWaypointPath();
|
||||
|
||||
@ -848,6 +876,10 @@ bool RoutePlanner::repairPath(Unit *unit) {
|
||||
PF_TRACE();
|
||||
UnitPathInterface *unitpath = unit->getPath();
|
||||
UnitPath *advPath = dynamic_cast<UnitPath *>(unitpath);
|
||||
if(advPath == NULL) {
|
||||
throw runtime_error("Invalid or NULL unit path pointer!");
|
||||
}
|
||||
|
||||
UnitPath &path = *advPath;
|
||||
WaypointPath &wpPath = *unit->getWaypointPath();
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Martio Figueroa
|
||||
// Copyright (C) 2001-2008 Martiño Figueroa
|
||||
// 2009-2010 James McCulloch
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
@ -189,6 +189,10 @@ private:
|
||||
bool attemptMove(Unit *unit) const {
|
||||
UnitPathInterface *path = unit->getPath();
|
||||
UnitPath *advPath = dynamic_cast<UnitPath *>(path);
|
||||
if(advPath == NULL) {
|
||||
throw runtime_error("Invalid or NULL unit path pointer!");
|
||||
}
|
||||
|
||||
assert(advPath->isEmpty() == false);
|
||||
Vec2i pos = advPath->peek();
|
||||
if (isLegalMove(unit, pos)) {
|
||||
|
@ -105,7 +105,7 @@ public:
|
||||
virtual void clear() = 0;
|
||||
virtual void incBlockCount() = 0;
|
||||
virtual void push(const Vec2i &path) = 0;
|
||||
virtual Vec2i pop() = 0;
|
||||
//virtual Vec2i pop() = 0;
|
||||
|
||||
virtual std::string toString() const = 0;
|
||||
};
|
||||
@ -160,7 +160,8 @@ public:
|
||||
#else
|
||||
// new style, for the new RoutePlanner
|
||||
Vec2i peek() {return front();} /**< peek at the next position */
|
||||
virtual Vec2i pop() { Vec2i p= front(); erase(begin()); return p; } /**< pop the next position off the path */
|
||||
//virtual Vec2i pop() { Vec2i p= front(); erase(begin()); return p; } /**< pop the next position off the path */
|
||||
void pop() { erase(begin()); } /**< pop the next position off the path */
|
||||
#endif
|
||||
int getBlockCount() const { return blockCount; }
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user