<URL: http://bugs.freeciv.org/Ticket/Display.html?id=18441 >
On 7/16/06, Per I. Mathisen <[EMAIL PROTECTED]> wrote: > > On Tue, 11 Jul 2006, Marko Lindqvist wrote: > >> Also, there is still two users for gotohand.c:do_unit_goto(). > >> grep -r do_unit_goto server/*.c > > > > do_unit_goto() is only place that needs find_the_shortest_path(). > > find_the_shortest_path() implements its own warmap filling method > > distinct from generate_warmap(), in theory requiring maintenance > > separately from generate_warmap() (as find_the_shortest_path() is not > > fatally broken, I'm not fixing it). Getting rid of > > find_the_shortest_path() would be good. > > 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. - 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-14 23:26:51.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,17 +396,60 @@ 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. */ + + struct pf_map *map; + struct pf_parameter parameter; + + pft_fill_unit_parameter(¶meter, punit); + map = pf_create_map(¶meter); + + 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 i; + + /* 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; + + punit->goto_tile = pos.tile; set_unit_activity(punit, ACTIVITY_GOTO); - (void) do_unit_goto(punit, GOTO_MOVE_ANY, FALSE); + path = pf_get_path(map, pos.tile); + + /* We start with i = 1 for i = 0 is our present position */ + for (i = 1; i < path->length; i++) { + struct tile *ptile = path->positions[i].tile; + int id = punit->id; + + if (same_pos(punit->tile, ptile)) { + freelog(LOG_ERROR, "rescue plane: unit %d waiting this turn?!", punit->id); + break; + } + + (void) handle_unit_move_request(punit, ptile, FALSE, TRUE); + + if (!find_unit_by_id(id)) { + freelog(LOG_ERROR, "rescue plane: unit %d died enroute?!", id); + break; + } + + if (!same_pos(punit->tile, ptile) || punit->moves_left <= 0) { + /* Something odd happened */ + freelog(LOG_ERROR, "rescue plane: unit %d could not move?!", punit->id); + break; + } + } + + /* 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); @@ -415,9 +461,11 @@ 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); } }
_______________________________________________ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev