Freeciv-3.2: /fast/freeciv/nightly/S3_2/ai/default/aitools.c File Reference

Freeciv-3.2

Loading...
Searching...
No Matches
Macros | Functions
aitools.c File Reference
`#include "bitvector.h"`
`#include "log.h"`
`#include "mem.h"`
`#include "shared.h"`
`#include "city.h"`
`#include "combat.h"`
`#include "game.h"`
`#include "government.h"`
`#include "map.h"`
`#include "movement.h"`
`#include "nation.h"`
`#include "packets.h"`
`#include "player.h"`
`#include "unit.h"`
`#include "unitlist.h"`
`#include "citymap.h"`
`#include "pf_tools.h"`
`#include "barbarian.h"`
`#include "citytools.h"`
`#include "cityturn.h"`
`#include "maphand.h"`
`#include "plrhand.h"`
`#include "score.h"`
`#include "srv_log.h"`
`#include "unithand.h"`
`#include "unittools.h"`
`#include "advdata.h"`
`#include "advgoto.h"`
`#include "advtools.h"`
`#include "autosettlers.h"`
`#include "infracache.h"`
`#include "handicaps.h"`
`#include "aiferry.h"`
`#include "aiguard.h"`
`#include "aitech.h"`
`#include "daidata.h"`
`#include "dailog.h"`
`#include "daimilitary.h"`
`#include "daiplayer.h"`
`#include "aitools.h"`

Go to the source code of this file.

## Macros

#define | LOGLEVEL_GOTHERE LOG_DEBUG
#define | LONG_TIME 4

## Functions

const char * | dai_unit_task_rule_name (const enum ai_unit_task task)
adv_want | military_amortize (struct player *pplayer, struct city *pcity, adv_want value, int delay, int build_cost)
void | dai_consider_plr_dangerous (struct ai_type *ait, struct player *plr1, struct player *plr2, enum override_bool *result)
static bool | dai_gothere_bodyguard (struct ai_type *ait, struct unit *punit, struct tile *dest_tile)
bool | dai_gothere (struct ai_type *ait, struct player *pplayer, struct unit *punit, struct tile *dest_tile)
struct tile * | immediate_destination (struct unit *punit, struct tile *dest_tile)
void | dai_log_path (struct unit *punit, struct pf_path *path, struct pf_parameter *parameter)
bool | dai_unit_goto_constrained (struct ai_type *ait, struct unit *punit, struct tile *ptile, struct pf_parameter *parameter)
bool | goto_is_sane (struct unit *punit, struct tile *ptile)
void | dai_fill_unit_param (struct ai_type *ait, struct pf_parameter *parameter, struct adv_risk_cost *risk_cost, struct unit *punit, struct tile *ptile)
bool | dai_unit_goto (struct ai_type *ait, struct unit *punit, struct tile *ptile)
void | dai_unit_new_adv_task (struct ai_type *ait, struct unit *punit, enum adv_unit_task task, struct tile *ptile)
void | dai_unit_new_task (struct ai_type *ait, struct unit *punit, enum ai_unit_task task, struct tile *ptile)
bool | dai_unit_make_homecity (struct unit *punit, struct city *pcity)
static void | dai_unit_bodyguard_move (struct ai_type *ait, struct unit *bodyguard, struct tile *ptile)
bool | dai_unit_attack (struct ai_type *ait, struct unit *punit, struct tile *ptile)
void | dai_unit_move_or_attack (struct ai_type *ait, struct unit *punit, struct tile *ptile, struct pf_path *path, int step)
bool | dai_unit_move (struct ai_type *ait, struct unit *punit, struct tile *ptile)
int | stack_cost (struct unit *pattacker, struct unit *pdefender)
void | dai_government_change (struct player *pplayer, struct government *gov)
int | dai_gold_reserve (struct player *pplayer)
void | adjust_choice (int pct, struct adv_choice *choice)
bool | dai_choose_role_unit (struct ai_type *ait, struct player *pplayer, struct city *pcity, struct adv_choice *choice, enum choice_type type, int role, int want, bool need_boat)
void | dai_build_adv_override (struct ai_type *ait, struct city *pcity, struct adv_choice *choice)
bool | dai_assess_military_unhappiness (struct city *pcity)

