Pathfinder.h

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2003-2007 The Pentagram team
00003 
00004 This program is free software; you can redistribute it and/or
00005 modify it under the terms of the GNU General Public License
00006 as published by the Free Software Foundation; either version 2
00007 of the License, or (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 */
00018 
00019 #ifndef PATHFINDER_H
00020 #define PATHFINDER_H
00021 
00022 #include <vector>
00023 #include <queue>
00024 #include <list>
00025 #include "Animation.h"
00026 
00027 class Actor;
00028 class Item;
00029 
00030 struct PathfindingState
00031 {
00032         sint32 x, y, z;
00033         Animation::Sequence lastanim;
00034         uint32 direction;
00035         bool flipped;
00036         bool firststep;
00037         bool combat;
00038 
00039         void load(Actor* actor);
00040         bool checkPoint(sint32 x_, sint32 y_, sint32 z_,int range);
00041         bool checkItem(Item* item, int xyRange, int zRange);
00042         bool checkHit(Actor* actor, Actor* target);
00043 };
00044 
00045 struct PathfindingAction
00046 {
00047         Animation::Sequence action;
00048         uint32 direction;
00049         uint32 steps;
00050 };
00051 
00052 struct PathNode;
00053 
00054 class PathNodeCmp {
00055 public:
00056         bool operator()(PathNode* n1, PathNode* n2);
00057 };
00058 
00059 class Pathfinder
00060 {
00061 public:
00062         Pathfinder();
00063         ~Pathfinder();
00064 
00065         void init(Actor* actor, PathfindingState* state=0);
00066         void setTarget(sint32 x, sint32 y, sint32 z);
00067         void setTarget(Item* item, bool hit=false);
00068 
00070         bool canReach();
00071 
00073         bool pathfind(std::vector<PathfindingAction>& path);
00074 
00075 #ifdef DEBUG
00077         static void ConCmd_visualDebug(const Console::ArgvType &argv);
00078         static ObjId visualdebug_actor;
00079 #endif
00080 
00081 
00082 protected:
00083         PathfindingState start;
00084         Actor* actor;
00085         sint32 targetx, targety, targetz;
00086         Item* targetitem;
00087         bool hitmode;
00088         sint32 expandtime;
00089 
00090         sint32 actor_xd,actor_yd,actor_zd;
00091 
00092         std::list<PathfindingState> visited;
00093         std::priority_queue<PathNode*,std::vector<PathNode*>,PathNodeCmp> nodes;
00094 
00095         std::list<PathNode*> nodelist;
00096 
00097         bool alreadyVisited(sint32 x, sint32 y, sint32 z);
00098         void newNode(PathNode* oldnode,PathfindingState& state,unsigned int steps);
00099         void expandNode(PathNode* node);
00100         unsigned int costHeuristic(PathNode* node);
00101         bool checkTarget(PathNode* node);
00102 };
00103 
00104 #endif

Generated on Fri Jul 27 22:27:29 2007 for pentagram by  doxygen 1.4.7