Changeset - r3079:e4f78ffd69d5
[Not reviewed]
master
0 2 0
tron - 18 years ago 2006-02-24 20:38:08
tron@openttd.org
(svn r3668) Add a function to turn a tile into a tree tile
2 files changed with 24 insertions and 42 deletions:
tree.h
11
tree_cmd.c
13
42
0 comments (0 inline, 0 general)
tree.h
Show inline comments
 
@@ -53,7 +53,18 @@ static inline uint GetTreeGrowth(TileInd
 
static inline void SetTreeGrowth(TileIndex t, uint g) { SB(_m[t].m5, 0, 3, g); }
 

	
 
static inline void AddTreeCounter(TileIndex t, int a) { _m[t].m2 += a; }
 
static inline uint GetTreeCounter(TileIndex t) { return GB(_m[t].m2, 0, 4); }
 
static inline void SetTreeCounter(TileIndex t, uint c) { SB(_m[t].m2, 0, 4, c); }
 

	
 

	
 
static inline void MakeTree(TileIndex t, TreeType type, uint count, uint growth, TreeGround ground, uint density)
 
{
 
	SetTileType(t, MP_TREES);
 
	SetTileOwner(t, OWNER_NONE);
 
	_m[t].m2 = density << 6 | ground << 4 | 0;
 
	_m[t].m3 = type;
 
	_m[t].m4 = 0 << 5 | 0 << 2;
 
	_m[t].m5 = count << 6 | growth;
 
}
 

	
 
#endif
tree_cmd.c
Show inline comments
 
@@ -39,18 +39,13 @@ static TreeType GetRandomTreeType(TileIn
 

	
 
static void PlaceTree(TileIndex tile, uint32 r)
 
{
 
	TreeType tree = GetRandomTreeType(tile, GB(r, 24, 8));
 

	
 
	if (tree != TR_INVALID) {
 
		SetTileType(tile, MP_TREES);
 
		SetTreeType(tile, tree);
 
		SetFenceSE(tile, 0);
 
		SetFenceSW(tile, 0);
 
		SetTreeCount(tile, GB(r, 22, 2));
 
		SetTreeGrowth(tile, min(GB(r, 16, 3), 6));
 
		MakeTree(tile, tree, GB(r, 22, 2), min(GB(r, 16, 3), 6), TR_GRASS, 0);
 

	
 
		// above snowline?
 
		if (_opt.landscape == LT_HILLY && GetTileZ(tile) > _opt.snow_line) {
 
			SetTreeGroundDensity(tile, TR_SNOW_DESERT, 3);
 
			SetTreeCounter(tile, GB(r, 24, 3));
 
		} else {
 
@@ -186,12 +181,13 @@ int32 CmdPlantTree(int ex, int ey, uint3
 
						case CL_ROCKS:  cost += _price.clear_2; break;
 
						default: break;
 
					}
 

	
 
					if (flags & DC_EXEC) {
 
						TreeType treetype;
 
						uint growth;
 

	
 
						if (_game_mode != GM_EDITOR && _current_player < MAX_PLAYERS) {
 
							Town *t = ClosestTownFromTile(tile, _patches.dist_local_authority);
 
							if (t != NULL)
 
								ChangeTownRating(t, RATING_TREE_UP_STEP, RATING_TREE_MAXIMUM);
 
						}
 
@@ -199,25 +195,18 @@ int32 CmdPlantTree(int ex, int ey, uint3
 
						treetype = p1;
 
						if (treetype == TR_INVALID) {
 
							treetype = GetRandomTreeType(tile, GB(Random(), 24, 8));
 
							if (treetype == TR_INVALID) treetype = TR_CACTUS;
 
						}
 

	
 
						growth = _game_mode == GM_EDITOR ? 3 : 0;
 
						switch (GetClearGround(tile)) {
 
							case CL_ROUGH: SetTreeGroundDensity(tile, TR_ROUGH, 0); break;
 
							case CL_SNOW:  SetTreeGroundDensity(tile, TR_SNOW_DESERT, GetClearDensity(tile)); break;
 
							default:       SetTreeGroundDensity(tile, TR_GRASS, 0); break;
 
							case CL_ROUGH: MakeTree(tile, treetype, 0, growth, TR_ROUGH, 0); break;
 
							case CL_SNOW:  MakeTree(tile, treetype, 0, growth, TR_SNOW_DESERT, GetClearDensity(tile)); break;
 
							default:       MakeTree(tile, treetype, 0, growth, TR_GRASS, 0); break;
 
						}
 
						SetTreeCounter(tile, 0);
 

	
 
						SetTileType(tile, MP_TREES);
 
						SetTreeType(tile, treetype);
 
						SetFenceSE(tile, 0);
 
						SetFenceSW(tile, 0);
 
						SetTreeCount(tile, 0);
 
						SetTreeGrowth(tile, _game_mode == GM_EDITOR ? 3 : 0);
 
						MarkTileDirtyByTile(tile);
 

	
 
						if (_game_mode == GM_EDITOR && IS_INT_INSIDE(treetype, TR_RAINFOREST, TR_CACTUS))
 
							SetMapExtraBits(tile, 2);
 
					}
 
					cost += _price.build_trees;
 
@@ -481,27 +470,19 @@ static void TileLoop_Trees(TileIndex til
 

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

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

	
 
							case CL_ROUGH: SetTreeGroundDensity(tile, TR_ROUGH, 0); break;
 
							case CL_SNOW:  SetTreeGroundDensity(tile, TR_SNOW_DESERT, GetClearDensity(tile)); break;
 
							case CL_ROUGH: MakeTree(tile, treetype, 0, 0, TR_ROUGH, 0); break;
 
							case CL_SNOW:  MakeTree(tile, treetype, 0, 0, TR_SNOW_DESERT, GetClearDensity(tile)); break;
 
							default: return;
 
						}
 
						SetTreeCounter(tile, 0);
 

	
 
						SetTileType(tile, MP_TREES);
 
						SetTreeType(tile, treetype);
 
						SetFenceSE(tile, 0);
 
						SetFenceSW(tile, 0);
 
						SetTreeCount(tile, 0);
 
						SetTreeGrowth(tile, 0);
 
						break;
 
					}
 

	
 
					default:
 
						return;
 
				}
 
@@ -541,39 +522,29 @@ void OnTick_Trees(void)
 
	/* place a tree at a random rainforest spot */
 
	if (_opt.landscape == LT_DESERT &&
 
			(r = Random(), tile = RandomTileSeed(r), GetMapExtraBits(tile) == 2) &&
 
			IsTileType(tile, MP_CLEAR) &&
 
			(ct = GetClearGround(tile), ct == CL_GRASS || ct == CL_ROUGH) &&
 
			(tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TR_INVALID) {
 
		SetTileType(tile, MP_TREES);
 
		SetTreeGroundDensity(tile, ct == CL_ROUGH ? TR_ROUGH : TR_GRASS, 0);
 
		SetTreeCounter(tile, 0);
 
		SetTreeType(tile, tree);
 
		SetTreeCount(tile, 0);
 
		SetTreeGrowth(tile, 0);
 
		MakeTree(tile, tree, 0, 0, ct == CL_ROUGH ? TR_ROUGH : TR_GRASS, 0);
 
	}
 

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

	
 
	/* place a tree at a random spot */
 
	r = Random();
 
	tile = TILE_MASK(r);
 
	if (IsTileType(tile, MP_CLEAR) &&
 
			(ct = GetClearGround(tile), ct == CL_GRASS || ct == CL_ROUGH || ct == CL_SNOW) &&
 
			(tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TR_INVALID) {
 
		switch (ct) {
 
			case CL_GRASS: SetTreeGroundDensity(tile, TR_GRASS, 0); break;
 
			case CL_ROUGH: SetTreeGroundDensity(tile, TR_ROUGH, 0); break;
 
			default:       SetTreeGroundDensity(tile, TR_SNOW_DESERT, GetClearDensity(tile)); break;
 
			case CL_GRASS: MakeTree(tile, tree, 0, 0, TR_GRASS, 0); break;
 
			case CL_ROUGH: MakeTree(tile, tree, 0, 0, TR_ROUGH, 0); break;
 
			default:       MakeTree(tile, tree, 0, 0, TR_SNOW_DESERT, GetClearDensity(tile)); break;
 
		}
 
		SetTreeCounter(tile, 0);
 
		SetTileType(tile, MP_TREES);
 
		SetTreeType(tile, tree);
 
		SetTreeCount(tile, 0);
 
		SetTreeGrowth(tile, 0);
 
	}
 
}
 

	
 
static void ClickTile_Trees(TileIndex tile)
 
{
 
	/* not used */
0 comments (0 inline, 0 general)