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