2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2006-12-27 12:38:02 +00:00
|
|
|
#include "bridge_map.h"
|
2006-03-05 10:19:33 +00:00
|
|
|
#include "clear_map.h"
|
2004-11-25 10:47:30 +00:00
|
|
|
#include "table/strings.h"
|
2005-07-20 22:05:13 +00:00
|
|
|
#include "table/sprites.h"
|
2005-05-09 22:33:00 +00:00
|
|
|
#include "table/tree_land.h"
|
2005-07-22 07:02:20 +00:00
|
|
|
#include "functions.h"
|
2004-12-15 22:18:54 +00:00
|
|
|
#include "map.h"
|
2005-01-29 12:19:05 +00:00
|
|
|
#include "tile.h"
|
2006-03-05 10:19:33 +00:00
|
|
|
#include "tree_map.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "viewport.h"
|
|
|
|
#include "command.h"
|
|
|
|
#include "town.h"
|
2004-11-05 23:12:33 +00:00
|
|
|
#include "sound.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"
|
|
|
|
|
|
|
|
enum TreePlacer {
|
|
|
|
TP_NONE,
|
|
|
|
TP_ORIGINAL,
|
|
|
|
TP_IMPROVED,
|
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-05 14:47:15 +00:00
|
|
|
static TreeType GetRandomTreeType(TileIndex tile, uint seed)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-02-04 16:50:18 +00:00
|
|
|
switch (_opt.landscape) {
|
|
|
|
case LT_NORMAL:
|
2006-04-04 06:25:05 +00:00
|
|
|
return seed * TREE_COUNT_TEMPERATE / 256 + TREE_TEMPERATE;
|
2005-02-04 16:50:18 +00:00
|
|
|
|
|
|
|
case LT_HILLY:
|
2006-04-04 06:25:05 +00:00
|
|
|
return seed * TREE_COUNT_SUB_ARCTIC / 256 + TREE_SUB_ARCTIC;
|
2005-02-04 16:50:18 +00:00
|
|
|
|
|
|
|
case LT_DESERT:
|
2006-03-30 19:16:44 +00:00
|
|
|
switch (GetTropicZone(tile)) {
|
2006-04-04 06:25:05 +00:00
|
|
|
case TROPICZONE_INVALID: return seed * TREE_COUNT_SUB_TROPICAL / 256 + TREE_SUB_TROPICAL;
|
|
|
|
case TROPICZONE_DESERT: return (seed > 12) ? TREE_INVALID : TREE_CACTUS;
|
|
|
|
default: return seed * TREE_COUNT_RAINFOREST / 256 + TREE_RAINFOREST;
|
2005-02-04 16:50:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
2006-04-04 06:25:05 +00:00
|
|
|
return seed * TREE_COUNT_TOYLAND / 256 + TREE_TOYLAND;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
MakeTree(tile, tree, GB(r, 22, 2), min(GB(r, 16, 3), 6), TREE_GROUND_GRASS, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// above snowline?
|
2005-02-14 18:55:10 +00:00
|
|
|
if (_opt.landscape == LT_HILLY && GetTileZ(tile) > _opt.snow_line) {
|
2006-04-04 06:25:05 +00:00
|
|
|
SetTreeGroundDensity(tile, TREE_GROUND_SNOW_DESERT, 3);
|
2006-02-05 14:47:15 +00:00
|
|
|
SetTreeCounter(tile, GB(r, 24, 3));
|
2005-07-17 11:09:03 +00:00
|
|
|
} else {
|
2006-02-05 14:47:15 +00:00
|
|
|
SetTreeGroundDensity(tile, GB(r, 28, 1), 0);
|
|
|
|
SetTreeCounter(tile, GB(r, 24, 4));
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
uint dist = myabs(x) + myabs(y);
|
|
|
|
TileIndex cur_tile = TILE_MASK(tile + TileDiffXY(x, y));
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-01 15:31:21 +00:00
|
|
|
if (dist <= 13 &&
|
|
|
|
IsTileType(cur_tile, MP_CLEAR) &&
|
2006-12-27 12:38:02 +00:00
|
|
|
!IsBridgeAbove(cur_tile) &&
|
2006-04-04 21:35:13 +00:00
|
|
|
!IsClearGround(cur_tile, CLEAR_FIELDS) &&
|
|
|
|
!IsClearGround(cur_tile, CLEAR_ROCKS)) {
|
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
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
static void PlaceMoreTrees(void)
|
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.
|
|
|
|
* This gives cool effects to the map.
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
TileIndex cur_tile = TILE_MASK(tile + TileDiffXY(x, y));
|
|
|
|
|
|
|
|
/* Keep in range of the existing tree */
|
|
|
|
if (myabs(x) + myabs(y) > 16) continue;
|
|
|
|
|
|
|
|
/* Clear tile, no farm-tiles or rocks */
|
|
|
|
if (!IsTileType(cur_tile, MP_CLEAR) ||
|
|
|
|
IsClearGround(cur_tile, CLEAR_FIELDS) ||
|
|
|
|
IsClearGround(cur_tile, CLEAR_ROCKS))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Not too much height difference */
|
|
|
|
if (myabs(GetTileZ(cur_tile) - height) > 2) continue;
|
|
|
|
|
|
|
|
/* Place one tree and quit */
|
|
|
|
PlaceTree(cur_tile, r);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaceTreesRandomly(void)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
2006-02-01 15:31:21 +00:00
|
|
|
if (IsTileType(tile, MP_CLEAR) &&
|
2006-12-27 12:38:02 +00:00
|
|
|
!IsBridgeAbove(tile) &&
|
2006-04-04 21:35:13 +00:00
|
|
|
!IsClearGround(tile, CLEAR_FIELDS) &&
|
|
|
|
!IsClearGround(tile, CLEAR_ROCKS)) {
|
2006-02-02 07:15:46 +00:00
|
|
|
PlaceTree(tile, 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
|
|
|
if (_patches.tree_placer != TP_IMPROVED) continue;
|
|
|
|
|
|
|
|
/* 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! */
|
|
|
|
if (_opt.landscape == LT_HILLY && ht > _opt.snow_line) {
|
|
|
|
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 */
|
|
|
|
if (_opt.landscape == LT_DESERT) {
|
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);
|
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
if (IsTileType(tile, MP_CLEAR) &&
|
|
|
|
!IsBridgeAbove(tile) &&
|
|
|
|
!IsClearGround(tile, CLEAR_FIELDS) &&
|
|
|
|
GetTropicZone(tile) == TROPICZONE_RAINFOREST) {
|
2006-02-02 07:15:46 +00:00
|
|
|
PlaceTree(tile, r);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
} while (--i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void GenerateTrees(void)
|
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;
|
|
|
|
|
|
|
|
if (_patches.tree_placer == TP_NONE) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-17 11:09:03 +00:00
|
|
|
if (_opt.landscape != LT_CANDY) PlaceMoreTrees();
|
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
|
|
|
switch (_patches.tree_placer) {
|
|
|
|
case TP_ORIGINAL: i = _opt.landscape == LT_HILLY ? 15 : 6; break;
|
|
|
|
case TP_IMPROVED: i = _opt.landscape == LT_HILLY ? 4 : 2; break;
|
|
|
|
default: NOT_REACHED(); return;
|
|
|
|
}
|
|
|
|
|
|
|
|
total = ScaleByMapSize(1000);
|
|
|
|
if (_opt.landscape == LT_DESERT) total += ScaleByMapSize(15000);
|
|
|
|
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
|
2005-05-09 22:33:00 +00:00
|
|
|
* @param p1 tree type, -1 means random.
|
|
|
|
* @param p2 end tile of area-drag
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
2006-04-10 07:15:58 +00:00
|
|
|
int32 CmdPlantTree(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-03-12 12:19:25 +00:00
|
|
|
StringID msg = INVALID_STRING_ID;
|
2004-08-09 17:04:08 +00:00
|
|
|
int32 cost;
|
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 */
|
|
|
|
if (p1 != (uint)-1 && p1 - _tree_base_by_landscape[_opt.landscape] >= _tree_count_by_landscape[_opt.landscape]) return CMD_ERROR;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
SET_EXPENSES_TYPE(EXPENSES_OTHER);
|
|
|
|
|
|
|
|
// 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);
|
2004-08-09 17:04:08 +00:00
|
|
|
if (ex < sx) intswap(ex, sx);
|
|
|
|
if (ey < sy) intswap(ey, sy);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
cost = 0; // total cost
|
|
|
|
|
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
|
|
|
if (!EnsureNoVehicle(tile)) continue;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-17 11:09:03 +00:00
|
|
|
switch (GetTileType(tile)) {
|
2005-02-04 16:50:18 +00:00
|
|
|
case MP_TREES:
|
|
|
|
// no more space for trees?
|
2006-02-09 07:34:37 +00:00
|
|
|
if (_game_mode != GM_EDITOR && GetTreeCount(tile) == 3) {
|
2006-03-12 12:19:25 +00:00
|
|
|
msg = STR_2803_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
|
|
|
}
|
2005-02-04 16:50:18 +00:00
|
|
|
// 2x as expensive to add more trees to an existing tile
|
|
|
|
cost += _price.build_trees * 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_CLEAR:
|
2006-12-27 12:38:02 +00:00
|
|
|
if (!IsTileOwner(tile, OWNER_NONE) ||
|
|
|
|
IsBridgeAbove(tile)) {
|
2006-03-12 12:19:25 +00:00
|
|
|
msg = STR_2804_SITE_UNSUITABLE;
|
2005-02-04 16:50:18 +00:00
|
|
|
continue;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-02-01 15:31:21 +00:00
|
|
|
switch (GetClearGround(tile)) {
|
2006-04-04 21:35:13 +00:00
|
|
|
case CLEAR_FIELDS: cost += _price.clear_3; break;
|
|
|
|
case CLEAR_ROCKS: cost += _price.clear_2; break;
|
2006-02-01 15:31:21 +00:00
|
|
|
default: break;
|
|
|
|
}
|
2005-02-04 16:50:18 +00:00
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
2006-02-05 14:47:15 +00:00
|
|
|
TreeType treetype;
|
2006-02-24 20:38:08 +00:00
|
|
|
uint growth;
|
2005-02-04 16:50:18 +00:00
|
|
|
|
2006-10-14 22:31:18 +00:00
|
|
|
if (_game_mode != GM_EDITOR && IsValidPlayer(_current_player)) {
|
2005-07-17 11:09:03 +00:00
|
|
|
Town *t = ClosestTownFromTile(tile, _patches.dist_local_authority);
|
2005-02-04 16:50:18 +00:00
|
|
|
if (t != NULL)
|
|
|
|
ChangeTownRating(t, RATING_TREE_UP_STEP, RATING_TREE_MAXIMUM);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2006-02-24 20:38:08 +00:00
|
|
|
growth = _game_mode == GM_EDITOR ? 3 : 0;
|
2006-02-05 14:47:15 +00:00
|
|
|
switch (GetClearGround(tile)) {
|
2006-04-04 21:35:13 +00:00
|
|
|
case CLEAR_ROUGH: MakeTree(tile, treetype, 0, growth, TREE_GROUND_ROUGH, 0); break;
|
|
|
|
case CLEAR_SNOW: MakeTree(tile, treetype, 0, growth, TREE_GROUND_SNOW_DESERT, GetClearDensity(tile)); break;
|
|
|
|
default: MakeTree(tile, treetype, 0, growth, TREE_GROUND_GRASS, 0); break;
|
2006-02-05 14:47:15 +00:00
|
|
|
}
|
2006-02-09 07:34:37 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
2006-02-05 14:47:15 +00:00
|
|
|
|
2006-04-04 06:25:05 +00:00
|
|
|
if (_game_mode == GM_EDITOR && IS_INT_INSIDE(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
|
|
|
}
|
2005-02-04 16:50:18 +00:00
|
|
|
cost += _price.build_trees;
|
|
|
|
break;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-02-04 16:50:18 +00:00
|
|
|
default:
|
2006-03-12 12:19:25 +00:00
|
|
|
msg = STR_2804_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
|
|
|
|
2006-03-12 12:19:25 +00:00
|
|
|
if (cost == 0) {
|
|
|
|
return_cmd_error(msg);
|
|
|
|
} else {
|
|
|
|
return cost;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct TreeListEnt {
|
|
|
|
uint32 image;
|
|
|
|
byte x,y;
|
|
|
|
} TreeListEnt;
|
|
|
|
|
|
|
|
static void DrawTile_Trees(TileInfo *ti)
|
|
|
|
{
|
|
|
|
const uint32 *s;
|
2005-11-16 12:01:46 +00:00
|
|
|
const TreePos* d;
|
2004-08-09 17:04:08 +00:00
|
|
|
byte z;
|
|
|
|
|
2006-02-05 14:47:15 +00:00
|
|
|
switch (GetTreeGround(ti->tile)) {
|
2006-04-04 06:25:05 +00:00
|
|
|
case TREE_GROUND_GRASS: DrawClearLandTile(ti, 3); break;
|
|
|
|
case TREE_GROUND_ROUGH: DrawHillyLandTile(ti); break;
|
|
|
|
default: DrawGroundSprite(_tree_sprites_1[GetTreeDensity(ti->tile)] + _tileh_to_sprite[ti->tileh]); 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
|
|
|
|
|
|
|
z = ti->z;
|
2006-04-23 13:48:16 +00:00
|
|
|
if (ti->tileh != SLOPE_FLAT) {
|
2004-08-09 17:04:08 +00:00
|
|
|
z += 4;
|
2006-04-23 13:48:16 +00:00
|
|
|
if (IsSteepSlope(ti->tileh)) z += 4;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
uint16 tmp = ti->x;
|
2005-01-09 21:25:44 +00:00
|
|
|
uint index;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-17 11:09:03 +00:00
|
|
|
tmp = ROR(tmp, 2);
|
2004-08-09 17:04:08 +00:00
|
|
|
tmp -= ti->y;
|
2005-07-17 11:09:03 +00:00
|
|
|
tmp = ROR(tmp, 3);
|
2004-08-09 17:04:08 +00:00
|
|
|
tmp -= ti->x;
|
2005-07-17 11:09:03 +00:00
|
|
|
tmp = ROR(tmp, 1);
|
2004-08-09 17:04:08 +00:00
|
|
|
tmp += ti->y;
|
|
|
|
|
2005-07-17 11:09:03 +00:00
|
|
|
d = _tree_layout_xy[GB(tmp, 4, 2)];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-05 14:47:15 +00:00
|
|
|
index = GB(tmp, 6, 2) + (GetTreeType(ti->tile) << 2);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
/* different tree styles above one of the grounds */
|
2006-04-04 06:25:05 +00:00
|
|
|
if (GetTreeGround(ti->tile) == TREE_GROUND_SNOW_DESERT &&
|
2006-02-05 14:47:15 +00:00
|
|
|
GetTreeDensity(ti->tile) >= 2 &&
|
2006-04-04 06:25:05 +00:00
|
|
|
IS_INT_INSIDE(index, TREE_SUB_ARCTIC << 2, TREE_RAINFOREST << 2)) {
|
|
|
|
index += 164 - (TREE_SUB_ARCTIC << 2);
|
2006-02-05 14:47:15 +00:00
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
|
|
|
assert(index < lengthof(_tree_layout_sprite));
|
2004-08-09 17:04:08 +00:00
|
|
|
s = _tree_layout_sprite[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
StartSpriteCombine();
|
|
|
|
|
2005-07-17 11:09:03 +00:00
|
|
|
if (!(_display_opt & DO_TRANS_BUILDINGS) || !_patches.invisible_trees) {
|
|
|
|
TreeListEnt te[4];
|
|
|
|
uint i;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
/* put the trees to draw in a list */
|
2006-03-19 16:57:48 +00:00
|
|
|
i = GetTreeCount(ti->tile) + 1;
|
2004-08-09 17:04:08 +00:00
|
|
|
do {
|
2006-03-19 16:57:48 +00:00
|
|
|
uint32 image = s[0] + (--i == 0 ? GetTreeGrowth(ti->tile) : 3);
|
2005-11-14 19:48:04 +00:00
|
|
|
if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image);
|
2004-08-09 17:04:08 +00:00
|
|
|
te[i].image = image;
|
2005-11-16 12:01:46 +00:00
|
|
|
te[i].x = d->x;
|
|
|
|
te[i].y = d->y;
|
2004-08-09 17:04:08 +00:00
|
|
|
s++;
|
2005-11-16 12:01:46 +00:00
|
|
|
d++;
|
2004-08-09 17:04:08 +00:00
|
|
|
} while (i);
|
|
|
|
|
|
|
|
/* draw them in a sorted way */
|
2006-02-01 07:36:15 +00:00
|
|
|
for (;;) {
|
2004-08-09 17:04:08 +00:00
|
|
|
byte min = 0xFF;
|
|
|
|
TreeListEnt *tep = NULL;
|
|
|
|
|
2006-03-19 16:57:48 +00:00
|
|
|
i = GetTreeCount(ti->tile) + 1;
|
2004-08-09 17:04:08 +00:00
|
|
|
do {
|
2005-11-15 09:05:16 +00:00
|
|
|
if (te[--i].image != 0 && te[i].x + te[i].y < min) {
|
2004-08-09 17:04:08 +00:00
|
|
|
min = te[i].x + te[i].y;
|
|
|
|
tep = &te[i];
|
|
|
|
}
|
|
|
|
} while (i);
|
|
|
|
|
2005-07-17 11:09:03 +00:00
|
|
|
if (tep == NULL) break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
AddSortableSpriteToDraw(tep->image, ti->x + tep->x, ti->y + tep->y, 5, 5, 0x10, z);
|
|
|
|
tep->image = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
uint tileh = GetTileSlope(tile, &z);
|
|
|
|
|
|
|
|
return z + GetPartialZ(x & 0xF, y & 0xF, tileh);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
static Slope GetSlopeTileh_Trees(TileIndex tile, Slope tileh)
|
2005-10-22 06:39:32 +00:00
|
|
|
{
|
2006-04-02 12:49:18 +00:00
|
|
|
return tileh;
|
2004-08-13 18:27:33 +00:00
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static int32 ClearTile_Trees(TileIndex tile, byte flags)
|
|
|
|
{
|
2005-07-30 18:30:07 +00:00
|
|
|
uint num;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-10-14 22:31:18 +00:00
|
|
|
if ((flags & DC_EXEC) && IsValidPlayer(_current_player)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
Town *t = ClosestTownFromTile(tile, _patches.dist_local_authority);
|
2004-09-10 19:02:27 +00:00
|
|
|
if (t != NULL)
|
2005-01-14 09:20:12 +00:00
|
|
|
ChangeTownRating(t, RATING_TREE_DOWN_STEP, RATING_TREE_MINIMUM);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-02-05 14:47:15 +00:00
|
|
|
num = GetTreeCount(tile) + 1;
|
2006-04-04 06:25:05 +00:00
|
|
|
if (IS_INT_INSIDE(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
|
|
|
|
|
|
|
return num * _price.remove_trees;
|
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void GetAcceptedCargo_Trees(TileIndex tile, AcceptedCargo ac)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
/* not used */
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2006-04-04 06:25:05 +00:00
|
|
|
if (IS_INT_INSIDE(tt, TREE_RAINFOREST, TREE_CACTUS)) {
|
2006-02-05 14:47:15 +00:00
|
|
|
td->str = STR_280F_RAINFOREST;
|
2006-04-04 06:25:05 +00:00
|
|
|
} else if (tt == TREE_CACTUS) {
|
2006-02-05 14:47:15 +00:00
|
|
|
td->str = STR_2810_CACTUS_PLANTS;
|
|
|
|
} else {
|
|
|
|
td->str = STR_280E_TREES;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-05 14:47:15 +00:00
|
|
|
td->owner = GetTileOwner(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void AnimateTile_Trees(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
/* not used */
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2006-02-05 14:47:15 +00:00
|
|
|
if (CHANCE16I(1, 200, r)) SndPlayTileFx(forest_sounds[GB(r, 16, 2)], tile);
|
|
|
|
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
|
|
|
{
|
2006-07-22 07:36:01 +00:00
|
|
|
int k = GetTileZ(tile) - _opt.snow_line + 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;
|
|
|
|
SetTreeGroundDensity(tile, TREE_GROUND_GRASS, 0);
|
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();
|
|
|
|
if (CHANCE16I(1, 200, r)) {
|
|
|
|
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
|
|
|
{
|
2006-02-05 14:47:15 +00:00
|
|
|
switch (_opt.landscape) {
|
|
|
|
case LT_DESERT: TileLoopTreesDesert(tile); break;
|
|
|
|
case LT_HILLY: TileLoopTreesAlps(tile); break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TileLoopClearHelper(tile);
|
|
|
|
|
2006-02-05 14:47:15 +00:00
|
|
|
if (GetTreeCounter(tile) < 15) {
|
|
|
|
AddTreeCounter(tile, 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SetTreeCounter(tile, 0);
|
|
|
|
|
|
|
|
switch (GetTreeGrowth(tile)) {
|
|
|
|
case 3: /* regular sized tree */
|
2006-03-30 19:16:44 +00:00
|
|
|
if (_opt.landscape == LT_DESERT &&
|
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)) {
|
|
|
|
case 0: /* start destructing */
|
|
|
|
AddTreeGrowth(tile, 1);
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-05 14:47:15 +00:00
|
|
|
case 1: /* add a tree */
|
|
|
|
if (GetTreeCount(tile) < 3) {
|
|
|
|
AddTreeCount(tile, 1);
|
|
|
|
SetTreeGrowth(tile, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* FALL THROUGH */
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-05 14:47:15 +00:00
|
|
|
case 2: { /* add a neighbouring tree */
|
|
|
|
TreeType treetype = GetTreeType(tile);
|
2006-02-04 11:53:31 +00:00
|
|
|
|
2006-09-05 23:21:41 +00:00
|
|
|
tile += TileOffsByDir(Random() & 7);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
if (!IsTileType(tile, MP_CLEAR) || IsBridgeAbove(tile)) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-05 14:47:15 +00:00
|
|
|
switch (GetClearGround(tile)) {
|
2006-04-04 21:35:13 +00:00
|
|
|
case CLEAR_GRASS:
|
2006-02-05 14:47:15 +00:00
|
|
|
if (GetClearDensity(tile) != 3) return;
|
2006-04-04 06:25:05 +00:00
|
|
|
MakeTree(tile, treetype, 0, 0, TREE_GROUND_GRASS, 0);
|
2006-02-05 14:47:15 +00:00
|
|
|
break;
|
|
|
|
|
2006-04-04 21:35:13 +00:00
|
|
|
case CLEAR_ROUGH: MakeTree(tile, treetype, 0, 0, TREE_GROUND_ROUGH, 0); break;
|
|
|
|
case CLEAR_SNOW: MakeTree(tile, treetype, 0, 0, TREE_GROUND_SNOW_DESERT, GetClearDensity(tile)); break;
|
2006-02-05 14:47:15 +00:00
|
|
|
default: return;
|
|
|
|
}
|
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;
|
|
|
|
|
|
|
|
case 6: /* final stage of tree destruction */
|
|
|
|
if (GetTreeCount(tile) > 0) {
|
|
|
|
/* more than one tree, delete it */
|
|
|
|
AddTreeCount(tile, -1);
|
|
|
|
SetTreeGrowth(tile, 3);
|
|
|
|
} else {
|
|
|
|
/* just one tree, change type into MP_CLEAR */
|
|
|
|
switch (GetTreeGround(tile)) {
|
2006-04-04 21:35:13 +00:00
|
|
|
case TREE_GROUND_GRASS: MakeClear(tile, CLEAR_GRASS, 3); break;
|
|
|
|
case TREE_GROUND_ROUGH: MakeClear(tile, CLEAR_ROUGH, 3); break;
|
|
|
|
default: MakeClear(tile, CLEAR_SNOW, GetTreeDensity(tile)); break;
|
2006-02-05 14:47:15 +00:00
|
|
|
}
|
2006-12-27 12:38:02 +00:00
|
|
|
ClearBridgeMiddle(tile);
|
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);
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void OnTick_Trees(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
uint32 r;
|
2005-06-24 12:38:35 +00:00
|
|
|
TileIndex tile;
|
2006-02-01 15:31:21 +00:00
|
|
|
ClearGround ct;
|
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 */
|
2004-09-10 19:02:27 +00:00
|
|
|
if (_opt.landscape == LT_DESERT &&
|
2006-03-30 19:16:44 +00:00
|
|
|
(r = Random(), tile = RandomTileSeed(r), GetTropicZone(tile) == TROPICZONE_RAINFOREST) &&
|
2005-01-16 11:24:58 +00:00
|
|
|
IsTileType(tile, MP_CLEAR) &&
|
2006-12-27 12:38:02 +00:00
|
|
|
!IsBridgeAbove(tile) &&
|
2006-04-04 21:35:13 +00:00
|
|
|
(ct = GetClearGround(tile), ct == CLEAR_GRASS || ct == CLEAR_ROUGH) &&
|
2006-04-04 06:25:05 +00:00
|
|
|
(tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TREE_INVALID) {
|
2006-04-04 21:35:13 +00:00
|
|
|
MakeTree(tile, tree, 0, 0, ct == CLEAR_ROUGH ? TREE_GROUND_ROUGH : TREE_GROUND_GRASS, 0);
|
2004-08-09 17:04:08 +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();
|
|
|
|
tile = TILE_MASK(r);
|
2005-01-16 11:24:58 +00:00
|
|
|
if (IsTileType(tile, MP_CLEAR) &&
|
2006-12-27 12:38:02 +00:00
|
|
|
!IsBridgeAbove(tile) &&
|
2006-04-04 21:35:13 +00:00
|
|
|
(ct = GetClearGround(tile), ct == CLEAR_GRASS || ct == CLEAR_ROUGH || ct == CLEAR_SNOW) &&
|
2006-04-04 06:25:05 +00:00
|
|
|
(tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TREE_INVALID) {
|
2006-02-01 15:31:21 +00:00
|
|
|
switch (ct) {
|
2006-04-04 21:35:13 +00:00
|
|
|
case CLEAR_GRASS: MakeTree(tile, tree, 0, 0, TREE_GROUND_GRASS, 0); break;
|
|
|
|
case CLEAR_ROUGH: MakeTree(tile, tree, 0, 0, TREE_GROUND_ROUGH, 0); break;
|
2006-04-04 06:25:05 +00:00
|
|
|
default: MakeTree(tile, tree, 0, 0, TREE_GROUND_SNOW_DESERT, GetClearDensity(tile)); break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void ClickTile_Trees(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
/* not used */
|
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static uint32 GetTileTrackStatus_Trees(TileIndex tile, TransportType mode)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
static void ChangeTileOwner_Trees(TileIndex tile, PlayerID old_player, PlayerID new_player)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
/* not used */
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void InitializeTrees(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
_trees_tick_ctr = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const TileTypeProcs _tile_type_trees_procs = {
|
2006-08-22 14:38:37 +00:00
|
|
|
DrawTile_Trees, /* draw_tile_proc */
|
|
|
|
GetSlopeZ_Trees, /* get_slope_z_proc */
|
|
|
|
ClearTile_Trees, /* clear_tile_proc */
|
|
|
|
GetAcceptedCargo_Trees, /* get_accepted_cargo_proc */
|
|
|
|
GetTileDesc_Trees, /* get_tile_desc_proc */
|
|
|
|
GetTileTrackStatus_Trees, /* get_tile_track_status_proc */
|
|
|
|
ClickTile_Trees, /* click_tile_proc */
|
|
|
|
AnimateTile_Trees, /* animate_tile_proc */
|
|
|
|
TileLoop_Trees, /* tile_loop_clear */
|
|
|
|
ChangeTileOwner_Trees, /* change_tile_owner_clear */
|
|
|
|
NULL, /* get_produced_cargo_proc */
|
|
|
|
NULL, /* vehicle_enter_tile_proc */
|
|
|
|
GetSlopeTileh_Trees, /* get_slope_tileh_proc */
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|