Freeciv-3.1
|
Go to the source code of this file.
Macros | |
#define | POWER_FACTOR 10 |
Enumerations | |
enum | unit_attack_result { ATT_OK , ATT_NON_ATTACK , ATT_UNREACHABLE , ATT_NONNATIVE_SRC , ATT_NONNATIVE_DST } |
Functions | |
bool | is_unit_reachable_at (const struct unit *defender, const struct unit *attacker, const struct tile *location) |
enum unit_attack_result | unit_attack_unit_at_tile_result (const struct unit *punit, const struct action *paction, const struct unit *pdefender, const struct tile *dest_tile) |
enum unit_attack_result | unit_attack_units_at_tile_result (const struct unit *punit, const struct action *paction, const struct tile *ptile) |
bool | can_unit_attack_tile (const struct unit *punit, const struct action *paction, const struct tile *ptile) |
double | win_chance (int as, int ahp, int afp, int ds, int dhp, int dfp) |
void | get_modified_firepower (const struct civ_map *nmap, const struct unit *attacker, const struct unit *defender, int *att_fp, int *def_fp) |
double | unit_win_chance (const struct civ_map *nmap, const struct unit *attacker, const struct unit *defender) |
bool | unit_really_ignores_citywalls (const struct unit *punit) |
struct city * | sdi_try_defend (const struct civ_map *nmap, const struct player *owner, const struct tile *ptile) |
bool | is_tired_attack (int moves_left) |
int | get_attack_power (const struct unit *punit) |
int | base_get_attack_power (const struct unit_type *punittype, int veteran, int moves_left) |
int | base_get_defense_power (const struct unit *punit) |
int | get_total_defense_power (const struct unit *attacker, const struct unit *defender) |
int | get_fortified_defense_power (const struct unit *attacker, struct unit *defender) |
int | get_virtual_defense_power (const struct civ_map *nmap, const struct unit_type *attacker, const struct unit_type *defender, struct player *defending_player, struct tile *ptile, bool fortified, int veteran) |
int | get_total_attack_power (const struct unit *attacker, const struct unit *defender) |
struct unit * | get_defender (const struct civ_map *nmap, const struct unit *attacker, const struct tile *ptile) |
struct unit * | get_attacker (const struct civ_map *nmap, const struct unit *defender, const struct tile *ptile) |
struct unit * | get_diplomatic_defender (const struct unit *act_unit, const struct unit *pvictim, const struct tile *tgt_tile) |
bool | is_stack_vulnerable (const struct tile *ptile) |
int | combat_bonus_against (const struct combat_bonus_list *list, const struct unit_type *enemy, enum combat_bonus_type type) |
int | unit_bombard_rate (struct unit *punit) |
enum unit_attack_result |
int base_get_attack_power | ( | const struct unit_type * | punittype, |
int | veteran, | ||
int | moves_left | ||
) |
Returns the attack power, modified by moves left, and veteran status.
Definition at line 504 of file combat.c.
Referenced by adv_unittype_att_rating(), and get_attack_power().
int base_get_defense_power | ( | const struct unit * | punit | ) |
Returns the defense power, modified by veteran status.
Definition at line 528 of file combat.c.
Referenced by adv_unit_def_rating_basic(), get_defense_power(), and has_defense().
bool can_unit_attack_tile | ( | const struct unit * | punit, |
const struct action * | paction, | ||
const struct tile * | dest_tile | ||
) |
Is unit (1) diplomatically allowed to attack and (2) physically able to do so?
Definition at line 271 of file combat.c.
Referenced by can_units_attack_at(), dai_evaluate_tile_for_air_attack(), dai_hunter_manage(), dai_hunter_try_launch(), dai_military_attack(), dai_rampage_want(), find_best_tile_to_paradrop_to(), find_something_to_bomb(), find_something_to_kill(), is_action_possible(), and kill_something_with().
int combat_bonus_against | ( | const struct combat_bonus_list * | list, |
const struct unit_type * | enemy, | ||
enum combat_bonus_type | type | ||
) |
Get bonus value against given unit type from bonus list.
Consider using cached values instead of calling this recalculation directly.
Definition at line 943 of file combat.c.
Referenced by dai_wants_defender_against(), defense_multiplication(), get_modified_firepower(), and set_unit_type_caches().
int get_attack_power | ( | const struct unit * | punit | ) |
Convenience wrapper for base_get_attack_power().
Definition at line 494 of file combat.c.
Referenced by get_total_attack_power().
struct unit * get_attacker | ( | const struct civ_map * | nmap, |
const struct unit * | defender, | ||
const struct tile * | ptile | ||
) |
Get unit at (x, y) that wants to kill defender.
Works like get_defender(); see comment there. This function is mostly used by the AI.
Definition at line 851 of file combat.c.
Referenced by popup_advanced_terrain_dialog().
struct unit * get_defender | ( | const struct civ_map * | nmap, |
const struct unit * | attacker, | ||
const struct tile * | ptile | ||
) |
Finds the best defender on the tile, given an attacker. The diplomatic relationship of attacker and defender is ignored; the caller should check this.
Definition at line 783 of file combat.c.
Referenced by action_prob(), dai_evaluate_tile_for_air_attack(), dai_hunter_manage(), dai_rampage_want(), do_attack(), find_best_tile_to_paradrop_to(), find_something_to_kill(), kill_something_with(), popup_advanced_terrain_dialog(), and unit_survive_autoattack().
struct unit * get_diplomatic_defender | ( | const struct unit * | act_unit, |
const struct unit * | pvictim, | ||
const struct tile * | tgt_tile | ||
) |
Returns the defender of the tile in a diplomatic battle or NULL if no diplomatic defender could be found.
act_unit | the diplomatic attacker, trying to perform an action. |
pvictim | unit that should be excluded as a defender. |
tgt_tile | the tile to defend. |
Definition at line 884 of file combat.c.
Referenced by ap_diplomat_battle(), and diplomat_infiltrate_tile().
Return total defense power of the unit if it fortifies, if possible, where it is. attacker might be NULL to skip calculating attacker specific bonuses.
Definition at line 728 of file combat.c.
Referenced by base_assess_defense_unit().
void get_modified_firepower | ( | const struct civ_map * | nmap, |
const struct unit * | attacker, | ||
const struct unit * | defender, | ||
int * | att_fp, | ||
int * | def_fp | ||
) |
A unit's effective firepower depend on the situation.
Definition at line 369 of file combat.c.
Referenced by dai_choose_defender_versus(), do_attack(), get_defense_rating(), unit_bombs_unit(), unit_versus_unit(), and unit_win_chance().
Return the modified attack power of a unit.
Definition at line 569 of file combat.c.
Referenced by dai_choose_defender_versus(), do_attack(), unit_bombs_unit(), unit_versus_unit(), and unit_win_chance().
return the modified defense power of a unit. An veteran aegis cruiser in a mountain city with SAM and SDI defense being attacked by a missile gets defense 288.
Definition at line 714 of file combat.c.
Referenced by dai_choose_defender_versus(), do_attack(), get_defense_rating(), unit_bombs_unit(), unit_def_rating(), unit_versus_unit(), and unit_win_chance().
int get_virtual_defense_power | ( | const struct civ_map * | nmap, |
const struct unit_type * | att_type, | ||
const struct unit_type * | def_type, | ||
struct player * | def_player, | ||
struct tile * | ptile, | ||
bool | fortified, | ||
int | veteran | ||
) |
May be called with a non-existing att_type to avoid any effects which depend on the attacker.
Definition at line 659 of file combat.c.
Referenced by find_a_good_partisan_spot(), is_my_turn(), and unittype_def_rating_squared().
Is it a city/fortress/air base or will the whole stack die in an attack
Definition at line 930 of file combat.c.
Referenced by dai_rampage_want(), find_best_tile_to_paradrop_to(), get_defender(), kill_unit(), process_attacker_want(), stack_cost(), and stack_value().
bool is_tired_attack | ( | int | moves_left | ) |
Returns if the attack is going to be a tired attack
Definition at line 486 of file combat.c.
Referenced by base_get_attack_power(), and unit_tired_attack_string().
bool is_unit_reachable_at | ( | const struct unit * | defender, |
const struct unit * | attacker, | ||
const struct tile * | location | ||
) |
Can unit attack other at given location
Definition at line 85 of file combat.c.
Referenced by is_action_possible(), kill_unit(), unit_attack_unit_at_tile_result(), and unit_bombard().
struct city * sdi_try_defend | ( | const struct civ_map * | nmap, |
const struct player * | owner, | ||
const struct tile * | ptile | ||
) |
Try defending against nuclear attack; if successful, return a city which had enough luck and EFT_NUKE_PROOF. If the attack was successful return NULL.
Definition at line 460 of file combat.c.
Referenced by unit_nuke().
enum unit_attack_result unit_attack_unit_at_tile_result | ( | const struct unit * | punit, |
const struct action * | paction, | ||
const struct unit * | pdefender, | ||
const struct tile * | dest_tile | ||
) |
Checks if a unit can physically attack pdefender at the tile (assuming it is adjacent and at war).
Unit can NOT attack if: 1) its unit type is unable to perform any attack action. 2) it is a ground unit without marine ability and it attacks from ocean. 3) it is a ground unit and it attacks a target on an ocean square or it is a sailing unit without shore bombardment capability and it attempts to attack land. 4) it is not a fighter and defender is a flying unit (except city/airbase).
Does NOT check: 1) Moves left 2) Adjacency 3) Diplomatic status
Definition at line 122 of file combat.c.
Referenced by adv_danger_at(), dai_consider_tile_dangerous(), dai_hunter_manage(), find_best_tile_to_paradrop_to(), get_defender(), is_my_turn(), stack_cost(), unit_attack_all_at_tile_result(), and unit_attack_any_at_tile_result().
enum unit_attack_result unit_attack_units_at_tile_result | ( | const struct unit * | punit, |
const struct action * | paction, | ||
const struct tile * | ptile | ||
) |
Check if unit can attack unit stack at tile.
Definition at line 256 of file combat.c.
Referenced by adv_danger_at(), can_unit_attack_tile(), dai_consider_tile_dangerous(), expl_act_not_enabl(), is_action_possible(), and is_my_turn().
int unit_bombard_rate | ( | struct unit * | punit | ) |
Get unit's current bombard rate.
Definition at line 961 of file combat.c.
Referenced by unit_bombs_unit().
double unit_win_chance | ( | const struct civ_map * | nmap, |
const struct unit * | attacker, | ||
const struct unit * | defender | ||
) |
Returns a double in the range [0;1] indicating the attackers chance of winning. The calculation takes all factors into account.
Definition at line 438 of file combat.c.
Referenced by action_prob(), dai_evaluate_tile_for_air_attack(), dai_hunter_manage(), dai_rampage_want(), find_best_tile_to_paradrop_to(), get_attacker(), get_defender(), popup_info_text(), sdl_get_chance_to_win(), and unit_survive_autoattack().
double win_chance | ( | int | as, |
int | ahp, | ||
int | afp, | ||
int | ds, | ||
int | dhp, | ||
int | dfp | ||
) |
Returns the chance of the attacker winning, a number between 0 and 1. If you want the chance that the defender wins just use 1-chance(...)
NOTE: this number can be very small, fx in a battle between an ironclad and a battleship the ironclad has less than 1/100000 chance of winning.
The algoritm calculates the probability of each possible number of HP's the attacker has left. Maybe that info should be preserved for use in the AI.
Definition at line 292 of file combat.c.
Referenced by unit_win_chance().