Complete.Org: Mailing Lists: Archives: freeciv-ai: September 2003:
[freeciv-ai] Re: (PR#6227) Boats in assess danger
Home

[freeciv-ai] Re: (PR#6227) Boats in assess danger

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Gregory.Berkolaiko@xxxxxxxxxxxx
Subject: [freeciv-ai] Re: (PR#6227) Boats in assess danger
From: "Per I. Mathisen" <per@xxxxxxxxxxx>
Date: Mon, 22 Sep 2003 05:47:13 -0700
Reply-to: rt@xxxxxxxxxxxxxx

Here is a patch that rips out the current, mostly defunct assessment code
for ferries, and replaces it with a more specialized check. I need to
remove this to pave way for the ferry cleanup.

Fixed the bug where I used punit->ai.ferryboat instead of
punit->transported_by

  - Per

Index: ai/advmilitary.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/advmilitary.c,v
retrieving revision 1.153
diff -u -r1.153 advmilitary.c
--- ai/advmilitary.c    2003/09/16 18:04:47     1.153
+++ ai/advmilitary.c    2003/09/19 13:07:23
@@ -308,10 +308,10 @@
   Assess distance between punit and pcity.
 **************************************************************************/
 static int assess_distance(struct city *pcity, struct unit *punit,
-                           int move_rate, int boatid, int boatdist,
-                           int boatspeed)
+                           int move_rate)
 {
-  int x, y, distance = 0;
+  int distance = 0;
+  struct unit *ferry = find_unit_by_id(punit->transported_by);
 
   if (same_pos(punit->x, punit->y, pcity->x, pcity->y)) {
     return 0;
@@ -324,6 +324,8 @@
   } else if (!is_ground_unit(punit)) {
     distance = real_map_distance(punit->x, punit->y, pcity->x, pcity->y)
                * SINGLE_MOVE;
+  } else if (is_ground_unit(punit) && ferry) {
+    distance = WARMAP_SEACOST(ferry->x, ferry->y); /* Sea travellers. */
   } else if (unit_flag(punit, F_IGTER)) {
     distance = real_map_distance(punit->x, punit->y, pcity->x, pcity->y);
   } else {
@@ -335,25 +337,6 @@
     distance = SINGLE_MOVE;
   }
 
-  if (is_ground_unit(punit) && boatid != 0
-      && find_beachhead(punit, pcity->x, pcity->y, &x, &y)) {
-    /* Sea travellers. */
-
-    y = WARMAP_SEACOST(punit->x, punit->y);
-    if (y >= 6 * THRESHOLD) {
-      y = real_map_distance(pcity->x, pcity->y, punit->x, punit->y) * 
SINGLE_MOVE;
-    }
-
-    x = MAX(y, boatdist) * move_rate / boatspeed;
-
-    if (distance > x) {
-      distance = x;
-    }
-    if (distance < SINGLE_MOVE) {
-      distance = SINGLE_MOVE;
-    }
-  }
-
   return distance;
 }
 
@@ -446,30 +429,16 @@
   } unit_list_iterate_end;
 
   players_iterate(aplayer) {
-    int boatspeed;
-    int boatid, boatdist;
-    int x = pcity->x, y = pcity->y; /* dummy variables */
-
     if (!is_player_dangerous(city_owner(pcity), aplayer)) {
       continue;
     }
 
-    boatspeed = ((get_invention(aplayer, game.rtech.nav) == TECH_KNOWN) 
-                 ? 4 * SINGLE_MOVE : 2 * SINGLE_MOVE); /* likely speed */
-    boatid = find_boat(aplayer, &x, &y, 0); /* acquire a boat */
-    if (boatid != 0) {
-      boatdist = WARMAP_SEACOST(x, y); /* distance to acquired boat */
-    } else {
-      boatdist = -1; /* boat wanted */
-    }
-
     /* Look for enemy units */
     unit_list_iterate(aplayer->units, punit) {
       int paramove = 0;
       int move_rate = unit_type(punit)->move_rate;
       int vulnerability = assess_danger_unit(pcity, punit);
-      int dist = assess_distance(pcity, punit, move_rate, boatid, boatdist, 
-                                 boatspeed);
+      int dist = assess_distance(pcity, punit, move_rate);
       bool igwall = unit_really_ignores_citywalls(punit);
 
       if (unit_flag(punit, F_PARATROOPERS)) {

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