From 917c8419a4e64e48c999de1705b079f2a72ce788 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 10 Dec 2022 07:31:02 +0200 Subject: [PATCH 44/44] Check Casus_Belli_Caught after failed paradrop Seee osdn #46174 Signed-off-by: Marko Lindqvist --- doc/README.effects | 9 +++++---- server/actiontools.c | 3 +-- server/unittools.c | 41 +++++++++++++++++++++++++++++++++++++---- 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/doc/README.effects b/doc/README.effects index a66fb9bd82..33ee758a15 100644 --- a/doc/README.effects +++ b/doc/README.effects @@ -234,7 +234,10 @@ Casus_Belli_Caught Targeted Sabotage City Escape, Sabotage City Production, Sabotage City Production Escape, Steal Gold, Steal Gold Escape, Steal Maps, Steal Maps Escape, Suitcase Nuke, Suitcase Nuke Escape, - Explode Nuclear, Nuke City, Nuke Units + Explode Nuclear, Nuke City, Nuke Units, + Paradrop Unit, Paradrop Unit Conquer, Paradrop Unit Frighten, + Paradrop Unit Frighten Conquer, Paradrop Unit Enter, + Paradrop Unit Enter Conquer, Casus_Belli_Complete Checked when a player completes an action that takes several turns @@ -259,9 +262,7 @@ Casus_Belli_Success Found City, Join City, Bombard, Bombard Lethal, Destroy City, Attack, Suicide Attack, Conquer City, Unit Move, Help Wonder, Disband Unit Recover, Establish Trade Route, Enter Marketplace, - Pillage, Paradrop Unit, Paradrop Unit Conquer, Paradrop Unit Frighten, - Paradrop Unit Frighten Conquer, Paradrop Unit Enter, - Paradrop Unit Enter Conquer, Spy Escape + Pillage, Spy Escape City_Build_Slots Increase the number of units with no population cost a city can build in diff --git a/server/actiontools.c b/server/actiontools.c index 8319cc019f..6e28ae7a83 100644 --- a/server/actiontools.c +++ b/server/actiontools.c @@ -173,7 +173,7 @@ static void action_consequence_common(const struct action *paction, /* Notify the involved players by sending them a message. */ notify_actor(offender, paction, offender, victim_player, - victim_tile, victim_link); + victim_tile, victim_link); notify_victim(victim_player, paction, offender, victim_player, victim_tile, victim_link); @@ -378,7 +378,6 @@ void action_consequence_caught(const struct action *paction, const struct tile *victim_tile, const char *victim_link) { - action_consequence_common(paction, offender, offender_utype, victim_player, victim_tile, victim_link, notify_actor_caught, diff --git a/server/unittools.c b/server/unittools.c index 470d13f133..ca534269da 100644 --- a/server/unittools.c +++ b/server/unittools.c @@ -2987,6 +2987,7 @@ bool do_paradrop(struct unit *punit, struct tile *ptile, struct player *pplayer = unit_owner(punit); struct player *tgt_player = tile_owner(ptile); const struct unit_type *act_utype = unit_type_get(punit); + const struct city *pcity; /* Hard requirements */ /* FIXME: hard requirements belong in common/actions's @@ -3040,7 +3041,7 @@ bool do_paradrop(struct unit *punit, struct tile *ptile, if (!can_unit_exist_at_tile(&(wld.map), punit, ptile) && (!BV_ISSET(paction->sub_results, ACT_SUB_RES_MAY_EMBARK) || !unit_could_load_at(punit, ptile))) { - map_show_circle(pplayer, ptile, unit_type_get(punit)->vision_radius_sq); + map_show_circle(pplayer, ptile, act_utype->vision_radius_sq); notify_player(pplayer, ptile, E_UNIT_LOST_MISC, ftc_server, _("Your %s paradropped into the %s and was lost."), unit_tile_link(punit), @@ -3050,10 +3051,15 @@ bool do_paradrop(struct unit *punit, struct tile *ptile, return TRUE; } - if ((is_non_allied_city_tile(ptile, pplayer) + pcity = tile_city(ptile); + + if ((pcity != NULL && !pplayers_allied(pplayer, city_owner(pcity)) && !action_has_result(paction, ACTRES_PARADROP_CONQUER)) || is_non_allied_unit_tile(ptile, pplayer)) { - map_show_circle(pplayer, ptile, unit_type_get(punit)->vision_radius_sq); + struct player *main_victim = NULL; + char victim_link[MAX_LEN_LINK]; + + map_show_circle(pplayer, ptile, act_utype->vision_radius_sq); maybe_make_contact(ptile, pplayer); notify_player(pplayer, ptile, E_UNIT_LOST_MISC, ftc_server, _("Your %s was killed by enemy units at the " @@ -3063,11 +3069,38 @@ bool do_paradrop(struct unit *punit, struct tile *ptile, * What if there's units of several allied players? Should the * city owner or owner of the first/random unit get the kill? */ pplayer->score.units_lost++; + + if (pcity != NULL) { + struct player *owner = city_owner(pcity); + + if (pplayers_at_war(pplayer, owner)) { + main_victim = owner; + } + + sz_strlcpy(victim_link, city_link(pcity)); + } else { + sz_strlcpy(victim_link, tile_link(ptile)); + } + + if (main_victim == NULL) { + unit_list_iterate(ptile->units, tgt) { + struct player *owner = unit_owner(tgt); + + if (pplayers_at_war(pplayer, owner)) { + main_victim = owner; + break; + } + } unit_list_iterate_end; + } + + action_consequence_caught(paction, pplayer, act_utype, + main_victim, ptile, + victim_link); + server_remove_unit(punit, ULR_KILLED); return TRUE; } - /* All ok */ punit->paradropped = TRUE; if (unit_move(punit, ptile, -- 2.35.1