Author: cazfi
Date: Fri Jan 20 11:37:50 2017
New Revision: 34871

URL: http://svn.gna.org/viewcvs/freeciv?rev=34871&view=rev
Log:
Sync main map tile terrain info to threxpr map.

See patch #8071

Modified:
    trunk/ai/classic/classicai.c
    trunk/ai/threxpr/texaimsg.h
    trunk/ai/threxpr/texaiplayer.c
    trunk/ai/threxpr/texaiworld.c
    trunk/ai/threxpr/texaiworld.h
    trunk/ai/threxpr/threxprai.c
    trunk/common/ai.h
    trunk/doc/README.AI_modules
    trunk/server/maphand.c

Modified: trunk/ai/classic/classicai.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/classic/classicai.c?rev=34871&r1=34870&r2=34871&view=diff
==============================================================================
--- trunk/ai/classic/classicai.c        (original)
+++ trunk/ai/classic/classicai.c        Fri Jan 20 11:37:50 2017
@@ -660,7 +660,9 @@
   ai->funcs.consider_tile_dangerous = cai_consider_tile_dangerous;
   ai->funcs.consider_wonder_city = cai_consider_wonder_city;
 
-  ai->funcs.refresh = NULL;
+  /* ai->funcs.refresh = NULL; */
+
+  /* ai->funcs.tile_info = NULL; */
 
   return TRUE;
 }

Modified: trunk/ai/threxpr/texaimsg.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/threxpr/texaimsg.h?rev=34871&r1=34870&r2=34871&view=diff
==============================================================================
--- trunk/ai/threxpr/texaimsg.h (original)
+++ trunk/ai/threxpr/texaimsg.h Fri Jan 20 11:37:50 2017
@@ -20,6 +20,12 @@
 #define SPECENUM_VALUE1NAME "FirstActivities"
 #define SPECENUM_VALUE2 TEXAI_MSG_PHASE_FINISHED
 #define SPECENUM_VALUE2NAME "PhaseFinished"
+#define SPECENUM_VALUE3 TEXAI_MSG_TILE_INFO
+#define SPECENUM_VALUE3NAME "TileInfo"
+#define SPECENUM_VALUE4 TEXAI_MSG_GAME_START
+#define SPECENUM_VALUE4NAME "GameStart"
+#define SPECENUM_VALUE5 TEXAI_MSG_GAME_END
+#define SPECENUM_VALUE5NAME "GameEnd"
 #include "specenum_gen.h"
 
 #define SPECENUM_NAME texaireqtype

Modified: trunk/ai/threxpr/texaiplayer.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/threxpr/texaiplayer.c?rev=34871&r1=34870&r2=34871&view=diff
==============================================================================
--- trunk/ai/threxpr/texaiplayer.c      (original)
+++ trunk/ai/threxpr/texaiplayer.c      Fri Jan 20 11:37:50 2017
@@ -104,6 +104,14 @@
 **************************************************************************/
 void texai_game_start(struct ai_type *ait)
 {
+  texai_send_msg(TEXAI_MSG_GAME_START, NULL, NULL);
+}
+
+/**************************************************************************
+  Game start message received
+**************************************************************************/
+static void texai_game_start_recv(void)
+{
   texai_world_init();
 }
 
@@ -111,6 +119,14 @@
   Game has ended
 **************************************************************************/
 void texai_game_free(struct ai_type *ait)
+{
+  texai_send_msg(TEXAI_MSG_GAME_END, NULL, NULL);
+}
+
+/**************************************************************************
+  Game end message received
+**************************************************************************/
+static void texai_game_free_recv(void)
 {
   texai_world_close();
 }
@@ -161,11 +177,20 @@
       texai_send_req(TEXAI_REQ_TURN_DONE, msg->plr, NULL);
 
       break;
+    case TEXAI_MSG_TILE_INFO:
+      texai_tile_info_recv(msg->data);
+      break;
     case TEXAI_MSG_PHASE_FINISHED:
       new_abort = TEXAI_ABORT_PHASE_END;
       break;
     case TEXAI_MSG_THR_EXIT:
       new_abort = TEXAI_ABORT_EXIT;
