Author: sveinung Date: Sat Sep 24 23:24:17 2016 New Revision: 33877 URL: http://svn.gna.org/viewcvs/freeciv?rev=33877&view=rev Log: Action not enabled explain wrong target nation.
See patch #7718 Modified: trunk/server/unithand.c trunk/server/unithand.h Modified: trunk/server/unithand.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/server/unithand.c?rev=33877&r1=33876&r2=33877&view=diff ============================================================================== --- trunk/server/unithand.c (original) +++ trunk/server/unithand.c Sat Sep 24 23:24:17 2016 @@ -86,6 +86,9 @@ /* The player to advice declaring war on. */ struct player *no_war_with; + + /* The nation that can't be involved. */ + struct nation_type *no_act_nation; /* The action that blocks the action. */ struct action *blocker; @@ -655,6 +658,49 @@ if (requirement_fulfilled_by_terrain(pterrain, (is_target ? &enabler->target_reqs : &enabler->actor_reqs))) { /* This terrain kind doesn't block this action enabler. */ + return FALSE; + } + } action_enabler_list_iterate_end; + + return TRUE; +} + +/************************************************************************** + Returns TRUE iff the specified nation blocks the specified action. + + If the "action" is ACTION_ANY all actions are checked. +**************************************************************************/ +static bool does_nation_block_action(const int action_id, + bool is_target, + struct unit *actor_unit, + struct nation_type *pnation) +{ + if (action_id == ACTION_ANY) { + /* Any action is OK. */ + action_iterate(alt_act) { + if (utype_can_do_action(unit_type_get(actor_unit), alt_act) + && !does_nation_block_action(alt_act, is_target, + actor_unit, pnation)) { + /* Only one action has to be possible. */ + return FALSE; + } + } action_iterate_end; + + /* No action enabled. */ + return TRUE; + } + + /* ACTION_ANY is handled above. */ + fc_assert_ret_val(action_id_is_valid(action_id), FALSE); + + action_enabler_list_iterate(action_enablers_for_action(action_id), + enabler) { + if (requirement_fulfilled_by_nation(pnation, + (is_target ? &enabler->target_reqs + : &enabler->actor_reqs)) + && requirement_fulfilled_by_unit_type(unit_type_get(actor_unit), + &enabler->actor_reqs)) { + /* This nation doesn't block this action enabler. */ return FALSE; } } action_enabler_list_iterate_end; @@ -841,6 +887,11 @@ DRO_FOREIGN, FALSE)) { explnat->kind = ANEK_DOMESTIC; + } else if (tgt_player + && does_nation_block_action(action_id, TRUE, + punit, tgt_player->nation)) { + explnat->kind = ANEK_NATION_TGT; + explnat->no_act_nation = tgt_player->nation; } else if ((target_tile && tile_city(target_tile)) && !utype_may_act_tgt_city_tile(unit_type_get(punit), action_id, @@ -1077,6 +1128,12 @@ notify_player(pplayer, unit_tile(punit), E_BAD_COMMAND, ftc_server, _("This unit cannot act against foreign targets.")); break; + case ANEK_NATION_TGT: + notify_player(pplayer, unit_tile(punit), E_BAD_COMMAND, ftc_server, + /* TRANS: ... Pirate ... */ + _("This unit cannot act against %s targets."), + nation_adjective_translation(explnat->no_act_nation)); + break; case ANEK_LOW_MP: notify_player(pplayer, unit_tile(punit), E_BAD_COMMAND, ftc_server, _("This unit has too few moves left to act.")); @@ -1460,6 +1517,17 @@ _("Your %s can't do %s to foreign %s."), unit_name_translation(actor), action_get_ui_name(stopped_action), + action_target_kind_translated_name( + action_id_get_target_kind(stopped_action))); + break; + case ANEK_NATION_TGT: + notify_player(pplayer, unit_tile(actor), + event, ftc_server, + /* TRANS: Riflemen... Expel Unit... Pirate... Migrants */ + _("Your %s can't do %s to %s %s."), + unit_name_translation(actor), + action_get_ui_name(stopped_action), + nation_adjective_translation(explnat->no_act_nation), action_target_kind_translated_name( action_id_get_target_kind(stopped_action))); break; Modified: trunk/server/unithand.h URL: http://svn.gna.org/viewcvs/freeciv/trunk/server/unithand.h?rev=33877&r1=33876&r2=33877&view=diff ============================================================================== --- trunk/server/unithand.h (original) +++ trunk/server/unithand.h Sat Sep 24 23:24:17 2016 @@ -45,6 +45,8 @@ ANEK_DOMESTIC, /* Explanation: can't be done to foreign targets. */ ANEK_FOREIGN, + /* Explanation: this nation can't be targeted. */ + ANEK_NATION_TGT, /* Explanation: not enough MP left. */ ANEK_LOW_MP, /* Explanation: can't be done to city centers. */ _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits