Freeciv-3.3
Loading...
Searching...
No Matches
Functions
advgoto.c File Reference
#include "ai.h"
#include "combat.h"
#include "game.h"
#include "movement.h"
#include "unit.h"
#include "tile.h"
#include "path_finding.h"
#include "maphand.h"
#include "srv_log.h"
#include "unithand.h"
#include "unittools.h"
#include "advtools.h"
#include "advgoto.h"

Go to the source code of this file.

Functions

static bool adv_unit_move (struct unit *punit, struct tile *ptile)
 
bool adv_follow_path (struct unit *punit, struct pf_path *path, struct tile *ptile)
 
bool adv_unit_execute_path (struct unit *punit, struct pf_path *path)
 
static bool adv_could_be_my_zoc (struct unit *punit, struct tile *ptile)
 
int adv_could_unit_move_to_tile (struct unit *punit, struct tile *dest_tile)
 
int adv_unittype_att_rating (const struct unit_type *punittype, int veteran, int moves_left, int hp)
 
int adv_unit_att_rating (const struct unit *punit)
 
int adv_unit_def_rating_basic (const struct unit *punit)
 
int adv_unit_def_rating_basic_squared (const struct unit *punit)
 
bool adv_danger_at (struct unit *punit, struct tile *ptile)
 
static int stack_value (const struct tile *ptile, const struct player *pplayer)
 
static double chance_killed_at (const struct tile *ptile, struct adv_risk_cost *risk_cost, const struct pf_parameter *param)
 
static unsigned stack_risk (const struct tile *ptile, struct adv_risk_cost *risk_cost, const struct pf_parameter *param)
 
