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

On 1/14/07, Marko Lindqvist <[EMAIL PROTECTED]> wrote:
>
> <URL: http://bugs.freeciv.org/Ticket/Display.html?id=18441 >
>
> On 7/16/06, Per I. Mathisen <[EMAIL PROTECTED]> wrote:
> >
> > It should be almost trivial to replace these two uses of do_unit_goto()
> > and then remove both that function and find_the_shortest_path().
> >
> > Attached is an untested proof-of-concept patch for the air return part.
>
>  Patch updated against svn. Still untested.

 - Use ai_follow_path() instead of own implementation
 - Do not access unit if it has died moving

 Still untested


 - ML

diff -Nurd -X.diff_ignore freeciv/server/unittools.c freeciv/server/unittools.c
--- freeciv/server/unittools.c	2007-01-14 21:35:41.000000000 +0200
+++ freeciv/server/unittools.c	2007-01-15 00:29:44.000000000 +0200
@@ -40,6 +40,9 @@
 #include "unit.h"
 #include "unitlist.h"
 
+#include "path_finding.h"
+#include "pf_tools.h"
+
 #include "barbarian.h"
 #include "citytools.h"
 #include "cityturn.h"
@@ -393,31 +396,69 @@
         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)) {
-	      /* Client orders may already be running for this unit - if so
-	       * we free them before engaging server goto. */
+          bool alive;
+
+          struct pf_map *map;
+          struct pf_parameter parameter;
+
+          pft_fill_unit_parameter(&parameter, punit);
+          map = pf_create_map(&parameter);
+
+          pf_iterator(map, pos) {
+            if (pos.total_MC > punit->moves_left) {
+              /* Too far */
+              break;
+            }
+
+            if (is_airunit_refuel_point(pos.tile, pplayer, punit->type, FALSE)) {
+
+              struct pf_path *path;
+              int id = punit->id;
+
+              /* Client orders may be running for this unit - if so
+               * we free them before engaging goto. */
               free_unit_orders(punit);
-              punit->goto_tile = itr_tile;
-              set_unit_activity(punit, ACTIVITY_GOTO);
-              (void) do_unit_goto(punit, GOTO_MOVE_ANY, FALSE);
 
-              if (!is_unit_being_refueled(punit)) {
-                carrier = find_transport_from_tile(punit, punit->tile);
-                if (carrier) {
-                  put_unit_onto_transporter(punit, carrier);
-                }
+              path = pf_get_path(map, pos.tile);
+
+	      alive = ai_follow_path(punit, path, pos.tile);
+
+	      if (!alive) {
+                freelog(LOG_ERROR, "rescue plane: unit %d died enroute!", id);
+              } else if (!same_pos(punit->tile, pos.tile)) {
+                  /* Something odd happened */
+                  freelog(LOG_ERROR,
+                          "rescue plane: unit %d could not move to refuel point!",
+                          punit->id);
               }
 
-              notify_player(pplayer, punit->tile, E_UNIT_ORDERS, 
-                            _("Your %s has returned to refuel."),
-                            unit_name(punit->type));
+              if (alive) {
+                /* Clear activity. Unit info will be sent in the end of
+	         * the function. */
+                handle_unit_activity_request(punit, ACTIVITY_IDLE);
+                punit->goto_tile = NULL;
+
+                if (!is_unit_being_refueled(punit)) {
+                  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));
+	      }
+              pf_destroy_path(path);
               break;
             }
-          } iterate_outward_end;
+          } pf_iterator_end;
+          pf_destroy_map(map);
+
+          if (!alive) {
+            /* Unit died trying to move to refuel point. */
+            return;
+	  }
         }
       }
 
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to