Author: cazfi
Date: Wed Dec 16 23:57:40 2015
New Revision: 31030

URL: http://svn.gna.org/viewcvs/freeciv?rev=31030&view=rev
Log:
Remove third party units seen in allied cities from the client when the 
alliance gets cancelled.

See bug #24169

Modified:
    trunk/server/diplhand.c
    trunk/server/plrhand.c
    trunk/server/unittools.c
    trunk/server/unittools.h

Modified: trunk/server/diplhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/diplhand.c?rev=31030&r1=31029&r2=31030&view=diff
==============================================================================
--- trunk/server/diplhand.c     (original)
+++ trunk/server/diplhand.c     Wed Dec 16 23:57:40 2015
@@ -533,8 +533,8 @@
        }
       case CLAUSE_CEASEFIRE:
         if (old_diplstate == DS_ALLIANCE) {
-          pgiver_seen_units = get_seen_units(pgiver, pdest);
-          pdest_seen_units = get_seen_units(pdest, pgiver);
+          pgiver_seen_units = get_units_seen_via_ally(pgiver, pdest);
+          pdest_seen_units = get_units_seen_via_ally(pdest, pgiver);
         }
         ds_giverdest->type = DS_CEASEFIRE;
         ds_giverdest->turns_left = TURNS_LEFT;
@@ -558,8 +558,8 @@
        break;
       case CLAUSE_PEACE:
         if (old_diplstate == DS_ALLIANCE) {
-          pgiver_seen_units = get_seen_units(pgiver, pdest);
-          pdest_seen_units = get_seen_units(pdest, pgiver);
+          pgiver_seen_units = get_units_seen_via_ally(pgiver, pdest);
+          pdest_seen_units = get_units_seen_via_ally(pdest, pgiver);
         }
         ds_giverdest->type = DS_ARMISTICE;
         ds_destgiver->type = DS_ARMISTICE;

Modified: trunk/server/plrhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/plrhand.c?rev=31030&r1=31029&r2=31030&view=diff
==============================================================================
--- trunk/server/plrhand.c      (original)
+++ trunk/server/plrhand.c      Wed Dec 16 23:57:40 2015
@@ -700,8 +700,8 @@
   ds_plr2plr = player_diplstate_get(pplayer2, pplayer);
 
   if (old_type == DS_ALLIANCE) {
-    pplayer_seen_units = get_seen_units(pplayer, pplayer2);
-    pplayer2_seen_units = get_seen_units(pplayer2, pplayer);
+    pplayer_seen_units = get_units_seen_via_ally(pplayer, pplayer2);
+    pplayer2_seen_units = get_units_seen_via_ally(pplayer2, pplayer);
   } else {
     pplayer_seen_units = NULL;
     pplayer2_seen_units = NULL;

Modified: trunk/server/unittools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unittools.c?rev=31030&r1=31029&r2=31030&view=diff
==============================================================================
--- trunk/server/unittools.c    (original)
+++ trunk/server/unittools.c    Wed Dec 16 23:57:40 2015
@@ -1326,20 +1326,34 @@
 }
 
 /****************************************************************************
-  Returns the list of the units owned by 'aplayer' seen by 'pplayer'. The
-  returned pointer is newly allocated and should be freed by the caller,
-  using unit_list_destroy().
+  Returns the list of the units seen by 'pplayer' potentially seen only
+  thanks to an alliance with 'aplayer'. The returned pointer is newly
+  allocated and should be freed by the caller, using unit_list_destroy().
 ****************************************************************************/
-struct unit_list *get_seen_units(const struct player *pplayer,
-                                 const struct player *aplayer)
+struct unit_list *get_units_seen_via_ally(const struct player *pplayer,
+                                          const struct player *aplayer)
 {
   struct unit_list *seen_units = unit_list_new();
 
+  /* Anybody's units inside ally's cities */
+  city_list_iterate(aplayer->cities, pcity) {
+    unit_list_iterate(city_tile(pcity)->units, punit) {
+      if (can_player_see_unit(pplayer, punit)) {
+        unit_list_append(seen_units, punit);
+      }
+    } unit_list_iterate_end;
+  } city_list_iterate_end;
+
+  /* Ally's own units inside transports */
   unit_list_iterate(aplayer->units, punit) {
-    if (can_player_see_unit(pplayer, punit)) {
+    if (unit_transported(punit) && can_player_see_unit(pplayer, punit)) {
       unit_list_append(seen_units, punit);
     }
   } unit_list_iterate_end;
+
+  /* Make sure the same unit is not added in multiple phases
+   * (unit within transport in a city) */
+  unit_list_unique(seen_units);
 
   return seen_units;
 }
@@ -1348,8 +1362,8 @@
   When two players cancel an alliance, a lot of units that were visible may
   no longer be visible (this includes units in transporters and cities).
   Call this function to inform the clients that these units are no longer
-  visible. Pass the list of seen units returned by get_seen_units() before
-  alliance was broken up.
+  visible. Pass the list of seen units returned by get_units_seen_via_ally()
+  before alliance was broken up.
 ****************************************************************************/
 void remove_allied_visibility(struct player *pplayer, struct player *aplayer,
                               const struct unit_list *seen_units)

Modified: trunk/server/unittools.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unittools.h?rev=31030&r1=31029&r2=31030&view=diff
==============================================================================
--- trunk/server/unittools.h    (original)
+++ trunk/server/unittools.h    Wed Dec 16 23:57:40 2015
@@ -99,8 +99,8 @@
                          bool verbose);
 void resolve_unit_stacks(struct player *pplayer, struct player *aplayer,
                          bool verbose);
-struct unit_list *get_seen_units(const struct player *pplayer,
-                                 const struct player *aplayer);
+struct unit_list *get_units_seen_via_ally(const struct player *pplayer,
+                                          const struct player *aplayer);
 void remove_allied_visibility(struct player *pplayer, struct player *aplayer,
                               const struct unit_list *seen_units);
 void give_allied_visibility(struct player *pplayer, struct player *aplayer);


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

Reply via email to