Freeciv21
Develop your civilization from humble roots to a global empire
path_finding.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  pf_position
 
class  PFPath
 
struct  pf_parameter
 

Macros

#define PF_IMPOSSIBLE_MC   -1
 
#define PF_TURN_FACTOR   65536
 
#define pf_map_tiles_iterate(ARG_pfm, NAME_tile, COND_from_start)
 
#define pf_map_tiles_iterate_end
 
#define pf_map_move_costs_iterate(ARG_pfm, NAME_tile, NAME_cost, COND_from_start)
 
#define pf_map_move_costs_iterate_end
 
#define pf_map_positions_iterate(ARG_pfm, NAME_pos, COND_from_start)
 
#define pf_map_positions_iterate_end
 

Enumerations

enum  pf_action {
  PF_ACTION_NONE = 0 , PF_ACTION_ATTACK , PF_ACTION_DIPLOMAT , PF_ACTION_TRADE_ROUTE ,
  PF_ACTION_IMPOSSIBLE = -1
}
 
enum  pf_action_account {
  PF_AA_NONE = 0 , PF_AA_UNIT_ATTACK = 1 << 0 , PF_AA_CITY_ATTACK = 1 << 1 , PF_AA_DIPLOMAT = 1 << 2 ,
  PF_AA_TRADE_ROUTE = 1 << 3
}
 
enum  tile_behavior { TB_NORMAL = 0 , TB_IGNORE , TB_DONT_LEAVE }
 
enum  pf_move_scope { PF_MS_NONE = 0 , PF_MS_NATIVE = 1 << 0 , PF_MS_CITY = 1 << 1 , PF_MS_TRANSPORT = 1 << 2 }
 

Functions

QDebug & operator<< (QDebug &logger, const PFPath &path)
 Debug a path. More...
 
struct pf_mappf_map_new (const struct pf_parameter *parameter) fc__warn_unused_result
 Factory function to create a new map according to the parameter. More...
 
void pf_map_destroy (struct pf_map *pfm)
 After usage the map must be destroyed. More...
 
int pf_map_move_cost (struct pf_map *pfm, struct tile *ptile)
 Tries to find the minimal move cost to reach ptile. More...
 
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 map to the position ptile. More...
 
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. More...
 
bool pf_map_iterate (struct pf_map *pfm)
 Iterates the path-finding algorithm one step further, to the next nearest position. More...
 
struct tilepf_map_iter (struct pf_map *pfm)
 Return the current tile. More...
 
int pf_map_iter_move_cost (struct pf_map *pfm)
 Return the move cost at the current position. More...
 
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)). More...
 
void pf_map_iter_position (struct pf_map *pfm, struct pf_position *pos)
 Read all info about the current position into pos. More...
 
const struct pf_parameterpf_map_parameter (const struct pf_map *pfm)
 Return the pf_parameter for given pf_map. More...
 
struct pf_reverse_mappf_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. More...
 
struct pf_reverse_mappf_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. More...
 
void pf_reverse_map_destroy (struct pf_reverse_map *prfm)
 'pf_reverse_map' destructor. More...
 
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. More...
 
bool pf_reverse_map_unit_position (struct pf_reverse_map *pfrm, const struct unit *punit, struct pf_position *pos)
 Fill the position. More...
 

Macro Definition Documentation

◆ PF_IMPOSSIBLE_MC

#define PF_IMPOSSIBLE_MC   -1

Definition at line 244 of file path_finding.h.

◆ pf_map_move_costs_iterate

#define pf_map_move_costs_iterate (   ARG_pfm,
  NAME_tile,
  NAME_cost,
  COND_from_start 
)
Value:
if (COND_from_start || pf_map_iterate((ARG_pfm))) { \
struct pf_map *_MY_pf_map_ = (ARG_pfm); \
struct tile *NAME_tile; \
int NAME_cost; \
do { \
NAME_tile = pf_map_iter(_MY_pf_map_); \
NAME_cost = pf_map_iter_move_cost(_MY_pf_map_);
bool pf_map_iterate(struct pf_map *pfm)
Iterates the path-finding algorithm one step further, to the next nearest position.
int pf_map_iter_move_cost(struct pf_map *pfm)
Return the move cost at the current position.
struct tile * pf_map_iter(struct pf_map *pfm)
Return the current tile.
Definition: tile.h:42

Definition at line 532 of file path_finding.h.

◆ pf_map_move_costs_iterate_end

#define pf_map_move_costs_iterate_end
Value:
} \
while (pf_map_iterate(_MY_pf_map_)) \
; \
}

