Author: sveinung
Date: Mon Aug 25 13:52:15 2014
New Revision: 26031

URL: http://svn.gna.org/viewcvs/freeciv?rev=26031&view=rev
Log:
SDL clients: don't use client side knowledge to evaluate action enablers

Checking for what diplomatic actions are possible in the client can give the
wrong result since a rule may depend on knowledge the player don't have. The
only targets that currently are legal to act against when they share the actors
tile are foreign cities. Check for the presence of a foreign city in stead of
using possibly wrong client knowledge to check if any spy action is possible.

See bug #22510

Modified:
    trunk/client/climisc.c
    trunk/client/climisc.h
    trunk/client/gui-sdl/menu.c
    trunk/client/gui-sdl2/menu.c

Modified: trunk/client/climisc.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/climisc.c?rev=26031&r1=26030&r2=26031&view=diff
==============================================================================
--- trunk/client/climisc.c      (original)
+++ trunk/client/climisc.c      Mon Aug 25 13:52:15 2014
@@ -1201,27 +1201,36 @@
   return FALSE;
 }
 
-/****************************************************************************
-  Returns TRUE if any of the units can do a generalized action against its
-  own tile.
-****************************************************************************/
+/**************************************************************************
+  Returns TRUE if the unit can do a generalized action against its own
+  tile.
+**************************************************************************/
+bool can_unit_act_against_own_tile(struct unit *punit)
+{
+  struct city *pcity;
+
+  /* All generalized actions vs own tile is currently against cities */
+  return (is_actor_unit(punit)
+          && (pcity = tile_city(unit_tile(punit)))
+          && city_owner(pcity) != unit_owner(punit));
+
+  /* FIXME: Ask the server so other target types than foreign cities can
+   * be supported as targeting them on your own tile becomes possible. */
+}
+
+/**************************************************************************
+  Returns TRUE if any of the units can do a generalized action against
+  its own tile.
+**************************************************************************/
 bool can_units_act_against_own_tile(struct unit_list *punits)
 {
-  struct city *pcity;
-
   unit_list_iterate(punits, punit) {
-    /* All generalized actions vs own tile is currently against cities */
-    if (is_actor_unit(punit)
-        && (pcity = tile_city(unit_tile(punit)))
-        && city_owner(pcity) != unit_owner(punit)) {
+    if (can_unit_act_against_own_tile(punit)) {
       return TRUE;
     }
   } unit_list_iterate_end;
 
   return FALSE;
-
-  /* FIXME: Ask the server so other target types than foreign cities can be
-   * supported as targeting them on your own tile becomes possible. */
 }
 
 /****************************************************************************

Modified: trunk/client/climisc.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/climisc.h?rev=26031&r1=26030&r2=26031&view=diff
==============================================================================
--- trunk/client/climisc.h      (original)
+++ trunk/client/climisc.h      Mon Aug 25 13:52:15 2014
@@ -118,6 +118,7 @@
                          enum unit_activity activity,
                           struct extra_type *tgt);
 
+bool can_unit_act_against_own_tile(struct unit *punit);
 bool can_units_act_against_own_tile(struct unit_list *punits);
 
 enum unit_bg_color_type { UNIT_BG_HP_LOSS,

Modified: trunk/client/gui-sdl/menu.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-sdl/menu.c?rev=26031&r1=26030&r2=26031&view=diff
==============================================================================
--- trunk/client/gui-sdl/menu.c (original)
+++ trunk/client/gui-sdl/menu.c Mon Aug 25 13:52:15 2014
@@ -1413,9 +1413,7 @@
         }
       }
 
-      if (is_actor_unit(pUnit) &&
-          /* FIXME: Should not be based on client side knowledge */
-         diplomat_can_do_action(pUnit, DIPLOMAT_ANY_ACTION, unit_tile(pUnit))) 
{
+      if (can_unit_act_against_own_tile(pUnit)) {
        local_show(ID_UNIT_ORDER_DIPLOMAT_DLG);
       } else {
        local_hide(ID_UNIT_ORDER_DIPLOMAT_DLG);

Modified: trunk/client/gui-sdl2/menu.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-sdl2/menu.c?rev=26031&r1=26030&r2=26031&view=diff
==============================================================================
--- trunk/client/gui-sdl2/menu.c        (original)
+++ trunk/client/gui-sdl2/menu.c        Mon Aug 25 13:52:15 2014
@@ -1415,9 +1415,7 @@
         }
       }
 
-      if (is_actor_unit(pUnit) &&
-          /* FIXME: Should not be based on client side knowledge */
-         diplomat_can_do_action(pUnit, DIPLOMAT_ANY_ACTION, unit_tile(pUnit))) 
{
+     if (can_unit_act_against_own_tile(pUnit)) {
        local_show(ID_UNIT_ORDER_DIPLOMAT_DLG);
       } else {
        local_hide(ID_UNIT_ORDER_DIPLOMAT_DLG);


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to