Complete.Org: Mailing Lists: Archives: freeciv-dev: October 2004:
[Freeciv-Dev] (PR#10317) Tile marked as worked but occupied by an enemy
Home

[Freeciv-Dev] (PR#10317) Tile marked as worked but occupied by an enemy

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: marko.lindqvist@xxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#10317) Tile marked as worked but occupied by an enemy unit!
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 14 Oct 2004 12:40:52 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=10317 >

And, this patch should fix it as describe in the previous emails.

Like I said, it's a bit ugly.  But I see no better way.

jason

? diff.diff
? newtiles
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.250
diff -u -r1.250 city.c
--- common/city.c       8 Oct 2004 05:11:50 -0000       1.250
+++ common/city.c       14 Oct 2004 03:22:57 -0000
@@ -2449,6 +2449,9 @@
   pcity->rapture = 0;
   pcity->city_options = CITYOPT_DEFAULT;
 
+  pcity->server.workers_frozen = 0;
+  pcity->server.needs_arrange = FALSE;
+
   pcity->ai.trade_want = 1; /* we always want some */
   memset(pcity->ai.building_want, 0, sizeof(pcity->ai.building_want));
   pcity->ai.danger = 0;
Index: common/city.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.h,v
retrieving revision 1.163
diff -u -r1.163 city.h
--- common/city.h       29 Sep 2004 02:24:22 -0000      1.163
+++ common/city.h       14 Oct 2004 03:23:01 -0000
@@ -294,7 +294,15 @@
 
   /* server variable. indicates if the city map is synced with the client. */
   bool synced;
-    
+  struct {
+    /* If > 0, workers will not be rearranged until they are unfrozen. */
+    int workers_frozen;
+
+    /* If set, workers need to be arranged when the city is unfrozen.  Only
+     * set inside auto_arrange_workers. */
+    bool needs_arrange;
+  } server;
+
   int turn_founded;            /* In which turn was the city founded? */
 
   /* info for dipl/spy investigation -- used only in client */
Index: server/citytools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/citytools.c,v
retrieving revision 1.276
diff -u -r1.276 citytools.c
--- server/citytools.c  29 Sep 2004 02:24:23 -0000      1.276
+++ server/citytools.c  14 Oct 2004 03:23:03 -0000
@@ -63,6 +63,28 @@
 static bool update_city_tile_status(struct city *pcity, int city_x,
                                    int city_y);
 
+/****************************************************************************
+  Freeze the workers (citizens on tiles) for the city.  They will not be
+  auto-arranged until unfreeze_workers is called.
+****************************************************************************/
+static void freeze_workers(struct city *pcity)
+{
+  pcity->server.workers_frozen++;
+}
+
+/****************************************************************************
+  Thaw (unfreeze) the workers (citizens on tiles) for the city.  The workers
+  will be auto-arranged if there is an arrangement pending.
+****************************************************************************/
+static void thaw_workers(struct city *pcity)
+{
+  pcity->server.workers_frozen--;
+  assert(pcity->server.workers_frozen >= 0);
+  if (pcity->server.workers_frozen == 0 && pcity->server.needs_arrange) {
+    auto_arrange_workers(pcity);
+  }
+}
+
 /****************************************************************
 Returns the priority of the city name at the given position,
 using its own internal algorithm.  Lower priority values are
@@ -743,6 +765,8 @@
 
   assert(pgiver != ptaker);
 
+  freeze_workers(pcity);
+
   unit_list_init(&old_city_units);
   unit_list_iterate(pcity->units_supported, punit) {
     unit_list_insert(&old_city_units, punit);
@@ -834,6 +858,7 @@
     update_city_tile_status_map(pcity, ptile);
   } map_city_radius_iterate_end;
   auto_arrange_workers(pcity);
+  thaw_workers(pcity);
   if (raze)
     raze_city(pcity);
 
Index: server/cityturn.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/cityturn.c,v
retrieving revision 1.268
diff -u -r1.268 cityturn.c
--- server/cityturn.c   11 Oct 2004 01:57:52 -0000      1.268
+++ server/cityturn.c   14 Oct 2004 03:23:03 -0000
@@ -182,6 +182,12 @@
   struct cm_result cmr;
   struct player *pplayer = city_owner(pcity);
 
+  if (pcity->server.workers_frozen > 0) {
+    pcity->server.needs_arrange = TRUE;
+    return;
+  }
+  pcity->server.needs_arrange = FALSE;
+
   cm_init_parameter(&cmp);
 
   /* HACK: make sure everything is up-to-date before continuing.  This may

[Prev in Thread] Current Thread [Next in Thread]