static unsigned prefer_short_stacks (const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
 
void adv_avoid_risks (struct pf_parameter *parameter, struct adv_risk_cost *risk_cost, struct unit *punit, const double fearfulness)
 

Function Documentation

◆ adv_avoid_risks()

void adv_avoid_risks ( struct pf_parameter parameter,
struct adv_risk_cost risk_cost,
struct unit punit,
const double  fearfulness 
)

Set PF callbacks to favour paths that do not create tall stacks or cross dangerous tiles.

Definition at line 595 of file advgoto.c.

Referenced by dai_fill_unit_param(), and explorer_goto().

◆ adv_could_be_my_zoc()

static bool adv_could_be_my_zoc ( struct unit punit,
struct tile ptile 
)
static

Similar to is_my_zoc(), but with some changes:

  • destination (x0, y0) need not be adjacent?
  • don't care about some directions?

Fix to bizarre did-not-find bug. Thanks, Katvrr – Syela

Definition at line 324 of file advgoto.c.

Referenced by adv_could_unit_move_to_tile().

◆ adv_could_unit_move_to_tile()

int adv_could_unit_move_to_tile ( struct unit punit,
struct tile dest_tile 
)

returns: 0 if can't move 1 if zoc_ok -1 if zoc could be ok?

see also unithand can_unit_move_to_tile_with_notify()

Definition at line 359 of file advgoto.c.

Referenced by dai_manage_barbarian_leader(), and remove_city().

◆ adv_danger_at()

bool adv_danger_at ( struct unit punit,
struct tile ptile 
)

Are there dangerous enemies at or adjacent to the tile 'ptile'?

Definition at line 425 of file advgoto.c.

Referenced by adv_unit_move(), city_desirability(), and dai_unit_move().

◆ adv_follow_path()

bool adv_follow_path ( struct unit punit,
struct pf_path path,
struct tile ptile 
)

Move a unit along a path without disturbing its activity, role or assigned destination Return FALSE iff we died.

Definition at line 47 of file advgoto.c.

Referenced by auto_worker_setup_work(), dai_manage_airunit(), dai_manage_barbarian_leader(), dai_military_attack(), dai_unit_goto_constrained(), explorer_goto(), and player_restore_units().

◆ adv_unit_att_rating()

int adv_unit_att_rating ( const struct unit punit)

Attack rating of this particular unit assuming that it has a complete move left.

Definition at line 396 of file advgoto.c.

Referenced by adv_danger_at(), assess_danger_unit(), dai_consider_tile_dangerous(), dai_gothere_bodyguard(), find_something_to_kill(), kill_something_with(), reinforcements_cost_and_value(), and unit_att_rating_squared().

◆ adv_unit_def_rating_basic()

int adv_unit_def_rating_basic ( const struct unit punit)

Basic (i.e. not taking attacker specific corrections into account) defense rating of this particular unit.

Definition at line 406 of file advgoto.c.

Referenced by adv_unit_def_rating_basic_squared(), and dai_military_findjob().

◆ adv_unit_def_rating_basic_squared()

int adv_unit_def_rating_basic_squared ( const struct unit punit)

Square of the previous function - used in actual computations.

Definition at line 415 of file advgoto.c.

Referenced by adv_danger_at(), dai_consider_tile_dangerous(), and look_for_charge().

◆ adv_unit_execute_path()

bool adv_unit_execute_path ( struct unit punit,
struct pf_path path 
)

This is a function to execute paths returned by the path-finding engine, for units controlled by advisors.

Brings our bodyguard along. Returns FALSE only if died.

Definition at line 86 of file advgoto.c.

Referenced by adv_follow_path(), dai_diplomat_bribe_nearby(), dai_find_boat_for_unit(), dai_hunter_manage(), dai_manage_diplomat(), and dai_military_rampage().

◆ adv_unit_move()

static bool adv_unit_move ( struct unit punit,
struct tile ptile 
)
static

Move a unit. Do not attack. Do not leave bodyguard. For advisor controlled units.

This function returns only when we have a reply from the server and we can tell the calling function what happened to the move request. (Right now it is not a big problem, since we call the server directly.)

Definition at line 156 of file advgoto.c.

Referenced by adv_unit_execute_path().

◆ adv_unittype_att_rating()

int adv_unittype_att_rating ( const struct unit_type punittype,
int  veteran,
int  moves_left,
int  hp 
)

Attack rating of this kind of unit.

Definition at line 385 of file advgoto.c.

Referenced by adv_unit_att_rating(), dai_gothere_bodyguard(), process_attacker_want(), and unit_att_rating_now().

◆ chance_killed_at()

static double chance_killed_at ( const struct tile ptile,
struct adv_risk_cost risk_cost,
const struct pf_parameter param 
)
static

How dangerous would it be stop on a particular tile, because of enemy attacks, expressed as the probability of being killed.

TODO: This implementation is a kludge until we compute a more accurate probability using the movemap. Also, we should take into account the reduced probability of death if we have a bodyguard travelling with us.

Definition at line 507 of file advgoto.c.

Referenced by stack_risk().

◆ prefer_short_stacks()

static unsigned prefer_short_stacks ( const struct tile ptile,
enum known_type  known,
const struct pf_parameter param 
)
static

PF extra cost call back to avoid creating tall stacks or crossing dangerous tiles. By setting this as an extra-cost call-back, paths will avoid tall stacks. Avoiding tall stacks all along a path is useful because a unit following a path might have to stop early because of ZoCs.

Definition at line 584 of file advgoto.c.

Referenced by adv_avoid_risks().

◆ stack_risk()

static unsigned stack_risk ( const struct tile ptile,
struct adv_risk_cost risk_cost,
const struct pf_parameter param 
)
static

PF stack risk cost. How undesirable is passing through a tile because of risks? Weight by the cost of destruction, for risks that can kill the unit.

Why use the build cost when assessing the cost of destruction? The reasoning is thus.

  • Assume that all our units are doing necessary jobs; none are surplus to requirements. If that is not the case, we have problems elsewhere :-)
  • Then any units that are destroyed will have to be replaced.
  • The cost of replacing them will be their build cost.
  • Therefore the total (re)build cost is a good representation of the the cost of destruction.

Definition at line 548 of file advgoto.c.

Referenced by prefer_short_stacks().

◆ stack_value()

static int stack_value ( const struct tile ptile,
const struct player pplayer 
)
static

The value of the units belonging to a given player on a given tile.

Definition at line 481 of file advgoto.c.

Referenced by stack_risk().