Freeciv-3.2
Loading...
Searching...
No Matches
Data Structures | Macros | Enumerations | Functions
path_finding.h File Reference
#include "log.h"
#include "map.h"
#include "tile.h"
#include "unit.h"
#include "unittype.h"

Go to the source code of this file.

Data Structures

struct  pf_position
 
struct  pf_path
 
struct  pf_parameter
 

Macros

#define PF_IMPOSSIBLE_MC   -1
 
#define PF_TURN_FACTOR   65536
 
#define pf_path_print(path, level)
 
#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
 
#define pf_map_paths_iterate(ARG_pfm, NAME_path, COND_from_start)
 
#define pf_map_paths_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

struct pf_mappf_map_new (const struct pf_parameter *parameter) fc__warn_unused_result
 
void pf_map_destroy (struct pf_map *pfm)
 
int pf_map_move_cost (struct pf_map *pfm, struct tile *ptile)
 
struct pf_pathpf_map_path (struct pf_map *pfm, struct tile *ptile) fc__warn_unused_result
 
bool pf_map_position (struct pf_map *pfm, struct tile *ptile, struct pf_position *pos) fc__warn_unused_result
 
bool pf_map_iterate (struct pf_map *pfm)
 
struct tilepf_map_iter (struct pf_map *pfm)
 
int pf_map_iter_move_cost (struct pf_map *pfm)
 
struct pf_pathpf_map_iter_path (struct pf_map *pfm) fc__warn_unused_result
 
void pf_map_iter_position (struct pf_map *pfm, struct pf_position *pos)
 
const struct pf_parameterpf_map_parameter (const struct pf_map *pfm)
 
void pf_path_destroy (struct pf_path *path)
 
struct pf_pathpf_path_concat (struct pf_path *dest_path, const struct pf_path *src_path)
 
bool pf_path_advance (struct pf_path *path, struct tile *ptile)
 
bool pf_path_backtrack (struct pf_path *path, struct tile *ptile)
 
const struct pf_positionpf_path_last_position (const struct pf_path *path)
 
void pf_path_print_real (const struct pf_path *path, enum log_level level, const char *file, const char *function, int line)
 
struct pf_reverse_mappf_reverse_map_new (const struct civ_map *nmap, const struct player *pplayer, struct tile *start_tile, int max_turns, bool omniscient) fc__warn_unused_result
 
struct pf_reverse_mappf_reverse_map_new_for_city (const struct civ_map *nmap, const struct city *pcity, const struct player *attacker, int max_turns, bool omniscient) fc__warn_unused_result
 
void pf_reverse_map_destroy (struct pf_reverse_map *prfm)
 
int pf_reverse_map_utype_move_cost (struct pf_reverse_map *pfrm, const struct unit_type *punittype, struct tile *ptile)
 
int pf_reverse_map_unit_move_cost (struct pf_reverse_map *pfrm, const struct unit *punit)
 
bool pf_reverse_map_utype_position (struct pf_reverse_map *pfrm, const struct unit_type *punittype, struct tile *ptile, struct pf_position *pos)
 
bool pf_reverse_map_unit_position (struct pf_reverse_map *pfrm, const struct unit *punit, struct pf_position *pos)
 

Macro Definition Documentation

◆ PF_IMPOSSIBLE_MC

#define PF_IMPOSSIBLE_MC   -1

Definition at line 266 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:
struct pf_map *_MY_pf_map_ = (ARG_pfm); \
struct tile *NAME_tile; \
int NAME_cost; \
do { \
char * incite_cost
Definition comments.c:75
bool pf_map_iterate(struct pf_map *pfm)
int pf_map_iter_move_cost(struct pf_map *pfm)
struct tile * pf_map_iter(struct pf_map *pfm)
Definition tile.h:50

Definition at line 581 of file path_finding.h.

◆ pf_map_move_costs_iterate_end

#define pf_map_move_costs_iterate_end
Value:
}

Definition at line 591 of file path_finding.h.

◆ pf_map_paths_iterate

#define pf_map_paths_iterate (   ARG_pfm,
  NAME_path,
  COND_from_start 
)
Value:
struct pf_map *_MY_pf_map_ = (ARG_pfm); \
struct pf_path *NAME_path;\
do {\
struct pf_path * pf_map_iter_path(struct pf_map *pfm) fc__warn_unused_result

Definition at line 624 of file path_finding.h.

◆ pf_map_paths_iterate_end

#define pf_map_paths_iterate_end
Value:
}

Definition at line 631 of file path_finding.h.

◆ pf_map_positions_iterate

#define pf_map_positions_iterate (   ARG_pfm,
  NAME_pos,
  COND_from_start 
)

◆ pf_map_positions_iterate_end

#define pf_map_positions_iterate_end
Value:
}

Definition at line 611 of file path_finding.h.

◆ pf_map_tiles_iterate

#define pf_map_tiles_iterate (   ARG_pfm,
  NAME_tile,
  COND_from_start 
)
Value:

Definition at line 560 of file path_finding.h.

◆ pf_map_tiles_iterate_end

#define pf_map_tiles_iterate_end
Value:
}

