OpenTTD Source: src/void_cmd.cpp Source File

OpenTTD Source 15.3

void_cmd.cpp
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#include "stdafx.h"
11#include "landscape.h"
12#include "command_func.h"
13#include "viewport_func.h"
14#include "slope_func.h"
15#include "water.h"
16
17#include "table/strings.h"
18#include "table/sprites.h"
19
20#include "safeguards.h"
21
22static void DrawTile_Void(TileInfo *ti)
23{
24 /* If freeform edges are off, draw infinite water off the edges of the map. */
25 if (!_settings_game.construction.freeform_edges) {
26 DrawGroundSprite(SPR_FLAT_WATER_TILE + SlopeToSpriteOffset(ti->tileh), PAL_NONE);
27 } else {
28 DrawGroundSprite(SPR_FLAT_BARE_LAND + SlopeToSpriteOffset(ti->tileh), PALETTE_ALL_BLACK);
29 }
30}
31
32
33static int GetSlopePixelZ_Void(TileIndex, uint x, uint y, bool)
34{
35 /* This function may be called on tiles outside the map, don't assume
36 * that 'tile' is a valid tile index. See GetSlopePixelZOutsideMap. */
37 auto [tileh, z] = GetTilePixelSlopeOutsideMap(x >> 4, y >> 4);
38
39 return z + GetPartialPixelZ(x & 0xF, y & 0xF, tileh);
40}
41
42static Foundation GetFoundation_Void(TileIndex, Slope)
43{
44 return FOUNDATION_NONE;
45}
46
47static CommandCost ClearTile_Void(TileIndex, DoCommandFlags)
48{
49 return CommandCost(STR_ERROR_OFF_EDGE_OF_MAP);
50}
51
52
53static void GetTileDesc_Void(TileIndex, TileDesc &td)
54{
55 td.str = STR_EMPTY;
56 td.owner[0] = OWNER_NONE;
57}
58
59static void TileLoop_Void(TileIndex tile)
60{
61 /* Floods adjacent edge tile to prevent maps without water. */
62 TileLoop_Water(tile);
63}
64
65static void ChangeTileOwner_Void(TileIndex, Owner, Owner)
66{
67 /* not used */
68}
69
70static TrackStatus GetTileTrackStatus_Void(TileIndex, TransportType, uint, DiagDirection)
71{
72 return 0;
73}
74
75static CommandCost TerraformTile_Void(TileIndex, DoCommandFlags, int, Slope)
76{
77 return CommandCost(STR_ERROR_OFF_EDGE_OF_MAP);
78}
79
80extern const TileTypeProcs _tile_type_void_procs = {
81 DrawTile_Void, // draw_tile_proc
82 GetSlopePixelZ_Void, // get_slope_z_proc
83 ClearTile_Void, // clear_tile_proc
84 nullptr, // add_accepted_cargo_proc
85 GetTileDesc_Void, // get_tile_desc_proc
86 GetTileTrackStatus_Void, // get_tile_track_status_proc
87 nullptr, // click_tile_proc
88 nullptr, // animate_tile_proc
89 TileLoop_Void, // tile_loop_proc
90 ChangeTileOwner_Void, // change_tile_owner_proc
91 nullptr, // add_produced_cargo_proc
92 nullptr, // vehicle_enter_tile_proc
93 GetFoundation_Void, // get_foundation_proc
94 TerraformTile_Void, // terraform_tile_proc
95 nullptr, // check_build_above_proc
96};
CommandCost
Common return value for all commands.
Definition command_type.h:24
EnumBitSet
Enum-as-bit-set wrapper.
Definition enum_type.hpp:177
command_func.h
Functions related to commands.
OWNER_NONE
static constexpr Owner OWNER_NONE
The tile has no ownership.
Definition company_type.h:26
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition direction_type.h:78
GetPartialPixelZ
uint GetPartialPixelZ(int x, int y, Slope corners)
Determines height at given coordinate of a slope.
Definition landscape.cpp:232
landscape.h
Functions related to OTTD's landscape.
safeguards.h
A number of safeguards to prevent using unsafe methods.
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:61
slope_func.h
Functions related to slopes.
SlopeToSpriteOffset
uint SlopeToSpriteOffset(Slope s)
Returns the Sprite offset for a given Slope.
Definition slope_func.h:415
Slope
Slope
Enumeration for the slope-type.
Definition slope_type.h:48
Foundation
Foundation
Enumeration for Foundations.
Definition slope_type.h:93
FOUNDATION_NONE
@ FOUNDATION_NONE
The tile has no foundation, the slope remains unchanged.
Definition slope_type.h:94
sprites.h
This file contains all sprite-related enums and defines.
PALETTE_ALL_BLACK
static const PaletteID PALETTE_ALL_BLACK
Exchange any colour by black, needed for painting fictive tiles outside map.
Definition sprites.h:1625
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
ConstructionSettings::freeform_edges
bool freeform_edges
allow terraforming the tiles at the map edges
Definition settings_type.h:423
GameSettings::construction
ConstructionSettings construction
construction of things in-game
Definition settings_type.h:635
PoolID< uint8_t, struct CompanyIDTag, 0xF, 0xFF >
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
TileDesc
Tile description for the 'land area information' tool.
Definition tile_cmd.h:36
TileDesc::str
StringID str
Description of the tile.
Definition tile_cmd.h:37
TileDesc::owner
std::array< Owner, 4 > owner
Name of the owner(s)
Definition tile_cmd.h:39
TileInfo
Tile information, used while rendering the tile.
Definition tile_cmd.h:30
TileInfo::tileh
Slope tileh
Slope of the tile.
Definition tile_cmd.h:31
TileTypeProcs
Set of callback functions for performing tile operations of a given tile type.
Definition tile_cmd.h:152
GetTilePixelSlopeOutsideMap
std::tuple< Slope, int > GetTilePixelSlopeOutsideMap(int x, int y)
Return the slope of a given tile, also for tiles outside the map (virtual "black" tiles).
Definition tile_map.cpp:78
TransportType
TransportType
Available types of transport.
Definition transport_type.h:17
DrawGroundSprite
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.
Definition viewport.cpp:579
viewport_func.h
Functions related to (drawing on) viewports.
water.h
Functions related to water (management)
TileLoop_Water
void TileLoop_Water(TileIndex tile)
Let a water tile floods its diagonal adjoining tiles called from tunnelbridge_cmd,...
Definition water_cmd.cpp:1269