From 796f0d7590b67d1266d7e20ea404e4ad91094e1a Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 10 Dec 2022 07:35:30 +0200 Subject: [PATCH 30/30] Check Casus_Belli_Caught after failed paradrop Seee osdn #46174 Signed-off-by: Marko Lindqvist --- doc/README.effects | 10 +++++----- server/actiontools.c | 3 +-- server/unittools.c | 41 +++++++++++++++++++++++++++++++++++++---- 3 files changed, 43 insertions(+), 11 deletions(-) diff --git a/doc/README.effects b/doc/README.effects index 4ec4a48e62..6c05a057d9 100644 --- a/doc/README.effects +++ b/doc/README.effects @@ -356,7 +356,10 @@ This effect is supported only for following actions: 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_Success Checked when a player does an action to another player. Will cause an @@ -371,10 +374,7 @@ following actions that always success: Capture Units, Expel Unit, Conquer Extras, Heal Unit, Found City, Join City, Bombard, 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 + Establish Trade Route, Enter Marketplace, Pillage Casus_Belli_Complete Checked when a player completes an action that takes several turns diff --git a/server/actiontools.c b/server/actiontools.c index 14728e9c98..bd1b08d8fb 100644 --- a/server/actiontools.c +++ b/server/actiontools.c @@ -171,7 +171,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); @@ -376,7 +376,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 1207671876..df639a5394 100644 --- a/server/unittools.c +++ b/server/unittools.c @@ -2996,6 +2996,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 @@ -3049,7 +3050,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), @@ -3059,10 +3060,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 " @@ -3072,11 +3078,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