Author: sveinung Date: Sat May 6 23:01:53 2017 New Revision: 35426 URL: http://svn.gna.org/viewcvs/freeciv?rev=35426&view=rev Log: Use actor_consuming_always to wipe the actor.
See hrm Feature #657310 Modified: branches/S3_0/server/actiontools.c branches/S3_0/server/actiontools.h branches/S3_0/server/diplomats.c branches/S3_0/server/unithand.c Modified: branches/S3_0/server/actiontools.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S3_0/server/actiontools.c?rev=35426&r1=35425&r2=35426&view=diff ============================================================================== --- branches/S3_0/server/actiontools.c (original) +++ branches/S3_0/server/actiontools.c Sat May 6 23:01:53 2017 @@ -23,6 +23,7 @@ #include "notify.h" #include "plrhand.h" #include "unithand.h" +#include "unittools.h" #include "actiontools.h" @@ -32,6 +33,25 @@ struct player *, const struct tile *, const char *); + +/************************************************************************** + Wipe an actor if the action it successfully performed consumed it. +**************************************************************************/ +void action_success_actor_consume(struct action *paction, + int actor_id, struct unit *actor) +{ + if (unit_is_alive(actor_id) + && utype_is_consumed_by_action(paction, unit_type_get(actor))) { + if (action_has_result(paction, ACTION_DISBAND_UNIT) + || action_has_result(paction, ACTION_RECYCLE_UNIT)) { + wipe_unit(actor, ULR_DISBANDED, NULL); + } else if (action_has_result(paction, ACTION_NUKE)) { + wipe_unit(actor, ULR_DETONATED, NULL); + } else { + wipe_unit(actor, ULR_USED, NULL); + } + } +} /************************************************************************** Give the victim a casus belli against the offender. Modified: branches/S3_0/server/actiontools.h URL: http://svn.gna.org/viewcvs/freeciv/branches/S3_0/server/actiontools.h?rev=35426&r1=35425&r2=35426&view=diff ============================================================================== --- branches/S3_0/server/actiontools.h (original) +++ branches/S3_0/server/actiontools.h Sat May 6 23:01:53 2017 @@ -42,6 +42,9 @@ action_consequence_success(action_by_number(action_id), offender, \ victim_player, victim_tile, victim_link) +void action_success_actor_consume(struct action *paction, + int actor_id, struct unit *actor); + struct city *action_tgt_city(struct unit *actor, struct tile *target_tile, bool accept_all_actions); Modified: branches/S3_0/server/diplomats.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S3_0/server/diplomats.c?rev=35426&r1=35425&r2=35426&view=diff ============================================================================== --- branches/S3_0/server/diplomats.c (original) +++ branches/S3_0/server/diplomats.c Sat May 6 23:01:53 2017 @@ -245,9 +245,9 @@ /* The actor unit always survive unless the action it self has determined * to always consume it. */ - if (utype_is_consumed_by_action(paction, unit_type_get(pdiplomat))) { - wipe_unit(pdiplomat, ULR_USED, NULL); - } else { + if (!utype_is_consumed_by_action(paction, unit_type_get(pdiplomat))) { + /* This unit isn't about to be consumed. Send updated unit information + * to the clients. */ send_unit_info(NULL, pdiplomat); } @@ -343,9 +343,9 @@ /* The actor unit always survive unless the action it self has determined * to always consume it. */ - if (utype_is_consumed_by_action(paction, unit_type_get(pdiplomat))) { - wipe_unit(pdiplomat, ULR_USED, NULL); - } else { + if (!utype_is_consumed_by_action(paction, unit_type_get(pdiplomat))) { + /* This unit isn't about to be consumed. Send updated unit information + * to the clients. */ send_unit_info(NULL, pdiplomat); } Modified: branches/S3_0/server/unithand.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S3_0/server/unithand.c?rev=35426&r1=35425&r2=35426&view=diff ============================================================================== --- branches/S3_0/server/unithand.c (original) +++ branches/S3_0/server/unithand.c Sat May 6 23:01:53 2017 @@ -2227,6 +2227,7 @@ if (pcity \ && is_action_enabled_unit_on_city(action_type, \ actor_unit, pcity)) { \ + bool success; \ script_server_signal_emit("action_started_unit_city", 3, \ API_TYPE_ACTION, action_by_number(action), \ API_TYPE_UNIT, actor, \ @@ -2239,7 +2240,11 @@ /* Target city was destroyed during pre action Lua. */ \ return FALSE; \ } \ - return action_performer; \ + success = action_performer; \ + if (success) { \ + action_success_actor_consume(paction, actor_id, actor); \ + } \ + return success; \ } else { \ illegal_action(pplayer, actor_unit, action_type, \ pcity ? city_owner(pcity) : NULL, NULL, pcity, NULL, \ @@ -2249,6 +2254,7 @@ #define ACTION_STARTED_UNIT_SELF(action, actor, action_performer) \ if (actor_unit \ && is_action_enabled_unit_on_self(action_type, actor_unit)) { \ + bool success; \ script_server_signal_emit("action_started_unit_self", 2, \ API_TYPE_ACTION, action_by_number(action), \ API_TYPE_UNIT, actor); \ @@ -2256,7 +2262,11 @@ /* Actor unit was destroyed during pre action Lua. */ \ return FALSE; \ } \ - return action_performer; \ + success = action_performer; \ + if (success) { \ + action_success_actor_consume(paction, actor_id, actor); \ + } \ + return success; \ } else { \ illegal_action(pplayer, actor_unit, action_type, \ unit_owner(actor_unit), NULL, NULL, actor_unit, \ @@ -2266,6 +2276,7 @@ #define ACTION_STARTED_UNIT_UNIT(action, actor, target, action_performer) \ if (punit \ && is_action_enabled_unit_on_unit(action_type, actor_unit, punit)) {\ + bool success; \ script_server_signal_emit("action_started_unit_unit", 3, \ API_TYPE_ACTION, action_by_number(action), \ API_TYPE_UNIT, actor, \ @@ -2278,7 +2289,11 @@ /* Target unit was destroyed during pre action Lua. */ \ return FALSE; \ } \ - return action_performer; \ + success = action_performer; \ + if (success) { \ + action_success_actor_consume(paction, actor_id, actor); \ + } \ + return success; \ } else { \ illegal_action(pplayer, actor_unit, action_type, \ punit ? unit_owner(punit) : NULL, NULL, NULL, punit, \ @@ -2289,6 +2304,7 @@ if (target_tile \ && is_action_enabled_unit_on_units(action_type, \ actor_unit, target_tile)) { \ + bool success; \ script_server_signal_emit("action_started_unit_units", 3, \ API_TYPE_ACTION, action_by_number(action), \ API_TYPE_UNIT, actor, \ @@ -2297,7 +2313,11 @@ /* Actor unit was destroyed during pre action Lua. */ \ return FALSE; \ } \ - return action_performer; \ + success = action_performer; \ + if (success) { \ + action_success_actor_consume(paction, actor_id, actor); \ + } \ + return success; \ } else { \ illegal_action(pplayer, actor_unit, action_type, \ target_tile ? tile_owner(target_tile) : NULL, \ @@ -2309,6 +2329,7 @@ if (target_tile \ && is_action_enabled_unit_on_tile(action_type, \ actor_unit, target_tile)) { \ + bool success; \ script_server_signal_emit("action_started_unit_tile", 3, \ API_TYPE_ACTION, action_by_number(action), \ API_TYPE_UNIT, actor, \ @@ -2317,7 +2338,11 @@ /* Actor unit was destroyed during pre action Lua. */ \ return FALSE; \ } \ - return action_performer; \ + success = action_performer; \ + if (success) { \ + action_success_actor_consume(paction, actor_id, actor); \ + } \ + return success; \ } else { \ illegal_action(pplayer, actor_unit, action_type, \ NULL, target_tile, NULL, NULL, \ @@ -2619,8 +2644,6 @@ fc_assert_ret_val(pplayer, FALSE); fc_assert_ret_val(punit, FALSE); - wipe_unit(punit, ULR_DISBANDED, NULL); - /* The unit is now disbanded. */ return TRUE; } @@ -2663,8 +2686,6 @@ city_link(pcity)); send_city_info(city_owner(pcity), pcity); - - wipe_unit(punit, ULR_DISBANDED, NULL); /* The unit is now recycled. */ return TRUE; @@ -2720,7 +2741,6 @@ action_id_consequence_success(ACTION_JOIN_CITY, pplayer, city_owner(pcity), city_tile(pcity), city_link(pcity)); - wipe_unit(punit, ULR_USED, NULL); sanity_check_city(pcity); @@ -2769,7 +2789,6 @@ city_change_size(pcity, size, nationality, NULL); } - wipe_unit(punit, ULR_USED, NULL); /* May cause an incident even if the target tile is unclaimed. A ruleset * could give everyone a casus belli against the city founder. A rule @@ -3153,7 +3172,13 @@ dlsend_packet_nuke_tile_info(game.est_connections, tile_index(def_tile)); + /* A nuke is always consumed when it detonates. See below. */ + fc_assert(action_by_number(ACTION_NUKE)->actor_consuming_always); + + /* The nuke must be wiped here so it won't be seen as a victim of its own + * detonation. */ wipe_unit(punit, ULR_DETONATED, NULL); + do_nuclear_explosion(pplayer, def_tile); /* May cause an incident even if the target tile is unclaimed. A ruleset @@ -3774,7 +3799,6 @@ work); } - wipe_unit(punit, ULR_USED, NULL); send_player_info_c(pplayer, pplayer->connections); send_city_info(pplayer, pcity_dest); conn_list_do_unbuffer(pplayer->connections); @@ -3978,7 +4002,6 @@ destcity_link, goods_str); } - wipe_unit(punit, ULR_USED, NULL); if (bonus_type == TBONUS_GOLD || bonus_type == TBONUS_BOTH) { pplayer->economic.gold += revenue; _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits