Project

General

Profile

Feature #642 » 0002-Client-Keep-track-of-continent-and-ocean-sizes.patch

main - Alina Lenk, 05/18/2024 09:23 PM

View differences:

client/packhand.c
unit_list_clear(ptile->units);
}
if (ptile->continent != packet->continent) {
/* Update known continents and sizes */
if (packet->continent > wld.map.num_continents) {
int i;
/* Reallocate sizes array and fill new spots with zeros */
wld.map.continent_sizes = fc_realloc(wld.map.continent_sizes,
(packet->continent + 1) * sizeof(*wld.map.continent_sizes));
for (i = wld.map.num_continents + 1; i <= packet->continent; i++) {
wld.map.continent_sizes[i] = 0;
}
wld.map.num_continents = packet->continent;
} else if (packet->continent < -wld.map.num_oceans) {
int i;
/* Reallocate sizes array and fill new spots with zeros */
wld.map.ocean_sizes = fc_realloc(wld.map.ocean_sizes,
(-packet->continent + 1) * sizeof(*wld.map.ocean_sizes));
for (i = wld.map.num_oceans + 1; i <= -packet->continent; i++) {
wld.map.ocean_sizes[i] = 0;
}
wld.map.num_oceans = -packet->continent;
}
/* Decrement old continent/ocean size */
if (ptile->continent > 0) {
wld.map.continent_sizes[ptile->continent]--;
} else if (ptile->continent < 0) {
wld.map.ocean_sizes[-ptile->continent]--;
}
/* Increment new continent/ocean size */
if (packet->continent > 0) {
wld.map.continent_sizes[packet->continent]++;
} else if (packet->continent < 0) {
wld.map.ocean_sizes[-packet->continent]++;
}
}
ptile->continent = packet->continent;
wld.map.num_continents = MAX(ptile->continent, wld.map.num_continents);
if (packet->label[0] == '\0') {
if (ptile->label != NULL) {
client/text.c
index_to_native_pos(&nat_x, &nat_y, tile_index(ptile));
astr_add_line(&str, _("Native coordinates: (%d, %d)"),
nat_x, nat_y);
if (tile_continent(ptile) > 0) {
astr_add_line(&str, _("Continent size: at least %d"),
get_continent_size(tile_continent(ptile)));
} else if (tile_continent(ptile) < 0) {
astr_add_line(&str, _("Ocean size: at least %d"),
get_ocean_size(-tile_continent(ptile)));
}
astr_add_line(&str, _("Latitude: %d"),
map_signed_latitude(ptile));
common/map.c
{
fc_assert_ret_val(id > 0, -1);
fc_assert_ret_val(id <= wld.map.num_continents, -1);
/* Client updates num_continents, but not continent_sizes */
fc_assert_ret_val(is_server(), -1);
return wld.map.continent_sizes[id];
}
......
{
fc_assert_ret_val(id < 0, -1);
fc_assert_ret_val(id >= -wld.map.num_oceans, -1);
/* Client updates num_oceans, but not lake_surrounders */
fc_assert_ret_val(is_server(), -1);
return wld.map.lake_surrounders[-id];
}
common/map_types.h
int south_latitude;
int num_continents;
int num_oceans; /* Not updated at the client */
int num_oceans;
/* These arrays are indexed by continent number (or negative of the
* ocean number) so the 0th element is unused and the array is 1 element
* larger than you'd expect.
......
* The lake_surrounders array tells which single continent surrounds each
* ocean; or -1 if there's more than one adjacent continent.
*/
int *continent_sizes; /* Not updated at the client */
int *ocean_sizes; /* Not updated at the client */
int *continent_sizes;
int *ocean_sizes;
Continent_id *lake_surrounders; /* Not updated at the client */
struct tile *tiles;
(1-1/2)