diff -Naur -Xbrunel/no.freeciv freeciv/ai/advmilitary.c freeciv-mod/ai/advmilitary.c --- freeciv/ai/advmilitary.c Thu May 4 00:55:36 2000 +++ freeciv-mod/ai/advmilitary.c Thu May 4 00:52:42 2000 @@ -164,7 +164,7 @@ { int x, y, dist; if (is_tiles_adjacent(punit->x, punit->y, pcity->x, pcity->y)) dist = 3; - else if (is_sailing_unit(punit)) dist = warmap.seacost[punit->x][punit->y]; + else if (is_sailing_unit(punit)) dist = warmap.cost[punit->x][punit->y]; else if (!is_ground_unit(punit)) dist = real_map_distance(punit->x, punit->y, pcity->x, pcity->y) * 3; else if (unit_flag(punit->type, F_IGTER)) @@ -177,7 +177,7 @@ if (is_ground_unit(punit) && boatid && find_beachhead(punit, pcity->x, pcity->y, &x, &y)) { /* this bug is so obvious I can't believe it wasn't discovered sooner. -- Syela */ - y = warmap.seacost[punit->x][punit->y]; + y = warmap.cost[punit->x][punit->y]; if (y >= 6 * THRESHOLD) y = real_map_distance(pcity->x, pcity->y, punit->x, punit->y) * 3; x = MAX(y, boatdist) * m / boatspeed; @@ -242,7 +242,7 @@ boatspeed = (get_invention(aplayer, game.rtech.nav) == TECH_KNOWN ? 12 : 6); boatid = find_boat(aplayer, &x, &y, 0); - if (boatid) boatdist = warmap.seacost[x][y]; + if (boatid) boatdist = warmap.cost[x][y]; else boatdist = -1; /* should I treat empty enemy cities as danger? */ /* After much contemplation, I've decided the answer is sometimes -- Syela */ @@ -539,13 +539,13 @@ if (unit_types[i].move_type == LAND_MOVING) { if (boatspeed) { /* has to be a city, so don't bother with q */ c = (warmap.cost[bx][by] + m - 1) / m + 1 + - warmap.seacost[x][y] / boatspeed; /* kluge */ + warmap.cost[x][y] / boatspeed; /* kluge */ if (unit_flag(i, F_MARINES)) c -= 1; } else if (warmap.cost[x][y] <= m) c = 1; else c = (warmap.cost[x][y] * q + m - 1) / m; } else if (unit_types[i].move_type == SEA_MOVING) { - if (warmap.seacost[x][y] <= m) c = 1; - else c = (warmap.seacost[x][y] * q + m - 1) / m; + if (warmap.cost[x][y] <= m) c = 1; + else c = (warmap.cost[x][y] * q + m - 1) / m; } else if (real_map_distance(pcity->x, pcity->y, x, y) * 3 <= m) c = 1; else c = real_map_distance(pcity->x, pcity->y, x, y) * 3 * q / m; @@ -669,14 +669,14 @@ if (is_ground_unit(myunit)) { if (!sanity) { if (boatid) c = (warmap.cost[bx][by] + m - 1) / m + 1 + - warmap.seacost[acity->x][acity->y] / boatspeed; /* kluge */ - else c = warmap.seacost[acity->x][acity->y] / boatspeed + 1; + warmap.cost[acity->x][acity->y] / boatspeed; /* kluge */ + else c = warmap.cost[acity->x][acity->y] / boatspeed + 1; if (unit_flag(myunit->type, F_MARINES)) c -= 1; freelog(LOG_DEBUG, "%s attempting to attack via ferryboat" " (boatid = %d, c = %d)", unit_types[v].name, boatid, c); } else c = (warmap.cost[acity->x][acity->y] + m - 1) / m; } else if (is_sailing_unit(myunit)) - c = (warmap.seacost[acity->x][acity->y] + m - 1) / m; + c = (warmap.cost[acity->x][acity->y] + m - 1) / m; else c = real_map_distance(myunit->x, myunit->y, acity->x, acity->y) * 3 / m; n = ai_choose_defender_versus(acity, v); @@ -728,7 +728,7 @@ sanity = 1; if (is_ground_unit(myunit)) dist = warmap.cost[x][y]; - else if (is_sailing_unit(myunit)) dist = warmap.seacost[x][y]; + else if (is_sailing_unit(myunit)) dist = warmap.cost[x][y]; else dist = real_map_distance(pcity->x, pcity->y, x, y) * 3; if (dist > m) { dist *= unit_types[pdef->type].move_rate; @@ -855,10 +855,10 @@ { city_list_iterate(pplayer->cities, pcity) if (city_got_building(pcity, B_PORT) && - warmap.seacost[pcity->x][pcity->y] <= d) return 1; + warmap.cost[pcity->x][pcity->y] <= d) return 1; if (!pcity->is_building_unit && pcity->currently_building == B_PORT && pcity->shield_stock >= improvement_value(B_PORT) && - warmap.seacost[pcity->x][pcity->y] <= d) return 1; + warmap.cost[pcity->x][pcity->y] <= d) return 1; if (!player_knows_improvement_tech(pplayer, B_PORT) && pcity->is_building_unit && is_water_unit(pcity->currently_building) && diff -Naur -Xbrunel/no.freeciv freeciv/ai/aiunit.c freeciv-mod/ai/aiunit.c --- freeciv/ai/aiunit.c Thu May 4 00:55:59 2000 +++ freeciv-mod/ai/aiunit.c Thu May 4 00:52:42 2000 @@ -89,7 +89,7 @@ if (unit_types[punit->type].move_type == LAND_MOVING) d = warmap.cost[x][y] / m; else if (unit_types[punit->type].move_type == SEA_MOVING) - d = warmap.seacost[x][y] / m; + d = warmap.cost[x][y] / m; else d = real_map_distance(punit->x, punit->y, x, y) * 3 / m; return(d); } @@ -638,7 +638,7 @@ j = map_adjust_y(dest_y + jj[k]); ok = 0; fu = 0; t = map_get_terrain(i, j); - if (warmap.seacost[i][j] <= 6 * THRESHOLD && t != T_OCEAN) { /* accessible beachhead */ + if (warmap.cost[i][j] <= 6 * THRESHOLD && t != T_OCEAN) { /* accessible beachhead */ for (l = 0; l < 8 && !ok; l++) { if (map_get_terrain(i + ii[l], j + jj[l]) == T_OCEAN) { fu++; @@ -651,7 +651,7 @@ ok += (ok * terrain_control.river_defense_bonus) / 100; if (get_tile_type(t)->movement_cost * 3 < unit_types[punit->type].move_rate) ok *= 8; - ok += (6 * THRESHOLD - warmap.seacost[i][j]); + ok += (6 * THRESHOLD - warmap.cost[i][j]); if (ok > best) { best = ok; *x = i; *y = j; } } } @@ -1058,6 +1058,8 @@ /* this is horrible, but I need to do something like this somewhere. -- Syela */ for (i = 0; i < game.nplayers; i++) { aplayer = &game.players[i]; + if (aplayer == pplayer) continue; + /* AI will try to conquer only ennemy cities. -- Nb */ city_list_iterate(aplayer->cities, acity) city_reinforcements_cost_and_value(acity, punit); acity->ai.invasion = 0; @@ -1134,8 +1136,8 @@ if (ai_fuzzy(pplayer,1) && ((is_ground_unit(punit) && ((sanity) || ((ferryboat || harborcity) && - warmap.seacost[acity->x][acity->y] <= 6 * THRESHOLD))) || - (is_sailing_unit(punit) && warmap.seacost[acity->x][acity->y] < maxd))) { + warmap.cost[acity->x][acity->y] <= 6 * THRESHOLD))) || + (is_sailing_unit(punit) && warmap.cost[acity->x][acity->y] < maxd))) { if ((pdef = get_defender(pplayer, punit, acity->x, acity->y))) { d = unit_vulnerability(punit, pdef); b = unit_types[pdef->type].build_cost + 40; @@ -1143,14 +1145,14 @@ /* attempting to make empty cities less enticing. -- Syela */ if (is_ground_unit(punit)) { if (!sanity) { - c = (warmap.seacost[acity->x][acity->y]) / boatspeed; /* kluge */ + c = (warmap.cost[acity->x][acity->y]) / boatspeed; /* kluge */ if (boatspeed < 9 && c > 2) c = 999; /* tired of Kaput! -- Syela */ if (ferryboat) c += (warmap.cost[bx][by] + m - 1) / m + 1; else c += 1; if (unit_flag(punit->type, F_MARINES)) c -= 1; } else c = (warmap.cost[acity->x][acity->y] + m - 1) / m; } else if (is_sailing_unit(punit)) - c = (warmap.seacost[acity->x][acity->y] + m - 1) / m; + c = (warmap.cost[acity->x][acity->y] + m - 1) / m; else c = (real_map_distance(punit->x, punit->y, acity->x, acity->y) * 3) / m; if (c > 1) { n = ai_choose_defender_versus(acity, punit->type); @@ -1262,12 +1264,12 @@ warmap.cost[aunit->x][aunit->y] < maxd) || (is_sailing_unit(punit) && goto_is_sane(pplayer, punit, aunit->x, aunit->y, 1) && /* Thanks, Damon */ - warmap.seacost[aunit->x][aunit->y] < maxd)))) { + warmap.cost[aunit->x][aunit->y] < maxd)))) { d = unit_vulnerability(punit, aunit); b = unit_types[aunit->type].build_cost; if (is_ground_unit(punit)) n = warmap.cost[aunit->x][aunit->y]; - else if (is_sailing_unit(punit)) n = warmap.seacost[aunit->x][aunit->y]; + else if (is_sailing_unit(punit)) n = warmap.cost[aunit->x][aunit->y]; else n = real_map_distance(punit->x, punit->y, aunit->x, aunit->y) * 3; if (n > m) { /* if n <= m, it can't run away -- Syela */ n *= unit_types[aunit->type].move_rate; @@ -1324,7 +1326,7 @@ int best = 6 * THRESHOLD + 1, cur; generate_warmap(map_get_city(punit->x, punit->y), punit); city_list_iterate(pplayer->cities, pcity) - cur = warmap.seacost[pcity->x][pcity->y]; + cur = warmap.cost[pcity->x][pcity->y]; if (city_got_building(pcity, B_PORT)) cur /= 3; if (cur < best) { punit->goto_dest_x = pcity->x; @@ -1552,15 +1554,15 @@ generate_warmap(map_get_city(punit->x, punit->y), punit); p = 0; /* yes, I know it's already zero. -- Syela */ unit_list_iterate(pplayer->units, aunit) -/* if (aunit->ai.ferryboat == punit->id && warmap.seacost[aunit->x][aunit->y] < best) {*/ - if (aunit->ai.ferryboat && warmap.seacost[aunit->x][aunit->y] < best && +/* if (aunit->ai.ferryboat == punit->id && warmap.cost[aunit->x][aunit->y] < best) {*/ + if (aunit->ai.ferryboat && warmap.cost[aunit->x][aunit->y] < best && !is_transporter_with_free_space(pplayer, aunit->x, aunit->y) && ai_fuzzy(pplayer,1)) { freelog(LOG_DEBUG, "Found a friend %d@(%d, %d)", aunit->id, aunit->x, aunit->y); x = aunit->x; y = aunit->y; - best = warmap.seacost[x][y]; + best = warmap.cost[x][y]; } if (is_sailing_unit(aunit) && map_get_terrain(aunit->x, aunit->y) == T_OCEAN) p++; unit_list_iterate_end; diff -Naur -Xbrunel/no.freeciv freeciv/server/gotohand.c freeciv-mod/server/gotohand.c --- freeciv/server/gotohand.c Thu May 4 00:56:11 2000 +++ freeciv-mod/server/gotohand.c Thu May 4 00:53:09 2000 @@ -109,21 +109,13 @@ if (!warmap.cost[0]) { for (x = 0; x < map.xsize; x++) { warmap.cost[x]=fc_malloc(map.ysize*sizeof(unsigned char)); - warmap.seacost[x]=fc_malloc(map.ysize*sizeof(unsigned char)); warmap.vector[x]=fc_malloc(map.ysize*sizeof(unsigned char)); } } - if (which == LAND_MOVING) { - for (x = 0; x < map.xsize; x++) + for (x = 0; x < map.xsize; x++) memset(warmap.cost[x],255,map.ysize*sizeof(unsigned char)); - /* one if by land */ warmap.cost[orig_x][orig_y] = 0; - } else { - for (x = 0; x < map.xsize; x++) - memset(warmap.seacost[x],255,map.ysize*sizeof(unsigned char)); - warmap.seacost[orig_x][orig_y] = 0; - } } /************************************************************************** @@ -193,9 +185,9 @@ } } else { c = 3; /* allow for shore bombardment/transport/etc */ - tm = warmap.seacost[x][y] + c; - if (warmap.seacost[x1][y1] > tm && tm < maxcost) { - warmap.seacost[x1][y1] = tm; + tm = warmap.cost[x][y] + c; + if (warmap.cost[x1][y1] > tm && tm < maxcost) { + warmap.cost[x1][y1] = tm; if (tile0->move_cost[k] == -3) add_to_stack(x1, y1); } } @@ -473,18 +465,15 @@ if (!warmap.cost[0]) { for (x = 0; x < map.xsize; x++) { warmap.cost[x]=fc_malloc(map.ysize*sizeof(unsigned char)); - warmap.seacost[x]=fc_malloc(map.ysize*sizeof(unsigned char)); warmap.vector[x]=fc_malloc(map.ysize*sizeof(unsigned char)); } } for (x = 0; x < map.xsize; x++) { memset(warmap.cost[x],255,map.ysize*sizeof(unsigned char)); - memset(warmap.seacost[x],255,map.ysize*sizeof(unsigned char)); memset(warmap.vector[x],0,map.ysize*sizeof(unsigned char)); } warmap.cost[orig_x][orig_y] = 0; - warmap.seacost[orig_x][orig_y] = 0; return; } @@ -550,8 +539,6 @@ deal with merging these functions yet. Once they work correctly and independently I can worry about optimizing them. -- Syela */ - memset(local_vector, 0, sizeof(local_vector)); -/* I think I only need to zero (orig_x, orig_y), but ... */ init_gotomap(punit->x, punit->y); warstacksize = 0; @@ -637,8 +624,8 @@ if ((restriction == GOTO_MOVE_STRAIGHTEST) && (k == str)) { c /= 3; } - tm = warmap.seacost[x][y] + c; - if (warmap.seacost[x][y] < punit->moves_left && tm < maxcost && + tm = warmap.cost[x][y] + c; + if (warmap.cost[x][y] < punit->moves_left && tm < maxcost && (pplayer->ai.control) && tm >= punit->moves_left - (get_transporter_capacity(punit) > unit_types[punit->type].attack_strength ? 3 : 2) && @@ -650,11 +637,11 @@ punit->goto_dest_x, punit->goto_dest_y); } if (tm < maxcost) { - if (warmap.seacost[x1][y1] > tm) { - warmap.seacost[x1][y1] = tm; + if (warmap.cost[x1][y1] > tm) { + warmap.cost[x1][y1] = tm; add_to_stack(x1, y1); local_vector[x1][y1] = 128>>k; - } else if (warmap.seacost[x1][y1] == tm) { + } else if (warmap.cost[x1][y1] == tm) { local_vector[x1][y1] |= 128>>k; } } @@ -1026,13 +1013,13 @@ generate_warmap(NULL,punit); if(is_sailing_unit(punit)) - return warmap.seacost[dest_x][dest_y]; + return warmap.cost[dest_x][dest_y]; else if (is_ground_unit(punit)) { return warmap.cost[dest_x][dest_y]; } else { - return warmap.cost[dest_x][dest_y] < warmap.seacost[dest_x][dest_y] ? + return warmap.cost[dest_x][dest_y] < warmap.cost[dest_x][dest_y] ? warmap.cost[dest_x][dest_y] - : warmap.seacost[dest_x][dest_y]; + : warmap.cost[dest_x][dest_y]; } } diff -Naur -Xbrunel/no.freeciv freeciv/server/gotohand.h freeciv-mod/server/gotohand.h --- freeciv/server/gotohand.h Thu May 4 00:56:18 2000 +++ freeciv-mod/server/gotohand.h Thu May 4 00:53:09 2000 @@ -37,7 +37,6 @@ struct move_cost_map { unsigned char *cost[MAP_MAX_WIDTH]; - unsigned char *seacost[MAP_MAX_WIDTH]; unsigned char *vector[MAP_MAX_WIDTH]; struct city *warcity; /* so we know what we're dealing with here */ struct unit *warunit; /* so we know what we're dealing with here */ diff -Naur -Xbrunel/no.freeciv freeciv/server/settlers.c freeciv-mod/server/settlers.c --- freeciv/server/settlers.c Thu May 4 00:56:23 2000 +++ freeciv-mod/server/settlers.c Thu May 4 00:53:10 2000 @@ -1055,7 +1055,7 @@ if (!is_terrain_near_tile(x, y, T_OCEAN)) { mv_cost = 9999; } else { - mv_cost = warmap.seacost[x][y] * mv_rate / + mv_cost = warmap.cost[x][y] * mv_rate / unit_types[ferryboat->type].move_rate; } } else if (!goto_is_sane(pplayer, punit, x, y, 1) || @@ -1071,9 +1071,9 @@ !is_terrain_near_tile(mycity->x, mycity->y, T_OCEAN)) { mv_cost = 9999; } else { - mv_cost = warmap.seacost[x][y] * mv_rate / 9; + mv_cost = warmap.cost[x][y] * mv_rate / 9; /* this should be fresh; the only thing that could have - munged the seacost is the ferryboat code in + munged the cost is the ferryboat code in k_s_w/f_s_t_k, but only if find_boat succeeded */ w_virtual = 1; }