Freeciv21
Develop your civilization from humble roots to a global empire
pf_tools.cpp File Reference
#include <cstring>
#include "bitvector.h"
#include "log.h"
#include "base.h"
#include "game.h"
#include "movement.h"
#include "tile.h"
#include "unit.h"
#include "unittype.h"
#include "aiactions.h"
#include "pf_tools.h"
+ Include dependency graph for pf_tools.cpp:

Go to the source code of this file.

Functions

static bool pf_attack_possible (const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
 Can we attack 'ptile'? At this point, it assumes there are non-allied units on the tile. More...
 
static enum pf_action pf_get_action (const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
 Determines if a path to 'ptile' would be considered as action rather than normal move: attack, diplomat action, caravan action. More...
 
static bool pf_action_possible (const struct tile *src, enum pf_move_scope src_scope, const struct tile *dst, enum pf_action action, const struct pf_parameter *param)
 Determines if an action is possible from 'src' to 'dst': attack, diplomat action, or caravan action. More...
 
static enum pf_action pf_reverse_get_action (const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
 Special case for reverse maps. More...
 
static bool pf_transport_check (const struct pf_parameter *param, const struct unit *ptrans, const struct unit_type *trans_utype)
 Determine if we could load into 'ptrans' and its parents. More...
 
static enum pf_move_scope pf_get_move_scope (const struct tile *ptile, bool *can_disembark, enum pf_move_scope previous_scope, const struct pf_parameter *param)
 Determine how it is possible to move from/to 'ptile'. More...
 
static enum pf_move_scope amphibious_move_scope (const struct tile *ptile, bool *can_disembark, enum pf_move_scope previous_scope, const struct pf_parameter *param)
 A cost function for amphibious movement. More...
 
static bool pf_move_possible (const struct tile *src, enum pf_move_scope src_scope, const struct tile *dst, enum pf_move_scope dst_scope, const struct pf_parameter *param)
 Determines if the move between two tiles is possible. More...
 
static int normal_move (const struct tile *src, enum pf_move_scope src_scope, const struct tile *dst, enum pf_move_scope dst_scope, const struct pf_parameter *param)
 A cost function for regular movement. More...
 
static int overlap_move (const struct tile *src, enum pf_move_scope src_scope, const struct tile *dst, enum pf_move_scope dst_scope, const struct pf_parameter *param)
 A cost function for overlap movement. More...
 
static int amphibious_move (const struct tile *ptile, enum pf_move_scope src_scope, const struct tile *ptile1, enum pf_move_scope dst_scope, const struct pf_parameter *param)
 A cost function for amphibious movement. More...
 
static int amphibious_extra_cost (const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
 Extra cost call back for amphibious movement. More...
 
enum tile_behavior no_fights_or_unknown (const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
 PF callback to prohibit going into the unknown. More...
 
enum tile_behavior no_fights (const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
 PF callback to prohibit attacking anyone. More...
 
enum tile_behavior no_intermediate_fights (const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
 PF callback to prohibit attacking anyone, except at the destination. More...
 
static enum tile_behavior amphibious_behaviour (const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
 A callback for amphibious movement. More...
 
static bool is_possible_base_fuel (const struct tile *ptile, const struct pf_parameter *param)
 Refueling base for air units. More...
 
static int get_closest_safe_tile_distance (const struct tile *src_tile, const struct pf_parameter *param, int max_distance)
 Check if there is a safe position to move. More...
 
static int get_fuel_moves_left_req (const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
 Position-dangerous callback for air units. More...
 
static bool amphibious_is_pos_dangerous (const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
 Position-dangerous callback for amphibious movement. More...
 
static void pft_fill_default_parameter (struct pf_parameter *parameter, const struct unit_type *punittype)
 Fill general use parameters to defaults. More...
 
static void pft_enable_default_actions (struct pf_parameter *parameter)
 Enable default actions. More...
 
static void pft_fill_utype_default_parameter (struct pf_parameter *parameter, const struct unit_type *punittype, struct tile *pstart_tile, struct player *powner)
 Fill general use parameters to defaults for an unit type. More...
 
static void pft_fill_unit_default_parameter (struct pf_parameter *parameter, const struct unit *punit)
 Fill general use parameters to defaults for an unit. More...
 
static void pft_fill_parameter (struct pf_parameter *parameter, const struct unit_type *punittype)
 Base function to fill classic parameters. More...
 
void pft_fill_utype_parameter (struct pf_parameter *parameter, const struct unit_type *punittype, struct tile *pstart_tile, struct player *pplayer)
 Fill classic parameters for an unit type. More...
 
void pft_fill_unit_parameter (struct pf_parameter *parameter, const struct unit *punit)
 Fill classic parameters for an unit. More...
 
static void pft_fill_overlap_param (struct pf_parameter *parameter, const struct unit_type *punittype)
 pft_fill_*_overlap_param() base function. More...
 
void pft_fill_utype_overlap_param (struct pf_parameter *parameter, const struct unit_type *punittype, struct tile *pstart_tile, struct player *pplayer)
 Switch on one tile overlapping into the non-native terrain. More...
 
void pft_fill_unit_overlap_param (struct pf_parameter *parameter, const struct unit *punit)
 Switch on one tile overlapping into the non-native terrain. More...
 
static void pft_fill_attack_param (struct pf_parameter *parameter, const struct unit_type *punittype)
 pft_fill_*_attack_param() base function. More...
 
void pft_fill_unit_attack_param (struct pf_parameter *parameter, const struct unit *punit)
 pft_fill_*_attack_param() base function. More...
 
void pft_fill_reverse_parameter (struct pf_parameter *parameter, struct tile *target_tile)
 Fill default parameters for reverse map. More...
 
void pft_fill_amphibious_parameter (struct pft_amphibious *parameter)
 Fill parameters for combined sea-land movement. More...
 

Function Documentation

◆ amphibious_behaviour()

static enum tile_behavior amphibious_behaviour ( const struct tile ptile,
enum known_type  known,
const struct pf_parameter param 
)
static

A callback for amphibious movement.

Definition at line 432 of file pf_tools.cpp.

Referenced by pft_fill_amphibious_parameter().

◆ amphibious_extra_cost()

static int amphibious_extra_cost ( const struct tile ptile,
enum known_type  known,
const struct pf_parameter param 
)
static

Extra cost call back for amphibious movement.

Definition at line 432 of file pf_tools.cpp.

Referenced by pft_fill_amphibious_parameter().

◆ amphibious_is_pos_dangerous()

static bool amphibious_is_pos_dangerous ( const struct tile ptile,
enum known_type  known,
const struct pf_parameter param 
)
static

Position-dangerous callback for amphibious movement.

Definition at line 642 of file pf_tools.cpp.

Referenced by pft_fill_amphibious_parameter().

◆ amphibious_move()

static int amphibious_move ( const struct tile ptile,
enum pf_move_scope  src_scope,
const struct tile ptile1,
enum pf_move_scope  dst_scope,
const struct pf_parameter param 
)
static

A cost function for amphibious movement.

Definition at line 384 of file pf_tools.cpp.

Referenced by pft_fill_amphibious_parameter().

◆ amphibious_move_scope()

static enum pf_move_scope amphibious_move_scope ( const struct tile ptile,
bool *  can_disembark,
enum pf_move_scope  previous_scope,
const struct pf_parameter param 
)
static

A cost function for amphibious movement.

Definition at line 166 of file pf_tools.cpp.

Referenced by pft_fill_amphibious_parameter().

◆ get_closest_safe_tile_distance()

static int get_closest_safe_tile_distance ( const struct tile src_tile,
const struct pf_parameter param,
int  max_distance 
)
static

Check if there is a safe position to move.

Definition at line 590 of file pf_tools.cpp.

Referenced by get_fuel_moves_left_req().

◆ get_fuel_moves_left_req()

static int get_fuel_moves_left_req ( const struct tile ptile,
enum known_type  known,
const struct pf_parameter param 
)
static

Position-dangerous callback for air units.

Definition at line 617 of file pf_tools.cpp.

Referenced by pft_fill_attack_param(), pft_fill_overlap_param(), and pft_fill_parameter().

◆ is_possible_base_fuel()

static bool is_possible_base_fuel ( const struct tile ptile,
const struct pf_parameter param 
)
static

Refueling base for air units.

Definition at line 535 of file pf_tools.cpp.

Referenced by get_closest_safe_tile_distance(), and get_fuel_moves_left_req().

◆ no_fights()

enum tile_behavior no_fights ( const struct tile ptile,
enum known_type  known,
const struct pf_parameter param 
)

PF callback to prohibit attacking anyone.

Definition at line 432 of file pf_tools.cpp.

Referenced by dai_fill_unit_param().

◆ no_fights_or_unknown()

enum tile_behavior no_fights_or_unknown ( const struct tile ptile,
enum known_type  known,
const struct pf_parameter param 
)

PF callback to prohibit going into the unknown.

Also makes sure we don't plan to attack anyone.

Definition at line 432 of file pf_tools.cpp.

Referenced by find_best_city_placement().

◆ no_intermediate_fights()

enum tile_behavior no_intermediate_fights ( const struct tile ptile,
enum known_type  known,
const struct pf_parameter param 
)

PF callback to prohibit attacking anyone, except at the destination.

Definition at line 432 of file pf_tools.cpp.

Referenced by dai_fill_unit_param(), and dai_manage_diplomat().

◆ normal_move()

static int normal_move ( const struct tile src,
enum pf_move_scope  src_scope,
const struct tile dst,
enum pf_move_scope  dst_scope,
const struct pf_parameter param 
)
static

A cost function for regular movement.

Permits attacks. Use with a TB callback to prevent passing through occupied tiles. Does not permit passing through non-native tiles without transport.

Definition at line 351 of file pf_tools.cpp.

Referenced by pft_fill_attack_param(), pft_fill_parameter(), and pft_fill_reverse_parameter().

◆ overlap_move()

static int overlap_move ( const struct tile src,
enum pf_move_scope  src_scope,
const struct tile dst,
enum pf_move_scope  dst_scope,
const struct pf_parameter param 
)
static

A cost function for overlap movement.

Do not consider enemy units and attacks. Permits moves one step into non-native terrain (for ferries, etc.) Use with a TB callback to prevent passing through occupied tiles. Does not permit passing through non-native tiles without transport.

Definition at line 368 of file pf_tools.cpp.

Referenced by pft_fill_overlap_param().

◆ pf_action_possible()

static bool pf_action_possible ( const struct tile src,
enum pf_move_scope  src_scope,
const struct tile dst,
enum pf_action  action,
const struct pf_parameter param 
)
static

Determines if an action is possible from 'src' to 'dst': attack, diplomat action, or caravan action.

Definition at line 126 of file pf_tools.cpp.

Referenced by pft_enable_default_actions().

◆ pf_attack_possible()

static bool pf_attack_possible ( const struct tile ptile,
enum known_type  known,
const struct pf_parameter param 
)
inlinestatic

Can we attack 'ptile'? At this point, it assumes there are non-allied units on the tile.

Definition at line 37 of file pf_tools.cpp.

◆ pf_get_action()

static enum pf_action pf_get_action ( const struct tile ptile,
enum known_type  known,
const struct pf_parameter param 
)
static

Determines if a path to 'ptile' would be considered as action rather than normal move: attack, diplomat action, caravan action.

FIXME: For diplomat actions, we should take in account action enablers.

Definition at line 37 of file pf_tools.cpp.

Referenced by pft_enable_default_actions().

◆ pf_get_move_scope()

static enum pf_move_scope pf_get_move_scope ( const struct tile ptile,
bool *  can_disembark,
enum pf_move_scope  previous_scope,
const struct pf_parameter param 
)
static

Determine how it is possible to move from/to 'ptile'.

The checks for specific move from tile to tile is done in pf_move_possible().

Definition at line 166 of file pf_tools.cpp.

Referenced by pft_fill_default_parameter(), and pft_fill_reverse_parameter().

◆ pf_move_possible()

static bool pf_move_possible ( const struct tile src,
enum pf_move_scope  src_scope,
const struct tile dst,
enum pf_move_scope  dst_scope,
const struct pf_parameter param 
)
inlinestatic

Determines if the move between two tiles is possible.

Do not use this function as part of a test of whether a unit may attack a tile: many tiles that pass this test may be unsuitable for some units to attack to/from.

Does not check if the tile is occupied by non-allied units.

Definition at line 324 of file pf_tools.cpp.

Referenced by normal_move(), and overlap_move().

◆ pf_reverse_get_action()

static enum pf_action pf_reverse_get_action ( const struct tile ptile,
enum known_type  known,
const struct pf_parameter param 
)
static

Special case for reverse maps.

Always consider the target tile as attackable, notably for transports.

Definition at line 126 of file pf_tools.cpp.

Referenced by pft_fill_reverse_parameter().

◆ pf_transport_check()

static bool pf_transport_check ( const struct pf_parameter param,
const struct unit ptrans,
const struct unit_type trans_utype 
)
inlinestatic

Determine if we could load into 'ptrans' and its parents.

Definition at line 166 of file pf_tools.cpp.

Referenced by is_possible_base_fuel().

◆ pft_enable_default_actions()

static void pft_enable_default_actions ( struct pf_parameter parameter)
inlinestatic

Enable default actions.

Definition at line 685 of file pf_tools.cpp.

Referenced by pft_fill_attack_param(), and pft_fill_parameter().

◆ pft_fill_amphibious_parameter()

void pft_fill_amphibious_parameter ( struct pft_amphibious parameter)

Fill parameters for combined sea-land movement.

This is suitable for the case of a land unit riding a ferry. The starting position of the ferry is taken to be the starting position for the PF. The passenger is assumed to initailly be on the given ferry. The destination may be inland, in which case the passenger will ride the ferry to a beach head, disembark, then continue on land. One complexity of amphibious movement is that the movement rate on land might be different from that at sea. We therefore scale up the movement rates (and the corresponding movement consts) to the product of the two rates.

Definition at line 955 of file pf_tools.cpp.

◆ pft_fill_attack_param()

static void pft_fill_attack_param ( struct pf_parameter parameter,
const struct unit_type punittype 
)
static

pft_fill_*_attack_param() base function.

Consider attacking and non-attacking possibilities properly.

Definition at line 883 of file pf_tools.cpp.

Referenced by pft_fill_unit_attack_param().

◆ pft_fill_default_parameter()

static void pft_fill_default_parameter ( struct pf_parameter parameter,
const struct unit_type punittype 
)
inlinestatic

Fill general use parameters to defaults.

Definition at line 664 of file pf_tools.cpp.

Referenced by pft_fill_unit_default_parameter(), and pft_fill_utype_default_parameter().

◆ pft_fill_overlap_param()

static void pft_fill_overlap_param ( struct pf_parameter parameter,
const struct unit_type punittype 
)
static

pft_fill_*_overlap_param() base function.

Switch on one tile overlapping into the non-native terrain. For sea/land bombardment and for ferries.

Definition at line 835 of file pf_tools.cpp.

Referenced by pft_fill_unit_overlap_param(), and pft_fill_utype_overlap_param().

◆ pft_fill_parameter()

static void pft_fill_parameter ( struct pf_parameter parameter,
const struct unit_type punittype 
)
inlinestatic

Base function to fill classic parameters.

Definition at line 787 of file pf_tools.cpp.

Referenced by pft_fill_unit_parameter(), and pft_fill_utype_parameter().

◆ pft_fill_reverse_parameter()

void pft_fill_reverse_parameter ( struct pf_parameter parameter,
struct tile target_tile 
)

Fill default parameters for reverse map.

Definition at line 923 of file pf_tools.cpp.

Referenced by pf_reverse_map_new().

◆ pft_fill_unit_attack_param()

void pft_fill_unit_attack_param ( struct pf_parameter parameter,
const struct unit punit 
)

pft_fill_*_attack_param() base function.

Consider attacking and non-attacking possibilities properly.

Definition at line 913 of file pf_tools.cpp.

Referenced by dai_fill_unit_param(), find_rampage_target(), find_something_to_kill(), and goto_is_sane().

◆ pft_fill_unit_default_parameter()

static void pft_fill_unit_default_parameter ( struct pf_parameter parameter,
const struct unit punit 
)
inlinestatic

Fill general use parameters to defaults for an unit.

Definition at line 752 of file pf_tools.cpp.

Referenced by pft_fill_unit_attack_param(), pft_fill_unit_overlap_param(), and pft_fill_unit_parameter().

◆ pft_fill_unit_overlap_param()

void pft_fill_unit_overlap_param ( struct pf_parameter parameter,
const struct unit punit 
)

Switch on one tile overlapping into the non-native terrain.

For sea/land bombardment and for ferries.

Definition at line 871 of file pf_tools.cpp.

Referenced by dai_fill_unit_param(), find_best_city_placement(), and find_something_to_kill().

◆ pft_fill_unit_parameter()

◆ pft_fill_utype_default_parameter()

static void pft_fill_utype_default_parameter ( struct pf_parameter parameter,
const struct unit_type punittype,
struct tile pstart_tile,
struct player powner 
)
inlinestatic

Fill general use parameters to defaults for an unit type.

Definition at line 716 of file pf_tools.cpp.

Referenced by pft_fill_utype_overlap_param(), and pft_fill_utype_parameter().

◆ pft_fill_utype_overlap_param()

void pft_fill_utype_overlap_param ( struct pf_parameter parameter,
const struct unit_type punittype,
struct tile pstart_tile,
struct player pplayer 
)

Switch on one tile overlapping into the non-native terrain.

For sea/land bombardment and for ferry types.

Definition at line 857 of file pf_tools.cpp.

Referenced by find_something_to_kill().

◆ pft_fill_utype_parameter()

void pft_fill_utype_parameter ( struct pf_parameter parameter,
const struct unit_type punittype,
struct tile pstart_tile,
struct player pplayer 
)

Fill classic parameters for an unit type.

Definition at line 809 of file pf_tools.cpp.

Referenced by process_attacker_want().