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/world/actors/animation.h"
29 
30 //#define DEBUG_PATHFINDER
31 
32 namespace Ultima {
33 namespace Ultima8 {
34 
35 class Actor;
36 class Item;
37 
39  PathfindingState() : _point(), _direction(dir_north),
40  _lastAnim(Animation::walk), _flipped(false),
41  _firstStep(true), _combat(false) {};
42  Point3 _point;
43  Animation::Sequence _lastAnim;
44  Direction _direction;
45  bool _flipped;
46  bool _firstStep;
47  bool _combat;
48 
49  void load(const Actor *actor);
50  bool checkPoint(const Point3 &pt, int range) const;
51  bool checkItem(const Item *item, int xyRange, int zRange) const;
52  bool checkHit(const Actor *actor, const Item *target) const;
53 };
54 
56  Animation::Sequence _action;
57  Direction _direction;
58  uint32 _steps;
59 };
60 
61 struct PathNode;
62 
63 class PathNodeCmp {
64 public:
65  bool operator()(const PathNode *n1, const PathNode *n2) const;
66 };
67 
68 class Pathfinder {
69 public:
70  Pathfinder();
71  ~Pathfinder();
72 
73  void init(Actor *actor, PathfindingState *state = 0);
74  void setTarget(const Point3 &pt);
75  void setTarget(Item *item, bool hit = false);
76 
78  bool canReach();
79 
81  bool pathfind(Std::vector<PathfindingAction> &path);
82 
83 #ifdef DEBUG_PATHFINDER
84  static ObjId _visualDebugActor;
85 #endif
86 
87 
88 protected:
89  PathfindingState _start;
90  Actor *_actor;
91  Point3 _target;
92  Item *_targetItem;
93  bool _hitMode;
94  int32 _expandTime;
95 
96  int32 _actorXd, _actorYd, _actorZd;
97 
100 
103 
104  bool alreadyVisited(const Point3 &pt) const;
105  void newNode(PathNode *oldnode, PathfindingState &state,
106  unsigned int steps);
107  void expandNode(PathNode *node);
108  unsigned int costHeuristic(PathNode *node) const;
109  bool checkTarget(const PathNode *node) const;
110 };
111 
112 } // End of namespace Ultima8
113 } // End of namespace Ultima
114 
115 #endif
Definition: pathfinder.h:63
Definition: array.h:52
Definition: item.h:42
Definition: point3.h:28
Std::vector< PathNode * > _cleanupNodes
Definition: pathfinder.h:102
Definition: pathfinder.h:55
Definition: detection.h:27
Definition: containers.h:234
Definition: pathfinder.h:68
Definition: pathfinder.h:38
Definition: actor.h:37
Definition: containers.h:38