2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file tree_cmd.cpp Handling of tree tiles. */
|
2007-04-04 03:21:14 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2006-03-05 10:19:33 +00:00
|
|
|
#include "clear_map.h"
|
2007-03-20 13:47:00 +00:00
|
|
|
#include "landscape.h"
|
2006-03-05 10:19:33 +00:00
|
|
|
#include "tree_map.h"
|
2008-01-09 09:57:48 +00:00
|
|
|
#include "viewport_func.h"
|
2007-12-21 21:50:46 +00:00
|
|
|
#include "command_func.h"
|
|
|
|
#include "economy_func.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "town.h"
|
2005-07-21 18:44:27 +00:00
|
|
|
#include "variables.h"
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
#include "genworld.h"
|
2007-11-10 01:17:15 +00:00
|
|
|
#include "transparency.h"
|
2007-12-25 11:26:07 +00:00
|
|
|
#include "functions.h"
|
2008-09-30 20:51:04 +00:00
|
|
|
#include "company_func.h"
|
2007-12-29 09:24:26 +00:00
|
|
|
#include "sound_func.h"
|
2008-01-31 17:54:13 +00:00
|
|
|
#include "water_map.h"
|
|
|
|
#include "water.h"
|
2008-05-07 09:07:19 +00:00
|
|
|
#include "landscape_type.h"
|
2008-09-30 20:51:04 +00:00
|
|
|
#include "company_base.h"
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/strings.h"
|
|
|
|
#include "table/sprites.h"
|
|
|
|
#include "table/tree_land.h"
|
2009-09-07 13:38:57 +00:00
|
|
|
#include "table/clear_land.h"
|
2008-01-13 01:21:35 +00:00
|
|
|
|
2007-09-17 16:56:15 +00:00
|
|
|
/**
|
|
|
|
* List of tree placer algorithm.
|
|
|
|
*
|
|
|
|
* This enumeration defines all possible tree placer algorithm in the game.
|
|
|
|
*/
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
enum TreePlacer {
|
2007-09-17 16:56:15 +00:00
|
|
|
TP_NONE, ///< No tree placer algorithm
|
|
|
|
TP_ORIGINAL, ///< The original algorithm
|
|
|
|
TP_IMPROVED, ///< A 'improved' algorithm
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-01-30 18:40:42 +00:00
|
|
|
/**
|
|
|
|
* Tests if a tile can be converted to MP_TREES
|
|
|
|
* This is true for clear ground without farms or rocks.
|
|
|
|
*
|
|
|
|
* @param tile the tile of interest
|
|
|
|
* @param allow_desert Allow planting trees on CLEAR_DESERT?
|
|
|
|
* @return true if trees can be built.
|
|
|
|
*/
|
2008-01-31 17:54:13 +00:00
|
|
|
static bool CanPlantTreesOnTile(TileIndex tile, bool allow_desert)
|
2008-01-30 18:40:42 +00:00
|
|
|
{
|
2008-01-31 17:54:13 +00:00
|
|
|
switch (GetTileType(tile)) {
|
|
|
|
case MP_WATER:
|
|
|
|
return !IsBridgeAbove(tile) && IsCoast(tile) && !IsSlopeWithOneCornerRaised(GetTileSlope(tile, NULL));
|
|
|
|
|
|
|
|
case MP_CLEAR:
|
|
|
|
return !IsBridgeAbove(tile) && !IsClearGround(tile, CLEAR_FIELDS) && !IsClearGround(tile, CLEAR_ROCKS) &&
|
|
|
|
(allow_desert || !IsClearGround(tile, CLEAR_DESERT));
|
|
|
|
|
|
|
|
default: return false;
|
|
|
|
}
|
2008-01-30 18:40:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a tree tile
|
|
|
|
* Ground type and density is preserved.
|
|
|
|
*
|
|
|
|
* @pre the tile must be suitable for trees.
|
|
|
|
*
|
|
|
|
* @param tile where to plant the trees.
|
2009-09-19 09:51:14 +00:00
|
|
|
* @param treetype The type of the tree
|
2008-01-30 18:40:42 +00:00
|
|
|
* @param count the number of trees (minus 1)
|
|
|
|
* @param growth the growth status
|
|
|
|
*/
|
|
|
|
static void PlantTreesOnTile(TileIndex tile, TreeType treetype, uint count, uint growth)
|
|
|
|
{
|
|
|
|
assert(treetype != TREE_INVALID);
|
|
|
|
assert(CanPlantTreesOnTile(tile, true));
|
|
|
|
|
|
|
|
TreeGround ground;
|
|
|
|
uint density = 3;
|
2008-01-31 17:54:13 +00:00
|
|
|
|
|
|
|
switch (GetTileType(tile)) {
|
|
|
|
case MP_WATER:
|
|
|
|
ground = TREE_GROUND_SHORE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_CLEAR:
|
|
|
|
switch (GetClearGround(tile)) {
|
|
|
|
case CLEAR_GRASS: ground = TREE_GROUND_GRASS; density = GetClearDensity(tile); break;
|
|
|
|
case CLEAR_ROUGH: ground = TREE_GROUND_ROUGH; break;
|
|
|
|
default: ground = TREE_GROUND_SNOW_DESERT; density = GetClearDensity(tile); break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: NOT_REACHED();
|
2008-01-30 18:40:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MakeTree(tile, treetype, count, growth, ground, density);
|
|
|
|
}
|
|
|
|
|
2007-09-17 16:56:15 +00:00
|
|
|
/**
|
|
|
|
* Get a random TreeType for the given tile based on a given seed
|
|
|
|
*
|
|
|
|
* This function returns a random TreeType which can be placed on the given tile.
|
|
|
|
* The seed for randomness must be less or equal 256, use #GB on the value of Random()
|
|
|
|
* to get such a value.
|
|
|
|
*
|
|
|
|
* @param tile The tile to get a random TreeType from
|
|
|
|
* @param seed The seed for randomness, must be less or equal 256
|
|
|
|
* @return The random tree type
|
|
|
|
*/
|
2006-02-05 14:47:15 +00:00
|
|
|
static TreeType GetRandomTreeType(TileIndex tile, uint seed)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-05-29 15:13:28 +00:00
|
|
|
switch (_settings_game.game_creation.landscape) {
|
2007-03-22 03:42:43 +00:00
|
|
|
case LT_TEMPERATE:
|
2007-01-10 18:56:51 +00:00
|
|
|
return (TreeType)(seed * TREE_COUNT_TEMPERATE / 256 + TREE_TEMPERATE);
|
2005-02-04 16:50:18 +00:00
|
|
|
|
2007-03-22 03:42:43 +00:00
|
|
|
case LT_ARCTIC:
|
2007-01-10 18:56:51 +00:00
|
|
|
return (TreeType)(seed * TREE_COUNT_SUB_ARCTIC / 256 + TREE_SUB_ARCTIC);
|
2005-02-04 16:50:18 +00:00
|
|
|
|
2007-03-22 03:42:43 +00:00
|
|
|
case LT_TROPIC:
|
2006-03-30 19:16:44 +00:00
|
|
|
switch (GetTropicZone(tile)) {
|
2008-01-30 17:22:06 +00:00
|
|
|
case TROPICZONE_NORMAL: return (TreeType)(seed * TREE_COUNT_SUB_TROPICAL / 256 + TREE_SUB_TROPICAL);
|
2007-01-10 18:56:51 +00:00
|
|
|
case TROPICZONE_DESERT: return (TreeType)((seed > 12) ? TREE_INVALID : TREE_CACTUS);
|
|
|
|
default: return (TreeType)(seed * TREE_COUNT_RAINFOREST / 256 + TREE_RAINFOREST);
|
2005-02-04 16:50:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
2007-01-10 18:56:51 +00:00
|
|
|
return (TreeType)(seed * TREE_COUNT_TOYLAND / 256 + TREE_TOYLAND);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-17 16:56:15 +00:00
|
|
|
/**
|
|
|
|
* Make a random tree tile of the given tile
|
|
|
|
*
|
|
|
|
* Create a new tree-tile for the given tile. The second parameter is used for
|
|
|
|
* randomness like type and number of trees.
|
|
|
|
*
|
|
|
|
* @param tile The tile to make a tree-tile from
|
|
|
|
* @param r The randomness value from a Random() value
|
|
|
|
*/
|
2006-02-02 07:15:46 +00:00
|
|
|
static void PlaceTree(TileIndex tile, uint32 r)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-02-05 14:47:15 +00:00
|
|
|
TreeType tree = GetRandomTreeType(tile, GB(r, 24, 8));
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-04 06:25:05 +00:00
|
|
|
if (tree != TREE_INVALID) {
|
2008-01-30 18:40:42 +00:00
|
|
|
PlantTreesOnTile(tile, tree, GB(r, 22, 2), min(GB(r, 16, 3), 6));
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-01-31 17:54:13 +00:00
|
|
|
/* Rerandomize ground, if neither snow nor shore */
|
|
|
|
TreeGround ground = GetTreeGround(tile);
|
|
|
|
if (ground != TREE_GROUND_SNOW_DESERT && ground != TREE_GROUND_SHORE) {
|
2007-10-11 11:06:04 +00:00
|
|
|
SetTreeGroundDensity(tile, (TreeGround)GB(r, 28, 1), 3);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2008-01-30 18:40:42 +00:00
|
|
|
|
|
|
|
/* Set the counter to a random start value */
|
|
|
|
SetTreeCounter(tile, (TreeGround)GB(r, 24, 4));
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-17 16:56:15 +00:00
|
|
|
/**
|
|
|
|
* Place some amount of trees around a given tile.
|
|
|
|
*
|
|
|
|
* This function adds some trees around a given tile. As this function use
|
|
|
|
* the Random() call it depends on the random how many trees are actually placed
|
|
|
|
* around the given tile.
|
|
|
|
*
|
|
|
|
* @param tile The center of the trees to add
|
|
|
|
*/
|
2005-06-24 12:38:35 +00:00
|
|
|
static void DoPlaceMoreTrees(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-07-17 11:09:03 +00:00
|
|
|
uint i;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-17 11:09:03 +00:00
|
|
|
for (i = 0; i < 1000; i++) {
|
2004-08-09 17:04:08 +00:00
|
|
|
uint32 r = Random();
|
2005-07-17 11:09:03 +00:00
|
|
|
int x = GB(r, 0, 5) - 16;
|
|
|
|
int y = GB(r, 8, 5) - 16;
|
2007-11-19 18:58:04 +00:00
|
|
|
uint dist = abs(x) + abs(y);
|
2009-02-25 21:29:50 +00:00
|
|
|
TileIndex cur_tile = TileAddWrap(tile, x, y);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-02-25 21:29:50 +00:00
|
|
|
if (cur_tile != INVALID_TILE && dist <= 13 && CanPlantTreesOnTile(cur_tile, true)) {
|
2006-02-02 07:15:46 +00:00
|
|
|
PlaceTree(cur_tile, r);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2005-07-17 11:09:03 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-09-17 16:56:15 +00:00
|
|
|
/**
|
|
|
|
* Place more trees on the map.
|
|
|
|
*
|
|
|
|
* This function add more trees to the map.
|
|
|
|
*/
|
2007-03-07 11:47:46 +00:00
|
|
|
static void PlaceMoreTrees()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-07-30 18:30:07 +00:00
|
|
|
uint i = ScaleByMapSize(GB(Random(), 0, 5) + 25);
|
2004-08-09 17:04:08 +00:00
|
|
|
do {
|
2005-07-13 19:51:31 +00:00
|
|
|
DoPlaceMoreTrees(RandomTile());
|
2004-08-09 17:04:08 +00:00
|
|
|
} while (--i);
|
|
|
|
}
|
|
|
|
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
/**
|
|
|
|
* Place a tree at the same height as an existing tree.
|
2007-09-17 16:56:15 +00:00
|
|
|
*
|
|
|
|
* Add a new tree around the given tile which is at the same
|
|
|
|
* height or at some offset (2 units) of it.
|
|
|
|
*
|
|
|
|
* @param tile The base tile to add a new tree somewhere around
|
|
|
|
* @param height The height (like the one from the tile)
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
*/
|
2008-01-30 18:40:42 +00:00
|
|
|
static void PlaceTreeAtSameHeight(TileIndex tile, uint height)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-07-17 11:09:03 +00:00
|
|
|
uint i;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
for (i = 0; i < 1000; i++) {
|
|
|
|
uint32 r = Random();
|
|
|
|
int x = GB(r, 0, 5) - 16;
|
|
|
|
int y = GB(r, 8, 5) - 16;
|
2009-02-25 21:29:50 +00:00
|
|
|
TileIndex cur_tile = TileAddWrap(tile, x, y);
|
|
|
|
if (cur_tile == INVALID_TILE) continue;
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
|
|
|
|
/* Keep in range of the existing tree */
|
2007-11-19 18:58:04 +00:00
|
|
|
if (abs(x) + abs(y) > 16) continue;
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
|
|
|
|
/* Clear tile, no farm-tiles or rocks */
|
2008-01-30 18:40:42 +00:00
|
|
|
if (!CanPlantTreesOnTile(cur_tile, true)) continue;
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
|
|
|
|
/* Not too much height difference */
|
2007-11-26 16:01:29 +00:00
|
|
|
if (Delta(GetTileZ(cur_tile), height) > 2) continue;
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
|
|
|
|
/* Place one tree and quit */
|
|
|
|
PlaceTree(cur_tile, r);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-17 16:56:15 +00:00
|
|
|
/**
|
|
|
|
* Place some trees randomly
|
|
|
|
*
|
|
|
|
* This function just place some trees randomly on the map.
|
|
|
|
*/
|
2007-03-07 11:47:46 +00:00
|
|
|
void PlaceTreesRandomly()
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
{
|
|
|
|
uint i, j, ht;
|
|
|
|
|
2005-01-28 15:31:04 +00:00
|
|
|
i = ScaleByMapSize(1000);
|
2004-08-09 17:04:08 +00:00
|
|
|
do {
|
2005-07-17 11:09:03 +00:00
|
|
|
uint32 r = Random();
|
|
|
|
TileIndex tile = RandomTileSeed(r);
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
|
|
|
|
IncreaseGeneratingWorldProgress(GWP_TREE);
|
|
|
|
|
2008-01-30 18:40:42 +00:00
|
|
|
if (CanPlantTreesOnTile(tile, true)) {
|
2006-02-02 07:15:46 +00:00
|
|
|
PlaceTree(tile, r);
|
2008-05-29 15:13:28 +00:00
|
|
|
if (_settings_game.game_creation.tree_placer != TP_IMPROVED) continue;
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
|
|
|
|
/* Place a number of trees based on the tile height.
|
|
|
|
* This gives a cool effect of multiple trees close together.
|
|
|
|
* It is almost real life ;) */
|
|
|
|
ht = GetTileZ(tile);
|
|
|
|
/* The higher we get, the more trees we plant */
|
|
|
|
j = GetTileZ(tile) / TILE_HEIGHT * 2;
|
|
|
|
while (j--) {
|
|
|
|
/* Above snowline more trees! */
|
2008-05-29 15:13:28 +00:00
|
|
|
if (_settings_game.game_creation.landscape == LT_ARCTIC && ht > GetSnowLine()) {
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
PlaceTreeAtSameHeight(tile, ht);
|
|
|
|
PlaceTreeAtSameHeight(tile, ht);
|
|
|
|
};
|
|
|
|
|
|
|
|
PlaceTreeAtSameHeight(tile, ht);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
} while (--i);
|
|
|
|
|
|
|
|
/* place extra trees at rainforest area */
|
2008-05-29 15:13:28 +00:00
|
|
|
if (_settings_game.game_creation.landscape == LT_TROPIC) {
|
2005-01-28 15:31:04 +00:00
|
|
|
i = ScaleByMapSize(15000);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
do {
|
2005-07-17 11:09:03 +00:00
|
|
|
uint32 r = Random();
|
|
|
|
TileIndex tile = RandomTileSeed(r);
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
|
|
|
|
IncreaseGeneratingWorldProgress(GWP_TREE);
|
|
|
|
|
2008-01-30 18:40:42 +00:00
|
|
|
if (GetTropicZone(tile) == TROPICZONE_RAINFOREST && CanPlantTreesOnTile(tile, false)) {
|
2006-02-02 07:15:46 +00:00
|
|
|
PlaceTree(tile, r);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
} while (--i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-17 16:56:15 +00:00
|
|
|
/**
|
|
|
|
* Place new trees.
|
|
|
|
*
|
|
|
|
* This function takes care of the selected tree placer algorithm and
|
|
|
|
* place randomly the trees for a new game.
|
|
|
|
*/
|
2007-03-07 11:47:46 +00:00
|
|
|
void GenerateTrees()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
uint i, total;
|
|
|
|
|
2008-05-29 15:13:28 +00:00
|
|
|
if (_settings_game.game_creation.tree_placer == TP_NONE) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-29 15:13:28 +00:00
|
|
|
if (_settings_game.game_creation.landscape != LT_TOYLAND) PlaceMoreTrees();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-29 15:13:28 +00:00
|
|
|
switch (_settings_game.game_creation.tree_placer) {
|
|
|
|
case TP_ORIGINAL: i = _settings_game.game_creation.landscape == LT_ARCTIC ? 15 : 6; break;
|
|
|
|
case TP_IMPROVED: i = _settings_game.game_creation.landscape == LT_ARCTIC ? 4 : 2; break;
|
2009-05-26 15:46:24 +00:00
|
|
|
default: NOT_REACHED();
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
total = ScaleByMapSize(1000);
|
2008-05-29 15:13:28 +00:00
|
|
|
if (_settings_game.game_creation.landscape == LT_TROPIC) total += ScaleByMapSize(15000);
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
total *= i;
|
|
|
|
SetGeneratingWorldProgress(GWP_TREE, total);
|
|
|
|
|
|
|
|
for (; i != 0; i--) {
|
2004-08-09 17:04:08 +00:00
|
|
|
PlaceTreesRandomly();
|
2005-07-17 11:09:03 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-05-09 22:33:00 +00:00
|
|
|
/** Plant a tree.
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile start tile of area-drag of tree plantation
|
2007-04-04 03:21:14 +00:00
|
|
|
* @param flags type of operation
|
2005-05-09 22:33:00 +00:00
|
|
|
* @param p1 tree type, -1 means random.
|
|
|
|
* @param p2 end tile of area-drag
|
2009-09-18 14:23:58 +00:00
|
|
|
* @param text unused
|
|
|
|
* @return the cost of this operation or an error
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
2009-02-09 21:20:05 +00:00
|
|
|
CommandCost CmdPlantTree(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-03-12 12:19:25 +00:00
|
|
|
StringID msg = INVALID_STRING_ID;
|
2008-01-09 16:55:48 +00:00
|
|
|
CommandCost cost(EXPENSES_OTHER);
|
2006-04-10 07:15:58 +00:00
|
|
|
int ex;
|
|
|
|
int ey;
|
2005-07-18 00:17:19 +00:00
|
|
|
int sx, sy, x, y;
|
2005-02-04 16:50:18 +00:00
|
|
|
|
2006-01-26 18:45:04 +00:00
|
|
|
if (p2 >= MapSize()) return CMD_ERROR;
|
2005-05-09 22:33:00 +00:00
|
|
|
/* Check the tree type. It can be random or some valid value within the current climate */
|
2008-10-14 18:38:51 +00:00
|
|
|
if (p1 != UINT_MAX && p1 - _tree_base_by_landscape[_settings_game.game_creation.landscape] >= _tree_count_by_landscape[_settings_game.game_creation.landscape]) return CMD_ERROR;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
/* make sure sx,sy are smaller than ex, ey */
|
2006-04-10 07:15:58 +00:00
|
|
|
ex = TileX(tile);
|
|
|
|
ey = TileY(tile);
|
2005-07-18 00:17:19 +00:00
|
|
|
sx = TileX(p2);
|
|
|
|
sy = TileY(p2);
|
2007-02-22 08:43:02 +00:00
|
|
|
if (ex < sx) Swap(ex, sx);
|
|
|
|
if (ey < sy) Swap(ey, sy);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-07-18 00:17:19 +00:00
|
|
|
for (x = sx; x <= ex; x++) {
|
|
|
|
for (y = sy; y <= ey; y++) {
|
2005-07-17 11:09:03 +00:00
|
|
|
TileIndex tile = TileXY(x, y);
|
2005-02-04 16:50:18 +00:00
|
|
|
|
2005-07-17 11:09:03 +00:00
|
|
|
switch (GetTileType(tile)) {
|
2005-02-04 16:50:18 +00:00
|
|
|
case MP_TREES:
|
2007-04-04 03:21:14 +00:00
|
|
|
/* no more space for trees? */
|
2008-11-23 16:45:53 +00:00
|
|
|
if (_game_mode != GM_EDITOR && GetTreeCount(tile) == 4) {
|
2009-04-21 23:40:56 +00:00
|
|
|
msg = STR_ERROR_TREE_ALREADY_HERE;
|
2005-02-04 16:50:18 +00:00
|
|
|
continue;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-04 16:50:18 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2006-02-05 14:47:15 +00:00
|
|
|
AddTreeCount(tile, 1);
|
2005-07-17 11:09:03 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2007-04-04 03:21:14 +00:00
|
|
|
/* 2x as expensive to add more trees to an existing tile */
|
2007-06-18 19:53:50 +00:00
|
|
|
cost.AddCost(_price.build_trees * 2);
|
2005-02-04 16:50:18 +00:00
|
|
|
break;
|
|
|
|
|
2007-08-31 20:03:50 +00:00
|
|
|
case MP_WATER:
|
2008-01-31 17:54:13 +00:00
|
|
|
if (!IsCoast(tile) || IsSlopeWithOneCornerRaised(GetTileSlope(tile, NULL))) {
|
2009-04-21 23:40:56 +00:00
|
|
|
msg = STR_ERROR_CAN_T_BUILD_ON_WATER;
|
2008-01-31 17:54:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* FALL THROUGH */
|
2005-02-04 16:50:18 +00:00
|
|
|
case MP_CLEAR:
|
2008-01-30 18:40:42 +00:00
|
|
|
if (IsBridgeAbove(tile)) {
|
2009-04-21 23:40:56 +00:00
|
|
|
msg = STR_ERROR_SITE_UNSUITABLE;
|
2005-02-04 16:50:18 +00:00
|
|
|
continue;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-01-31 17:54:13 +00:00
|
|
|
if (IsTileType(tile, MP_CLEAR)) {
|
|
|
|
/* Remove fields or rocks. Note that the ground will get barrened */
|
|
|
|
switch (GetClearGround(tile)) {
|
|
|
|
case CLEAR_FIELDS:
|
|
|
|
case CLEAR_ROCKS: {
|
|
|
|
CommandCost ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
|
|
|
if (CmdFailed(ret)) return ret;
|
|
|
|
cost.AddCost(ret);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default: break;
|
2008-01-30 18:40:42 +00:00
|
|
|
}
|
2006-02-01 15:31:21 +00:00
|
|
|
}
|
2005-02-04 16:50:18 +00:00
|
|
|
|
2009-05-17 01:00:56 +00:00
|
|
|
if (_game_mode != GM_EDITOR && Company::IsValidID(_current_company)) {
|
2008-05-29 15:13:28 +00:00
|
|
|
Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority);
|
2009-02-11 18:50:47 +00:00
|
|
|
if (t != NULL) ChangeTownRating(t, RATING_TREE_UP_STEP, RATING_TREE_MAXIMUM, flags);
|
2008-01-09 17:47:05 +00:00
|
|
|
}
|
|
|
|
|
2005-02-04 16:50:18 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2006-02-05 14:47:15 +00:00
|
|
|
TreeType treetype;
|
2005-02-04 16:50:18 +00:00
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
treetype = (TreeType)p1;
|
2006-04-04 06:25:05 +00:00
|
|
|
if (treetype == TREE_INVALID) {
|
2005-11-14 08:09:57 +00:00
|
|
|
treetype = GetRandomTreeType(tile, GB(Random(), 24, 8));
|
2006-04-04 06:25:05 +00:00
|
|
|
if (treetype == TREE_INVALID) treetype = TREE_CACTUS;
|
2005-02-04 16:50:18 +00:00
|
|
|
}
|
|
|
|
|
2008-01-30 18:40:42 +00:00
|
|
|
/* Plant full grown trees in scenario editor */
|
|
|
|
PlantTreesOnTile(tile, treetype, 0, _game_mode == GM_EDITOR ? 3 : 0);
|
2006-02-09 07:34:37 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
2006-02-05 14:47:15 +00:00
|
|
|
|
2008-01-30 18:40:42 +00:00
|
|
|
/* When planting rainforest-trees, set tropiczone to rainforest in editor. */
|
2007-11-24 10:38:43 +00:00
|
|
|
if (_game_mode == GM_EDITOR && IsInsideMM(treetype, TREE_RAINFOREST, TREE_CACTUS))
|
2006-03-30 19:16:44 +00:00
|
|
|
SetTropicZone(tile, TROPICZONE_RAINFOREST);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2007-06-18 19:53:50 +00:00
|
|
|
cost.AddCost(_price.build_trees);
|
2005-02-04 16:50:18 +00:00
|
|
|
break;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-02-04 16:50:18 +00:00
|
|
|
default:
|
2009-04-21 23:40:56 +00:00
|
|
|
msg = STR_ERROR_SITE_UNSUITABLE;
|
2005-02-04 16:50:18 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2007-06-18 19:53:50 +00:00
|
|
|
if (cost.GetCost() == 0) {
|
2006-03-12 12:19:25 +00:00
|
|
|
return_cmd_error(msg);
|
|
|
|
} else {
|
|
|
|
return cost;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
struct TreeListEnt {
|
2007-01-14 19:57:49 +00:00
|
|
|
SpriteID image;
|
|
|
|
SpriteID pal;
|
2007-04-18 22:10:36 +00:00
|
|
|
byte x, y;
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
static void DrawTile_Trees(TileInfo *ti)
|
|
|
|
{
|
2006-02-05 14:47:15 +00:00
|
|
|
switch (GetTreeGround(ti->tile)) {
|
2008-01-31 17:54:13 +00:00
|
|
|
case TREE_GROUND_SHORE: DrawShoreTile(ti->tileh); break;
|
2007-10-11 11:06:04 +00:00
|
|
|
case TREE_GROUND_GRASS: DrawClearLandTile(ti, GetTreeDensity(ti->tile)); break;
|
2006-04-04 06:25:05 +00:00
|
|
|
case TREE_GROUND_ROUGH: DrawHillyLandTile(ti); break;
|
2009-09-07 13:38:57 +00:00
|
|
|
default: DrawGroundSprite(_clear_land_sprites_snow_desert[GetTreeDensity(ti->tile)] + _tileh_to_sprite[ti->tileh], PAL_NONE); break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-07-28 19:18:27 +00:00
|
|
|
DrawClearLandFence(ti);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-02-08 12:25:13 +00:00
|
|
|
/* Do not draw trees when the invisible trees setting is set */
|
2008-04-03 19:55:40 +00:00
|
|
|
if (IsInvisibilitySet(TO_TREES)) return;
|
2008-02-06 22:59:31 +00:00
|
|
|
|
2008-02-06 23:08:04 +00:00
|
|
|
uint16 tmp = ti->x;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-02-06 23:08:04 +00:00
|
|
|
tmp = ROR(tmp, 2);
|
|
|
|
tmp -= ti->y;
|
|
|
|
tmp = ROR(tmp, 3);
|
|
|
|
tmp -= ti->x;
|
|
|
|
tmp = ROR(tmp, 1);
|
|
|
|
tmp += ti->y;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-02-06 23:08:04 +00:00
|
|
|
uint index = GB(tmp, 6, 2) + (GetTreeType(ti->tile) << 2);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-02-06 23:08:04 +00:00
|
|
|
/* different tree styles above one of the grounds */
|
|
|
|
if (GetTreeGround(ti->tile) == TREE_GROUND_SNOW_DESERT &&
|
|
|
|
GetTreeDensity(ti->tile) >= 2 &&
|
|
|
|
IsInsideMM(index, TREE_SUB_ARCTIC << 2, TREE_RAINFOREST << 2)) {
|
|
|
|
index += 164 - (TREE_SUB_ARCTIC << 2);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-02-06 23:08:04 +00:00
|
|
|
assert(index < lengthof(_tree_layout_sprite));
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2008-02-06 23:08:04 +00:00
|
|
|
const PalSpriteID *s = _tree_layout_sprite[index];
|
|
|
|
const TreePos *d = _tree_layout_xy[GB(tmp, 4, 2)];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-02-06 23:08:04 +00:00
|
|
|
/* combine trees into one sprite object */
|
2004-08-09 17:04:08 +00:00
|
|
|
StartSpriteCombine();
|
|
|
|
|
2008-02-06 22:59:31 +00:00
|
|
|
TreeListEnt te[4];
|
|
|
|
|
|
|
|
/* put the trees to draw in a list */
|
2008-11-23 16:45:53 +00:00
|
|
|
uint trees = GetTreeCount(ti->tile);
|
2008-02-06 23:08:04 +00:00
|
|
|
|
|
|
|
for (uint i = 0; i < trees; i++) {
|
|
|
|
SpriteID image = s[0].sprite + (i == trees - 1 ? GetTreeGrowth(ti->tile) : 3);
|
2008-02-06 22:59:31 +00:00
|
|
|
SpriteID pal = s[0].pal;
|
|
|
|
|
|
|
|
te[i].image = image;
|
|
|
|
te[i].pal = pal;
|
|
|
|
te[i].x = d->x;
|
|
|
|
te[i].y = d->y;
|
|
|
|
s++;
|
|
|
|
d++;
|
2008-02-06 23:08:04 +00:00
|
|
|
}
|
2008-02-06 22:59:31 +00:00
|
|
|
|
|
|
|
/* draw them in a sorted way */
|
2008-02-06 23:08:04 +00:00
|
|
|
byte z = ti->z + GetSlopeMaxZ(ti->tileh) / 2;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-02-06 23:08:04 +00:00
|
|
|
for (; trees > 0; trees--) {
|
|
|
|
uint min = te[0].x + te[0].y;
|
|
|
|
uint mi = 0;
|
|
|
|
|
|
|
|
for (uint i = 1; i < trees; i++) {
|
2008-02-08 17:53:01 +00:00
|
|
|
if ((uint)(te[i].x + te[i].y) < min) {
|
2008-02-06 22:59:31 +00:00
|
|
|
min = te[i].x + te[i].y;
|
2008-02-06 23:08:04 +00:00
|
|
|
mi = i;
|
2008-02-06 22:59:31 +00:00
|
|
|
}
|
2008-02-06 23:08:04 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-02-06 23:08:04 +00:00
|
|
|
AddSortableSpriteToDraw(te[mi].image, 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);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-02-06 23:08:04 +00:00
|
|
|
/* replace the removed one with the last one */
|
|
|
|
te[mi] = te[trees - 1];
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EndSpriteCombine();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-06 16:32:49 +00:00
|
|
|
static uint GetSlopeZ_Trees(TileIndex tile, uint x, uint y)
|
2005-10-19 14:49:46 +00:00
|
|
|
{
|
2006-08-06 16:32:49 +00:00
|
|
|
uint z;
|
2007-01-10 18:56:51 +00:00
|
|
|
Slope tileh = GetTileSlope(tile, &z);
|
2006-08-06 16:32:49 +00:00
|
|
|
|
|
|
|
return z + GetPartialZ(x & 0xF, y & 0xF, tileh);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-07-26 16:51:10 +00:00
|
|
|
static Foundation GetFoundation_Trees(TileIndex tile, Slope tileh)
|
2005-10-22 06:39:32 +00:00
|
|
|
{
|
2007-07-26 16:51:10 +00:00
|
|
|
return FOUNDATION_NONE;
|
2004-08-13 18:27:33 +00:00
|
|
|
}
|
|
|
|
|
2009-02-09 21:20:05 +00:00
|
|
|
static CommandCost ClearTile_Trees(TileIndex tile, DoCommandFlag flags)
|
2005-06-24 12:38:35 +00:00
|
|
|
{
|
2005-07-30 18:30:07 +00:00
|
|
|
uint num;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-05-17 01:00:56 +00:00
|
|
|
if (Company::IsValidID(_current_company)) {
|
2008-05-29 15:13:28 +00:00
|
|
|
Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority);
|
2009-02-11 18:50:47 +00:00
|
|
|
if (t != NULL) ChangeTownRating(t, RATING_TREE_DOWN_STEP, RATING_TREE_MINIMUM, flags);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-11-23 16:45:53 +00:00
|
|
|
num = GetTreeCount(tile);
|
2007-11-24 10:38:43 +00:00
|
|
|
if (IsInsideMM(GetTreeType(tile), TREE_RAINFOREST, TREE_CACTUS)) num *= 4;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-30 18:30:07 +00:00
|
|
|
if (flags & DC_EXEC) DoClearSquare(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-01-09 16:55:48 +00:00
|
|
|
return CommandCost(EXPENSES_CONSTRUCTION, num * _price.remove_trees);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void GetTileDesc_Trees(TileIndex tile, TileDesc *td)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-02-05 14:47:15 +00:00
|
|
|
TreeType tt = GetTreeType(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-11-24 10:38:43 +00:00
|
|
|
if (IsInsideMM(tt, TREE_RAINFOREST, TREE_CACTUS)) {
|
2009-08-05 17:59:21 +00:00
|
|
|
td->str = STR_LAI_TREE_NAME_RAINFOREST;
|
2006-02-05 14:47:15 +00:00
|
|
|
} else {
|
2009-08-05 17:59:21 +00:00
|
|
|
td->str = tt == TREE_CACTUS ? STR_LAI_TREE_NAME_CACTUS_PLANTS : STR_LAI_TREE_NAME_TREES;
|
2006-02-05 14:47:15 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-21 22:15:39 +00:00
|
|
|
td->owner[0] = GetTileOwner(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void TileLoopTreesDesert(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-03-30 19:16:44 +00:00
|
|
|
switch (GetTropicZone(tile)) {
|
|
|
|
case TROPICZONE_DESERT:
|
2006-04-04 06:25:05 +00:00
|
|
|
if (GetTreeGround(tile) != TREE_GROUND_SNOW_DESERT) {
|
|
|
|
SetTreeGroundDensity(tile, TREE_GROUND_SNOW_DESERT, 3);
|
2006-02-05 14:47:15 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2006-03-30 19:16:44 +00:00
|
|
|
case TROPICZONE_RAINFOREST: {
|
2006-02-05 14:47:15 +00:00
|
|
|
static const SoundFx forest_sounds[] = {
|
|
|
|
SND_42_LOON_BIRD,
|
|
|
|
SND_43_LION,
|
|
|
|
SND_44_MONKEYS,
|
|
|
|
SND_48_DISTANT_BIRD
|
|
|
|
};
|
|
|
|
uint32 r = Random();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-11-25 15:35:25 +00:00
|
|
|
if (Chance16I(1, 200, r)) SndPlayTileFx(forest_sounds[GB(r, 16, 2)], tile);
|
2006-02-05 14:47:15 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2006-03-30 19:16:44 +00:00
|
|
|
|
|
|
|
default: break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void TileLoopTreesAlps(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-03-20 13:47:00 +00:00
|
|
|
int k = GetTileZ(tile) - GetSnowLine() + TILE_HEIGHT;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-07-22 07:36:01 +00:00
|
|
|
if (k < 0) {
|
2006-04-04 06:25:05 +00:00
|
|
|
if (GetTreeGround(tile) != TREE_GROUND_SNOW_DESERT) return;
|
2007-10-11 11:06:04 +00:00
|
|
|
SetTreeGroundDensity(tile, TREE_GROUND_GRASS, 3);
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2006-07-22 07:36:01 +00:00
|
|
|
uint density = min((uint)k / TILE_HEIGHT, 3);
|
2006-02-05 14:47:15 +00:00
|
|
|
|
2006-04-04 06:25:05 +00:00
|
|
|
if (GetTreeGround(tile) != TREE_GROUND_SNOW_DESERT ||
|
|
|
|
GetTreeDensity(tile) != density) {
|
|
|
|
SetTreeGroundDensity(tile, TREE_GROUND_SNOW_DESERT, density);
|
2006-02-05 14:47:15 +00:00
|
|
|
} else {
|
|
|
|
if (GetTreeDensity(tile) == 3) {
|
|
|
|
uint32 r = Random();
|
2007-11-25 15:35:25 +00:00
|
|
|
if (Chance16I(1, 200, r)) {
|
2006-02-05 14:47:15 +00:00
|
|
|
SndPlayTileFx((r & 0x80000000) ? SND_39_HEAVY_WIND : SND_34_WIND, tile);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void TileLoop_Trees(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-01-31 17:54:13 +00:00
|
|
|
if (GetTreeGround(tile) == TREE_GROUND_SHORE) {
|
|
|
|
TileLoop_Water(tile);
|
|
|
|
} else {
|
2008-05-29 15:13:28 +00:00
|
|
|
switch (_settings_game.game_creation.landscape) {
|
2008-01-31 17:54:13 +00:00
|
|
|
case LT_TROPIC: TileLoopTreesDesert(tile); break;
|
|
|
|
case LT_ARCTIC: TileLoopTreesAlps(tile); break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TileLoopClearHelper(tile);
|
|
|
|
|
2007-10-11 11:06:04 +00:00
|
|
|
uint treeCounter = GetTreeCounter(tile);
|
|
|
|
|
2009-09-26 12:30:30 +00:00
|
|
|
/* Handle growth of grass (under trees/on MP_TREES tiles) at every 8th processings, like it's done for grass on MP_CLEAR tiles. */
|
2007-10-11 11:06:04 +00:00
|
|
|
if ((treeCounter & 7) == 7 && GetTreeGround(tile) == TREE_GROUND_GRASS) {
|
|
|
|
uint density = GetTreeDensity(tile);
|
|
|
|
if (density < 3) {
|
|
|
|
SetTreeGroundDensity(tile, TREE_GROUND_GRASS, density + 1);
|
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
}
|
2006-02-05 14:47:15 +00:00
|
|
|
if (GetTreeCounter(tile) < 15) {
|
|
|
|
AddTreeCounter(tile, 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SetTreeCounter(tile, 0);
|
|
|
|
|
|
|
|
switch (GetTreeGrowth(tile)) {
|
2009-03-15 00:32:18 +00:00
|
|
|
case 3: // regular sized tree
|
2008-05-29 15:13:28 +00:00
|
|
|
if (_settings_game.game_creation.landscape == LT_TROPIC &&
|
2006-04-04 06:25:05 +00:00
|
|
|
GetTreeType(tile) != TREE_CACTUS &&
|
2006-03-30 19:16:44 +00:00
|
|
|
GetTropicZone(tile) == TROPICZONE_DESERT) {
|
2006-02-05 14:47:15 +00:00
|
|
|
AddTreeGrowth(tile, 1);
|
|
|
|
} else {
|
|
|
|
switch (GB(Random(), 0, 3)) {
|
2009-03-15 00:32:18 +00:00
|
|
|
case 0: // start destructing
|
2006-02-05 14:47:15 +00:00
|
|
|
AddTreeGrowth(tile, 1);
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
case 1: // add a tree
|
2008-11-23 16:45:53 +00:00
|
|
|
if (GetTreeCount(tile) < 4) {
|
2006-02-05 14:47:15 +00:00
|
|
|
AddTreeCount(tile, 1);
|
|
|
|
SetTreeGrowth(tile, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* FALL THROUGH */
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
case 2: { // add a neighbouring tree
|
2006-02-05 14:47:15 +00:00
|
|
|
TreeType treetype = GetTreeType(tile);
|
2006-02-04 11:53:31 +00:00
|
|
|
|
2007-07-24 13:03:24 +00:00
|
|
|
tile += TileOffsByDir((Direction)(Random() & 7));
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-01-30 18:40:42 +00:00
|
|
|
/* Cacti don't spread */
|
|
|
|
if (!CanPlantTreesOnTile(tile, false)) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-01-30 18:40:42 +00:00
|
|
|
/* Don't plant trees, if ground was freshly cleared */
|
2008-01-31 17:54:13 +00:00
|
|
|
if (IsTileType(tile, MP_CLEAR) && GetClearGround(tile) == CLEAR_GRASS && GetClearDensity(tile) != 3) return;
|
2008-01-30 18:40:42 +00:00
|
|
|
|
|
|
|
PlantTreesOnTile(tile, treetype, 0, 0);
|
2006-02-05 14:47:15 +00:00
|
|
|
|
2006-02-01 15:31:21 +00:00
|
|
|
break;
|
2006-02-05 14:47:15 +00:00
|
|
|
}
|
2006-02-01 15:31:21 +00:00
|
|
|
|
2006-02-05 14:47:15 +00:00
|
|
|
default:
|
|
|
|
return;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
}
|
2006-02-05 14:47:15 +00:00
|
|
|
break;
|
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
case 6: // final stage of tree destruction
|
2008-11-23 16:45:53 +00:00
|
|
|
if (GetTreeCount(tile) > 1) {
|
2006-02-05 14:47:15 +00:00
|
|
|
/* more than one tree, delete it */
|
|
|
|
AddTreeCount(tile, -1);
|
|
|
|
SetTreeGrowth(tile, 3);
|
|
|
|
} else {
|
|
|
|
/* just one tree, change type into MP_CLEAR */
|
|
|
|
switch (GetTreeGround(tile)) {
|
2008-01-31 17:54:13 +00:00
|
|
|
case TREE_GROUND_SHORE: MakeShore(tile); break;
|
2007-10-11 11:06:04 +00:00
|
|
|
case TREE_GROUND_GRASS: MakeClear(tile, CLEAR_GRASS, GetTreeDensity(tile)); break;
|
2006-04-04 21:35:13 +00:00
|
|
|
case TREE_GROUND_ROUGH: MakeClear(tile, CLEAR_ROUGH, 3); break;
|
2007-10-11 11:06:04 +00:00
|
|
|
default: // snow or desert
|
2008-05-29 15:13:28 +00:00
|
|
|
MakeClear(tile, _settings_game.game_creation.landscape == LT_TROPIC ? CLEAR_DESERT : CLEAR_SNOW, GetTreeDensity(tile));
|
2007-10-11 11:06:04 +00:00
|
|
|
break;
|
2006-02-05 14:47:15 +00:00
|
|
|
}
|
2006-02-01 15:31:21 +00:00
|
|
|
}
|
2006-02-05 14:47:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
AddTreeGrowth(tile, 1);
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void OnTick_Trees()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
uint32 r;
|
2005-06-24 12:38:35 +00:00
|
|
|
TileIndex tile;
|
2006-02-13 21:15:00 +00:00
|
|
|
TreeType tree;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
/* place a tree at a random rainforest spot */
|
2008-05-29 15:13:28 +00:00
|
|
|
if (_settings_game.game_creation.landscape == LT_TROPIC &&
|
2006-03-30 19:16:44 +00:00
|
|
|
(r = Random(), tile = RandomTileSeed(r), GetTropicZone(tile) == TROPICZONE_RAINFOREST) &&
|
2008-01-30 18:40:42 +00:00
|
|
|
CanPlantTreesOnTile(tile, false) &&
|
2006-04-04 06:25:05 +00:00
|
|
|
(tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TREE_INVALID) {
|
2008-01-30 18:40:42 +00:00
|
|
|
PlantTreesOnTile(tile, tree, 0, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-04-04 03:21:14 +00:00
|
|
|
/* byte underflow */
|
2005-07-17 11:09:03 +00:00
|
|
|
if (--_trees_tick_ctr != 0) return;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
/* place a tree at a random spot */
|
|
|
|
r = Random();
|
2009-02-25 21:29:50 +00:00
|
|
|
tile = RandomTileSeed(r);
|
2008-01-30 18:40:42 +00:00
|
|
|
if (CanPlantTreesOnTile(tile, false) && (tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TREE_INVALID) {
|
|
|
|
PlantTreesOnTile(tile, tree, 0, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-20 17:49:50 +00:00
|
|
|
static TrackStatus GetTileTrackStatus_Trees(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
static void ChangeTileOwner_Trees(TileIndex tile, Owner old_owner, Owner new_owner)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
/* not used */
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void InitializeTrees()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
_trees_tick_ctr = 0;
|
|
|
|
}
|
|
|
|
|
2009-02-09 21:20:05 +00:00
|
|
|
static CommandCost TerraformTile_Trees(TileIndex tile, DoCommandFlag flags, uint z_new, Slope tileh_new)
|
2007-08-30 17:17:04 +00:00
|
|
|
{
|
|
|
|
return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
extern const TileTypeProcs _tile_type_trees_procs = {
|
2009-03-15 00:32:18 +00:00
|
|
|
DrawTile_Trees, // draw_tile_proc
|
|
|
|
GetSlopeZ_Trees, // get_slope_z_proc
|
|
|
|
ClearTile_Trees, // clear_tile_proc
|
2009-06-25 20:08:59 +00:00
|
|
|
NULL, // add_accepted_cargo_proc
|
2009-03-15 00:32:18 +00:00
|
|
|
GetTileDesc_Trees, // get_tile_desc_proc
|
|
|
|
GetTileTrackStatus_Trees, // get_tile_track_status_proc
|
2009-06-25 20:08:59 +00:00
|
|
|
NULL, // click_tile_proc
|
|
|
|
NULL, // animate_tile_proc
|
2009-03-15 00:32:18 +00:00
|
|
|
TileLoop_Trees, // tile_loop_clear
|
|
|
|
ChangeTileOwner_Trees, // change_tile_owner_clear
|
2009-06-27 17:05:20 +00:00
|
|
|
NULL, // add_produced_cargo_proc
|
2009-03-15 00:32:18 +00:00
|
|
|
NULL, // vehicle_enter_tile_proc
|
|
|
|
GetFoundation_Trees, // get_foundation_proc
|
|
|
|
TerraformTile_Trees, // terraform_tile_proc
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|