Author: sveinung Date: Wed Mar 8 17:09:44 2017 New Revision: 35076 URL: http://svn.gna.org/viewcvs/freeciv?rev=35076&view=rev Log: Don't advice a player to declare war on himself.
The player can ask what actions a unit can perform to targets located at a specific tile in two ways. He can ask directly via the unit_get_actions packet. Ordering the unit to move to the tile is sometimes interpreted as an indirect question. When no action is possible the server will notify the player. If able to it will try to explain why no action was possible. An action may be impossible because the actor isn't at war with the target. The server will consider this when trying to find an explanation why no action could be performed. If declaring war may make an action legal it will let the player know. A player can't declare war on himself or on a team mate. Informing the player that a war may make some action legal is therefore pointless. See gna bug #25551 Modified: trunk/server/unithand.c Modified: trunk/server/unithand.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/server/unithand.c?rev=35076&r1=35075&r2=35076&view=diff ============================================================================== --- trunk/server/unithand.c (original) +++ trunk/server/unithand.c Wed Mar 8 17:09:44 2017 @@ -498,6 +498,29 @@ } /************************************************************************** + Returns TRUE iff the player is able to change his diplomatic + relationship to the other player to war. + + Note that the player can't declare war on someone he already is at war + with. +**************************************************************************/ +static bool rel_may_become_war(const struct player *pplayer, + const struct player *oplayer) +{ + enum diplstate_type ds; + + fc_assert_ret_val(pplayer, FALSE); + fc_assert_ret_val(oplayer, FALSE); + + ds = player_diplstate_get(pplayer, oplayer)->type; + + /* The player can't declare war on someone he already is at war with. */ + return ds != DS_WAR + /* The player can't declare war on a teammate or on himself. */ + && ds != DS_TEAM && pplayer != oplayer; +} + +/************************************************************************** Returns the first player that may enable the specified action if war is declared. @@ -535,14 +558,12 @@ struct unit *tunit; if ((tcity = tile_city(target_tile)) - && player_diplstate_get(unit_owner(actor), - city_owner(tcity))->type != DS_WAR) { + && rel_may_become_war(unit_owner(actor), city_owner(tcity))) { return city_owner(tcity); } if ((tunit = is_non_attack_unit_tile(target_tile, unit_owner(actor))) - && player_diplstate_get(unit_owner(actor), - unit_owner(tunit))->type != DS_WAR) { + && rel_may_become_war(unit_owner(actor), unit_owner(tunit))) { return unit_owner(tunit); } } @@ -554,7 +575,8 @@ if (target_tile && (tunit = is_non_attack_unit_tile(target_tile, - unit_owner(actor)))) { + unit_owner(actor))) + && rel_may_become_war(unit_owner(actor), unit_owner(tunit))) { return unit_owner(tunit); } } @@ -609,8 +631,7 @@ return NULL; } - if (player_diplstate_get(unit_owner(actor), - city_owner(target_city))->type != DS_WAR) { + if (rel_may_become_war(unit_owner(actor), city_owner(target_city))) { return city_owner(target_city); } break; @@ -620,8 +641,7 @@ return NULL; } - if (player_diplstate_get(unit_owner(actor), - unit_owner(target_unit))->type != DS_WAR) { + if (rel_may_become_war(unit_owner(actor), unit_owner(target_unit))) { return unit_owner(target_unit); } break; @@ -632,8 +652,7 @@ } unit_list_iterate(target_tile->units, tunit) { - if (player_diplstate_get(unit_owner(actor), - unit_owner(tunit))->type != DS_WAR) { + if (rel_may_become_war(unit_owner(actor), unit_owner(tunit))) { return unit_owner(tunit); } } unit_list_iterate_end; @@ -644,8 +663,7 @@ return NULL; } - if (player_diplstate_get(unit_owner(actor), - tile_owner(target_tile))->type != DS_WAR) { + if (rel_may_become_war(unit_owner(actor), tile_owner(target_tile))) { return tile_owner(target_tile); } break; _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits