2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2007-02-23 11:50:43 +00:00
|
|
|
/** @file clear_cmd.cpp */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2006-03-05 10:19:33 +00:00
|
|
|
#include "clear_map.h"
|
2006-06-18 15:28:29 +00:00
|
|
|
#include "rail_map.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"
|
2006-03-07 07:51:05 +00:00
|
|
|
#include "tunnel_map.h"
|
2006-12-27 12:38:02 +00:00
|
|
|
#include "bridge_map.h"
|
2007-02-26 18:25:03 +00:00
|
|
|
#include "bridge.h"
|
2007-03-20 13:47:00 +00:00
|
|
|
#include "landscape.h"
|
2005-07-21 18:44:27 +00:00
|
|
|
#include "variables.h"
|
2005-10-15 11:06:54 +00:00
|
|
|
#include "table/sprites.h"
|
2006-03-23 20:47:56 +00:00
|
|
|
#include "unmovable_map.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"
|
2006-08-20 18:44:26 +00:00
|
|
|
#include "industry.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
struct TerraformerHeightMod {
|
2004-08-09 17:04:08 +00:00
|
|
|
TileIndex tile;
|
|
|
|
byte height;
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
struct TerraformerState {
|
2004-08-09 17:04:08 +00:00
|
|
|
int height[4];
|
|
|
|
uint32 flags;
|
|
|
|
|
|
|
|
int direction;
|
|
|
|
int modheight_count;
|
|
|
|
int tile_table_count;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost cost;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
TileIndex *tile_table;
|
|
|
|
TerraformerHeightMod *modheight;
|
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
static int TerraformAllowTileProcess(TerraformerState *ts, TileIndex tile)
|
|
|
|
{
|
|
|
|
TileIndex *t;
|
|
|
|
int count;
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) return -1;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
t = ts->tile_table;
|
2005-11-14 19:48:04 +00:00
|
|
|
for (count = ts->tile_table_count; count != 0; count--, t++) {
|
|
|
|
if (*t == tile) return 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int TerraformGetHeightOfTile(TerraformerState *ts, TileIndex tile)
|
|
|
|
{
|
|
|
|
TerraformerHeightMod *mod = ts->modheight;
|
|
|
|
int count;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
for (count = ts->modheight_count; count != 0; count--, mod++) {
|
|
|
|
if (mod->tile == tile) return mod->height;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (count >= 625) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-18 22:10:36 +00:00
|
|
|
for (t = ts->tile_table; count != 0; count--, t++) {
|
2005-11-14 19:48:04 +00:00
|
|
|
if (*t == tile) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2006-06-25 17:39:19 +00:00
|
|
|
static int TerraformProc(TerraformerState *ts, TileIndex tile, int mode)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
int r;
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost ret;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-03 18:59:58 +00:00
|
|
|
assert(tile < MapSize());
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2006-06-25 17:51:23 +00:00
|
|
|
r = TerraformAllowTileProcess(ts, tile);
|
|
|
|
if (r <= 0) return r;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2006-06-25 17:39:19 +00:00
|
|
|
if (IsTileType(tile, MP_RAILWAY)) {
|
2006-06-25 17:51:23 +00:00
|
|
|
static const TrackBits safe_track[] = { TRACK_BIT_LOWER, TRACK_BIT_LEFT, TRACK_BIT_UPPER, TRACK_BIT_RIGHT };
|
|
|
|
static const Slope unsafe_slope[] = { SLOPE_S, SLOPE_W, SLOPE_N, SLOPE_E };
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-06-25 18:58:45 +00:00
|
|
|
Slope tileh;
|
|
|
|
uint z;
|
|
|
|
|
2007-02-23 11:50:43 +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
|
|
|
|
* basement and then you raise/lower the other corner. */
|
2006-06-25 18:58:45 +00:00
|
|
|
tileh = GetTileSlope(tile, &z);
|
2006-06-25 17:51:23 +00:00
|
|
|
if (tileh == unsafe_slope[mode] ||
|
|
|
|
tileh == ComplementSlope(unsafe_slope[mode])) {
|
2005-11-22 22:30:35 +00:00
|
|
|
_terraform_err_tile = tile;
|
2006-06-25 17:39:19 +00:00
|
|
|
_error_message = STR_1008_MUST_REMOVE_RAILROAD_TRACK;
|
2005-11-22 22:30:35 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-02-23 11:50:43 +00:00
|
|
|
/* If we have a single diagonal track there, the other side of
|
|
|
|
* tile can be terraformed. */
|
2006-06-25 17:51:23 +00:00
|
|
|
if (IsPlainRailTile(tile) && GetTrackBits(tile) == safe_track[mode]) {
|
2006-06-25 18:58:45 +00:00
|
|
|
/* If terraforming downwards prevent damaging a potential tunnel below.
|
|
|
|
* This check is only necessary for flat tiles, because if the tile is
|
|
|
|
* non-flat, then the corner opposing the rail is raised. Only this corner
|
|
|
|
* can be lowered and this is a safe action
|
|
|
|
*/
|
|
|
|
if (tileh == SLOPE_FLAT &&
|
|
|
|
ts->direction == -1 &&
|
|
|
|
IsTunnelInWay(tile, z - TILE_HEIGHT)) {
|
|
|
|
_terraform_err_tile = tile;
|
|
|
|
_error_message = STR_1002_EXCAVATION_WOULD_DAMAGE;
|
|
|
|
return -1;
|
|
|
|
}
|
2006-06-25 17:39:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-18 22:10:36 +00:00
|
|
|
ret = DoCommand(tile, 0, 0, ts->flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
2006-06-25 17:39:19 +00:00
|
|
|
|
2006-09-05 23:43:42 +00:00
|
|
|
if (CmdFailed(ret)) {
|
2006-06-25 17:39:19 +00:00
|
|
|
_terraform_err_tile = tile;
|
|
|
|
return -1;
|
2005-11-22 22:30:35 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-06-18 19:53:50 +00:00
|
|
|
ts->cost.AddCost(ret.GetCost());
|
2006-06-25 17:39:19 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (ts->tile_table_count >= 625) return -1;
|
2004-08-09 17:04:08 +00:00
|
|
|
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;
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (height > 15) return false;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
nh = TerraformGetHeightOfTile(ts, tile);
|
2005-11-14 19:48:04 +00:00
|
|
|
if (nh < 0 || height == nh) return false;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2006-06-25 17:39:19 +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;
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
for (;;) {
|
2004-08-09 17:04:08 +00:00
|
|
|
if (count == 0) {
|
2006-06-10 08:37:41 +00:00
|
|
|
if (ts->modheight_count >= 576) return false;
|
2004-08-09 17:04:08 +00:00
|
|
|
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;
|
|
|
|
|
2007-06-18 19:53:50 +00:00
|
|
|
ts->cost.AddCost(_price.terraform);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2006-02-01 07:36:15 +00:00
|
|
|
for (ttm = _terraform_tilepos; ttm != endof(_terraform_tilepos); ttm++) {
|
2005-01-06 11:39:00 +00:00
|
|
|
tile += ToTileIndexDiff(*ttm);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
r = TerraformGetHeightOfTile(ts, tile);
|
2007-04-18 22:10:36 +00:00
|
|
|
if (r != height && r - direction != height && r + direction != height) {
|
|
|
|
if (!TerraformTileHeight(ts, tile, r + direction))
|
2004-08-09 17:04:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-05-07 10:26:12 +00:00
|
|
|
/** Terraform land
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile tile to terraform
|
2007-02-23 11:50:43 +00:00
|
|
|
* @param flags for this command type
|
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
|
2007-02-23 11:50:43 +00:00
|
|
|
* @return error or cost of terraforming
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost CmdTerraformLand(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
TerraformerState ts;
|
2006-06-10 08:37:41 +00:00
|
|
|
TileIndex t;
|
2004-08-09 17:04:08 +00:00
|
|
|
int direction;
|
|
|
|
|
|
|
|
TerraformerHeightMod modheight_data[576];
|
|
|
|
TileIndex tile_table_data[625];
|
|
|
|
|
|
|
|
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
|
|
|
|
|
|
|
|
_terraform_err_tile = 0;
|
|
|
|
|
|
|
|
ts.direction = direction = p2 ? 1 : -1;
|
|
|
|
ts.flags = flags;
|
|
|
|
ts.modheight_count = ts.tile_table_count = 0;
|
2007-06-18 19:53:50 +00:00
|
|
|
ts.cost = CommandCost();
|
2004-08-09 17:04:08 +00:00
|
|
|
ts.modheight = modheight_data;
|
|
|
|
ts.tile_table = tile_table_data;
|
|
|
|
|
2005-05-30 15:50:20 +00:00
|
|
|
/* Make an extra check for map-bounds cause we add tiles to the originating tile */
|
2006-01-30 17:18:45 +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) {
|
2006-06-10 08:37:41 +00:00
|
|
|
t = tile + TileDiffXY(1, 0);
|
|
|
|
if (!TerraformTileHeight(&ts, t, TileHeight(t) + direction)) {
|
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (p1 & 2) {
|
2006-06-10 08:37:41 +00:00
|
|
|
t = tile + TileDiffXY(1, 1);
|
|
|
|
if (!TerraformTileHeight(&ts, t, TileHeight(t) + direction)) {
|
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (p1 & 4) {
|
2006-06-10 08:37:41 +00:00
|
|
|
t = tile + TileDiffXY(0, 1);
|
|
|
|
if (!TerraformTileHeight(&ts, t, TileHeight(t) + direction)) {
|
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (p1 & 8) {
|
2006-06-10 08:37:41 +00:00
|
|
|
t = tile + TileDiffXY(0, 0);
|
|
|
|
if (!TerraformTileHeight(&ts, t, TileHeight(t) + direction)) {
|
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
{
|
2006-06-25 17:39:19 +00:00
|
|
|
/* Check if tunnel would take damage */
|
2004-08-09 17:04:08 +00:00
|
|
|
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++) {
|
2005-06-24 12:38:35 +00:00
|
|
|
TileIndex tile = *ti;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-05-26 23:23:22 +00:00
|
|
|
uint z_min = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 0));
|
|
|
|
uint z_max = z_min;
|
|
|
|
uint t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 0));
|
|
|
|
z_min = min(z_min, t);
|
|
|
|
z_max = max(z_max, t);
|
|
|
|
t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 1));
|
|
|
|
z_min = min(z_min, t);
|
|
|
|
z_max = max(z_max, t);
|
|
|
|
t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 1));
|
|
|
|
z_min = min(z_min, t);
|
|
|
|
z_max = max(z_max, t);
|
|
|
|
|
|
|
|
if (direction == 1 && MayHaveBridgeAbove(tile) && IsBridgeAbove(tile) &&
|
|
|
|
GetBridgeHeight(GetSouthernBridgeEnd(tile)) <= z_max * TILE_HEIGHT) {
|
2006-12-27 12:38:02 +00:00
|
|
|
return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
|
|
|
|
}
|
2007-05-26 23:23:22 +00:00
|
|
|
if (direction == -1 && IsTunnelInWay(tile, z_min * TILE_HEIGHT)) {
|
|
|
|
return_cmd_error(STR_1002_EXCAVATION_WOULD_DAMAGE);
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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++) {
|
2006-04-10 07:15:58 +00:00
|
|
|
DoCommand(*ti, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
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
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile end tile of area-drag
|
2007-02-23 11:50:43 +00:00
|
|
|
* @param flags for this command type
|
2005-05-12 23:46:01 +00:00
|
|
|
* @param p1 start tile of area drag
|
|
|
|
* @param p2 unused
|
2007-02-23 11:50:43 +00:00
|
|
|
* @return error or cost of terraforming
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost CmdLevelLand(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
int size_x, size_y;
|
2006-04-10 07:15:58 +00:00
|
|
|
int ex;
|
|
|
|
int ey;
|
2004-08-09 17:04:08 +00:00
|
|
|
int sx, sy;
|
|
|
|
uint h, curh;
|
2007-06-18 19:53:50 +00:00
|
|
|
CommandCost money;
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost ret;
|
|
|
|
CommandCost cost;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-01-30 17:18:45 +00:00
|
|
|
if (p1 >= MapSize()) return CMD_ERROR;
|
2005-05-12 23:46:01 +00:00
|
|
|
|
2005-01-04 17:11:03 +00:00
|
|
|
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
|
|
|
|
|
2007-02-23 11:50:43 +00:00
|
|
|
/* remember level height */
|
2005-01-16 14:50:01 +00:00
|
|
|
h = TileHeight(p1);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-02-23 11:50:43 +00:00
|
|
|
/* make sure sx,sy are smaller than ex,ey */
|
2006-04-10 07:15:58 +00:00
|
|
|
ex = TileX(tile);
|
|
|
|
ey = TileY(tile);
|
2005-01-07 17:02:43 +00:00
|
|
|
sx = TileX(p1);
|
|
|
|
sy = TileY(p1);
|
2007-02-22 08:43:02 +00:00
|
|
|
if (ex < sx) Swap(ex, sx);
|
|
|
|
if (ey < sy) Swap(ey, sy);
|
2005-06-25 16:44:57 +00:00
|
|
|
tile = TileXY(sx, sy);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-18 22:10:36 +00:00
|
|
|
size_x = ex - sx + 1;
|
|
|
|
size_y = ey - sy + 1;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-06-18 19:53:50 +00:00
|
|
|
money.AddCost(GetAvailableMoneyForCommand());
|
2004-08-09 17:04:08 +00:00
|
|
|
|
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) {
|
2006-04-10 07:15:58 +00:00
|
|
|
ret = DoCommand(tile2, 8, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND);
|
2005-05-12 23:46:01 +00:00
|
|
|
if (CmdFailed(ret)) break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
2007-06-18 19:53:50 +00:00
|
|
|
money.AddCost(-ret.GetCost());
|
|
|
|
if (money.GetCost() < 0) {
|
|
|
|
_additional_cash_required = ret.GetCost();
|
|
|
|
return cost;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2006-04-10 07:15:58 +00:00
|
|
|
DoCommand(tile2, 8, (curh > h) ? 0 : 1, flags, CMD_TERRAFORM_LAND);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 19:53:50 +00:00
|
|
|
cost.AddCost(ret);
|
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
|
|
|
|
2007-06-18 19:53:50 +00:00
|
|
|
return (cost.GetCost() == 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
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile the tile the player is purchasing
|
2007-02-23 11:50:43 +00:00
|
|
|
* @param flags for this command type
|
2005-05-09 16:37:40 +00:00
|
|
|
* @param p1 unused
|
|
|
|
* @param p2 unused
|
2007-02-23 11:50:43 +00:00
|
|
|
* @return error of cost of operation
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost CmdPurchaseLandArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost 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-05-09 16:37:40 +00:00
|
|
|
if (!EnsureNoVehicle(tile)) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-23 20:47:56 +00:00
|
|
|
if (IsOwnedLandTile(tile) && IsTileOwner(tile, _current_player)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
return_cmd_error(STR_5807_YOU_ALREADY_OWN_IT);
|
2006-03-23 20:47:56 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-10 07:15:58 +00:00
|
|
|
cost = DoCommand(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) {
|
2006-03-23 20:47:56 +00:00
|
|
|
MakeOwnedLand(tile, _current_player);
|
|
|
|
MarkTileDirtyByTile(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 19:53:50 +00:00
|
|
|
return cost.AddCost(_price.purchase_land * 10);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-06-18 10:48:15 +00:00
|
|
|
static CommandCost ClearTile_Clear(TileIndex tile, byte flags)
|
2005-01-22 22:47:58 +00:00
|
|
|
{
|
2007-06-18 21:44:47 +00:00
|
|
|
static const Money* clear_price_table[] = {
|
2005-07-28 19:18:27 +00:00
|
|
|
&_price.clear_1,
|
|
|
|
&_price.purchase_land,
|
|
|
|
&_price.clear_2,
|
|
|
|
&_price.clear_3,
|
|
|
|
&_price.purchase_land,
|
|
|
|
&_price.purchase_land,
|
2006-02-01 15:31:21 +00:00
|
|
|
&_price.clear_2, // XXX unused?
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost price;
|
2006-02-01 15:31:21 +00:00
|
|
|
|
2007-06-18 19:53:50 +00:00
|
|
|
if (!IsClearGround(tile, CLEAR_GRASS) || GetClearDensity(tile) != 0) {
|
|
|
|
price.AddCost(*clear_price_table[GetClearGround(tile)]);
|
2006-02-01 15:31:21 +00:00
|
|
|
}
|
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
|
|
|
|
2006-02-01 15:31:21 +00:00
|
|
|
return price;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
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
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile the tile the player is selling
|
2007-02-23 11:50:43 +00:00
|
|
|
* @param flags for this command type
|
2005-05-09 16:37:40 +00:00
|
|
|
* @param p1 unused
|
|
|
|
* @param p2 unused
|
2007-02-23 11:50:43 +00:00
|
|
|
* @return error or cost of operation
|
2005-05-09 16:37:40 +00:00
|
|
|
*/
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost CmdSellLandArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
|
|
|
|
|
2006-03-23 20:47:56 +00:00
|
|
|
if (!IsOwnedLandTile(tile)) 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
|
|
|
|
2006-06-10 08:37:41 +00:00
|
|
|
if (flags & DC_EXEC) DoClearSquare(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-06-18 19:53:50 +00:00
|
|
|
return CommandCost(- _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
|
|
|
{
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawGroundSprite(SPR_FLAT_BARE_LAND + _tileh_to_sprite[ti->tileh] + set * 19, PAL_NONE);
|
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
|
|
|
{
|
2006-04-23 13:48:16 +00:00
|
|
|
if (ti->tileh != SLOPE_FLAT) {
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawGroundSprite(SPR_FLAT_ROUGH_LAND + _tileh_to_sprite[ti->tileh], PAL_NONE);
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawGroundSprite(_landscape_clear_sprites[GB(ti->x ^ ti->y, 4, 3)], PAL_NONE);
|
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
|
|
|
{
|
|
|
|
byte z = ti->z;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
if (ti->tileh & SLOPE_S) {
|
2006-04-23 19:35:36 +00:00
|
|
|
z += TILE_HEIGHT;
|
|
|
|
if (ti->tileh == SLOPE_STEEP_S) z += TILE_HEIGHT;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-02-05 11:54:25 +00:00
|
|
|
if (GetFenceSW(ti->tile) != 0) {
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawGroundSpriteAt(_clear_land_fence_sprites_1[GetFenceSW(ti->tile) - 1] + _fence_mod_by_tileh[ti->tileh], PAL_NONE, ti->x, ti->y, z);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-02-05 11:54:25 +00:00
|
|
|
if (GetFenceSE(ti->tile) != 0) {
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawGroundSpriteAt(_clear_land_fence_sprites_1[GetFenceSE(ti->tile) - 1] + _fence_mod_by_tileh_2[ti->tileh], PAL_NONE, ti->x, ti->y, z);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void DrawTile_Clear(TileInfo *ti)
|
|
|
|
{
|
2006-03-08 15:28:38 +00:00
|
|
|
switch (GetClearGround(ti->tile)) {
|
2006-04-04 21:35:13 +00:00
|
|
|
case CLEAR_GRASS:
|
2006-03-08 15:28:38 +00:00
|
|
|
DrawClearLandTile(ti, GetClearDensity(ti->tile));
|
2006-02-01 15:31:21 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-04 21:35:13 +00:00
|
|
|
case CLEAR_ROUGH:
|
2006-02-01 15:31:21 +00:00
|
|
|
DrawHillyLandTile(ti);
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-04 21:35:13 +00:00
|
|
|
case CLEAR_ROCKS:
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawGroundSprite(SPR_FLAT_ROCKY_LAND_1 + _tileh_to_sprite[ti->tileh], PAL_NONE);
|
2006-02-01 15:31:21 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-04 21:35:13 +00:00
|
|
|
case CLEAR_FIELDS:
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawGroundSprite(_clear_land_sprites_1[GetFieldType(ti->tile)] + _tileh_to_sprite[ti->tileh], PAL_NONE);
|
2006-02-01 15:31:21 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-04 21:35:13 +00:00
|
|
|
case CLEAR_SNOW:
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawGroundSprite(_clear_land_sprites_2[GetClearDensity(ti->tile)] + _tileh_to_sprite[ti->tileh], PAL_NONE);
|
2006-02-01 15:31:21 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-04 21:35:13 +00:00
|
|
|
case CLEAR_DESERT:
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawGroundSprite(_clear_land_sprites_3[GetClearDensity(ti->tile)] + _tileh_to_sprite[ti->tileh], PAL_NONE);
|
2006-02-01 15:31:21 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-07-28 19:18:27 +00:00
|
|
|
DrawClearLandFence(ti);
|
2006-12-27 12:38:02 +00:00
|
|
|
DrawBridgeMiddle(ti);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-08-06 16:32:49 +00:00
|
|
|
static uint GetSlopeZ_Clear(TileIndex tile, uint x, uint y)
|
2005-01-22 22:47:58 +00:00
|
|
|
{
|
2006-08-06 16:32:49 +00:00
|
|
|
uint z;
|
2007-01-10 18:56:51 +00:00
|
|
|
Slope tileh = GetTileSlope(tile, &z);
|
2006-08-06 16:32:49 +00:00
|
|
|
|
|
|
|
return z + GetPartialZ(x & 0xF, y & 0xF, tileh);
|
2005-01-22 22:47:58 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
static Slope GetSlopeTileh_Clear(TileIndex tile, Slope tileh)
|
2004-08-13 18:27:33 +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 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;
|
|
|
|
|
2006-04-04 21:35:13 +00:00
|
|
|
self = (IsTileType(tile, MP_CLEAR) && IsClearGround(tile, CLEAR_FIELDS));
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-04 21:35:13 +00:00
|
|
|
neighbour = (IsTileType(TILE_ADDXY(tile, 1, 0), MP_CLEAR) && IsClearGround(TILE_ADDXY(tile, 1, 0), CLEAR_FIELDS));
|
2006-02-05 11:54:25 +00:00
|
|
|
if (GetFenceSW(tile) == 0) {
|
2005-07-28 19:23:19 +00:00
|
|
|
if (self != neighbour) {
|
2006-02-05 11:54:25 +00:00
|
|
|
SetFenceSW(tile, 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) {
|
2006-02-05 11:54:25 +00:00
|
|
|
SetFenceSW(tile, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
dirty = tile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-04 21:35:13 +00:00
|
|
|
neighbour = (IsTileType(TILE_ADDXY(tile, 0, 1), MP_CLEAR) && IsClearGround(TILE_ADDXY(tile, 0, 1), CLEAR_FIELDS));
|
2006-02-05 11:54:25 +00:00
|
|
|
if (GetFenceSE(tile) == 0) {
|
2005-07-28 19:23:19 +00:00
|
|
|
if (self != neighbour) {
|
2006-02-05 11:54:25 +00:00
|
|
|
SetFenceSE(tile, 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) {
|
2006-02-05 11:54:25 +00:00
|
|
|
SetFenceSE(tile, 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
|
|
|
{
|
2007-03-20 13:47:00 +00:00
|
|
|
int k = GetTileZ(tile) - GetSnowLine() + TILE_HEIGHT;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-07-22 07:36:01 +00:00
|
|
|
if (k < 0) { // well below the snow line
|
2006-04-04 21:35:13 +00:00
|
|
|
if (!IsClearGround(tile, CLEAR_SNOW)) return;
|
|
|
|
if (GetClearDensity(tile) == 0) SetClearGroundDensity(tile, CLEAR_GRASS, 3);
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2006-04-04 21:35:13 +00:00
|
|
|
if (!IsClearGround(tile, CLEAR_SNOW)) {
|
|
|
|
SetClearGroundDensity(tile, CLEAR_SNOW, 0);
|
2006-02-01 15:31:21 +00:00
|
|
|
} else {
|
2006-07-22 07:36:01 +00:00
|
|
|
uint density = min((uint)k / TILE_HEIGHT, 3);
|
2006-02-01 15:31:21 +00:00
|
|
|
|
|
|
|
if (GetClearDensity(tile) < density) {
|
|
|
|
AddClearDensity(tile, 1);
|
|
|
|
} else if (GetClearDensity(tile) > density) {
|
|
|
|
AddClearDensity(tile, -1);
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
{
|
2006-04-04 21:35:13 +00:00
|
|
|
if (IsClearGround(tile, CLEAR_DESERT)) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-30 19:16:44 +00:00
|
|
|
if (GetTropicZone(tile) == TROPICZONE_DESERT) {
|
2006-04-04 21:35:13 +00:00
|
|
|
SetClearGroundDensity(tile, CLEAR_DESERT, 3);
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2006-03-30 19:16:44 +00:00
|
|
|
if (GetTropicZone(tile + TileDiffXY( 1, 0)) != TROPICZONE_DESERT &&
|
|
|
|
GetTropicZone(tile + TileDiffXY(-1, 0)) != TROPICZONE_DESERT &&
|
|
|
|
GetTropicZone(tile + TileDiffXY( 0, 1)) != TROPICZONE_DESERT &&
|
|
|
|
GetTropicZone(tile + TileDiffXY( 0, -1)) != TROPICZONE_DESERT)
|
2005-06-25 16:44:57 +00:00
|
|
|
return;
|
2006-04-04 21:35:13 +00:00
|
|
|
SetClearGroundDensity(tile, CLEAR_DESERT, 1);
|
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
|
|
|
{
|
|
|
|
TileLoopClearHelper(tile);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2006-02-06 09:18:04 +00:00
|
|
|
switch (_opt.landscape) {
|
2007-03-22 03:42:43 +00:00
|
|
|
case LT_TROPIC: TileLoopClearDesert(tile); break;
|
|
|
|
case LT_ARCTIC: TileLoopClearAlps(tile); break;
|
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_GRASS:
|
2006-02-01 15:31:21 +00:00
|
|
|
if (GetClearDensity(tile) == 3) return;
|
|
|
|
|
|
|
|
if (_game_mode != GM_EDITOR) {
|
|
|
|
if (GetClearCounter(tile) < 7) {
|
|
|
|
AddClearCounter(tile, 1);
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
SetClearCounter(tile, 0);
|
|
|
|
AddClearDensity(tile, 1);
|
|
|
|
}
|
|
|
|
} else {
|
2006-04-04 21:35:13 +00:00
|
|
|
SetClearGroundDensity(tile, GB(Random(), 0, 8) > 21 ? CLEAR_GRASS : CLEAR_ROUGH, 3);
|
2006-02-01 15:31:21 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2006-04-04 21:35:13 +00:00
|
|
|
case CLEAR_FIELDS: {
|
2006-02-01 15:31:21 +00:00
|
|
|
uint field_type;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-01 15:31:21 +00:00
|
|
|
if (_game_mode == GM_EDITOR) return;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2006-02-01 15:31:21 +00:00
|
|
|
if (GetClearCounter(tile) < 7) {
|
|
|
|
AddClearCounter(tile, 1);
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
2006-02-01 15:31:21 +00:00
|
|
|
} else {
|
|
|
|
SetClearCounter(tile, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2006-02-01 15:31:21 +00:00
|
|
|
|
2006-08-21 09:22:44 +00:00
|
|
|
if (GetIndustryIndexOfField(tile) == INVALID_INDUSTRY && GetFieldType(tile) >= 7) {
|
2006-08-20 18:44:26 +00:00
|
|
|
/* This farmfield is no longer farmfield, so make it grass again */
|
2006-10-11 21:20:53 +00:00
|
|
|
MakeClear(tile, CLEAR_GRASS, 2);
|
2006-08-20 18:44:26 +00:00
|
|
|
} else {
|
|
|
|
field_type = GetFieldType(tile);
|
|
|
|
field_type = (field_type < 8) ? field_type + 1 : 0;
|
|
|
|
SetFieldType(tile, field_type);
|
|
|
|
}
|
2006-02-01 15:31:21 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2006-02-01 15:31:21 +00:00
|
|
|
|
|
|
|
default:
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void GenerateClearTile()
|
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, gi;
|
2005-06-24 12:38:35 +00:00
|
|
|
TileIndex tile;
|
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
|
|
|
/* add rough tiles */
|
2005-11-14 08:09:57 +00:00
|
|
|
i = ScaleByMapSize(GB(Random(), 0, 10) + 0x400);
|
(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
|
|
|
gi = ScaleByMapSize(GB(Random(), 0, 7) + 0x80);
|
|
|
|
|
|
|
|
SetGeneratingWorldProgress(GWP_ROUGH_ROCKY, gi + i);
|
2004-08-09 17:04:08 +00:00
|
|
|
do {
|
(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_ROUGH_ROCKY);
|
2005-07-13 19:51:31 +00:00
|
|
|
tile = RandomTile();
|
(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 (IsTileType(tile, MP_CLEAR) && !IsClearGround(tile, CLEAR_DESERT)) SetClearGroundDensity(tile, CLEAR_ROUGH, 3);
|
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
|
|
|
/* add rocky tiles */
|
|
|
|
i = gi;
|
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);
|
(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_ROUGH_ROCKY);
|
|
|
|
if (IsTileType(tile, MP_CLEAR) && !IsClearGround(tile, CLEAR_DESERT)) {
|
2005-07-21 06:31:02 +00:00
|
|
|
uint j = GB(r, 16, 4) + 5;
|
2006-02-01 06:32:03 +00:00
|
|
|
for (;;) {
|
2005-06-24 12:38:35 +00:00
|
|
|
TileIndex tile_new;
|
|
|
|
|
2006-04-04 21:35:13 +00:00
|
|
|
SetClearGroundDensity(tile, CLEAR_ROCKS, 3);
|
2004-08-09 17:04:08 +00:00
|
|
|
do {
|
|
|
|
if (--j == 0) goto get_out;
|
2006-09-05 23:21:41 +00:00
|
|
|
tile_new = tile + TileOffsByDiagDir(GB(Random(), 0, 2));
|
(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
|
|
|
} while (!IsTileType(tile_new, MP_CLEAR) || IsClearGround(tile_new, CLEAR_DESERT));
|
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 */
|
|
|
|
}
|
|
|
|
|
2007-05-24 22:41:50 +00:00
|
|
|
static uint32 GetTileTrackStatus_Clear(TileIndex tile, TransportType mode, uint sub_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[] = {
|
2006-02-01 15:31:21 +00:00
|
|
|
STR_080D_GRASS,
|
2004-08-09 17:04:08 +00:00
|
|
|
STR_080B_ROUGH_LAND,
|
|
|
|
STR_080A_ROCKS,
|
|
|
|
STR_080E_FIELDS,
|
|
|
|
STR_080F_SNOW_COVERED_LAND,
|
2006-02-01 15:31:21 +00:00
|
|
|
STR_0810_DESERT
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void GetTileDesc_Clear(TileIndex tile, TileDesc *td)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-04-04 21:35:13 +00:00
|
|
|
if (IsClearGround(tile, CLEAR_GRASS) && GetClearDensity(tile) == 0) {
|
2006-02-01 15:31:21 +00:00
|
|
|
td->str = STR_080C_BARE_LAND;
|
|
|
|
} else {
|
|
|
|
td->str = _clear_land_str[GetClearGround(tile)];
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void InitializeClearLand()
|
2005-01-22 20:23:18 +00:00
|
|
|
{
|
2006-04-03 09:07:21 +00:00
|
|
|
_opt.snow_line = _patches.snow_line_height * TILE_HEIGHT;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
extern const TileTypeProcs _tile_type_clear_procs = {
|
2007-02-23 11:50:43 +00:00
|
|
|
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
|
|
|
|
GetSlopeTileh_Clear, ///< get_slope_tileh_proc
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|