OpenTTD Source
20240915-master-g3784a3d3d6
|
Go to the documentation of this file.
42 #include "table/strings.h"
48 _tile_type_clear_procs,
49 _tile_type_rail_procs,
52 _tile_type_trees_procs,
53 _tile_type_station_procs,
54 _tile_type_water_procs,
55 _tile_type_void_procs,
56 _tile_type_industry_procs,
57 _tile_type_tunnelbridge_procs,
58 _tile_type_object_procs;
66 &_tile_type_clear_procs,
67 &_tile_type_rail_procs,
70 &_tile_type_trees_procs,
71 &_tile_type_station_procs,
72 &_tile_type_water_procs,
73 &_tile_type_void_procs,
74 &_tile_type_industry_procs,
75 &_tile_type_tunnelbridge_procs,
76 &_tile_type_object_procs,
81 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0,
82 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 17, 0, 15, 18, 0,
113 if (clamped !=
nullptr) *clamped =
false;
131 if (clamped !=
nullptr) *clamped = (pt.x != old_pt.x) || (pt.y != old_pt.y);
141 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;
142 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;
143 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;
154 pt.x =
Clamp(pt.x, min_coord, max_x);
155 pt.y =
Clamp(pt.y, min_coord, max_y);
156 if (clamped !=
nullptr) *clamped = *clamped || (pt.x != old_pt.x) || (pt.y != old_pt.y);
195 s = (((highest_corner == CORNER_W) || (highest_corner == CORNER_S)) ?
SLOPE_SW :
SLOPE_NE);
199 s = (((highest_corner == CORNER_S) || (highest_corner == CORNER_E)) ?
SLOPE_SE :
SLOPE_NW);
210 default: NOT_REACHED();
250 default: NOT_REACHED();
259 case SLOPE_E:
return y >= x ? (1 + y - x) >> 1 : 0;
261 case SLOPE_W:
return x >= y ? (x - y) >> 1 : 0;
277 case SLOPE_EW:
return x >= y ? (x - y) >> 1 : (1 + y - x) >> 1;
288 default: NOT_REACHED();
356 static const Slope corners[4][4] = {
366 if (halftile_test == corners[edge][0]) z2 +=
TILE_HEIGHT;
367 if (halftile_test == corners[edge][1]) z1 +=
TILE_HEIGHT;
369 if ((tileh & corners[edge][0]) != 0) z1 +=
TILE_HEIGHT;
370 if ((tileh & corners[edge][1]) != 0) z2 +=
TILE_HEIGHT;
391 bool HasFoundationNW(
TileIndex tile,
Slope slope_here, uint z_here)
393 int z_W_here = z_here;
394 int z_N_here = z_here;
402 return (z_N_here > z_N) || (z_W_here > z_W);
406 bool HasFoundationNE(
TileIndex tile,
Slope slope_here, uint z_here)
408 int z_E_here = z_here;
409 int z_N_here = z_here;
417 return (z_N_here > z_N) || (z_E_here > z_E);
432 uint sprite_block = 0;
441 if (!HasFoundationNW(ti->
tile, slope, z)) sprite_block += 1;
442 if (!HasFoundationNE(ti->
tile, slope, z)) sprite_block += 2;
445 SpriteID leveled_base = (sprite_block == 0 ? (int)SPR_FOUNDATION_BASE : (SPR_SLOPES_VIRTUAL_BASE + sprite_block * SPR_TRKFOUND_BLOCK_SIZE));
446 SpriteID inclined_base = SPR_SLOPES_VIRTUAL_BASE + SPR_SLOPES_INCLINED_OFFSET + sprite_block * SPR_TRKFOUND_BLOCK_SIZE;
478 int x_bb = (((highest_corner == CORNER_W) || (highest_corner == CORNER_S)) ?
TILE_SIZE / 2 : 0);
479 int y_bb = (((highest_corner == CORNER_S) || (highest_corner == CORNER_E)) ?
TILE_SIZE / 2 : 0);
484 Point pt = {(y_bb - x_bb) * 2, y_bb + x_bb};
495 int x_bb = (((halftile_corner == CORNER_W) || (halftile_corner == CORNER_S)) ?
TILE_SIZE / 2 : 0);
496 int y_bb = (((halftile_corner == CORNER_S) || (halftile_corner == CORNER_E)) ?
TILE_SIZE / 2 : 0);
501 Point pt = {(y_bb - x_bb) * 2, y_bb + x_bb};
538 if (remove) RemoveDockingTile(tile);
655 bool do_clear =
false;
672 if (coa !=
nullptr && coa->
first_tile != tile) {
716 bool had_success =
false;
719 int limit = (c ==
nullptr ? INT32_MAX :
GB(c->
clear_limit, 16, 16));
738 if (ret.
GetCost() > 0 && money < 0) {
739 return { cost, ret.
GetCost() };
753 if (ret.
GetCost() != 0 && --limit <= 0)
break;
758 return { had_success ? cost : last_error, 0 };
777 static const uint32_t feedbacks[] = {
778 0xD8F, 0x1296, 0x2496, 0x4357, 0x8679, 0x1030E, 0x206CD, 0x403FE, 0x807B8, 0x1004B2, 0x2006A8, 0x4004B2, 0x800B87
801 tile = (tile.base() >> 1) ^ (-(int32_t)(tile.base() & 1) & feedback);
804 _cur_tileloop_tile = tile;
807 void InitializeLandscape()
822 static const uint8_t _genterrain_tbl_1[5] = { 10, 22, 33, 37, 4 };
823 static const uint8_t _genterrain_tbl_2[5] = { 0, 0, 0, 0, 33 };
825 static void GenerateTerrain(
int type, uint flag)
827 uint32_t r = Random();
830 const Sprite *templ = GetSprite((((r >> 24) * _genterrain_tbl_1[type]) >> 8) + _genterrain_tbl_2[type] + SPR_MAPGEN_BEGIN,
SpriteType::MapGen);
831 if (templ ==
nullptr) UserError(
"Map generator sprites could not be loaded");
839 if (x <= edge_distance || y <= edge_distance)
return;
842 uint w = templ->
width;
847 const uint8_t *p = templ->
data;
849 if ((flag & 4) != 0) {
858 default: NOT_REACHED();
860 if (xw + yw >
Map::Size() - bias)
return;
864 if (yw < xw + bias)
return;
868 if (xw + yw <
Map::Size() + bias)
return;
872 if (xw < yw + bias)
return;
887 default: NOT_REACHED();
892 for (uint w_cur = w; w_cur != 0; --w_cur) {
905 for (uint h_cur = h; h_cur != 0; --h_cur) {
919 for (uint w_cur = w; w_cur != 0; --w_cur) {
933 for (uint h_cur = h; h_cur != 0; --h_cur) {
947 static void CreateDesertOrRainForest(uint desert_tropic_line)
956 auto allows_desert = [tile, desert_tropic_line](
auto &offset) {
960 if (std::all_of(std::begin(_make_desert_or_rainforest_data), std::end(_make_desert_or_rainforest_data), allows_desert)) {
976 auto allows_rainforest = [tile](
auto &offset) {
980 if (std::all_of(std::begin(_make_desert_or_rainforest_data), std::end(_make_desert_or_rainforest_data), allows_rainforest)) {
1001 for (
int dx = -1; dx <= 1; dx++) {
1002 for (
int dy = -1; dy <= 1; dy++) {
1008 if (num < 4)
return false;
1011 for (
int dx = -16; dx <= 16; dx++) {
1012 for (
int dy = -16; dy <= 16; dy++) {
1029 uint height = *(uint*)user_data;
1073 bool flat_river_found =
false;
1074 bool sloped_river_found =
false;
1093 desired_slope = other_slope;
1094 sloped_river_found =
true;
1099 if (
IsTileFlat(other_tile)) flat_river_found =
true;
1103 if (!sloped_river_found && !flat_river_found)
return false;
1106 if (!sloped_river_found && flat_river_found) desired_slope =
SLOPE_FLAT;
1133 Slope to_change = cur_slope ^ desired_slope;
1144 to_change = cur_slope ^ desired_slope;
1166 if (!
IsWaterTile(downstream_tile) && !downstream_is_ocean) {
1183 if (cur_slope == desired_slope) {
1204 return heightEnd <= heightBegin &&
1208 ((slopeEnd == slopeBegin && heightEnd < heightBegin) || slopeEnd ==
SLOPE_FLAT || slopeBegin ==
SLOPE_FLAT);
1218 static int32_t River_EndNodeCheck(
const AyStar *aystar,
const PathNode *current)
1236 static void River_GetNeighbours(
AyStar *aystar,
PathNode *current)
1240 aystar->neighbours.clear();
1244 auto &neighbour = aystar->neighbours.emplace_back();
1245 neighbour.m_tile = t2;
1252 static void River_FoundEndNode(
AyStar *aystar,
PathNode *current)
1258 for (
PathNode *path = current->m_parent; path !=
nullptr; path = path->m_parent, cur_pos++) {
1270 uint current_river_length;
1274 for (
PathNode *path = current->m_parent; path !=
nullptr; path = path->m_parent, cur_pos++) {
1279 radius = std::min(3u, (current_river_length / (long_river_length / 3u)) + 1u);
1298 finder.CalculateG = River_CalculateG;
1299 finder.CalculateH = River_CalculateH;
1300 finder.GetNeighbours = River_GetNeighbours;
1301 finder.EndNodeCheck = River_EndNodeCheck;
1302 finder.FoundEndNode = River_FoundEndNode;
1303 finder.user_target = &end;
1304 finder.user_data = &user_data;
1307 start.m_tile = begin;
1322 # define SET_MARK(x) marks.insert(x)
1323 # define IS_MARKED(x) (marks.find(x) != marks.end())
1331 std::set<TileIndex> marks;
1335 std::list<TileIndex> queue;
1336 queue.push_back(begin);
1342 end = queue.front();
1356 queue.push_back(t2);
1359 }
while (!queue.empty());
1361 bool main_river =
false;
1364 std::tie(found, main_river) =
FlowRiver(spring, end, min_river_length);
1365 }
else if (count > 32) {
1367 std::set<TileIndex>::const_iterator cit = marks.cbegin();
1377 lakeCenter != begin &&
1394 if (found)
BuildRiver(begin, end, spring, main_river);
1395 return { found, main_river };
1404 if (amount == 0)
return;
1407 const uint num_short_rivers = wells - std::max(1u, wells / 10);
1411 for (; wells > num_short_rivers; wells--) {
1413 for (
int tries = 0; tries < 512; tries++) {
1421 for (; wells != 0; wells--) {
1423 for (
int tries = 0; tries < 128; tries++) {
1431 ConvertGroundTilesIntoWaterTiles();
1467 std::array<int, MAX_TILE_HEIGHT + 1> histogram = {};
1469 std::array<int, MAX_TILE_HEIGHT + 1> edge_histogram = {};
1476 if (edge_multiplier != 0) {
1478 for (
auto dir : neighbour_dir) {
1481 edge_histogram[h]++;
1488 uint land_tiles =
Map::Size() - histogram[0];
1489 int best_score = land_tiles;
1492 int goal_tiles = land_tiles * coverage / 100;
1498 int current_tiles = 0;
1499 for (; h > 0; h--) {
1500 current_tiles += histogram[h];
1501 int current_score = goal_tiles - current_tiles;
1510 if (edge_multiplier != 0 && h > 1) {
1512 current_score -= edge_histogram[1] * edge_multiplier;
1514 current_score -= edge_histogram[h] * edge_multiplier;
1518 best_score = current_score;
1552 enum GenLandscapeSteps {
1554 GLS_TERRAGENESIS = 5,
1578 uint32_t r = Random();
1581 GenerateTerrain(2, 0);
1584 uint flag =
GB(r, 7, 2) | 4;
1586 GenerateTerrain(4, flag);
1592 uint32_t r = Random();
1595 GenerateTerrain(0, 0);
1598 uint flag =
GB(r, 7, 2) | 4;
1600 GenerateTerrain(0, flag);
1606 GenerateTerrain(3, flag);
1612 uint32_t r = Random();
1616 for (; i != 0; --i) {
1631 ConvertGroundTilesIntoWaterTiles();
1642 CreateDesertOrRainForest(desert_tropic_line);
1655 void OnTick_Trees();
1656 void OnTick_Station();
1657 void OnTick_Industry();
1662 void CallLandscapeTick()
uint16_t height
Height of the sprite.
uint8_t highest_value
Highest snow line of the year.
@ SLOPE_E
the east corner of the tile is raised
void GenerateTerrainPerlin()
The main new land generator using Perlin noise.
static bool FindSpring(TileIndex tile, void *)
Find the spring of a river.
bool IsFoundation(Foundation f)
Tests for FOUNDATION_NONE.
@ SLOPE_SE
south and east corner are raised
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
TileIndexDiffC TileIndexDiffCByDiagDir(DiagDirection dir)
Returns the TileIndexDiffC offset from a DiagDirection.
@ MP_CLEAR
A tile without any structures, i.e. grass, rocks, farm fields etc.
bool IsTileFlat(TileIndex tile, int *h)
Check if a given tile is flat.
static constexpr Slope HalftileSlope(Slope s, Corner corner)
Adds a halftile slope to a slope.
@ TROPICZONE_DESERT
Tile is desert.
uint32_t clear_limit
Amount of tiles we can (still) clear (times 65536).
@ DIAGDIR_NE
Northeast, upper right on your monitor.
bool IsInclinedSlope(Slope s)
Tests if a specific slope is an inclined slope.
bool IsCoastTile(Tile t)
Is it a coast tile.
@ AYSTAR_DONE
Not an end-tile, or wrong direction.
bool IsClearGround(Tile t, ClearGround ct)
Set the type of clear tile.
static Titem * Get(size_t index)
Returns Titem with given index.
static TickCounter counter
Monotonic counter, in ticks, since start of game.
static void CalculateSnowLine()
Calculate the line from which snow begins.
void FixSlopes()
This function takes care of the fact that land in OpenTTD can never differ more than 1 in height.
static const uint SNOW_LINE_DAYS
Number of days in each month in the snow line table.
int GetTileMaxZ(TileIndex t)
Get top height of the tile inside the map.
static constexpr bool IsHalftileSlope(Slope s)
Checks for non-continuous slope on halftile foundations.
std::tuple< Slope, int > GetFoundationPixelSlope(TileIndex tile)
Get slope of a tile on top of a (possible) foundation If a tile does not have a foundation,...
static void BuildRiver(TileIndex begin, TileIndex end, TileIndex spring, bool main_river)
Actually build the river between the begin and end tiles using AyStar.
const TileTypeProcs *const _tile_type_procs[16]
Tile callback functions for each type of tile.
constexpr void Swap(T &a, T &b)
Type safe swap operation.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
TileIndex AddTileIndexDiffCWrap(TileIndex tile, TileIndexDiffC diff)
Add a TileIndexDiffC to a TileIndex and returns the new one.
Tile information, used while rendering the tile.
WaterClass GetWaterClass(Tile t)
Get the water class at a tile.
static const uint TILE_UPDATE_FREQUENCY_LOG
The logarithm of how many ticks it takes between tile updates (log base 2).
static debug_inline uint MaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
static debug_inline uint LogX()
Logarithm of the map size along the X side.
uint8_t table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS]
Height of the snow line each day of the year.
@ SLOPE_NE
north and east corner are raised
static void CreateRivers()
Actually (try to) create some rivers.
void AddStartNode(AyStarNode *start_node, int g)
Adds a node from where to start an algorithm.
Slope GetTileSlope(TileIndex tile)
Return the slope of a given tile inside the map.
static constexpr Slope RemoveHalftileSlope(Slope s)
Removes a halftile slope from a slope.
DiagDirDiff
Enumeration for the difference between to DiagDirection.
uint8_t snow_line_height
the configured snow line height (deduced from "snow_coverage")
static const uint MIN_MAP_SIZE_BITS
Minimal and maximal map width and height.
std::string name
Name of the file.
uint8_t desert_coverage
the amount of desert coverage on the map
@ SLOPE_ENW
east, north and west corner are raised
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
int GetSlopeZInCorner(Slope tileh, Corner corner)
Determine the Z height of a corner relative to TileZ.
Owner
Enum for all companies/owners.
Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
TileIndex TileAddXY(TileIndex tile, int x, int y)
Adds a given offset to a tile.
static uint8_t CalculateDesertLine()
Calculate the line (in height) between desert and tropic.
void SetTileHeight(Tile tile, uint height)
Sets the height of a tile.
@ TROPICZONE_RAINFOREST
Rainforest tile.
@ LG_ORIGINAL
The original landscape generator.
DifficultySettings difficulty
settings related to the difficulty
int GetTileZ(TileIndex tile)
Get bottom height of the tile.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
static std::unique_ptr< TileIterator > Create(TileIndex corner1, TileIndex corner2, bool diagonal)
Create either an OrthogonalTileIterator or DiagonalTileIterator given the diagonal parameter.
uint8_t terrain_type
the mountainousness of the landscape
@ DIAGDIRDIFF_90LEFT
90 degrees left
static constexpr bool IsSteepSlope(Slope s)
Checks if a slope is steep.
static const SpriteID SPR_HALFTILE_FOUNDATION_BASE
Halftile foundations.
uint GetPartialPixelZ(int x, int y, Slope corners)
Determines height at given coordinate of a slope.
static const uint TILE_SIZE
Tile size in world coordinates.
GetTileTrackStatusProc * get_tile_track_status_proc
Get available tracks and status of a tile.
DiagDirection
Enumeration for diagonal directions.
void ClearBridgeMiddle(Tile t)
Removes bridges from the given, that is bridges along the X and Y axis.
constexpr uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
void SetSnowLine(uint8_t table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS])
Set a variable snow line, as loaded from a newgrf file.
@ SLOPE_NW
north and west corner are raised
@ DC_NO_WATER
don't allow building on water
@ SLOPE_STEEP_E
a steep slope falling to west (from east)
int y
Y position of the tile in unit coordinates.
@ DIAGDIRDIFF_SAME
Same directions.
@ SLOPE_W
the west corner of the tile is raised
static constexpr Corner GetHalftileSlopeCorner(Slope s)
Returns the leveled halftile of a halftile slope.
static const uint TILE_UPDATE_FREQUENCY
How many ticks it takes between tile updates (has to be a power of 2).
bool IsWaterTile(Tile t)
Is it a water tile with plain water?
@ EV_EXPLOSION_SMALL
Various explosions.
static const uint MAX_TILE_HEIGHT
Maximum allowed tile height.
@ SLOPE_EW
east and west corner are raised
int Main()
This is the function you call to run AyStar.
uint8_t amount_of_rivers
the amount of rivers
static uint ScaleBySize(uint n)
Scales the given value by the map size, where the given value is for a 256 by 256 map.
@ EV_EXPLOSION_LARGE
Various explosions.
@ DC_EXEC
execute the given command
int GetSlopePixelZ(int x, int y, bool ground_vehicle)
Return world Z coordinate of a given point of a tile.
uint8_t landscape
the landscape we're currently in
Tile description for the 'land area information' tool.
DoCommandFlag
List of flags for a command.
@ SLOPE_S
the south corner of the tile is raised
Foundation
Enumeration for Foundations.
@ SLOPE_STEEP_S
a steep slope falling to north (from south)
void IncreaseGeneratingWorldProgress(GenWorldProgress cls)
Increases the current stage of the world generation with one.
@ PFE_GL_LANDSCAPE
Time spent processing other world features.
uint8_t snow_coverage
the amount of snow coverage on the map
GameCreationSettings game_creation
settings used during the creation of a game (map)
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
Slope SlopeWithThreeCornersRaised(Corner corner)
Returns the slope with all except one corner raised.
Slope ComplementSlope(Slope s)
Return the complement of a slope.
Slope tileh
Slope of the tile.
static debug_inline TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
void MakeClear(Tile t, ClearGround g, uint density)
Make a clear tile.
@ GWP_LANDSCAPE
Create the landscape.
void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner)
Change the owner of a tile.
void OnTick_Companies()
Called every tick for updating some company info.
TransportType
Available types of transport.
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
constexpr bool IsInsideBS(const T x, const size_t base, const size_t size)
Checks if a value is between a window started at some base point.
@ FOUNDATION_INCLINED_Y
The tile has an along Y-axis inclined foundation.
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
@ SLOPE_WSE
west, south and east corner are raised
void OnTick_Town()
Iterate through all towns and call their tick handler.
Money GetAvailableMoneyForCommand()
This functions returns the money which can be used to execute a command.
const TileTypeProcs _tile_type_town_procs
Tile callback functions for a town.
TileIndex TileAddWrap(TileIndex tile, int addx, int addy)
This function checks if we add addx/addy to tile, if we do wrap around the edges.
Common return value for all commands.
uint ApplyPixelFoundationToSlope(Foundation f, Slope &s)
Applies a foundation to a slope.
@ GWM_HEIGHTMAP
Generate a newgame from a heightmap.
@ DIAGDIRDIFF_BEGIN
Used for iterations.
@ SLOPE_NS
north and south corner are raised
bool CircularTileSearch(TileIndex *tile, uint size, TestTileOnSearchProc proc, void *user_data)
Function performing a search around a center tile and going outward, thus in circle.
@ FOUNDATION_STEEP_BOTH
The tile has a steep slope. The lowest corner is raised by a foundation and the upper halftile is lev...
DiagDirection ChangeDiagDir(DiagDirection d, DiagDirDiff delta)
Applies a difference on a DiagDirection.
static constexpr int GetSlopeMaxPixelZ(Slope s)
Returns the height of the highest corner of a slope relative to TileZ (= minimal height)
void DirtyCompanyInfrastructureWindows(CompanyID company)
Redraw all windows with company infrastructure counts.
void free(const void *ptr)
Version of the standard free that accepts const pointers.
@ DIAGDIR_BEGIN
Used for iterations.
uint8_t map_height_limit
the maximum allowed heightlevel
TileIndex first_tile
The first tile being cleared, which then causes the whole object to be cleared.
static uint CalculateCoverageLine(uint coverage, uint edge_multiplier)
Calculate what height would be needed to cover N% of the landmass.
DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
@ FOUNDATION_INCLINED_X
The tile has an along X-axis inclined foundation.
void MakeVoid(Tile t)
Make a nice void tile ;)
bool Failed() const
Did this command fail?
uint16_t width
Width of the sprite.
Corner
Enumeration of tile corners.
bool IsNonContinuousFoundation(Foundation f)
Tests if a foundation is a non-continuous foundation, i.e.
PauseMode _pause_mode
The current pause mode.
TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
GameSettings _settings_game
Game settings of a running game or the scenario editor.
void GetSlopePixelZOnEdge(Slope tileh, DiagDirection edge, int &z1, int &z2)
Determine the Z height of the corners of a specific tile edge.
uint ApplyFoundationToSlope(Foundation f, Slope &s)
Applies a foundation to a slope.
@ MapGen
Special sprite for the map generator.
bool IsTileOnWater(Tile t)
Tests if the tile was built on water.
@ DIAGDIRDIFF_90RIGHT
90 degrees right
static std::tuple< bool, bool > FlowRiver(TileIndex spring, TileIndex begin, uint min_river_length)
Try to flow the river down from a given begin.
static YearMonthDay ConvertDateToYMD(Date date)
Converts a Date to a Year, Month & Day.
#define lengthof(array)
Return the length of an fixed size array.
bool freeform_edges
allow terraforming the tiles at the map edges
Money GetCost() const
The costs as made up to this moment.
GetTileDescProc * get_tile_desc_proc
Get a description of a tile (for the 'land area information' tool)
#define RandomTile()
Get a valid random tile.
uint8_t quantity_sea_lakes
the amount of seas/lakes
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
Coordinates of a point in 2D.
static SnowLine * _snow_line
Description of the snow line throughout the year.
Corner GetHalftileFoundationCorner(Foundation f)
Returns the halftile corner of a halftile-foundation.
void OffsetGroundSprite(int x, int y)
Called when a foundation has been drawn for the current tile.
Structure describing the height of the snow line each day of the year.
@ SLOPE_N
the north corner of the tile is raised
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
Set of callback functions for performing tile operations of a given tile type.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
@ DC_BANKRUPT
company bankrupts, skip money check, skip vehicle on tile check in some cases
Point InverseRemapCoords2(int x, int y, bool clamp_to_map, bool *clamped)
Map 2D viewport or smallmap coordinate to 3D world or tile coordinate.
bool HasTileWaterClass(Tile t)
Checks whether the tile has an waterclass associated.
void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, int x, int y, int w, int h, int dz, int z, bool transparent, int bb_offset_x, int bb_offset_y, int bb_offset_z, const SubSprite *sub)
Draw a (transparent) sprite at given coordinates with a given bounding box.
bool IsValidTile(Tile tile)
Checks if a tile is valid.
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
@ FOUNDATION_STEEP_LOWER
The tile has a steep slope. The lowest corner is raised by a foundation to allow building railroad on...
void DrawFoundation(TileInfo *ti, Foundation f)
Draw foundation f at tile ti.
static debug_inline uint SizeX()
Get the size of the map along the X.
bool _generating_world
Whether we are generating the map or not.
@ DIAGDIRDIFF_REVERSE
Reverse directions.
uint8_t river_route_random
the amount of randomicity for the route finding
@ SLOPE_STEEP_W
a steep slope falling to east (from west)
CompanyID _current_company
Company currently doing an action.
static uint MaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
@ AYSTAR_FOUND_END_NODE
An end node was found.
TileIndex spring
The current spring during river generation.
@ DC_FORCE_CLEAR_TILE
do not only remove the object on the tile, but also clear any water left on it
@ WATER_CLASS_CANAL
Canal.
ClearedObjectArea * FindClearedObject(TileIndex tile)
Find the entry in _cleared_object_areas which occupies a certain tile.
AyStar search algorithm struct.
@ MP_VOID
Invisible tiles at the SW and SE border.
uint8_t lowest_value
Lowest snow line of the year.
static const uint MAX_MAP_SIZE_BITS
Maximal size of map is equal to 2 ^ MAX_MAP_SIZE_BITS.
static bool FlowsDown(TileIndex begin, TileIndex end)
Check whether a river at begin could (logically) flow down to end.
void DeleteAnimatedTile(TileIndex tile)
Removes the given tile from the animated tile table.
bool IsDockingTile(Tile t)
Checks whether the tile is marked as a dockling tile.
@ SLOPE_STEEP
indicates the slope is steep
Slope
Enumeration for the slope-type.
bool IsSlopeWithThreeCornersRaised(Slope s)
Tests if a specific slope has exactly three corners raised.
@ DIAGDIRDIFF_END
Used for iterations.
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
Corner GetHighestSlopeCorner(Slope s)
Returns the highest corner of a slope (one corner raised or a steep slope).
Parameters for river generation to pass as AyStar user data.
static debug_inline uint Size()
Get the size of the map.
void SetGeneratingWorldProgress(GenWorldProgress cls, uint total)
Set the total of a stage of the world generation.
FileToSaveLoad _file_to_saveload
File to save or load in the openttd loop.
bool IsLeveledFoundation(Foundation f)
Tests if the foundation is a leveled foundation.
@ SLOPE_SW
south and west corner are raised
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
@ LG_TERRAGENESIS
TerraGenesis Perlin landscape generator.
bool IsSnowLineSet()
Has a snow line table already been loaded.
Corner GetRailFoundationCorner(Foundation f)
Returns the track corner of a special rail foundation.
void InvalidateWaterRegion(TileIndex tile)
Marks the water region that tile is part of as invalid.
uint8_t min_river_length
the minimum river length
@ DIAGDIR_END
Used for iterations.
@ SLOPE_ELEVATED
bit mask containing all 'simple' slopes
std::tuple< Slope, int > GetFoundationSlope(TileIndex tile)
Get slope of a tile on top of a (possible) foundation If a tile does not have a foundation,...
bool IsInclinedFoundation(Foundation f)
Tests if the foundation is an inclined foundation.
@ DC_AUTO
don't allow building on structures
const uint8_t _slope_to_sprite_offset[32]
landscape slope => sprite
EffectVehicle * CreateEffectVehicleAbove(int x, int y, int z, EffectVehicleType type)
Create an effect vehicle above a particular location.
bool IsSpecialRailFoundation(Foundation f)
Tests if a foundation is a special rail foundation for single horizontal/vertical track.
CommandCost CmdLandscapeClear(DoCommandFlag flags, TileIndex tile)
Clear a piece of landscape.
uint32_t RandomRange(uint32_t limit, const std::source_location location=std::source_location::current())
Pick a random number between 0 and limit - 1, inclusive.
Slope SteepSlope(Corner corner)
Returns a specific steep slope.
std::tuple< CommandCost, Money > CmdClearArea(DoCommandFlag flags, TileIndex tile, TileIndex start_tile, bool diagonal)
Clear a big piece of landscape.
static uint LogY()
Logarithm of the map size along the y side.
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
static debug_inline TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
static debug_inline uint TileHeight(Tile tile)
Returns the height of a tile.
uint8_t LowestSnowLine()
Get the lowest possible snow line height, either variable or static.
int GetSlopePixelZOutsideMap(int x, int y)
Return world z coordinate of a given point of a tile, also for tiles outside the map (virtual "black"...
static const uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in #ZOOM_BASE.
@ SLOPE_SEN
south, east and north corner are raised
static bool MakeLake(TileIndex tile, void *user_data)
Make a connected lake; fill all tiles in the circular tile search that are connected.
@ GWP_RIVER
Create the rivers.
void MakeRiverAndModifyDesertZoneAround(TileIndex tile)
Make a river tile and remove desert directly around it.
static debug_inline TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
int x
X position of the tile in unit coordinates.
static Date date
Current date in days (day counter).
TileIndex tile
Tile index.
ConstructionSettings construction
construction of things in-game
uint8_t land_generator
the landscape generator
void ClearSnowLine()
Clear the variable snow line table and free the memory.
Slope SlopeWithOneCornerRaised(Corner corner)
Returns the slope with a specific corner raised.
static const uint TILE_PIXELS
Pixel distance between tile columns/rows in #ZOOM_BASE.
uint8_t GetSnowLine()
Get the current snow line, either variable or static.
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
DetailedFileType detail_ftype
Concrete file type (PNG, BMP, old save, etc).
@ SLOPE_NWS
north, west and south corner are raised
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
@ TROPICZONE_NORMAL
Normal tropiczone.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
bool main_river
Whether the current river is a big river that others flow into.
uint8_t HighestSnowLine()
Get the highest possible snow line height, either variable or static.
@ PM_UNPAUSED
A normal unpaused game.
uint8_t data[]
Sprite data.
Point InverseRemapCoords(int x, int y)
Map 2D viewport or smallmap coordinate to 3D world or tile coordinate.
static const uint CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY
Value for custom sea level in difficulty settings.
const TileTypeProcs _tile_type_road_procs
Tile callback functions for road tiles.
static bool RiverMakeWider(TileIndex tile, void *data)
Widen a river by expanding into adjacent tiles via circular tile search.
Keeps track of removed objects during execution/testruns of commands.
bool IsSlopeWithOneCornerRaised(Slope s)
Tests if a specific slope has exactly one corner raised.
bool IsCanal(Tile t)
Is it a canal tile?
void OnTick_LinkGraph()
Spawn or join a link graph job or compress a link graph if any link graph is due to do so.
Data structure describing a sprite.
TropicZone GetTropicZone(Tile tile)
Get the tropic zone.
bool IsRiver(Tile t)
Is it a river water tile?
@ INVALID_TRACKDIR
Flag for an invalid trackdir.
TileIndex TileAddByDiagDir(TileIndex tile, DiagDirection dir)
Adds a DiagDir to a tile.
DiagDirection GetInclinedSlopeDirection(Slope s)
Returns the direction of an inclined slope.
void SetTropicZone(Tile tile, TropicZone type)
Set the tropic zone.
@ SLOPE_STEEP_N
a steep slope falling to south (from north)
bool GenerateLandscape(uint8_t mode)
bool LoadHeightmap(DetailedFileType dft, const char *filename)
Load a heightmap from file and change the map in its current dimensions to a landscape representing t...
std::tuple< Slope, int > GetTileSlopeZ(TileIndex tile)
Return the slope of a given tile inside the map.
static uint SizeY()
Get the size of the map along the Y.
Corner OppositeCorner(Corner corner)
Returns the opposite corner.
void RunTileLoop()
Gradually iterate over all tiles on the map, calling their TileLoopProcs once every TILE_UPDATE_FREQU...
@ EXPENSES_CONSTRUCTION
Construction costs.
static const uint SNOW_LINE_MONTHS
Number of months in the snow line table.