+      break;
+    case TEXAI_MSG_GAME_START:
+      texai_game_start_recv();
+      break;
+    case TEXAI_MSG_GAME_END:
+      texai_game_free_recv();
       break;
     default:
       log_error("Illegal message type %s (%d) for threaded ai!",

Modified: trunk/ai/threxpr/texaiworld.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/threxpr/texaiworld.c?rev=34871&r1=34870&r2=34871&view=diff
==============================================================================
--- trunk/ai/threxpr/texaiworld.c       (original)
+++ trunk/ai/threxpr/texaiworld.c       Fri Jan 20 11:37:50 2017
@@ -19,9 +19,19 @@
 #include "map.h"
 #include "world_object.h"
 
+/* threxpr */
+#include "texaiplayer.h"
+
 #include "texaiworld.h"
 
 static struct world texai_world;
+
+struct texai_tile_info_msg
+{
+  int index;
+  struct terrain *terrain;
+  bv_extras extras;
+};
 
 /**************************************************************************
   Initialize world object for texai
@@ -39,3 +49,37 @@
 {
   map_free(&(texai_world.map));
 }
+
+/**************************************************************************
+  Tile info updated on main map. Send update to threxpr map.
+**************************************************************************/
+void texai_tile_info(struct tile *ptile)
+{
+  if (texai_thread_running()) {
+    struct texai_tile_info_msg *info = fc_malloc(sizeof(struct 
texai_tile_info_msg));
+
+    info->index = tile_index(ptile);
+    info->terrain = ptile->terrain;
+    info->extras = ptile->extras;
+
+    texai_send_msg(TEXAI_MSG_TILE_INFO, NULL, info);
+  }
+}
+
+/**************************************************************************
+  Receive tile update to the thread.
+**************************************************************************/
+void texai_tile_info_recv(void *data)
+{
+  struct texai_tile_info_msg *info = (struct texai_tile_info_msg *)data;
+
+  if (texai_world.map.tiles != NULL) {
+    struct tile *ptile;
+
+    ptile = index_to_tile(&(texai_world.map), info->index);
+    ptile->terrain = info->terrain;
+    ptile->extras = info->extras;
+  }
+
+  free(info);
+}

Modified: trunk/ai/threxpr/texaiworld.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/threxpr/texaiworld.h?rev=34871&r1=34870&r2=34871&view=diff
==============================================================================
--- trunk/ai/threxpr/texaiworld.h       (original)
+++ trunk/ai/threxpr/texaiworld.h       Fri Jan 20 11:37:50 2017
@@ -16,4 +16,7 @@
 void texai_world_init(void);
 void texai_world_close(void);
 
+void texai_tile_info(struct tile *ptile);
+void texai_tile_info_recv(void *data);
+
 #endif /* FC__TEXAIWORLD_H */

Modified: trunk/ai/threxpr/threxprai.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/threxpr/threxprai.c?rev=34871&r1=34870&r2=34871&view=diff
==============================================================================
--- trunk/ai/threxpr/threxprai.c        (original)
+++ trunk/ai/threxpr/threxprai.c        Fri Jan 20 11:37:50 2017
@@ -35,6 +35,7 @@
 #include "texaicity.h"
 #include "texaimsg.h"
 #include "texaiplayer.h"
+#include "texaiworld.h"
 
 const char *fc_ai_threxpr_capstr(void);
 bool fc_ai_threxpr_setup(struct ai_type *ai);
@@ -656,5 +657,7 @@
 
   ai->funcs.refresh = texwai_refresh;
 
+  ai->funcs.tile_info = texai_tile_info;
+  
   return TRUE;
 }

Modified: trunk/common/ai.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/ai.h?rev=34871&r1=34870&r2=34871&view=diff
==============================================================================
--- trunk/common/ai.h   (original)
+++ trunk/common/ai.h   Fri Jan 20 11:37:50 2017
@@ -1,4 +1,4 @@
-/**********************************************************************
+/***********************************************************************
  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
@@ -24,7 +24,7 @@
  * structure below. When changing mandatory capability part, check that
  * there's enough reserved_xx pointers in the end of the structure for
  * taking to use without need to bump mandatory capability again. */
-#define FC_AI_MOD_CAPSTR "+Freeciv-3.0-ai-module-2016.Sep.23"
+#define FC_AI_MOD_CAPSTR "+Freeciv-3.1-ai-module-2017.Jan.13"
 
 /* Timers for all AI activities. Define it to get statistics about the AI. */
 #ifdef FREECIV_DEBUG
@@ -264,6 +264,9 @@
 
     /* Called for player AI type with short internval */
     void (*refresh)(struct player *pplayer);
+
+    /* Called for every AI type when tile has changed */
+    void (*tile_info)(struct tile *ptile);
 
     /* These are here reserving space for future optional callbacks.
      * This way we don't need to change the mandatory capability of the AI 
module

Modified: trunk/doc/README.AI_modules
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/doc/README.AI_modules?rev=34871&r1=34870&r2=34871&view=diff
==============================================================================
--- trunk/doc/README.AI_modules (original)
+++ trunk/doc/README.AI_modules Fri Jan 20 11:37:50 2017
@@ -116,6 +116,11 @@
 6. Callback interface ChangeLog
 -------------------------------
 
+New in Freeciv 3.1:
+-------------------
+- Added 'tile_info', called when tile has changed
+
+
 New in Freeciv 3.0:
 -------------------
 - Added 'private' pointer for ai module to store data of its own

Modified: trunk/server/maphand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/maphand.c?rev=34871&r1=34870&r2=34871&view=diff
==============================================================================
--- trunk/server/maphand.c      (original)
+++ trunk/server/maphand.c      Fri Jan 20 11:37:50 2017
@@ -24,6 +24,7 @@
 #include "support.h"
 
 /* common */
+#include "ai.h"
 #include "base.h"
 #include "borders.h"
 #include "events.h"
@@ -473,6 +474,10 @@
   struct packet_tile_info info;
   const struct player *owner;
   const struct player *eowner;
+
+  if (dest == NULL) {
+    CALL_FUNC_EACH_AI(tile_info, ptile);
+  }
 
   if (send_tile_suppressed) {
     return;


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

Reply via email to