Index: ai/aitools.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/ai/aitools.c,v retrieving revision 1.57 diff -u -r1.57 aitools.c --- ai/aitools.c 2002/09/28 21:58:15 1.57 +++ ai/aitools.c 2002/10/30 22:10:22 @@ -48,7 +48,7 @@ charge->ai.bodyguard = BODYGUARD_NONE; } punit->ai.charge = BODYGUARD_NONE; - punit->ai.ai_role = task; + ai_unit_set_role(punit, task, -1, -1); } /************************************************************************** Index: ai/aiunit.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.c,v retrieving revision 1.222 diff -u -r1.222 aiunit.c --- ai/aiunit.c 2002/10/28 17:06:12 1.222 +++ ai/aiunit.c 2002/10/30 22:10:28 @@ -1353,7 +1353,7 @@ assert(player_find_unit_by_id(pplayer, id) != NULL); /* in case we need to change */ - punit->ai.ai_role = AIUNIT_NONE; /* this can't be right -- Per */ + ai_unit_set_role(punit, AIUNIT_NONE, -1, -1); /* this can't be right -- Per */ if (!same_pos(punit->x, punit->y, x, y)) { return 1; /* moved */ @@ -1492,12 +1492,12 @@ acity = find_city_by_id(punit->ai.charge); /* another crazy duct-tape sanity check to ensure we don't do something stupid */ - if ((aunit && aunit->ai.bodyguard != BODYGUARD_NONE - && unit_vulnerability_virtual(punit) > - unit_vulnerability_virtual(aunit)) || - (acity && acity->owner == punit->owner && acity->ai.urgency != 0 && - acity->ai.danger > assess_defense_quadratic(acity))) { - punit->ai.ai_role = AIUNIT_ESCORT; /* do not use ai_unit_new_role() */ + if ((aunit && aunit->ai.bodyguard != BODYGUARD_NONE + && unit_vulnerability_virtual(punit) > + unit_vulnerability_virtual(aunit)) || + (acity && acity->owner == punit->owner && acity->ai.urgency != 0 && + acity->ai.danger > assess_defense_quadratic(acity))) { + ai_unit_set_role(punit, AIUNIT_ESCORT, -1, -1); /* do not use ai_unit_new_role() */ return; } else { ai_unit_new_role(punit, AIUNIT_NONE); @@ -2255,7 +2255,8 @@ if (punit->activity != ACTIVITY_IDLE) handle_unit_activity_request(punit, ACTIVITY_IDLE); - punit->ai.ai_role = AIUNIT_NONE; /* this can't be right -- Per */ + ai_unit_set_role(punit, AIUNIT_NONE, -1, -1); /* this can't be right -- Per */ + /* 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 */ ai_military_findjob(pplayer, punit); @@ -2797,4 +2798,25 @@ } unit_type_iterate_end; simple_ai_types[i] = U_LAST; +} + +/************************************************************************* + Wrapper to take care of add_city_from_minimap, + remove_city_from_minimap. new_role_target_x and new_role_target_y + are only used if AIUNIT_BUILD_CITY is specified. +**************************************************************************/ +void ai_unit_set_role(struct unit *punit, enum ai_unit_task role, + int new_role_target_x, int new_role_target_y) +{ + 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); + } + + punit->ai.ai_role = role; + + if (punit->ai.ai_role == AIUNIT_BUILD_CITY) { + assert(is_normal_map_pos(new_role_target_x, new_role_target_y)); + add_city_to_minimap(new_role_target_x, new_role_target_y); + } } Index: ai/aiunit.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.h,v retrieving revision 1.34 diff -u -r1.34 aiunit.h --- ai/aiunit.h 2002/03/21 20:57:29 1.34 +++ ai/aiunit.h 2002/10/30 22:10:29 @@ -64,6 +64,8 @@ void ai_choose_role_unit(struct player *pplayer, struct city *pcity, struct ai_choice *choice, int role, int want); void update_simple_ai_types(void); +void ai_unit_set_role(struct unit *punit, enum ai_unit_task role, + int new_role_target_x, int new_role_target_y); #define simple_ai_unit_type_iterate(m_i) \ { \ Index: server/settlers.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/settlers.c,v retrieving revision 1.147 diff -u -r1.147 settlers.c --- server/settlers.c 2002/10/30 21:19:41 1.147 +++ server/settlers.c 2002/10/30 22:10:36 @@ -427,7 +427,7 @@ punit->ai.control = TRUE; /* if BUILD_CITY must remain BUILD_CITY, otherwise turn into autosettler */ if (punit->ai.ai_role == AIUNIT_NONE) { - punit->ai.ai_role = AIUNIT_AUTO_SETTLER; + ai_unit_set_role(punit, AIUNIT_AUTO_SETTLER, -1, -1); } return; } @@ -915,10 +915,8 @@ generate_warmap(mycity, punit); - if (punit->ai.ai_role == AIUNIT_BUILD_CITY) { - remove_city_from_minimap(punit->goto_dest_x, punit->goto_dest_y); - } - punit->ai.ai_role = AIUNIT_AUTO_SETTLER; /* here and not before! -- Syela */ + ai_unit_set_role(punit, AIUNIT_AUTO_SETTLER, -1, -1); + /* hope 11 is far enough -- Syela */ square_iterate(punit->x, punit->y, 11, x, y) { int near = real_map_distance(punit->x, punit->y, x, y); @@ -1298,13 +1296,10 @@ } /* If we intent on building a city then reserve the square. */ - if (unit_flag(punit, F_CITIES) && - best_act == ACTIVITY_UNKNOWN /* flag */) { - punit->ai.ai_role = AIUNIT_BUILD_CITY; - /* FIXME: is the unit taken off the minimap if it dies? */ - add_city_to_minimap(gx, gy); + if (unit_flag(punit, F_CITIES) && best_act == ACTIVITY_UNKNOWN /* flag */ ) { + ai_unit_set_role(punit, AIUNIT_BUILD_CITY, gx, gy); } else { - punit->ai.ai_role = AIUNIT_AUTO_SETTLER; + ai_unit_set_role(punit, AIUNIT_AUTO_SETTLER, -1, -1); } /* We've now worked out what to do; go to it! */ Index: server/unittools.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/unittools.c,v retrieving revision 1.185 diff -u -r1.185 unittools.c --- server/unittools.c 2002/09/28 23:00:51 1.185 +++ server/unittools.c 2002/10/30 22:10:42 @@ -1770,11 +1770,8 @@ are built, so that no two settlers head towards the same city spot, we need to ensure this reservation is cleared should the settler die on the way. */ - if (unit_owner(punit)->ai.control - && punit->ai.ai_role == AIUNIT_AUTO_SETTLER) { - if (normalize_map_pos(&punit->goto_dest_x, &punit->goto_dest_y)) { - remove_city_from_minimap(punit->goto_dest_x, punit->goto_dest_y); - } + if (unit_owner(punit)->ai.control) { + ai_unit_set_role(punit, AIUNIT_NONE, -1, -1); } remove_unit_sight_points(punit);