mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2026-07-24 03:56:43 +00:00
Codechange: make CanalFeature a scoped enum
This commit is contained in:
+1
-1
@@ -849,7 +849,7 @@ static void CalculateRefitMasks()
|
||||
/** Set to use the correct action0 properties for each canal feature */
|
||||
static void FinaliseCanals()
|
||||
{
|
||||
for (CanalFeature i : EnumRange(CF_END)) {
|
||||
for (CanalFeature i : EnumRange(CanalFeature::End)) {
|
||||
if (_water_feature[i].grffile != nullptr) {
|
||||
_water_feature[i].callback_mask = _water_feature[i].grffile->canal_local_properties[i].callback_mask;
|
||||
_water_feature[i].flags = _water_feature[i].grffile->canal_local_properties[i].flags;
|
||||
|
||||
+13
-13
@@ -26,21 +26,21 @@ struct GRFConfig;
|
||||
* List of different canal 'features'.
|
||||
* Each feature gets an entry in the canal spritegroup table
|
||||
*/
|
||||
enum CanalFeature : uint8_t {
|
||||
CF_WATERSLOPE,
|
||||
CF_LOCKS,
|
||||
CF_DIKES,
|
||||
CF_ICON,
|
||||
CF_DOCKS,
|
||||
CF_RIVER_SLOPE,
|
||||
CF_RIVER_EDGE,
|
||||
CF_RIVER_GUI,
|
||||
CF_BUOY,
|
||||
CF_END,
|
||||
enum class CanalFeature : uint8_t {
|
||||
LockWaterSlope, ///< The sloped water tiles in locks.
|
||||
Locks, ///< The sides of the lock.
|
||||
Dikes, ///< The canal dikes/embankment.
|
||||
Icon, ///< Unused: the TTDP UI icon for canals.
|
||||
FlatDocks, ///< Unused: the graphics for TTDP flat docks.
|
||||
RiverSlope, ///< The sloped water tiles for rivers.
|
||||
RiverEdge, ///< The river banks.
|
||||
RiverIcon, ///< Unused: the TTDP UI icons for rivers.
|
||||
Buoy, ///< Buoy without underlying water.
|
||||
End, ///< End marker.
|
||||
};
|
||||
|
||||
/** Flags controlling the display of canals. */
|
||||
enum CanalFeatureFlag : uint8_t {
|
||||
enum class CanalFeatureFlag : uint8_t {
|
||||
HasFlatSprite = 0, ///< Additional flat ground sprite in the beginning.
|
||||
};
|
||||
/** CanalFeatureFlag bitmask. */
|
||||
@@ -161,7 +161,7 @@ struct GRFFile {
|
||||
std::vector<RoadTypeLabel> tramtype_list{}; ///< Roadtype translation table (tram)
|
||||
std::array<RoadType, ROADTYPE_END> tramtype_map{};
|
||||
|
||||
std::array<CanalProperties, CF_END> canal_local_properties{}; ///< Canal properties as set by this NewGRF
|
||||
EnumIndexArray<CanalProperties, CanalFeature, CanalFeature::End> canal_local_properties{}; ///< Canal properties as set by this NewGRF
|
||||
|
||||
std::unordered_map<uint8_t, LanguageMap> language_map{}; ///< Mappings related to the languages.
|
||||
|
||||
|
||||
@@ -26,13 +26,13 @@ static ChangeInfoResult CanalChangeInfo(uint first, uint last, int prop, ByteRea
|
||||
{
|
||||
ChangeInfoResult ret = ChangeInfoResult::Success;
|
||||
|
||||
if (last > CF_END) {
|
||||
GrfMsg(1, "CanalChangeInfo: Canal feature 0x{:02X} is invalid, max {}, ignoring", last, CF_END);
|
||||
if (last > to_underlying(CanalFeature::End)) {
|
||||
GrfMsg(1, "CanalChangeInfo: Canal feature 0x{:02X} is invalid, max {}, ignoring", last, CanalFeature::End);
|
||||
return ChangeInfoResult::InvalidId;
|
||||
}
|
||||
|
||||
for (uint id = first; id < last; ++id) {
|
||||
CanalProperties *cp = &_cur_gps.grffile->canal_local_properties[id];
|
||||
CanalProperties *cp = &_cur_gps.grffile->canal_local_properties[static_cast<CanalFeature>(id)];
|
||||
|
||||
switch (prop) {
|
||||
case 0x08:
|
||||
|
||||
@@ -244,11 +244,12 @@ struct CanalMapSpriteGroupHandler : MapSpriteGroupHandler {
|
||||
|
||||
void MapDefault(uint16_t local_id, const SpriteGroup *group) override
|
||||
{
|
||||
if (local_id >= CF_END) {
|
||||
if (local_id >= to_underlying(CanalFeature::End)) {
|
||||
GrfMsg(1, "CanalMapSpriteGroup: Canal subset {} out of range, skipping", local_id);
|
||||
} else {
|
||||
_water_feature[local_id].grffile = _cur_gps.grffile;
|
||||
_water_feature[local_id].group = group;
|
||||
auto &feature = _water_feature[static_cast<CanalFeature>(local_id)];
|
||||
feature.grffile = _cur_gps.grffile;
|
||||
feature.group = group;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include "safeguards.h"
|
||||
|
||||
/** Table of canal 'feature' sprite groups */
|
||||
std::array<WaterFeature, CF_END> _water_feature;
|
||||
EnumIndexArray<WaterFeature, CanalFeature, CanalFeature::End> _water_feature;
|
||||
|
||||
/** Scope resolver of a canal tile. */
|
||||
struct CanalScopeResolver : public ScopeResolver {
|
||||
@@ -112,7 +112,7 @@ GrfSpecFeature CanalResolverObject::GetFeature() const
|
||||
|
||||
uint32_t CanalResolverObject::GetDebugID() const
|
||||
{
|
||||
return this->feature;
|
||||
return to_underlying(this->feature);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ struct WaterFeature {
|
||||
|
||||
|
||||
/** Table of canal 'feature' sprite groups */
|
||||
extern std::array<WaterFeature, CF_END> _water_feature;
|
||||
extern EnumIndexArray<WaterFeature, CanalFeature, CanalFeature::End> _water_feature;
|
||||
|
||||
|
||||
SpriteID GetCanalSprite(CanalFeature feature, TileIndex tile);
|
||||
|
||||
+1
-1
@@ -3376,7 +3376,7 @@ static void DrawTile_Station(TileInfo *ti)
|
||||
|
||||
if (IsBuoy(ti->tile)) {
|
||||
DrawWaterClassGround(ti);
|
||||
SpriteID sprite = GetCanalSprite(CF_BUOY, ti->tile);
|
||||
SpriteID sprite = GetCanalSprite(CanalFeature::Buoy, ti->tile);
|
||||
if (sprite != 0) total_offset = sprite - SPR_IMG_BUOY;
|
||||
} else if (IsDock(ti->tile) || (IsOilRig(ti->tile) && IsTileOnWater(ti->tile))) {
|
||||
if (ti->tileh == SLOPE_FLAT) {
|
||||
|
||||
+17
-17
@@ -763,12 +763,12 @@ static void DrawWaterEdges(bool canal, uint offset, TileIndex tile)
|
||||
CanalFeature feature;
|
||||
SpriteID base = 0;
|
||||
if (canal) {
|
||||
feature = CF_DIKES;
|
||||
base = GetCanalSprite(CF_DIKES, tile);
|
||||
feature = CanalFeature::Dikes;
|
||||
base = GetCanalSprite(CanalFeature::Dikes, tile);
|
||||
if (base == 0) base = SPR_CANAL_DIKES_BASE;
|
||||
} else {
|
||||
feature = CF_RIVER_EDGE;
|
||||
base = GetCanalSprite(CF_RIVER_EDGE, tile);
|
||||
feature = CanalFeature::RiverEdge;
|
||||
base = GetCanalSprite(CanalFeature::RiverEdge, tile);
|
||||
if (base == 0) return; // Don't draw if no sprites provided.
|
||||
}
|
||||
|
||||
@@ -823,12 +823,12 @@ static void DrawSeaWater(TileIndex)
|
||||
static void DrawCanalWater(TileIndex tile)
|
||||
{
|
||||
SpriteID image = SPR_FLAT_WATER_TILE;
|
||||
if (_water_feature[CF_WATERSLOPE].flags.Test(CanalFeatureFlag::HasFlatSprite)) {
|
||||
if (_water_feature[CanalFeature::LockWaterSlope].flags.Test(CanalFeatureFlag::HasFlatSprite)) {
|
||||
/* First water slope sprite is flat water. */
|
||||
image = GetCanalSprite(CF_WATERSLOPE, tile);
|
||||
image = GetCanalSprite(CanalFeature::LockWaterSlope, tile);
|
||||
if (image == 0) image = SPR_FLAT_WATER_TILE;
|
||||
}
|
||||
DrawWaterSprite(image, 0, CF_WATERSLOPE, tile);
|
||||
DrawWaterSprite(image, 0, CanalFeature::LockWaterSlope, tile);
|
||||
|
||||
DrawWaterEdges(true, 0, tile);
|
||||
}
|
||||
@@ -852,7 +852,7 @@ static void DrawWaterTileStruct(const TileInfo *ti, std::span<const DrawTileSeqS
|
||||
|
||||
for (const DrawTileSeqStruct &dtss : seq) {
|
||||
uint tile_offs = offset + dtss.image.sprite;
|
||||
if (feature < CF_END) tile_offs = GetCanalSpriteOffset(feature, ti->tile, tile_offs);
|
||||
if (feature < CanalFeature::End) tile_offs = GetCanalSpriteOffset(feature, ti->tile, tile_offs);
|
||||
AddSortableSpriteToDraw(base + tile_offs, palette, *ti, dtss, IsTransparencySet(TransparencyOption::Buildings));
|
||||
}
|
||||
}
|
||||
@@ -869,11 +869,11 @@ static void DrawWaterLock(const TileInfo *ti)
|
||||
/* Draw ground sprite. */
|
||||
SpriteID image = dts.ground.sprite;
|
||||
|
||||
SpriteID water_base = GetCanalSprite(CF_WATERSLOPE, ti->tile);
|
||||
SpriteID water_base = GetCanalSprite(CanalFeature::LockWaterSlope, ti->tile);
|
||||
if (water_base == 0) {
|
||||
/* Use default sprites. */
|
||||
water_base = SPR_CANALS_BASE;
|
||||
} else if (_water_feature[CF_WATERSLOPE].flags.Test(CanalFeatureFlag::HasFlatSprite)) {
|
||||
} else if (_water_feature[CanalFeature::LockWaterSlope].flags.Test(CanalFeatureFlag::HasFlatSprite)) {
|
||||
/* NewGRF supplies a flat sprite as first sprite. */
|
||||
if (image == SPR_FLAT_WATER_TILE) {
|
||||
image = water_base;
|
||||
@@ -887,7 +887,7 @@ static void DrawWaterLock(const TileInfo *ti)
|
||||
|
||||
/* Draw structures. */
|
||||
uint zoffs = 0;
|
||||
SpriteID base = GetCanalSprite(CF_LOCKS, ti->tile);
|
||||
SpriteID base = GetCanalSprite(CanalFeature::Locks, ti->tile);
|
||||
|
||||
if (base == 0) {
|
||||
/* If no custom graphics, use defaults. */
|
||||
@@ -896,7 +896,7 @@ static void DrawWaterLock(const TileInfo *ti)
|
||||
zoffs = ti->z > z_threshold ? 24 : 0;
|
||||
}
|
||||
|
||||
DrawWaterTileStruct(ti, dts.GetSequence(), base, zoffs, PAL_NONE, CF_LOCKS);
|
||||
DrawWaterTileStruct(ti, dts.GetSequence(), base, zoffs, PAL_NONE, CanalFeature::Locks);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -906,7 +906,7 @@ static void DrawWaterLock(const TileInfo *ti)
|
||||
static void DrawWaterDepot(const TileInfo *ti)
|
||||
{
|
||||
DrawWaterClassGround(ti);
|
||||
DrawWaterTileStruct(ti, _shipdepot_display_data[GetShipDepotAxis(ti->tile)][GetShipDepotPart(ti->tile)].seq, 0, 0, GetCompanyPalette(GetTileOwner(ti->tile)), CF_END);
|
||||
DrawWaterTileStruct(ti, _shipdepot_display_data[GetShipDepotAxis(ti->tile)][GetShipDepotPart(ti->tile)].seq, 0, 0, GetCompanyPalette(GetTileOwner(ti->tile)), CanalFeature::End);
|
||||
}
|
||||
|
||||
static void DrawRiverWater(const TileInfo *ti)
|
||||
@@ -915,8 +915,8 @@ static void DrawRiverWater(const TileInfo *ti)
|
||||
uint offset = 0;
|
||||
uint edges_offset = 0;
|
||||
|
||||
if (ti->tileh != SLOPE_FLAT || _water_feature[CF_RIVER_SLOPE].flags.Test(CanalFeatureFlag::HasFlatSprite)) {
|
||||
image = GetCanalSprite(CF_RIVER_SLOPE, ti->tile);
|
||||
if (ti->tileh != SLOPE_FLAT || _water_feature[CanalFeature::RiverSlope].flags.Test(CanalFeatureFlag::HasFlatSprite)) {
|
||||
image = GetCanalSprite(CanalFeature::RiverSlope, ti->tile);
|
||||
if (image == 0) {
|
||||
switch (ti->tileh) {
|
||||
case SLOPE_NW: image = SPR_WATER_SLOPE_Y_DOWN; break;
|
||||
@@ -927,7 +927,7 @@ static void DrawRiverWater(const TileInfo *ti)
|
||||
}
|
||||
} else {
|
||||
/* Flag bit 0 indicates that the first sprite is flat water. */
|
||||
offset = _water_feature[CF_RIVER_SLOPE].flags.Test(CanalFeatureFlag::HasFlatSprite) ? 1 : 0;
|
||||
offset = _water_feature[CanalFeature::RiverSlope].flags.Test(CanalFeatureFlag::HasFlatSprite) ? 1 : 0;
|
||||
|
||||
switch (ti->tileh) {
|
||||
case SLOPE_SE: edges_offset += 12; break;
|
||||
@@ -937,7 +937,7 @@ static void DrawRiverWater(const TileInfo *ti)
|
||||
default: offset = 0; break;
|
||||
}
|
||||
|
||||
offset = GetCanalSpriteOffset(CF_RIVER_SLOPE, ti->tile, offset);
|
||||
offset = GetCanalSpriteOffset(CanalFeature::RiverSlope, ti->tile, offset);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user