1
0
Fork 0

Compare commits

...

4 Commits

Author SHA1 Message Date
SamuXarick 22b4b0df0d
Merge f9aef24325 into 7546c1acab 2025-07-14 08:01:51 +00:00
Peter Nelson 7546c1acab
Codefix f220ed179d: GetUnicodeGlyph takes a unicode character. (#14438)
Previous change erroneously changed type to GlyphID, based on naming. It should actually be char32_t.
2025-07-14 08:01:42 +00:00
Peter Nelson a6143eea21
Codechange: Include more relevant headers for script_storage. (#14437) 2025-07-14 07:49:50 +01:00
SamuXarick f9aef24325 Fix: Remove unwanted river artifacts after generation
This requires postponing ModifyDesertZoneAroundRiver to after river generation.
2025-04-24 12:26:28 +01:00
7 changed files with 63 additions and 23 deletions

View File

@ -43,26 +43,26 @@ SpriteFontCache::SpriteFontCache(FontSize fs) : FontCache(fs)
} }
/** /**
* Get SpriteID associated with a GlyphID. * Get SpriteID associated with a character.
* @param key Glyph to find. * @param key Character to find.
* @return SpriteID of glyph, or 0 if not present. * @return SpriteID for character, or 0 if not present.
*/ */
SpriteID SpriteFontCache::GetUnicodeGlyph(GlyphID key) SpriteID SpriteFontCache::GetUnicodeGlyph(char32_t key)
{ {
const auto found = this->glyph_to_spriteid_map.find(key & ~SPRITE_GLYPH); const auto found = this->char_map.find(key);
if (found == std::end(this->glyph_to_spriteid_map)) return 0; if (found == std::end(this->char_map)) return 0;
return found->second; return found->second;
} }
void SpriteFontCache::SetUnicodeGlyph(char32_t key, SpriteID sprite) void SpriteFontCache::SetUnicodeGlyph(char32_t key, SpriteID sprite)
{ {
this->glyph_to_spriteid_map[key] = sprite; this->char_map[key] = sprite;
} }
void SpriteFontCache::InitializeUnicodeGlyphMap() void SpriteFontCache::InitializeUnicodeGlyphMap()
{ {
/* Clear out existing glyph map if it exists */ /* Clear out existing glyph map if it exists */
this->glyph_to_spriteid_map.clear(); this->char_map.clear();
SpriteID base; SpriteID base;
switch (this->fs) { switch (this->fs) {

View File

@ -28,8 +28,8 @@ public:
bool IsBuiltInFont() override { return true; } bool IsBuiltInFont() override { return true; }
private: private:
std::unordered_map<GlyphID, SpriteID> glyph_to_spriteid_map{}; ///< Mapping of glyphs to sprite IDs. std::unordered_map<char32_t, SpriteID> char_map{}; ///< Mapping of characters to sprite IDs.
SpriteID GetUnicodeGlyph(GlyphID key); SpriteID GetUnicodeGlyph(char32_t key);
}; };
#endif /* SPRITEFONTCACHE_H */ #endif /* SPRITEFONTCACHE_H */

View File

@ -1024,7 +1024,8 @@ static void MakeLake(TileIndex tile, uint height_lake)
for (DiagDirection d = DIAGDIR_BEGIN; d < DIAGDIR_END; d++) { for (DiagDirection d = DIAGDIR_BEGIN; d < DIAGDIR_END; d++) {
TileIndex t = tile + TileOffsByDiagDir(d); TileIndex t = tile + TileOffsByDiagDir(d);
if (IsWaterTile(t)) { if (IsWaterTile(t)) {
MakeRiverAndModifyDesertZoneAround(tile); MakeRiver(tile, Random());
MarkTileDirtyByTile(tile);
return; return;
} }
} }
@ -1154,7 +1155,8 @@ static void RiverMakeWider(TileIndex tile, TileIndex origin_tile)
/* If the tile upstream isn't flat, don't bother. */ /* If the tile upstream isn't flat, don't bother. */
if (GetTileSlope(downstream_tile) != SLOPE_FLAT) return; if (GetTileSlope(downstream_tile) != SLOPE_FLAT) return;
MakeRiverAndModifyDesertZoneAround(downstream_tile); MakeRiver(downstream_tile, Random());
MarkTileDirtyByTile(downstream_tile);
} }
/* If upstream is dry and flat, try making it a river tile. */ /* If upstream is dry and flat, try making it a river tile. */
@ -1162,13 +1164,15 @@ static void RiverMakeWider(TileIndex tile, TileIndex origin_tile)
/* If the tile upstream isn't flat, don't bother. */ /* If the tile upstream isn't flat, don't bother. */
if (GetTileSlope(upstream_tile) != SLOPE_FLAT) return; if (GetTileSlope(upstream_tile) != SLOPE_FLAT) return;
MakeRiverAndModifyDesertZoneAround(upstream_tile); MakeRiver(upstream_tile, Random());
MarkTileDirtyByTile(upstream_tile);
} }
} }
/* If the tile slope matches the desired slope, add a river tile. */ /* If the tile slope matches the desired slope, add a river tile. */
if (cur_slope == desired_slope) { if (cur_slope == desired_slope) {
MakeRiverAndModifyDesertZoneAround(tile); MakeRiver(tile, Random());
MarkTileDirtyByTile(tile);
} }
} }
@ -1238,7 +1242,8 @@ protected:
for (PathNode *path = current.parent; path != nullptr; path = path->parent) { for (PathNode *path = current.parent; path != nullptr; path = path->parent) {
TileIndex tile = path->GetTile(); TileIndex tile = path->GetTile();
if (!IsWaterTile(tile)) { if (!IsWaterTile(tile)) {
MakeRiverAndModifyDesertZoneAround(tile); MakeRiver(tile, Random());
MarkTileDirtyByTile(tile);
} }
} }
@ -1356,7 +1361,8 @@ static std::tuple<bool, bool> FlowRiver(TileIndex spring, TileIndex begin, uint
/* We only want a lake if the river is long enough. */ /* We only want a lake if the river is long enough. */
DistanceManhattan(spring, lake_centre) > min_river_length) { DistanceManhattan(spring, lake_centre) > min_river_length) {
end = lake_centre; end = lake_centre;
MakeRiverAndModifyDesertZoneAround(lake_centre); MakeRiver(lake_centre, Random());
MarkTileDirtyByTile(lake_centre);
uint diameter = RandomRange(8) + 3; uint diameter = RandomRange(8) + 3;
/* Run the loop twice, so artefacts from going circular in one direction get (mostly) hidden. */ /* Run the loop twice, so artefacts from going circular in one direction get (mostly) hidden. */
@ -1420,6 +1426,25 @@ static void CreateRivers()
/* Widening rivers may have left some tiles requiring to be watered. */ /* Widening rivers may have left some tiles requiring to be watered. */
ConvertGroundTilesIntoWaterTiles(); ConvertGroundTilesIntoWaterTiles();
/* Search for unwanted pockets of river artifacts to clear them of water. */
for (const auto tile : Map::Iterate()) {
if (!IsTileType(tile, MP_WATER) || !IsRiver(tile)) continue;
bool has_neighbour = false;
for (DiagDirection d = DIAGDIR_BEGIN; d != DIAGDIR_END; d++) {
TileIndex other_tile = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDiagDir(d));
if (other_tile == INVALID_TILE || !IsWaterTile(other_tile)) continue;
has_neighbour = true;
if (_settings_game.game_creation.landscape == LandscapeType::Tropic) ModifyDesertZoneAroundRiver(tile);
break;
}
if (!has_neighbour) {
DoClearSquare(tile);
}
}
/* Run tile loop to update the ground density. */ /* Run tile loop to update the ground density. */
for (uint i = 0; i != TILE_UPDATE_FREQUENCY; i++) { for (uint i = 0; i != TILE_UPDATE_FREQUENCY; i++) {
if (i % 64 == 0) IncreaseGeneratingWorldProgress(GWP_RIVER); if (i % 64 == 0) IncreaseGeneratingWorldProgress(GWP_RIVER);

View File

@ -24,10 +24,12 @@
#include "api/script_event.hpp" #include "api/script_event.hpp"
#include "api/script_log.hpp" #include "api/script_log.hpp"
#include "../company_base.h" #include "../company_type.h"
#include "../company_func.h"
#include "../fileio_func.h" #include "../fileio_func.h"
#include "../goal_type.h"
#include "../league_type.h" #include "../league_type.h"
#include "../signs_type.h"
#include "../story_type.h"
#include "../misc/endian_buffer.hpp" #include "../misc/endian_buffer.hpp"
#include "../safeguards.h" #include "../safeguards.h"

View File

@ -12,12 +12,10 @@
#include <queue> #include <queue>
#include "../signs_func.h" #include "../command_type.h"
#include "../vehicle_func.h" #include "../company_type.h"
#include "../rail_type.h"
#include "../road_type.h" #include "../road_type.h"
#include "../group.h"
#include "../goal_type.h"
#include "../story_type.h"
#include "script_types.hpp" #include "script_types.hpp"
#include "script_log_types.hpp" #include "script_log_types.hpp"

View File

@ -39,6 +39,7 @@ void MakeWaterKeepingClass(TileIndex tile, Owner o);
void CheckForDockingTile(TileIndex t); void CheckForDockingTile(TileIndex t);
void MakeRiverAndModifyDesertZoneAround(TileIndex tile); void MakeRiverAndModifyDesertZoneAround(TileIndex tile);
void ModifyDesertZoneAroundRiver(TileIndex tile);
static const uint RIVER_OFFSET_DESERT_DISTANCE = 5; ///< Circular tile search diameter to create non-desert around a river tile. static const uint RIVER_OFFSET_DESERT_DISTANCE = 5; ///< Circular tile search diameter to create non-desert around a river tile.
bool IsWateredTile(TileIndex tile, Direction from); bool IsWateredTile(TileIndex tile, Direction from);

View File

@ -454,6 +454,20 @@ void MakeRiverAndModifyDesertZoneAround(TileIndex tile)
} }
} }
/**
* Remove desert directly around a river tile.
* @param tile The tile to create non-desert around
*/
void ModifyDesertZoneAroundRiver(TileIndex tile)
{
assert(IsTileType(tile, MP_WATER) && IsRiver(tile));
/* Remove desert directly around the river tile. */
for (auto t : SpiralTileSequence(tile, RIVER_OFFSET_DESERT_DISTANCE)) {
if (GetTropicZone(t) == TROPICZONE_DESERT) SetTropicZone(t, TROPICZONE_NORMAL);
}
}
/** /**
* Build a piece of canal. * Build a piece of canal.
* @param flags type of operation * @param flags type of operation