Index: ai/aiunit.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.c,v retrieving revision 1.163 diff -u -r1.163 aiunit.c --- ai/aiunit.c 2002/02/09 14:46:09 1.163 +++ ai/aiunit.c 2002/02/09 18:20:52 @@ -180,9 +180,8 @@ Explores unknown territory, finds huts. Returns whether there is any more territory to be explored. **************************************************************************/ -int ai_manage_explorer(struct unit *punit) +int ai_manage_explorer(struct player *pplayer, struct unit *punit) { - struct player *pplayer = unit_owner(punit); int x, y; /* is the position of the unit; updated inside the function */ int con; /* continent the unit is on */ struct city *pcity; @@ -192,6 +191,8 @@ int move_rate = unit_move_rate(punit); int range; + if (!punit->moves_left) return 0; /* can't do anything with no moves */ + if (unit_profits_of_watchtower(punit) && map_get_tile(punit->x, punit->y)->special & S_FORTRESS) range =get_watchtower_vision(punit); @@ -237,7 +238,7 @@ if (punit->moves_left) { if (punit->x == best_x && punit->y == best_y) { - return ai_manage_explorer(punit); + return ai_manage_explorer(pplayer, punit); } else { /* Something went wrong; fall through. This should almost never happen. */ if (punit->x != x || punit->y != y) @@ -337,7 +338,7 @@ handle_unit_activity_request(punit, ACTIVITY_IDLE); return 1; /* Something wrong; what to do but return? */ } else - return ai_manage_explorer(punit); + return ai_manage_explorer(pplayer, punit); } else { return 1; } @@ -1511,7 +1512,7 @@ if (find_nearest_friendly_port(punit)) do_unit_goto(punit, GOTO_MOVE_ANY, 0); } else { - ai_manage_explorer(punit); /* nothing else to do */ + ai_manage_explorer(pplayer, punit); /* nothing else to do */ /* you can still have some moves left here, but barbarians should not sit helplessly, but advance towards nearest known enemy city */ punit = find_unit_by_id(id); /* unit might die while exploring */ @@ -1674,7 +1675,7 @@ freelog(LOG_DEBUG, "Ferryboat %d@(%d,%d) stalling.", punit->id, punit->x, punit->y); if(is_barbarian(pplayer)) /* just in case */ - ai_manage_explorer(punit); + ai_manage_explorer(pplayer, punit); } return; } @@ -1740,7 +1741,7 @@ } } if (map_get_terrain(punit->x, punit->y) == T_OCEAN) /* thanks, Tony */ - ai_manage_explorer(punit); + ai_manage_explorer(pplayer, punit); return; } @@ -1753,6 +1754,8 @@ id = punit->id; + if (!punit->moves_left) return; /* can't do anything with no moves */ + if (punit->activity != ACTIVITY_IDLE) handle_unit_activity_request(punit, ACTIVITY_IDLE); @@ -1797,7 +1800,7 @@ handle_unit_activity_request(punit, ACTIVITY_PILLAGE); return; /* when you pillage, you have moves left, avoid later fortify */ case AIUNIT_EXPLORE: - ai_manage_explorer(punit); + ai_manage_explorer(pplayer, punit); break; default: abort(); @@ -1875,7 +1878,6 @@ return; } else if (unit_flag(punit, F_SETTLERS) ||unit_flag(punit, F_CITIES)) { - if (!punit->moves_left) return; /* can't do anything with no moves */ ai_manage_settler(pplayer, punit); return; } else if (unit_flag(punit, F_CARAVAN)) { @@ -1888,12 +1890,10 @@ ai_manage_ferryboat(pplayer, punit); return; } else if (is_military_unit(punit)) { - if (!punit->moves_left) return; /* can't do anything with no moves */ ai_manage_military(pplayer,punit); return; } else { - if (!punit->moves_left) return; /* can't do anything with no moves */ - ai_manage_explorer(punit); /* what else could this be? -- Syela */ + ai_manage_explorer(pplayer, punit); /* what else could this be? -- Syela */ return; } /* should never get here */ Index: ai/aiunit.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.h,v retrieving revision 1.27 diff -u -r1.27 aiunit.h --- ai/aiunit.h 2002/02/07 10:24:13 1.27 +++ ai/aiunit.h 2002/02/09 18:20:52 @@ -26,7 +26,7 @@ int look_for_charge(struct player *pplayer, struct unit *punit, struct unit **aunit, struct city **acity); -int ai_manage_explorer(struct unit *punit); +int ai_manage_explorer(struct player *pplayer, struct unit *punit); int find_something_to_kill(struct player *pplayer, struct unit *punit, int *x, int *y); Index: server/settlers.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/settlers.c,v retrieving revision 1.117 diff -u -r1.117 settlers.c --- server/settlers.c 2002/02/09 14:46:30 1.117 +++ server/settlers.c 2002/02/09 18:21:05 @@ -392,6 +392,7 @@ **************************************************************************/ void ai_manage_settler(struct player *pplayer, struct unit *punit) { + if (!punit->moves_left) return; /* can't do anything with no moves */ punit->ai.control = 1; if (punit->ai.ai_role == AIUNIT_NONE) /* if BUILD_CITY must remain BUILD_CITY */ punit->ai.ai_role = AIUNIT_AUTO_SETTLER; Index: server/unithand.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/unithand.c,v retrieving revision 1.210 diff -u -r1.210 unithand.c --- server/unithand.c 2002/02/09 14:46:32 1.210 +++ server/unithand.c 2002/02/09 18:21:10 @@ -1256,7 +1256,7 @@ case ACTIVITY_EXPLORE: if (punit->moves_left > 0) { int id = punit->id; - int more_to_explore = ai_manage_explorer(punit); + int more_to_explore = ai_manage_explorer(unit_owner(punit), punit); /* ai_manage_explorer sets the activity to idle, so we reset it */ if (more_to_explore && (punit = find_unit_by_id(id)) != NULL) { set_unit_activity(punit, ACTIVITY_EXPLORE); Index: server/unittools.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/unittools.c,v retrieving revision 1.151 diff -u -r1.151 unittools.c --- server/unittools.c 2002/02/09 14:46:32 1.151 +++ server/unittools.c 2002/02/09 18:21:19 @@ -803,7 +803,7 @@ } if (activity == ACTIVITY_EXPLORE) { - int more_to_explore = ai_manage_explorer(punit); + int more_to_explore = ai_manage_explorer(pplayer, punit); if (more_to_explore && player_find_unit_by_id(pplayer, id) != NULL) handle_unit_activity_request(punit, ACTIVITY_EXPLORE); else