![]() |
Freeciv21
Develop your civilization from humble roots to a global empire
|
#include "bitvector.h"#include "rand.h"#include "registry.h"#include "registry_ini.h"#include "city.h"#include "combat.h"#include "game.h"#include "map.h"#include "movement.h"#include "nation.h"#include "specialist.h"#include "traderoutes.h"#include "unit.h"#include "unitlist.h"#include "caravan.h"#include "pf_tools.h"#include "barbarian.h"#include "citytools.h"#include "maphand.h"#include "srv_log.h"#include "unithand.h"#include "advbuilding.h"#include "advgoto.h"#include "advtools.h"#include "autoexplorer.h"#include "autosettlers.h"#include "difficulty.h"#include "handicaps.h"#include "aiair.h"#include "aidata.h"#include "aidiplomat.h"#include "aiferry.h"#include "aiguard.h"#include "aihunt.h"#include "ailog.h"#include "aiparatrooper.h"#include "aiplayer.h"#include "aitools.h"#include "daicity.h"#include "daieffects.h"#include "daimilitary.h"#include "aiunit.h"
Include dependency graph for aiunit.cpp:Go to the source code of this file.
Classes | |
| struct | role_unit_cb_data |
Macros | |
| #define | LOGLEVEL_RECOVERY LOG_DEBUG |
| #define | LOG_CARAVAN LOG_DEBUG |
| #define | LOG_CARAVAN2 LOG_DEBUG |
| #define | LOG_CARAVAN3 LOG_DEBUG |
Functions | |
| static bool | dai_find_boat_for_unit (struct ai_type *ait, struct unit *punit) |
| Request a boat for a unit to transport it to another continent. More... | |
| static bool | dai_caravan_can_trade_cities_diff_cont (struct player *pplayer, struct unit *punit) |
| Check if a caravan can make a trade route to a city on a different continent. More... | |
| static void | dai_manage_caravan (struct ai_type *ait, struct player *pplayer, struct unit *punit) |
| Use caravans for building wonders, or send caravans to establish trade with a city, owned by yourself or an ally. More... | |
| static void | dai_manage_barbarian_leader (struct ai_type *ait, struct player *pplayer, struct unit *leader) |
| Barbarian leader tries to stack with other barbarian units, and if it's not possible it runs away. More... | |
| static void | dai_military_findjob (struct ai_type *ait, struct player *pplayer, struct unit *punit) |
| See if we have a specific job for the unit. More... | |
| static void | dai_military_defend (struct ai_type *ait, struct player *pplayer, struct unit *punit) |
| Send a unit to the city it should defend. More... | |
| static void | dai_military_attack (struct ai_type *ait, struct player *pplayer, struct unit *punit) |
| This does the attack until we have used up all our movement, unless we should safeguard a city. More... | |
| static bool | unit_role_defender (const struct unit_type *punittype) |
| Does the unit with the id given have the flag L_DEFEND_GOOD? More... | |
| static int | unit_def_rating_squared (const struct unit *attacker, const struct unit *defender) |
| Square of the previous function - used in actual computations. More... | |
| static struct city * | find_neediest_airlift_city (struct ai_type *ait, const struct player *pplayer) |
| Returns the city with the most need of an airlift. More... | |
| static void | dai_airlift (struct ai_type *ait, struct player *pplayer) |
| Move defenders around with airports. More... | |
| static bool | has_defense (struct city *pcity) |
| This is a much simplified form of assess_defense (see daimilitary.c), but which doesn't use pcity->server.ai.wallvalue and just returns a boolean value. More... | |
| int | build_cost_balanced (const struct unit_type *punittype) |
| In the words of Syela: "Using funky fprime variable instead of f in the denom, so that def=1 units are penalized correctly. More... | |
| static int | unit_att_rating_now (const struct unit *punit) |
| Attack rating of this particular unit right now. More... | |
| static int | unit_att_rating_squared (const struct unit *punit) |
| Square of the adv_unit_att_rating() function - used in actual computations. More... | |
| static int | unit_def_rating (const struct unit *attacker, const struct unit *defender) |
| Defence rating of this particular unit against this attacker. More... | |
| int | unittype_def_rating_squared (const struct unit_type *att_type, const struct unit_type *def_type, struct player *def_player, struct tile *ptile, bool fortified, int veteran) |
| Defence rating of def_type unit against att_type unit, squared. More... | |
| int | kill_desire (int benefit, int attack, int loss, int vuln, int victim_count) |
| Compute how much we want to kill certain victim we've chosen, counted in SHIELDs. More... | |
| static int | avg_benefit (int benefit, int loss, double chance) |
| Compute how much we want to kill certain victim we've chosen, counted in SHIELDs. More... | |
| static void | reinforcements_cost_and_value (struct unit *punit, struct tile *ptile0, int *value, int *cost) |
| Calculates the value and cost of nearby allied units to see if we can expect any help in our attack. More... | |
| static bool | is_my_turn (struct unit *punit, struct unit *pdef) |
| Is there another unit which really should be doing this attack? Checks all adjacent tiles and the tile we stand on for such units. More... | |
| static int | dai_rampage_want (struct unit *punit, struct tile *ptile) |
| This function appraises the location (x, y) for a quick hit-n-run operation. More... | |
| static PFPath | find_rampage_target (struct unit *punit, int thresh_adj, int thresh_move) |
| Look for worthy targets within a one-turn horizon. More... | |
| bool | dai_military_rampage (struct unit *punit, int thresh_adj, int thresh_move) |
| Find and kill anything reachable within this turn and worth more than the relevant of the given thresholds until we have run out of juicy targets or movement. More... | |
| static void | dai_military_bodyguard (struct ai_type *ait, struct player *pplayer, struct unit *punit) |
| If we are not covering our charge's ass, go do it now. More... | |
| int | look_for_charge (struct ai_type *ait, struct player *pplayer, struct unit *punit, struct unit **aunit, struct city **acity) |
| See if we can find something to defend. More... | |
| bool | dai_can_unit_type_follow_unit_type (const struct unit_type *follower, const struct unit_type *followee, struct ai_type *ait) |
| See if the follower can follow the followee. More... | |
| static void | invasion_funct (struct ai_type *ait, struct unit *punit, bool dest, int radius, int which) |
| Mark invasion possibilities of punit in the surrounding cities. More... | |
| bool | find_beachhead (const struct player *pplayer, struct pf_map *ferry_map, struct tile *dest_tile, const struct unit_type *cargo_type, struct tile **ferry_dest, struct tile **beachhead_tile) |
| Returns TRUE if a beachhead as been found to reach 'dest_tile'. More... | |
| int | find_something_to_kill (struct ai_type *ait, struct player *pplayer, struct unit *punit, struct tile **pdest_tile, PFPath *ppath, struct pf_map **pferrymap, struct unit **pferryboat, const struct unit_type **pboattype, int *pmove_time) |
| Find something to kill! This function is called for units to find targets to destroy and for cities that want to know if they should build offensive units. More... | |
| struct city * | find_nearest_safe_city (struct unit *punit) |
| Find safe city to recover in. More... | |
| static void | dai_military_attack_barbarian (struct ai_type *ait, struct player *pplayer, struct unit *punit) |
| Go berserk, assuming there are no targets nearby. More... | |
| static void | dai_caravan_goto (struct ai_type *ait, struct player *pplayer, struct unit *punit, const struct city *dest_city, bool help_wonder, bool required_boat, bool request_boat) |
| Send the caravan to the specified city, or make it help the wonder / trade, if it's already there. More... | |
| static void | caravan_optimize_callback (const struct caravan_result *result, void *data) |
| For debugging, print out information about every city we come to when optimizing the caravan. More... | |
| static bool | dai_is_unit_tired_waiting_boat (struct ai_type *ait, struct unit *punit) |
| Evaluate if a unit is tired of waiting for a boat at home continent. More... | |
| static bool | search_homecity_for_caravan (struct ai_type *ait, struct unit *punit) |
| Try to move caravan to suitable city and to make it caravan's homecity. More... | |
| static void | dai_manage_hitpoint_recovery (struct ai_type *ait, struct unit *punit) |
| This function goes wait a unit in a city for the hitpoints to recover. More... | |
| void | dai_manage_military (struct ai_type *ait, struct player *pplayer, struct unit *punit) |
| Decide what to do with a military unit. More... | |
| static void | dai_manage_settler (struct ai_type *ait, struct player *pplayer, struct unit *punit) |
| Manages settlers. More... | |
| void | dai_manage_unit (struct ai_type *ait, struct player *pplayer, struct unit *punit) |
| manage one unit Careful: punit may have been destroyed upon return from this routine! More... | |
| static void | dai_set_defenders (struct ai_type *ait, struct player *pplayer) |
| Master city defense function. More... | |
| void | dai_manage_units (struct ai_type *ait, struct player *pplayer) |
| Master manage unit function. More... | |
| const struct impr_type * | utype_needs_improvement (const struct unit_type *putype, const struct city *pcity) |
| Returns an improvement that will make it possible to build units of the specified type the specified city. More... | |
| void | dai_consider_tile_dangerous (struct ai_type *ait, struct tile *ptile, struct unit *punit, enum override_bool *result) |
| Are there dangerous enemies at or adjacent to the tile 'ptile'? More... | |
| static void | update_simple_ai_types () |
| Updates the global array simple_ai_types. More... | |
| void | dai_units_ruleset_init (struct ai_type *ait) |
| Initialise the unit data from the ruleset for the AI. More... | |
| void | dai_units_ruleset_close (struct ai_type *ait) |
| Close AI unit type data. More... | |
| void | dai_unit_init (struct ai_type *ait, struct unit *punit) |
| Initialize unit for use with default AI. More... | |
| void | dai_unit_turn_end (struct ai_type *ait, struct unit *punit) |
| Free unit from use with default AI. More... | |
| void | dai_unit_close (struct ai_type *ait, struct unit *punit) |
| Free unit from use with default AI. More... | |
| void | dai_unit_save (struct ai_type *ait, const char *aitstr, struct section_file *file, const struct unit *punit, const char *unitstr) |
| Save AI data of a unit. More... | |
| void | dai_unit_load (struct ai_type *ait, const char *aitstr, const struct section_file *file, struct unit *punit, const char *unitstr) |
| Load AI data of a unit. More... | |
| static bool | role_unit_cb (struct unit_type *ptype, void *data) |
| Filter callback for role unit iteration. More... | |
| struct unit_type * | dai_role_utype_for_terrain_class (struct city *pcity, int role, enum terrain_class tc) |
| Get unit type player can build, suitable to role, with given move type. More... | |
| bool | dai_unit_can_strike_my_unit (const struct unit *attacker, const struct unit *defender) |
| Returns whether 'attacker' can attack 'defender' immediately. More... | |
| void | dai_switch_to_explore (struct ai_type *ait, struct unit *punit, struct tile *target, enum override_bool *allow) |
| Switch to autoexploring. More... | |
Variables | |
| struct unit_type * | simple_ai_types [U_LAST] |
| #define LOG_CARAVAN LOG_DEBUG |
Definition at line 72 of file aiunit.cpp.
| #define LOG_CARAVAN2 LOG_DEBUG |
Definition at line 73 of file aiunit.cpp.
| #define LOG_CARAVAN3 LOG_DEBUG |
Definition at line 74 of file aiunit.cpp.
| #define LOGLEVEL_RECOVERY LOG_DEBUG |
Definition at line 71 of file aiunit.cpp.
|
static |
Compute how much we want to kill certain victim we've chosen, counted in SHIELDs.
See comment to kill_desire.
chance – the probability the action will succeed, benefit – the benefit (in shields) that we are getting in the case of success loss – the loss (in shields) that we suffer in the case of failure
Essentially returns the probabilistic average win amount: benefit * chance - loss * (1 - chance)
Definition at line 358 of file aiunit.cpp.
Referenced by dai_rampage_want().
| int build_cost_balanced | ( | const struct unit_type * | punittype | ) |
In the words of Syela: "Using funky fprime variable instead of f in the denom, so that def=1 units are penalized correctly.
"
Translation (GB): build_cost_balanced is used in the denominator of the want equation (see, e.g. find_something_to_kill) instead of just build_cost to make AI build more balanced units (with def > 1).
Definition at line 240 of file aiunit.cpp.
Referenced by dai_evaluate_tile_for_air_attack(), find_something_to_kill(), and process_attacker_want().
|
static |
For debugging, print out information about every city we come to when optimizing the caravan.
Definition at line 2023 of file aiunit.cpp.
Referenced by dai_manage_caravan().
Move defenders around with airports.
Since this expends all our movement, a valid question is - why don't we do this on turn end? That's because we want to avoid emergency actions to protect the city during the turn if that isn't necessary.
Definition at line 157 of file aiunit.cpp.
Referenced by dai_manage_units().
| bool dai_can_unit_type_follow_unit_type | ( | const struct unit_type * | follower, |
| const struct unit_type * | followee, | ||
| struct ai_type * | ait | ||
| ) |
See if the follower can follow the followee.
Definition at line 834 of file aiunit.cpp.
Referenced by look_for_charge(), and process_attacker_want().
|
static |
Check if a caravan can make a trade route to a city on a different continent.
Definition at line 2091 of file aiunit.cpp.
Referenced by dai_manage_caravan().
|
static |
Send the caravan to the specified city, or make it help the wonder / trade, if it's already there.
After this call, the unit may no longer exist (it might have been used up, or may have died travelling). It uses the ferry system to trade among continents.
Definition at line 1923 of file aiunit.cpp.
Referenced by dai_manage_caravan().
| void dai_consider_tile_dangerous | ( | struct ai_type * | ait, |
| struct tile * | ptile, | ||
| struct unit * | punit, | ||
| enum override_bool * | result | ||
| ) |
Are there dangerous enemies at or adjacent to the tile 'ptile'?
Always override advisor danger detection since we are omniscient and advisor is not.
Definition at line 3017 of file aiunit.cpp.
Referenced by cai_consider_tile_dangerous(), texwai_consider_tile_dangerous(), and twai_consider_tile_dangerous().
Request a boat for a unit to transport it to another continent.
Return whether is alive or not
Definition at line 1884 of file aiunit.cpp.
Referenced by dai_caravan_goto().
Evaluate if a unit is tired of waiting for a boat at home continent.
Definition at line 2039 of file aiunit.cpp.
Referenced by dai_manage_caravan().
|
static |
Barbarian leader tries to stack with other barbarian units, and if it's not possible it runs away.
When on coast, it may disappear with 33% chance.
Definition at line 2835 of file aiunit.cpp.
Referenced by dai_manage_unit().
|
static |
Use caravans for building wonders, or send caravans to establish trade with a city, owned by yourself or an ally.
We use ferries for trade across the sea.
Definition at line 2178 of file aiunit.cpp.
Referenced by dai_manage_unit().
This function goes wait a unit in a city for the hitpoints to recover.
If something is attacking our city, kill it yeahhh!!!.
Definition at line 2338 of file aiunit.cpp.
Referenced by dai_manage_military().
Decide what to do with a military unit.
It will be managed once only. It is up to the caller to try again if it has moves left.
Definition at line 2399 of file aiunit.cpp.
Referenced by dai_manage_paratrooper(), and dai_manage_unit().
manage one unit Careful: punit may have been destroyed upon return from this routine!
Gregor: This function is a very limited approach because if a unit has several flags the first one in order of appearance in this function will be used.
Definition at line 2551 of file aiunit.cpp.
Referenced by dai_manage_barbarian_leader(), and dai_manage_units().
Master manage unit function.
A manage function should set the unit to 'done' when it should no longer be touched by this code, and its role should be reset to IDLE when its role has accomplished its mission or the manage function fails to have or no longer has any use for the unit.
Definition at line 2761 of file aiunit.cpp.
Referenced by dai_do_first_activities().
|
static |
This does the attack until we have used up all our movement, unless we should safeguard a city.
First we rampage nearby, then we go looking for trouble elsewhere. If there is nothing to kill, sailing units go home, others explore while barbs go berserk.
Definition at line 1738 of file aiunit.cpp.
Referenced by dai_manage_hitpoint_recovery(), and dai_manage_military().
|
static |
Go berserk, assuming there are no targets nearby.
TODO: Is it not possible to remove this special casing for barbarians? FIXME: enum unit_move_result
Definition at line 1672 of file aiunit.cpp.
Referenced by dai_military_attack().
|
static |
If we are not covering our charge's ass, go do it now.
Also check if we can kick some ass, which is always nice.
Definition at line 622 of file aiunit.cpp.
Referenced by dai_manage_military().
|
static |
Send a unit to the city it should defend.
If we already have a city it should defend, use the punit->server.ai->charge field to denote this. Otherwise, it will stay put in the city it is in, or find a city to reside in, or travel all the way home.
TODO: Add make homecity. TODO: Add better selection of city to defend.
Definition at line 944 of file aiunit.cpp.
Referenced by dai_manage_military(), dai_manage_unit(), and dai_military_attack().
|
static |
See if we have a specific job for the unit.
Definition at line 855 of file aiunit.cpp.
Referenced by dai_manage_military().
| bool dai_military_rampage | ( | struct unit * | punit, |
| int | thresh_adj, | ||
| int | thresh_move | ||
| ) |
Find and kill anything reachable within this turn and worth more than the relevant of the given thresholds until we have run out of juicy targets or movement.
The first threshold is for attacking which will leave us where we stand (attacking adjacent units), the second is for attacking distant (but within reach) targets.
For example, if unit is a bodyguard on duty, it should call dai_military_rampage(punit, 100, RAMPAGE_FREE_CITY_OR_BETTER) meaning "we will move _only_ to pick up a free city but we are happy to attack adjacent squares as long as they are worthy of it".
Returns TRUE if survived the rampage session.
Definition at line 592 of file aiunit.cpp.
Referenced by dai_manage_hitpoint_recovery(), dai_manage_paratrooper(), dai_military_attack(), dai_military_bodyguard(), and dai_military_defend().
This function appraises the location (x, y) for a quick hit-n-run operation.
We do not take into account reinforcements: rampage is for loners.
Returns value as follows: -RAMPAGE_FREE_CITY_OR_BETTER means undefended enemy city -RAMPAGE_HUT_OR_BETTER means hut RAMPAGE_ANYTHING ... RAMPAGE_HUT_OR_BETTER - 1 is value of enemy unit weaker than our unit 0 means nothing found or error Here the minus indicates that you need to enter the target tile (as opposed to attacking it, which leaves you where you are).
Definition at line 452 of file aiunit.cpp.
Referenced by find_rampage_target().
| struct unit_type* dai_role_utype_for_terrain_class | ( | struct city * | pcity, |
| int | role, | ||
| enum terrain_class | tc | ||
| ) |
Get unit type player can build, suitable to role, with given move type.
Definition at line 3344 of file aiunit.cpp.
Referenced by contemplate_terrain_improvements(), and dai_city_choose_build().
Master city defense function.
We try to pick up the best available defenders, and not disrupt existing roles.
TODO: Make homecity, respect homecity.
Definition at line 2660 of file aiunit.cpp.
Referenced by dai_manage_units().
| void dai_switch_to_explore | ( | struct ai_type * | ait, |
| struct unit * | punit, | ||
| struct tile * | target, | ||
| enum override_bool * | allow | ||
| ) |
Switch to autoexploring.
Definition at line 3390 of file aiunit.cpp.
Referenced by cai_switch_to_explore(), texwai_switch_to_explore(), and twai_switch_to_explore().
Returns whether 'attacker' can attack 'defender' immediately.
Definition at line 3356 of file aiunit.cpp.
Referenced by dai_hunter_try_launch().
Free unit from use with default AI.
Definition at line 3264 of file aiunit.cpp.
Referenced by cai_unit_close(), texwai_unit_free(), and twai_unit_free().
Initialize unit for use with default AI.
Definition at line 3229 of file aiunit.cpp.
Referenced by cai_unit_init(), texwai_unit_alloc(), and twai_unit_alloc().
| void dai_unit_load | ( | struct ai_type * | ait, |
| const char * | aitstr, | ||
| const struct section_file * | file, | ||
| struct unit * | punit, | ||
| const char * | unitstr | ||
| ) |
Load AI data of a unit.
Definition at line 3302 of file aiunit.cpp.
Referenced by cai_unit_load(), texwai_unit_load(), and twai_unit_load().
| void dai_unit_save | ( | struct ai_type * | ait, |
| const char * | aitstr, | ||
| struct section_file * | file, | ||
| const struct unit * | punit, | ||
| const char * | unitstr | ||
| ) |
Save AI data of a unit.
Definition at line 3283 of file aiunit.cpp.
Referenced by cai_unit_save(), texwai_unit_save(), and twai_unit_save().
Free unit from use with default AI.
Definition at line 3252 of file aiunit.cpp.
Referenced by cai_unit_turn_end(), texwai_unit_turn_end(), and twai_unit_turn_end().
| void dai_units_ruleset_close | ( | struct ai_type * | ait | ) |
Close AI unit type data.
Definition at line 3208 of file aiunit.cpp.
Referenced by cai_units_ruleset_close(), texwai_units_ruleset_close(), and twai_units_ruleset_close().
| void dai_units_ruleset_init | ( | struct ai_type * | ait | ) |
Initialise the unit data from the ruleset for the AI.
Definition at line 3101 of file aiunit.cpp.
Referenced by cai_units_ruleset_init(), texwai_units_ruleset_init(), and twai_units_ruleset_init().
| bool find_beachhead | ( | const struct player * | pplayer, |
| struct pf_map * | ferry_map, | ||
| struct tile * | dest_tile, | ||
| const struct unit_type * | cargo_type, | ||
| struct tile ** | ferry_dest, | ||
| struct tile ** | beachhead_tile | ||
| ) |
Returns TRUE if a beachhead as been found to reach 'dest_tile'.
Definition at line 1037 of file aiunit.cpp.
Referenced by find_something_to_kill(), and process_attacker_want().
Find safe city to recover in.
An allied player's city is just as good as one of our own, since both replenish our hitpoints and reduce unhappiness.
TODO: Actually check how safe the city is. This is a difficult decision not easily taken, since we also want to protect unsafe cities, at least most of the time.
Definition at line 1620 of file aiunit.cpp.
Referenced by dai_find_boat_for_unit(), dai_manage_hitpoint_recovery(), dai_manage_paratrooper(), and dai_military_attack().
|
static |
Returns the city with the most need of an airlift.
To be considerd, a city must have an air field. All cities with an urgent need for units are serviced before cities in danger.
Return value may be nullptr, this means no servicable city found.
parameter pplayer may not be nullptr.
Definition at line 124 of file aiunit.cpp.
Referenced by dai_airlift().
Look for worthy targets within a one-turn horizon.
Definition at line 512 of file aiunit.cpp.
Referenced by dai_military_rampage().
| int find_something_to_kill | ( | struct ai_type * | ait, |
| struct player * | pplayer, | ||
| struct unit * | punit, | ||
| struct tile ** | pdest_tile, | ||
| PFPath * | ppath, | ||
| struct pf_map ** | pferrymap, | ||
| struct unit ** | pferryboat, | ||
| const struct unit_type ** | pboattype, | ||
| int * | pmove_time | ||
| ) |
Find something to kill! This function is called for units to find targets to destroy and for cities that want to know if they should build offensive units.
Target location returned in 'dest_tile', want as function return value.
punit->id == 0 means that the unit is virtual (considered to be built).
Definition at line 1118 of file aiunit.cpp.
Referenced by dai_military_attack(), and kill_something_with().
|
static |
This is a much simplified form of assess_defense (see daimilitary.c), but which doesn't use pcity->server.ai.wallvalue and just returns a boolean value.
This is for use with "foreign" cities, especially non-ai cities, where ai.wallvalue may be out of date or uninitialized –dwp
Definition at line 211 of file aiunit.cpp.
Referenced by invasion_funct().
|
static |
Mark invasion possibilities of punit in the surrounding cities.
The given radius limites the area which is searched for cities. The center of the area is either the unit itself (dest == FALSE) or the destination of the current goto (dest == TRUE). The invasion threat is marked in pcity->server.ai.invasion by setting the "which" bit (to tell attack which can only kill units from occupy possibility).
If dest == TRUE then a valid goto is presumed.
Definition at line 997 of file aiunit.cpp.
Referenced by find_something_to_kill().
Is there another unit which really should be doing this attack? Checks all adjacent tiles and the tile we stand on for such units.
Definition at line 397 of file aiunit.cpp.
Referenced by dai_rampage_want().
| int kill_desire | ( | int | benefit, |
| int | attack, | ||
| int | loss, | ||
| int | vuln, | ||
| int | victim_count | ||
| ) |
Compute how much we want to kill certain victim we've chosen, counted in SHIELDs.
FIXME?: The equation is not accurate as the other values can vary for other victims on same tile (we take values from best defender) - however I believe it's accurate just enough now and lost speed isn't worth that. –pasky
Benefit is something like 'attractiveness' of the victim, how nice it would be to destroy it. Larger value, worse loss for enemy.
Attack is the total possible attack power we can throw on the victim. Note that it usually comes squared.
Loss is the possible loss when we would lose the unit we are attacking with (in SHIELDs).
Vuln is vulnerability of our unit when attacking the enemy. Note that it usually comes squared as well.
Victim count is number of victims stacked in the target tile. Note that we shouldn't treat cities as a stack (despite the code using this function) - the scaling is probably different. (extremely dodgy usage of it – GB)
Definition at line 334 of file aiunit.cpp.
Referenced by dai_evaluate_tile_for_air_attack(), find_something_to_kill(), and process_attacker_want().
| int look_for_charge | ( | struct ai_type * | ait, |
| struct player * | pplayer, | ||
| struct unit * | punit, | ||
| struct unit ** | aunit, | ||
| struct city ** | acity | ||
| ) |
See if we can find something to defend.
Called both by wannabe bodyguards and building want estimation code. Returns desirability for using this unit as a bodyguard or for defending a city.
We do not consider units with higher movement than us, or units that are native to terrains or extras not native to us, as potential charges. Nor do we attempt to bodyguard units with higher defence than us, or military units with lower attack than us that are not transports.
Definition at line 707 of file aiunit.cpp.
Referenced by dai_military_findjob(), and dai_unit_consider_bodyguard().
|
static |
Calculates the value and cost of nearby allied units to see if we can expect any help in our attack.
Base function.
Definition at line 368 of file aiunit.cpp.
Referenced by find_something_to_kill().
|
static |
Filter callback for role unit iteration.
Definition at line 3326 of file aiunit.cpp.
Referenced by dai_role_utype_for_terrain_class().
Try to move caravan to suitable city and to make it caravan's homecity.
Returns FALSE iff caravan dies.
Definition at line 2138 of file aiunit.cpp.
Referenced by dai_manage_caravan().
|
static |
Attack rating of this particular unit right now.
Definition at line 250 of file aiunit.cpp.
Referenced by dai_rampage_want(), and is_my_turn().
|
static |
Square of the adv_unit_att_rating() function - used in actual computations.
Definition at line 260 of file aiunit.cpp.
Referenced by find_something_to_kill().
Defence rating of this particular unit against this attacker.
Definition at line 270 of file aiunit.cpp.
Referenced by unit_def_rating_squared().
Square of the previous function - used in actual computations.
Definition at line 283 of file aiunit.cpp.
Referenced by find_something_to_kill().
|
static |
Does the unit with the id given have the flag L_DEFEND_GOOD?
Definition at line 692 of file aiunit.cpp.
Referenced by dai_military_findjob().
| int unittype_def_rating_squared | ( | const struct unit_type * | att_type, |
| const struct unit_type * | def_type, | ||
| struct player * | def_player, | ||
| struct tile * | ptile, | ||
| bool | fortified, | ||
| int | veteran | ||
| ) |
Defence rating of def_type unit against att_type unit, squared.
See get_virtual_defense_power for the arguments att_type, def_type, x, y, fortified and veteran.
Definition at line 296 of file aiunit.cpp.
Referenced by find_something_to_kill(), kill_something_with(), and process_attacker_want().
|
static |
Updates the global array simple_ai_types.
Definition at line 3075 of file aiunit.cpp.
Referenced by dai_units_ruleset_init().
| const struct impr_type* utype_needs_improvement | ( | const struct unit_type * | putype, |
| const struct city * | pcity | ||
| ) |
Returns an improvement that will make it possible to build units of the specified type the specified city.
Returns FALSE if no new improvement will make it possible or if no improvement is needed.
Definition at line 2802 of file aiunit.cpp.
Referenced by dai_wants_defender_against(), dai_wants_role_unit(), and process_attacker_want().
Definition at line 112 of file aiunit.cpp.
Referenced by update_simple_ai_types().