35 else est =
goal.
x - x;
38 else est +=
goal.
y - y;
46 priority_queue <mapsquare *, vector<mapsquare *>, compare_squarecost> sorted_nodes;
48 vector <mapsquare *> opened_nodes;
50 vector <mapsquare *> closed_nodes;
52 moves_to_goal.clear ();
59 n->
h = goal_estimate (n->
x (), n->
y ());
63 sorted_nodes.push (n);
64 opened_nodes.push_back (n);
65 while (!sorted_nodes.empty ())
67 n = sorted_nodes.top ();
69 opened_nodes.erase (find (opened_nodes.begin (), opened_nodes.end (), n));
113 bool in_opened, in_closed;
114 in_opened = (find (opened_nodes.begin (), opened_nodes.end (), np) != opened_nodes.end ());
115 in_closed = (find (closed_nodes.begin (), closed_nodes.end (), np) != closed_nodes.end ());
118 if (!((in_opened || in_closed) && np->
g <= newg))
122 np->
h = goal_estimate (np->
x (), np->
y ());
123 np->
f = np->
g + np->
h;
128 closed_nodes.erase (find (closed_nodes.begin (), closed_nodes.end (), np));
133 sorted_nodes.push (np);
134 opened_nodes.push_back (np);
152 bool in_opened, in_closed;
153 in_opened = (find (opened_nodes.begin (), opened_nodes.end (), np) != opened_nodes.end ());
154 in_closed = (find (closed_nodes.begin (), closed_nodes.end (), np) != closed_nodes.end ());
157 if (!((in_opened || in_closed) && np->
g <= newg))
161 np->
h = goal_estimate (np->
x (), np->
y ());
162 np->
f = np->
g + np->
h;
167 closed_nodes.erase (find (closed_nodes.begin (), closed_nodes.end (), np));
172 sorted_nodes.push (np);
173 opened_nodes.push_back (np);
191 bool in_opened, in_closed;
192 in_opened = (find (opened_nodes.begin (), opened_nodes.end (), np) != opened_nodes.end ());
193 in_closed = (find (closed_nodes.begin (), closed_nodes.end (), np) != closed_nodes.end ());
196 if (!((in_opened || in_closed) && np->
g <= newg))
200 np->
h = goal_estimate (np->
x (), np->
y ());
201 np->
f = np->
g + np->
h;
206 closed_nodes.erase (find (closed_nodes.begin (), closed_nodes.end (), np));
211 sorted_nodes.push (np);
212 opened_nodes.push_back (np);
229 bool in_opened, in_closed;
230 in_opened = (find (opened_nodes.begin (), opened_nodes.end (), np) != opened_nodes.end ());
231 in_closed = (find (closed_nodes.begin (), closed_nodes.end (), np) != closed_nodes.end ());
234 if (!((in_opened || in_closed) && np->
g <= newg))
238 np->
h = goal_estimate (np->
x (), np->
y ());
239 np->
f = np->
g + np->
h;
244 closed_nodes.erase (find (closed_nodes.begin (), closed_nodes.end (), np));
249 sorted_nodes.push (np);
250 opened_nodes.push_back (np);
256 closed_nodes.push_back (n);
276 for (
u_int16 i = 0; i < nb_moves; i++)
280 moves_to_goal.push_back (t);
s_int8 get_state(igzstream &file)
Restore the path's state from an opened file.
Class to write data from a Gzip compressed file.
bool is_walkable_west() const
Returns whether a mapsquare is walkable from west.
u_int16 x()
Returns the X position of this mapsquare.
Class to read data from a Gzip compressed file.
area_coord goal
Goal point.
bool is_free()
Returns whether the mapsquare is free for a character to go on or not.
#define u_int16
16 bits long unsigned integer
mapsquare * parent
Parent square for the path.
area_coord start
Start point.
u_int16 submap
Submap where the pathfinding will occur.
mapsquare * get_square(u_int16 x, u_int16 y) const
Returns a pointer to a desired square.
u_int16 area_height() const
Returns the height of the area.
u_int16 dir
Direction to face once the goal is reached.
#define WALK_SOUTH
Walking South.
#define WALK_WEST
Walking West.
bool can_use_for_pathfinding
If == false, then this square will never be considered as walkable by pathfinding functions...
u_int16 area_length() const
Returns the length of the area.
Declares the landmap class.
mapsquare_area * get_submap(u_int16 pos)
Returns a pointer to a submap belonging to this landmap.
bool is_walkable_east() const
Returns whether a mapsquare is walkable from east.
u_int16 g
Distance from the source square.
landmap * refmap
Landmap where the pathfinding will occur.
u_int16 y()
Returns the Y position of this mapsquare.
void clear()
Totally clears the path.
Base unit of a landsubmap, where you can place mapobjects or mapcharacters.
bool is_walkable_north() const
Returns whether a mapsquare is walkable from north.
#define WALK_NORTH
Walking North.
bool is_walkable_south() const
Returns whether a mapsquare is walkable from south.
u_int16 h
Estimated distance to the goal square.
#define WALK_EAST
Walking East.
s_int8 put_state(ogzstream &file) const
Saves the path's state into an opened file.
bool calculate()
Tries to find the shortest path possible between the start point and the goal point.
#define s_int8
8 bits long signed integer
u_int16 get_move(u_int16 nbr) const
Returns the move to perform when at position nbr.
Area of mapsquares, for use with landmap.
u_int16 nbr_moves() const
Returns the number of moves between start and goal.