Freeciv21
Develop your civilization from humble roots to a global empire
combat.h
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 1996-2020 Freeciv21 and Freeciv
3 \_ \ / __/ contributors. This file is part of Freeciv21.
4  _\ \ / /__ Freeciv21 is free software: you can redistribute it
5  \___ \____/ __/ and/or modify it under the terms of the GNU General
6  \_ _/ Public License as published by the Free Software
7  | @ @ \_ Foundation, either version 3 of the License,
8  | or (at your option) any later version.
9  _/ /\ You should have received a copy of the GNU
10  /o) (o/\ \_ General Public License along with Freeciv21.
11  \_____/ / If not, see https://www.gnu.org/licenses/.
12  \____/ ********************************************************/
13 #pragma once
14 
15 #include "unittype.h"
16 
17 /*
18  * attack_strength and defense_strength are multiplied by POWER_FACTOR
19  * to yield the base of attack_power and defense_power.
20  *
21  * The constant may be changed since it isn't externally visible used.
22  */
23 #define POWER_FACTOR 10
24 
31 };
32 
33 bool is_unit_reachable_at(const struct unit *defender,
34  const struct unit *attacker,
35  const struct tile *location);
37 unit_attack_unit_at_tile_result(const struct unit *punit,
38  const struct unit *pdefender,
39  const struct tile *dest_tile);
41 unit_attack_units_at_tile_result(const struct unit *punit,
42  const struct tile *ptile);
43 bool can_unit_attack_tile(const struct unit *punit,
44  const struct tile *ptile);
45 
46 double win_chance(int as, int ahp, int afp, int ds, int dhp, int dfp);
47 
48 void get_modified_firepower(const struct unit *attacker,
49  const struct unit *defender, int *att_fp,
50  int *def_fp);
51 double unit_win_chance(const struct unit *attacker,
52  const struct unit *defender);
53 
54 struct city *sdi_try_defend(const struct player *owner,
55  const struct tile *ptile);
56 bool is_tired_attack(int moves_left);
57 
58 int get_attack_power(const struct unit *punit);
59 int base_get_attack_power(const struct unit_type *punittype, int veteran,
60  int moves_left);
61 int base_get_defense_power(const struct unit *punit);
62 int get_total_defense_power(const struct unit *attacker,
63  const struct unit *defender);
64 int get_fortified_defense_power(const struct unit *attacker,
65  struct unit *defender);
66 int get_virtual_defense_power(const struct unit_type *attacker,
67  const struct unit_type *defender,
68  struct player *defending_player,
69  struct tile *ptile, bool fortified,
70  int veteran);
71 int get_total_attack_power(const struct unit *attacker,
72  const struct unit *defender);
73 
74 struct unit *get_defender(const struct unit *attacker,
75  const struct tile *ptile);
76 
77 struct unit *get_diplomatic_defender(const struct unit *act_unit,
78  const struct unit *pvictim,
79  const struct tile *tgt_tile);
80 
81 bool is_stack_vulnerable(const struct tile *ptile);
82 
83 int combat_bonus_against(const struct combat_bonus_list *list,
84  const struct unit_type *enemy,
85  enum combat_bonus_type type);
struct unit * get_defender(const struct unit *attacker, const struct tile *ptile)
Finds the best defender on the tile, given an attacker.
Definition: combat.cpp:721
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: combat.cpp:83
enum unit_attack_result unit_attack_unit_at_tile_result(const struct unit *punit, 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).
Definition: combat.cpp:121
enum unit_attack_result unit_attack_units_at_tile_result(const struct unit *punit, const struct tile *ptile)
Check if unit can attack unit stack at tile.
Definition: combat.cpp:237
bool is_stack_vulnerable(const struct tile *ptile)
Is it a city/fortress/air base or will the whole stack die in an attack.
Definition: combat.cpp:839
int get_attack_power(const struct unit *punit)
Convenience wrapper for base_get_attack_power.
Definition: combat.cpp:453
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.
Definition: combat.cpp:852
int get_fortified_defense_power(const struct unit *attacker, struct unit *defender)
Return total defense power of the unit if it fortifies, if possible, where it is.
Definition: combat.cpp:667
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: combat.cpp:463
int get_total_defense_power(const struct unit *attacker, const struct unit *defender)
return the modified defense power of a unit.
Definition: combat.cpp:654
struct city * sdi_try_defend(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...
Definition: combat.cpp:430
bool can_unit_attack_tile(const struct unit *punit, const struct tile *ptile)
Is unit (1) diplomatically allowed to attack and (2) physically able to do so?
Definition: combat.cpp:251
bool is_tired_attack(int moves_left)
Returns if the attack is going to be a tired attack.
Definition: combat.cpp:872
unit_attack_result
Definition: combat.h:25
@ ATT_NONNATIVE_DST
Definition: combat.h:30
@ ATT_OK
Definition: combat.h:26
@ ATT_NON_ATTACK
Definition: combat.h:27
@ ATT_UNREACHABLE
Definition: combat.h:28
@ ATT_NONNATIVE_SRC
Definition: combat.h:29
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 nullptr if no diplomatic defender could be...
Definition: combat.cpp:792
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.
Definition: combat.cpp:270
int get_total_attack_power(const struct unit *attacker, const struct unit *defender)
Return the modified attack power of a unit.
Definition: combat.cpp:526
int get_virtual_defense_power(const struct unit_type *attacker, const struct unit_type *defender, struct player *defending_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: combat.cpp:601
int base_get_defense_power(const struct unit *punit)
Returns the defense power, modified by veteran status.
Definition: combat.cpp:487
double unit_win_chance(const struct unit *attacker, const struct unit *defender)
Returns a double in the range [0;1] indicating the attackers chance of winning.
Definition: combat.cpp:408
void get_modified_firepower(const struct unit *attacker, const struct unit *defender, int *att_fp, int *def_fp)
A unit's effective firepower depend on the situation.
Definition: combat.cpp:352
Definition: city.h:291
struct player * owner
Definition: city.h:294
Definition: player.h:231
Definition: tile.h:42
Definition: unit.h:134
struct unit_order * list
Definition: unit.h:195