ScummVM API documentation
pathfinder.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef ULTIMA8_WORLD_ACTORS_PATHFINDER_H
23 #define ULTIMA8_WORLD_ACTORS_PATHFINDER_H
24 
25 #include "ultima/shared/std/containers.h"
26 #include "ultima/ultima8/misc/direction.h"
27 #include "ultima/ultima8/misc/point3.h"
28 #include "ultima/ultima8/misc/priority_queue.h"
29 #include "ultima/ultima8/world/actors/animation.h"
30 
31 //#define DEBUG_PATHFINDER
32 
33 namespace Ultima {
34 namespace Ultima8 {
35 
36 class Actor;
37 class Item;
38 
40  PathfindingState() : _point(), _direction(dir_north),
41  _lastAnim(Animation::walk), _flipped(false),
42  _firstStep(true), _combat(false) {};
43  Point3 _point;
44  Animation::Sequence _lastAnim;
45  Direction _direction;
46  bool _flipped;
47  bool _firstStep;
48  bool _combat;
49 
50  void load(const Actor *actor);
51  bool checkPoint(const Point3 &pt, int range) const;
52  bool checkItem(const Item *item, int xyRange, int zRange) const;
53  bool checkHit(const Actor *actor, const Item *target) const;
54 };
55 
57  Animation::Sequence _action;
58  Direction _direction;
59  uint32 _steps;
60 };
61 
62 struct PathNode;
63 
64 class PathNodeCmp {
65 public:
66  bool operator()(const PathNode *n1, const PathNode *n2) const;
67 };
68 
69 class Pathfinder {
70 public:
71  Pathfinder();
72  ~Pathfinder();
73 
74  void init(Actor *actor, PathfindingState *state = 0);
75  void setTarget(const Point3 &pt);
76  void setTarget(Item *item, bool hit = false);
77 
79  bool canReach();
80 
82  bool pathfind(Std::vector<PathfindingAction> &path);
83 
84 #ifdef DEBUG_PATHFINDER
85  static ObjId _visualDebugActor;
86 #endif
87 
88 
89 protected:
90  PathfindingState _start;
91  Actor *_actor;
92  Point3 _target;
93  Item *_targetItem;
94  bool _hitMode;
95  int32 _expandTime;
96 
97  int32 _actorXd, _actorYd, _actorZd;
98 
101 
104 
105  bool alreadyVisited(const Point3 &pt) const;
106  void newNode(PathNode *oldnode, PathfindingState &state,
107  unsigned int steps);
108  void expandNode(PathNode *node);
109  unsigned int costHeuristic(PathNode *node) const;
110  bool checkTarget(const PathNode *node) const;
111 };
112 
113 } // End of namespace Ultima8
114 } // End of namespace Ultima
115 
116 #endif
Definition: pathfinder.h:64
Definition: array.h:52
Definition: item.h:42
Definition: priority_queue.h:37
Definition: point3.h:28
Std::vector< PathNode * > _cleanupNodes
Definition: pathfinder.h:103
Definition: pathfinder.h:56
Definition: detection.h:27
Definition: pathfinder.h:69
Definition: pathfinder.h:39
Definition: actor.h:37
Definition: containers.h:38