Changeset - r7710:64254e378532
[Not reviewed]
master
0 3 0
truelight - 17 years ago 2007-10-11 11:06:04
truelight@openttd.org
(svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
-Fix: planting tree in desert doesn't make it grassy for the first tile-cycle (Csaboka)
-Fix: when a tree dies in desert, it no longer becomes a snowy tile for the first tile-cycle (Csaboka)
3 files changed with 44 insertions and 15 deletions:
0 comments (0 inline, 0 general)
src/openttd.cpp
Show inline comments
 
@@ -73,12 +73,13 @@
 
#include "clear_map.h"
 
#include "rail_map.h"
 
#include "road_map.h"
 
#include "water_map.h"
 
#include "industry_map.h"
 
#include "unmovable_map.h"
 
#include "tree_map.h"
 

	
 
#include <stdarg.h>
 

	
 
void CallLandscapeTick();
 
void IncreaseDate();
 
void DoPaletteAnimations();
 
@@ -2193,12 +2194,25 @@ bool AfterLoadGame()
 
			for (j = 0; j < lengthof(i->accepts_cargo); j++) {
 
				i->accepts_cargo[j] = indsp->accepts_cargo[j];
 
			}
 
		}
 
	}
 

	
 
	/* Before version 81, the density of grass was always stored as zero, and
 
	 * grassy trees were always drawn fully grassy. Furthermore, trees on rough
 
	 * land used to have zero density, now they have full density. Therefore,
 
	 * make all grassy/rough land trees have a density of 3. */
 
	if (CheckSavegameVersion(81)) {
 
		for (TileIndex t = 0; t < map_size; t++) {
 
			if (GetTileType(t) == MP_TREES) {
 
				TreeGround groundType = GetTreeGround(t);
 
				if (groundType != TREE_GROUND_SNOW_DESERT) SetTreeGroundDensity(t, groundType, 3);
 
			}
 
		}
 
	}
 

	
 
	return true;
 
}
 

	
 
/** Reload all NewGRF files during a running game. This is a cut-down
 
 * version of AfterLoadGame().
 
 * XXX - We need to reset the vehicle position hash because with a non-empty
src/saveload.cpp
Show inline comments
 
@@ -26,13 +26,13 @@
 
#include "network/network.h"
 
#include "variables.h"
 
#include "table/strings.h"
 
#include "strings.h"
 
#include <list>
 

	
 
extern const uint16 SAVEGAME_VERSION = 80;
 
extern const uint16 SAVEGAME_VERSION = 81;
 
uint16 _sl_version;       ///< the major savegame version identifier
 
byte   _sl_minor_version; ///< the minor savegame version, DO NOT USE!
 

	
 
typedef void WriterProc(uint len);
 
typedef uint ReaderProc();
 

	
src/tree_cmd.cpp
Show inline comments
 
@@ -82,13 +82,13 @@ static void PlaceTree(TileIndex tile, ui
 

	
 
		/* above snowline? */
 
		if (_opt.landscape == LT_ARCTIC && GetTileZ(tile) > GetSnowLine()) {
 
			SetTreeGroundDensity(tile, TREE_GROUND_SNOW_DESERT, 3);
 
			SetTreeCounter(tile, (TreeGround)GB(r, 24, 3));
 
		} else {
 
			SetTreeGroundDensity(tile, (TreeGround)GB(r, 28, 1), 0);
 
			SetTreeGroundDensity(tile, (TreeGround)GB(r, 28, 1), 3);
 
			SetTreeCounter(tile, (TreeGround)GB(r, 24, 4));
 
		}
 
	}
 
}
 

	
 
/**
 
@@ -343,15 +343,16 @@ CommandCost CmdPlantTree(TileIndex tile,
 
							treetype = GetRandomTreeType(tile, GB(Random(), 24, 8));
 
							if (treetype == TREE_INVALID) treetype = TREE_CACTUS;
 
						}
 

	
 
						growth = _game_mode == GM_EDITOR ? 3 : 0;
 
						switch (GetClearGround(tile)) {
 
							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;
 
							case CLEAR_ROUGH:  MakeTree(tile, treetype, 0, growth, TREE_GROUND_ROUGH, 3); break;
 
							case CLEAR_SNOW:
 
							case CLEAR_DESERT: MakeTree(tile, treetype, 0, growth, TREE_GROUND_SNOW_DESERT, GetClearDensity(tile)); break;
 
							default:           MakeTree(tile, treetype, 0, growth, TREE_GROUND_GRASS, GetClearDensity(tile)); break;
 
						}
 
						MarkTileDirtyByTile(tile);
 

	
 
						if (_game_mode == GM_EDITOR && IS_INT_INSIDE(treetype, TREE_RAINFOREST, TREE_CACTUS))
 
							SetTropicZone(tile, TROPICZONE_RAINFOREST);
 
					}
 
@@ -382,13 +383,13 @@ static void DrawTile_Trees(TileInfo *ti)
 
{
 
	const PalSpriteID *s;
 
	const TreePos* d;
 
	byte z;
 

	
 
	switch (GetTreeGround(ti->tile)) {
 
		case TREE_GROUND_GRASS: DrawClearLandTile(ti, 3); break;
 
		case TREE_GROUND_GRASS: DrawClearLandTile(ti, GetTreeDensity(ti->tile)); break;
 
		case TREE_GROUND_ROUGH: DrawHillyLandTile(ti); break;
 
		default: DrawGroundSprite(_tree_sprites_1[GetTreeDensity(ti->tile)] + _tileh_to_sprite[ti->tileh], PAL_NONE); break;
 
	}
 

	
 
	DrawClearLandFence(ti);
 

	
 
@@ -554,13 +555,13 @@ static void TileLoopTreesDesert(TileInde
 
static void TileLoopTreesAlps(TileIndex tile)
 
{
 
	int k = GetTileZ(tile) - GetSnowLine() + TILE_HEIGHT;
 

	
 
	if (k < 0) {
 
		if (GetTreeGround(tile) != TREE_GROUND_SNOW_DESERT) return;
 
		SetTreeGroundDensity(tile, TREE_GROUND_GRASS, 0);
 
		SetTreeGroundDensity(tile, TREE_GROUND_GRASS, 3);
 
	} else {
 
		uint density = min((uint)k / TILE_HEIGHT, 3);
 

	
 
		if (GetTreeGround(tile) != TREE_GROUND_SNOW_DESERT ||
 
				GetTreeDensity(tile) != density) {
 
			SetTreeGroundDensity(tile, TREE_GROUND_SNOW_DESERT, density);
 
@@ -583,12 +584,22 @@ static void TileLoop_Trees(TileIndex til
 
		case LT_TROPIC: TileLoopTreesDesert(tile); break;
 
		case LT_ARCTIC: TileLoopTreesAlps(tile);   break;
 
	}
 

	
 
	TileLoopClearHelper(tile);
 

	
 
	uint treeCounter = GetTreeCounter(tile);
 

	
 
	/* Handle growth of grass at every 8th processings, like it's done for grass */
 
	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);
 
		}
 
	}
 
	if (GetTreeCounter(tile) < 15) {
 
		AddTreeCounter(tile, 1);
 
		return;
 
	}
 
	SetTreeCounter(tile, 0);
 

	
 
@@ -619,17 +630,18 @@ static void TileLoop_Trees(TileIndex til
 

	
 
						if (!IsTileType(tile, MP_CLEAR) || IsBridgeAbove(tile)) return;
 

	
 
						switch (GetClearGround(tile)) {
 
							case CLEAR_GRASS:
 
								if (GetClearDensity(tile) != 3) return;
 
								MakeTree(tile, treetype, 0, 0, TREE_GROUND_GRASS, 0);
 
								MakeTree(tile, treetype, 0, 0, TREE_GROUND_GRASS, 3);
 
								break;
 

	
 
							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;
 
							case CLEAR_ROUGH: MakeTree(tile, treetype, 0, 0, TREE_GROUND_ROUGH, 3); break;
 
							case CLEAR_DESERT: return; // Cacti don't spread
 
							case CLEAR_SNOW: MakeTree(tile, treetype, 0, 0, TREE_GROUND_SNOW_DESERT, GetClearDensity(tile)); break;
 
							default: return;
 
						}
 
						break;
 
					}
 

	
 
					default:
 
@@ -643,15 +655,18 @@ static void TileLoop_Trees(TileIndex til
 
				/* more than one tree, delete it */
 
				AddTreeCount(tile, -1);
 
				SetTreeGrowth(tile, 3);
 
			} else {
 
				/* just one tree, change type into MP_CLEAR */
 
				switch (GetTreeGround(tile)) {
 
					case TREE_GROUND_GRASS: MakeClear(tile, CLEAR_GRASS, 3); break;
 
					case TREE_GROUND_GRASS: MakeClear(tile, CLEAR_GRASS, GetTreeDensity(tile)); break;
 
					case TREE_GROUND_ROUGH: MakeClear(tile, CLEAR_ROUGH, 3); break;
 
					default: MakeClear(tile, CLEAR_SNOW, GetTreeDensity(tile)); break;
 
					default: // snow or desert
 
						if (_opt.landscape == LT_TROPIC) MakeClear(tile, CLEAR_DESERT, GetTreeDensity(tile));
 
						else                             MakeClear(tile, CLEAR_SNOW,   GetTreeDensity(tile));
 
						break;
 
				}
 
			}
 
			break;
 

	
 
		default:
 
			AddTreeGrowth(tile, 1);
 
@@ -672,13 +687,13 @@ void OnTick_Trees()
 
	if (_opt.landscape == LT_TROPIC &&
 
			(r = Random(), tile = RandomTileSeed(r), GetTropicZone(tile) == TROPICZONE_RAINFOREST) &&
 
			IsTileType(tile, MP_CLEAR) &&
 
			!IsBridgeAbove(tile) &&
 
			(ct = GetClearGround(tile), ct == CLEAR_GRASS || ct == CLEAR_ROUGH) &&
 
			(tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TREE_INVALID) {
 
		MakeTree(tile, tree, 0, 0, ct == CLEAR_ROUGH ? TREE_GROUND_ROUGH : TREE_GROUND_GRASS, 0);
 
			MakeTree(tile, tree, 0, 0, ct == CLEAR_ROUGH ? TREE_GROUND_ROUGH : TREE_GROUND_GRASS, GetClearDensity(tile));
 
	}
 

	
 
	/* byte underflow */
 
	if (--_trees_tick_ctr != 0) return;
 

	
 
	/* place a tree at a random spot */
 
@@ -686,14 +701,14 @@ void OnTick_Trees()
 
	tile = TILE_MASK(r);
 
	if (IsTileType(tile, MP_CLEAR) &&
 
			!IsBridgeAbove(tile) &&
 
			(ct = GetClearGround(tile), ct == CLEAR_GRASS || ct == CLEAR_ROUGH || ct == CLEAR_SNOW) &&
 
			(tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TREE_INVALID) {
 
		switch (ct) {
 
			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;
 
			case CLEAR_GRASS: MakeTree(tile, tree, 0, 0, TREE_GROUND_GRASS, GetClearDensity(tile)); break;
 
			case CLEAR_ROUGH: MakeTree(tile, tree, 0, 0, TREE_GROUND_ROUGH, 3); break;
 
			default: MakeTree(tile, tree, 0, 0, TREE_GROUND_SNOW_DESERT, GetClearDensity(tile)); break;
 
		}
 
	}
 
}
 

	
 
static void ClickTile_Trees(TileIndex tile)
0 comments (0 inline, 0 general)