Definition at line 567 of file path_finding.h.

◆ pf_path_print

#define pf_path_print (   path,
  level 
)
Value:
}
#define __FC_LINE__
Definition log.h:40
#define log_do_output_for_level(level)
Definition log.h:89
struct setting_list * level[OLEVELS_NUM]
Definition settings.c:190

Definition at line 518 of file path_finding.h.

◆ PF_TURN_FACTOR

#define PF_TURN_FACTOR   65536

Definition at line 272 of file path_finding.h.

Enumeration Type Documentation

◆ pf_action

Enumerator
PF_ACTION_NONE 
PF_ACTION_ATTACK 
PF_ACTION_DIPLOMAT 
PF_ACTION_TRADE_ROUTE 
PF_ACTION_IMPOSSIBLE 

Definition at line 287 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 296 of file path_finding.h.

◆ pf_move_scope

Enumerator
PF_MS_NONE 
PF_MS_NATIVE 
PF_MS_CITY 
PF_MS_TRANSPORT 

Definition at line 319 of file path_finding.h.

◆ tile_behavior

Enumerator
TB_NORMAL 
TB_IGNORE 
TB_DONT_LEAVE 

Definition at line 308 of file path_finding.h.

Function Documentation

◆ pf_map_destroy()

void pf_map_destroy ( struct pf_map pfm)

◆ pf_map_iter()

struct tile * pf_map_iter ( struct pf_map pfm)

Return the current tile.

Definition at line 3312 of file path_finding.c.

◆ 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 3324 of file path_finding.c.

◆ pf_map_iter_path()

struct pf_path * 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 3337 of file path_finding.c.

◆ 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 3350 of file path_finding.c.

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 3288 of file path_finding.c.

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 3219 of file path_finding.c.

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

◆ pf_map_new()

struct pf_map * pf_map_new ( const struct pf_parameter parameter)

◆ pf_map_parameter()

const struct pf_parameter * pf_map_parameter ( const struct pf_map pfm)

◆ pf_map_path()

struct pf_path * pf_map_path ( struct pf_map pfm,
struct tile ptile 
)

◆ 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, for the position might be unreachable.

Definition at line 3267 of file path_finding.c.

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

◆ pf_path_advance()

bool pf_path_advance ( struct pf_path path,
struct tile ptile 
)

Remove the part of a path leading up to a given tile. If given tile is on the path more than once then the first occurrence will be the one used. If tile is not on the path at all, returns FALSE and path is not changed at all.

Definition at line 3475 of file path_finding.c.

◆ pf_path_backtrack()

bool pf_path_backtrack ( struct pf_path path,
struct tile ptile 
)

Remove the part of a path following a given tile. If given tile is on the path more than once then the last occurrence will be the one used. If tile is not on the path at all, returns FALSE and path is not changed at all.

Definition at line 3503 of file path_finding.c.

Referenced by send_goto_route().

◆ pf_path_concat()

struct pf_path * pf_path_concat ( struct pf_path dest_path,
const struct pf_path src_path 
)

Concatenate two paths together. The additional segment 'src_path' should start where the initial segment 'dest_path' stops. The overlapping position is removed.

If 'dest_path' == NULL, we just copy the src_path and nothing else.

Definition at line 3426 of file path_finding.c.

Referenced by send_connect_route(), send_goto_route(), and send_patrol_route().

◆ pf_path_destroy()

void pf_path_destroy ( struct pf_path path)

◆ pf_path_last_position()

const struct pf_position * pf_path_last_position ( const struct pf_path path)

◆ pf_path_print_real()

void pf_path_print_real ( const struct pf_path path,
enum log_level  level,
const char file,
const char function,
int  line 
)

Debug a path. This function shouldn't be called directly, see pf_path_print() defined in "path_finding.h".

Definition at line 3540 of file path_finding.c.

◆ pf_reverse_map_destroy()

void pf_reverse_map_destroy ( struct pf_reverse_map pfrm)

'pf_reverse_map' destructor.

Definition at line 3726 of file path_finding.c.

Referenced by assess_danger(), and dai_manage_barbarian_leader().

◆ pf_reverse_map_new()

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

'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 3688 of file path_finding.c.

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 civ_map nmap,
const struct city pcity,
const struct player attacker,
int  max_turns,
bool  omniscient 
)

'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 3715 of file path_finding.c.

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 3865 of file path_finding.c.

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 3895 of file path_finding.c.

Referenced by assess_danger_unit().

◆ pf_reverse_map_utype_move_cost()

int pf_reverse_map_utype_move_cost ( struct pf_reverse_map pfrm,
const struct unit_type punittype,
struct tile ptile 
)

Get the move costs that a unit type needs to reach the start tile. Returns PF_IMPOSSIBLE_MC if the tile is unreachable.

Definition at line 3851 of file path_finding.c.

◆ pf_reverse_map_utype_position()

bool pf_reverse_map_utype_position ( struct pf_reverse_map pfrm,
const struct unit_type punittype,
struct tile ptile,
struct pf_position pos 
)

Fill the position. Return TRUE if the tile is reachable.

Definition at line 3876 of file path_finding.c.