44 #include "table/strings.h" 67 for (
TileIndex t = begin; t != end; t += delta) {
87 if (_bridge[i].sprite_table !=
nullptr) {
88 for (
BridgePieces j = BRIDGE_PIECE_NORTH; j < BRIDGE_PIECE_INVALID; j++)
free(_bridge[i].sprite_table[j]);
89 free(_bridge[i].sprite_table);
94 memset(&_bridge, 0,
sizeof(_bridge));
96 memcpy(&_bridge, &_orig_bridge,
sizeof(_orig_bridge));
107 if (length < 2)
return length;
111 for (
int delta = 1;; delta++) {
112 for (
int count = 0; count < delta; count++) {
113 if (length == 0)
return sum;
152 assert(table < BRIDGE_PIECE_INVALID);
154 return _bridge_sprite_table[index][table];
172 assert(bridge_piece == BRIDGE_PIECE_NORTH || bridge_piece == BRIDGE_PIECE_SOUTH);
177 Slope valid_inclined;
178 if (bridge_piece == BRIDGE_PIECE_NORTH) {
240 TransportType transport_type = Extract<TransportType, 15, 2>(p2);
243 switch (transport_type) {
245 roadtype = Extract<RoadType, 8, 6>(p2);
250 railtype = Extract<RailType, 8, 6>(p2);
276 if (tile_start == tile_end) {
283 }
else if (
TileY(tile_start) ==
TileY(tile_end)) {
289 if (tile_end < tile_start)
Swap(tile_start, tile_end);
295 if (ret.
Failed())
return ret;
304 bool pbs_reservation =
false;
311 if (z_start != z_end)
return_cmd_error(STR_ERROR_BRIDGEHEADS_NOT_SAME_HEIGHT);
323 switch (transport_type) {
331 road_rt = GetRoadTypeRoad(tile_start);
332 tram_rt = GetRoadTypeTram(tile_start);
345 RoadType existing_rt = RoadTypeIsRoad(roadtype) ? road_rt : tram_rt;
354 _game_mode != GM_EDITOR) {
366 if (!(flags & DC_QUERY_COST) && (bridge_type ==
GetBridgeType(tile_start)) && (transport_type !=
TRANSPORT_ROAD || road_rt == roadtype || tram_rt == roadtype)) {
375 cost.
AddCost((bridge_len + 1) * _price[PR_CLEAR_BRIDGE]);
380 if (is_new_owner) owner = company;
388 if (ret.
Failed())
return ret;
391 if (terraform_cost_north.
Failed() || (terraform_cost_north.
GetCost() != 0 && !allow_on_slopes))
return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
392 cost.
AddCost(terraform_cost_north);
396 if (ret.
Failed())
return ret;
400 if (terraform_cost_south.
Failed() || (terraform_cost_south.
GetCost() != 0 && !allow_on_slopes))
return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
401 cost.
AddCost(terraform_cost_south);
403 const TileIndex heads[] = {tile_start, tile_end};
404 for (
int i = 0; i < 2; i++) {
417 for (
TileIndex tile = tile_start + delta; tile != tile_end; tile += delta) {
468 if (ret.
Failed())
return ret;
488 if (RoadTypeIsRoad(roadtype)) road_rt = roadtype;
489 if (RoadTypeIsTram(roadtype)) tram_rt = roadtype;
497 switch (transport_type) {
526 MakeRoadBridgeRamp(tile_start, owner, owner_road, owner_tram, bridge_type, dir, road_rt, tram_rt);
562 switch (transport_type) {
579 cost.
AddCost((int64)bridge_len * _price[PR_BUILD_BRIDGE] *
GetBridgeSpec(bridge_type)->price >> 8);
582 cost.
AddCost((int64)bridge_len * _price[PR_BUILD_AQUEDUCT]);
605 TransportType transport_type = Extract<TransportType, 8, 2>(p1);
609 switch (transport_type) {
611 railtype = Extract<RailType, 0, 6>(p1);
616 roadtype = Extract<RoadType, 0, 6>(p1);
644 if (ret.
Failed())
return ret;
675 if (start_z == end_z)
break;
682 if (tiles == tiles_bump) {
687 cost.
AddCost(_price[PR_BUILD_TUNNEL]);
692 cost.
AddCost(_price[PR_BUILD_TUNNEL]);
712 if (coa ==
nullptr) {
713 _cleared_object_areas.push_back({end_tile,
TileArea(end_tile, 1, 1)});
714 coa = &_cleared_object_areas.back();
731 assert(coa >= begin && coa < begin + _cleared_object_areas.size());
732 size_t coa_index = coa - begin;
733 assert(coa_index < UINT_MAX);
737 _cleared_object_areas[(uint)coa_index].first_tile = old_first_tile;
741 cost.
AddCost(_price[PR_BUILD_TUNNEL]);
744 switch (transport_type) {
747 default: NOT_REACHED();
785 RoadType road_rt = GetRoadTypeRoad(tile);
786 RoadType tram_rt = GetRoadTypeTram(tile);
816 default: NOT_REACHED();
829 if (ret.
Failed())
return ret;
834 if (ret.
Failed())
return ret;
845 if (ret.
Failed())
return ret;
875 DoClearSquare(endtile);
891 DoClearSquare(endtile);
907 if (ret.
Failed())
return ret;
912 if (ret.
Failed())
return ret;
924 if (ret.
Failed())
return ret;
948 bool removetile =
false;
949 bool removeendtile =
false;
966 DoClearSquare(endtile);
968 if (removetile) RemoveDockingTile(tile);
969 if (removeendtile) RemoveDockingTile(endtile);
970 for (
TileIndex c = tile + delta; c != endtile; c += delta) {
1026 AddSortableSpriteToDraw(psid->
sprite, psid->
pal, x, y, w, h,
BB_HEIGHT_UNDER_BRIDGE - PILLAR_Z_OFFSET, z,
IsTransparencySet(
TO_BRIDGES), 0, 0, -PILLAR_Z_OFFSET, subsprite);
1043 for (cur_z = z_top; cur_z >= z_bottom; cur_z -=
TILE_HEIGHT) {
1044 DrawPillar(psid, x, y, cur_z, w, h,
nullptr);
1062 static const int bounding_box_size[2] = {16, 2};
1063 static const int back_pillar_offset[2] = { 0, 9};
1065 static const int INF = 1000;
1066 static const SubSprite half_pillar_sub_sprite[2][2] = {
1067 { { -14, -INF, INF, INF }, { -INF, -INF, -15, INF } },
1068 { { -INF, -INF, 15, INF }, { 16, -INF, INF, INF } },
1071 if (psid->
sprite == 0)
return;
1075 int z_front_north = ti->
z;
1076 int z_back_north = ti->
z;
1077 int z_front_south = ti->
z;
1078 int z_back_south = ti->
z;
1083 int z_front =
max(z_front_north, z_front_south);
1084 int z_back =
max(z_back_north, z_back_south);
1087 int w = bounding_box_size[axis];
1088 int h = bounding_box_size[
OtherAxis(axis)];
1090 int x_back = x - back_pillar_offset[axis];
1091 int y_back = y - back_pillar_offset[
OtherAxis(axis)];
1095 if (z_front_north < z_front)
DrawPillar(psid, x, y, bottom_z, w, h, &half_pillar_sub_sprite[axis][0]);
1096 if (z_front_south < z_front)
DrawPillar(psid, x, y, bottom_z, w, h, &half_pillar_sub_sprite[axis][1]);
1099 int z_bridge_back = z_bridge - 2 * (int)
TILE_HEIGHT;
1100 if (drawfarpillar && (z_back_north <= z_bridge_back || z_back_south <= z_bridge_back)) {
1101 bottom_z =
DrawPillarColumn(z_back, z_bridge_back, psid, x_back, y_back, w, h);
1102 if (z_back_north < z_back)
DrawPillar(psid, x_back, y_back, bottom_z, w, h, &half_pillar_sub_sprite[axis][0]);
1103 if (z_back_south < z_back)
DrawPillar(psid, x_back, y_back, bottom_z, w, h, &half_pillar_sub_sprite[axis][1]);
1118 RoadType road_rt = GetRoadTypeRoad(head_tile);
1119 RoadType tram_rt = GetRoadTypeTram(head_tile);
1124 bool trans_back[4] = {
false };
1126 bool trans_front[4] = {
false };
1128 static const SpriteID overlay_offsets[6] = { 0, 1, 11, 12, 13, 14 };
1129 static const SpriteID back_offsets[6] = { 95, 96, 99, 102, 100, 101 };
1130 static const SpriteID front_offsets[6] = { 97, 98, 103, 106, 104, 105 };
1135 if (road_rti !=
nullptr) {
1136 if (road_rti->UsesOverlay()) {
1139 }
else if (tram_rti !=
nullptr) {
1140 if (tram_rti->UsesOverlay()) {
1143 seq_back[0] = SPR_TRAMWAY_BRIDGE + offset;
1149 if (road_rti !=
nullptr) {
1150 if (road_rti->UsesOverlay()) {
1152 if (seq_back[1] != 0) seq_back[1] += overlay_offsets[offset];
1158 if (tram_rti !=
nullptr) {
1159 if (tram_rti->UsesOverlay()) {
1161 if (seq_back[2] != 0) seq_back[2] += overlay_offsets[offset];
1162 }
else if (road_rti !=
nullptr) {
1163 seq_back[2] = SPR_TRAMWAY_OVERLAY + overlay_offsets[offset];
1173 if (seq_back[3] == 0 || seq_front[0] == 0) {
1177 seq_back[3] += 23 + offset;
1178 seq_front[0] += 23 + offset;
1183 if (seq_back[3] == 0 || seq_front[0] == 0) {
1187 seq_back[3] += 23 + offset;
1188 seq_front[0] += 23 + offset;
1193 static const uint size_x[6] = { 1, 16, 16, 1, 16, 1 };
1194 static const uint size_y[6] = { 16, 1, 1, 16, 1, 16 };
1195 static const uint front_bb_offset_x[6] = { 15, 0, 0, 15, 0, 15 };
1196 static const uint front_bb_offset_y[6] = { 0, 15, 15, 0, 15, 0 };
1200 for (uint i = 0; i <
lengthof(seq_back); ++i) {
1201 if (seq_back[i] != 0) {
1203 x, y, size_x[offset], size_y[offset], 0x28, z,
1212 for (uint i = 0; i <
lengthof(seq_front); ++i) {
1213 if (seq_front[i] != 0) {
1215 x, y, size_x[offset] + front_bb_offset_x[offset], size_y[offset] + front_bb_offset_y[offset], 0x28, z,
1217 front_bb_offset_x[offset], front_bb_offset_y[offset]);
1250 static const int _tunnel_BB[4][12] = {
1253 { 1, 0, -15, -14, 0, 15, 16, 1, 0, 1, 16, 15 },
1254 { 0, 1, -14, -15, 15, 0, 1, 16, 1, 0, 15, 16 },
1255 { 1, 0, -15, -14, 0, 15, 16, 1, 0, 1, 16, 15 },
1256 { 0, 1, -14, -15, 15, 0, 1, 16, 1, 0, 15, 16 },
1258 const int *BB_data = _tunnel_BB[tunnelbridge_direction];
1260 bool catenary =
false;
1267 if (rti->UsesOverlay()) {
1273 image = SPR_TUNNEL_ENTRY_REAR_ROAD;
1278 image += tunnelbridge_direction * 2;
1288 DrawRoadOverlays(ti, PAL_NONE, road_rti, tram_rti, sprite_offset, sprite_offset);
1294 if (catenary_sprite_base == 0) {
1295 catenary_sprite_base = SPR_TRAMWAY_TUNNEL_WIRES;
1297 catenary_sprite_base += 19;
1301 if (catenary_sprite_base == 0) {
1302 catenary_sprite_base = SPR_TRAMWAY_TUNNEL_WIRES;
1304 catenary_sprite_base += 19;
1308 if (catenary_sprite_base != 0) {
1311 AddSortableSpriteToDraw(catenary_sprite_base + tunnelbridge_direction, PAL_NONE, ti->
x, ti->
y, BB_data[10], BB_data[11],
TILE_HEIGHT, ti->
z,
IsTransparencySet(
TO_CATENARY), BB_data[8], BB_data[9],
BB_Z_SEPARATOR);
1315 if (rti->UsesOverlay()) {
1317 if (surface != 0)
DrawGroundSprite(surface + tunnelbridge_direction, PAL_NONE);
1322 if (rti->UsesOverlay()) {
1343 AddSortableSpriteToDraw(image + 1, PAL_NONE, ti->
x +
TILE_SIZE - 1, ti->
y +
TILE_SIZE - 1, BB_data[0], BB_data[1],
TILE_HEIGHT, ti->
z,
false, BB_data[2], BB_data[3],
BB_Z_SEPARATOR);
1345 if (railtype_overlay != 0)
AddSortableSpriteToDraw(railtype_overlay + tunnelbridge_direction, PAL_NONE, ti->
x +
TILE_SIZE - 1, ti->
y +
TILE_SIZE - 1, BB_data[0], BB_data[1],
TILE_HEIGHT, ti->
z,
false, BB_data[2], BB_data[3],
BB_Z_SEPARATOR);
1361 assert(base_offset != 8);
1367 assert( (base_offset & 0x07) == 0x00);
1372 base_offset += (6 - tunnelbridge_direction) % 4;
1377 psid = &GetBridgeSpriteTable(
GetBridgeType(ti->
tile), BRIDGE_PIECE_HEAD)[base_offset];
1379 psid = _aqueduct_sprites + base_offset;
1385 DrawShoreTile(ti->
tileh);
1387 DrawClearLandTile(ti, 3);
1405 uint offset = tunnelbridge_direction;
1408 offset = (offset + 1) & 1;
1420 if (rti->UsesOverlay()) {
1436 if (rti->UsesOverlay()) {
1484 return BRIDGE_PIECE_NORTH;
1485 }
else if (south == 1) {
1486 return BRIDGE_PIECE_SOUTH;
1487 }
else if (north < south) {
1488 return north & 1 ? BRIDGE_PIECE_INNER_SOUTH : BRIDGE_PIECE_INNER_NORTH;
1489 }
else if (north > south) {
1490 return south & 1 ? BRIDGE_PIECE_INNER_NORTH : BRIDGE_PIECE_INNER_SOUTH;
1492 return north & 1 ? BRIDGE_PIECE_MIDDLE_EVEN : BRIDGE_PIECE_MIDDLE_ODD;
1543 psid = base_offset + GetBridgeSpriteTable(type, piece);
1545 drawfarpillar =
true;
1546 psid = _aqueduct_sprites;
1549 if (axis !=
AXIS_X) psid += 4;
1565 AddSortableSpriteToDraw(psid->
sprite, psid->
pal, x, y, 16, 1, 0x28, z,
IsTransparencySet(
TO_BRIDGES), 0, 0, BRIDGE_Z_START);
1567 AddSortableSpriteToDraw(psid->
sprite, psid->
pal, x, y, 1, 16, 0x28, z,
IsTransparencySet(
TO_BRIDGES), 0, 0, BRIDGE_Z_START);
1586 if (rti->UsesOverlay()) {
1605 if (psid->
sprite &
SPRITE_MASK)
AddSortableSpriteToDraw(psid->
sprite, psid->
pal, x, y, 16, 4, 0x28, z,
IsTransparencySet(
TO_BRIDGES), 0, 3, BRIDGE_Z_START);
1608 if (psid->
sprite &
SPRITE_MASK)
AddSortableSpriteToDraw(psid->
sprite, psid->
pal, x, y, 4, 16, 0x28, z,
IsTransparencySet(
TO_BRIDGES), 3, 0, BRIDGE_Z_START);
1619 if (ti->
z + 5 == z) {
1638 static int GetSlopePixelZ_TunnelBridge(
TileIndex tile, uint x, uint y)
1650 if (5 <= pos && pos <= 10)
return z;
1658 if (5 <= pos && pos <= 10) {
1664 default: NOT_REACHED();
1670 return z + 1 + delta;
1687 td->
str = (tt ==
TRANSPORT_RAIL) ? STR_LAI_TUNNEL_DESCRIPTION_RAILROAD : STR_LAI_TUNNEL_DESCRIPTION_ROAD;
1695 RoadType road_rt = GetRoadTypeRoad(tile);
1696 RoadType tram_rt = GetRoadTypeTram(tile);
1715 td->
owner_type[i] = STR_LAND_AREA_INFORMATION_ROAD_OWNER;
1716 td->
owner[i] = road_owner;
1720 td->
owner_type[i] = STR_LAND_AREA_INFORMATION_TRAM_OWNER;
1721 td->
owner[i] = tram_owner;
1732 if (td->
rail_speed == 0 || spd < td->rail_speed) {
1744 static void TileLoop_TunnelBridge(
TileIndex tile)
1782 static void ChangeTileOwner_TunnelBridge(
TileIndex tile,
Owner old_owner,
Owner new_owner)
1789 FOR_ALL_ROADTRAMTYPES(rtt) {
1792 RoadType rt = GetRoadType(tile, rtt);
1796 Company::Get(old_owner)->infrastructure.road[rt] -= num_pieces * 2;
1852 int z = GetSlopePixelZ(x, y) - v->
z_pos;
1871 SndPlayVehicleFx(SND_05_TRAIN_THROUGH_TUNNEL, v);
1898 assert(frame == rv->frame + 1);
1952 default: NOT_REACHED();
1986 default: NOT_REACHED();
2018 extern const TileTypeProcs _tile_type_tunnelbridge_procs = {
2020 GetSlopePixelZ_TunnelBridge,
2023 GetTileDesc_TunnelBridge,
2024 GetTileTrackStatus_TunnelBridge,
2027 TileLoop_TunnelBridge,
2028 ChangeTileOwner_TunnelBridge,
2030 VehicleEnter_TunnelBridge,
2031 GetFoundation_TunnelBridge,
2032 TerraformTile_TunnelBridge,
TileIndex GetOtherBridgeEnd(TileIndex tile)
Starting at one bridge end finds the other bridge end.
static bool HasSlopeHighestCorner(Slope s)
Tests if a slope has a highest corner (i.e.
Functions related to OTTD's strings.
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
Owner
Enum for all companies/owners.
don't allow building on structures
uint ApplyFoundationToSlope(Foundation f, Slope *s)
Applies a foundation to a slope.
static void Swap(T &a, T &b)
Type safe swap operation.
TileIndex first_tile
The first tile being cleared, which then causes the whole object to be cleared.
struct RailtypeInfo::@36 base_sprites
Struct containing the main sprites.
static void ClearBridgeMiddle(TileIndex t)
Removes bridges from the given, that is bridges along the X and Y axis.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition of stuff that is very close to a company, like the company struct itself.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
static const PaletteID PALETTE_TO_TRANSPARENT
This sets the sprite to transparent.
static const int BRIDGE_Z_START
Z position of the bridge sprites relative to bridge height (downwards)
NewGRF handling of rail types.
static const RailtypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Year avail_year
the year where it becomes available
static TropicZone GetTropicZone(TileIndex tile)
Get the tropic zone.
static TransportType GetTunnelBridgeTransportType(TileIndex t)
Tunnel: Get the transport type of the tunnel (road or rail) Bridge: Get the transport type of the bri...
ObjectFlags flags
Flags/settings related to the object.
Direction direction
facing
static void SetTunnelBridgeReservation(TileIndex t, bool b)
Set the reservation state of the rail tunnel/bridge.
static void SetTileOwner(TileIndex tile, Owner owner)
Sets the owner of a tile.
Tile information, used while rendering the tile.
south and east corner are raised
SpriteID single_sloped
single piece of rail for slopes
void DrawRailCatenaryOnBridge(const TileInfo *ti)
Draws wires on a tunnel tile.
static DiagDirection DirToDiagDir(Direction dir)
Convert a Direction to a DiagDirection.
byte landscape
the landscape we're currently in
The mask to for the main sprite.
bool HasBridgeFlatRamp(Slope tileh, Axis axis)
Determines if the track on a bridge ramp is flat or goes up/down.
uint32 squared_town_zone_radius[HZB_END]
UpdateTownRadius updates this given the house count.
uint GetPartialPixelZ(int x, int y, Slope corners)
Determines height at given coordinate of a slope.
int32 TileIndexDiff
An offset value between to tiles.
static bool IsWater(TileIndex t)
Is it a plain water tile?
void ResetBridges()
Reset the data been eventually changed by the grf loaded.
static Titem * Get(size_t index)
Returns Titem with given index.
static bool IsBridgeTile(TileIndex t)
checks if there is a bridge on this tile
Functions related to dates.
static WaterClass GetWaterClass(TileIndex t)
Get the water class at a tile.
penalty for removing town owned tunnel or bridge
Base for the train class.
static const byte TUNNEL_SOUND_FRAME
Frame when the 'enter tunnel' sound should be played.
PalSpriteID ** sprite_table
table of sprites for drawing the bridge
static bool HasTileRoadType(TileIndex t, RoadTramType rtt)
Check if a tile has a road or a tram road type.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
uint16 cur_speed
current speed
static bool HasRoadCatenaryDrawn(RoadType roadtype)
Test if we should draw road catenary.
query cost only, don't build.
A tile with road (or tram tracks)
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Slope tileh
Slope of the tile.
static const uint BB_Z_SEPARATOR
Separates the bridge/tunnel from the things under/above it.
A town owns the tile, or a town is expanding.
Flag for invalid railtype.
static void SetTunnelBridgeSnowOrDesert(TileIndex t, bool snow_or_desert)
Tunnel: Places this tunnel entrance in a snowy or desert area, or takes it out of there...
bool extra_dynamite
extra dynamite
static void DrawBridgeRoadBits(TileIndex head_tile, int x, int y, int z, int offset, bool head)
Draws the road and trambits over an already drawn (lower end) of a bridge.
bool ValParamRailtype(const RailType rail)
Validate functions for rail building.
static void MakeRailTunnel(TileIndex t, Owner o, DiagDirection d, RailType r)
Makes a rail tunnel entrance.
Piece of rail on slope with north-east raised.
StringID tramtype
Type of tram on the tile.
Functions related to vehicles.
static TrackBits DiagDirToDiagTrackBits(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal track bits incidating with that diagdir. ...
void AddSideToSignalBuffer(TileIndex tile, DiagDirection side, Owner owner)
Add side of tile to signal update buffer.
static bool HasTileWaterGround(TileIndex t)
Checks whether the tile has water at the ground.
static uint TileX(TileIndex tile)
Get the X component of a tile.
static void MakeRailBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, RailType rt)
Make a bridge ramp for rails.
Combination of a palette sprite and a 'real' sprite.
static int DrawPillarColumn(int z_bottom, int z_top, const PalSpriteID *psid, int x, int y, int w, int h)
Draw two bridge pillars (north and south).
Tile description for the 'land area information' tool.
CommandCost CheckTileOwnership(TileIndex tile)
Check whether the current owner owns the stuff on the given tile.
Tindex index
Index of this pool item.
flag for invalid roadtype
static Roadside GetRoadside(TileIndex tile)
Get the decorations of a road.
uint16 speed
maximum travel speed (1 unit = 1/1.6 mph = 1 km-ish/h)
Allow incrementing of ObjectClassID variables.
static CommandCost CheckAllowRemoveTunnelBridge(TileIndex tile)
Are we allowed to remove the tunnel or bridge at tile?
Helper functions to extract data from command parameters.
int GetBridgeHeight(TileIndex t)
Get the height ('z') of a bridge.
static Track DiagDirToDiagTrack(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal track incidating with that diagdir.
const byte _tunnel_visibility_frame[DIAGDIR_END]
Frame when a vehicle should be hidden in a tunnel with a certain direction.
static Track AxisToTrack(Axis a)
Convert an Axis to the corresponding Track AXIS_X -> TRACK_X AXIS_Y -> TRACK_Y Uses the fact that the...
Money GetCost() const
The costs as made up to this moment.
bool IsTunnelInWayDir(TileIndex tile, int z, DiagDirection dir)
Is there a tunnel in the way in the given direction?
Contains objects such as transmitters and owned land.
Flag for an invalid DiagDirection.
south and west corner are raised
Common return value for all commands.
void StartSpriteCombine()
Starts a block of sprites, which are "combined" into a single bounding box.
RoadType
The different roadtypes we support.
static void DrawPillar(const PalSpriteID *psid, int x, int y, int z, int w, int h, const SubSprite *subsprite)
Draw a single pillar sprite.
static T max(const T a, const T b)
Returns the maximum of two values.
Year _cur_year
Current year, starting at 0.
Struct containing information about a single bridge type.
struct RailtypeInfo::@39 strings
Strings associated with the rail type.
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Road with paved sidewalks.
uint16 rail_speed
Speed limit of rail (bridges and track)
static const uint TILE_SIZE
Tile size in world coordinates.
void DrawFoundation(TileInfo *ti, Foundation f)
Draw foundation f at tile ti.
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
Owner owner[4]
Name of the owner(s)
static void MakeRoadBridgeRamp(TileIndex t, Owner o, Owner owner_road, Owner owner_tram, BridgeType bridgetype, DiagDirection d, RoadType road_rt, RoadType tram_rt)
Make a bridge ramp for roads.
TileIndex GetNorthernBridgeEnd(TileIndex t)
Finds the northern end of a bridge starting at a middle tile.
void YapfNotifyTrackLayoutChange(TileIndex tile, Track track)
Use this function to notify YAPF that track layout (or signal configuration) has change.
north and east corner are raised
This struct contains all the info that is needed to draw and construct tracks.
int GetTileZ(TileIndex tile)
Get bottom height of the tile.
company bankrupts, skip money check, skip vehicle on tile check in some cases
void DrawBridgeMiddle(const TileInfo *ti)
Draw the middle bits of a bridge.
Functions related to (drawing on) viewports.
Functions related to NewGRF objects.
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
SpriteID single_y
single piece of rail in Y direction, without ground
void EndSpriteCombine()
Terminates a block of sprites started by StartSpriteCombine.
static bool IsBridgeAbove(TileIndex t)
checks if a bridge is set above the ground of this tile
Buses, trucks and trams belong to this class.
Querying information about stuff on the bridge (via some bridgehead).
static bool IsTileOwner(TileIndex tile, Owner owner)
Checks if a tile belongs to the given owner.
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold...
uint8 height
The height of this structure, in heightlevels; max MAX_TILE_HEIGHT.
StringID name
Name of this rail type.
static const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
static Slope ComplementSlope(Slope s)
Return the complement of a slope.
SpriteID GetCustomRailSprite(const RailtypeInfo *rti, TileIndex tile, RailTypeSpriteGroup rtsg, TileContext context, uint *num_results)
Get the sprite to draw for the given tile.
uint x
X position of the tile in unit coordinates.
The tile has no ownership.
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
bool ValParamRoadType(RoadType roadtype)
Validate functions for rail building.
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
Foundation
Enumeration for Foundations.
Types related to cheating.
TileIndex xy
town center tile
TileIndex tile
Tile index.
static uint ApplyPixelFoundationToSlope(Foundation f, Slope *s)
Applies a foundation to a slope.
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
static bool IsCoast(TileIndex t)
Is it a coast tile?
Sloped rail pieces, in order NE, SE, SW, NW.
Piece of rail in X direction.
StringID owner_type[4]
Type of each owner.
Road with trees on paved sidewalks.
Header file for things common for tunnels and bridges.
void DirtyCompanyInfrastructureWindows(CompanyID company)
Redraw all windows with company infrastructure counts.
Images for overlaying track.
Entry point for OpenTTD to YAPF's cache.
The vehicle is in a tunnel and/or bridge.
CommandCost TunnelBridgeIsFree(TileIndex tile, TileIndex endtile, const Vehicle *ignore)
Finds vehicle in tunnel / bridge.
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
static DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
DoCommandFlag
List of flags for a command.
int CalcBridgeLenCostFactor(int length)
Calculate the price factor for building a long bridge.
static uint GetTunnelBridgeLength(TileIndex begin, TileIndex end)
Calculates the length of a tunnel or a bridge (without end tiles)
uint16 tram_speed
Speed limit of tram (bridges and track)
The vehicle either entered a bridge, tunnel or depot tile (this includes the last tile of the bridge/...
ClientSettings _settings_client
The current settings for this game.
Piece of rail in X direction.
bool Succeeded() const
Did this command succeed?
Keeps track of removed objects during execution/testruns of commands.
SpriteID GetCustomRoadSprite(const RoadTypeInfo *rti, TileIndex tile, RoadTypeSpriteGroup rtsg, TileContext context, uint *num_results)
Get the sprite to draw for the given tile.
Definition of base types and functions in a cross-platform compatible way.
static const BridgeSpec * GetBridgeSpec(BridgeType i)
Get the specification of a bridge type.
uint32 road[ROADTYPE_END]
Count of company owned track bits for each road type.
static const uint BB_HEIGHT_UNDER_BRIDGE
Some values for constructing bounding boxes (BB).
A number of safeguards to prevent using unsafe methods.
bool value
tells if the bool cheat is active or not
BridgeSpec _bridge[MAX_BRIDGES]
The specification of all bridges.
Optional: Catenary front.
The vehicle cannot enter the tile.
uint y
Y position of the tile in unit coordinates.
Foundation GetBridgeFoundation(Slope tileh, Axis axis)
Get the foundation for a bridge.
void DrawRailCatenaryOnTunnel(const TileInfo *ti)
Draws wires on a tunnel tile.
static bool IsDockingTile(TileIndex t)
Checks whether the tile is marked as a dockling tile.
static Slope GetTilePixelSlope(TileIndex tile, int *h)
Return the slope of a given tile.
static CommandCost DoClearBridge(TileIndex tile, DoCommandFlag flags)
Remove a bridge from the game, update town rating, etc.
static const uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in #ZOOM_LVL_BASE.
Train * GetTrainForReservation(TileIndex tile, Track track)
Find the train which has reserved a specific path.
NewGRF handling of road types.
GUI Functions related to companies.
static const uint TUNNELBRIDGE_TRACKBIT_FACTOR
Multiplier for how many regular track bits a tunnel/bridge counts.
uint16 max_bridge_length
maximum length of bridges
bool IsFrontEngine() const
Check if the vehicle is a front engine.
uint16 max_speed
Maximum speed for vehicles travelling on this rail type.
byte min_length
the minimum length (not counting start and end tile)
TileIndex tile
Current tile index.
uint16 max_speed
Maximum speed for vehicles travelling on this road type.
CommandCost CheckOwnership(Owner owner, TileIndex tile)
Check whether the current owner owns something.
static Money RoadBuildCost(RoadType roadtype)
Returns the cost of building the specified roadtype.
void UpdateCompanyRoadInfrastructure(RoadType rt, Owner o, int count)
Update road infrastructure counts for a company.
bool is_ai
If true, the company is (also) controlled by the computer (a NoAI program).
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
static Trackdir DiagDirToDiagTrackdir(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal trackdir that runs in that direction.
SpriteID single_x
single piece of rail in X direction, without ground
struct RoadTypeInfo::@42 strings
Strings associated with the rail type.
Functions related to stations.
BridgePieces
This enum is related to the definition of bridge pieces, which is used to determine the proper sprite...
CommandCost CmdBuildTunnel(TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build Tunnel.
#define lengthof(x)
Return the length of an fixed size array.
static T min(const T a, const T b)
Returns the minimum of two values.
static Foundation FlatteningFoundation(Slope s)
Returns the foundation needed to flatten a slope.
StringID railtype
Type of rail on the tile.
TileIndex GetSouthernBridgeEnd(TileIndex t)
Finds the southern end of a bridge starting at a middle tile.
static DiagDirection GetInclinedSlopeDirection(Slope s)
Returns the direction of an inclined slope.
Functions related to autoslope.
Functions related to sound.
static void SetBridgeMiddle(TileIndex t, Axis a)
Set that there is a bridge over the given axis.
ClearedObjectArea * FindClearedObject(TileIndex tile)
Find the entry in _cleared_object_areas which occupies a certain tile.
static DiagDirection GetTunnelBridgeDirection(TileIndex t)
Get the direction pointing to the other end.
Vehicle is currently going uphill. (Cached track information for acceleration)
static bool AutoslopeEnabled()
Tests if autoslope is enabled for _current_company.
Vehicle * First() const
Get the first vehicle of this vehicle chain.
static TrackStatus CombineTrackStatus(TrackdirBits trackdirbits, TrackdirBits red_signals)
Builds a TrackStatus.
bool build_on_slopes
allow building on slopes
bool Failed() const
Did this command fail?
Piece of rail in Y direction.
Bitflag for a wormhole (used for tunnels)
All ships have this type.
static Axis GetBridgeAxis(TileIndex t)
Get the axis of the bridge that goes over the tile.
void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, int x, int y, int w, int h, int dz, int z, bool transparent, int bb_offset_x, int bb_offset_y, int bb_offset_z, const SubSprite *sub)
Draw a (transparent) sprite at given coordinates with a given bounding box.
bool PlayVehicleSound(const Vehicle *v, VehicleSoundEvent event)
Checks whether a NewGRF wants to play a different vehicle sound effect.
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
static void SetRoadOwner(TileIndex t, RoadTramType rtt, Owner o)
Set the owner of a specific road type.
static void SetRoadside(TileIndex tile, Roadside s)
Set the decorations of a road.
static const SpriteID SPR_RAILTYPE_TUNNEL_BASE
Tunnel sprites with grass only for custom railtype tunnel.
Removal of a tunnel or bridge owned by the towb.
'Train' is either a loco or a wagon.
Functions related to clear (MP_CLEAR) land.
static BridgeType GetBridgeType(TileIndex t)
Determines the type of bridge on a tile.
CompanyInfrastructure infrastructure
NOSAVE: Counts of company owned infrastructure.
uint32 rail[RAILTYPE_END]
Count of company owned track bits for each rail type.
static Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
Town * CalcClosestTownFromTile(TileIndex tile, uint threshold=UINT_MAX)
Return the town closest to the given tile within threshold.
static TileIndex GetOtherTunnelBridgeEnd(TileIndex t)
Determines type of the wormhole and returns its other end.
static bool HasTunnelBridgeSnowOrDesert(TileIndex t)
Tunnel: Is this tunnel entrance in a snowy or desert area? Bridge: Does the bridge ramp lie in a snow...
execute the given command
The tile/execution is done by "water".
void GetSlopePixelZOnEdge(Slope tileh, DiagDirection edge, int *z1, int *z2)
Determine the Z height of the corners of a specific tile edge.
Required: Bridge surface images.
Vehicle is currently going downhill. (Cached track information for acceleration)
static Owner GetRoadOwner(TileIndex t, RoadTramType rtt)
Get the owner of a specific road type.
TrackBits state
The "track" the ship is following.
static bool IsNormalRoadTile(TileIndex t)
Return whether a tile is a normal road tile.
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
RailType
Enumeration for all possible railtypes.
GUISettings gui
settings related to the GUI
Tunnel entry/exit and bridge heads.
static bool HasTunnelBridgeReservation(TileIndex t)
Get the reservation state of the rail tunnel/bridge.
uint16 max_length
the maximum length (not counting start and end tile)
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
int GetTileMaxZ(TileIndex t)
Get top height of the tile inside the map.
uint16 road_speed
Speed limit of road (bridges and track)
Set of callback functions for performing tile operations of a given tile type.
uint32 TileIndex
The index/ID of a Tile.
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
static BridgePieces CalcBridgePiece(uint north, uint south)
Compute bridge piece.
This file contains all the sprites for bridges It consists of a number of arrays. ...
static void MakeRoadTunnel(TileIndex t, Owner o, DiagDirection d, RoadType road_rt, RoadType tram_rt)
Makes a road tunnel entrance.
Cheat crossing_tunnels
allow tunnels that cross each other
static int GetBridgePixelHeight(TileIndex tile)
Get the height ('z') of a bridge in pixels.
north and west corner are raised
static Money RailBuildCost(RailType railtype)
Returns the cost of building the specified railtype.
Track
These are used to specify a single track.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Cheat magic_bulldozer
dynamite industries, objects
Bit sets of the above specified bits.
when a sprite is to be displayed transparently, this bit needs to be set.
static T abs(const T a)
Returns the absolute value of (scalar) variable.
The tile has no foundation, the slope remains unchanged.
void FreeTrainTrackReservation(const Train *v)
Free the reserved path in front of a vehicle.
TransportType
Available types of transport.
static const uint MAX_BRIDGES
Maximal number of available bridge specs.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Slope
Enumeration for the slope-type.
VehicleType type
Type of vehicle.
void DrawRailCatenary(const TileInfo *ti)
Draws overhead wires and pylons for electric railways.
TownCache cache
Container for all cacheable data.
bool show_track_reservation
highlight reserved tracks.
Used to only draw a part of the sprite.
Transport by road vehicle.
byte max_bridge_height
maximum height of bridges
static const uint TILE_UNIT_MASK
For masking in/out the inner-tile world coordinate units.
Functions related to commands.
CompanyID _current_company
Company currently doing an action.
void DrawGroundSprite(SpriteID image, PaletteID pal, const SubSprite *sub, int extra_offs_x, int extra_offs_y)
Draws a ground sprite for the current tile.
byte GetSnowLine()
Get the current snow line, either variable or static.
uint BridgeType
Bridge spec number.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
static bool HasRailCatenaryDrawn(RailType rt)
Test if we should draw rail catenary.
void MarkBridgeDirty(TileIndex begin, TileIndex end, DiagDirection direction, uint bridge_height)
Mark bridge tiles dirty.
static uint TileHeight(TileIndex tile)
Returns the height of a tile.
header file for electrified rail specific functions
static Axis OtherAxis(Axis a)
Select the other axis as provided.
SpriteID bridge_offset
Bridge offset.
static const SpriteID SPR_TRAMWAY_BASE
Tramway sprites.
TileIndex GetOtherTunnelEnd(TileIndex tile)
Gets the other end of the tunnel.
static uint SlopeToSpriteOffset(Slope s)
Returns the Sprite offset for a given Slope.
static CommandCost DoClearTunnel(TileIndex tile, DoCommandFlag flags)
Remove a tunnel from the game, update town rating, etc.
ConstructionSettings construction
construction of things in-game
Functions that have tunnels and bridges in common.
static TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
static void DrawTile_TunnelBridge(TileInfo *ti)
Draws a tunnel of bridge tile.
StringID name
Name of this rail type.
static CommandCost ClearTile_TunnelBridge(TileIndex tile, DoCommandFlag flags)
Remove a tunnel or a bridge from the game.
EngineID engine_type
The type of engine used for this vehicle.
static Foundation InclinedFoundation(Axis axis)
Returns the along a specific axis inclined foundation.
StringID str
Description of the tile.
SpriteID tunnel
tunnel sprites base
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
static bool HasTileWaterClass(TileIndex t)
Checks whether the tile has an waterclass associated.
Functions related to NewGRF provided sounds.
DiagDirection
Enumeration for diagonal directions.
static TrackdirBits TrackBitsToTrackdirBits(TrackBits bits)
Converts TrackBits to TrackdirBits while allowing both directions.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Object can built under a bridge.
StringID roadtype
Type of road on the tile.
void DrawRoadOverlays(const TileInfo *ti, PaletteID pal, const RoadTypeInfo *road_rti, const RoadTypeInfo *tram_rti, uint road_offset, uint tram_offset)
Draw road underlay and overlay sprites.
Main group of ground images for snow or desert.
Northeast, upper right on your monitor.
GameCreationSettings game_creation
settings used during the creation of a game (map)
static bool IsPlainRail(TileIndex t)
Returns whether this is plain rails, with or without signals.
A tile without any structures, i.e. grass, rocks, farm fields etc.
static const ObjectSpec * GetByTile(TileIndex tile)
Get the specification associated with a tile.
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
void DrawGroundSpriteAt(SpriteID image, PaletteID pal, int32 x, int32 y, int z, const SubSprite *sub, int extra_offs_x, int extra_offs_y)
Draws a ground sprite at a specific world-coordinate relative to the current tile.
static bool IsInvisibilitySet(TransparencyOption to)
Check if the invisibility option bit is set and if we aren't in the game menu (there's never transpar...
uint DistanceSquare(TileIndex t0, TileIndex t1)
Gets the 'Square' distance between the two given tiles.
static void MakeAqueductBridgeRamp(TileIndex t, Owner o, DiagDirection d)
Make a bridge ramp for aqueducts.
Functions related to water (management)
static DiagDirection AxisToDiagDir(Axis a)
Converts an Axis to a DiagDirection.
VehicleEnterTileStatus
The returned bits of VehicleEnterTile.
SpriteID sprite
The 'real' sprite.
bool TryPathReserve(Train *v, bool mark_as_stuck=false, bool first_tile_okay=false)
Try to reserve a path to a safe position.
The object is owned by a superuser / goal script.
void CheckForDockingTile(TileIndex t)
Mark the supplied tile as a docking tile if it is suitable for docking.
static void DrawBridgePillars(const PalSpriteID *psid, const TileInfo *ti, Axis axis, bool drawfarpillar, int x, int y, int z_bridge)
Draws the pillars under high bridges.
static bool IsTunnel(TileIndex t)
Is this a tunnel (entrance)?
Optional: Images for overlaying track.
static bool IsTransparencySet(TransparencyOption to)
Check if the transparency option bit is set and if we aren't in the game menu (there's never transpar...
Axis
Allow incrementing of DiagDirDiff variables.
CommandCost CheckBridgeAvailability(BridgeType bridge_type, uint bridge_len, DoCommandFlag flags)
Is a bridge of the specified type and length available?
static bool IsRoadDepot(TileIndex t)
Return whether a tile is a road depot.
minimum rating after removing tunnel or bridge
static RailType GetRailType(TileIndex t)
Gets the rail type of the given tile.
static bool IsBridge(TileIndex t)
Checks if this is a bridge, instead of a tunnel.
CommandCost CheckforTownRating(DoCommandFlag flags, Town *t, TownRatingCheckType type)
Does the town authority allow the (destructive) action of the current company?
CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build a Bridge.
void ChangeTownRating(Town *t, int add, int max, DoCommandFlag flags)
Changes town rating of the current company.
TileIndex _build_tunnel_endtile
The end of a tunnel; as hidden return from the tunnel build command for GUI purposes.
Cheats _cheats
All the cheats.
uint16 max_tunnel_length
maximum length of tunnels
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
static CommandCost CheckBridgeSlope(BridgePieces bridge_piece, Axis axis, Slope *tileh, int *z)
Determines the foundation for the bridge head, and tests if the resulting slope is valid...
PaletteID pal
The palette (use PAL_NONE) if not needed)
uint32 water
Count of company owned track bits for canals.