Author: cazfi
Date: Fri Oct 30 05:32:23 2015
New Revision: 30311

URL: http://svn.gna.org/viewcvs/freeciv?rev=30311&view=rev
Log:
Resolved a case where unit has a default AI task with goto target which advisor 
code,
uaware of default AI task, then overwrites while unit autoexplores.

Added callback for notifying ai type code and asking if autoexplorer may 
proceed.
Default AI clears AI task from a unit that has started exploring instead.

See bug #23888

Modified:
    branches/S2_6/ai/classic/classicai.c
    branches/S2_6/ai/default/aiunit.c
    branches/S2_6/ai/default/aiunit.h
    branches/S2_6/ai/threaded/threadedai.c
    branches/S2_6/common/ai.h
    branches/S2_6/common/movement.h
    branches/S2_6/doc/README.AI_modules
    branches/S2_6/server/advisors/autoexplorer.c
    branches/S2_6/server/unittools.c

Modified: branches/S2_6/ai/classic/classicai.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/ai/classic/classicai.c?rev=30311&r1=30310&r2=30311&view=diff
==============================================================================
--- branches/S2_6/ai/classic/classicai.c        (original)
+++ branches/S2_6/ai/classic/classicai.c        Fri Oct 30 05:32:23 2015
@@ -416,6 +416,17 @@
   struct ai_type *deftype = classic_ai_get_self();
 
   dai_auto_settler_cont(deftype, pplayer, punit, state);
+}
+
+/**************************************************************************
+  Call default ai with classic ai type as parameter.
+**************************************************************************/
+static void cai_switch_to_explore(struct unit *punit, struct tile *target,
+                                  enum override_bool *allow)
+{
+  struct ai_type *deftype = classic_ai_get_self();
+
+  dai_switch_to_explore(deftype, punit, target, allow);
 }
 
 /**************************************************************************
@@ -626,6 +637,8 @@
   ai->funcs.settler_run = cai_auto_settler_run;
   ai->funcs.settler_cont = cai_auto_settler_cont;
 
+  ai->funcs.want_to_explore = cai_switch_to_explore;
+
   ai->funcs.first_activities = cai_do_first_activities;
   ai->funcs.restart_phase = cai_restart_phase;
   ai->funcs.diplomacy_actions = cai_diplomacy_actions;

Modified: branches/S2_6/ai/default/aiunit.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/ai/default/aiunit.c?rev=30311&r1=30310&r2=30311&view=diff
==============================================================================
--- branches/S2_6/ai/default/aiunit.c   (original)
+++ branches/S2_6/ai/default/aiunit.c   Fri Oct 30 05:32:23 2015
@@ -3256,3 +3256,12 @@
 
   return able_to_strike;
 }
+
+/****************************************************************************
+  Switch to autoexploring.
+****************************************************************************/
+void dai_switch_to_explore(struct ai_type *ait, struct unit *punit,
+                           struct tile *target, enum override_bool *allow)
+{
+  dai_unit_new_task(ait, punit, AIUNIT_NONE, target);
+}

Modified: branches/S2_6/ai/default/aiunit.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/ai/default/aiunit.h?rev=30311&r1=30310&r2=30311&view=diff
==============================================================================
--- branches/S2_6/ai/default/aiunit.h   (original)
+++ branches/S2_6/ai/default/aiunit.h   Fri Oct 30 05:32:23 2015
@@ -156,4 +156,7 @@
 bool dai_unit_can_strike_my_unit(const struct unit *attacker,
                                  const struct unit *defender);
 
+void dai_switch_to_explore(struct ai_type *ait, struct unit *punit,
+                           struct tile *target, enum override_bool *allow);
+
 #endif  /* FC__AIUNIT_H */

Modified: branches/S2_6/ai/threaded/threadedai.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/ai/threaded/threadedai.c?rev=30311&r1=30310&r2=30311&view=diff
==============================================================================
--- branches/S2_6/ai/threaded/threadedai.c      (original)
+++ branches/S2_6/ai/threaded/threadedai.c      Fri Oct 30 05:32:23 2015
@@ -392,6 +392,16 @@
 /**************************************************************************
   Call default ai with threaded ai type as parameter.
 **************************************************************************/