## Macro Definition Documentation

## ◆ LOGLEVEL_GOTHERE

#define LOGLEVEL_GOTHERE LOG_DEBUG

Definition at line 233 of file aitools.c.

## ◆ LONG_TIME

#define LONG_TIME 4

Definition at line 455 of file aitools.c.

## Function Documentation

## ◆ adjust_choice()

void adjust_choice | ( | int | pct,
|  | struct adv_choice * | choice
| ) |  |

Adjust want for choice to given percentage.

Definition at line 1335 of file aitools.c.

## ◆ dai_assess_military_unhappiness()

bool dai_assess_military_unhappiness | ( | struct city * | pcity | ) |

"The following evaluates the unhappiness caused by military units in the field (or aggressive) at a city when at Republic or Democracy. Now generalised somewhat for government rulesets, though I'm not sure whether it is fully general for all possible parameters/ combinations." –dwp

Definition at line 1415 of file aitools.c.

Referenced by find_something_to_kill(), and process_attacker_want().

## ◆ dai_build_adv_override()

void dai_build_adv_override | ( | struct ai_type * | ait,
|  | struct city * | pcity,
|  | struct adv_choice * | choice
| ) |  |

Consider overriding building target selected by common advisor code.

Definition at line 1367 of file aitools.c.

Referenced by cai_build_adv_override(), and texwai_build_adv_override().

## ◆ dai_choose_role_unit()

bool dai_choose_role_unit | ( | struct ai_type * | ait,
|  | struct player * | pplayer,
|  | struct city * | pcity,
|  | struct adv_choice * | choice,
|  | enum choice_type | type,
|  | int | role,
|  | int | want,
|  | bool | need_boat
| ) |  |

Calls dai_wants_role_unit to choose the best unit with the given role and set tech wants. Sets choice->value.utype when we can build something.

Definition at line 1344 of file aitools.c.

Referenced by domestic_advisor_choose_build(), and kill_something_with().

## ◆ dai_consider_plr_dangerous()

void dai_consider_plr_dangerous | ( | struct ai_type * | ait,
|  | struct player * | plr1,
|  | struct player * | plr2,
|  | enum override_bool * | result
| ) |  |

There are some signs that a player might be dangerous: We are at war with them, they have done lots of ignoble things to us, they are an ally of one of our enemies (a ticking bomb to be sure), they are our war target, we don't like them, diplomatic state is neutral or we have case fire. This function is used for example to check if pplayer can leave their city undefended when aplayer's units are near it.

Definition at line 142 of file aitools.c.

Referenced by cai_consider_plr_dangerous(), and texwai_consider_plr_dangerous().

## ◆ dai_fill_unit_param()

void dai_fill_unit_param | ( | struct ai_type * | ait,
|  | struct pf_parameter * | parameter,
|  | struct adv_risk_cost * | risk_cost,
|  | struct unit * | punit,
|  | struct tile * | ptile
| ) |  |

Set up the constraints on a path for an AI unit.

parameter: constraints (output) risk_cost: auxiliary data used by the constraints (output) ptile: the destination of the unit. For ferries, the destination may be a coastal land tile, in which case the ferry should stop on an adjacent tile.

Definition at line 468 of file aitools.c.

Referenced by dai_unit_goto().

## ◆ dai_gold_reserve()

int dai_gold_reserve | ( | struct player * | pplayer | ) |

Credits the AI wants to have in reserves. We need some gold to bribe and incite cities.

"I still don't trust this function" – Syela

Definition at line 1325 of file aitools.c.

Referenced by dai_diplomat_bribe_nearby(), dai_manage_taxes(), and dai_spend_gold().

## ◆ dai_gothere()

bool dai_gothere | ( | struct ai_type * | ait,
|  | struct player * | pplayer,
|  | struct unit * | punit,
|  | struct tile * | dest_tile
| ) |  |

This is ferry-enabled goto. Should not normally be used for non-ferried units (i.e. planes or ships), use dai_unit_goto instead.

Return values: TRUE if got to or next to our destination, FALSE otherwise.

