OpenTTD Source  1.11.2
tree_cmd.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 
10 #include "stdafx.h"
11 #include "clear_map.h"
12 #include "landscape.h"
13 #include "tree_map.h"
14 #include "viewport_func.h"
15 #include "command_func.h"
16 #include "town.h"
17 #include "genworld.h"
18 #include "clear_func.h"
19 #include "company_func.h"
20 #include "sound_func.h"
21 #include "water.h"
22 #include "company_base.h"
23 #include "core/random_func.hpp"
24 #include "newgrf_generic.h"
25 
26 #include "table/strings.h"
27 #include "table/tree_land.h"
28 #include "table/clear_land.h"
29 
30 #include "safeguards.h"
31 
37 enum TreePlacer {
41 };
42 
49 };
50 
53 
54 static const uint16 DEFAULT_TREE_STEPS = 1000;
55 static const uint16 DEFAULT_RAINFOREST_TREE_STEPS = 15000;
56 static const uint16 EDITOR_TREE_DIV = 5;
57 
66 static bool CanPlantTreesOnTile(TileIndex tile, bool allow_desert)
67 {
68  switch (GetTileType(tile)) {
69  case MP_WATER:
70  return !IsBridgeAbove(tile) && IsCoast(tile) && !IsSlopeWithOneCornerRaised(GetTileSlope(tile));
71 
72  case MP_CLEAR:
73  return !IsBridgeAbove(tile) && !IsClearGround(tile, CLEAR_FIELDS) && GetRawClearGround(tile) != CLEAR_ROCKS &&
74  (allow_desert || !IsClearGround(tile, CLEAR_DESERT));
75 
76  default: return false;
77  }
78 }
79 
91 static void PlantTreesOnTile(TileIndex tile, TreeType treetype, uint count, uint growth)
92 {
93  assert(treetype != TREE_INVALID);
94  assert(CanPlantTreesOnTile(tile, true));
95 
96  TreeGround ground;
97  uint density = 3;
98 
99  switch (GetTileType(tile)) {
100  case MP_WATER:
101  ground = TREE_GROUND_SHORE;
102  break;
103 
104  case MP_CLEAR:
105  switch (GetClearGround(tile)) {
106  case CLEAR_GRASS: ground = TREE_GROUND_GRASS; break;
107  case CLEAR_ROUGH: ground = TREE_GROUND_ROUGH; break;
109  default: ground = TREE_GROUND_SNOW_DESERT; break;
110  }
111  if (GetClearGround(tile) != CLEAR_ROUGH) density = GetClearDensity(tile);
112  break;
113 
114  default: NOT_REACHED();
115  }
116 
117  MakeTree(tile, treetype, count, growth, ground, density);
118 }
119 
131 static TreeType GetRandomTreeType(TileIndex tile, uint seed)
132 {
134  case LT_TEMPERATE:
135  return (TreeType)(seed * TREE_COUNT_TEMPERATE / 256 + TREE_TEMPERATE);
136 
137  case LT_ARCTIC:
138  return (TreeType)(seed * TREE_COUNT_SUB_ARCTIC / 256 + TREE_SUB_ARCTIC);
139 
140  case LT_TROPIC:
141  switch (GetTropicZone(tile)) {
143  case TROPICZONE_DESERT: return (TreeType)((seed > 12) ? TREE_INVALID : TREE_CACTUS);
144  default: return (TreeType)(seed * TREE_COUNT_RAINFOREST / 256 + TREE_RAINFOREST);
145  }
146 
147  default:
148  return (TreeType)(seed * TREE_COUNT_TOYLAND / 256 + TREE_TOYLAND);
149  }
150 }
151 
161 static void PlaceTree(TileIndex tile, uint32 r)
162 {
163  TreeType tree = GetRandomTreeType(tile, GB(r, 24, 8));
164 
165  if (tree != TREE_INVALID) {
166  PlantTreesOnTile(tile, tree, GB(r, 22, 2), std::min<byte>(GB(r, 16, 3), 6));
167  MarkTileDirtyByTile(tile);
168 
169  /* Rerandomize ground, if neither snow nor shore */
170  TreeGround ground = GetTreeGround(tile);
171  if (ground != TREE_GROUND_SNOW_DESERT && ground != TREE_GROUND_ROUGH_SNOW && ground != TREE_GROUND_SHORE) {
172  SetTreeGroundDensity(tile, (TreeGround)GB(r, 28, 1), 3);
173  }
174 
175  /* Set the counter to a random start value */
176  SetTreeCounter(tile, (TreeGround)GB(r, 24, 4));
177  }
178 }
179 
186 static void PlaceTreeGroups(uint num_groups)
187 {
188  do {
189  TileIndex center_tile = RandomTile();
190 
191  for (uint i = 0; i < DEFAULT_TREE_STEPS; i++) {
192  uint32 r = Random();
193  int x = GB(r, 0, 5) - 16;
194  int y = GB(r, 8, 5) - 16;
195  uint dist = abs(x) + abs(y);
196  TileIndex cur_tile = TileAddWrap(center_tile, x, y);
197 
199 
200  if (cur_tile != INVALID_TILE && dist <= 13 && CanPlantTreesOnTile(cur_tile, true)) {
201  PlaceTree(cur_tile, r);
202  }
203  }
204 
205  } while (--num_groups);
206 }
207 
217 static void PlaceTreeAtSameHeight(TileIndex tile, int height)
218 {
219  for (uint i = 0; i < DEFAULT_TREE_STEPS; i++) {
220  uint32 r = Random();
221  int x = GB(r, 0, 5) - 16;
222  int y = GB(r, 8, 5) - 16;
223  TileIndex cur_tile = TileAddWrap(tile, x, y);
224  if (cur_tile == INVALID_TILE) continue;
225 
226  /* Keep in range of the existing tree */
227  if (abs(x) + abs(y) > 16) continue;
228 
229  /* Clear tile, no farm-tiles or rocks */
230  if (!CanPlantTreesOnTile(cur_tile, true)) continue;
231 
232  /* Not too much height difference */
233  if (Delta(GetTileZ(cur_tile), height) > 2) continue;
234 
235  /* Place one tree and quit */
236  PlaceTree(cur_tile, r);
237  break;
238  }
239 }
240 
247 {
248  int i, j, ht;
249 
251  if (_game_mode == GM_EDITOR) i /= EDITOR_TREE_DIV;
252  do {
253  uint32 r = Random();
254  TileIndex tile = RandomTileSeed(r);
255 
257 
258  if (CanPlantTreesOnTile(tile, true)) {
259  PlaceTree(tile, r);
261 
262  /* Place a number of trees based on the tile height.
263  * This gives a cool effect of multiple trees close together.
264  * It is almost real life ;) */
265  ht = GetTileZ(tile);
266  /* The higher we get, the more trees we plant */
267  j = GetTileZ(tile) * 2;
268  /* Above snowline more trees! */
269  if (_settings_game.game_creation.landscape == LT_ARCTIC && ht > GetSnowLine()) j *= 3;
270  while (j--) {
271  PlaceTreeAtSameHeight(tile, ht);
272  }
273  }
274  } while (--i);
275 
276  /* place extra trees at rainforest area */
277  if (_settings_game.game_creation.landscape == LT_TROPIC) {
279  if (_game_mode == GM_EDITOR) i /= EDITOR_TREE_DIV;
280 
281  do {
282  uint32 r = Random();
283  TileIndex tile = RandomTileSeed(r);
284 
286 
287  if (GetTropicZone(tile) == TROPICZONE_RAINFOREST && CanPlantTreesOnTile(tile, false)) {
288  PlaceTree(tile, r);
289  }
290  } while (--i);
291  }
292 }
293 
305 uint PlaceTreeGroupAroundTile(TileIndex tile, TreeType treetype, uint radius, uint count)
306 {
307  assert(treetype < TREE_TOYLAND + TREE_COUNT_TOYLAND);
308  const bool allow_desert = treetype == TREE_CACTUS;
309  uint planted = 0;
310 
311  for (; count > 0; count--) {
312  /* Simple quasi-normal distribution with range [-radius; radius) */
313  auto mkcoord = [&]() -> int32 {
314  const uint32 rand = InteractiveRandom();
315  const int32 dist = GB<int32>(rand, 0, 8) + GB<int32>(rand, 8, 8) + GB<int32>(rand, 16, 8) + GB<int32>(rand, 24, 8);
316  const int32 scu = dist * radius / 512;
317  return scu - radius;
318  };
319  const int32 xofs = mkcoord();
320  const int32 yofs = mkcoord();
321  const TileIndex tile_to_plant = TileAddWrap(tile, xofs, yofs);
322  if (tile_to_plant != INVALID_TILE) {
323  if (IsTileType(tile_to_plant, MP_TREES) && GetTreeCount(tile_to_plant) < 4) {
324  AddTreeCount(tile_to_plant, 1);
325  SetTreeGrowth(tile_to_plant, 0);
326  MarkTileDirtyByTile(tile_to_plant, 0);
327  planted++;
328  } else if (CanPlantTreesOnTile(tile_to_plant, allow_desert)) {
329  PlantTreesOnTile(tile_to_plant, treetype, 0, 3);
330  MarkTileDirtyByTile(tile_to_plant, 0);
331  planted++;
332  }
333  }
334  }
335 
336  return planted;
337 }
338 
346 {
347  uint i, total;
348 
350 
352  case TP_ORIGINAL: i = _settings_game.game_creation.landscape == LT_ARCTIC ? 15 : 6; break;
353  case TP_IMPROVED: i = _settings_game.game_creation.landscape == LT_ARCTIC ? 4 : 2; break;
354  default: NOT_REACHED();
355  }
356 
359  total *= i;
360  uint num_groups = (_settings_game.game_creation.landscape != LT_TOYLAND) ? ScaleByMapSize(GB(Random(), 0, 5) + 25) : 0;
361  total += num_groups * DEFAULT_TREE_STEPS;
363 
364  if (num_groups != 0) PlaceTreeGroups(num_groups);
365 
366  for (; i != 0; i--) {
368  }
369 }
370 
380 CommandCost CmdPlantTree(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
381 {
384  const byte tree_to_plant = GB(p1, 0, 8); // We cannot use Extract as min and max are climate specific.
385 
386  if (p2 >= MapSize()) return CMD_ERROR;
387  /* Check the tree type within the current climate */
388  if (tree_to_plant != TREE_INVALID && !IsInsideBS(tree_to_plant, _tree_base_by_landscape[_settings_game.game_creation.landscape], _tree_count_by_landscape[_settings_game.game_creation.landscape])) return CMD_ERROR;
389 
390  Company *c = (_game_mode != GM_EDITOR) ? Company::GetIfValid(_current_company) : nullptr;
391  int limit = (c == nullptr ? INT32_MAX : GB(c->tree_limit, 16, 16));
392 
393  TileArea ta(tile, p2);
394  TILE_AREA_LOOP(tile, ta) {
395  switch (GetTileType(tile)) {
396  case MP_TREES:
397  /* no more space for trees? */
398  if (GetTreeCount(tile) == 4) {
399  msg = STR_ERROR_TREE_ALREADY_HERE;
400  continue;
401  }
402 
403  /* Test tree limit. */
404  if (--limit < 1) {
405  msg = STR_ERROR_TREE_PLANT_LIMIT_REACHED;
406  break;
407  }
408 
409  if (flags & DC_EXEC) {
410  AddTreeCount(tile, 1);
411  MarkTileDirtyByTile(tile);
412  if (c != nullptr) c->tree_limit -= 1 << 16;
413  }
414  /* 2x as expensive to add more trees to an existing tile */
415  cost.AddCost(_price[PR_BUILD_TREES] * 2);
416  break;
417 
418  case MP_WATER:
419  if (!IsCoast(tile) || IsSlopeWithOneCornerRaised(GetTileSlope(tile))) {
420  msg = STR_ERROR_CAN_T_BUILD_ON_WATER;
421  continue;
422  }
423  FALLTHROUGH;
424 
425  case MP_CLEAR: {
426  if (IsBridgeAbove(tile)) {
427  msg = STR_ERROR_SITE_UNSUITABLE;
428  continue;
429  }
430 
431  TreeType treetype = (TreeType)tree_to_plant;
432  /* Be a bit picky about which trees go where. */
433  if (_settings_game.game_creation.landscape == LT_TROPIC && treetype != TREE_INVALID && (
434  /* No cacti outside the desert */
435  (treetype == TREE_CACTUS && GetTropicZone(tile) != TROPICZONE_DESERT) ||
436  /* No rain forest trees outside the rain forest, except in the editor mode where it makes those tiles rain forest tile */
437  (IsInsideMM(treetype, TREE_RAINFOREST, TREE_CACTUS) && GetTropicZone(tile) != TROPICZONE_RAINFOREST && _game_mode != GM_EDITOR) ||
438  /* And no subtropical trees in the desert/rain forest */
440  msg = STR_ERROR_TREE_WRONG_TERRAIN_FOR_TREE_TYPE;
441  continue;
442  }
443 
444  /* Test tree limit. */
445  if (--limit < 1) {
446  msg = STR_ERROR_TREE_PLANT_LIMIT_REACHED;
447  break;
448  }
449 
450  if (IsTileType(tile, MP_CLEAR)) {
451  /* Remove fields or rocks. Note that the ground will get barrened */
452  switch (GetRawClearGround(tile)) {
453  case CLEAR_FIELDS:
454  case CLEAR_ROCKS: {
455  CommandCost ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
456  if (ret.Failed()) return ret;
457  cost.AddCost(ret);
458  break;
459  }
460 
461  default: break;
462  }
463  }
464 
465  if (_game_mode != GM_EDITOR && Company::IsValidID(_current_company)) {
467  if (t != nullptr) ChangeTownRating(t, RATING_TREE_UP_STEP, RATING_TREE_MAXIMUM, flags);
468  }
469 
470  if (flags & DC_EXEC) {
471  if (treetype == TREE_INVALID) {
472  treetype = GetRandomTreeType(tile, GB(Random(), 24, 8));
473  if (treetype == TREE_INVALID) treetype = TREE_CACTUS;
474  }
475 
476  /* Plant full grown trees in scenario editor */
477  PlantTreesOnTile(tile, treetype, 0, _game_mode == GM_EDITOR ? 3 : 0);
478  MarkTileDirtyByTile(tile);
479  if (c != nullptr) c->tree_limit -= 1 << 16;
480 
481  /* When planting rainforest-trees, set tropiczone to rainforest in editor. */
482  if (_game_mode == GM_EDITOR && IsInsideMM(treetype, TREE_RAINFOREST, TREE_CACTUS)) {
484  }
485  }
486  cost.AddCost(_price[PR_BUILD_TREES]);
487  break;
488  }
489 
490  default:
491  msg = STR_ERROR_SITE_UNSUITABLE;
492  break;
493  }
494 
495  /* Tree limit used up? No need to check more. */
496  if (limit < 0) break;
497  }
498 
499  if (cost.GetCost() == 0) {
500  return_cmd_error(msg);
501  } else {
502  return cost;
503  }
504 }
505 
507  byte x, y;
508 };
509 
510 static void DrawTile_Trees(TileInfo *ti)
511 {
512  switch (GetTreeGround(ti->tile)) {
513  case TREE_GROUND_SHORE: DrawShoreTile(ti->tileh); break;
514  case TREE_GROUND_GRASS: DrawClearLandTile(ti, GetTreeDensity(ti->tile)); break;
515  case TREE_GROUND_ROUGH: DrawHillyLandTile(ti); break;
516  default: DrawGroundSprite(_clear_land_sprites_snow_desert[GetTreeDensity(ti->tile)] + SlopeToSpriteOffset(ti->tileh), PAL_NONE); break;
517  }
518 
519  /* Do not draw trees when the invisible trees setting is set */
520  if (IsInvisibilitySet(TO_TREES)) return;
521 
522  uint tmp = CountBits(ti->tile + ti->x + ti->y);
523  uint index = GB(tmp, 0, 2) + (GetTreeType(ti->tile) << 2);
524 
525  /* different tree styles above one of the grounds */
527  GetTreeDensity(ti->tile) >= 2 &&
528  IsInsideMM(index, TREE_SUB_ARCTIC << 2, TREE_RAINFOREST << 2)) {
529  index += 164 - (TREE_SUB_ARCTIC << 2);
530  }
531 
532  assert(index < lengthof(_tree_layout_sprite));
533 
534  const PalSpriteID *s = _tree_layout_sprite[index];
535  const TreePos *d = _tree_layout_xy[GB(tmp, 2, 2)];
536 
537  /* combine trees into one sprite object */
539 
540  TreeListEnt te[4];
541 
542  /* put the trees to draw in a list */
543  uint trees = GetTreeCount(ti->tile);
544 
545  for (uint i = 0; i < trees; i++) {
546  SpriteID sprite = s[0].sprite + (i == trees - 1 ? GetTreeGrowth(ti->tile) : 3);
547  PaletteID pal = s[0].pal;
548 
549  te[i].sprite = sprite;
550  te[i].pal = pal;
551  te[i].x = d->x;
552  te[i].y = d->y;
553  s++;
554  d++;
555  }
556 
557  /* draw them in a sorted way */
558  int z = ti->z + GetSlopeMaxPixelZ(ti->tileh) / 2;
559 
560  for (; trees > 0; trees--) {
561  uint min = te[0].x + te[0].y;
562  uint mi = 0;
563 
564  for (uint i = 1; i < trees; i++) {
565  if ((uint)(te[i].x + te[i].y) < min) {
566  min = te[i].x + te[i].y;
567  mi = i;
568  }
569  }
570 
571  AddSortableSpriteToDraw(te[mi].sprite, te[mi].pal, ti->x + te[mi].x, ti->y + te[mi].y, 16 - te[mi].x, 16 - te[mi].y, 0x30, z, IsTransparencySet(TO_TREES), -te[mi].x, -te[mi].y);
572 
573  /* replace the removed one with the last one */
574  te[mi] = te[trees - 1];
575  }
576 
578 }
579 
580 
581 static int GetSlopePixelZ_Trees(TileIndex tile, uint x, uint y)
582 {
583  int z;
584  Slope tileh = GetTilePixelSlope(tile, &z);
585 
586  return z + GetPartialPixelZ(x & 0xF, y & 0xF, tileh);
587 }
588 
589 static Foundation GetFoundation_Trees(TileIndex tile, Slope tileh)
590 {
591  return FOUNDATION_NONE;
592 }
593 
594 static CommandCost ClearTile_Trees(TileIndex tile, DoCommandFlag flags)
595 {
596  uint num;
597 
600  if (t != nullptr) ChangeTownRating(t, RATING_TREE_DOWN_STEP, RATING_TREE_MINIMUM, flags);
601  }
602 
603  num = GetTreeCount(tile);
604  if (IsInsideMM(GetTreeType(tile), TREE_RAINFOREST, TREE_CACTUS)) num *= 4;
605 
606  if (flags & DC_EXEC) DoClearSquare(tile);
607 
608  return CommandCost(EXPENSES_CONSTRUCTION, num * _price[PR_CLEAR_TREES]);
609 }
610 
611 static void GetTileDesc_Trees(TileIndex tile, TileDesc *td)
612 {
613  TreeType tt = GetTreeType(tile);
614 
616  td->str = STR_LAI_TREE_NAME_RAINFOREST;
617  } else {
618  td->str = tt == TREE_CACTUS ? STR_LAI_TREE_NAME_CACTUS_PLANTS : STR_LAI_TREE_NAME_TREES;
619  }
620 
621  td->owner[0] = GetTileOwner(tile);
622 }
623 
624 static void TileLoopTreesDesert(TileIndex tile)
625 {
626  switch (GetTropicZone(tile)) {
627  case TROPICZONE_DESERT:
628  if (GetTreeGround(tile) != TREE_GROUND_SNOW_DESERT) {
630  MarkTileDirtyByTile(tile);
631  }
632  break;
633 
634  case TROPICZONE_RAINFOREST: {
635  static const SoundFx forest_sounds[] = {
640  };
641  uint32 r = Random();
642 
643  if (Chance16I(1, 200, r) && _settings_client.sound.ambient) SndPlayTileFx(forest_sounds[GB(r, 16, 2)], tile);
644  break;
645  }
646 
647  default: break;
648  }
649 }
650 
651 static void TileLoopTreesAlps(TileIndex tile)
652 {
653  int k = GetTileZ(tile) - GetSnowLine() + 1;
654 
655  if (k < 0) {
656  switch (GetTreeGround(tile)) {
659  default: return;
660  }
661  } else {
662  uint density = std::min<uint>(k, 3);
663 
666  SetTreeGroundDensity(tile, tg, density);
667  } else if (GetTreeDensity(tile) != density) {
668  SetTreeGroundDensity(tile, GetTreeGround(tile), density);
669  } else {
670  if (GetTreeDensity(tile) == 3) {
671  uint32 r = Random();
672  if (Chance16I(1, 200, r) && _settings_client.sound.ambient) {
673  SndPlayTileFx((r & 0x80000000) ? SND_39_ARCTIC_SNOW_2 : SND_34_ARCTIC_SNOW_1, tile);
674  }
675  }
676  return;
677  }
678  }
679  MarkTileDirtyByTile(tile);
680 }
681 
682 static bool CanPlantExtraTrees(TileIndex tile)
683 {
684  return ((_settings_game.game_creation.landscape == LT_TROPIC && GetTropicZone(tile) == TROPICZONE_RAINFOREST) ?
687 }
688 
689 static void TileLoop_Trees(TileIndex tile)
690 {
691  if (GetTreeGround(tile) == TREE_GROUND_SHORE) {
692  TileLoop_Water(tile);
693  } else {
695  case LT_TROPIC: TileLoopTreesDesert(tile); break;
696  case LT_ARCTIC: TileLoopTreesAlps(tile); break;
697  }
698  }
699 
700  AmbientSoundEffect(tile);
701 
702  uint treeCounter = GetTreeCounter(tile);
703 
704  /* Handle growth of grass (under trees/on MP_TREES tiles) at every 8th processings, like it's done for grass on MP_CLEAR tiles. */
705  if ((treeCounter & 7) == 7 && GetTreeGround(tile) == TREE_GROUND_GRASS) {
706  uint density = GetTreeDensity(tile);
707  if (density < 3) {
708  SetTreeGroundDensity(tile, TREE_GROUND_GRASS, density + 1);
709  MarkTileDirtyByTile(tile);
710  }
711  }
712 
714 
715  if (GetTreeCounter(tile) < 15) {
716  AddTreeCounter(tile, 1);
717  return;
718  }
719  SetTreeCounter(tile, 0);
720 
721  switch (GetTreeGrowth(tile)) {
722  case 3: // regular sized tree
723  if (_settings_game.game_creation.landscape == LT_TROPIC &&
724  GetTreeType(tile) != TREE_CACTUS &&
725  GetTropicZone(tile) == TROPICZONE_DESERT) {
726  AddTreeGrowth(tile, 1);
727  } else {
728  switch (GB(Random(), 0, 3)) {
729  case 0: // start destructing
730  AddTreeGrowth(tile, 1);
731  break;
732 
733  case 1: // add a tree
734  if (GetTreeCount(tile) < 4 && CanPlantExtraTrees(tile)) {
735  AddTreeCount(tile, 1);
736  SetTreeGrowth(tile, 0);
737  break;
738  }
739  FALLTHROUGH;
740 
741  case 2: { // add a neighbouring tree
742  if (!CanPlantExtraTrees(tile)) break;
743 
744  TreeType treetype = GetTreeType(tile);
745 
746  tile += TileOffsByDir((Direction)(Random() & 7));
747 
748  /* Cacti don't spread */
749  if (!CanPlantTreesOnTile(tile, false)) return;
750 
751  /* Don't plant trees, if ground was freshly cleared */
752  if (IsTileType(tile, MP_CLEAR) && GetClearGround(tile) == CLEAR_GRASS && GetClearDensity(tile) != 3) return;
753 
754  PlantTreesOnTile(tile, treetype, 0, 0);
755 
756  break;
757  }
758 
759  default:
760  return;
761  }
762  }
763  break;
764 
765  case 6: // final stage of tree destruction
766  if (!CanPlantExtraTrees(tile)) {
767  /* if trees can't spread just plant a new one to prevent deforestation */
768  SetTreeGrowth(tile, 0);
769  } else if (GetTreeCount(tile) > 1) {
770  /* more than one tree, delete it */
771  AddTreeCount(tile, -1);
772  SetTreeGrowth(tile, 3);
773  } else {
774  /* just one tree, change type into MP_CLEAR */
775  switch (GetTreeGround(tile)) {
776  case TREE_GROUND_SHORE: MakeShore(tile); break;
777  case TREE_GROUND_GRASS: MakeClear(tile, CLEAR_GRASS, GetTreeDensity(tile)); break;
778  case TREE_GROUND_ROUGH: MakeClear(tile, CLEAR_ROUGH, 3); break;
779  case TREE_GROUND_ROUGH_SNOW: {
780  uint density = GetTreeDensity(tile);
781  MakeClear(tile, CLEAR_ROUGH, 3);
782  MakeSnow(tile, density);
783  break;
784  }
785  default: // snow or desert
786  if (_settings_game.game_creation.landscape == LT_TROPIC) {
787  MakeClear(tile, CLEAR_DESERT, GetTreeDensity(tile));
788  } else {
789  uint density = GetTreeDensity(tile);
790  MakeClear(tile, CLEAR_GRASS, 3);
791  MakeSnow(tile, density);
792  }
793  break;
794  }
795  }
796  break;
797 
798  default:
799  AddTreeGrowth(tile, 1);
800  break;
801  }
802 
803  MarkTileDirtyByTile(tile);
804 }
805 
806 void OnTick_Trees()
807 {
808  /* Don't spread trees if that's not allowed */
810 
811  uint32 r;
812  TileIndex tile;
813  TreeType tree;
814 
815  /* place a tree at a random rainforest spot */
816  if (_settings_game.game_creation.landscape == LT_TROPIC &&
817  (r = Random(), tile = RandomTileSeed(r), GetTropicZone(tile) == TROPICZONE_RAINFOREST) &&
818  CanPlantTreesOnTile(tile, false) &&
819  (tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TREE_INVALID) {
820  PlantTreesOnTile(tile, tree, 0, 0);
821  }
822 
823  /* byte underflow */
825 
826  /* place a tree at a random spot */
827  r = Random();
828  tile = RandomTileSeed(r);
829  if (CanPlantTreesOnTile(tile, false) && (tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TREE_INVALID) {
830  PlantTreesOnTile(tile, tree, 0, 0);
831  }
832 }
833 
834 static TrackStatus GetTileTrackStatus_Trees(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
835 {
836  return 0;
837 }
838 
839 static void ChangeTileOwner_Trees(TileIndex tile, Owner old_owner, Owner new_owner)
840 {
841  /* not used */
842 }
843 
844 void InitializeTrees()
845 {
846  _trees_tick_ctr = 0;
847 }
848 
849 static CommandCost TerraformTile_Trees(TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new)
850 {
851  return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
852 }
853 
854 
855 extern const TileTypeProcs _tile_type_trees_procs = {
856  DrawTile_Trees, // draw_tile_proc
857  GetSlopePixelZ_Trees, // get_slope_z_proc
858  ClearTile_Trees, // clear_tile_proc
859  nullptr, // add_accepted_cargo_proc
860  GetTileDesc_Trees, // get_tile_desc_proc
861  GetTileTrackStatus_Trees, // get_tile_track_status_proc
862  nullptr, // click_tile_proc
863  nullptr, // animate_tile_proc
864  TileLoop_Trees, // tile_loop_proc
865  ChangeTileOwner_Trees, // change_tile_owner_proc
866  nullptr, // add_produced_cargo_proc
867  nullptr, // vehicle_enter_tile_proc
868  GetFoundation_Trees, // get_foundation_proc
869  TerraformTile_Trees, // terraform_tile_proc
870 };
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:46
GetTreeType
static TreeType GetTreeType(TileIndex t)
Returns the treetype of a tile.
Definition: tree_map.h:73
CLEAR_SNOW
@ CLEAR_SNOW
0-3
Definition: clear_map.h:24
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:83
TROPICZONE_DESERT
@ TROPICZONE_DESERT
Tile is desert.
Definition: tile_type.h:76
sound_func.h
DoCommand
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
Definition: command.cpp:450
PlaceTreeAtSameHeight
static void PlaceTreeAtSameHeight(TileIndex tile, int height)
Place a tree at the same height as an existing tree.
Definition: tree_cmd.cpp:217
Direction
Direction
Defines the 8 directions on the map.
Definition: direction_type.h:24
water.h
GenerateTrees
void GenerateTrees()
Place new trees.
Definition: tree_cmd.cpp:345
TP_NONE
@ TP_NONE
No tree placer algorithm.
Definition: tree_cmd.cpp:38
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
command_func.h
ConstructionSettings::extra_tree_placement
uint8 extra_tree_placement
(dis)allow building extra trees in-game
Definition: settings_type.h:334
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
ClosestTownFromTile
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold.
Definition: town_cmd.cpp:3598
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:308
GetTreeGrowth
static uint GetTreeGrowth(TileIndex t)
Returns the tree growth status.
Definition: tree_map.h:181
company_base.h
IsTransparencySet
static bool IsTransparencySet(TransparencyOption to)
Check if the transparency option bit is set and if we aren't in the game menu (there's never transpar...
Definition: transparency.h:48
EXPENSES_OTHER
@ EXPENSES_OTHER
Other expenses.
Definition: economy_type.h:170
CLEAR_ROCKS
@ CLEAR_ROCKS
3
Definition: clear_map.h:22
ExtraTreePlacement
ExtraTreePlacement
Where to place trees while in-game?
Definition: tree_cmd.cpp:44
TileDesc::owner
Owner owner[4]
Name of the owner(s)
Definition: tile_cmd.h:53
AmbientSoundEffect
static void AmbientSoundEffect(TileIndex tile)
Play an ambient sound effect for an empty tile.
Definition: newgrf_generic.h:53
SetTreeGrowth
static void SetTreeGrowth(TileIndex t, uint g)
Sets the tree growth status of a tile.
Definition: tree_map.h:212
TREE_RAINFOREST
@ TREE_RAINFOREST
tree on the 'green part' on a sub-tropical map
Definition: tree_map.h:28
CompanyProperties::tree_limit
uint32 tree_limit
Amount of trees we can (still) plant (times 65536).
Definition: company_base.h:88
SND_44_RAINFOREST_3
@ SND_44_RAINFOREST_3
68 == 0x44 Tree ambient: rainforest ambient (3): monkeys
Definition: sound_type.h:107
MakeClear
static void MakeClear(TileIndex t, ClearGround g, uint density)
Make a clear tile.
Definition: clear_map.h:259
TREE_GROUND_SHORE
@ TREE_GROUND_SHORE
shore
Definition: tree_map.h:56
TROPICZONE_RAINFOREST
@ TROPICZONE_RAINFOREST
Rainforest tile.
Definition: tile_type.h:77
PalSpriteID::sprite
SpriteID sprite
The 'real' sprite.
Definition: gfx_type.h:23
GetTreeDensity
static uint GetTreeDensity(TileIndex t)
Returns the 'density' of a tile with trees.
Definition: tree_map.h:113
GetTileZ
int GetTileZ(TileIndex tile)
Get bottom height of the tile.
Definition: tile_map.cpp:121
CLEAR_GRASS
@ CLEAR_GRASS
0-3
Definition: clear_map.h:20
IsClearGround
static bool IsClearGround(TileIndex t, ClearGround ct)
Set the type of clear tile.
Definition: clear_map.h:71
DEFAULT_TREE_STEPS
static const uint16 DEFAULT_TREE_STEPS
Default number of attempts for placing trees.
Definition: tree_cmd.cpp:54
GetPartialPixelZ
uint GetPartialPixelZ(int x, int y, Slope corners)
Determines height at given coordinate of a slope.
Definition: landscape.cpp:216
TileInfo::y
uint y
Y position of the tile in unit coordinates.
Definition: tile_cmd.h:44
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:79
IsCoast
static bool IsCoast(TileIndex t)
Is it a coast tile?
Definition: water_map.h:195
town.h
Chance16I
static bool Chance16I(const uint a, const uint b, const uint32 r)
Checks if a given randomize-number is below a given probability.
Definition: random_func.hpp:112
TransportType
TransportType
Available types of transport.
Definition: transport_type.h:19
clear_map.h
TREE_COUNT_TEMPERATE
static const uint TREE_COUNT_TEMPERATE
number of tree types on a temperate map.
Definition: tree_map.h:41
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
DC_EXEC
@ DC_EXEC
execute the given command
Definition: command_type.h:348
SND_39_ARCTIC_SNOW_2
@ SND_39_ARCTIC_SNOW_2
57 == 0x39 Tree ambient: arctic snow (2): heavy wind
Definition: sound_type.h:96
TileDesc
Tile description for the 'land area information' tool.
Definition: tile_cmd.h:51
EDITOR_TREE_DIV
static const uint16 EDITOR_TREE_DIV
Game editor tree generation divisor factor.
Definition: tree_cmd.cpp:56
tree_land.h
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
PlaceTreesRandomly
void PlaceTreesRandomly()
Place some trees randomly.
Definition: tree_cmd.cpp:246
newgrf_generic.h
IncreaseGeneratingWorldProgress
void IncreaseGeneratingWorldProgress(GenWorldProgress cls)
Increases the current stage of the world generation with one.
Definition: genworld_gui.cpp:1494
GetClearGround
static ClearGround GetClearGround(TileIndex t)
Get the type of clear tile.
Definition: clear_map.h:59
SlopeToSpriteOffset
static uint SlopeToSpriteOffset(Slope s)
Returns the Sprite offset for a given Slope.
Definition: slope_func.h:415
SetTreeCounter
static void SetTreeCounter(TileIndex t, uint c)
Set the tick counter for a tree-tile.
Definition: tree_map.h:256
CountBits
static uint CountBits(T value)
Counts the number of set bits in a variable.
Definition: bitmath_func.hpp:251
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition: settings_type.h:564
GetTreeCounter
static uint GetTreeCounter(TileIndex t)
Get the tick counter of a tree tile.
Definition: tree_map.h:226
IsInsideMM
static bool IsInsideMM(const T x, const size_t min, const size_t max)
Checks if a value is in an interval.
Definition: math_func.hpp:204
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
TO_TREES
@ TO_TREES
trees
Definition: transparency.h:24
SoundSettings::ambient
bool ambient
Play ambient, industry and town sounds.
Definition: settings_type.h:201
GetTreeCount
static uint GetTreeCount(TileIndex t)
Returns the number of trees on a tile.
Definition: tree_map.h:149
TREE_GROUND_ROUGH
@ TREE_GROUND_ROUGH
some rough tile
Definition: tree_map.h:54
TREE_SUB_ARCTIC
@ TREE_SUB_ARCTIC
tree on a sub_arctic landscape
Definition: tree_map.h:27
GetRawClearGround
static ClearGround GetRawClearGround(TileIndex t)
Get the type of clear tile but never return CLEAR_SNOW.
Definition: clear_map.h:47
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
GetClearDensity
static uint GetClearDensity(TileIndex t)
Get the density of a non-field clear tile.
Definition: clear_map.h:83
EXPENSES_CONSTRUCTION
@ EXPENSES_CONSTRUCTION
Construction costs.
Definition: economy_type.h:158
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
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:645
SetTropicZone
static void SetTropicZone(TileIndex tile, TropicZone type)
Set the tropic zone.
Definition: tile_map.h:225
TILE_AREA_LOOP
#define TILE_AREA_LOOP(var, ta)
A loop which iterates over the tiles of a TileArea.
Definition: tilearea_type.h:232
ClientSettings::sound
SoundSettings sound
sound effect settings
Definition: settings_type.h:584
clear_func.h
_trees_tick_ctr
byte _trees_tick_ctr
Determines when to consider building more trees.
Definition: tree_cmd.cpp:52
ETP_NO_SPREAD
@ ETP_NO_SPREAD
Grow trees on tiles that have them but don't spread to new ones.
Definition: tree_cmd.cpp:45
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
MP_WATER
@ MP_WATER
Water tile.
Definition: tile_type.h:52
TREE_CACTUS
@ TREE_CACTUS
a cactus for the 'desert part' on a sub-tropical map
Definition: tree_map.h:29
CommandCost::Failed
bool Failed() const
Did this command fail?
Definition: command_type.h:159
ETP_SPREAD_RAINFOREST
@ ETP_SPREAD_RAINFOREST
Grow trees on tiles that have them, only spread to new ones in rainforests.
Definition: tree_cmd.cpp:46
PlaceTree
static void PlaceTree(TileIndex tile, uint32 r)
Make a random tree tile of the given tile.
Definition: tree_cmd.cpp:161
PlaceTreeGroups
static void PlaceTreeGroups(uint num_groups)
Creates a number of tree groups.
Definition: tree_cmd.cpp:186
IsInvisibilitySet
static bool IsInvisibilitySet(TransparencyOption to)
Check if the invisibility option bit is set and if we aren't in the game menu (there's never transpar...
Definition: transparency.h:59
OrthogonalTileArea
Represents the covered area of e.g.
Definition: tilearea_type.h:16
EndSpriteCombine
void EndSpriteCombine()
Terminates a block of sprites started by StartSpriteCombine.
Definition: viewport.cpp:766
CLEAR_DESERT
@ CLEAR_DESERT
1,3
Definition: clear_map.h:25
TREE_INVALID
@ TREE_INVALID
An invalid tree.
Definition: tree_map.h:32
clear_land.h
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:80
TP_IMPROVED
@ TP_IMPROVED
A 'improved' algorithm.
Definition: tree_cmd.cpp:40
GetTropicZone
static TropicZone GetTropicZone(TileIndex tile)
Get the tropic zone.
Definition: tile_map.h:238
GameSettings::economy
EconomySettings economy
settings to change the economy
Definition: settings_type.h:573
TileOffsByDir
static TileIndexDiff TileOffsByDir(Direction dir)
Convert a Direction to a TileIndexDiff.
Definition: map_func.h:355
safeguards.h
CommandCost::GetCost
Money GetCost() const
The costs as made up to this moment.
Definition: command_type.h:82
PlaceTreeGroupAroundTile
uint PlaceTreeGroupAroundTile(TileIndex tile, TreeType treetype, uint radius, uint count)
Place some trees in a radius around a tile.
Definition: tree_cmd.cpp:305
GetTileSlope
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
Definition: tile_map.cpp:59
CLEAR_ROUGH
@ CLEAR_ROUGH
3
Definition: clear_map.h:21
RandomTile
#define RandomTile()
Get a valid random tile.
Definition: map_func.h:435
StartSpriteCombine
void StartSpriteCombine()
Starts a block of sprites, which are "combined" into a single bounding box.
Definition: viewport.cpp:756
TREE_TOYLAND
@ TREE_TOYLAND
tree on a toyland map
Definition: tree_map.h:31
SND_34_ARCTIC_SNOW_1
@ SND_34_ARCTIC_SNOW_1
52 == 0x34 Tree ambient: arctic snow (1): wind
Definition: sound_type.h:91
FOUNDATION_NONE
@ FOUNDATION_NONE
The tile has no foundation, the slope remains unchanged.
Definition: slope_type.h:94
Slope
Slope
Enumeration for the slope-type.
Definition: slope_type.h:48
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition: direction_type.h:77
ETP_NO_GROWTH_NO_SPREAD
@ ETP_NO_GROWTH_NO_SPREAD
Don't grow trees and don't spread them at all.
Definition: tree_cmd.cpp:48
CommandCost::AddCost
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
Definition: command_type.h:62
stdafx.h
landscape.h
TileTypeProcs
Set of callback functions for performing tile operations of a given tile type.
Definition: tile_cmd.h:145
SoundFx
SoundFx
Sound effects from baseset.
Definition: sound_type.h:37
viewport_func.h
TileLoop_Water
void TileLoop_Water(TileIndex tile)
Let a water tile floods its diagonal adjoining tiles called from tunnelbridge_cmd,...
Definition: water_cmd.cpp:1210
IsTileType
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
ChangeTownRating
void ChangeTownRating(Town *t, int add, int max, DoCommandFlag flags)
Changes town rating of the current company.
Definition: town_cmd.cpp:3677
GetTileOwner
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
Definition: tile_map.h:178
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
TREE_GROUND_GRASS
@ TREE_GROUND_GRASS
normal grass
Definition: tree_map.h:53
ETP_SPREAD_ALL
@ ETP_SPREAD_ALL
Grow trees and spread them without restrictions.
Definition: tree_cmd.cpp:47
MP_TREES
@ MP_TREES
Tile got trees.
Definition: tile_type.h:50
EconomySettings::dist_local_authority
byte dist_local_authority
distance for town local authority, default 20
Definition: settings_type.h:493
TreePos
Definition: tree_land.h:16
TREE_SUB_TROPICAL
@ TREE_SUB_TROPICAL
tree on a sub-tropical map, non-rainforest, non-desert
Definition: tree_map.h:30
TREE_COUNT_RAINFOREST
static const uint TREE_COUNT_RAINFOREST
number of tree types for the 'rainforest part' of a sub-tropic map.
Definition: tree_map.h:43
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:47
TreeGround
TreeGround
Enumeration for ground types of tiles with trees.
Definition: tree_map.h:52
TREE_COUNT_TOYLAND
static const uint TREE_COUNT_TOYLAND
number of tree types on a toyland map.
Definition: tree_map.h:45
GetRandomTreeType
static TreeType GetRandomTreeType(TileIndex tile, uint seed)
Get a random TreeType for the given tile based on a given seed.
Definition: tree_cmd.cpp:131
MakeSnow
static void MakeSnow(TileIndex t, uint density=0)
Make a snow tile.
Definition: clear_map.h:300
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
AddTreeGrowth
static void AddTreeGrowth(TileIndex t, int a)
Add a value to the tree growth status.
Definition: tree_map.h:196
IsSlopeWithOneCornerRaised
static bool IsSlopeWithOneCornerRaised(Slope s)
Tests if a specific slope has exactly one corner raised.
Definition: slope_func.h:88
TreeListEnt
Definition: tree_cmd.cpp:506
TREE_COUNT_SUB_TROPICAL
static const uint TREE_COUNT_SUB_TROPICAL
number of tree types for the 'sub-tropic part' of a sub-tropic map.
Definition: tree_map.h:44
SetGeneratingWorldProgress
void SetGeneratingWorldProgress(GenWorldProgress cls, uint total)
Set the total of a stage of the world generation.
Definition: genworld_gui.cpp:1480
TreePlacer
TreePlacer
List of tree placer algorithm.
Definition: tree_cmd.cpp:37
DEFAULT_RAINFOREST_TREE_STEPS
static const uint16 DEFAULT_RAINFOREST_TREE_STEPS
Default number of attempts for placing extra trees at rainforest in tropic.
Definition: tree_cmd.cpp:55
PaletteID
uint32 PaletteID
The number of the palette.
Definition: gfx_type.h:18
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
TP_ORIGINAL
@ TP_ORIGINAL
The original algorithm.
Definition: tree_cmd.cpp:39
tree_map.h
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
AddTreeCount
static void AddTreeCount(TileIndex t, int c)
Add a amount to the tree-count value of a tile with trees.
Definition: tree_map.h:166
MakeShore
static void MakeShore(TileIndex t)
Helper function to make a coast tile.
Definition: water_map.h:375
CmdPlantTree
CommandCost CmdPlantTree(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Plant a tree.
Definition: tree_cmd.cpp:380
PlantTreesOnTile
static void PlantTreesOnTile(TileIndex tile, TreeType treetype, uint count, uint growth)
Creates a tree tile Ground type and density is preserved.
Definition: tree_cmd.cpp:91
TileDesc::str
StringID str
Description of the tile.
Definition: tile_cmd.h:52
PalSpriteID
Combination of a palette sprite and a 'real' sprite.
Definition: gfx_type.h:22
SND_48_RAINFOREST_4
@ SND_48_RAINFOREST_4
72 == 0x48 Tree ambient: rainforest ambient (4): bird (2)
Definition: sound_type.h:111
company_func.h
MakeTree
static void MakeTree(TileIndex t, TreeType type, uint count, uint growth, TreeGround ground, uint density)
Make a tree-tile.
Definition: tree_map.h:274
CanPlantTreesOnTile
static bool CanPlantTreesOnTile(TileIndex tile, bool allow_desert)
Tests if a tile can be converted to MP_TREES This is true for clear ground without farms or rocks.
Definition: tree_cmd.cpp:66
abs
static T abs(const T a)
Returns the absolute value of (scalar) variable.
Definition: math_func.hpp:21
GetTreeGround
static TreeGround GetTreeGround(TileIndex t)
Returns the groundtype for tree tiles.
Definition: tree_map.h:88
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:369
Town
Town data structure.
Definition: town.h:50
random_func.hpp
INVALID_TILE
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:88
GameCreationSettings::tree_placer
byte tree_placer
the tree placer algorithm
Definition: settings_type.h:304
TREE_TEMPERATE
@ TREE_TEMPERATE
temperate tree
Definition: tree_map.h:26
AddTreeCounter
static void AddTreeCounter(TileIndex t, int a)
Add a value on the tick counter of a tree-tile.
Definition: tree_map.h:241
TREE_GROUND_SNOW_DESERT
@ TREE_GROUND_SNOW_DESERT
a desert or snow tile, depend on landscape
Definition: tree_map.h:55
PalSpriteID::pal
PaletteID pal
The palette (use PAL_NONE) if not needed)
Definition: gfx_type.h:24
TileInfo::tile
TileIndex tile
Tile index.
Definition: tile_cmd.h:46
SND_42_RAINFOREST_1
@ SND_42_RAINFOREST_1
66 == 0x42 Tree ambient: rainforest ambient (1): bird (1)
Definition: sound_type.h:105
GameSettings::construction
ConstructionSettings construction
construction of things in-game
Definition: settings_type.h:565
TREE_COUNT_SUB_ARCTIC
static const uint TREE_COUNT_SUB_ARCTIC
number of tree types on a sub arctic map.
Definition: tree_map.h:42
GetTileType
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
Definition: tile_map.h:96
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:318
SND_43_RAINFOREST_2
@ SND_43_RAINFOREST_2
67 == 0x43 Tree ambient: rainforest ambient (2): lion
Definition: sound_type.h:106
TROPICZONE_NORMAL
@ TROPICZONE_NORMAL
Normal tropiczone.
Definition: tile_type.h:75
GetTilePixelSlope
static Slope GetTilePixelSlope(TileIndex tile, int *h)
Return the slope of a given tile.
Definition: tile_map.h:280
Company
Definition: company_base.h:110
CLEAR_FIELDS
@ CLEAR_FIELDS
3
Definition: clear_map.h:23
CMD_LANDSCAPE_CLEAR
@ CMD_LANDSCAPE_CLEAR
demolish a tile
Definition: command_type.h:180
DrawGroundSprite
void DrawGroundSprite(SpriteID image, PaletteID pal, const SubSprite *sub, int extra_offs_x, int extra_offs_y)
Draws a ground sprite for the current tile.
Definition: viewport.cpp:576
RandomTileSeed
static TileIndex RandomTileSeed(uint32 r)
Get a random tile out of a given seed.
Definition: map_func.h:424
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
TreeType
TreeType
List of tree types along all landscape types.
Definition: tree_map.h:25
Delta
static T Delta(const T a, const T b)
Returns the (absolute) difference between two (scalar) variables.
Definition: math_func.hpp:170
SetTreeGroundDensity
static void SetTreeGroundDensity(TileIndex t, TreeGround g, uint d)
Set the density and ground type of a tile with trees.
Definition: tree_map.h:130
IsBridgeAbove
static bool IsBridgeAbove(TileIndex t)
checks if a bridge is set above the ground of this tile
Definition: bridge_map.h:45
GWP_TREE
@ GWP_TREE
Generate trees.
Definition: genworld.h:77
TREE_GROUND_ROUGH_SNOW
@ TREE_GROUND_ROUGH_SNOW
A snow tile that is rough underneath.
Definition: tree_map.h:57