Complete.Org: Mailing Lists: Archives: freeciv-ai: September 2003:
[freeciv-ai] Re: (PR#4137) Auto-explore with new PF
Home

[freeciv-ai] Re: (PR#4137) Auto-explore with new PF

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: cameron@xxxxxxxxxx
Subject: [freeciv-ai] Re: (PR#4137) Auto-explore with new PF
From: "Per I. Mathisen" <per@xxxxxxxxxxx>
Date: Tue, 16 Sep 2003 06:43:57 -0700
Reply-to: rt@xxxxxxxxxxxxxx

On Sat, 13 Sep 2003, Gregory Berkolaiko wrote:
> Attached is the updated patch to the auto-explorers.
...
> What the patch doesn't do:
...
> 2. Send units home (or somewhere) when they've done exploring.

Attached patch fixes this. Also adds a fix from Jordi's ferry patch. Will
commit both patches soon unless someone objects.

  - Per

Index: ai/aiunit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.c,v
retrieving revision 1.285
diff -u -r1.285 aiunit.c
--- ai/aiunit.c 31 Aug 2003 17:21:03 -0000      1.285
+++ ai/aiunit.c 16 Sep 2003 13:40:31 -0000
@@ -1796,16 +1694,15 @@
 }
 
 /********************************************************************** 
-...
+  Send a unit to its homecity. FIXME: Give it one if it has none.
 ***********************************************************************/
 static void ai_military_gohome(struct player *pplayer,struct unit *punit)
 {
-  struct city *pcity;
+  struct city *pcity = find_city_by_id(punit->homecity);
 
   CHECK_UNIT(punit);
 
-  if (punit->homecity != 0){
-    pcity=find_city_by_id(punit->homecity);
+  if (pcity) {
     freelog(LOG_DEBUG, "GOHOME (%d)(%d,%d)C(%d,%d)",
                 punit->id,punit->x,punit->y,pcity->x,pcity->y); 
     if (same_pos(punit->x, punit->y, pcity->x, pcity->y)) {
@@ -2465,8 +2362,7 @@
     /* Sail somewhere */
     (void) ai_unit_goto(punit, pcity->x, pcity->y);
   } else if (!is_barbarian(pplayer)) {
-    /* Nothing else to do. Worst case, this function
-       will send us back home */
+    /* Nothing else to do, so try exploring. */
     (void) ai_manage_explorer(punit);
   } else {
     /* You can still have some moves left here, but barbarians should
@@ -2481,18 +2377,24 @@
         /* sometimes find_beachhead is not enough */
         if (!find_beachhead(punit, pc->x, pc->y, &fx, &fy)) {
           find_city_beach(pc, punit, &fx, &fy);
-          freelog(LOG_DEBUG, "Barbarian sailing to city");
-          ai_military_gothere(pplayer, punit, fx, fy);
-       }
+        }
+        UNIT_LOG(LOG_DEBUG, punit, "Barbarian sailing to %s", pc->name);
+        ai_military_gothere(pplayer, punit, fx, fy);
       }
     }
   }
   if ((punit = find_unit_by_id(id)) && punit->moves_left > 0) {
     struct city *pcity = map_get_city(punit->x, punit->y);
 
-    if (pcity && pcity->id == punit->homecity) {
-      /* We're needlessly idle in our homecity */
-      UNIT_LOG(LOG_DEBUG, punit, "fstk could not find work for me!");
+    if (pcity) {
+      ai_unit_new_role(punit, AIUNIT_DEFEND_HOME, pcity->x, pcity->y);
+      /* FIXME: Send unit to nearest city needing more defence */
+      UNIT_LOG(LOG_DEBUG, punit, "could not find work, sitting duck");
+    } else {
+      /* Going home */
+      UNIT_LOG(LOG_DEBUG, punit, "sent home");
+      /* FIXME: Rehome & send us to nearest city needing more defence */
+      ai_military_gohome(pplayer, punit);
     }
   }
 }

[Prev in Thread] Current Thread [Next in Thread]