TODO: A big one is rendezvous points. When this is implemented, we won't have to be at the coast to ask for a boat to come to us.

Definition at line 243 of file aitools.c.

Referenced by dai_auto_settler_run(), dai_caravan_goto(), dai_military_attack_barbarian(), dai_military_bodyguard(), and dai_military_defend().

## ◆ dai_gothere_bodyguard()

static bool dai_gothere_bodyguard | ( | struct ai_type * | ait,
|  | struct unit * | punit,
|  | struct tile * | dest_tile
| ) |  |

static

A helper function for ai_gothere. Estimates the dangers we will be facing at our destination and tries to find/request a bodyguard if needed.

Definition at line 161 of file aitools.c.

Referenced by dai_gothere().

## ◆ dai_government_change()

void dai_government_change | ( | struct player * | pplayer,
|  | struct government * | gov
| ) |  |

Change government, pretty fast...

Definition at line 1306 of file aitools.c.

Referenced by dai_manage_government().

## ◆ dai_log_path()

void dai_log_path | ( | struct unit * | punit,
|  | struct pf_path * | path,
|  | struct pf_parameter * | parameter
| ) |  |

Log the cost of travelling a path.

Definition at line 355 of file aitools.c.

Referenced by dai_unit_goto_constrained().

## ◆ dai_unit_attack()

bool dai_unit_attack | ( | struct ai_type * | ait,
|  | struct unit * | punit,
|  | struct tile * | ptile
| ) |  |

Move and attack with an ai unit. We do not wait for server reply.

Definition at line 816 of file aitools.c.

Referenced by dai_hunter_try_launch(), dai_military_attack(), and dai_unit_move_or_attack().

## ◆ dai_unit_bodyguard_move()

static void dai_unit_bodyguard_move | ( | struct ai_type * | ait,
|  | struct unit * | bodyguard,
|  | struct tile * | ptile
| ) |  |

static

Move a bodyguard along with another unit. We assume that unit has already been moved to ptile which is a valid, safe tile, and that our bodyguard has not. This is an ai_unit_* auxiliary function, do not use elsewhere.

Definition at line 783 of file aitools.c.

Referenced by dai_unit_attack(), and dai_unit_move().

## ◆ dai_unit_goto()

bool dai_unit_goto | ( | struct ai_type * | ait,
|  | struct unit * | punit,
|  | struct tile * | ptile
| ) |  |

Go to specified destination but do not disturb existing role or activity and do not clear the role's destination. Return FALSE iff we died.

Definition at line 604 of file aitools.c.

Referenced by dai_caravan_goto(), dai_find_boat_for_unit(), dai_gothere(), dai_hunter_try_launch(), dai_manage_barbarian_leader(), dai_manage_hitpoint_recovery(), dai_manage_paratrooper(), dai_military_attack(), and search_homecity_for_caravan().

## ◆ dai_unit_goto_constrained()

bool dai_unit_goto_constrained | ( | struct ai_type * | ait,
|  | struct unit * | punit,
|  | struct tile * | ptile,
|  | struct pf_parameter * | parameter
| ) |  |

Go to specified destination, subject to given PF constraints, but do not disturb existing role or activity and do not clear the role's destination. Return FALSE iff we died.

parameter: the PF constraints on the computed path. The unit will move as far along the computed path is it can; the movement code will impose all the real constraints (ZoC, etc).

Definition at line 377 of file aitools.c.

Referenced by dai_unit_goto().

## ◆ dai_unit_make_homecity()

bool dai_unit_make_homecity | ( | struct unit * | punit,
|  | struct city * | pcity
| ) |  |

Try to make pcity our new homecity. Fails if we can't upkeep it. Assumes success from server.

Definition at line 754 of file aitools.c.

Referenced by search_homecity_for_caravan().

## ◆ dai_unit_move()

bool dai_unit_move | ( | struct ai_type * | ait,
|  | struct unit * | punit,
|  | struct tile * | ptile
| ) |  |

Move a unit. Do not attack. Do not leave bodyguard. For AI 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 1083 of file aitools.c.

Referenced by dai_unit_bodyguard_move(), and dai_unit_move_or_attack().

