OpenTTD Source  1.11.0-beta2
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 <list>
35 #include <set>
36 
37 #include "table/strings.h"
38 #include "table/sprites.h"
39 
40 #include "safeguards.h"
41 
42 extern const TileTypeProcs
43  _tile_type_clear_procs,
44  _tile_type_rail_procs,
47  _tile_type_trees_procs,
48  _tile_type_station_procs,
49  _tile_type_water_procs,
50  _tile_type_void_procs,
51  _tile_type_industry_procs,
52  _tile_type_tunnelbridge_procs,
53  _tile_type_object_procs;
54 
60 const TileTypeProcs * const _tile_type_procs[16] = {
61  &_tile_type_clear_procs,
62  &_tile_type_rail_procs,
65  &_tile_type_trees_procs,
66  &_tile_type_station_procs,
67  &_tile_type_water_procs,
68  &_tile_type_void_procs,
69  &_tile_type_industry_procs,
70  &_tile_type_tunnelbridge_procs,
71  &_tile_type_object_procs,
72 };
73 
75 extern const byte _slope_to_sprite_offset[32] = {
76  0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0,
77  0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 17, 0, 15, 18, 0,
78 };
79 
88 static SnowLine *_snow_line = nullptr;
89 
103 Point InverseRemapCoords2(int x, int y, bool clamp_to_map, bool *clamped)
104 {
105  if (clamped != nullptr) *clamped = false; // Not clamping yet.
106 
107  /* Initial x/y world coordinate is like if the landscape
108  * was completely flat on height 0. */
109  Point pt = InverseRemapCoords(x, y);
110 
111  const uint min_coord = _settings_game.construction.freeform_edges ? TILE_SIZE : 0;
112  const uint max_x = MapMaxX() * TILE_SIZE - 1;
113  const uint max_y = MapMaxY() * TILE_SIZE - 1;
114 
115  if (clamp_to_map) {
116  /* Bring the coordinates near to a valid range. At the top we allow a number
117  * of extra tiles. This is mostly due to the tiles on the north side of
118  * the map possibly being drawn higher due to the extra height levels. */
120  Point old_pt = pt;
121  pt.x = Clamp(pt.x, -extra_tiles * TILE_SIZE, max_x);
122  pt.y = Clamp(pt.y, -extra_tiles * TILE_SIZE, max_y);
123  if (clamped != nullptr) *clamped = (pt.x != old_pt.x) || (pt.y != old_pt.y);
124  }
125 
126  /* Now find the Z-world coordinate by fix point iteration.
127  * This is a bit tricky because the tile height is non-continuous at foundations.
128  * The clicked point should be approached from the back, otherwise there are regions that are not clickable.
129  * (FOUNDATION_HALFTILE_LOWER on SLOPE_STEEP_S hides north halftile completely)
130  * So give it a z-malus of 4 in the first iterations. */
131  int z = 0;
132  if (clamp_to_map) {
133  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;
134  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;
135  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;
136  } else {
137  for (int i = 0; i < 5; i++) z = GetSlopePixelZOutsideMap(pt.x + std::max(z, 4) - 4, pt.y + std::max(z, 4) - 4) / 2;
138  for (int m = 3; m > 0; m--) z = GetSlopePixelZOutsideMap(pt.x + std::max(z, m) - m, pt.y + std::max(z, m) - m) / 2;
139  for (int i = 0; i < 5; i++) z = GetSlopePixelZOutsideMap(pt.x + z, pt.y + z ) / 2;
140  }
141 
142  pt.x += z;
143  pt.y += z;
144  if (clamp_to_map) {
145  Point old_pt = pt;
146  pt.x = Clamp(pt.x, min_coord, max_x);
147  pt.y = Clamp(pt.y, min_coord, max_y);
148  if (clamped != nullptr) *clamped = *clamped || (pt.x != old_pt.x) || (pt.y != old_pt.y);
149  }
150 
151  return pt;
152 }
153 
163 {
164  if (!IsFoundation(f)) return 0;
165 
166  if (IsLeveledFoundation(f)) {
167  uint dz = 1 + (IsSteepSlope(*s) ? 1 : 0);
168  *s = SLOPE_FLAT;
169  return dz;
170  }
171 
174  return 0;
175  }
176 
177  if (IsSpecialRailFoundation(f)) {
179  return 0;
180  }
181 
182  uint dz = IsSteepSlope(*s) ? 1 : 0;
183  Corner highest_corner = GetHighestSlopeCorner(*s);
184 
185  switch (f) {
187  *s = (((highest_corner == CORNER_W) || (highest_corner == CORNER_S)) ? SLOPE_SW : SLOPE_NE);
188  break;
189 
191  *s = (((highest_corner == CORNER_S) || (highest_corner == CORNER_E)) ? SLOPE_SE : SLOPE_NW);
192  break;
193 
195  *s = SlopeWithOneCornerRaised(highest_corner);
196  break;
197 
199  *s = HalftileSlope(SlopeWithOneCornerRaised(highest_corner), highest_corner);
200  break;
201 
202  default: NOT_REACHED();
203  }
204  return dz;
205 }
206 
207 
215 uint GetPartialPixelZ(int x, int y, Slope corners)
216 {
217  if (IsHalftileSlope(corners)) {
218  switch (GetHalftileSlopeCorner(corners)) {
219  case CORNER_W:
220  if (x - y >= 0) return GetSlopeMaxPixelZ(corners);
221  break;
222 
223  case CORNER_S:
224  if (x - (y ^ 0xF) >= 0) return GetSlopeMaxPixelZ(corners);
225  break;
226 
227  case CORNER_E:
228  if (y - x >= 0) return GetSlopeMaxPixelZ(corners);
229  break;
230 
231  case CORNER_N:
232  if ((y ^ 0xF) - x >= 0) return GetSlopeMaxPixelZ(corners);
233  break;
234 
235  default: NOT_REACHED();
236  }
237  }
238 
239  int z = 0;
240 
241  switch (RemoveHalftileSlope(corners)) {
242  case SLOPE_W:
243  if (x - y >= 0) {
244  z = (x - y) >> 1;
245  }
246  break;
247 
248  case SLOPE_S:
249  y ^= 0xF;
250  if ((x - y) >= 0) {
251  z = (x - y) >> 1;
252  }
253  break;
254 
255  case SLOPE_SW:
256  z = (x >> 1) + 1;
257  break;
258 
259  case SLOPE_E:
260  if (y - x >= 0) {
261  z = (y - x) >> 1;
262  }
263  break;
264 
265  case SLOPE_EW:
266  case SLOPE_NS:
267  case SLOPE_ELEVATED:
268  z = 4;
269  break;
270 
271  case SLOPE_SE:
272  z = (y >> 1) + 1;
273  break;
274 
275  case SLOPE_WSE:
276  z = 8;
277  y ^= 0xF;
278  if (x - y < 0) {
279  z += (x - y) >> 1;
280  }
281  break;
282 
283  case SLOPE_N:
284  y ^= 0xF;
285  if (y - x >= 0) {
286  z = (y - x) >> 1;
287  }
288  break;
289 
290  case SLOPE_NW:
291  z = (y ^ 0xF) >> 1;
292  break;
293 
294  case SLOPE_NWS:
295  z = 8;
296  if (x - y < 0) {
297  z += (x - y) >> 1;
298  }
299  break;
300 
301  case SLOPE_NE:
302  z = (x ^ 0xF) >> 1;
303  break;
304 
305  case SLOPE_ENW:
306  z = 8;
307  y ^= 0xF;
308  if (y - x < 0) {
309  z += (y - x) >> 1;
310  }
311  break;
312 
313  case SLOPE_SEN:
314  z = 8;
315  if (y - x < 0) {
316  z += (y - x) >> 1;
317  }
318  break;
319 
320  case SLOPE_STEEP_S:
321  z = 1 + ((x + y) >> 1);
322  break;
323 
324  case SLOPE_STEEP_W:
325  z = 1 + ((x + (y ^ 0xF)) >> 1);
326  break;
327 
328  case SLOPE_STEEP_N:
329  z = 1 + (((x ^ 0xF) + (y ^ 0xF)) >> 1);
330  break;
331 
332  case SLOPE_STEEP_E:
333  z = 1 + (((x ^ 0xF) + y) >> 1);
334  break;
335 
336  default: break;
337  }
338 
339  return z;
340 }
341 
342 int GetSlopePixelZ(int x, int y)
343 {
344  TileIndex tile = TileVirtXY(x, y);
345 
346  return _tile_type_procs[GetTileType(tile)]->get_slope_z_proc(tile, x, y);
347 }
348 
357 int GetSlopePixelZOutsideMap(int x, int y)
358 {
359  if (IsInsideBS(x, 0, MapSizeX() * TILE_SIZE) && IsInsideBS(y, 0, MapSizeY() * TILE_SIZE)) {
360  return GetSlopePixelZ(x, y);
361  } else {
362  return _tile_type_procs[MP_VOID]->get_slope_z_proc(INVALID_TILE, x, y);
363  }
364 }
365 
375 int GetSlopeZInCorner(Slope tileh, Corner corner)
376 {
377  assert(!IsHalftileSlope(tileh));
378  return ((tileh & SlopeWithOneCornerRaised(corner)) != 0 ? 1 : 0) + (tileh == SteepSlope(corner) ? 1 : 0);
379 }
380 
393 void GetSlopePixelZOnEdge(Slope tileh, DiagDirection edge, int *z1, int *z2)
394 {
395  static const Slope corners[4][4] = {
396  /* corner | steep slope
397  * z1 z2 | z1 z2 */
398  {SLOPE_E, SLOPE_N, SLOPE_STEEP_E, SLOPE_STEEP_N}, // DIAGDIR_NE, z1 = E, z2 = N
399  {SLOPE_S, SLOPE_E, SLOPE_STEEP_S, SLOPE_STEEP_E}, // DIAGDIR_SE, z1 = S, z2 = E
400  {SLOPE_S, SLOPE_W, SLOPE_STEEP_S, SLOPE_STEEP_W}, // DIAGDIR_SW, z1 = S, z2 = W
401  {SLOPE_W, SLOPE_N, SLOPE_STEEP_W, SLOPE_STEEP_N}, // DIAGDIR_NW, z1 = W, z2 = N
402  };
403 
404  int halftile_test = (IsHalftileSlope(tileh) ? SlopeWithOneCornerRaised(GetHalftileSlopeCorner(tileh)) : 0);
405  if (halftile_test == corners[edge][0]) *z2 += TILE_HEIGHT; // The slope is non-continuous in z2. z2 is on the upper side.
406  if (halftile_test == corners[edge][1]) *z1 += TILE_HEIGHT; // The slope is non-continuous in z1. z1 is on the upper side.
407 
408  if ((tileh & corners[edge][0]) != 0) *z1 += TILE_HEIGHT; // z1 is raised
409  if ((tileh & corners[edge][1]) != 0) *z2 += TILE_HEIGHT; // z2 is raised
410  if (RemoveHalftileSlope(tileh) == corners[edge][2]) *z1 += TILE_HEIGHT; // z1 is highest corner of a steep slope
411  if (RemoveHalftileSlope(tileh) == corners[edge][3]) *z2 += TILE_HEIGHT; // z2 is highest corner of a steep slope
412 }
413 
423 {
424  Slope tileh = GetTileSlope(tile, z);
425  Foundation f = _tile_type_procs[GetTileType(tile)]->get_foundation_proc(tile, tileh);
426  uint z_inc = ApplyFoundationToSlope(f, &tileh);
427  if (z != nullptr) *z += z_inc;
428  return tileh;
429 }
430 
431 
432 bool HasFoundationNW(TileIndex tile, Slope slope_here, uint z_here)
433 {
434  int z;
435 
436  int z_W_here = z_here;
437  int z_N_here = z_here;
438  GetSlopePixelZOnEdge(slope_here, DIAGDIR_NW, &z_W_here, &z_N_here);
439 
440  Slope slope = GetFoundationPixelSlope(TILE_ADDXY(tile, 0, -1), &z);
441  int z_W = z;
442  int z_N = z;
443  GetSlopePixelZOnEdge(slope, DIAGDIR_SE, &z_W, &z_N);
444 
445  return (z_N_here > z_N) || (z_W_here > z_W);
446 }
447 
448 
449 bool HasFoundationNE(TileIndex tile, Slope slope_here, uint z_here)
450 {
451  int z;
452 
453  int z_E_here = z_here;
454  int z_N_here = z_here;
455  GetSlopePixelZOnEdge(slope_here, DIAGDIR_NE, &z_E_here, &z_N_here);
456 
457  Slope slope = GetFoundationPixelSlope(TILE_ADDXY(tile, -1, 0), &z);
458  int z_E = z;
459  int z_N = z;
460  GetSlopePixelZOnEdge(slope, DIAGDIR_SW, &z_E, &z_N);
461 
462  return (z_N_here > z_N) || (z_E_here > z_E);
463 }
464 
471 {
472  if (!IsFoundation(f)) return;
473 
474  /* Two part foundations must be drawn separately */
475  assert(f != FOUNDATION_STEEP_BOTH);
476 
477  uint sprite_block = 0;
478  int z;
479  Slope slope = GetFoundationPixelSlope(ti->tile, &z);
480 
481  /* Select the needed block of foundations sprites
482  * Block 0: Walls at NW and NE edge
483  * Block 1: Wall at NE edge
484  * Block 2: Wall at NW edge
485  * Block 3: No walls at NW or NE edge
486  */
487  if (!HasFoundationNW(ti->tile, slope, z)) sprite_block += 1;
488  if (!HasFoundationNE(ti->tile, slope, z)) sprite_block += 2;
489 
490  /* Use the original slope sprites if NW and NE borders should be visible */
491  SpriteID leveled_base = (sprite_block == 0 ? (int)SPR_FOUNDATION_BASE : (SPR_SLOPES_VIRTUAL_BASE + sprite_block * SPR_TRKFOUND_BLOCK_SIZE));
492  SpriteID inclined_base = SPR_SLOPES_VIRTUAL_BASE + SPR_SLOPES_INCLINED_OFFSET + sprite_block * SPR_TRKFOUND_BLOCK_SIZE;
493  SpriteID halftile_base = SPR_HALFTILE_FOUNDATION_BASE + sprite_block * SPR_HALFTILE_BLOCK_SIZE;
494 
495  if (IsSteepSlope(ti->tileh)) {
496  if (!IsNonContinuousFoundation(f)) {
497  /* Lower part of foundation */
499  leveled_base + (ti->tileh & ~SLOPE_STEEP), PAL_NONE, ti->x, ti->y, 16, 16, 7, ti->z
500  );
501  }
502 
503  Corner highest_corner = GetHighestSlopeCorner(ti->tileh);
504  ti->z += ApplyPixelFoundationToSlope(f, &ti->tileh);
505 
506  if (IsInclinedFoundation(f)) {
507  /* inclined foundation */
508  byte inclined = highest_corner * 2 + (f == FOUNDATION_INCLINED_Y ? 1 : 0);
509 
510  AddSortableSpriteToDraw(inclined_base + inclined, PAL_NONE, ti->x, ti->y,
511  f == FOUNDATION_INCLINED_X ? 16 : 1,
512  f == FOUNDATION_INCLINED_Y ? 16 : 1,
513  TILE_HEIGHT, ti->z
514  );
515  OffsetGroundSprite(31, 9);
516  } else if (IsLeveledFoundation(f)) {
517  AddSortableSpriteToDraw(leveled_base + SlopeWithOneCornerRaised(highest_corner), PAL_NONE, ti->x, ti->y, 16, 16, 7, ti->z - TILE_HEIGHT);
518  OffsetGroundSprite(31, 1);
519  } else if (f == FOUNDATION_STEEP_LOWER) {
520  /* one corner raised */
521  OffsetGroundSprite(31, 1);
522  } else {
523  /* halftile foundation */
524  int x_bb = (((highest_corner == CORNER_W) || (highest_corner == CORNER_S)) ? 8 : 0);
525  int y_bb = (((highest_corner == CORNER_S) || (highest_corner == CORNER_E)) ? 8 : 0);
526 
527  AddSortableSpriteToDraw(halftile_base + highest_corner, PAL_NONE, ti->x + x_bb, ti->y + y_bb, 8, 8, 7, ti->z + TILE_HEIGHT);
528  OffsetGroundSprite(31, 9);
529  }
530  } else {
531  if (IsLeveledFoundation(f)) {
532  /* leveled foundation */
533  AddSortableSpriteToDraw(leveled_base + ti->tileh, PAL_NONE, ti->x, ti->y, 16, 16, 7, ti->z);
534  OffsetGroundSprite(31, 1);
535  } else if (IsNonContinuousFoundation(f)) {
536  /* halftile foundation */
537  Corner halftile_corner = GetHalftileFoundationCorner(f);
538  int x_bb = (((halftile_corner == CORNER_W) || (halftile_corner == CORNER_S)) ? 8 : 0);
539  int y_bb = (((halftile_corner == CORNER_S) || (halftile_corner == CORNER_E)) ? 8 : 0);
540 
541  AddSortableSpriteToDraw(halftile_base + halftile_corner, PAL_NONE, ti->x + x_bb, ti->y + y_bb, 8, 8, 7, ti->z);
542  OffsetGroundSprite(31, 9);
543  } else if (IsSpecialRailFoundation(f)) {
544  /* anti-zig-zag foundation */
545  SpriteID spr;
546  if (ti->tileh == SLOPE_NS || ti->tileh == SLOPE_EW) {
547  /* half of leveled foundation under track corner */
548  spr = leveled_base + SlopeWithThreeCornersRaised(GetRailFoundationCorner(f));
549  } else {
550  /* tile-slope = sloped along X/Y, foundation-slope = three corners raised */
551  spr = inclined_base + 2 * GetRailFoundationCorner(f) + ((ti->tileh == SLOPE_SW || ti->tileh == SLOPE_NE) ? 1 : 0);
552  }
553  AddSortableSpriteToDraw(spr, PAL_NONE, ti->x, ti->y, 16, 16, 7, ti->z);
554  OffsetGroundSprite(31, 9);
555  } else {
556  /* inclined foundation */
557  byte inclined = GetHighestSlopeCorner(ti->tileh) * 2 + (f == FOUNDATION_INCLINED_Y ? 1 : 0);
558 
559  AddSortableSpriteToDraw(inclined_base + inclined, PAL_NONE, ti->x, ti->y,
560  f == FOUNDATION_INCLINED_X ? 16 : 1,
561  f == FOUNDATION_INCLINED_Y ? 16 : 1,
562  TILE_HEIGHT, ti->z
563  );
564  OffsetGroundSprite(31, 9);
565  }
566  ti->z += ApplyPixelFoundationToSlope(f, &ti->tileh);
567  }
568 }
569 
570 void DoClearSquare(TileIndex tile)
571 {
572  /* If the tile can have animation and we clear it, delete it from the animated tile list. */
573  if (_tile_type_procs[GetTileType(tile)]->animate_tile_proc != nullptr) DeleteAnimatedTile(tile);
574 
575  MakeClear(tile, CLEAR_GRASS, _generating_world ? 3 : 0);
576  MarkTileDirtyByTile(tile);
577 }
578 
589 TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
590 {
591  return _tile_type_procs[GetTileType(tile)]->get_tile_track_status_proc(tile, mode, sub_mode, side);
592 }
593 
600 void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner)
601 {
602  _tile_type_procs[GetTileType(tile)]->change_tile_owner_proc(tile, old_owner, new_owner);
603 }
604 
605 void GetTileDesc(TileIndex tile, TileDesc *td)
606 {
608 }
609 
616 {
617  return _snow_line != nullptr;
618 }
619 
626 {
627  _snow_line = CallocT<SnowLine>(1);
628  _snow_line->lowest_value = 0xFF;
629  memcpy(_snow_line->table, table, sizeof(_snow_line->table));
630 
631  for (uint i = 0; i < SNOW_LINE_MONTHS; i++) {
632  for (uint j = 0; j < SNOW_LINE_DAYS; j++) {
633  _snow_line->highest_value = std::max(_snow_line->highest_value, table[i][j]);
634  _snow_line->lowest_value = std::min(_snow_line->lowest_value, table[i][j]);
635  }
636  }
637 }
638 
645 {
647 
648  YearMonthDay ymd;
649  ConvertDateToYMD(_date, &ymd);
650  return _snow_line->table[ymd.month][ymd.day];
651 }
652 
659 {
661 }
662 
669 {
671 }
672 
678 {
679  free(_snow_line);
680  _snow_line = nullptr;
681 }
682 
692 CommandCost CmdLandscapeClear(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
693 {
695  bool do_clear = false;
696  /* Test for stuff which results in water when cleared. Then add the cost to also clear the water. */
697  if ((flags & DC_FORCE_CLEAR_TILE) && HasTileWaterClass(tile) && IsTileOnWater(tile) && !IsWaterTile(tile) && !IsCoastTile(tile)) {
698  if ((flags & DC_AUTO) && GetWaterClass(tile) == WATER_CLASS_CANAL) return_cmd_error(STR_ERROR_MUST_DEMOLISH_CANAL_FIRST);
699  do_clear = true;
700  cost.AddCost(GetWaterClass(tile) == WATER_CLASS_CANAL ? _price[PR_CLEAR_CANAL] : _price[PR_CLEAR_WATER]);
701  }
702 
703  Company *c = (flags & (DC_AUTO | DC_BANKRUPT)) ? nullptr : Company::GetIfValid(_current_company);
704  if (c != nullptr && (int)GB(c->clear_limit, 16, 16) < 1) {
705  return_cmd_error(STR_ERROR_CLEARING_LIMIT_REACHED);
706  }
707 
708  const ClearedObjectArea *coa = FindClearedObject(tile);
709 
710  /* If this tile was the first tile which caused object destruction, always
711  * pass it on to the tile_type_proc. That way multiple test runs and the exec run stay consistent. */
712  if (coa != nullptr && coa->first_tile != tile) {
713  /* If this tile belongs to an object which was already cleared via another tile, pretend it has been
714  * already removed.
715  * However, we need to check stuff, which is not the same for all object tiles. (e.g. being on water or not) */
716 
717  /* If a object is removed, it leaves either bare land or water. */
718  if ((flags & DC_NO_WATER) && HasTileWaterClass(tile) && IsTileOnWater(tile)) {
719  return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
720  }
721  } else {
722  cost.AddCost(_tile_type_procs[GetTileType(tile)]->clear_tile_proc(tile, flags));
723  }
724 
725  if (flags & DC_EXEC) {
726  if (c != nullptr) c->clear_limit -= 1 << 16;
727  if (do_clear) DoClearSquare(tile);
728  }
729  return cost;
730 }
731 
742 CommandCost CmdClearArea(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
743 {
744  if (p1 >= MapSize()) return CMD_ERROR;
745 
748  CommandCost last_error = CMD_ERROR;
749  bool had_success = false;
750 
751  const Company *c = (flags & (DC_AUTO | DC_BANKRUPT)) ? nullptr : Company::GetIfValid(_current_company);
752  int limit = (c == nullptr ? INT32_MAX : GB(c->clear_limit, 16, 16));
753 
754  TileIterator *iter = HasBit(p2, 0) ? (TileIterator *)new DiagonalTileIterator(tile, p1) : new OrthogonalTileIterator(tile, p1);
755  for (; *iter != INVALID_TILE; ++(*iter)) {
756  TileIndex t = *iter;
757  CommandCost ret = DoCommand(t, 0, 0, flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR);
758  if (ret.Failed()) {
759  last_error = ret;
760 
761  /* We may not clear more tiles. */
762  if (c != nullptr && GB(c->clear_limit, 16, 16) < 1) break;
763  continue;
764  }
765 
766  had_success = true;
767  if (flags & DC_EXEC) {
768  money -= ret.GetCost();
769  if (ret.GetCost() > 0 && money < 0) {
770  _additional_cash_required = ret.GetCost();
771  delete iter;
772  return cost;
773  }
774  DoCommand(t, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
775 
776  /* draw explosion animation...
777  * Disable explosions when game is paused. Looks silly and blocks the view. */
778  if ((t == tile || t == p1) && _pause_mode == PM_UNPAUSED) {
779  /* big explosion in two corners, or small explosion for single tiles */
781  TileX(tile) == TileX(p1) && TileY(tile) == TileY(p1) ? EV_EXPLOSION_SMALL : EV_EXPLOSION_LARGE
782  );
783  }
784  } else {
785  /* When we're at the clearing limit we better bail (unneed) testing as well. */
786  if (ret.GetCost() != 0 && --limit <= 0) break;
787  }
788  cost.AddCost(ret);
789  }
790 
791  delete iter;
792  return had_success ? cost : last_error;
793 }
794 
795 
796 TileIndex _cur_tileloop_tile;
797 
802 {
804 
805  /* The pseudorandom sequence of tiles is generated using a Galois linear feedback
806  * shift register (LFSR). This allows a deterministic pseudorandom ordering, but
807  * still with minimal state and fast iteration. */
808 
809  /* Maximal length LFSR feedback terms, from 12-bit (for 64x64 maps) to 24-bit (for 4096x4096 maps).
810  * Extracted from http://www.ece.cmu.edu/~koopman/lfsr/ */
811  static const uint32 feedbacks[] = {
812  0xD8F, 0x1296, 0x2496, 0x4357, 0x8679, 0x1030E, 0x206CD, 0x403FE, 0x807B8, 0x1004B2, 0x2006A8, 0x4004B2, 0x800B87
813  };
814  static_assert(lengthof(feedbacks) == 2 * MAX_MAP_SIZE_BITS - 2 * MIN_MAP_SIZE_BITS + 1);
815  const uint32 feedback = feedbacks[MapLogX() + MapLogY() - 2 * MIN_MAP_SIZE_BITS];
816 
817  /* We update every tile every 256 ticks, so divide the map size by 2^8 = 256 */
818  uint count = 1 << (MapLogX() + MapLogY() - 8);
819 
820  TileIndex tile = _cur_tileloop_tile;
821  /* The LFSR cannot have a zeroed state. */
822  assert(tile != 0);
823 
824  /* Manually update tile 0 every 256 ticks - the LFSR never iterates over it itself. */
825  if (_tick_counter % 256 == 0) {
826  _tile_type_procs[GetTileType(0)]->tile_loop_proc(0);
827  count--;
828  }
829 
830  while (count--) {
831  _tile_type_procs[GetTileType(tile)]->tile_loop_proc(tile);
832 
833  /* Get the next tile in sequence using a Galois LFSR. */
834  tile = (tile >> 1) ^ (-(int32)(tile & 1) & feedback);
835  }
836 
837  _cur_tileloop_tile = tile;
838 }
839 
840 void InitializeLandscape()
841 {
842  for (uint y = _settings_game.construction.freeform_edges ? 1 : 0; y < MapMaxY(); y++) {
843  for (uint x = _settings_game.construction.freeform_edges ? 1 : 0; x < MapMaxX(); x++) {
844  MakeClear(TileXY(x, y), CLEAR_GRASS, 3);
845  SetTileHeight(TileXY(x, y), 0);
847  ClearBridgeMiddle(TileXY(x, y));
848  }
849  }
850 
851  for (uint x = 0; x < MapSizeX(); x++) MakeVoid(TileXY(x, MapMaxY()));
852  for (uint y = 0; y < MapSizeY(); y++) MakeVoid(TileXY(MapMaxX(), y));
853 }
854 
855 static const byte _genterrain_tbl_1[5] = { 10, 22, 33, 37, 4 };
856 static const byte _genterrain_tbl_2[5] = { 0, 0, 0, 0, 33 };
857 
858 static void GenerateTerrain(int type, uint flag)
859 {
860  uint32 r = Random();
861 
862  const Sprite *templ = GetSprite((((r >> 24) * _genterrain_tbl_1[type]) >> 8) + _genterrain_tbl_2[type] + 4845, ST_MAPGEN);
863  if (templ == nullptr) usererror("Map generator sprites could not be loaded");
864 
865  uint x = r & MapMaxX();
866  uint y = (r >> MapLogX()) & MapMaxY();
867 
868  uint edge_distance = 1 + (_settings_game.construction.freeform_edges ? 1 : 0);
869  if (x <= edge_distance || y <= edge_distance) return;
870 
871  DiagDirection direction = (DiagDirection)GB(r, 22, 2);
872  uint w = templ->width;
873  uint h = templ->height;
874 
875  if (DiagDirToAxis(direction) == AXIS_Y) Swap(w, h);
876 
877  const byte *p = templ->data;
878 
879  if ((flag & 4) != 0) {
880  uint xw = x * MapSizeY();
881  uint yw = y * MapSizeX();
882  uint bias = (MapSizeX() + MapSizeY()) * 16;
883 
884  switch (flag & 3) {
885  default: NOT_REACHED();
886  case 0:
887  if (xw + yw > MapSize() - bias) return;
888  break;
889 
890  case 1:
891  if (yw < xw + bias) return;
892  break;
893 
894  case 2:
895  if (xw + yw < MapSize() + bias) return;
896  break;
897 
898  case 3:
899  if (xw < yw + bias) return;
900  break;
901  }
902  }
903 
904  if (x + w >= MapMaxX()) return;
905  if (y + h >= MapMaxY()) return;
906 
907  TileIndex tile = TileXY(x, y);
908 
909  switch (direction) {
910  default: NOT_REACHED();
911  case DIAGDIR_NE:
912  do {
913  TileIndex tile_cur = tile;
914 
915  for (uint w_cur = w; w_cur != 0; --w_cur) {
916  if (GB(*p, 0, 4) >= TileHeight(tile_cur)) SetTileHeight(tile_cur, GB(*p, 0, 4));
917  p++;
918  tile_cur++;
919  }
920  tile += TileDiffXY(0, 1);
921  } while (--h != 0);
922  break;
923 
924  case DIAGDIR_SE:
925  do {
926  TileIndex tile_cur = tile;
927 
928  for (uint h_cur = h; h_cur != 0; --h_cur) {
929  if (GB(*p, 0, 4) >= TileHeight(tile_cur)) SetTileHeight(tile_cur, GB(*p, 0, 4));
930  p++;
931  tile_cur += TileDiffXY(0, 1);
932  }
933  tile += TileDiffXY(1, 0);
934  } while (--w != 0);
935  break;
936 
937  case DIAGDIR_SW:
938  tile += TileDiffXY(w - 1, 0);
939  do {
940  TileIndex tile_cur = tile;
941 
942  for (uint w_cur = w; w_cur != 0; --w_cur) {
943  if (GB(*p, 0, 4) >= TileHeight(tile_cur)) SetTileHeight(tile_cur, GB(*p, 0, 4));
944  p++;
945  tile_cur--;
946  }
947  tile += TileDiffXY(0, 1);
948  } while (--h != 0);
949  break;
950 
951  case DIAGDIR_NW:
952  tile += TileDiffXY(0, h - 1);
953  do {
954  TileIndex tile_cur = tile;
955 
956  for (uint h_cur = h; h_cur != 0; --h_cur) {
957  if (GB(*p, 0, 4) >= TileHeight(tile_cur)) SetTileHeight(tile_cur, GB(*p, 0, 4));
958  p++;
959  tile_cur -= TileDiffXY(0, 1);
960  }
961  tile += TileDiffXY(1, 0);
962  } while (--w != 0);
963  break;
964  }
965 }
966 
967 
968 #include "table/genland.h"
969 
970 static void CreateDesertOrRainForest()
971 {
972  TileIndex update_freq = MapSize() / 4;
973  const TileIndexDiffC *data;
974  uint max_desert_height = CeilDiv(_settings_game.construction.max_heightlevel, 4);
975 
976  for (TileIndex tile = 0; tile != MapSize(); ++tile) {
977  if ((tile % update_freq) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
978 
979  if (!IsValidTile(tile)) continue;
980 
981  for (data = _make_desert_or_rainforest_data;
982  data != endof(_make_desert_or_rainforest_data); ++data) {
983  TileIndex t = AddTileIndexDiffCWrap(tile, *data);
984  if (t != INVALID_TILE && (TileHeight(t) >= max_desert_height || IsTileType(t, MP_WATER))) break;
985  }
986  if (data == endof(_make_desert_or_rainforest_data)) {
988  }
989  }
990 
991  for (uint i = 0; i != 256; i++) {
993 
994  RunTileLoop();
995  }
996 
997  for (TileIndex tile = 0; tile != MapSize(); ++tile) {
998  if ((tile % update_freq) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
999 
1000  if (!IsValidTile(tile)) continue;
1001 
1002  for (data = _make_desert_or_rainforest_data;
1003  data != endof(_make_desert_or_rainforest_data); ++data) {
1004  TileIndex t = AddTileIndexDiffCWrap(tile, *data);
1005  if (t != INVALID_TILE && IsTileType(t, MP_CLEAR) && IsClearGround(t, CLEAR_DESERT)) break;
1006  }
1007  if (data == endof(_make_desert_or_rainforest_data)) {
1009  }
1010  }
1011 }
1012 
1019 static bool FindSpring(TileIndex tile, void *user_data)
1020 {
1021  int referenceHeight;
1022  if (!IsTileFlat(tile, &referenceHeight) || IsWaterTile(tile)) return false;
1023 
1024  /* In the tropics rivers start in the rainforest. */
1025  if (_settings_game.game_creation.landscape == LT_TROPIC && GetTropicZone(tile) != TROPICZONE_RAINFOREST) return false;
1026 
1027  /* Are there enough higher tiles to warrant a 'spring'? */
1028  uint num = 0;
1029  for (int dx = -1; dx <= 1; dx++) {
1030  for (int dy = -1; dy <= 1; dy++) {
1031  TileIndex t = TileAddWrap(tile, dx, dy);
1032  if (t != INVALID_TILE && GetTileMaxZ(t) > referenceHeight) num++;
1033  }
1034  }
1035 
1036  if (num < 4) return false;
1037 
1038  /* Are we near the top of a hill? */
1039  for (int dx = -16; dx <= 16; dx++) {
1040  for (int dy = -16; dy <= 16; dy++) {
1041  TileIndex t = TileAddWrap(tile, dx, dy);
1042  if (t != INVALID_TILE && GetTileMaxZ(t) > referenceHeight + 2) return false;
1043  }
1044  }
1045 
1046  return true;
1047 }
1048 
1055 static bool MakeLake(TileIndex tile, void *user_data)
1056 {
1057  uint height = *(uint*)user_data;
1058  if (!IsValidTile(tile) || TileHeight(tile) != height || !IsTileFlat(tile)) return false;
1059  if (_settings_game.game_creation.landscape == LT_TROPIC && GetTropicZone(tile) == TROPICZONE_DESERT) return false;
1060 
1061  for (DiagDirection d = DIAGDIR_BEGIN; d < DIAGDIR_END; d++) {
1062  TileIndex t2 = tile + TileOffsByDiagDir(d);
1063  if (IsWaterTile(t2)) {
1064  MakeRiver(tile, Random());
1065  /* Remove desert directly around the river tile. */
1066  TileIndex t = tile;
1068  return false;
1069  }
1070  }
1071 
1072  return false;
1073 }
1074 
1081 static bool FlowsDown(TileIndex begin, TileIndex end)
1082 {
1083  assert(DistanceManhattan(begin, end) == 1);
1084 
1085  int heightBegin;
1086  int heightEnd;
1087  Slope slopeBegin = GetTileSlope(begin, &heightBegin);
1088  Slope slopeEnd = GetTileSlope(end, &heightEnd);
1089 
1090  return heightEnd <= heightBegin &&
1091  /* Slope either is inclined or flat; rivers don't support other slopes. */
1092  (slopeEnd == SLOPE_FLAT || IsInclinedSlope(slopeEnd)) &&
1093  /* Slope continues, then it must be lower... or either end must be flat. */
1094  ((slopeEnd == slopeBegin && heightEnd < heightBegin) || slopeEnd == SLOPE_FLAT || slopeBegin == SLOPE_FLAT);
1095 }
1096 
1097 /* AyStar callback for checking whether we reached our destination. */
1098 static int32 River_EndNodeCheck(const AyStar *aystar, const OpenListNode *current)
1099 {
1100  return current->path.node.tile == *(TileIndex*)aystar->user_target ? AYSTAR_FOUND_END_NODE : AYSTAR_DONE;
1101 }
1102 
1103 /* AyStar callback for getting the cost of the current node. */
1104 static int32 River_CalculateG(AyStar *aystar, AyStarNode *current, OpenListNode *parent)
1105 {
1107 }
1108 
1109 /* AyStar callback for getting the estimated cost to the destination. */
1110 static int32 River_CalculateH(AyStar *aystar, AyStarNode *current, OpenListNode *parent)
1111 {
1112  return DistanceManhattan(*(TileIndex*)aystar->user_target, current->tile);
1113 }
1114 
1115 /* AyStar callback for getting the neighbouring nodes of the given node. */
1116 static void River_GetNeighbours(AyStar *aystar, OpenListNode *current)
1117 {
1118  TileIndex tile = current->path.node.tile;
1119 
1120  aystar->num_neighbours = 0;
1121  for (DiagDirection d = DIAGDIR_BEGIN; d < DIAGDIR_END; d++) {
1122  TileIndex t2 = tile + TileOffsByDiagDir(d);
1123  if (IsValidTile(t2) && FlowsDown(tile, t2)) {
1124  aystar->neighbours[aystar->num_neighbours].tile = t2;
1125  aystar->neighbours[aystar->num_neighbours].direction = INVALID_TRACKDIR;
1126  aystar->num_neighbours++;
1127  }
1128  }
1129 }
1130 
1131 /* AyStar callback when an route has been found. */
1132 static void River_FoundEndNode(AyStar *aystar, OpenListNode *current)
1133 {
1134  for (PathNode *path = &current->path; path != nullptr; path = path->parent) {
1135  TileIndex tile = path->node.tile;
1136  if (!IsWaterTile(tile)) {
1137  MakeRiver(tile, Random());
1138  /* Remove desert directly around the river tile. */
1140  }
1141  }
1142 }
1143 
1144 static const uint RIVER_HASH_SIZE = 8;
1145 
1152 static uint River_Hash(uint tile, uint dir)
1153 {
1154  return GB(TileHash(TileX(tile), TileY(tile)), 0, RIVER_HASH_SIZE);
1155 }
1156 
1162 static void BuildRiver(TileIndex begin, TileIndex end)
1163 {
1164  AyStar finder = {};
1165  finder.CalculateG = River_CalculateG;
1166  finder.CalculateH = River_CalculateH;
1167  finder.GetNeighbours = River_GetNeighbours;
1168  finder.EndNodeCheck = River_EndNodeCheck;
1169  finder.FoundEndNode = River_FoundEndNode;
1170  finder.user_target = &end;
1171 
1172  finder.Init(River_Hash, 1 << RIVER_HASH_SIZE);
1173 
1174  AyStarNode start;
1175  start.tile = begin;
1176  start.direction = INVALID_TRACKDIR;
1177  finder.AddStartNode(&start, 0);
1178  finder.Main();
1179  finder.Free();
1180 }
1181 
1188 static bool FlowRiver(TileIndex spring, TileIndex begin)
1189 {
1190 # define SET_MARK(x) marks.insert(x)
1191 # define IS_MARKED(x) (marks.find(x) != marks.end())
1192 
1193  uint height = TileHeight(begin);
1194  if (IsWaterTile(begin)) return DistanceManhattan(spring, begin) > _settings_game.game_creation.min_river_length;
1195 
1196  std::set<TileIndex> marks;
1197  SET_MARK(begin);
1198 
1199  /* Breadth first search for the closest tile we can flow down to. */
1200  std::list<TileIndex> queue;
1201  queue.push_back(begin);
1202 
1203  bool found = false;
1204  uint count = 0; // Number of tiles considered; to be used for lake location guessing.
1205  TileIndex end;
1206  do {
1207  end = queue.front();
1208  queue.pop_front();
1209 
1210  uint height2 = TileHeight(end);
1211  if (IsTileFlat(end) && (height2 < height || (height2 == height && IsWaterTile(end)))) {
1212  found = true;
1213  break;
1214  }
1215 
1216  for (DiagDirection d = DIAGDIR_BEGIN; d < DIAGDIR_END; d++) {
1217  TileIndex t2 = end + TileOffsByDiagDir(d);
1218  if (IsValidTile(t2) && !IS_MARKED(t2) && FlowsDown(end, t2)) {
1219  SET_MARK(t2);
1220  count++;
1221  queue.push_back(t2);
1222  }
1223  }
1224  } while (!queue.empty());
1225 
1226  if (found) {
1227  /* Flow further down hill. */
1228  found = FlowRiver(spring, end);
1229  } else if (count > 32) {
1230  /* Maybe we can make a lake. Find the Nth of the considered tiles. */
1231  TileIndex lakeCenter = 0;
1232  int i = RandomRange(count - 1) + 1;
1233  std::set<TileIndex>::const_iterator cit = marks.begin();
1234  while (--i) cit++;
1235  lakeCenter = *cit;
1236 
1237  if (IsValidTile(lakeCenter) &&
1238  /* A river, or lake, can only be built on flat slopes. */
1239  IsTileFlat(lakeCenter) &&
1240  /* We want the lake to be built at the height of the river. */
1241  TileHeight(begin) == TileHeight(lakeCenter) &&
1242  /* We don't want the lake at the entry of the valley. */
1243  lakeCenter != begin &&
1244  /* We don't want lakes in the desert. */
1245  (_settings_game.game_creation.landscape != LT_TROPIC || GetTropicZone(lakeCenter) != TROPICZONE_DESERT) &&
1246  /* We only want a lake if the river is long enough. */
1248  end = lakeCenter;
1249  MakeRiver(lakeCenter, Random());
1250  /* Remove desert directly around the river tile. */
1252  lakeCenter = end;
1253  uint range = RandomRange(8) + 3;
1254  CircularTileSearch(&lakeCenter, range, MakeLake, &height);
1255  /* Call the search a second time so artefacts from going circular in one direction get (mostly) hidden. */
1256  lakeCenter = end;
1257  CircularTileSearch(&lakeCenter, range, MakeLake, &height);
1258  found = true;
1259  }
1260  }
1261 
1262  marks.clear();
1263  if (found) BuildRiver(begin, end);
1264  return found;
1265 }
1266 
1270 static void CreateRivers()
1271 {
1273  if (amount == 0) return;
1274 
1276  SetGeneratingWorldProgress(GWP_RIVER, wells + 256 / 64); // Include the tile loop calls below.
1277 
1278  for (; wells != 0; wells--) {
1280  for (int tries = 0; tries < 128; tries++) {
1281  TileIndex t = RandomTile();
1282  if (!CircularTileSearch(&t, 8, FindSpring, nullptr)) continue;
1283  if (FlowRiver(t, t)) break;
1284  }
1285  }
1286 
1287  /* Run tile loop to update the ground density. */
1288  for (uint i = 0; i != 256; i++) {
1289  if (i % 64 == 0) IncreaseGeneratingWorldProgress(GWP_RIVER);
1290  RunTileLoop();
1291  }
1292 }
1293 
1294 void GenerateLandscape(byte mode)
1295 {
1297  enum GenLandscapeSteps {
1298  GLS_HEIGHTMAP = 3,
1299  GLS_TERRAGENESIS = 5,
1300  GLS_ORIGINAL = 2,
1301  GLS_TROPIC = 12,
1302  GLS_OTHER = 0,
1303  };
1304  uint steps = (_settings_game.game_creation.landscape == LT_TROPIC) ? GLS_TROPIC : GLS_OTHER;
1305 
1306  if (mode == GWM_HEIGHTMAP) {
1307  SetGeneratingWorldProgress(GWP_LANDSCAPE, steps + GLS_HEIGHTMAP);
1311  SetGeneratingWorldProgress(GWP_LANDSCAPE, steps + GLS_TERRAGENESIS);
1313  } else {
1314  SetGeneratingWorldProgress(GWP_LANDSCAPE, steps + GLS_ORIGINAL);
1316  for (uint x = 0; x < MapSizeX(); x++) MakeVoid(TileXY(x, 0));
1317  for (uint y = 0; y < MapSizeY(); y++) MakeVoid(TileXY(0, y));
1318  }
1320  case LT_ARCTIC: {
1321  uint32 r = Random();
1322 
1323  for (uint i = ScaleByMapSize(GB(r, 0, 7) + 950); i != 0; --i) {
1324  GenerateTerrain(2, 0);
1325  }
1326 
1327  uint flag = GB(r, 7, 2) | 4;
1328  for (uint i = ScaleByMapSize(GB(r, 9, 7) + 450); i != 0; --i) {
1329  GenerateTerrain(4, flag);
1330  }
1331  break;
1332  }
1333 
1334  case LT_TROPIC: {
1335  uint32 r = Random();
1336 
1337  for (uint i = ScaleByMapSize(GB(r, 0, 7) + 170); i != 0; --i) {
1338  GenerateTerrain(0, 0);
1339  }
1340 
1341  uint flag = GB(r, 7, 2) | 4;
1342  for (uint i = ScaleByMapSize(GB(r, 9, 8) + 1700); i != 0; --i) {
1343  GenerateTerrain(0, flag);
1344  }
1345 
1346  flag ^= 2;
1347 
1348  for (uint i = ScaleByMapSize(GB(r, 17, 7) + 410); i != 0; --i) {
1349  GenerateTerrain(3, flag);
1350  }
1351  break;
1352  }
1353 
1354  default: {
1355  uint32 r = Random();
1356 
1358  uint i = ScaleByMapSize(GB(r, 0, 7) + (3 - _settings_game.difficulty.quantity_sea_lakes) * 256 + 100);
1359  for (; i != 0; --i) {
1360  /* Make sure we do not overflow. */
1361  GenerateTerrain(Clamp(_settings_game.difficulty.terrain_type, 0, 3), 0);
1362  }
1363  break;
1364  }
1365  }
1366  }
1367 
1368  /* Do not call IncreaseGeneratingWorldProgress() before FixSlopes(),
1369  * it allows screen redraw. Drawing of broken slopes crashes the game */
1370  FixSlopes();
1372  ConvertGroundTilesIntoWaterTiles();
1374 
1375  if (_settings_game.game_creation.landscape == LT_TROPIC) CreateDesertOrRainForest();
1376 
1377  CreateRivers();
1378 }
1379 
1380 void OnTick_Town();
1381 void OnTick_Trees();
1382 void OnTick_Station();
1383 void OnTick_Industry();
1384 
1385 void OnTick_Companies();
1386 void OnTick_LinkGraph();
1387 
1388 void CallLandscapeTick()
1389 {
1390  {
1392 
1393  OnTick_Town();
1394  OnTick_Trees();
1395  OnTick_Station();
1396  OnTick_Industry();
1397  }
1398 
1399  OnTick_Companies();
1400  OnTick_LinkGraph();
1401 }
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:300
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:1001
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:41
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
YearMonthDay::day
Day day
Day (1..31)
Definition: date_type.h:106
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:78
TROPICZONE_DESERT
@ TROPICZONE_DESERT
Tile is desert.
Definition: tile_type.h:71
AddTileIndexDiffCWrap
static TileIndex AddTileIndexDiffCWrap(TileIndex tile, TileIndexDiffC diff)
Add a TileIndexDiffC to a TileIndex and returns the new one.
Definition: map_func.h:300
GenerateLandscape
void GenerateLandscape(byte mode)
Definition: landscape.cpp:1294
DiagonalTileIterator
Iterator to iterate over a diagonal area of the map.
Definition: tilearea_type.h:188
AYSTAR_DONE
@ AYSTAR_DONE
Not an end-tile, or wrong direction.
Definition: aystar.h:32
DoCommand
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
Definition: command.cpp:450
TileOffsByDiagDir
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition: map_func.h:341
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:388
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:100
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
LoadHeightmap
void LoadHeightmap(DetailedFileType dft, const char *filename)
Load a heightmap from file and change the map in his current dimensions to a landscape representing t...
Definition: heightmap.cpp:489
HasTileWaterClass
static bool HasTileWaterClass(TileIndex t)
Checks whether the tile has an waterclass associated.
Definition: water_map.h:95
command_func.h
_tile_type_procs
const TileTypeProcs *const _tile_type_procs[16]
Tile callback functions for each type of tile.
Definition: landscape.cpp:60
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:340
CMD_ERROR
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition: command_func.h:23
ConstructionSettings::max_heightlevel
uint8 max_heightlevel
maximum allowed heightlevel
Definition: settings_type.h:307
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:295
SLOPE_SEN
@ SLOPE_SEN
south, east and north corner are raised
Definition: slope_type.h:64
Sprite::data
byte data[]
Sprite data.
Definition: spritecache.h:22
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:1270
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:343
GetSlopeZInCorner
int GetSlopeZInCorner(Slope tileh, Corner corner)
Determine the Z height of a corner relative to TileZ.
Definition: landscape.cpp:375
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:72
GameSettings::difficulty
DifficultySettings difficulty
settings related to the difficulty
Definition: settings_type.h:549
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
IsHalftileSlope
static bool IsHalftileSlope(Slope s)
Checks for non-continuous slope on halftile foundations.
Definition: slope_func.h:47
CLEAR_GRASS
@ CLEAR_GRASS
0-3
Definition: clear_map.h:20
void_map.h
IsClearGround
static bool IsClearGround(TileIndex t, ClearGround ct)
Set the type of clear tile.
Definition: clear_map.h:71
Sprite::height
uint16 height
Height of the sprite.
Definition: spritecache.h:18
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:205
SPR_HALFTILE_FOUNDATION_BASE
static const SpriteID SPR_HALFTILE_FOUNDATION_BASE
Halftile foundations.
Definition: sprites.h:204
GetPartialPixelZ
uint GetPartialPixelZ(int x, int y, Slope corners)
Determines height at given coordinate of a slope.
Definition: landscape.cpp:215
saveload.h
TILE_SIZE
static const uint TILE_SIZE
Tile size in world coordinates.
Definition: tile_type.h:13
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:351
TileY
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:215
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
EV_EXPLOSION_SMALL
@ EV_EXPLOSION_SMALL
Various explosions.
Definition: effectvehicle_func.h:24
SLOPE_EW
@ SLOPE_EW
east and west corner are raised
Definition: slope_type.h:59
SLOPE_STEEP_S
@ SLOPE_STEEP_S
a steep slope falling to north (from south)
Definition: slope_type.h:67
TransportType
TransportType
Available types of transport.
Definition: transport_type.h:19
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:348
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
DoCommandFlag
DoCommandFlag
List of flags for a command.
Definition: command_type.h:346
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:1392
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
CmdClearArea
CommandCost CmdClearArea(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Clear a big piece of landscape.
Definition: landscape.cpp:742
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition: settings_type.h:550
GetTileTrackStatus
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
Definition: landscape.cpp:589
effectvehicle_func.h
SLOPE_NW
@ SLOPE_NW
north and west corner are raised
Definition: slope_type.h:55
PM_UNPAUSED
@ PM_UNPAUSED
A normal unpaused game.
Definition: openttd.h:59
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:87
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:130
SLOPE_FLAT
@ SLOPE_FLAT
a flat tile
Definition: slope_type.h:49
GWP_LANDSCAPE
@ GWP_LANDSCAPE
Create the landscape.
Definition: genworld.h:69
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:600
OnTick_Companies
void OnTick_Companies()
Called every tick for updating some company info.
Definition: company_cmd.cpp:700
OrthogonalTileIterator
Iterator to iterate over a tile area (rectangle) of the map.
Definition: tilearea_type.h:138
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:1019
AXIS_Y
@ AXIS_Y
The y axis.
Definition: direction_type.h:125
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:33
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:46
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:23
GetSnowLine
byte GetSnowLine()
Get the current snow line, either variable or static.
Definition: landscape.cpp:644
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
_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_ELEVATED
@ SLOPE_ELEVATED
bit mask containing all 'simple' slopes
Definition: slope_type.h:61
YearMonthDay::month
Month month
Month (0..11)
Definition: date_type.h:105
DifficultySettings::terrain_type
byte terrain_type
the mountainousness of the landscape
Definition: settings_type.h:65
PathNode
A path of nodes.
Definition: aystar.h:45
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:99
SLOPE_NWS
@ SLOPE_NWS
north, west and south corner are raised
Definition: slope_type.h:62
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:188
_slope_to_sprite_offset
const byte _slope_to_sprite_offset[32]
landscape slope => sprite
MP_WATER
@ MP_WATER
Water tile.
Definition: tile_type.h:47
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:159
Corner
Corner
Enumeration of tile corners.
Definition: slope_type.h:22
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:47
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:80
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
_tick_counter
uint16 _tick_counter
Ever incrementing (and sometimes wrapping) tick counter for setting off various events.
Definition: date.cpp:30
GameCreationSettings::snow_line_height
byte snow_line_height
the configured snow line height
Definition: settings_type.h:289
safeguards.h
HighestSnowLine
byte HighestSnowLine()
Get the highest possible snow line height, either variable or static.
Definition: landscape.cpp:658
SLOPE_STEEP
@ SLOPE_STEEP
indicates the slope is steep
Definition: slope_type.h:54
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:319
CommandCost::GetCost
Money GetCost() const
The costs as made up to this moment.
Definition: command_type.h:82
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:66
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:668
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:528
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
SLOPE_SW
@ SLOPE_SW
south and west corner are raised
Definition: slope_type.h:56
_snow_line
static SnowLine * _snow_line
Description of the snow line throughout the year.
Definition: landscape.cpp:88
SLOPE_STEEP_E
@ SLOPE_STEEP_E
a steep slope falling to west (from east)
Definition: slope_type.h:68
Slope
Slope
Enumeration for the slope-type.
Definition: slope_type.h:48
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:422
FlowRiver
static bool FlowRiver(TileIndex spring, TileIndex begin)
Try to flow the river down from a given begin.
Definition: landscape.cpp:1188
OffsetGroundSprite
void OffsetGroundSprite(int x, int y)
Called when a foundation has been drawn for the current tile.
Definition: viewport.cpp:588
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:393
date_func.h
CommandCost::AddCost
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
Definition: command_type.h:62
WATER_CLASS_CANAL
@ WATER_CLASS_CANAL
Canal.
Definition: water_map.h:49
stdafx.h
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:354
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:103
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:660
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:625
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
DrawFoundation
void DrawFoundation(TileInfo *ti, Foundation f)
Draw foundation f at tile ti.
Definition: landscape.cpp:470
_generating_world
bool _generating_world
Whether we are generating the map or not.
Definition: genworld.cpp:60
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
BuildRiver
static void BuildRiver(TileIndex begin, TileIndex end)
Actually build the river between the begin and end tiles using AyStar.
Definition: landscape.cpp:1162
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:47
SLOPE_N
@ SLOPE_N
the north corner of the tile is raised
Definition: slope_type.h:53
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:106
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:359
MapMaxY
static uint MapMaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
Definition: map_func.h:111
FindClearedObject
ClearedObjectArea * FindClearedObject(TileIndex tile)
Find the entry in _cleared_object_areas which occupies a certain tile.
Definition: object_cmd.cpp:456
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:48
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:1081
SLOPE_WSE
@ SLOPE_WSE
west, south and east corner are raised
Definition: slope_type.h:63
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::amount_of_rivers
byte amount_of_rivers
the amount of rivers
Definition: settings_type.h:302
GameCreationSettings::land_generator
byte land_generator
the landscape generator
Definition: settings_type.h:287
IsWaterTile
static bool IsWaterTile(TileIndex t)
Is it a water tile with plain water?
Definition: water_map.h:184
SetGeneratingWorldProgress
void SetGeneratingWorldProgress(GenWorldProgress cls, uint total)
Set the total of a stage of the world generation.
Definition: genworld_gui.cpp:1378
endof
#define endof(x)
Get the end element of an fixed size array.
Definition: stdafx.h:375
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:62
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:1985
CmdLandscapeClear
CommandCost CmdLandscapeClear(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Clear a piece of landscape.
Definition: landscape.cpp:692
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:615
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:349
SLOPE_S
@ SLOPE_S
the south corner of the tile is raised
Definition: slope_type.h:51
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
MapMaxX
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Definition: map_func.h:102
TILE_ADDXY
#define TILE_ADDXY(tile, x, y)
Adds a given offset to a tile.
Definition: map_func.h:258
SLOPE_W
@ SLOPE_W
the west corner of the tile is raised
Definition: slope_type.h:50
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:367
YearMonthDay
Data structure to convert between Date and triplet (year, month, and day).
Definition: date_type.h:103
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:357
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:16
OverflowSafeInt< int64, INT64_MAX, INT64_MIN >
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:1055
INVALID_TILE
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:83
GWP_RIVER
@ GWP_RIVER
Create the rivers.
Definition: genworld.h:70
GameCreationSettings::river_route_random
byte river_route_random
the amount of randomicity for the route finding
Definition: settings_type.h:301
SLOPE_STEEP_W
@ SLOPE_STEEP_W
a steep slope falling to east (from west)
Definition: slope_type.h:66
CeilDiv
static uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
Definition: math_func.hpp:254
TileInfo::tile
TileIndex tile
Tile index.
Definition: tile_cmd.h:46
GameSettings::construction
ConstructionSettings construction
construction of things in-game
Definition: settings_type.h:551
IsInclinedSlope
static bool IsInclinedSlope(Slope s)
Tests if a specific slope is an inclined slope.
Definition: slope_func.h:228
SLOPE_NS
@ SLOPE_NS
north and south corner are raised
Definition: slope_type.h:60
ClearSnowLine
void ClearSnowLine()
Clear the variable snow line table and free the memory.
Definition: landscape.cpp:677
TILE_PIXELS
static const uint TILE_PIXELS
Pixel distance between tile columns/rows in #ZOOM_LVL_BASE.
Definition: tile_type.h:15
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:341
TROPICZONE_NORMAL
@ TROPICZONE_NORMAL
Normal tropiczone.
Definition: tile_type.h:70
River_Hash
static uint River_Hash(uint tile, uint dir)
Simple hash function for river tiles to be used by AyStar.
Definition: landscape.cpp:1152
Swap
static void Swap(T &a, T &b)
Type safe swap operation.
Definition: math_func.hpp:215
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:162
CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY
static const uint CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY
Value for custom sea level in difficulty settings.
Definition: genworld.h:45
free
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: stdafx.h:454
_tile_type_road_procs
const TileTypeProcs _tile_type_road_procs
Tile callback functions for road tiles.
Definition: landscape.cpp:45
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:110
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:204
SLOPE_SE
@ SLOPE_SE
south and east corner are raised
Definition: slope_type.h:57
Sprite
Data structure describing a sprite.
Definition: spritecache.h:17
SLOPE_ENW
@ SLOPE_ENW
east, north and west corner are raised
Definition: slope_type.h:65
MapLogY
static uint MapLogY()
Logarithm of the map size along the y side.
Definition: map_func.h:62
SLOPE_NE
@ SLOPE_NE
north and east corner are raised
Definition: slope_type.h:58
IsLeveledFoundation
static bool IsLeveledFoundation(Foundation f)
Tests if the foundation is a leveled foundation.
Definition: slope_func.h:298
GetHalftileFoundationCorner
static Corner GetHalftileFoundationCorner(Foundation f)
Returns the halftile corner of a halftile-foundation.
Definition: slope_func.h:333
SLOPE_E
@ SLOPE_E
the east corner of the tile is raised
Definition: slope_type.h:52
ST_MAPGEN
@ ST_MAPGEN
Special sprite for the map generator.
Definition: gfx_type.h:303
CMD_LANDSCAPE_CLEAR
@ CMD_LANDSCAPE_CLEAR
demolish a tile
Definition: command_type.h:180
MakeRiver
static void MakeRiver(TileIndex t, uint8 random_bits)
Make a river tile.
Definition: water_map.h:424
RIVER_HASH_SIZE
static const uint RIVER_HASH_SIZE
The number of bits the hash for river finding should have.
Definition: landscape.cpp:1144
RiverModifyDesertZone
bool RiverModifyDesertZone(TileIndex tile, void *data)
Callback to create non-desert around a river tile.
Definition: water_cmd.cpp:429
SLOPE_STEEP_N
@ SLOPE_STEEP_N
a steep slope falling to south (from north)
Definition: slope_type.h:69
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:801
SNOW_LINE_MONTHS
static const uint SNOW_LINE_MONTHS
Number of months in the snow line table.
Definition: landscape.h:16