Definition at line 542 of file path_finding.h.

◆ pf_map_positions_iterate

#define pf_map_positions_iterate (   ARG_pfm,
  NAME_pos,
  COND_from_start 
)
Value:
if (COND_from_start || pf_map_iterate((ARG_pfm))) { \
struct pf_map *_MY_pf_map_ = (ARG_pfm); \
struct pf_position NAME_pos; \
do { \
pf_map_iter_position(_MY_pf_map_, &NAME_pos);

Definition at line 557 of file path_finding.h.

◆ pf_map_positions_iterate_end

#define pf_map_positions_iterate_end
Value:
} \
while (pf_map_iterate(_MY_pf_map_)) \
; \
}

Definition at line 564 of file path_finding.h.

◆ pf_map_tiles_iterate

#define pf_map_tiles_iterate (   ARG_pfm,
  NAME_tile,
  COND_from_start 
)
Value:
if (COND_from_start || pf_map_iterate((ARG_pfm))) { \
struct pf_map *_MY_pf_map_ = (ARG_pfm); \
struct tile *NAME_tile; \
do { \
NAME_tile = pf_map_iter(_MY_pf_map_);

Definition at line 509 of file path_finding.h.

◆ pf_map_tiles_iterate_end

#define pf_map_tiles_iterate_end
Value:
} \
while (pf_map_iterate(_MY_pf_map_)) \
; \
}

Definition at line 516 of file path_finding.h.

◆ PF_TURN_FACTOR

#define PF_TURN_FACTOR   65536

Definition at line 250 of file path_finding.h.

Enumeration Type Documentation

◆ pf_action

enum pf_action
Enumerator
PF_ACTION_NONE 
PF_ACTION_ATTACK 
PF_ACTION_DIPLOMAT 
PF_ACTION_TRADE_ROUTE 
PF_ACTION_IMPOSSIBLE 

Definition at line 255 of file path_finding.h.

◆ pf_action_account

Enumerator
PF_AA_NONE 
PF_AA_UNIT_ATTACK 
PF_AA_CITY_ATTACK 
PF_AA_DIPLOMAT 
PF_AA_TRADE_ROUTE 

Definition at line 264 of file path_finding.h.

◆ pf_move_scope

Enumerator
PF_MS_NONE 
PF_MS_NATIVE 
PF_MS_CITY 
PF_MS_TRANSPORT 

Definition at line 287 of file path_finding.h.

◆ tile_behavior

Enumerator
TB_NORMAL 
TB_IGNORE 
TB_DONT_LEAVE 

Definition at line 276 of file path_finding.h.

Function Documentation

◆ operator<<()

QDebug& operator<< ( QDebug &  logger,
const PFPath path 
)

Debug a path.

Definition at line 3310 of file path_finding.cpp.

◆ pf_map_destroy()

◆ pf_map_iter()

struct tile* pf_map_iter ( struct pf_map pfm)

Return the current tile.

Definition at line 3160 of file path_finding.cpp.

◆ pf_map_iter_move_cost()

int pf_map_iter_move_cost ( struct pf_map pfm)

Return the move cost at the current position.

This is equivalent to pf_map_move_cost(pfm, pf_map_iter(pfm)).

Definition at line 3172 of file path_finding.cpp.

◆ pf_map_iter_path()

PFPath pf_map_iter_path ( struct pf_map pfm)

Return the path to our current position.This is equivalent to pf_map_path(pfm, pf_map_iter(pfm)).

Definition at line 3185 of file path_finding.cpp.

◆ pf_map_iter_position()

void pf_map_iter_position ( struct pf_map pfm,
struct pf_position pos 
)

Read all info about the current position into pos.

This is equivalent to pf_map_position(pfm, pf_map_iter(pfm), &pos).

Definition at line 3198 of file path_finding.cpp.

Referenced by process_attacker_want().

◆ pf_map_iterate()

bool pf_map_iterate ( struct pf_map pfm)

Iterates the path-finding algorithm one step further, to the next nearest position.