+static void twai_switch_to_explore(struct unit *punit, struct tile *target,
+                                  enum override_bool *allow)
+{
+  TAI_AIT;
+  TAI_DFUNC(dai_switch_to_explore, punit, target, allow);
+}
+
+/**************************************************************************
+  Call default ai with threaded ai type as parameter.
+**************************************************************************/
 static void twai_first_activities(struct player *pplayer)
 {
   TAI_AIT;
@@ -580,6 +590,8 @@
   ai->funcs.settler_run = twai_auto_settler_run;
   ai->funcs.settler_cont = twai_auto_settler_cont;
 
+  ai->funcs.want_to_explore = twai_switch_to_explore;
+
   ai->funcs.first_activities = twai_first_activities;
   /* Do complete run after savegame loaded - we don't know what has been
      done before. */

Modified: branches/S2_6/common/ai.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/ai.h?rev=30311&r1=30310&r2=30311&view=diff
==============================================================================
--- branches/S2_6/common/ai.h   (original)
+++ branches/S2_6/common/ai.h   Fri Oct 30 05:32:23 2015
@@ -22,7 +22,7 @@
 
 /* Update this capability string when ever there is changes to ai_type
    structure below */
-#define FC_AI_MOD_CAPSTR "+Freeciv-ai-module-2015.Oct.15"
+#define FC_AI_MOD_CAPSTR "+Freeciv-2.6-ai-module-2015.Oct.30"
 
 /* Timers for all AI activities. Define it to get statistics about the AI. */
 #ifdef FREECIV_DEBUG
@@ -196,6 +196,10 @@
        Cancelling current work there will result in settler_run() call. */
     void (*settler_cont)(struct player *pplayer, struct unit *punit,
                          struct settlermap *state);
+
+    /* Called for player AI type when unit wants to autoexplore towards a 
tile. */
+    void (*want_to_explore)(struct unit *punit, struct tile *target,
+                            enum override_bool *allow);
 
     /* Called for player AI type in the beginning of player phase.
      * Unlike with phase_begin, everything is set up for phase already. */

Modified: branches/S2_6/common/movement.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/movement.h?rev=30311&r1=30310&r2=30311&view=diff
==============================================================================
--- branches/S2_6/common/movement.h     (original)
+++ branches/S2_6/common/movement.h     Fri Oct 30 05:32:23 2015
@@ -44,7 +44,8 @@
   MR_TRIREME,
   MR_CANNOT_DISEMBARK,
   MR_NON_NATIVE_MOVE,  /* Usually RMM_RELAXED road diagonally without link */
-  MR_ANIMAL_DISALLOWED
+  MR_ANIMAL_DISALLOWED,
+  MR_NOT_ALLOWED
 };
 
 int utype_move_rate(const struct unit_type *utype, const struct tile *ptile,

Modified: branches/S2_6/doc/README.AI_modules
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/doc/README.AI_modules?rev=30311&r1=30310&r2=30311&view=diff
==============================================================================
--- branches/S2_6/doc/README.AI_modules (original)
+++ branches/S2_6/doc/README.AI_modules Fri Oct 30 05:32:23 2015
@@ -130,3 +130,4 @@
 - Added player_save_relations and player_load_relations called on savegame 
handling for a
   player once per other player in game. Old player_save and player_load are 
called only once
   overall
+- Added want_to_explore, called for AI type of the unit owner, when it is 
about to autoexplore

Modified: branches/S2_6/server/advisors/autoexplorer.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/advisors/autoexplorer.c?rev=30311&r1=30310&r2=30311&view=diff
==============================================================================
--- branches/S2_6/server/advisors/autoexplorer.c        (original)
+++ branches/S2_6/server/advisors/autoexplorer.c        Fri Oct 30 05:32:23 2015
@@ -22,6 +22,7 @@
 #include "log.h"
 
 /* common */
+#include "ai.h"
 #include "movement.h"
 #include "player.h"
 #include "unit.h"
@@ -372,6 +373,15 @@
   if (best_tile != NULL) {
     /* TODO: read the path off the map we made.  Then we can make a path 
      * which goes beside the unknown, with a good EC callback... */
+    enum override_bool allow = NO_OVERRIDE;
+
+    if (pplayer->ai_controlled) {
+      CALL_PLR_AI_FUNC(want_to_explore, pplayer, punit, best_tile, &allow);
+    }
+    if (allow == OVERRIDE_FALSE) {
+      UNIT_LOG(LOG_DEBUG, punit, "not allowed to explore");
+      return MR_NOT_ALLOWED;
+    }
     if (!explorer_goto(punit, best_tile)) {
       /* Died?  Strange... */
       return MR_DEATH;

Modified: branches/S2_6/server/unittools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/unittools.c?rev=30311&r1=30310&r2=30311&view=diff
==============================================================================
--- branches/S2_6/server/unittools.c    (original)
+++ branches/S2_6/server/unittools.c    Fri Oct 30 05:32:23 2015
@@ -2602,6 +2602,9 @@
    case MR_DEATH:
      /* don't use punit! */
      return;
+   case MR_NOT_ALLOWED:
+     /* Needed for something else */
+     return;
    case MR_OK:
      /* FIXME: manage_auto_explorer() isn't supposed to change the activity,
       * but don't count on this.  See PR#39792.


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

Reply via email to