Freeciv-3.2
Loading...
Searching...
No Matches
Functions
pf_tools.c File Reference
#include <string.h>
#include "bitvector.h"
#include "log.h"
#include "mem.h"
#include "base.h"
#include "combat.h"
#include "game.h"
#include "movement.h"
#include "tile.h"
#include "unit.h"
#include "unittype.h"
#include "aiactions.h"
#include "pf_tools.h"

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)
 
static enum pf_action pf_get_action (const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
 
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 enum pf_action pf_reverse_get_action (const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
 
static bool pf_transport_check (const struct pf_parameter *param, const struct unit *ptrans, const struct unit_type *trans_utype)
 
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 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 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)
 
static unsigned 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 unsigned 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 unsigned 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 unsigned amphibious_extra_cost (const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
 
enum tile_behavior no_fights_or_unknown (const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
 
enum tile_behavior no_fights (const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
 
enum tile_behavior no_intermediate_fights (const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
 
static enum tile_behavior amphibious_behaviour (const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
 
static bool is_possible_base_fuel (const struct tile *ptile, const struct pf_parameter *param)
 
static int get_closest_safe_tile_distance (const struct tile *src_tile, const struct pf_parameter *param, int max_distance)
 
static int get_fuel_moves_left_req (const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
 
static bool amphibious_is_pos_dangerous (const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
 
static void pft_fill_default_parameter (struct pf_parameter *parameter, const struct civ_map *nmap, const struct unit_type *punittype)
 
static void pft_enable_default_actions (struct pf_parameter *parameter)
 
static void pft_fill_utype_default_parameter (struct pf_parameter *parameter, const struct civ_map *nmap, const struct unit_type *punittype, struct tile *pstart_tile, struct player *powner)
 
static void pft_fill_unit_default_parameter (struct pf_parameter *parameter, const struct civ_map *nmap, const struct unit *punit)
 
static void pft_fill_parameter (struct pf_parameter *parameter, const struct unit_type *punittype)
 
void pft_fill_utype_parameter (struct pf_parameter *parameter, const struct civ_map *nmap, const struct unit_type *punittype, struct tile *pstart_tile, struct player *pplayer)
 
void pft_fill_unit_parameter (struct pf_parameter *parameter, const struct civ_map *nmap, const struct unit *punit)
 
static void pft_fill_overlap_param (struct pf_parameter *parameter, const struct unit_type *punittype)
 
void pft_fill_utype_overlap_param (struct pf_parameter *parameter, const struct civ_map *nmap, const struct unit_type *punittype, struct tile *pstart_tile, struct player *pplayer)
 
void pft_fill_unit_overlap_param (struct pf_parameter *parameter, const struct civ_map *nmap, const struct unit *punit)
 
static void pft_fill_attack_param (struct pf_parameter *parameter, const struct unit_type *punittype)
 
void pft_fill_utype_attack_param (struct pf_parameter *parameter, const struct civ_map *nmap, const struct unit_type *punittype, struct tile *pstart_tile, struct player *pplayer)
 
void pft_fill_unit_attack_param (struct pf_parameter *parameter, const struct civ_map *nmap, const struct unit *punit)
 
void pft_fill_reverse_parameter (const struct civ_map *nmap, struct pf_parameter *parameter, struct tile *target_tile)
 
void pft_fill_amphibious_parameter (struct pft_amphibious *parameter)
 

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 539 of file pf_tools.c.

Referenced by pft_fill_amphibious_parameter().

◆ amphibious_extra_cost()

static unsigned 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 453 of file pf_tools.c.

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 659 of file pf_tools.c.

Referenced by pft_fill_amphibious_parameter().

◆ amphibious_move()

static unsigned 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 403 of file pf_tools.c.

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 304 of file pf_tools.c.

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 610 of file pf_tools.c.

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 635 of file pf_tools.c.

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 559 of file pf_tools.c.

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 509 of file pf_tools.c.

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 493 of file pf_tools.c.

Referenced by find_best_city_placement(), manage_auto_explorer(), and no_fights_or_unknown_goto().

◆ 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 524 of file pf_tools.c.

Referenced by dai_fill_unit_param(), and dai_manage_diplomat().

◆ normal_move()

static unsigned 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 364 of file pf_tools.c.

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

◆ overlap_move()

static unsigned 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 384 of file pf_tools.c.

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 139 of file pf_tools.c.

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 45 of file pf_tools.c.

Referenced by pf_get_action().

◆ 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 96 of file pf_tools.c.

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 228 of file pf_tools.c.

Referenced by amphibious_move_scope(), 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 335 of file pf_tools.c.

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 167 of file pf_tools.c.

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 177 of file pf_tools.c.

Referenced by is_possible_base_fuel(), and pf_get_move_scope().

◆ pft_enable_default_actions()

static void pft_enable_default_actions ( struct pf_parameter parameter)
inlinestatic

Enable default actions.

Definition at line 704 of file pf_tools.c.

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 initially to 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 994 of file pf_tools.c.

◆ 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 904 of file pf_tools.c.

Referenced by pft_fill_unit_attack_param(), and pft_fill_utype_attack_param().

◆ pft_fill_default_parameter()

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

Fill general use parameters to defaults.

Definition at line 681 of file pf_tools.c.

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 854 of file pf_tools.c.

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 804 of file pf_tools.c.

Referenced by pft_fill_unit_parameter(), and pft_fill_utype_parameter().

◆ pft_fill_reverse_parameter()

void pft_fill_reverse_parameter ( const struct civ_map nmap,
struct pf_parameter parameter,
struct tile target_tile 
)

Fill default parameters for reverse map.

Definition at line 960 of file pf_tools.c.

Referenced by pf_reverse_map_new().

◆ pft_fill_unit_attack_param()

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

pft_fill_*_attack_param() base function.

Consider attacking and non-attacking possibilities properly.

Definition at line 949 of file pf_tools.c.

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 civ_map nmap,
const struct unit punit 
)
inlinestatic

Fill general use parameters to defaults for an unit.

Definition at line 770 of file pf_tools.c.

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 civ_map nmap,
const struct unit punit 
)

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

Definition at line 891 of file pf_tools.c.

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

◆ pft_fill_unit_parameter()

void pft_fill_unit_parameter ( struct pf_parameter parameter,
const struct civ_map nmap,
const struct unit punit 
)

◆ pft_fill_utype_attack_param()

void pft_fill_utype_attack_param ( struct pf_parameter parameter,
const struct civ_map nmap,
const struct unit_type punittype,
struct tile pstart_tile,
struct player pplayer 
)

pft_fill_*_attack_param() base function.

Consider attacking and non-attacking possibilities properly.

Definition at line 933 of file pf_tools.c.

◆ pft_fill_utype_default_parameter()

static void pft_fill_utype_default_parameter ( struct pf_parameter parameter,
const struct civ_map nmap,
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 732 of file pf_tools.c.

Referenced by pft_fill_utype_attack_param(), 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 civ_map nmap,
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 876 of file pf_tools.c.

Referenced by find_something_to_kill().

◆ pft_fill_utype_parameter()

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

Fill classic parameters for an unit type.

Definition at line 826 of file pf_tools.c.

Referenced by process_attacker_want().