Index: server/settlers.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/settlers.c,v retrieving revision 1.154 diff -u -r1.154 settlers.c --- server/settlers.c 4 Dec 2002 13:34:27 -0000 1.154 +++ server/settlers.c 9 Dec 2002 21:55:33 -0000 @@ -52,8 +52,6 @@ static enemy_mask enemies[MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS]; static void auto_settlers_player(struct player *pplayer); -static bool is_already_assigned(struct unit *myunit, struct player *pplayer, - int x, int y); static int city_desirability(struct player *pplayer, int x, int y); /************************************************************************** @@ -282,8 +280,7 @@ if (trade[i][j] != 0) trade[i][j] += ctrade; else if (road[i][j] != 0) road[i][j] += ctrade; } - } - city_map_checked_iterate_end; + } city_map_checked_iterate_end; if (pcity) { /* quick-n-dirty immigration routine -- Syela */ n = pcity->size; @@ -440,28 +437,6 @@ } /************************************************************************** - return 1 if there is already a unit on this square or one destined for it - (via goto) -**************************************************************************/ -static bool is_already_assigned(struct unit *myunit, struct player *pplayer, - int x, int y) -{ - if (same_pos(myunit->x, myunit->y, x, y) || - same_pos(myunit->goto_dest_x, myunit->goto_dest_y, x, y)) { -/* I'm still not sure this is exactly right -- Syela */ - unit_list_iterate(map_get_tile(x, y)->units, punit) - if (myunit==punit) continue; - if (!pplayers_allied(unit_owner(punit), pplayer)) - return TRUE; /* oops, tile is occupied! */ - if (unit_flag(punit, F_SETTLERS) && unit_flag(myunit, F_SETTLERS)) - return TRUE; - unit_list_iterate_end; - return FALSE; - } - return TEST_BIT(map_get_tile(x, y)->assigned, pplayer->player_no); -} - -/************************************************************************** Calculates the value of removing pollution. **************************************************************************/ static int ai_calc_pollution(struct city *pcity, int cx, int cy, int best, @@ -728,23 +703,6 @@ } /************************************************************************** - simply puts the settler unit into goto -**************************************************************************/ -void auto_settler_do_goto(struct player *pplayer, struct unit *punit, int x, - int y) -{ - CHECK_MAP_POS(x, y); - punit->goto_dest_x = x; - punit->goto_dest_y = y; - set_unit_activity(punit, ACTIVITY_GOTO); - send_unit_info(NULL, punit); - if (!ai_unit_gothere(punit)) { - UNIT_LOG(LOG_DEBUG, punit, "did settler goto to %s", - get_activity_text(punit->activity)); - } -} - -/************************************************************************** Tries to find a boat for our settler. Requires warmap to be initialized with respect to x, y. cap is the requested capacity on the transport. Note that it may return a transport with less than cap capacity if this @@ -928,9 +886,11 @@ int near = real_map_distance(punit->x, punit->y, x, y); bool w_virtual = FALSE; /* I'm no entirely sure what this is --dwp */ int b, mv_cost, newv, moves = 0; + struct tile *ptile = map_get_tile(x, y); - if (!is_already_assigned(punit, pplayer, x, y) - && map_get_terrain(x, y) != T_OCEAN + if (!is_non_allied_unit_tile(ptile, pplayer) + && !TEST_BIT(map_get_tile(x, y)->assigned, pplayer->player_no) + && map_get_terrain(x, y) != T_OCEAN && !BV_CHECK_MASK(territory[x][y], my_enemies) /* pretty good, hope it's enough! -- Syela */ && (near < 8 || map_get_continent(x, y) != ucont) @@ -1069,6 +1029,8 @@ #endif /* try to work near the city */ city_map_checked_iterate(pcity->x, pcity->y, i, j, x, y) { + struct tile *ptile = map_get_tile(x, y); + if (get_worker_city(pcity, i, j) == C_TILE_UNAVAILABLE) continue; in_use = (get_worker_city(pcity, i, j) == C_TILE_WORKER); @@ -1076,10 +1038,11 @@ && warmap.cost[x][y] <= THRESHOLD * mv_rate && !BV_CHECK_MASK(territory[x][y], my_enemies) /* pretty good, hope it's enough! -- Syela */ - && !is_already_assigned(punit, pplayer, x, y)) { - /* calling is_already_assigned once instead of four times - for obvious reasons; structure is much the same as it once - was but subroutines are not -- Syela */ + && !is_non_allied_unit_tile(ptile, pplayer) + /* don't go there if already assigned, unless we're already + * there, in which case maybe we can help? */ + && (!TEST_BIT(map_get_tile(x, y)->assigned, pplayer->player_no) + || same_pos(x, y, punit->x, punit->y))) { int time; mv_turns = (warmap.cost[x][y]) / mv_rate; oldv = city_tile_value(pcity, i, j, 0, 0); @@ -1166,7 +1129,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; @@ -1204,23 +1167,24 @@ freelog(LOG_DEBUG, "%d@(%d, %d): Looking for BOAT.", punit->id, punit->x, punit->y); if (!same_pos(x, y, punit->x, punit->y)) { - auto_settler_do_goto(pplayer, punit, x, y); + (void) ai_unit_goto(punit, x, y); if (!player_find_unit_by_id(pplayer, save_id)) return FALSE; /* died */ } ferryboat = unit_list_find(&(map_get_tile(punit->x, punit->y)->units), punit->ai.ferryboat); + punit->goto_dest_x = gx; punit->goto_dest_y = gy; + if (ferryboat && (ferryboat->ai.passenger == 0 || ferryboat->ai.passenger == punit->id)) { freelog(LOG_DEBUG, "We have FOUND BOAT, %d ABOARD %d@(%d,%d)->(%d,%d).", punit->id, ferryboat->id, punit->x, punit->y, gx, gy); - set_unit_activity(punit, ACTIVITY_SENTRY); - /* kinda cheating -- Syela */ + handle_unit_activity_request(punit, ACTIVITY_SENTRY); ferryboat->ai.passenger = punit->id; - auto_settler_do_goto(pplayer, ferryboat, gx, gy); - set_unit_activity(punit, ACTIVITY_IDLE); + (void) ai_unit_goto(ferryboat, gx, gy); + handle_unit_activity_request(punit, ACTIVITY_IDLE); } /* need to zero pass & ferryboat at some point. */ } if (goto_is_sane(punit, gx, gy, TRUE) @@ -1228,7 +1192,7 @@ && (!ferryboat || (is_tiles_adjacent(punit->x, punit->y, gx, gy) && could_unit_move_to_tile(punit, gx, gy) != 0))) { - auto_settler_do_goto(pplayer, punit, gx, gy); + (void) ai_unit_goto(punit, gx, gy); if (!player_find_unit_by_id(pplayer, save_id)) return FALSE; /* died */ punit->ai.ferryboat = 0; } @@ -1372,12 +1336,15 @@ || unit_flag(punit, F_CITIES))) { freelog(LOG_DEBUG, "%s's settler at (%d, %d) is ai controlled.", pplayer->name, punit->x, punit->y); - if(punit->activity == ACTIVITY_SENTRY) - set_unit_activity(punit, ACTIVITY_IDLE); - if (punit->activity == ACTIVITY_GOTO && punit->moves_left > 0) - set_unit_activity(punit, ACTIVITY_IDLE); - if (punit->activity == ACTIVITY_IDLE) + if (punit->activity == ACTIVITY_SENTRY) { + handle_unit_activity_request(punit, ACTIVITY_IDLE); + } + if (punit->activity == ACTIVITY_GOTO && punit->moves_left > 0) { + handle_unit_activity_request(punit, ACTIVITY_IDLE); + } + if (punit->activity == ACTIVITY_IDLE) { auto_settler_findwork(pplayer, punit); + } freelog(LOG_DEBUG, "Has been processed."); } }