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-22 07:02:20 +00:00
|
|
|
#include "functions.h"
|
2004-12-15 22:18:54 +00:00
|
|
|
#include "map.h"
|
2005-07-21 19:36:43 +00:00
|
|
|
#include "player.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"
|
2005-07-21 18:44:27 +00:00
|
|
|
#include "variables.h"
|
2005-10-15 11:06:54 +00:00
|
|
|
#include "table/sprites.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
typedef struct TerraformerHeightMod {
|
|
|
|
TileIndex tile;
|
|
|
|
byte height;
|
|
|
|
} TerraformerHeightMod;
|
|
|
|
|
|
|
|
typedef struct TerraformerState {
|
|
|
|
int height[4];
|
|
|
|
uint32 flags;
|
|
|
|
|
|
|
|
int direction;
|
|
|
|
int modheight_count;
|
|
|
|
int tile_table_count;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
int32 cost;
|
|
|
|
|
|
|
|
TileIndex *tile_table;
|
|
|
|
TerraformerHeightMod *modheight;
|
|
|
|
|
|
|
|
} TerraformerState;
|
|
|
|
|
|
|
|
static int TerraformAllowTileProcess(TerraformerState *ts, TileIndex tile)
|
|
|
|
{
|
|
|
|
TileIndex *t;
|
|
|
|
int count;
|
|
|
|
|
2005-01-07 17:02:43 +00:00
|
|
|
if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY())
|
2004-08-09 17:04:08 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
t = ts->tile_table;
|
|
|
|
for(count = ts->tile_table_count; count != 0; count--,t++) {
|
|
|
|
if (*t == tile)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int TerraformGetHeightOfTile(TerraformerState *ts, TileIndex tile)
|
|
|
|
{
|
|
|
|
TerraformerHeightMod *mod = ts->modheight;
|
|
|
|
int count;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
for(count = ts->modheight_count; count != 0; count--, mod++) {
|
|
|
|
if (mod->tile == tile)
|
|
|
|
return mod->height;
|
|
|
|
}
|
|
|
|
|
2005-01-16 14:50:01 +00:00
|
|
|
return TileHeight(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void TerraformAddDirtyTile(TerraformerState *ts, TileIndex tile)
|
|
|
|
{
|
|
|
|
int count;
|
|
|
|
TileIndex *t;
|
|
|
|
|
|
|
|
count = ts->tile_table_count;
|
|
|
|
|
|
|
|
if (count >= 625)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for(t = ts->tile_table; count != 0; count--,t++) {
|
|
|
|
if (*t == tile)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ts->tile_table[ts->tile_table_count++] = tile;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void TerraformAddDirtyTileAround(TerraformerState *ts, TileIndex tile)
|
|
|
|
{
|
2005-06-25 16:44:57 +00:00
|
|
|
TerraformAddDirtyTile(ts, tile + TileDiffXY( 0, -1));
|
|
|
|
TerraformAddDirtyTile(ts, tile + TileDiffXY(-1, -1));
|
|
|
|
TerraformAddDirtyTile(ts, tile + TileDiffXY(-1, 0));
|
2004-08-09 17:04:08 +00:00
|
|
|
TerraformAddDirtyTile(ts, tile);
|
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static int TerraformProc(TerraformerState *ts, TileIndex tile, int mode)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
int r;
|
|
|
|
int32 ret;
|
|
|
|
|
2005-01-03 18:59:58 +00:00
|
|
|
assert(tile < MapSize());
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if ((r=TerraformAllowTileProcess(ts, tile)) <= 0)
|
|
|
|
return r;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-01-16 14:50:01 +00:00
|
|
|
if (IsTileType(tile, MP_RAILWAY)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
static const byte _railway_modes[4] = {8, 0x10, 4, 0x20};
|
|
|
|
static const byte _railway_dangslopes[4] = {0xd, 0xe, 7, 0xb};
|
2004-11-08 09:11:55 +00:00
|
|
|
static const byte _railway_dangslopes2[4] = {0x2, 0x1, 0x8, 0x4};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// Nothing could be built at the steep slope - this avoids a bug
|
|
|
|
// when you have a single diagonal track in one corner on a
|
2004-11-08 09:11:55 +00:00
|
|
|
// basement and then you raise/lower the other corner.
|
|
|
|
int tileh = GetTileSlope(tile, NULL) & 0xF;
|
|
|
|
if (tileh == _railway_dangslopes[mode] ||
|
|
|
|
tileh == _railway_dangslopes2[mode]) {
|
|
|
|
_terraform_err_tile = tile;
|
2004-08-09 17:04:08 +00:00
|
|
|
_error_message = STR_1008_MUST_REMOVE_RAILROAD_TRACK;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have a single diagonal track there, the other side of
|
|
|
|
// tile can be terraformed.
|
2005-07-13 18:04:01 +00:00
|
|
|
if ((_m[tile].m5&~0x40) == _railway_modes[mode])
|
2004-08-09 17:04:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = DoCommandByTile(tile, 0,0, ts->flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
|
|
|
|
|
|
|
if (ret == CMD_ERROR) {
|
|
|
|
_terraform_err_tile = tile;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ts->cost += ret;
|
|
|
|
|
|
|
|
if (ts->tile_table_count >= 625)
|
|
|
|
return -1;
|
|
|
|
ts->tile_table[ts->tile_table_count++] = tile;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static bool TerraformTileHeight(TerraformerState *ts, TileIndex tile, int height)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
int nh;
|
|
|
|
TerraformerHeightMod *mod;
|
|
|
|
int count;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-01-03 18:59:58 +00:00
|
|
|
assert(tile < MapSize());
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (height < 0) {
|
|
|
|
_error_message = STR_1003_ALREADY_AT_SEA_LEVEL;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
_error_message = STR_1004_TOO_HIGH;
|
|
|
|
|
|
|
|
if (height > 0xF)
|
|
|
|
return false;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
nh = TerraformGetHeightOfTile(ts, tile);
|
|
|
|
if (nh < 0 || height == nh)
|
2004-09-10 19:02:27 +00:00
|
|
|
return false;
|
|
|
|
|
2005-06-25 16:44:57 +00:00
|
|
|
if (TerraformProc(ts, tile, 0) < 0) return false;
|
|
|
|
if (TerraformProc(ts, tile + TileDiffXY( 0, -1), 1) < 0) return false;
|
|
|
|
if (TerraformProc(ts, tile + TileDiffXY(-1, -1), 2) < 0) return false;
|
|
|
|
if (TerraformProc(ts, tile + TileDiffXY(-1, 0), 3) < 0) return false;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
mod = ts->modheight;
|
|
|
|
count = ts->modheight_count;
|
|
|
|
|
|
|
|
for(;;) {
|
|
|
|
if (count == 0) {
|
|
|
|
if (ts->modheight_count >= 576)
|
|
|
|
return false;
|
|
|
|
ts->modheight_count++;
|
|
|
|
break;
|
|
|
|
}
|
2005-06-27 06:57:24 +00:00
|
|
|
if (mod->tile == tile) break;
|
2004-08-09 17:04:08 +00:00
|
|
|
mod++;
|
|
|
|
count--;
|
|
|
|
}
|
|
|
|
|
2005-06-27 06:57:24 +00:00
|
|
|
mod->tile = tile;
|
2004-08-09 17:04:08 +00:00
|
|
|
mod->height = (byte)height;
|
|
|
|
|
|
|
|
ts->cost += _price.terraform;
|
|
|
|
|
|
|
|
{
|
|
|
|
int direction = ts->direction, r;
|
2005-01-06 11:39:00 +00:00
|
|
|
const TileIndexDiffC *ttm;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-06 11:39:00 +00:00
|
|
|
static const TileIndexDiffC _terraform_tilepos[] = {
|
|
|
|
{ 1, 0},
|
|
|
|
{-2, 0},
|
|
|
|
{ 1, 1},
|
|
|
|
{ 0, -2}
|
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-06 11:39:00 +00:00
|
|
|
for(ttm = _terraform_tilepos; ttm != endof(_terraform_tilepos); ttm++) {
|
|
|
|
tile += ToTileIndexDiff(*ttm);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
r = TerraformGetHeightOfTile(ts, tile);
|
|
|
|
if (r != height && r-direction != height && r+direction != height) {
|
|
|
|
if (!TerraformTileHeight(ts, tile, r+direction))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-05-07 10:26:12 +00:00
|
|
|
/** Terraform land
|
|
|
|
* @param x,y coordinates to terraform
|
2005-05-09 16:37:40 +00:00
|
|
|
* @param p1 corners to terraform.
|
2005-05-07 10:26:12 +00:00
|
|
|
* @param p2 direction; eg up or down
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
|
|
|
int32 CmdTerraformLand(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
|
|
|
{
|
|
|
|
TerraformerState ts;
|
2005-05-07 10:26:12 +00:00
|
|
|
TileIndex tile;
|
2004-08-09 17:04:08 +00:00
|
|
|
int direction;
|
|
|
|
|
|
|
|
TerraformerHeightMod modheight_data[576];
|
|
|
|
TileIndex tile_table_data[625];
|
|
|
|
|
|
|
|
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
|
|
|
|
|
|
|
|
_error_message = INVALID_STRING_ID;
|
|
|
|
_terraform_err_tile = 0;
|
|
|
|
|
|
|
|
ts.direction = direction = p2 ? 1 : -1;
|
|
|
|
ts.flags = flags;
|
|
|
|
ts.modheight_count = ts.tile_table_count = 0;
|
|
|
|
ts.cost = 0;
|
|
|
|
ts.modheight = modheight_data;
|
|
|
|
ts.tile_table = tile_table_data;
|
|
|
|
|
2005-06-25 06:15:43 +00:00
|
|
|
tile = TileVirtXY(x, y);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-05-30 15:50:20 +00:00
|
|
|
/* Make an extra check for map-bounds cause we add tiles to the originating tile */
|
2005-06-25 16:44:57 +00:00
|
|
|
if (tile + TileDiffXY(1, 1) > MapSize()) return CMD_ERROR;
|
2005-05-30 15:50:20 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (p1 & 1) {
|
2005-06-25 16:44:57 +00:00
|
|
|
if (!TerraformTileHeight(&ts, tile + TileDiffXY(1, 0),
|
|
|
|
TileHeight(tile + TileDiffXY(1, 0)) + direction))
|
2004-08-09 17:04:08 +00:00
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p1 & 2) {
|
2005-06-25 16:44:57 +00:00
|
|
|
if (!TerraformTileHeight(&ts, tile + TileDiffXY(1, 1),
|
|
|
|
TileHeight(tile + TileDiffXY(1, 1)) + direction))
|
2004-08-09 17:04:08 +00:00
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p1 & 4) {
|
2005-06-25 16:44:57 +00:00
|
|
|
if (!TerraformTileHeight(&ts, tile + TileDiffXY(0, 1),
|
|
|
|
TileHeight(tile + TileDiffXY(0, 1)) + direction))
|
2004-08-09 17:04:08 +00:00
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p1 & 8) {
|
2005-06-25 16:44:57 +00:00
|
|
|
if (!TerraformTileHeight(&ts, tile + TileDiffXY(0, 0),
|
|
|
|
TileHeight(tile + TileDiffXY(0, 0)) + direction))
|
2004-08-09 17:04:08 +00:00
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (direction == -1) {
|
|
|
|
/* Check if tunnel would take damage */
|
|
|
|
int count;
|
|
|
|
TileIndex *ti = ts.tile_table;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-05-07 10:26:12 +00:00
|
|
|
for (count = ts.tile_table_count; count != 0; count--, ti++) {
|
2004-08-09 17:04:08 +00:00
|
|
|
uint z, t;
|
2005-06-24 12:38:35 +00:00
|
|
|
TileIndex tile = *ti;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-06-25 16:44:57 +00:00
|
|
|
z = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 0));
|
|
|
|
t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 0));
|
2004-08-09 17:04:08 +00:00
|
|
|
if (t <= z) z = t;
|
2005-06-25 16:44:57 +00:00
|
|
|
t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 1));
|
2004-08-09 17:04:08 +00:00
|
|
|
if (t <= z) z = t;
|
2005-06-25 16:44:57 +00:00
|
|
|
t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 1));
|
2004-08-09 17:04:08 +00:00
|
|
|
if (t <= z) z = t;
|
|
|
|
|
|
|
|
if (!CheckTunnelInWay(tile, z*8))
|
|
|
|
return_cmd_error(STR_1002_EXCAVATION_WOULD_DAMAGE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
/* Clear the landscape at the tiles */
|
|
|
|
{
|
|
|
|
int count;
|
|
|
|
TileIndex *ti = ts.tile_table;
|
2005-05-07 10:26:12 +00:00
|
|
|
for (count = ts.tile_table_count; count != 0; count--, ti++) {
|
2004-08-09 17:04:08 +00:00
|
|
|
DoCommandByTile(*ti, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
/* change the height */
|
|
|
|
{
|
|
|
|
int count;
|
|
|
|
TerraformerHeightMod *mod;
|
|
|
|
|
|
|
|
mod = ts.modheight;
|
2005-05-07 10:26:12 +00:00
|
|
|
for (count = ts.modheight_count; count != 0; count--, mod++) {
|
2005-06-24 17:41:08 +00:00
|
|
|
TileIndex til = mod->tile;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-01-18 18:41:56 +00:00
|
|
|
SetTileHeight(til, mod->height);
|
2004-08-09 17:04:08 +00:00
|
|
|
TerraformAddDirtyTileAround(&ts, til);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* finally mark the dirty tiles dirty */
|
|
|
|
{
|
|
|
|
int count;
|
|
|
|
TileIndex *ti = ts.tile_table;
|
2005-05-07 10:26:12 +00:00
|
|
|
for (count = ts.tile_table_count; count != 0; count--, ti++) {
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkTileDirtyByTile(*ti);
|
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
return ts.cost;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-05-12 23:46:01 +00:00
|
|
|
/** Levels a selected (rectangle) area of land
|
|
|
|
* @param x,y end tile of area-drag
|
|
|
|
* @param p1 start tile of area drag
|
|
|
|
* @param p2 unused
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
|
|
|
int32 CmdLevelLand(int ex, int ey, uint32 flags, uint32 p1, uint32 p2)
|
|
|
|
{
|
|
|
|
int size_x, size_y;
|
|
|
|
int sx, sy;
|
|
|
|
uint h, curh;
|
2005-05-12 23:46:01 +00:00
|
|
|
TileIndex tile;
|
2004-08-09 17:04:08 +00:00
|
|
|
int32 ret, cost, money;
|
|
|
|
|
2005-05-12 23:46:01 +00:00
|
|
|
if (p1 > MapSize()) return CMD_ERROR;
|
|
|
|
|
2005-01-04 17:11:03 +00:00
|
|
|
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// remember level height
|
2005-01-16 14:50:01 +00:00
|
|
|
h = TileHeight(p1);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
ex >>= 4; ey >>= 4;
|
|
|
|
|
|
|
|
// make sure sx,sy are smaller than ex,ey
|
2005-01-07 17:02:43 +00:00
|
|
|
sx = TileX(p1);
|
|
|
|
sy = TileY(p1);
|
2004-08-09 17:04:08 +00:00
|
|
|
if (ex < sx) intswap(ex, sx);
|
|
|
|
if (ey < sy) intswap(ey, sy);
|
2005-06-25 16:44:57 +00:00
|
|
|
tile = TileXY(sx, sy);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
size_x = ex-sx+1;
|
|
|
|
size_y = ey-sy+1;
|
|
|
|
|
|
|
|
money = GetAvailableMoneyForCommand();
|
|
|
|
cost = 0;
|
|
|
|
|
2005-05-12 23:46:01 +00:00
|
|
|
BEGIN_TILE_LOOP(tile2, size_x, size_y, tile) {
|
2005-01-16 14:50:01 +00:00
|
|
|
curh = TileHeight(tile2);
|
2004-08-09 17:04:08 +00:00
|
|
|
while (curh != h) {
|
2005-05-12 23:46:01 +00:00
|
|
|
ret = DoCommandByTile(tile2, 8, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND);
|
|
|
|
if (CmdFailed(ret)) break;
|
2004-08-09 17:04:08 +00:00
|
|
|
cost += ret;
|
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
if ((money -= ret) < 0) {
|
|
|
|
_additional_cash_required = ret;
|
|
|
|
return cost - ret;
|
|
|
|
}
|
2005-05-12 23:46:01 +00:00
|
|
|
DoCommandByTile(tile2, 8, (curh > h) ? 0 : 1, flags, CMD_TERRAFORM_LAND);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
curh += (curh > h) ? -1 : 1;
|
|
|
|
}
|
2005-05-12 23:46:01 +00:00
|
|
|
} END_TILE_LOOP(tile2, size_x, size_y, tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-05-12 23:46:01 +00:00
|
|
|
return (cost == 0) ? CMD_ERROR : cost;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-05-09 16:37:40 +00:00
|
|
|
/** Purchase a land area. Actually you only purchase one tile, so
|
|
|
|
* the name is a bit confusing ;p
|
|
|
|
* @param x,y the tile the player is purchasing
|
|
|
|
* @param p1 unused
|
|
|
|
* @param p2 unused
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
|
|
|
int32 CmdPurchaseLandArea(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
|
|
|
{
|
2005-05-09 16:37:40 +00:00
|
|
|
TileIndex tile;
|
2004-08-09 17:04:08 +00:00
|
|
|
int32 cost;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-06-25 06:15:43 +00:00
|
|
|
tile = TileVirtXY(x, y);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-05-09 16:37:40 +00:00
|
|
|
if (!EnsureNoVehicle(tile)) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-13 18:04:01 +00:00
|
|
|
if (IsTileType(tile, MP_UNMOVABLE) && _m[tile].m5 == 3 &&
|
2005-06-04 11:56:32 +00:00
|
|
|
IsTileOwner(tile, _current_player))
|
2004-08-09 17:04:08 +00:00
|
|
|
return_cmd_error(STR_5807_YOU_ALREADY_OWN_IT);
|
|
|
|
|
|
|
|
cost = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
2005-05-09 16:37:40 +00:00
|
|
|
if (CmdFailed(cost)) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
ModifyTile(tile,
|
|
|
|
MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5,
|
|
|
|
3 /* map5 */
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return cost + _price.purchase_land * 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static int32 ClearTile_Clear(TileIndex tile, byte flags)
|
2005-01-22 22:47:58 +00:00
|
|
|
{
|
2005-07-28 19:18:27 +00:00
|
|
|
static const int32 null = 0;
|
|
|
|
static const int32* clear_price_table[] = {
|
|
|
|
&null,
|
|
|
|
&_price.clear_1,
|
|
|
|
&_price.clear_1,
|
|
|
|
&_price.clear_1,
|
|
|
|
&_price.purchase_land,
|
|
|
|
&_price.purchase_land,
|
|
|
|
&_price.purchase_land,
|
|
|
|
&_price.purchase_land,
|
|
|
|
&_price.clear_2,
|
|
|
|
&_price.clear_2,
|
|
|
|
&_price.clear_2,
|
|
|
|
&_price.clear_2,
|
|
|
|
&_price.clear_3,
|
|
|
|
&_price.clear_3,
|
|
|
|
&_price.clear_3,
|
|
|
|
&_price.clear_3,
|
|
|
|
&_price.purchase_land,
|
|
|
|
&_price.purchase_land,
|
|
|
|
&_price.purchase_land,
|
|
|
|
&_price.purchase_land,
|
|
|
|
&_price.purchase_land,
|
|
|
|
&_price.purchase_land,
|
|
|
|
&_price.purchase_land,
|
|
|
|
&_price.purchase_land,
|
|
|
|
&_price.clear_2,
|
|
|
|
&_price.clear_2,
|
|
|
|
&_price.clear_2,
|
|
|
|
&_price.clear_2,
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
2005-07-28 19:18:27 +00:00
|
|
|
const int32 *price = clear_price_table[GB(_m[tile].m5, 0, 5)];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-28 19:18:27 +00:00
|
|
|
if (flags & DC_EXEC) DoClearSquare(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
return *price;
|
|
|
|
}
|
|
|
|
|
2005-05-09 16:37:40 +00:00
|
|
|
/** Sell a land area. Actually you only sell one tile, so
|
|
|
|
* the name is a bit confusing ;p
|
|
|
|
* @param x,y the tile the player is selling
|
|
|
|
* @param p1 unused
|
|
|
|
* @param p2 unused
|
|
|
|
*/
|
2004-08-09 17:04:08 +00:00
|
|
|
int32 CmdSellLandArea(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
|
|
|
{
|
2005-05-09 16:37:40 +00:00
|
|
|
TileIndex tile;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
|
|
|
|
|
2005-06-25 06:15:43 +00:00
|
|
|
tile = TileVirtXY(x, y);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-13 18:04:01 +00:00
|
|
|
if (!IsTileType(tile, MP_UNMOVABLE) || _m[tile].m5 != 3) return CMD_ERROR;
|
2005-05-30 15:50:20 +00:00
|
|
|
if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER) return CMD_ERROR;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-05-09 16:37:40 +00:00
|
|
|
if (!EnsureNoVehicle(tile)) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (flags & DC_EXEC)
|
|
|
|
DoClearSquare(tile);
|
|
|
|
|
2005-05-09 16:37:40 +00:00
|
|
|
return - _price.purchase_land * 2;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#include "table/clear_land.h"
|
|
|
|
|
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
void DrawClearLandTile(const TileInfo *ti, byte set)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-10-15 11:06:54 +00:00
|
|
|
DrawGroundSprite(SPR_FLAT_BARE_LAND + _tileh_to_sprite[ti->tileh] + set * 19);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
void DrawHillyLandTile(const TileInfo *ti)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
if (ti->tileh != 0) {
|
2005-10-15 11:06:54 +00:00
|
|
|
DrawGroundSprite(SPR_FLAT_ROUGH_LAND + _tileh_to_sprite[ti->tileh]);
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2005-07-20 15:29:28 +00:00
|
|
|
DrawGroundSprite(_landscape_clear_sprites[GB(ti->x ^ ti->y, 4, 3)]);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-28 19:18:27 +00:00
|
|
|
void DrawClearLandFence(const TileInfo *ti)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-07-28 19:18:27 +00:00
|
|
|
byte m4 = _m[ti->tile].m4;
|
2004-08-09 17:04:08 +00:00
|
|
|
byte z = ti->z;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (ti->tileh & 2) {
|
|
|
|
z += 8;
|
|
|
|
if (ti->tileh == 0x17)
|
|
|
|
z += 8;
|
|
|
|
}
|
|
|
|
|
2005-07-28 19:18:27 +00:00
|
|
|
if (GB(m4, 5, 3) != 0) {
|
|
|
|
DrawGroundSpriteAt(_clear_land_fence_sprites_1[GB(m4, 5, 3) - 1] + _fence_mod_by_tileh[ti->tileh], ti->x, ti->y, z);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-07-28 19:18:27 +00:00
|
|
|
if (GB(m4, 2, 3) != 0) {
|
|
|
|
DrawGroundSpriteAt(_clear_land_fence_sprites_1[GB(m4, 2, 3) - 1] + _fence_mod_by_tileh_2[ti->tileh], ti->x, ti->y, z);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void DrawTile_Clear(TileInfo *ti)
|
|
|
|
{
|
2005-07-28 19:18:27 +00:00
|
|
|
switch (GB(ti->map5, 2, 3)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
case 0:
|
2005-07-28 19:18:27 +00:00
|
|
|
DrawClearLandTile(ti, GB(ti->map5, 0, 2));
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
DrawHillyLandTile(ti);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
2005-10-15 11:06:54 +00:00
|
|
|
DrawGroundSprite(SPR_FLAT_ROCKY_LAND_1 + _tileh_to_sprite[ti->tileh]);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
2005-07-28 19:18:27 +00:00
|
|
|
DrawGroundSprite(_clear_land_sprites_1[GB(_m[ti->tile].m3, 0, 4)] + _tileh_to_sprite[ti->tileh]);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
2005-07-28 19:18:27 +00:00
|
|
|
DrawGroundSprite(_clear_land_sprites_2[GB(ti->map5, 0, 2)] + _tileh_to_sprite[ti->tileh]);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 5:
|
2005-07-28 19:18:27 +00:00
|
|
|
DrawGroundSprite(_clear_land_sprites_3[GB(ti->map5, 0, 2)] + _tileh_to_sprite[ti->tileh]);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-07-28 19:18:27 +00:00
|
|
|
DrawClearLandFence(ti);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-10-19 14:49:46 +00:00
|
|
|
static uint GetSlopeZ_Clear(const TileInfo* ti)
|
2005-01-22 22:47:58 +00:00
|
|
|
{
|
|
|
|
return GetPartialZ(ti->x & 0xF, ti->y & 0xF, ti->tileh) + ti->z;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
static uint GetSlopeTileh_Clear(const TileInfo *ti)
|
2004-08-13 18:27:33 +00:00
|
|
|
{
|
|
|
|
return ti->tileh;
|
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void GetAcceptedCargo_Clear(TileIndex tile, AcceptedCargo ac)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2004-09-10 19:02:27 +00:00
|
|
|
/* unused */
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void AnimateTile_Clear(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
/* unused */
|
|
|
|
}
|
|
|
|
|
2005-02-04 20:17:15 +00:00
|
|
|
void TileLoopClearHelper(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-07-28 19:23:19 +00:00
|
|
|
byte self;
|
|
|
|
byte neighbour;
|
2005-02-04 20:17:15 +00:00
|
|
|
TileIndex dirty = INVALID_TILE;
|
|
|
|
|
|
|
|
switch (GetTileType(tile)) {
|
|
|
|
case MP_CLEAR:
|
2005-07-28 19:23:19 +00:00
|
|
|
self = (GB(_m[tile].m5, 0, 5) == 15);
|
2005-02-05 15:49:57 +00:00
|
|
|
break;
|
2005-02-04 20:17:15 +00:00
|
|
|
|
|
|
|
default:
|
2005-07-28 19:23:19 +00:00
|
|
|
self = 0;
|
2005-02-04 20:17:15 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-02-04 20:17:15 +00:00
|
|
|
switch (GetTileType(TILE_ADDXY(tile, 1, 0))) {
|
|
|
|
case MP_CLEAR:
|
2005-07-28 19:23:19 +00:00
|
|
|
neighbour = (GB(_m[TILE_ADDXY(tile, 1, 0)].m5, 0, 5) == 15);
|
2005-02-04 20:17:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2005-07-28 19:23:19 +00:00
|
|
|
neighbour = 0;
|
2005-02-04 20:17:15 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-07-28 19:23:19 +00:00
|
|
|
if (GB(_m[tile].m4, 5, 3) == 0) {
|
|
|
|
if (self != neighbour) {
|
|
|
|
SB(_m[tile].m4, 5, 3, 3);
|
2004-08-09 17:04:08 +00:00
|
|
|
dirty = tile;
|
2004-09-10 19:02:27 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2005-07-28 19:23:19 +00:00
|
|
|
if (self == 0 && neighbour == 0) {
|
|
|
|
SB(_m[tile].m4, 5, 3, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
dirty = tile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-04 20:17:15 +00:00
|
|
|
switch (GetTileType(TILE_ADDXY(tile, 0, 1))) {
|
|
|
|
case MP_CLEAR:
|
2005-07-28 19:23:19 +00:00
|
|
|
neighbour = (GB(_m[TILE_ADDXY(tile, 0, 1)].m5, 0, 5) == 15);
|
2005-02-04 20:17:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2005-07-28 19:23:19 +00:00
|
|
|
neighbour = 0;
|
2005-02-04 20:17:15 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-07-28 19:23:19 +00:00
|
|
|
if (GB(_m[tile].m4, 2, 3) == 0) {
|
|
|
|
if (self != neighbour) {
|
|
|
|
SB(_m[tile].m4, 2, 3, 3);
|
2004-08-09 17:04:08 +00:00
|
|
|
dirty = tile;
|
2004-09-10 19:02:27 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2005-07-28 19:23:19 +00:00
|
|
|
if (self == 0 && neighbour == 0) {
|
|
|
|
SB(_m[tile].m4, 2, 3, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
dirty = tile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-28 19:23:19 +00:00
|
|
|
if (dirty != INVALID_TILE) MarkTileDirtyByTile(dirty);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* convert into snowy tiles */
|
2005-06-24 12:38:35 +00:00
|
|
|
static void TileLoopClearAlps(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
int k;
|
|
|
|
byte m5,tmp;
|
|
|
|
|
|
|
|
/* distance from snow line, in steps of 8 */
|
|
|
|
k = GetTileZ(tile) - _opt.snow_line;
|
|
|
|
|
2005-07-13 18:04:01 +00:00
|
|
|
m5 = _m[tile].m5 & 0x1C;
|
|
|
|
tmp = _m[tile].m5 & 3;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (k < -8) {
|
|
|
|
/* snow_m2_down */
|
|
|
|
if (m5 != 0x10)
|
|
|
|
return;
|
|
|
|
if (tmp == 0)
|
|
|
|
m5 = 3;
|
|
|
|
} else if (k == -8) {
|
|
|
|
/* snow_m1 */
|
|
|
|
if (m5 != 0x10) {
|
|
|
|
m5 = 0x10;
|
|
|
|
} else if (tmp != 0) {
|
|
|
|
m5 = (tmp - 1) + 0x10;
|
|
|
|
} else
|
|
|
|
return;
|
|
|
|
} else if (k < 8) {
|
|
|
|
/* snow_0 */
|
|
|
|
if (m5 != 0x10) {
|
|
|
|
m5 = 0x10;
|
|
|
|
} else if (tmp != 1) {
|
|
|
|
m5 = 1;
|
|
|
|
if (tmp != 0)
|
|
|
|
m5 = tmp - 1;
|
|
|
|
m5 += 0x10;
|
|
|
|
} else
|
|
|
|
return;
|
|
|
|
} else if (k == 8) {
|
|
|
|
/* snow_p1 */
|
|
|
|
if (m5 != 0x10) {
|
|
|
|
m5 = 0x10;
|
|
|
|
} else if (tmp != 2) {
|
|
|
|
m5 = 2;
|
|
|
|
if (tmp <= 2)
|
|
|
|
m5 = tmp + 1;
|
|
|
|
m5 += 0x10;
|
|
|
|
} else
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
/* snow_p2_up */
|
|
|
|
if (m5 != 0x10) {
|
|
|
|
m5 = 0x10;
|
|
|
|
} else if (tmp != 3) {
|
|
|
|
m5 = tmp + 1 + 0x10;
|
|
|
|
} else
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-07-13 18:04:01 +00:00
|
|
|
_m[tile].m5 = m5;
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void TileLoopClearDesert(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-07-13 18:04:01 +00:00
|
|
|
if ( (_m[tile].m5 & 0x1C) == 0x14)
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (GetMapExtraBits(tile) == 1) {
|
2005-07-13 18:04:01 +00:00
|
|
|
_m[tile].m5 = 0x17;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2005-06-25 16:44:57 +00:00
|
|
|
if (GetMapExtraBits(tile + TileDiffXY( 1, 0)) != 1 &&
|
|
|
|
GetMapExtraBits(tile + TileDiffXY(-1, 0)) != 1 &&
|
|
|
|
GetMapExtraBits(tile + TileDiffXY( 0, 1)) != 1 &&
|
|
|
|
GetMapExtraBits(tile + TileDiffXY( 0, -1)) != 1)
|
|
|
|
return;
|
2005-07-13 18:04:01 +00:00
|
|
|
_m[tile].m5 = 0x15;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void TileLoop_Clear(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
byte m5,m3;
|
|
|
|
|
|
|
|
TileLoopClearHelper(tile);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (_opt.landscape == LT_DESERT) {
|
|
|
|
TileLoopClearDesert(tile);
|
|
|
|
} else if (_opt.landscape == LT_HILLY) {
|
|
|
|
TileLoopClearAlps(tile);
|
|
|
|
}
|
|
|
|
|
2005-07-13 18:04:01 +00:00
|
|
|
m5 = _m[tile].m5;
|
2004-08-09 17:04:08 +00:00
|
|
|
if ( (m5 & 0x1C) == 0x10 || (m5 & 0x1C) == 0x14)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( (m5 & 0x1C) != 0xC) {
|
|
|
|
if ( (m5 & 3) == 3)
|
|
|
|
return;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (_game_mode != GM_EDITOR) {
|
|
|
|
m5 += 0x20;
|
|
|
|
if (m5 >= 0x20) {
|
|
|
|
// Didn't overflow
|
2005-07-13 18:04:01 +00:00
|
|
|
_m[tile].m5 = m5;
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* did overflow, so continue */
|
|
|
|
} else {
|
2005-07-21 06:31:02 +00:00
|
|
|
m5 = (GB(Random(), 0, 8) > 21) ? 2 : 6;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
m5++;
|
|
|
|
} else if (_game_mode != GM_EDITOR) {
|
|
|
|
/* handle farm field */
|
|
|
|
m5 += 0x20;
|
|
|
|
if (m5 >= 0x20) {
|
|
|
|
// Didn't overflow
|
2005-07-13 18:04:01 +00:00
|
|
|
_m[tile].m5 = m5;
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* overflowed */
|
2005-07-13 18:04:01 +00:00
|
|
|
m3 = _m[tile].m3 + 1;
|
2004-08-09 17:04:08 +00:00
|
|
|
assert( (m3 & 0xF) != 0);
|
|
|
|
if ( (m3 & 0xF) >= 9) /* NOTE: will not work properly if m3&0xF == 0xF */
|
|
|
|
m3 &= ~0xF;
|
2005-07-13 18:04:01 +00:00
|
|
|
_m[tile].m3 = m3;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
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 GenerateClearTile(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-07-21 06:31:02 +00:00
|
|
|
uint i;
|
2005-06-24 12:38:35 +00:00
|
|
|
TileIndex tile;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
/* add hills */
|
2005-01-28 15:31:04 +00:00
|
|
|
i = ScaleByMapSize((Random() & 0x3FF) + 0x400);
|
2004-08-09 17:04:08 +00:00
|
|
|
do {
|
2005-07-13 19:51:31 +00:00
|
|
|
tile = RandomTile();
|
2005-07-21 06:31:02 +00:00
|
|
|
if (IsTileType(tile, MP_CLEAR)) SB(_m[tile].m5, 2, 2, 1);
|
2004-08-09 17:04:08 +00:00
|
|
|
} while (--i);
|
|
|
|
|
|
|
|
/* add grey squares */
|
2005-01-28 15:31:04 +00:00
|
|
|
i = ScaleByMapSize((Random() & 0x7F) + 0x80);
|
2004-08-09 17:04:08 +00:00
|
|
|
do {
|
2005-07-21 06:31:02 +00:00
|
|
|
uint32 r = Random();
|
2005-07-13 19:51:31 +00:00
|
|
|
tile = RandomTileSeed(r);
|
2005-01-16 11:24:58 +00:00
|
|
|
if (IsTileType(tile, MP_CLEAR)) {
|
2005-07-21 06:31:02 +00:00
|
|
|
uint j = GB(r, 16, 4) + 5;
|
2004-08-09 17:04:08 +00:00
|
|
|
for(;;) {
|
2005-06-24 12:38:35 +00:00
|
|
|
TileIndex tile_new;
|
|
|
|
|
2005-07-21 06:31:02 +00:00
|
|
|
SB(_m[tile].m5, 2, 2, 2);
|
2004-08-09 17:04:08 +00:00
|
|
|
do {
|
|
|
|
if (--j == 0) goto get_out;
|
2005-01-05 13:32:03 +00:00
|
|
|
tile_new = tile + TileOffsByDir(Random() & 3);
|
2005-01-16 11:24:58 +00:00
|
|
|
} while (!IsTileType(tile_new, MP_CLEAR));
|
2004-08-09 17:04:08 +00:00
|
|
|
tile = tile_new;
|
|
|
|
}
|
|
|
|
get_out:;
|
|
|
|
}
|
|
|
|
} while (--i);
|
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void ClickTile_Clear(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
/* not used */
|
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static uint32 GetTileTrackStatus_Clear(TileIndex tile, TransportType mode)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-07-28 19:18:27 +00:00
|
|
|
static const StringID _clear_land_str[] = {
|
2004-08-09 17:04:08 +00:00
|
|
|
STR_080B_ROUGH_LAND,
|
|
|
|
STR_080A_ROCKS,
|
|
|
|
STR_080E_FIELDS,
|
|
|
|
STR_080F_SNOW_COVERED_LAND,
|
|
|
|
STR_0810_DESERT,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
STR_080C_BARE_LAND,
|
|
|
|
STR_080D_GRASS,
|
|
|
|
STR_080D_GRASS,
|
|
|
|
STR_080D_GRASS,
|
|
|
|
};
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void GetTileDesc_Clear(TileIndex tile, TileDesc *td)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-07-28 19:18:27 +00:00
|
|
|
uint i = GB(_m[tile].m5, 2, 3);
|
|
|
|
if (i == 0) i = GB(_m[tile].m5, 0, 2) + 8;
|
2004-08-09 17:04:08 +00:00
|
|
|
td->str = _clear_land_str[i - 1];
|
2005-06-04 11:56:32 +00:00
|
|
|
td->owner = GetTileOwner(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
static void ChangeTileOwner_Clear(TileIndex tile, PlayerID old_player, PlayerID new_player)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void InitializeClearLand(void)
|
|
|
|
{
|
2004-08-09 17:04:08 +00:00
|
|
|
_opt.snow_line = _patches.snow_line_height * 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
const TileTypeProcs _tile_type_clear_procs = {
|
|
|
|
DrawTile_Clear, /* draw_tile_proc */
|
|
|
|
GetSlopeZ_Clear, /* get_slope_z_proc */
|
|
|
|
ClearTile_Clear, /* clear_tile_proc */
|
|
|
|
GetAcceptedCargo_Clear, /* get_accepted_cargo_proc */
|
|
|
|
GetTileDesc_Clear, /* get_tile_desc_proc */
|
|
|
|
GetTileTrackStatus_Clear, /* get_tile_track_status_proc */
|
|
|
|
ClickTile_Clear, /* click_tile_proc */
|
|
|
|
AnimateTile_Clear, /* animate_tile_proc */
|
|
|
|
TileLoop_Clear, /* tile_loop_clear */
|
|
|
|
ChangeTileOwner_Clear, /* 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_Clear, /* get_slope_tileh_proc */
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|