OpenTTD Source  13.2.1
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 "date_func.h"
24 #include "water.h"
25 #include "effectvehicle_func.h"
26 #include "landscape_type.h"
27 #include "animated_tile_func.h"
28 #include "core/random_func.hpp"
29 #include "object_base.h"
30 #include "company_func.h"
31 #include "pathfinder/npf/aystar.h"
32 #include "saveload/saveload.h"
33 #include "framerate_type.h"
34 #include "landscape_cmd.h"
35 #include "terraform_cmd.h"
36 #include "station_func.h"
37 #include <array>
38 #include <list>
39 #include <set>
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,
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,
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 = MapMaxX() * TILE_SIZE - 1;
117  const uint max_y = MapMaxY() * 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. */
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 
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 
178  return 0;
179  }
180 
181  if (IsSpecialRailFoundation(f)) {
183  return 0;
184  }
185 
186  uint dz = IsSteepSlope(*s) ? 1 : 0;
187  Corner highest_corner = GetHighestSlopeCorner(*s);
188 
189  switch (f) {
191  *s = (((highest_corner == CORNER_W) || (highest_corner == CORNER_S)) ? SLOPE_SW : SLOPE_NE);
192  break;
193 
195  *s = (((highest_corner == CORNER_S) || (highest_corner == CORNER_E)) ? SLOPE_SE : SLOPE_NW);
196  break;
197 
199  *s = SlopeWithOneCornerRaised(highest_corner);
200  break;
201 
203  *s = HalftileSlope(SlopeWithOneCornerRaised(highest_corner), highest_corner);
204  break;
205 
206  default: NOT_REACHED();
207  }
208  return dz;
209 }
210 
211 
219 uint GetPartialPixelZ(int x, int y, Slope corners)
220 {
221  if (IsHalftileSlope(corners)) {
222  switch (GetHalftileSlopeCorner(corners)) {
223  case CORNER_W:
224  if (x - y >= 0) return GetSlopeMaxPixelZ(corners);
225  break;
226 
227  case CORNER_S:
228  if (x - (y ^ 0xF) >= 0) return GetSlopeMaxPixelZ(corners);
229  break;
230 
231  case CORNER_E:
232  if (y - x >= 0) return GetSlopeMaxPixelZ(corners);
233  break;
234 
235  case CORNER_N:
236  if ((y ^ 0xF) - x >= 0) return GetSlopeMaxPixelZ(corners);
237  break;
238 
239  default: NOT_REACHED();
240  }
241  }
242 
243  int z = 0;
244 
245  switch (RemoveHalftileSlope(corners)) {
246  case SLOPE_W:
247  if (x - y >= 0) {
248  z = (x - y) >> 1;
249  }
250  break;
251 
252  case SLOPE_S:
253  y ^= 0xF;
254  if ((x - y) >= 0) {
255  z = (x - y) >> 1;
256  }
257  break;
258 
259  case SLOPE_SW:
260  z = (x >> 1) + 1;
261  break;
262 
263  case SLOPE_E:
264  if (y - x >= 0) {
265  z = (y - x) >> 1;
266  }
267  break;
268 
269  case SLOPE_EW:
270  case SLOPE_NS:
271  case SLOPE_ELEVATED:
272  z = 4;
273  break;
274 
275  case SLOPE_SE:
276  z = (y >> 1) + 1;
277  break;
278 
279  case SLOPE_WSE:
280  z = 8;
281  y ^= 0xF;
282  if (x - y < 0) {
283  z += (x - y) >> 1;
284  }
285  break;
286 
287  case SLOPE_N:
288  y ^= 0xF;
289  if (y - x >= 0) {
290  z = (y - x) >> 1;
291  }
292  break;
293 
294  case SLOPE_NW:
295  z = (y ^ 0xF) >> 1;
296  break;
297 
298  case SLOPE_NWS:
299  z = 8;
300  if (x - y < 0) {
301  z += (x - y) >> 1;
302  }
303  break;
304 
305  case SLOPE_NE:
306  z = (x ^ 0xF) >> 1;
307  break;
308 
309  case SLOPE_ENW:
310  z = 8;
311  y ^= 0xF;
312  if (y - x < 0) {
313  z += (y - x) >> 1;
314  }
315  break;
316 
317  case SLOPE_SEN:
318  z = 8;
319  if (y - x < 0) {
320  z += (y - x) >> 1;
321  }
322  break;
323 
324  case SLOPE_STEEP_S:
325  z = 1 + ((x + y) >> 1);
326  break;
327 
328  case SLOPE_STEEP_W:
329  z = 1 + ((x + (y ^ 0xF)) >> 1);
330  break;
331 
332  case SLOPE_STEEP_N:
333  z = 1 + (((x ^ 0xF) + (y ^ 0xF)) >> 1);
334  break;
335 
336  case SLOPE_STEEP_E:
337  z = 1 + (((x ^ 0xF) + y) >> 1);
338  break;
339 
340  default: break;
341  }
342 
343  return z;
344 }
345 
346 int GetSlopePixelZ(int x, int y)
347 {
348  TileIndex tile = TileVirtXY(x, y);
349 
350  return _tile_type_procs[GetTileType(tile)]->get_slope_z_proc(tile, x, y);
351 }
352 
361 int GetSlopePixelZOutsideMap(int x, int y)
362 {
363  if (IsInsideBS(x, 0, MapSizeX() * TILE_SIZE) && IsInsideBS(y, 0, MapSizeY() * TILE_SIZE)) {
364  return GetSlopePixelZ(x, y);
365  } else {
366  return _tile_type_procs[MP_VOID]->get_slope_z_proc(INVALID_TILE, x, y);
367  }
368 }
369 
379 int GetSlopeZInCorner(Slope tileh, Corner corner)
380 {
381  assert(!IsHalftileSlope(tileh));
382  return ((tileh & SlopeWithOneCornerRaised(corner)) != 0 ? 1 : 0) + (tileh == SteepSlope(corner) ? 1 : 0);
383 }
384 
397 void GetSlopePixelZOnEdge(Slope tileh, DiagDirection edge, int *z1, int *z2)
398 {
399  static const Slope corners[4][4] = {
400  /* corner | steep slope
401  * z1 z2 | z1 z2 */
402  {SLOPE_E, SLOPE_N, SLOPE_STEEP_E, SLOPE_STEEP_N}, // DIAGDIR_NE, z1 = E, z2 = N
403  {SLOPE_S, SLOPE_E, SLOPE_STEEP_S, SLOPE_STEEP_E}, // DIAGDIR_SE, z1 = S, z2 = E
404  {SLOPE_S, SLOPE_W, SLOPE_STEEP_S, SLOPE_STEEP_W}, // DIAGDIR_SW, z1 = S, z2 = W
405  {SLOPE_W, SLOPE_N, SLOPE_STEEP_W, SLOPE_STEEP_N}, // DIAGDIR_NW, z1 = W, z2 = N
406  };
407 
408  int halftile_test = (IsHalftileSlope(tileh) ? SlopeWithOneCornerRaised(GetHalftileSlopeCorner(tileh)) : 0);
409  if (halftile_test == corners[edge][0]) *z2 += TILE_HEIGHT; // The slope is non-continuous in z2. z2 is on the upper side.
410  if (halftile_test == corners[edge][1]) *z1 += TILE_HEIGHT; // The slope is non-continuous in z1. z1 is on the upper side.
411 
412  if ((tileh & corners[edge][0]) != 0) *z1 += TILE_HEIGHT; // z1 is raised
413  if ((tileh & corners[edge][1]) != 0) *z2 += TILE_HEIGHT; // z2 is raised
414  if (RemoveHalftileSlope(tileh) == corners[edge][2]) *z1 += TILE_HEIGHT; // z1 is highest corner of a steep slope
415  if (RemoveHalftileSlope(tileh) == corners[edge][3]) *z2 += TILE_HEIGHT; // z2 is highest corner of a steep slope
416 }
417 
427 {
428  Slope tileh = GetTileSlope(tile, z);
429  Foundation f = _tile_type_procs[GetTileType(tile)]->get_foundation_proc(tile, tileh);
430  uint z_inc = ApplyFoundationToSlope(f, &tileh);
431  if (z != nullptr) *z += z_inc;
432  return tileh;
433 }
434 
435 
436 bool HasFoundationNW(TileIndex tile, Slope slope_here, uint z_here)
437 {
438  int z;
439 
440  int z_W_here = z_here;
441  int z_N_here = z_here;
442  GetSlopePixelZOnEdge(slope_here, DIAGDIR_NW, &z_W_here, &z_N_here);
443 
444  Slope slope = GetFoundationPixelSlope(TILE_ADDXY(tile, 0, -1), &z);
445  int z_W = z;
446  int z_N = z;
447  GetSlopePixelZOnEdge(slope, DIAGDIR_SE, &z_W, &z_N);
448 
449  return (z_N_here > z_N) || (z_W_here > z_W);
450 }
451 
452 
453 bool HasFoundationNE(TileIndex tile, Slope slope_here, uint z_here)
454 {
455  int z;
456 
457  int z_E_here = z_here;
458  int z_N_here = z_here;
459  GetSlopePixelZOnEdge(slope_here, DIAGDIR_NE, &z_E_here, &z_N_here);
460 
461  Slope slope = GetFoundationPixelSlope(TILE_ADDXY(tile, -1, 0), &z);
462  int z_E = z;
463  int z_N = z;
464  GetSlopePixelZOnEdge(slope, DIAGDIR_SW, &z_E, &z_N);
465 
466  return (z_N_here > z_N) || (z_E_here > z_E);
467 }
468 
475 {
476  if (!IsFoundation(f)) return;
477 
478  /* Two part foundations must be drawn separately */
479  assert(f != FOUNDATION_STEEP_BOTH);
480 
481  uint sprite_block = 0;
482  int z;
483  Slope slope = GetFoundationPixelSlope(ti->tile, &z);
484 
485  /* Select the needed block of foundations sprites
486  * Block 0: Walls at NW and NE edge
487  * Block 1: Wall at NE edge
488  * Block 2: Wall at NW edge
489  * Block 3: No walls at NW or NE edge
490  */
491  if (!HasFoundationNW(ti->tile, slope, z)) sprite_block += 1;
492  if (!HasFoundationNE(ti->tile, slope, z)) sprite_block += 2;
493 
494  /* Use the original slope sprites if NW and NE borders should be visible */
495  SpriteID leveled_base = (sprite_block == 0 ? (int)SPR_FOUNDATION_BASE : (SPR_SLOPES_VIRTUAL_BASE + sprite_block * SPR_TRKFOUND_BLOCK_SIZE));
496  SpriteID inclined_base = SPR_SLOPES_VIRTUAL_BASE + SPR_SLOPES_INCLINED_OFFSET + sprite_block * SPR_TRKFOUND_BLOCK_SIZE;
497  SpriteID halftile_base = SPR_HALFTILE_FOUNDATION_BASE + sprite_block * SPR_HALFTILE_BLOCK_SIZE;
498 
499  if (IsSteepSlope(ti->tileh)) {
500  if (!IsNonContinuousFoundation(f)) {
501  /* Lower part of foundation */
503  leveled_base + (ti->tileh & ~SLOPE_STEEP), PAL_NONE, ti->x, ti->y, TILE_SIZE, TILE_SIZE, TILE_HEIGHT - 1, ti->z
504  );
505  }
506 
507  Corner highest_corner = GetHighestSlopeCorner(ti->tileh);
508  ti->z += ApplyPixelFoundationToSlope(f, &ti->tileh);
509 
510  if (IsInclinedFoundation(f)) {
511  /* inclined foundation */
512  byte inclined = highest_corner * 2 + (f == FOUNDATION_INCLINED_Y ? 1 : 0);
513 
514  AddSortableSpriteToDraw(inclined_base + inclined, PAL_NONE, ti->x, ti->y,
515  f == FOUNDATION_INCLINED_X ? TILE_SIZE : 1,
516  f == FOUNDATION_INCLINED_Y ? TILE_SIZE : 1,
517  TILE_HEIGHT, ti->z
518  );
519  OffsetGroundSprite(0, 0);
520  } else if (IsLeveledFoundation(f)) {
521  AddSortableSpriteToDraw(leveled_base + SlopeWithOneCornerRaised(highest_corner), PAL_NONE, ti->x, ti->y, TILE_SIZE, TILE_SIZE, TILE_HEIGHT - 1, ti->z - TILE_HEIGHT);
523  } else if (f == FOUNDATION_STEEP_LOWER) {
524  /* one corner raised */
526  } else {
527  /* halftile foundation */
528  int x_bb = (((highest_corner == CORNER_W) || (highest_corner == CORNER_S)) ? TILE_SIZE / 2 : 0);
529  int y_bb = (((highest_corner == CORNER_S) || (highest_corner == CORNER_E)) ? TILE_SIZE / 2 : 0);
530 
531  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);
532  /* Reposition ground sprite back to original position after bounding box change above. This is similar to
533  * RemapCoords() but without zoom scaling. */
534  Point pt = {(y_bb - x_bb) * 2, y_bb + x_bb};
535  OffsetGroundSprite(-pt.x, -pt.y);
536  }
537  } else {
538  if (IsLeveledFoundation(f)) {
539  /* leveled foundation */
540  AddSortableSpriteToDraw(leveled_base + ti->tileh, PAL_NONE, ti->x, ti->y, TILE_SIZE, TILE_SIZE, TILE_HEIGHT - 1, ti->z);
542  } else if (IsNonContinuousFoundation(f)) {
543  /* halftile foundation */
544  Corner halftile_corner = GetHalftileFoundationCorner(f);
545  int x_bb = (((halftile_corner == CORNER_W) || (halftile_corner == CORNER_S)) ? TILE_SIZE / 2 : 0);
546  int y_bb = (((halftile_corner == CORNER_S) || (halftile_corner == CORNER_E)) ? TILE_SIZE / 2 : 0);
547 
548  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);
549  /* Reposition ground sprite back to original position after bounding box change above. This is similar to
550  * RemapCoords() but without zoom scaling. */
551  Point pt = {(y_bb - x_bb) * 2, y_bb + x_bb};
552  OffsetGroundSprite(-pt.x, -pt.y);
553  } else if (IsSpecialRailFoundation(f)) {
554  /* anti-zig-zag foundation */
555  SpriteID spr;
556  if (ti->tileh == SLOPE_NS || ti->tileh == SLOPE_EW) {
557  /* half of leveled foundation under track corner */
558  spr = leveled_base + SlopeWithThreeCornersRaised(GetRailFoundationCorner(f));
559  } else {
560  /* tile-slope = sloped along X/Y, foundation-slope = three corners raised */
561  spr = inclined_base + 2 * GetRailFoundationCorner(f) + ((ti->tileh == SLOPE_SW || ti->tileh == SLOPE_NE) ? 1 : 0);
562  }
563  AddSortableSpriteToDraw(spr, PAL_NONE, ti->x, ti->y, TILE_SIZE, TILE_SIZE, TILE_HEIGHT - 1, ti->z);
564  OffsetGroundSprite(0, 0);
565  } else {
566  /* inclined foundation */
567  byte inclined = GetHighestSlopeCorner(ti->tileh) * 2 + (f == FOUNDATION_INCLINED_Y ? 1 : 0);
568 
569  AddSortableSpriteToDraw(inclined_base + inclined, PAL_NONE, ti->x, ti->y,
570  f == FOUNDATION_INCLINED_X ? TILE_SIZE : 1,
571  f == FOUNDATION_INCLINED_Y ? TILE_SIZE : 1,
572  TILE_HEIGHT, ti->z
573  );
574  OffsetGroundSprite(0, 0);
575  }
576  ti->z += ApplyPixelFoundationToSlope(f, &ti->tileh);
577  }
578 }
579 
580 void DoClearSquare(TileIndex tile)
581 {
582  /* If the tile can have animation and we clear it, delete it from the animated tile list. */
583  if (_tile_type_procs[GetTileType(tile)]->animate_tile_proc != nullptr) DeleteAnimatedTile(tile);
584 
585  bool remove = IsDockingTile(tile);
586  MakeClear(tile, CLEAR_GRASS, _generating_world ? 3 : 0);
587  MarkTileDirtyByTile(tile);
588  if (remove) RemoveDockingTile(tile);
589 }
590 
601 TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
602 {
603  return _tile_type_procs[GetTileType(tile)]->get_tile_track_status_proc(tile, mode, sub_mode, side);
604 }
605 
612 void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner)
613 {
614  _tile_type_procs[GetTileType(tile)]->change_tile_owner_proc(tile, old_owner, new_owner);
615 }
616 
617 void GetTileDesc(TileIndex tile, TileDesc *td)
618 {
620 }
621 
628 {
629  return _snow_line != nullptr;
630 }
631 
638 {
639  _snow_line = CallocT<SnowLine>(1);
640  _snow_line->lowest_value = 0xFF;
641  memcpy(_snow_line->table, table, sizeof(_snow_line->table));
642 
643  for (uint i = 0; i < SNOW_LINE_MONTHS; i++) {
644  for (uint j = 0; j < SNOW_LINE_DAYS; j++) {
645  _snow_line->highest_value = std::max(_snow_line->highest_value, table[i][j]);
646  _snow_line->lowest_value = std::min(_snow_line->lowest_value, table[i][j]);
647  }
648  }
649 }
650 
657 {
659 
660  YearMonthDay ymd;
661  ConvertDateToYMD(_date, &ymd);
662  return _snow_line->table[ymd.month][ymd.day];
663 }
664 
671 {
673 }
674 
681 {
683 }
684 
690 {
691  free(_snow_line);
692  _snow_line = nullptr;
693 }
694 
702 {
704  bool do_clear = false;
705  /* Test for stuff which results in water when cleared. Then add the cost to also clear the water. */
706  if ((flags & DC_FORCE_CLEAR_TILE) && HasTileWaterClass(tile) && IsTileOnWater(tile) && !IsWaterTile(tile) && !IsCoastTile(tile)) {
707  if ((flags & DC_AUTO) && GetWaterClass(tile) == WATER_CLASS_CANAL) return_cmd_error(STR_ERROR_MUST_DEMOLISH_CANAL_FIRST);
708  do_clear = true;
709  cost.AddCost(GetWaterClass(tile) == WATER_CLASS_CANAL ? _price[PR_CLEAR_CANAL] : _price[PR_CLEAR_WATER]);
710  }
711 
712  Company *c = (flags & (DC_AUTO | DC_BANKRUPT)) ? nullptr : Company::GetIfValid(_current_company);
713  if (c != nullptr && (int)GB(c->clear_limit, 16, 16) < 1) {
714  return_cmd_error(STR_ERROR_CLEARING_LIMIT_REACHED);
715  }
716 
717  const ClearedObjectArea *coa = FindClearedObject(tile);
718 
719  /* If this tile was the first tile which caused object destruction, always
720  * pass it on to the tile_type_proc. That way multiple test runs and the exec run stay consistent. */
721  if (coa != nullptr && coa->first_tile != tile) {
722  /* If this tile belongs to an object which was already cleared via another tile, pretend it has been
723  * already removed.
724  * However, we need to check stuff, which is not the same for all object tiles. (e.g. being on water or not) */
725 
726  /* If a object is removed, it leaves either bare land or water. */
727  if ((flags & DC_NO_WATER) && HasTileWaterClass(tile) && IsTileOnWater(tile)) {
728  return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
729  }
730  } else {
731  cost.AddCost(_tile_type_procs[GetTileType(tile)]->clear_tile_proc(tile, flags));
732  }
733 
734  if (flags & DC_EXEC) {
735  if (c != nullptr) c->clear_limit -= 1 << 16;
736  if (do_clear) DoClearSquare(tile);
737  }
738  return cost;
739 }
740 
749 std::tuple<CommandCost, Money> CmdClearArea(DoCommandFlag flags, TileIndex tile, TileIndex start_tile, bool diagonal)
750 {
751  if (start_tile >= MapSize()) return { CMD_ERROR, 0 };
752 
755  CommandCost last_error = CMD_ERROR;
756  bool had_success = false;
757 
758  const Company *c = (flags & (DC_AUTO | DC_BANKRUPT)) ? nullptr : Company::GetIfValid(_current_company);
759  int limit = (c == nullptr ? INT32_MAX : GB(c->clear_limit, 16, 16));
760 
761  TileIterator *iter = diagonal ? (TileIterator *)new DiagonalTileIterator(tile, start_tile) : new OrthogonalTileIterator(tile, start_tile);
762  for (; *iter != INVALID_TILE; ++(*iter)) {
763  TileIndex t = *iter;
765  if (ret.Failed()) {
766  last_error = ret;
767 
768  /* We may not clear more tiles. */
769  if (c != nullptr && GB(c->clear_limit, 16, 16) < 1) break;
770  continue;
771  }
772 
773  had_success = true;
774  if (flags & DC_EXEC) {
775  money -= ret.GetCost();
776  if (ret.GetCost() > 0 && money < 0) {
777  delete iter;
778  return { cost, ret.GetCost() };
779  }
781 
782  /* draw explosion animation...
783  * Disable explosions when game is paused. Looks silly and blocks the view. */
784  if ((t == tile || t == start_tile) && _pause_mode == PM_UNPAUSED) {
785  /* big explosion in two corners, or small explosion for single tiles */
787  TileX(tile) == TileX(start_tile) && TileY(tile) == TileY(start_tile) ? EV_EXPLOSION_SMALL : EV_EXPLOSION_LARGE
788  );
789  }
790  } else {
791  /* When we're at the clearing limit we better bail (unneed) testing as well. */
792  if (ret.GetCost() != 0 && --limit <= 0) break;
793  }
794  cost.AddCost(ret);
795  }
796 
797  delete iter;
798  return { had_success ? cost : last_error, 0 };
799 }
800 
801 
802 TileIndex _cur_tileloop_tile;
803 
808 {
810 
811  /* The pseudorandom sequence of tiles is generated using a Galois linear feedback
812  * shift register (LFSR). This allows a deterministic pseudorandom ordering, but
813  * still with minimal state and fast iteration. */
814 
815  /* Maximal length LFSR feedback terms, from 12-bit (for 64x64 maps) to 24-bit (for 4096x4096 maps).
816  * Extracted from http://www.ece.cmu.edu/~koopman/lfsr/ */
817  static const uint32 feedbacks[] = {
818  0xD8F, 0x1296, 0x2496, 0x4357, 0x8679, 0x1030E, 0x206CD, 0x403FE, 0x807B8, 0x1004B2, 0x2006A8, 0x4004B2, 0x800B87
819  };
820  static_assert(lengthof(feedbacks) == 2 * MAX_MAP_SIZE_BITS - 2 * MIN_MAP_SIZE_BITS + 1);
821  const uint32 feedback = feedbacks[MapLogX() + MapLogY() - 2 * MIN_MAP_SIZE_BITS];
822 
823  /* We update every tile every 256 ticks, so divide the map size by 2^8 = 256 */
824  uint count = 1 << (MapLogX() + MapLogY() - 8);
825 
826  TileIndex tile = _cur_tileloop_tile;
827  /* The LFSR cannot have a zeroed state. */
828  assert(tile != 0);
829 
830  /* Manually update tile 0 every 256 ticks - the LFSR never iterates over it itself. */
831  if (_tick_counter % 256 == 0) {
832  _tile_type_procs[GetTileType(0)]->tile_loop_proc(0);
833  count--;
834  }
835 
836  while (count--) {
837  _tile_type_procs[GetTileType(tile)]->tile_loop_proc(tile);
838 
839  /* Get the next tile in sequence using a Galois LFSR. */
840  tile = (tile >> 1) ^ (-(int32)(tile & 1) & feedback);
841  }
842 
843  _cur_tileloop_tile = tile;
844 }
845 
846 void InitializeLandscape()
847 {
848  for (uint y = _settings_game.construction.freeform_edges ? 1 : 0; y < MapMaxY(); y++) {
849  for (uint x = _settings_game.construction.freeform_edges ? 1 : 0; x < MapMaxX(); x++) {
850  MakeClear(TileXY(x, y), CLEAR_GRASS, 3);
851  SetTileHeight(TileXY(x, y), 0);
853  ClearBridgeMiddle(TileXY(x, y));
854  }
855  }
856 
857  for (uint x = 0; x < MapSizeX(); x++) MakeVoid(TileXY(x, MapMaxY()));
858  for (uint y = 0; y < MapSizeY(); y++) MakeVoid(TileXY(MapMaxX(), y));
859 }
860 
861 static const byte _genterrain_tbl_1[5] = { 10, 22, 33, 37, 4 };
862 static const byte _genterrain_tbl_2[5] = { 0, 0, 0, 0, 33 };
863 
864 static void GenerateTerrain(int type, uint flag)
865 {
866  uint32 r = Random();
867 
868  const Sprite *templ = GetSprite((((r >> 24) * _genterrain_tbl_1[type]) >> 8) + _genterrain_tbl_2[type] + 4845, ST_MAPGEN);
869  if (templ == nullptr) usererror("Map generator sprites could not be loaded");
870 
871  uint x = r & MapMaxX();
872  uint y = (r >> MapLogX()) & MapMaxY();
873 
874  uint edge_distance = 1 + (_settings_game.construction.freeform_edges ? 1 : 0);
875  if (x <= edge_distance || y <= edge_distance) return;
876 
877  DiagDirection direction = (DiagDirection)GB(r, 22, 2);
878  uint w = templ->width;
879  uint h = templ->height;
880 
881  if (DiagDirToAxis(direction) == AXIS_Y) Swap(w, h);
882 
883  const byte *p = templ->data;
884 
885  if ((flag & 4) != 0) {
886  uint xw = x * MapSizeY();
887  uint yw = y * MapSizeX();
888  uint bias = (MapSizeX() + MapSizeY()) * 16;
889 
890  switch (flag & 3) {
891  default: NOT_REACHED();
892  case 0:
893  if (xw + yw > MapSize() - bias) return;
894  break;
895 
896  case 1:
897  if (yw < xw + bias) return;
898  break;
899 
900  case 2:
901  if (xw + yw < MapSize() + bias) return;
902  break;
903 
904  case 3:
905  if (xw < yw + bias) return;
906  break;
907  }
908  }
909 
910  if (x + w >= MapMaxX()) return;
911  if (y + h >= MapMaxY()) return;
912 
913  TileIndex tile = TileXY(x, y);
914 
915  switch (direction) {
916  default: NOT_REACHED();
917  case DIAGDIR_NE:
918  do {
919  TileIndex tile_cur = tile;
920 
921  for (uint w_cur = w; w_cur != 0; --w_cur) {
922  if (GB(*p, 0, 4) >= TileHeight(tile_cur)) SetTileHeight(tile_cur, GB(*p, 0, 4));
923  p++;
924  tile_cur++;
925  }
926  tile += TileDiffXY(0, 1);
927  } while (--h != 0);
928  break;
929 
930  case DIAGDIR_SE:
931  do {
932  TileIndex tile_cur = tile;
933 
934  for (uint h_cur = h; h_cur != 0; --h_cur) {
935  if (GB(*p, 0, 4) >= TileHeight(tile_cur)) SetTileHeight(tile_cur, GB(*p, 0, 4));
936  p++;
937  tile_cur += TileDiffXY(0, 1);
938  }
939  tile += TileDiffXY(1, 0);
940  } while (--w != 0);
941  break;
942 
943  case DIAGDIR_SW:
944  tile += TileDiffXY(w - 1, 0);
945  do {
946  TileIndex tile_cur = tile;
947 
948  for (uint w_cur = w; w_cur != 0; --w_cur) {
949  if (GB(*p, 0, 4) >= TileHeight(tile_cur)) SetTileHeight(tile_cur, GB(*p, 0, 4));
950  p++;
951  tile_cur--;
952  }
953  tile += TileDiffXY(0, 1);
954  } while (--h != 0);
955  break;
956 
957  case DIAGDIR_NW:
958  tile += TileDiffXY(0, h - 1);
959  do {
960  TileIndex tile_cur = tile;
961 
962  for (uint h_cur = h; h_cur != 0; --h_cur) {
963  if (GB(*p, 0, 4) >= TileHeight(tile_cur)) SetTileHeight(tile_cur, GB(*p, 0, 4));
964  p++;
965  tile_cur -= TileDiffXY(0, 1);
966  }
967  tile += TileDiffXY(1, 0);
968  } while (--w != 0);
969  break;
970  }
971 }
972 
973 
974 #include "table/genland.h"
975 
976 static void CreateDesertOrRainForest(uint desert_tropic_line)
977 {
978  TileIndex update_freq = MapSize() / 4;
979  const TileIndexDiffC *data;
980 
981  for (TileIndex tile = 0; tile != MapSize(); ++tile) {
982  if ((tile % update_freq) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
983 
984  if (!IsValidTile(tile)) continue;
985 
986  for (data = _make_desert_or_rainforest_data;
987  data != endof(_make_desert_or_rainforest_data); ++data) {
988  TileIndex t = AddTileIndexDiffCWrap(tile, *data);
989  if (t != INVALID_TILE && (TileHeight(t) >= desert_tropic_line || IsTileType(t, MP_WATER))) break;
990  }
991  if (data == endof(_make_desert_or_rainforest_data)) {
993  }
994  }
995 
996  for (uint i = 0; i != 256; i++) {
998 
999  RunTileLoop();
1000  }
1001 
1002  for (TileIndex tile = 0; tile != MapSize(); ++tile) {
1003  if ((tile % update_freq) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
1004 
1005  if (!IsValidTile(tile)) continue;
1006 
1007  for (data = _make_desert_or_rainforest_data;
1008  data != endof(_make_desert_or_rainforest_data); ++data) {
1009  TileIndex t = AddTileIndexDiffCWrap(tile, *data);
1010  if (t != INVALID_TILE && IsTileType(t, MP_CLEAR) && IsClearGround(t, CLEAR_DESERT)) break;
1011  }
1012  if (data == endof(_make_desert_or_rainforest_data)) {
1014  }
1015  }
1016 }
1017 
1024 static bool FindSpring(TileIndex tile, void *user_data)
1025 {
1026  int referenceHeight;
1027  if (!IsTileFlat(tile, &referenceHeight) || IsWaterTile(tile)) return false;
1028 
1029  /* In the tropics rivers start in the rainforest. */
1030  if (_settings_game.game_creation.landscape == LT_TROPIC && GetTropicZone(tile) != TROPICZONE_RAINFOREST) return false;
1031 
1032  /* Are there enough higher tiles to warrant a 'spring'? */
1033  uint num = 0;
1034  for (int dx = -1; dx <= 1; dx++) {
1035  for (int dy = -1; dy <= 1; dy++) {
1036  TileIndex t = TileAddWrap(tile, dx, dy);
1037  if (t != INVALID_TILE && GetTileMaxZ(t) > referenceHeight) num++;
1038  }
1039  }
1040 
1041  if (num < 4) return false;
1042 
1043  /* Are we near the top of a hill? */
1044  for (int dx = -16; dx <= 16; dx++) {
1045  for (int dy = -16; dy <= 16; dy++) {
1046  TileIndex t = TileAddWrap(tile, dx, dy);
1047  if (t != INVALID_TILE && GetTileMaxZ(t) > referenceHeight + 2) return false;
1048  }
1049  }
1050 
1051  return true;
1052 }
1053 
1060 static bool MakeLake(TileIndex tile, void *user_data)
1061 {
1062  uint height = *(uint*)user_data;
1063  if (!IsValidTile(tile) || TileHeight(tile) != height || !IsTileFlat(tile)) return false;
1064  if (_settings_game.game_creation.landscape == LT_TROPIC && GetTropicZone(tile) == TROPICZONE_DESERT) return false;
1065 
1066  for (DiagDirection d = DIAGDIR_BEGIN; d < DIAGDIR_END; d++) {
1067  TileIndex t2 = tile + TileOffsByDiagDir(d);
1068  if (IsWaterTile(t2)) {
1069  MakeRiver(tile, Random());
1070  MarkTileDirtyByTile(tile);
1071  /* Remove desert directly around the river tile. */
1072  TileIndex t = tile;
1074  return false;
1075  }
1076  }
1077 
1078  return false;
1079 }
1080 
1087 static bool RiverMakeWider(TileIndex tile, void *data)
1088 {
1089  /* Don't expand into void tiles. */
1090  if (!IsValidTile(tile)) return false;
1091 
1092  /* If the tile is already sea or river, don't expand. */
1093  if (IsWaterTile(tile)) return false;
1094 
1095  /* If the tile is at height 0 after terraforming but the ocean hasn't flooded yet, don't build river. */
1096  if (GetTileMaxZ(tile) == 0) return false;
1097 
1098  TileIndex origin_tile = *(TileIndex *)data;
1099  Slope cur_slope = GetTileSlope(tile);
1100  Slope desired_slope = GetTileSlope(origin_tile); // Initialize matching the origin tile as a shortcut if no terraforming is needed.
1101 
1102  /* Never flow uphill. */
1103  if (GetTileMaxZ(tile) > GetTileMaxZ(origin_tile)) return false;
1104 
1105  /* If the new tile can't hold a river tile, try terraforming. */
1106  if (!IsTileFlat(tile) && !IsInclinedSlope(cur_slope)) {
1107  /* Don't try to terraform steep slopes. */
1108  if (IsSteepSlope(cur_slope)) return false;
1109 
1110  bool flat_river_found = false;
1111  bool sloped_river_found = false;
1112 
1113  /* There are two common possibilities:
1114  * 1. River flat, adjacent tile has one corner lowered.
1115  * 2. River descending, adjacent tile has either one or three corners raised.
1116  */
1117 
1118  /* First, determine the desired slope based on adjacent river tiles. This doesn't necessarily match the origin tile for the CircularTileSearch. */
1119  for (DiagDirection d = DIAGDIR_BEGIN; d < DIAGDIR_END; d++) {
1120  TileIndex other_tile = TileAddByDiagDir(tile, d);
1121  Slope other_slope = GetTileSlope(other_tile);
1122 
1123  /* Only consider river tiles. */
1124  if (IsWaterTile(other_tile) && IsRiver(other_tile)) {
1125  /* If the adjacent river tile flows downhill, we need to check where we are relative to the slope. */
1126  if (IsInclinedSlope(other_slope) && GetTileMaxZ(tile) == GetTileMaxZ(other_tile)) {
1127  /* Check for a parallel slope. If we don't find one, we're above or below the slope instead. */
1130  desired_slope = other_slope;
1131  sloped_river_found = true;
1132  break;
1133  }
1134  }
1135  /* If we find an adjacent river tile, remember it. We'll terraform to match it later if we don't find a slope. */
1136  if (IsTileFlat(other_tile)) flat_river_found = true;
1137  }
1138  }
1139  /* We didn't find either an inclined or flat river, so we're climbing the wrong slope. Bail out. */
1140  if (!sloped_river_found && !flat_river_found) return false;
1141 
1142  /* We didn't find an inclined river, but there is a flat river. */
1143  if (!sloped_river_found && flat_river_found) desired_slope = SLOPE_FLAT;
1144 
1145  /* Now that we know the desired slope, it's time to terraform! */
1146 
1147  /* If the river is flat and the adjacent tile has one corner lowered, we want to raise it. */
1148  if (desired_slope == SLOPE_FLAT && IsSlopeWithThreeCornersRaised(cur_slope)) {
1149  /* Make sure we're not affecting an existing river slope tile. */
1150  for (DiagDirection d = DIAGDIR_BEGIN; d < DIAGDIR_END; d++) {
1151  TileIndex other_tile = TileAddByDiagDir(tile, d);
1152  if (IsInclinedSlope(GetTileSlope(other_tile)) && IsWaterTile(other_tile)) return false;
1153  }
1155 
1156  /* If the river is descending and the adjacent tile has either one or three corners raised, we want to make it match the slope. */
1157  } else if (IsInclinedSlope(desired_slope)) {
1158  /* Don't break existing flat river tiles by terraforming under them. */
1159  DiagDirection river_direction = ReverseDiagDir(GetInclinedSlopeDirection(desired_slope));
1160 
1161  for (DiagDirDiff d = DIAGDIRDIFF_BEGIN; d < DIAGDIRDIFF_END; d++) {
1162  /* We don't care about downstream or upstream tiles, just the riverbanks. */
1163  if (d == DIAGDIRDIFF_SAME || d == DIAGDIRDIFF_REVERSE) continue;
1164 
1165  TileIndex other_tile = (TileAddByDiagDir(tile, ChangeDiagDir(river_direction, d)));
1166  if (IsWaterTile(other_tile) && IsRiver(other_tile) && IsTileFlat(other_tile)) return false;
1167  }
1168 
1169  /* Get the corners which are different between the current and desired slope. */
1170  Slope to_change = cur_slope ^ desired_slope;
1171 
1172  /* Lower unwanted corners first. If only one corner is raised, no corners need lowering. */
1173  if (!IsSlopeWithOneCornerRaised(cur_slope)) {
1174  to_change = to_change & ComplementSlope(desired_slope);
1175  Command<CMD_TERRAFORM_LAND>::Do(DC_EXEC | DC_AUTO, tile, to_change, false);
1176  }
1177 
1178  /* Now check the match and raise any corners needed. */
1179  cur_slope = GetTileSlope(tile);
1180  if (cur_slope != desired_slope && IsSlopeWithOneCornerRaised(cur_slope)) {
1181  to_change = cur_slope ^ desired_slope;
1182  Command<CMD_TERRAFORM_LAND>::Do(DC_EXEC | DC_AUTO, tile, to_change, true);
1183  }
1184  }
1185  /* Update cur_slope after possibly terraforming. */
1186  cur_slope = GetTileSlope(tile);
1187  }
1188 
1189  /* Sloped rivers need water both upstream and downstream. */
1190  if (IsInclinedSlope(cur_slope)) {
1191  DiagDirection slope_direction = GetInclinedSlopeDirection(cur_slope);
1192 
1193  TileIndex upstream_tile = TileAddByDiagDir(tile, slope_direction);
1194  TileIndex downstream_tile = TileAddByDiagDir(tile, ReverseDiagDir(slope_direction));
1195 
1196  /* Don't look outside the map. */
1197  if (!IsValidTile(upstream_tile) || !IsValidTile(downstream_tile)) return false;
1198 
1199  /* Downstream might be new ocean created by our terraforming, and it hasn't flooded yet. */
1200  bool downstream_is_ocean = GetTileZ(downstream_tile) == 0 && (GetTileSlope(downstream_tile) == SLOPE_FLAT || IsSlopeWithOneCornerRaised(GetTileSlope(downstream_tile)));
1201 
1202  /* If downstream is dry, flat, and not ocean, try making it a river tile. */
1203  if (!IsWaterTile(downstream_tile) && !downstream_is_ocean) {
1204  /* If the tile upstream isn't flat, don't bother. */
1205  if (GetTileSlope(downstream_tile) != SLOPE_FLAT) return false;
1206 
1207  MakeRiver(downstream_tile, Random());
1208  MarkTileDirtyByTile(downstream_tile);
1209 
1210  /* Remove desert directly around the river tile. */
1211  TileIndex cur_tile = downstream_tile;
1213  }
1214 
1215  /* If upstream is dry and flat, try making it a river tile. */
1216  if (!IsWaterTile(upstream_tile)) {
1217  /* If the tile upstream isn't flat, don't bother. */
1218  if (GetTileSlope(upstream_tile) != SLOPE_FLAT) return false;
1219 
1220  MakeRiver(upstream_tile, Random());
1221  MarkTileDirtyByTile(upstream_tile);
1222 
1223  /* Remove desert directly around the river tile. */
1224  TileIndex cur_tile = upstream_tile;
1226  }
1227  }
1228 
1229  /* If the tile slope matches the desired slope, add a river tile. */
1230  if (cur_slope == desired_slope) {
1231  MakeRiver(tile, Random());
1232  MarkTileDirtyByTile(tile);
1233 
1234  /* Remove desert directly around the river tile. */
1235  TileIndex cur_tile = tile;
1237  }
1238 
1239  /* Always return false to keep searching. */
1240  return false;
1241 }
1242 
1249 static bool FlowsDown(TileIndex begin, TileIndex end)
1250 {
1251  assert(DistanceManhattan(begin, end) == 1);
1252 
1253  int heightBegin;
1254  int heightEnd;
1255  Slope slopeBegin = GetTileSlope(begin, &heightBegin);
1256  Slope slopeEnd = GetTileSlope(end, &heightEnd);
1257 
1258  return heightEnd <= heightBegin &&
1259  /* Slope either is inclined or flat; rivers don't support other slopes. */
1260  (slopeEnd == SLOPE_FLAT || IsInclinedSlope(slopeEnd)) &&
1261  /* Slope continues, then it must be lower... or either end must be flat. */
1262  ((slopeEnd == slopeBegin && heightEnd < heightBegin) || slopeEnd == SLOPE_FLAT || slopeBegin == SLOPE_FLAT);
1263 }
1264 
1268  bool main_river;
1269 };
1270 
1271 /* AyStar callback for checking whether we reached our destination. */
1272 static int32 River_EndNodeCheck(const AyStar *aystar, const OpenListNode *current)
1273 {
1274  return current->path.node.tile == *(TileIndex*)aystar->user_target ? AYSTAR_FOUND_END_NODE : AYSTAR_DONE;
1275 }
1276 
1277 /* AyStar callback for getting the cost of the current node. */
1278 static int32 River_CalculateG(AyStar *aystar, AyStarNode *current, OpenListNode *parent)
1279 {
1281 }
1282 
1283 /* AyStar callback for getting the estimated cost to the destination. */
1284 static int32 River_CalculateH(AyStar *aystar, AyStarNode *current, OpenListNode *parent)
1285 {
1286  return DistanceManhattan(*(TileIndex*)aystar->user_target, current->tile);
1287 }
1288 
1289 /* AyStar callback for getting the neighbouring nodes of the given node. */
1290 static void River_GetNeighbours(AyStar *aystar, OpenListNode *current)
1291 {
1292  TileIndex tile = current->path.node.tile;
1293 
1294  aystar->num_neighbours = 0;
1295  for (DiagDirection d = DIAGDIR_BEGIN; d < DIAGDIR_END; d++) {
1296  TileIndex t2 = tile + TileOffsByDiagDir(d);
1297  if (IsValidTile(t2) && FlowsDown(tile, t2)) {
1298  aystar->neighbours[aystar->num_neighbours].tile = t2;
1299  aystar->neighbours[aystar->num_neighbours].direction = INVALID_TRACKDIR;
1300  aystar->num_neighbours++;
1301  }
1302  }
1303 }
1304 
1305 /* AyStar callback when an route has been found. */
1306 static void River_FoundEndNode(AyStar *aystar, OpenListNode *current)
1307 {
1308  River_UserData *data = (River_UserData *)aystar->user_data;
1309 
1310  /* First, build the river without worrying about its width. */
1311  uint cur_pos = 0;
1312  for (PathNode *path = &current->path; path != nullptr; path = path->parent, cur_pos++) {
1313  TileIndex tile = path->node.tile;
1314  if (!IsWaterTile(tile)) {
1315  MakeRiver(tile, Random());
1316  MarkTileDirtyByTile(tile);
1317  /* Remove desert directly around the river tile. */
1319  }
1320  }
1321 
1322  /* If the river is a main river, go back along the path to widen it.
1323  * Don't make wide rivers if we're using the original landscape generator.
1324  */
1326  const uint long_river_length = _settings_game.game_creation.min_river_length * 4;
1327  uint current_river_length;
1328  uint radius;
1329 
1330  cur_pos = 0;
1331  for (PathNode *path = &current->path; path != nullptr; path = path->parent, cur_pos++) {
1332  TileIndex tile = path->node.tile;
1333 
1334  /* Check if we should widen river depending on how far we are away from the source. */
1335  current_river_length = DistanceManhattan(data->spring, tile);
1336  radius = std::min(3u, (current_river_length / (long_river_length / 3u)) + 1u);
1337 
1338  if (radius > 1) CircularTileSearch(&tile, radius, RiverMakeWider, (void *)&path->node.tile);
1339  }
1340  }
1341 }
1342 
1343 static const uint RIVER_HASH_SIZE = 8;
1344 
1351 static uint River_Hash(uint tile, uint dir)
1352 {
1353  return GB(TileHash(TileX(tile), TileY(tile)), 0, RIVER_HASH_SIZE);
1354 }
1355 
1363 static void BuildRiver(TileIndex begin, TileIndex end, TileIndex spring, bool main_river)
1364 {
1365  River_UserData user_data = { spring, main_river };
1366 
1367  AyStar finder = {};
1368  finder.CalculateG = River_CalculateG;
1369  finder.CalculateH = River_CalculateH;
1370  finder.GetNeighbours = River_GetNeighbours;
1371  finder.EndNodeCheck = River_EndNodeCheck;
1372  finder.FoundEndNode = River_FoundEndNode;
1373  finder.user_target = &end;
1374  finder.user_data = &user_data;
1375 
1376  finder.Init(River_Hash, 1 << RIVER_HASH_SIZE);
1377 
1378  AyStarNode start;
1379  start.tile = begin;
1380  start.direction = INVALID_TRACKDIR;
1381  finder.AddStartNode(&start, 0);
1382  finder.Main();
1383  finder.Free();
1384 }
1385 
1393 static std::tuple<bool, bool> FlowRiver(TileIndex spring, TileIndex begin, uint min_river_length)
1394 {
1395 # define SET_MARK(x) marks.insert(x)
1396 # define IS_MARKED(x) (marks.find(x) != marks.end())
1397 
1398  uint height = TileHeight(begin);
1399 
1400  if (IsWaterTile(begin)) {
1401  return { DistanceManhattan(spring, begin) > min_river_length, GetTileZ(begin) == 0 };
1402  }
1403 
1404  std::set<TileIndex> marks;
1405  SET_MARK(begin);
1406 
1407  /* Breadth first search for the closest tile we can flow down to. */
1408  std::list<TileIndex> queue;
1409  queue.push_back(begin);
1410 
1411  bool found = false;
1412  uint count = 0; // Number of tiles considered; to be used for lake location guessing.
1413  TileIndex end;
1414  do {
1415  end = queue.front();
1416  queue.pop_front();
1417 
1418  uint height2 = TileHeight(end);
1419  if (IsTileFlat(end) && (height2 < height || (height2 == height && IsWaterTile(end)))) {
1420  found = true;
1421  break;
1422  }
1423 
1424  for (DiagDirection d = DIAGDIR_BEGIN; d < DIAGDIR_END; d++) {
1425  TileIndex t2 = end + TileOffsByDiagDir(d);
1426  if (IsValidTile(t2) && !IS_MARKED(t2) && FlowsDown(end, t2)) {
1427  SET_MARK(t2);
1428  count++;
1429  queue.push_back(t2);
1430  }
1431  }
1432  } while (!queue.empty());
1433 
1434  bool main_river = false;
1435  if (found) {
1436  /* Flow further down hill. */
1437  std::tie(found, main_river) = FlowRiver(spring, end, min_river_length);
1438  } else if (count > 32) {
1439  /* Maybe we can make a lake. Find the Nth of the considered tiles. */
1440  TileIndex lakeCenter = 0;
1441  int i = RandomRange(count - 1) + 1;
1442  std::set<TileIndex>::const_iterator cit = marks.begin();
1443  while (--i) cit++;
1444  lakeCenter = *cit;
1445 
1446  if (IsValidTile(lakeCenter) &&
1447  /* A river, or lake, can only be built on flat slopes. */
1448  IsTileFlat(lakeCenter) &&
1449  /* We want the lake to be built at the height of the river. */
1450  TileHeight(begin) == TileHeight(lakeCenter) &&
1451  /* We don't want the lake at the entry of the valley. */
1452  lakeCenter != begin &&
1453  /* We don't want lakes in the desert. */
1454  (_settings_game.game_creation.landscape != LT_TROPIC || GetTropicZone(lakeCenter) != TROPICZONE_DESERT) &&
1455  /* We only want a lake if the river is long enough. */
1456  DistanceManhattan(spring, lakeCenter) > min_river_length) {
1457  end = lakeCenter;
1458  MakeRiver(lakeCenter, Random());
1459  MarkTileDirtyByTile(lakeCenter);
1460  /* Remove desert directly around the river tile. */
1462  lakeCenter = end;
1463  uint range = RandomRange(8) + 3;
1464  CircularTileSearch(&lakeCenter, range, MakeLake, &height);
1465  /* Call the search a second time so artefacts from going circular in one direction get (mostly) hidden. */
1466  lakeCenter = end;
1467  CircularTileSearch(&lakeCenter, range, MakeLake, &height);
1468  found = true;
1469  }
1470  }
1471 
1472  marks.clear();
1473  if (found) BuildRiver(begin, end, spring, main_river);
1474  return { found, main_river };
1475 }
1476 
1480 static void CreateRivers()
1481 {
1483  if (amount == 0) return;
1484 
1486  const uint num_short_rivers = wells - std::max(1u, wells / 10);
1487  SetGeneratingWorldProgress(GWP_RIVER, wells + 256 / 64); // Include the tile loop calls below.
1488 
1489  /* Try to create long rivers. */
1490  for (; wells > num_short_rivers; wells--) {
1492  for (int tries = 0; tries < 512; tries++) {
1493  TileIndex t = RandomTile();
1494  if (!CircularTileSearch(&t, 8, FindSpring, nullptr)) continue;
1495  if (std::get<0>(FlowRiver(t, t, _settings_game.game_creation.min_river_length * 4))) break;
1496  }
1497  }
1498 
1499  /* Try to create short rivers. */
1500  for (; wells != 0; wells--) {
1502  for (int tries = 0; tries < 128; tries++) {
1503  TileIndex t = RandomTile();
1504  if (!CircularTileSearch(&t, 8, FindSpring, nullptr)) continue;
1505  if (std::get<0>(FlowRiver(t, t, _settings_game.game_creation.min_river_length))) break;
1506  }
1507  }
1508 
1509  /* Widening rivers may have left some tiles requiring to be watered. */
1510  ConvertGroundTilesIntoWaterTiles();
1511 
1512  /* Run tile loop to update the ground density. */
1513  for (uint i = 0; i != 256; i++) {
1514  if (i % 64 == 0) IncreaseGeneratingWorldProgress(GWP_RIVER);
1515  RunTileLoop();
1516  }
1517 }
1518 
1536 static uint CalculateCoverageLine(uint coverage, uint edge_multiplier)
1537 {
1538  const DiagDirection neighbour_dir[] = {
1539  DIAGDIR_NE,
1540  DIAGDIR_SE,
1541  DIAGDIR_SW,
1542  DIAGDIR_NW,
1543  };
1544 
1545  /* Histogram of how many tiles per height level exist. */
1546  std::array<int, MAX_TILE_HEIGHT + 1> histogram = {};
1547  /* Histogram of how many neighbour tiles are lower than the tiles of the height level. */
1548  std::array<int, MAX_TILE_HEIGHT + 1> edge_histogram = {};
1549 
1550  /* Build a histogram of the map height. */
1551  for (TileIndex tile = 0; tile < MapSize(); tile++) {
1552  uint h = TileHeight(tile);
1553  histogram[h]++;
1554 
1555  if (edge_multiplier != 0) {
1556  /* Check if any of our neighbours is below us. */
1557  for (auto dir : neighbour_dir) {
1558  TileIndex neighbour_tile = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDiagDir(dir));
1559  if (IsValidTile(neighbour_tile) && TileHeight(neighbour_tile) < h) {
1560  edge_histogram[h]++;
1561  }
1562  }
1563  }
1564  }
1565 
1566  /* The amount of land we have is the map size minus the first (sea) layer. */
1567  uint land_tiles = MapSizeX() * MapSizeY() - histogram[0];
1568  int best_score = land_tiles;
1569 
1570  /* Our goal is the coverage amount of the land-mass. */
1571  int goal_tiles = land_tiles * coverage / 100;
1572 
1573  /* We scan from top to bottom. */
1574  uint h = MAX_TILE_HEIGHT;
1575  uint best_h = h;
1576 
1577  int current_tiles = 0;
1578  for (; h > 0; h--) {
1579  current_tiles += histogram[h];
1580  int current_score = goal_tiles - current_tiles;
1581 
1582  /* Tropic grows from water and mountains into the desert. This is a
1583  * great visual, but it also means we* need to take into account how
1584  * much less desert tiles are being created if we are on this
1585  * height-level. We estimate this based on how many neighbouring
1586  * tiles are below us for a given length, assuming that is where
1587  * tropic is growing from.
1588  */
1589  if (edge_multiplier != 0 && h > 1) {
1590  /* From water tropic tiles grow for a few tiles land inward. */
1591  current_score -= edge_histogram[1] * edge_multiplier;
1592  /* Tropic tiles grow into the desert for a few tiles. */
1593  current_score -= edge_histogram[h] * edge_multiplier;
1594  }
1595 
1596  if (std::abs(current_score) < std::abs(best_score)) {
1597  best_score = current_score;
1598  best_h = h;
1599  }
1600 
1601  /* Always scan all height-levels, as h == 1 might give a better
1602  * score than any before. This is true for example with 0% desert
1603  * coverage. */
1604  }
1605 
1606  return best_h;
1607 }
1608 
1612 static void CalculateSnowLine()
1613 {
1614  /* We do not have snow sprites on coastal tiles, so never allow "1" as height. */
1616 }
1617 
1622 static uint8 CalculateDesertLine()
1623 {
1624  /* CalculateCoverageLine() runs from top to bottom, so we need to invert the coverage. */
1626 }
1627 
1628 void GenerateLandscape(byte mode)
1629 {
1631  enum GenLandscapeSteps {
1632  GLS_HEIGHTMAP = 3,
1633  GLS_TERRAGENESIS = 5,
1634  GLS_ORIGINAL = 2,
1635  GLS_TROPIC = 12,
1636  GLS_OTHER = 0,
1637  };
1638  uint steps = (_settings_game.game_creation.landscape == LT_TROPIC) ? GLS_TROPIC : GLS_OTHER;
1639 
1640  if (mode == GWM_HEIGHTMAP) {
1641  SetGeneratingWorldProgress(GWP_LANDSCAPE, steps + GLS_HEIGHTMAP);
1645  SetGeneratingWorldProgress(GWP_LANDSCAPE, steps + GLS_TERRAGENESIS);
1647  } else {
1648  SetGeneratingWorldProgress(GWP_LANDSCAPE, steps + GLS_ORIGINAL);
1650  for (uint x = 0; x < MapSizeX(); x++) MakeVoid(TileXY(x, 0));
1651  for (uint y = 0; y < MapSizeY(); y++) MakeVoid(TileXY(0, y));
1652  }
1654  case LT_ARCTIC: {
1655  uint32 r = Random();
1656 
1657  for (uint i = ScaleByMapSize(GB(r, 0, 7) + 950); i != 0; --i) {
1658  GenerateTerrain(2, 0);
1659  }
1660 
1661  uint flag = GB(r, 7, 2) | 4;
1662  for (uint i = ScaleByMapSize(GB(r, 9, 7) + 450); i != 0; --i) {
1663  GenerateTerrain(4, flag);
1664  }
1665  break;
1666  }
1667 
1668  case LT_TROPIC: {
1669  uint32 r = Random();
1670 
1671  for (uint i = ScaleByMapSize(GB(r, 0, 7) + 170); i != 0; --i) {
1672  GenerateTerrain(0, 0);
1673  }
1674 
1675  uint flag = GB(r, 7, 2) | 4;
1676  for (uint i = ScaleByMapSize(GB(r, 9, 8) + 1700); i != 0; --i) {
1677  GenerateTerrain(0, flag);
1678  }
1679 
1680  flag ^= 2;
1681 
1682  for (uint i = ScaleByMapSize(GB(r, 17, 7) + 410); i != 0; --i) {
1683  GenerateTerrain(3, flag);
1684  }
1685  break;
1686  }
1687 
1688  default: {
1689  uint32 r = Random();
1690 
1692  uint i = ScaleByMapSize(GB(r, 0, 7) + (3 - _settings_game.difficulty.quantity_sea_lakes) * 256 + 100);
1693  for (; i != 0; --i) {
1694  /* Make sure we do not overflow. */
1695  GenerateTerrain(Clamp(_settings_game.difficulty.terrain_type, 0, 3), 0);
1696  }
1697  break;
1698  }
1699  }
1700  }
1701 
1702  /* Do not call IncreaseGeneratingWorldProgress() before FixSlopes(),
1703  * it allows screen redraw. Drawing of broken slopes crashes the game */
1704  FixSlopes();
1707 
1708  ConvertGroundTilesIntoWaterTiles();
1711 
1713  case LT_ARCTIC:
1715  break;
1716 
1717  case LT_TROPIC: {
1718  uint desert_tropic_line = CalculateDesertLine();
1719  CreateDesertOrRainForest(desert_tropic_line);
1720  break;
1721  }
1722 
1723  default:
1724  break;
1725  }
1726 
1727  CreateRivers();
1728 }
1729 
1730 void OnTick_Town();
1731 void OnTick_Trees();
1732 void OnTick_Station();
1733 void OnTick_Industry();
1734 
1735 void OnTick_Companies();
1736 void OnTick_LinkGraph();
1737 
1738 void CallLandscapeTick()
1739 {
1740  {
1742 
1743  OnTick_Town();
1744  OnTick_Trees();
1745  OnTick_Station();
1746  OnTick_Industry();
1747  }
1748 
1749  OnTick_Companies();
1750  OnTick_LinkGraph();
1751 }
CalculateDesertLine
static uint8 CalculateDesertLine()
Calculate the line (in height) between desert and tropic.
Definition: landscape.cpp:1622
MapLogX
static uint MapLogX()
Logarithm of the map size along the X side.
Definition: map_func.h:51
GameCreationSettings::min_river_length
byte min_river_length
the minimum river length
Definition: settings_type.h:335
OppositeCorner
static Corner OppositeCorner(Corner corner)
Returns the opposite corner.
Definition: slope_func.h:184
GenerateTerrainPerlin
void GenerateTerrainPerlin()
The main new land generator using Perlin noise.
Definition: tgp.cpp:992
TileInfo::z
int z
Height.
Definition: tile_cmd.h:47
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:80
SLOPE_SE
@ SLOPE_SE
south and east corner are raised
Definition: slope_type.h:57
YearMonthDay::day
Day day
Day (1..31)
Definition: date_type.h:107
TROPICZONE_DESERT
@ TROPICZONE_DESERT
Tile is desert.
Definition: tile_type.h:78
AddTileIndexDiffCWrap
static TileIndex AddTileIndexDiffCWrap(TileIndex tile, TileIndexDiffC diff)
Add a TileIndexDiffC to a TileIndex and returns the new one.
Definition: map_func.h:300
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:127
GenerateLandscape
void GenerateLandscape(byte mode)
Definition: landscape.cpp:1628
DiagonalTileIterator
Iterator to iterate over a diagonal area of the map.
Definition: tilearea_type.h:233
AYSTAR_DONE
@ AYSTAR_DONE
Not an end-tile, or wrong direction.
Definition: aystar.h:32
TileOffsByDiagDir
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition: map_func.h:341
CalculateSnowLine
static void CalculateSnowLine()
Calculate the line from which snow begins.
Definition: landscape.cpp:1612
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
usererror
void CDECL usererror(const char *s,...)
Error handling for fatal user errors.
Definition: openttd.cpp:105
GB
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:32
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:1363
LoadHeightmap
void 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
HasTileWaterClass
static bool HasTileWaterClass(TileIndex t)
Checks whether the tile has an waterclass associated.
Definition: water_map.h:106
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
TileInfo::x
uint x
X position of the tile in unit coordinates.
Definition: tile_cmd.h:43
Pool::PoolItem<&_company_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:348
CMD_ERROR
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition: command_func.h:28
TileInfo
Tile information, used while rendering the tile.
Definition: tile_cmd.h:42
GameCreationSettings::landscape
byte landscape
the landscape we're currently in
Definition: settings_type.h:328
Sprite::data
byte data[]
Sprite data.
Definition: spritecache.h:22
terraform_cmd.h
GetFoundationPixelSlope
static 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
CreateRivers
static void CreateRivers()
Actually (try to) create some rivers.
Definition: landscape.cpp:1480
SLOPE_NW
@ SLOPE_NW
north and west corner are raised
Definition: slope_type.h:55
DiagDirDiff
DiagDirDiff
Enumeration for the difference between to DiagDirection.
Definition: direction_type.h:104
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:63
DiagDirToAxis
static Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
Definition: direction_func.h:214
FileToSaveLoad::name
std::string name
Name of the file.
Definition: saveload.h:363
ConstructionSettings::map_height_limit
uint8 map_height_limit
the maximum allowed heightlevel
Definition: settings_type.h:342
GetSlopeZInCorner
int GetSlopeZInCorner(Slope tileh, Corner corner)
Determine the Z height of a corner relative to TileZ.
Definition: landscape.cpp:379
DIAGDIR_END
@ DIAGDIR_END
Used for iterations.
Definition: direction_type.h:83
MakeClear
static void MakeClear(TileIndex t, ClearGround g, uint density)
Make a clear tile.
Definition: clear_map.h:259
IsFoundation
static bool IsFoundation(Foundation f)
Tests for FOUNDATION_NONE.
Definition: slope_func.h:287
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:586
IsHalftileSlope
static bool IsHalftileSlope(Slope s)
Checks for non-continuous slope on halftile foundations.
Definition: slope_func.h:47
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
static constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:108
void_map.h
IsClearGround
static bool IsClearGround(TileIndex t, ClearGround ct)
Set the type of clear tile.
Definition: clear_map.h:71
TileIndex
The index/ID of a Tile.
Definition: tile_type.h:85
Sprite::height
uint16 height
Height of the sprite.
Definition: spritecache.h:18
DIAGDIRDIFF_90LEFT
@ DIAGDIRDIFF_90LEFT
90 degrees left
Definition: direction_type.h:109
RemoveHalftileSlope
static Slope RemoveHalftileSlope(Slope s)
Removes a halftile slope from a slope.
Definition: slope_func.h:60
IsCoastTile
static bool IsCoastTile(TileIndex t)
Is it a coast tile.
Definition: water_map.h:216
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:219
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:151
TileInfo::y
uint y
Y position of the tile in unit coordinates.
Definition: tile_cmd.h:44
DC_NO_WATER
@ DC_NO_WATER
don't allow building on water
Definition: command_type.h:360
SLOPE_ENW
@ SLOPE_ENW
east, north and west corner are raised
Definition: slope_type.h:65
TileY
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:215
SLOPE_S
@ SLOPE_S
the south corner of the tile is raised
Definition: slope_type.h:51
DIAGDIR_NW
@ DIAGDIR_NW
Northwest.
Definition: direction_type.h:82
RandomRange
static uint32 RandomRange(uint32 limit)
Pick a random number between 0 and limit - 1, inclusive.
Definition: random_func.hpp:81
DIAGDIRDIFF_SAME
@ DIAGDIRDIFF_SAME
Same directions.
Definition: direction_type.h:106
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
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:357
TileDesc
Tile description for the 'land area information' tool.
Definition: tile_cmd.h:51
GetHighestSlopeCorner
static Corner GetHighestSlopeCorner(Slope s)
Returns the highest corner of a slope (one corner raised or a steep slope).
Definition: slope_func.h:126
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:355
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:1572
PFE_GL_LANDSCAPE
@ PFE_GL_LANDSCAPE
Time spent processing other world features.
Definition: framerate_type.h:55
object_base.h
TileX
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:205
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition: settings_type.h:587
GetTileTrackStatus
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
Definition: landscape.cpp:601
effectvehicle_func.h
PM_UNPAUSED
@ PM_UNPAUSED
A normal unpaused game.
Definition: openttd.h:61
TileInfo::tileh
Slope tileh
Slope of the tile.
Definition: tile_cmd.h:45
SpriteID
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
CompanyProperties::clear_limit
uint32 clear_limit
Amount of tiles we can (still) clear (times 65536).
Definition: company_base.h:88
MapSizeX
static uint MapSizeX()
Get the size of the map along the X.
Definition: map_func.h:72
IsTileOnWater
static bool IsTileOnWater(TileIndex t)
Tests if the tile was built on water.
Definition: water_map.h:141
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:612
OnTick_Companies
void OnTick_Companies()
Called every tick for updating some company info.
Definition: company_cmd.cpp:712
Slope
Slope
Enumeration for the slope-type.
Definition: slope_type.h:48
OrthogonalTileIterator
Iterator to iterate over a tile area (rectangle) of the map.
Definition: tilearea_type.h:183
DistanceManhattan
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
Definition: map.cpp:157
DIAGDIR_SW
@ DIAGDIR_SW
Southwest.
Definition: direction_type.h:81
heightmap.h
FindSpring
static bool FindSpring(TileIndex tile, void *user_data)
Find the spring of a river.
Definition: landscape.cpp:1024
landscape_cmd.h
FOUNDATION_INCLINED_Y
@ FOUNDATION_INCLINED_Y
The tile has an along Y-axis inclined foundation.
Definition: slope_type.h:97
SteepSlope
static Slope SteepSlope(Corner corner)
Returns a specific steep slope.
Definition: slope_func.h:217
return_cmd_error
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
Definition: command_func.h:38
MapSize
static uint MapSize()
Get the size of the map.
Definition: map_func.h:92
EXPENSES_CONSTRUCTION
@ EXPENSES_CONSTRUCTION
Construction costs.
Definition: economy_type.h:158
_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:114
IsSteepSlope
static bool IsSteepSlope(Slope s)
Checks if a slope is steep.
Definition: slope_func.h:36
CommandCost
Common return value for all commands.
Definition: command_type.h:24
GetSnowLine
byte GetSnowLine()
Get the current snow line, either variable or static.
Definition: landscape.cpp:656
InverseRemapCoords
static Point InverseRemapCoords(int x, int y)
Map 2D viewport or smallmap coordinate to 3D world or tile coordinate.
Definition: landscape.h:112
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:105
_date
Date _date
Current date in days (day counter)
Definition: date.cpp:28
SetTropicZone
static void SetTropicZone(TileIndex tile, TropicZone type)
Set the tropic zone.
Definition: tile_map.h:225
TileHeight
static uint TileHeight(TileIndex tile)
Returns the height of a tile.
Definition: tile_map.h:29
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:258
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
SLOPE_WSE
@ SLOPE_WSE
west, south and east corner are raised
Definition: slope_type.h:63
ChangeDiagDir
static DiagDirection ChangeDiagDir(DiagDirection d, DiagDirDiff delta)
Applies a difference on a DiagDirection.
Definition: direction_func.h:149
SLOPE_NE
@ SLOPE_NE
north and east corner are raised
Definition: slope_type.h:58
YearMonthDay::month
Month month
Month (0..11)
Definition: date_type.h:106
DifficultySettings::terrain_type
byte terrain_type
the mountainousness of the landscape
Definition: settings_type.h:89
PathNode
A path of nodes.
Definition: aystar.h:45
IsSlopeWithThreeCornersRaised
static bool IsSlopeWithThreeCornersRaised(Slope s)
Tests if a specific slope has exactly three corners raised.
Definition: slope_func.h:195
IsInclinedFoundation
static bool IsInclinedFoundation(Foundation f)
Tests if the foundation is an inclined foundation.
Definition: slope_func.h:309
TileIterator
Base class for tile iterators.
Definition: tilearea_type.h:105
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
IsInsideBS
static 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:214
CalculateCoverageLine
static uint CalculateCoverageLine(uint coverage, uint edge_multiplier)
Calculate what height would be needed to cover N% of the landmass.
Definition: landscape.cpp:1536
_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
FOUNDATION_INCLINED_X
@ FOUNDATION_INCLINED_X
The tile has an along X-axis inclined foundation.
Definition: slope_type.h:96
CommandCost::Failed
bool Failed() const
Did this command fail?
Definition: command_type.h:160
Corner
Corner
Enumeration of tile corners.
Definition: slope_type.h:22
station_func.h
WATER_CLASS_CANAL
@ WATER_CLASS_CANAL
Canal.
Definition: water_map.h:49
MakeVoid
static void MakeVoid(TileIndex t)
Make a nice void tile ;)
Definition: void_map.h:19
_pause_mode
PauseMode _pause_mode
The current pause mode.
Definition: gfx.cpp:50
CLEAR_DESERT
@ CLEAR_DESERT
1,3
Definition: clear_map.h:25
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:54
GetTropicZone
static TropicZone GetTropicZone(TileIndex tile)
Get the tropic zone.
Definition: tile_map.h:238
ConvertDateToYMD
void ConvertDateToYMD(Date date, YearMonthDay *ymd)
Converts a Date to a Year, Month & Day.
Definition: date.cpp:94
DIAGDIRDIFF_90RIGHT
@ DIAGDIRDIFF_90RIGHT
90 degrees right
Definition: direction_type.h:107
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:1393
GameCreationSettings::snow_line_height
byte snow_line_height
the configured snow line height (deduced from "snow_coverage")
Definition: settings_type.h:319
safeguards.h
HighestSnowLine
byte HighestSnowLine()
Get the highest possible snow line height, either variable or static.
Definition: landscape.cpp:670
Sprite::width
uint16 width
Width of the sprite.
Definition: spritecache.h:19
IsValidTile
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
Definition: tile_map.h:161
ConstructionSettings::freeform_edges
bool freeform_edges
allow terraforming the tiles at the map edges
Definition: settings_type.h:354
CommandCost::GetCost
Money GetCost() const
The costs as made up to this moment.
Definition: command_type.h:83
ReverseDiagDir
static DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
Definition: direction_func.h:118
TileAddByDiagDir
static TileIndex TileAddByDiagDir(TileIndex tile, DiagDirection dir)
Adds a DiagDir to a tile.
Definition: map_func.h:382
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:150
DifficultySettings::quantity_sea_lakes
byte quantity_sea_lakes
the amount of seas/lakes
Definition: settings_type.h:90
IsNonContinuousFoundation
static bool IsNonContinuousFoundation(Foundation f)
Tests if a foundation is a non-continuous foundation, i.e.
Definition: slope_func.h:320
RandomTile
#define RandomTile()
Get a valid random tile.
Definition: map_func.h:435
LowestSnowLine
byte LowestSnowLine()
Get the lowest possible snow line height, either variable or static.
Definition: landscape.cpp:680
SlopeWithThreeCornersRaised
static Slope SlopeWithThreeCornersRaised(Corner corner)
Returns the slope with all except one corner raised.
Definition: slope_func.h:206
TileHash
static uint TileHash(uint x, uint y)
Calculate a hash value from a tile position.
Definition: tile_map.h:316
GetHalftileSlopeCorner
static Corner GetHalftileSlopeCorner(Slope s)
Returns the leveled halftile of a halftile slope.
Definition: slope_func.h:148
GetAvailableMoneyForCommand
Money GetAvailableMoneyForCommand()
Definition: command.cpp:173
INVALID_TRACKDIR
@ INVALID_TRACKDIR
Flag for an invalid trackdir.
Definition: track_type.h:89
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
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:77
MapSizeY
static uint MapSizeY()
Get the size of the map along the Y.
Definition: map_func.h:82
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:426
OffsetGroundSprite
void OffsetGroundSprite(int x, int y)
Called when a foundation has been drawn for the current tile.
Definition: viewport.cpp:595
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:397
date_func.h
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
landscape.h
TileTypeProcs
Set of callback functions for performing tile operations of a given tile type.
Definition: tile_cmd.h:145
DC_BANKRUPT
@ DC_BANKRUPT
company bankrupts, skip money check, skip vehicle on tile check in some cases
Definition: command_type.h:363
SetTileHeight
static void SetTileHeight(TileIndex tile, uint height)
Sets the height of a tile.
Definition: tile_map.h:57
viewport_func.h
OpenListNode
Internal node.
Definition: aystar.h:55
IsTileType
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
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
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:667
SLOPE_W
@ SLOPE_W
the west corner of the tile is raised
Definition: slope_type.h:50
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:637
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
ApplyPixelFoundationToSlope
static uint ApplyPixelFoundationToSlope(Foundation f, Slope *s)
Applies a foundation to a slope.
Definition: landscape.h:129
TileIndexDiffC
A pair-construct of a TileIndexDiff.
Definition: map_type.h:57
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:474
_generating_world
bool _generating_world
Whether we are generating the map or not.
Definition: genworld.cpp:61
DIAGDIRDIFF_REVERSE
@ DIAGDIRDIFF_REVERSE
Reverse directions.
Definition: direction_type.h:108
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:47
Clamp
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:77
SnowLine::highest_value
byte highest_value
Highest snow line of the year.
Definition: landscape.h:25
AYSTAR_FOUND_END_NODE
@ AYSTAR_FOUND_END_NODE
An end node was found.
Definition: aystar.h:27
GetWaterClass
static WaterClass GetWaterClass(TileIndex t)
Get the water class at a tile.
Definition: water_map.h:117
River_UserData::spring
TileIndex spring
The current spring during river generation.
Definition: landscape.cpp:1267
ScaleByMapSize
static uint ScaleByMapSize(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:122
SlopeWithOneCornerRaised
static Slope SlopeWithOneCornerRaised(Corner corner)
Returns the slope with a specific corner raised.
Definition: slope_func.h:99
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:368
MapMaxY
static uint MapMaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
Definition: map_func.h:111
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:529
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:64
FlowsDown
static bool FlowsDown(TileIndex begin, TileIndex end)
Check whether a river at begin could (logically) flow down to end.
Definition: landscape.cpp:1249
DeleteAnimatedTile
void DeleteAnimatedTile(TileIndex tile)
Removes the given tile from the animated tile table.
Definition: animated_tile.cpp:26
TileXY
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition: map_func.h:163
ClearBridgeMiddle
static void ClearBridgeMiddle(TileIndex t)
Removes bridges from the given, that is bridges along the X and Y axis.
Definition: bridge_map.h:103
IsSpecialRailFoundation
static bool IsSpecialRailFoundation(Foundation f)
Tests if a foundation is a special rail foundation for single horizontal/vertical track.
Definition: slope_func.h:345
GameCreationSettings::desert_coverage
byte desert_coverage
the amount of desert coverage on the map
Definition: settings_type.h:321
IsSlopeWithOneCornerRaised
static bool IsSlopeWithOneCornerRaised(Slope s)
Tests if a specific slope has exactly one corner raised.
Definition: slope_func.h:88
SLOPE_N
@ SLOPE_N
the north corner of the tile is raised
Definition: slope_type.h:53
DIAGDIRDIFF_END
@ DIAGDIRDIFF_END
Used for iterations.
Definition: direction_type.h:110
GameCreationSettings::amount_of_rivers
byte amount_of_rivers
the amount of rivers
Definition: settings_type.h:337
GameCreationSettings::land_generator
byte land_generator
the landscape generator
Definition: settings_type.h:317
River_UserData
Parameters for river generation to pass as AyStar user data.
Definition: landscape.cpp:1266
IsWaterTile
static bool IsWaterTile(TileIndex t)
Is it a water tile with plain water?
Definition: water_map.h:195
SetGeneratingWorldProgress
void SetGeneratingWorldProgress(GenWorldProgress cls, uint total)
Set the total of a stage of the world generation.
Definition: genworld_gui.cpp:1558
endof
#define endof(x)
Get the end element of an fixed size array.
Definition: stdafx.h:394
GetSlopeMaxPixelZ
static int GetSlopeMaxPixelZ(Slope s)
Returns the height of the highest corner of a slope relative to TileZ (= minimal height)
Definition: slope_func.h:173
framerate_type.h
_file_to_saveload
FileToSaveLoad _file_to_saveload
File to save or load in the openttd loop.
Definition: saveload.cpp:63
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
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:1998
TileDiffXY
static TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
Definition: map_func.h:179
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:627
RIVER_OFFSET_DESERT_DISTANCE
static const uint RIVER_OFFSET_DESERT_DISTANCE
Circular tile search radius to create non-desert around a river tile.
Definition: water.h:42
DIAGDIR_BEGIN
@ DIAGDIR_BEGIN
Used for iterations.
Definition: direction_type.h:78
DC_AUTO
@ DC_AUTO
don't allow building on structures
Definition: command_type.h:358
GetRailFoundationCorner
static Corner GetRailFoundationCorner(Foundation f)
Returns the track corner of a special rail foundation.
Definition: slope_func.h:356
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
genland.h
IsRiver
static bool IsRiver(TileIndex t)
Is it a river water tile?
Definition: water_map.h:185
MapMaxX
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Definition: map_func.h:102
CmdLandscapeClear
CommandCost CmdLandscapeClear(DoCommandFlag flags, TileIndex tile)
Clear a piece of landscape.
Definition: landscape.cpp:701
abs
static T abs(const T a)
Returns the absolute value of (scalar) variable.
Definition: math_func.hpp:21
TILE_ADDXY
#define TILE_ADDXY(tile, x, y)
Adds a given offset to a tile.
Definition: map_func.h:258
IsDockingTile
static bool IsDockingTile(TileIndex t)
Checks whether the tile is marked as a dockling tile.
Definition: water_map.h:376
CommandHelper
Definition: command_func.h:94
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:386
YearMonthDay
Data structure to convert between Date and triplet (year, month, and day).
Definition: date_type.h:104
CmdClearArea
std::tuple< CommandCost, Money > CmdClearArea(DoCommandFlag flags, TileIndex tile, TileIndex start_tile, bool diagonal)
Clear a big piece of landscape.
Definition: landscape.cpp:749
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1767
random_func.hpp
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:361
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 >
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:1060
GWP_RIVER
@ GWP_RIVER
Create the rivers.
Definition: genworld.h:72
GameCreationSettings::snow_coverage
byte snow_coverage
the amount of snow coverage on the map
Definition: settings_type.h:320
GameCreationSettings::river_route_random
byte river_route_random
the amount of randomicity for the route finding
Definition: settings_type.h:336
CeilDiv
static uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
Definition: math_func.hpp:280
TileInfo::tile
TileIndex tile
Tile index.
Definition: tile_cmd.h:46
GameSettings::construction
ConstructionSettings construction
construction of things in-game
Definition: settings_type.h:588
IsInclinedSlope
static bool IsInclinedSlope(Slope s)
Tests if a specific slope is an inclined slope.
Definition: slope_func.h:228
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:689
TILE_PIXELS
static const uint TILE_PIXELS
Pixel distance between tile columns/rows in #ZOOM_LVL_BASE.
Definition: tile_type.h:17
GetTileType
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
Definition: tile_map.h:96
FileToSaveLoad::detail_ftype
DetailedFileType detail_ftype
Concrete file type (PNG, BMP, old save, etc).
Definition: saveload.h:361
TROPICZONE_NORMAL
@ TROPICZONE_NORMAL
Normal tropiczone.
Definition: tile_type.h:77
River_UserData::main_river
bool main_river
Whether the current river is a big river that others flow into.
Definition: landscape.cpp:1268
River_Hash
static uint River_Hash(uint tile, uint dir)
Simple hash function for river tiles to be used by AyStar.
Definition: landscape.cpp:1351
Swap
static void Swap(T &a, T &b)
Type safe swap operation.
Definition: math_func.hpp:241
SLOPE_FLAT
@ SLOPE_FLAT
a flat tile
Definition: slope_type.h:49
HalftileSlope
static Slope HalftileSlope(Slope s, Corner corner)
Adds a halftile slope to a slope.
Definition: slope_func.h:274
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
free
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: stdafx.h:470
_tile_type_road_procs
const TileTypeProcs _tile_type_road_procs
Tile callback functions for road tiles.
Definition: landscape.cpp:49
_tick_counter
uint64 _tick_counter
Ever incrementing tick counter for setting off various events.
Definition: date.cpp:30
RiverMakeWider
static bool RiverMakeWider(TileIndex tile, void *data)
Widen a river by expanding into adjacent tiles via circular tile search.
Definition: landscape.cpp:1087
DIAGDIR_NE
@ DIAGDIR_NE
Northeast, upper right on your monitor.
Definition: direction_type.h:79
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:117
TileIndexDiffCByDiagDir
static TileIndexDiffC TileIndexDiffCByDiagDir(DiagDirection dir)
Returns the TileIndexDiffC offset from a DiagDirection.
Definition: map_func.h:268
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
SLOPE_STEEP
@ SLOPE_STEEP
indicates the slope is steep
Definition: slope_type.h:54
MapLogY
static uint MapLogY()
Logarithm of the map size along the y side.
Definition: map_func.h:62
IsLeveledFoundation
static bool IsLeveledFoundation(Foundation f)
Tests if the foundation is a leveled foundation.
Definition: slope_func.h:298
ComplementSlope
static Slope ComplementSlope(Slope s)
Return the complement of a slope.
Definition: slope_func.h:76
GetHalftileFoundationCorner
static Corner GetHalftileFoundationCorner(Foundation f)
Returns the halftile corner of a halftile-foundation.
Definition: slope_func.h:333
ST_MAPGEN
@ ST_MAPGEN
Special sprite for the map generator.
Definition: gfx_type.h:309
SLOPE_STEEP_N
@ SLOPE_STEEP_N
a steep slope falling to south (from north)
Definition: slope_type.h:69
MakeRiver
static void MakeRiver(TileIndex t, uint8 random_bits)
Make a river tile.
Definition: water_map.h:435
RIVER_HASH_SIZE
static const uint RIVER_HASH_SIZE
The number of bits the hash for river finding should have.
Definition: landscape.cpp:1343
RiverModifyDesertZone
bool RiverModifyDesertZone(TileIndex tile, void *data)
Callback to create non-desert around a river tile.
Definition: water_cmd.cpp:427
GetInclinedSlopeDirection
static DiagDirection GetInclinedSlopeDirection(Slope s)
Returns the direction of an inclined slope.
Definition: slope_func.h:239
TileVirtXY
static TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
Definition: map_func.h:194
RunTileLoop
void RunTileLoop()
Gradually iterate over all tiles on the map, calling their TileLoopProcs once every 256 ticks.
Definition: landscape.cpp:807
SNOW_LINE_MONTHS
static const uint SNOW_LINE_MONTHS
Number of months in the snow line table.
Definition: landscape.h:16