Author: sveinung
Date: Sat Apr  1 22:13:16 2017
New Revision: 35184

URL: http://svn.gna.org/viewcvs/freeciv?rev=35184&view=rev
Log:
Make target-city-must-be-known precise.

The rule that a city must be known to a player before he can perform an
action to it used to be content when the player knew the city's tile. It was
therefore possible to act against an unknown city founded at a tile observed
before the city was founded.

Add player_tile_city_id_get() to the Freeciv interface. This makes it
possible to check if the city it self is known. Use it to make the rule
precise.

See Feature #648787

Modified:
    trunk/client/client_main.c
    trunk/common/actions.c
    trunk/common/fc_interface.c
    trunk/common/fc_interface.h
    trunk/server/srv_main.c

Modified: trunk/client/client_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/client_main.c?rev=35184&r1=35183&r2=35184&view=diff
==============================================================================
--- trunk/client/client_main.c  (original)
+++ trunk/client/client_main.c  Sat Apr  1 22:13:16 2017
@@ -1341,6 +1341,20 @@
   return dbv_isset(&pplayer->client.tile_vision[vlayer], tile_index(ptile));
 }
 
+/***************************************************************************
+  Returns the id of the city the player believes exists at 'ptile'.
+***************************************************************************/
+static int client_plr_tile_city_id_get(const struct tile *ptile,
+                                       const struct player *pplayer)
+{
+  struct city *pcity = tile_city(ptile);
+
+  /* Can't look up what other players think. */
+  fc_assert(pplayer == client_player());
+
+  return pcity ? pcity->id : IDENTITY_NUMBER_ZERO;
+}
+
 /***************************************************************
   Initialize client specific functions.
 ***************************************************************/
@@ -1351,6 +1365,7 @@
   funcs->create_extra = NULL;
   funcs->destroy_extra = NULL;
   funcs->player_tile_vision_get = client_map_is_known_and_seen;
+  funcs->player_tile_city_id_get = client_plr_tile_city_id_get;
   funcs->gui_color_free = color_free;
 
   /* Keep this function call at the end. It checks if all required functions

Modified: trunk/common/actions.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/actions.c?rev=35184&r1=35183&r2=35184&view=diff
==============================================================================
--- trunk/common/actions.c      (original)
+++ trunk/common/actions.c      Sat Apr  1 22:13:16 2017
@@ -24,6 +24,7 @@
 #include "actions.h"
 #include "city.h"
 #include "combat.h"
+#include "fc_interface.h"
 #include "game.h"
 #include "map.h"
 #include "movement.h"
@@ -1745,7 +1746,9 @@
     /* The Freeciv code assumes that the player is aware of the target
      * city's existence. (How can you order an airlift to a city when you
      * don't know its city ID?) */
-    if (!(plr_knows_tile(actor_player, city_tile(target_city)))) {
+    if (fc_funcs->player_tile_city_id_get(city_tile(target_city),
+                                          actor_player)
+        != target_city->id) {
       return TRI_NO;
     }
     break;

Modified: trunk/common/fc_interface.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/fc_interface.c?rev=35184&r1=35183&r2=35184&view=diff
==============================================================================
--- trunk/common/fc_interface.c (original)
+++ trunk/common/fc_interface.c Sat Apr  1 22:13:16 2017
@@ -57,6 +57,7 @@
 
   /* Test the existence of each required function here! */
   fc_assert_exit(fc_funcs->player_tile_vision_get);
+  fc_assert_exit(fc_funcs->player_tile_city_id_get);
   fc_assert_exit(fc_funcs->gui_color_free);
 
   fc_funcs_defined = TRUE;

Modified: trunk/common/fc_interface.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/fc_interface.h?rev=35184&r1=35183&r2=35184&view=diff
==============================================================================
--- trunk/common/fc_interface.h (original)
+++ trunk/common/fc_interface.h Sat Apr  1 22:13:16 2017
@@ -38,6 +38,11 @@
   bool (*player_tile_vision_get)(const struct tile *ptile,
                                  const struct player *pplayer,
                                  enum vision_layer vision);
+  /* Returns the id of the city 'pplayer' believes exists at 'ptile' or
+   * IDENTITY_NUMBER_ZERO when the player is unaware of a city at that
+   * location. */
+  int (*player_tile_city_id_get)(const struct tile *ptile,
+                                 const struct player *pplayer);
   void (*gui_color_free)(struct color *pcolor);
 };
 

Modified: trunk/server/srv_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/srv_main.c?rev=35184&r1=35183&r2=35184&view=diff
==============================================================================
--- trunk/server/srv_main.c     (original)
+++ trunk/server/srv_main.c     Sat Apr  1 22:13:16 2017
@@ -3251,6 +3251,19 @@
   return;
 }
 
+/***************************************************************************
+  Returns the id of the city the player map of 'pplayer' has at 'ptile' or
+  IDENTITY_NUMBER_ZERO if the player map don't have a city there.
+***************************************************************************/
+static int server_plr_tile_city_id_get(const struct tile *ptile,
+                                       const struct player *pplayer)
+{
+  const struct player_tile *plrtile = map_get_player_tile(ptile, pplayer);
+
+  return plrtile && plrtile->site ? plrtile->site->identity
+                                  : IDENTITY_NUMBER_ZERO;
+}
+
 /***************************************************************
   Initialize client specific functions.
 ***************************************************************/
@@ -3261,6 +3274,7 @@
   funcs->create_extra = create_extra;
   funcs->destroy_extra = destroy_extra;
   funcs->player_tile_vision_get = map_is_known_and_seen;
+  funcs->player_tile_city_id_get = server_plr_tile_city_id_get;
   funcs->gui_color_free = server_gui_color_free;
 
   /* Keep this function call at the end. It checks if all required functions


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

Reply via email to