Author: cazfi
Date: Fri Jan 13 07:44:05 2017
New Revision: 34825

URL: http://svn.gna.org/viewcvs/freeciv?rev=34825&view=rev
Log:
Allocate map of its own to threxpr AI type.

See patch #8067

Added:
    trunk/ai/threxpr/texaiworld.c
    trunk/ai/threxpr/texaiworld.h
Modified:
    trunk/ai/threxpr/Makefile.am
    trunk/ai/threxpr/texaiplayer.c
    trunk/ai/threxpr/texaiplayer.h
    trunk/ai/threxpr/threxprai.c
    trunk/common/map_types.h

Modified: trunk/ai/threxpr/Makefile.am
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/threxpr/Makefile.am?rev=34825&r1=34824&r2=34825&view=diff
==============================================================================
--- trunk/ai/threxpr/Makefile.am        (original)
+++ trunk/ai/threxpr/Makefile.am        Fri Jan 13 07:44:05 2017
@@ -23,6 +23,8 @@
        texaimsg.h              \
        texaiplayer.c           \
        texaiplayer.h           \
+       texaiworld.c            \
+       texaiworld.h            \
        threxprai.c
 
 if AI_MOD_STATIC_THREXPR

Modified: trunk/ai/threxpr/texaiplayer.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/threxpr/texaiplayer.c?rev=34825&r1=34824&r2=34825&view=diff
==============================================================================
--- trunk/ai/threxpr/texaiplayer.c      (original)
+++ trunk/ai/threxpr/texaiplayer.c      Fri Jan 13 07:44:05 2017
@@ -22,6 +22,7 @@
 #include "ai.h"
 #include "city.h"
 #include "game.h"
+#include "map.h"
 #include "unit.h"
 
 /* server/advisors */
@@ -32,6 +33,7 @@
 
 /* ai/threxpr */
 #include "texaicity.h"
+#include "texaiworld.h"
 
 #include "texaiplayer.h"
 
@@ -77,6 +79,10 @@
 
   log_debug("New AI thread launched");
 
+  if (!map_is_empty()) {
+    texai_world_init();
+  }
+
   /* Just wait until we are signaled to shutdown */
   fc_allocate_mutex(&exthrai.msgs_to.mutex);
   while (!finished) {
@@ -88,7 +94,25 @@
   }
   fc_release_mutex(&exthrai.msgs_to.mutex);
 
+  texai_world_close();
+
   log_debug("AI thread exiting");
+}
+
+/**************************************************************************
+  Game has started
+**************************************************************************/
+void texai_game_start(struct ai_type *ait)
+{
+  texai_world_init();
+}
+
+/**************************************************************************
+  Game has ended
+**************************************************************************/
+void texai_game_free(struct ai_type *ait)
+{
+  texai_world_close();
 }
 
 /**************************************************************************

Modified: trunk/ai/threxpr/texaiplayer.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/threxpr/texaiplayer.h?rev=34825&r1=34824&r2=34825&view=diff
==============================================================================
--- trunk/ai/threxpr/texaiplayer.h      (original)
+++ trunk/ai/threxpr/texaiplayer.h      Fri Jan 13 07:44:05 2017
@@ -48,6 +48,8 @@
 
 bool texai_thread_running(void);
 
+void texai_game_start(struct ai_type *ait);
+void texai_game_free(struct ai_type *ait);
 void texai_player_alloc(struct ai_type *ait, struct player *pplayer);
 void texai_player_free(struct ai_type *ait, struct player *pplayer);
 void texai_control_gained(struct ai_type *ait,struct player *pplayer);

Added: trunk/ai/threxpr/texaiworld.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/threxpr/texaiworld.c?rev=34825&view=auto
==============================================================================
--- trunk/ai/threxpr/texaiworld.c       (added)
+++ trunk/ai/threxpr/texaiworld.c       Fri Jan 13 07:44:05 2017
@@ -0,0 +1,41 @@
+/***********************************************************************
+ Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+***********************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <fc_config.h>
+#endif
+
+/* common */
+#include "map.h"
+#include "world_object.h"
+
+#include "texaiworld.h"
+
+static struct world texai_world;
+
+/**************************************************************************
+  Initialize world object for texai
+**************************************************************************/
+void texai_world_init(void)
+{
+  map_init(&(texai_world.map), TRUE);
+  map_allocate(&(texai_world.map));
+}
+
+/**************************************************************************
+  Free resources allocated for texai world object
+**************************************************************************/
+void texai_world_close(void)
+{
+  map_free(&(texai_world.map));
+}

Added: trunk/ai/threxpr/texaiworld.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/threxpr/texaiworld.h?rev=34825&view=auto
==============================================================================
--- trunk/ai/threxpr/texaiworld.h       (added)
+++ trunk/ai/threxpr/texaiworld.h       Fri Jan 13 07:44:05 2017
@@ -0,0 +1,19 @@
+/***********************************************************************
+ Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+***********************************************************************/
+#ifndef FC__TEXAIWORLD_H
+#define FC__TEXAIWORLD_H
+
+void texai_world_init(void);
+void texai_world_close(void);
+
+#endif /* FC__TEXAIWORLD_H */

Modified: trunk/ai/threxpr/threxprai.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/threxpr/threxprai.c?rev=34825&r1=34824&r2=34825&view=diff
==============================================================================
--- trunk/ai/threxpr/threxprai.c        (original)
+++ trunk/ai/threxpr/threxprai.c        Fri Jan 13 07:44:05 2017
@@ -69,6 +69,26 @@
 /**************************************************************************
   Call default ai with threxpr ai type as parameter.
 **************************************************************************/
+static void texwai_game_start(void)
+{
+  TEXAI_AIT;
+  TEXAI_TFUNC(texai_game_start);
+  /* Do not call default AI here, texai_player_alloc() does necessary parts */
+}
+
+/**************************************************************************
+  Call default ai with threxpr ai type as parameter.
+**************************************************************************/
+static void texwai_game_free(void)
+{
+  TEXAI_AIT;
+  TEXAI_TFUNC(texai_game_free);
+  /* Do not call default AI here, texai_player_alloc() does necessary parts */
+}
+
+/**************************************************************************
+  Call default ai with threxpr ai type as parameter.
+**************************************************************************/
 static void texwai_player_alloc(struct player *pplayer)
 {
   TEXAI_AIT;
@@ -565,6 +585,9 @@
   ai->private = private;
 
   texai_init_self(ai);
+
+  ai->funcs.game_start = texwai_game_start;
+  ai->funcs.game_free = texwai_game_free;
 
   ai->funcs.player_alloc = texwai_player_alloc;
   ai->funcs.player_free = texwai_player_free;

Modified: trunk/common/map_types.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/map_types.h?rev=34825&r1=34824&r2=34825&view=diff
==============================================================================
--- trunk/common/map_types.h    (original)
+++ trunk/common/map_types.h    Fri Jan 13 07:44:05 2017
@@ -16,6 +16,9 @@
 #ifdef __cplusplus
 extern "C" {
 #endif /* __cplusplus */
+
+/* common */
+#include "fc_types.h"
 
 /****************************************************************
   Miscellaneous terrain information


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

Reply via email to