Freeciv21
Develop your civilization from humble roots to a global empire
path_finding.h
Go to the documentation of this file.
1 /**************************************************************************
2  Copyright (c) 1996-2020 Freeciv21 and Freeciv contributors. This file is
3  __ __ part of Freeciv21. Freeciv21 is free software: you can
4 / \\..// \ redistribute it and/or modify it under the terms of the GNU
5  ( oo ) General Public License as published by the Free Software
6  \__/ Foundation, either version 3 of the License, or (at your
7  option) any later version. You should have received
8  a copy of the GNU General Public License along with Freeciv21. If not,
9  see https://www.gnu.org/licenses/.
10 **************************************************************************/
11 #pragma once
12 
13 // ========================== Explanations ===============================
14 
15 /*
16  * Functions in this file help to find a path from A to B.
17  *
18  * DEFINITIONS:
19  * step: one movement step which brings us from one tile to an
20  * adjacent one
21  *
22  * turn: turns spent to reach a tile. Since movement rules involve
23  * randomness, we use different "turn modes" to get an estimate of
24  * this number
25  *
26  * moves left: move points left upon reaching a tile.
27  *
28  * path: a list of steps which leads from the start to the end
29  *
30  * move cost (MC): move cost of a _single_ step. MC is always >= 0.
31  * [The parameter can specify what the MC of a step into the unknown is
32  * to be (this is a constant for each map). This defaults to a
33  * slightly large value meaning unknown tiles are avoided slightly.
34  * It's also possible to use 0 here and use TB or EC to control
35  * movement through unknown tiles, or to use PF_IMPOSSIBLE_MC to
36  * easily avoid unknown tiles.]
37  *
38  * extra cost (EC): extra cost of a _single_ tile. EC is always >= 0.
39  * The intended meaning for EC is "how much we want to avoid this tile",
40  * see DISCUSSION below for more.
41  *
42  * tile behaviour (TB): the extra information about a tile which
43  * tells us whether we can enter and leave tile as normal (see enum
44  * tile_behavior).
45  *
46  * total_MC: (effective) move cost of the whole path.
47  *
48  * total_EC: extra cost of the whole path (just sum of ECs of all
49  * tiles).
50  *
51  * total_CC: combined cost of the whole path (see below).
52  *
53  * best path: a path which has the minimal total_CC. If two paths
54  * have equal total_CC the behavior is undefined.
55  *
56  *
57  * DISCUSSION:
58  * First of all it should be noted that path-finding is not about finding
59  * shortest paths but about finding the "best" paths. Now, each path has
60  * two major characteristics:
61  * (1) How long it is (or how much does it cost in terms of time)
62  * and
63  * (2) How dangerous it is (or how much does it cost in terms of resources).
64  *
65  * We use MC (and total_MC) to describe (1) and use EC (and total_EC) to
66  * describe (2). Of course, when it comes to selecting the "best" path,
67  * we need to compromise between taking the shortest road and taking the
68  * safest road. To that end, we use the "combined cost", calculated as
69  * total_CC = PF_TURN_FACTOR * total_MC + move_rate * total_EC,
70  * where PF_TURN_FACTOR is a large constant. This means that each EC
71  * point is equivalent to 1/PF_TURN_FACTOR-th of one turn, or,
72  * equivalently, we are willing to spend one more turn on the road to
73  * avoid PF_TURN_FACTOR worth of danger. Note that if ECs are kept
74  * significantly lower than PF_TURN_FACTOR, the total_EC will only act as a
75  * tie-breaker between equally long paths.
76  *
77  * Note, that the user is expected to ask "So this best path, how long will
78  * it take me to walk it?". For that reason we keep our accounts of MCs and
79  * ECs separately, as one cannot answer the above question basing on
80  * total_CC alone.
81  *
82  * The above setup allows us to find elegant solutions to rather involved
83  * questions. A good example would be designing a road from A to B:
84  * ================
85  * The future road should be as short as possible, but out of many
86  * shortest roads we want to select the one which is fastest to
87  * construct. For example:
88  * the initial conditions ("-"s mark existing road, "."s mark plains)
89  * A.....B
90  * .....
91  * .---.
92  * a possible solution
93  * A-----B
94  * .....
95  * .---.
96  * the best solution (utilize existing road)
97  * A.....B
98  * \.../
99  * .---.
100  *
101  * To solve the problem we simply declare that
102  * MC between any two tiles shall be MOVE_COST_ROAD
103  * EC of any tile shall be the time to construct a road there
104  * =================
105  *
106  * In some cases we would like to impose extra restrictions on the
107  * paths/tiles we want to consider. For example, a trireme might want to
108  * never enter deep sea. A chariot, would like to find paths going to
109  * enemy cities but not going _through_ them. This can be achieved
110  * through an additional tile_behaviour callback, which would return
111  * TB_IGNORE for tiles we don't want to visit and TB_DONT_LEAVE for tiles
112  * we won't be able to leave (at least alive).
113  *
114  * Dangerous tiles are those on which we don't want to end a turn. If the
115  * danger callback is specified it is used to determine which tiles are
116  * dangerous; no path that ends a turn on such a tile will ever be
117  * considered.
118  *
119  * There is also support for fuel, and thus indirectly for air units. If
120  * the fuel parameters are provided then the unit is considered to have
121  * that much fuel. The net effect is that if a unit has N fuel then only
122  * every Nth turn will be considered a stopping point. To support air
123  * units, then, all tiles that don't have airfields (or cities/carriers)
124  * should be returned as dangerous (see danger, above). Setting fuel == 1
125  * in the pf_parameter disables fuel support.
126  *
127  * There are few other options in the path-finding. For further info about
128  * them, see comment for the pf_parameter structure below.
129  *
130  *
131  * FORMULAE:
132  * For calculating total_MC (given particular tile_behaviour)
133  * total_MC = ((turn + 1) * move_rate - moves_left)
134  *
135  * For calculating total_CC:
136  * total_CC = PF_TURN_FACTOR * total_MC + move_rate * total_EC
137  *
138  *
139  * EXAMPLES:
140  * The path-finding can be used in two major modes:
141  * (A) We know where we want to go and need the best path there
142  * How many miles to Dublin?
143  * Three score and ten, sir.
144  * Will we be there by candlelight?
145  * (B) We know what we want and need the nearest one
146  * Where is the nearest pub, gov?
147  *
148  * In the first case we use pf_map_move_cost(), pf_map_path(), and
149  * pf_map_position() (the latter will only tell us the distance but not the
150  * path to take). In the second case we use pf_map_iterate() to iterate
151  * through all tiles in the order of increased distance and break when we
152  * found what we were looking for. In this case we use pf_map_iter_*() to
153  * get information about the "closest tile".
154  *
155  * A) the caller knows the map position of the goal and wants to know the
156  * path:
157  *
158  * struct pf_parameter parameter;
159  * struct pf_map *pfm;
160  * PFPath *path;
161  *
162  * // fill parameter (see below)
163  *
164  * // create the map: the main path-finding object.
165  * pfm = pf_map_new(&parameter);
166  *
167  * // create the path to the tile 'ptile'.
168  * if ((path = pf_map_path(pfm, ptile))) {
169  * // success, use path
170  * pf_path_destroy(path);
171  * } else {
172  * // no path could be found
173  * }
174  *
175  * // don't forget to destroy the map after usage.
176  * pf_map_destroy(pfm);
177  *
178  * You may call pf_map_path() multiple times with the same pfm.
179  *
180  * B) the caller doesn't know the map position of the goal yet (but knows
181  * what he is looking for, e.g. a port) and wants to iterate over
182  * all paths in order of increasing costs (total_CC):
183  *
184  * struct pf_parameter parameter;
185  * struct pf_map *pfm;
186  *
187  * // fill parameter (see below)
188  *
189  * // create the map: the main path-finding object.
190  * pfm = pf_map_new(&parameter);
191  *
192  * // iterate the map, using macros defined on this header.
193  * pf_map_*_iterate(pfm, something, true) {
194  * // do something
195  * } pf_map_*_iterate_end;
196  *
197  * // don't forget to destroy the map after usage.
198  * pf_map_destroy(pfm);
199  *
200  * Depending on the kind of information required, the iteration macro
201  * should be:
202  *
203  * 1) tile iteration:
204  * pf_map_tiles_iterate(pfm, ptile, true) {
205  * // do something
206  * } pf_map_tiles_iterate_end;
207  *
208  * 2) move cost iteration on the nearest position:
209  * pf_map_move_costs_iterate(pfm, ptile, move_cost, true) {
210  * // do something
211  * } pf_map_move_costs_iterate_end;
212  *
213  * 3) information (for example the total MC and the number of turns) on the
214  * next nearest position:
215  * pf_map_positions_iterate(pfm, pos, true) {
216  * // do something
217  * } pf_map_positions_iterate_end;
218  *
219  * The third argument passed to the iteration macros is a condition that
220  * controls if the start tile of the pf_parameter should iterated or not.
221  *
222  *
223  * FILLING the struct pf_parameter:
224  * This can either be done by hand or using the pft_* functions from
225  * "common/aicore/pf_tools.h" or a mix of these.
226  *
227  * Hints:
228  * 1. It is useful to limit the expansion of unknown tiles with a get_TB
229  * callback. In this case you might set the unknown_MC to be 0.
230  * 2. If there are two paths of the same cost to a tile, you are
231  * not guaranteed to get the one with the least steps in it. If you care,
232  * specifying EC to be 1 will do the job.
233  * 3. To prevent AI from thinking that it can pass through "chokepoints"
234  * controlled by enemy cities, you can specify tile behaviour of each
235  * occupied enemy city to be TB_DONT_LEAVE.
236  */
237 
238 // Forward declarations
239 class QDebug;
240 
241 /* MC for an impossible step. If this value is returned by get_MC it
242  * is treated like TB_IGNORE for this step. This won't change the TB
243  * for any other step to this tile. */
244 #define PF_IMPOSSIBLE_MC -1
245 
246 /* The factor which is used to multiple total_EC in the total_CC
247  * calculation. See definition of total_CC above.
248  * The number is chosen to be much larger than 0 and much smaller
249  * than MAX_INT (and a power of 2 for easy multiplication). */
250 #define PF_TURN_FACTOR 65536
251 
252 // =========================== Structures ================================
253 
254 // Specifies the type of the action.
255 enum pf_action {
261 };
262 
263 // Specifies the actions to consider.
267  /* When this option is turned on, the move to a city will be considered
268  * as attacking a unit, even if we ignore if there is a unit in the city.
269  * This does not mean we are considering taking over a city! */
271  PF_AA_DIPLOMAT = 1 << 2,
272  PF_AA_TRADE_ROUTE = 1 << 3
273 };
274 
275 // Specifies the way path-finding will treat a tile.
277  TB_NORMAL = 0, /* Well, normal .*/
278  TB_IGNORE, // This one will be ignored.
279  TB_DONT_LEAVE /* Paths can lead _to_ such tile, but are not
280  * allowed to go _through_. This move cost is
281  * always evaluated to a constant single move cost,
282  * prefering straight paths because we don't need
283  * moves left to leave this tile. */
284 };
285 
286 /* Specifies the possibility to move from/to a tile. */
289  PF_MS_NATIVE = 1 << 0,
290  PF_MS_CITY = 1 << 1,
291  PF_MS_TRANSPORT = 1 << 2
292 };
293 
294 // Full specification of a position and time to reach it.
295 struct pf_position {
296  struct tile *tile; // The tile.
297  int turn; // The number of turns to the target.
298  int moves_left; /* The number of moves left the unit would have when
299  * reaching the tile. */
300  int fuel_left; /* The number of turns of fuel left the unit would
301  * have when reaching the tile. It is always set to
302  * 1 when unit types are not fueled. */
303 
304  int total_MC; // Total MC to reach this point
305  int total_EC; // Total EC to reach this point
306 
307  enum direction8 dir_to_next_pos; // Used only in 'PFPath'.
308  enum direction8 dir_to_here; // Where did we come from.
309 };
310 
311 // Full specification of a path.
312 class PFPath {
313  std::vector<pf_position> positions;
314 
315 public:
316  PFPath() = default; // Constructor
317  PFPath(int size); // Construct with size
318  PFPath(const PFPath &obj) = default; // Default copy constructor
319  PFPath(PFPath &&obj) = default; // Default move constructor
320  PFPath(const struct pf_parameter *param);
321  int length() const;
322  virtual ~PFPath();
323  bool empty() const;
324  bool advance(struct tile *ptile);
325  pf_position &operator[](int i);
326  const pf_position &operator[](int i) const;
327  PFPath &operator=(PFPath &&other) = default; // Default move assignment
328 };
329 QDebug &operator<<(QDebug &logger, const PFPath &path);
330 
331 /* Initial data for the path-finding. Normally should use functions
332  * from "pf_tools.[ch]" to fill the parameter.
333  *
334  * All callbacks get the parameter passed to pf_map_new() as the last
335  * argument.
336  *
337  * Examples of callbacks can be found in "pf_tools.c"
338  * NB: It should be safe to struct copy pf_parameter. */
339 struct pf_parameter {
340  const struct civ_map *map;
341  struct tile *start_tile; // Initial position
342 
344  int fuel_left_initially; // Ignored for non-air units.
345  // Set if the unit is transported.
347  // See unit_cargo_depth().
349  // All cargo unit types.
350  bv_unit_types cargo_types;
351 
352  int move_rate; // Move rate of the virtual unit
353  int fuel; // Should be 1 for units without fuel.
354 
355  const struct unit_type *utype;
356  const struct player *owner;
357 
358  bool omniscience; // Do we care if the tile is visible?
359 
360  /* Callback to get MC of a move from 'from_tile' to 'to_tile' and in the
361  * direction 'dir'. Note that the callback can calculate 'to_tile' by
362  * itself based on 'from_tile' and 'dir'. Excessive information 'to_tile'
363  * is provided to ease the implementation of the callback. */
364  int (*get_MC)(const struct tile *from_tile,
365  enum pf_move_scope src_move_scope,
366  const struct tile *to_tile,
367  enum pf_move_scope dst_move_scope,
368  const struct pf_parameter *param);
369 
370  /* Callback which determines if we can move from/to 'ptile'. */
371  enum pf_move_scope (*get_move_scope)(const struct tile *ptile,
372  bool *can_disembark,
373  enum pf_move_scope previous_scope,
374  const struct pf_parameter *param);
376 
377  /* Callback which determines the behavior of a tile. If nullptr
378  * TB_NORMAL is assumed. It can be assumed that the implementation
379  * of "path_finding.h" will cache this value. */
380  enum tile_behavior (*get_TB)(const struct tile *ptile,
381  enum known_type known,
382  const struct pf_parameter *param);
383 
384  /* Callback which can be used to provide extra costs depending on the
385  * tile. Can be nullptr. It can be assumed that the implementation of
386  * "path_finding.h" will cache this value. */
387  int (*get_EC)(const struct tile *ptile, enum known_type known,
388  const struct pf_parameter *param);
389 
390  /* Callback which determines whether an action would be performed at
391  * 'ptile' instead of moving to it. */
392  enum pf_action (*get_action)(const struct tile *ptile,
393  enum known_type known,
394  const struct pf_parameter *param);
396 
397  /* Callback which determines whether the action from 'from_tile' to
398  * 'to_tile' is effectively possible. */
399  bool (*is_action_possible)(const struct tile *from_tile,
400  enum pf_move_scope src_move_scope,
401  const struct tile *to_tile,
402  enum pf_action action,
403  const struct pf_parameter *param);
404 
405  /* Although the rules governing ZoC are universal, the amount of
406  * information available at server and client is different. To
407  * compensate for it, we might need to supply our own version
408  * of "common" is_my_zoc. Also AI might need to partially ignore
409  * ZoC for strategic planning purposes (take into account enemy cities
410  * but not units for example).
411  * If this callback is nullptr, ZoC are ignored. */
412  bool (*get_zoc)(const struct player *pplayer, const struct tile *ptile,
413  const struct civ_map *zmap);
414 
415  /* If this callback is non-nullptr and returns true this position is
416  * dangerous. The unit will never end a turn at a dangerous
417  * position. Can be nullptr. */
418  bool (*is_pos_dangerous)(const struct tile *ptile, enum known_type,
419  const struct pf_parameter *param);
420 
421  /* If this callback is non-nullptr and returns the required moves left to
422  * move to this tile and to leave the position safely. Can be nullptr. */
423  int (*get_moves_left_req)(const struct tile *ptile, enum known_type,
424  const struct pf_parameter *param);
425 
426  /* This is a jumbo callback which overrides all previous ones. It takes
427  * care of everything (ZOC, known, costs etc).
428  * Variables:
429  * from_tile -- the source tile
430  * from_cost, from_extra -- costs of the source tile
431  * to_tile -- the dest tile
432  * to_cost, to_extra -- costs of the dest tile
433  * dir -- direction from source to dest
434  * param -- a pointer to this struct
435  * If the dest tile hasn't been reached before, to_cost is -1.
436  *
437  * The callback should:
438  * - evaluate the costs of the move
439  * - calculate the cost of the whole path
440  * - compare it to the ones recorded at dest tile
441  * - if new cost are not better, return -1
442  * - if new costs are better, record them in to_cost/to_extra and return
443  * the cost-of-the-path which is the overall measure of goodness of the
444  * path (less is better) and used to order newly discovered locations. */
445  int (*get_costs)(const struct tile *from_tile, enum direction8 dir,
446  const struct tile *to_tile, int from_cost, int from_extra,
447  int *to_cost, int *to_extra,
448  const struct pf_parameter *param);
449 
450  /* User provided data. Can be used to attach arbitrary information
451  * to the map. */
452  void *data;
453 };
454 
455 // The map itself. Opaque type.
456 struct pf_map;
457 
458 // The reverse map strucure. Opaque type.
459 struct pf_reverse_map;
460 
461 // ========================= Public Interface ============================
462 
463 // Create and free.
464 struct pf_map *
465 pf_map_new(const struct pf_parameter *parameter) fc__warn_unused_result;
466 void pf_map_destroy(struct pf_map *pfm);
467 
468 // Method A) functions.
469 int pf_map_move_cost(struct pf_map *pfm, struct tile *ptile);
470 PFPath pf_map_path(struct pf_map *pfm,
471  struct tile *ptile) fc__warn_unused_result;
472 bool pf_map_position(struct pf_map *pfm, struct tile *ptile,
473  struct pf_position *pos) fc__warn_unused_result;
474 
475 // Method B) functions.
476 bool pf_map_iterate(struct pf_map *pfm);
477 struct tile *pf_map_iter(struct pf_map *pfm);
478 int pf_map_iter_move_cost(struct pf_map *pfm);
480 void pf_map_iter_position(struct pf_map *pfm, struct pf_position *pos);
481 
482 // Other related functions.
483 const struct pf_parameter *pf_map_parameter(const struct pf_map *pfm);
484 
485 // Reverse map functions (Costs to go to start tile).
486 struct pf_reverse_map *
487 pf_reverse_map_new(const struct player *pplayer, struct tile *start_tile,
488  int max_turns, bool omniscient,
489  const struct civ_map *map) fc__warn_unused_result;
491  const struct city *pcity, const struct player *attacker, int max_turns,
492  bool omniscient, const struct civ_map *map) fc__warn_unused_result;
493 void pf_reverse_map_destroy(struct pf_reverse_map *prfm);
494 
496  const struct unit *punit);
498  const struct unit *punit,
499  struct pf_position *pos);
500 
501 /* This macro iterates all reachable tiles.
502  *
503  * ARG_pfm - A pf_map structure pointer.
504  * NAME_tile - The name of the iterator to use (type struct tile *). This
505  * is defined inside the macro.
506  * COND_from_start - A boolean value (or equivalent, it can be a function)
507  * which indicate if the start tile should be iterated or
508  * not. */
509 #define pf_map_tiles_iterate(ARG_pfm, NAME_tile, COND_from_start) \
510  if (COND_from_start || pf_map_iterate((ARG_pfm))) { \
511  struct pf_map *_MY_pf_map_ = (ARG_pfm); \
512  struct tile *NAME_tile; \
513  do { \
514  NAME_tile = pf_map_iter(_MY_pf_map_);
515 
516 #define pf_map_tiles_iterate_end \
517  } \
518  while (pf_map_iterate(_MY_pf_map_)) \
519  ; \
520  }
521 
522 /* This macro iterates all reachable tiles and their move costs.
523  *
524  * ARG_pfm - A pf_map structure pointer.
525  * NAME_tile - The name of the iterator to use (type struct tile *). This
526  * is defined inside the macro.
527  * NAME_cost - The name of the variable containing the move cost info (type
528  * integer). This is defined inside the macro.
529  * COND_from_start - A boolean value (or equivalent, it can be a function)
530  * which indicate if the start tile should be iterated or
531  * not. */
532 #define pf_map_move_costs_iterate(ARG_pfm, NAME_tile, NAME_cost, \
533  COND_from_start) \
534  if (COND_from_start || pf_map_iterate((ARG_pfm))) { \
535  struct pf_map *_MY_pf_map_ = (ARG_pfm); \
536  struct tile *NAME_tile; \
537  int NAME_cost; \
538  do { \
539  NAME_tile = pf_map_iter(_MY_pf_map_); \
540  NAME_cost = pf_map_iter_move_cost(_MY_pf_map_);
541 
542 #define pf_map_move_costs_iterate_end \
543  } \
544  while (pf_map_iterate(_MY_pf_map_)) \
545  ; \
546  }
547 
548 /* This macro iterates all reachable tiles and fill a pf_position structure.
549  * structure as info.
550  *
551  * ARG_pfm - A pf_map structure pointer.
552  * NAME_pos - The name of the iterator to use (type struct pf_position).
553  * This is defined inside the macro.
554  * COND_from_start - A boolean value (or equivalent, it can be a function)
555  * which indicate if the start tile should be iterated or
556  * not. */
557 #define pf_map_positions_iterate(ARG_pfm, NAME_pos, COND_from_start) \
558  if (COND_from_start || pf_map_iterate((ARG_pfm))) { \
559  struct pf_map *_MY_pf_map_ = (ARG_pfm); \
560  struct pf_position NAME_pos; \
561  do { \
562  pf_map_iter_position(_MY_pf_map_, &NAME_pos);
563 
564 #define pf_map_positions_iterate_end \
565  } \
566  while (pf_map_iterate(_MY_pf_map_)) \
567  ; \
568  }
bool advance(struct tile *ptile)
Remove the part of a path leading up to a given tile.
bool empty() const
pf_position & operator[](int i)
std::vector< pf_position > positions
Definition: path_finding.h:313
virtual ~PFPath()
PFPath(const PFPath &obj)=default
PFPath()=default
PFPath & operator=(PFPath &&other)=default
int length() const
PFPath(PFPath &&obj)=default
bool pf_reverse_map_unit_position(struct pf_reverse_map *pfrm, const struct unit *punit, struct pf_position *pos)
Fill the position.
bool pf_map_position(struct pf_map *pfm, struct tile *ptile, struct pf_position *pos) fc__warn_unused_result
Get info about position at ptile and put it in pos.
PFPath pf_map_path(struct pf_map *pfm, struct tile *ptile) fc__warn_unused_result
CHECK DOCS AFTER FULL CONVERSTION OF pf_path to class PFPath Tries to find the best path in the given...
const struct pf_parameter * pf_map_parameter(const struct pf_map *pfm)
Return the pf_parameter for given pf_map.
bool pf_map_iterate(struct pf_map *pfm)
Iterates the path-finding algorithm one step further, to the next nearest position.
pf_action
Definition: path_finding.h:255
@ PF_ACTION_ATTACK
Definition: path_finding.h:257
@ PF_ACTION_DIPLOMAT
Definition: path_finding.h:258
@ PF_ACTION_TRADE_ROUTE
Definition: path_finding.h:259
@ PF_ACTION_IMPOSSIBLE
Definition: path_finding.h:260
@ PF_ACTION_NONE
Definition: path_finding.h:256
void pf_map_iter_position(struct pf_map *pfm, struct pf_position *pos)
Read all info about the current position into pos.
int pf_map_iter_move_cost(struct pf_map *pfm)
Return the move cost at the current position.
PFPath pf_map_iter_path(struct pf_map *pfm) fc__warn_unused_result
Return the path to our current position.This is equivalent to pf_map_path(pfm, pf_map_iter(pfm)).
QDebug & operator<<(QDebug &logger, const PFPath &path)
Debug a path.
pf_move_scope
Definition: path_finding.h:287
@ PF_MS_TRANSPORT
Definition: path_finding.h:291
@ PF_MS_CITY
Definition: path_finding.h:290
@ PF_MS_NATIVE
Definition: path_finding.h:289
@ PF_MS_NONE
Definition: path_finding.h:288
void pf_reverse_map_destroy(struct pf_reverse_map *prfm)
'pf_reverse_map' destructor.
struct pf_map * pf_map_new(const struct pf_parameter *parameter) fc__warn_unused_result
Factory function to create a new map according to the parameter.
int pf_reverse_map_unit_move_cost(struct pf_reverse_map *pfrm, const struct unit *punit)
Get the move costs that a unit needs to reach the start tile.
struct pf_reverse_map * pf_reverse_map_new_for_city(const struct city *pcity, const struct player *attacker, int max_turns, bool omniscient, const struct civ_map *map) fc__warn_unused_result
'pf_reverse_map' constructor for city.
void pf_map_destroy(struct pf_map *pfm)
After usage the map must be destroyed.
pf_action_account
Definition: path_finding.h:264
@ PF_AA_CITY_ATTACK
Definition: path_finding.h:270
@ PF_AA_UNIT_ATTACK
Definition: path_finding.h:266
@ PF_AA_NONE
Definition: path_finding.h:265
@ PF_AA_DIPLOMAT
Definition: path_finding.h:271
@ PF_AA_TRADE_ROUTE
Definition: path_finding.h:272
struct tile * pf_map_iter(struct pf_map *pfm)
Return the current tile.
struct pf_reverse_map * pf_reverse_map_new(const struct player *pplayer, struct tile *start_tile, int max_turns, bool omniscient, const struct civ_map *map) fc__warn_unused_result
'pf_reverse_map' constructor.
int pf_map_move_cost(struct pf_map *pfm, struct tile *ptile)
Tries to find the minimal move cost to reach ptile.
tile_behavior
Definition: path_finding.h:276
@ TB_NORMAL
Definition: path_finding.h:277
@ TB_DONT_LEAVE
Definition: path_finding.h:279
@ TB_IGNORE
Definition: path_finding.h:278
size_t size
Definition: specvec.h:64
Definition: city.h:291
int fuel_left_initially
Definition: path_finding.h:344
const struct unit_type * transported_by_initially
Definition: path_finding.h:346
enum pf_action(* get_action)(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
Definition: path_finding.h:392
enum pf_move_scope(* get_move_scope)(const struct tile *ptile, bool *can_disembark, enum pf_move_scope previous_scope, const struct pf_parameter *param)
Definition: path_finding.h:371
bool ignore_none_scopes
Definition: path_finding.h:375
const struct civ_map * map
Definition: path_finding.h:340
enum tile_behavior(* get_TB)(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
Definition: path_finding.h:380
int(* get_EC)(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
Definition: path_finding.h:387
enum pf_action_account actions
Definition: path_finding.h:395
const struct player * owner
Definition: path_finding.h:356
bool(* is_pos_dangerous)(const struct tile *ptile, enum known_type, const struct pf_parameter *param)
Definition: path_finding.h:418
int(* get_moves_left_req)(const struct tile *ptile, enum known_type, const struct pf_parameter *param)
Definition: path_finding.h:423
int moves_left_initially
Definition: path_finding.h:343
bool(* get_zoc)(const struct player *pplayer, const struct tile *ptile, const struct civ_map *zmap)
Definition: path_finding.h:412
int(* get_MC)(const struct tile *from_tile, enum pf_move_scope src_move_scope, const struct tile *to_tile, enum pf_move_scope dst_move_scope, const struct pf_parameter *param)
Definition: path_finding.h:364
int(* get_costs)(const struct tile *from_tile, enum direction8 dir, const struct tile *to_tile, int from_cost, int from_extra, int *to_cost, int *to_extra, const struct pf_parameter *param)
Definition: path_finding.h:445
const struct unit_type * utype
Definition: path_finding.h:355
bool(* is_action_possible)(const struct tile *from_tile, enum pf_move_scope src_move_scope, const struct tile *to_tile, enum pf_action action, const struct pf_parameter *param)
Definition: path_finding.h:399
bv_unit_types cargo_types
Definition: path_finding.h:350
struct tile * start_tile
Definition: path_finding.h:341
enum direction8 dir_to_here
Definition: path_finding.h:308
enum direction8 dir_to_next_pos
Definition: path_finding.h:307
struct tile * tile
Definition: path_finding.h:296
Definition: player.h:231
Definition: tile.h:42
Definition: unit.h:134
#define fc__warn_unused_result
Definition: support.h:41
known_type
Definition: tile.h:28