Complete.Org: Mailing Lists: Archives: freeciv-ai: May 2004:
[freeciv-ai] (PR#8777) Find ferry
Home

[freeciv-ai] (PR#8777) Find ferry

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Gregory.Berkolaiko@xxxxxxxxxxxxx
Subject: [freeciv-ai] (PR#8777) Find ferry
From: "Guest" <rt-guest@xxxxxxxxxxx>
Date: Thu, 27 May 2004 04:36:31 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=8777 >



>+int find_ferry(struct unit *punit, int cap, struct pf_path **path)
>+{
>+  int best_turns = FC_INFINITY;
>+  int best_id = 0;
>+  struct pf_parameter param;
>+  struct pf_map *search_map;
>+
>+
>+  UNIT_LOG(LOGLEVEL_FINDFERRY, punit, "asked find_ferry for a boat");
>+
>+  if (ai_available_boats(unit_owner(punit)) <= 0 
>+      && punit->ai.ferryboat <= 0) {
>+    /* No boats to be found (the second check is to ensure that we are
not 
>+     * the ones keeping the last boat busy) */
>+    return 0;
>+  }
>+
>+  pft_fill_unit_parameter(&param, punit);
>+  param.turn_mode = TM_WORST_TIME;
>+  param.get_TB = no_fights_or_unknown;
>+  param.get_EC = sea_move;
>+  param.get_MC = combined_land_sea_move;
>+
>+  search_map = pf_create_map(&param);
>+
>+  pf_iterator(search_map, pos) {


>+    int radius = (is_ocean(map_get_tile(pos.x, pos.y)->terrain) ? 1 : 0);

It looks like only ocean tiles are searched. Do we want to look in
cities as well?


>+    if (pos.turn + pos.total_EC/PF_TURN_FACTOR > best_turns) {
>+      /* Won't find anything better */
>+      /* FIXME: This condition is somewhat dodgy */
>+      break;
>+    }
>+    
>+    square_iterate(pos.x, pos.y, radius, x, y) {
>+      struct tile *ptile = map_get_tile(x, y);
>+      
>+      unit_list_iterate(ptile->units, aunit) {
>+        if (is_ground_units_transport(aunit)
>+            && (aunit->ai.passenger == FERRY_AVAILABLE
>+                || aunit->ai.passenger == punit->id)) {
>+          /* Turns for the unit to get to rendezvous pnt */
>+          int u_turns = pos.turn;
>+          /* Turns for the boat to get to the rendezvous pnt */
>+          int f_turns = ((pos.total_EC / PF_TURN_FACTOR * 16 
>+                          - aunit->moves_left) 
>+                         / unit_type(aunit)->move_rate);
>+          int turns = MAX(u_turns, f_turns);
>+          
>+          if (turns < best_turns) {
>+            UNIT_LOG(LOGLEVEL_FINDFERRY, punit, 
>+                     "Found a potential boat %s[%d](%d,%d)",
>+                     unit_type(aunit)->name, aunit->id, aunit->x,
aunit->y);
>+          if (path) {
>+            *path = pf_next_get_path(search_map);
>+          }
>+            best_turns = turns;
>+            best_id = aunit->id;
>+          }
>+        }
>+      } unit_list_iterate_end;
>+    } square_iterate_end;
>+  } pf_iterator_end;
>+  pf_destroy_map(search_map);
>+
>+  return best_id;
>+}

David Stewart




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