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"
|
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"
|
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"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-04 16:50:18 +00:00
|
|
|
static int 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:
|
|
|
|
return seed * 12 >> 8;
|
|
|
|
|
|
|
|
case LT_HILLY:
|
|
|
|
return (seed >> 5) + 12;
|
|
|
|
|
|
|
|
case LT_DESERT:
|
|
|
|
switch (GetMapExtraBits(tile)) {
|
2005-07-17 11:09:03 +00:00
|
|
|
case 0: return (seed >> 6) + 28;
|
|
|
|
case 1: return (seed > 12) ? -1 : 27;
|
|
|
|
default: return (seed * 7 >> 8) + 20;
|
2005-02-04 16:50:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return (seed * 9 >> 8) + 32;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void PlaceTree(TileIndex tile, uint32 r, byte m5_or)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-07-17 11:09:03 +00:00
|
|
|
int tree = GetRandomTreeType(tile, GB(r, 24, 8));
|
2004-08-09 17:04:08 +00:00
|
|
|
byte m5;
|
|
|
|
|
|
|
|
if (tree >= 0) {
|
2005-07-17 11:09:03 +00:00
|
|
|
SetTileType(tile, MP_TREES);
|
|
|
|
|
|
|
|
m5 = GB(r, 16, 8);
|
|
|
|
if (GB(m5, 0, 3) == 7) m5--; // there is no growth state 7
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-13 18:04:01 +00:00
|
|
|
_m[tile].m5 = m5 & 0x07; // growth state;
|
|
|
|
_m[tile].m5 |= m5 & 0xC0; // amount of trees
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-13 18:04:01 +00:00
|
|
|
_m[tile].m3 = tree; // set type of tree
|
|
|
|
_m[tile].m4 = 0; // no hedge
|
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) {
|
2005-07-13 18:04:01 +00:00
|
|
|
_m[tile].m2 = 0xE0; // set land type to snow
|
2005-07-17 11:09:03 +00:00
|
|
|
_m[tile].m2 |= GB(r, 24, 3); // randomize counter
|
|
|
|
} else {
|
|
|
|
_m[tile].m2 = GB(r, 24, 5); // randomize counter and ground
|
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
|
|
|
|
2004-12-30 09:43:12 +00:00
|
|
|
/* Only on tiles within 13 squares from tile,
|
2005-01-03 21:47:52 +00:00
|
|
|
on clear tiles, and NOT on farm-tiles or rocks */
|
2005-01-16 11:24:58 +00:00
|
|
|
if (dist <= 13 && IsTileType(cur_tile, MP_CLEAR) &&
|
2005-07-13 18:04:01 +00:00
|
|
|
(_m[cur_tile].m5 & 0x1F) != 0x0F && (_m[cur_tile].m5 & 0x1C) != 8) {
|
2004-08-09 17:04:08 +00:00
|
|
|
PlaceTree(cur_tile, r, dist <= 6 ? 0xC0 : 0);
|
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void PlaceTreesRandomly(void)
|
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-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);
|
2005-01-03 21:47:52 +00:00
|
|
|
/* Only on clear tiles, and NOT on farm-tiles or rocks */
|
2005-07-13 18:04:01 +00:00
|
|
|
if (IsTileType(tile, MP_CLEAR) && (_m[tile].m5 & 0x1F) != 0x0F && (_m[tile].m5 & 0x1C) != 8) {
|
2004-08-09 17:04:08 +00:00
|
|
|
PlaceTree(tile, r, 0);
|
|
|
|
}
|
|
|
|
} 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);
|
2005-01-16 11:24:58 +00:00
|
|
|
if (IsTileType(tile, MP_CLEAR) && GetMapExtraBits(tile) == 2) {
|
2004-08-09 17:04:08 +00:00
|
|
|
PlaceTree(tile, r, 0);
|
|
|
|
}
|
|
|
|
} while (--i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void GenerateTrees(void)
|
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
|
|
|
if (_opt.landscape != LT_CANDY) PlaceMoreTrees();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-17 11:09:03 +00:00
|
|
|
for (i = _opt.landscape == LT_HILLY ? 15 : 6; 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.
|
|
|
|
* @param x,y start tile of area-drag of tree plantation
|
|
|
|
* @param p1 tree type, -1 means random.
|
|
|
|
* @param p2 end tile of area-drag
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
|
|
|
int32 CmdPlantTree(int ex, int ey, uint32 flags, uint32 p1, uint32 p2)
|
|
|
|
{
|
|
|
|
int32 cost;
|
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
|
2005-07-18 00:17:19 +00:00
|
|
|
sx = TileX(p2);
|
|
|
|
sy = TileY(p2);
|
|
|
|
ex /= 16; ey /= 16;
|
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?
|
2005-07-17 11:09:03 +00:00
|
|
|
if (_game_mode != GM_EDITOR && (_m[tile].m5 & 0xC0) == 0xC0) {
|
2005-02-04 16:50:18 +00:00
|
|
|
_error_message = STR_2803_TREE_ALREADY_HERE;
|
|
|
|
continue;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-04 16:50:18 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2005-07-17 11:09:03 +00:00
|
|
|
_m[tile].m5 += 0x40;
|
|
|
|
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:
|
2005-07-17 11:09:03 +00:00
|
|
|
if (!IsTileOwner(tile, OWNER_NONE)) {
|
2005-02-04 16:50:18 +00:00
|
|
|
_error_message = STR_2804_SITE_UNSUITABLE;
|
|
|
|
continue;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-02-04 16:50:18 +00:00
|
|
|
// it's expensive to clear farmland
|
2005-07-17 11:09:03 +00:00
|
|
|
if ((_m[tile].m5 & 0x1F) == 0xF)
|
2005-02-04 16:50:18 +00:00
|
|
|
cost += _price.clear_3;
|
2005-07-17 11:09:03 +00:00
|
|
|
else if ((_m[tile].m5 & 0x1C) == 8)
|
2005-02-04 16:50:18 +00:00
|
|
|
cost += _price.clear_2;
|
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
int treetype;
|
|
|
|
int m2;
|
|
|
|
|
|
|
|
if (_game_mode != GM_EDITOR && _current_player < MAX_PLAYERS) {
|
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);
|
|
|
|
}
|
|
|
|
|
2005-07-17 11:09:03 +00:00
|
|
|
switch (_m[tile].m5 & 0x1C) {
|
2005-02-04 16:50:18 +00:00
|
|
|
case 0x04:
|
|
|
|
m2 = 16;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x10:
|
2005-07-17 11:09:03 +00:00
|
|
|
m2 = ((_m[tile].m5 & 3) << 6) | 0x20;
|
2005-02-04 16:50:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
m2 = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
treetype = p1;
|
|
|
|
if (treetype == -1) {
|
2005-11-14 08:09:57 +00:00
|
|
|
treetype = GetRandomTreeType(tile, GB(Random(), 24, 8));
|
2005-02-04 16:50:18 +00:00
|
|
|
if (treetype == -1) treetype = 27;
|
|
|
|
}
|
|
|
|
|
2005-07-17 11:09:03 +00:00
|
|
|
ModifyTile(tile,
|
2005-02-04 16:50:18 +00:00
|
|
|
MP_SETTYPE(MP_TREES) |
|
|
|
|
MP_MAP2 | MP_MAP3LO | MP_MAP3HI_CLEAR | MP_MAP5,
|
|
|
|
m2, /* map2 */
|
|
|
|
treetype, /* map3lo */
|
|
|
|
_game_mode == GM_EDITOR ? 3 : 0 /* map5 */
|
|
|
|
);
|
|
|
|
|
|
|
|
if (_game_mode == GM_EDITOR && IS_BYTE_INSIDE(treetype, 0x14, 0x1B))
|
2005-07-17 11:09:03 +00:00
|
|
|
SetMapExtraBits(tile, 2);
|
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:
|
|
|
|
_error_message = STR_2804_SITE_UNSUITABLE;
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-05-09 22:33:00 +00:00
|
|
|
return (cost == 0) ? CMD_ERROR : cost;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct TreeListEnt {
|
|
|
|
uint32 image;
|
|
|
|
byte x,y;
|
|
|
|
} TreeListEnt;
|
|
|
|
|
|
|
|
static void DrawTile_Trees(TileInfo *ti)
|
|
|
|
{
|
2004-12-28 11:51:31 +00:00
|
|
|
uint16 m2;
|
2004-08-09 17:04:08 +00:00
|
|
|
const uint32 *s;
|
2005-11-16 12:01:46 +00:00
|
|
|
const TreePos* d;
|
2004-08-09 17:04:08 +00:00
|
|
|
byte z;
|
|
|
|
|
2005-07-13 18:04:01 +00:00
|
|
|
m2 = _m[ti->tile].m2;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-17 11:09:03 +00:00
|
|
|
if ((m2 & 0x30) == 0) {
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawClearLandTile(ti, 3);
|
2005-07-17 11:09:03 +00:00
|
|
|
} else if ((m2 & 0x30) == 0x20) {
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawGroundSprite(_tree_sprites_1[m2 >> 6] + _tileh_to_sprite[ti->tileh]);
|
|
|
|
} else {
|
|
|
|
DrawHillyLandTile(ti);
|
|
|
|
}
|
|
|
|
|
2005-07-28 19:18:27 +00:00
|
|
|
DrawClearLandFence(ti);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
z = ti->z;
|
|
|
|
if (ti->tileh != 0) {
|
|
|
|
z += 4;
|
2005-07-16 23:47:37 +00:00
|
|
|
if (IsSteepTileh(ti->tileh))
|
2004-08-09 17:04:08 +00:00
|
|
|
z += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2005-07-17 11:09:03 +00:00
|
|
|
index = GB(tmp, 6, 2) + (_m[ti->tile].m3 << 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 */
|
|
|
|
if ((m2 & 0xB0) == 0xA0 && index >= 48 && index < 80)
|
|
|
|
index += 164 - 48;
|
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 */
|
|
|
|
i = (ti->map5 >> 6) + 1;
|
|
|
|
do {
|
2005-07-30 18:30:07 +00:00
|
|
|
uint32 image = s[0] + (--i == 0 ? GB(ti->map5, 0, 3) : 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;
|
|
|
|
|
|
|
|
i = (ti->map5 >> 6) + 1;
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-19 14:49:46 +00:00
|
|
|
static uint GetSlopeZ_Trees(const TileInfo* ti)
|
|
|
|
{
|
2005-07-30 18:30:07 +00:00
|
|
|
return GetPartialZ(ti->x & 0xF, ti->y & 0xF, ti->tileh) + ti->z;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-10-22 06:39:32 +00:00
|
|
|
static uint GetSlopeTileh_Trees(const TileInfo* ti)
|
|
|
|
{
|
2004-08-13 18:27:33 +00:00
|
|
|
return ti->tileh;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
if (flags & DC_EXEC && _current_player < MAX_PLAYERS) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2005-07-30 18:30:07 +00:00
|
|
|
num = GB(_m[tile].m5, 6, 2) + 1;
|
|
|
|
if (IS_INT_INSIDE(_m[tile].m3, 20, 26 + 1)) 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
|
|
|
{
|
|
|
|
byte b;
|
|
|
|
StringID str;
|
|
|
|
|
2005-06-04 11:56:32 +00:00
|
|
|
td->owner = GetTileOwner(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-13 18:04:01 +00:00
|
|
|
b = _m[tile].m3;
|
2004-08-09 17:04:08 +00:00
|
|
|
(str=STR_2810_CACTUS_PLANTS, b==0x1B) ||
|
|
|
|
(str=STR_280F_RAINFOREST, IS_BYTE_INSIDE(b, 0x14, 0x1A+1)) ||
|
|
|
|
(str=STR_280E_TREES, true);
|
2004-09-10 19:02:27 +00:00
|
|
|
td->str = str;
|
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
|
|
|
{
|
2005-07-30 18:30:07 +00:00
|
|
|
static const SoundFx forest_sounds[] = {
|
|
|
|
SND_42_LOON_BIRD,
|
|
|
|
SND_43_LION,
|
|
|
|
SND_44_MONKEYS,
|
|
|
|
SND_48_DISTANT_BIRD
|
|
|
|
};
|
|
|
|
|
|
|
|
byte b = GetMapExtraBits(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-17 11:09:03 +00:00
|
|
|
if (b == 2) {
|
|
|
|
uint32 r = Random();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-30 18:30:07 +00:00
|
|
|
if (CHANCE16I(1, 200, r)) SndPlayTileFx(forest_sounds[GB(r, 16, 2)], tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
} else if (b == 1) {
|
2005-07-30 18:30:07 +00:00
|
|
|
if (GB(_m[tile].m2, 4, 2) != 2) {
|
|
|
|
SB(_m[tile].m2, 4, 2, 2);
|
|
|
|
SB(_m[tile].m2, 6, 2, 3);
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void TileLoopTreesAlps(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
byte tmp, m2;
|
|
|
|
int k;
|
|
|
|
|
|
|
|
/* distance from snow line, in steps of 8 */
|
|
|
|
k = GetTileZ(tile) - _opt.snow_line;
|
|
|
|
|
2005-07-29 18:22:04 +00:00
|
|
|
tmp = _m[tile].m2 & 0xF0;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (k < -8) {
|
2005-07-17 11:09:03 +00:00
|
|
|
if ((tmp & 0x30) != 0x20) return;
|
2005-07-30 18:30:07 +00:00
|
|
|
m2 = 0; // no snow
|
2004-08-09 17:04:08 +00:00
|
|
|
} else if (k == -8) {
|
2005-07-30 18:30:07 +00:00
|
|
|
m2 = 0x20; // 1/4 snow
|
2005-07-17 11:09:03 +00:00
|
|
|
if (tmp == m2) return;
|
2005-07-30 18:30:07 +00:00
|
|
|
} else if (k == 0) {
|
|
|
|
m2 = 0x60;// 1/2 snow
|
2005-07-17 11:09:03 +00:00
|
|
|
if (tmp == m2) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else if (k == 8) {
|
2005-07-30 18:30:07 +00:00
|
|
|
m2 = 0xA0; // 3/4 snow
|
2005-07-17 11:09:03 +00:00
|
|
|
if (tmp == m2) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2005-07-29 18:22:04 +00:00
|
|
|
if (tmp == 0xE0) {
|
2005-07-17 11:09:03 +00:00
|
|
|
uint32 r = Random();
|
2005-07-30 18:30:07 +00:00
|
|
|
if (CHANCE16I(1, 200, r)) {
|
2004-12-04 09:26:39 +00:00
|
|
|
SndPlayTileFx((r & 0x80000000) ? SND_39_HEAVY_WIND : SND_34_WIND, tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
} else {
|
2005-07-30 18:30:07 +00:00
|
|
|
m2 = 0xE0; // full snow
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-13 18:04:01 +00:00
|
|
|
_m[tile].m2 &= 0xF;
|
|
|
|
_m[tile].m2 |= m2;
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void TileLoop_Trees(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2004-12-28 11:51:31 +00:00
|
|
|
byte m5;
|
|
|
|
uint16 m2;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-06 11:39:00 +00:00
|
|
|
static const TileIndexDiffC _tileloop_trees_dir[] = {
|
|
|
|
{-1, -1},
|
|
|
|
{ 0, -1},
|
|
|
|
{ 1, -1},
|
|
|
|
{-1, 0},
|
|
|
|
{ 1, 0},
|
|
|
|
{-1, 1},
|
|
|
|
{ 0, 1},
|
|
|
|
{ 1, 1}
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (_opt.landscape == LT_DESERT) {
|
|
|
|
TileLoopTreesDesert(tile);
|
|
|
|
} else if (_opt.landscape == LT_HILLY) {
|
|
|
|
TileLoopTreesAlps(tile);
|
|
|
|
}
|
|
|
|
|
|
|
|
TileLoopClearHelper(tile);
|
|
|
|
|
|
|
|
/* increase counter */
|
2005-07-30 09:29:20 +00:00
|
|
|
AB(_m[tile].m2, 0, 4, 1);
|
|
|
|
if (GB(_m[tile].m2, 0, 4) != 0) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-13 18:04:01 +00:00
|
|
|
m5 = _m[tile].m5;
|
2005-07-17 11:09:03 +00:00
|
|
|
if (GB(m5, 0, 3) == 3) {
|
2004-08-09 17:04:08 +00:00
|
|
|
/* regular sized tree */
|
2005-07-17 11:09:03 +00:00
|
|
|
if (_opt.landscape == LT_DESERT && _m[tile].m3 != 0x1B && GetMapExtraBits(tile) == 1) {
|
2004-08-09 17:04:08 +00:00
|
|
|
m5++; /* start destructing */
|
|
|
|
} else {
|
2005-11-14 08:09:57 +00:00
|
|
|
switch (GB(Random(), 0, 3)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
case 0: /* start destructing */
|
|
|
|
m5++;
|
|
|
|
break;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
case 1: /* add a tree */
|
|
|
|
if (m5 < 0xC0) {
|
|
|
|
m5 = (m5 + 0x40) & ~7;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fall through */
|
|
|
|
|
|
|
|
case 2: { /* add a neighbouring tree */
|
2005-01-06 11:39:00 +00:00
|
|
|
tile += ToTileIndexDiff(_tileloop_trees_dir[Random() & 7]);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-17 11:09:03 +00:00
|
|
|
if (!IsTileType(tile, MP_CLEAR)) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-13 18:04:01 +00:00
|
|
|
if ( (_m[tile].m5 & 0x1C) == 4) {
|
|
|
|
_m[tile].m2 = 0x10;
|
|
|
|
} else if ((_m[tile].m5 & 0x1C) == 16) {
|
|
|
|
_m[tile].m2 = ((_m[tile].m5 & 3) << 6) | 0x20;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2005-07-17 11:09:03 +00:00
|
|
|
if ((_m[tile].m5 & 0x1F) != 3) return;
|
2005-07-13 18:04:01 +00:00
|
|
|
_m[tile].m2 = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-07-13 18:04:01 +00:00
|
|
|
_m[tile].m4 = 0;
|
2005-01-18 18:41:56 +00:00
|
|
|
SetTileType(tile, MP_TREES);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
m5 = 0;
|
|
|
|
break;
|
2004-09-10 19:02:27 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2005-07-17 11:09:03 +00:00
|
|
|
} else if (GB(m5, 0, 3) == 6) {
|
2004-08-09 17:04:08 +00:00
|
|
|
/* final stage of tree destruction */
|
2005-07-17 11:09:03 +00:00
|
|
|
if (GB(m5, 6, 2) != 0) {
|
2004-08-09 17:04:08 +00:00
|
|
|
/* more than one tree, delete it? */
|
|
|
|
m5 = ((m5 - 6) - 0x40) + 3;
|
|
|
|
} else {
|
|
|
|
/* just one tree, change type into MP_CLEAR */
|
2005-01-18 18:41:56 +00:00
|
|
|
SetTileType(tile, MP_CLEAR);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
m5 = 3;
|
2005-07-13 18:04:01 +00:00
|
|
|
m2 = _m[tile].m2;
|
2005-07-17 11:09:03 +00:00
|
|
|
if ((m2 & 0x30) != 0) { // on snow/desert or rough land
|
2004-08-09 17:04:08 +00:00
|
|
|
m5 = (m2 >> 6) | 0x10;
|
2005-07-17 11:09:03 +00:00
|
|
|
if ((m2 & 0x30) != 0x20) // if not on snow/desert, then on rough land
|
2004-08-09 17:04:08 +00:00
|
|
|
m5 = 7;
|
|
|
|
}
|
2005-06-04 12:13:24 +00:00
|
|
|
SetTileOwner(tile, OWNER_NONE);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* in the middle of a transition, change to next */
|
|
|
|
m5++;
|
|
|
|
}
|
|
|
|
|
2005-07-13 18:04:01 +00:00
|
|
|
_m[tile].m5 = m5;
|
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;
|
2004-08-09 17:04:08 +00:00
|
|
|
byte m;
|
|
|
|
int tree;
|
|
|
|
|
|
|
|
/* place a tree at a random rainforest spot */
|
2004-09-10 19:02:27 +00:00
|
|
|
if (_opt.landscape == LT_DESERT &&
|
2005-07-17 11:09:03 +00:00
|
|
|
(r = Random(), tile = RandomTileSeed(r), GetMapExtraBits(tile) == 2) &&
|
2005-01-16 11:24:58 +00:00
|
|
|
IsTileType(tile, MP_CLEAR) &&
|
2005-07-17 11:09:03 +00:00
|
|
|
(m = _m[tile].m5 & 0x1C, m <= 4) &&
|
2005-11-14 08:09:57 +00:00
|
|
|
(tree = GetRandomTreeType(tile, GB(r, 24, 8))) >= 0) {
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
ModifyTile(tile,
|
2004-09-10 19:02:27 +00:00
|
|
|
MP_SETTYPE(MP_TREES) |
|
2004-08-09 17:04:08 +00:00
|
|
|
MP_MAP2 | MP_MAP3LO | MP_MAP3HI | MP_MAP5,
|
|
|
|
(m == 4 ? 0x10 : 0),
|
|
|
|
tree,
|
2005-07-13 18:04:01 +00:00
|
|
|
_m[tile].m4 & ~3,
|
2004-08-09 17:04:08 +00:00
|
|
|
0
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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) &&
|
2005-07-17 11:09:03 +00:00
|
|
|
(m = _m[tile].m5 & 0x1C, m == 0 || m == 4 || m == 0x10) &&
|
2005-11-14 08:09:57 +00:00
|
|
|
(tree = GetRandomTreeType(tile, GB(r, 24, 8))) >= 0) {
|
2004-08-09 17:04:08 +00:00
|
|
|
int m2;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (m == 0) {
|
|
|
|
m2 = 0;
|
|
|
|
} else if (m == 4) {
|
|
|
|
m2 = 0x10;
|
|
|
|
} else {
|
2005-07-13 18:04:01 +00:00
|
|
|
m2 = ((_m[tile].m5 & 3) << 6) | 0x20;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ModifyTile(tile,
|
2004-09-10 19:02:27 +00:00
|
|
|
MP_SETTYPE(MP_TREES) |
|
2004-08-09 17:04:08 +00:00
|
|
|
MP_MAP2 | MP_MAP3LO | MP_MAP3HI | MP_MAP5,
|
|
|
|
m2,
|
|
|
|
tree,
|
2005-07-13 18:04:01 +00:00
|
|
|
_m[tile].m4 & ~3,
|
2004-08-09 17:04:08 +00:00
|
|
|
0
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 = {
|
|
|
|
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 */
|
|
|
|
NULL, /* vehicle_leave_tile_proc */
|
2004-08-13 18:27:33 +00:00
|
|
|
GetSlopeTileh_Trees, /* get_slope_tileh_proc */
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|