2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file landscape.cpp Functions related to the landscape (slopes etc.). */
|
|
|
|
|
2008-10-19 15:39:12 +00:00
|
|
|
/** @defgroup SnowLineGroup Snowline functions and data structures */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.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-02-10 05:43:30 +00:00
|
|
|
#include "spritecache.h"
|
2008-01-09 09:57:48 +00:00
|
|
|
#include "viewport_func.h"
|
2007-12-21 21:50:46 +00:00
|
|
|
#include "command_func.h"
|
2007-03-20 13:47:00 +00:00
|
|
|
#include "landscape.h"
|
2006-03-05 10:19:33 +00:00
|
|
|
#include "void_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-28 03:14:55 +00:00
|
|
|
#include "fios.h"
|
2007-12-26 13:50:40 +00:00
|
|
|
#include "date_func.h"
|
2008-01-22 17:48:08 +00:00
|
|
|
#include "water.h"
|
2008-04-20 11:12:07 +00:00
|
|
|
#include "effectvehicle_func.h"
|
2008-05-07 09:07:19 +00:00
|
|
|
#include "landscape_type.h"
|
2009-07-01 14:51:05 +00:00
|
|
|
#include "animated_tile_func.h"
|
2010-01-15 16:41:15 +00:00
|
|
|
#include "core/random_func.hpp"
|
2010-09-03 21:50:51 +00:00
|
|
|
#include "object_base.h"
|
2011-01-04 22:50:09 +00:00
|
|
|
#include "company_func.h"
|
2017-02-05 18:07:10 +00:00
|
|
|
#include "tunnelbridge_map.h"
|
2011-08-20 14:14:17 +00:00
|
|
|
#include "pathfinder/npf/aystar.h"
|
2023-06-07 22:29:52 +00:00
|
|
|
#include "sl/saveload.h"
|
2018-07-19 19:17:07 +00:00
|
|
|
#include "framerate_type.h"
|
2020-10-16 21:12:57 +00:00
|
|
|
#include "town.h"
|
2017-02-08 00:18:09 +00:00
|
|
|
#include "3rdparty/cpp-btree/btree_set.h"
|
2017-08-16 17:30:06 +00:00
|
|
|
#include "scope_info.h"
|
2023-08-18 17:48:12 +00:00
|
|
|
#include "core/ring_buffer.hpp"
|
2023-08-28 14:17:53 +00:00
|
|
|
#include "network/network_sync.h"
|
2021-03-24 13:48:12 +00:00
|
|
|
#include <array>
|
2011-08-20 14:14:17 +00:00
|
|
|
#include <list>
|
2014-02-06 20:51:01 +00:00
|
|
|
#include <set>
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2010-09-05 13:31:39 +00:00
|
|
|
#include "table/strings.h"
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/sprites.h"
|
|
|
|
|
2023-08-17 13:40:39 +00:00
|
|
|
#include INCLUDE_FOR_PREFETCH_NTA
|
|
|
|
|
2014-04-23 20:13:33 +00:00
|
|
|
#include "safeguards.h"
|
|
|
|
|
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,
|
2010-08-09 06:48:52 +00:00
|
|
|
_tile_type_void_procs,
|
2004-08-09 17:04:08 +00:00
|
|
|
_tile_type_industry_procs,
|
|
|
|
_tile_type_tunnelbridge_procs,
|
2010-08-08 10:59:30 +00:00
|
|
|
_tile_type_object_procs;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Tile callback functions for each type of tile.
|
2008-10-19 15:39:12 +00:00
|
|
|
* @ingroup TileCallbackGroup
|
2010-08-01 19:44:49 +00:00
|
|
|
* @see TileType
|
|
|
|
*/
|
2004-08-09 17:04:08 +00:00
|
|
|
const TileTypeProcs * const _tile_type_procs[16] = {
|
2008-10-19 15:39:12 +00:00
|
|
|
&_tile_type_clear_procs, ///< Callback functions for MP_CLEAR tiles
|
|
|
|
&_tile_type_rail_procs, ///< Callback functions for MP_RAILWAY tiles
|
|
|
|
&_tile_type_road_procs, ///< Callback functions for MP_ROAD tiles
|
|
|
|
&_tile_type_town_procs, ///< Callback functions for MP_HOUSE tiles
|
|
|
|
&_tile_type_trees_procs, ///< Callback functions for MP_TREES tiles
|
|
|
|
&_tile_type_station_procs, ///< Callback functions for MP_STATION tiles
|
|
|
|
&_tile_type_water_procs, ///< Callback functions for MP_WATER tiles
|
2010-08-09 06:48:52 +00:00
|
|
|
&_tile_type_void_procs, ///< Callback functions for MP_VOID tiles
|
2008-10-19 15:39:12 +00:00
|
|
|
&_tile_type_industry_procs, ///< Callback functions for MP_INDUSTRY tiles
|
|
|
|
&_tile_type_tunnelbridge_procs, ///< Callback functions for MP_TUNNELBRIDGE tiles
|
2010-08-08 10:59:30 +00:00
|
|
|
&_tile_type_object_procs, ///< Callback functions for MP_OBJECT tiles
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2010-07-19 17:00:54 +00:00
|
|
|
/** landscape slope => sprite */
|
|
|
|
extern const byte _slope_to_sprite_offset[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
|
|
|
};
|
|
|
|
|
2008-10-19 15:39:12 +00:00
|
|
|
/**
|
|
|
|
* Description of the snow line throughout the year.
|
|
|
|
*
|
2019-04-10 21:07:06 +00:00
|
|
|
* If it is \c nullptr, a static snowline height is used, as set by \c _settings_game.game_creation.snow_line_height.
|
2010-10-30 17:51:07 +00:00
|
|
|
* Otherwise it points to a table loaded from a newGRF file that describes the variable snowline.
|
2008-10-19 15:39:12 +00:00
|
|
|
* @ingroup SnowLineGroup
|
2010-08-01 19:44:49 +00:00
|
|
|
* @see GetSnowLine() GameCreationSettings
|
|
|
|
*/
|
2019-04-10 21:07:06 +00:00
|
|
|
static SnowLine *_snow_line = nullptr;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2021-06-13 05:36:41 +00:00
|
|
|
/** The current spring during river generation */
|
|
|
|
static TileIndex _current_spring = INVALID_TILE;
|
|
|
|
|
|
|
|
/** The current estuary during river generation when one river flows into another */
|
|
|
|
static TileIndex _current_estuary = INVALID_TILE;
|
|
|
|
|
|
|
|
/** Whether the current river is a big river that others flow into */
|
|
|
|
static bool _is_main_river = false;
|
|
|
|
|
2021-02-21 22:02:58 +00:00
|
|
|
byte _cached_snowline = 0;
|
2022-04-29 16:10:18 +00:00
|
|
|
byte _cached_highest_snowline = 0;
|
|
|
|
byte _cached_lowest_snowline = 0;
|
2022-04-30 23:41:08 +00:00
|
|
|
byte _cached_tree_placement_highest_snowline = 0;
|
2021-02-21 22:02:58 +00:00
|
|
|
|
2019-01-13 19:52:04 +00:00
|
|
|
/**
|
|
|
|
* Map 2D viewport or smallmap coordinate to 3D world or tile coordinate.
|
|
|
|
* Function takes into account height of tiles and foundations.
|
|
|
|
*
|
|
|
|
* @param x X viewport 2D coordinate.
|
|
|
|
* @param y Y viewport 2D coordinate.
|
|
|
|
* @param clamp_to_map Clamp the coordinate outside of the map to the closest, non-void tile within the map.
|
2019-01-13 19:54:21 +00:00
|
|
|
* @param[out] clamped Whether coordinates were clamped.
|
2019-01-13 19:52:04 +00:00
|
|
|
* @return 3D world coordinate of point visible at the given screen coordinate (3D perspective).
|
|
|
|
*
|
|
|
|
* @note Inverse of #RemapCoords2 function. Smaller values may get rounded.
|
|
|
|
* @see InverseRemapCoords
|
|
|
|
*/
|
2019-01-13 19:54:21 +00:00
|
|
|
Point InverseRemapCoords2(int x, int y, bool clamp_to_map, bool *clamped)
|
2019-01-13 19:52:04 +00:00
|
|
|
{
|
2019-04-10 21:07:06 +00:00
|
|
|
if (clamped != nullptr) *clamped = false; // Not clamping yet.
|
2019-01-13 19:54:21 +00:00
|
|
|
|
2019-01-13 19:52:04 +00:00
|
|
|
/* Initial x/y world coordinate is like if the landscape
|
|
|
|
* was completely flat on height 0. */
|
|
|
|
Point pt = InverseRemapCoords(x, y);
|
|
|
|
|
|
|
|
const uint min_coord = _settings_game.construction.freeform_edges ? TILE_SIZE : 0;
|
|
|
|
const uint max_x = MapMaxX() * TILE_SIZE - 1;
|
|
|
|
const uint max_y = MapMaxY() * TILE_SIZE - 1;
|
|
|
|
|
|
|
|
if (clamp_to_map) {
|
|
|
|
/* Bring the coordinates near to a valid range. At the top we allow a number
|
|
|
|
* of extra tiles. This is mostly due to the tiles on the north side of
|
|
|
|
* the map possibly being drawn higher due to the extra height levels. */
|
2021-03-24 08:42:54 +00:00
|
|
|
int extra_tiles = CeilDiv(_settings_game.construction.map_height_limit * TILE_HEIGHT, TILE_PIXELS);
|
2019-01-13 19:54:21 +00:00
|
|
|
Point old_pt = pt;
|
2019-01-13 19:52:04 +00:00
|
|
|
pt.x = Clamp(pt.x, -extra_tiles * TILE_SIZE, max_x);
|
|
|
|
pt.y = Clamp(pt.y, -extra_tiles * TILE_SIZE, max_y);
|
2019-04-10 21:07:06 +00:00
|
|
|
if (clamped != nullptr) *clamped = (pt.x != old_pt.x) || (pt.y != old_pt.y);
|
2019-01-13 19:52:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Now find the Z-world coordinate by fix point iteration.
|
|
|
|
* This is a bit tricky because the tile height is non-continuous at foundations.
|
|
|
|
* The clicked point should be approached from the back, otherwise there are regions that are not clickable.
|
|
|
|
* (FOUNDATION_HALFTILE_LOWER on SLOPE_STEEP_S hides north halftile completely)
|
|
|
|
* So give it a z-malus of 4 in the first iterations. */
|
|
|
|
int z = 0;
|
2019-01-13 19:58:48 +00:00
|
|
|
if (clamp_to_map) {
|
2021-01-08 10:16:18 +00:00
|
|
|
for (int i = 0; i < 5; i++) z = GetSlopePixelZ(Clamp(pt.x + std::max(z, 4) - 4, min_coord, max_x), Clamp(pt.y + std::max(z, 4) - 4, min_coord, max_y)) / 2;
|
|
|
|
for (int m = 3; m > 0; m--) z = GetSlopePixelZ(Clamp(pt.x + std::max(z, m) - m, min_coord, max_x), Clamp(pt.y + std::max(z, m) - m, min_coord, max_y)) / 2;
|
2019-01-13 19:58:48 +00:00
|
|
|
for (int i = 0; i < 5; i++) z = GetSlopePixelZ(Clamp(pt.x + z, min_coord, max_x), Clamp(pt.y + z, min_coord, max_y)) / 2;
|
|
|
|
} else {
|
2021-01-08 10:16:18 +00:00
|
|
|
for (int i = 0; i < 5; i++) z = GetSlopePixelZOutsideMap(pt.x + std::max(z, 4) - 4, pt.y + std::max(z, 4) - 4) / 2;
|
|
|
|
for (int m = 3; m > 0; m--) z = GetSlopePixelZOutsideMap(pt.x + std::max(z, m) - m, pt.y + std::max(z, m) - m) / 2;
|
2019-01-13 19:58:48 +00:00
|
|
|
for (int i = 0; i < 5; i++) z = GetSlopePixelZOutsideMap(pt.x + z, pt.y + z ) / 2;
|
|
|
|
}
|
2019-01-13 19:52:04 +00:00
|
|
|
|
|
|
|
pt.x += z;
|
|
|
|
pt.y += z;
|
|
|
|
if (clamp_to_map) {
|
2019-01-13 19:54:21 +00:00
|
|
|
Point old_pt = pt;
|
2019-01-13 19:52:04 +00:00
|
|
|
pt.x = Clamp(pt.x, min_coord, max_x);
|
|
|
|
pt.y = Clamp(pt.y, min_coord, max_y);
|
2019-04-10 21:07:06 +00:00
|
|
|
if (clamped != nullptr) *clamped = *clamped || (pt.x != old_pt.x) || (pt.y != old_pt.y);
|
2019-01-13 19:52:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return pt;
|
|
|
|
}
|
|
|
|
|
2007-07-26 16:51:10 +00:00
|
|
|
/**
|
2008-10-13 03:26:48 +00:00
|
|
|
* Applies a foundation to a slope.
|
2007-07-26 16:51:10 +00:00
|
|
|
*
|
|
|
|
* @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.
|
|
|
|
*/
|
2011-11-04 10:20:24 +00:00
|
|
|
uint ApplyFoundationToSlope(Foundation f, Slope *s)
|
2007-07-26 16:51:10 +00:00
|
|
|
{
|
|
|
|
if (!IsFoundation(f)) return 0;
|
|
|
|
|
|
|
|
if (IsLeveledFoundation(f)) {
|
2011-11-04 10:20:24 +00:00
|
|
|
uint dz = 1 + (IsSteepSlope(*s) ? 1 : 0);
|
2007-07-26 16:51:10 +00:00
|
|
|
*s = SLOPE_FLAT;
|
2008-06-12 21:36:56 +00:00
|
|
|
return dz;
|
2007-07-26 16:51:10 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-11-04 10:20:24 +00:00
|
|
|
uint dz = IsSteepSlope(*s) ? 1 : 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;
|
|
|
|
}
|
|
|
|
|
2023-03-12 17:14:44 +00:00
|
|
|
/**
|
|
|
|
* Return world \c Z coordinate of a given point of a tile. Normally this is the
|
|
|
|
* Z of the ground/foundation at the given location, but in some cases the
|
|
|
|
* ground/foundation can differ from the Z coordinate that the (ground) vehicle
|
|
|
|
* passing over it would take. For example when entering a tunnel or bridge.
|
|
|
|
*
|
|
|
|
* @param x World X coordinate in tile "units".
|
|
|
|
* @param y World Y coordinate in tile "units".
|
|
|
|
* @param ground_vehicle Whether to get the Z coordinate of the ground vehicle, or the ground.
|
|
|
|
* @return World Z coordinate at tile ground (vehicle) level, including slopes and foundations.
|
|
|
|
*/
|
|
|
|
int GetSlopePixelZ(int x, int y, bool ground_vehicle)
|
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
|
|
|
|
2023-03-12 17:14:44 +00:00
|
|
|
return _tile_type_procs[GetTileType(tile)]->get_slope_z_proc(tile, x, y, ground_vehicle);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2019-01-13 19:58:48 +00:00
|
|
|
/**
|
|
|
|
* Return world \c z coordinate of a given point of a tile,
|
|
|
|
* also for tiles outside the map (virtual "black" tiles).
|
|
|
|
*
|
2019-09-29 20:27:32 +00:00
|
|
|
* @param x World X coordinate in tile "units", may be outside the map.
|
|
|
|
* @param y World Y coordinate in tile "units", may be outside the map.
|
2019-01-13 19:58:48 +00:00
|
|
|
* @return World Z coordinate at tile ground level, including slopes and foundations.
|
|
|
|
*/
|
|
|
|
int GetSlopePixelZOutsideMap(int x, int y)
|
|
|
|
{
|
|
|
|
if (IsInsideBS(x, 0, MapSizeX() * TILE_SIZE) && IsInsideBS(y, 0, MapSizeY() * TILE_SIZE)) {
|
2023-03-12 17:14:44 +00:00
|
|
|
return GetSlopePixelZ(x, y, false);
|
2019-01-13 19:58:48 +00:00
|
|
|
} else {
|
2023-03-12 17:14:44 +00:00
|
|
|
return _tile_type_procs[MP_VOID]->get_slope_z_proc(INVALID_TILE, x, y, false);
|
2019-01-13 19:58:48 +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.
|
|
|
|
*/
|
2011-11-04 10:20:24 +00:00
|
|
|
int GetSlopeZInCorner(Slope tileh, Corner corner)
|
2007-10-20 21:04:14 +00:00
|
|
|
{
|
|
|
|
assert(!IsHalftileSlope(tileh));
|
2011-11-04 10:20:24 +00:00
|
|
|
return ((tileh & SlopeWithOneCornerRaised(corner)) != 0 ? 1 : 0) + (tileh == SteepSlope(corner) ? 1 : 0);
|
2007-10-20 21:04:14 +00:00
|
|
|
}
|
|
|
|
|
2007-10-14 20:16:44 +00:00
|
|
|
/**
|
|
|
|
* Determine the Z height of the corners of a specific tile edge
|
|
|
|
*
|
2010-04-12 14:12:47 +00:00
|
|
|
* @note If a tile has a non-continuous halftile foundation, a corner can have different heights wrt. its edges.
|
2007-10-20 16:50:48 +00:00
|
|
|
*
|
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)
|
|
|
|
*/
|
2011-11-04 10:18:13 +00:00
|
|
|
void GetSlopePixelZOnEdge(Slope tileh, DiagDirection edge, int *z1, int *z2)
|
2007-10-14 20:16:44 +00:00
|
|
|
{
|
|
|
|
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
|
2008-01-25 15:47:58 +00:00
|
|
|
if (RemoveHalftileSlope(tileh) == corners[edge][2]) *z1 += TILE_HEIGHT; // z1 is highest corner of a steep slope
|
|
|
|
if (RemoveHalftileSlope(tileh) == 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
|
|
|
|
2023-02-25 22:12:31 +00:00
|
|
|
Slope GetFoundationSlopeFromTileSlope(TileIndex tile, Slope tileh, int *z)
|
|
|
|
{
|
|
|
|
Foundation f = _tile_type_procs[GetTileType(tile)]->get_foundation_proc(tile, tileh);
|
|
|
|
uint z_inc = ApplyFoundationToSlope(f, &tileh);
|
|
|
|
if (z != nullptr) *z += z_inc;
|
|
|
|
return tileh;
|
|
|
|
}
|
|
|
|
|
2008-01-25 15:47:58 +00:00
|
|
|
/**
|
|
|
|
* Get slope of a tile on top of a (possible) foundation
|
2013-10-12 22:01:21 +00:00
|
|
|
* If a tile does not have a foundation, the function returns the same as GetTileSlope.
|
2008-01-25 15:47:58 +00:00
|
|
|
*
|
|
|
|
* @param tile The tile of interest.
|
2019-04-10 21:07:06 +00:00
|
|
|
* @param z returns the z of the foundation slope. (Can be nullptr, if not needed)
|
2008-01-25 15:47:58 +00:00
|
|
|
* @return The slope on top of the foundation.
|
|
|
|
*/
|
2011-11-04 11:30:37 +00:00
|
|
|
Slope GetFoundationSlope(TileIndex tile, int *z)
|
2004-08-13 11:28:59 +00:00
|
|
|
{
|
2011-11-04 10:20:24 +00:00
|
|
|
Slope tileh = GetTileSlope(tile, z);
|
2023-02-25 22:12:31 +00:00
|
|
|
return GetFoundationSlopeFromTileSlope(tile, tileh, z);
|
2006-06-24 22:19:28 +00:00
|
|
|
}
|
2004-08-13 18:27:33 +00:00
|
|
|
|
2006-06-24 22:19:28 +00:00
|
|
|
|
2010-01-03 22:44:57 +00:00
|
|
|
bool HasFoundationNW(TileIndex tile, Slope slope_here, uint z_here)
|
2006-06-24 22:19:28 +00:00
|
|
|
{
|
2018-07-03 18:09:10 +00:00
|
|
|
if (IsCustomBridgeHeadTile(tile) && GetTunnelBridgeDirection(tile) == DIAGDIR_NW) return false;
|
2017-02-05 18:07:10 +00:00
|
|
|
|
2011-11-04 11:30:37 +00:00
|
|
|
int z;
|
2007-10-14 20:16:44 +00:00
|
|
|
|
|
|
|
int z_W_here = z_here;
|
|
|
|
int z_N_here = z_here;
|
2011-11-04 10:18:13 +00:00
|
|
|
GetSlopePixelZOnEdge(slope_here, DIAGDIR_NW, &z_W_here, &z_N_here);
|
2007-10-14 20:16:44 +00:00
|
|
|
|
2011-11-04 10:18:13 +00:00
|
|
|
Slope slope = GetFoundationPixelSlope(TILE_ADDXY(tile, 0, -1), &z);
|
2007-10-14 20:16:44 +00:00
|
|
|
int z_W = z;
|
|
|
|
int z_N = z;
|
2011-11-04 10:18:13 +00:00
|
|
|
GetSlopePixelZOnEdge(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
|
|
|
|
2010-01-03 22:44:57 +00:00
|
|
|
bool HasFoundationNE(TileIndex tile, Slope slope_here, uint z_here)
|
2006-06-24 22:19:28 +00:00
|
|
|
{
|
2018-07-03 18:09:10 +00:00
|
|
|
if (IsCustomBridgeHeadTile(tile) && GetTunnelBridgeDirection(tile) == DIAGDIR_NE) return false;
|
2017-02-05 18:07:10 +00:00
|
|
|
|
2011-11-04 11:30:37 +00:00
|
|
|
int z;
|
2007-10-14 20:16:44 +00:00
|
|
|
|
|
|
|
int z_E_here = z_here;
|
|
|
|
int z_N_here = z_here;
|
2011-11-04 10:18:13 +00:00
|
|
|
GetSlopePixelZOnEdge(slope_here, DIAGDIR_NE, &z_E_here, &z_N_here);
|
2007-10-14 20:16:44 +00:00
|
|
|
|
2011-11-04 10:18:13 +00:00
|
|
|
Slope slope = GetFoundationPixelSlope(TILE_ADDXY(tile, -1, 0), &z);
|
2007-10-14 20:16:44 +00:00
|
|
|
int z_E = z;
|
|
|
|
int z_N = z;
|
2011-11-04 10:18:13 +00:00
|
|
|
GetSlopePixelZOnEdge(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
|
|
|
}
|
|
|
|
|
2008-10-19 15:39:12 +00:00
|
|
|
/**
|
|
|
|
* Draw foundation \a f at tile \a ti. Updates \a ti.
|
|
|
|
* @param ti Tile to draw foundation on
|
|
|
|
* @param f Foundation to draw
|
|
|
|
*/
|
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;
|
2011-11-04 11:30:37 +00:00
|
|
|
int z;
|
2011-11-04 10:18:13 +00:00
|
|
|
Slope slope = GetFoundationPixelSlope(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(
|
2022-12-23 14:47:11 +00:00
|
|
|
leveled_base + (ti->tileh & ~SLOPE_STEEP), PAL_NONE, ti->x, ti->y, TILE_SIZE, TILE_SIZE, TILE_HEIGHT - 1, ti->z
|
2007-10-20 21:04:14 +00:00
|
|
|
);
|
|
|
|
}
|
2007-07-26 16:51:10 +00:00
|
|
|
|
2007-10-05 19:36:13 +00:00
|
|
|
Corner highest_corner = GetHighestSlopeCorner(ti->tileh);
|
2011-11-04 10:18:13 +00:00
|
|
|
ti->z += ApplyPixelFoundationToSlope(f, &ti->tileh);
|
2007-07-26 16:51:10 +00:00
|
|
|
|
|
|
|
if (IsInclinedFoundation(f)) {
|
|
|
|
/* inclined foundation */
|
|
|
|
byte inclined = highest_corner * 2 + (f == FOUNDATION_INCLINED_Y ? 1 : 0);
|
|
|
|
|
2008-10-25 18:58:24 +00:00
|
|
|
AddSortableSpriteToDraw(inclined_base + inclined, PAL_NONE, ti->x, ti->y,
|
2022-12-23 14:47:11 +00:00
|
|
|
f == FOUNDATION_INCLINED_X ? TILE_SIZE : 1,
|
|
|
|
f == FOUNDATION_INCLINED_Y ? TILE_SIZE : 1,
|
2008-11-02 11:23:44 +00:00
|
|
|
TILE_HEIGHT, ti->z
|
2008-10-25 18:58:24 +00:00
|
|
|
);
|
2022-12-18 12:35:08 +00:00
|
|
|
OffsetGroundSprite(0, 0);
|
2008-06-12 21:36:56 +00:00
|
|
|
} else if (IsLeveledFoundation(f)) {
|
2022-12-23 14:47:11 +00:00
|
|
|
AddSortableSpriteToDraw(leveled_base + SlopeWithOneCornerRaised(highest_corner), PAL_NONE, ti->x, ti->y, TILE_SIZE, TILE_SIZE, TILE_HEIGHT - 1, ti->z - TILE_HEIGHT);
|
|
|
|
OffsetGroundSprite(0, -(int)TILE_HEIGHT);
|
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 */
|
2022-12-23 14:47:11 +00:00
|
|
|
OffsetGroundSprite(0, -(int)TILE_HEIGHT);
|
2007-10-20 21:04:14 +00:00
|
|
|
} else {
|
|
|
|
/* halftile foundation */
|
2022-12-23 14:47:11 +00:00
|
|
|
int x_bb = (((highest_corner == CORNER_W) || (highest_corner == CORNER_S)) ? TILE_SIZE / 2 : 0);
|
|
|
|
int y_bb = (((highest_corner == CORNER_S) || (highest_corner == CORNER_E)) ? TILE_SIZE / 2 : 0);
|
2007-10-20 21:04:14 +00:00
|
|
|
|
2022-12-23 14:47:11 +00:00
|
|
|
AddSortableSpriteToDraw(halftile_base + highest_corner, PAL_NONE, ti->x + x_bb, ti->y + y_bb, TILE_SIZE / 2, TILE_SIZE / 2, TILE_HEIGHT - 1, ti->z + TILE_HEIGHT);
|
|
|
|
/* Reposition ground sprite back to original position after bounding box change above. This is similar to
|
|
|
|
* RemapCoords() but without zoom scaling. */
|
2022-12-18 12:35:08 +00:00
|
|
|
Point pt = {(y_bb - x_bb) * 2, y_bb + x_bb};
|
|
|
|
OffsetGroundSprite(-pt.x, -pt.y);
|
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 */
|
2022-12-23 14:47:11 +00:00
|
|
|
AddSortableSpriteToDraw(leveled_base + ti->tileh, PAL_NONE, ti->x, ti->y, TILE_SIZE, TILE_SIZE, TILE_HEIGHT - 1, ti->z);
|
|
|
|
OffsetGroundSprite(0, -(int)TILE_HEIGHT);
|
2007-10-20 21:04:14 +00:00
|
|
|
} else if (IsNonContinuousFoundation(f)) {
|
|
|
|
/* halftile foundation */
|
|
|
|
Corner halftile_corner = GetHalftileFoundationCorner(f);
|
2022-12-23 14:47:11 +00:00
|
|
|
int x_bb = (((halftile_corner == CORNER_W) || (halftile_corner == CORNER_S)) ? TILE_SIZE / 2 : 0);
|
|
|
|
int y_bb = (((halftile_corner == CORNER_S) || (halftile_corner == CORNER_E)) ? TILE_SIZE / 2 : 0);
|
2007-10-20 21:04:14 +00:00
|
|
|
|
2022-12-23 14:47:11 +00:00
|
|
|
AddSortableSpriteToDraw(halftile_base + halftile_corner, PAL_NONE, ti->x + x_bb, ti->y + y_bb, TILE_SIZE / 2, TILE_SIZE / 2, TILE_HEIGHT - 1, ti->z);
|
|
|
|
/* Reposition ground sprite back to original position after bounding box change above. This is similar to
|
|
|
|
* RemapCoords() but without zoom scaling. */
|
2022-12-18 12:35:08 +00:00
|
|
|
Point pt = {(y_bb - x_bb) * 2, y_bb + x_bb};
|
|
|
|
OffsetGroundSprite(-pt.x, -pt.y);
|
2007-10-20 21:04:14 +00:00
|
|
|
} 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);
|
|
|
|
}
|
2022-12-23 14:47:11 +00:00
|
|
|
AddSortableSpriteToDraw(spr, PAL_NONE, ti->x, ti->y, TILE_SIZE, TILE_SIZE, TILE_HEIGHT - 1, ti->z);
|
2022-12-18 12:35:08 +00:00
|
|
|
OffsetGroundSprite(0, 0);
|
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);
|
|
|
|
|
2008-10-25 18:58:24 +00:00
|
|
|
AddSortableSpriteToDraw(inclined_base + inclined, PAL_NONE, ti->x, ti->y,
|
2022-12-23 14:47:11 +00:00
|
|
|
f == FOUNDATION_INCLINED_X ? TILE_SIZE : 1,
|
|
|
|
f == FOUNDATION_INCLINED_Y ? TILE_SIZE : 1,
|
2008-11-02 11:23:44 +00:00
|
|
|
TILE_HEIGHT, ti->z
|
2008-10-25 18:58:24 +00:00
|
|
|
);
|
2022-12-18 12:35:08 +00:00
|
|
|
OffsetGroundSprite(0, 0);
|
2006-08-10 14:44:32 +00:00
|
|
|
}
|
2011-11-04 10:18:13 +00:00
|
|
|
ti->z += ApplyPixelFoundationToSlope(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
|
|
|
{
|
2009-07-01 14:51:05 +00:00
|
|
|
/* If the tile can have animation and we clear it, delete it from the animated tile list. */
|
2019-04-10 21:07:06 +00:00
|
|
|
if (_tile_type_procs[GetTileType(tile)]->animate_tile_proc != nullptr) DeleteAnimatedTile(tile);
|
2009-07-01 14:51:05 +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
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Returns information about trackdirs and signal states.
|
2008-02-18 16:11:31 +00:00
|
|
|
* If there is any trackbit at 'side', return all trackdirbits.
|
2008-02-20 17:49:50 +00:00
|
|
|
* For TRANSPORT_ROAD, return no trackbits if there is no roadbit (of given subtype) at given side.
|
2008-02-18 16:11:31 +00:00
|
|
|
* @param tile tile to get info about
|
|
|
|
* @param mode transport type
|
|
|
|
* @param sub_mode for TRANSPORT_ROAD, roadtypes to check
|
|
|
|
* @param side side we are entering from, INVALID_DIAGDIR to return all trackbits
|
|
|
|
* @return trackdirbits and other info depending on 'mode'
|
|
|
|
*/
|
2008-02-20 17:49:50 +00:00
|
|
|
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-02-18 16:11:31 +00:00
|
|
|
return _tile_type_procs[GetTileType(tile)]->get_tile_track_status_proc(tile, mode, sub_mode, side);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-10-13 03:26:48 +00:00
|
|
|
/**
|
|
|
|
* Change the owner of a tile
|
|
|
|
* @param tile Tile to change
|
|
|
|
* @param old_owner Current owner of the tile
|
|
|
|
* @param new_owner New owner of the tile
|
|
|
|
*/
|
2008-09-30 20:39:50 +00:00
|
|
|
void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-09-30 20:39:50 +00:00
|
|
|
_tile_type_procs[GetTileType(tile)]->change_tile_owner_proc(tile, old_owner, new_owner);
|
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.
|
2008-10-19 15:39:12 +00:00
|
|
|
* @ingroup SnowLineGroup
|
2007-03-20 13:47:00 +00:00
|
|
|
*/
|
2009-05-21 22:43:25 +00:00
|
|
|
bool IsSnowLineSet()
|
2007-03-20 13:47:00 +00:00
|
|
|
{
|
2019-04-10 21:07:06 +00:00
|
|
|
return _snow_line != nullptr;
|
2007-03-20 13:47:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a variable snow line, as loaded from a newgrf file.
|
|
|
|
* @param table the 12 * 32 byte table containing the snowline for each day
|
2008-10-19 15:39:12 +00:00
|
|
|
* @ingroup SnowLineGroup
|
2007-03-20 13:47:00 +00:00
|
|
|
*/
|
|
|
|
void SetSnowLine(byte table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS])
|
|
|
|
{
|
|
|
|
_snow_line = CallocT<SnowLine>(1);
|
2009-02-23 20:03:38 +00:00
|
|
|
_snow_line->lowest_value = 0xFF;
|
2007-03-20 13:47:00 +00:00
|
|
|
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++) {
|
2021-01-08 10:16:18 +00:00
|
|
|
_snow_line->highest_value = std::max(_snow_line->highest_value, table[i][j]);
|
|
|
|
_snow_line->lowest_value = std::min(_snow_line->lowest_value, table[i][j]);
|
2007-03-20 13:47:00 +00:00
|
|
|
}
|
|
|
|
}
|
2021-02-21 22:02:58 +00:00
|
|
|
|
|
|
|
UpdateCachedSnowLine();
|
2022-04-29 16:10:18 +00:00
|
|
|
UpdateCachedSnowLineBounds();
|
2007-03-20 13:47:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the current snow line, either variable or static.
|
|
|
|
* @return the snow line height.
|
2008-10-19 15:39:12 +00:00
|
|
|
* @ingroup SnowLineGroup
|
2007-03-20 13:47:00 +00:00
|
|
|
*/
|
2021-02-21 22:02:58 +00:00
|
|
|
byte GetSnowLineUncached()
|
2007-03-20 13:47:00 +00:00
|
|
|
{
|
2019-04-10 21:07:06 +00:00
|
|
|
if (_snow_line == nullptr) return _settings_game.game_creation.snow_line_height;
|
2007-03-20 13:47:00 +00:00
|
|
|
|
2018-04-10 02:51:24 +00:00
|
|
|
return _snow_line->table[_cur_date_ymd.month][_cur_date_ymd.day];
|
2007-03-20 13:47:00 +00:00
|
|
|
}
|
|
|
|
|
2021-02-21 22:02:58 +00:00
|
|
|
void UpdateCachedSnowLine()
|
|
|
|
{
|
|
|
|
_cached_snowline = GetSnowLineUncached();
|
|
|
|
}
|
|
|
|
|
2007-03-20 13:47:00 +00:00
|
|
|
/**
|
2022-04-29 16:10:18 +00:00
|
|
|
* Cache the lowest and highest possible snow line heights, either variable or static.
|
2008-10-19 15:39:12 +00:00
|
|
|
* @ingroup SnowLineGroup
|
2007-03-20 13:47:00 +00:00
|
|
|
*/
|
2022-04-29 16:10:18 +00:00
|
|
|
void UpdateCachedSnowLineBounds()
|
2007-03-20 13:47:00 +00:00
|
|
|
{
|
2022-04-29 16:10:18 +00:00
|
|
|
_cached_highest_snowline = _snow_line == nullptr ? _settings_game.game_creation.snow_line_height : _snow_line->highest_value;
|
|
|
|
_cached_lowest_snowline = _snow_line == nullptr ? _settings_game.game_creation.snow_line_height : _snow_line->lowest_value;
|
2022-04-30 23:41:08 +00:00
|
|
|
|
2022-05-05 16:17:24 +00:00
|
|
|
uint snowline_range = ((_settings_game.construction.trees_around_snow_line_dynamic_range * (HighestSnowLine() - LowestSnowLine())) + 50) / 100;
|
|
|
|
_cached_tree_placement_highest_snowline = LowestSnowLine() + snowline_range;
|
2009-02-23 20:03:38 +00:00
|
|
|
}
|
|
|
|
|
2007-03-20 13:47:00 +00:00
|
|
|
/**
|
|
|
|
* Clear the variable snow line table and free the memory.
|
2008-10-19 15:39:12 +00:00
|
|
|
* @ingroup SnowLineGroup
|
2007-03-20 13:47:00 +00:00
|
|
|
*/
|
2009-05-21 22:43:25 +00:00
|
|
|
void ClearSnowLine()
|
2007-03-20 13:47:00 +00:00
|
|
|
{
|
|
|
|
free(_snow_line);
|
2019-04-10 21:07:06 +00:00
|
|
|
_snow_line = nullptr;
|
2021-02-21 22:02:58 +00:00
|
|
|
UpdateCachedSnowLine();
|
2022-04-29 16:10:18 +00:00
|
|
|
UpdateCachedSnowLineBounds();
|
2007-03-20 13:47:00 +00:00
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +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
|
2009-09-18 14:23:58 +00:00
|
|
|
* @param text unused
|
|
|
|
* @return the cost of this operation or an error
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
2024-01-07 16:41:53 +00:00
|
|
|
CommandCost CmdLandscapeClear(TileIndex tile, DoCommandFlag flags, uint32_t p1, uint32_t p2, const char *text)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2010-09-05 16:00:36 +00:00
|
|
|
CommandCost cost(EXPENSES_CONSTRUCTION);
|
|
|
|
bool do_clear = false;
|
2010-12-12 11:41:15 +00:00
|
|
|
/* Test for stuff which results in water when cleared. Then add the cost to also clear the water. */
|
|
|
|
if ((flags & DC_FORCE_CLEAR_TILE) && HasTileWaterClass(tile) && IsTileOnWater(tile) && !IsWaterTile(tile) && !IsCoastTile(tile)) {
|
2010-09-05 16:00:36 +00:00
|
|
|
if ((flags & DC_AUTO) && GetWaterClass(tile) == WATER_CLASS_CANAL) return_cmd_error(STR_ERROR_MUST_DEMOLISH_CANAL_FIRST);
|
|
|
|
do_clear = true;
|
2017-07-30 13:27:42 +00:00
|
|
|
const bool is_canal = GetWaterClass(tile) == WATER_CLASS_CANAL;
|
|
|
|
if (!is_canal && _game_mode != GM_EDITOR && !_settings_game.construction.enable_remove_water && !(flags & DC_ALLOW_REMOVE_WATER)) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
|
|
|
|
cost.AddCost(is_canal ? _price[PR_CLEAR_CANAL] : _price[PR_CLEAR_WATER]);
|
2010-09-05 16:00:36 +00:00
|
|
|
}
|
2010-09-05 13:31:39 +00:00
|
|
|
|
2019-04-10 21:07:06 +00:00
|
|
|
Company *c = (flags & (DC_AUTO | DC_BANKRUPT)) ? nullptr : Company::GetIfValid(_current_company);
|
|
|
|
if (c != nullptr && (int)GB(c->clear_limit, 16, 16) < 1) {
|
2011-01-04 22:50:09 +00:00
|
|
|
return_cmd_error(STR_ERROR_CLEARING_LIMIT_REACHED);
|
|
|
|
}
|
|
|
|
|
2020-10-16 21:12:57 +00:00
|
|
|
if ((flags & DC_TOWN) && !MayTownModifyRoad(tile)) return CMD_ERROR;
|
|
|
|
|
2010-11-21 17:05:23 +00:00
|
|
|
const ClearedObjectArea *coa = FindClearedObject(tile);
|
|
|
|
|
|
|
|
/* If this tile was the first tile which caused object destruction, always
|
|
|
|
* pass it on to the tile_type_proc. That way multiple test runs and the exec run stay consistent. */
|
2019-04-10 21:07:06 +00:00
|
|
|
if (coa != nullptr && coa->first_tile != tile) {
|
2010-09-05 13:31:39 +00:00
|
|
|
/* If this tile belongs to an object which was already cleared via another tile, pretend it has been
|
|
|
|
* already removed.
|
|
|
|
* However, we need to check stuff, which is not the same for all object tiles. (e.g. being on water or not) */
|
2010-11-21 17:05:23 +00:00
|
|
|
|
|
|
|
/* If a object is removed, it leaves either bare land or water. */
|
|
|
|
if ((flags & DC_NO_WATER) && HasTileWaterClass(tile) && IsTileOnWater(tile)) {
|
|
|
|
return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
|
2010-09-05 13:31:39 +00:00
|
|
|
}
|
2011-01-04 20:33:22 +00:00
|
|
|
} else {
|
|
|
|
cost.AddCost(_tile_type_procs[GetTileType(tile)]->clear_tile_proc(tile, flags));
|
2010-09-03 21:50:51 +00:00
|
|
|
}
|
2011-01-04 20:33:22 +00:00
|
|
|
|
2011-01-04 22:50:09 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2019-04-10 21:07:06 +00:00
|
|
|
if (c != nullptr) c->clear_limit -= 1 << 16;
|
2022-04-25 16:35:19 +00:00
|
|
|
if (do_clear) ForceClearWaterTile(tile);
|
2011-01-04 22:50:09 +00:00
|
|
|
}
|
2010-09-05 16:00:36 +00:00
|
|
|
return cost;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Clear a big piece of landscape
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile end tile of area dragging
|
2007-03-03 04:04:22 +00:00
|
|
|
* @param flags of operation to conduct
|
2010-04-17 14:57:49 +00:00
|
|
|
* @param p1 start tile of area dragging
|
2010-12-13 15:15:02 +00:00
|
|
|
* @param p2 various bitstuffed data.
|
|
|
|
* bit 0: Whether to use the Orthogonal (0) or Diagonal (1) iterator.
|
2009-09-18 14:23:58 +00:00
|
|
|
* @param text unused
|
|
|
|
* @return the cost of this operation or an error
|
2005-05-12 00:11:37 +00:00
|
|
|
*/
|
2024-01-07 16:41:53 +00:00
|
|
|
CommandCost CmdClearArea(TileIndex tile, DoCommandFlag flags, uint32_t p1, uint32_t p2, const char *text)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-01-30 17:18:45 +00:00
|
|
|
if (p1 >= MapSize()) return CMD_ERROR;
|
2005-05-12 00:11:37 +00:00
|
|
|
|
2008-04-04 16:32:27 +00:00
|
|
|
Money money = GetAvailableMoneyForCommand();
|
|
|
|
CommandCost cost(EXPENSES_CONSTRUCTION);
|
2010-03-20 17:19:16 +00:00
|
|
|
CommandCost last_error = CMD_ERROR;
|
|
|
|
bool had_success = false;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2019-04-10 21:07:06 +00:00
|
|
|
const Company *c = (flags & (DC_AUTO | DC_BANKRUPT)) ? nullptr : Company::GetIfValid(_current_company);
|
|
|
|
int limit = (c == nullptr ? INT32_MAX : GB(c->clear_limit, 16, 16));
|
2011-01-04 22:50:09 +00:00
|
|
|
|
2022-12-30 18:09:55 +00:00
|
|
|
OrthogonalOrDiagonalTileIterator iter(tile, p1, HasBit(p2, 0));
|
|
|
|
for (; *iter != INVALID_TILE; ++iter) {
|
2010-12-13 15:15:02 +00:00
|
|
|
TileIndex t = *iter;
|
2010-12-12 17:22:17 +00:00
|
|
|
CommandCost ret = DoCommand(t, 0, 0, flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
|
|
|
if (ret.Failed()) {
|
|
|
|
last_error = ret;
|
2011-01-04 22:50:09 +00:00
|
|
|
|
|
|
|
/* We may not clear more tiles. */
|
2019-04-10 21:07:06 +00:00
|
|
|
if (c != nullptr && GB(c->clear_limit, 16, 16) < 1) break;
|
2010-12-12 17:22:17 +00:00
|
|
|
continue;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2010-12-12 17:22:17 +00:00
|
|
|
had_success = true;
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
money -= ret.GetCost();
|
|
|
|
if (ret.GetCost() > 0 && money < 0) {
|
|
|
|
_additional_cash_required = ret.GetCost();
|
|
|
|
return cost;
|
|
|
|
}
|
|
|
|
DoCommand(t, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
|
|
|
|
2011-07-17 16:09:38 +00:00
|
|
|
/* draw explosion animation...
|
|
|
|
* Disable explosions when game is paused. Looks silly and blocks the view. */
|
2014-02-02 14:53:52 +00:00
|
|
|
if ((t == tile || t == p1) && _pause_mode == PM_UNPAUSED) {
|
|
|
|
/* big explosion in two corners, or small explosion for single tiles */
|
2010-12-12 17:22:17 +00:00
|
|
|
CreateEffectVehicleAbove(TileX(t) * TILE_SIZE + TILE_SIZE / 2, TileY(t) * TILE_SIZE + TILE_SIZE / 2, 2,
|
2014-02-02 14:53:52 +00:00
|
|
|
TileX(tile) == TileX(p1) && TileY(tile) == TileY(p1) ? EV_EXPLOSION_SMALL : EV_EXPLOSION_LARGE
|
2010-12-12 17:22:17 +00:00
|
|
|
);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2011-01-04 22:50:09 +00:00
|
|
|
} else {
|
|
|
|
/* When we're at the clearing limit we better bail (unneed) testing as well. */
|
|
|
|
if (ret.GetCost() != 0 && --limit <= 0) break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2010-12-12 17:22:17 +00:00
|
|
|
cost.AddCost(ret);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2010-03-20 17:19:16 +00:00
|
|
|
return had_success ? cost : last_error;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-18 10:16:51 +00:00
|
|
|
TileIndex _cur_tileloop_tile;
|
2023-02-09 21:39:04 +00:00
|
|
|
TileIndex _aux_tileloop_tile;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2024-01-07 16:41:53 +00:00
|
|
|
static uint32_t GetTileLoopFeedback()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2012-04-17 19:43:43 +00:00
|
|
|
/* The pseudorandom sequence of tiles is generated using a Galois linear feedback
|
|
|
|
* shift register (LFSR). This allows a deterministic pseudorandom ordering, but
|
|
|
|
* still with minimal state and fast iteration. */
|
|
|
|
|
2015-09-11 21:36:15 +00:00
|
|
|
/* Maximal length LFSR feedback terms, from 12-bit (for 64x64 maps) to 28-bit (for 16kx16k maps).
|
2012-04-17 19:43:43 +00:00
|
|
|
* Extracted from http://www.ece.cmu.edu/~koopman/lfsr/ */
|
2024-01-07 16:41:53 +00:00
|
|
|
static const uint32_t feedbacks[] = {
|
2015-09-11 21:34:54 +00:00
|
|
|
0xD8F, 0x1296, 0x2496, 0x4357, 0x8679, 0x1030E, 0x206CD, 0x403FE, 0x807B8, 0x1004B2, 0x2006A8,
|
2015-09-11 21:36:15 +00:00
|
|
|
0x4004B2, 0x800B87, 0x10004F3, 0x200072D, 0x40006AE, 0x80009E3,
|
2012-04-17 19:43:43 +00:00
|
|
|
};
|
2021-01-30 23:24:40 +00:00
|
|
|
static_assert(lengthof(feedbacks) == MAX_MAP_TILES_BITS - 2 * MIN_MAP_SIZE_BITS + 1);
|
2023-02-09 21:39:04 +00:00
|
|
|
return feedbacks[MapLogX() + MapLogY() - 2 * MIN_MAP_SIZE_BITS];
|
|
|
|
}
|
|
|
|
|
2023-06-17 18:32:33 +00:00
|
|
|
static std::vector<uint> _tile_loop_counts;
|
|
|
|
|
|
|
|
void SetupTileLoopCounts()
|
|
|
|
{
|
|
|
|
_tile_loop_counts.resize(_settings_game.economy.day_length_factor);
|
|
|
|
if (_settings_game.economy.day_length_factor == 0) return;
|
|
|
|
|
2024-01-07 16:41:53 +00:00
|
|
|
uint64_t count_per_tick_fp16 = (static_cast<uint64_t>(1) << (MapLogX() + MapLogY() + 8)) / _settings_game.economy.day_length_factor;
|
|
|
|
uint64_t accumulator = 0;
|
2023-06-17 18:32:33 +00:00
|
|
|
for (uint &count : _tile_loop_counts) {
|
|
|
|
accumulator += count_per_tick_fp16;
|
2024-01-07 16:41:53 +00:00
|
|
|
count = static_cast<uint32_t>(accumulator >> 16);
|
2023-06-17 18:32:33 +00:00
|
|
|
accumulator &= 0xFFFF;
|
|
|
|
}
|
|
|
|
if (accumulator > 0) _tile_loop_counts[0]++;
|
|
|
|
}
|
|
|
|
|
2023-02-09 21:39:04 +00:00
|
|
|
/**
|
|
|
|
* Gradually iterate over all tiles on the map, calling their TileLoopProcs once every 256 ticks.
|
|
|
|
*/
|
2023-06-17 18:32:33 +00:00
|
|
|
void RunTileLoop(bool apply_day_length)
|
2023-02-09 21:39:04 +00:00
|
|
|
{
|
2023-06-17 18:32:33 +00:00
|
|
|
/* We update every tile every 256 ticks, so divide the map size by 2^8 = 256 */
|
|
|
|
uint count;
|
|
|
|
if (apply_day_length && _settings_game.economy.day_length_factor > 1) {
|
|
|
|
count = _tile_loop_counts[_tick_skip_counter];
|
|
|
|
if (count == 0) return;
|
|
|
|
} else {
|
|
|
|
count = 1 << (MapLogX() + MapLogY() - 8);
|
|
|
|
}
|
|
|
|
|
2023-02-09 21:39:04 +00:00
|
|
|
PerformanceAccumulator framerate(PFE_GL_LANDSCAPE);
|
|
|
|
|
2024-01-07 16:41:53 +00:00
|
|
|
const uint32_t feedback = GetTileLoopFeedback();
|
2012-04-17 19:43:43 +00:00
|
|
|
|
2008-04-04 16:32:27 +00:00
|
|
|
TileIndex tile = _cur_tileloop_tile;
|
2012-04-17 19:43:43 +00:00
|
|
|
/* The LFSR cannot have a zeroed state. */
|
2022-10-22 11:34:54 +00:00
|
|
|
dbg_assert(tile != 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2017-08-16 17:30:06 +00:00
|
|
|
SCOPE_INFO_FMT([&], "RunTileLoop: tile: %dx%d", TileX(tile), TileY(tile));
|
|
|
|
|
2012-04-17 19:43:43 +00:00
|
|
|
/* Manually update tile 0 every 256 ticks - the LFSR never iterates over it itself. */
|
|
|
|
if (_tick_counter % 256 == 0) {
|
|
|
|
_tile_type_procs[GetTileType(0)]->tile_loop_proc(0);
|
|
|
|
count--;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2012-04-17 19:43:43 +00:00
|
|
|
while (count--) {
|
2023-08-17 13:40:39 +00:00
|
|
|
/* Get the next tile in sequence using a Galois LFSR. */
|
2024-01-07 16:41:53 +00:00
|
|
|
TileIndex next = (tile >> 1) ^ (-(int32_t)(tile & 1) & feedback);
|
2023-09-04 00:00:30 +00:00
|
|
|
if (count > 0) {
|
|
|
|
PREFETCH_NTA(&_m[next]);
|
|
|
|
}
|
2023-08-17 13:40:39 +00:00
|
|
|
|
2012-04-17 19:43:43 +00:00
|
|
|
_tile_type_procs[GetTileType(tile)]->tile_loop_proc(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2023-08-17 13:40:39 +00:00
|
|
|
tile = next;
|
2008-04-04 16:32:27 +00:00
|
|
|
}
|
2012-04-17 19:43:43 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
_cur_tileloop_tile = tile;
|
2023-08-28 14:17:53 +00:00
|
|
|
RecordSyncEvent(NSRE_TILE);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2023-02-09 21:39:04 +00:00
|
|
|
void RunAuxiliaryTileLoop()
|
|
|
|
{
|
|
|
|
/* At day lengths <= 4, flooding is handled by main tile loop */
|
|
|
|
if (_settings_game.economy.day_length_factor <= 4 || (_scaled_tick_counter % 4) != 0) return;
|
|
|
|
|
|
|
|
PerformanceAccumulator framerate(PFE_GL_LANDSCAPE);
|
|
|
|
|
2024-01-07 16:41:53 +00:00
|
|
|
const uint32_t feedback = GetTileLoopFeedback();
|
2023-02-09 21:39:04 +00:00
|
|
|
uint count = 1 << (MapLogX() + MapLogY() - 8);
|
|
|
|
TileIndex tile = _aux_tileloop_tile;
|
|
|
|
|
|
|
|
while (count--) {
|
2023-08-17 13:40:39 +00:00
|
|
|
/* Get the next tile in sequence using a Galois LFSR. */
|
2024-01-07 16:41:53 +00:00
|
|
|
TileIndex next = (tile >> 1) ^ (-(int32_t)(tile & 1) & feedback);
|
2023-09-04 00:00:30 +00:00
|
|
|
if (count > 0) {
|
|
|
|
PREFETCH_NTA(&_m[next]);
|
|
|
|
}
|
2023-08-17 13:40:39 +00:00
|
|
|
|
2023-08-17 13:40:07 +00:00
|
|
|
if (IsFloodingTypeTile(tile) && !IsNonFloodingWaterTile(tile)) {
|
2023-02-09 21:39:04 +00:00
|
|
|
FloodingBehaviour fb = GetFloodingBehaviour(tile);
|
|
|
|
if (fb != FLOOD_NONE) TileLoopWaterFlooding(fb, tile);
|
|
|
|
}
|
|
|
|
|
2023-08-17 13:40:39 +00:00
|
|
|
tile = next;
|
2023-02-09 21:39:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_aux_tileloop_tile = tile;
|
2023-08-28 14:17:53 +00:00
|
|
|
RecordSyncEvent(NSRE_AUX_TILE);
|
2023-02-09 21:39:04 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void InitializeLandscape()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2019-02-08 23:05:25 +00:00
|
|
|
for (uint y = _settings_game.construction.freeform_edges ? 1 : 0; y < MapMaxY(); y++) {
|
|
|
|
for (uint x = _settings_game.construction.freeform_edges ? 1 : 0; x < MapMaxX(); x++) {
|
|
|
|
MakeClear(TileXY(x, y), CLEAR_GRASS, 3);
|
|
|
|
SetTileHeight(TileXY(x, y), 0);
|
|
|
|
SetTropicZone(TileXY(x, y), TROPICZONE_NORMAL);
|
|
|
|
ClearBridgeMiddle(TileXY(x, y));
|
2006-02-24 20:35:37 +00:00
|
|
|
}
|
2005-07-13 18:04:01 +00:00
|
|
|
}
|
2019-02-08 23:05:25 +00:00
|
|
|
|
|
|
|
for (uint x = 0; x < MapSizeX(); x++) MakeVoid(TileXY(x, MapMaxY()));
|
|
|
|
for (uint y = 0; y < MapSizeY(); y++) MakeVoid(TileXY(MapMaxX(), y));
|
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
|
|
|
|
2008-04-04 16:32:27 +00:00
|
|
|
static void GenerateTerrain(int type, uint flag)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2024-01-07 16:41:53 +00:00
|
|
|
uint32_t r = Random();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2023-02-25 15:59:43 +00:00
|
|
|
/* Choose one of the templates from the graphics file. */
|
2023-08-22 21:16:04 +00:00
|
|
|
const Sprite *templ = GetSprite((((r >> 24) * _genterrain_tbl_1[type]) >> 8) + _genterrain_tbl_2[type] + SPR_MAPGEN_BEGIN, SpriteType::MapGen, 0);
|
2019-04-10 21:07:06 +00:00
|
|
|
if (templ == nullptr) usererror("Map generator sprites could not be loaded");
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2023-02-25 15:59:43 +00:00
|
|
|
/* Chose a random location to apply the template to. */
|
2008-04-04 16:32:27 +00:00
|
|
|
uint x = r & MapMaxX();
|
|
|
|
uint y = (r >> MapLogX()) & MapMaxY();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2023-02-25 15:59:43 +00:00
|
|
|
/* Make sure the template is not too close to the upper edges; bottom edges are checked later. */
|
2020-12-15 20:52:41 +00:00
|
|
|
uint edge_distance = 1 + (_settings_game.construction.freeform_edges ? 1 : 0);
|
|
|
|
if (x <= edge_distance || y <= edge_distance) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-04-04 16:32:27 +00:00
|
|
|
DiagDirection direction = (DiagDirection)GB(r, 22, 2);
|
|
|
|
uint w = templ->width;
|
|
|
|
uint h = templ->height;
|
|
|
|
|
|
|
|
if (DiagDirToAxis(direction) == AXIS_Y) Swap(w, h);
|
|
|
|
|
|
|
|
const byte *p = templ->data;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-04-04 16:32:27 +00:00
|
|
|
if ((flag & 4) != 0) {
|
2023-02-25 15:59:43 +00:00
|
|
|
/* This is only executed in secondary/tertiary loops to generate the terrain for arctic and tropic.
|
|
|
|
* It prevents the templates to be applied to certain parts of the map based on the flags, thus
|
|
|
|
* creating regions with different elevations/topography. */
|
2005-02-03 18:20:43 +00:00
|
|
|
uint xw = x * MapSizeY();
|
|
|
|
uint yw = y * MapSizeX();
|
|
|
|
uint bias = (MapSizeX() + MapSizeY()) * 16;
|
|
|
|
|
|
|
|
switch (flag & 3) {
|
2008-04-04 16:32:27 +00:00
|
|
|
default: NOT_REACHED();
|
2005-02-03 18:20:43 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-25 15:59:43 +00:00
|
|
|
/* Ensure the template does not overflow at the bottom edges of the map; upper edges were checked before. */
|
2020-12-15 20:52:41 +00:00
|
|
|
if (x + w >= MapMaxX()) return;
|
|
|
|
if (y + h >= MapMaxY()) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2011-11-04 06:05:11 +00:00
|
|
|
TileIndex tile = TileXY(x, y);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2023-02-25 15:59:43 +00:00
|
|
|
/* Get the template and overlay in a particular direction over the map's height from the given
|
|
|
|
* origin point (tile), and update the map's height everywhere where the height from the template
|
|
|
|
* is higher than the height of the map. In other words, this only raises the tile heights. */
|
2005-02-03 20:52:12 +00:00
|
|
|
switch (direction) {
|
2008-04-04 16:32:27 +00:00
|
|
|
default: NOT_REACHED();
|
|
|
|
case DIAGDIR_NE:
|
2004-08-09 17:04:08 +00:00
|
|
|
do {
|
2011-11-04 06:05:11 +00:00
|
|
|
TileIndex tile_cur = tile;
|
2005-02-03 20:52:12 +00:00
|
|
|
|
2008-04-04 16:32:27 +00:00
|
|
|
for (uint w_cur = w; w_cur != 0; --w_cur) {
|
2011-11-04 06:05:11 +00:00
|
|
|
if (GB(*p, 0, 4) >= TileHeight(tile_cur)) SetTileHeight(tile_cur, GB(*p, 0, 4));
|
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;
|
|
|
|
|
2008-04-04 16:32:27 +00:00
|
|
|
case DIAGDIR_SE:
|
2004-08-09 17:04:08 +00:00
|
|
|
do {
|
2011-11-04 06:05:11 +00:00
|
|
|
TileIndex tile_cur = tile;
|
2005-02-03 20:52:12 +00:00
|
|
|
|
2008-04-04 16:32:27 +00:00
|
|
|
for (uint h_cur = h; h_cur != 0; --h_cur) {
|
2011-11-04 06:05:11 +00:00
|
|
|
if (GB(*p, 0, 4) >= TileHeight(tile_cur)) SetTileHeight(tile_cur, GB(*p, 0, 4));
|
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
|
|
|
}
|
2008-04-04 16:32:27 +00:00
|
|
|
tile += TileDiffXY(1, 0);
|
2005-02-03 20:52:12 +00:00
|
|
|
} while (--w != 0);
|
|
|
|
break;
|
|
|
|
|
2008-04-04 16:32:27 +00:00
|
|
|
case DIAGDIR_SW:
|
2005-06-25 16:44:57 +00:00
|
|
|
tile += TileDiffXY(w - 1, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
do {
|
2011-11-04 06:05:11 +00:00
|
|
|
TileIndex tile_cur = tile;
|
2005-02-03 20:52:12 +00:00
|
|
|
|
2008-04-04 16:32:27 +00:00
|
|
|
for (uint w_cur = w; w_cur != 0; --w_cur) {
|
2011-11-04 06:05:11 +00:00
|
|
|
if (GB(*p, 0, 4) >= TileHeight(tile_cur)) SetTileHeight(tile_cur, GB(*p, 0, 4));
|
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;
|
|
|
|
|
2008-04-04 16:32:27 +00:00
|
|
|
case DIAGDIR_NW:
|
2005-06-25 16:44:57 +00:00
|
|
|
tile += TileDiffXY(0, h - 1);
|
2004-08-09 17:04:08 +00:00
|
|
|
do {
|
2011-11-04 06:05:11 +00:00
|
|
|
TileIndex tile_cur = tile;
|
2005-02-03 20:52:12 +00:00
|
|
|
|
2008-04-04 16:32:27 +00:00
|
|
|
for (uint h_cur = h; h_cur != 0; --h_cur) {
|
2011-11-04 06:05:11 +00:00
|
|
|
if (GB(*p, 0, 4) >= TileHeight(tile_cur)) SetTileHeight(tile_cur, GB(*p, 0, 4));
|
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
|
|
|
}
|
2008-04-04 16:32:27 +00:00
|
|
|
tile += TileDiffXY(1, 0);
|
2005-02-03 20:52:12 +00:00
|
|
|
} while (--w != 0);
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#include "table/genland.h"
|
|
|
|
|
2022-03-06 02:05:12 +00:00
|
|
|
static std::pair<const Rect16 *, const Rect16 *> GetDesertOrRainforestData()
|
2022-03-05 14:59:31 +00:00
|
|
|
{
|
|
|
|
switch (_settings_game.game_creation.coast_tropics_width) {
|
|
|
|
case 0:
|
|
|
|
return { _make_desert_or_rainforest_data, endof(_make_desert_or_rainforest_data) };
|
|
|
|
case 1:
|
|
|
|
return { _make_desert_or_rainforest_data_medium, endof(_make_desert_or_rainforest_data_medium) };
|
|
|
|
case 2:
|
|
|
|
return { _make_desert_or_rainforest_data_large, endof(_make_desert_or_rainforest_data_large) };
|
2022-03-06 00:47:14 +00:00
|
|
|
case 3:
|
|
|
|
return { _make_desert_or_rainforest_data_extralarge, endof(_make_desert_or_rainforest_data_extralarge) };
|
2022-03-05 14:59:31 +00:00
|
|
|
default:
|
|
|
|
NOT_REACHED();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-06 02:05:12 +00:00
|
|
|
template <typename F>
|
|
|
|
void DesertOrRainforestProcessTiles(const std::pair<const Rect16 *, const Rect16 *> desert_rainforest_data, const Rect16 *&data, TileIndex tile, F handle_tile)
|
|
|
|
{
|
|
|
|
for (data = desert_rainforest_data.first; data != desert_rainforest_data.second; ++data) {
|
|
|
|
const Rect16 r = *data;
|
2024-01-07 16:41:53 +00:00
|
|
|
for (int16_t x = r.left; x <= r.right; x++) {
|
|
|
|
for (int16_t y = r.top; y <= r.bottom; y++) {
|
2022-03-06 02:05:12 +00:00
|
|
|
TileIndex t = AddTileIndexDiffCWrap(tile, { x, y });
|
|
|
|
if (handle_tile(t)) return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-24 15:38:36 +00:00
|
|
|
static void CreateDesertOrRainForest(uint desert_tropic_line)
|
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
|
|
|
TileIndex update_freq = MapSize() / 4;
|
2022-03-06 02:05:12 +00:00
|
|
|
const Rect16 *data;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2022-03-06 02:05:12 +00:00
|
|
|
const std::pair<const Rect16 *, const Rect16 *> desert_rainforest_data = GetDesertOrRainforestData();
|
2022-03-05 14:59:31 +00:00
|
|
|
|
2008-04-04 16:32:27 +00:00
|
|
|
for (TileIndex 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);
|
|
|
|
|
2010-05-08 14:43:59 +00:00
|
|
|
if (!IsValidTile(tile)) continue;
|
|
|
|
|
2022-03-06 02:05:12 +00:00
|
|
|
DesertOrRainforestProcessTiles(desert_rainforest_data, data, tile, [&](TileIndex t) -> bool {
|
|
|
|
return (t != INVALID_TILE && (TileHeight(t) >= desert_tropic_line || IsTileType(t, MP_WATER)));
|
|
|
|
});
|
2022-03-05 14:59:31 +00:00
|
|
|
if (data == desert_rainforest_data.second) {
|
|
|
|
SetTropicZone(tile, TROPICZONE_DESERT);
|
2010-07-24 10:14:39 +00:00
|
|
|
}
|
2005-01-06 11:39:00 +00:00
|
|
|
}
|
2004-09-08 17:44:29 +00:00
|
|
|
|
2008-04-04 16:32:27 +00:00
|
|
|
for (uint i = 0; i != 256; i++) {
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
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
|
|
|
|
2008-04-04 16:32:27 +00:00
|
|
|
for (TileIndex 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);
|
|
|
|
|
2010-05-08 14:43:59 +00:00
|
|
|
if (!IsValidTile(tile)) continue;
|
|
|
|
|
2022-03-06 02:05:12 +00:00
|
|
|
DesertOrRainforestProcessTiles(desert_rainforest_data, data, tile, [&](TileIndex t) -> bool {
|
|
|
|
return (t != INVALID_TILE && IsTileType(t, MP_CLEAR) && IsClearGround(t, CLEAR_DESERT));
|
|
|
|
});
|
2022-03-05 14:59:31 +00:00
|
|
|
if (data == desert_rainforest_data.second) {
|
|
|
|
SetTropicZone(tile, TROPICZONE_RAINFOREST);
|
2010-07-24 10:14:39 +00:00
|
|
|
}
|
2005-01-06 11:39:00 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2011-08-20 14:14:17 +00:00
|
|
|
/**
|
|
|
|
* Find the spring of a river.
|
|
|
|
* @param tile The tile to consider for being the spring.
|
|
|
|
* @return True iff it is suitable as a spring.
|
|
|
|
*/
|
2023-09-16 20:20:53 +00:00
|
|
|
static bool FindSpring(TileIndex tile, void *)
|
2011-08-20 14:14:17 +00:00
|
|
|
{
|
2011-11-04 11:30:37 +00:00
|
|
|
int referenceHeight;
|
2013-10-12 22:07:58 +00:00
|
|
|
if (!IsTileFlat(tile, &referenceHeight) || IsWaterTile(tile)) return false;
|
2011-08-20 14:14:17 +00:00
|
|
|
|
|
|
|
/* In the tropics rivers start in the rainforest. */
|
2021-11-19 01:59:20 +00:00
|
|
|
if (_settings_game.game_creation.landscape == LT_TROPIC && GetTropicZone(tile) != TROPICZONE_RAINFOREST && !_settings_game.game_creation.lakes_allowed_in_deserts) return false;
|
2011-08-20 14:14:17 +00:00
|
|
|
|
|
|
|
/* Are there enough higher tiles to warrant a 'spring'? */
|
|
|
|
uint num = 0;
|
|
|
|
for (int dx = -1; dx <= 1; dx++) {
|
|
|
|
for (int dy = -1; dy <= 1; dy++) {
|
|
|
|
TileIndex t = TileAddWrap(tile, dx, dy);
|
2011-11-04 10:29:26 +00:00
|
|
|
if (t != INVALID_TILE && GetTileMaxZ(t) > referenceHeight) num++;
|
2011-08-20 14:14:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num < 4) return false;
|
|
|
|
|
2021-03-28 22:45:08 +00:00
|
|
|
if (_settings_game.game_creation.rivers_top_of_hill) {
|
|
|
|
/* Are we near the top of a hill? */
|
|
|
|
for (int dx = -16; dx <= 16; dx++) {
|
|
|
|
for (int dy = -16; dy <= 16; dy++) {
|
|
|
|
TileIndex t = TileAddWrap(tile, dx, dy);
|
|
|
|
if (t != INVALID_TILE && GetTileMaxZ(t) > referenceHeight + 2) return false;
|
|
|
|
}
|
2011-08-20 14:14:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-04-14 00:22:32 +00:00
|
|
|
struct MakeLakeData {
|
|
|
|
TileIndex centre; ///< Lake centre tile
|
|
|
|
uint height; ///< Lake height
|
|
|
|
int max_distance; ///< Max radius
|
|
|
|
int secondary_axis_scale; ///< Multiplier for ellipse narrow axis, 16 bit fixed point
|
|
|
|
int sin_fp; ///< sin of ellipse rotation angle, 16 bit fixed point
|
|
|
|
int cos_fp; ///< cos of ellipse rotation angle, 16 bit fixed point
|
|
|
|
};
|
|
|
|
|
2011-08-20 14:14:17 +00:00
|
|
|
/**
|
|
|
|
* Make a connected lake; fill all tiles in the circular tile search that are connected.
|
|
|
|
* @param tile The tile to consider for lake making.
|
|
|
|
* @param user_data The height of the lake.
|
|
|
|
* @return Always false, so it continues searching.
|
|
|
|
*/
|
|
|
|
static bool MakeLake(TileIndex tile, void *user_data)
|
|
|
|
{
|
2021-04-14 00:22:32 +00:00
|
|
|
const MakeLakeData *data = (const MakeLakeData *)user_data;
|
|
|
|
if (!IsValidTile(tile) || TileHeight(tile) != data->height || !IsTileFlat(tile)) return false;
|
2021-11-19 01:59:20 +00:00
|
|
|
if (_settings_game.game_creation.landscape == LT_TROPIC && GetTropicZone(tile) == TROPICZONE_DESERT && !_settings_game.game_creation.lakes_allowed_in_deserts) return false;
|
2011-08-20 14:14:17 +00:00
|
|
|
|
2021-04-14 00:22:32 +00:00
|
|
|
/* Offset from centre tile */
|
2024-01-07 16:41:53 +00:00
|
|
|
const int64_t x_delta = (int)TileX(tile) - (int)TileX(data->centre);
|
|
|
|
const int64_t y_delta = (int)TileY(tile) - (int)TileY(data->centre);
|
2021-04-14 00:22:32 +00:00
|
|
|
|
|
|
|
/* Rotate to new coordinate system */
|
2024-01-07 16:41:53 +00:00
|
|
|
const int64_t a_delta = (x_delta * data->cos_fp + y_delta * data->sin_fp) >> 8;
|
|
|
|
const int64_t b_delta = (-x_delta * data->sin_fp + y_delta * data->cos_fp) >> 8;
|
2021-04-14 00:22:32 +00:00
|
|
|
|
|
|
|
int max_distance = data->max_distance;
|
|
|
|
if (max_distance >= 6) {
|
|
|
|
/* Vary radius a bit for larger lakes */
|
|
|
|
uint coord = (std::abs(x_delta) > std::abs(y_delta)) ? TileY(tile) : TileX(tile);
|
2024-01-07 16:41:53 +00:00
|
|
|
static const int8_t offset_fuzz[4] = { 0, 1, 0, -1 };
|
2021-04-14 00:22:32 +00:00
|
|
|
max_distance += offset_fuzz[(coord / 3) & 3];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if inside ellipse */
|
2024-01-07 16:41:53 +00:00
|
|
|
if ((a_delta * a_delta) + ((data->secondary_axis_scale * b_delta * b_delta) >> 16) > ((int64_t)(max_distance * max_distance) << 16)) return false;
|
2021-04-14 00:22:32 +00:00
|
|
|
|
2011-08-20 14:14:17 +00:00
|
|
|
for (DiagDirection d = DIAGDIR_BEGIN; d < DIAGDIR_END; d++) {
|
|
|
|
TileIndex t2 = tile + TileOffsByDiagDir(d);
|
|
|
|
if (IsWaterTile(t2)) {
|
|
|
|
MakeRiver(tile, Random());
|
2021-03-09 13:53:51 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
2019-02-23 12:16:12 +00:00
|
|
|
/* Remove desert directly around the river tile. */
|
2024-01-09 03:18:02 +00:00
|
|
|
IterateCurvedCircularTileArea(tile, _settings_game.game_creation.lake_tropics_width, RiverModifyDesertZone, nullptr);
|
2011-08-20 14:14:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether a river at begin could (logically) flow down to end.
|
|
|
|
* @param begin The origin of the flow.
|
|
|
|
* @param end The destination of the flow.
|
|
|
|
* @return True iff the water can be flowing down.
|
|
|
|
*/
|
|
|
|
static bool FlowsDown(TileIndex begin, TileIndex end)
|
|
|
|
{
|
2022-10-22 11:34:54 +00:00
|
|
|
dbg_assert(DistanceManhattan(begin, end) == 1);
|
2011-08-20 14:14:17 +00:00
|
|
|
|
2011-11-04 11:30:37 +00:00
|
|
|
int heightBegin;
|
|
|
|
int heightEnd;
|
2011-11-04 10:29:26 +00:00
|
|
|
Slope slopeBegin = GetTileSlope(begin, &heightBegin);
|
|
|
|
Slope slopeEnd = GetTileSlope(end, &heightEnd);
|
2011-08-20 14:14:17 +00:00
|
|
|
|
|
|
|
return heightEnd <= heightBegin &&
|
|
|
|
/* Slope either is inclined or flat; rivers don't support other slopes. */
|
|
|
|
(slopeEnd == SLOPE_FLAT || IsInclinedSlope(slopeEnd)) &&
|
|
|
|
/* Slope continues, then it must be lower... or either end must be flat. */
|
|
|
|
((slopeEnd == slopeBegin && heightEnd < heightBegin) || slopeEnd == SLOPE_FLAT || slopeBegin == SLOPE_FLAT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* AyStar callback for checking whether we reached our destination. */
|
2024-01-07 16:41:53 +00:00
|
|
|
static int32_t River_EndNodeCheck(const AyStar *aystar, const OpenListNode *current)
|
2011-08-20 14:14:17 +00:00
|
|
|
{
|
|
|
|
return current->path.node.tile == *(TileIndex*)aystar->user_target ? AYSTAR_FOUND_END_NODE : AYSTAR_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* AyStar callback for getting the cost of the current node. */
|
2024-01-07 16:41:53 +00:00
|
|
|
static int32_t River_CalculateG(AyStar *aystar, AyStarNode *current, OpenListNode *parent)
|
2011-08-20 14:14:17 +00:00
|
|
|
{
|
|
|
|
return 1 + RandomRange(_settings_game.game_creation.river_route_random);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* AyStar callback for getting the estimated cost to the destination. */
|
2024-01-07 16:41:53 +00:00
|
|
|
static int32_t River_CalculateH(AyStar *aystar, AyStarNode *current, OpenListNode *parent)
|
2011-08-20 14:14:17 +00:00
|
|
|
{
|
|
|
|
return DistanceManhattan(*(TileIndex*)aystar->user_target, current->tile);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* AyStar callback for getting the neighbouring nodes of the given node. */
|
|
|
|
static void River_GetNeighbours(AyStar *aystar, OpenListNode *current)
|
|
|
|
{
|
|
|
|
TileIndex tile = current->path.node.tile;
|
|
|
|
|
|
|
|
aystar->num_neighbours = 0;
|
|
|
|
for (DiagDirection d = DIAGDIR_BEGIN; d < DIAGDIR_END; d++) {
|
|
|
|
TileIndex t2 = tile + TileOffsByDiagDir(d);
|
|
|
|
if (IsValidTile(t2) && FlowsDown(tile, t2)) {
|
|
|
|
aystar->neighbours[aystar->num_neighbours].tile = t2;
|
|
|
|
aystar->neighbours[aystar->num_neighbours].direction = INVALID_TRACKDIR;
|
|
|
|
aystar->num_neighbours++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-13 05:36:41 +00:00
|
|
|
/** Callback to widen a river tile. */
|
|
|
|
static bool RiverMakeWider(TileIndex tile, void *data)
|
|
|
|
{
|
|
|
|
if (IsValidTile(tile) && !IsWaterTile(tile) && GetTileSlope(tile) == GetTileSlope(*(TileIndex *)data)) {
|
|
|
|
MakeRiver(tile, Random());
|
|
|
|
/* Remove desert directly around the river tile. */
|
|
|
|
|
2024-01-09 03:18:02 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
IterateCurvedCircularTileArea(tile, _settings_game.game_creation.river_tropics_width, RiverModifyDesertZone, nullptr);
|
2021-06-13 05:36:41 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-08-20 14:14:17 +00:00
|
|
|
/* AyStar callback when an route has been found. */
|
|
|
|
static void River_FoundEndNode(AyStar *aystar, OpenListNode *current)
|
|
|
|
{
|
2021-06-15 12:45:46 +00:00
|
|
|
for (PathNode *path = ¤t->path; path != nullptr; path = path->parent) {
|
2011-08-20 20:07:02 +00:00
|
|
|
TileIndex tile = path->node.tile;
|
|
|
|
if (!IsWaterTile(tile)) {
|
|
|
|
MakeRiver(tile, Random());
|
2021-06-13 05:36:41 +00:00
|
|
|
|
|
|
|
// Widen river depending on how far we are away from the source.
|
|
|
|
const uint current_river_length = DistanceManhattan(_current_spring, path->node.tile);
|
|
|
|
const uint long_river_length = _settings_game.game_creation.min_river_length * 4;
|
|
|
|
const uint radius = std::min(3u, (current_river_length / (long_river_length / 3u)) + 1u);
|
2022-03-05 14:59:31 +00:00
|
|
|
|
2021-03-09 13:53:51 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
2021-06-13 05:36:41 +00:00
|
|
|
|
2022-10-22 18:52:51 +00:00
|
|
|
if (_settings_game.game_creation.land_generator != LG_ORIGINAL && _is_main_river && (radius > 1)) {
|
2021-06-13 05:36:41 +00:00
|
|
|
CircularTileSearch(&tile, radius + RandomRange(1), RiverMakeWider, (void *)&path->node.tile);
|
|
|
|
} else {
|
|
|
|
/* Remove desert directly around the river tile. */
|
2024-01-09 03:18:02 +00:00
|
|
|
IterateCurvedCircularTileArea(tile, _settings_game.game_creation.river_tropics_width, RiverModifyDesertZone, nullptr);
|
2021-06-13 05:36:41 +00:00
|
|
|
}
|
2011-08-20 20:07:02 +00:00
|
|
|
}
|
2011-08-20 14:14:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const uint RIVER_HASH_SIZE = 8; ///< The number of bits the hash for river finding should have.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Actually build the river between the begin and end tiles using AyStar.
|
|
|
|
* @param begin The begin of the river.
|
|
|
|
* @param end The end of the river.
|
|
|
|
*/
|
|
|
|
static void BuildRiver(TileIndex begin, TileIndex end)
|
|
|
|
{
|
2018-05-13 17:34:57 +00:00
|
|
|
AyStar finder = {};
|
2011-08-20 14:14:17 +00:00
|
|
|
finder.CalculateG = River_CalculateG;
|
|
|
|
finder.CalculateH = River_CalculateH;
|
|
|
|
finder.GetNeighbours = River_GetNeighbours;
|
|
|
|
finder.EndNodeCheck = River_EndNodeCheck;
|
|
|
|
finder.FoundEndNode = River_FoundEndNode;
|
|
|
|
finder.user_target = &end;
|
2023-12-25 10:16:42 +00:00
|
|
|
finder.max_search_nodes = AYSTAR_DEF_MAX_SEARCH_NODES;
|
2011-08-20 14:14:17 +00:00
|
|
|
|
2021-06-13 15:45:28 +00:00
|
|
|
finder.Init(1 << RIVER_HASH_SIZE);
|
2011-08-20 14:14:17 +00:00
|
|
|
|
|
|
|
AyStarNode start;
|
|
|
|
start.tile = begin;
|
|
|
|
start.direction = INVALID_TRACKDIR;
|
|
|
|
finder.AddStartNode(&start, 0);
|
|
|
|
finder.Main();
|
|
|
|
finder.Free();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Try to flow the river down from a given begin.
|
|
|
|
* @param spring The springing point of the river.
|
|
|
|
* @param begin The begin point we are looking from; somewhere down hill from the spring.
|
2021-06-13 05:36:41 +00:00
|
|
|
* @param min_river_length The minimum length for the river.
|
2011-08-20 14:14:17 +00:00
|
|
|
* @return True iff a river could/has been built, otherwise false.
|
|
|
|
*/
|
2021-06-13 05:36:41 +00:00
|
|
|
static bool FlowRiver(TileIndex spring, TileIndex begin, uint min_river_length)
|
2011-08-20 14:14:17 +00:00
|
|
|
{
|
2020-07-02 21:36:10 +00:00
|
|
|
# define SET_MARK(x) marks.insert(x)
|
|
|
|
# define IS_MARKED(x) (marks.find(x) != marks.end())
|
2014-02-06 20:51:01 +00:00
|
|
|
|
2011-08-20 14:14:17 +00:00
|
|
|
uint height = TileHeight(begin);
|
2021-06-13 05:36:41 +00:00
|
|
|
if (IsWaterTile(begin))
|
|
|
|
{
|
|
|
|
if (GetTileZ(begin) == 0) {
|
|
|
|
_current_estuary = begin;
|
|
|
|
_is_main_river = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DistanceManhattan(spring, begin) > min_river_length;
|
|
|
|
}
|
2011-08-20 14:14:17 +00:00
|
|
|
|
2017-02-08 00:18:09 +00:00
|
|
|
btree::btree_set<TileIndex> marks;
|
2014-02-06 20:51:01 +00:00
|
|
|
SET_MARK(begin);
|
2011-08-20 14:14:17 +00:00
|
|
|
|
|
|
|
/* Breadth first search for the closest tile we can flow down to. */
|
2023-08-18 17:48:12 +00:00
|
|
|
ring_buffer<TileIndex> queue;
|
2011-08-20 14:14:17 +00:00
|
|
|
queue.push_back(begin);
|
|
|
|
|
|
|
|
bool found = false;
|
|
|
|
uint count = 0; // Number of tiles considered; to be used for lake location guessing.
|
|
|
|
TileIndex end;
|
|
|
|
do {
|
|
|
|
end = queue.front();
|
|
|
|
queue.pop_front();
|
|
|
|
|
|
|
|
uint height2 = TileHeight(end);
|
2013-10-12 22:07:58 +00:00
|
|
|
if (IsTileFlat(end) && (height2 < height || (height2 == height && IsWaterTile(end)))) {
|
2011-08-20 14:14:17 +00:00
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (DiagDirection d = DIAGDIR_BEGIN; d < DIAGDIR_END; d++) {
|
|
|
|
TileIndex t2 = end + TileOffsByDiagDir(d);
|
2014-02-06 20:51:01 +00:00
|
|
|
if (IsValidTile(t2) && !IS_MARKED(t2) && FlowsDown(end, t2)) {
|
|
|
|
SET_MARK(t2);
|
2011-08-20 14:14:17 +00:00
|
|
|
count++;
|
|
|
|
queue.push_back(t2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (!queue.empty());
|
|
|
|
|
|
|
|
if (found) {
|
|
|
|
/* Flow further down hill. */
|
2021-06-13 05:36:41 +00:00
|
|
|
found = FlowRiver(spring, end, min_river_length);
|
2021-06-13 06:15:43 +00:00
|
|
|
} else if (count > 32 && _settings_game.game_creation.lake_size != 0) {
|
2011-08-20 14:14:17 +00:00
|
|
|
/* Maybe we can make a lake. Find the Nth of the considered tiles. */
|
|
|
|
TileIndex lakeCenter = 0;
|
2014-02-06 20:51:01 +00:00
|
|
|
int i = RandomRange(count - 1) + 1;
|
2017-02-08 00:18:09 +00:00
|
|
|
btree::btree_set<TileIndex>::const_iterator cit = marks.begin();
|
2014-02-06 20:51:01 +00:00
|
|
|
while (--i) cit++;
|
|
|
|
lakeCenter = *cit;
|
2011-08-20 14:14:17 +00:00
|
|
|
|
|
|
|
if (IsValidTile(lakeCenter) &&
|
|
|
|
/* A river, or lake, can only be built on flat slopes. */
|
2013-10-12 22:07:58 +00:00
|
|
|
IsTileFlat(lakeCenter) &&
|
2011-08-20 14:14:17 +00:00
|
|
|
/* We want the lake to be built at the height of the river. */
|
|
|
|
TileHeight(begin) == TileHeight(lakeCenter) &&
|
|
|
|
/* We don't want the lake at the entry of the valley. */
|
|
|
|
lakeCenter != begin &&
|
|
|
|
/* We don't want lakes in the desert. */
|
2021-03-28 22:45:08 +00:00
|
|
|
(_settings_game.game_creation.landscape != LT_TROPIC || _settings_game.game_creation.lakes_allowed_in_deserts || GetTropicZone(lakeCenter) != TROPICZONE_DESERT) &&
|
2011-08-20 14:14:17 +00:00
|
|
|
/* We only want a lake if the river is long enough. */
|
2021-06-13 05:36:41 +00:00
|
|
|
DistanceManhattan(spring, lakeCenter) > min_river_length) {
|
2011-08-20 14:14:17 +00:00
|
|
|
end = lakeCenter;
|
|
|
|
MakeRiver(lakeCenter, Random());
|
2021-03-09 13:53:51 +00:00
|
|
|
MarkTileDirtyByTile(lakeCenter);
|
2019-02-23 12:16:12 +00:00
|
|
|
/* Remove desert directly around the river tile. */
|
2024-01-09 03:18:02 +00:00
|
|
|
IterateCurvedCircularTileArea(lakeCenter, _settings_game.game_creation.river_tropics_width, RiverModifyDesertZone, nullptr);
|
2021-06-13 06:15:43 +00:00
|
|
|
|
|
|
|
// Setting lake size +- 25%
|
|
|
|
const auto random_percentage = 75 + RandomRange(50);
|
|
|
|
const uint range = ((_settings_game.game_creation.lake_size * random_percentage) / 100) + 3;
|
2021-04-14 00:22:32 +00:00
|
|
|
|
|
|
|
MakeLakeData data;
|
|
|
|
data.centre = lakeCenter;
|
|
|
|
data.height = height;
|
|
|
|
data.max_distance = range / 2;
|
|
|
|
|
|
|
|
/* Square of ratio of ellipse dimensions: 1 to 5 (16 bit fixed point) */
|
|
|
|
data.secondary_axis_scale = (1 << 16) + RandomRange(1 << 18);
|
|
|
|
|
|
|
|
/* Range from -1 to 1 (16 bit fixed point) */
|
|
|
|
data.sin_fp = RandomRange(1 << 17) - (1 << 16);
|
|
|
|
|
|
|
|
/* sin^2 + cos^2 = 1 */
|
2024-01-07 16:41:53 +00:00
|
|
|
data.cos_fp = IntSqrt64(((int64_t)1 << 32) - ((int64_t)data.sin_fp * (int64_t)data.sin_fp));
|
2021-04-14 00:22:32 +00:00
|
|
|
|
|
|
|
CircularTileSearch(&lakeCenter, range, MakeLake, &data);
|
2011-08-20 14:14:17 +00:00
|
|
|
/* Call the search a second time so artefacts from going circular in one direction get (mostly) hidden. */
|
|
|
|
lakeCenter = end;
|
2021-04-14 00:22:32 +00:00
|
|
|
CircularTileSearch(&lakeCenter, range, MakeLake, &data);
|
2011-08-20 14:14:17 +00:00
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-06 20:51:01 +00:00
|
|
|
marks.clear();
|
2011-08-20 14:14:17 +00:00
|
|
|
if (found) BuildRiver(begin, end);
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Actually (try to) create some rivers.
|
|
|
|
*/
|
|
|
|
static void CreateRivers()
|
|
|
|
{
|
|
|
|
int amount = _settings_game.game_creation.amount_of_rivers;
|
|
|
|
if (amount == 0) return;
|
|
|
|
|
2011-08-20 14:15:40 +00:00
|
|
|
uint wells = ScaleByMapSize(4 << _settings_game.game_creation.amount_of_rivers);
|
2021-06-13 05:36:41 +00:00
|
|
|
const uint num_short_rivers = wells - std::max(1u, wells / 10);
|
2011-08-20 20:07:02 +00:00
|
|
|
SetGeneratingWorldProgress(GWP_RIVER, wells + 256 / 64); // Include the tile loop calls below.
|
2011-08-20 14:14:17 +00:00
|
|
|
|
2021-06-13 05:36:41 +00:00
|
|
|
for (; wells > num_short_rivers; wells--) {
|
|
|
|
IncreaseGeneratingWorldProgress(GWP_RIVER);
|
2021-06-13 06:15:43 +00:00
|
|
|
for (int tries = 0; tries < 128; tries++) {
|
2021-06-13 05:36:41 +00:00
|
|
|
TileIndex t = RandomTile();
|
|
|
|
if (!CircularTileSearch(&t, 8, FindSpring, nullptr)) continue;
|
|
|
|
_current_spring = t;
|
|
|
|
_is_main_river = false;
|
|
|
|
if (FlowRiver(t, t, _settings_game.game_creation.min_river_length * 4)) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-20 14:15:40 +00:00
|
|
|
for (; wells != 0; wells--) {
|
|
|
|
IncreaseGeneratingWorldProgress(GWP_RIVER);
|
2011-08-20 14:14:17 +00:00
|
|
|
for (int tries = 0; tries < 128; tries++) {
|
|
|
|
TileIndex t = RandomTile();
|
2019-04-10 21:07:06 +00:00
|
|
|
if (!CircularTileSearch(&t, 8, FindSpring, nullptr)) continue;
|
2021-06-13 05:36:41 +00:00
|
|
|
_current_spring = t;
|
|
|
|
_is_main_river = false;
|
|
|
|
if (FlowRiver(t, t, _settings_game.game_creation.min_river_length)) break;
|
2011-08-20 14:14:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-14 13:20:19 +00:00
|
|
|
/* Widening rivers may have left some tiles requiring to be watered. */
|
|
|
|
ConvertGroundTilesIntoWaterTiles();
|
|
|
|
|
2011-08-20 20:07:02 +00:00
|
|
|
/* Run tile loop to update the ground density. */
|
|
|
|
for (uint i = 0; i != 256; i++) {
|
|
|
|
if (i % 64 == 0) IncreaseGeneratingWorldProgress(GWP_RIVER);
|
|
|
|
RunTileLoop();
|
|
|
|
}
|
2011-08-20 14:14:17 +00:00
|
|
|
}
|
|
|
|
|
2021-03-24 13:48:12 +00:00
|
|
|
/**
|
2021-03-24 15:38:36 +00:00
|
|
|
* Calculate what height would be needed to cover N% of the landmass.
|
|
|
|
*
|
|
|
|
* The function allows both snow and desert/tropic line to be calculated. It
|
|
|
|
* tries to find the closests height which covers N% of the landmass; it can
|
|
|
|
* be below or above it.
|
|
|
|
*
|
|
|
|
* Tropic has a mechanism where water and tropic tiles in mountains grow
|
|
|
|
* inside the desert. To better approximate the requested coverage, this is
|
|
|
|
* taken into account via an edge histogram, which tells how many neighbouring
|
|
|
|
* tiles are lower than the tiles of that height. The multiplier indicates how
|
|
|
|
* severe this has to be taken into account.
|
|
|
|
*
|
|
|
|
* @param coverage A value between 0 and 100 indicating a percentage of landmass that should be covered.
|
|
|
|
* @param edge_multiplier How much effect neighbouring tiles that are of a lower height level have on the score.
|
|
|
|
* @return The estimated best height to use to cover N% of the landmass.
|
2021-03-24 13:48:12 +00:00
|
|
|
*/
|
2021-03-24 15:38:36 +00:00
|
|
|
static uint CalculateCoverageLine(uint coverage, uint edge_multiplier)
|
2021-03-24 13:48:12 +00:00
|
|
|
{
|
2021-03-24 15:38:36 +00:00
|
|
|
const DiagDirection neighbour_dir[] = {
|
|
|
|
DIAGDIR_NE,
|
|
|
|
DIAGDIR_SE,
|
|
|
|
DIAGDIR_SW,
|
|
|
|
DIAGDIR_NW,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Histogram of how many tiles per height level exist. */
|
2021-03-24 13:48:12 +00:00
|
|
|
std::array<int, MAX_TILE_HEIGHT + 1> histogram = {};
|
2021-03-24 15:38:36 +00:00
|
|
|
/* Histogram of how many neighbour tiles are lower than the tiles of the height level. */
|
|
|
|
std::array<int, MAX_TILE_HEIGHT + 1> edge_histogram = {};
|
|
|
|
|
|
|
|
/* Build a histogram of the map height. */
|
2021-03-24 13:48:12 +00:00
|
|
|
for (TileIndex tile = 0; tile < MapSize(); tile++) {
|
|
|
|
uint h = TileHeight(tile);
|
|
|
|
histogram[h]++;
|
2021-03-24 15:38:36 +00:00
|
|
|
|
|
|
|
if (edge_multiplier != 0) {
|
|
|
|
/* Check if any of our neighbours is below us. */
|
|
|
|
for (auto dir : neighbour_dir) {
|
|
|
|
TileIndex neighbour_tile = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDiagDir(dir));
|
|
|
|
if (IsValidTile(neighbour_tile) && TileHeight(neighbour_tile) < h) {
|
|
|
|
edge_histogram[h]++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-03-24 13:48:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The amount of land we have is the map size minus the first (sea) layer. */
|
2023-01-23 19:10:07 +00:00
|
|
|
uint land_tiles = MapSize() - histogram[0];
|
2021-03-24 13:48:12 +00:00
|
|
|
int best_score = land_tiles;
|
|
|
|
|
|
|
|
/* Our goal is the coverage amount of the land-mass. */
|
2021-03-24 15:38:36 +00:00
|
|
|
int goal_tiles = land_tiles * coverage / 100;
|
2021-03-24 13:48:12 +00:00
|
|
|
|
|
|
|
/* We scan from top to bottom. */
|
|
|
|
uint h = MAX_TILE_HEIGHT;
|
|
|
|
uint best_h = h;
|
|
|
|
|
|
|
|
int current_tiles = 0;
|
|
|
|
for (; h > 0; h--) {
|
|
|
|
current_tiles += histogram[h];
|
|
|
|
int current_score = goal_tiles - current_tiles;
|
|
|
|
|
2021-03-24 15:38:36 +00:00
|
|
|
/* Tropic grows from water and mountains into the desert. This is a
|
|
|
|
* great visual, but it also means we* need to take into account how
|
|
|
|
* much less desert tiles are being created if we are on this
|
|
|
|
* height-level. We estimate this based on how many neighbouring
|
|
|
|
* tiles are below us for a given length, assuming that is where
|
|
|
|
* tropic is growing from.
|
|
|
|
*/
|
|
|
|
if (edge_multiplier != 0 && h > 1) {
|
|
|
|
/* From water tropic tiles grow for a few tiles land inward. */
|
|
|
|
current_score -= edge_histogram[1] * edge_multiplier;
|
|
|
|
/* Tropic tiles grow into the desert for a few tiles. */
|
|
|
|
current_score -= edge_histogram[h] * edge_multiplier;
|
|
|
|
}
|
|
|
|
|
2021-03-24 13:48:12 +00:00
|
|
|
if (std::abs(current_score) < std::abs(best_score)) {
|
|
|
|
best_score = current_score;
|
|
|
|
best_h = h;
|
|
|
|
}
|
2021-03-24 15:38:36 +00:00
|
|
|
|
|
|
|
/* Always scan all height-levels, as h == 1 might give a better
|
|
|
|
* score than any before. This is true for example with 0% desert
|
|
|
|
* coverage. */
|
2021-03-24 13:48:12 +00:00
|
|
|
}
|
|
|
|
|
2021-03-24 15:38:36 +00:00
|
|
|
return best_h;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculate the line from which snow begins.
|
|
|
|
*/
|
|
|
|
static void CalculateSnowLine()
|
|
|
|
{
|
2021-04-10 17:29:36 +00:00
|
|
|
if (_settings_game.game_creation.climate_threshold_mode == 0) {
|
|
|
|
/* We do not have snow sprites on coastal tiles, so never allow "1" as height. */
|
|
|
|
_settings_game.game_creation.snow_line_height = std::max(CalculateCoverageLine(_settings_game.game_creation.snow_coverage, 0), 2u);
|
|
|
|
}
|
|
|
|
UpdateCachedSnowLine();
|
2022-04-29 16:10:18 +00:00
|
|
|
UpdateCachedSnowLineBounds();
|
2021-03-24 15:38:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculate the line (in height) between desert and tropic.
|
|
|
|
* @return The height of the line between desert and tropic.
|
|
|
|
*/
|
2024-01-07 16:41:53 +00:00
|
|
|
static uint8_t CalculateDesertLine()
|
2021-03-24 15:38:36 +00:00
|
|
|
{
|
2021-04-10 17:29:36 +00:00
|
|
|
if (_settings_game.game_creation.climate_threshold_mode != 0) return _settings_game.game_creation.rainforest_line_height;
|
|
|
|
|
2021-03-24 15:38:36 +00:00
|
|
|
/* CalculateCoverageLine() runs from top to bottom, so we need to invert the coverage. */
|
2021-04-10 17:29:36 +00:00
|
|
|
return CalculateCoverageLine(100 - _settings_game.game_creation.desert_coverage, 4);
|
2021-03-24 13:48:12 +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
|
|
|
{
|
2010-01-17 21:40:35 +00:00
|
|
|
/** Number of steps of landscape generation */
|
|
|
|
enum GenLandscapeSteps {
|
|
|
|
GLS_HEIGHTMAP = 3, ///< Loading a heightmap
|
|
|
|
GLS_TERRAGENESIS = 5, ///< Terragenesis generator
|
|
|
|
GLS_ORIGINAL = 2, ///< Original generator
|
|
|
|
GLS_TROPIC = 12, ///< Extra steps needed for tropic landscape
|
|
|
|
GLS_OTHER = 0, ///< Extra steps for other landscapes
|
|
|
|
};
|
|
|
|
uint steps = (_settings_game.game_creation.landscape == LT_TROPIC) ? GLS_TROPIC : GLS_OTHER;
|
2004-09-08 17:44:29 +00:00
|
|
|
|
2010-01-17 22:59:24 +00:00
|
|
|
if (mode == GWM_HEIGHTMAP) {
|
2010-01-17 21:40:35 +00:00
|
|
|
SetGeneratingWorldProgress(GWP_LANDSCAPE, steps + GLS_HEIGHTMAP);
|
2020-12-06 20:11:45 +00:00
|
|
|
LoadHeightmap(_file_to_saveload.detail_ftype, _file_to_saveload.name.c_str());
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
|
2008-05-29 15:13:28 +00:00
|
|
|
} else if (_settings_game.game_creation.land_generator == LG_TERRAGENESIS) {
|
2010-01-17 21:40:35 +00:00
|
|
|
SetGeneratingWorldProgress(GWP_LANDSCAPE, steps + GLS_TERRAGENESIS);
|
(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 {
|
2010-01-17 21:40:35 +00:00
|
|
|
SetGeneratingWorldProgress(GWP_LANDSCAPE, steps + GLS_ORIGINAL);
|
2009-02-17 20:33:13 +00:00
|
|
|
if (_settings_game.construction.freeform_edges) {
|
|
|
|
for (uint x = 0; x < MapSizeX(); x++) MakeVoid(TileXY(x, 0));
|
|
|
|
for (uint y = 0; y < MapSizeY(); y++) MakeVoid(TileXY(0, y));
|
|
|
|
}
|
2008-05-29 15:13:28 +00:00
|
|
|
switch (_settings_game.game_creation.landscape) {
|
2008-04-04 16:32:27 +00:00
|
|
|
case LT_ARCTIC: {
|
2024-01-07 16:41:53 +00:00
|
|
|
uint32_t r = Random();
|
2008-04-04 16:32:27 +00:00
|
|
|
|
|
|
|
for (uint i = ScaleByMapSize(GB(r, 0, 7) + 950); i != 0; --i) {
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
GenerateTerrain(2, 0);
|
|
|
|
}
|
2006-02-13 21:15:00 +00:00
|
|
|
|
2008-04-04 16:32:27 +00:00
|
|
|
uint flag = GB(r, 7, 2) | 4;
|
|
|
|
for (uint i = ScaleByMapSize(GB(r, 9, 7) + 450); i != 0; --i) {
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
GenerateTerrain(4, flag);
|
|
|
|
}
|
2010-08-01 18:53:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-09-08 17:44:29 +00:00
|
|
|
|
2008-04-04 16:32:27 +00:00
|
|
|
case LT_TROPIC: {
|
2024-01-07 16:41:53 +00:00
|
|
|
uint32_t r = Random();
|
2008-04-04 16:32:27 +00:00
|
|
|
|
|
|
|
for (uint i = ScaleByMapSize(GB(r, 0, 7) + 170); i != 0; --i) {
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
GenerateTerrain(0, 0);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-04-04 16:32:27 +00:00
|
|
|
uint flag = GB(r, 7, 2) | 4;
|
|
|
|
for (uint i = ScaleByMapSize(GB(r, 9, 8) + 1700); i != 0; --i) {
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
GenerateTerrain(0, flag);
|
|
|
|
}
|
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;
|
|
|
|
|
2008-04-04 16:32:27 +00:00
|
|
|
for (uint i = ScaleByMapSize(GB(r, 17, 7) + 410); i != 0; --i) {
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
GenerateTerrain(3, flag);
|
|
|
|
}
|
2010-08-01 18:53:30 +00:00
|
|
|
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
|
|
|
|
2008-04-04 16:32:27 +00:00
|
|
|
default: {
|
2024-01-07 16:41:53 +00:00
|
|
|
uint32_t r = Random();
|
2008-04-04 16:32:27 +00:00
|
|
|
|
2010-11-04 18:34:37 +00:00
|
|
|
assert(_settings_game.difficulty.quantity_sea_lakes != CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY);
|
2008-05-29 15:13:28 +00:00
|
|
|
uint i = ScaleByMapSize(GB(r, 0, 7) + (3 - _settings_game.difficulty.quantity_sea_lakes) * 256 + 100);
|
(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) {
|
2014-10-13 14:22:48 +00:00
|
|
|
/* Make sure we do not overflow. */
|
|
|
|
GenerateTerrain(Clamp(_settings_game.difficulty.terrain_type, 0, 3), 0);
|
(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
|
|
|
}
|
2010-08-01 18:53:30 +00:00
|
|
|
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
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2010-01-17 20:28:08 +00:00
|
|
|
/* Do not call IncreaseGeneratingWorldProgress() before FixSlopes(),
|
|
|
|
* it allows screen redraw. Drawing of broken slopes crashes the game */
|
2009-03-30 08:59:26 +00:00
|
|
|
FixSlopes();
|
2021-03-09 13:53:51 +00:00
|
|
|
MarkWholeScreenDirty();
|
2010-01-17 20:28:08 +00:00
|
|
|
IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
|
2021-03-09 13:53:51 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
ConvertGroundTilesIntoWaterTiles();
|
2021-03-09 13:53:51 +00:00
|
|
|
MarkWholeScreenDirty();
|
2010-01-17 20:28:08 +00:00
|
|
|
IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2021-03-24 13:48:12 +00:00
|
|
|
switch (_settings_game.game_creation.landscape) {
|
|
|
|
case LT_ARCTIC:
|
|
|
|
CalculateSnowLine();
|
|
|
|
break;
|
|
|
|
|
2021-03-24 15:38:36 +00:00
|
|
|
case LT_TROPIC: {
|
|
|
|
uint desert_tropic_line = CalculateDesertLine();
|
|
|
|
CreateDesertOrRainForest(desert_tropic_line);
|
2021-03-24 13:48:12 +00:00
|
|
|
break;
|
2021-03-24 15:38:36 +00:00
|
|
|
}
|
2021-03-24 13:48:12 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2011-08-20 14:14:17 +00:00
|
|
|
|
|
|
|
CreateRivers();
|
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
|
|
|
|
2013-06-09 12:58:37 +00:00
|
|
|
void OnTick_LinkGraph();
|
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
|
|
|
{
|
2018-07-19 19:17:07 +00:00
|
|
|
{
|
|
|
|
PerformanceAccumulator framerate(PFE_GL_LANDSCAPE);
|
|
|
|
|
|
|
|
OnTick_Town();
|
2023-08-28 14:17:53 +00:00
|
|
|
RecordSyncEvent(NSRE_TOWN);
|
2018-07-19 19:17:07 +00:00
|
|
|
OnTick_Trees();
|
2023-08-28 14:17:53 +00:00
|
|
|
RecordSyncEvent(NSRE_TREE);
|
2018-07-19 19:17:07 +00:00
|
|
|
OnTick_Station();
|
2023-08-28 14:17:53 +00:00
|
|
|
RecordSyncEvent(NSRE_STATION);
|
2018-07-19 19:17:07 +00:00
|
|
|
OnTick_Industry();
|
2023-08-28 14:17:53 +00:00
|
|
|
RecordSyncEvent(NSRE_INDUSTRY);
|
2018-07-19 19:17:07 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2013-06-09 12:58:37 +00:00
|
|
|
OnTick_LinkGraph();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|