diff -r -u freeciv/ai/aiunit.c freeciv_new/ai/aiunit.c --- freeciv/ai/aiunit.c Sun Oct 29 22:58:07 2000 +++ freeciv_new/ai/aiunit.c Thu Nov 2 18:09:46 2000 @@ -27,7 +27,7 @@ #include "rand.h" #include "shared.h" #include "timing.h" -#include "unit.h" +#include "unit.h" /* unit_h */ #include "barbarian.h" #include "cityhand.h" @@ -62,7 +62,6 @@ static int unit_move_turns(struct unit *punit, int x, int y); static int unit_can_defend(int type); - /************************************************************************** Similar to is_my_zoc(), but with some changes: - destination (x0,y0) need not be adjacent? @@ -233,6 +232,7 @@ Explores unknown territory, finds huts. Returns whether there is any more territory to be explored. **************************************************************************/ +#define STATUS_CONTINUE -1 int ai_manage_explorer(struct unit *punit) { struct player *pplayer = unit_owner(punit); @@ -244,6 +244,14 @@ int best_x = -1, best_y = -1; int range = get_unit_type(punit->type)->vision_range; int move_rate = unit_move_rate(punit); + int status = STATUS_CONTINUE; + + freelog(LOG_DEBUG, "-->ai_manage_explorer"); + freelog(LOG_DEBUG, "IN: unit %s %i@(%i,%i), activity=%i, move_left=%i, owner=%i, homecity=%i", + unit_types[punit->type].name, id, punit->x, punit->y, punit->activity, + punit->moves_left, punit->owner, punit->homecity); + freelog(LOG_DEBUG, "IN: vision_range=%i, move_rate=%i, handic_hide_hut=%i", + range, move_rate, pplayer->ai.handicap ); if (punit->activity != ACTIVITY_IDLE) handle_unit_activity_request(punit, ACTIVITY_IDLE); @@ -256,11 +264,13 @@ generate_warmap(map_get_city(x, y), punit); /* BEGIN PART ONE: Look for huts. Non-Barbarian Ground units ONLY. */ + freelog(LOG_DEBUG, "begin part 1"); if (!is_barbarian(pplayer) && is_ground_unit(punit)) { /* boats don't hunt huts */ int x1, y1; int maxcost = pplayer->ai.control ? 2 * THRESHOLD : 3; int bestcost = maxcost * 3 + 1; + int hutTargetKnown; /* Iterating outward so that with two tiles with the same movecost the nearest is used */ @@ -270,151 +280,232 @@ && (!ai_handicap(pplayer, H_HUTS) || map_get_known(x1, y1, pplayer)) && tile_is_accessible(punit, x1, y1) && ai_fuzzy(pplayer, 1)) { - best_x = x1; - best_y = y1; - bestcost = warmap.cost[best_x][best_y]; + freelog(LOG_DEBUG, "find hut (%i,%i)", x1, y1); + + /* Check nobody already target this hut --Vicet */ + hutTargetKnown = 0; + hutTarget_list_iterate(pplayer->hutTargList, pTarg) { + if ( (pTarg->x == x1) && (pTarg->y == y1) && (pTarg->id != punit->id)) { + hutTargetKnown = 1; + break; + } + } hutTarget_list_iterate_end; + if ( hutTargetKnown == 0 ) { + freelog(LOG_DEBUG, "new best target (%i,%i)", x1, y1); + best_x = x1; + best_y = y1; + bestcost = warmap.cost[best_x][best_y]; + } } } iterate_outward_end; + if (bestcost <= maxcost * 3) { + struct map_target *t; + + /* Save target to avoid other unit to target the same one --Vicet */ + t = fc_malloc(sizeof(struct map_target)); + t->x = best_x; + t->y = best_y; + t->id = punit->id; + hutTarget_list_insert(&pplayer->hutTargList, t); + punit->goto_dest_x = best_x; punit->goto_dest_y = best_y; set_unit_activity(punit, ACTIVITY_GOTO); do_unit_goto(punit, GOTO_MOVE_ANY, 0); - if (!player_find_unit_by_id(pplayer, id)) - return 0; /* died */ - if (punit->moves_left) { + if (!player_find_unit_by_id(pplayer, id)) { + /* unit died */ + freelog(LOG_DEBUG, "unit died", best_x, best_y); + status = 0; + } + else if (punit->moves_left) { if (punit->x == best_x && punit->y == best_y) { - return ai_manage_explorer(punit); - } else { + status = ai_manage_explorer(punit); + } + else { + freelog(LOG_DEBUG, "ERROR: Something went wrong"); /* Something went wrong; fall through. This should almost never happen. */ if (punit->x != x || punit->y != y) generate_warmap(map_get_city(punit->x, punit->y), punit); x = punit->x; y = punit->y; /* Fallthough to next fase */ } - } else { - return 1; + } + else { + status = 1; } } } - /* BEGIN PART TWO: Move into unexplored territory */ - /* move the unit as long as moving will unveil unknown territory */ - while (punit->moves_left) { - int most_unknown = 0; - int unknown; - int x1, y1, x2, y2; - int landnear; - - /* evaluate all adjacent tiles */ - square_iterate(x, y, 1, x1, y1) { - landnear = 0; - unknown = 0; - square_iterate(x1, y1, range, x2, y2) { - if (!map_get_known(x2, y2, pplayer)) - unknown++; - if (map_get_terrain(x2, y2) != T_OCEAN) - landnear = 1; + if( status == STATUS_CONTINUE ) { + /* BEGIN PART TWO: Move into unexplored territory */ + /* move the unit as long as moving will unveil unknown territory */ + int most_unknown = 0; + int unknown; + int x1, y1, x2, y2; + int landnear; + + freelog(LOG_DEBUG, "begin part 2"); + + /* evaluate all adjacent tiles */ + square_iterate(x, y, 1, x1, y1) { + landnear = 0; + unknown = 0; + square_iterate(x1, y1, range, x2, y2) { + if (!map_get_known(x2, y2, pplayer)) + unknown++; + if (map_get_terrain(x2, y2) != T_OCEAN) + landnear = 1; + } square_iterate_end; + if (unknown > most_unknown + && (landnear || !unit_flag(punit->type, F_TRIREME)) + && map_get_continent(x1, y1) == con + && can_unit_move_to_tile(punit, x1, y1, 0) + && !((pcity = map_get_city(x1,y1)) + && (unit_flag(punit->type, F_DIPLOMAT) + || unit_flag(punit->type, F_CARAVAN))) + && !(is_barbarian(pplayer) && map_get_special(x1, y1) & S_HUT)) { + most_unknown = unknown; + best_x = x1; + best_y = y1; + } } square_iterate_end; - if (unknown > most_unknown - && (landnear || !unit_flag(punit->type, F_TRIREME)) - && map_get_continent(x1, y1) == con - && can_unit_move_to_tile(punit, x1, y1, 0) - && !((pcity = map_get_city(x1,y1)) - && (unit_flag(punit->type, F_DIPLOMAT) - || unit_flag(punit->type, F_CARAVAN))) - && !(is_barbarian(pplayer) && map_get_special(x1, y1) & S_HUT)) { - most_unknown = unknown; - best_x = x1; - best_y = y1; - } - } square_iterate_end; - - if (most_unknown > 0) { /* a tile have unexplored territory adjacent */ - int res = handle_unit_move_request(punit, best_x, best_y, FALSE, FALSE); - if (!res) /* This shouldn't happen */ - break; - if (!player_find_unit_by_id(pplayer, id)) - return 0; /* died */ - x = punit->x; y = punit->y; - } else { - break; - } - } - if (!punit->moves_left) return 1; + if (most_unknown > 0) { /* a tile have unexplored territory adjacent */ + int res = handle_unit_move_request(punit, best_x, best_y, FALSE, FALSE); + freelog(LOG_DEBUG, "find tile with unexplored territory adjacent @(%i,%i)", + best_x, best_y); + if (!res) {/* This shouldn't happen */ + freelog(LOG_DEBUG, "ERROR : handle_unit_move_request"); + } + else { + if (!player_find_unit_by_id(pplayer, id)) { + /* Unit is died */ + freelog(LOG_DEBUG, "unit is died !"); + status = 0; + } + x = punit->x; y = punit->y; + if (punit->moves_left) { + status = ai_manage_explorer(punit); + } + else { + /* if hut has unveiled by the last movement then this unit will + target this hut to avoid that another unit waste of time to move + to this hut --Vicet */ + iterate_outward(x, y, 1, x1, y1) { + if (map_get_special(x1, y1) & S_HUT + && tile_is_accessible(punit, x1, y1)) { + struct map_target *t; + + freelog(LOG_DEBUG, "Find hut unveiled by last movement (%i,%i)", x1, y1); + + /* Save target into hut target list */ + t = fc_malloc(sizeof(struct map_target)); + t->x = x1; + t->y = y1; + t->id = punit->id; + hutTarget_list_insert(&pplayer->hutTargList, t); + + punit->goto_dest_x = x1; + punit->goto_dest_y = y1; + set_unit_activity(punit, ACTIVITY_GOTO); + do_unit_goto(punit, GOTO_MOVE_ANY, 0); + } + } iterate_outward_end; + } + } + } - /* BEGIN PART THREE: Go towards unexplored territory */ - /* no adjacent squares help us to explore - really slow part follows */ - generate_warmap(map_get_city(x, y), punit); + if (!punit->moves_left) status = 1; - { - int unknown, most_unknown = 0; - int threshold = THRESHOLD * move_rate; - whole_map_iterate(x1, y1) { - struct tile *ptile = map_get_tile(x1, y1); - unknown = 0; - if (ptile->continent == con - && !is_non_allied_unit_tile(ptile, punit->owner) - && !is_non_allied_city_tile(ptile, punit->owner) - && tile_is_accessible(punit, x1, y1)) { - int x2, y2; - square_iterate(x1, y1, range, x2, y2) { - if (!map_get_known(x2, y2, pplayer)) - unknown++; - } square_iterate_end; - if (unknown) { - if (is_sailing_unit(punit)) - unknown += 9 * (threshold - warmap.seacost[x1][y1]); - else - unknown += 9 * (threshold - warmap.cost[x1][y1]); - if ((unknown > most_unknown || (unknown == most_unknown && myrand(2))) - && !(is_barbarian(pplayer) && ptile->special & S_HUT)) { - best_x = x1; - best_y = y1; - most_unknown = unknown; - } - } - } - } whole_map_iterate_end; + if( status == STATUS_CONTINUE ) { + freelog(LOG_DEBUG, "begin part 3"); + /* BEGIN PART THREE: Go towards unexplored territory */ + /* no adjacent squares help us to explore - really slow part follows */ + generate_warmap(map_get_city(x, y), punit); + + { + int unknown, unknown1, most_unknown = 0; + int threshold = THRESHOLD * move_rate; + whole_map_iterate(x1, y1) { + struct tile *ptile = map_get_tile(x1, y1); + unknown = 0; + if (ptile->continent == con + && !is_non_allied_unit_tile(ptile, punit->owner) + && !is_non_allied_city_tile(ptile, punit->owner) + && tile_is_accessible(punit, x1, y1)) { + int x2, y2; +/* freelog(LOG_DEBUG, "tile (%i,%i) on our continent",x1, y1); */ + square_iterate(x1, y1, range, x2, y2) { + if (!map_get_known(x2, y2, pplayer)) + unknown++; + } square_iterate_end; + if (unknown) { + if (is_sailing_unit(punit)) + unknown += 9 * (threshold - warmap.seacost[x1][y1]); + else + unknown += 9 * (threshold - warmap.cost[x1][y1]); + unknown1 = unknown; + if ((unknown > most_unknown || (unknown == most_unknown && myrand(2))) + && !(is_barbarian(pplayer) && ptile->special & S_HUT)) { + best_x = x1; + best_y = y1; + most_unknown = unknown; + } + } + } + } whole_map_iterate_end; - if (most_unknown > 0) { - punit->goto_dest_x = best_x; - punit->goto_dest_y = best_y; - handle_unit_activity_request(punit, ACTIVITY_GOTO); - do_unit_goto(punit, GOTO_MOVE_ANY, 0); - if (punit->moves_left) { - if (punit->x != best_x || punit->y != best_y) { - handle_unit_activity_request(punit, ACTIVITY_IDLE); - return 1; /* Something wrong; what to do but return? */ - } else - return ai_manage_explorer(punit); - } else { - return 1; + if (most_unknown > 0) { + freelog(LOG_DEBUG, "find target tile @(%i,%i)", best_x, best_y); + punit->goto_dest_x = best_x; + punit->goto_dest_y = best_y; + handle_unit_activity_request(punit, ACTIVITY_GOTO); + do_unit_goto(punit, GOTO_MOVE_ANY, 0); + if (punit->moves_left) { + if (punit->x != best_x || punit->y != best_y) { + freelog(LOG_DEBUG, "ERROR: Something wrong; what to do but return" ); + handle_unit_activity_request(punit, ACTIVITY_IDLE); + status = 1; /* Something wrong; what to do but return? */ + } else { + status = ai_manage_explorer(punit); + } + } else { + status = 1; + } + } /* no candidates; fall-through */ } - } /* no candidates; fall-through */ - } - /* BEGIN PART FOUR: maybe go to another continent */ - freelog(LOG_DEBUG, "%s's %s at (%d,%d) failed to explore.", - pplayer->name, unit_types[punit->type].name, punit->x, punit->y); - handle_unit_activity_request(punit, ACTIVITY_IDLE); - if (pplayer->ai.control && is_military_unit(punit)) { - pcity = find_city_by_id(punit->homecity); - if (pcity && map_get_continent(pcity->x, pcity->y) == con) - ai_military_gohome(pplayer, punit); - else if (pcity) { - if (!find_boat(pplayer, &x, &y, 0)) /* Gilligan's Island */ - punit->ai.ferryboat = -1; - else { - punit->goto_dest_x = x; - punit->goto_dest_y = y; - do_unit_goto(punit, GOTO_MOVE_ANY, 0); + if( status == STATUS_CONTINUE ) { + /* BEGIN PART FOUR: maybe go to another continent */ + freelog(LOG_DEBUG, "begin part 4"); + freelog(LOG_DEBUG, "%s's %s at (%d,%d) failed to explore.", + pplayer->name, unit_types[punit->type].name, punit->x, punit->y); + handle_unit_activity_request(punit, ACTIVITY_IDLE); + if (pplayer->ai.control && is_military_unit(punit)) { + pcity = find_city_by_id(punit->homecity); + if (pcity && map_get_continent(pcity->x, pcity->y) == con) + ai_military_gohome(pplayer, punit); + else if (pcity) { + if (!find_boat(pplayer, &x, &y, 0)) /* Gilligan's Island */ + punit->ai.ferryboat = -1; + else { + punit->goto_dest_x = x; + punit->goto_dest_y = y; + do_unit_goto(punit, GOTO_MOVE_ANY, 0); + } + } + } + status = 0; } } } - return 0; + + freelog(LOG_DEBUG, "<--ai_manage_explorer"); + freelog(LOG_DEBUG, "OUT: status=%i, goto_dest=(%i,%i), ai.ferryboat=%i", + status, punit->goto_dest_x, punit->goto_dest_y, punit->ai.ferryboat); + return status; } /************************************************************************** @@ -1055,7 +1146,8 @@ def = (mycity->ai.danger - assess_defense_quadratic(mycity))>>d; if (def > val && ai_fuzzy(pplayer,1)) { *acity = mycity; val = def; } city_list_iterate_end; - freelog(LOG_DEBUG, "%s@(%d,%d) looking for charge; %d/%d", + freelog(LOG_DEBUG, "<--look_for_charge"); + freelog(LOG_DEBUG, "OUT: %s@(%d,%d) = %d/%d", unit_types[punit->type].name, punit->x, punit->y, val, val * 100 / u); return((val * 100) / u); @@ -1227,6 +1319,9 @@ int bk = 0; /* this is a kluge, because if we don't set x and y with !punit->id, p_a_w isn't called, and we end up not wanting ironclads and therefore never learning steam engine, even though ironclads would be very useful. -- Syela */ + freelog(LOG_DEBUG, "-->find_something_to_kill"); + freelog(LOG_DEBUG, "IN: player=%s, unit=%s, (%i,%i)", pplayer->name, + unit_types[punit->type].name, punit->x, punit->y, a); /* this is horrible, but I need to do something like this somewhere. -- Syela */ for (i = 0; i < game.nplayers; i++) { diff -r -u freeciv/common/map.h freeciv_new/common/map.h --- freeciv/common/map.h Sun Oct 29 22:58:31 2000 +++ freeciv_new/common/map.h Thu Nov 2 18:09:59 2000 @@ -26,6 +26,12 @@ int x,y; }; +/* AVT_COORDONATE - BEGIN */ +struct map_target { + int x, y, id; +}; +/* AVT_COORDONATE - END */ + struct goto_route { int first_index; /* first valid tile pos */ int last_index; /* point to the first non_legal pos. Note that the pos diff -r -u freeciv/common/player.c freeciv_new/common/player.c --- freeciv/common/player.c Sun Oct 29 22:58:32 2000 +++ freeciv_new/common/player.c Thu Nov 2 18:10:24 2000 @@ -32,6 +32,12 @@ #include "player.h" +/* define related functions to hutTarget --Vicet */ +#define SPECLIST_TAG hutTarget +#define SPECLIST_TYPE struct map_target +#include "speclist_c.h" + + /*************************************************************** ... @@ -101,6 +107,7 @@ } plr->gives_shared_vision = 0; plr->really_gives_vision = 0; + hutTarget_list_init(&plr->hutTargList); } /*************************************************************** diff -r -u freeciv/common/player.h freeciv_new/common/player.h --- freeciv/common/player.h Wed Sep 6 23:41:16 2000 +++ freeciv_new/common/player.h Thu Nov 2 18:10:39 2000 @@ -19,7 +19,16 @@ #include "shared.h" #include "spaceship.h" #include "tech.h" -#include "unit.h" +#include "unit.h" /* unit_h */ + +/* get 'struct exploTarget_list' and related functions: --Vicet */ +#define SPECLIST_TAG hutTarget +#define SPECLIST_TYPE struct map_target +#include "speclist.h" + +#define hutTarget_list_iterate(hutTargetList, pHutTarget) \ + TYPED_LIST_ITERATE(struct map_target, hutTargetList, pHutTarget) +#define hutTarget_list_iterate_end LIST_ITERATE_END struct tile; @@ -27,7 +36,6 @@ #define PLAYER_DEFAULT_SCIENCE_RATE 100 #define PLAYER_DEFAULT_LUXURY_RATE 0 - enum handicap_type { H_NONE=0, /* no handicaps */ H_RIGIDPROD=1, /* can't switch to/from building_unit without penalty */ @@ -158,6 +166,8 @@ struct player_tile *private_map; unsigned int gives_shared_vision; /* bitvector those that give you shared vision */ unsigned int really_gives_vision; /* takes into account that p3 may see what p1 has via p2 */ + struct hutTarget_list hutTargList; /* hut target list to avoid several unit + target the same hut */ }; void player_init(struct player *plr); diff -r -u freeciv/server/settlers.c freeciv_new/server/settlers.c --- freeciv/server/settlers.c Sun Oct 29 23:07:53 2000 +++ freeciv_new/server/settlers.c Thu Nov 2 18:11:19 2000 @@ -894,7 +894,7 @@ int gx,gy; /* x,y of target (goto) square */ int mv_turns; /* estimated turns to move to target square */ int oldv; /* current value of consideration tile */ - int newv; /* upgraded value of consideration tile */ + int newv; /* upgraded value of consideration tile */ int best_newv = 0; /* newv of best target so far, all cities */ int best_oldv = 9999; /* oldv of best target so far; compared if newv==best_newv; not initialized to zero, @@ -917,6 +917,7 @@ /* for debugging only */ int save_newv; #endif + freelog(LOG_DEBUG, "-->auto_settler_findwork"); choice.type = 1; choice.want = 0; /* will change as needed */ @@ -944,7 +945,7 @@ AI settlers improving enemy cities. arguably should include city_spot */ generate_warmap(mycity, punit); city_list_iterate(pplayer->cities, pcity) - freelog(LOG_DEBUG, "%s", pcity->name); + freelog(LOG_DEBUG, "Try to work near city %s", pcity->name); /* try to work near the city */ city_map_iterate_outwards(i, j) if (get_worker_city(pcity, i, j) == C_TILE_UNAVAILABLE) continue; @@ -956,7 +957,8 @@ && warmap.cost[x][y] <= THRESHOLD * mv_rate && (territory[x][y]&(1< 0) { freelog(LOG_DEBUG, - "Settler %d@(%d,%d) wants to %s at (%d,%d) with desire %d", + "DESIRE: Settler %d@(%d,%d) wants to %s at (%d,%d) with desire %d", punit->id, punit->x, punit->y, get_activity_text(best_act), gx, gy, best_newv); } @@ -1063,8 +1066,9 @@ else boatid = 0; ferryboat = unit_list_find(&(map_get_tile(punit->x, punit->y)->units), boatid); - if (ferryboat) + if (ferryboat) { really_generate_warmap(mycity, ferryboat, SEA_MOVING); + } /** Decide whether to build a new city: ** if so, modify: gx, gy, best_newv, best_act */ @@ -1090,7 +1094,9 @@ /* pretty good, hope it's enough! -- Syela */ && (near < 8 || map_get_continent(x, y) != ucont) && city_can_be_built_here(x,y) - && !city_exists_within_city_radius(x,y)) { + && !city_exists_within_city_radius(x,y) + /* ai is not a cheat --Vicet */ + && (!ai_handicap(pplayer, H_TARGETS) || map_get_known(x, y, pplayer))) { /* potential target, calculate mv_cost: */ if (ferryboat) { @@ -1160,10 +1166,13 @@ if (map_get_continent(x, y) != ucont && !nav_known && near >= 8) { if (newv > choice.want && !punit->id) choice.want = newv; freelog(LOG_DEBUG, - "%s @(%d, %d) city_des (%d, %d) = %d, newv = %d, d = %d", + "%s @(%d, %d) city_des (%d, %d) = %d, newv = %d, delay = %d", (punit->id ? unit_types[punit->type].name : mycity->name), punit->x, punit->y, x, y, b, newv, d); } else if (newv > best_newv) { + freelog(LOG_DEBUG, "new best target for %s @(%d, %d) -> @(%d, %d) :", + (punit->id ? unit_types[punit->type].name : mycity->name), punit->x, + punit->y, x, y); best_act = ACTIVITY_UNKNOWN; /* flag value */ best_newv = newv; if (w_virtual) { @@ -1184,7 +1193,7 @@ if ((best_newv != save_newv) || (map_get_terrain(punit->x, punit->y) == T_OCEAN)) { freelog(LOG_DEBUG, - "%s %d@(%d,%d) wants to %s at (%d,%d) with desire %d", + "DESIRE: %s %d@(%d,%d) wants to %s at (%d,%d) with desire %d", unit_name(punit->type), punit->id, punit->x, punit->y, get_activity_text(best_act), gx, gy, best_newv); } @@ -1216,7 +1225,7 @@ } } - /** We've now worked out what to do; go to it! **/ + freelog(LOG_DEBUG, "We've now worked out what to do; go to it"); if (gx!=-1 && gy!=-1) { if (unit_flag(punit->type, F_CITIES) && (best_act == ACTIVITY_UNKNOWN /* flag */)) { @@ -1303,7 +1312,7 @@ pcity->ai.irrigate[i][j] = ai_calc_irrigate(pcity, pplayer, i, j); pcity->ai.transform[i][j] = ai_calc_transform(pcity, i, j); pcity->ai.road[i][j] = ai_calc_road(pcity, pplayer, i, j); -/* gonna handle road_bo dynamically for now since it can change + /* gonna handle road_bo dynamically for now since it can change as punits arrive at adjacent tiles and start laying road -- Syela */ pcity->ai.railroad[i][j] = ai_calc_railroad(pcity, pplayer, i, j); } @@ -1318,6 +1327,7 @@ static struct timer *t = NULL; /* alloc once, never free */ t = renew_timer_start(t, TIMER_CPU, TIMER_DEBUG); + freelog(LOG_DEBUG, "-->auto_settlers_player"); city_list_iterate(pplayer->cities, pcity) initialize_infrastructure_cache(pcity); /* saves oodles of time -- Syela */ @@ -1445,6 +1455,8 @@ void auto_settlers(void) { int i; + + freelog(LOG_DEBUG, "-->auto_settlers"); assign_settlers(); assign_territory(); for (i = 0; i < game.nplayers; i++) { diff -r -u freeciv/server/unitfunc.c freeciv_new/server/unitfunc.c --- freeciv/server/unitfunc.c Sun Oct 29 22:58:39 2000 +++ freeciv_new/server/unitfunc.c Thu Nov 2 18:11:04 2000 @@ -2095,6 +2095,7 @@ enum ocean_land_change solvency = OLC_NONE; struct tile *ptile = map_get_tile(punit->x, punit->y); + freelog(LOG_DEBUG,"-->update_unit_activity"); /* to allow a settler to begin a task with no moves left without it counting toward the time to finish */ if (punit->moves_left){ @@ -2438,6 +2439,7 @@ struct unit_list *punit_list; struct city *pcity; punit_list=&map_get_tile(x, y)->units; + while(unit_list_size(punit_list)) { struct unit *punit=unit_list_get(punit_list, 0); @@ -2745,6 +2747,7 @@ struct city *pcity = map_get_city(punit->x, punit->y); struct city *phomecity = find_city_by_id(punit->homecity); + remove_unit_sight_points(punit); if (punit->pgr) { @@ -2785,6 +2788,7 @@ void wipe_unit_spec_safe(struct unit *punit, struct genlist_iterator *iter, int wipe_cargo) { + freelog(LOG_DEBUG, "-->wipe_unit_spec_safe %i", punit->id); /* No need to remove air units as they can still fly away */ if (is_ground_units_transport(punit) && map_get_terrain(punit->x, punit->y)==T_OCEAN @@ -2827,6 +2831,7 @@ **************************************************************************/ void wipe_unit_safe(struct unit *punit, struct genlist_iterator *iter){ + freelog(LOG_DEBUG, "-->wipe_unit_safe %i", punit->id); wipe_unit_spec_safe(punit, iter, 1); } @@ -2835,6 +2840,7 @@ **************************************************************************/ void wipe_unit(struct unit *punit) { + freelog(LOG_DEBUG, "-->wipe_unit %i", punit->id); wipe_unit_safe(punit, NULL); } @@ -2851,6 +2857,8 @@ char *loc_str = get_location_str_in(pplayer, punit->x, punit->y); int num_killed[MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS]; int ransom, unitcount = 0; + + freelog(LOG_DEBUG, "-->kill_unit %i", punit->id); /* barbarian leader ransom hack */ if( is_barbarian(pplayer) && unit_has_role(punit->type, L_BARBARIAN_LEADER) @@ -3522,6 +3530,18 @@ struct player *pplayer = get_player(playerid); struct tile *psrctile = map_get_tile(src_x, src_y); struct tile *pdesttile = map_get_tile(dest_x, dest_y); + + freelog(LOG_DEBUG, "-->move_unit (%i,%i)", dest_x, dest_y); + /* free hut in target list if necessary --Vicet */ + hutTarget_list_iterate(pplayer->hutTargList, pTarg) { + if ( (pTarg->x == dest_x) && (pTarg->y == dest_y) && (pTarg->id == punit->id) ) { + freelog(LOG_DEBUG, "MEM_HUT_TARGET : free %i@(%i,%i) ", + punit->id, dest_x, dest_y); + hutTarget_list_unlink(&pplayer->hutTargList, pTarg); + free(pTarg); + } + } hutTarget_list_iterate_end; + conn_list_do_buffer(&pplayer->connections);