Update: Translations from eints
[openttd-github.git] / src / landscape.cpp
blob8cdfb7227bb15eeaf5df2e0c022ac2923c195134
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 <http://www.gnu.org/licenses/>.
6 */
8 /** @file landscape.cpp Functions related to the landscape (slopes etc.). */
10 /** @defgroup SnowLineGroup Snowline functions and data structures */
12 #include "stdafx.h"
13 #include "heightmap.h"
14 #include "clear_map.h"
15 #include "spritecache.h"
16 #include "viewport_func.h"
17 #include "command_func.h"
18 #include "landscape.h"
19 #include "void_map.h"
20 #include "tgp.h"
21 #include "genworld.h"
22 #include "fios.h"
23 #include "error_func.h"
24 #include "timer/timer_game_calendar.h"
25 #include "timer/timer_game_tick.h"
26 #include "water.h"
27 #include "effectvehicle_func.h"
28 #include "landscape_type.h"
29 #include "animated_tile_func.h"
30 #include "core/random_func.hpp"
31 #include "object_base.h"
32 #include "company_func.h"
33 #include "company_gui.h"
34 #include "pathfinder/aystar.h"
35 #include "saveload/saveload.h"
36 #include "framerate_type.h"
37 #include "landscape_cmd.h"
38 #include "terraform_cmd.h"
39 #include "station_func.h"
40 #include "pathfinder/water_regions.h"
42 #include "table/strings.h"
43 #include "table/sprites.h"
45 #include "safeguards.h"
47 extern const TileTypeProcs
48 _tile_type_clear_procs,
49 _tile_type_rail_procs,
50 _tile_type_road_procs,
51 _tile_type_town_procs,
52 _tile_type_trees_procs,
53 _tile_type_station_procs,
54 _tile_type_water_procs,
55 _tile_type_void_procs,
56 _tile_type_industry_procs,
57 _tile_type_tunnelbridge_procs,
58 _tile_type_object_procs;
60 /**
61 * Tile callback functions for each type of tile.
62 * @ingroup TileCallbackGroup
63 * @see TileType
65 const TileTypeProcs * const _tile_type_procs[16] = {
66 &_tile_type_clear_procs, ///< Callback functions for MP_CLEAR tiles
67 &_tile_type_rail_procs, ///< Callback functions for MP_RAILWAY tiles
68 &_tile_type_road_procs, ///< Callback functions for MP_ROAD tiles
69 &_tile_type_town_procs, ///< Callback functions for MP_HOUSE tiles
70 &_tile_type_trees_procs, ///< Callback functions for MP_TREES tiles
71 &_tile_type_station_procs, ///< Callback functions for MP_STATION tiles
72 &_tile_type_water_procs, ///< Callback functions for MP_WATER tiles
73 &_tile_type_void_procs, ///< Callback functions for MP_VOID tiles
74 &_tile_type_industry_procs, ///< Callback functions for MP_INDUSTRY tiles
75 &_tile_type_tunnelbridge_procs, ///< Callback functions for MP_TUNNELBRIDGE tiles
76 &_tile_type_object_procs, ///< Callback functions for MP_OBJECT tiles
79 /** landscape slope => sprite */
80 extern const uint8_t _slope_to_sprite_offset[32] = {
81 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0,
82 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 17, 0, 15, 18, 0,
85 static const uint TILE_UPDATE_FREQUENCY_LOG = 8; ///< The logarithm of how many ticks it takes between tile updates (log base 2).
86 static const uint TILE_UPDATE_FREQUENCY = 1 << TILE_UPDATE_FREQUENCY_LOG; ///< How many ticks it takes between tile updates (has to be a power of 2).
88 /**
89 * Description of the snow line throughout the year.
91 * If it is \c nullptr, a static snowline height is used, as set by \c _settings_game.game_creation.snow_line_height.
92 * Otherwise it points to a table loaded from a newGRF file that describes the variable snowline.
93 * @ingroup SnowLineGroup
94 * @see GetSnowLine() GameCreationSettings
96 static SnowLine *_snow_line = nullptr;
98 /**
99 * Map 2D viewport or smallmap coordinate to 3D world or tile coordinate.
100 * Function takes into account height of tiles and foundations.
102 * @param x X viewport 2D coordinate.
103 * @param y Y viewport 2D coordinate.
104 * @param clamp_to_map Clamp the coordinate outside of the map to the closest, non-void tile within the map.
105 * @param[out] clamped Whether coordinates were clamped.
106 * @return 3D world coordinate of point visible at the given screen coordinate (3D perspective).
108 * @note Inverse of #RemapCoords2 function. Smaller values may get rounded.
109 * @see InverseRemapCoords
111 Point InverseRemapCoords2(int x, int y, bool clamp_to_map, bool *clamped)
113 if (clamped != nullptr) *clamped = false; // Not clamping yet.
115 /* Initial x/y world coordinate is like if the landscape
116 * was completely flat on height 0. */
117 Point pt = InverseRemapCoords(x, y);
119 const uint min_coord = _settings_game.construction.freeform_edges ? TILE_SIZE : 0;
120 const uint max_x = Map::MaxX() * TILE_SIZE - 1;
121 const uint max_y = Map::MaxY() * TILE_SIZE - 1;
123 if (clamp_to_map) {
124 /* Bring the coordinates near to a valid range. At the top we allow a number
125 * of extra tiles. This is mostly due to the tiles on the north side of
126 * the map possibly being drawn higher due to the extra height levels. */
127 int extra_tiles = CeilDiv(_settings_game.construction.map_height_limit * TILE_HEIGHT, TILE_PIXELS);
128 Point old_pt = pt;
129 pt.x = Clamp(pt.x, -extra_tiles * TILE_SIZE, max_x);
130 pt.y = Clamp(pt.y, -extra_tiles * TILE_SIZE, max_y);
131 if (clamped != nullptr) *clamped = (pt.x != old_pt.x) || (pt.y != old_pt.y);
134 /* Now find the Z-world coordinate by fix point iteration.
135 * This is a bit tricky because the tile height is non-continuous at foundations.
136 * The clicked point should be approached from the back, otherwise there are regions that are not clickable.
137 * (FOUNDATION_HALFTILE_LOWER on SLOPE_STEEP_S hides north halftile completely)
138 * So give it a z-malus of 4 in the first iterations. */
139 int z = 0;
140 if (clamp_to_map) {
141 for (int i = 0; i < 5; i++) z = GetSlopePixelZ(Clamp(pt.x + std::max(z, 4) - 4, min_coord, max_x), Clamp(pt.y + std::max(z, 4) - 4, min_coord, max_y)) / 2;
142 for (int m = 3; m > 0; m--) z = GetSlopePixelZ(Clamp(pt.x + std::max(z, m) - m, min_coord, max_x), Clamp(pt.y + std::max(z, m) - m, min_coord, max_y)) / 2;
143 for (int i = 0; i < 5; i++) z = GetSlopePixelZ(Clamp(pt.x + z, min_coord, max_x), Clamp(pt.y + z, min_coord, max_y)) / 2;
144 } else {
145 for (int i = 0; i < 5; i++) z = GetSlopePixelZOutsideMap(pt.x + std::max(z, 4) - 4, pt.y + std::max(z, 4) - 4) / 2;
146 for (int m = 3; m > 0; m--) z = GetSlopePixelZOutsideMap(pt.x + std::max(z, m) - m, pt.y + std::max(z, m) - m) / 2;
147 for (int i = 0; i < 5; i++) z = GetSlopePixelZOutsideMap(pt.x + z, pt.y + z ) / 2;
150 pt.x += z;
151 pt.y += z;
152 if (clamp_to_map) {
153 Point old_pt = pt;
154 pt.x = Clamp(pt.x, min_coord, max_x);
155 pt.y = Clamp(pt.y, min_coord, max_y);
156 if (clamped != nullptr) *clamped = *clamped || (pt.x != old_pt.x) || (pt.y != old_pt.y);
159 return pt;
163 * Applies a foundation to a slope.
165 * @pre Foundation and slope must be valid combined.
166 * @param f The #Foundation.
167 * @param s The #Slope to modify.
168 * @return Increment to the tile Z coordinate.
170 uint ApplyFoundationToSlope(Foundation f, Slope &s)
172 if (!IsFoundation(f)) return 0;
174 if (IsLeveledFoundation(f)) {
175 uint dz = 1 + (IsSteepSlope(s) ? 1 : 0);
176 s = SLOPE_FLAT;
177 return dz;
180 if (f != FOUNDATION_STEEP_BOTH && IsNonContinuousFoundation(f)) {
181 s = HalftileSlope(s, GetHalftileFoundationCorner(f));
182 return 0;
185 if (IsSpecialRailFoundation(f)) {
186 s = SlopeWithThreeCornersRaised(OppositeCorner(GetRailFoundationCorner(f)));
187 return 0;
190 uint dz = IsSteepSlope(s) ? 1 : 0;
191 Corner highest_corner = GetHighestSlopeCorner(s);
193 switch (f) {
194 case FOUNDATION_INCLINED_X:
195 s = (((highest_corner == CORNER_W) || (highest_corner == CORNER_S)) ? SLOPE_SW : SLOPE_NE);
196 break;
198 case FOUNDATION_INCLINED_Y:
199 s = (((highest_corner == CORNER_S) || (highest_corner == CORNER_E)) ? SLOPE_SE : SLOPE_NW);
200 break;
202 case FOUNDATION_STEEP_LOWER:
203 s = SlopeWithOneCornerRaised(highest_corner);
204 break;
206 case FOUNDATION_STEEP_BOTH:
207 s = HalftileSlope(SlopeWithOneCornerRaised(highest_corner), highest_corner);
208 break;
210 default: NOT_REACHED();
212 return dz;
217 * Determines height at given coordinate of a slope.
219 * At the northern corner (0, 0) the result is always a multiple of TILE_HEIGHT.
220 * When the height is a fractional Z, then the height is rounded down. For example,
221 * when at the height is 0 at x = 0 and the height is 8 at x = 16 (actually x = 0
222 * of the next tile), then height is 0 at x = 1, 1 at x = 2, and 7 at x = 15.
223 * @param x x coordinate (value from 0 to 15)
224 * @param y y coordinate (value from 0 to 15)
225 * @param corners slope to examine
226 * @return height of given point of given slope
228 uint GetPartialPixelZ(int x, int y, Slope corners)
230 if (IsHalftileSlope(corners)) {
231 /* A foundation is placed on half the tile at a specific corner. This means that,
232 * depending on the corner, that one half of the tile is at the maximum height. */
233 switch (GetHalftileSlopeCorner(corners)) {
234 case CORNER_W:
235 if (x > y) return GetSlopeMaxPixelZ(corners);
236 break;
238 case CORNER_S:
239 if (x + y >= (int)TILE_SIZE) return GetSlopeMaxPixelZ(corners);
240 break;
242 case CORNER_E:
243 if (x <= y) return GetSlopeMaxPixelZ(corners);
244 break;
246 case CORNER_N:
247 if (x + y < (int)TILE_SIZE) return GetSlopeMaxPixelZ(corners);
248 break;
250 default: NOT_REACHED();
254 switch (RemoveHalftileSlope(corners)) {
255 case SLOPE_FLAT: return 0;
257 /* One corner is up.*/
258 case SLOPE_N: return x + y <= (int)TILE_SIZE ? (TILE_SIZE - x - y) >> 1 : 0;
259 case SLOPE_E: return y >= x ? (1 + y - x) >> 1 : 0;
260 case SLOPE_S: return x + y >= (int)TILE_SIZE ? (1 + x + y - TILE_SIZE) >> 1 : 0;
261 case SLOPE_W: return x >= y ? (x - y) >> 1 : 0;
263 /* Two corners next to eachother are up. */
264 case SLOPE_NE: return (TILE_SIZE - x) >> 1;
265 case SLOPE_SE: return (y + 1) >> 1;
266 case SLOPE_SW: return (x + 1) >> 1;
267 case SLOPE_NW: return (TILE_SIZE - y) >> 1;
269 /* Three corners are up on the same level. */
270 case SLOPE_ENW: return x + y >= (int)TILE_SIZE ? TILE_HEIGHT - ((1 + x + y - TILE_SIZE) >> 1) : TILE_HEIGHT;
271 case SLOPE_SEN: return y < x ? TILE_HEIGHT - ((x - y) >> 1) : TILE_HEIGHT;
272 case SLOPE_WSE: return x + y <= (int)TILE_SIZE ? TILE_HEIGHT - ((TILE_SIZE - x - y) >> 1) : TILE_HEIGHT;
273 case SLOPE_NWS: return x < y ? TILE_HEIGHT - ((1 + y - x) >> 1) : TILE_HEIGHT;
275 /* Two corners at opposite sides are up. */
276 case SLOPE_NS: return x + y < (int)TILE_SIZE ? (TILE_SIZE - x - y) >> 1 : (1 + x + y - TILE_SIZE) >> 1;
277 case SLOPE_EW: return x >= y ? (x - y) >> 1 : (1 + y - x) >> 1;
279 /* Very special cases. */
280 case SLOPE_ELEVATED: return TILE_HEIGHT;
282 /* Steep slopes. The top is at 2 * TILE_HEIGHT. */
283 case SLOPE_STEEP_N: return (TILE_SIZE - x + TILE_SIZE - y) >> 1;
284 case SLOPE_STEEP_E: return (TILE_SIZE + 1 + y - x) >> 1;
285 case SLOPE_STEEP_S: return (1 + x + y) >> 1;
286 case SLOPE_STEEP_W: return (TILE_SIZE + x - y) >> 1;
288 default: NOT_REACHED();
293 * Return world \c Z coordinate of a given point of a tile. Normally this is the
294 * Z of the ground/foundation at the given location, but in some cases the
295 * ground/foundation can differ from the Z coordinate that the (ground) vehicle
296 * passing over it would take. For example when entering a tunnel or bridge.
298 * @param x World X coordinate in tile "units".
299 * @param y World Y coordinate in tile "units".
300 * @param ground_vehicle Whether to get the Z coordinate of the ground vehicle, or the ground.
301 * @return World Z coordinate at tile ground (vehicle) level, including slopes and foundations.
303 int GetSlopePixelZ(int x, int y, bool ground_vehicle)
305 TileIndex tile = TileVirtXY(x, y);
307 return _tile_type_procs[GetTileType(tile)]->get_slope_z_proc(tile, x, y, ground_vehicle);
311 * Return world \c z coordinate of a given point of a tile,
312 * also for tiles outside the map (virtual "black" tiles).
314 * @param x World X coordinate in tile "units", may be outside the map.
315 * @param y World Y coordinate in tile "units", may be outside the map.
316 * @return World Z coordinate at tile ground level, including slopes and foundations.
318 int GetSlopePixelZOutsideMap(int x, int y)
320 if (IsInsideBS(x, 0, Map::SizeX() * TILE_SIZE) && IsInsideBS(y, 0, Map::SizeY() * TILE_SIZE)) {
321 return GetSlopePixelZ(x, y, false);
322 } else {
323 return _tile_type_procs[MP_VOID]->get_slope_z_proc(INVALID_TILE, x, y, false);
328 * Determine the Z height of a corner relative to TileZ.
330 * @pre The slope must not be a halftile slope.
332 * @param tileh The slope.
333 * @param corner The corner.
334 * @return Z position of corner relative to TileZ.
336 int GetSlopeZInCorner(Slope tileh, Corner corner)
338 assert(!IsHalftileSlope(tileh));
339 return ((tileh & SlopeWithOneCornerRaised(corner)) != 0 ? 1 : 0) + (tileh == SteepSlope(corner) ? 1 : 0);
343 * Determine the Z height of the corners of a specific tile edge
345 * @note If a tile has a non-continuous halftile foundation, a corner can have different heights wrt. its edges.
347 * @pre z1 and z2 must be initialized (typ. with TileZ). The corner heights just get added.
349 * @param tileh The slope of the tile.
350 * @param edge The edge of interest.
351 * @param z1 Gets incremented by the height of the first corner of the edge. (near corner wrt. the camera)
352 * @param z2 Gets incremented by the height of the second corner of the edge. (far corner wrt. the camera)
354 void GetSlopePixelZOnEdge(Slope tileh, DiagDirection edge, int &z1, int &z2)
356 static const Slope corners[4][4] = {
357 /* corner | steep slope
358 * z1 z2 | z1 z2 */
359 {SLOPE_E, SLOPE_N, SLOPE_STEEP_E, SLOPE_STEEP_N}, // DIAGDIR_NE, z1 = E, z2 = N
360 {SLOPE_S, SLOPE_E, SLOPE_STEEP_S, SLOPE_STEEP_E}, // DIAGDIR_SE, z1 = S, z2 = E
361 {SLOPE_S, SLOPE_W, SLOPE_STEEP_S, SLOPE_STEEP_W}, // DIAGDIR_SW, z1 = S, z2 = W
362 {SLOPE_W, SLOPE_N, SLOPE_STEEP_W, SLOPE_STEEP_N}, // DIAGDIR_NW, z1 = W, z2 = N
365 int halftile_test = (IsHalftileSlope(tileh) ? SlopeWithOneCornerRaised(GetHalftileSlopeCorner(tileh)) : 0);
366 if (halftile_test == corners[edge][0]) z2 += TILE_HEIGHT; // The slope is non-continuous in z2. z2 is on the upper side.
367 if (halftile_test == corners[edge][1]) z1 += TILE_HEIGHT; // The slope is non-continuous in z1. z1 is on the upper side.
369 if ((tileh & corners[edge][0]) != 0) z1 += TILE_HEIGHT; // z1 is raised
370 if ((tileh & corners[edge][1]) != 0) z2 += TILE_HEIGHT; // z2 is raised
371 if (RemoveHalftileSlope(tileh) == corners[edge][2]) z1 += TILE_HEIGHT; // z1 is highest corner of a steep slope
372 if (RemoveHalftileSlope(tileh) == corners[edge][3]) z2 += TILE_HEIGHT; // z2 is highest corner of a steep slope
376 * Get slope of a tile on top of a (possible) foundation
377 * If a tile does not have a foundation, the function returns the same as GetTileSlope.
379 * @param tile The tile of interest.
380 * @return The slope on top of the foundation and the z of the foundation slope.
382 std::tuple<Slope, int> GetFoundationSlope(TileIndex tile)
384 auto [tileh, z] = GetTileSlopeZ(tile);
385 Foundation f = _tile_type_procs[GetTileType(tile)]->get_foundation_proc(tile, tileh);
386 z += ApplyFoundationToSlope(f, tileh);
387 return {tileh, z};
391 bool HasFoundationNW(TileIndex tile, Slope slope_here, uint z_here)
393 int z_W_here = z_here;
394 int z_N_here = z_here;
395 GetSlopePixelZOnEdge(slope_here, DIAGDIR_NW, z_W_here, z_N_here);
397 auto [slope, z] = GetFoundationPixelSlope(TileAddXY(tile, 0, -1));
398 int z_W = z;
399 int z_N = z;
400 GetSlopePixelZOnEdge(slope, DIAGDIR_SE, z_W, z_N);
402 return (z_N_here > z_N) || (z_W_here > z_W);
406 bool HasFoundationNE(TileIndex tile, Slope slope_here, uint z_here)
408 int z_E_here = z_here;
409 int z_N_here = z_here;
410 GetSlopePixelZOnEdge(slope_here, DIAGDIR_NE, z_E_here, z_N_here);
412 auto [slope, z] = GetFoundationPixelSlope(TileAddXY(tile, -1, 0));
413 int z_E = z;
414 int z_N = z;
415 GetSlopePixelZOnEdge(slope, DIAGDIR_SW, z_E, z_N);
417 return (z_N_here > z_N) || (z_E_here > z_E);
421 * Draw foundation \a f at tile \a ti. Updates \a ti.
422 * @param ti Tile to draw foundation on
423 * @param f Foundation to draw
425 void DrawFoundation(TileInfo *ti, Foundation f)
427 if (!IsFoundation(f)) return;
429 /* Two part foundations must be drawn separately */
430 assert(f != FOUNDATION_STEEP_BOTH);
432 uint sprite_block = 0;
433 auto [slope, z] = GetFoundationPixelSlope(ti->tile);
435 /* Select the needed block of foundations sprites
436 * Block 0: Walls at NW and NE edge
437 * Block 1: Wall at NE edge
438 * Block 2: Wall at NW edge
439 * Block 3: No walls at NW or NE edge
441 if (!HasFoundationNW(ti->tile, slope, z)) sprite_block += 1;
442 if (!HasFoundationNE(ti->tile, slope, z)) sprite_block += 2;
444 /* Use the original slope sprites if NW and NE borders should be visible */
445 SpriteID leveled_base = (sprite_block == 0 ? (int)SPR_FOUNDATION_BASE : (SPR_SLOPES_VIRTUAL_BASE + sprite_block * SPR_TRKFOUND_BLOCK_SIZE));
446 SpriteID inclined_base = SPR_SLOPES_VIRTUAL_BASE + SPR_SLOPES_INCLINED_OFFSET + sprite_block * SPR_TRKFOUND_BLOCK_SIZE;
447 SpriteID halftile_base = SPR_HALFTILE_FOUNDATION_BASE + sprite_block * SPR_HALFTILE_BLOCK_SIZE;
449 if (IsSteepSlope(ti->tileh)) {
450 if (!IsNonContinuousFoundation(f)) {
451 /* Lower part of foundation */
452 AddSortableSpriteToDraw(
453 leveled_base + (ti->tileh & ~SLOPE_STEEP), PAL_NONE, ti->x, ti->y, TILE_SIZE, TILE_SIZE, TILE_HEIGHT - 1, ti->z
457 Corner highest_corner = GetHighestSlopeCorner(ti->tileh);
458 ti->z += ApplyPixelFoundationToSlope(f, ti->tileh);
460 if (IsInclinedFoundation(f)) {
461 /* inclined foundation */
462 uint8_t inclined = highest_corner * 2 + (f == FOUNDATION_INCLINED_Y ? 1 : 0);
464 AddSortableSpriteToDraw(inclined_base + inclined, PAL_NONE, ti->x, ti->y,
465 f == FOUNDATION_INCLINED_X ? TILE_SIZE : 1,
466 f == FOUNDATION_INCLINED_Y ? TILE_SIZE : 1,
467 TILE_HEIGHT, ti->z
469 OffsetGroundSprite(0, 0);
470 } else if (IsLeveledFoundation(f)) {
471 AddSortableSpriteToDraw(leveled_base + SlopeWithOneCornerRaised(highest_corner), PAL_NONE, ti->x, ti->y, TILE_SIZE, TILE_SIZE, TILE_HEIGHT - 1, ti->z - TILE_HEIGHT);
472 OffsetGroundSprite(0, -(int)TILE_HEIGHT);
473 } else if (f == FOUNDATION_STEEP_LOWER) {
474 /* one corner raised */
475 OffsetGroundSprite(0, -(int)TILE_HEIGHT);
476 } else {
477 /* halftile foundation */
478 int x_bb = (((highest_corner == CORNER_W) || (highest_corner == CORNER_S)) ? TILE_SIZE / 2 : 0);
479 int y_bb = (((highest_corner == CORNER_S) || (highest_corner == CORNER_E)) ? TILE_SIZE / 2 : 0);
481 AddSortableSpriteToDraw(halftile_base + highest_corner, PAL_NONE, ti->x + x_bb, ti->y + y_bb, TILE_SIZE / 2, TILE_SIZE / 2, TILE_HEIGHT - 1, ti->z + TILE_HEIGHT);
482 /* Reposition ground sprite back to original position after bounding box change above. This is similar to
483 * RemapCoords() but without zoom scaling. */
484 Point pt = {(y_bb - x_bb) * 2, y_bb + x_bb};
485 OffsetGroundSprite(-pt.x, -pt.y);
487 } else {
488 if (IsLeveledFoundation(f)) {
489 /* leveled foundation */
490 AddSortableSpriteToDraw(leveled_base + ti->tileh, PAL_NONE, ti->x, ti->y, TILE_SIZE, TILE_SIZE, TILE_HEIGHT - 1, ti->z);
491 OffsetGroundSprite(0, -(int)TILE_HEIGHT);
492 } else if (IsNonContinuousFoundation(f)) {
493 /* halftile foundation */
494 Corner halftile_corner = GetHalftileFoundationCorner(f);
495 int x_bb = (((halftile_corner == CORNER_W) || (halftile_corner == CORNER_S)) ? TILE_SIZE / 2 : 0);
496 int y_bb = (((halftile_corner == CORNER_S) || (halftile_corner == CORNER_E)) ? TILE_SIZE / 2 : 0);
498 AddSortableSpriteToDraw(halftile_base + halftile_corner, PAL_NONE, ti->x + x_bb, ti->y + y_bb, TILE_SIZE / 2, TILE_SIZE / 2, TILE_HEIGHT - 1, ti->z);
499 /* Reposition ground sprite back to original position after bounding box change above. This is similar to
500 * RemapCoords() but without zoom scaling. */
501 Point pt = {(y_bb - x_bb) * 2, y_bb + x_bb};
502 OffsetGroundSprite(-pt.x, -pt.y);
503 } else if (IsSpecialRailFoundation(f)) {
504 /* anti-zig-zag foundation */
505 SpriteID spr;
506 if (ti->tileh == SLOPE_NS || ti->tileh == SLOPE_EW) {
507 /* half of leveled foundation under track corner */
508 spr = leveled_base + SlopeWithThreeCornersRaised(GetRailFoundationCorner(f));
509 } else {
510 /* tile-slope = sloped along X/Y, foundation-slope = three corners raised */
511 spr = inclined_base + 2 * GetRailFoundationCorner(f) + ((ti->tileh == SLOPE_SW || ti->tileh == SLOPE_NE) ? 1 : 0);
513 AddSortableSpriteToDraw(spr, PAL_NONE, ti->x, ti->y, TILE_SIZE, TILE_SIZE, TILE_HEIGHT - 1, ti->z);
514 OffsetGroundSprite(0, 0);
515 } else {
516 /* inclined foundation */
517 uint8_t inclined = GetHighestSlopeCorner(ti->tileh) * 2 + (f == FOUNDATION_INCLINED_Y ? 1 : 0);
519 AddSortableSpriteToDraw(inclined_base + inclined, PAL_NONE, ti->x, ti->y,
520 f == FOUNDATION_INCLINED_X ? TILE_SIZE : 1,
521 f == FOUNDATION_INCLINED_Y ? TILE_SIZE : 1,
522 TILE_HEIGHT, ti->z
524 OffsetGroundSprite(0, 0);
526 ti->z += ApplyPixelFoundationToSlope(f, ti->tileh);
530 void DoClearSquare(TileIndex tile)
532 /* If the tile can have animation and we clear it, delete it from the animated tile list. */
533 if (_tile_type_procs[GetTileType(tile)]->animate_tile_proc != nullptr) DeleteAnimatedTile(tile);
535 bool remove = IsDockingTile(tile);
536 MakeClear(tile, CLEAR_GRASS, _generating_world ? 3 : 0);
537 MarkTileDirtyByTile(tile);
538 if (remove) RemoveDockingTile(tile);
540 InvalidateWaterRegion(tile);
544 * Returns information about trackdirs and signal states.
545 * If there is any trackbit at 'side', return all trackdirbits.
546 * For TRANSPORT_ROAD, return no trackbits if there is no roadbit (of given subtype) at given side.
547 * @param tile tile to get info about
548 * @param mode transport type
549 * @param sub_mode for TRANSPORT_ROAD, roadtypes to check
550 * @param side side we are entering from, INVALID_DIAGDIR to return all trackbits
551 * @return trackdirbits and other info depending on 'mode'
553 TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
555 return _tile_type_procs[GetTileType(tile)]->get_tile_track_status_proc(tile, mode, sub_mode, side);
559 * Change the owner of a tile
560 * @param tile Tile to change
561 * @param old_owner Current owner of the tile
562 * @param new_owner New owner of the tile
564 void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner)
566 _tile_type_procs[GetTileType(tile)]->change_tile_owner_proc(tile, old_owner, new_owner);
569 void GetTileDesc(TileIndex tile, TileDesc *td)
571 _tile_type_procs[GetTileType(tile)]->get_tile_desc_proc(tile, td);
575 * Has a snow line table already been loaded.
576 * @return true if the table has been loaded already.
577 * @ingroup SnowLineGroup
579 bool IsSnowLineSet()
581 return _snow_line != nullptr;
585 * Set a variable snow line, as loaded from a newgrf file.
586 * @param table the 12 * 32 byte table containing the snowline for each day
587 * @ingroup SnowLineGroup
589 void SetSnowLine(uint8_t table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS])
591 _snow_line = CallocT<SnowLine>(1);
592 _snow_line->lowest_value = 0xFF;
593 memcpy(_snow_line->table, table, sizeof(_snow_line->table));
595 for (uint i = 0; i < SNOW_LINE_MONTHS; i++) {
596 for (uint j = 0; j < SNOW_LINE_DAYS; j++) {
597 _snow_line->highest_value = std::max(_snow_line->highest_value, table[i][j]);
598 _snow_line->lowest_value = std::min(_snow_line->lowest_value, table[i][j]);
604 * Get the current snow line, either variable or static.
605 * @return the snow line height.
606 * @ingroup SnowLineGroup
608 uint8_t GetSnowLine()
610 if (_snow_line == nullptr) return _settings_game.game_creation.snow_line_height;
612 TimerGameCalendar::YearMonthDay ymd = TimerGameCalendar::ConvertDateToYMD(TimerGameCalendar::date);
613 return _snow_line->table[ymd.month][ymd.day];
617 * Get the highest possible snow line height, either variable or static.
618 * @return the highest snow line height.
619 * @ingroup SnowLineGroup
621 uint8_t HighestSnowLine()
623 return _snow_line == nullptr ? _settings_game.game_creation.snow_line_height : _snow_line->highest_value;
627 * Get the lowest possible snow line height, either variable or static.
628 * @return the lowest snow line height.
629 * @ingroup SnowLineGroup
631 uint8_t LowestSnowLine()
633 return _snow_line == nullptr ? _settings_game.game_creation.snow_line_height : _snow_line->lowest_value;
637 * Clear the variable snow line table and free the memory.
638 * @ingroup SnowLineGroup
640 void ClearSnowLine()
642 free(_snow_line);
643 _snow_line = nullptr;
647 * Clear a piece of landscape
648 * @param flags of operation to conduct
649 * @param tile tile to clear
650 * @return the cost of this operation or an error
652 CommandCost CmdLandscapeClear(DoCommandFlag flags, TileIndex tile)
654 CommandCost cost(EXPENSES_CONSTRUCTION);
655 bool do_clear = false;
656 /* Test for stuff which results in water when cleared. Then add the cost to also clear the water. */
657 if ((flags & DC_FORCE_CLEAR_TILE) && HasTileWaterClass(tile) && IsTileOnWater(tile) && !IsWaterTile(tile) && !IsCoastTile(tile)) {
658 if ((flags & DC_AUTO) && GetWaterClass(tile) == WATER_CLASS_CANAL) return_cmd_error(STR_ERROR_MUST_DEMOLISH_CANAL_FIRST);
659 do_clear = true;
660 cost.AddCost(GetWaterClass(tile) == WATER_CLASS_CANAL ? _price[PR_CLEAR_CANAL] : _price[PR_CLEAR_WATER]);
663 Company *c = (flags & (DC_AUTO | DC_BANKRUPT)) ? nullptr : Company::GetIfValid(_current_company);
664 if (c != nullptr && (int)GB(c->clear_limit, 16, 16) < 1) {
665 return_cmd_error(STR_ERROR_CLEARING_LIMIT_REACHED);
668 const ClearedObjectArea *coa = FindClearedObject(tile);
670 /* If this tile was the first tile which caused object destruction, always
671 * pass it on to the tile_type_proc. That way multiple test runs and the exec run stay consistent. */
672 if (coa != nullptr && coa->first_tile != tile) {
673 /* If this tile belongs to an object which was already cleared via another tile, pretend it has been
674 * already removed.
675 * However, we need to check stuff, which is not the same for all object tiles. (e.g. being on water or not) */
677 /* If a object is removed, it leaves either bare land or water. */
678 if ((flags & DC_NO_WATER) && HasTileWaterClass(tile) && IsTileOnWater(tile)) {
679 return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
681 } else {
682 cost.AddCost(_tile_type_procs[GetTileType(tile)]->clear_tile_proc(tile, flags));
685 if (flags & DC_EXEC) {
686 if (c != nullptr) c->clear_limit -= 1 << 16;
687 if (do_clear) {
688 if (IsWaterTile(tile) && IsCanal(tile)) {
689 Owner owner = GetTileOwner(tile);
690 if (Company::IsValidID(owner)) {
691 Company::Get(owner)->infrastructure.water--;
692 DirtyCompanyInfrastructureWindows(owner);
695 DoClearSquare(tile);
698 return cost;
702 * Clear a big piece of landscape
703 * @param flags of operation to conduct
704 * @param tile end tile of area dragging
705 * @param start_tile start tile of area dragging
706 * @param diagonal Whether to use the Orthogonal (false) or Diagonal (true) iterator.
707 * @return the cost of this operation or an error
709 std::tuple<CommandCost, Money> CmdClearArea(DoCommandFlag flags, TileIndex tile, TileIndex start_tile, bool diagonal)
711 if (start_tile >= Map::Size()) return { CMD_ERROR, 0 };
713 Money money = GetAvailableMoneyForCommand();
714 CommandCost cost(EXPENSES_CONSTRUCTION);
715 CommandCost last_error = CMD_ERROR;
716 bool had_success = false;
718 const Company *c = (flags & (DC_AUTO | DC_BANKRUPT)) ? nullptr : Company::GetIfValid(_current_company);
719 int limit = (c == nullptr ? INT32_MAX : GB(c->clear_limit, 16, 16));
721 if (tile != start_tile) flags |= DC_FORCE_CLEAR_TILE;
723 std::unique_ptr<TileIterator> iter = TileIterator::Create(tile, start_tile, diagonal);
724 for (; *iter != INVALID_TILE; ++(*iter)) {
725 TileIndex t = *iter;
726 CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags & ~DC_EXEC, t);
727 if (ret.Failed()) {
728 last_error = ret;
730 /* We may not clear more tiles. */
731 if (c != nullptr && GB(c->clear_limit, 16, 16) < 1) break;
732 continue;
735 had_success = true;
736 if (flags & DC_EXEC) {
737 money -= ret.GetCost();
738 if (ret.GetCost() > 0 && money < 0) {
739 return { cost, ret.GetCost() };
741 Command<CMD_LANDSCAPE_CLEAR>::Do(flags, t);
743 /* draw explosion animation...
744 * Disable explosions when game is paused. Looks silly and blocks the view. */
745 if ((t == tile || t == start_tile) && _pause_mode == PM_UNPAUSED) {
746 /* big explosion in two corners, or small explosion for single tiles */
747 CreateEffectVehicleAbove(TileX(t) * TILE_SIZE + TILE_SIZE / 2, TileY(t) * TILE_SIZE + TILE_SIZE / 2, 2,
748 TileX(tile) == TileX(start_tile) && TileY(tile) == TileY(start_tile) ? EV_EXPLOSION_SMALL : EV_EXPLOSION_LARGE
751 } else {
752 /* When we're at the clearing limit we better bail (unneed) testing as well. */
753 if (ret.GetCost() != 0 && --limit <= 0) break;
755 cost.AddCost(ret);
758 return { had_success ? cost : last_error, 0 };
762 TileIndex _cur_tileloop_tile;
765 * Gradually iterate over all tiles on the map, calling their TileLoopProcs once every TILE_UPDATE_FREQUENCY ticks.
767 void RunTileLoop()
769 PerformanceAccumulator framerate(PFE_GL_LANDSCAPE);
771 /* The pseudorandom sequence of tiles is generated using a Galois linear feedback
772 * shift register (LFSR). This allows a deterministic pseudorandom ordering, but
773 * still with minimal state and fast iteration. */
775 /* Maximal length LFSR feedback terms, from 12-bit (for 64x64 maps) to 24-bit (for 4096x4096 maps).
776 * Extracted from http://www.ece.cmu.edu/~koopman/lfsr/ */
777 static const uint32_t feedbacks[] = {
778 0xD8F, 0x1296, 0x2496, 0x4357, 0x8679, 0x1030E, 0x206CD, 0x403FE, 0x807B8, 0x1004B2, 0x2006A8, 0x4004B2, 0x800B87
780 static_assert(lengthof(feedbacks) == 2 * MAX_MAP_SIZE_BITS - 2 * MIN_MAP_SIZE_BITS + 1);
781 const uint32_t feedback = feedbacks[Map::LogX() + Map::LogY() - 2 * MIN_MAP_SIZE_BITS];
783 /* We update every tile every TILE_UPDATE_FREQUENCY ticks, so divide the map size by 2^TILE_UPDATE_FREQUENCY_LOG = TILE_UPDATE_FREQUENCY */
784 static_assert(2 * MIN_MAP_SIZE_BITS >= TILE_UPDATE_FREQUENCY_LOG);
785 uint count = 1 << (Map::LogX() + Map::LogY() - TILE_UPDATE_FREQUENCY_LOG);
787 TileIndex tile = _cur_tileloop_tile;
788 /* The LFSR cannot have a zeroed state. */
789 assert(tile != 0);
791 /* Manually update tile 0 every TILE_UPDATE_FREQUENCY ticks - the LFSR never iterates over it itself. */
792 if (TimerGameTick::counter % TILE_UPDATE_FREQUENCY == 0) {
793 _tile_type_procs[GetTileType(0)]->tile_loop_proc(0);
794 count--;
797 while (count--) {
798 _tile_type_procs[GetTileType(tile)]->tile_loop_proc(tile);
800 /* Get the next tile in sequence using a Galois LFSR. */
801 tile = (tile.base() >> 1) ^ (-(int32_t)(tile.base() & 1) & feedback);
804 _cur_tileloop_tile = tile;
807 void InitializeLandscape()
809 for (uint y = _settings_game.construction.freeform_edges ? 1 : 0; y < Map::MaxY(); y++) {
810 for (uint x = _settings_game.construction.freeform_edges ? 1 : 0; x < Map::MaxX(); x++) {
811 MakeClear(TileXY(x, y), CLEAR_GRASS, 3);
812 SetTileHeight(TileXY(x, y), 0);
813 SetTropicZone(TileXY(x, y), TROPICZONE_NORMAL);
814 ClearBridgeMiddle(TileXY(x, y));
818 for (uint x = 0; x < Map::SizeX(); x++) MakeVoid(TileXY(x, Map::MaxY()));
819 for (uint y = 0; y < Map::SizeY(); y++) MakeVoid(TileXY(Map::MaxX(), y));
822 static const uint8_t _genterrain_tbl_1[5] = { 10, 22, 33, 37, 4 };
823 static const uint8_t _genterrain_tbl_2[5] = { 0, 0, 0, 0, 33 };
825 static void GenerateTerrain(int type, uint flag)
827 uint32_t r = Random();
829 /* Choose one of the templates from the graphics file. */
830 const Sprite *templ = GetSprite((((r >> 24) * _genterrain_tbl_1[type]) >> 8) + _genterrain_tbl_2[type] + SPR_MAPGEN_BEGIN, SpriteType::MapGen);
831 if (templ == nullptr) UserError("Map generator sprites could not be loaded");
833 /* Chose a random location to apply the template to. */
834 uint x = r & Map::MaxX();
835 uint y = (r >> Map::LogX()) & Map::MaxY();
837 /* Make sure the template is not too close to the upper edges; bottom edges are checked later. */
838 uint edge_distance = 1 + (_settings_game.construction.freeform_edges ? 1 : 0);
839 if (x <= edge_distance || y <= edge_distance) return;
841 DiagDirection direction = (DiagDirection)GB(r, 22, 2);
842 uint w = templ->width;
843 uint h = templ->height;
845 if (DiagDirToAxis(direction) == AXIS_Y) Swap(w, h);
847 const uint8_t *p = templ->data;
849 if ((flag & 4) != 0) {
850 /* This is only executed in secondary/tertiary loops to generate the terrain for arctic and tropic.
851 * It prevents the templates to be applied to certain parts of the map based on the flags, thus
852 * creating regions with different elevations/topography. */
853 uint xw = x * Map::SizeY();
854 uint yw = y * Map::SizeX();
855 uint bias = (Map::SizeX() + Map::SizeY()) * 16;
857 switch (flag & 3) {
858 default: NOT_REACHED();
859 case 0:
860 if (xw + yw > Map::Size() - bias) return;
861 break;
863 case 1:
864 if (yw < xw + bias) return;
865 break;
867 case 2:
868 if (xw + yw < Map::Size() + bias) return;
869 break;
871 case 3:
872 if (xw < yw + bias) return;
873 break;
877 /* Ensure the template does not overflow at the bottom edges of the map; upper edges were checked before. */
878 if (x + w >= Map::MaxX()) return;
879 if (y + h >= Map::MaxY()) return;
881 TileIndex tile = TileXY(x, y);
883 /* Get the template and overlay in a particular direction over the map's height from the given
884 * origin point (tile), and update the map's height everywhere where the height from the template
885 * is higher than the height of the map. In other words, this only raises the tile heights. */
886 switch (direction) {
887 default: NOT_REACHED();
888 case DIAGDIR_NE:
889 do {
890 TileIndex tile_cur = tile;
892 for (uint w_cur = w; w_cur != 0; --w_cur) {
893 if (GB(*p, 0, 4) >= TileHeight(tile_cur)) SetTileHeight(tile_cur, GB(*p, 0, 4));
894 p++;
895 tile_cur++;
897 tile += TileDiffXY(0, 1);
898 } while (--h != 0);
899 break;
901 case DIAGDIR_SE:
902 do {
903 TileIndex tile_cur = tile;
905 for (uint h_cur = h; h_cur != 0; --h_cur) {
906 if (GB(*p, 0, 4) >= TileHeight(tile_cur)) SetTileHeight(tile_cur, GB(*p, 0, 4));
907 p++;
908 tile_cur += TileDiffXY(0, 1);
910 tile += TileDiffXY(1, 0);
911 } while (--w != 0);
912 break;
914 case DIAGDIR_SW:
915 tile += TileDiffXY(w - 1, 0);
916 do {
917 TileIndex tile_cur = tile;
919 for (uint w_cur = w; w_cur != 0; --w_cur) {
920 if (GB(*p, 0, 4) >= TileHeight(tile_cur)) SetTileHeight(tile_cur, GB(*p, 0, 4));
921 p++;
922 tile_cur--;
924 tile += TileDiffXY(0, 1);
925 } while (--h != 0);
926 break;
928 case DIAGDIR_NW:
929 tile += TileDiffXY(0, h - 1);
930 do {
931 TileIndex tile_cur = tile;
933 for (uint h_cur = h; h_cur != 0; --h_cur) {
934 if (GB(*p, 0, 4) >= TileHeight(tile_cur)) SetTileHeight(tile_cur, GB(*p, 0, 4));
935 p++;
936 tile_cur -= TileDiffXY(0, 1);
938 tile += TileDiffXY(1, 0);
939 } while (--w != 0);
940 break;
945 #include "table/genland.h"
947 static void CreateDesertOrRainForest(uint desert_tropic_line)
949 uint update_freq = Map::Size() / 4;
951 for (TileIndex tile = 0; tile != Map::Size(); ++tile) {
952 if ((tile.base() % update_freq) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
954 if (!IsValidTile(tile)) continue;
956 auto allows_desert = [tile, desert_tropic_line](auto &offset) {
957 TileIndex t = AddTileIndexDiffCWrap(tile, offset);
958 return t == INVALID_TILE || (TileHeight(t) < desert_tropic_line && !IsTileType(t, MP_WATER));
960 if (std::all_of(std::begin(_make_desert_or_rainforest_data), std::end(_make_desert_or_rainforest_data), allows_desert)) {
961 SetTropicZone(tile, TROPICZONE_DESERT);
965 for (uint i = 0; i != TILE_UPDATE_FREQUENCY; i++) {
966 if ((i % 64) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
968 RunTileLoop();
971 for (TileIndex tile = 0; tile != Map::Size(); ++tile) {
972 if ((tile.base() % update_freq) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
974 if (!IsValidTile(tile)) continue;
976 auto allows_rainforest = [tile](auto &offset) {
977 TileIndex t = AddTileIndexDiffCWrap(tile, offset);
978 return t == INVALID_TILE || !IsTileType(t, MP_CLEAR) || !IsClearGround(t, CLEAR_DESERT);
980 if (std::all_of(std::begin(_make_desert_or_rainforest_data), std::end(_make_desert_or_rainforest_data), allows_rainforest)) {
981 SetTropicZone(tile, TROPICZONE_RAINFOREST);
987 * Find the spring of a river.
988 * @param tile The tile to consider for being the spring.
989 * @return True iff it is suitable as a spring.
991 static bool FindSpring(TileIndex tile, void *)
993 int referenceHeight;
994 if (!IsTileFlat(tile, &referenceHeight) || IsWaterTile(tile)) return false;
996 /* In the tropics rivers start in the rainforest. */
997 if (_settings_game.game_creation.landscape == LT_TROPIC && GetTropicZone(tile) != TROPICZONE_RAINFOREST) return false;
999 /* Are there enough higher tiles to warrant a 'spring'? */
1000 uint num = 0;
1001 for (int dx = -1; dx <= 1; dx++) {
1002 for (int dy = -1; dy <= 1; dy++) {
1003 TileIndex t = TileAddWrap(tile, dx, dy);
1004 if (t != INVALID_TILE && GetTileMaxZ(t) > referenceHeight) num++;
1008 if (num < 4) return false;
1010 /* Are we near the top of a hill? */
1011 for (int dx = -16; dx <= 16; dx++) {
1012 for (int dy = -16; dy <= 16; dy++) {
1013 TileIndex t = TileAddWrap(tile, dx, dy);
1014 if (t != INVALID_TILE && GetTileMaxZ(t) > referenceHeight + 2) return false;
1018 return true;
1022 * Make a connected lake; fill all tiles in the circular tile search that are connected.
1023 * @param tile The tile to consider for lake making.
1024 * @param user_data The height of the lake.
1025 * @return Always false, so it continues searching.
1027 static bool MakeLake(TileIndex tile, void *user_data)
1029 uint height = *(uint*)user_data;
1030 if (!IsValidTile(tile) || TileHeight(tile) != height || !IsTileFlat(tile)) return false;
1031 if (_settings_game.game_creation.landscape == LT_TROPIC && GetTropicZone(tile) == TROPICZONE_DESERT) return false;
1033 for (DiagDirection d = DIAGDIR_BEGIN; d < DIAGDIR_END; d++) {
1034 TileIndex t2 = tile + TileOffsByDiagDir(d);
1035 if (IsWaterTile(t2)) {
1036 MakeRiverAndModifyDesertZoneAround(tile);
1037 return false;
1041 return false;
1045 * Widen a river by expanding into adjacent tiles via circular tile search.
1046 * @param tile The tile to try expanding the river into.
1047 * @param data The tile to try surrounding the river around.
1048 * @return Always false, so it continues searching.
1050 static bool RiverMakeWider(TileIndex tile, void *data)
1052 /* Don't expand into void tiles. */
1053 if (!IsValidTile(tile)) return false;
1055 /* If the tile is already sea or river, don't expand. */
1056 if (IsWaterTile(tile)) return false;
1058 /* If the tile is at height 0 after terraforming but the ocean hasn't flooded yet, don't build river. */
1059 if (GetTileMaxZ(tile) == 0) return false;
1061 TileIndex origin_tile = *(TileIndex *)data;
1062 Slope cur_slope = GetTileSlope(tile);
1063 Slope desired_slope = GetTileSlope(origin_tile); // Initialize matching the origin tile as a shortcut if no terraforming is needed.
1065 /* Never flow uphill. */
1066 if (GetTileMaxZ(tile) > GetTileMaxZ(origin_tile)) return false;
1068 /* If the new tile can't hold a river tile, try terraforming. */
1069 if (!IsTileFlat(tile) && !IsInclinedSlope(cur_slope)) {
1070 /* Don't try to terraform steep slopes. */
1071 if (IsSteepSlope(cur_slope)) return false;
1073 bool flat_river_found = false;
1074 bool sloped_river_found = false;
1076 /* There are two common possibilities:
1077 * 1. River flat, adjacent tile has one corner lowered.
1078 * 2. River descending, adjacent tile has either one or three corners raised.
1081 /* First, determine the desired slope based on adjacent river tiles. This doesn't necessarily match the origin tile for the CircularTileSearch. */
1082 for (DiagDirection d = DIAGDIR_BEGIN; d < DIAGDIR_END; d++) {
1083 TileIndex other_tile = TileAddByDiagDir(tile, d);
1084 Slope other_slope = GetTileSlope(other_tile);
1086 /* Only consider river tiles. */
1087 if (IsWaterTile(other_tile) && IsRiver(other_tile)) {
1088 /* If the adjacent river tile flows downhill, we need to check where we are relative to the slope. */
1089 if (IsInclinedSlope(other_slope) && GetTileMaxZ(tile) == GetTileMaxZ(other_tile)) {
1090 /* Check for a parallel slope. If we don't find one, we're above or below the slope instead. */
1091 if (GetInclinedSlopeDirection(other_slope) == ChangeDiagDir(d, DIAGDIRDIFF_90RIGHT) ||
1092 GetInclinedSlopeDirection(other_slope) == ChangeDiagDir(d, DIAGDIRDIFF_90LEFT)) {
1093 desired_slope = other_slope;
1094 sloped_river_found = true;
1095 break;
1098 /* If we find an adjacent river tile, remember it. We'll terraform to match it later if we don't find a slope. */
1099 if (IsTileFlat(other_tile)) flat_river_found = true;
1102 /* We didn't find either an inclined or flat river, so we're climbing the wrong slope. Bail out. */
1103 if (!sloped_river_found && !flat_river_found) return false;
1105 /* We didn't find an inclined river, but there is a flat river. */
1106 if (!sloped_river_found && flat_river_found) desired_slope = SLOPE_FLAT;
1108 /* Now that we know the desired slope, it's time to terraform! */
1110 /* If the river is flat and the adjacent tile has one corner lowered, we want to raise it. */
1111 if (desired_slope == SLOPE_FLAT && IsSlopeWithThreeCornersRaised(cur_slope)) {
1112 /* Make sure we're not affecting an existing river slope tile. */
1113 for (DiagDirection d = DIAGDIR_BEGIN; d < DIAGDIR_END; d++) {
1114 TileIndex other_tile = TileAddByDiagDir(tile, d);
1115 if (IsInclinedSlope(GetTileSlope(other_tile)) && IsWaterTile(other_tile)) return false;
1117 Command<CMD_TERRAFORM_LAND>::Do(DC_EXEC | DC_AUTO, tile, ComplementSlope(cur_slope), true);
1119 /* If the river is descending and the adjacent tile has either one or three corners raised, we want to make it match the slope. */
1120 } else if (IsInclinedSlope(desired_slope)) {
1121 /* Don't break existing flat river tiles by terraforming under them. */
1122 DiagDirection river_direction = ReverseDiagDir(GetInclinedSlopeDirection(desired_slope));
1124 for (DiagDirDiff d = DIAGDIRDIFF_BEGIN; d < DIAGDIRDIFF_END; d++) {
1125 /* We don't care about downstream or upstream tiles, just the riverbanks. */
1126 if (d == DIAGDIRDIFF_SAME || d == DIAGDIRDIFF_REVERSE) continue;
1128 TileIndex other_tile = (TileAddByDiagDir(tile, ChangeDiagDir(river_direction, d)));
1129 if (IsWaterTile(other_tile) && IsRiver(other_tile) && IsTileFlat(other_tile)) return false;
1132 /* Get the corners which are different between the current and desired slope. */
1133 Slope to_change = cur_slope ^ desired_slope;
1135 /* Lower unwanted corners first. If only one corner is raised, no corners need lowering. */
1136 if (!IsSlopeWithOneCornerRaised(cur_slope)) {
1137 to_change = to_change & ComplementSlope(desired_slope);
1138 Command<CMD_TERRAFORM_LAND>::Do(DC_EXEC | DC_AUTO, tile, to_change, false);
1141 /* Now check the match and raise any corners needed. */
1142 cur_slope = GetTileSlope(tile);
1143 if (cur_slope != desired_slope && IsSlopeWithOneCornerRaised(cur_slope)) {
1144 to_change = cur_slope ^ desired_slope;
1145 Command<CMD_TERRAFORM_LAND>::Do(DC_EXEC | DC_AUTO, tile, to_change, true);
1148 /* Update cur_slope after possibly terraforming. */
1149 cur_slope = GetTileSlope(tile);
1152 /* Sloped rivers need water both upstream and downstream. */
1153 if (IsInclinedSlope(cur_slope)) {
1154 DiagDirection slope_direction = GetInclinedSlopeDirection(cur_slope);
1156 TileIndex upstream_tile = TileAddByDiagDir(tile, slope_direction);
1157 TileIndex downstream_tile = TileAddByDiagDir(tile, ReverseDiagDir(slope_direction));
1159 /* Don't look outside the map. */
1160 if (!IsValidTile(upstream_tile) || !IsValidTile(downstream_tile)) return false;
1162 /* Downstream might be new ocean created by our terraforming, and it hasn't flooded yet. */
1163 bool downstream_is_ocean = GetTileZ(downstream_tile) == 0 && (GetTileSlope(downstream_tile) == SLOPE_FLAT || IsSlopeWithOneCornerRaised(GetTileSlope(downstream_tile)));
1165 /* If downstream is dry, flat, and not ocean, try making it a river tile. */
1166 if (!IsWaterTile(downstream_tile) && !downstream_is_ocean) {
1167 /* If the tile upstream isn't flat, don't bother. */
1168 if (GetTileSlope(downstream_tile) != SLOPE_FLAT) return false;
1170 MakeRiverAndModifyDesertZoneAround(downstream_tile);
1173 /* If upstream is dry and flat, try making it a river tile. */
1174 if (!IsWaterTile(upstream_tile)) {
1175 /* If the tile upstream isn't flat, don't bother. */
1176 if (GetTileSlope(upstream_tile) != SLOPE_FLAT) return false;
1178 MakeRiverAndModifyDesertZoneAround(upstream_tile);
1182 /* If the tile slope matches the desired slope, add a river tile. */
1183 if (cur_slope == desired_slope) {
1184 MakeRiverAndModifyDesertZoneAround(tile);
1187 /* Always return false to keep searching. */
1188 return false;
1192 * Check whether a river at begin could (logically) flow down to end.
1193 * @param begin The origin of the flow.
1194 * @param end The destination of the flow.
1195 * @return True iff the water can be flowing down.
1197 static bool FlowsDown(TileIndex begin, TileIndex end)
1199 assert(DistanceManhattan(begin, end) == 1);
1201 auto [slopeBegin, heightBegin] = GetTileSlopeZ(begin);
1202 auto [slopeEnd, heightEnd] = GetTileSlopeZ(end);
1204 return heightEnd <= heightBegin &&
1205 /* Slope either is inclined or flat; rivers don't support other slopes. */
1206 (slopeEnd == SLOPE_FLAT || IsInclinedSlope(slopeEnd)) &&
1207 /* Slope continues, then it must be lower... or either end must be flat. */
1208 ((slopeEnd == slopeBegin && heightEnd < heightBegin) || slopeEnd == SLOPE_FLAT || slopeBegin == SLOPE_FLAT);
1211 /** Parameters for river generation to pass as AyStar user data. */
1212 struct River_UserData {
1213 TileIndex spring; ///< The current spring during river generation.
1214 bool main_river; ///< Whether the current river is a big river that others flow into.
1217 /* AyStar callback for checking whether we reached our destination. */
1218 static int32_t River_EndNodeCheck(const AyStar *aystar, const PathNode *current)
1220 return current->GetTile() == *(TileIndex*)aystar->user_target ? AYSTAR_FOUND_END_NODE : AYSTAR_DONE;
1223 /* AyStar callback for getting the cost of the current node. */
1224 static int32_t River_CalculateG(AyStar *, AyStarNode *, PathNode *)
1226 return 1 + RandomRange(_settings_game.game_creation.river_route_random);
1229 /* AyStar callback for getting the estimated cost to the destination. */
1230 static int32_t River_CalculateH(AyStar *aystar, AyStarNode *current, PathNode *)
1232 return DistanceManhattan(*(TileIndex*)aystar->user_target, current->tile);
1235 /* AyStar callback for getting the neighbouring nodes of the given node. */
1236 static void River_GetNeighbours(AyStar *aystar, PathNode *current)
1238 TileIndex tile = current->GetTile();
1240 aystar->neighbours.clear();
1241 for (DiagDirection d = DIAGDIR_BEGIN; d < DIAGDIR_END; d++) {
1242 TileIndex t2 = tile + TileOffsByDiagDir(d);
1243 if (IsValidTile(t2) && FlowsDown(tile, t2)) {
1244 auto &neighbour = aystar->neighbours.emplace_back();
1245 neighbour.tile = t2;
1246 neighbour.td = INVALID_TRACKDIR;
1251 /* AyStar callback when an route has been found. */
1252 static void River_FoundEndNode(AyStar *aystar, PathNode *current)
1254 River_UserData *data = (River_UserData *)aystar->user_data;
1256 /* First, build the river without worrying about its width. */
1257 uint cur_pos = 0;
1258 for (PathNode *path = current->parent; path != nullptr; path = path->parent, cur_pos++) {
1259 TileIndex tile = path->GetTile();
1260 if (!IsWaterTile(tile)) {
1261 MakeRiverAndModifyDesertZoneAround(tile);
1265 /* If the river is a main river, go back along the path to widen it.
1266 * Don't make wide rivers if we're using the original landscape generator.
1268 if (_settings_game.game_creation.land_generator != LG_ORIGINAL && data->main_river) {
1269 const uint long_river_length = _settings_game.game_creation.min_river_length * 4;
1270 uint current_river_length;
1271 uint radius;
1273 cur_pos = 0;
1274 for (PathNode *path = current->parent; path != nullptr; path = path->parent, cur_pos++) {
1275 TileIndex tile = path->GetTile();
1277 /* Check if we should widen river depending on how far we are away from the source. */
1278 current_river_length = DistanceManhattan(data->spring, tile);
1279 radius = std::min(3u, (current_river_length / (long_river_length / 3u)) + 1u);
1281 if (radius > 1) CircularTileSearch(&tile, radius, RiverMakeWider, (void *)&path->key.tile);
1287 * Actually build the river between the begin and end tiles using AyStar.
1288 * @param begin The begin of the river.
1289 * @param end The end of the river.
1290 * @param spring The springing point of the river.
1291 * @param main_river Whether the current river is a big river that others flow into.
1293 static void BuildRiver(TileIndex begin, TileIndex end, TileIndex spring, bool main_river)
1295 River_UserData user_data = { spring, main_river };
1297 AyStar finder = {};
1298 finder.CalculateG = River_CalculateG;
1299 finder.CalculateH = River_CalculateH;
1300 finder.GetNeighbours = River_GetNeighbours;
1301 finder.EndNodeCheck = River_EndNodeCheck;
1302 finder.FoundEndNode = River_FoundEndNode;
1303 finder.user_target = &end;
1304 finder.user_data = &user_data;
1306 AyStarNode start;
1307 start.tile = begin;
1308 start.td = INVALID_TRACKDIR;
1309 finder.AddStartNode(&start, 0);
1310 finder.Main();
1314 * Try to flow the river down from a given begin.
1315 * @param spring The springing point of the river.
1316 * @param begin The begin point we are looking from; somewhere down hill from the spring.
1317 * @param min_river_length The minimum length for the river.
1318 * @return First element: True iff a river could/has been built, otherwise false; second element: River ends at sea.
1320 static std::tuple<bool, bool> FlowRiver(TileIndex spring, TileIndex begin, uint min_river_length)
1322 # define SET_MARK(x) marks.insert(x)
1323 # define IS_MARKED(x) (marks.find(x) != marks.end())
1325 uint height = TileHeight(begin);
1327 if (IsWaterTile(begin)) {
1328 return { DistanceManhattan(spring, begin) > min_river_length, GetTileZ(begin) == 0 };
1331 std::set<TileIndex> marks;
1332 SET_MARK(begin);
1334 /* Breadth first search for the closest tile we can flow down to. */
1335 std::list<TileIndex> queue;
1336 queue.push_back(begin);
1338 bool found = false;
1339 uint count = 0; // Number of tiles considered; to be used for lake location guessing.
1340 TileIndex end;
1341 do {
1342 end = queue.front();
1343 queue.pop_front();
1345 uint height2 = TileHeight(end);
1346 if (IsTileFlat(end) && (height2 < height || (height2 == height && IsWaterTile(end)))) {
1347 found = true;
1348 break;
1351 for (DiagDirection d = DIAGDIR_BEGIN; d < DIAGDIR_END; d++) {
1352 TileIndex t2 = end + TileOffsByDiagDir(d);
1353 if (IsValidTile(t2) && !IS_MARKED(t2) && FlowsDown(end, t2)) {
1354 SET_MARK(t2);
1355 count++;
1356 queue.push_back(t2);
1359 } while (!queue.empty());
1361 bool main_river = false;
1362 if (found) {
1363 /* Flow further down hill. */
1364 std::tie(found, main_river) = FlowRiver(spring, end, min_river_length);
1365 } else if (count > 32) {
1366 /* Maybe we can make a lake. Find the Nth of the considered tiles. */
1367 std::set<TileIndex>::const_iterator cit = marks.cbegin();
1368 std::advance(cit, RandomRange(count - 1));
1369 TileIndex lakeCenter = *cit;
1371 if (IsValidTile(lakeCenter) &&
1372 /* A river, or lake, can only be built on flat slopes. */
1373 IsTileFlat(lakeCenter) &&
1374 /* We want the lake to be built at the height of the river. */
1375 TileHeight(begin) == TileHeight(lakeCenter) &&
1376 /* We don't want the lake at the entry of the valley. */
1377 lakeCenter != begin &&
1378 /* We don't want lakes in the desert. */
1379 (_settings_game.game_creation.landscape != LT_TROPIC || GetTropicZone(lakeCenter) != TROPICZONE_DESERT) &&
1380 /* We only want a lake if the river is long enough. */
1381 DistanceManhattan(spring, lakeCenter) > min_river_length) {
1382 end = lakeCenter;
1383 MakeRiverAndModifyDesertZoneAround(lakeCenter);
1384 uint range = RandomRange(8) + 3;
1385 CircularTileSearch(&lakeCenter, range, MakeLake, &height);
1386 /* Call the search a second time so artefacts from going circular in one direction get (mostly) hidden. */
1387 lakeCenter = end;
1388 CircularTileSearch(&lakeCenter, range, MakeLake, &height);
1389 found = true;
1393 marks.clear();
1394 if (found) BuildRiver(begin, end, spring, main_river);
1395 return { found, main_river };
1399 * Actually (try to) create some rivers.
1401 static void CreateRivers()
1403 int amount = _settings_game.game_creation.amount_of_rivers;
1404 if (amount == 0) return;
1406 uint wells = Map::ScaleBySize(4 << _settings_game.game_creation.amount_of_rivers);
1407 const uint num_short_rivers = wells - std::max(1u, wells / 10);
1408 SetGeneratingWorldProgress(GWP_RIVER, wells + TILE_UPDATE_FREQUENCY / 64); // Include the tile loop calls below.
1410 /* Try to create long rivers. */
1411 for (; wells > num_short_rivers; wells--) {
1412 IncreaseGeneratingWorldProgress(GWP_RIVER);
1413 for (int tries = 0; tries < 512; tries++) {
1414 TileIndex t = RandomTile();
1415 if (!CircularTileSearch(&t, 8, FindSpring, nullptr)) continue;
1416 if (std::get<0>(FlowRiver(t, t, _settings_game.game_creation.min_river_length * 4))) break;
1420 /* Try to create short rivers. */
1421 for (; wells != 0; wells--) {
1422 IncreaseGeneratingWorldProgress(GWP_RIVER);
1423 for (int tries = 0; tries < 128; tries++) {
1424 TileIndex t = RandomTile();
1425 if (!CircularTileSearch(&t, 8, FindSpring, nullptr)) continue;
1426 if (std::get<0>(FlowRiver(t, t, _settings_game.game_creation.min_river_length))) break;
1430 /* Widening rivers may have left some tiles requiring to be watered. */
1431 ConvertGroundTilesIntoWaterTiles();
1433 /* Run tile loop to update the ground density. */
1434 for (uint i = 0; i != TILE_UPDATE_FREQUENCY; i++) {
1435 if (i % 64 == 0) IncreaseGeneratingWorldProgress(GWP_RIVER);
1436 RunTileLoop();
1441 * Calculate what height would be needed to cover N% of the landmass.
1443 * The function allows both snow and desert/tropic line to be calculated. It
1444 * tries to find the closests height which covers N% of the landmass; it can
1445 * be below or above it.
1447 * Tropic has a mechanism where water and tropic tiles in mountains grow
1448 * inside the desert. To better approximate the requested coverage, this is
1449 * taken into account via an edge histogram, which tells how many neighbouring
1450 * tiles are lower than the tiles of that height. The multiplier indicates how
1451 * severe this has to be taken into account.
1453 * @param coverage A value between 0 and 100 indicating a percentage of landmass that should be covered.
1454 * @param edge_multiplier How much effect neighbouring tiles that are of a lower height level have on the score.
1455 * @return The estimated best height to use to cover N% of the landmass.
1457 static uint CalculateCoverageLine(uint coverage, uint edge_multiplier)
1459 const DiagDirection neighbour_dir[] = {
1460 DIAGDIR_NE,
1461 DIAGDIR_SE,
1462 DIAGDIR_SW,
1463 DIAGDIR_NW,
1466 /* Histogram of how many tiles per height level exist. */
1467 std::array<int, MAX_TILE_HEIGHT + 1> histogram = {};
1468 /* Histogram of how many neighbour tiles are lower than the tiles of the height level. */
1469 std::array<int, MAX_TILE_HEIGHT + 1> edge_histogram = {};
1471 /* Build a histogram of the map height. */
1472 for (TileIndex tile = 0; tile < Map::Size(); tile++) {
1473 uint h = TileHeight(tile);
1474 histogram[h]++;
1476 if (edge_multiplier != 0) {
1477 /* Check if any of our neighbours is below us. */
1478 for (auto dir : neighbour_dir) {
1479 TileIndex neighbour_tile = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDiagDir(dir));
1480 if (IsValidTile(neighbour_tile) && TileHeight(neighbour_tile) < h) {
1481 edge_histogram[h]++;
1487 /* The amount of land we have is the map size minus the first (sea) layer. */
1488 uint land_tiles = Map::Size() - histogram[0];
1489 int best_score = land_tiles;
1491 /* Our goal is the coverage amount of the land-mass. */
1492 int goal_tiles = land_tiles * coverage / 100;
1494 /* We scan from top to bottom. */
1495 uint h = MAX_TILE_HEIGHT;
1496 uint best_h = h;
1498 int current_tiles = 0;
1499 for (; h > 0; h--) {
1500 current_tiles += histogram[h];
1501 int current_score = goal_tiles - current_tiles;
1503 /* Tropic grows from water and mountains into the desert. This is a
1504 * great visual, but it also means we* need to take into account how
1505 * much less desert tiles are being created if we are on this
1506 * height-level. We estimate this based on how many neighbouring
1507 * tiles are below us for a given length, assuming that is where
1508 * tropic is growing from.
1510 if (edge_multiplier != 0 && h > 1) {
1511 /* From water tropic tiles grow for a few tiles land inward. */
1512 current_score -= edge_histogram[1] * edge_multiplier;
1513 /* Tropic tiles grow into the desert for a few tiles. */
1514 current_score -= edge_histogram[h] * edge_multiplier;
1517 if (std::abs(current_score) < std::abs(best_score)) {
1518 best_score = current_score;
1519 best_h = h;
1522 /* Always scan all height-levels, as h == 1 might give a better
1523 * score than any before. This is true for example with 0% desert
1524 * coverage. */
1527 return best_h;
1531 * Calculate the line from which snow begins.
1533 static void CalculateSnowLine()
1535 /* We do not have snow sprites on coastal tiles, so never allow "1" as height. */
1536 _settings_game.game_creation.snow_line_height = std::max(CalculateCoverageLine(_settings_game.game_creation.snow_coverage, 0), 2u);
1540 * Calculate the line (in height) between desert and tropic.
1541 * @return The height of the line between desert and tropic.
1543 static uint8_t CalculateDesertLine()
1545 /* CalculateCoverageLine() runs from top to bottom, so we need to invert the coverage. */
1546 return CalculateCoverageLine(100 - _settings_game.game_creation.desert_coverage, 4);
1549 bool GenerateLandscape(uint8_t mode)
1551 /* Number of steps of landscape generation */
1552 static constexpr uint GLS_HEIGHTMAP = 3; ///< Loading a heightmap
1553 static constexpr uint GLS_TERRAGENESIS = 5; ///< Terragenesis generator
1554 static constexpr uint GLS_ORIGINAL = 2; ///< Original generator
1555 static constexpr uint GLS_TROPIC = 12; ///< Extra steps needed for tropic landscape
1556 static constexpr uint GLS_OTHER = 0; ///< Extra steps for other landscapes
1557 uint steps = (_settings_game.game_creation.landscape == LT_TROPIC) ? GLS_TROPIC : GLS_OTHER;
1559 if (mode == GWM_HEIGHTMAP) {
1560 SetGeneratingWorldProgress(GWP_LANDSCAPE, steps + GLS_HEIGHTMAP);
1561 if (!LoadHeightmap(_file_to_saveload.detail_ftype, _file_to_saveload.name.c_str())) {
1562 return false;
1564 IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
1565 } else if (_settings_game.game_creation.land_generator == LG_TERRAGENESIS) {
1566 SetGeneratingWorldProgress(GWP_LANDSCAPE, steps + GLS_TERRAGENESIS);
1567 GenerateTerrainPerlin();
1568 } else {
1569 SetGeneratingWorldProgress(GWP_LANDSCAPE, steps + GLS_ORIGINAL);
1570 if (_settings_game.construction.freeform_edges) {
1571 for (uint x = 0; x < Map::SizeX(); x++) MakeVoid(TileXY(x, 0));
1572 for (uint y = 0; y < Map::SizeY(); y++) MakeVoid(TileXY(0, y));
1574 switch (_settings_game.game_creation.landscape) {
1575 case LT_ARCTIC: {
1576 uint32_t r = Random();
1578 for (uint i = Map::ScaleBySize(GB(r, 0, 7) + 950); i != 0; --i) {
1579 GenerateTerrain(2, 0);
1582 uint flag = GB(r, 7, 2) | 4;
1583 for (uint i = Map::ScaleBySize(GB(r, 9, 7) + 450); i != 0; --i) {
1584 GenerateTerrain(4, flag);
1586 break;
1589 case LT_TROPIC: {
1590 uint32_t r = Random();
1592 for (uint i = Map::ScaleBySize(GB(r, 0, 7) + 170); i != 0; --i) {
1593 GenerateTerrain(0, 0);
1596 uint flag = GB(r, 7, 2) | 4;
1597 for (uint i = Map::ScaleBySize(GB(r, 9, 8) + 1700); i != 0; --i) {
1598 GenerateTerrain(0, flag);
1601 flag ^= 2;
1603 for (uint i = Map::ScaleBySize(GB(r, 17, 7) + 410); i != 0; --i) {
1604 GenerateTerrain(3, flag);
1606 break;
1609 default: {
1610 uint32_t r = Random();
1612 assert(_settings_game.difficulty.quantity_sea_lakes != CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY);
1613 uint i = Map::ScaleBySize(GB(r, 0, 7) + (3 - _settings_game.difficulty.quantity_sea_lakes) * 256 + 100);
1614 for (; i != 0; --i) {
1615 /* Make sure we do not overflow. */
1616 GenerateTerrain(Clamp(_settings_game.difficulty.terrain_type, 0, 3), 0);
1618 break;
1623 /* Do not call IncreaseGeneratingWorldProgress() before FixSlopes(),
1624 * it allows screen redraw. Drawing of broken slopes crashes the game */
1625 FixSlopes();
1626 MarkWholeScreenDirty();
1627 IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
1629 ConvertGroundTilesIntoWaterTiles();
1630 MarkWholeScreenDirty();
1631 IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
1633 switch (_settings_game.game_creation.landscape) {
1634 case LT_ARCTIC:
1635 CalculateSnowLine();
1636 break;
1638 case LT_TROPIC: {
1639 uint desert_tropic_line = CalculateDesertLine();
1640 CreateDesertOrRainForest(desert_tropic_line);
1641 break;
1644 default:
1645 break;
1648 CreateRivers();
1649 return true;
1652 void OnTick_Town();
1653 void OnTick_Trees();
1654 void OnTick_Station();
1655 void OnTick_Industry();
1657 void OnTick_Companies();
1658 void OnTick_LinkGraph();
1660 void CallLandscapeTick()
1663 PerformanceAccumulator framerate(PFE_GL_LANDSCAPE);
1665 OnTick_Town();
1666 OnTick_Trees();
1667 OnTick_Station();
1668 OnTick_Industry();
1671 OnTick_Companies();
1672 OnTick_LinkGraph();