Index: server/settlers.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/settlers.c,v retrieving revision 1.146 diff -u -r1.146 settlers.c --- server/settlers.c 2002/09/27 12:32:47 1.146 +++ server/settlers.c 2002/10/28 16:44:07 @@ -31,8 +31,9 @@ #include "unittools.h" #include "aicity.h" -#include "aiunit.h" #include "aidata.h" +#include "ailog.h" +#include "aiunit.h" #include "settlers.h" @@ -919,7 +920,9 @@ 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 */ +/* here and not before! -- Syela + what kind of insanity is this?? -- Per + punit->ai.ai_role = AIUNIT_AUTO_SETTLER; */ /* 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); @@ -1159,7 +1162,7 @@ pcity->ai.railroad[i][j], pcity->ai.detox[i][j], pcity->ai.derad[i][j]); #endif - } /* end if we are a legal destination */ + } } city_map_iterate_outwards_end; } city_map_checked_iterate_end; @@ -1233,6 +1236,32 @@ } /************************************************************************** + Move settler around and maybe build a city. +**************************************************************************/ +static void auto_settler_move(struct player *pplayer, struct unit *punit, + int act) +{ + int x = punit->goto_dest_x; + int y = punit->goto_dest_y; + + if (is_enemy_unit_tile(map_get_tile(x, y), unit_owner(punit))) { + return; + } else if (!same_pos(x, y, punit->x, punit->y)) { + do_unit_goto(punit, GOTO_MOVE_ANY, FALSE); + } + + if (same_pos(x, y, punit->x, punit->y)) { + if (punit->ai.ai_role == AIUNIT_BUILD_CITY) { + remove_city_from_minimap(punit->goto_dest_x, punit->goto_dest_y); + (void) ai_do_build_city(pplayer, punit); + } else if (punit->ai.ai_role == AIUNIT_AUTO_SETTLER) { + set_unit_activity(punit, act); + send_unit_info(NULL, punit); + } + } +} + +/************************************************************************** find some work for the settler **************************************************************************/ static void auto_settler_findwork(struct player *pplayer, struct unit *punit) @@ -1241,16 +1270,28 @@ int best_newv = 0; /* newv of best target so far, all cities */ int best_act = 0; /* ACTIVITY_ of best target so far */ struct unit *ferryboat = NULL; /* if non-null, boatid boat at unit's x,y */ + int id = punit->id; + bool build_city = FALSE; + + if (!punit->ai.control || punit->moves_left <= 0) { + return; + } #ifdef DEBUG int save_newv; #endif + auto_settler_move(pplayer, punit, ACTIVITY_IDLE); + if (!(punit = find_unit_by_id(id)) || punit->moves_left <= 0) { + /* dead or exhausted */ + return; + } + /* First find the best square to upgrade, * results in: gx, gy, best_newv, best_act */ if (unit_flag(punit, F_SETTLERS)) { - best_newv = evaluate_improvements(punit, &best_act,&gx, &gy); + best_newv = evaluate_improvements(punit, &best_act, &gx, &gy); } /* Found the best square to upgrade, have gx, gy, best_newv, best_act */ @@ -1270,7 +1311,8 @@ if (want > best_newv) { best_newv = want; - best_act = ACTIVITY_UNKNOWN; + best_act = ACTIVITY_IDLE; + build_city = TRUE; gx = nx; gy = ny; } @@ -1296,10 +1338,8 @@ } /* If we intent on building a city then reserve the square. */ - if (unit_flag(punit, F_CITIES) && - best_act == ACTIVITY_UNKNOWN /* flag */) { + if (build_city) { punit->ai.ai_role = AIUNIT_BUILD_CITY; - /* FIXME: is the unit taken off the minimap if it dies? */ add_city_to_minimap(gx, gy); } else { punit->ai.ai_role = AIUNIT_AUTO_SETTLER; @@ -1307,6 +1347,8 @@ /* We've now worked out what to do; go to it! */ if (gx != -1 && gy != -1) { + punit->goto_dest_x = gx; + punit->goto_dest_y = gy; bool survived = ai_gothere(punit, gx, gy, ferryboat); if (!survived) return; @@ -1317,21 +1359,8 @@ punit->ai.control = FALSE; } - /* If we are at the destination then do the activity. */ - if (punit->ai.control - && punit->moves_left > 0 - && punit->activity == ACTIVITY_IDLE) { - if (same_pos(gx, gy, punit->x, punit->y)) { - if (best_act == ACTIVITY_UNKNOWN) { - remove_city_from_minimap(gx, gy); /* yeah, I know. -- Syela */ - (void) ai_do_build_city(pplayer, punit); - return; - } - set_unit_activity(punit, best_act); - send_unit_info(NULL, punit); - return; - } - } + /* We may still not have arrived! */ + auto_settler_move(pplayer, punit, best_act); } /**************************************************************************