From 73c6a6fdd61701bf0e1c560dcb63ccc42ad5aa60 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Tue, 19 Jul 2022 07:40:10 +0300 Subject: [PATCH 40/40] Give loot regardless of exact way of killing the leader Loot was being given only in the case that the leader was the one actually defending in the battle. Reported by ihnatus See osdn #44672 Signed-off-by: Marko Lindqvist --- server/unittools.c | 155 +++++++++++++++++++++++---------------------- 1 file changed, 78 insertions(+), 77 deletions(-) diff --git a/server/unittools.c b/server/unittools.c index 46dcbb2732..f8aaa7f032 100644 --- a/server/unittools.c +++ b/server/unittools.c @@ -1957,6 +1957,84 @@ static void wipe_unit_full(struct unit *punit, bool transported, struct unit *ptrans = unit_transport_get(punit); struct city *pexclcity; + if (killer != NULL + && (game.info.gameloss_style & GAMELOSS_STYLE_LOOT) + && unit_has_type_flag(punit, UTYF_GAMELOSS)) { + int ransom = fc_rand(1 + pplayer->economic.gold); + int n; + + /* give map */ + give_distorted_map(pplayer, killer, 50, TRUE); + + log_debug("victim has money: %d", pplayer->economic.gold); + killer->economic.gold += ransom; + pplayer->economic.gold -= ransom; + + n = 1 + fc_rand(3); + + while (n > 0) { + Tech_type_id ttid = steal_a_tech(killer, pplayer, A_UNSET); + + if (ttid == A_NONE) { + log_debug("Worthless enemy doesn't have more techs to steal."); + break; + } else { + log_debug("Pressed tech %s from captured enemy", + research_advance_rule_name(research_get(killer), ttid)); + if (!fc_rand(3)) { + break; /* out of luck */ + } + n--; + } + } + + { /* try to submit some cities */ + int vcsize = city_list_size(pplayer->cities); + int evcsize = vcsize; + int conqsize = evcsize; + + if (evcsize < 3) { + evcsize = 0; + } else { + evcsize -=3; + } + /* about a quarter on average with high numbers less probable */ + conqsize = fc_rand(fc_rand(evcsize)); + + log_debug("conqsize=%d", conqsize); + + if (conqsize > 0) { + bool palace = game.server.savepalace; + bool submit = FALSE; + + game.server.savepalace = FALSE; /* moving it around is dumb */ + + city_list_iterate_safe(pplayer->cities, pcity) { + /* kindly ask the citizens to submit */ + if (fc_rand(vcsize) < conqsize) { + submit = TRUE; + } + vcsize--; + if (submit) { + conqsize--; + /* Transfer city to the victorious player + * kill all its units outside of a radius of 7, + * give verbose messages of every unit transferred, + * and raze buildings according to raze chance + * (also removes palace) */ + (void) transfer_city(killer, pcity, 7, TRUE, TRUE, TRUE, + !is_barbarian(killer)); + submit = FALSE; + } + if (conqsize <= 0) { + break; + } + } city_list_iterate_safe_end; + game.server.savepalace = palace; + } + } + } + /* The unit is doomed. */ punit->server.dying = TRUE; @@ -2270,83 +2348,6 @@ void kill_unit(struct unit *pkiller, struct unit *punit, bool vet) /* The unit is doomed. */ punit->server.dying = TRUE; - if ((game.info.gameloss_style & GAMELOSS_STYLE_LOOT) - && unit_has_type_flag(punit, UTYF_GAMELOSS)) { - ransom = fc_rand(1 + pvictim->economic.gold); - int n; - - /* give map */ - give_distorted_map(pvictim, pvictor, 50, TRUE); - - log_debug("victim has money: %d", pvictim->economic.gold); - pvictor->economic.gold += ransom; - pvictim->economic.gold -= ransom; - - n = 1 + fc_rand(3); - - while (n > 0) { - Tech_type_id ttid = steal_a_tech(pvictor, pvictim, A_UNSET); - - if (ttid == A_NONE) { - log_debug("Worthless enemy doesn't have more techs to steal."); - break; - } else { - log_debug("Pressed tech %s from captured enemy", - research_advance_rule_name(research_get(pvictor), ttid)); - if (!fc_rand(3)) { - break; /* out of luck */ - } - n--; - } - } - - { /* try to submit some cities */ - int vcsize = city_list_size(pvictim->cities); - int evcsize = vcsize; - int conqsize = evcsize; - - if (evcsize < 3) { - evcsize = 0; - } else { - evcsize -=3; - } - /* about a quarter on average with high numbers less probable */ - conqsize = fc_rand(fc_rand(evcsize)); - - log_debug("conqsize=%d", conqsize); - - if (conqsize > 0) { - bool palace = game.server.savepalace; - bool submit = FALSE; - - game.server.savepalace = FALSE; /* moving it around is dumb */ - - city_list_iterate_safe(pvictim->cities, pcity) { - /* kindly ask the citizens to submit */ - if (fc_rand(vcsize) < conqsize) { - submit = TRUE; - } - vcsize--; - if (submit) { - conqsize--; - /* Transfer city to the victorious player - * kill all its units outside of a radius of 7, - * give verbose messages of every unit transferred, - * and raze buildings according to raze chance - * (also removes palace) */ - (void) transfer_city(pvictor, pcity, 7, TRUE, TRUE, TRUE, - !is_barbarian(pvictor)); - submit = FALSE; - } - if (conqsize <= 0) { - break; - } - } city_list_iterate_safe_end; - game.server.savepalace = palace; - } - } - } - /* barbarian leader ransom hack */ if (is_barbarian(pvictim) && uclass_has_flag(unit_class_get(pkiller), UCF_COLLECT_RANSOM)) { -- 2.35.1