Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2006:
[Freeciv-Dev] Re: (PR#18605) [Bugfix] auto-return fixes
Home

[Freeciv-Dev] Re: (PR#18605) [Bugfix] auto-return fixes

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] Re: (PR#18605) [Bugfix] auto-return fixes
From: "Marko Lindqvist" <cazfi74@xxxxxxxxx>
Date: Sun, 16 Jul 2006 12:14:21 -0700
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=18605 >


  New version for TRUNK.

  - Helper function is_unit_being_refueled() introduced and used
  - Fix problems with ai aicrafts at carrier



  - ML

diff -Nurd -X.diff_ignore freeciv/ai/aiair.c freeciv/ai/aiair.c
--- freeciv/ai/aiair.c  2006-07-16 18:47:33.750000000 +0300
+++ freeciv/ai/aiair.c  2006-07-16 21:58:32.343750000 +0300
@@ -292,8 +292,7 @@
 
   CHECK_UNIT(punit);
 
-  if (!is_airunit_refuel_point(punit->tile, 
-                              pplayer, punit->type, FALSE)) {
+  if (!is_unit_being_refueled(punit)) {
     /* We are out in the open, what shall we do? */
     struct tile *refuel_tile;
 
diff -Nurd -X.diff_ignore freeciv/server/unittools.c freeciv/server/unittools.c
--- freeciv/server/unittools.c  2006-07-16 18:50:56.578125000 +0300
+++ freeciv/server/unittools.c  2006-07-16 21:55:55.375000000 +0300
@@ -386,33 +386,45 @@
        * The problem is (again) that here we know too much. -- Zamar */
 
       if (punit->fuel == 1
-         && !is_airunit_refuel_point(punit->tile,
-                                     unit_owner(punit), punit->type, TRUE)) {
-       iterate_outward(punit->tile, punit->moves_left/3, itr_tile) {
-         if (is_airunit_refuel_point(itr_tile, unit_owner(punit),
-                                     punit->type, FALSE)
-             &&(air_can_move_between(punit->moves_left / 3, punit->tile,
-                                     itr_tile, unit_owner(punit)) >= 0)) {
-           punit->goto_tile = itr_tile;
-           set_unit_activity(punit, ACTIVITY_GOTO);
-           (void) do_unit_goto(punit, GOTO_MOVE_ANY, FALSE);
-           notify_player(pplayer, punit->tile, E_UNIT_ORDERS, 
-                            _("Your %s has returned to refuel."),
-                            unit_name(punit->type));
-           goto OUT;
-         }
-       } iterate_outward_end;
+          && !is_unit_being_refueled(punit)) {
+        struct unit *carrier;
+
+        carrier = find_transport_from_tile(punit, punit->tile);
+        if (carrier) {
+          put_unit_onto_transporter(punit, carrier);
+        } else {
+          iterate_outward(punit->tile, punit->moves_left / SINGLE_MOVE, 
itr_tile) {
+            if (is_airunit_refuel_point(itr_tile, unit_owner(punit),
+                                        punit->type, FALSE)
+                &&(air_can_move_between(punit->moves_left / SINGLE_MOVE, 
punit->tile,
+                                        itr_tile, unit_owner(punit)) >= 0)) {
+              punit->goto_tile = itr_tile;
+              set_unit_activity(punit, ACTIVITY_GOTO);
+              (void) do_unit_goto(punit, GOTO_MOVE_ANY, FALSE);
+
+              if (!punit->tile->city
+                  && !contains_special(punit->tile->special, S_AIRBASE)) {
+                carrier = find_transport_from_tile(punit, punit->tile);
+                if (carrier) {
+                  put_unit_onto_transporter(punit, carrier);
+                }
+              }
+
+              notify_player(pplayer, punit->tile, E_UNIT_ORDERS, 
+                            _("Your %s has returned to refuel."),
+                            unit_name(punit->type));
+              break;
+            }
+          } iterate_outward_end;
+        }
       }
-    OUT:
 
       /* 6) Update fuel */
       punit->fuel--;
 
       /* 7) Automatically refuel air units in cities, airbases, and
        *    transporters (carriers). */
-      if (tile_get_city(punit->tile)
-         || tile_has_special(punit->tile, S_AIRBASE)
-         || punit->transported_by != -1) {
+      if (is_unit_being_refueled(punit)) {
        punit->fuel=unit_type(punit)->fuel;
       }
     }
@@ -1170,6 +1182,16 @@
 }
 
 /**************************************************************************
+ Is unit being refueled in its current position
+**************************************************************************/
+bool is_unit_being_refueled(const struct unit *punit)
+{
+  return (punit->transported_by != -1                   /* Carrier */
+          || punit->tile->city                          /* City    */
+          || tile_has_special(punit->tile, S_AIRBASE)); /* Airbase */
+}
+
+/**************************************************************************
 ...
 **************************************************************************/
 bool is_airunit_refuel_point(struct tile *ptile, struct player *pplayer,
diff -Nurd -X.diff_ignore freeciv/server/unittools.h freeciv/server/unittools.h
--- freeciv/server/unittools.h  2006-07-16 18:50:56.640625000 +0300
+++ freeciv/server/unittools.h  2006-07-16 21:47:06.046875000 +0300
@@ -27,6 +27,7 @@
                      bool bombard);
 
 /* move check related */
+bool is_unit_being_refueled(const struct unit *punit);
 bool is_airunit_refuel_point(struct tile *ptile, struct player *pplayer,
                             const struct unit_type *punittype,
                             bool unit_is_on_tile);

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