## ◆ dai_unit_move_or_attack()

void dai_unit_move_or_attack | ( | struct ai_type * | ait,
|  | struct unit * | punit,
|  | struct tile * | ptile,
|  | struct pf_path * | path,
|  | int | step
| ) |  |

Ai unit moving function called from AI interface.

Definition at line 1065 of file aitools.c.

Referenced by cai_unit_move_or_attack(), and texwai_unit_move_or_attack().

## ◆ dai_unit_new_adv_task()

void dai_unit_new_adv_task | ( | struct ai_type * | ait,
|  | struct unit * | punit,
|  | enum adv_unit_task | task,
|  | struct tile * | ptile
| ) |  |

Adviser task for unit has been changed.

Definition at line 618 of file aitools.c.

Referenced by cai_unit_new_adv_task(), and texwai_unit_new_adv_task().

## ◆ dai_unit_new_task()

void dai_unit_new_task | ( | struct ai_type * | ait,
|  | struct unit * | punit,
|  | enum ai_unit_task | task,
|  | struct tile * | ptile
| ) |  |

Ensure unit sanity by telling charge that we won't bodyguard it anymore, tell bodyguard it can roam free if our job is done, add and remove city spot reservation, and set destination. If we set a unit to hunter, also reserve its target, and try to load it with cruise missiles or nukes to bring along.

Definition at line 642 of file aitools.c.

Referenced by dai_auto_settler_run(), dai_diplomat_city(), dai_do_build_city(), dai_hunter_manage(), dai_manage_caravan(), dai_manage_diplomat(), dai_manage_hitpoint_recovery(), dai_manage_military(), dai_manage_unit(), dai_manage_units(), dai_military_bodyguard(), dai_military_findjob(), dai_set_defenders(), dai_unit_new_adv_task(), and dai_unit_new_task().

## ◆ dai_unit_task_rule_name()

const char * dai_unit_task_rule_name | ( | const enum ai_unit_task | task | ) |

Return the (untranslated) rule name of the ai_unit_task. You don't have to free the return pointer.

Definition at line 77 of file aitools.c.

Referenced by dai_caravan_goto(), dai_manage_caravan(), and dai_unit_new_task().

## ◆ goto_is_sane()

bool goto_is_sane | ( | struct unit * | punit,
|  | struct tile * | ptile
| ) |  |

Use pathfinding to determine whether a GOTO is possible, considering all aspects of the unit being moved and the terrain under consideration. Don't bother with pathfinding if the unit is already there.

Definition at line 428 of file aitools.c.

Referenced by dai_gothere(), dai_is_unit_tired_waiting_boat(), dai_manage_barbarian_leader(), dai_military_bodyguard(), and dai_unit_goto_constrained().

## ◆ immediate_destination()

struct tile * immediate_destination | ( | struct unit * | punit,
|  | struct tile * | dest_tile
| ) |  |

Returns the destination for a unit moving towards a given final destination. That is, it gives a suitable way-point, if necessary. For example, aircraft need these way-points to refuel.

Definition at line 301 of file aitools.c.

## ◆ military_amortize()

adv_want military_amortize | ( | struct player * | pplayer,
|  | struct city * | pcity,
|  | adv_want | value,
|  | int | delay,
|  | int | build_cost
| ) |  |

Amortize a want modified by the shields (build_cost) we risk losing. We add the build time of the unit(s) we risk to amortize delay. The build time is calculated as the build cost divided by the production output of the unit's homecity or the city where we want to produce the unit. If the city has less than average shield output, we use the average instead, to encourage long-term thinking.

Definition at line 118 of file aitools.c.

Referenced by dai_choose_diplomat_offensive(), dai_evaluate_tile_for_air_attack(), find_something_to_kill(), and process_attacker_want().

## ◆ stack_cost()

int stack_cost | ( | struct unit * | pattacker,
|  | struct unit * | pdefender
| ) |  |

Calculate the value of the target unit including the other units which will die in a successful attack

Definition at line 1280 of file aitools.c.

Referenced by dai_evaluate_tile_for_air_attack(), and dai_rampage_want().