Index: ai/aiunit.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.c,v retrieving revision 1.295 diff -u -r1.295 aiunit.c --- ai/aiunit.c 25 Sep 2003 20:11:12 -0000 1.295 +++ ai/aiunit.c 27 Sep 2003 11:17:54 -0000 @@ -1069,45 +1069,6 @@ } /************************************************************************* - This is a function to execute paths returned by the path-finding engine. - It is analogous to goto_route_execute, only much simpler. - - Weuse ai_unit_attack which means "move if target unoccupied, attack - otherwise" and also brings our bodyguard along. -*************************************************************************/ -bool ai_unit_execute_path(struct unit *punit, struct pf_path *path) -{ - int i; - - /* We start with i = 1 for i = 0 is our present position */ - for (i = 1; i < path->length; i++) { - int x = path->positions[i].x, y = path->positions[i].y; - bool result; - - /* We use ai_unit_move() for everything but the last step - * of the way so that we abort if unexpected opposition - * shows up. Any enemy on the target tile is expected to - * be our target and any attack there intentional. */ - if (i == path->length) { - result = ai_unit_attack(punit, x, y); - } else { - result = ai_unit_move(punit, x, y); - } - if (!result) { - /* Died... */ - return FALSE; - } - - if (!same_pos(punit->x, punit->y, x, y)) { - /* Stopped (or maybe fought) */ - return TRUE; - } - } - - return TRUE; -} - -/************************************************************************* Find and kill anything reachable within this turn and worth more than the relevant of the given thresholds until we have run out of juicy targets or movement. The first threshold is for attacking which will Index: ai/aiunit.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.h,v retrieving revision 1.48 diff -u -r1.48 aiunit.h --- ai/aiunit.h 25 Sep 2003 20:11:12 -0000 1.48 +++ ai/aiunit.h 27 Sep 2003 11:17:54 -0000 @@ -46,7 +46,6 @@ extern Unit_Type_id simple_ai_types[U_LAST]; -bool ai_unit_execute_path(struct unit *punit, struct pf_path *path); void ai_manage_units(struct player *pplayer); int could_unit_move_to_tile(struct unit *punit, int dest_x, int dest_y); int look_for_charge(struct player *pplayer, struct unit *punit, Index: ai/aitools.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/ai/aitools.c,v retrieving revision 1.89 diff -u -r1.89 aitools.c --- ai/aitools.c 25 Sep 2003 17:51:33 -0000 1.89 +++ ai/aitools.c 27 Sep 2003 11:17:54 -0000 @@ -30,6 +30,9 @@ #include "shared.h" #include "unit.h" +#include "path_finding.h" +#include "pf_tools.h" + #include "airgoto.h" #include "barbarian.h" #include "citytools.h" @@ -88,6 +91,47 @@ || pplayer->diplstates[aplayer->player_no].has_reason_to_cancel || ai->diplomacy.acceptable_reputation > aplayer->reputation || adip->is_allied_with_enemy); +} + +/************************************************************************* + This is a function to execute paths returned by the path-finding engine. + It is analogous to goto_route_execute, only much simpler. + + We use ai_unit_attack which means "move if target unoccupied, attack + otherwise" and also brings our bodyguard along. +*************************************************************************/ +bool ai_unit_execute_path(struct unit *punit, struct pf_path *path) +{ + int i; + + /* We start with i = 1 for i = 0 is our present position */ + for (i = 1; i < path->length; i++) { + int x = path->positions[i].x, y = path->positions[i].y; + bool result; + int id = punit->id; + + /* We use ai_unit_move() for everything but the last step + * of the way so that we abort if unexpected opposition + * shows up. Any enemy on the target tile is expected to + * be our target and any attack there intentional. */ + if (i == path->length - 1) { + result = ai_unit_attack(punit, x, y); + } else { + ai_unit_move(punit, x, y); + result = (punit = find_unit_by_id(id)); + } + if (!result) { + /* Died... */ + return FALSE; + } + + if (!same_pos(punit->x, punit->y, x, y)) { + /* Stopped (or maybe fought) */ + return TRUE; + } + } + + return TRUE; } /************************************************************************** Index: ai/aitools.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/ai/aitools.h,v retrieving revision 1.38 diff -u -r1.38 aitools.h --- ai/aitools.h 5 May 2003 12:41:39 -0000 1.38 +++ ai/aitools.h 27 Sep 2003 11:17:54 -0000 @@ -21,6 +21,7 @@ struct city; struct government; struct player; +struct pf_path; #ifdef DEBUG #define CHECK_UNIT(punit) \ @@ -41,6 +42,7 @@ int value, int delay, int build_cost); int stack_cost(struct unit *pdef); +bool ai_unit_execute_path(struct unit *punit, struct pf_path *path); bool ai_unit_gothere(struct unit *punit); bool ai_unit_goto(struct unit *punit, int x, int y); void ai_unit_new_role(struct unit *punit, enum ai_unit_task task, int x, int y);