<URL: http://bugs.freeciv.org/Ticket/Display.html?id=40282 >

> 2008/6/10 Patrick Smith:
>> Hi,
>>
>> The attached patch seems to fix some CMA problems when loading a saved game.
>> The city report still indicates fairly random CMA choices for cities, but
>> some messages about the governor being confused seem to have disappeared,
>> and I can now set the governor as I wish after loading a game, which wasn't
>> always possible before.

 Your patch was a bit too hackish. For example, it handled only first
connection client made. If client reconnects to same or another
server, your fix was not used at all.
 Based on your comments about the actual problem and its reasons, I
wrote a bit different patch. It is attached to this email. Can you
test if it fixes the problems. (This version is written against TRUNK,
I don't know if it applies cleanly to other branches)


 - ML

diff -Nurd -X.diff_ignore freeciv/client/agents/cma_core.c 
freeciv/client/agents/cma_core.c
--- freeciv/client/agents/cma_core.c    2008-03-10 20:08:04.000000000 +0200
+++ freeciv/client/agents/cma_core.c    2008-06-15 20:17:12.000000000 +0300
@@ -48,6 +48,8 @@
 
 #include "cma_core.h"
 
+static bool cma_frozen;
+
 /*
  * The CMA is an agent. The CMA will subscribe itself to all city
  * events. So if a city changes the callback function city_changed is
@@ -362,6 +364,10 @@
   bool handled;
   int i, city_id = pcity->id;
 
+  if (cma_frozen) {
+    return;
+  }
+
   freelog(HANDLE_CITY_LOG_LEVEL,
          "handle_city(city %d=\"%s\") pos=(%d,%d) owner=%s",
          pcity->id,
@@ -505,13 +511,14 @@
 ...
 *****************************************************************************/
 bool cma_apply_result(struct city *pcity,
-                    const struct cm_result *const result)
+                      const struct cm_result *const result)
 {
   assert(!cma_is_city_under_agent(pcity, NULL));
   if (result->found_a_valid) {
     return apply_result_on_server(pcity, result);
-  } else
+  } else {
     return TRUE; /* ???????? */
+  }
 }
 
 /****************************************************************************
@@ -635,3 +642,25 @@
 
   attr_city_set(attr, city_id, SAVED_PARAMETER_SIZE, buffer);
 }
+
+/**************************************************************************
+  Freeze CMA not to act while cities have inconsistent state.
+**************************************************************************/
+void cma_freeze(void)
+{
+  cma_frozen = TRUE;
+}
+
+/**************************************************************************
+  Thaw CMA when cities reach consistent state.
+**************************************************************************/
+void cma_thaw(void)
+{
+  cma_frozen = FALSE;
+
+  cities_iterate(pcity) {
+    if (cma_is_city_under_agent(pcity, NULL)) {
+      city_changed(pcity->id);
+    }
+  } cities_iterate_end;
+}
diff -Nurd -X.diff_ignore freeciv/client/agents/cma_core.h 
freeciv/client/agents/cma_core.h
--- freeciv/client/agents/cma_core.h    2007-08-04 18:38:37.000000000 +0300
+++ freeciv/client/agents/cma_core.h    2008-06-15 20:18:20.000000000 +0300
@@ -37,6 +37,10 @@
  */
 void cma_init(void);
 
+/* Freeze cma for the time cities have inconsistent state */
+void cma_freeze(void);
+void cma_thaw(void);
+
 /* Change the actual city setting. */
 bool cma_apply_result(struct city *pcity,
                      const struct cm_result *const result);
diff -Nurd -X.diff_ignore freeciv/client/packhand.c freeciv/client/packhand.c
--- freeciv/client/packhand.c   2008-05-13 13:26:10.000000000 +0300
+++ freeciv/client/packhand.c   2008-06-15 20:27:01.000000000 +0300
@@ -18,16 +18,19 @@
 #include <assert.h>
 #include <string.h>
 
+/* utility */
 #include "capability.h"
 #include "capstr.h"
-#include "events.h"
 #include "fcintl.h"
+#include "log.h"
+#include "mem.h"
+
+/* common */
+#include "events.h"
 #include "game.h"
 #include "government.h"
 #include "idex.h"
-#include "log.h"
 #include "map.h"
-#include "mem.h"
 #include "nation.h"
 #include "packets.h"
 #include "player.h"
@@ -38,7 +41,7 @@
 #include "unitlist.h"
 #include "worklist.h"
 
-#include "agents.h"
+/* client */
 #include "attribute.h"
 #include "audio.h"
 #include "chatline_g.h"
@@ -70,6 +73,10 @@
 #include "tilespec.h"
 #include "wldlg_g.h"
 
+/* agents */
+#include "agents.h"
+#include "cma_core.h"
+
 #include "packhand.h"
 
 static void city_packet_common(struct city *pcity, struct tile *pcenter,
@@ -1061,6 +1068,9 @@
 {
   freelog(LOG_DEBUG, "handle_begin_turn()");
 
+  /* Cities are guaranteed to be in consistent state. */
+  cma_thaw();
+
   /* probably duplicate insurance */
   update_client_state(C_S_RUNNING);
 
@@ -2433,6 +2443,9 @@
 {
   int i;
 
+  /* Cities will have inconsistent state until told otherwise */
+  cma_freeze();
+
   update_client_state(C_S_PREPARING);
 
   ruleset_data_free();
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to