From 5d6f1d124b30ef6279332935c0e0e246850c5011 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 26 Nov 2022 03:18:22 +0200 Subject: [PATCH 32/32] Store continent/ocean sizes to advdata See osdn #45846 Signed-off-by: Marko Lindqvist --- ai/default/daieffects.c | 10 +++++----- server/advisors/advbuilding.c | 2 +- server/advisors/advdata.c | 33 ++++++++++++++++++++++----------- server/advisors/advdata.h | 12 +++++++++--- 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/ai/default/daieffects.c b/ai/default/daieffects.c index 5c1fc60cec..c9086b3cc0 100644 --- a/ai/default/daieffects.c +++ b/ai/default/daieffects.c @@ -493,12 +493,12 @@ adv_want dai_effect_value(struct player *pplayer, if (affects_sea_capable_units) { if (is_ocean_tile(pcity->tile)) { - v += adv->threats.ocean[-tile_continent(pcity->tile)] + v += adv->oceans[-tile_continent(pcity->tile)].threat ? amount / 6 : amount / 25; } else { adjc_iterate(&(wld.map), pcity->tile, tile2) { if (is_ocean_tile(tile2)) { - if (adv->threats.ocean[-tile_continent(tile2)]) { + if (adv->oceans[-tile_continent(tile2)].threat) { v += amount / 6; break; } @@ -506,18 +506,18 @@ adv_want dai_effect_value(struct player *pplayer, } adjc_iterate_end; } } - v += (amount / 25 + adv->threats.invasions - 1) * c; /* for wonder */ + v += (amount / 25 + adv->threats.invasions - 1) * c; /* For wonder */ if (capital || affects_land_capable_units) { Continent_id place = tile_continent(pcity->tile); - if ((place > 0 && adv->threats.continent[place]) + if ((place > 0 && adv->continents[place].threat) || capital || (adv->threats.invasions /* FIXME: This ignores riverboats on some rulesets. We should analyze rulesets when game starts and have relevant checks here. */ && is_terrain_class_near_tile(pcity->tile, TC_OCEAN))) { - if (place > 0 && adv->threats.continent[place]) { + if (place > 0 && adv->continents[place].threat) { v += amount * 4 / 5; } else { v += amount / (!adv->threats.igwall ? (18 - capital * 6) : 18); diff --git a/server/advisors/advbuilding.c b/server/advisors/advbuilding.c index 59c24aa845..675f922e80 100644 --- a/server/advisors/advbuilding.c +++ b/server/advisors/advbuilding.c @@ -234,7 +234,7 @@ void building_advisor(struct player *pplayer) value += adv->stats.cities[place] / 8; } } - if (place >= 0 && adv->threats.continent[place] > 0) { + if (place >= 0 && adv->continents[place].threat > 0) { /* We have threatening neighbours: -25% */ value -= value / 4; } diff --git a/server/advisors/advdata.c b/server/advisors/advdata.c index 519bb1876e..3e3df92897 100644 --- a/server/advisors/advdata.c +++ b/server/advisors/advdata.c @@ -290,12 +290,22 @@ bool adv_data_phase_init(struct player *pplayer, bool is_new_phase) adv->num_continents = wld.map.num_continents; adv->num_oceans = wld.map.num_oceans; - adv->threats.continent = fc_calloc(adv->num_continents + 1, sizeof(bool)); + adv->continents = fc_calloc(adv->num_continents + 1, sizeof(struct adv_area_info)); + adv->oceans = fc_calloc(adv->num_oceans + 1, sizeof(struct adv_area_info)); adv->threats.invasions = FALSE; - adv->threats.nuclear = 0; /* none */ - adv->threats.ocean = fc_calloc(adv->num_oceans + 1, sizeof(bool)); + adv->threats.nuclear = 0; /* None */ adv->threats.igwall = FALSE; + whole_map_iterate(&(wld.map), ptile) { + Continent_id cont = tile_continent(ptile); + + if (cont >= 0) { + adv->continents[cont].size++; + } else { + adv->oceans[-cont].size++; + } + } whole_map_iterate_end; + players_iterate(aplayer) { if (!adv_is_player_dangerous(pplayer, aplayer)) { continue; @@ -307,8 +317,9 @@ bool adv_data_phase_init(struct player *pplayer, bool is_new_phase) * coastal fortresses and hunting down enemy transports. */ city_list_iterate(aplayer->cities, acity) { Continent_id continent = tile_continent(acity->tile); + if (continent >= 0) { - adv->threats.continent[continent] = TRUE; + adv->continents[continent].threat = TRUE; } } city_list_iterate_end; @@ -343,13 +354,13 @@ bool adv_data_phase_init(struct player *pplayer, bool is_new_phase) if (is_ocean_tile(unit_tile(punit))) { Continent_id continent = tile_continent(unit_tile(punit)); - adv->threats.ocean[-continent] = TRUE; + adv->oceans[-continent].threat = TRUE; } else { adjc_iterate(&(wld.map), unit_tile(punit), tile2) { if (is_ocean_tile(tile2)) { Continent_id continent = tile_continent(tile2); - adv->threats.ocean[-continent] = TRUE; + adv->oceans[-continent].threat = TRUE; } } adjc_iterate_end; } @@ -405,7 +416,7 @@ bool adv_data_phase_init(struct player *pplayer, bool is_new_phase) if (is_ocean_tile(ptile)) { if (adv->explore.sea_done && has_handicap(pplayer, H_TARGETS) && !map_is_known(ptile, pplayer)) { - /* We're not done there. */ + /* We're not done there. */ adv->explore.sea_done = FALSE; adv->explore.ocean[-continent] = TRUE; } @@ -566,11 +577,11 @@ void adv_data_phase_done(struct player *pplayer) free(adv->explore.continent); adv->explore.continent = NULL; - free(adv->threats.continent); - adv->threats.continent = NULL; + free(adv->continents); + adv->continents = NULL; - free(adv->threats.ocean); - adv->threats.ocean = NULL; + free(adv->oceans); + adv->oceans = NULL; free(adv->stats.cities); adv->stats.cities = NULL; diff --git a/server/advisors/advdata.h b/server/advisors/advdata.h index 10271bba0e..97d4ceda52 100644 --- a/server/advisors/advdata.h +++ b/server/advisors/advdata.h @@ -42,6 +42,11 @@ struct adv_dipl { bool allied_with_enemy; }; +struct adv_area_info { + int size; + bool threat; +}; + struct adv_data { /* Whether adv_data_phase_init() has been called or not. */ bool phase_is_initialized; @@ -53,13 +58,14 @@ struct adv_data { enum adv_improvement_status impr_calc[B_LAST]; enum req_range impr_range[B_LAST]; + struct adv_area_info *continents; + struct adv_area_info *oceans; + /* Long-term threats, not to be confused with short-term danger */ struct { bool invasions; /* check if we need to consider invasions */ - bool *continent; /* non-allied cities on continent? */ - bool *ocean; /* non-allied offensive ships in ocean? */ bool suicide_attack; /* check for non-allied missiles */ - int nuclear; /* nuke check: 0=no, 1=capability, 2=built */ + int nuclear; /* nuke check: 0 = no, 1 = capability, 2 = built */ bool igwall; /* enemies have igwall units */ } threats; -- 2.35.1