Author: cazfi
Date: Wed Dec 16 23:57:45 2015
New Revision: 31031

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

See bug #24169

Modified:
    branches/S2_6/server/diplhand.c
    branches/S2_6/server/plrhand.c
    branches/S2_6/server/unittools.c
    branches/S2_6/server/unittools.h

Modified: branches/S2_6/server/diplhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/diplhand.c?rev=31031&r1=31030&r2=31031&view=diff
==============================================================================
--- branches/S2_6/server/diplhand.c     (original)
+++ branches/S2_6/server/diplhand.c     Wed Dec 16 23:57:45 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: branches/S2_6/server/plrhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/plrhand.c?rev=31031&r1=31030&r2=31031&view=diff
==============================================================================
--- branches/S2_6/server/plrhand.c      (original)
+++ branches/S2_6/server/plrhand.c      Wed Dec 16 23:57:45 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: branches/S2_6/server/unittools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/unittools.c?rev=31031&r1=31030&r2=31031&view=diff
==============================================================================
--- branches/S2_6/server/unittools.c    (original)
+++ branches/S2_6/server/unittools.c    Wed Dec 16 23:57:45 2015
@@ -1316,20 +1316,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;
 }
@@ -1338,8 +1352,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: branches/S2_6/server/unittools.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/unittools.h?rev=31031&r1=31030&r2=31031&view=diff
==============================================================================
--- branches/S2_6/server/unittools.h    (original)
+++ branches/S2_6/server/unittools.h    Wed Dec 16 23:57:45 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