Re: [Freeciv-Dev] (PR#10301) cachemap is way too big

"Jason Short" <[email protected]>
Newsgroups gmane.games.freeciv.ai
Message-ID <[email protected]>
<URL: http://rt.freeciv.org/Ticket/Display.html?id=10301 >

The bug here is pretty significant too.  auto_settlers_player is called 
twice: once in auto_settlers_init and again in srv_main. 
ai_settler_init, which must be called before auto_settlers_player, is 
not called until after auto_settlers_init.  Thus the autosettlers is run 
twice, and on the first run its cachemap is not initialized.

So, in this patch:

- I change the cachemap to be dynamically allocated.  It is realloc'ed 
in ai_settlers_player.

- I removed the first call to auto_settlers_player (the one in 
init_auto_settlers).  Now the function is only called once, and it's 
done after ai_settler_init.

jason
aisettler-2.diff (text/x-patch, 1.5 KB)
Index: ai/aisettler.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aisettler.c,v
retrieving revision 1.5
diff -u -r1.5 aisettler.c
--- ai/aisettler.c	29 Sep 2004 02:24:18 -0000	1.5
+++ ai/aisettler.c	29 Sep 2004 04:55:17 -0000
@@ -98,7 +98,7 @@
   char food;
   char trade;
   char shield;
-} cachemap[MAP_MAX_WIDTH * MAP_MAX_HEIGHT];
+} *cachemap;
 
 /**************************************************************************
   Fill cityresult struct with useful info about the city spot. It must 
@@ -441,7 +441,8 @@
 **************************************************************************/
 void ai_settler_init(struct player *pplayer)
 {
-  memset(&cachemap, -1, sizeof(cachemap));
+  cachemap = fc_realloc(cachemap, MAX_MAP_INDEX * sizeof(*cachemap));
+  memset(cachemap, -1, MAX_MAP_INDEX * sizeof(*cachemap));
 }
 
 /**************************************************************************
Index: server/settlers.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/settlers.c,v
retrieving revision 1.204
diff -u -r1.204 settlers.c
--- server/settlers.c	29 Sep 2004 02:24:24 -0000	1.204
+++ server/settlers.c	29 Sep 2004 04:55:18 -0000
@@ -1449,9 +1449,6 @@
   assign_settlers();
   assign_territory();
   recount_enemy_masks();
-  shuffled_players_iterate(pplayer) {
-    auto_settlers_player(pplayer);
-  } shuffled_players_iterate_end;
 }
 
 /**************************************************************************
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.