From ffe86dd4dd4d0af33ff37aa7dcadadd75e0c86e8 Mon Sep 17 00:00:00 2001 From: Sveinung Kvilhaugsvik Date: Tue, 11 May 2021 14:50:59 +0200 Subject: [PATCH 11/12] Factor out unit_attack_civilian_casualties(). Factor out the civilian casualties from attacking or bombarding units in a city to a new function. See osdn #42240 --- server/unithand.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/server/unithand.c b/server/unithand.c index d76b6c0cd8..cbabdcceea 100644 --- a/server/unithand.c +++ b/server/unithand.c @@ -4168,6 +4168,26 @@ static void send_combat(struct unit *pattacker, struct unit *pdefender, } conn_list_iterate_end; } +/**********************************************************************//** + Reduce the city's population after an attack action. +**************************************************************************/ +static void unit_attack_civilian_casualties(const struct unit *punit, + struct city *pcity, + const struct action *paction, + const char *reason) +{ + struct player *pplayer = unit_owner(punit); + + if (pcity + && city_size_get(pcity) > 1 + && get_city_bonus(pcity, EFT_UNIT_NO_LOSE_POP) <= 0 + && kills_citizen_after_attack(punit)) { + city_reduce_size(pcity, 1, pplayer, reason); + city_refresh(pcity); + send_city_info(NULL, pcity); + } +} + /**********************************************************************//** This function assumes the bombard is legal. The calling function should have already made all necessary checks. @@ -4263,14 +4283,7 @@ static bool unit_bombard(struct unit *punit, struct tile *ptile, unit_did_action(punit); unit_forget_last_activity(punit); - if (pcity - && city_size_get(pcity) > 1 - && get_city_bonus(pcity, EFT_UNIT_NO_LOSE_POP) <= 0 - && kills_citizen_after_attack(punit)) { - city_reduce_size(pcity, 1, pplayer, "bombard"); - city_refresh(pcity); - send_city_info(NULL, pcity); - } + unit_attack_civilian_casualties(punit, pcity, paction, "bombard"); send_unit_info(NULL, punit); @@ -4565,13 +4578,8 @@ static bool do_attack(struct unit *punit, struct tile *def_tile, def_tile, unit_link(pdefender)); if (pdefender->hp <= 0 - && (pcity = tile_city(def_tile)) - && city_size_get(pcity) > 1 - && get_city_bonus(pcity, EFT_UNIT_NO_LOSE_POP) <= 0 - && kills_citizen_after_attack(punit)) { - city_reduce_size(pcity, 1, pplayer, "attack"); - city_refresh(pcity); - send_city_info(NULL, pcity); + && (pcity = tile_city(def_tile))) { + unit_attack_civilian_casualties(punit, pcity, paction, "attack"); } if (punit->hp > 0 && pdefender->hp > 0) { /* Neither died */ -- 2.30.2