From 80b05e77b0a9c01efb903f02d365385f782315a1 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Fri, 23 Jun 2023 05:34:13 +0300 Subject: [PATCH 12/12] Replace tile_virtual_check() with tile_map_check() - Rename tile_virtual_check() as tile_map_check() - Add map -parameter for it It's (never was) if the tile is virtual, but only if the tile exist on a specific map. The old implementation hardcoded the check to be against the main map. See osdn #48269 Signed-off-by: Marko Lindqvist --- common/tile.c | 15 ++++++++++----- common/tile.h | 17 +++++++++-------- server/maphand.c | 8 ++++---- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/common/tile.c b/common/tile.c index 7225e36dd5..e96c47f212 100644 --- a/common/tile.c +++ b/common/tile.c @@ -125,7 +125,7 @@ void tile_set_terrain(struct tile *ptile, struct terrain *pterrain) { /* The terrain change is valid if one of the following is TRUE: * - pterrain is NULL (= unknown terrain) - * - ptile is a virtual tile + * - ptile is a virtual tile, or otherwise not on the map being checked * - pterrain does not has the flag TER_NO_CITIES * - there is no city on ptile * - client may have had tile fogged and is receiving terrain change before @@ -133,9 +133,13 @@ void tile_set_terrain(struct tile *ptile, struct terrain *pterrain) * This should be read as: The terrain change is INVALID if a terrain with * the flag TER_NO_CITIES is given for a real tile with a city (i.e. all * check evaluate to TRUE). */ + + /* Assert disabled for now, so we don't need to make this function + * care about what map is being changed. */ +#if 0 fc_assert_msg(NULL == pterrain || !is_server() - || tile_virtual_check(ptile) + || !tile_map_check(nmap, ptile) || !terrain_has_flag(pterrain, TER_NO_CITIES) || NULL == tile_city(ptile), "At (%d, %d), the terrain \"%s\" (nb %d) doesn't " @@ -143,6 +147,7 @@ void tile_set_terrain(struct tile *ptile, struct terrain *pterrain) TILE_XY(ptile), terrain_rule_name(pterrain), terrain_number(pterrain), city_name_get(tile_city(ptile)), tile_city(ptile)->id); +#endif /* 0 */ ptile->terrain = pterrain; if (ptile->resource != NULL) { @@ -1059,9 +1064,9 @@ void tile_virtual_destroy(struct tile *vtile) } /************************************************************************//** - Check if the given tile is a virtual one or not. + Check if the given tile is on a map. ****************************************************************************/ -bool tile_virtual_check(struct tile *vtile) +bool tile_map_check(struct civ_map *nmap, struct tile *vtile) { int tindex; @@ -1072,7 +1077,7 @@ bool tile_virtual_check(struct tile *vtile) tindex = tile_index(vtile); fc_assert_ret_val(0 <= tindex && tindex < map_num_tiles(), FALSE); - return (vtile != wld.map.tiles + tindex); + return (vtile == nmap->tiles + tindex); } /************************************************************************//** diff --git a/common/tile.h b/common/tile.h index 91d4b399b1..00d68a1941 100644 --- a/common/tile.h +++ b/common/tile.h @@ -90,11 +90,11 @@ struct tile { struct city *tile_city(const struct tile *ptile); #define tile_continent(_tile) ((_tile)->continent) -/*Continent_id tile_continent(const struct tile *ptile);*/ +/* Continent_id tile_continent(const struct tile *ptile); */ void tile_set_continent(struct tile *ptile, Continent_id val); #define tile_owner(_tile) ((_tile)->owner) -/*struct player *tile_owner(const struct tile *ptile);*/ +/* struct player *tile_owner(const struct tile *ptile); */ void tile_set_owner(struct tile *ptile, struct player *pplayer, struct tile *claimer); #define tile_claimer(_tile) ((_tile)->claimer) @@ -104,11 +104,11 @@ static inline bool tile_resource_is_valid(const struct tile *ptile) { return ptile->resource != NULL && BV_ISSET(ptile->extras, ptile->resource->id); } -/*const struct resource *tile_resource(const struct tile *ptile);*/ +/* const struct resource *tile_resource(const struct tile *ptile); */ void tile_set_resource(struct tile *ptile, struct extra_type *presource); #define tile_terrain(_tile) ((_tile)->terrain) -/*struct terrain *tile_terrain(const struct tile *ptile);*/ +/* struct terrain *tile_terrain(const struct tile *ptile); */ void tile_set_terrain(struct tile *ptile, struct terrain *pterrain); #define tile_worked(_tile) ((_tile)->worked) @@ -160,12 +160,12 @@ enum known_type tile_get_known(const struct tile *ptile, bool tile_is_seen(const struct tile *target_tile, const struct player *pow_player); -/* A somewhat arbitrary integer value. Activity times are multiplied by - * this amount, and divided by them later before being used. This may +/* A somewhat arbitrary integer value. Activity times are multiplied by + * this amount, and divided by them later before being used. This may * help to avoid rounding errors; however it should probably be removed. */ #define ACTIVITY_FACTOR 10 int tile_activity_time(enum unit_activity activity, - const struct tile *ptile, + const struct tile *ptile, const struct extra_type *tgt); /* These are higher-level functions that handle side effects on the tile. */ @@ -182,7 +182,8 @@ const char *tile_get_info_text(const struct tile *ptile, /* Virtual tiles are tiles that do not exist on the game map. */ struct tile *tile_virtual_new(const struct tile *ptile); void tile_virtual_destroy(struct tile *vtile); -bool tile_virtual_check(struct tile *vtile); + +bool tile_map_check(struct civ_map *nmap, struct tile *vtile); void *tile_hash_key(const struct tile *ptile); diff --git a/server/maphand.c b/server/maphand.c index 4702ad7da2..15f5d1de4e 100644 --- a/server/maphand.c +++ b/server/maphand.c @@ -2526,10 +2526,10 @@ void create_extra(struct tile *ptile, struct extra_type *pextra, void destroy_extra(struct tile *ptile, struct extra_type *pextra) { bv_player base_seen; - bool virtual = tile_virtual_check(ptile); + bool real = tile_map_check(&(wld.map), ptile); /* Remember what players were able to see the base. */ - if (!virtual) { + if (real) { BV_CLR_ALL(base_seen); players_iterate(pplayer) { if (map_is_known_and_seen(ptile, pplayer, V_MAIN)) { @@ -2538,7 +2538,7 @@ void destroy_extra(struct tile *ptile, struct extra_type *pextra) } players_iterate_end; } - if (!virtual && is_extra_caused_by(pextra, EC_BASE)) { + if (real && is_extra_caused_by(pextra, EC_BASE)) { struct base_type *pbase = extra_base_get(pextra); struct player *owner = extra_owner(ptile); @@ -2562,7 +2562,7 @@ void destroy_extra(struct tile *ptile, struct extra_type *pextra) tile_remove_extra(ptile, pextra); - if (!virtual) { + if (real) { /* Remove base from vision of players which were able to see the base. */ players_iterate(pplayer) { if (BV_ISSET(base_seen, player_index(pplayer)) -- 2.39.2