mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-11 13:10:45 +00:00
Add: [NewGRF] Station property 1E, extended station tile flags.
Properties 11, 14 and 15 to set pylons/nowires/blocked intrinsically only support 8 station tiles.
Add new property to define all three flags for each station tile layout.
(cherry picked from commit a03ddb3ccb
)
# Conflicts:
# src/newgrf.cpp
# src/newgrf_station.h
# src/station_cmd.cpp
This commit is contained in:
parent
c709976703
commit
839ec6f1e8
@ -2062,9 +2062,18 @@ static ChangeInfoResult StationChangeInfo(uint stid, int numinfo, int prop, cons
|
||||
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) {
|
||||
@ -2078,13 +2087,31 @@ static ChangeInfoResult StationChangeInfo(uint stid, int numinfo, int prop, cons
|
||||
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();
|
||||
@ -2147,6 +2174,13 @@ static ChangeInfoResult StationChangeInfo(uint stid, int numinfo, int prop, cons
|
||||
AddStringForMapping(buf->ReadWord(), statspec, [](StringID str, StationSpec *statspec) { StationClass::Get(statspec->class_index)->name = str; });
|
||||
break;
|
||||
|
||||
case 0x1E: { // Extended tile flags (replaces prop 11, 14 and 15)
|
||||
uint16_t tiles = buf->ReadExtendedByte();
|
||||
auto flags = reinterpret_cast<const StationSpec::TileFlags *>(buf->ReadBytes(tiles));
|
||||
statspec->tileflags.assign(flags, flags + tiles);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
ret = HandleAction0PropertyDefault(buf, prop);
|
||||
break;
|
||||
|
@ -1100,9 +1100,9 @@ void UpdateStationTileCacheFlags(bool force_update)
|
||||
if (statspec == nullptr) continue;
|
||||
|
||||
checksum.Update(j);
|
||||
checksum.Update(statspec->blocked);
|
||||
checksum.Update(statspec->pylons);
|
||||
checksum.Update(statspec->wires);
|
||||
for (StationSpec::TileFlags flags : statspec->tileflags) {
|
||||
checksum.Update(static_cast<uint64_t>(flags));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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"
|
||||
@ -131,7 +132,7 @@ struct StationSpec : NewGRFSpecBase<StationClassID> {
|
||||
StationSpec() : 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}), internal_flags(0) {}
|
||||
/**
|
||||
* Properties related the the grf file.
|
||||
@ -175,12 +176,17 @@ struct StationSpec : NewGRFSpecBase<StationClassID> {
|
||||
|
||||
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
|
||||
uint8_t bridge_height[8]; ///< Minimum height for a bridge above, 0 for none
|
||||
uint8_t bridge_disallowed_pillars[8]; ///< Disallowed pillar flags for a bridge above
|
||||
|
||||
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> tileflags; ///< List of tile flags.
|
||||
|
||||
AnimationInfo animation;
|
||||
|
||||
uint8_t internal_flags; ///< Bitmask of internal spec flags (StationSpecIntlFlags)
|
||||
@ -195,6 +201,7 @@ struct StationSpec : NewGRFSpecBase<StationClassID> {
|
||||
*/
|
||||
std::vector<std::vector<std::vector<uint8_t>>> layouts;
|
||||
};
|
||||
DECLARE_ENUM_AS_BIT_SET(StationSpec::TileFlags);
|
||||
|
||||
/** Class containing information relating to station classes. */
|
||||
using StationClass = NewGRFClass<StationSpec, StationClassID, STAT_CLASS_MAX>;
|
||||
|
@ -71,6 +71,8 @@
|
||||
|
||||
#include "safeguards.h"
|
||||
|
||||
static StationSpec::TileFlags GetStationTileFlags(StationGfx gfx, const StationSpec *statspec);
|
||||
|
||||
bool _town_noise_no_update = false;
|
||||
|
||||
/**
|
||||
@ -945,7 +947,7 @@ CommandCost IsRailStationBridgeAboveOk(TileIndex tile, const StationSpec *statsp
|
||||
// default stations/waypoints
|
||||
static const uint8_t st_flags[8] = { 0x50, 0xA0, 0x50, 0xA0, 0x50 | 0x26, 0xA0 | 0x1C, 0x50 | 0x89, 0xA0 | 0x43 };
|
||||
disallowed_pillar_flags = (BridgePiecePillarFlags) st_flags[layout];
|
||||
} else if (HasBit(statspec->blocked, layout)) {
|
||||
} else if ((GetStationTileFlags(layout, statspec) & StationSpec::TileFlags::Blocked) == StationSpec::TileFlags::Blocked) {
|
||||
// non-track station tiles
|
||||
disallowed_pillar_flags = (BridgePiecePillarFlags) 0;
|
||||
} else {
|
||||
@ -1458,6 +1460,19 @@ static void RestoreTrainReservation(Train *v)
|
||||
if (IsRailStationTile(v->tile)) SetRailStationPlatformReservation(v->tile, TrackdirToExitdir(ReverseTrackdir(v->GetVehicleTrackdir())), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get station tile flags for the given StationGfx.
|
||||
* @param gfx StationGfx of station tile.
|
||||
* @param statspec Station spec of station tile.
|
||||
* @return Tile flags to apply.
|
||||
*/
|
||||
static StationSpec::TileFlags GetStationTileFlags(StationGfx gfx, const StationSpec *statspec)
|
||||
{
|
||||
/* 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.
|
||||
@ -1465,15 +1480,10 @@ static void RestoreTrainReservation(Train *v)
|
||||
*/
|
||||
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);
|
||||
const auto flags = GetStationTileFlags(GetStationGfx(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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user