Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2002:
[Freeciv-Dev] (PR#2631) [Fix] ACTIVITY_EXPLORE infinite cycle
Home

[Freeciv-Dev] (PR#2631) [Fix] ACTIVITY_EXPLORE infinite cycle

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients:;
Subject: [Freeciv-Dev] (PR#2631) [Fix] ACTIVITY_EXPLORE infinite cycle
From: "Gregory Berkolaiko via RT" <rt@xxxxxxxxxxxxxx>
Date: Sun, 22 Dec 2002 09:47:34 -0800
Reply-to: rt@xxxxxxxxxxxxxx

Attached are two possible fixes for PR#2631.  Both work, both are kludges.

Actually, this bug is _very_ rare, because you'd need to manually set a 
AI-controlled unit to be explorer and only then you'd have it.  But still 
it is a bug.

Few comments first:

On Sun, 22 Dec 2002, Gregory Berkolaiko via RT wrote:

> The cycle goes like this:
> 
> 1. ai_manage_explorer asks ai_unit_goto to move the unit
> 2. ai_unit_goto cannot do it ("Ending turn early to stay out of trouble")
>  and attempts to reset the activity to ACTIVITY_EXPLORE 

Activity is being reset to ACTIVITY_EXPLORE only because it was that 
originally.  So the idea of patch#2 is to set it to IDLE.

> 3. handle_unit_activity_request calls handle_unit_activity_dependencies
>  which calls ai_manage_explorer

Calling ai_manage_explorer from handle_unit_activity_dependencies is done 
so that when you press "X", the request is received by server, which does 
handle_unit_activity_request_targeted and then explorer moves 
_straight_away_.  So the idea of the patch#1 is to let 
handle_unit_activity_request_targeted force movement immediately and
handle_unit_activity_request (which is called from inside AI) not force 
it.

The real fix would involve removing EXPLORE from activities and putting it
into a class of it's own, say AUTO.  There it can be joined by other
auto-unit modes, like auto-settler and auto-attack.  Then these auto-modes
can be cleanly detected and handled, not in a kludgy way it is done now
(fx.  if punit->ai.control == TRUE and the unit is settler, it must be in
auto-settler mode, and if it's a military unit, it must be in auto-attack
mode).

Best wishes,
G.


? pitfight.sh
? pitfight_g.sh
? score.log
? test.c
? ttt.gz
? ttt1.gz
? common/aicore/.deps
? common/aicore/Makefile
? common/aicore/Makefile.in
Index: server/unithand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unithand.c,v
retrieving revision 1.244
diff -u -r1.244 unithand.c
--- server/unithand.c   2002/12/18 17:36:20     1.244
+++ server/unithand.c   2002/12/22 17:16:25
@@ -1192,7 +1192,8 @@
 **************************************************************************/
 static void handle_unit_activity_dependencies(struct unit *punit,
                                              enum unit_activity old_activity,
-                                             int old_target)
+                                             int old_target,
+                                              bool start_now)
 {
   switch (punit->activity) {
   case ACTIVITY_IDLE:
@@ -1221,8 +1222,10 @@
     }
     break;
   case ACTIVITY_EXPLORE:
+    /* FIXME: exploring is not really an activity, it's and auto-mode like
+     * auto-settler and auto-attack */
     punit->ai.control = TRUE;
-    if (punit->moves_left > 0) {
+    if (punit->moves_left > 0 && start_now) {
       int id = punit->id;
       bool more_to_explore = ai_manage_explorer(punit);
 
@@ -1260,7 +1263,8 @@
       punit->pgr = NULL;
     }
     send_unit_info(NULL, punit);
-    handle_unit_activity_dependencies(punit, old_activity, old_target);
+    handle_unit_activity_dependencies(punit, old_activity, 
+                                      old_target, FALSE);
   }
 }
 
@@ -1287,7 +1291,8 @@
 
     send_unit_info_to_onlookers(NULL, punit, punit->x, punit->y, FALSE,
                                select_unit);
-    handle_unit_activity_dependencies(punit, old_activity, old_target);
+    handle_unit_activity_dependencies(punit, old_activity, 
+                                      old_target, TRUE);
   }
 }
 
? pitfight.sh
? pitfight_g.sh
? score.log
? test.c
? ttt.gz
? common/aicore/.deps
? common/aicore/Makefile
? common/aicore/Makefile.in
Index: ai/aiunit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.c,v
retrieving revision 1.241
diff -u -r1.241 aiunit.c
--- ai/aiunit.c 2002/12/21 09:39:23     1.241
+++ ai/aiunit.c 2002/12/22 17:36:22
@@ -287,6 +287,14 @@
     range = unit_type(punit)->vision_range;
   }
 
+  /* Idle unit */
+  /* FIXME: This is a kludge to fix PR#2631
+   * a real fix would involve changing EXPLORE from ACTIVITY to a new 
+   * AUTO class, together with auto-settler and auto-attack */
+  if (punit->activity != ACTIVITY_IDLE) {
+    handle_unit_activity_request(punit, ACTIVITY_IDLE);
+  }
+
   /* Localize the unit */
   
   if (is_ground_unit(punit)) {

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#2631) [Fix] ACTIVITY_EXPLORE infinite cycle, Gregory Berkolaiko via RT <=