mirror of https://github.com/OpenTTD/OpenTTD
Compare commits
4 Commits
feaeda8fd0
...
3c5fcdefe1
Author | SHA1 | Date |
---|---|---|
|
3c5fcdefe1 | |
|
10eeba86a6 | |
|
d99dad9e9e | |
|
13f24c25ca |
|
@ -193,6 +193,7 @@ static uint32_t GetAirportTileIDAtOffset(TileIndex tile, const Station *st, uint
|
|||
/* Get airport tile ID at offset */
|
||||
case 0x62: return GetAirportTileIDAtOffset(GetNearbyTile(parameter, this->tile), this->st, this->ro.grffile->grfid);
|
||||
|
||||
case 0x79: return GetNearbyBadgeVariableResult(*this->ro.grffile, GetNearbyTile(parameter, this->tile), this->ro);
|
||||
case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, this->ats->badges, parameter);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,13 +8,25 @@
|
|||
/** @file newgrf_badge.cpp Functionality for NewGRF badges. */
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "house.h"
|
||||
#include "industry_map.h"
|
||||
#include "newgrf.h"
|
||||
#include "newgrf_airporttiles.h"
|
||||
#include "newgrf_badge.h"
|
||||
#include "newgrf_badge_type.h"
|
||||
#include "newgrf_object.h"
|
||||
#include "newgrf_roadstop.h"
|
||||
#include "newgrf_station.h"
|
||||
#include "newgrf_spritegroup.h"
|
||||
#include "rail.h"
|
||||
#include "rail_map.h"
|
||||
#include "station_map.h"
|
||||
#include "stringfilter_type.h"
|
||||
#include "strings_func.h"
|
||||
#include "tile_map.h"
|
||||
#include "timer/timer_game_calendar.h"
|
||||
#include "town_map.h"
|
||||
#include "tunnelbridge_map.h"
|
||||
|
||||
#include "table/strings.h"
|
||||
|
||||
|
@ -216,7 +228,173 @@ BadgeResolverObject::BadgeResolverObject(const Badge &badge, GrfSpecFeature feat
|
|||
}
|
||||
|
||||
/**
|
||||
* Test for a matching badge in a list of badges, returning the number of matching bits.
|
||||
* Test if a list of badges contains a badge.
|
||||
* @param badges List of badges.
|
||||
* @param badge Badge to find.
|
||||
* @returns true iff the badge appears in the list.
|
||||
*/
|
||||
static bool BadgesContains(std::span<const BadgeID> badges, BadgeID badge)
|
||||
{
|
||||
return std::ranges::find(badges, badge) != std::end(badges);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a rail type has a badge.
|
||||
* @param rt Rail type to test.
|
||||
* @param badge Badge to find.
|
||||
* @returns true iff the rail type has the badge.
|
||||
*/
|
||||
static bool RailTypeHasBadge(RailType rt, BadgeID badge)
|
||||
{
|
||||
return rt != INVALID_RAILTYPE && BadgesContains(GetRailTypeInfo(rt)->badges, badge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a road type has a badge.
|
||||
* @param rt Road type to test.
|
||||
* @param badge Badge to find.
|
||||
* @returns true iff the road type has the badge.
|
||||
*/
|
||||
static bool RoadTypeHasBadge(RoadType rt, BadgeID badge)
|
||||
{
|
||||
return rt != INVALID_ROADTYPE && BadgesContains(GetRoadTypeInfo(rt)->badges, badge);
|
||||
}
|
||||
|
||||
using TileHasBadgeProc = bool(*)(TileIndex tile, BadgeID badge, GrfSpecFeatures features);
|
||||
|
||||
static bool TileHasBadge_Rail(TileIndex tile, BadgeID badge, GrfSpecFeatures features)
|
||||
{
|
||||
if (features.Test(GrfSpecFeature::GSF_RAILTYPES) && RailTypeHasBadge(GetRailType(tile), badge)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool TileHasBadge_Road(TileIndex tile, BadgeID badge, GrfSpecFeatures features)
|
||||
{
|
||||
if (features.Test(GrfSpecFeature::GSF_ROADTYPES) && RoadTypeHasBadge(GetRoadTypeRoad(tile), badge)) return true;
|
||||
if (features.Test(GrfSpecFeature::GSF_TRAMTYPES) && RoadTypeHasBadge(GetRoadTypeTram(tile), badge)) return true;
|
||||
if (features.Test(GrfSpecFeature::GSF_RAILTYPES) && IsLevelCrossing(tile) && RailTypeHasBadge(GetRailType(tile), badge)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool TileHasBadge_Town(TileIndex tile, BadgeID badge, GrfSpecFeatures features)
|
||||
{
|
||||
if (features.Test(GrfSpecFeature::GSF_HOUSES) && BadgesContains(HouseSpec::Get(GetHouseType(tile))->badges, badge)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool TileHasBadge_Station(TileIndex tile, BadgeID badge, GrfSpecFeatures features)
|
||||
{
|
||||
switch (GetStationType(tile)) {
|
||||
case StationType::Rail:
|
||||
case StationType::RailWaypoint:
|
||||
if (features.Test(GrfSpecFeature::GSF_STATIONS)) {
|
||||
if (const StationSpec *spec = GetStationSpec(tile); spec != nullptr && BadgesContains(spec->badges, badge)) return true;
|
||||
}
|
||||
if (features.Test(GrfSpecFeature::GSF_RAILTYPES) && RailTypeHasBadge(GetRailType(tile), badge)) return true;
|
||||
return false;
|
||||
|
||||
case StationType::Bus:
|
||||
case StationType::Truck:
|
||||
case StationType::RoadWaypoint:
|
||||
if (features.Test(GrfSpecFeature::GSF_ROADSTOPS)) {
|
||||
if (const RoadStopSpec *spec = GetRoadStopSpec(tile); spec != nullptr && BadgesContains(spec->badges, badge)) return true;
|
||||
}
|
||||
if (features.Test(GrfSpecFeature::GSF_ROADTYPES) && RoadTypeHasBadge(GetRoadTypeRoad(tile), badge)) return true;
|
||||
if (features.Test(GrfSpecFeature::GSF_TRAMTYPES) && RoadTypeHasBadge(GetRoadTypeTram(tile), badge)) return true;
|
||||
return false;
|
||||
|
||||
case StationType::Airport:
|
||||
if (features.Test(GrfSpecFeature::GSF_AIRPORTTILES) && BadgesContains(AirportTileSpec::GetByTile(tile)->badges, badge)) return true;
|
||||
return false;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static bool TileHasBadge_Industry(TileIndex tile, BadgeID badge, GrfSpecFeatures features)
|
||||
{
|
||||
if (features.Test(GrfSpecFeature::GSF_INDUSTRYTILES) && BadgesContains(GetIndustryTileSpec(GetIndustryGfx(tile))->badges, badge)) return true;
|
||||
if (features.Test(GrfSpecFeature::GSF_INDUSTRIES) && BadgesContains(GetIndustrySpec(GetIndustryType(tile))->badges, badge)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool TileHasBadge_TunnelBridge(TileIndex tile, BadgeID badge, GrfSpecFeatures features)
|
||||
{
|
||||
switch (GetTunnelBridgeTransportType(tile)) {
|
||||
case TransportType::TRANSPORT_RAIL:
|
||||
if (features.Test(GrfSpecFeature::GSF_RAILTYPES) && RailTypeHasBadge(GetRailType(tile), badge)) return true;
|
||||
return false;
|
||||
|
||||
case TransportType::TRANSPORT_ROAD:
|
||||
if (features.Test(GrfSpecFeature::GSF_ROADTYPES) && RoadTypeHasBadge(GetRoadTypeRoad(tile), badge)) return true;
|
||||
if (features.Test(GrfSpecFeature::GSF_TRAMTYPES) && RoadTypeHasBadge(GetRoadTypeTram(tile), badge)) return true;
|
||||
return false;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static bool TileHasBadge_Object(TileIndex tile, BadgeID badge, GrfSpecFeatures features)
|
||||
{
|
||||
if (features.Test(GrfSpecFeature::GSF_OBJECTS) && BadgesContains(ObjectSpec::GetByTile(tile)->badges, badge)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a tile has an item containing the specified badge.
|
||||
* @param tile Tile to query.
|
||||
* @param badge Badge to search for.
|
||||
* @param features GRF features to include in the test.
|
||||
* @returns true iff the badge 'is on' the tile.
|
||||
*/
|
||||
static bool TileHasBadge(TileIndex tile, BadgeID badge, GrfSpecFeatures features)
|
||||
{
|
||||
/* Per-tiletype functions for badge testing. Like _tile_type_procs, this is 16 entries as GetTileType() reads 4 bits. */
|
||||
static constexpr std::array<TileHasBadgeProc, 16> tile_procs = {
|
||||
nullptr,
|
||||
TileHasBadge_Rail,
|
||||
TileHasBadge_Road,
|
||||
TileHasBadge_Town,
|
||||
nullptr,
|
||||
TileHasBadge_Station,
|
||||
nullptr,
|
||||
nullptr,
|
||||
TileHasBadge_Industry,
|
||||
TileHasBadge_TunnelBridge,
|
||||
TileHasBadge_Object,
|
||||
};
|
||||
|
||||
TileHasBadgeProc proc = tile_procs[GetTileType(tile)];
|
||||
return proc != nullptr && proc(tile, badge, features);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for a matching badge 'on' a specific map tile.
|
||||
* @param grffile GRF file of the current varaction.
|
||||
* @param tile Tile to test.
|
||||
* @param parameter GRF-local badge index.
|
||||
* @param features GRF features to include in the test.
|
||||
* @returns true iff the badge is present.
|
||||
*/
|
||||
uint32_t GetNearbyBadgeVariableResult(const GRFFile &grffile, TileIndex tile, const ResolverObject &object)
|
||||
{
|
||||
GrfSpecFeatures features = static_cast<GrfSpecFeatures>(object.GetRegister(0x101));
|
||||
if (features.None()) return 0;
|
||||
|
||||
uint32_t parameter = object.GetRegister(0x100);
|
||||
if (parameter >= std::size(grffile.badge_list)) return UINT_MAX;
|
||||
|
||||
/* NewGRF cannot be expected to know the bounds of the map. If the tile is invalid it doesn't have the queried badge. */
|
||||
if (!IsValidTile(tile)) return 0;
|
||||
|
||||
BadgeID index = grffile.badge_list[parameter];
|
||||
return TileHasBadge(tile, index, features);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for a matching badge in a list of badges.
|
||||
* @param grffile GRF file of the current varaction.
|
||||
* @param badges List of badges to test.
|
||||
* @param parameter GRF-local badge index.
|
||||
|
@ -227,7 +405,7 @@ uint32_t GetBadgeVariableResult(const GRFFile &grffile, std::span<const BadgeID>
|
|||
if (parameter >= std::size(grffile.badge_list)) return UINT_MAX;
|
||||
|
||||
BadgeID index = grffile.badge_list[parameter];
|
||||
return std::ranges::find(badges, index) != std::end(badges);
|
||||
return BadgesContains(badges, index);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -64,6 +64,7 @@ Badge *GetBadgeByLabel(std::string_view label);
|
|||
Badge *GetClassBadge(BadgeClassID class_index);
|
||||
std::span<const BadgeID> GetClassBadges();
|
||||
|
||||
uint32_t GetNearbyBadgeVariableResult(const GRFFile &grffile, TileIndex tile, const ResolverObject &object);
|
||||
uint32_t GetBadgeVariableResult(const struct GRFFile &grffile, std::span<const BadgeID> badges, uint32_t parameter);
|
||||
|
||||
PalSpriteID GetBadgeSprite(const Badge &badge, GrfSpecFeature feature, std::optional<TimerGameCalendar::Date> introduction_date, PaletteID remap);
|
||||
|
|
|
@ -444,6 +444,7 @@ static uint32_t GetDistanceFromNearbyHouse(uint8_t parameter, TileIndex start_ti
|
|||
return _house_mngr.GetGRFID(house_id);
|
||||
}
|
||||
|
||||
case 0x79: return GetNearbyBadgeVariableResult(*this->ro.grffile, GetNearbyTile(parameter, this->tile), this->ro);
|
||||
case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, HouseSpec::Get(this->house_id)->badges, parameter);
|
||||
}
|
||||
|
||||
|
|
|
@ -168,6 +168,7 @@ static uint32_t GetCountAndDistanceOfClosestInstance(const ResolverObject &objec
|
|||
/* Variables available during construction check. */
|
||||
|
||||
switch (variable) {
|
||||
case 0x79: return GetNearbyBadgeVariableResult(*this->ro.grffile, GetNearbyTile(parameter, this->tile), this->ro);
|
||||
case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, GetIndustrySpec(this->type)->badges, parameter);
|
||||
|
||||
case 0x80: return this->tile.base();
|
||||
|
@ -354,6 +355,7 @@ static uint32_t GetCountAndDistanceOfClosestInstance(const ResolverObject &objec
|
|||
NOT_REACHED();
|
||||
}
|
||||
|
||||
case 0x79: return GetNearbyBadgeVariableResult(*this->ro.grffile, GetNearbyTile(parameter, this->tile), this->ro);
|
||||
case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, GetIndustrySpec(this->type)->badges, parameter);
|
||||
|
||||
/* Get a variable from the persistent storage */
|
||||
|
|
|
@ -93,6 +93,7 @@ uint32_t GetRelativePosition(TileIndex tile, TileIndex ind_tile)
|
|||
/* Get industry tile ID at offset */
|
||||
case 0x62: return GetIndustryIDAtOffset(GetNearbyTile(parameter, this->tile), this->industry, this->ro.grffile->grfid);
|
||||
|
||||
case 0x79: return GetNearbyBadgeVariableResult(*this->ro.grffile, GetNearbyTile(parameter, this->tile), this->ro);
|
||||
case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, GetIndustryTileSpec(GetIndustryGfx(this->tile))->badges, parameter);
|
||||
}
|
||||
|
||||
|
|
|
@ -291,6 +291,7 @@ static uint32_t GetCountAndDistanceOfClosestInstance(const ResolverObject &objec
|
|||
/* Object view */
|
||||
case 0x48: return this->view;
|
||||
|
||||
case 0x79: return GetNearbyBadgeVariableResult(*this->ro.grffile, GetNearbyTile(parameter, this->tile), this->ro);
|
||||
case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, this->spec->badges, parameter);
|
||||
|
||||
/*
|
||||
|
@ -364,6 +365,7 @@ static uint32_t GetCountAndDistanceOfClosestInstance(const ResolverObject &objec
|
|||
/* Count of object, distance of closest instance */
|
||||
case 0x64: return GetCountAndDistanceOfClosestInstance(this->ro, parameter, this->ro.grffile->grfid, this->tile, this->obj);
|
||||
|
||||
case 0x79: return GetNearbyBadgeVariableResult(*this->ro.grffile, GetNearbyTile(parameter, this->tile), this->ro);
|
||||
case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, this->spec->badges, parameter);
|
||||
}
|
||||
|
||||
|
|
|
@ -205,6 +205,7 @@ uint32_t RoadStopScopeResolver::GetVariable(uint8_t variable, [[maybe_unused]] u
|
|||
return 0xFFFE;
|
||||
}
|
||||
|
||||
case 0x79: return GetNearbyBadgeVariableResult(*this->ro.grffile, GetNearbyTile(parameter, this->tile), this->ro);
|
||||
case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, this->roadstopspec->badges, parameter);
|
||||
|
||||
case 0xF0: return this->st == nullptr ? 0 : this->st->facilities.base(); // facilities
|
||||
|
|
|
@ -295,6 +295,12 @@ TownScopeResolver *StationResolverObject::GetTown()
|
|||
}
|
||||
break;
|
||||
|
||||
case 0x79:
|
||||
if (this->axis != INVALID_AXIS && this->tile != INVALID_TILE) {
|
||||
return GetNearbyBadgeVariableResult(*this->ro.grffile, GetNearbyTile(parameter, this->tile, true, this->axis), this->ro);
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, this->statspec->badges, parameter);
|
||||
|
||||
case 0xFA: return ClampTo<uint16_t>(TimerGameCalendar::date - CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR); // Build date, clamped to a 16 bit value
|
||||
|
@ -398,6 +404,7 @@ TownScopeResolver *StationResolverObject::GetTown()
|
|||
return 0xFFFE;
|
||||
}
|
||||
|
||||
case 0x79: return GetNearbyBadgeVariableResult(*this->ro.grffile, GetNearbyTile(parameter, this->tile), this->ro);
|
||||
case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, this->statspec->badges, parameter);
|
||||
|
||||
/* General station variables */
|
||||
|
|
|
@ -36,10 +36,15 @@
|
|||
# define MW(a) {a, PALETTE_TO_STRUCT_WHITE}
|
||||
# define MC(a) {a, PALETTE_TO_STRUCT_CONCRETE}
|
||||
|
||||
static const PalSpriteID _aqueduct_sprites[] = {
|
||||
{ SPR_AQUEDUCT_MIDDLE_X, PAL_NONE }, { 0x0, PAL_NONE }, { SPR_AQUEDUCT_PILLAR_X, PAL_NONE }, { 0x0, PAL_NONE },
|
||||
{ SPR_AQUEDUCT_MIDDLE_Y, PAL_NONE }, { 0x0, PAL_NONE }, { SPR_AQUEDUCT_PILLAR_Y, PAL_NONE }, { 0x0, PAL_NONE },
|
||||
{ SPR_AQUEDUCT_RAMP_SW, PAL_NONE }, { SPR_AQUEDUCT_RAMP_SE, PAL_NONE }, { SPR_AQUEDUCT_RAMP_NE, PAL_NONE }, { SPR_AQUEDUCT_RAMP_NW, PAL_NONE },
|
||||
/* Sprite table for middle part of aqueduct. */
|
||||
static const PalSpriteID _aqueduct_sprite_table_middle[] = {
|
||||
{SPR_AQUEDUCT_MIDDLE_X, PAL_NONE}, {0x0, PAL_NONE}, {SPR_AQUEDUCT_PILLAR_X, PAL_NONE}, {0x0, PAL_NONE}, // AXIS_X
|
||||
{SPR_AQUEDUCT_MIDDLE_Y, PAL_NONE}, {0x0, PAL_NONE}, {SPR_AQUEDUCT_PILLAR_Y, PAL_NONE}, {0x0, PAL_NONE}, // AIXS_Y
|
||||
};
|
||||
|
||||
/* Sprite table for head part of aqueduct. */
|
||||
static const PalSpriteID _aqueduct_sprite_table_heads[] = {
|
||||
{SPR_AQUEDUCT_RAMP_SW, PAL_NONE}, {SPR_AQUEDUCT_RAMP_SE, PAL_NONE}, {SPR_AQUEDUCT_RAMP_NE, PAL_NONE}, {SPR_AQUEDUCT_RAMP_NW, PAL_NONE},
|
||||
};
|
||||
|
||||
static const PalSpriteID _bridge_sprite_table_4_0[] = {
|
||||
|
|
|
@ -138,15 +138,58 @@ bool HasBridgeFlatRamp(Slope tileh, Axis axis)
|
|||
return (tileh != SLOPE_FLAT);
|
||||
}
|
||||
|
||||
static inline std::span<const PalSpriteID> GetBridgeSpriteTable(int index, BridgePieces table)
|
||||
/**
|
||||
* Get the sprite table for a rail/road bridge piece.
|
||||
* @param bridge_type Bridge type.
|
||||
* @param piece Bridge piece.
|
||||
* @return Sprite table for the bridge piece.
|
||||
*/
|
||||
static std::span<const PalSpriteID> GetBridgeSpriteTable(BridgeType bridge_type, BridgePieces piece)
|
||||
{
|
||||
const BridgeSpec *bridge = GetBridgeSpec(index);
|
||||
assert(table < NUM_BRIDGE_PIECES);
|
||||
if (table < bridge->sprite_table.size() && !bridge->sprite_table[table].empty()) return bridge->sprite_table[table];
|
||||
assert(piece < NUM_BRIDGE_PIECES);
|
||||
|
||||
return _bridge_sprite_table[index][table];
|
||||
const BridgeSpec *bridge = GetBridgeSpec(bridge_type);
|
||||
if (piece < bridge->sprite_table.size() && !bridge->sprite_table[piece].empty()) return bridge->sprite_table[piece];
|
||||
|
||||
return _bridge_sprite_table[bridge_type][piece];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the sprite table transport type base offset for a rail/road bridge.
|
||||
* @param transport_type Transport type of bridge.
|
||||
* @param ramp Tile of bridge ramp.
|
||||
* @return Offset for transport type.
|
||||
*/
|
||||
static uint8_t GetBridgeSpriteTableBaseOffset(TransportType transport_type, TileIndex ramp)
|
||||
{
|
||||
switch (transport_type) {
|
||||
case TRANSPORT_RAIL: return GetRailTypeInfo(GetRailType(ramp))->bridge_offset;
|
||||
case TRANSPORT_ROAD: return 8;
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get bridge sprite table base offset for the ramp part of bridge.
|
||||
* @param diagdir Direction of ramp.
|
||||
* @return Offset for direction.
|
||||
*/
|
||||
static uint8_t GetBridgeRampDirectionBaseOffset(DiagDirection diagdir)
|
||||
{
|
||||
/* Bridge ramps are ordered SW, SE, NE, NW instead of NE, SE, SW, NW. */
|
||||
static constexpr uint8_t ramp_offsets[DIAGDIR_END] = {2, 1, 0, 3};
|
||||
return ramp_offsets[diagdir];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get bridge sprite table base offset for the middle part of bridge.
|
||||
* @param axis Axis of bridge.
|
||||
* @return Offset for axis.
|
||||
*/
|
||||
static uint8_t GetBridgeMiddleAxisBaseOffset(Axis axis)
|
||||
{
|
||||
return axis == AXIS_X ? 0 : 4;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the foundation for the bridge head, and tests if the resulting slope is valid.
|
||||
|
@ -1017,10 +1060,10 @@ static CommandCost ClearTile_TunnelBridge(TileIndex tile, DoCommandFlags flags)
|
|||
* @param h Bounding box size in Y direction
|
||||
* @param subsprite Optional subsprite for drawing halfpillars
|
||||
*/
|
||||
static inline void DrawPillar(const PalSpriteID *psid, int x, int y, int z, uint8_t w, uint8_t h, const SubSprite *subsprite)
|
||||
static inline void DrawPillar(const PalSpriteID &psid, int x, int y, int z, uint8_t w, uint8_t h, const SubSprite *subsprite)
|
||||
{
|
||||
static const int PILLAR_Z_OFFSET = TILE_HEIGHT - BRIDGE_Z_START; ///< Start offset of pillar wrt. bridge (downwards)
|
||||
AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, z, {{0, 0, -PILLAR_Z_OFFSET}, {w, h, BB_HEIGHT_UNDER_BRIDGE}, {0, 0, PILLAR_Z_OFFSET}}, IsTransparencySet(TO_BRIDGES), subsprite);
|
||||
AddSortableSpriteToDraw(psid.sprite, psid.pal, x, y, z, {{0, 0, -PILLAR_Z_OFFSET}, {w, h, BB_HEIGHT_UNDER_BRIDGE}, {0, 0, PILLAR_Z_OFFSET}}, IsTransparencySet(TO_BRIDGES), subsprite);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1034,7 +1077,7 @@ static inline void DrawPillar(const PalSpriteID *psid, int x, int y, int z, uint
|
|||
* @param h Bounding box size in Y direction
|
||||
* @return Reached Z at the bottom
|
||||
*/
|
||||
static int DrawPillarColumn(int z_bottom, int z_top, const PalSpriteID *psid, int x, int y, int w, int h)
|
||||
static int DrawPillarColumn(int z_bottom, int z_top, const PalSpriteID &psid, int x, int y, int w, int h)
|
||||
{
|
||||
int cur_z;
|
||||
for (cur_z = z_top; cur_z >= z_bottom; cur_z -= TILE_HEIGHT) {
|
||||
|
@ -1054,7 +1097,7 @@ static int DrawPillarColumn(int z_bottom, int z_top, const PalSpriteID *psid, in
|
|||
* @param y Sprite Y position of front pillar.
|
||||
* @param z_bridge Absolute height of bridge bottom.
|
||||
*/
|
||||
static void DrawBridgePillars(const PalSpriteID *psid, const TileInfo *ti, Axis axis, bool drawfarpillar, int x, int y, int z_bridge)
|
||||
static void DrawBridgePillars(const PalSpriteID &psid, const TileInfo *ti, Axis axis, bool drawfarpillar, int x, int y, int z_bridge)
|
||||
{
|
||||
static const int bounding_box_size[2] = {16, 2}; ///< bounding box size of pillars along bridge direction
|
||||
static const int back_pillar_offset[2] = { 0, 9}; ///< sprite position offset of back facing pillar
|
||||
|
@ -1065,7 +1108,7 @@ static void DrawBridgePillars(const PalSpriteID *psid, const TileInfo *ti, Axis
|
|||
{ { -INF, -INF, 15, INF }, { 16, -INF, INF, INF } }, // Y axis, north and south
|
||||
};
|
||||
|
||||
if (psid->sprite == 0) return;
|
||||
if (psid.sprite == 0) return;
|
||||
|
||||
/* Determine ground height under pillars */
|
||||
DiagDirection south_dir = AxisToDiagDir(axis);
|
||||
|
@ -1404,34 +1447,20 @@ static void DrawTile_TunnelBridge(TileInfo *ti)
|
|||
|
||||
DrawBridgeMiddle(ti);
|
||||
} else { // IsBridge(ti->tile)
|
||||
const PalSpriteID *psid;
|
||||
int base_offset;
|
||||
bool ice = HasTunnelBridgeSnowOrDesert(ti->tile);
|
||||
|
||||
if (transport_type == TRANSPORT_RAIL) {
|
||||
base_offset = GetRailTypeInfo(GetRailType(ti->tile))->bridge_offset;
|
||||
assert(base_offset != 8); // This one is used for roads
|
||||
} else {
|
||||
base_offset = 8;
|
||||
}
|
||||
|
||||
/* as the lower 3 bits are used for other stuff, make sure they are clear */
|
||||
assert( (base_offset & 0x07) == 0x00);
|
||||
|
||||
DrawFoundation(ti, GetBridgeFoundation(ti->tileh, DiagDirToAxis(tunnelbridge_direction)));
|
||||
|
||||
/* HACK Wizardry to convert the bridge ramp direction into a sprite offset */
|
||||
base_offset += (6 - tunnelbridge_direction) % 4;
|
||||
|
||||
/* Table number BRIDGE_PIECE_HEAD always refers to the bridge heads for any bridge type */
|
||||
uint base_offset = GetBridgeRampDirectionBaseOffset(tunnelbridge_direction);
|
||||
std::span<const PalSpriteID> psid;
|
||||
if (transport_type != TRANSPORT_WATER) {
|
||||
if (ti->tileh == SLOPE_FLAT) base_offset += 4; // sloped bridge head
|
||||
psid = &GetBridgeSpriteTable(GetBridgeType(ti->tile), BRIDGE_PIECE_HEAD)[base_offset];
|
||||
base_offset += GetBridgeSpriteTableBaseOffset(transport_type, ti->tile);
|
||||
psid = GetBridgeSpriteTable(GetBridgeType(ti->tile), BRIDGE_PIECE_HEAD);
|
||||
} else {
|
||||
psid = _aqueduct_sprites + base_offset;
|
||||
psid = _aqueduct_sprite_table_heads;
|
||||
}
|
||||
psid = psid.subspan(base_offset, 1);
|
||||
|
||||
if (!ice) {
|
||||
if (!HasTunnelBridgeSnowOrDesert(ti->tile)) {
|
||||
TileIndex next = ti->tile + TileOffsByDiagDir(tunnelbridge_direction);
|
||||
if (ti->tileh != SLOPE_FLAT && ti->z == 0 && HasTileWaterClass(next) && GetWaterClass(next) == WATER_CLASS_SEA) {
|
||||
DrawShoreTile(ti->tileh);
|
||||
|
@ -1451,7 +1480,7 @@ static void DrawTile_TunnelBridge(TileInfo *ti)
|
|||
* it doesn't disappear behind it
|
||||
*/
|
||||
/* Bridge heads are drawn solid no matter how invisibility/transparency is set */
|
||||
AddSortableSpriteToDraw(psid->sprite, psid->pal, *ti, {{}, {TILE_SIZE, TILE_SIZE, static_cast<uint8_t>(ti->tileh == SLOPE_FLAT ? 0 : TILE_HEIGHT)}, {}});
|
||||
AddSortableSpriteToDraw(psid[0].sprite, psid[0].pal, *ti, {{}, {TILE_SIZE, TILE_SIZE, static_cast<uint8_t>(ti->tileh == SLOPE_FLAT ? 0 : TILE_HEIGHT)}, {}});
|
||||
|
||||
if (transport_type == TRANSPORT_ROAD) {
|
||||
uint offset = tunnelbridge_direction;
|
||||
|
@ -1572,33 +1601,21 @@ void DrawBridgeMiddle(const TileInfo *ti)
|
|||
TileIndex rampnorth = GetNorthernBridgeEnd(ti->tile);
|
||||
TileIndex rampsouth = GetSouthernBridgeEnd(ti->tile);
|
||||
TransportType transport_type = GetTunnelBridgeTransportType(rampsouth);
|
||||
|
||||
Axis axis = GetBridgeAxis(ti->tile);
|
||||
BridgePieces piece = CalcBridgePiece(
|
||||
GetTunnelBridgeLength(ti->tile, rampnorth) + 1,
|
||||
GetTunnelBridgeLength(ti->tile, rampsouth) + 1
|
||||
);
|
||||
|
||||
const PalSpriteID *psid;
|
||||
uint base_offset = GetBridgeMiddleAxisBaseOffset(axis);
|
||||
std::span<const PalSpriteID> psid;
|
||||
bool drawfarpillar;
|
||||
if (transport_type != TRANSPORT_WATER) {
|
||||
BridgeType type = GetBridgeType(rampsouth);
|
||||
drawfarpillar = !HasBit(GetBridgeSpec(type)->flags, 0);
|
||||
|
||||
uint base_offset;
|
||||
if (transport_type == TRANSPORT_RAIL) {
|
||||
base_offset = GetRailTypeInfo(GetRailType(rampsouth))->bridge_offset;
|
||||
} else {
|
||||
base_offset = 8;
|
||||
}
|
||||
|
||||
psid = &GetBridgeSpriteTable(type, piece)[base_offset];
|
||||
BridgeType bridge_type = GetBridgeType(rampsouth);
|
||||
drawfarpillar = !HasBit(GetBridgeSpec(bridge_type)->flags, 0);
|
||||
base_offset += GetBridgeSpriteTableBaseOffset(transport_type, rampsouth);
|
||||
psid = GetBridgeSpriteTable(bridge_type, CalcBridgePiece(GetTunnelBridgeLength(ti->tile, rampnorth) + 1, GetTunnelBridgeLength(ti->tile, rampsouth) + 1));
|
||||
} else {
|
||||
drawfarpillar = true;
|
||||
psid = _aqueduct_sprites;
|
||||
psid = _aqueduct_sprite_table_middle;
|
||||
}
|
||||
|
||||
if (axis != AXIS_X) psid += 4;
|
||||
psid = psid.subspan(base_offset, 3);
|
||||
|
||||
int x = ti->x;
|
||||
int y = ti->y;
|
||||
|
@ -1614,14 +1631,12 @@ void DrawBridgeMiddle(const TileInfo *ti)
|
|||
/* Draw floor and far part of bridge*/
|
||||
if (!IsInvisibilitySet(TO_BRIDGES)) {
|
||||
if (axis == AXIS_X) {
|
||||
AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, z, {{0, 0, BRIDGE_Z_START}, {TILE_SIZE, 1, 40}, {0, 0, -BRIDGE_Z_START}}, IsTransparencySet(TO_BRIDGES));
|
||||
AddSortableSpriteToDraw(psid[0].sprite, psid[0].pal, x, y, z, {{0, 0, BRIDGE_Z_START}, {TILE_SIZE, 1, 40}, {0, 0, -BRIDGE_Z_START}}, IsTransparencySet(TO_BRIDGES));
|
||||
} else {
|
||||
AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, z, {{0, 0, BRIDGE_Z_START}, {1, TILE_SIZE, 40}, {0, 0, -BRIDGE_Z_START}}, IsTransparencySet(TO_BRIDGES));
|
||||
AddSortableSpriteToDraw(psid[0].sprite, psid[0].pal, x, y, z, {{0, 0, BRIDGE_Z_START}, {1, TILE_SIZE, 40}, {0, 0, -BRIDGE_Z_START}}, IsTransparencySet(TO_BRIDGES));
|
||||
}
|
||||
}
|
||||
|
||||
psid++;
|
||||
|
||||
if (transport_type == TRANSPORT_ROAD) {
|
||||
/* DrawBridgeRoadBits() calls EndSpriteCombine() and StartSpriteCombine() */
|
||||
DrawBridgeRoadBits(rampsouth, x, y, bridge_z, axis ^ 1, false);
|
||||
|
@ -1654,10 +1669,10 @@ void DrawBridgeMiddle(const TileInfo *ti)
|
|||
if (!IsInvisibilitySet(TO_BRIDGES)) {
|
||||
if (axis == AXIS_X) {
|
||||
y += 12;
|
||||
if (psid->sprite & SPRITE_MASK) AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, z, {{0, 3, BRIDGE_Z_START}, {TILE_SIZE, 1, 40}, {0, -3, -BRIDGE_Z_START}}, IsTransparencySet(TO_BRIDGES));
|
||||
if (psid[1].sprite & SPRITE_MASK) AddSortableSpriteToDraw(psid[1].sprite, psid[1].pal, x, y, z, {{0, 3, BRIDGE_Z_START}, {TILE_SIZE, 1, 40}, {0, -3, -BRIDGE_Z_START}}, IsTransparencySet(TO_BRIDGES));
|
||||
} else {
|
||||
x += 12;
|
||||
if (psid->sprite & SPRITE_MASK) AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, z, {{3, 0, BRIDGE_Z_START}, {1, TILE_SIZE, 40}, {-3, 0, -BRIDGE_Z_START}}, IsTransparencySet(TO_BRIDGES));
|
||||
if (psid[1].sprite & SPRITE_MASK) AddSortableSpriteToDraw(psid[1].sprite, psid[1].pal, x, y, z, {{3, 0, BRIDGE_Z_START}, {1, TILE_SIZE, 40}, {-3, 0, -BRIDGE_Z_START}}, IsTransparencySet(TO_BRIDGES));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1667,8 +1682,7 @@ void DrawBridgeMiddle(const TileInfo *ti)
|
|||
/* Do not draw anything more if bridges are invisible */
|
||||
if (IsInvisibilitySet(TO_BRIDGES)) return;
|
||||
|
||||
psid++;
|
||||
DrawBridgePillars(psid, ti, axis, drawfarpillar, x, y, z);
|
||||
DrawBridgePillars(psid[2], ti, axis, drawfarpillar, x, y, z);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue