00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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