diff --git a/source/glest_game/ai/path_finder.cpp b/source/glest_game/ai/path_finder.cpp index 5df68072..18baa28d 100644 --- a/source/glest_game/ai/path_finder.cpp +++ b/source/glest_game/ai/path_finder.cpp @@ -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(path) != NULL) { if(!path->isEmpty()) { //route cache - Vec2i pos= path->pop(); + UnitPathBasic *basicPath = dynamic_cast(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(path) != NULL) { - Vec2i pos= path->pop(); + UnitPathBasic *basicPath = dynamic_cast(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; } diff --git a/source/glest_game/ai/path_finder.h b/source/glest_game/ai/path_finder.h index b708c92f..1a82b1bd 100644 --- a/source/glest_game/ai/path_finder.h +++ b/source/glest_game/ai/path_finder.h @@ -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 diff --git a/source/glest_game/ai/route_planner.cpp b/source/glest_game/ai/route_planner.cpp index ba583bf7..1bf0e4d9 100644 --- a/source/glest_game/ai/route_planner.cpp +++ b/source/glest_game/ai/route_planner.cpp @@ -404,6 +404,9 @@ bool RoutePlanner::refinePath(Unit *unit) { UnitPathInterface *unitpath = unit->getPath(); UnitPath *advPath = dynamic_cast(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(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); + 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); + 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); + 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); + 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); + 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); + 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); + if(advPath == NULL) { + throw runtime_error("Invalid or NULL unit path pointer!"); + } + UnitPath &path = *advPath; WaypointPath &wpPath = *unit->getWaypointPath(); diff --git a/source/glest_game/ai/route_planner.h b/source/glest_game/ai/route_planner.h index 89601d50..f9f9f2cf 100644 --- a/source/glest_game/ai/route_planner.h +++ b/source/glest_game/ai/route_planner.h @@ -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(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)) { diff --git a/source/glest_game/type_instances/unit.h b/source/glest_game/type_instances/unit.h index 8890f6b0..5656443b 100644 --- a/source/glest_game/type_instances/unit.h +++ b/source/glest_game/type_instances/unit.h @@ -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; }