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"
|
2006-12-27 12:38:02 +00:00
|
|
|
#include "bridge_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 "heightmap.h"
|
2006-03-05 10:19:33 +00:00
|
|
|
#include "clear_map.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-02-10 05:43:30 +00:00
|
|
|
#include "spritecache.h"
|
2005-02-13 11:18:02 +00:00
|
|
|
#include "table/sprites.h"
|
2005-01-29 12:19:05 +00:00
|
|
|
#include "tile.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include "viewport.h"
|
|
|
|
#include "command.h"
|
|
|
|
#include "vehicle.h"
|
2005-07-21 22:15:02 +00:00
|
|
|
#include "variables.h"
|
2006-03-05 10:19:33 +00:00
|
|
|
#include "void_map.h"
|
2006-03-01 21:00:44 +00:00
|
|
|
#include "water_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 "tgp.h"
|
|
|
|
#include "genworld.h"
|
|
|
|
#include "heightmap.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-09-08 17:44:29 +00:00
|
|
|
extern const TileTypeProcs
|
2004-08-09 17:04:08 +00:00
|
|
|
_tile_type_clear_procs,
|
|
|
|
_tile_type_rail_procs,
|
|
|
|
_tile_type_road_procs,
|
|
|
|
_tile_type_town_procs,
|
|
|
|
_tile_type_trees_procs,
|
|
|
|
_tile_type_station_procs,
|
|
|
|
_tile_type_water_procs,
|
|
|
|
_tile_type_dummy_procs,
|
|
|
|
_tile_type_industry_procs,
|
|
|
|
_tile_type_tunnelbridge_procs,
|
|
|
|
_tile_type_unmovable_procs;
|
|
|
|
|
|
|
|
const TileTypeProcs * const _tile_type_procs[16] = {
|
|
|
|
&_tile_type_clear_procs,
|
|
|
|
&_tile_type_rail_procs,
|
|
|
|
&_tile_type_road_procs,
|
|
|
|
&_tile_type_town_procs,
|
|
|
|
&_tile_type_trees_procs,
|
|
|
|
&_tile_type_station_procs,
|
|
|
|
&_tile_type_water_procs,
|
|
|
|
&_tile_type_dummy_procs,
|
|
|
|
&_tile_type_industry_procs,
|
|
|
|
&_tile_type_tunnelbridge_procs,
|
|
|
|
&_tile_type_unmovable_procs,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* landscape slope => sprite */
|
|
|
|
const byte _tileh_to_sprite[32] = {
|
2006-08-22 14:38:37 +00:00
|
|
|
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 17, 0, 15, 18, 0,
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
const Slope _inclined_tileh[] = {
|
2006-08-22 14:38:37 +00:00
|
|
|
SLOPE_SW, SLOPE_NW, SLOPE_SW, SLOPE_SE, SLOPE_NE, SLOPE_SE, SLOPE_NE, SLOPE_NW,
|
|
|
|
SLOPE_E, SLOPE_N, SLOPE_W, SLOPE_S,
|
2006-08-12 12:56:45 +00:00
|
|
|
SLOPE_NWS, SLOPE_WSE, SLOPE_SEN, SLOPE_ENW
|
2005-06-20 20:08:10 +00:00
|
|
|
};
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
uint GetPartialZ(int x, int y, Slope corners)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
int z = 0;
|
|
|
|
|
2006-02-01 07:36:15 +00:00
|
|
|
switch (corners) {
|
2006-04-23 13:48:16 +00:00
|
|
|
case SLOPE_W:
|
2004-08-09 17:04:08 +00:00
|
|
|
if (x - y >= 0)
|
|
|
|
z = (x - y) >> 1;
|
|
|
|
break;
|
2004-09-08 17:44:29 +00:00
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
case SLOPE_S:
|
2004-08-09 17:04:08 +00:00
|
|
|
y^=0xF;
|
|
|
|
if ( (x - y) >= 0)
|
|
|
|
z = (x - y) >> 1;
|
|
|
|
break;
|
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
case SLOPE_SW:
|
2004-08-09 17:04:08 +00:00
|
|
|
z = (x>>1) + 1;
|
|
|
|
break;
|
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
case SLOPE_E:
|
2004-08-09 17:04:08 +00:00
|
|
|
if (y - x >= 0)
|
|
|
|
z = (y - x) >> 1;
|
|
|
|
break;
|
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
case SLOPE_EW:
|
|
|
|
case SLOPE_NS:
|
|
|
|
case SLOPE_ELEVATED:
|
2004-08-09 17:04:08 +00:00
|
|
|
z = 4;
|
|
|
|
break;
|
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
case SLOPE_SE:
|
2004-08-09 17:04:08 +00:00
|
|
|
z = (y>>1) + 1;
|
|
|
|
break;
|
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
case SLOPE_WSE:
|
2004-08-09 17:04:08 +00:00
|
|
|
z = 8;
|
|
|
|
y^=0xF;
|
|
|
|
if (x - y < 0)
|
|
|
|
z += (x - y) >> 1;
|
|
|
|
break;
|
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
case SLOPE_N:
|
2004-08-09 17:04:08 +00:00
|
|
|
y ^= 0xF;
|
|
|
|
if (y - x >= 0)
|
|
|
|
z = (y - x) >> 1;
|
|
|
|
break;
|
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
case SLOPE_NW:
|
2004-08-09 17:04:08 +00:00
|
|
|
z = (y^0xF)>>1;
|
|
|
|
break;
|
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
case SLOPE_NWS:
|
2004-08-09 17:04:08 +00:00
|
|
|
z = 8;
|
|
|
|
if (x - y < 0)
|
|
|
|
z += (x - y) >> 1;
|
|
|
|
break;
|
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
case SLOPE_NE:
|
2004-08-09 17:04:08 +00:00
|
|
|
z = (x^0xF)>>1;
|
|
|
|
break;
|
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
case SLOPE_ENW:
|
2004-08-09 17:04:08 +00:00
|
|
|
z = 8;
|
|
|
|
y ^= 0xF;
|
|
|
|
if (y - x < 0)
|
|
|
|
z += (y - x) >> 1;
|
|
|
|
break;
|
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
case SLOPE_SEN:
|
2004-08-09 17:04:08 +00:00
|
|
|
z = 8;
|
|
|
|
if (y - x < 0)
|
|
|
|
z += (y - x) >> 1;
|
|
|
|
break;
|
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
case SLOPE_STEEP_S:
|
2004-08-09 17:04:08 +00:00
|
|
|
z = 1 + ((x+y)>>1);
|
|
|
|
break;
|
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
case SLOPE_STEEP_W:
|
2004-08-09 17:04:08 +00:00
|
|
|
z = 1 + ((x+(y^0xF))>>1);
|
|
|
|
break;
|
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
case SLOPE_STEEP_N:
|
2004-08-09 17:04:08 +00:00
|
|
|
z = 1 + (((x^0xF)+(y^0xF))>>1);
|
|
|
|
break;
|
2004-09-08 17:44:29 +00:00
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
case SLOPE_STEEP_E:
|
2004-08-09 17:04:08 +00:00
|
|
|
z = 1 + (((x^0xF)+(y^0xF))>>1);
|
|
|
|
break;
|
2006-04-23 13:48:16 +00:00
|
|
|
|
|
|
|
default: break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return z;
|
|
|
|
}
|
|
|
|
|
2006-02-01 06:32:03 +00:00
|
|
|
uint GetSlopeZ(int x, int y)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-08-06 16:32:49 +00:00
|
|
|
TileIndex tile = TileVirtXY(x, y);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-08-06 16:32:49 +00:00
|
|
|
return _tile_type_procs[GetTileType(tile)]->get_slope_z_proc(tile, x, y);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-06-24 22:19:28 +00:00
|
|
|
|
|
|
|
static Slope GetFoundationSlope(TileIndex tile, uint* z)
|
2004-08-13 11:28:59 +00:00
|
|
|
{
|
2006-06-24 22:19:28 +00:00
|
|
|
Slope tileh = GetTileSlope(tile, z);
|
2006-04-23 13:48:16 +00:00
|
|
|
Slope slope = _tile_type_procs[GetTileType(tile)]->get_slope_tileh_proc(tile, tileh);
|
2004-08-14 10:05:27 +00:00
|
|
|
|
2006-06-24 22:19:28 +00:00
|
|
|
// Flatter slope -> higher base height
|
|
|
|
if (slope < tileh) *z += TILE_HEIGHT;
|
|
|
|
return slope;
|
|
|
|
}
|
2004-08-13 18:27:33 +00:00
|
|
|
|
2006-06-24 22:19:28 +00:00
|
|
|
|
|
|
|
static bool HasFoundationNW(TileIndex tile, Slope slope_here, uint z_here)
|
|
|
|
{
|
|
|
|
uint z;
|
|
|
|
Slope slope = GetFoundationSlope(TILE_ADDXY(tile, 0, -1), &z);
|
|
|
|
|
|
|
|
return
|
2006-10-28 14:06:40 +00:00
|
|
|
(
|
|
|
|
z_here + (slope_here & SLOPE_N ? TILE_HEIGHT : 0) + (slope_here == SLOPE_STEEP_N ? TILE_HEIGHT : 0) >
|
|
|
|
z + (slope & SLOPE_E ? TILE_HEIGHT : 0) + (slope == SLOPE_STEEP_E ? TILE_HEIGHT : 0)
|
|
|
|
) || (
|
|
|
|
z_here + (slope_here & SLOPE_W ? TILE_HEIGHT : 0) + (slope_here == SLOPE_STEEP_W ? TILE_HEIGHT : 0) >
|
|
|
|
z + (slope & SLOPE_S ? TILE_HEIGHT : 0) + (slope == SLOPE_STEEP_S ? TILE_HEIGHT : 0)
|
|
|
|
);
|
2004-08-13 11:28:59 +00:00
|
|
|
}
|
|
|
|
|
2006-06-24 22:19:28 +00:00
|
|
|
|
|
|
|
static bool HasFoundationNE(TileIndex tile, Slope slope_here, uint z_here)
|
|
|
|
{
|
|
|
|
uint z;
|
|
|
|
Slope slope = GetFoundationSlope(TILE_ADDXY(tile, -1, 0), &z);
|
|
|
|
|
|
|
|
return
|
2006-10-28 14:06:40 +00:00
|
|
|
(
|
|
|
|
z_here + (slope_here & SLOPE_N ? TILE_HEIGHT : 0) + (slope_here == SLOPE_STEEP_N ? TILE_HEIGHT : 0) >
|
|
|
|
z + (slope & SLOPE_W ? TILE_HEIGHT : 0) + (slope == SLOPE_STEEP_W ? TILE_HEIGHT : 0)
|
|
|
|
) || (
|
|
|
|
z_here + (slope_here & SLOPE_E ? TILE_HEIGHT : 0) + (slope_here == SLOPE_STEEP_E ? TILE_HEIGHT : 0) >
|
|
|
|
z + (slope & SLOPE_S ? TILE_HEIGHT : 0) + (slope == SLOPE_STEEP_S ? TILE_HEIGHT : 0)
|
|
|
|
);
|
2006-06-24 22:19:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
void DrawFoundation(TileInfo *ti, uint f)
|
|
|
|
{
|
2006-08-08 12:30:55 +00:00
|
|
|
uint32 sprite_base = SPR_SLOPES_BASE - 15;
|
2006-06-24 22:19:28 +00:00
|
|
|
Slope slope;
|
|
|
|
uint z;
|
2004-08-13 18:27:33 +00:00
|
|
|
|
2006-06-24 22:19:28 +00:00
|
|
|
slope = GetFoundationSlope(ti->tile, &z);
|
|
|
|
if (!HasFoundationNW(ti->tile, slope, z)) sprite_base += 22;
|
|
|
|
if (!HasFoundationNE(ti->tile, slope, z)) sprite_base += 44;
|
2004-08-13 11:28:59 +00:00
|
|
|
|
2006-08-12 12:56:45 +00:00
|
|
|
if (IsSteepSlope(ti->tileh)) {
|
|
|
|
uint32 lower_base;
|
2004-08-13 11:28:59 +00:00
|
|
|
|
2006-08-12 12:56:45 +00:00
|
|
|
// Lower part of foundation
|
|
|
|
lower_base = sprite_base;
|
|
|
|
if (lower_base == SPR_SLOPES_BASE - 15) lower_base = SPR_FOUNDATION_BASE;
|
|
|
|
AddSortableSpriteToDraw(
|
|
|
|
lower_base + (ti->tileh & ~SLOPE_STEEP), ti->x, ti->y, 16, 16, 7, ti->z
|
|
|
|
);
|
2006-04-23 19:35:36 +00:00
|
|
|
ti->z += TILE_HEIGHT;
|
2006-08-12 12:56:45 +00:00
|
|
|
ti->tileh = _inclined_tileh[f - 15];
|
|
|
|
if (f < 15 + 8) {
|
|
|
|
// inclined
|
|
|
|
AddSortableSpriteToDraw(sprite_base + f, ti->x, ti->y, 16, 16, 1, ti->z);
|
|
|
|
OffsetGroundSprite(31, 9);
|
|
|
|
} else if (f >= 15 + 8 + 4) {
|
|
|
|
// three corners raised
|
|
|
|
uint32 upper = sprite_base + 15 + (f - 15 - 8 - 4) * 2;
|
|
|
|
|
|
|
|
AddSortableSpriteToDraw(upper, ti->x, ti->y, 16, 16, 1, ti->z);
|
|
|
|
AddChildSpriteScreen(upper + 1, 31, 9);
|
|
|
|
OffsetGroundSprite(31, 9);
|
|
|
|
} else {
|
|
|
|
// one corner raised
|
|
|
|
OffsetGroundSprite(31, 1);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2006-08-12 12:56:45 +00:00
|
|
|
if (f < 15) {
|
|
|
|
// leveled foundation
|
|
|
|
// Use the original slope sprites if NW and NE borders should be visible
|
|
|
|
if (sprite_base == SPR_SLOPES_BASE - 15) sprite_base = SPR_FOUNDATION_BASE;
|
|
|
|
|
|
|
|
AddSortableSpriteToDraw(sprite_base + f, ti->x, ti->y, 16, 16, 7, ti->z);
|
2006-08-10 14:44:32 +00:00
|
|
|
ti->z += TILE_HEIGHT;
|
2006-08-12 12:56:45 +00:00
|
|
|
ti->tileh = SLOPE_FLAT;
|
|
|
|
OffsetGroundSprite(31, 1);
|
|
|
|
} else {
|
|
|
|
// inclined foundation
|
|
|
|
AddSortableSpriteToDraw(sprite_base + f, ti->x, ti->y, 16, 16, 1, ti->z);
|
|
|
|
ti->tileh = _inclined_tileh[f - 15];
|
|
|
|
OffsetGroundSprite(31, 9);
|
2006-08-10 14:44:32 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-27 18:15:27 +00:00
|
|
|
void DoClearSquare(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-04-04 21:35:13 +00:00
|
|
|
MakeClear(tile, CLEAR_GRASS, _generating_world ? 3 : 0);
|
2006-02-01 15:31:21 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-03-27 18:15:27 +00:00
|
|
|
uint32 GetTileTrackStatus(TileIndex tile, TransportType mode)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-01-29 15:12:40 +00:00
|
|
|
return _tile_type_procs[GetTileType(tile)]->get_tile_track_status_proc(tile, mode);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
void ChangeTileOwner(TileIndex tile, PlayerID old_player, PlayerID new_player)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-01-29 15:12:40 +00:00
|
|
|
_tile_type_procs[GetTileType(tile)]->change_tile_owner_proc(tile, old_player, new_player);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-03-27 18:15:27 +00:00
|
|
|
void GetAcceptedCargo(TileIndex tile, AcceptedCargo ac)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
memset(ac, 0, sizeof(AcceptedCargo));
|
2005-01-29 15:12:40 +00:00
|
|
|
_tile_type_procs[GetTileType(tile)]->get_accepted_cargo_proc(tile, ac);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-03-27 18:15:27 +00:00
|
|
|
void AnimateTile(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-01-29 15:12:40 +00:00
|
|
|
_tile_type_procs[GetTileType(tile)]->animate_tile_proc(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-03-27 18:15:27 +00:00
|
|
|
void ClickTile(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-01-29 15:12:40 +00:00
|
|
|
_tile_type_procs[GetTileType(tile)]->click_tile_proc(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-03-27 18:15:27 +00:00
|
|
|
void GetTileDesc(TileIndex tile, TileDesc *td)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-01-29 15:12:40 +00:00
|
|
|
_tile_type_procs[GetTileType(tile)]->get_tile_desc_proc(tile, td);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-05-07 10:26:12 +00:00
|
|
|
/** Clear a piece of landscape
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile tile to clear
|
2005-05-07 10:26:12 +00:00
|
|
|
* @param p1 unused
|
|
|
|
* @param p2 unused
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
2006-04-10 07:15:58 +00:00
|
|
|
int32 CmdLandscapeClear(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
|
|
|
|
|
2005-01-29 15:12:40 +00:00
|
|
|
return _tile_type_procs[GetTileType(tile)]->clear_tile_proc(tile, flags);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-05-12 00:11:37 +00:00
|
|
|
/** Clear a big piece of landscape
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile end tile of area dragging
|
2005-05-12 00:11:37 +00:00
|
|
|
* @param p1 start tile of area dragging
|
|
|
|
* @param p2 unused
|
|
|
|
*/
|
2006-04-10 07:15:58 +00:00
|
|
|
int32 CmdClearArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-05-12 00:11:37 +00:00
|
|
|
int32 cost, ret, money;
|
2006-04-10 07:15:58 +00:00
|
|
|
int ex;
|
|
|
|
int ey;
|
2004-08-09 17:04:08 +00:00
|
|
|
int sx,sy;
|
|
|
|
int x,y;
|
|
|
|
bool success = false;
|
|
|
|
|
2006-01-30 17:18:45 +00:00
|
|
|
if (p1 >= MapSize()) return CMD_ERROR;
|
2005-05-12 00:11:37 +00:00
|
|
|
|
2005-01-04 17:11:03 +00:00
|
|
|
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// make sure sx,sy are smaller than ex,ey
|
2006-04-10 12:36:04 +00:00
|
|
|
ex = TileX(tile);
|
|
|
|
ey = TileY(tile);
|
|
|
|
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);
|
|
|
|
|
|
|
|
money = GetAvailableMoneyForCommand();
|
|
|
|
cost = 0;
|
|
|
|
|
2006-04-10 12:36:04 +00:00
|
|
|
for (x = sx; x <= ex; ++x) {
|
|
|
|
for (y = sy; y <= ey; ++y) {
|
|
|
|
ret = DoCommand(TileXY(x, y), 0, 0, flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
2005-05-12 00:11:37 +00:00
|
|
|
if (CmdFailed(ret)) continue;
|
2004-08-09 17:04:08 +00:00
|
|
|
cost += ret;
|
|
|
|
success = true;
|
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
2005-05-12 00:11:37 +00:00
|
|
|
if (ret > 0 && (money -= ret) < 0) {
|
2004-08-09 17:04:08 +00:00
|
|
|
_additional_cash_required = ret;
|
|
|
|
return cost - ret;
|
|
|
|
}
|
2006-04-10 12:36:04 +00:00
|
|
|
DoCommand(TileXY(x, y), 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// draw explosion animation...
|
2005-05-12 00:11:37 +00:00
|
|
|
if ((x == sx || x == ex) && (y == sy || y == ey)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
// big explosion in each corner, or small explosion for single tiles
|
2006-04-23 19:35:36 +00:00
|
|
|
CreateEffectVehicleAbove(x * TILE_SIZE + TILE_SIZE / 2, y * TILE_SIZE + TILE_SIZE / 2, 2,
|
2005-02-12 15:53:32 +00:00
|
|
|
sy == ey && sx == ex ? EV_EXPLOSION_SMALL : EV_EXPLOSION_LARGE
|
|
|
|
);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-12 00:11:37 +00:00
|
|
|
return (success) ? cost : CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define TILELOOP_BITS 4
|
|
|
|
#define TILELOOP_SIZE (1 << TILELOOP_BITS)
|
2005-01-07 17:40:23 +00:00
|
|
|
#define TILELOOP_ASSERTMASK ((TILELOOP_SIZE-1) + ((TILELOOP_SIZE-1) << MapLogX()))
|
|
|
|
#define TILELOOP_CHKMASK (((1 << (MapLogX() - TILELOOP_BITS))-1) << TILELOOP_BITS)
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void RunTileLoop(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-03-27 18:15:27 +00:00
|
|
|
TileIndex tile;
|
2004-08-09 17:04:08 +00:00
|
|
|
uint count;
|
|
|
|
|
|
|
|
tile = _cur_tileloop_tile;
|
|
|
|
|
|
|
|
assert( (tile & ~TILELOOP_ASSERTMASK) == 0);
|
2005-01-03 18:59:58 +00:00
|
|
|
count = (MapSizeX() / TILELOOP_SIZE) * (MapSizeY() / TILELOOP_SIZE);
|
2004-08-09 17:04:08 +00:00
|
|
|
do {
|
2005-01-29 15:12:40 +00:00
|
|
|
_tile_type_procs[GetTileType(tile)]->tile_loop_proc(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-07 17:02:43 +00:00
|
|
|
if (TileX(tile) < MapSizeX() - TILELOOP_SIZE) {
|
2004-08-09 17:04:08 +00:00
|
|
|
tile += TILELOOP_SIZE; /* no overflow */
|
|
|
|
} else {
|
2005-06-25 16:44:57 +00:00
|
|
|
tile = TILE_MASK(tile - TILELOOP_SIZE * (MapSizeX() / TILELOOP_SIZE - 1) + TileDiffXY(0, TILELOOP_SIZE)); /* x would overflow, also increase y */
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
} while (--count);
|
|
|
|
assert( (tile & ~TILELOOP_ASSERTMASK) == 0);
|
|
|
|
|
|
|
|
tile += 9;
|
|
|
|
if (tile & TILELOOP_CHKMASK)
|
2005-01-03 18:59:58 +00:00
|
|
|
tile = (tile + MapSizeX()) & TILELOOP_ASSERTMASK;
|
2004-08-09 17:04:08 +00:00
|
|
|
_cur_tileloop_tile = tile;
|
|
|
|
}
|
|
|
|
|
2005-07-14 09:43:59 +00:00
|
|
|
void InitializeLandscape(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-02-24 20:35:37 +00:00
|
|
|
uint maxx = MapMaxX();
|
|
|
|
uint maxy = MapMaxY();
|
|
|
|
uint sizex = MapSizeX();
|
|
|
|
uint x;
|
|
|
|
uint y;
|
|
|
|
|
|
|
|
for (y = 0; y < maxy; y++) {
|
|
|
|
for (x = 0; x < maxx; x++) {
|
2006-04-04 21:35:13 +00:00
|
|
|
MakeClear(sizex * y + x, CLEAR_GRASS, 3);
|
2006-02-24 20:35:37 +00:00
|
|
|
SetTileHeight(sizex * y + x, 0);
|
2007-01-11 02:05:13 +00:00
|
|
|
SetTropicZone(sizex * y + x, TROPICZONE_INVALID);
|
2006-12-27 12:38:02 +00:00
|
|
|
ClearBridgeMiddle(sizex * y + x);
|
2006-02-24 20:35:37 +00:00
|
|
|
}
|
|
|
|
MakeVoid(sizex * y + x);
|
2005-07-13 18:04:01 +00:00
|
|
|
}
|
2006-02-24 20:35:37 +00:00
|
|
|
for (x = 0; x < sizex; x++) MakeVoid(sizex * y + x);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void ConvertGroundTilesIntoWaterTiles(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-06-10 08:37:41 +00:00
|
|
|
TileIndex tile;
|
(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 z;
|
|
|
|
Slope slope;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-03 20:52:12 +00:00
|
|
|
for (tile = 0; tile < MapSize(); ++tile) {
|
(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
|
|
|
slope = GetTileSlope(tile, &z);
|
|
|
|
if (IsTileType(tile, MP_CLEAR) && z == 0) {
|
|
|
|
/* Make both water for tiles at level 0
|
|
|
|
* and make shore, as that looks much better
|
|
|
|
* during the generation. */
|
|
|
|
switch (slope) {
|
|
|
|
case SLOPE_FLAT:
|
|
|
|
MakeWater(tile);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SLOPE_N:
|
|
|
|
case SLOPE_E:
|
|
|
|
case SLOPE_S:
|
|
|
|
case SLOPE_W:
|
|
|
|
case SLOPE_NW:
|
|
|
|
case SLOPE_SW:
|
|
|
|
case SLOPE_SE:
|
|
|
|
case SLOPE_NE:
|
|
|
|
MakeShore(tile);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-22 14:38:37 +00:00
|
|
|
static const byte _genterrain_tbl_1[5] = { 10, 22, 33, 37, 4 };
|
|
|
|
static const byte _genterrain_tbl_2[5] = { 0, 0, 0, 0, 33 };
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
static void GenerateTerrain(int type, int flag)
|
|
|
|
{
|
|
|
|
uint32 r;
|
2005-02-03 20:52:12 +00:00
|
|
|
uint x;
|
|
|
|
uint y;
|
|
|
|
uint w;
|
|
|
|
uint h;
|
2007-01-10 18:56:51 +00:00
|
|
|
const Sprite* templ;
|
2005-02-03 20:52:12 +00:00
|
|
|
const byte *p;
|
2005-07-13 18:04:01 +00:00
|
|
|
Tile* tile;
|
2004-08-09 17:04:08 +00:00
|
|
|
byte direction;
|
|
|
|
|
|
|
|
r = Random();
|
2007-01-10 18:56:51 +00:00
|
|
|
templ = GetSprite((((r >> 24) * _genterrain_tbl_1[type]) >> 8) + _genterrain_tbl_2[type] + 4845);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-03 12:56:22 +00:00
|
|
|
x = r & MapMaxX();
|
2005-01-07 17:40:23 +00:00
|
|
|
y = (r >> MapLogX()) & MapMaxY();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
|
2006-02-01 06:32:03 +00:00
|
|
|
if (x < 2 || y < 2) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-20 15:29:28 +00:00
|
|
|
direction = GB(r, 22, 2);
|
2005-02-03 20:52:12 +00:00
|
|
|
if (direction & 1) {
|
2007-01-10 18:56:51 +00:00
|
|
|
w = templ->height;
|
|
|
|
h = templ->width;
|
2005-02-03 20:52:12 +00:00
|
|
|
} else {
|
2007-01-10 18:56:51 +00:00
|
|
|
w = templ->width;
|
|
|
|
h = templ->height;
|
2005-02-03 20:52:12 +00:00
|
|
|
}
|
2007-01-10 18:56:51 +00:00
|
|
|
p = templ->data;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (flag & 4) {
|
2005-02-03 18:20:43 +00:00
|
|
|
uint xw = x * MapSizeY();
|
|
|
|
uint yw = y * MapSizeX();
|
|
|
|
uint bias = (MapSizeX() + MapSizeY()) * 16;
|
|
|
|
|
|
|
|
switch (flag & 3) {
|
|
|
|
case 0:
|
|
|
|
if (xw + yw > MapSize() - bias) return;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
if (yw < xw + bias) return;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
if (xw + yw < MapSize() + bias) return;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
if (xw < yw + bias) return;
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-01 06:32:03 +00:00
|
|
|
if (x + w >= MapMaxX() - 1) return;
|
|
|
|
if (y + h >= MapMaxY() - 1) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-13 18:04:01 +00:00
|
|
|
tile = &_m[TileXY(x, y)];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-03 20:52:12 +00:00
|
|
|
switch (direction) {
|
|
|
|
case 0:
|
2004-08-09 17:04:08 +00:00
|
|
|
do {
|
2005-07-13 18:04:01 +00:00
|
|
|
Tile* tile_cur = tile;
|
2005-02-03 20:52:12 +00:00
|
|
|
uint w_cur;
|
|
|
|
|
|
|
|
for (w_cur = w; w_cur != 0; --w_cur) {
|
2005-07-13 18:04:01 +00:00
|
|
|
if (*p >= tile_cur->type_height) tile_cur->type_height = *p;
|
2005-02-03 20:52:12 +00:00
|
|
|
p++;
|
|
|
|
tile_cur++;
|
|
|
|
}
|
2005-06-25 16:44:57 +00:00
|
|
|
tile += TileDiffXY(0, 1);
|
2005-02-03 20:52:12 +00:00
|
|
|
} while (--h != 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
2004-08-09 17:04:08 +00:00
|
|
|
do {
|
2005-07-13 18:04:01 +00:00
|
|
|
Tile* tile_cur = tile;
|
2005-02-03 20:52:12 +00:00
|
|
|
uint h_cur;
|
|
|
|
|
|
|
|
for (h_cur = h; h_cur != 0; --h_cur) {
|
2005-07-13 18:04:01 +00:00
|
|
|
if (*p >= tile_cur->type_height) tile_cur->type_height = *p;
|
2005-02-03 20:52:12 +00:00
|
|
|
p++;
|
2005-06-25 16:44:57 +00:00
|
|
|
tile_cur += TileDiffXY(0, 1);
|
2005-02-03 20:52:12 +00:00
|
|
|
}
|
|
|
|
tile++;
|
|
|
|
} while (--w != 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
2005-06-25 16:44:57 +00:00
|
|
|
tile += TileDiffXY(w - 1, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
do {
|
2005-07-13 18:04:01 +00:00
|
|
|
Tile* tile_cur = tile;
|
2005-02-03 20:52:12 +00:00
|
|
|
uint w_cur;
|
|
|
|
|
|
|
|
for (w_cur = w; w_cur != 0; --w_cur) {
|
2005-07-13 18:04:01 +00:00
|
|
|
if (*p >= tile_cur->type_height) tile_cur->type_height = *p;
|
2005-02-03 20:52:12 +00:00
|
|
|
p++;
|
|
|
|
tile_cur--;
|
|
|
|
}
|
2005-06-25 16:44:57 +00:00
|
|
|
tile += TileDiffXY(0, 1);
|
2005-02-03 20:52:12 +00:00
|
|
|
} while (--h != 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
2005-06-25 16:44:57 +00:00
|
|
|
tile += TileDiffXY(0, h - 1);
|
2004-08-09 17:04:08 +00:00
|
|
|
do {
|
2005-07-13 18:04:01 +00:00
|
|
|
Tile* tile_cur = tile;
|
2005-02-03 20:52:12 +00:00
|
|
|
uint h_cur;
|
|
|
|
|
|
|
|
for (h_cur = h; h_cur != 0; --h_cur) {
|
2005-07-13 18:04:01 +00:00
|
|
|
if (*p >= tile_cur->type_height) tile_cur->type_height = *p;
|
2005-02-03 20:52:12 +00:00
|
|
|
p++;
|
2005-06-25 16:44:57 +00:00
|
|
|
tile_cur -= TileDiffXY(0, 1);
|
2005-02-04 07:52:12 +00:00
|
|
|
}
|
2005-02-03 20:52:12 +00:00
|
|
|
tile++;
|
|
|
|
} while (--w != 0);
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#include "table/genland.h"
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
static void CreateDesertOrRainForest(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-02-03 20:52:12 +00:00
|
|
|
TileIndex tile;
|
(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
|
|
|
TileIndex update_freq = MapSize() / 4;
|
2005-01-06 11:39:00 +00:00
|
|
|
const TileIndexDiffC *data;
|
2005-02-03 20:52:12 +00:00
|
|
|
uint i;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-06 11:39:00 +00:00
|
|
|
for (tile = 0; tile != MapSize(); ++tile) {
|
(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 ((tile % update_freq) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
|
|
|
|
|
2005-01-06 11:39:00 +00:00
|
|
|
for (data = _make_desert_or_rainforest_data;
|
|
|
|
data != endof(_make_desert_or_rainforest_data); ++data) {
|
2005-01-26 18:59:10 +00:00
|
|
|
TileIndex t = TILE_MASK(tile + ToTileIndexDiff(*data));
|
2005-01-16 14:50:01 +00:00
|
|
|
if (TileHeight(t) >= 4 || IsTileType(t, MP_WATER)) break;
|
2005-01-06 11:39:00 +00:00
|
|
|
}
|
|
|
|
if (data == endof(_make_desert_or_rainforest_data))
|
2006-03-30 19:16:44 +00:00
|
|
|
SetTropicZone(tile, TROPICZONE_DESERT);
|
2005-01-06 11:39:00 +00:00
|
|
|
}
|
2004-09-08 17:44:29 +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
|
|
|
for (i = 0; i != 256; i++) {
|
|
|
|
if ((i % 64) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
RunTileLoop();
|
(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
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-06 11:39:00 +00:00
|
|
|
for (tile = 0; tile != MapSize(); ++tile) {
|
(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 ((tile % update_freq) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
|
|
|
|
|
2005-01-06 11:39:00 +00:00
|
|
|
for (data = _make_desert_or_rainforest_data;
|
|
|
|
data != endof(_make_desert_or_rainforest_data); ++data) {
|
|
|
|
TileIndex t = TILE_MASK(tile + ToTileIndexDiff(*data));
|
2006-04-04 21:35:13 +00:00
|
|
|
if (IsTileType(t, MP_CLEAR) && IsClearGround(t, CLEAR_DESERT)) break;
|
2005-01-06 11:39:00 +00:00
|
|
|
}
|
|
|
|
if (data == endof(_make_desert_or_rainforest_data))
|
2006-03-30 19:16:44 +00:00
|
|
|
SetTropicZone(tile, TROPICZONE_RAINFOREST);
|
2005-01-06 11:39:00 +00:00
|
|
|
}
|
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
|
|
|
void GenerateLandscape(byte mode)
|
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
|
|
|
const int gwp_desert_amount = 4 + 8;
|
2005-02-03 20:52:12 +00:00
|
|
|
uint i;
|
|
|
|
uint flag;
|
2004-08-09 17:04:08 +00:00
|
|
|
uint32 r;
|
2004-09-08 17:44:29 +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
|
|
|
if (mode == GW_HEIGHTMAP) {
|
|
|
|
SetGeneratingWorldProgress(GWP_LANDSCAPE, (_opt.landscape == LT_DESERT) ? 1 + gwp_desert_amount : 1);
|
|
|
|
LoadHeightmap(_file_to_saveload.name);
|
|
|
|
IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
|
|
|
|
} else if (_patches.land_generator == LG_TERRAGENESIS) {
|
|
|
|
SetGeneratingWorldProgress(GWP_LANDSCAPE, (_opt.landscape == LT_DESERT) ? 3 + gwp_desert_amount : 3);
|
|
|
|
GenerateTerrainPerlin();
|
|
|
|
} else {
|
|
|
|
switch (_opt.landscape) {
|
|
|
|
case LT_HILLY:
|
|
|
|
SetGeneratingWorldProgress(GWP_LANDSCAPE, 2);
|
2006-02-13 21:15:00 +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
|
|
|
for (i = ScaleByMapSize((Random() & 0x7F) + 950); i != 0; --i) {
|
|
|
|
GenerateTerrain(2, 0);
|
|
|
|
}
|
|
|
|
IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
|
2006-02-13 21:15:00 +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
|
|
|
r = Random();
|
|
|
|
flag = GB(r, 0, 2) | 4;
|
|
|
|
for (i = ScaleByMapSize(GB(r, 16, 7) + 450); i != 0; --i) {
|
|
|
|
GenerateTerrain(4, flag);
|
|
|
|
}
|
|
|
|
IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
|
|
|
|
break;
|
2004-09-08 17:44:29 +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
|
|
|
case LT_DESERT:
|
|
|
|
SetGeneratingWorldProgress(GWP_LANDSCAPE, 3 + gwp_desert_amount);
|
2004-09-08 17:44:29 +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
|
|
|
for (i = ScaleByMapSize((Random() & 0x7F) + 170); i != 0; --i) {
|
|
|
|
GenerateTerrain(0, 0);
|
|
|
|
}
|
|
|
|
IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
|
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
|
|
|
r = Random();
|
|
|
|
flag = GB(r, 0, 2) | 4;
|
|
|
|
for (i = ScaleByMapSize(GB(r, 16, 8) + 1700); i != 0; --i) {
|
|
|
|
GenerateTerrain(0, flag);
|
|
|
|
}
|
|
|
|
IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
|
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
|
|
|
flag ^= 2;
|
|
|
|
|
|
|
|
for (i = ScaleByMapSize((Random() & 0x7F) + 410); i != 0; --i) {
|
|
|
|
GenerateTerrain(3, flag);
|
|
|
|
}
|
|
|
|
IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
SetGeneratingWorldProgress(GWP_LANDSCAPE, 1);
|
|
|
|
|
|
|
|
i = ScaleByMapSize((Random() & 0x7F) + (3 - _opt.diff.quantity_sea_lakes) * 256 + 100);
|
|
|
|
for (; i != 0; --i) {
|
|
|
|
GenerateTerrain(_opt.diff.terrain_type, 0);
|
|
|
|
}
|
|
|
|
IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
|
|
|
|
break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ConvertGroundTilesIntoWaterTiles();
|
|
|
|
|
2006-02-13 21:15:00 +00:00
|
|
|
if (_opt.landscape == LT_DESERT) CreateDesertOrRainForest();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void OnTick_Town(void);
|
|
|
|
void OnTick_Trees(void);
|
|
|
|
void OnTick_Station(void);
|
|
|
|
void OnTick_Industry(void);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void OnTick_Players(void);
|
|
|
|
void OnTick_Train(void);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void CallLandscapeTick(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
OnTick_Town();
|
|
|
|
OnTick_Trees();
|
|
|
|
OnTick_Station();
|
|
|
|
OnTick_Industry();
|
|
|
|
|
|
|
|
OnTick_Players();
|
|
|
|
OnTick_Train();
|
|
|
|
}
|
|
|
|
|
|
|
|
TileIndex AdjustTileCoordRandomly(TileIndex a, byte rng)
|
|
|
|
{
|
|
|
|
int rn = rng;
|
|
|
|
uint32 r = Random();
|
|
|
|
|
2005-06-25 16:44:57 +00:00
|
|
|
return TILE_MASK(TileXY(
|
2005-07-21 06:31:02 +00:00
|
|
|
TileX(a) + (GB(r, 0, 8) * rn * 2 >> 8) - rn,
|
|
|
|
TileY(a) + (GB(r, 8, 8) * rn * 2 >> 8) - rn
|
2005-01-25 21:43:57 +00:00
|
|
|
));
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-03-27 18:15:27 +00:00
|
|
|
bool IsValidTile(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-01-07 17:02:43 +00:00
|
|
|
return (tile < MapSizeX() * MapMaxY() && TileX(tile) != MapMaxX());
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|