Index: ai/aitools.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/ai/aitools.c,v retrieving revision 1.65 diff -u -r1.65 aitools.c --- ai/aitools.c 9 Dec 2002 01:50:09 -0000 1.65 +++ ai/aitools.c 9 Dec 2002 16:42:16 -0000 @@ -159,6 +159,11 @@ { struct unit *charge = find_unit_by_id(punit->ai.charge); + if (punit->activity == ACTIVITY_GOTO) { + /* It would indicate we're going somewhere otherwise */ + handle_unit_activity_request(punit, ACTIVITY_IDLE); + } + if (punit->ai.ai_role == AIUNIT_BUILD_CITY) { assert(is_normal_map_pos(punit->goto_dest_x, punit->goto_dest_y)); remove_city_from_minimap(punit->goto_dest_x, punit->goto_dest_y); @@ -237,7 +242,6 @@ handle_unit_activity_request(bodyguard, ACTIVITY_IDLE); (void) ai_unit_move(bodyguard, x, y); - handle_unit_activity_request(bodyguard, ACTIVITY_FORTIFYING); } /************************************************************************** @@ -279,10 +283,7 @@ pmove.x = x; pmove.y = y; pmove.unid = punit->id; - if (punit->activity != ACTIVITY_IDLE - && punit->activity != ACTIVITY_GOTO) { - handle_unit_activity_request(punit, ACTIVITY_IDLE); - } + handle_unit_activity_request(punit, ACTIVITY_IDLE); handle_move_unit(unit_owner(punit), &pmove); if (find_unit_by_id(sanity) && same_pos(x, y, punit->x, punit->y)) { @@ -346,6 +347,7 @@ pmove.x = x; pmove.y = y; pmove.unid = punit->id; + handle_unit_activity_request(punit, ACTIVITY_IDLE); handle_move_unit(unit_owner(punit), &pmove); /* handle the results */ Index: ai/aiunit.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.c,v retrieving revision 1.237 diff -u -r1.237 aiunit.c --- ai/aiunit.c 9 Dec 2002 15:51:42 -0000 1.237 +++ ai/aiunit.c 9 Dec 2002 16:42:16 -0000 @@ -288,12 +288,6 @@ range = unit_type(punit)->vision_range; } - /* Idle unit */ - - if (punit->activity != ACTIVITY_IDLE) { - handle_unit_activity_request(punit, ACTIVITY_IDLE); - } - /* Localize the unit */ if (is_ground_unit(punit)) { @@ -518,7 +512,9 @@ return ai_manage_explorer(punit); } else { /* Something went wrong. What to do but return? */ - handle_unit_activity_request(punit, ACTIVITY_IDLE); + if (punit->activity == ACTIVITY_EXPLORE) { + handle_unit_activity_request(punit, ACTIVITY_IDLE); + } return FALSE; } @@ -532,7 +528,9 @@ /* We have nothing to explore, so we can go idle. */ UNIT_LOG(LOG_DEBUG, punit, "failed to explore more"); - handle_unit_activity_request(punit, ACTIVITY_IDLE); + if (punit->activity == ACTIVITY_EXPLORE) { + handle_unit_activity_request(punit, ACTIVITY_IDLE); + } /* * PART 4: Go home @@ -1065,9 +1063,7 @@ ai_unit_attack(punit, x, y); punit = find_unit_by_id(id); } - if (count <= 0) { - UNIT_LOG(LOG_ERROR, punit, "infinite loop averted"); - } + assert(count >= 0); return punit; } @@ -1261,29 +1257,31 @@ freelog(LOG_DEBUG, "We have FOUND BOAT, %d ABOARD %d@(%d,%d)->(%d, %d).", punit->id, ferryboat->id, punit->x, punit->y, dest_x, dest_y); - set_unit_activity(punit, ACTIVITY_SENTRY); /* kinda cheating -- Syela */ + handle_unit_activity_request(punit, ACTIVITY_SENTRY); ferryboat->ai.passenger = punit->id; /* the code that worked for settlers wasn't good for piles of cannons */ if (find_beachhead(punit, dest_x, dest_y, &ferryboat->goto_dest_x, &ferryboat->goto_dest_y) != 0) { punit->goto_dest_x = dest_x; punit->goto_dest_y = dest_y; - set_unit_activity(punit, ACTIVITY_SENTRY); /* anything but GOTO!! */ + handle_unit_activity_request(punit, ACTIVITY_SENTRY); if (ground_unit_transporter_capacity(punit->x, punit->y, pplayer) <= 0) { freelog(LOG_DEBUG, "All aboard!"); /* perhaps this should only require two passengers */ unit_list_iterate(ptile->units, mypass) { if (mypass->ai.ferryboat == ferryboat->id) { - set_unit_activity(mypass, ACTIVITY_SENTRY); + handle_unit_activity_request(mypass, ACTIVITY_SENTRY); def = unit_list_find(&ptile->units, mypass->ai.bodyguard); - if (def) set_unit_activity(def, ACTIVITY_SENTRY); + if (def) { + handle_unit_activity_request(def, ACTIVITY_SENTRY); + } } } unit_list_iterate_end; /* passengers are safely stowed away */ if (!ai_unit_goto(ferryboat, dest_x, dest_y)) { return -1; /* died */ } - set_unit_activity(punit, ACTIVITY_IDLE); + handle_unit_activity_request(punit, ACTIVITY_IDLE); } /* else wait, we can GOTO later. */ } } @@ -1573,8 +1571,6 @@ UNIT_LOG(LOG_DEBUG, punit, "GOHOME"); (void) ai_unit_goto(punit, pcity->x, pcity->y); } - } else { - handle_unit_activity_request(punit, ACTIVITY_FORTIFYING); } } @@ -1960,11 +1956,6 @@ int ct = 10; struct city *pcity = NULL; - assert(punit != NULL); - if (punit->activity == ACTIVITY_GOTO) { - return; - } - /* Main attack loop */ do { /* First find easy adjacent enemies; 2 is better than pillage */ @@ -2068,8 +2059,6 @@ struct packet_unit_request req; int tradeval, best_city = -1, best=0; - if (punit->activity != ACTIVITY_IDLE) - return; if (punit->ai.ai_role == AIUNIT_NONE) { if ((pcity = wonder_on_continent(pplayer, map_get_continent(punit->x, punit->y))) @@ -2160,8 +2149,10 @@ pcity->ai.invasion, aunit->ai.bodyguard); } n++; - set_unit_activity(aunit, ACTIVITY_SENTRY); - if (bodyguard) set_unit_activity(bodyguard, ACTIVITY_SENTRY); + handle_unit_activity_request(aunit, ACTIVITY_SENTRY); + if (bodyguard) { + handle_unit_activity_request(bodyguard, ACTIVITY_SENTRY); + } } } unit_list_iterate_end; @@ -2206,7 +2197,7 @@ /* ok, not carrying anyone, even the ferryman */ punit->ai.passenger = 0; UNIT_LOG(LOG_DEBUG, punit, "Ferryboat is lonely."); - set_unit_activity(punit, ACTIVITY_IDLE); + handle_unit_activity_request(punit, ACTIVITY_IDLE); punit->goto_dest_x = 0; /* FIXME: -1 */ punit->goto_dest_y = 0; /* FIXME: -1 */ @@ -2325,9 +2316,6 @@ static void ai_manage_military(struct player *pplayer, struct unit *punit) { int id = punit->id; - - if (punit->activity != ACTIVITY_IDLE) - handle_unit_activity_request(punit, ACTIVITY_IDLE); /* was getting a bad bug where a settlers caused a defender to leave home */ /* and then all other supported units went on DEFEND_HOME/goto */