Author: cazfi
Date: Mon May  8 15:24:21 2017
New Revision: 35460

URL: http://svn.gna.org/viewcvs/freeciv?rev=35460&view=rev
Log:
Add city|unit_created|destroyed() to AI module API

See hrm Feature #658069

Modified:
    branches/S3_0/ai/classic/classicai.c
    branches/S3_0/common/ai.h
    branches/S3_0/doc/README.AI_modules
    branches/S3_0/server/citytools.c
    branches/S3_0/server/unittools.c

Modified: branches/S3_0/ai/classic/classicai.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S3_0/ai/classic/classicai.c?rev=35460&r1=35459&r2=35460&view=diff
==============================================================================
--- branches/S3_0/ai/classic/classicai.c        (original)
+++ branches/S3_0/ai/classic/classicai.c        Mon May  8 15:24:21 2017
@@ -599,6 +599,8 @@
   ai->funcs.city_alloc = cai_city_alloc;
   ai->funcs.city_free = cai_city_free;
   /*
+    ai->funcs.city_created = NULL;
+    ai->funcs.city_destroyed = NULL;
     ai->funcs.city_got = NULL;
     ai->funcs.city_lost = NULL;
   */
@@ -622,6 +624,8 @@
   /*
     ai->funcs.unit_alloc = NULL;
     ai->funcs.unit_free = NULL;
+    ai->funcs.unit_created = NULL;
+    ai->funcs.unit_destroyed = NULL;
     ai->funcs.unit_got = dai_unit_init;
     ai->funcs.unit_lost = dai_unit_close;
   */

Modified: branches/S3_0/common/ai.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S3_0/common/ai.h?rev=35460&r1=35459&r2=35460&view=diff
==============================================================================
--- branches/S3_0/common/ai.h   (original)
+++ branches/S3_0/common/ai.h   Mon May  8 15:24:21 2017
@@ -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.0-ai-module-2017.May.06"
 
 /* Timers for all AI activities. Define it to get statistics about the AI. */
 #ifdef FREECIV_DEBUG
@@ -112,11 +112,21 @@
     /* Called for player AI type when player phase ends. */
     void (*phase_finished)(struct player *pplayer);
 
-    /* Called for every AI type when new city is added to game. */
+    /* Called for every AI type when new city is added to game. Called even for
+     * virtual cities. */
     void (*city_alloc)(struct city *pcity);
 
-    /* Called for every AI type when city is removed from game. */
+    /* Called for every AI type when new city is removed from game. Called 
even for
+     * virtual cities. */
     void (*city_free)(struct city *pcity);
+
+    /* Called for every AI type when new city is added to game. Called for 
real cities
+     * only. */
+    void (*city_created)(struct city *pcity);
+
+    /* Called for every AI type when new city is removed from game. Called for 
real
+     * cities only. */
+    void (*city_destroyed)(struct city *pcity);
 
     /* Called for player AI type when player gains control of city. */
     void (*city_got)(struct player *pplayer, struct city *pcity);
@@ -158,11 +168,21 @@
     /* Called for every AI type before unit ruleset gets reloaded. */
     void (*units_ruleset_close)(void);
 
-    /* Called for every AI type when new unit is added to game. */
+    /* Called for every AI type when new unit is added to game. Called even for
+     * virtual units. */
     void (*unit_alloc)(struct unit *punit);
 
-    /* Called for every AI type when unit is removed from game. */
+    /* Called for every AI type when unit is removed from game. Called even for
+     * virtual units. */
     void (*unit_free)(struct unit *punit);
+
+    /* Called for every AI type when new unit is added to game. Called for real
+     * units only. */
+    void (*unit_created)(struct unit *punit);
+
+    /* Called for every AI type when unit is removed from game. Called for real
+     * units only. */
+    void (*unit_destroyed)(struct unit *punit);
 
     /* Called for player AI type when player gains control of unit. */
     void (*unit_got)(struct unit *punit);

Modified: branches/S3_0/doc/README.AI_modules
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S3_0/doc/README.AI_modules?rev=35460&r1=35459&r2=35460&view=diff
==============================================================================
--- branches/S3_0/doc/README.AI_modules (original)
+++ branches/S3_0/doc/README.AI_modules Mon May  8 15:24:21 2017
@@ -120,6 +120,10 @@
 -------------------
 - Added 'private' pointer for ai module to store data of its own
 - Added 'player_console', called when user enter aicmd
+- Added 'city_created', 'city_destroyed', 'unit_created', and 'unit_destroyed'
+  They are like 'city_alloc', 'city_free', 'unit_alloc', and 'unit_free' but 
called
+  for real cities and units only, in a later phase of creation or earlier phase
+  of destruction
 
 
 New in Freeciv 2.6:

Modified: branches/S3_0/server/citytools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S3_0/server/citytools.c?rev=35460&r1=35459&r2=35460&view=diff
==============================================================================
--- branches/S3_0/server/citytools.c    (original)
+++ branches/S3_0/server/citytools.c    Mon May  8 15:24:21 2017
@@ -1599,6 +1599,7 @@
   script_server_signal_emit("city_built", 1,
                             API_TYPE_CITY, pcity);
 
+  CALL_FUNC_EACH_AI(city_created, pcity);
   CALL_PLR_AI_FUNC(city_got, pplayer, pplayer, pcity);
 }
 
@@ -1620,6 +1621,7 @@
   const char *ctl = city_tile_link(pcity);
 
   CALL_PLR_AI_FUNC(city_lost, powner, powner, pcity);
+  CALL_FUNC_EACH_AI(city_destroyed, pcity);
 
   BV_CLR_ALL(had_small_wonders);
   city_built_iterate(pcity, pimprove) {

Modified: branches/S3_0/server/unittools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S3_0/server/unittools.c?rev=35460&r1=35459&r2=35460&view=diff
==============================================================================
--- branches/S3_0/server/unittools.c    (original)
+++ branches/S3_0/server/unittools.c    Mon May  8 15:24:21 2017
@@ -1647,6 +1647,7 @@
 
   unit_get_goods(punit);
 
+  CALL_FUNC_EACH_AI(unit_created, punit);
   CALL_PLR_AI_FUNC(unit_got, pplayer, punit);
 
   return punit;
@@ -1698,6 +1699,7 @@
 #endif /* FREECIV_DEBUG */
 
   CALL_PLR_AI_FUNC(unit_lost, pplayer, punit);
+  CALL_FUNC_EACH_AI(unit_destroyed, punit);
 
   /* Save transporter for updating below. */
   ptrans = unit_transport_get(punit);


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

Reply via email to