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: Sat, 15 Jul 2006 06:32:45 -0700
Reply-to: bugs@xxxxxxxxxxx

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

Jason Dorje Short wrote:
> 
> Marko Lindqvist wrote:
>>
>>   These fix several airplane auto-return problems
>>
>>   - Don't go for another refuel point if we are loaded to carrier.
>>   - If we are above free carrier: land
>>   - Once we reach free carrier: land
>>
>>   Untested
> 
> I'm pretty sure the use of "3" in this code should be replaced with 
> SINGLE_MOVE.

  Done.
  This is still not right in TRUNK, though. It should check for 
UCF_TERRAIN_SPEED. I'll leave fixing that to later date.


  Still untested


  - ML


diff -Nurd -X.diff_ignore freeciv/server/unittools.c freeciv/server/unittools.c
--- freeciv/server/unittools.c  2006-07-14 03:26:21.171875000 +0300
+++ freeciv/server/unittools.c  2006-07-15 16:24:54.906250000 +0300
@@ -386,24 +386,55 @@
        * 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;
+          && punit->transported_by == -1
+          && !punit->tile->city
+          && !contains_special(punit->tile->special, S_AIRBASE)) {
+        bool carrier_found = FALSE;
+
+        unit_list_iterate(punit->tile->units, carrier) {
+          if ((unit_flag(carrier, F_CARRIER)
+               || (unit_flag(punit, F_MISSILE)
+                   && unit_flag(carrier, F_MISSILE_CARRIER)))
+              && get_transporter_capacity(carrier) >
+                 get_transporter_occupancy(carrier)) {
+            put_unit_onto_transporter(punit, carrier);
+            carrier_found = TRUE;
+            break;
+          }
+        } unit_list_iterate_end;
+       
+        if (!carrier_found) {
+          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)) {
+                unit_list_iterate(punit->tile->units, carrier) {
+                  if ((unit_flag(carrier, F_CARRIER)
+                       || (unit_flag(punit, F_MISSILE)
+                           && unit_flag(carrier, F_MISSILE_CARRIER)))
+                      && get_transporter_capacity(carrier) >
+                         get_transporter_occupancy(carrier)) {
+                    put_unit_onto_transporter(punit, carrier);
+                    break;
+                  }
+                } unit_list_iterate_end;
+              }
+
+              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--;
diff -Nurd -X.diff_ignore freeciv/server/unittools.c freeciv/server/unittools.c
--- freeciv/server/unittools.c  2006-07-15 16:14:00.781250000 +0300
+++ freeciv/server/unittools.c  2006-07-15 16:20:33.234375000 +0300
@@ -386,24 +386,40 @@
        * 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;
+          && punit->transported_by == -1
+          && !punit->tile->city
+          && !contains_special(punit->tile->special, S_AIRBASE)) {
+        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--;

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