This full info on this position and the best path to it can be obtained using pf_map_iter_move_cost(), pf_map_iter_path(), and pf_map_iter_position() correspondingly. Returns FALSE if no further positions are available in this map.

NB: If pf_map_move_cost(pfm, ptile), pf_map_path(pfm, ptile), or pf_map_position(pfm, ptile) has been called before the call to pf_map_iterate(), the iteration will resume from 'ptile'.

Definition at line 3136 of file path_finding.cpp.

Referenced by pf_danger_map_iterate_until(), pf_fuel_map_iterate_until(), and pf_normal_map_iterate_until().

◆ pf_map_move_cost()

int pf_map_move_cost ( struct pf_map pfm,
struct tile ptile 
)

Tries to find the minimal move cost to reach ptile.

Returns PF_IMPOSSIBLE_MC if not reachable. If ptile has not been reached yet, iterate the map until we reach it or run out of map.

Definition at line 3068 of file path_finding.cpp.

Referenced by dai_manage_barbarian_leader(), find_beachhead(), and goto_is_sane().

◆ pf_map_new()

◆ pf_map_parameter()

◆ pf_map_path()

PFPath pf_map_path ( struct pf_map pfm,
struct tile ptile 
)

CHECK DOCS AFTER FULL CONVERSTION OF pf_path to class PFPath Tries to find the best path in the given map to the position ptile.

If empty path is returned no path could be found. The pf_path[-1] of such path would be the same (almost) as the result of the call to pf_map_position(). If ptile has not been reached yet, iterate the map until we reach it or run out of map.

Definition at line 3085 of file path_finding.cpp.

Referenced by auto_settler_setup_work(), dai_diplomat_bribe_nearby(), dai_find_strategic_airbase(), dai_hunter_manage(), dai_manage_airunit(), dai_manage_barbarian_leader(), dai_manage_diplomat(), dai_unit_goto_constrained(), explorer_goto(), find_nearest_airbase(), find_rampage_target(), find_something_to_bomb(), find_something_to_kill(), immediate_destination(), player_restore_units(), send_attack_tile(), send_goto_tile(), send_rally_tile(), settler_evaluate_city_requests(), settler_evaluate_improvements(), and tile_before_end_path().

◆ pf_map_position()

bool pf_map_position ( struct pf_map pfm,
struct tile ptile,
struct pf_position pos 
)

Get info about position at ptile and put it in pos.

If ptile has not been reached yet, iterate the map until we reach it. Should always check the return value, forthe position might be unreachable.

Definition at line 3115 of file path_finding.cpp.

Referenced by dai_manage_diplomat(), find_something_to_kill(), process_attacker_want(), settler_evaluate_city_requests(), and settler_evaluate_improvements().

◆ pf_reverse_map_destroy()

void pf_reverse_map_destroy ( struct pf_reverse_map prfm)

'pf_reverse_map' destructor.

Definition at line 3433 of file path_finding.cpp.

Referenced by assess_danger(), and dai_manage_barbarian_leader().

◆ pf_reverse_map_new()

struct pf_reverse_map* pf_reverse_map_new ( const struct player pplayer,
struct tile target_tile,
int  max_turns,
bool  omniscient,
const struct civ_map map 
)

'pf_reverse_map' constructor.

If 'max_turns' is positive, then it won't try to iterate the maps beyond this number of turns.

Definition at line 3394 of file path_finding.cpp.

Referenced by dai_manage_barbarian_leader(), and pf_reverse_map_new_for_city().

◆ pf_reverse_map_new_for_city()

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 
)

'pf_reverse_map' constructor for city.

If 'max_turns' is positive, then it won't try to iterate the maps beyond this number of turns.

Definition at line 3422 of file path_finding.cpp.

Referenced by assess_danger().

◆ pf_reverse_map_unit_move_cost()

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.

Returns PF_IMPOSSIBLE_MC if the tile is unreachable.

Definition at line 3538 of file path_finding.cpp.

Referenced by dai_manage_barbarian_leader().

◆ pf_reverse_map_unit_position()

bool pf_reverse_map_unit_position ( struct pf_reverse_map pfrm,
const struct unit punit,
struct pf_position pos 
)

Fill the position.

Return TRUE if the tile is reachable.

Definition at line 3549 of file path_finding.cpp.

Referenced by assess_danger_unit().