diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 31963f5d27..bf7a34269f 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -2070,9 +2070,18 @@ static ChangeInfoResult StationChangeInfo(uint stid, int numinfo, int prop, Byte statspec->cargo_threshold = buf->ReadWord(); break; - case 0x11: // Pylon placement - statspec->pylons = buf->ReadByte(); + case 0x11: { // Pylon placement + uint8_t pylons = buf->ReadByte(); + if (statspec->tileflags.size() < 8) statspec->tileflags.resize(8); + for (int j = 0; j < 8; ++j) { + if (HasBit(pylons, j)) { + statspec->tileflags[j] |= StationSpec::TileFlags::Pylons; + } else { + statspec->tileflags[j] &= ~StationSpec::TileFlags::Pylons; + } + } break; + } case 0x12: // Cargo types for random triggers if (_cur.grffile->grf_version >= 7) { @@ -2086,13 +2095,31 @@ static ChangeInfoResult StationChangeInfo(uint stid, int numinfo, int prop, Byte statspec->flags = buf->ReadByte(); break; - case 0x14: // Overhead wire placement - statspec->wires = buf->ReadByte(); + case 0x14: { // Overhead wire placement + uint8_t wires = buf->ReadByte(); + if (statspec->tileflags.size() < 8) statspec->tileflags.resize(8); + for (int j = 0; j < 8; ++j) { + if (HasBit(wires, j)) { + statspec->tileflags[j] |= StationSpec::TileFlags::NoWires; + } else { + statspec->tileflags[j] &= ~StationSpec::TileFlags::NoWires; + } + } break; + } - case 0x15: // Blocked tiles - statspec->blocked = buf->ReadByte(); + case 0x15: { // Blocked tiles + uint8_t blocked = buf->ReadByte(); + if (statspec->tileflags.size() < 8) statspec->tileflags.resize(8); + for (int j = 0; j < 8; ++j) { + if (HasBit(blocked, j)) { + statspec->tileflags[j] |= StationSpec::TileFlags::Blocked; + } else { + statspec->tileflags[j] &= ~StationSpec::TileFlags::Blocked; + } + } break; + } case 0x16: // Animation info statspec->animation.frames = buf->ReadByte(); @@ -2144,6 +2171,13 @@ static ChangeInfoResult StationChangeInfo(uint stid, int numinfo, int prop, Byte AddStringForMapping(buf->ReadWord(), [statspec](StringID str) { StationClass::Get(statspec->cls_id)->name = str; }); break; + case 0x1E: { // Extended tile flags (replaces prop 11, 14 and 15) + uint16_t tiles = buf->ReadExtendedByte(); + auto flags = reinterpret_cast(buf->ReadBytes(tiles)); + statspec->tileflags.assign(flags, flags + tiles); + break; + } + default: ret = CIR_UNKNOWN; break; diff --git a/src/newgrf_station.h b/src/newgrf_station.h index f1c619153e..a2da7537ef 100644 --- a/src/newgrf_station.h +++ b/src/newgrf_station.h @@ -10,6 +10,7 @@ #ifndef NEWGRF_STATION_H #define NEWGRF_STATION_H +#include "core/enum_type.hpp" #include "newgrf_animation_type.h" #include "newgrf_callbacks.h" #include "newgrf_class.h" @@ -112,7 +113,7 @@ struct StationSpec { StationSpec() : cls_id(STAT_CLASS_DFLT), name(0), disallowed_platforms(0), disallowed_lengths(0), cargo_threshold(0), cargo_triggers(0), - callback_mask(0), flags(0), pylons(0), wires(0), blocked(0), + callback_mask(0), flags(0), animation({0, 0, 0, 0}) {} /** * Properties related the the grf file. @@ -157,9 +158,13 @@ struct StationSpec { uint8_t flags; ///< Bitmask of flags, bit 0: use different sprite set; bit 1: divide cargo about by station size - uint8_t pylons; ///< Bitmask of base tiles (0 - 7) which should contain elrail pylons - uint8_t wires; ///< Bitmask of base tiles (0 - 7) which should contain elrail wires - uint8_t blocked; ///< Bitmask of base tiles (0 - 7) which are blocked to trains + enum class TileFlags : uint8_t { + None = 0, + Pylons = 1U << 0, ///< Tile should contain catenary pylons. + NoWires = 1U << 1, ///< Tile should NOT contain catenary wires. + Blocked = 1U << 2, ///< Tile is blocked to vehicles. + }; + std::vector tileflags; ///< List of tile flags. AnimationInfo animation; @@ -173,6 +178,7 @@ struct StationSpec { */ std::vector>> layouts; }; +DECLARE_ENUM_AS_BIT_SET(StationSpec::TileFlags); /** Class containing information relating to station classes. */ using StationClass = NewGRFClass; diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 2e3e397be0..ad6a719882 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -1294,6 +1294,14 @@ static CommandCost CalculateRailStationCost(TileArea tile_area, DoCommandFlag fl return cost; } +StationSpec::TileFlags GetStationTileFlags(TileIndex tile, const StationSpec *statspec) +{ + const StationGfx gfx = GetStationGfx(tile); + /* Default stations do not draw pylons under roofs (gfx >= 4) */ + if (statspec == nullptr || gfx >= statspec->tileflags.size()) return gfx < 4 ? StationSpec::TileFlags::Pylons : StationSpec::TileFlags::None; + return statspec->tileflags[gfx]; +} + /** * Set rail station tile flags for the given tile. * @param tile Tile to set flags on. @@ -1301,15 +1309,10 @@ static CommandCost CalculateRailStationCost(TileArea tile_area, DoCommandFlag fl */ void SetRailStationTileFlags(TileIndex tile, const StationSpec *statspec) { - const StationGfx gfx = GetStationGfx(tile); - bool blocked = statspec != nullptr && HasBit(statspec->blocked, gfx); - /* Default stations do not draw pylons under roofs (gfx >= 4) */ - bool pylons = statspec != nullptr ? HasBit(statspec->pylons, gfx) : gfx < 4; - bool wires = statspec == nullptr || !HasBit(statspec->wires, gfx); - - SetStationTileBlocked(tile, blocked); - SetStationTileHavePylons(tile, pylons); - SetStationTileHaveWires(tile, wires); + auto flags = GetStationTileFlags(tile, statspec); + SetStationTileBlocked(tile, (flags & StationSpec::TileFlags::Blocked) == StationSpec::TileFlags::Blocked); + SetStationTileHavePylons(tile, (flags & StationSpec::TileFlags::Pylons) == StationSpec::TileFlags::Pylons); + SetStationTileHaveWires(tile, (flags & StationSpec::TileFlags::NoWires) != StationSpec::TileFlags::NoWires); } /**