OpenTTD Source: src/landscape.cpp Source File

OpenTTD Source 14.0-beta3

landscape.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 <http://www.gnu.org/licenses/>.
6 */
7
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 "pathfinder/npf/aystar.h"
34 #include "saveload/saveload.h"
35 #include "framerate_type.h"
36 #include "landscape_cmd.h"
37 #include "terraform_cmd.h"
38 #include "station_func.h"
39 #include "pathfinder/water_regions.h"
40
41 #include "table/strings.h"
42 #include "table/sprites.h"
43
44 #include "safeguards.h"
45
46 extern const TileTypeProcs
47 _tile_type_clear_procs,
48 _tile_type_rail_procs,
49 _tile_type_road_procs,
50 _tile_type_town_procs,
51 _tile_type_trees_procs,
52 _tile_type_station_procs,
53 _tile_type_water_procs,
54 _tile_type_void_procs,
55 _tile_type_industry_procs,
56 _tile_type_tunnelbridge_procs,
57 _tile_type_object_procs;
58
64 const TileTypeProcs * const _tile_type_procs[16] = {
65 &_tile_type_clear_procs,
66 &_tile_type_rail_procs,
67 &_tile_type_road_procs,
68 &_tile_type_town_procs,
69 &_tile_type_trees_procs,
70 &_tile_type_station_procs,
71 &_tile_type_water_procs,
72 &_tile_type_void_procs,
73 &_tile_type_industry_procs,
74 &_tile_type_tunnelbridge_procs,
75 &_tile_type_object_procs,
76 };
77
79 extern const byte _slope_to_sprite_offset[32] = {
80 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0,
81 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 17, 0, 15, 18, 0,
82 };
83
92 static SnowLine *_snow_line = nullptr;
93
107 Point InverseRemapCoords2(int x, int y, bool clamp_to_map, bool *clamped)
108 {
109 if (clamped != nullptr) *clamped = false; // Not clamping yet.
110
111 /* Initial x/y world coordinate is like if the landscape
112 * was completely flat on height 0. */
113 Point pt = InverseRemapCoords(x, y);
114
115 const uint min_coord = _settings_game.construction.freeform_edges ? TILE_SIZE : 0;
116 const uint max_x = Map::MaxX() * TILE_SIZE - 1;
117 const uint max_y = Map::MaxY() * TILE_SIZE - 1;
118
119 if (clamp_to_map) {
120 /* Bring the coordinates near to a valid range. At the top we allow a number
121 * of extra tiles. This is mostly due to the tiles on the north side of
122 * the map possibly being drawn higher due to the extra height levels. */
123 int extra_tiles = CeilDiv(_settings_game.construction.map_height_limit * TILE_HEIGHT, TILE_PIXELS);
124 Point old_pt = pt;
125 pt.x = Clamp(pt.x, -extra_tiles * TILE_SIZE, max_x);
126 pt.y = Clamp(pt.y, -extra_tiles * TILE_SIZE, max_y);
127 if (clamped != nullptr) *clamped = (pt.x != old_pt.x) || (pt.y != old_pt.y);
128 }
129
130 /* Now find the Z-world coordinate by fix point iteration.
131 * This is a bit tricky because the tile height is non-continuous at foundations.
132 * The clicked point should be approached from the back, otherwise there are regions that are not clickable.
133 * (FOUNDATION_HALFTILE_LOWER on SLOPE_STEEP_S hides north halftile completely)
134 * So give it a z-malus of 4 in the first iterations. */
135 int z = 0;
136 if (clamp_to_map) {
137 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;
138 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;
139 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;
140 } else {
141 for (int i = 0; i < 5; i++) z = GetSlopePixelZOutsideMap(pt.x + std::max(z, 4) - 4, pt.y + std::max(z, 4) - 4) / 2;
142 for (int m = 3; m > 0; m--) z = GetSlopePixelZOutsideMap(pt.x + std::max(z, m) - m, pt.y + std::max(z, m) - m) / 2;
143 for (int i = 0; i < 5; i++) z = GetSlopePixelZOutsideMap(pt.x + z, pt.y + z ) / 2;
144 }
145
146 pt.x += z;
147 pt.y += z;
148 if (clamp_to_map) {
149 Point old_pt = pt;
150 pt.x = Clamp(pt.x, min_coord, max_x);
151 pt.y = Clamp(pt.y, min_coord, max_y);
152 if (clamped != nullptr) *clamped = *clamped || (pt.x != old_pt.x) || (pt.y != old_pt.y);
153 }
154
155 return pt;
156 }
157
166 uint ApplyFoundationToSlope(Foundation f, Slope *s)
167 {
168 if (!IsFoundation(f)) return 0;
169
170 if (IsLeveledFoundation(f)) {
171 uint dz = 1 + (IsSteepSlope(*s) ? 1 : 0);
172 *s = SLOPE_FLAT;
173 return dz;
174 }
175
176 if (f != FOUNDATION_STEEP_BOTH && IsNonContinuousFoundation(f)) {
177 *s = HalftileSlope(*s, GetHalftileFoundationCorner(f));
178 return 0;
179 }
180
181 if (IsSpecialRailFoundation(f)) {
182 *s = SlopeWithThreeCornersRaised(OppositeCorner(GetRailFoundationCorner(f)));
183 return 0;
184 }
185
186 uint dz = IsSteepSlope(*s) ? 1 : 0;
187 Corner highest_corner = GetHighestSlopeCorner(*s);
188
189 switch (f) {
190 case FOUNDATION_INCLINED_X:
191 *s = (((highest_corner == CORNER_W) || (highest_corner == CORNER_S)) ? SLOPE_SW : SLOPE_NE);
192 break;
193
194 case FOUNDATION_INCLINED_Y:
195 *s = (((highest_corner == CORNER_S) || (highest_corner == CORNER_E)) ? SLOPE_SE : SLOPE_NW);
196 break;
197
198 case FOUNDATION_STEEP_LOWER:
199 *s = SlopeWithOneCornerRaised(highest_corner);
200 break;
201
202 case FOUNDATION_STEEP_BOTH:
203 *s = HalftileSlope(SlopeWithOneCornerRaised(highest_corner), highest_corner);
204 break;
205
206 default: NOT_REACHED();
207 }
208 return dz;
209 }
210
211
224 uint GetPartialPixelZ(int x, int y, Slope corners)
225 {
226 if (IsHalftileSlope(corners)) {
227 /* A foundation is placed on half the tile at a specific corner. This means that,
228 * depending on the corner, that one half of the tile is at the maximum height. */
229 switch (GetHalftileSlopeCorner(corners)) {
230 case CORNER_W:
231 if (x > y) return GetSlopeMaxPixelZ(corners);
232 break;
233
234 case CORNER_S:
235 if (x + y >= (int)TILE_SIZE) return GetSlopeMaxPixelZ(corners);
236 break;
237
238 case CORNER_E:
239 if (x <= y) return GetSlopeMaxPixelZ(corners);
240 break;
241
242 case CORNER_N:
243 if (x + y < (int)TILE_SIZE) return GetSlopeMaxPixelZ(corners);
244 break;
245
246 default: NOT_REACHED();
247 }
248 }
249
250 switch (RemoveHalftileSlope(corners)) {
251 case SLOPE_FLAT: return 0;
252
253 /* One corner is up.*/
254 case SLOPE_N: return x + y <= (int)TILE_SIZE ? (TILE_SIZE - x - y) >> 1 : 0;
255 case SLOPE_E: return y >= x ? (1 + y - x) >> 1 : 0;
256 case SLOPE_S: return x + y >= (int)TILE_SIZE ? (1 + x + y - TILE_SIZE) >> 1 : 0;
257 case SLOPE_W: return x >= y ? (x - y) >> 1 : 0;
258
259 /* Two corners next to eachother are up. */
260 case SLOPE_NE: return (TILE_SIZE - x) >> 1;
261 case SLOPE_SE: return (y + 1) >> 1;
262 case SLOPE_SW: return (x + 1) >> 1;
263 case SLOPE_NW: return (TILE_SIZE - y) >> 1;
264
265 /* Three corners are up on the same level. */
266 case SLOPE_ENW: return x + y >= (int)TILE_SIZE ? TILE_HEIGHT - ((1 + x + y - TILE_SIZE) >> 1) : TILE_HEIGHT;
267 case SLOPE_SEN: return y < x ? TILE_HEIGHT - ((x - y) >> 1) : TILE_HEIGHT;
268 case SLOPE_WSE: return x + y <= (int)TILE_SIZE ? TILE_HEIGHT - ((TILE_SIZE - x - y) >> 1) : TILE_HEIGHT;
269 case SLOPE_NWS: return x < y ? TILE_HEIGHT - ((1 + y - x) >> 1) : TILE_HEIGHT;
270
271 /* Two corners at opposite sides are up. */
272 case SLOPE_NS: return x + y < (int)TILE_SIZE ? (TILE_SIZE - x - y) >> 1 : (1 + x + y - TILE_SIZE) >> 1;
273 case SLOPE_EW: return x >= y ? (x - y) >> 1 : (1 + y - x) >> 1;
274
275 /* Very special cases. */
276 case SLOPE_ELEVATED: return TILE_HEIGHT;
277
278 /* Steep slopes. The top is at 2 * TILE_HEIGHT. */
279 case SLOPE_STEEP_N: return (TILE_SIZE - x + TILE_SIZE - y) >> 1;
280 case SLOPE_STEEP_E: return (TILE_SIZE + 1 + y - x) >> 1;
281 case SLOPE_STEEP_S: return (1 + x + y) >> 1;
282 case SLOPE_STEEP_W: return (TILE_SIZE + x - y) >> 1;
283
284 default: NOT_REACHED();
285 }
286 }
287
299 int GetSlopePixelZ(int x, int y, bool ground_vehicle)
300 {
301 TileIndex tile = TileVirtXY(x, y);
302
303 return _tile_type_procs[GetTileType(tile)]->get_slope_z_proc(tile, x, y, ground_vehicle);
304 }
305
314 int GetSlopePixelZOutsideMap(int x, int y)
315 {
316 if (IsInsideBS(x, 0, Map::SizeX() * TILE_SIZE) && IsInsideBS(y, 0, Map::SizeY() * TILE_SIZE)) {
317 return GetSlopePixelZ(x, y, false);
318 } else {
319 return _tile_type_procs[MP_VOID]->get_slope_z_proc(INVALID_TILE, x, y, false);
320 }
321 }
322
332 int GetSlopeZInCorner(Slope tileh, Corner corner)
333 {
334 assert(!IsHalftileSlope(tileh));
335 return ((tileh & SlopeWithOneCornerRaised(corner)) != 0 ? 1 : 0) + (tileh == SteepSlope(corner) ? 1 : 0);
336 }
337
350 void GetSlopePixelZOnEdge(Slope tileh, DiagDirection edge, int *z1, int *z2)
351 {
352 static const Slope corners[4][4] = {
353 /* corner | steep slope
354 * z1 z2 | z1 z2 */
355 {SLOPE_E, SLOPE_N, SLOPE_STEEP_E, SLOPE_STEEP_N}, // DIAGDIR_NE, z1 = E, z2 = N
356 {SLOPE_S, SLOPE_E, SLOPE_STEEP_S, SLOPE_STEEP_E}, // DIAGDIR_SE, z1 = S, z2 = E
357 {SLOPE_S, SLOPE_W, SLOPE_STEEP_S, SLOPE_STEEP_W}, // DIAGDIR_SW, z1 = S, z2 = W
358 {SLOPE_W, SLOPE_N, SLOPE_STEEP_W, SLOPE_STEEP_N}, // DIAGDIR_NW, z1 = W, z2 = N
359 };
360
361 int halftile_test = (IsHalftileSlope(tileh) ? SlopeWithOneCornerRaised(GetHalftileSlopeCorner(tileh)) : 0);
362 if (halftile_test == corners[edge][0]) *z2 += TILE_HEIGHT; // The slope is non-continuous in z2. z2 is on the upper side.
363 if (halftile_test == corners[edge][1]) *z1 += TILE_HEIGHT; // The slope is non-continuous in z1. z1 is on the upper side.
364
365 if ((tileh & corners[edge][0]) != 0) *z1 += TILE_HEIGHT; // z1 is raised
366 if ((tileh & corners[edge][1]) != 0) *z2 += TILE_HEIGHT; // z2 is raised
367 if (RemoveHalftileSlope(tileh) == corners[edge][2]) *z1 += TILE_HEIGHT; // z1 is highest corner of a steep slope
368 if (RemoveHalftileSlope(tileh) == corners[edge][3]) *z2 += TILE_HEIGHT; // z2 is highest corner of a steep slope
369 }
370
379 Slope GetFoundationSlope(TileIndex tile, int *z)
380 {
381 Slope tileh = GetTileSlope(tile, z);
382 Foundation f = _tile_type_procs[GetTileType(tile)]->get_foundation_proc(tile, tileh);
383 uint z_inc = ApplyFoundationToSlope(f, &tileh);
384 if (z != nullptr) *z += z_inc;
385 return tileh;
386 }
387
388
389 bool HasFoundationNW(TileIndex tile, Slope slope_here, uint z_here)
390 {
391 int z;
392
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);
396
397 Slope slope = GetFoundationPixelSlope(TILE_ADDXY(tile, 0, -1), &z);
398 int z_W = z;
399 int z_N = z;
400 GetSlopePixelZOnEdge(slope, DIAGDIR_SE, &z_W, &z_N);
401
402 return (z_N_here > z_N) || (z_W_here > z_W);
403 }
404
405
406 bool HasFoundationNE(TileIndex tile, Slope slope_here, uint z_here)
407 {
408 int z;
409
410 int z_E_here = z_here;
411 int z_N_here = z_here;
412 GetSlopePixelZOnEdge(slope_here, DIAGDIR_NE, &z_E_here, &z_N_here);
413
414 Slope slope = GetFoundationPixelSlope(TILE_ADDXY(tile, -1, 0), &z);
415 int z_E = z;
416 int z_N = z;
417 GetSlopePixelZOnEdge(slope, DIAGDIR_SW, &z_E, &z_N);
418
419 return (z_N_here > z_N) || (z_E_here > z_E);
420 }
421
427 void DrawFoundation(TileInfo *ti, Foundation f)
428 {
429 if (!IsFoundation(f)) return;
430
431 /* Two part foundations must be drawn separately */
432 assert(f != FOUNDATION_STEEP_BOTH);
433
434 uint sprite_block = 0;
435 int z;
436 Slope slope = GetFoundationPixelSlope(ti->tile, &z);
437
438 /* Select the needed block of foundations sprites
439 * Block 0: Walls at NW and NE edge
440 * Block 1: Wall at NE edge
441 * Block 2: Wall at NW edge
442 * Block 3: No walls at NW or NE edge
443 */
444 if (!HasFoundationNW(ti->tile, slope, z)) sprite_block += 1;
445 if (!HasFoundationNE(ti->tile, slope, z)) sprite_block += 2;
446
447 /* Use the original slope sprites if NW and NE borders should be visible */
448 SpriteID leveled_base = (sprite_block == 0 ? (int)SPR_FOUNDATION_BASE : (SPR_SLOPES_VIRTUAL_BASE + sprite_block * SPR_TRKFOUND_BLOCK_SIZE));
449 SpriteID inclined_base = SPR_SLOPES_VIRTUAL_BASE + SPR_SLOPES_INCLINED_OFFSET + sprite_block * SPR_TRKFOUND_BLOCK_SIZE;
450 SpriteID halftile_base = SPR_HALFTILE_FOUNDATION_BASE + sprite_block * SPR_HALFTILE_BLOCK_SIZE;
451
452 if (IsSteepSlope(ti->tileh)) {
453 if (!IsNonContinuousFoundation(f)) {
454 /* Lower part of foundation */
455 AddSortableSpriteToDraw(
456 leveled_base + (ti->tileh & ~SLOPE_STEEP), PAL_NONE, ti->x, ti->y, TILE_SIZE, TILE_SIZE, TILE_HEIGHT - 1, ti->z
457 );
458 }
459
460 Corner highest_corner = GetHighestSlopeCorner(ti->tileh);
461 ti->z += ApplyPixelFoundationToSlope(f, &ti->tileh);
462
463 if (IsInclinedFoundation(f)) {
464 /* inclined foundation */
465 byte inclined = highest_corner * 2 + (f == FOUNDATION_INCLINED_Y ? 1 : 0);
466
467 AddSortableSpriteToDraw(inclined_base + inclined, PAL_NONE, ti->x, ti->y,
468 f == FOUNDATION_INCLINED_X ? TILE_SIZE : 1,
469 f == FOUNDATION_INCLINED_Y ? TILE_SIZE : 1,
470 TILE_HEIGHT, ti->z
471 );
472 OffsetGroundSprite(0, 0);
473 } else if (IsLeveledFoundation(f)) {
474 AddSortableSpriteToDraw(leveled_base + SlopeWithOneCornerRaised(highest_corner), PAL_NONE, ti->x, ti->y, TILE_SIZE, TILE_SIZE, TILE_HEIGHT - 1, ti->z - TILE_HEIGHT);
475 OffsetGroundSprite(0, -(int)TILE_HEIGHT);
476 } else if (f == FOUNDATION_STEEP_LOWER) {
477 /* one corner raised */
478 OffsetGroundSprite(0, -(int)TILE_HEIGHT);
479 } else {
480 /* halftile foundation */
481 int x_bb = (((highest_corner == CORNER_W) || (highest_corner == CORNER_S)) ? TILE_SIZE / 2 : 0);
482 int y_bb = (((highest_corner == CORNER_S) || (highest_corner == CORNER_E)) ? TILE_SIZE / 2 : 0);
483
484 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);
485 /* Reposition ground sprite back to original position after bounding box change above. This is similar to
486 * RemapCoords() but without zoom scaling. */
487 Point pt = {(y_bb - x_bb) * 2, y_bb + x_bb};
488 OffsetGroundSprite(-pt.x, -pt.y);
489 }
490 } else {
491 if (IsLeveledFoundation(f)) {
492 /* leveled foundation */
493 AddSortableSpriteToDraw(leveled_base + ti->tileh, PAL_NONE, ti->x, ti->y, TILE_SIZE, TILE_SIZE, TILE_HEIGHT - 1, ti->z);
494 OffsetGroundSprite(0, -(int)TILE_HEIGHT);
495 } else if (IsNonContinuousFoundation(f)) {
496 /* halftile foundation */
497 Corner halftile_corner = GetHalftileFoundationCorner(f);
498 int x_bb = (((halftile_corner == CORNER_W) || (halftile_corner == CORNER_S)) ? TILE_SIZE / 2 : 0);
499 int y_bb = (((halftile_corner == CORNER_S) || (halftile_corner == CORNER_E)) ? TILE_SIZE / 2 : 0);
500
501 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);
502 /* Reposition ground sprite back to original position after bounding box change above. This is similar to
503 * RemapCoords() but without zoom scaling. */
504 Point pt = {(y_bb - x_bb) * 2, y_bb + x_bb};
505 OffsetGroundSprite(-pt.x, -pt.y);
506 } else if (IsSpecialRailFoundation(f)) {
507 /* anti-zig-zag foundation */
508 SpriteID spr;
509 if (ti->tileh == SLOPE_NS || ti->tileh == SLOPE_EW) {
510 /* half of leveled foundation under track corner */
511 spr = leveled_base + SlopeWithThreeCornersRaised(GetRailFoundationCorner(f));
512 } else {
513 /* tile-slope = sloped along X/Y, foundation-slope = three corners raised */
514 spr = inclined_base + 2 * GetRailFoundationCorner(f) + ((ti->tileh == SLOPE_SW || ti->tileh == SLOPE_NE) ? 1 : 0);
515 }
516 AddSortableSpriteToDraw(spr, PAL_NONE, ti->x, ti->y, TILE_SIZE, TILE_SIZE, TILE_HEIGHT - 1, ti->z);
517 OffsetGroundSprite(0, 0);
518 } else {
519 /* inclined foundation */
520 byte inclined = GetHighestSlopeCorner(ti->tileh) * 2 + (f == FOUNDATION_INCLINED_Y ? 1 : 0);
521
522 AddSortableSpriteToDraw(inclined_base + inclined, PAL_NONE, ti->x, ti->y,
523 f == FOUNDATION_INCLINED_X ? TILE_SIZE : 1,
524 f == FOUNDATION_INCLINED_Y ? TILE_SIZE : 1,
525 TILE_HEIGHT, ti->z
526 );
527 OffsetGroundSprite(0, 0);
528 }
529 ti->z += ApplyPixelFoundationToSlope(f, &ti->tileh);
530 }
531 }
532
533 void DoClearSquare(TileIndex tile)
534 {
535 /* If the tile can have animation and we clear it, delete it from the animated tile list. */
536 if (_tile_type_procs[GetTileType(tile)]->animate_tile_proc != nullptr) DeleteAnimatedTile(tile);
537
538 bool remove = IsDockingTile(tile);
539 MakeClear(tile, CLEAR_GRASS, _generating_world ? 3 : 0);
540 MarkTileDirtyByTile(tile);
541 if (remove) RemoveDockingTile(tile);
542
543 InvalidateWaterRegion(tile);
544 }
545
556 TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
557 {
558 return _tile_type_procs[GetTileType(tile)]->get_tile_track_status_proc(tile, mode, sub_mode, side);
559 }
560
567 void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner)
568 {
569 _tile_type_procs[GetTileType(tile)]->change_tile_owner_proc(tile, old_owner, new_owner);
570 }
571
572 void GetTileDesc(TileIndex tile, TileDesc *td)
573 {
574 _tile_type_procs[GetTileType(tile)]->get_tile_desc_proc(tile, td);
575 }
576
582 bool IsSnowLineSet()
583 {
584 return _snow_line != nullptr;
585 }
586
592 void SetSnowLine(byte table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS])
593 {
594 _snow_line = CallocT<SnowLine>(1);
595 _snow_line->lowest_value = 0xFF;
596 memcpy(_snow_line->table, table, sizeof(_snow_line->table));
597
598 for (uint i = 0; i < SNOW_LINE_MONTHS; i++) {
599 for (uint j = 0; j < SNOW_LINE_DAYS; j++) {
600 _snow_line->highest_value = std::max(_snow_line->highest_value, table[i][j]);
601 _snow_line->lowest_value = std::min(_snow_line->lowest_value, table[i][j]);
602 }
603 }
604 }
605
611 byte GetSnowLine()
612 {
613 if (_snow_line == nullptr) return _settings_game.game_creation.snow_line_height;
614
615 TimerGameCalendar::YearMonthDay ymd = TimerGameCalendar::ConvertDateToYMD(TimerGameCalendar::date);
616 return _snow_line->table[ymd.month][ymd.day];
617 }
618
624 byte HighestSnowLine()
625 {
626 return _snow_line == nullptr ? _settings_game.game_creation.snow_line_height : _snow_line->highest_value;
627 }
628
634 byte LowestSnowLine()
635 {
636 return _snow_line == nullptr ? _settings_game.game_creation.snow_line_height : _snow_line->lowest_value;
637 }
638
643 void ClearSnowLine()
644 {
645 free(_snow_line);
646 _snow_line = nullptr;
647 }
648
655 CommandCost CmdLandscapeClear(DoCommandFlag flags, TileIndex tile)
656 {
657 CommandCost cost(EXPENSES_CONSTRUCTION);
658 bool do_clear = false;
659 /* Test for stuff which results in water when cleared. Then add the cost to also clear the water. */
660 if ((flags & DC_FORCE_CLEAR_TILE) && HasTileWaterClass(tile) && IsTileOnWater(tile) && !IsWaterTile(tile) && !IsCoastTile(tile)) {
661 if ((flags & DC_AUTO) && GetWaterClass(tile) == WATER_CLASS_CANAL) return_cmd_error(STR_ERROR_MUST_DEMOLISH_CANAL_FIRST);
662 do_clear = true;
663 cost.AddCost(GetWaterClass(tile) == WATER_CLASS_CANAL ? _price[PR_CLEAR_CANAL] : _price[PR_CLEAR_WATER]);
664 }
665
666 Company *c = (flags & (DC_AUTO | DC_BANKRUPT)) ? nullptr : Company::GetIfValid(_current_company);
667 if (c != nullptr && (int)GB(c->clear_limit, 16, 16) < 1) {
668 return_cmd_error(STR_ERROR_CLEARING_LIMIT_REACHED);
669 }
670
671 const ClearedObjectArea *coa = FindClearedObject(tile);
672
673 /* If this tile was the first tile which caused object destruction, always
674 * pass it on to the tile_type_proc. That way multiple test runs and the exec run stay consistent. */
675 if (coa != nullptr && coa->first_tile != tile) {
676 /* If this tile belongs to an object which was already cleared via another tile, pretend it has been
677 * already removed.
678 * However, we need to check stuff, which is not the same for all object tiles. (e.g. being on water or not) */
679
680 /* If a object is removed, it leaves either bare land or water. */
681 if ((flags & DC_NO_WATER) && HasTileWaterClass(tile) && IsTileOnWater(tile)) {
682 return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
683 }
684 } else {
685 cost.AddCost(_tile_type_procs[GetTileType(tile)]->clear_tile_proc(tile, flags));
686 }
687
688 if (flags & DC_EXEC) {
689 if (c != nullptr) c->clear_limit -= 1 << 16;
690 if (do_clear) DoClearSquare(tile);
691 }
692 return cost;
693 }
694
703 std::tuple<CommandCost, Money> CmdClearArea(DoCommandFlag flags, TileIndex tile, TileIndex start_tile, bool diagonal)
704 {
705 if (start_tile >= Map::Size()) return { CMD_ERROR, 0 };
706
707 Money money = GetAvailableMoneyForCommand();
708 CommandCost cost(EXPENSES_CONSTRUCTION);
709 CommandCost last_error = CMD_ERROR;
710 bool had_success = false;
711
712 const Company *c = (flags & (DC_AUTO | DC_BANKRUPT)) ? nullptr : Company::GetIfValid(_current_company);
713 int limit = (c == nullptr ? INT32_MAX : GB(c->clear_limit, 16, 16));
714
715 std::unique_ptr<TileIterator> iter = TileIterator::Create(tile, start_tile, diagonal);
716 for (; *iter != INVALID_TILE; ++(*iter)) {
717 TileIndex t = *iter;
718 CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags & ~DC_EXEC, t);
719 if (ret.Failed()) {
720 last_error = ret;
721
722 /* We may not clear more tiles. */
723 if (c != nullptr && GB(c->clear_limit, 16, 16) < 1) break;
724 continue;
725 }
726
727 had_success = true;
728 if (flags & DC_EXEC) {
729 money -= ret.GetCost();
730 if (ret.GetCost() > 0 && money < 0) {
731 return { cost, ret.GetCost() };
732 }
733 Command<CMD_LANDSCAPE_CLEAR>::Do(flags, t);
734
735 /* draw explosion animation...
736 * Disable explosions when game is paused. Looks silly and blocks the view. */
737 if ((t == tile || t == start_tile) && _pause_mode == PM_UNPAUSED) {
738 /* big explosion in two corners, or small explosion for single tiles */
739 CreateEffectVehicleAbove(TileX(t) * TILE_SIZE + TILE_SIZE / 2, TileY(t) * TILE_SIZE + TILE_SIZE / 2, 2,
740 TileX(tile) == TileX(start_tile) && TileY(tile) == TileY(start_tile) ? EV_EXPLOSION_SMALL : EV_EXPLOSION_LARGE
741 );
742 }
743 } else {
744 /* When we're at the clearing limit we better bail (unneed) testing as well. */
745 if (ret.GetCost() != 0 && --limit <= 0) break;
746 }
747 cost.AddCost(ret);
748 }
749
750 return { had_success ? cost : last_error, 0 };
751 }
752
753
754 TileIndex _cur_tileloop_tile;
755
759 void RunTileLoop()
760 {
761 PerformanceAccumulator framerate(PFE_GL_LANDSCAPE);
762
763 /* The pseudorandom sequence of tiles is generated using a Galois linear feedback
764 * shift register (LFSR). This allows a deterministic pseudorandom ordering, but
765 * still with minimal state and fast iteration. */
766
767 /* Maximal length LFSR feedback terms, from 12-bit (for 64x64 maps) to 24-bit (for 4096x4096 maps).
768 * Extracted from http://www.ece.cmu.edu/~koopman/lfsr/ */
769 static const uint32_t feedbacks[] = {
770 0xD8F, 0x1296, 0x2496, 0x4357, 0x8679, 0x1030E, 0x206CD, 0x403FE, 0x807B8, 0x1004B2, 0x2006A8, 0x4004B2, 0x800B87
771 };
772 static_assert(lengthof(feedbacks) == 2 * MAX_MAP_SIZE_BITS - 2 * MIN_MAP_SIZE_BITS + 1);
773 const uint32_t feedback = feedbacks[Map::LogX() + Map::LogY() - 2 * MIN_MAP_SIZE_BITS];
774
775 /* We update every tile every 256 ticks, so divide the map size by 2^8 = 256 */
776 uint count = 1 << (Map::LogX() + Map::LogY() - 8);
777
778 TileIndex tile = _cur_tileloop_tile;
779 /* The LFSR cannot have a zeroed state. */
780 assert(tile != 0);
781
782 /* Manually update tile 0 every 256 ticks - the LFSR never iterates over it itself. */
783 if (TimerGameTick::counter % 256 == 0) {
784 _tile_type_procs[GetTileType(0)]->tile_loop_proc(0);
785 count--;
786 }
787
788 while (count--) {
789 _tile_type_procs[GetTileType(tile)]->tile_loop_proc(tile);
790
791 /* Get the next tile in sequence using a Galois LFSR. */
792 tile = (tile.base() >> 1) ^ (-(int32_t)(tile.base() & 1) & feedback);
793 }
794
795 _cur_tileloop_tile = tile;
796 }
797
798 void InitializeLandscape()
799 {
800 for (uint y = _settings_game.construction.freeform_edges ? 1 : 0; y < Map::MaxY(); y++) {
801 for (uint x = _settings_game.construction.freeform_edges ? 1 : 0; x < Map::MaxX(); x++) {
802 MakeClear(TileXY(x, y), CLEAR_GRASS, 3);
803 SetTileHeight(TileXY(x, y), 0);
804 SetTropicZone(TileXY(x, y), TROPICZONE_NORMAL);
805 ClearBridgeMiddle(TileXY(x, y));
806 }
807 }
808
809 for (uint x = 0; x < Map::SizeX(); x++) MakeVoid(TileXY(x, Map::MaxY()));
810 for (uint y = 0; y < Map::SizeY(); y++) MakeVoid(TileXY(Map::MaxX(), y));
811 }
812
813 static const byte _genterrain_tbl_1[5] = { 10, 22, 33, 37, 4 };
814 static const byte _genterrain_tbl_2[5] = { 0, 0, 0, 0, 33 };
815
816 static void GenerateTerrain(int type, uint flag)
817 {
818 uint32_t r = Random();
819
820 /* Choose one of the templates from the graphics file. */
821 const Sprite *templ = GetSprite((((r >> 24) * _genterrain_tbl_1[type]) >> 8) + _genterrain_tbl_2[type] + SPR_MAPGEN_BEGIN, SpriteType::MapGen);
822 if (templ == nullptr) UserError("Map generator sprites could not be loaded");
823
824 /* Chose a random location to apply the template to. */
825 uint x = r & Map::MaxX();
826 uint y = (r >> Map::LogX()) & Map::MaxY();
827
828 /* Make sure the template is not too close to the upper edges; bottom edges are checked later. */
829 uint edge_distance = 1 + (_settings_game.construction.freeform_edges ? 1 : 0);
830 if (x <= edge_distance || y <= edge_distance) return;
831
832 DiagDirection direction = (DiagDirection)GB(r, 22, 2);
833 uint w = templ->width;
834 uint h = templ->height;
835
836 if (DiagDirToAxis(direction) == AXIS_Y) Swap(w, h);
837
838 const byte *p = templ->data;
839
840 if ((flag & 4) != 0) {
841 /* This is only executed in secondary/tertiary loops to generate the terrain for arctic and tropic.
842 * It prevents the templates to be applied to certain parts of the map based on the flags, thus
843 * creating regions with different elevations/topography. */
844 uint xw = x * Map::SizeY();
845 uint yw = y * Map::SizeX();
846 uint bias = (Map::SizeX() + Map::SizeY()) * 16;
847
848 switch (flag & 3) {
849 default: NOT_REACHED();
850 case 0:
851 if (xw + yw > Map::Size() - bias) return;
852 break;
853
854 case 1:
855 if (yw < xw + bias) return;
856 break;
857
858 case 2:
859 if (xw + yw < Map::Size() + bias) return;
860 break;
861
862 case 3:
863 if (xw < yw + bias) return;
864 break;
865 }
866 }
867
868 /* Ensure the template does not overflow at the bottom edges of the map; upper edges were checked before. */
869 if (x + w >= Map::MaxX()) return;
870 if (y + h >= Map::MaxY()) return;
871
872 TileIndex tile = TileXY(x, y);
873
874 /* Get the template and overlay in a particular direction over the map's height from the given
875 * origin point (tile), and update the map's height everywhere where the height from the template
876 * is higher than the height of the map. In other words, this only raises the tile heights. */
877 switch (direction) {
878 default: NOT_REACHED();
879 case DIAGDIR_NE:
880 do {
881 TileIndex tile_cur = tile;
882
883 for (uint w_cur = w; w_cur != 0; --w_cur) {
884 if (GB(*p, 0, 4) >= TileHeight(tile_cur)) SetTileHeight(tile_cur, GB(*p, 0, 4));
885 p++;
886 tile_cur++;
887 }
888 tile += TileDiffXY(0, 1);
889 } while (--h != 0);
890 break;
891
892 case DIAGDIR_SE:
893 do {
894 TileIndex tile_cur = tile;
895
896 for (uint h_cur = h; h_cur != 0; --h_cur) {
897 if (GB(*p, 0, 4) >= TileHeight(tile_cur)) SetTileHeight(tile_cur, GB(*p, 0, 4));
898 p++;
899 tile_cur += TileDiffXY(0, 1);
900 }
901 tile += TileDiffXY(1, 0);
902 } while (--w != 0);
903 break;
904
905 case DIAGDIR_SW:
906 tile += TileDiffXY(w - 1, 0);
907 do {
908 TileIndex tile_cur = tile;
909
910 for (uint w_cur = w; w_cur != 0; --w_cur) {
911 if (GB(*p, 0, 4) >= TileHeight(tile_cur)) SetTileHeight(tile_cur, GB(*p, 0, 4));
912 p++;
913 tile_cur--;
914 }
915 tile += TileDiffXY(0, 1);
916 } while (--h != 0);
917 break;
918
919 case DIAGDIR_NW:
920 tile += TileDiffXY(0, h - 1);
921 do {
922 TileIndex tile_cur = tile;
923
924 for (uint h_cur = h; h_cur != 0; --h_cur) {
925 if (GB(*p, 0, 4) >= TileHeight(tile_cur)) SetTileHeight(tile_cur, GB(*p, 0, 4));
926 p++;
927 tile_cur -= TileDiffXY(0, 1);
928 }
929 tile += TileDiffXY(1, 0);
930 } while (--w != 0);
931 break;
932 }
933 }
934
935
936 #include "table/genland.h"
937
938 static void CreateDesertOrRainForest(uint desert_tropic_line)
939 {
940 uint update_freq = Map::Size() / 4;
941 const TileIndexDiffC *data;
942
943 for (TileIndex tile = 0; tile != Map::Size(); ++tile) {
944 if ((tile.base() % update_freq) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
945
946 if (!IsValidTile(tile)) continue;
947
948 for (data = _make_desert_or_rainforest_data;
949 data != endof(_make_desert_or_rainforest_data); ++data) {
950 TileIndex t = AddTileIndexDiffCWrap(tile, *data);
951 if (t != INVALID_TILE && (TileHeight(t) >= desert_tropic_line || IsTileType(t, MP_WATER))) break;
952 }
953 if (data == endof(_make_desert_or_rainforest_data)) {
954 SetTropicZone(tile, TROPICZONE_DESERT);
955 }
956 }
957
958 for (uint i = 0; i != 256; i++) {
959 if ((i % 64) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
960
961 RunTileLoop();
962 }
963
964 for (TileIndex tile = 0; tile != Map::Size(); ++tile) {
965 if ((tile.base() % update_freq) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
966
967 if (!IsValidTile(tile)) continue;
968
969 for (data = _make_desert_or_rainforest_data;
970 data != endof(_make_desert_or_rainforest_data); ++data) {
971 TileIndex t = AddTileIndexDiffCWrap(tile, *data);
972 if (t != INVALID_TILE && IsTileType(t, MP_CLEAR) && IsClearGround(t, CLEAR_DESERT)) break;
973 }
974 if (data == endof(_make_desert_or_rainforest_data)) {
975 SetTropicZone(tile, TROPICZONE_RAINFOREST);
976 }
977 }
978 }
979
985 static bool FindSpring(TileIndex tile, void *)
986 {
987 int referenceHeight;
988 if (!IsTileFlat(tile, &referenceHeight) || IsWaterTile(tile)) return false;
989
990 /* In the tropics rivers start in the rainforest. */
991 if (_settings_game.game_creation.landscape == LT_TROPIC && GetTropicZone(tile) != TROPICZONE_RAINFOREST) return false;
992
993 /* Are there enough higher tiles to warrant a 'spring'? */
994 uint num = 0;
995 for (int dx = -1; dx <= 1; dx++) {
996 for (int dy = -1; dy <= 1; dy++) {
997 TileIndex t = TileAddWrap(tile, dx, dy);
998 if (t != INVALID_TILE && GetTileMaxZ(t) > referenceHeight) num++;
999 }
1000 }
1001
1002 if (num < 4) return false;
1003
1004 /* Are we near the top of a hill? */
1005 for (int dx = -16; dx <= 16; dx++) {
1006 for (int dy = -16; dy <= 16; dy++) {
1007 TileIndex t = TileAddWrap(tile, dx, dy);
1008 if (t != INVALID_TILE && GetTileMaxZ(t) > referenceHeight + 2) return false;
1009 }
1010 }
1011
1012 return true;
1013 }
1014
1021 static bool MakeLake(TileIndex tile, void *user_data)
1022 {
1023 uint height = *(uint*)user_data;
1024 if (!IsValidTile(tile) || TileHeight(tile) != height || !IsTileFlat(tile)) return false;
1025 if (_settings_game.game_creation.landscape == LT_TROPIC && GetTropicZone(tile) == TROPICZONE_DESERT) return false;
1026
1027 for (DiagDirection d = DIAGDIR_BEGIN; d < DIAGDIR_END; d++) {
1028 TileIndex t2 = tile + TileOffsByDiagDir(d);
1029 if (IsWaterTile(t2)) {
1030 MakeRiverAndModifyDesertZoneAround(tile);
1031 return false;
1032 }
1033 }
1034
1035 return false;
1036 }
1037
1044 static bool RiverMakeWider(TileIndex tile, void *data)
1045 {
1046 /* Don't expand into void tiles. */
1047 if (!IsValidTile(tile)) return false;
1048
1049 /* If the tile is already sea or river, don't expand. */
1050 if (IsWaterTile(tile)) return false;
1051
1052 /* If the tile is at height 0 after terraforming but the ocean hasn't flooded yet, don't build river. */
1053 if (GetTileMaxZ(tile) == 0) return false;
1054
1055 TileIndex origin_tile = *(TileIndex *)data;
1056 Slope cur_slope = GetTileSlope(tile);
1057 Slope desired_slope = GetTileSlope(origin_tile); // Initialize matching the origin tile as a shortcut if no terraforming is needed.
1058
1059 /* Never flow uphill. */
1060 if (GetTileMaxZ(tile) > GetTileMaxZ(origin_tile)) return false;
1061
1062 /* If the new tile can't hold a river tile, try terraforming. */
1063 if (!IsTileFlat(tile) && !IsInclinedSlope(cur_slope)) {
1064 /* Don't try to terraform steep slopes. */
1065 if (IsSteepSlope(cur_slope)) return false;
1066
1067 bool flat_river_found = false;
1068 bool sloped_river_found = false;
1069
1070 /* There are two common possibilities:
1071 * 1. River flat, adjacent tile has one corner lowered.
1072 * 2. River descending, adjacent tile has either one or three corners raised.
1073 */
1074
1075 /* First, determine the desired slope based on adjacent river tiles. This doesn't necessarily match the origin tile for the CircularTileSearch. */
1076 for (DiagDirection d = DIAGDIR_BEGIN; d < DIAGDIR_END; d++) {
1077 TileIndex other_tile = TileAddByDiagDir(tile, d);
1078 Slope other_slope = GetTileSlope(other_tile);
1079
1080 /* Only consider river tiles. */
1081 if (IsWaterTile(other_tile) && IsRiver(other_tile)) {
1082 /* If the adjacent river tile flows downhill, we need to check where we are relative to the slope. */
1083 if (IsInclinedSlope(other_slope) && GetTileMaxZ(tile) == GetTileMaxZ(other_tile)) {
1084 /* Check for a parallel slope. If we don't find one, we're above or below the slope instead. */
1085 if (GetInclinedSlopeDirection(other_slope) == ChangeDiagDir(d, DIAGDIRDIFF_90RIGHT) ||
1086 GetInclinedSlopeDirection(other_slope) == ChangeDiagDir(d, DIAGDIRDIFF_90LEFT)) {
1087 desired_slope = other_slope;
1088 sloped_river_found = true;
1089 break;
1090 }
1091 }
1092 /* If we find an adjacent river tile, remember it. We'll terraform to match it later if we don't find a slope. */
1093 if (IsTileFlat(other_tile)) flat_river_found = true;
1094 }
1095 }
1096 /* We didn't find either an inclined or flat river, so we're climbing the wrong slope. Bail out. */
1097 if (!sloped_river_found && !flat_river_found) return false;
1098
1099 /* We didn't find an inclined river, but there is a flat river. */
1100 if (!sloped_river_found && flat_river_found) desired_slope = SLOPE_FLAT;
1101
1102 /* Now that we know the desired slope, it's time to terraform! */
1103
1104 /* If the river is flat and the adjacent tile has one corner lowered, we want to raise it. */
1105 if (desired_slope == SLOPE_FLAT && IsSlopeWithThreeCornersRaised(cur_slope)) {
1106 /* Make sure we're not affecting an existing river slope tile. */
1107 for (DiagDirection d = DIAGDIR_BEGIN; d < DIAGDIR_END; d++) {
1108 TileIndex other_tile = TileAddByDiagDir(tile, d);
1109 if (IsInclinedSlope(GetTileSlope(other_tile)) && IsWaterTile(other_tile)) return false;
1110 }
1111 Command<CMD_TERRAFORM_LAND>::Do(DC_EXEC | DC_AUTO, tile, ComplementSlope(cur_slope), true);
1112
1113 /* If the river is descending and the adjacent tile has either one or three corners raised, we want to make it match the slope. */
1114 } else if (IsInclinedSlope(desired_slope)) {
1115 /* Don't break existing flat river tiles by terraforming under them. */
1116 DiagDirection river_direction = ReverseDiagDir(GetInclinedSlopeDirection(desired_slope));
1117
1118 for (DiagDirDiff d = DIAGDIRDIFF_BEGIN; d < DIAGDIRDIFF_END; d++) {
1119 /* We don't care about downstream or upstream tiles, just the riverbanks. */
1120 if (d == DIAGDIRDIFF_SAME || d == DIAGDIRDIFF_REVERSE) continue;
1121
1122 TileIndex other_tile = (TileAddByDiagDir(tile, ChangeDiagDir(river_direction, d)));
1123 if (IsWaterTile(other_tile) && IsRiver(other_tile) && IsTileFlat(other_tile)) return false;
1124 }
1125
1126 /* Get the corners which are different between the current and desired slope. */
1127 Slope to_change = cur_slope ^ desired_slope;
1128
1129 /* Lower unwanted corners first. If only one corner is raised, no corners need lowering. */
1130 if (!IsSlopeWithOneCornerRaised(cur_slope)) {
1131 to_change = to_change & ComplementSlope(desired_slope);
1132 Command<CMD_TERRAFORM_LAND>::Do(DC_EXEC | DC_AUTO, tile, to_change, false);
1133 }
1134
1135 /* Now check the match and raise any corners needed. */
1136 cur_slope = GetTileSlope(tile);
1137 if (cur_slope != desired_slope && IsSlopeWithOneCornerRaised(cur_slope)) {
1138 to_change = cur_slope ^ desired_slope;
1139 Command<CMD_TERRAFORM_LAND>::Do(DC_EXEC | DC_AUTO, tile, to_change, true);
1140 }
1141 }
1142 /* Update cur_slope after possibly terraforming. */
1143 cur_slope = GetTileSlope(tile);
1144 }
1145
1146 /* Sloped rivers need water both upstream and downstream. */
1147 if (IsInclinedSlope(cur_slope)) {
1148 DiagDirection slope_direction = GetInclinedSlopeDirection(cur_slope);
1149
1150 TileIndex upstream_tile = TileAddByDiagDir(tile, slope_direction);
1151 TileIndex downstream_tile = TileAddByDiagDir(tile, ReverseDiagDir(slope_direction));
1152
1153 /* Don't look outside the map. */
1154 if (!IsValidTile(upstream_tile) || !IsValidTile(downstream_tile)) return false;
1155
1156 /* Downstream might be new ocean created by our terraforming, and it hasn't flooded yet. */
1157 bool downstream_is_ocean = GetTileZ(downstream_tile) == 0 && (GetTileSlope(downstream_tile) == SLOPE_FLAT || IsSlopeWithOneCornerRaised(GetTileSlope(downstream_tile)));
1158
1159 /* If downstream is dry, flat, and not ocean, try making it a river tile. */
1160 if (!IsWaterTile(downstream_tile) && !downstream_is_ocean) {
1161 /* If the tile upstream isn't flat, don't bother. */
1162 if (GetTileSlope(downstream_tile) != SLOPE_FLAT) return false;
1163
1164 MakeRiverAndModifyDesertZoneAround(downstream_tile);
1165 }
1166
1167 /* If upstream is dry and flat, try making it a river tile. */
1168 if (!IsWaterTile(upstream_tile)) {
1169 /* If the tile upstream isn't flat, don't bother. */
1170 if (GetTileSlope(upstream_tile) != SLOPE_FLAT) return false;
1171
1172 MakeRiverAndModifyDesertZoneAround(upstream_tile);
1173 }
1174 }
1175
1176 /* If the tile slope matches the desired slope, add a river tile. */
1177 if (cur_slope == desired_slope) {
1178 MakeRiverAndModifyDesertZoneAround(tile);
1179 }
1180
1181 /* Always return false to keep searching. */
1182 return false;
1183 }
1184
1191 static bool FlowsDown(TileIndex begin, TileIndex end)
1192 {
1193 assert(DistanceManhattan(begin, end) == 1);
1194
1195 int heightBegin;
1196 int heightEnd;
1197 Slope slopeBegin = GetTileSlope(begin, &heightBegin);
1198 Slope slopeEnd = GetTileSlope(end, &heightEnd);
1199
1200 return heightEnd <= heightBegin &&
1201 /* Slope either is inclined or flat; rivers don't support other slopes. */
1202 (slopeEnd == SLOPE_FLAT || IsInclinedSlope(slopeEnd)) &&
1203 /* Slope continues, then it must be lower... or either end must be flat. */
1204 ((slopeEnd == slopeBegin && heightEnd < heightBegin) || slopeEnd == SLOPE_FLAT || slopeBegin == SLOPE_FLAT);
1205 }
1206
1208 struct River_UserData {
1209 TileIndex spring;
1210 bool main_river;
1211 };
1212
1213 /* AyStar callback for checking whether we reached our destination. */
1214 static int32_t River_EndNodeCheck(const AyStar *aystar, const OpenListNode *current)
1215 {
1216 return current->path.node.tile == *(TileIndex*)aystar->user_target ? AYSTAR_FOUND_END_NODE : AYSTAR_DONE;
1217 }
1218
1219 /* AyStar callback for getting the cost of the current node. */
1220 static int32_t River_CalculateG(AyStar *, AyStarNode *, OpenListNode *)
1221 {
1222 return 1 + RandomRange(_settings_game.game_creation.river_route_random);
1223 }
1224
1225 /* AyStar callback for getting the estimated cost to the destination. */
1226 static int32_t River_CalculateH(AyStar *aystar, AyStarNode *current, OpenListNode *)
1227 {
1228 return DistanceManhattan(*(TileIndex*)aystar->user_target, current->tile);
1229 }
1230
1231 /* AyStar callback for getting the neighbouring nodes of the given node. */
1232 static void River_GetNeighbours(AyStar *aystar, OpenListNode *current)
1233 {
1234 TileIndex tile = current->path.node.tile;
1235
1236 aystar->num_neighbours = 0;
1237 for (DiagDirection d = DIAGDIR_BEGIN; d < DIAGDIR_END; d++) {
1238 TileIndex t2 = tile + TileOffsByDiagDir(d);
1239 if (IsValidTile(t2) && FlowsDown(tile, t2)) {
1240 aystar->neighbours[aystar->num_neighbours].tile = t2;
1241 aystar->neighbours[aystar->num_neighbours].direction = INVALID_TRACKDIR;
1242 aystar->num_neighbours++;
1243 }
1244 }
1245 }
1246
1247 /* AyStar callback when an route has been found. */
1248 static void River_FoundEndNode(AyStar *aystar, OpenListNode *current)
1249 {
1250 River_UserData *data = (River_UserData *)aystar->user_data;
1251
1252 /* First, build the river without worrying about its width. */
1253 uint cur_pos = 0;
1254 for (PathNode *path = &current->path; path != nullptr; path = path->parent, cur_pos++) {
1255 TileIndex tile = path->node.tile;
1256 if (!IsWaterTile(tile)) {
1257 MakeRiverAndModifyDesertZoneAround(tile);
1258 }
1259 }
1260
1261 /* If the river is a main river, go back along the path to widen it.
1262 * Don't make wide rivers if we're using the original landscape generator.
1263 */
1264 if (_settings_game.game_creation.land_generator != LG_ORIGINAL && data->main_river) {
1265 const uint long_river_length = _settings_game.game_creation.min_river_length * 4;
1266 uint current_river_length;
1267 uint radius;
1268
1269 cur_pos = 0;
1270 for (PathNode *path = &current->path; path != nullptr; path = path->parent, cur_pos++) {
1271 TileIndex tile = path->node.tile;
1272
1273 /* Check if we should widen river depending on how far we are away from the source. */
1274 current_river_length = DistanceManhattan(data->spring, tile);
1275 radius = std::min(3u, (current_river_length / (long_river_length / 3u)) + 1u);
1276
1277 if (radius > 1) CircularTileSearch(&tile, radius, RiverMakeWider, (void *)&path->node.tile);
1278 }
1279 }
1280 }
1281
1282 static const uint RIVER_HASH_SIZE = 8;
1283
1289 static uint River_Hash(TileIndex tile, Trackdir)
1290 {
1291 return GB(TileHash(TileX(tile), TileY(tile)), 0, RIVER_HASH_SIZE);
1292 }
1293
1301 static void BuildRiver(TileIndex begin, TileIndex end, TileIndex spring, bool main_river)
1302 {
1303 River_UserData user_data = { spring, main_river };
1304
1305 AyStar finder = {};
1306 finder.CalculateG = River_CalculateG;
1307 finder.CalculateH = River_CalculateH;
1308 finder.GetNeighbours = River_GetNeighbours;
1309 finder.EndNodeCheck = River_EndNodeCheck;
1310 finder.FoundEndNode = River_FoundEndNode;
1311 finder.user_target = &end;
1312 finder.user_data = &user_data;
1313
1314 finder.Init(River_Hash, 1 << RIVER_HASH_SIZE);
1315
1316 AyStarNode start;
1317 start.tile = begin;
1318 start.direction = INVALID_TRACKDIR;
1319 finder.AddStartNode(&start, 0);
1320 finder.Main();
1321 finder.Free();
1322 }
1323
1331 static std::tuple<bool, bool> FlowRiver(TileIndex spring, TileIndex begin, uint min_river_length)
1332 {
1333 # define SET_MARK(x) marks.insert(x)
1334 # define IS_MARKED(x) (marks.find(x) != marks.end())
1335
1336 uint height = TileHeight(begin);
1337
1338 if (IsWaterTile(begin)) {
1339 return { DistanceManhattan(spring, begin) > min_river_length, GetTileZ(begin) == 0 };
1340 }
1341
1342 std::set<TileIndex> marks;
1343 SET_MARK(begin);
1344
1345 /* Breadth first search for the closest tile we can flow down to. */
1346 std::list<TileIndex> queue;
1347 queue.push_back(begin);
1348
1349 bool found = false;
1350 uint count = 0; // Number of tiles considered; to be used for lake location guessing.
1351 TileIndex end;
1352 do {
1353 end = queue.front();
1354 queue.pop_front();
1355
1356 uint height2 = TileHeight(end);
1357 if (IsTileFlat(end) && (height2 < height || (height2 == height && IsWaterTile(end)))) {
1358 found = true;
1359 break;
1360 }
1361
1362 for (DiagDirection d = DIAGDIR_BEGIN; d < DIAGDIR_END; d++) {
1363 TileIndex t2 = end + TileOffsByDiagDir(d);
1364 if (IsValidTile(t2) && !IS_MARKED(t2) && FlowsDown(end, t2)) {
1365 SET_MARK(t2);
1366 count++;
1367 queue.push_back(t2);
1368 }
1369 }
1370 } while (!queue.empty());
1371
1372 bool main_river = false;
1373 if (found) {
1374 /* Flow further down hill. */
1375 std::tie(found, main_river) = FlowRiver(spring, end, min_river_length);
1376 } else if (count > 32) {
1377 /* Maybe we can make a lake. Find the Nth of the considered tiles. */
1378 std::set<TileIndex>::const_iterator cit = marks.cbegin();
1379 std::advance(cit, RandomRange(count - 1));
1380 TileIndex lakeCenter = *cit;
1381
1382 if (IsValidTile(lakeCenter) &&
1383 /* A river, or lake, can only be built on flat slopes. */
1384 IsTileFlat(lakeCenter) &&
1385 /* We want the lake to be built at the height of the river. */
1386 TileHeight(begin) == TileHeight(lakeCenter) &&
1387 /* We don't want the lake at the entry of the valley. */
1388 lakeCenter != begin &&
1389 /* We don't want lakes in the desert. */
1390 (_settings_game.game_creation.landscape != LT_TROPIC || GetTropicZone(lakeCenter) != TROPICZONE_DESERT) &&
1391 /* We only want a lake if the river is long enough. */
1392 DistanceManhattan(spring, lakeCenter) > min_river_length) {
1393 end = lakeCenter;
1394 MakeRiverAndModifyDesertZoneAround(lakeCenter);
1395 uint range = RandomRange(8) + 3;
1396 CircularTileSearch(&lakeCenter, range, MakeLake, &height);
1397 /* Call the search a second time so artefacts from going circular in one direction get (mostly) hidden. */
1398 lakeCenter = end;
1399 CircularTileSearch(&lakeCenter, range, MakeLake, &height);
1400 found = true;
1401 }
1402 }
1403
1404 marks.clear();
1405 if (found) BuildRiver(begin, end, spring, main_river);
1406 return { found, main_river };
1407 }
1408
1412 static void CreateRivers()
1413 {
1414 int amount = _settings_game.game_creation.amount_of_rivers;
1415 if (amount == 0) return;
1416
1417 uint wells = Map::ScaleBySize(4 << _settings_game.game_creation.amount_of_rivers);
1418 const uint num_short_rivers = wells - std::max(1u, wells / 10);
1419 SetGeneratingWorldProgress(GWP_RIVER, wells + 256 / 64); // Include the tile loop calls below.
1420
1421 /* Try to create long rivers. */
1422 for (; wells > num_short_rivers; wells--) {
1423 IncreaseGeneratingWorldProgress(GWP_RIVER);
1424 for (int tries = 0; tries < 512; tries++) {
1425 TileIndex t = RandomTile();
1426 if (!CircularTileSearch(&t, 8, FindSpring, nullptr)) continue;
1427 if (std::get<0>(FlowRiver(t, t, _settings_game.game_creation.min_river_length * 4))) break;
1428 }
1429 }
1430
1431 /* Try to create short rivers. */
1432 for (; wells != 0; wells--) {
1433 IncreaseGeneratingWorldProgress(GWP_RIVER);
1434 for (int tries = 0; tries < 128; tries++) {
1435 TileIndex t = RandomTile();
1436 if (!CircularTileSearch(&t, 8, FindSpring, nullptr)) continue;
1437 if (std::get<0>(FlowRiver(t, t, _settings_game.game_creation.min_river_length))) break;
1438 }
1439 }
1440
1441 /* Widening rivers may have left some tiles requiring to be watered. */
1442 ConvertGroundTilesIntoWaterTiles();
1443
1444 /* Run tile loop to update the ground density. */
1445 for (uint i = 0; i != 256; i++) {
1446 if (i % 64 == 0) IncreaseGeneratingWorldProgress(GWP_RIVER);
1447 RunTileLoop();
1448 }
1449 }
1450
1468 static uint CalculateCoverageLine(uint coverage, uint edge_multiplier)
1469 {
1470 const DiagDirection neighbour_dir[] = {
1471 DIAGDIR_NE,
1472 DIAGDIR_SE,
1473 DIAGDIR_SW,
1474 DIAGDIR_NW,
1475 };
1476
1477 /* Histogram of how many tiles per height level exist. */
1478 std::array<int, MAX_TILE_HEIGHT + 1> histogram = {};
1479 /* Histogram of how many neighbour tiles are lower than the tiles of the height level. */
1480 std::array<int, MAX_TILE_HEIGHT + 1> edge_histogram = {};
1481
1482 /* Build a histogram of the map height. */
1483 for (TileIndex tile = 0; tile < Map::Size(); tile++) {
1484 uint h = TileHeight(tile);
1485 histogram[h]++;
1486
1487 if (edge_multiplier != 0) {
1488 /* Check if any of our neighbours is below us. */
1489 for (auto dir : neighbour_dir) {
1490 TileIndex neighbour_tile = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDiagDir(dir));
1491 if (IsValidTile(neighbour_tile) && TileHeight(neighbour_tile) < h) {
1492 edge_histogram[h]++;
1493 }
1494 }
1495 }
1496 }
1497
1498 /* The amount of land we have is the map size minus the first (sea) layer. */
1499 uint land_tiles = Map::Size() - histogram[0];
1500 int best_score = land_tiles;
1501
1502 /* Our goal is the coverage amount of the land-mass. */
1503 int goal_tiles = land_tiles * coverage / 100;
1504
1505 /* We scan from top to bottom. */
1506 uint h = MAX_TILE_HEIGHT;
1507 uint best_h = h;
1508
1509 int current_tiles = 0;
1510 for (; h > 0; h--) {
1511 current_tiles += histogram[h];
1512 int current_score = goal_tiles - current_tiles;
1513
1514 /* Tropic grows from water and mountains into the desert. This is a
1515 * great visual, but it also means we* need to take into account how
1516 * much less desert tiles are being created if we are on this
1517 * height-level. We estimate this based on how many neighbouring
1518 * tiles are below us for a given length, assuming that is where
1519 * tropic is growing from.
1520 */
1521 if (edge_multiplier != 0 && h > 1) {
1522 /* From water tropic tiles grow for a few tiles land inward. */
1523 current_score -= edge_histogram[1] * edge_multiplier;
1524 /* Tropic tiles grow into the desert for a few tiles. */
1525 current_score -= edge_histogram[h] * edge_multiplier;
1526 }
1527
1528 if (std::abs(current_score) < std::abs(best_score)) {
1529 best_score = current_score;
1530 best_h = h;
1531 }
1532
1533 /* Always scan all height-levels, as h == 1 might give a better
1534 * score than any before. This is true for example with 0% desert
1535 * coverage. */
1536 }
1537
1538 return best_h;
1539 }
1540
1544 static void CalculateSnowLine()
1545 {
1546 /* We do not have snow sprites on coastal tiles, so never allow "1" as height. */
1547 _settings_game.game_creation.snow_line_height = std::max(CalculateCoverageLine(_settings_game.game_creation.snow_coverage, 0), 2u);
1548 }
1549
1554 static uint8_t CalculateDesertLine()
1555 {
1556 /* CalculateCoverageLine() runs from top to bottom, so we need to invert the coverage. */
1557 return CalculateCoverageLine(100 - _settings_game.game_creation.desert_coverage, 4);
1558 }
1559
1560 bool GenerateLandscape(byte mode)
1561 {
1563 enum GenLandscapeSteps {
1564 GLS_HEIGHTMAP = 3,
1565 GLS_TERRAGENESIS = 5,
1566 GLS_ORIGINAL = 2,
1567 GLS_TROPIC = 12,
1568 GLS_OTHER = 0,
1569 };
1570 uint steps = (_settings_game.game_creation.landscape == LT_TROPIC) ? GLS_TROPIC : GLS_OTHER;
1571
1572 if (mode == GWM_HEIGHTMAP) {
1573 SetGeneratingWorldProgress(GWP_LANDSCAPE, steps + GLS_HEIGHTMAP);
1574 if (!LoadHeightmap(_file_to_saveload.detail_ftype, _file_to_saveload.name.c_str())) {
1575 return false;
1576 }
1577 IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
1578 } else if (_settings_game.game_creation.land_generator == LG_TERRAGENESIS) {
1579 SetGeneratingWorldProgress(GWP_LANDSCAPE, steps + GLS_TERRAGENESIS);
1580 GenerateTerrainPerlin();
1581 } else {
1582 SetGeneratingWorldProgress(GWP_LANDSCAPE, steps + GLS_ORIGINAL);
1583 if (_settings_game.construction.freeform_edges) {
1584 for (uint x = 0; x < Map::SizeX(); x++) MakeVoid(TileXY(x, 0));
1585 for (uint y = 0; y < Map::SizeY(); y++) MakeVoid(TileXY(0, y));
1586 }
1587 switch (_settings_game.game_creation.landscape) {
1588 case LT_ARCTIC: {
1589 uint32_t r = Random();
1590
1591 for (uint i = Map::ScaleBySize(GB(r, 0, 7) + 950); i != 0; --i) {
1592 GenerateTerrain(2, 0);
1593 }
1594
1595 uint flag = GB(r, 7, 2) | 4;
1596 for (uint i = Map::ScaleBySize(GB(r, 9, 7) + 450); i != 0; --i) {
1597 GenerateTerrain(4, flag);
1598 }
1599 break;
1600 }
1601
1602 case LT_TROPIC: {
1603 uint32_t r = Random();
1604
1605 for (uint i = Map::ScaleBySize(GB(r, 0, 7) + 170); i != 0; --i) {
1606 GenerateTerrain(0, 0);
1607 }
1608
1609 uint flag = GB(r, 7, 2) | 4;
1610 for (uint i = Map::ScaleBySize(GB(r, 9, 8) + 1700); i != 0; --i) {
1611 GenerateTerrain(0, flag);
1612 }
1613
1614 flag ^= 2;
1615
1616 for (uint i = Map::ScaleBySize(GB(r, 17, 7) + 410); i != 0; --i) {
1617 GenerateTerrain(3, flag);
1618 }
1619 break;
1620 }
1621
1622 default: {
1623 uint32_t r = Random();
1624
1625 assert(_settings_game.difficulty.quantity_sea_lakes != CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY);
1626 uint i = Map::ScaleBySize(GB(r, 0, 7) + (3 - _settings_game.difficulty.quantity_sea_lakes) * 256 + 100);
1627 for (; i != 0; --i) {
1628 /* Make sure we do not overflow. */
1629 GenerateTerrain(Clamp(_settings_game.difficulty.terrain_type, 0, 3), 0);
1630 }
1631 break;
1632 }
1633 }
1634 }
1635
1636 /* Do not call IncreaseGeneratingWorldProgress() before FixSlopes(),
1637 * it allows screen redraw. Drawing of broken slopes crashes the game */
1638 FixSlopes();
1639 MarkWholeScreenDirty();
1640 IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
1641
1642 ConvertGroundTilesIntoWaterTiles();
1643 MarkWholeScreenDirty();
1644 IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
1645
1646 switch (_settings_game.game_creation.landscape) {
1647 case LT_ARCTIC:
1648 CalculateSnowLine();
1649 break;
1650
1651 case LT_TROPIC: {
1652 uint desert_tropic_line = CalculateDesertLine();
1653 CreateDesertOrRainForest(desert_tropic_line);
1654 break;
1655 }
1656
1657 default:
1658 break;
1659 }
1660
1661 CreateRivers();
1662 return true;
1663 }
1664
1665 void OnTick_Town();
1666 void OnTick_Trees();
1667 void OnTick_Station();
1668 void OnTick_Industry();
1669
1670 void OnTick_Companies();
1671 void OnTick_LinkGraph();
1672
1673 void CallLandscapeTick()
1674 {
1675 {
1676 PerformanceAccumulator framerate(PFE_GL_LANDSCAPE);
1677
1678 OnTick_Town();
1679 OnTick_Trees();
1680 OnTick_Station();
1681 OnTick_Industry();
1682 }
1683
1684 OnTick_Companies();
1685 OnTick_LinkGraph();
1686 }
Sprite::height
uint16_t height
Height of the sprite.
Definition: spritecache.h:18
GameCreationSettings::min_river_length
byte min_river_length
the minimum river length
Definition: settings_type.h:363
GenerateTerrainPerlin
void GenerateTerrainPerlin()
The main new land generator using Perlin noise.
Definition: tgp.cpp:991
FindSpring
static bool FindSpring(TileIndex tile, void *)
Find the spring of a river.
Definition: landscape.cpp:985
IsFoundation
bool IsFoundation(Foundation f)
Tests for FOUNDATION_NONE.
Definition: slope_func.h:287
TileY
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:437
TileIndexDiffCByDiagDir
TileIndexDiffC TileIndexDiffCByDiagDir(DiagDirection dir)
Returns the TileIndexDiffC offset from a DiagDirection.
Definition: map_func.h:490
TileInfo::z
int z
Height.
Definition: tile_cmd.h:48
MP_CLEAR
@ MP_CLEAR
A tile without any structures, i.e. grass, rocks, farm fields etc.
Definition: tile_type.h:48
IsTileFlat
bool IsTileFlat(TileIndex tile, int *h)
Check if a given tile is flat.
Definition: tile_map.cpp:100
DIAGDIR_SE
@ DIAGDIR_SE
Southeast.
Definition: direction_type.h:76
SLOPE_SE
@ SLOPE_SE
south and east corner are raised
Definition: slope_type.h:57
HalftileSlope
static constexpr Slope HalftileSlope(Slope s, Corner corner)
Adds a halftile slope to a slope.
Definition: slope_func.h:274
TROPICZONE_DESERT
@ TROPICZONE_DESERT
Tile is desert.
Definition: tile_type.h:78
CompanyProperties::clear_limit
uint32_t clear_limit
Amount of tiles we can (still) clear (times 65536).
Definition: company_base.h:87
SLOPE_STEEP_E
@ SLOPE_STEEP_E
a steep slope falling to west (from east)
Definition: slope_type.h:68
AXIS_Y
@ AXIS_Y
The y axis.
Definition: direction_type.h:118
IsInclinedSlope
bool IsInclinedSlope(Slope s)
Tests if a specific slope is an inclined slope.
Definition: slope_func.h:228
IsCoastTile
bool IsCoastTile(Tile t)
Is it a coast tile.
Definition: water_map.h:214
AYSTAR_DONE
@ AYSTAR_DONE
Not an end-tile, or wrong direction.
Definition: aystar.h:32
IsClearGround
bool IsClearGround(Tile t, ClearGround ct)
Set the type of clear tile.
Definition: clear_map.h:71
TimerGameTick::counter
static TickCounter counter
Monotonic counter, in ticks, since start of game.
Definition: timer_game_tick.h:33
CalculateSnowLine
static void CalculateSnowLine()
Calculate the line from which snow begins.
Definition: landscape.cpp:1544
FixSlopes
void FixSlopes()
This function takes care of the fact that land in OpenTTD can never differ more than 1 in height.
Definition: heightmap.cpp:422
water.h
SNOW_LINE_DAYS
static const uint SNOW_LINE_DAYS
Number of days in each month in the snow line table.
Definition: landscape.h:17
GetTileMaxZ
int GetTileMaxZ(TileIndex t)
Get top height of the tile inside the map.
Definition: tile_map.cpp:141
IsHalftileSlope
static constexpr bool IsHalftileSlope(Slope s)
Checks for non-continuous slope on halftile foundations.
Definition: slope_func.h:47
tgp.h
landscape_type.h
BuildRiver
static void BuildRiver(TileIndex begin, TileIndex end, TileIndex spring, bool main_river)
Actually build the river between the begin and end tiles using AyStar.
Definition: landscape.cpp:1301
command_func.h
SLOPE_STEEP_S
@ SLOPE_STEEP_S
a steep slope falling to north (from south)
Definition: slope_type.h:67
_tile_type_procs
const TileTypeProcs *const _tile_type_procs[16]
Tile callback functions for each type of tile.
Definition: landscape.cpp:64
Swap
constexpr void Swap(T &a, T &b)
Type safe swap operation.
Definition: math_func.hpp:283
Pool::PoolItem<&_company_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:346
CMD_ERROR
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition: command_func.h:28
AddTileIndexDiffCWrap
TileIndex AddTileIndexDiffCWrap(TileIndex tile, TileIndexDiffC diff)
Add a TileIndexDiffC to a TileIndex and returns the new one.
Definition: map_func.h:522
TileInfo
Tile information, used while rendering the tile.
Definition: tile_cmd.h:43
GetWaterClass
WaterClass GetWaterClass(Tile t)
Get the water class at a tile.
Definition: water_map.h:115
GameCreationSettings::landscape
byte landscape
the landscape we're currently in
Definition: settings_type.h:356
Map::MaxX
static debug_inline uint MaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Definition: map_func.h:297
Sprite::data
byte data[]
Sprite data.
Definition: spritecache.h:22
terraform_cmd.h
Map::LogX
static debug_inline uint LogX()
Logarithm of the map size along the X side.
Definition: map_func.h:251
timer_game_calendar.h
CreateRivers
static void CreateRivers()
Actually (try to) create some rivers.
Definition: landscape.cpp:1412
SLOPE_NW
@ SLOPE_NW
north and west corner are raised
Definition: slope_type.h:55
RemoveHalftileSlope
static constexpr Slope RemoveHalftileSlope(Slope s)
Removes a halftile slope from a slope.
Definition: slope_func.h:60
DiagDirDiff
DiagDirDiff
Enumeration for the difference between to DiagDirection.
Definition: direction_type.h:95
SnowLine::table
byte table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS]
Height of the snow line each day of the year.
Definition: landscape.h:24
MIN_MAP_SIZE_BITS
static const uint MIN_MAP_SIZE_BITS
Minimal and maximal map width and height.
Definition: map_type.h:37
FileToSaveLoad::name
std::string name
Name of the file.
Definition: saveload.h:394
GB
constexpr static debug_inline 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
GetSlopeZInCorner
int GetSlopeZInCorner(Slope tileh, Corner corner)
Determine the Z height of a corner relative to TileZ.
Definition: landscape.cpp:332
DIAGDIR_END
@ DIAGDIR_END
Used for iterations.
Definition: direction_type.h:79
DiagDirToAxis
Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
Definition: direction_func.h:214
CalculateDesertLine
static uint8_t CalculateDesertLine()
Calculate the line (in height) between desert and tropic.
Definition: landscape.cpp:1554
SetTileHeight
void SetTileHeight(Tile tile, uint height)
Sets the height of a tile.
Definition: tile_map.h:57
TROPICZONE_RAINFOREST
@ TROPICZONE_RAINFOREST
Rainforest tile.
Definition: tile_type.h:79
LG_ORIGINAL
@ LG_ORIGINAL
The original landscape generator.
Definition: genworld.h:20
SLOPE_ELEVATED
@ SLOPE_ELEVATED
bit mask containing all 'simple' slopes
Definition: slope_type.h:61
GameSettings::difficulty
DifficultySettings difficulty
settings related to the difficulty
Definition: settings_type.h:618
GetTileZ
int GetTileZ(TileIndex tile)
Get bottom height of the tile.
Definition: tile_map.cpp:121
CLEAR_GRASS
@ CLEAR_GRASS
0-3
Definition: clear_map.h:20
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:95
void_map.h
TileIterator::Create
static std::unique_ptr< TileIterator > Create(TileIndex corner1, TileIndex corner2, bool diagonal)
Create either an OrthogonalTileIterator or DiagonalTileIterator given the diagonal parameter.
Definition: tilearea.cpp:291
DIAGDIRDIFF_90LEFT
@ DIAGDIRDIFF_90LEFT
90 degrees left
Definition: direction_type.h:100
TileHash
uint TileHash(uint x, uint y)
Calculate a hash value from a tile position.
Definition: tile_map.h:316
IsSteepSlope
static constexpr bool IsSteepSlope(Slope s)
Checks if a slope is steep.
Definition: slope_func.h:36
SPR_HALFTILE_FOUNDATION_BASE
static const SpriteID SPR_HALFTILE_FOUNDATION_BASE
Halftile foundations.
Definition: sprites.h:210
GetPartialPixelZ
uint GetPartialPixelZ(int x, int y, Slope corners)
Determines height at given coordinate of a slope.
Definition: landscape.cpp:224
saveload.h
TILE_SIZE
static const uint TILE_SIZE
Tile size in world coordinates.
Definition: tile_type.h:15
TileTypeProcs::get_tile_track_status_proc
GetTileTrackStatusProc * get_tile_track_status_proc
Get available tracks and status of a tile.
Definition: tile_cmd.h:164
ClearBridgeMiddle
void ClearBridgeMiddle(Tile t)
Removes bridges from the given, that is bridges along the X and Y axis.
Definition: bridge_map.h:103
CeilDiv
constexpr uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
Definition: math_func.hpp:320
DC_NO_WATER
@ DC_NO_WATER
don't allow building on water
Definition: command_type.h:374
SLOPE_ENW
@ SLOPE_ENW
east, north and west corner are raised
Definition: slope_type.h:65
TileInfo::y
int y
Y position of the tile in unit coordinates.
Definition: tile_cmd.h:45
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
SLOPE_S
@ SLOPE_S
the south corner of the tile is raised
Definition: slope_type.h:51
GetFoundationPixelSlope
Slope GetFoundationPixelSlope(TileIndex tile, int *z)
Get slope of a tile on top of a (possible) foundation If a tile does not have a foundation,...
Definition: landscape.h:66
DIAGDIR_NW
@ DIAGDIR_NW
Northwest.
Definition: direction_type.h:78
DIAGDIRDIFF_SAME
@ DIAGDIRDIFF_SAME
Same directions.
Definition: direction_type.h:97
GetHalftileSlopeCorner
static constexpr Corner GetHalftileSlopeCorner(Slope s)
Returns the leveled halftile of a halftile slope.
Definition: slope_func.h:148
IsWaterTile
bool IsWaterTile(Tile t)
Is it a water tile with plain water?
Definition: water_map.h:193
EV_EXPLOSION_SMALL
@ EV_EXPLOSION_SMALL
Various explosions.
Definition: effectvehicle_func.h:24
MAX_TILE_HEIGHT
static const uint MAX_TILE_HEIGHT
Maximum allowed tile height.
Definition: tile_type.h:24
clear_map.h
AyStar::Main
int Main()
This is the function you call to run AyStar.
Definition: aystar.cpp:245
fios.h
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:328
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
EV_EXPLOSION_LARGE
@ EV_EXPLOSION_LARGE
Various explosions.
Definition: effectvehicle_func.h:22
DC_EXEC
@ DC_EXEC
execute the given command
Definition: command_type.h:371
GetSlopePixelZ
int GetSlopePixelZ(int x, int y, bool ground_vehicle)
Return world Z coordinate of a given point of a tile.
Definition: landscape.cpp:299
TileDesc
Tile description for the 'land area information' tool.
Definition: tile_cmd.h:52
SLOPE_E
@ SLOPE_E
the east corner of the tile is raised
Definition: slope_type.h:52
DoCommandFlag
DoCommandFlag
List of flags for a command.
Definition: command_type.h:369
genworld.h
Foundation
Foundation
Enumeration for Foundations.
Definition: slope_type.h:93
IncreaseGeneratingWorldProgress
void IncreaseGeneratingWorldProgress(GenWorldProgress cls)
Increases the current stage of the world generation with one.
Definition: genworld_gui.cpp:1550
PFE_GL_LANDSCAPE
@ PFE_GL_LANDSCAPE
Time spent processing other world features.
Definition: framerate_type.h:55
object_base.h
RandomRange
static uint32_t RandomRange(uint32_t limit)
Pick a random number between 0 and limit - 1, inclusive.
Definition: random_func.hpp:81
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition: settings_type.h:619
GetTileTrackStatus
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
Definition: landscape.cpp:556
effectvehicle_func.h
GenerateLandscape
bool GenerateLandscape(byte mode)
Definition: landscape.cpp:1560
SlopeWithThreeCornersRaised
Slope SlopeWithThreeCornersRaised(Corner corner)
Returns the slope with all except one corner raised.
Definition: slope_func.h:206
ComplementSlope
Slope ComplementSlope(Slope s)
Return the complement of a slope.
Definition: slope_func.h:76
PM_UNPAUSED
@ PM_UNPAUSED
A normal unpaused game.
Definition: openttd.h:63
TileInfo::tileh
Slope tileh
Slope of the tile.
Definition: tile_cmd.h:46
GetTileType
static debug_inline TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
Definition: tile_map.h:96
MakeClear
void MakeClear(Tile t, ClearGround g, uint density)
Make a clear tile.
Definition: clear_map.h:259
GWP_LANDSCAPE
@ GWP_LANDSCAPE
Create the landscape.
Definition: genworld.h:71
AyStar::Init
void Init(Hash_HashProc hash, uint num_buckets)
Initialize an AyStar.
Definition: aystar.cpp:293
ChangeTileOwner
void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner)
Change the owner of a tile.
Definition: landscape.cpp:567
OnTick_Companies
void OnTick_Companies()
Called every tick for updating some company info.
Definition: company_cmd.cpp:748
Slope
Slope
Enumeration for the slope-type.
Definition: slope_type.h:48
DistanceManhattan
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
Definition: map.cpp:159
DIAGDIR_SW
@ DIAGDIR_SW
Southwest.
Definition: direction_type.h:77
IsInsideBS
constexpr bool IsInsideBS(const T x, const size_t base, const size_t size)
Checks if a value is between a window started at some base point.
Definition: math_func.hpp:252
heightmap.h
landscape_cmd.h
error_func.h
FOUNDATION_INCLINED_Y
@ FOUNDATION_INCLINED_Y
The tile has an along Y-axis inclined foundation.
Definition: slope_type.h:97
return_cmd_error
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
Definition: command_func.h:38
OnTick_Town
void OnTick_Town()
Iterate through all towns and call their tick handler.
Definition: town_cmd.cpp:887
GetAvailableMoneyForCommand
Money GetAvailableMoneyForCommand()
This functions returns the money which can be used to execute a command.
Definition: company_cmd.cpp:227
EXPENSES_CONSTRUCTION
@ EXPENSES_CONSTRUCTION
Construction costs.
Definition: economy_type.h:173
_tile_type_town_procs
const TileTypeProcs _tile_type_town_procs
Tile callback functions for a town.
Definition: landscape.cpp:50
TileAddWrap
TileIndex TileAddWrap(TileIndex tile, int addx, int addy)
This function checks if we add addx/addy to tile, if we do wrap around the edges.
Definition: map.cpp:116
CommandCost
Common return value for all commands.
Definition: command_type.h:23
GetSnowLine
byte GetSnowLine()
Get the current snow line, either variable or static.
Definition: landscape.cpp:611
GWM_HEIGHTMAP
@ GWM_HEIGHTMAP
Generate a newgame from a heightmap.
Definition: genworld.h:31
DIAGDIRDIFF_BEGIN
@ DIAGDIRDIFF_BEGIN
Used for iterations.
Definition: direction_type.h:96
River_Hash
static uint River_Hash(TileIndex tile, Trackdir)
Simple hash function for river tiles to be used by AyStar.
Definition: landscape.cpp:1289
CircularTileSearch
bool CircularTileSearch(TileIndex *tile, uint size, TestTileOnSearchProc proc, void *user_data)
Function performing a search around a center tile and going outward, thus in circle.
Definition: map.cpp:260
AyStar::Free
void Free()
This function frees the memory it allocated.
Definition: aystar.cpp:206
FOUNDATION_STEEP_BOTH
@ FOUNDATION_STEEP_BOTH
The tile has a steep slope. The lowest corner is raised by a foundation and the upper halftile is lev...
Definition: slope_type.h:101
ChangeDiagDir
DiagDirection ChangeDiagDir(DiagDirection d, DiagDirDiff delta)
Applies a difference on a DiagDirection.
Definition: direction_func.h:149
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_WSE
@ SLOPE_WSE
west, south and east corner are raised
Definition: slope_type.h:63
SLOPE_NE
@ SLOPE_NE
north and east corner are raised
Definition: slope_type.h:58
DifficultySettings::terrain_type
byte terrain_type
the mountainousness of the landscape
Definition: settings_type.h:111
PathNode
A path of nodes.
Definition: aystar.h:45
free
void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: stdafx.h:379
ConstructionSettings::map_height_limit
uint8_t map_height_limit
the maximum allowed heightlevel
Definition: settings_type.h:370
TransportType
TransportType
Available types of transport.
Definition: transport_type.h:19
ClearedObjectArea::first_tile
TileIndex first_tile
The first tile being cleared, which then causes the whole object to be cleared.
Definition: object_base.h:85
CalculateCoverageLine
static uint CalculateCoverageLine(uint coverage, uint edge_multiplier)
Calculate what height would be needed to cover N% of the landmass.
Definition: landscape.cpp:1468
_slope_to_sprite_offset
const byte _slope_to_sprite_offset[32]
landscape slope => sprite
MP_WATER
@ MP_WATER
Water tile.
Definition: tile_type.h:54
ReverseDiagDir
DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
Definition: direction_func.h:118
FOUNDATION_INCLINED_X
@ FOUNDATION_INCLINED_X
The tile has an along X-axis inclined foundation.
Definition: slope_type.h:96
MakeVoid
void MakeVoid(Tile t)
Make a nice void tile ;)
Definition: void_map.h:19
CommandCost::Failed
bool Failed() const
Did this command fail?
Definition: command_type.h:171
Sprite::width
uint16_t width
Width of the sprite.
Definition: spritecache.h:19
Corner
Corner
Enumeration of tile corners.
Definition: slope_type.h:22
IsNonContinuousFoundation
bool IsNonContinuousFoundation(Foundation f)
Tests if a foundation is a non-continuous foundation, i.e.
Definition: slope_func.h:320
station_func.h
WATER_CLASS_CANAL
@ WATER_CLASS_CANAL
Canal.
Definition: water_map.h:49
_pause_mode
PauseMode _pause_mode
The current pause mode.
Definition: gfx.cpp:50
CLEAR_DESERT
@ CLEAR_DESERT
1,3
Definition: clear_map.h:25
water_regions.h
TileDiffXY
TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
Definition: map_func.h:401
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:55
IsTileOnWater
bool IsTileOnWater(Tile t)
Tests if the tile was built on water.
Definition: water_map.h:139
timer_game_tick.h
DIAGDIRDIFF_90RIGHT
@ DIAGDIRDIFF_90RIGHT
90 degrees right
Definition: direction_type.h:98
FlowRiver
static std::tuple< bool, bool > FlowRiver(TileIndex spring, TileIndex begin, uint min_river_length)
Try to flow the river down from a given begin.
Definition: landscape.cpp:1331
TimerGameCalendar::ConvertDateToYMD
static YearMonthDay ConvertDateToYMD(Date date)
Converts a Date to a Year, Month & Day.
Definition: timer_game_calendar.cpp:42
GameCreationSettings::snow_line_height
byte snow_line_height
the configured snow line height (deduced from "snow_coverage")
Definition: settings_type.h:347
safeguards.h
HighestSnowLine
byte HighestSnowLine()
Get the highest possible snow line height, either variable or static.
Definition: landscape.cpp:624
ConstructionSettings::freeform_edges
bool freeform_edges
allow terraforming the tiles at the map edges
Definition: settings_type.h:383
CommandCost::GetCost
Money GetCost() const
The costs as made up to this moment.
Definition: command_type.h:83
GetTileSlope
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
Definition: tile_map.cpp:59
TileTypeProcs::get_tile_desc_proc
GetTileDescProc * get_tile_desc_proc
Get a description of a tile (for the 'land area information' tool)
Definition: tile_cmd.h:163
DifficultySettings::quantity_sea_lakes
byte quantity_sea_lakes
the amount of seas/lakes
Definition: settings_type.h:112
RandomTile
#define RandomTile()
Get a valid random tile.
Definition: map_func.h:657
LowestSnowLine
byte LowestSnowLine()
Get the lowest possible snow line height, either variable or static.
Definition: landscape.cpp:634
INVALID_TRACKDIR
@ INVALID_TRACKDIR
Flag for an invalid trackdir.
Definition: track_type.h:86
sprites.h
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
AyStarNode
Node in the search.
Definition: aystar.h:38
_snow_line
static SnowLine * _snow_line
Description of the snow line throughout the year.
Definition: landscape.cpp:92
GetHalftileFoundationCorner
Corner GetHalftileFoundationCorner(Foundation f)
Returns the halftile corner of a halftile-foundation.
Definition: slope_func.h:333
SLOPE_NS
@ SLOPE_NS
north and south corner are raised
Definition: slope_type.h:60
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition: direction_type.h:73
GetFoundationSlope
Slope GetFoundationSlope(TileIndex tile, int *z)
Get slope of a tile on top of a (possible) foundation If a tile does not have a foundation,...
Definition: landscape.cpp:379
OffsetGroundSprite
void OffsetGroundSprite(int x, int y)
Called when a foundation has been drawn for the current tile.
Definition: viewport.cpp:601
SnowLine
Structure describing the height of the snow line each day of the year.
Definition: landscape.h:23
GetSlopePixelZOnEdge
void GetSlopePixelZOnEdge(Slope tileh, DiagDirection edge, int *z1, int *z2)
Determine the Z height of the corners of a specific tile edge.
Definition: landscape.cpp:350
CommandCost::AddCost
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
Definition: command_type.h:63
stdafx.h
SLOPE_NWS
@ SLOPE_NWS
north, west and south corner are raised
Definition: slope_type.h:62
SpriteType::MapGen
@ MapGen
Special sprite for the map generator.
landscape.h
TileTypeProcs
Set of callback functions for performing tile operations of a given tile type.
Definition: tile_cmd.h:158
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
DC_BANKRUPT
@ DC_BANKRUPT
company bankrupts, skip money check, skip vehicle on tile check in some cases
Definition: command_type.h:377
viewport_func.h
OpenListNode
Internal node.
Definition: aystar.h:55
InverseRemapCoords2
Point InverseRemapCoords2(int x, int y, bool clamp_to_map, bool *clamped)
Map 2D viewport or smallmap coordinate to 3D world or tile coordinate.
Definition: landscape.cpp:107
animated_tile_func.h
HasTileWaterClass
bool HasTileWaterClass(Tile t)
Checks whether the tile has an waterclass associated.
Definition: water_map.h:104
AddSortableSpriteToDraw
void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, int x, int y, int w, int h, int dz, int z, bool transparent, int bb_offset_x, int bb_offset_y, int bb_offset_z, const SubSprite *sub)
Draw a (transparent) sprite at given coordinates with a given bounding box.
Definition: viewport.cpp:673
SLOPE_W
@ SLOPE_W
the west corner of the tile is raised
Definition: slope_type.h:50
IsValidTile
bool IsValidTile(Tile tile)
Checks if a tile is valid.
Definition: tile_map.h:161
SetSnowLine
void SetSnowLine(byte table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS])
Set a variable snow line, as loaded from a newgrf file.
Definition: landscape.cpp:592
TileOffsByDiagDir
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition: map_func.h:563
FOUNDATION_STEEP_LOWER
@ FOUNDATION_STEEP_LOWER
The tile has a steep slope. The lowest corner is raised by a foundation to allow building railroad on...
Definition: slope_type.h:98
TileIndexDiffC
A pair-construct of a TileIndexDiff.
Definition: map_type.h:31
SLOPE_SEN
@ SLOPE_SEN
south, east and north corner are raised
Definition: slope_type.h:64
DrawFoundation
void DrawFoundation(TileInfo *ti, Foundation f)
Draw foundation f at tile ti.
Definition: landscape.cpp:427
Map::SizeX
static debug_inline uint SizeX()
Get the size of the map along the X.
Definition: map_func.h:270
_generating_world
bool _generating_world
Whether we are generating the map or not.
Definition: genworld.cpp:62
DIAGDIRDIFF_REVERSE
@ DIAGDIRDIFF_REVERSE
Reverse directions.
Definition: direction_type.h:99
PerformanceAccumulator
RAII class for measuring multi-step elements of performance.
Definition: framerate_type.h:114
SnowLine::lowest_value
byte lowest_value
Lowest snow line of the year.
Definition: landscape.h:26
spritecache.h
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:50
SnowLine::highest_value
byte highest_value
Highest snow line of the year.
Definition: landscape.h:25
Map::MaxY
static uint MaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
Definition: map_func.h:306
AYSTAR_FOUND_END_NODE
@ AYSTAR_FOUND_END_NODE
An end node was found.
Definition: aystar.h:27
River_UserData::spring
TileIndex spring
The current spring during river generation.
Definition: landscape.cpp:1209
DC_FORCE_CLEAR_TILE
@ DC_FORCE_CLEAR_TILE
do not only remove the object on the tile, but also clear any water left on it
Definition: command_type.h:382
SLOPE_EW
@ SLOPE_EW
east and west corner are raised
Definition: slope_type.h:59
FindClearedObject
ClearedObjectArea * FindClearedObject(TileIndex tile)
Find the entry in _cleared_object_areas which occupies a certain tile.
Definition: object_cmd.cpp:531
AyStar
AyStar search algorithm struct.
Definition: aystar.h:116
MP_VOID
@ MP_VOID
Invisible tiles at the SW and SE border.
Definition: tile_type.h:55
MAX_MAP_SIZE_BITS
static const uint MAX_MAP_SIZE_BITS
Maximal size of map is equal to 2 ^ MAX_MAP_SIZE_BITS.
Definition: map_type.h:38
FlowsDown
static bool FlowsDown(TileIndex begin, TileIndex end)
Check whether a river at begin could (logically) flow down to end.
Definition: landscape.cpp:1191
DeleteAnimatedTile
void DeleteAnimatedTile(TileIndex tile)
Removes the given tile from the animated tile table.
Definition: animated_tile.cpp:25
IsDockingTile
bool IsDockingTile(Tile t)
Checks whether the tile is marked as a dockling tile.
Definition: water_map.h:374
GameCreationSettings::desert_coverage
byte desert_coverage
the amount of desert coverage on the map
Definition: settings_type.h:349
SLOPE_N
@ SLOPE_N
the north corner of the tile is raised
Definition: slope_type.h:53
IsSlopeWithThreeCornersRaised
bool IsSlopeWithThreeCornersRaised(Slope s)
Tests if a specific slope has exactly three corners raised.
Definition: slope_func.h:195
DIAGDIRDIFF_END
@ DIAGDIRDIFF_END
Used for iterations.
Definition: direction_type.h:101
GameCreationSettings::amount_of_rivers
byte amount_of_rivers
the amount of rivers
Definition: settings_type.h:365
abs
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
Definition: math_func.hpp:23
GameCreationSettings::land_generator
byte land_generator
the landscape generator
Definition: settings_type.h:345
GetHighestSlopeCorner
Corner GetHighestSlopeCorner(Slope s)
Returns the highest corner of a slope (one corner raised or a steep slope).
Definition: slope_func.h:126
River_UserData
Parameters for river generation to pass as AyStar user data.
Definition: landscape.cpp:1208
Map::Size
static debug_inline uint Size()
Get the size of the map.
Definition: map_func.h:288
SetGeneratingWorldProgress
void SetGeneratingWorldProgress(GenWorldProgress cls, uint total)
Set the total of a stage of the world generation.
Definition: genworld_gui.cpp:1536
endof
#define endof(x)
Get the end element of an fixed size array.
Definition: stdafx.h:308
framerate_type.h
_file_to_saveload
FileToSaveLoad _file_to_saveload
File to save or load in the openttd loop.
Definition: saveload.cpp:60
SLOPE_SW
@ SLOPE_SW
south and west corner are raised
Definition: slope_type.h:56
PathNode::parent
PathNode * parent
The parent of this item.
Definition: aystar.h:47
IsLeveledFoundation
bool IsLeveledFoundation(Foundation f)
Tests if the foundation is a leveled foundation.
Definition: slope_func.h:298
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:2051
LG_TERRAGENESIS
@ LG_TERRAGENESIS
TerraGenesis Perlin landscape generator.
Definition: genworld.h:21
IsSnowLineSet
bool IsSnowLineSet()
Has a snow line table already been loaded.
Definition: landscape.cpp:582
GetRailFoundationCorner
Corner GetRailFoundationCorner(Foundation f)
Returns the track corner of a special rail foundation.
Definition: slope_func.h:356
InvalidateWaterRegion
void InvalidateWaterRegion(TileIndex tile)
Marks the water region that tile is part of as invalid.
Definition: water_regions.cpp:300
DIAGDIR_BEGIN
@ DIAGDIR_BEGIN
Used for iterations.
Definition: direction_type.h:74
IsInclinedFoundation
bool IsInclinedFoundation(Foundation f)
Tests if the foundation is an inclined foundation.
Definition: slope_func.h:309
DC_AUTO
@ DC_AUTO
don't allow building on structures
Definition: command_type.h:372
CreateEffectVehicleAbove
EffectVehicle * CreateEffectVehicleAbove(int x, int y, int z, EffectVehicleType type)
Create an effect vehicle above a particular location.
Definition: effectvehicle.cpp:622
company_func.h
IsSpecialRailFoundation
bool IsSpecialRailFoundation(Foundation f)
Tests if a foundation is a special rail foundation for single horizontal/vertical track.
Definition: slope_func.h:345
genland.h
CmdLandscapeClear
CommandCost CmdLandscapeClear(DoCommandFlag flags, TileIndex tile)
Clear a piece of landscape.
Definition: landscape.cpp:655
TILE_ADDXY
#define TILE_ADDXY(tile, x, y)
Adds a given offset to a tile.
Definition: map_func.h:480
SteepSlope
Slope SteepSlope(Corner corner)
Returns a specific steep slope.
Definition: slope_func.h:217
CommandHelper
Definition: command_func.h:93
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:300
CmdClearArea
std::tuple< CommandCost, Money > CmdClearArea(DoCommandFlag flags, TileIndex tile, TileIndex start_tile, bool diagonal)
Clear a big piece of landscape.
Definition: landscape.cpp:703
Map::LogY
static uint LogY()
Logarithm of the map size along the y side.
Definition: map_func.h:261
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1552
TileXY
static debug_inline TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition: map_func.h:385
random_func.hpp
TileHeight
static debug_inline uint TileHeight(Tile tile)
Returns the height of a tile.
Definition: tile_map.h:29
GetSlopePixelZOutsideMap
int GetSlopePixelZOutsideMap(int x, int y)
Return world z coordinate of a given point of a tile, also for tiles outside the map (virtual "black"...
Definition: landscape.cpp:314
TILE_HEIGHT
static const uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in #ZOOM_LVL_BASE.
Definition: tile_type.h:18
OverflowSafeInt< int64_t >
MakeLake
static bool MakeLake(TileIndex tile, void *user_data)
Make a connected lake; fill all tiles in the circular tile search that are connected.
Definition: landscape.cpp:1021
GWP_RIVER
@ GWP_RIVER
Create the rivers.
Definition: genworld.h:72
MakeRiverAndModifyDesertZoneAround
void MakeRiverAndModifyDesertZoneAround(TileIndex tile)
Make a river tile and remove desert directly around it.
Definition: water_cmd.cpp:440
GameCreationSettings::snow_coverage
byte snow_coverage
the amount of snow coverage on the map
Definition: settings_type.h:348
GameCreationSettings::river_route_random
byte river_route_random
the amount of randomicity for the route finding
Definition: settings_type.h:364
TileVirtXY
static debug_inline TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
Definition: map_func.h:416
TileInfo::x
int x
X position of the tile in unit coordinates.
Definition: tile_cmd.h:44
TimerGameCalendar::date
static Date date
Current date in days (day counter).
Definition: timer_game_calendar.h:34
TileInfo::tile
TileIndex tile
Tile index.
Definition: tile_cmd.h:47
GameSettings::construction
ConstructionSettings construction
construction of things in-game
Definition: settings_type.h:620
Trackdir
Trackdir
Enumeration for tracks and directions.
Definition: track_type.h:67
SLOPE_STEEP_W
@ SLOPE_STEEP_W
a steep slope falling to east (from west)
Definition: slope_type.h:66
ClearSnowLine
void ClearSnowLine()
Clear the variable snow line table and free the memory.
Definition: landscape.cpp:643
SlopeWithOneCornerRaised
Slope SlopeWithOneCornerRaised(Corner corner)
Returns the slope with a specific corner raised.
Definition: slope_func.h:99
TILE_PIXELS
static const uint TILE_PIXELS
Pixel distance between tile columns/rows in #ZOOM_LVL_BASE.
Definition: tile_type.h:17
IsTileType
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
FileToSaveLoad::detail_ftype
DetailedFileType detail_ftype
Concrete file type (PNG, BMP, old save, etc).
Definition: saveload.h:392
TROPICZONE_NORMAL
@ TROPICZONE_NORMAL
Normal tropiczone.
Definition: tile_type.h:77
Clamp
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:79
TileX
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:427
River_UserData::main_river
bool main_river
Whether the current river is a big river that others flow into.
Definition: landscape.cpp:1210
SLOPE_FLAT
@ SLOPE_FLAT
a flat tile
Definition: slope_type.h:49
InverseRemapCoords
Point InverseRemapCoords(int x, int y)
Map 2D viewport or smallmap coordinate to 3D world or tile coordinate.
Definition: landscape.h:112
ApplyFoundationToSlope
uint ApplyFoundationToSlope(Foundation f, Slope *s)
Applies a foundation to a slope.
Definition: landscape.cpp:166
CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY
static const uint CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY
Value for custom sea level in difficulty settings.
Definition: genworld.h:47
_tile_type_road_procs
const TileTypeProcs _tile_type_road_procs
Tile callback functions for road tiles.
Definition: landscape.cpp:49
RiverMakeWider
static bool RiverMakeWider(TileIndex tile, void *data)
Widen a river by expanding into adjacent tiles via circular tile search.
Definition: landscape.cpp:1044
DIAGDIR_NE
@ DIAGDIR_NE
Northeast, upper right on your monitor.
Definition: direction_type.h:75
ClearedObjectArea
Keeps track of removed objects during execution/testruns of commands.
Definition: object_base.h:84
AyStar::AddStartNode
void AddStartNode(AyStarNode *start_node, uint g)
Adds a node from where to start an algorithm.
Definition: aystar.cpp:280
Company
Definition: company_base.h:116
IsSlopeWithOneCornerRaised
bool IsSlopeWithOneCornerRaised(Slope s)
Tests if a specific slope has exactly one corner raised.
Definition: slope_func.h:88
aystar.h
OnTick_LinkGraph
void OnTick_LinkGraph()
Spawn or join a link graph job or compress a link graph if any link graph is due to do so.
Definition: linkgraphschedule.cpp:205
Sprite
Data structure describing a sprite.
Definition: spritecache.h:17
GetTropicZone
TropicZone GetTropicZone(Tile tile)
Get the tropic zone.
Definition: tile_map.h:238
IsRiver
bool IsRiver(Tile t)
Is it a river water tile?
Definition: water_map.h:183
TileAddByDiagDir
TileIndex TileAddByDiagDir(TileIndex tile, DiagDirection dir)
Adds a DiagDir to a tile.
Definition: map_func.h:604
GetInclinedSlopeDirection
DiagDirection GetInclinedSlopeDirection(Slope s)
Returns the direction of an inclined slope.
Definition: slope_func.h:239
SetTropicZone
void SetTropicZone(Tile tile, TropicZone type)
Set the tropic zone.
Definition: tile_map.h:225
ApplyPixelFoundationToSlope
uint ApplyPixelFoundationToSlope(Foundation f, Slope *s)
Applies a foundation to a slope.
Definition: landscape.h:129
SLOPE_STEEP
@ SLOPE_STEEP
indicates the slope is steep
Definition: slope_type.h:54
LoadHeightmap
bool LoadHeightmap(DetailedFileType dft, const char *filename)
Load a heightmap from file and change the map in its current dimensions to a landscape representing t...
Definition: heightmap.cpp:523
SLOPE_STEEP_N
@ SLOPE_STEEP_N
a steep slope falling to south (from north)
Definition: slope_type.h:69
Map::SizeY
static uint SizeY()
Get the size of the map along the Y.
Definition: map_func.h:279
RIVER_HASH_SIZE
static const uint RIVER_HASH_SIZE
The number of bits the hash for river finding should have.
Definition: landscape.cpp:1282
OppositeCorner
Corner OppositeCorner(Corner corner)
Returns the opposite corner.
Definition: slope_func.h:184
RunTileLoop
void RunTileLoop()
Gradually iterate over all tiles on the map, calling their TileLoopProcs once every 256 ticks.
Definition: landscape.cpp:759
SNOW_LINE_MONTHS
static const uint SNOW_LINE_MONTHS
Number of months in the snow line table.
Definition: landscape.h:16