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"
|
2007-03-20 13:47:00 +00:00
|
|
|
#include "date.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"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include "viewport.h"
|
2007-12-21 21:50:46 +00:00
|
|
|
#include "command_func.h"
|
2007-03-20 13:47:00 +00:00
|
|
|
#include "landscape.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#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"
|
2007-12-21 22:50:51 +00:00
|
|
|
#include "tile_cmd.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-03-20 13:47:00 +00:00
|
|
|
SnowLine *_snow_line = NULL;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-07-26 16:51:10 +00:00
|
|
|
/**
|
|
|
|
* Applys a foundation to a slope.
|
|
|
|
*
|
|
|
|
* @pre Foundation and slope must be valid combined.
|
|
|
|
* @param f The #Foundation.
|
|
|
|
* @param s The #Slope to modify.
|
|
|
|
* @return Increment to the tile Z coordinate.
|
|
|
|
*/
|
|
|
|
uint ApplyFoundationToSlope(Foundation f, Slope *s)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!IsFoundation(f)) return 0;
|
|
|
|
|
|
|
|
if (IsLeveledFoundation(f)) {
|
|
|
|
*s = SLOPE_FLAT;
|
|
|
|
return TILE_HEIGHT;
|
|
|
|
}
|
|
|
|
|
2007-10-20 21:04:14 +00:00
|
|
|
if (f != FOUNDATION_STEEP_BOTH && IsNonContinuousFoundation(f)) {
|
|
|
|
*s = HalftileSlope(*s, GetHalftileFoundationCorner(f));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsSpecialRailFoundation(f)) {
|
|
|
|
*s = SlopeWithThreeCornersRaised(OppositeCorner(GetRailFoundationCorner(f)));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-07-26 16:51:10 +00:00
|
|
|
uint dz = IsSteepSlope(*s) ? TILE_HEIGHT : 0;
|
2007-10-05 19:36:13 +00:00
|
|
|
Corner highest_corner = GetHighestSlopeCorner(*s);
|
2007-07-26 16:51:10 +00:00
|
|
|
|
|
|
|
switch (f) {
|
|
|
|
case FOUNDATION_INCLINED_X:
|
2007-10-05 19:36:13 +00:00
|
|
|
*s = (((highest_corner == CORNER_W) || (highest_corner == CORNER_S)) ? SLOPE_SW : SLOPE_NE);
|
2007-07-26 16:51:10 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FOUNDATION_INCLINED_Y:
|
2007-10-05 19:36:13 +00:00
|
|
|
*s = (((highest_corner == CORNER_S) || (highest_corner == CORNER_E)) ? SLOPE_SE : SLOPE_NW);
|
2007-07-26 16:51:10 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FOUNDATION_STEEP_LOWER:
|
2007-10-05 19:36:13 +00:00
|
|
|
*s = SlopeWithOneCornerRaised(highest_corner);
|
2007-07-26 16:51:10 +00:00
|
|
|
break;
|
|
|
|
|
2007-10-20 21:04:14 +00:00
|
|
|
case FOUNDATION_STEEP_BOTH:
|
|
|
|
*s = HalftileSlope(SlopeWithOneCornerRaised(highest_corner), highest_corner);
|
2007-07-26 16:51:10 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
|
|
|
return dz;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
uint GetPartialZ(int x, int y, Slope corners)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-10-20 16:50:48 +00:00
|
|
|
if (IsHalftileSlope(corners)) {
|
|
|
|
switch (GetHalftileSlopeCorner(corners)) {
|
|
|
|
case CORNER_W:
|
|
|
|
if (x - y >= 0) return GetSlopeMaxZ(corners);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CORNER_S:
|
|
|
|
if (x - (y ^ 0xF) >= 0) return GetSlopeMaxZ(corners);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CORNER_E:
|
|
|
|
if (y - x >= 0) return GetSlopeMaxZ(corners);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CORNER_N:
|
|
|
|
if ((y ^ 0xF) - x >= 0) return GetSlopeMaxZ(corners);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
int z = 0;
|
|
|
|
|
2007-10-20 16:50:48 +00:00
|
|
|
switch (corners & ~SLOPE_HALFTILE_MASK) {
|
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:
|
2007-04-18 22:10:36 +00:00
|
|
|
y ^= 0xF;
|
2004-08-09 17:04:08 +00:00
|
|
|
if ( (x - y) >= 0)
|
|
|
|
z = (x - y) >> 1;
|
|
|
|
break;
|
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
case SLOPE_SW:
|
2007-04-18 22:10:36 +00:00
|
|
|
z = (x >> 1) + 1;
|
2004-08-09 17:04:08 +00:00
|
|
|
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:
|
2007-04-18 22:10:36 +00:00
|
|
|
z = (y >> 1) + 1;
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
case SLOPE_WSE:
|
2004-08-09 17:04:08 +00:00
|
|
|
z = 8;
|
2007-04-18 22:10:36 +00:00
|
|
|
y ^= 0xF;
|
2004-08-09 17:04:08 +00:00
|
|
|
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:
|
2007-04-18 22:10:36 +00:00
|
|
|
z = (y ^ 0xF) >> 1;
|
2004-08-09 17:04:08 +00:00
|
|
|
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:
|
2007-04-18 22:10:36 +00:00
|
|
|
z = (x ^ 0xF) >> 1;
|
2004-08-09 17:04:08 +00:00
|
|
|
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:
|
2007-04-18 22:10:36 +00:00
|
|
|
z = 1 + ((x + y) >> 1);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
case SLOPE_STEEP_W:
|
2007-04-18 22:10:36 +00:00
|
|
|
z = 1 + ((x + (y ^ 0xF)) >> 1);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
case SLOPE_STEEP_N:
|
2007-04-18 22:10:36 +00:00
|
|
|
z = 1 + (((x ^ 0xF) + (y ^ 0xF)) >> 1);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
2004-09-08 17:44:29 +00:00
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
case SLOPE_STEEP_E:
|
2007-07-23 15:18:53 +00:00
|
|
|
z = 1 + (((x ^ 0xF) + y) >> 1);
|
2004-08-09 17:04:08 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2007-10-20 21:04:14 +00:00
|
|
|
/**
|
|
|
|
* Determine the Z height of a corner relative to TileZ.
|
|
|
|
*
|
|
|
|
* @pre The slope must not be a halftile slope.
|
|
|
|
*
|
|
|
|
* @param tileh The slope.
|
|
|
|
* @param corner The corner.
|
|
|
|
* @return Z position of corner relative to TileZ.
|
|
|
|
*/
|
|
|
|
int GetSlopeZInCorner(Slope tileh, Corner corner)
|
|
|
|
{
|
|
|
|
assert(!IsHalftileSlope(tileh));
|
|
|
|
static const int _corner_slopes[4][2] = {
|
|
|
|
{ SLOPE_W, SLOPE_STEEP_W }, { SLOPE_S, SLOPE_STEEP_S }, { SLOPE_E, SLOPE_STEEP_E }, { SLOPE_N, SLOPE_STEEP_N }
|
|
|
|
};
|
|
|
|
return ((tileh & _corner_slopes[corner][0]) != 0 ? TILE_HEIGHT : 0) + (tileh == _corner_slopes[corner][1] ? TILE_HEIGHT : 0);
|
|
|
|
}
|
|
|
|
|
2007-10-14 20:16:44 +00:00
|
|
|
/**
|
|
|
|
* Determine the Z height of the corners of a specific tile edge
|
|
|
|
*
|
2007-10-20 16:50:48 +00:00
|
|
|
* @note If a tile has a non-continuous halftile foundation, a corner can have different heights wrt. it's edges.
|
|
|
|
*
|
2007-10-14 20:16:44 +00:00
|
|
|
* @pre z1 and z2 must be initialized (typ. with TileZ). The corner heights just get added.
|
|
|
|
*
|
|
|
|
* @param tileh The slope of the tile.
|
|
|
|
* @param edge The edge of interest.
|
|
|
|
* @param z1 Gets incremented by the height of the first corner of the edge. (near corner wrt. the camera)
|
|
|
|
* @param z2 Gets incremented by the height of the second corner of the edge. (far corner wrt. the camera)
|
|
|
|
*/
|
|
|
|
void GetSlopeZOnEdge(Slope tileh, DiagDirection edge, int *z1, int *z2)
|
|
|
|
{
|
|
|
|
static const Slope corners[4][4] = {
|
|
|
|
/* corner | steep slope
|
|
|
|
* z1 z2 | z1 z2 */
|
|
|
|
{SLOPE_E, SLOPE_N, SLOPE_STEEP_E, SLOPE_STEEP_N}, // DIAGDIR_NE, z1 = E, z2 = N
|
|
|
|
{SLOPE_S, SLOPE_E, SLOPE_STEEP_S, SLOPE_STEEP_E}, // DIAGDIR_SE, z1 = S, z2 = E
|
|
|
|
{SLOPE_S, SLOPE_W, SLOPE_STEEP_S, SLOPE_STEEP_W}, // DIAGDIR_SW, z1 = S, z2 = W
|
|
|
|
{SLOPE_W, SLOPE_N, SLOPE_STEEP_W, SLOPE_STEEP_N}, // DIAGDIR_NW, z1 = W, z2 = N
|
|
|
|
};
|
|
|
|
|
2007-10-20 16:50:48 +00:00
|
|
|
int halftile_test = (IsHalftileSlope(tileh) ? SlopeWithOneCornerRaised(GetHalftileSlopeCorner(tileh)) : 0);
|
|
|
|
if (halftile_test == corners[edge][0]) *z2 += TILE_HEIGHT; // The slope is non-continuous in z2. z2 is on the upper side.
|
|
|
|
if (halftile_test == corners[edge][1]) *z1 += TILE_HEIGHT; // The slope is non-continuous in z1. z1 is on the upper side.
|
|
|
|
|
2007-10-14 20:16:44 +00:00
|
|
|
if ((tileh & corners[edge][0]) != 0) *z1 += TILE_HEIGHT; // z1 is raised
|
|
|
|
if ((tileh & corners[edge][1]) != 0) *z2 += TILE_HEIGHT; // z2 is raised
|
2007-10-20 16:50:48 +00:00
|
|
|
if ((tileh & ~SLOPE_HALFTILE_MASK) == corners[edge][2]) *z1 += TILE_HEIGHT; // z1 is highest corner of a steep slope
|
|
|
|
if ((tileh & ~SLOPE_HALFTILE_MASK) == corners[edge][3]) *z2 += TILE_HEIGHT; // z2 is highest corner of a steep slope
|
2007-10-14 20:16:44 +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);
|
2007-07-26 16:51:10 +00:00
|
|
|
Foundation f = _tile_type_procs[GetTileType(tile)]->get_foundation_proc(tile, tileh);
|
|
|
|
*z += ApplyFoundationToSlope(f, &tileh);
|
|
|
|
return tileh;
|
2006-06-24 22:19:28 +00:00
|
|
|
}
|
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;
|
2007-10-14 20:16:44 +00:00
|
|
|
|
|
|
|
int z_W_here = z_here;
|
|
|
|
int z_N_here = z_here;
|
|
|
|
GetSlopeZOnEdge(slope_here, DIAGDIR_NW, &z_W_here, &z_N_here);
|
|
|
|
|
2006-06-24 22:19:28 +00:00
|
|
|
Slope slope = GetFoundationSlope(TILE_ADDXY(tile, 0, -1), &z);
|
2007-10-14 20:16:44 +00:00
|
|
|
int z_W = z;
|
|
|
|
int z_N = z;
|
|
|
|
GetSlopeZOnEdge(slope, DIAGDIR_SE, &z_W, &z_N);
|
2006-06-24 22:19:28 +00:00
|
|
|
|
2007-10-14 20:16:44 +00:00
|
|
|
return (z_N_here > z_N) || (z_W_here > z_W);
|
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;
|
2007-10-14 20:16:44 +00:00
|
|
|
|
|
|
|
int z_E_here = z_here;
|
|
|
|
int z_N_here = z_here;
|
|
|
|
GetSlopeZOnEdge(slope_here, DIAGDIR_NE, &z_E_here, &z_N_here);
|
|
|
|
|
2006-06-24 22:19:28 +00:00
|
|
|
Slope slope = GetFoundationSlope(TILE_ADDXY(tile, -1, 0), &z);
|
2007-10-14 20:16:44 +00:00
|
|
|
int z_E = z;
|
|
|
|
int z_N = z;
|
|
|
|
GetSlopeZOnEdge(slope, DIAGDIR_SW, &z_E, &z_N);
|
2006-06-24 22:19:28 +00:00
|
|
|
|
2007-10-14 20:16:44 +00:00
|
|
|
return (z_N_here > z_N) || (z_E_here > z_E);
|
2006-06-24 22:19:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-26 16:51:10 +00:00
|
|
|
void DrawFoundation(TileInfo *ti, Foundation f)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-07-26 16:51:10 +00:00
|
|
|
if (!IsFoundation(f)) return;
|
|
|
|
|
2007-10-20 21:04:14 +00:00
|
|
|
/* Two part foundations must be drawn separately */
|
|
|
|
assert(f != FOUNDATION_STEEP_BOTH);
|
|
|
|
|
2007-10-20 20:06:55 +00:00
|
|
|
uint sprite_block = 0;
|
2006-06-24 22:19:28 +00:00
|
|
|
uint z;
|
2007-07-26 16:51:10 +00:00
|
|
|
Slope slope = GetFoundationSlope(ti->tile, &z);
|
2004-08-13 18:27:33 +00:00
|
|
|
|
2007-10-20 20:06:55 +00:00
|
|
|
/* Select the needed block of foundations sprites
|
|
|
|
* Block 0: Walls at NW and NE edge
|
|
|
|
* Block 1: Wall at NE edge
|
|
|
|
* Block 2: Wall at NW edge
|
|
|
|
* Block 3: No walls at NW or NE edge
|
|
|
|
*/
|
|
|
|
if (!HasFoundationNW(ti->tile, slope, z)) sprite_block += 1;
|
|
|
|
if (!HasFoundationNE(ti->tile, slope, z)) sprite_block += 2;
|
2004-08-13 11:28:59 +00:00
|
|
|
|
2007-10-20 20:06:55 +00:00
|
|
|
/* Use the original slope sprites if NW and NE borders should be visible */
|
|
|
|
SpriteID leveled_base = (sprite_block == 0 ? (int)SPR_FOUNDATION_BASE : (SPR_SLOPES_VIRTUAL_BASE + sprite_block * SPR_TRKFOUND_BLOCK_SIZE));
|
|
|
|
SpriteID inclined_base = SPR_SLOPES_VIRTUAL_BASE + SPR_SLOPES_INCLINED_OFFSET + sprite_block * SPR_TRKFOUND_BLOCK_SIZE;
|
2007-10-20 21:04:14 +00:00
|
|
|
SpriteID halftile_base = SPR_HALFTILE_FOUNDATION_BASE + sprite_block * SPR_HALFTILE_BLOCK_SIZE;
|
2004-08-13 11:28:59 +00:00
|
|
|
|
2007-10-20 20:06:55 +00:00
|
|
|
if (IsSteepSlope(ti->tileh)) {
|
2007-10-20 21:04:14 +00:00
|
|
|
if (!IsNonContinuousFoundation(f)) {
|
|
|
|
/* Lower part of foundation */
|
|
|
|
AddSortableSpriteToDraw(
|
|
|
|
leveled_base + (ti->tileh & ~SLOPE_STEEP), PAL_NONE, ti->x, ti->y, 16, 16, 7, ti->z
|
|
|
|
);
|
|
|
|
}
|
2007-07-26 16:51:10 +00:00
|
|
|
|
2007-10-05 19:36:13 +00:00
|
|
|
Corner highest_corner = GetHighestSlopeCorner(ti->tileh);
|
2007-07-26 16:51:10 +00:00
|
|
|
ti->z += ApplyFoundationToSlope(f, &ti->tileh);
|
|
|
|
|
|
|
|
if (IsInclinedFoundation(f)) {
|
|
|
|
/* inclined foundation */
|
|
|
|
byte inclined = highest_corner * 2 + (f == FOUNDATION_INCLINED_Y ? 1 : 0);
|
|
|
|
|
2007-10-20 20:06:55 +00:00
|
|
|
AddSortableSpriteToDraw(inclined_base + inclined, PAL_NONE, ti->x, ti->y, 16, 16, 1, ti->z);
|
2006-08-12 12:56:45 +00:00
|
|
|
OffsetGroundSprite(31, 9);
|
2007-10-20 21:04:14 +00:00
|
|
|
} else if (f == FOUNDATION_STEEP_LOWER) {
|
2007-03-03 04:04:22 +00:00
|
|
|
/* one corner raised */
|
2006-08-12 12:56:45 +00:00
|
|
|
OffsetGroundSprite(31, 1);
|
2007-10-20 21:04:14 +00:00
|
|
|
} else {
|
|
|
|
/* halftile foundation */
|
|
|
|
int x_bb = (((highest_corner == CORNER_W) || (highest_corner == CORNER_S)) ? 8 : 0);
|
|
|
|
int y_bb = (((highest_corner == CORNER_S) || (highest_corner == CORNER_E)) ? 8 : 0);
|
|
|
|
|
|
|
|
AddSortableSpriteToDraw(halftile_base + highest_corner, PAL_NONE, ti->x + x_bb, ti->y + y_bb, 8, 8, 7, ti->z + TILE_HEIGHT);
|
|
|
|
OffsetGroundSprite(31, 9);
|
2006-08-12 12:56:45 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2007-07-26 16:51:10 +00:00
|
|
|
if (IsLeveledFoundation(f)) {
|
2007-10-20 20:06:55 +00:00
|
|
|
/* leveled foundation */
|
|
|
|
AddSortableSpriteToDraw(leveled_base + ti->tileh, PAL_NONE, ti->x, ti->y, 16, 16, 7, ti->z);
|
2006-08-12 12:56:45 +00:00
|
|
|
OffsetGroundSprite(31, 1);
|
2007-10-20 21:04:14 +00:00
|
|
|
} else if (IsNonContinuousFoundation(f)) {
|
|
|
|
/* halftile foundation */
|
|
|
|
Corner halftile_corner = GetHalftileFoundationCorner(f);
|
|
|
|
int x_bb = (((halftile_corner == CORNER_W) || (halftile_corner == CORNER_S)) ? 8 : 0);
|
|
|
|
int y_bb = (((halftile_corner == CORNER_S) || (halftile_corner == CORNER_E)) ? 8 : 0);
|
|
|
|
|
|
|
|
AddSortableSpriteToDraw(halftile_base + halftile_corner, PAL_NONE, ti->x + x_bb, ti->y + y_bb, 8, 8, 7, ti->z);
|
|
|
|
OffsetGroundSprite(31, 9);
|
|
|
|
} else if (IsSpecialRailFoundation(f)) {
|
|
|
|
/* anti-zig-zag foundation */
|
|
|
|
SpriteID spr;
|
|
|
|
if (ti->tileh == SLOPE_NS || ti->tileh == SLOPE_EW) {
|
|
|
|
/* half of leveled foundation under track corner */
|
|
|
|
spr = leveled_base + SlopeWithThreeCornersRaised(GetRailFoundationCorner(f));
|
|
|
|
} else {
|
|
|
|
/* tile-slope = sloped along X/Y, foundation-slope = three corners raised */
|
|
|
|
spr = inclined_base + 2 * GetRailFoundationCorner(f) + ((ti->tileh == SLOPE_SW || ti->tileh == SLOPE_NE) ? 1 : 0);
|
|
|
|
}
|
|
|
|
AddSortableSpriteToDraw(spr, PAL_NONE, ti->x, ti->y, 16, 16, 7, ti->z);
|
|
|
|
OffsetGroundSprite(31, 9);
|
2006-08-12 12:56:45 +00:00
|
|
|
} else {
|
2007-03-03 04:04:22 +00:00
|
|
|
/* inclined foundation */
|
2007-07-26 16:51:10 +00:00
|
|
|
byte inclined = GetHighestSlopeCorner(ti->tileh) * 2 + (f == FOUNDATION_INCLINED_Y ? 1 : 0);
|
|
|
|
|
2007-10-20 20:06:55 +00:00
|
|
|
AddSortableSpriteToDraw(inclined_base + inclined, PAL_NONE, ti->x, ti->y, 16, 16, 1, ti->z);
|
2006-08-12 12:56:45 +00:00
|
|
|
OffsetGroundSprite(31, 9);
|
2006-08-10 14:44:32 +00:00
|
|
|
}
|
2007-07-26 16:51:10 +00:00
|
|
|
ti->z += ApplyFoundationToSlope(f, &ti->tileh);
|
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
|
|
|
}
|
|
|
|
|
2007-05-24 22:41:50 +00:00
|
|
|
uint32 GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-05-24 22:41:50 +00:00
|
|
|
return _tile_type_procs[GetTileType(tile)]->get_tile_track_status_proc(tile, mode, sub_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
|
|
|
}
|
|
|
|
|
2007-03-20 13:47:00 +00:00
|
|
|
/**
|
|
|
|
* Has a snow line table already been loaded.
|
|
|
|
* @return true if the table has been loaded already.
|
|
|
|
*/
|
|
|
|
bool IsSnowLineSet(void)
|
|
|
|
{
|
|
|
|
return _snow_line != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a variable snow line, as loaded from a newgrf file.
|
|
|
|
* @param table the 12 * 32 byte table containing the snowline for each day
|
|
|
|
*/
|
|
|
|
void SetSnowLine(byte table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS])
|
|
|
|
{
|
|
|
|
_snow_line = CallocT<SnowLine>(1);
|
|
|
|
memcpy(_snow_line->table, table, sizeof(_snow_line->table));
|
|
|
|
|
|
|
|
for (uint i = 0; i < SNOW_LINE_MONTHS; i++) {
|
|
|
|
for (uint j = 0; j < SNOW_LINE_DAYS; j++) {
|
|
|
|
_snow_line->highest_value = max(_snow_line->highest_value, table[i][j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the current snow line, either variable or static.
|
|
|
|
* @return the snow line height.
|
|
|
|
*/
|
|
|
|
byte GetSnowLine(void)
|
|
|
|
{
|
|
|
|
if (_snow_line == NULL) return _opt.snow_line;
|
|
|
|
|
|
|
|
YearMonthDay ymd;
|
|
|
|
ConvertDateToYMD(_date, &ymd);
|
|
|
|
return _snow_line->table[ymd.month][ymd.day];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the highest possible snow line height, either variable or static.
|
|
|
|
* @return the highest snow line height.
|
|
|
|
*/
|
|
|
|
byte HighestSnowLine(void)
|
|
|
|
{
|
|
|
|
return _snow_line == NULL ? _opt.snow_line : _snow_line->highest_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear the variable snow line table and free the memory.
|
|
|
|
*/
|
|
|
|
void ClearSnowLine(void)
|
|
|
|
{
|
|
|
|
free(_snow_line);
|
|
|
|
_snow_line = NULL;
|
|
|
|
}
|
|
|
|
|
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
|
2007-03-03 04:04:22 +00:00
|
|
|
* @param flags of operation to conduct
|
2005-05-07 10:26:12 +00:00
|
|
|
* @param p1 unused
|
|
|
|
* @param p2 unused
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost 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
|
2007-03-03 04:04:22 +00:00
|
|
|
* @param flags of operation to conduct
|
2005-05-12 00:11:37 +00:00
|
|
|
* @param p2 unused
|
|
|
|
*/
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost CmdClearArea(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, ret, money;
|
2006-04-10 07:15:58 +00:00
|
|
|
int ex;
|
|
|
|
int ey;
|
2007-04-18 22:10:36 +00:00
|
|
|
int sx, sy;
|
|
|
|
int x, y;
|
2004-08-09 17:04:08 +00:00
|
|
|
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);
|
|
|
|
|
2007-03-03 04:04:22 +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);
|
2007-02-22 08:43:02 +00:00
|
|
|
if (ex < sx) Swap(ex, sx);
|
|
|
|
if (ey < sy) Swap(ey, sy);
|
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
|
|
|
|
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
|
|
|
success = true;
|
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
2007-06-18 19:53:50 +00:00
|
|
|
money.AddCost(-ret.GetCost());
|
|
|
|
if (ret.GetCost() > 0 && money.GetCost() < 0) {
|
|
|
|
_additional_cash_required = ret.GetCost();
|
|
|
|
return cost;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
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
|
|
|
|
2007-03-03 04:04:22 +00:00
|
|
|
/* draw explosion animation... */
|
2005-05-12 00:11:37 +00:00
|
|
|
if ((x == sx || x == ex) && (y == sy || y == ey)) {
|
2007-03-03 04:04:22 +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
|
|
|
}
|
|
|
|
}
|
2007-06-18 19:53:50 +00:00
|
|
|
cost.AddCost(ret);
|
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)
|
2007-04-18 22:10:36 +00:00
|
|
|
#define TILELOOP_ASSERTMASK ((TILELOOP_SIZE - 1) + ((TILELOOP_SIZE - 1) << MapLogX()))
|
2005-01-07 17:40:23 +00:00
|
|
|
#define TILELOOP_CHKMASK (((1 << (MapLogX() - TILELOOP_BITS))-1) << TILELOOP_BITS)
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void RunTileLoop()
|
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) {
|
2007-03-03 04:04:22 +00:00
|
|
|
tile += TILELOOP_SIZE; // no overflow
|
2004-08-09 17:04:08 +00:00
|
|
|
} 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;
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void InitializeLandscape()
|
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
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void ConvertGroundTilesIntoWaterTiles()
|
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:
|
2007-11-15 18:07:30 +00:00
|
|
|
MakeShore(tile);
|
|
|
|
break;
|
|
|
|
|
(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 SLOPE_NW:
|
2007-11-15 18:07:30 +00:00
|
|
|
if (GetTileSlope(TileAddByDiagDir(tile, DIAGDIR_SE), NULL) != SLOPE_SE) MakeShore(tile);
|
|
|
|
break;
|
|
|
|
|
(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 SLOPE_SW:
|
2007-11-15 18:07:30 +00:00
|
|
|
if (GetTileSlope(TileAddByDiagDir(tile, DIAGDIR_NE), NULL) != SLOPE_NE) MakeShore(tile);
|
|
|
|
break;
|
|
|
|
|
(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 SLOPE_SE:
|
2007-11-15 18:07:30 +00:00
|
|
|
if (GetTileSlope(TileAddByDiagDir(tile, DIAGDIR_NW), NULL) != SLOPE_NW) MakeShore(tile);
|
|
|
|
break;
|
|
|
|
|
(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 SLOPE_NE:
|
2007-11-15 18:07:30 +00:00
|
|
|
if (GetTileSlope(TileAddByDiagDir(tile, DIAGDIR_SW), NULL) != SLOPE_SW) MakeShore(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
|
|
|
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"
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void CreateDesertOrRainForest()
|
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) {
|
2007-03-22 03:42:43 +00:00
|
|
|
SetGeneratingWorldProgress(GWP_LANDSCAPE, (_opt.landscape == LT_TROPIC) ? 1 + gwp_desert_amount : 1);
|
(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
|
|
|
LoadHeightmap(_file_to_saveload.name);
|
|
|
|
IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
|
|
|
|
} else if (_patches.land_generator == LG_TERRAGENESIS) {
|
2007-03-22 03:42:43 +00:00
|
|
|
SetGeneratingWorldProgress(GWP_LANDSCAPE, (_opt.landscape == LT_TROPIC) ? 3 + gwp_desert_amount : 3);
|
(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
|
|
|
GenerateTerrainPerlin();
|
|
|
|
} else {
|
|
|
|
switch (_opt.landscape) {
|
2007-03-22 03:42:43 +00:00
|
|
|
case LT_ARCTIC:
|
(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
|
|
|
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
|
|
|
|
2007-03-22 03:42:43 +00:00
|
|
|
case LT_TROPIC:
|
(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
|
|
|
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();
|
|
|
|
|
2007-03-22 03:42:43 +00:00
|
|
|
if (_opt.landscape == LT_TROPIC) CreateDesertOrRainForest();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void OnTick_Town();
|
|
|
|
void OnTick_Trees();
|
|
|
|
void OnTick_Station();
|
|
|
|
void OnTick_Industry();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void OnTick_Players();
|
|
|
|
void OnTick_Train();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void CallLandscapeTick()
|
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
|
|
|
}
|