45 const struct tile *ptile)
50 if (!pcity && unit_list_size((ptile->
units)) == 0) {
74 const struct unit *attacker)
86 const struct unit *attacker,
87 const struct tile *location)
123 const struct action *paction,
124 const struct unit *pdefender,
125 const struct tile *dest_tile)
128 if (paction == NULL) {
131 ACTION_SUICIDE_ATTACK)
135 ACTION_NUKE_UNITS))) {
145 if (paction == NULL) {
149 USP_NATIVE_TILE,
FALSE)
151 ACTION_SUICIDE_ATTACK,
152 USP_NATIVE_TILE,
FALSE)) {
159 USP_NATIVE_TILE,
FALSE)) {
189 const struct action *paction,
190 const struct tile *ptile)
192 bool any_reachable_unit =
FALSE;
193 bool any_neverprotect_unit =
FALSE;
209 any_neverprotect_unit =
TRUE;
211 }
else if (result !=
ATT_OK) {
214 any_reachable_unit =
TRUE;
230 const struct action *paction,
231 const struct tile *ptile)
257 const struct action *paction,
258 const struct tile *ptile)
272 const struct action *paction,
273 const struct tile *dest_tile)
292double win_chance(
int as,
int ahp,
int afp,
int ds,
int dhp,
int dfp)
295 int att_N_lose = (ahp + dfp - 1) / dfp;
296 int def_N_lose = (dhp + afp - 1) / afp;
298 double att_P_lose1 = (as + ds == 0) ? 0.5 : (double) ds / (as + ds);
299 double def_P_lose1 = 1 - att_P_lose1;
347 double binom_save = pow(def_P_lose1, (
double)(def_N_lose - 1));
348 double accum_prob = binom_save;
351 for (lr = 1; lr < att_N_lose; lr++) {
353 int n = lr + def_N_lose - 1;
356 binom_save *= att_P_lose1;
358 accum_prob += binom_save;
361 accum_prob *= def_P_lose1;
370 const struct unit *attacker,
371 const struct unit *defender,
372 int *att_fp,
int *def_fp)
377 struct tile *att_tile;
398 EFT_DEFEND_BONUS) > 0) {
415 CBONUS_LOW_FIREPOWER)) {
439 const struct unit *attacker,
440 const struct unit *defender)
450 def_power, defender->
hp, def_fp);
462 const struct tile *ptile)
475 owner, EFT_NUKE_PROOF)) {
505 int veteran,
int moves_left)
556 power = (power * db) / 100;
570 const struct unit *defender)
579 return attackpower * mod / 100;
593 const struct unit *def,
594 const struct player *def_player,
595 const struct tile *ptile,
603 if (NULL != att_type) {
604 int scramble_bonus = 0;
605 int defense_divider_pct;
611 if (scramble_bonus) {
614 defensepower = defensepower * scramble_bonus / 10000;
615 defensepower =
MAX(0, defensepower);
618 int defense_multiplier_pct = 100
621 att_type, NULL, EFT_DEFEND_BONUS);
624 defensepower = defensepower * defense_multiplier_pct / 100;
625 defensepower =
MAX(0, defensepower * mod / 100);
629 def_type, CBONUS_DEFENSE_DIVIDER_PCT)
631 CBONUS_DEFENSE_DIVIDER);
633 defensepower = defensepower * 100 / defense_divider_pct;
639 defensepower = defensepower
650 EFT_FORTIFY_DEFENSE_BONUS)) / 100;
662 struct player *def_player,
688 vdef->
activity = ACTIVITY_FORTIFIED;
702 ptile, defensepower);
715 const struct unit *defender)
729 struct unit *defender)
732 enum unit_activity real_act;
736 if (attacker != NULL) {
744 defender->
activity = ACTIVITY_FORTIFIED;
762 const struct unit *attacker,
763 const struct unit *defender)
771 rating *= (defender->
hp + afp-1)/afp;
784 const struct unit *attacker,
785 const struct tile *ptile)
787 struct unit *bestdef = NULL;
788 int bestvalue = -99, best_cost = 0, rating_of_best = 0;
821 if (unit_def > bestvalue) {
823 }
else if (unit_def == bestvalue) {
824 if (build_cost < best_cost) {
826 }
else if (build_cost == best_cost) {
827 if (rating_of_best < defense_rating) {
834 bestvalue = unit_def;
836 best_cost = build_cost;
837 rating_of_best = defense_rating;
852 const struct unit *defender,
853 const struct tile *ptile)
855 struct unit *bestatt = 0;
856 int bestvalue = -1, unit_a, best_cost = 0;
865 if (unit_a > bestvalue
866 || (unit_a == bestvalue && build_cost < best_cost)) {
869 best_cost = build_cost;
885 const struct unit *pvictim,
886 const struct tile *tgt_tile)
945 enum combat_bonus_type
type)
951 value += pbonus->value;
967 int rate = (base_bombard_rate *
punit->
hp) / utype->
hp;
972 return base_bombard_rate;
#define BV_ISSET(bv, bit)
#define city_owner(_pcity_)
static struct fc_sockaddr_list * list
bool is_unit_reachable_at(const struct unit *defender, const struct unit *attacker, const struct tile *location)
bool is_stack_vulnerable(const struct tile *ptile)
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)
static enum unit_attack_result unit_attack_any_at_tile_result(const struct unit *punit, const struct action *paction, const struct tile *ptile)
int get_attack_power(const struct unit *punit)
int unit_bombard_rate(struct unit *punit)
int combat_bonus_against(const struct combat_bonus_list *list, const struct unit_type *enemy, enum combat_bonus_type type)
int get_fortified_defense_power(const struct unit *attacker, struct unit *defender)
enum unit_attack_result unit_attack_units_at_tile_result(const struct unit *punit, const struct action *paction, const struct tile *ptile)
static int get_defense_rating(const struct civ_map *nmap, const struct unit *attacker, const struct unit *defender)
struct unit * get_attacker(const struct civ_map *nmap, const struct unit *defender, const struct tile *ptile)
int base_get_attack_power(const struct unit_type *punittype, int veteran, int moves_left)
struct city * sdi_try_defend(const struct civ_map *nmap, const struct player *owner, const struct tile *ptile)
int get_total_defense_power(const struct unit *attacker, const struct unit *defender)
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)
static enum unit_attack_result unit_attack_all_at_tile_result(const struct unit *punit, const struct action *paction, const struct tile *ptile)
static int get_defense_power(const struct unit *punit)
struct unit * get_diplomatic_defender(const struct unit *act_unit, const struct unit *pvictim, const struct tile *tgt_tile)
bool is_tired_attack(int moves_left)
static int defense_multiplication(const struct unit_type *att_type, const struct unit *def, const struct player *def_player, const struct tile *ptile, int defensepower)
double win_chance(int as, int ahp, int afp, int ds, int dhp, int dfp)
int get_total_attack_power(const struct unit *attacker, const struct unit *defender)
double unit_win_chance(const struct civ_map *nmap, const struct unit *attacker, const struct unit *defender)
bool can_unit_attack_tile(const struct unit *punit, const struct action *paction, const struct tile *dest_tile)
int base_get_defense_power(const struct unit *punit)
struct unit * get_defender(const struct civ_map *nmap, const struct unit *attacker, const struct tile *ptile)
void get_modified_firepower(const struct civ_map *nmap, const struct unit *attacker, const struct unit *defender, int *att_fp, int *def_fp)
static bool can_player_attack_tile(const struct player *pplayer, const struct tile *ptile)
static bool is_unit_reachable_by_unit(const struct unit *defender, const struct unit *attacker)
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
int get_target_bonus_effects(struct effect_list *plist, const struct req_context *context, const struct player *other_player, enum effect_type effect_type)
int get_unittype_bonus(const struct player *pplayer, const struct tile *ptile, const struct unit_type *punittype, const struct action *paction, enum effect_type effect_type)
#define fc_assert_ret_val(condition, val)
#define fc_assert_action(condition, action)
#define square_iterate(nmap, center_tile, radius, tile_itr)
#define square_iterate_end
bool can_exist_at_tile(const struct civ_map *nmap, const struct unit_type *utype, const struct tile *ptile)
bool is_native_tile(const struct unit_type *punittype, const struct tile *ptile)
bool unit_can_defend_here(const struct civ_map *nmap, const struct unit *punit)
bool can_attack_non_native(const struct unit_type *utype)
static bool is_native_tile_to_class(const struct unit_class *punitclass, const struct tile *ptile)
bool pplayers_at_war(const struct player *pplayer, const struct player *pplayer2)
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
struct packet_game_info info
bool damage_reduces_bombard_rate
int low_firepower_pearl_harbour
int low_firepower_nonnat_bombard
int low_firepower_combat_bonus
bool unreachable_protects
int low_firepower_badwallattacker
struct veteran_system * veteran
int scramble_coeff[U_LAST]
struct unit_type::@88 cache
int defense_mp_bonuses_pct[U_LAST]
struct combat_bonus_list * bonuses
enum unit_activity activity
bool tile_has_extra_flag(const struct tile *ptile, enum extra_flag_id flag)
int tile_extras_defense_bonus(const struct tile *ptile, const struct unit_type *punittype)
bool tile_has_native_base(const struct tile *ptile, const struct unit_type *punittype)
struct city * tile_city(const struct tile *ptile)
#define tile_terrain(_tile)
struct unit * unit_virtual_create(struct player *pplayer, struct city *pcity, const struct unit_type *punittype, int veteran_level)
void unit_virtual_destroy(struct unit *punit)
void unit_tile_set(struct unit *punit, struct tile *ptile)
bool unit_transported(const struct unit *pcargo)
#define unit_list_iterate(unitlist, punit)
#define unit_list_iterate_end
const struct unit_type * unit_type_get(const struct unit *punit)
bool utype_has_class_flag(const struct unit_type *ptype, enum unit_class_flag_id flag)
int unit_build_shield_cost_base(const struct unit *punit)
bool utype_can_do_act_when_ustate(const struct unit_type *punit_type, const action_id act_id, const enum ustate_prop prop, const bool is_there)
struct unit_class * unit_class_get(const struct unit *punit)
bool utype_can_do_action_result(const struct unit_type *putype, enum action_result result)
const struct veteran_level * utype_veteran_level(const struct unit_type *punittype, int level)
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Unit_type_id utype_index(const struct unit_type *punittype)
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
static bool uclass_has_flag(const struct unit_class *punitclass, enum unit_class_flag_id flag)
#define combat_bonus_list_iterate_end
#define combat_bonus_list_iterate(bonuslist, pbonus)
static bool utype_has_flag(const struct unit_type *punittype, int flag)
#define uclass_index(_c_)