OpenTTD Source: src/tree_cmd.cpp Source File

OpenTTD Source 14.1

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 #include "timer/timer_game_tick.h"
26 #include "tree_cmd.h"
27 #include "landscape_cmd.h"
28
29 #include "table/strings.h"
30 #include "table/tree_land.h"
31 #include "table/clear_land.h"
32
33 #include "safeguards.h"
34
40 enum TreePlacer {
41 TP_NONE,
42 TP_ORIGINAL,
43 TP_IMPROVED,
44 };
45
47 enum ExtraTreePlacement {
48 ETP_NO_SPREAD,
49 ETP_SPREAD_RAINFOREST,
50 ETP_SPREAD_ALL,
51 ETP_NO_GROWTH_NO_SPREAD,
52 };
53
55 byte _trees_tick_ctr;
56
57 static const uint16_t DEFAULT_TREE_STEPS = 1000;
58 static const uint16_t DEFAULT_RAINFOREST_TREE_STEPS = 15000;
59 static const uint16_t EDITOR_TREE_DIV = 5;
60
69 static bool CanPlantTreesOnTile(TileIndex tile, bool allow_desert)
70 {
71 switch (GetTileType(tile)) {
72 case MP_WATER:
73 return !IsBridgeAbove(tile) && IsCoast(tile) && !IsSlopeWithOneCornerRaised(GetTileSlope(tile));
74
75 case MP_CLEAR:
76 return !IsBridgeAbove(tile) && !IsClearGround(tile, CLEAR_FIELDS) && GetRawClearGround(tile) != CLEAR_ROCKS &&
77 (allow_desert || !IsClearGround(tile, CLEAR_DESERT));
78
79 default: return false;
80 }
81 }
82
94 static void PlantTreesOnTile(TileIndex tile, TreeType treetype, uint count, uint growth)
95 {
96 assert(treetype != TREE_INVALID);
97 assert(CanPlantTreesOnTile(tile, true));
98
99 TreeGround ground;
100 uint density = 3;
101
102 switch (GetTileType(tile)) {
103 case MP_WATER:
104 ground = TREE_GROUND_SHORE;
105 break;
106
107 case MP_CLEAR:
108 switch (GetClearGround(tile)) {
109 case CLEAR_GRASS: ground = TREE_GROUND_GRASS; break;
110 case CLEAR_ROUGH: ground = TREE_GROUND_ROUGH; break;
111 case CLEAR_SNOW: ground = GetRawClearGround(tile) == CLEAR_ROUGH ? TREE_GROUND_ROUGH_SNOW : TREE_GROUND_SNOW_DESERT; break;
112 default: ground = TREE_GROUND_SNOW_DESERT; break;
113 }
114 if (GetClearGround(tile) != CLEAR_ROUGH) density = GetClearDensity(tile);
115 break;
116
117 default: NOT_REACHED();
118 }
119
120 MakeTree(tile, treetype, count, growth, ground, density);
121 }
122
134 static TreeType GetRandomTreeType(TileIndex tile, uint seed)
135 {
136 switch (_settings_game.game_creation.landscape) {
137 case LT_TEMPERATE:
138 return (TreeType)(seed * TREE_COUNT_TEMPERATE / 256 + TREE_TEMPERATE);
139
140 case LT_ARCTIC:
141 return (TreeType)(seed * TREE_COUNT_SUB_ARCTIC / 256 + TREE_SUB_ARCTIC);
142
143 case LT_TROPIC:
144 switch (GetTropicZone(tile)) {
145 case TROPICZONE_NORMAL: return (TreeType)(seed * TREE_COUNT_SUB_TROPICAL / 256 + TREE_SUB_TROPICAL);
146 case TROPICZONE_DESERT: return (TreeType)((seed > 12) ? TREE_INVALID : TREE_CACTUS);
147 default: return (TreeType)(seed * TREE_COUNT_RAINFOREST / 256 + TREE_RAINFOREST);
148 }
149
150 default:
151 return (TreeType)(seed * TREE_COUNT_TOYLAND / 256 + TREE_TOYLAND);
152 }
153 }
154
164 static void PlaceTree(TileIndex tile, uint32_t r)
165 {
166 TreeType tree = GetRandomTreeType(tile, GB(r, 24, 8));
167
168 if (tree != TREE_INVALID) {
169 PlantTreesOnTile(tile, tree, GB(r, 22, 2), std::min<byte>(GB(r, 16, 3), 6));
170 MarkTileDirtyByTile(tile);
171
172 /* Rerandomize ground, if neither snow nor shore */
173 TreeGround ground = GetTreeGround(tile);
174 if (ground != TREE_GROUND_SNOW_DESERT && ground != TREE_GROUND_ROUGH_SNOW && ground != TREE_GROUND_SHORE) {
175 SetTreeGroundDensity(tile, (TreeGround)GB(r, 28, 1), 3);
176 }
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_t 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
198 IncreaseGeneratingWorldProgress(GWP_TREE);
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_t 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
246 void PlaceTreesRandomly()
247 {
248 int i, j, ht;
249
250 i = Map::ScaleBySize(DEFAULT_TREE_STEPS);
251 if (_game_mode == GM_EDITOR) i /= EDITOR_TREE_DIV;
252 do {
253 uint32_t r = Random();
254 TileIndex tile = RandomTileSeed(r);
255
256 IncreaseGeneratingWorldProgress(GWP_TREE);
257
258 if (CanPlantTreesOnTile(tile, true)) {
259 PlaceTree(tile, r);
260 if (_settings_game.game_creation.tree_placer != TP_IMPROVED) continue;
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) {
278 i = Map::ScaleBySize(DEFAULT_RAINFOREST_TREE_STEPS);
279 if (_game_mode == GM_EDITOR) i /= EDITOR_TREE_DIV;
280
281 do {
282 uint32_t r = Random();
283 TileIndex tile = RandomTileSeed(r);
284
285 IncreaseGeneratingWorldProgress(GWP_TREE);
286
287 if (GetTropicZone(tile) == TROPICZONE_RAINFOREST && CanPlantTreesOnTile(tile, false)) {
288 PlaceTree(tile, r);
289 }
290 } while (--i);
291 }
292 }
293
306 uint PlaceTreeGroupAroundTile(TileIndex tile, TreeType treetype, uint radius, uint count, bool set_zone)
307 {
308 assert(_game_mode == GM_EDITOR); // Due to InteractiveRandom being used in this function
309 assert(treetype < TREE_TOYLAND + TREE_COUNT_TOYLAND);
310 const bool allow_desert = treetype == TREE_CACTUS;
311 uint planted = 0;
312
313 for (; count > 0; count--) {
314 /* Simple quasi-normal distribution with range [-radius; radius) */
315 auto mkcoord = [&]() -> int32_t {
316 const uint32_t rand = InteractiveRandom();
317 const int32_t dist = GB<int32_t>(rand, 0, 8) + GB<int32_t>(rand, 8, 8) + GB<int32_t>(rand, 16, 8) + GB<int32_t>(rand, 24, 8);
318 const int32_t scu = dist * radius / 512;
319 return scu - radius;
320 };
321 const int32_t xofs = mkcoord();
322 const int32_t yofs = mkcoord();
323 const TileIndex tile_to_plant = TileAddWrap(tile, xofs, yofs);
324 if (tile_to_plant != INVALID_TILE) {
325 if (IsTileType(tile_to_plant, MP_TREES) && GetTreeCount(tile_to_plant) < 4) {
326 AddTreeCount(tile_to_plant, 1);
327 SetTreeGrowth(tile_to_plant, 0);
328 MarkTileDirtyByTile(tile_to_plant, 0);
329 planted++;
330 } else if (CanPlantTreesOnTile(tile_to_plant, allow_desert)) {
331 PlantTreesOnTile(tile_to_plant, treetype, 0, 3);
332 MarkTileDirtyByTile(tile_to_plant, 0);
333 planted++;
334 }
335 }
336 }
337
338 if (set_zone && IsInsideMM(treetype, TREE_RAINFOREST, TREE_CACTUS)) {
339 for (TileIndex t : TileArea(tile).Expand(radius)) {
340 if (GetTileType(t) != MP_VOID && DistanceSquare(tile, t) < radius * radius) SetTropicZone(t, TROPICZONE_RAINFOREST);
341 }
342 }
343
344 return planted;
345 }
346
353 void GenerateTrees()
354 {
355 uint i, total;
356
357 if (_settings_game.game_creation.tree_placer == TP_NONE) return;
358
359 switch (_settings_game.game_creation.tree_placer) {
360 case TP_ORIGINAL: i = _settings_game.game_creation.landscape == LT_ARCTIC ? 15 : 6; break;
361 case TP_IMPROVED: i = _settings_game.game_creation.landscape == LT_ARCTIC ? 4 : 2; break;
362 default: NOT_REACHED();
363 }
364
365 total = Map::ScaleBySize(DEFAULT_TREE_STEPS);
366 if (_settings_game.game_creation.landscape == LT_TROPIC) total += Map::ScaleBySize(DEFAULT_RAINFOREST_TREE_STEPS);
367 total *= i;
368 uint num_groups = (_settings_game.game_creation.landscape != LT_TOYLAND) ? Map::ScaleBySize(GB(Random(), 0, 5) + 25) : 0;
369 total += num_groups * DEFAULT_TREE_STEPS;
370 SetGeneratingWorldProgress(GWP_TREE, total);
371
372 if (num_groups != 0) PlaceTreeGroups(num_groups);
373
374 for (; i != 0; i--) {
375 PlaceTreesRandomly();
376 }
377 }
378
388 CommandCost CmdPlantTree(DoCommandFlag flags, TileIndex tile, TileIndex start_tile, byte tree_to_plant, bool diagonal)
389 {
390 StringID msg = INVALID_STRING_ID;
391 CommandCost cost(EXPENSES_OTHER);
392
393 if (start_tile >= Map::Size()) return CMD_ERROR;
394 /* Check the tree type within the current climate */
395 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;
396
397 Company *c = (_game_mode != GM_EDITOR) ? Company::GetIfValid(_current_company) : nullptr;
398 int limit = (c == nullptr ? INT32_MAX : GB(c->tree_limit, 16, 16));
399
400 std::unique_ptr<TileIterator> iter = TileIterator::Create(tile, start_tile, diagonal);
401 for (; *iter != INVALID_TILE; ++(*iter)) {
402 TileIndex current_tile = *iter;
403 switch (GetTileType(current_tile)) {
404 case MP_TREES:
405 /* no more space for trees? */
406 if (GetTreeCount(current_tile) == 4) {
407 msg = STR_ERROR_TREE_ALREADY_HERE;
408 continue;
409 }
410
411 /* Test tree limit. */
412 if (--limit < 1) {
413 msg = STR_ERROR_TREE_PLANT_LIMIT_REACHED;
414 break;
415 }
416
417 if (flags & DC_EXEC) {
418 AddTreeCount(current_tile, 1);
419 MarkTileDirtyByTile(current_tile);
420 if (c != nullptr) c->tree_limit -= 1 << 16;
421 }
422 /* 2x as expensive to add more trees to an existing tile */
423 cost.AddCost(_price[PR_BUILD_TREES] * 2);
424 break;
425
426 case MP_WATER:
427 if (!IsCoast(current_tile) || IsSlopeWithOneCornerRaised(GetTileSlope(current_tile))) {
428 msg = STR_ERROR_CAN_T_BUILD_ON_WATER;
429 continue;
430 }
431 [[fallthrough]];
432
433 case MP_CLEAR: {
434 if (IsBridgeAbove(current_tile)) {
435 msg = STR_ERROR_SITE_UNSUITABLE;
436 continue;
437 }
438
439 TreeType treetype = (TreeType)tree_to_plant;
440 /* Be a bit picky about which trees go where. */
441 if (_settings_game.game_creation.landscape == LT_TROPIC && treetype != TREE_INVALID && (
442 /* No cacti outside the desert */
443 (treetype == TREE_CACTUS && GetTropicZone(current_tile) != TROPICZONE_DESERT) ||
444 /* No rain forest trees outside the rain forest, except in the editor mode where it makes those tiles rain forest tile */
445 (IsInsideMM(treetype, TREE_RAINFOREST, TREE_CACTUS) && GetTropicZone(current_tile) != TROPICZONE_RAINFOREST && _game_mode != GM_EDITOR) ||
446 /* And no subtropical trees in the desert/rain forest */
447 (IsInsideMM(treetype, TREE_SUB_TROPICAL, TREE_TOYLAND) && GetTropicZone(current_tile) != TROPICZONE_NORMAL))) {
448 msg = STR_ERROR_TREE_WRONG_TERRAIN_FOR_TREE_TYPE;
449 continue;
450 }
451
452 /* Test tree limit. */
453 if (--limit < 1) {
454 msg = STR_ERROR_TREE_PLANT_LIMIT_REACHED;
455 break;
456 }
457
458 if (IsTileType(current_tile, MP_CLEAR)) {
459 /* Remove fields or rocks. Note that the ground will get barrened */
460 switch (GetRawClearGround(current_tile)) {
461 case CLEAR_FIELDS:
462 case CLEAR_ROCKS: {
463 CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, current_tile);
464 if (ret.Failed()) return ret;
465 cost.AddCost(ret);
466 break;
467 }
468
469 default: break;
470 }
471 }
472
473 if (_game_mode != GM_EDITOR && Company::IsValidID(_current_company)) {
474 Town *t = ClosestTownFromTile(current_tile, _settings_game.economy.dist_local_authority);
475 if (t != nullptr) ChangeTownRating(t, RATING_TREE_UP_STEP, RATING_TREE_MAXIMUM, flags);
476 }
477
478 if (flags & DC_EXEC) {
479 if (treetype == TREE_INVALID) {
480 treetype = GetRandomTreeType(current_tile, GB(Random(), 24, 8));
481 if (treetype == TREE_INVALID) treetype = TREE_CACTUS;
482 }
483
484 /* Plant full grown trees in scenario editor */
485 PlantTreesOnTile(current_tile, treetype, 0, _game_mode == GM_EDITOR ? 3 : 0);
486 MarkTileDirtyByTile(current_tile);
487 if (c != nullptr) c->tree_limit -= 1 << 16;
488
489 /* When planting rainforest-trees, set tropiczone to rainforest in editor. */
490 if (_game_mode == GM_EDITOR && IsInsideMM(treetype, TREE_RAINFOREST, TREE_CACTUS)) {
491 SetTropicZone(current_tile, TROPICZONE_RAINFOREST);
492 }
493 }
494 cost.AddCost(_price[PR_BUILD_TREES]);
495 break;
496 }
497
498 default:
499 msg = STR_ERROR_SITE_UNSUITABLE;
500 break;
501 }
502
503 /* Tree limit used up? No need to check more. */
504 if (limit < 0) break;
505 }
506
507 if (cost.GetCost() == 0) {
508 return_cmd_error(msg);
509 } else {
510 return cost;
511 }
512 }
513
514 struct TreeListEnt : PalSpriteID {
515 byte x, y;
516 };
517
518 static void DrawTile_Trees(TileInfo *ti)
519 {
520 switch (GetTreeGround(ti->tile)) {
521 case TREE_GROUND_SHORE: DrawShoreTile(ti->tileh); break;
522 case TREE_GROUND_GRASS: DrawClearLandTile(ti, GetTreeDensity(ti->tile)); break;
523 case TREE_GROUND_ROUGH: DrawHillyLandTile(ti); break;
524 default: DrawGroundSprite(_clear_land_sprites_snow_desert[GetTreeDensity(ti->tile)] + SlopeToSpriteOffset(ti->tileh), PAL_NONE); break;
525 }
526
527 /* Do not draw trees when the invisible trees setting is set */
528 if (IsInvisibilitySet(TO_TREES)) return;
529
530 uint tmp = CountBits(ti->tile.base() + ti->x + ti->y);
531 uint index = GB(tmp, 0, 2) + (GetTreeType(ti->tile) << 2);
532
533 /* different tree styles above one of the grounds */
534 if ((GetTreeGround(ti->tile) == TREE_GROUND_SNOW_DESERT || GetTreeGround(ti->tile) == TREE_GROUND_ROUGH_SNOW) &&
535 GetTreeDensity(ti->tile) >= 2 &&
536 IsInsideMM(index, TREE_SUB_ARCTIC << 2, TREE_RAINFOREST << 2)) {
537 index += 164 - (TREE_SUB_ARCTIC << 2);
538 }
539
540 assert(index < lengthof(_tree_layout_sprite));
541
542 const PalSpriteID *s = _tree_layout_sprite[index];
543 const TreePos *d = _tree_layout_xy[GB(tmp, 2, 2)];
544
545 /* combine trees into one sprite object */
546 StartSpriteCombine();
547
548 TreeListEnt te[4];
549
550 /* put the trees to draw in a list */
551 uint trees = GetTreeCount(ti->tile);
552
553 for (uint i = 0; i < trees; i++) {
554 SpriteID sprite = s[0].sprite + (i == trees - 1 ? GetTreeGrowth(ti->tile) : 3);
555 PaletteID pal = s[0].pal;
556
557 te[i].sprite = sprite;
558 te[i].pal = pal;
559 te[i].x = d->x;
560 te[i].y = d->y;
561 s++;
562 d++;
563 }
564
565 /* draw them in a sorted way */
566 int z = ti->z + GetSlopeMaxPixelZ(ti->tileh) / 2;
567
568 for (; trees > 0; trees--) {
569 uint min = te[0].x + te[0].y;
570 uint mi = 0;
571
572 for (uint i = 1; i < trees; i++) {
573 if ((uint)(te[i].x + te[i].y) < min) {
574 min = te[i].x + te[i].y;
575 mi = i;
576 }
577 }
578
579 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);
580
581 /* replace the removed one with the last one */
582 te[mi] = te[trees - 1];
583 }
584
585 EndSpriteCombine();
586 }
587
588
589 static int GetSlopePixelZ_Trees(TileIndex tile, uint x, uint y, bool)
590 {
591 int z;
592 Slope tileh = GetTilePixelSlope(tile, &z);
593
594 return z + GetPartialPixelZ(x & 0xF, y & 0xF, tileh);
595 }
596
597 static Foundation GetFoundation_Trees(TileIndex, Slope)
598 {
599 return FOUNDATION_NONE;
600 }
601
602 static CommandCost ClearTile_Trees(TileIndex tile, DoCommandFlag flags)
603 {
604 uint num;
605
606 if (Company::IsValidID(_current_company)) {
607 Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority);
608 if (t != nullptr) ChangeTownRating(t, RATING_TREE_DOWN_STEP, RATING_TREE_MINIMUM, flags);
609 }
610
611 num = GetTreeCount(tile);
612 if (IsInsideMM(GetTreeType(tile), TREE_RAINFOREST, TREE_CACTUS)) num *= 4;
613
614 if (flags & DC_EXEC) DoClearSquare(tile);
615
616 return CommandCost(EXPENSES_CONSTRUCTION, num * _price[PR_CLEAR_TREES]);
617 }
618
619 static void GetTileDesc_Trees(TileIndex tile, TileDesc *td)
620 {
621 TreeType tt = GetTreeType(tile);
622
623 if (IsInsideMM(tt, TREE_RAINFOREST, TREE_CACTUS)) {
624 td->str = STR_LAI_TREE_NAME_RAINFOREST;
625 } else {
626 td->str = tt == TREE_CACTUS ? STR_LAI_TREE_NAME_CACTUS_PLANTS : STR_LAI_TREE_NAME_TREES;
627 }
628
629 td->owner[0] = GetTileOwner(tile);
630 }
631
632 static void TileLoopTreesDesert(TileIndex tile)
633 {
634 switch (GetTropicZone(tile)) {
635 case TROPICZONE_DESERT:
636 if (GetTreeGround(tile) != TREE_GROUND_SNOW_DESERT) {
637 SetTreeGroundDensity(tile, TREE_GROUND_SNOW_DESERT, 3);
638 MarkTileDirtyByTile(tile);
639 }
640 break;
641
642 case TROPICZONE_RAINFOREST: {
643 static const SoundFx forest_sounds[] = {
644 SND_42_RAINFOREST_1,
645 SND_43_RAINFOREST_2,
646 SND_44_RAINFOREST_3,
647 SND_48_RAINFOREST_4
648 };
649 uint32_t r = Random();
650
651 if (Chance16I(1, 200, r) && _settings_client.sound.ambient) SndPlayTileFx(forest_sounds[GB(r, 16, 2)], tile);
652 break;
653 }
654
655 default: break;
656 }
657 }
658
659 static void TileLoopTreesAlps(TileIndex tile)
660 {
661 int k = GetTileZ(tile) - GetSnowLine() + 1;
662
663 if (k < 0) {
664 switch (GetTreeGround(tile)) {
665 case TREE_GROUND_SNOW_DESERT: SetTreeGroundDensity(tile, TREE_GROUND_GRASS, 3); break;
666 case TREE_GROUND_ROUGH_SNOW: SetTreeGroundDensity(tile, TREE_GROUND_ROUGH, 3); break;
667 default: return;
668 }
669 } else {
670 uint density = std::min<uint>(k, 3);
671
672 if (GetTreeGround(tile) != TREE_GROUND_SNOW_DESERT && GetTreeGround(tile) != TREE_GROUND_ROUGH_SNOW) {
673 TreeGround tg = GetTreeGround(tile) == TREE_GROUND_ROUGH ? TREE_GROUND_ROUGH_SNOW : TREE_GROUND_SNOW_DESERT;
674 SetTreeGroundDensity(tile, tg, density);
675 } else if (GetTreeDensity(tile) != density) {
676 SetTreeGroundDensity(tile, GetTreeGround(tile), density);
677 } else {
678 if (GetTreeDensity(tile) == 3) {
679 uint32_t r = Random();
680 if (Chance16I(1, 200, r) && _settings_client.sound.ambient) {
681 SndPlayTileFx((r & 0x80000000) ? SND_39_ARCTIC_SNOW_2 : SND_34_ARCTIC_SNOW_1, tile);
682 }
683 }
684 return;
685 }
686 }
687 MarkTileDirtyByTile(tile);
688 }
689
690 static bool CanPlantExtraTrees(TileIndex tile)
691 {
692 return ((_settings_game.game_creation.landscape == LT_TROPIC && GetTropicZone(tile) == TROPICZONE_RAINFOREST) ?
693 (_settings_game.construction.extra_tree_placement == ETP_SPREAD_ALL || _settings_game.construction.extra_tree_placement == ETP_SPREAD_RAINFOREST) :
694 _settings_game.construction.extra_tree_placement == ETP_SPREAD_ALL);
695 }
696
697 static void TileLoop_Trees(TileIndex tile)
698 {
699 if (GetTreeGround(tile) == TREE_GROUND_SHORE) {
700 TileLoop_Water(tile);
701 } else {
702 switch (_settings_game.game_creation.landscape) {
703 case LT_TROPIC: TileLoopTreesDesert(tile); break;
704 case LT_ARCTIC: TileLoopTreesAlps(tile); break;
705 }
706 }
707
708 AmbientSoundEffect(tile);
709
710 /* TimerGameTick::counter is incremented by 256 between each call, so ignore lower 8 bits.
711 * Also, we use a simple hash to spread the updates evenly over the map.
712 * 11 and 9 are just some co-prime numbers for better spread.
713 */
714 uint32_t cycle = 11 * TileX(tile) + 9 * TileY(tile) + (TimerGameTick::counter >> 8);
715
716 /* Handle growth of grass (under trees/on MP_TREES tiles) at every 8th processings, like it's done for grass on MP_CLEAR tiles. */
717 if ((cycle & 7) == 7 && GetTreeGround(tile) == TREE_GROUND_GRASS) {
718 uint density = GetTreeDensity(tile);
719 if (density < 3) {
720 SetTreeGroundDensity(tile, TREE_GROUND_GRASS, density + 1);
721 MarkTileDirtyByTile(tile);
722 }
723 }
724
725 if (_settings_game.construction.extra_tree_placement == ETP_NO_GROWTH_NO_SPREAD) return;
726
727 if ((cycle & 15) != 15) return;
728
729 switch (GetTreeGrowth(tile)) {
730 case 3: // regular sized tree
731 if (_settings_game.game_creation.landscape == LT_TROPIC &&
732 GetTreeType(tile) != TREE_CACTUS &&
733 GetTropicZone(tile) == TROPICZONE_DESERT) {
734 AddTreeGrowth(tile, 1);
735 } else {
736 switch (GB(Random(), 0, 3)) {
737 case 0: // start destructing
738 AddTreeGrowth(tile, 1);
739 break;
740
741 case 1: // add a tree
742 if (GetTreeCount(tile) < 4 && CanPlantExtraTrees(tile)) {
743 AddTreeCount(tile, 1);
744 SetTreeGrowth(tile, 0);
745 break;
746 }
747 [[fallthrough]];
748
749 case 2: { // add a neighbouring tree
750 if (!CanPlantExtraTrees(tile)) break;
751
752 TreeType treetype = GetTreeType(tile);
753
754 tile += TileOffsByDir((Direction)(Random() & 7));
755
756 /* Cacti don't spread */
757 if (!CanPlantTreesOnTile(tile, false)) return;
758
759 /* Don't plant trees, if ground was freshly cleared */
760 if (IsTileType(tile, MP_CLEAR) && GetClearGround(tile) == CLEAR_GRASS && GetClearDensity(tile) != 3) return;
761
762 PlantTreesOnTile(tile, treetype, 0, 0);
763
764 break;
765 }
766
767 default:
768 return;
769 }
770 }
771 break;
772
773 case 6: // final stage of tree destruction
774 if (!CanPlantExtraTrees(tile)) {
775 /* if trees can't spread just plant a new one to prevent deforestation */
776 SetTreeGrowth(tile, 0);
777 } else if (GetTreeCount(tile) > 1) {
778 /* more than one tree, delete it */
779 AddTreeCount(tile, -1);
780 SetTreeGrowth(tile, 3);
781 } else {
782 /* just one tree, change type into MP_CLEAR */
783 switch (GetTreeGround(tile)) {
784 case TREE_GROUND_SHORE: MakeShore(tile); break;
785 case TREE_GROUND_GRASS: MakeClear(tile, CLEAR_GRASS, GetTreeDensity(tile)); break;
786 case TREE_GROUND_ROUGH: MakeClear(tile, CLEAR_ROUGH, 3); break;
787 case TREE_GROUND_ROUGH_SNOW: {
788 uint density = GetTreeDensity(tile);
789 MakeClear(tile, CLEAR_ROUGH, 3);
790 MakeSnow(tile, density);
791 break;
792 }
793 default: // snow or desert
794 if (_settings_game.game_creation.landscape == LT_TROPIC) {
795 MakeClear(tile, CLEAR_DESERT, GetTreeDensity(tile));
796 } else {
797 uint density = GetTreeDensity(tile);
798 MakeClear(tile, CLEAR_GRASS, 3);
799 MakeSnow(tile, density);
800 }
801 break;
802 }
803 }
804 break;
805
806 default:
807 AddTreeGrowth(tile, 1);
808 break;
809 }
810
811 MarkTileDirtyByTile(tile);
812 }
813
820 bool DecrementTreeCounter()
821 {
822 /* Ensure _trees_tick_ctr can be decremented past zero only once for the largest map size. */
823 static_assert(2 * (MAX_MAP_SIZE_BITS - MIN_MAP_SIZE_BITS) - 4 <= std::numeric_limits<byte>::digits);
824
825 /* byte underflow */
826 byte old_trees_tick_ctr = _trees_tick_ctr;
827 _trees_tick_ctr -= Map::ScaleBySize(1);
828 return old_trees_tick_ctr <= _trees_tick_ctr;
829 }
830
831 void OnTick_Trees()
832 {
833 /* Don't spread trees if that's not allowed */
834 if (_settings_game.construction.extra_tree_placement == ETP_NO_SPREAD || _settings_game.construction.extra_tree_placement == ETP_NO_GROWTH_NO_SPREAD) return;
835
836 uint32_t r;
837 TileIndex tile;
838 TreeType tree;
839
840 /* Skip some tree ticks for map sizes below 256 * 256. 64 * 64 is 16 times smaller, so
841 * this is the maximum number of ticks that are skipped. Number of ticks to skip is
842 * inversely proportional to map size, so that is handled to create a mask. */
843 int skip = Map::ScaleBySize(16);
844 if (skip < 16 && (TimerGameTick::counter & (16 / skip - 1)) != 0) return;
845
846 /* place a tree at a random rainforest spot */
847 if (_settings_game.game_creation.landscape == LT_TROPIC) {
848 for (uint c = Map::ScaleBySize(1); c > 0; c--) {
849 if ((r = Random(), tile = RandomTileSeed(r), GetTropicZone(tile) == TROPICZONE_RAINFOREST) &&
850 CanPlantTreesOnTile(tile, false) &&
851 (tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TREE_INVALID) {
852 PlantTreesOnTile(tile, tree, 0, 0);
853 }
854 }
855 }
856
857 if (!DecrementTreeCounter() || _settings_game.construction.extra_tree_placement == ETP_SPREAD_RAINFOREST) return;
858
859 /* place a tree at a random spot */
860 r = Random();
861 tile = RandomTileSeed(r);
862 if (CanPlantTreesOnTile(tile, false) && (tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TREE_INVALID) {
863 PlantTreesOnTile(tile, tree, 0, 0);
864 }
865 }
866
867 static TrackStatus GetTileTrackStatus_Trees(TileIndex, TransportType, uint, DiagDirection)
868 {
869 return 0;
870 }
871
872 static void ChangeTileOwner_Trees(TileIndex, Owner, Owner)
873 {
874 /* not used */
875 }
876
877 void InitializeTrees()
878 {
879 _trees_tick_ctr = 0;
880 }
881
882 static CommandCost TerraformTile_Trees(TileIndex tile, DoCommandFlag flags, int, Slope)
883 {
884 return Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile);
885 }
886
887
888 extern const TileTypeProcs _tile_type_trees_procs = {
889 DrawTile_Trees, // draw_tile_proc
890 GetSlopePixelZ_Trees, // get_slope_z_proc
891 ClearTile_Trees, // clear_tile_proc
892 nullptr, // add_accepted_cargo_proc
893 GetTileDesc_Trees, // get_tile_desc_proc
894 GetTileTrackStatus_Trees, // get_tile_track_status_proc
895 nullptr, // click_tile_proc
896 nullptr, // animate_tile_proc
897 TileLoop_Trees, // tile_loop_proc
898 ChangeTileOwner_Trees, // change_tile_owner_proc
899 nullptr, // add_produced_cargo_proc
900 nullptr, // vehicle_enter_tile_proc
901 GetFoundation_Trees, // get_foundation_proc
902 TerraformTile_Trees, // terraform_tile_proc
903 };
TileY
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:437
TileInfo::z
int z
Height.
Definition: tile_cmd.h:48
MP_CLEAR
@ MP_CLEAR
A tile without any structures, i.e. grass, rocks, farm fields etc.
Definition: tile_type.h:48
TileOffsByDir
TileIndexDiff TileOffsByDir(Direction dir)
Convert a Direction to a TileIndexDiff.
Definition: map_func.h:577
CLEAR_SNOW
@ CLEAR_SNOW
0-3
Definition: clear_map.h:24
TROPICZONE_DESERT
@ TROPICZONE_DESERT
Tile is desert.
Definition: tile_type.h:78
sound_func.h
IsClearGround
bool IsClearGround(Tile t, ClearGround ct)
Set the type of clear tile.
Definition: clear_map.h:71
TimerGameTick::counter
static TickCounter counter
Monotonic counter, in ticks, since start of game.
Definition: timer_game_tick.h:60
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:353
TP_NONE
@ TP_NONE
No tree placer algorithm.
Definition: tree_cmd.cpp:41
command_func.h
IsInsideMM
constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
Definition: math_func.hpp:268
MakeSnow
void MakeSnow(Tile t, uint density=0)
Make a snow tile.
Definition: clear_map.h:300
Pool::PoolItem<&_company_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:350
CMD_ERROR
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition: command_func.h:28
GetTreeGround
TreeGround GetTreeGround(Tile t)
Returns the groundtype for tree tiles.
Definition: tree_map.h:88
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:3783
TileInfo
Tile information, used while rendering the tile.
Definition: tile_cmd.h:43
GameCreationSettings::landscape
byte landscape
the landscape we're currently in
Definition: settings_type.h:355
company_base.h
EXPENSES_OTHER
@ EXPENSES_OTHER
Other expenses.
Definition: economy_type.h:185
GetTreeCount
uint GetTreeCount(Tile t)
Returns the number of trees on a tile.
Definition: tree_map.h:149
tree_cmd.h
CLEAR_ROCKS
@ CLEAR_ROCKS
3
Definition: clear_map.h:22
ExtraTreePlacement
ExtraTreePlacement
Where to place trees while in-game?
Definition: tree_cmd.cpp:47
TileDesc::owner
Owner owner[4]
Name of the owner(s)
Definition: tile_cmd.h:55
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
AmbientSoundEffect
void AmbientSoundEffect(TileIndex tile)
Play an ambient sound effect for an empty tile.
Definition: newgrf_generic.h:54
MIN_MAP_SIZE_BITS
static const uint MIN_MAP_SIZE_BITS
Minimal and maximal map width and height.
Definition: map_type.h:37
AddTreeGrowth
void AddTreeGrowth(Tile t, int a)
Add a value to the tree growth status.
Definition: tree_map.h:196
TREE_RAINFOREST
@ TREE_RAINFOREST
tree on the 'green part' on a sub-tropical map
Definition: tree_map.h:28
GB
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:32
SND_44_RAINFOREST_3
@ SND_44_RAINFOREST_3
68 == 0x44 Tree ambient: rainforest ambient (3): monkeys
Definition: sound_type.h:107
IsTransparencySet
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
TREE_GROUND_SHORE
@ TREE_GROUND_SHORE
shore
Definition: tree_map.h:56
TROPICZONE_RAINFOREST
@ TROPICZONE_RAINFOREST
Rainforest tile.
Definition: tile_type.h:79
PalSpriteID::sprite
SpriteID sprite
The 'real' sprite.
Definition: gfx_type.h:23
AddTreeCount
void AddTreeCount(Tile t, int c)
Add a amount to the tree-count value of a tile with trees.
Definition: tree_map.h:166
GetTileZ
int GetTileZ(TileIndex tile)
Get bottom height of the tile.
Definition: tile_map.cpp:121
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:95
CLEAR_GRASS
@ CLEAR_GRASS
0-3
Definition: clear_map.h:20
TileIterator::Create
static std::unique_ptr< TileIterator > Create(TileIndex corner1, TileIndex corner2, bool diagonal)
Create either an OrthogonalTileIterator or DiagonalTileIterator given the diagonal parameter.
Definition: tilearea.cpp:291
GetPartialPixelZ
uint GetPartialPixelZ(int x, int y, Slope corners)
Determines height at given coordinate of a slope.
Definition: landscape.cpp:224
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:54
town.h
TileInfo::y
int y
Y position of the tile in unit coordinates.
Definition: tile_cmd.h:45
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
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
Map::ScaleBySize
static uint ScaleBySize(uint n)
Scales the given value by the map size, where the given value is for a 256 by 256 map.
Definition: map_func.h:328
DC_EXEC
@ DC_EXEC
execute the given command
Definition: command_type.h:371
SND_39_ARCTIC_SNOW_2
@ SND_39_ARCTIC_SNOW_2
57 == 0x39 Tree ambient: arctic snow (2): heavy wind
Definition: sound_type.h:96
PaletteID
uint32_t PaletteID
The number of the palette.
Definition: gfx_type.h:18
TileDesc
Tile description for the 'land area information' tool.
Definition: tile_cmd.h:52
tree_land.h
DoCommandFlag
DoCommandFlag
List of flags for a command.
Definition: command_type.h:369
genworld.h
Foundation
Foundation
Enumeration for Foundations.
Definition: slope_type.h:93
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:1550
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition: settings_type.h:618
IsCoast
bool IsCoast(Tile t)
Is it a coast tile?
Definition: water_map.h:204
TileInfo::tileh
Slope tileh
Slope of the tile.
Definition: tile_cmd.h:46
GetTileType
static debug_inline TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
Definition: tile_map.h:96
MakeClear
void MakeClear(Tile t, ClearGround g, uint density)
Make a clear tile.
Definition: clear_map.h:259
TO_TREES
@ TO_TREES
trees
Definition: transparency.h:24
SoundSettings::ambient
bool ambient
Play ambient, industry and town sounds.
Definition: settings_type.h:244
IsInvisibilitySet
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
Slope
Slope
Enumeration for the slope-type.
Definition: slope_type.h:48
TREE_GROUND_ROUGH
@ TREE_GROUND_ROUGH
some rough tile
Definition: tree_map.h:54
IsInsideBS
constexpr bool IsInsideBS(const T x, const size_t base, const size_t size)
Checks if a value is between a window started at some base point.
Definition: math_func.hpp:252
TREE_SUB_ARCTIC
@ TREE_SUB_ARCTIC
tree on a sub_arctic landscape
Definition: tree_map.h:27
EDITOR_TREE_DIV
static const uint16_t EDITOR_TREE_DIV
Game editor tree generation divisor factor.
Definition: tree_cmd.cpp:59
GetTreeGrowth
uint GetTreeGrowth(Tile t)
Returns the tree growth status.
Definition: tree_map.h:181
landscape_cmd.h
return_cmd_error
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
Definition: command_func.h:38
EXPENSES_CONSTRUCTION
@ EXPENSES_CONSTRUCTION
Construction costs.
Definition: economy_type.h:173
TileAddWrap
TileIndex TileAddWrap(TileIndex tile, int addx, int addy)
This function checks if we add addx/addy to tile, if we do wrap around the edges.
Definition: map.cpp:116
CommandCost
Common return value for all commands.
Definition: command_type.h:23
GetSnowLine
byte GetSnowLine()
Get the current snow line, either variable or static.
Definition: landscape.cpp:611
CompanyProperties::tree_limit
uint32_t tree_limit
Amount of trees we can (still) plant (times 65536).
Definition: company_base.h:101
ClientSettings::sound
SoundSettings sound
sound effect settings
Definition: settings_type.h:638
clear_func.h
GetSlopeMaxPixelZ
static constexpr int GetSlopeMaxPixelZ(Slope s)
Returns the height of the highest corner of a slope relative to TileZ (= minimal height)
Definition: slope_func.h:173
_trees_tick_ctr
byte _trees_tick_ctr
Determines when to consider building more trees.
Definition: tree_cmd.cpp:55
ETP_NO_SPREAD
@ ETP_NO_SPREAD
Grow trees on tiles that have them but don't spread to new ones.
Definition: tree_cmd.cpp:48
TransportType
TransportType
Available types of transport.
Definition: transport_type.h:19
MP_WATER
@ MP_WATER
Water tile.
Definition: tile_type.h:54
TREE_CACTUS
@ TREE_CACTUS
a cactus for the 'desert part' on a sub-tropical map
Definition: tree_map.h:29
GetRawClearGround
ClearGround GetRawClearGround(Tile t)
Get the type of clear tile but never return CLEAR_SNOW.
Definition: clear_map.h:47
GetClearGround
ClearGround GetClearGround(Tile t)
Get the type of clear tile.
Definition: clear_map.h:59
CommandCost::Failed
bool Failed() const
Did this command fail?
Definition: command_type.h:171
ETP_SPREAD_RAINFOREST
@ ETP_SPREAD_RAINFOREST
Grow trees on tiles that have them, only spread to new ones in rainforests.
Definition: tree_cmd.cpp:49
PlaceTreeGroupAroundTile
uint PlaceTreeGroupAroundTile(TileIndex tile, TreeType treetype, uint radius, uint count, bool set_zone)
Place some trees in a radius around a tile.
Definition: tree_cmd.cpp:306
PlaceTreeGroups
static void PlaceTreeGroups(uint num_groups)
Creates a number of tree groups.
Definition: tree_cmd.cpp:186
EndSpriteCombine
void EndSpriteCombine()
Terminates a block of sprites started by StartSpriteCombine.
Definition: viewport.cpp:779
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:55
TP_IMPROVED
@ TP_IMPROVED
A 'improved' algorithm.
Definition: tree_cmd.cpp:43
timer_game_tick.h
GameSettings::economy
EconomySettings economy
settings to change the economy
Definition: settings_type.h:627
safeguards.h
lengthof
#define lengthof(array)
Return the length of an fixed size array.
Definition: stdafx.h:303
CommandCost::GetCost
Money GetCost() const
The costs as made up to this moment.
Definition: command_type.h:83
GetTileSlope
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
Definition: tile_map.cpp:59
CLEAR_ROUGH
@ CLEAR_ROUGH
3
Definition: clear_map.h:21
RandomTile
#define RandomTile()
Get a valid random tile.
Definition: map_func.h:657
GetTileOwner
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
Definition: tile_map.h:178
StartSpriteCombine
void StartSpriteCombine()
Starts a block of sprites, which are "combined" into a single bounding box.
Definition: viewport.cpp:769
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
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition: direction_type.h:73
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:51
CommandCost::AddCost
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
Definition: command_type.h:63
SetTreeGroundDensity
void SetTreeGroundDensity(Tile t, TreeGround g, uint d)
Set the density and ground type of a tile with trees.
Definition: tree_map.h:130
stdafx.h
landscape.h
TileTypeProcs
Set of callback functions for performing tile operations of a given tile type.
Definition: tile_cmd.h:158
SoundFx
SoundFx
Sound effects from baseset.
Definition: sound_type.h:37
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
CountBits
constexpr uint CountBits(T value)
Counts the number of set bits in a variable.
Definition: bitmath_func.hpp:243
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:1233
Chance16I
bool Chance16I(const uint a, const uint b, const uint32_t r)
Checks if a given randomize-number is below a given probability.
Definition: random_func.hpp:112
ChangeTownRating
void ChangeTownRating(Town *t, int add, int max, DoCommandFlag flags)
Changes town rating of the current company.
Definition: town_cmd.cpp:3862
AddSortableSpriteToDraw
void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, int x, int y, int w, int h, int dz, int z, bool transparent, int bb_offset_x, int bb_offset_y, int bb_offset_z, const SubSprite *sub)
Draw a (transparent) sprite at given coordinates with a given bounding box.
Definition: viewport.cpp:673
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:50
MP_TREES
@ MP_TREES
Tile got trees.
Definition: tile_type.h:52
EconomySettings::dist_local_authority
byte dist_local_authority
distance for town local authority, default 20
Definition: settings_type.h:542
DistanceSquare
uint DistanceSquare(TileIndex t0, TileIndex t1)
Gets the 'Square' distance between the two given tiles.
Definition: map.cpp:176
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
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:51
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:134
MP_VOID
@ MP_VOID
Invisible tiles at the SW and SE border.
Definition: tile_type.h:55
MAX_MAP_SIZE_BITS
static const uint MAX_MAP_SIZE_BITS
Maximal size of map is equal to 2 ^ MAX_MAP_SIZE_BITS.
Definition: map_type.h:38
TreeListEnt
Definition: tree_cmd.cpp:514
GetTilePixelSlope
Slope GetTilePixelSlope(TileIndex tile, int *h)
Return the slope of a given tile.
Definition: tile_map.h:280
abs
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
Definition: math_func.hpp:23
Map::Size
static debug_inline uint Size()
Get the size of the map.
Definition: map_func.h:288
MakeShore
void MakeShore(Tile t)
Helper function to make a coast tile.
Definition: water_map.h:384
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:1536
TreePlacer
TreePlacer
List of tree placer algorithm.
Definition: tree_cmd.cpp:40
TP_ORIGINAL
@ TP_ORIGINAL
The original algorithm.
Definition: tree_cmd.cpp:42
PlaceTree
static void PlaceTree(TileIndex tile, uint32_t r)
Make a random tree tile of the given tile.
Definition: tree_cmd.cpp:164
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:2051
SetTreeGrowth
void SetTreeGrowth(Tile t, uint g)
Sets the tree growth status of a tile.
Definition: tree_map.h:212
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:94
IsBridgeAbove
bool IsBridgeAbove(Tile t)
checks if a bridge is set above the ground of this tile
Definition: bridge_map.h:45
TileDesc::str
StringID str
Description of the tile.
Definition: tile_cmd.h:53
PalSpriteID
Combination of a palette sprite and a 'real' sprite.
Definition: gfx_type.h:22
DecrementTreeCounter
bool DecrementTreeCounter()
Decrement the tree tick counter.
Definition: tree_cmd.cpp:820
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
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:69
TileArea
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
Definition: tilearea_type.h:102
CommandHelper
Definition: command_func.h:93
DEFAULT_TREE_STEPS
static const uint16_t DEFAULT_TREE_STEPS
Default number of attempts for placing trees.
Definition: tree_cmd.cpp:57
Town
Town data structure.
Definition: town.h:50
Delta
constexpr T Delta(const T a, const T b)
Returns the (absolute) difference between two (scalar) variables.
Definition: math_func.hpp:234
SlopeToSpriteOffset
uint SlopeToSpriteOffset(Slope s)
Returns the Sprite offset for a given Slope.
Definition: slope_func.h:415
random_func.hpp
CmdPlantTree
CommandCost CmdPlantTree(DoCommandFlag flags, TileIndex tile, TileIndex start_tile, byte tree_to_plant, bool diagonal)
Plant a tree.
Definition: tree_cmd.cpp:388
GameCreationSettings::tree_placer
byte tree_placer
the tree placer algorithm
Definition: settings_type.h:351
TREE_TEMPERATE
@ TREE_TEMPERATE
temperate tree
Definition: tree_map.h:26
MakeTree
void MakeTree(Tile t, TreeType type, uint count, uint growth, TreeGround ground, uint density)
Make a tree-tile.
Definition: tree_map.h:230
TileInfo::x
int x
X position of the tile in unit coordinates.
Definition: tile_cmd.h:44
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:47
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:619
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
IsTileType
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
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:328
SND_43_RAINFOREST_2
@ SND_43_RAINFOREST_2
67 == 0x43 Tree ambient: rainforest ambient (2): lion
Definition: sound_type.h:106
GetTreeType
TreeType GetTreeType(Tile t)
Returns the treetype of a tile.
Definition: tree_map.h:73
TROPICZONE_NORMAL
@ TROPICZONE_NORMAL
Normal tropiczone.
Definition: tile_type.h:77
TileX
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:427
Company
Definition: company_base.h:129
IsSlopeWithOneCornerRaised
bool IsSlopeWithOneCornerRaised(Slope s)
Tests if a specific slope has exactly one corner raised.
Definition: slope_func.h:88
CLEAR_FIELDS
@ CLEAR_FIELDS
3
Definition: clear_map.h:23
GetTropicZone
TropicZone GetTropicZone(Tile tile)
Get the tropic zone.
Definition: tile_map.h:238
SetTropicZone
void SetTropicZone(Tile tile, TropicZone type)
Set the tropic zone.
Definition: tile_map.h:225
ConstructionSettings::extra_tree_placement
uint8_t extra_tree_placement
(dis)allow building extra trees in-game
Definition: settings_type.h:383
GetClearDensity
uint GetClearDensity(Tile t)
Get the density of a non-field clear tile.
Definition: clear_map.h:83
GetTreeDensity
uint GetTreeDensity(Tile t)
Returns the 'density' of a tile with trees.
Definition: tree_map.h:113
RandomTileSeed
TileIndex RandomTileSeed(uint32_t r)
Get a random tile out of a given seed.
Definition: map_func.h:646
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:589
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
DEFAULT_RAINFOREST_TREE_STEPS
static const uint16_t DEFAULT_RAINFOREST_TREE_STEPS
Default number of attempts for placing extra trees at rainforest in tropic.
Definition: tree_cmd.cpp:58
TreeType
TreeType
List of tree types along all landscape types.
Definition: tree_map.h:25
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