OpenTTD Source: src/clear_cmd.cpp Source File

OpenTTD Source 15.0-RC2

clear_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 "clear_map.h"
12#include "command_func.h"
13#include "landscape.h"
14#include "genworld.h"
15#include "viewport_func.h"
16#include "core/random_func.hpp"
17#include "newgrf_generic.h"
18#include "landscape_cmd.h"
19
20#include "table/strings.h"
21#include "table/sprites.h"
22#include "table/clear_land.h"
23
24#include "safeguards.h"
25
26static CommandCost ClearTile_Clear(TileIndex tile, DoCommandFlags flags)
27{
28 static constexpr Price clear_price_table[] = {
29 PR_CLEAR_GRASS,
30 PR_CLEAR_ROUGH,
31 PR_CLEAR_ROCKS,
32 PR_CLEAR_FIELDS,
33 PR_CLEAR_ROUGH,
34 PR_CLEAR_ROUGH,
35 };
36 CommandCost price(EXPENSES_CONSTRUCTION);
37
38 ClearGround ground = GetClearGround(tile);
39 uint8_t density = GetClearDensity(tile);
40 if (IsSnowTile(tile)) {
41 price.AddCost(_price[clear_price_table[ground]]);
42 /* Add a little more for removing snow. */
43 price.AddCost(std::abs(_price[PR_CLEAR_ROUGH] - _price[PR_CLEAR_GRASS]));
44 } else if (ground != CLEAR_GRASS || density != 0) {
45 price.AddCost(_price[clear_price_table[ground]]);
46 }
47
48 if (flags.Test(DoCommandFlag::Execute)) DoClearSquare(tile);
49
50 return price;
51}
52
53void DrawClearLandTile(const TileInfo *ti, uint8_t set)
54{
55 DrawGroundSprite(SPR_FLAT_BARE_LAND + SlopeToSpriteOffset(ti->tileh) + set * 19, PAL_NONE);
56}
57
58void DrawHillyLandTile(const TileInfo *ti)
59{
60 if (ti->tileh != SLOPE_FLAT) {
61 DrawGroundSprite(SPR_FLAT_ROUGH_LAND + SlopeToSpriteOffset(ti->tileh), PAL_NONE);
62 } else {
63 DrawGroundSprite(_landscape_clear_sprites_rough[GB(TileHash(ti->x, ti->y), 0, 3)], PAL_NONE);
64 }
65}
66
67static void DrawClearLandFence(const TileInfo *ti)
68{
69 /* combine fences into one sprite object */
70 StartSpriteCombine();
71
72 SpriteBounds bounds{{}, {TILE_SIZE, TILE_SIZE, 4}, {}};
73
74 bounds.extent.z += GetSlopeMaxPixelZ(ti->tileh);
75
76 uint fence_nw = GetFence(ti->tile, DIAGDIR_NW);
77 if (fence_nw != 0) {
78 bounds.offset.x = 0;
79 bounds.offset.y = -static_cast<int>(TILE_SIZE);
80 bounds.offset.z = GetSlopePixelZInCorner(ti->tileh, CORNER_W);
81 SpriteID sprite = _clear_land_fence_sprites[fence_nw - 1] + _fence_mod_by_tileh_nw[ti->tileh];
82 AddSortableSpriteToDraw(sprite, PAL_NONE, *ti, bounds, false);
83 }
84
85 uint fence_ne = GetFence(ti->tile, DIAGDIR_NE);
86 if (fence_ne != 0) {
87 bounds.offset.x = -static_cast<int>(TILE_SIZE);
88 bounds.offset.y = 0;
89 bounds.offset.z = GetSlopePixelZInCorner(ti->tileh, CORNER_E);
90 SpriteID sprite = _clear_land_fence_sprites[fence_ne - 1] + _fence_mod_by_tileh_ne[ti->tileh];
91 AddSortableSpriteToDraw(sprite, PAL_NONE, *ti, bounds, false);
92 }
93
94 uint fence_sw = GetFence(ti->tile, DIAGDIR_SW);
95 uint fence_se = GetFence(ti->tile, DIAGDIR_SE);
96
97 if (fence_sw != 0 || fence_se != 0) {
98 bounds.offset.x = 0;
99 bounds.offset.y = 0;
100 bounds.offset.z = GetSlopePixelZInCorner(ti->tileh, CORNER_S);
101
102 if (fence_sw != 0) {
103 SpriteID sprite = _clear_land_fence_sprites[fence_sw - 1] + _fence_mod_by_tileh_sw[ti->tileh];
104 AddSortableSpriteToDraw(sprite, PAL_NONE, *ti, bounds, false);
105 }
106
107 if (fence_se != 0) {
108 SpriteID sprite = _clear_land_fence_sprites[fence_se - 1] + _fence_mod_by_tileh_se[ti->tileh];
109 AddSortableSpriteToDraw(sprite, PAL_NONE, *ti, bounds, false);
110
111 }
112 }
113 EndSpriteCombine();
114}
115
116static void DrawTile_Clear(TileInfo *ti)
117{
118 ClearGround real_ground = GetClearGround(ti->tile);
119 ClearGround ground = IsSnowTile(ti->tile) ? CLEAR_SNOW : real_ground;
120
121 switch (ground) {
122 case CLEAR_GRASS:
123 DrawClearLandTile(ti, GetClearDensity(ti->tile));
124 break;
125
126 case CLEAR_ROUGH:
127 DrawHillyLandTile(ti);
128 break;
129
130 case CLEAR_ROCKS:
131 DrawGroundSprite((HasGrfMiscBit(GrfMiscBit::SecondRockyTileSet) && (TileHash(ti->x, ti->y) & 1) ? SPR_FLAT_ROCKY_LAND_2 : SPR_FLAT_ROCKY_LAND_1) + SlopeToSpriteOffset(ti->tileh), PAL_NONE);
132 break;
133
134 case CLEAR_FIELDS:
135 DrawGroundSprite(_clear_land_sprites_farmland[GetFieldType(ti->tile)] + SlopeToSpriteOffset(ti->tileh), PAL_NONE);
136 DrawClearLandFence(ti);
137 break;
138
139 case CLEAR_SNOW: {
140 uint8_t density = GetClearDensity(ti->tile);
141 DrawGroundSprite(_clear_land_sprites_snow_desert[density] + SlopeToSpriteOffset(ti->tileh), PAL_NONE);
142 if (real_ground == CLEAR_ROCKS) {
143 /* There 4 levels of snowy overlay rocks, each with 19 sprites. */
144 ++density;
145 DrawGroundSprite(SPR_OVERLAY_ROCKS_BASE + (density * 19) + SlopeToSpriteOffset(ti->tileh), PAL_NONE);
146 }
147 break;
148 }
149
150 case CLEAR_DESERT:
151 DrawGroundSprite(_clear_land_sprites_snow_desert[GetClearDensity(ti->tile)] + SlopeToSpriteOffset(ti->tileh), PAL_NONE);
152 break;
153 }
154
155 DrawBridgeMiddle(ti, {});
156}
157
158static int GetSlopePixelZ_Clear(TileIndex tile, uint x, uint y, bool)
159{
160 auto [tileh, z] = GetTilePixelSlope(tile);
161
162 return z + GetPartialPixelZ(x & 0xF, y & 0xF, tileh);
163}
164
165static Foundation GetFoundation_Clear(TileIndex, Slope)
166{
167 return FOUNDATION_NONE;
168}
169
170static void UpdateFences(TileIndex tile)
171{
172 assert(IsTileType(tile, MP_CLEAR) && IsClearGround(tile, CLEAR_FIELDS));
173 bool dirty = false;
174
175 for (DiagDirection dir = DIAGDIR_BEGIN; dir < DIAGDIR_END; dir++) {
176 if (GetFence(tile, dir) != 0) continue;
177 TileIndex neighbour = tile + TileOffsByDiagDir(dir);
178 if (IsTileType(neighbour, MP_CLEAR) && IsClearGround(neighbour, CLEAR_FIELDS)) continue;
179 SetFence(tile, dir, 3);
180 dirty = true;
181 }
182
183 if (dirty) MarkTileDirtyByTile(tile);
184}
185
186
188 static void TileLoopClearAlps(TileIndex tile)
189{
190 int k = GetTileZ(tile) - GetSnowLine() + 1;
191
192 if (!IsSnowTile(tile)) {
193 /* Below the snow line, do nothing if no snow. */
194 /* At or above the snow line, make snow tile if needed. */
195 if (k >= 0) {
196 /* Snow density is started at 0 so that it can gradually reach the required density. */
197 MakeSnow(tile, 0);
198 MarkTileDirtyByTile(tile);
199 }
200 return;
201 }
202
203 /* Update snow density. */
204 uint current_density = GetClearDensity(tile);
205 uint req_density = (k < 0) ? 0u : std::min<uint>(k, 3u);
206
207 if (current_density == req_density) {
208 /* Density at the required level. */
209 if (k >= 0) return;
210 ClearSnow(tile);
211 } else {
212 AddClearDensity(tile, current_density < req_density ? 1 : -1);
213 }
214
215 MarkTileDirtyByTile(tile);
216}
217
223 static inline bool NeighbourIsNormal(TileIndex tile)
224{
225 for (DiagDirection dir = DIAGDIR_BEGIN; dir < DIAGDIR_END; dir++) {
226 TileIndex t = tile + TileOffsByDiagDir(dir);
227 if (!IsValidTile(t)) continue;
228 if (GetTropicZone(t) != TROPICZONE_DESERT) return true;
229 if (HasTileWaterClass(t) && GetWaterClass(t) == WaterClass::Sea) return true;
230 }
231 return false;
232}
233
234static void TileLoopClearDesert(TileIndex tile)
235{
236 /* Current desert level - 0 if it is not desert */
237 uint current = 0;
238 if (IsClearGround(tile, CLEAR_DESERT)) current = GetClearDensity(tile);
239
240 /* Expected desert level - 0 if it shouldn't be desert */
241 uint expected = 0;
242 if (GetTropicZone(tile) == TROPICZONE_DESERT) {
243 expected = NeighbourIsNormal(tile) ? 1 : 3;
244 }
245
246 if (current == expected) return;
247
248 if (expected == 0) {
249 SetClearGroundDensity(tile, CLEAR_GRASS, 3);
250 } else {
251 /* Transition from clear to desert is not smooth (after clearing desert tile) */
252 SetClearGroundDensity(tile, CLEAR_DESERT, expected);
253 }
254
255 MarkTileDirtyByTile(tile);
256}
257
258static void TileLoop_Clear(TileIndex tile)
259{
260 AmbientSoundEffect(tile);
261
262 switch (_settings_game.game_creation.landscape) {
263 case LandscapeType::Tropic: TileLoopClearDesert(tile); break;
264 case LandscapeType::Arctic: TileLoopClearAlps(tile); break;
265 default: break;
266 }
267
268 if (IsSnowTile(tile)) return;
269
270 switch (GetClearGround(tile)) {
271 case CLEAR_GRASS:
272 if (GetClearDensity(tile) == 3) return;
273
274 if (_game_mode != GM_EDITOR) {
275 if (GetClearCounter(tile) < 7) {
276 AddClearCounter(tile, 1);
277 return;
278 } else {
279 SetClearCounter(tile, 0);
280 AddClearDensity(tile, 1);
281 }
282 } else {
283 SetClearGroundDensity(tile, GB(Random(), 0, 8) > 21 ? CLEAR_GRASS : CLEAR_ROUGH, 3);
284 }
285 break;
286
287 case CLEAR_FIELDS:
288 UpdateFences(tile);
289
290 if (_game_mode == GM_EDITOR) return;
291
292 if (GetClearCounter(tile) < 7) {
293 AddClearCounter(tile, 1);
294 return;
295 } else {
296 SetClearCounter(tile, 0);
297 }
298
299 if (GetIndustryIndexOfField(tile) == IndustryID::Invalid() && GetFieldType(tile) >= 7) {
300 /* This farmfield is no longer farmfield, so make it grass again */
301 MakeClear(tile, CLEAR_GRASS, 2);
302 } else {
303 uint field_type = GetFieldType(tile);
304 field_type = (field_type < 8) ? field_type + 1 : 0;
305 SetFieldType(tile, field_type);
306 }
307 break;
308
309 default:
310 return;
311 }
312
313 MarkTileDirtyByTile(tile);
314}
315
316void GenerateClearTile()
317{
318 uint i, gi;
319 TileIndex tile;
320
321 /* add rough tiles */
322 i = Map::ScaleBySize(GB(Random(), 0, 10) + 0x400);
323 gi = Map::ScaleBySize(GB(Random(), 0, 7) + 0x80);
324
325 SetGeneratingWorldProgress(GWP_ROUGH_ROCKY, gi + i);
326 do {
327 IncreaseGeneratingWorldProgress(GWP_ROUGH_ROCKY);
328 tile = RandomTile();
329 if (IsTileType(tile, MP_CLEAR) && !IsClearGround(tile, CLEAR_DESERT)) SetClearGroundDensity(tile, CLEAR_ROUGH, 3);
330 } while (--i);
331
332 /* add rocky tiles */
333 i = gi;
334 do {
335 uint32_t r = Random();
336 tile = RandomTileSeed(r);
337
338 IncreaseGeneratingWorldProgress(GWP_ROUGH_ROCKY);
339 if (IsTileType(tile, MP_CLEAR) && !IsClearGround(tile, CLEAR_DESERT)) {
340 uint j = GB(r, 16, 4) + 5;
341 for (;;) {
342 TileIndex tile_new;
343
344 SetClearGroundDensity(tile, CLEAR_ROCKS, 3);
345 MarkTileDirtyByTile(tile);
346 do {
347 if (--j == 0) goto get_out;
348 tile_new = tile + TileOffsByDiagDir((DiagDirection)GB(Random(), 0, 2));
349 } while (!IsTileType(tile_new, MP_CLEAR) || IsClearGround(tile_new, CLEAR_DESERT));
350 tile = tile_new;
351 }
352get_out:;
353 }
354 } while (--i);
355}
356
357static TrackStatus GetTileTrackStatus_Clear(TileIndex, TransportType, uint, DiagDirection)
358{
359 return 0;
360}
361
362static void GetTileDesc_Clear(TileIndex tile, TileDesc &td)
363{
364 /* Each pair holds a normal and a snowy ClearGround description. */
365 static constexpr std::pair<StringID, StringID> clear_land_str[] = {
366 {STR_LAI_CLEAR_DESCRIPTION_GRASS, STR_LAI_CLEAR_DESCRIPTION_SNOWY_GRASS},
367 {STR_LAI_CLEAR_DESCRIPTION_ROUGH_LAND, STR_LAI_CLEAR_DESCRIPTION_SNOWY_ROUGH_LAND},
368 {STR_LAI_CLEAR_DESCRIPTION_ROCKS, STR_LAI_CLEAR_DESCRIPTION_SNOWY_ROCKS},
369 {STR_LAI_CLEAR_DESCRIPTION_FIELDS, STR_EMPTY},
370 {STR_EMPTY, STR_EMPTY}, // CLEAR_SNOW does not appear in the map.
371 {STR_LAI_CLEAR_DESCRIPTION_DESERT, STR_EMPTY},
372 };
373
374 if (!IsSnowTile(tile) && IsClearGround(tile, CLEAR_GRASS) && GetClearDensity(tile) == 0) {
375 td.str = STR_LAI_CLEAR_DESCRIPTION_BARE_LAND;
376 } else {
377 const auto &[name, snowy_name] = clear_land_str[GetClearGround(tile)];
378 td.str = IsSnowTile(tile) ? snowy_name : name;
379 }
380 td.owner[0] = GetTileOwner(tile);
381}
382
383static void ChangeTileOwner_Clear(TileIndex, Owner, Owner)
384{
385 return;
386}
387
388static CommandCost TerraformTile_Clear(TileIndex tile, DoCommandFlags flags, int, Slope)
389{
390 return Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile);
391}
392
393static CommandCost CheckBuildAbove_Clear(TileIndex, DoCommandFlags, Axis, int)
394{
395 /* Can always build above clear tiles. */
396 return CommandCost();
397}
398
399extern const TileTypeProcs _tile_type_clear_procs = {
400 DrawTile_Clear,
401 GetSlopePixelZ_Clear,
402 ClearTile_Clear,
403 nullptr,
404 GetTileDesc_Clear,
405 GetTileTrackStatus_Clear,
406 nullptr,
407 nullptr,
408 TileLoop_Clear,
409 ChangeTileOwner_Clear,
410 nullptr,
411 nullptr,
412 GetFoundation_Clear,
413 TerraformTile_Clear,
414 CheckBuildAbove_Clear, // check_build_above_proc
415};
GB
static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
Definition bitmath_func.hpp:32
DrawBridgeMiddle
void DrawBridgeMiddle(const TileInfo *ti, BridgePillarFlags blocked_pillars)
Draw the middle bits of a bridge.
Definition tunnelbridge_cmd.cpp:1607
BaseBitSet::Test
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Definition base_bitset_type.hpp:141
CommandCost
Common return value for all commands.
Definition command_type.h:24
EnumBitSet
Enum-as-bit-set wrapper.
Definition enum_type.hpp:177
NeighbourIsNormal
static bool NeighbourIsNormal(TileIndex tile)
Tests if at least one surrounding tile is non-desert.
Definition clear_cmd.cpp:223
TileLoopClearAlps
static void TileLoopClearAlps(TileIndex tile)
Convert to or from snowy tiles.
Definition clear_cmd.cpp:188
clear_land.h
Tables with sprites for clear land and fences.
clear_map.h
Map accessors for 'clear' tiles.
SetFieldType
void SetFieldType(Tile t, uint f)
Set the field type (production stage) of the field.
Definition clear_map.h:171
AddClearCounter
void AddClearCounter(Tile t, int c)
Increments the counter used to advance to the next clear density/field type.
Definition clear_map.h:120
GetFieldType
uint GetFieldType(Tile t)
Get the field type (production stage) of the field.
Definition clear_map.h:159
AddClearDensity
void AddClearDensity(Tile t, int d)
Increment the density of a non-field clear tile.
Definition clear_map.h:83
ClearSnow
void ClearSnow(Tile t)
Clear the snow from a tile and return it to its previous type.
Definition clear_map.h:304
IsClearGround
bool IsClearGround(Tile t, ClearGround ct)
Set the type of clear tile.
Definition clear_map.h:59
MakeSnow
void MakeSnow(Tile t, uint density=0)
Make a snow tile.
Definition clear_map.h:288
SetFence
void SetFence(Tile t, DiagDirection side, uint h)
Sets the type of fence (and whether there is one) for the given border.
Definition clear_map.h:228
GetIndustryIndexOfField
IndustryID GetIndustryIndexOfField(Tile t)
Get the industry (farm) that made the field.
Definition clear_map.h:183
ClearGround
ClearGround
Ground types.
Definition clear_map.h:19
CLEAR_GRASS
@ CLEAR_GRASS
0-3
Definition clear_map.h:20
CLEAR_FIELDS
@ CLEAR_FIELDS
3
Definition clear_map.h:23
CLEAR_DESERT
@ CLEAR_DESERT
1,3
Definition clear_map.h:25
CLEAR_SNOW
@ CLEAR_SNOW
0-3 (Not stored in map.)
Definition clear_map.h:24
CLEAR_ROUGH
@ CLEAR_ROUGH
3
Definition clear_map.h:21
CLEAR_ROCKS
@ CLEAR_ROCKS
3
Definition clear_map.h:22
MakeClear
void MakeClear(Tile t, ClearGround g, uint density)
Make a clear tile.
Definition clear_map.h:247
GetClearGround
ClearGround GetClearGround(Tile t)
Get the type of clear tile.
Definition clear_map.h:47
SetClearCounter
void SetClearCounter(Tile t, uint c)
Sets the counter used to advance to the next clear density/field type.
Definition clear_map.h:132
SetClearGroundDensity
void SetClearGroundDensity(Tile t, ClearGround type, uint density)
Sets ground type and density in one go, also sets the counter to 0.
Definition clear_map.h:146
GetFence
uint GetFence(Tile t, DiagDirection side)
Is there a fence at the given border?
Definition clear_map.h:209
GetClearCounter
uint GetClearCounter(Tile t)
Get the counter used to advance to the next clear density/field type.
Definition clear_map.h:108
IsSnowTile
bool IsSnowTile(Tile t)
Test if a tile is covered with snow.
Definition clear_map.h:35
GetClearDensity
uint GetClearDensity(Tile t)
Get the density of a non-field clear tile.
Definition clear_map.h:71
command_func.h
Functions related to commands.
DoCommandFlag::Execute
@ Execute
execute the given command
Axis
Axis
Allow incrementing of DiagDirDiff variables.
Definition direction_type.h:123
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition direction_type.h:78
DIAGDIR_NE
@ DIAGDIR_NE
Northeast, upper right on your monitor.
Definition direction_type.h:80
DIAGDIR_NW
@ DIAGDIR_NW
Northwest.
Definition direction_type.h:83
DIAGDIR_SE
@ DIAGDIR_SE
Southeast.
Definition direction_type.h:81
DIAGDIR_END
@ DIAGDIR_END
Used for iterations.
Definition direction_type.h:84
DIAGDIR_BEGIN
@ DIAGDIR_BEGIN
Used for iterations.
Definition direction_type.h:79
DIAGDIR_SW
@ DIAGDIR_SW
Southwest.
Definition direction_type.h:82
EXPENSES_CONSTRUCTION
@ EXPENSES_CONSTRUCTION
Construction costs.
Definition economy_type.h:179
Price
Price
Enumeration of all base prices for use with Prices.
Definition economy_type.h:95
genworld.h
Functions related to world/map generation.
IncreaseGeneratingWorldProgress
void IncreaseGeneratingWorldProgress(GenWorldProgress cls)
Increases the current stage of the world generation with one.
Definition genworld_gui.cpp:1534
GWP_ROUGH_ROCKY
@ GWP_ROUGH_ROCKY
Make rough and rocky areas.
Definition genworld.h:65
SetGeneratingWorldProgress
void SetGeneratingWorldProgress(GenWorldProgress cls, uint total)
Set the total of a stage of the world generation.
Definition genworld_gui.cpp:1520
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
GetSnowLine
uint8_t GetSnowLine()
Get the current snow line, either variable or static.
Definition landscape.cpp:605
MarkTileDirtyByTile
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
Definition viewport.cpp:2128
GetPartialPixelZ
uint GetPartialPixelZ(int x, int y, Slope corners)
Determines height at given coordinate of a slope.
Definition landscape.cpp:231
landscape.h
Functions related to OTTD's landscape.
GetSlopePixelZInCorner
int GetSlopePixelZInCorner(Slope tileh, Corner corner)
Determine the Z height of a corner relative to TileZ.
Definition landscape.h:55
landscape_cmd.h
Command definitions related to landscape (slopes etc.).
BorderFlag::Random
@ Random
Randomise borders.
RandomTileSeed
TileIndex RandomTileSeed(uint32_t r)
Get a random tile out of a given seed.
Definition map_func.h:653
RandomTile
#define RandomTile()
Get a valid random tile.
Definition map_func.h:664
TileOffsByDiagDir
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition map_func.h:582
HasGrfMiscBit
bool HasGrfMiscBit(GrfMiscBit bit)
Check for grf miscellaneous bits.
Definition newgrf.h:209
newgrf_generic.h
Functions related to generic callbacks.
AmbientSoundEffect
void AmbientSoundEffect(TileIndex tile)
Play an ambient sound effect for an empty tile.
Definition newgrf_generic.h:54
random_func.hpp
Pseudo random number generator.
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
SlopeToSpriteOffset
uint SlopeToSpriteOffset(Slope s)
Returns the Sprite offset for a given Slope.
Definition slope_func.h:415
GetSlopeMaxPixelZ
static constexpr int GetSlopeMaxPixelZ(Slope s)
Returns the height of the highest corner of a slope relative to TileZ (= minimal height)
Definition slope_func.h:173
Slope
Slope
Enumeration for the slope-type.
Definition slope_type.h:48
SLOPE_FLAT
@ SLOPE_FLAT
a flat tile
Definition slope_type.h:49
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.
SPR_OVERLAY_ROCKS_BASE
static constexpr SpriteID SPR_OVERLAY_ROCKS_BASE
Overlay rocks sprites.
Definition sprites.h:321
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
CommandHelper
Definition command_func.h:83
Coord3D::x
T x
X coordinate.
Definition geometry_type.hpp:44
Coord3D::y
T y
Y coordinate.
Definition geometry_type.hpp:45
Coord3D::z
T z
Z coordinate.
Definition geometry_type.hpp:46
GameCreationSettings::landscape
LandscapeType landscape
the landscape we're currently in
Definition settings_type.h:395
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition settings_type.h:634
Map::ScaleBySize
static uint ScaleBySize(uint n)
Scales the given value by the map size, where the given value is for a 256 by 256 map.
Definition map_func.h:340
PoolID< uint8_t, struct CompanyIDTag, 0xF, 0xFF >
SpriteBounds
Definition sprite.h:18
SpriteBounds::extent
Coord3D< uint8_t > extent
Size of bounding box.
Definition sprite.h:20
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
TileInfo::tile
TileIndex tile
Tile index.
Definition tile_cmd.h:32
TileTypeProcs
Set of callback functions for performing tile operations of a given tile type.
Definition tile_cmd.h:152
GetTileZ
int GetTileZ(TileIndex tile)
Get bottom height of the tile.
Definition tile_map.cpp:116
IsTileType
static bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition tile_map.h:150
TileHash
uint TileHash(uint x, uint y)
Calculate a hash value from a tile position.
Definition tile_map.h:324
GetTileOwner
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
Definition tile_map.h:178
GetTilePixelSlope
std::tuple< Slope, int > GetTilePixelSlope(TileIndex tile)
Return the slope of a given tile.
Definition tile_map.h:289
IsValidTile
bool IsValidTile(Tile tile)
Checks if a tile is valid.
Definition tile_map.h:161
GetTropicZone
TropicZone GetTropicZone(Tile tile)
Get the tropic zone.
Definition tile_map.h:238
TROPICZONE_DESERT
@ TROPICZONE_DESERT
Tile is desert.
Definition tile_type.h:78
TILE_SIZE
static constexpr uint TILE_SIZE
Tile size in world coordinates.
Definition tile_type.h:15
MP_CLEAR
@ MP_CLEAR
A tile without any structures, i.e. grass, rocks, farm fields etc.
Definition tile_type.h:48
TransportType
TransportType
Available types of transport.
Definition transport_type.h:17
StartSpriteCombine
void StartSpriteCombine()
Starts a block of sprites, which are "combined" into a single bounding box.
Definition viewport.cpp:764
AddSortableSpriteToDraw
void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, int x, int y, int z, const SpriteBounds &bounds, bool transparent, const SubSprite *sub)
Draw a (transparent) sprite at given coordinates with a given bounding box.
Definition viewport.cpp:663
EndSpriteCombine
void EndSpriteCombine()
Terminates a block of sprites started by StartSpriteCombine.
Definition viewport.cpp:774
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.
WaterClass::Sea
@ Sea
Sea.
HasTileWaterClass
bool HasTileWaterClass(Tile t)
Checks whether the tile has an waterclass associated.
Definition water_map.h:103
GetWaterClass
WaterClass GetWaterClass(Tile t)
Get the water class at a tile.
Definition water_map.h:114