From 27743734dea2dc6fd933d55fb939efd8602208eb Mon Sep 17 00:00:00 2001 From: Ihnatus Date: Thu, 20 Oct 2022 22:23:49 +0300 Subject: [PATCH] Add "Tile" range to "Building" reqs Is true iff there is a city on the context tile and it has the building. See OSDN#45885 Signed-off-by: Ihnatus --- common/metaknowledge.c | 44 ++++++++++++++++++++++++++++++++++++++++++ common/reqtext.c | 13 +++++++++++++ common/requirements.c | 15 ++++++++++++-- doc/README.effects | 3 ++- 4 files changed, 72 insertions(+), 3 deletions(-) diff --git a/common/metaknowledge.c b/common/metaknowledge.c index a5225027c2..687cf0a041 100644 --- a/common/metaknowledge.c +++ b/common/metaknowledge.c @@ -470,6 +470,50 @@ static bool is_req_knowable(const struct player *pov_player, /* No way to know if a city has an improvement */ return FALSE; case REQ_RANGE_TILE: + if (context->tile == NULL) { + /* RPT_CERTAIN: Can't be. No tile to contain it. + * RPT_POSSIBLE: A tile city like that may exist but not be passed. */ + return prob_type == RPT_CERTAIN; + } + + { + const struct city *tcity = tile_city(context->tile); + + if (!tcity) { + /* No building can be in no city if it's known + * there is no city */ + if (is_great_wonder(req->source.value.building)) { + const struct city *wcity + = city_from_great_wonder(req->source.value.building); + + if (!wcity + || player_can_see_city_externals(pov_player, wcity)) { + /* Player can be sure the wonder is not here */ + return TRUE; + /* FIXME: deducing from known borders aside, the player + * may have seen wcity before and cities don't move */ + } + } + + return tile_is_seen(context->tile, pov_player); + } + + if (can_player_see_city_internals(pov_player, tcity)) { + /* Anyone that can see city internals (like the owner) known all + * its improvements. */ + return TRUE; + } + + if (is_improvement_visible(req->source.value.building) + && player_can_see_city_externals(pov_player, tcity)) { + /* Can see visible improvements when the outside of the city is + * seen. */ + return TRUE; + } + } + + /* No way to know if a city has an improvement */ + return FALSE; case REQ_RANGE_CADJACENT: case REQ_RANGE_ADJACENT: case REQ_RANGE_COUNT: diff --git a/common/reqtext.c b/common/reqtext.c index e6139b1a95..8e81381183 100644 --- a/common/reqtext.c +++ b/common/reqtext.c @@ -782,6 +782,19 @@ bool req_text_insert(char *buf, size_t bufsz, struct player *pplayer, } return TRUE; case REQ_RANGE_TILE: + fc_strlcat(buf, prefix, bufsz); + if (preq->present) { + cat_snprintf(buf, bufsz, + _("Requires \"%s\" building in a city on the tile."), + improvement_name_translation + (preq->source.value.building)); + } else { + cat_snprintf(buf, bufsz, + _("Prevented by \"%s\" building in a city on the tile."), + improvement_name_translation + (preq->source.value.building)); + } + return TRUE; case REQ_RANGE_CADJACENT: case REQ_RANGE_ADJACENT: case REQ_RANGE_COUNT: diff --git a/common/requirements.c b/common/requirements.c index b546af9334..e55039613a 100644 --- a/common/requirements.c +++ b/common/requirements.c @@ -1635,6 +1635,7 @@ static enum fc_tristate is_building_in_range(const struct player *target_player, const struct city *target_city, const struct impr_type *target_building, + const struct tile *target_tile, enum req_range range, bool survives, const struct impr_type *source) @@ -1749,9 +1750,19 @@ is_building_in_range(const struct player *target_player, return TRI_MAYBE; } case REQ_RANGE_TILE: + if (target_tile) { + const struct city *pcity = tile_city(target_tile); + + if (pcity) { + return BOOL_TO_TRISTATE(num_city_buildings(pcity, source) > 0); + } else { + return TRI_NO; + } + } else { + return TRI_MAYBE; + } case REQ_RANGE_CADJACENT: case REQ_RANGE_ADJACENT: - return TRI_NO; case REQ_RANGE_COUNT: break; } @@ -3552,7 +3563,7 @@ bool is_req_active(const struct req_context *context, break; case VUT_IMPROVEMENT: eval = is_building_in_range(context->player, context->city, - context->building, + context->building, context->tile, req->range, req->survives, req->source.value.building); break; diff --git a/doc/README.effects b/doc/README.effects index c89698387a..836f46cbf0 100644 --- a/doc/README.effects +++ b/doc/README.effects @@ -56,7 +56,8 @@ MinTechs: World, Player Achievement: World, Alliance, Team, Player Counter: City Gov: Player -Building: World, Alliance, Team, Player, Continent, Traderoute, City, Local +Building: World, Alliance, Team, Player, Continent, Traderoute, City, + Tile, Local BuildingGenus: Local Extra: Local, Tile, Adjacent, CAdjacent, Traderoute, City RoadFlag: Local, Tile, Adjacent, CAdjacent, Traderoute, City -- 2.34.1