Update to 14.0-beta1

This commit is contained in:
dP
2024-02-04 02:18:17 +05:30
parent 79037e2c65
commit 33ef333b57
1325 changed files with 138465 additions and 70987 deletions

View File

@@ -22,7 +22,7 @@
#include "company_base.h"
#include "core/random_func.hpp"
#include "newgrf_generic.h"
#include "date_func.h"
#include "timer/timer_game_tick.h"
#include "tree_cmd.h"
#include "landscape_cmd.h"
@@ -54,9 +54,9 @@ enum ExtraTreePlacement {
/** Determines when to consider building more trees. */
byte _trees_tick_ctr;
static const uint16 DEFAULT_TREE_STEPS = 1000; ///< Default number of attempts for placing trees.
static const uint16 DEFAULT_RAINFOREST_TREE_STEPS = 15000; ///< Default number of attempts for placing extra trees at rainforest in tropic.
static const uint16 EDITOR_TREE_DIV = 5; ///< Game editor tree generation divisor factor.
static const uint16_t DEFAULT_TREE_STEPS = 1000; ///< Default number of attempts for placing trees.
static const uint16_t DEFAULT_RAINFOREST_TREE_STEPS = 15000; ///< Default number of attempts for placing extra trees at rainforest in tropic.
static const uint16_t EDITOR_TREE_DIV = 5; ///< Game editor tree generation divisor factor.
/**
* Tests if a tile can be converted to MP_TREES
@@ -161,7 +161,7 @@ static TreeType GetRandomTreeType(TileIndex tile, uint seed)
* @param tile The tile to make a tree-tile from
* @param r The randomness value from a Random() value
*/
static void PlaceTree(TileIndex tile, uint32 r)
static void PlaceTree(TileIndex tile, uint32_t r)
{
TreeType tree = GetRandomTreeType(tile, GB(r, 24, 8));
@@ -174,9 +174,6 @@ static void PlaceTree(TileIndex tile, uint32 r)
if (ground != TREE_GROUND_SNOW_DESERT && ground != TREE_GROUND_ROUGH_SNOW && ground != TREE_GROUND_SHORE) {
SetTreeGroundDensity(tile, (TreeGround)GB(r, 28, 1), 3);
}
/* Set the counter to a random start value */
SetTreeCounter(tile, (TreeGround)GB(r, 24, 4));
}
}
@@ -192,7 +189,7 @@ static void PlaceTreeGroups(uint num_groups)
TileIndex center_tile = RandomTile();
for (uint i = 0; i < DEFAULT_TREE_STEPS; i++) {
uint32 r = Random();
uint32_t r = Random();
int x = GB(r, 0, 5) - 16;
int y = GB(r, 8, 5) - 16;
uint dist = abs(x) + abs(y);
@@ -220,7 +217,7 @@ static void PlaceTreeGroups(uint num_groups)
static void PlaceTreeAtSameHeight(TileIndex tile, int height)
{
for (uint i = 0; i < DEFAULT_TREE_STEPS; i++) {
uint32 r = Random();
uint32_t r = Random();
int x = GB(r, 0, 5) - 16;
int y = GB(r, 8, 5) - 16;
TileIndex cur_tile = TileAddWrap(tile, x, y);
@@ -250,10 +247,10 @@ void PlaceTreesRandomly()
{
int i, j, ht;
i = ScaleByMapSize(DEFAULT_TREE_STEPS);
i = Map::ScaleBySize(DEFAULT_TREE_STEPS);
if (_game_mode == GM_EDITOR) i /= EDITOR_TREE_DIV;
do {
uint32 r = Random();
uint32_t r = Random();
TileIndex tile = RandomTileSeed(r);
IncreaseGeneratingWorldProgress(GWP_TREE);
@@ -278,11 +275,11 @@ void PlaceTreesRandomly()
/* place extra trees at rainforest area */
if (_settings_game.game_creation.landscape == LT_TROPIC) {
i = ScaleByMapSize(DEFAULT_RAINFOREST_TREE_STEPS);
i = Map::ScaleBySize(DEFAULT_RAINFOREST_TREE_STEPS);
if (_game_mode == GM_EDITOR) i /= EDITOR_TREE_DIV;
do {
uint32 r = Random();
uint32_t r = Random();
TileIndex tile = RandomTileSeed(r);
IncreaseGeneratingWorldProgress(GWP_TREE);
@@ -308,20 +305,21 @@ void PlaceTreesRandomly()
*/
uint PlaceTreeGroupAroundTile(TileIndex tile, TreeType treetype, uint radius, uint count, bool set_zone)
{
assert(_game_mode == GM_EDITOR); // Due to InteractiveRandom being used in this function
assert(treetype < TREE_TOYLAND + TREE_COUNT_TOYLAND);
const bool allow_desert = treetype == TREE_CACTUS;
uint planted = 0;
for (; count > 0; count--) {
/* Simple quasi-normal distribution with range [-radius; radius) */
auto mkcoord = [&]() -> int32 {
const uint32 rand = InteractiveRandom();
const int32 dist = GB<int32>(rand, 0, 8) + GB<int32>(rand, 8, 8) + GB<int32>(rand, 16, 8) + GB<int32>(rand, 24, 8);
const int32 scu = dist * radius / 512;
auto mkcoord = [&]() -> int32_t {
const uint32_t rand = InteractiveRandom();
const int32_t dist = GB<int32_t>(rand, 0, 8) + GB<int32_t>(rand, 8, 8) + GB<int32_t>(rand, 16, 8) + GB<int32_t>(rand, 24, 8);
const int32_t scu = dist * radius / 512;
return scu - radius;
};
const int32 xofs = mkcoord();
const int32 yofs = mkcoord();
const int32_t xofs = mkcoord();
const int32_t yofs = mkcoord();
const TileIndex tile_to_plant = TileAddWrap(tile, xofs, yofs);
if (tile_to_plant != INVALID_TILE) {
if (IsTileType(tile_to_plant, MP_TREES) && GetTreeCount(tile_to_plant) < 4) {
@@ -364,10 +362,10 @@ void GenerateTrees()
default: NOT_REACHED();
}
total = ScaleByMapSize(DEFAULT_TREE_STEPS);
if (_settings_game.game_creation.landscape == LT_TROPIC) total += ScaleByMapSize(DEFAULT_RAINFOREST_TREE_STEPS);
total = Map::ScaleBySize(DEFAULT_TREE_STEPS);
if (_settings_game.game_creation.landscape == LT_TROPIC) total += Map::ScaleBySize(DEFAULT_RAINFOREST_TREE_STEPS);
total *= i;
uint num_groups = (_settings_game.game_creation.landscape != LT_TOYLAND) ? ScaleByMapSize(GB(Random(), 0, 5) + 25) : 0;
uint num_groups = (_settings_game.game_creation.landscape != LT_TOYLAND) ? Map::ScaleBySize(GB(Random(), 0, 5) + 25) : 0;
total += num_groups * DEFAULT_TREE_STEPS;
SetGeneratingWorldProgress(GWP_TREE, total);
@@ -392,14 +390,14 @@ CommandCost CmdPlantTree(DoCommandFlag flags, TileIndex tile, TileIndex start_ti
StringID msg = INVALID_STRING_ID;
CommandCost cost(EXPENSES_OTHER);
if (start_tile >= MapSize()) return CMD_ERROR;
if (start_tile >= Map::Size()) return CMD_ERROR;
/* Check the tree type within the current climate */
if (tree_to_plant != TREE_INVALID && !IsInsideBS(tree_to_plant, _tree_base_by_landscape[_settings_game.game_creation.landscape], _tree_count_by_landscape[_settings_game.game_creation.landscape])) return CMD_ERROR;
Company *c = (_game_mode != GM_EDITOR) ? Company::GetIfValid(_current_company) : nullptr;
int limit = (c == nullptr ? INT32_MAX : GB(c->tree_limit, 16, 16));
std::unique_ptr<TileIterator> iter(diagonal ? static_cast<TileIterator *>(new DiagonalTileIterator(tile, start_tile)) : static_cast<TileIterator *>(new OrthogonalTileIterator(tile, start_tile)));
std::unique_ptr<TileIterator> iter = TileIterator::Create(tile, start_tile, diagonal);
for (; *iter != INVALID_TILE; ++(*iter)) {
TileIndex current_tile = *iter;
switch (GetTileType(current_tile)) {
@@ -430,7 +428,7 @@ CommandCost CmdPlantTree(DoCommandFlag flags, TileIndex tile, TileIndex start_ti
msg = STR_ERROR_CAN_T_BUILD_ON_WATER;
continue;
}
FALLTHROUGH;
[[fallthrough]];
case MP_CLEAR: {
if (IsBridgeAbove(current_tile)) {
@@ -529,7 +527,7 @@ static void DrawTile_Trees(TileInfo *ti)
/* Do not draw trees when the invisible trees setting is set */
if (IsInvisibilitySet(TO_TREES)) return;
uint tmp = CountBits(static_cast<uint32>(ti->tile + ti->x + ti->y));
uint tmp = CountBits(ti->tile.base() + ti->x + ti->y);
uint index = GB(tmp, 0, 2) + (GetTreeType(ti->tile) << 2);
/* different tree styles above one of the grounds */
@@ -588,7 +586,7 @@ static void DrawTile_Trees(TileInfo *ti)
}
static int GetSlopePixelZ_Trees(TileIndex tile, uint x, uint y)
static int GetSlopePixelZ_Trees(TileIndex tile, uint x, uint y, bool)
{
int z;
Slope tileh = GetTilePixelSlope(tile, &z);
@@ -596,7 +594,7 @@ static int GetSlopePixelZ_Trees(TileIndex tile, uint x, uint y)
return z + GetPartialPixelZ(x & 0xF, y & 0xF, tileh);
}
static Foundation GetFoundation_Trees(TileIndex tile, Slope tileh)
static Foundation GetFoundation_Trees(TileIndex, Slope)
{
return FOUNDATION_NONE;
}
@@ -648,7 +646,7 @@ static void TileLoopTreesDesert(TileIndex tile)
SND_44_RAINFOREST_3,
SND_48_RAINFOREST_4
};
uint32 r = Random();
uint32_t r = Random();
if (Chance16I(1, 200, r) && _settings_client.sound.ambient) SndPlayTileFx(forest_sounds[GB(r, 16, 2)], tile);
break;
@@ -678,7 +676,7 @@ static void TileLoopTreesAlps(TileIndex tile)
SetTreeGroundDensity(tile, GetTreeGround(tile), density);
} else {
if (GetTreeDensity(tile) == 3) {
uint32 r = Random();
uint32_t r = Random();
if (Chance16I(1, 200, r) && _settings_client.sound.ambient) {
SndPlayTileFx((r & 0x80000000) ? SND_39_ARCTIC_SNOW_2 : SND_34_ARCTIC_SNOW_1, tile);
}
@@ -709,10 +707,14 @@ static void TileLoop_Trees(TileIndex tile)
AmbientSoundEffect(tile);
uint treeCounter = GetTreeCounter(tile);
/* TimerGameTick::counter is incremented by 256 between each call, so ignore lower 8 bits.
* Also, we use a simple hash to spread the updates evenly over the map.
* 11 and 9 are just some co-prime numbers for better spread.
*/
uint32_t cycle = 11 * TileX(tile) + 9 * TileY(tile) + (TimerGameTick::counter >> 8);
/* Handle growth of grass (under trees/on MP_TREES tiles) at every 8th processings, like it's done for grass on MP_CLEAR tiles. */
if ((treeCounter & 7) == 7 && GetTreeGround(tile) == TREE_GROUND_GRASS) {
if ((cycle & 7) == 7 && GetTreeGround(tile) == TREE_GROUND_GRASS) {
uint density = GetTreeDensity(tile);
if (density < 3) {
SetTreeGroundDensity(tile, TREE_GROUND_GRASS, density + 1);
@@ -722,11 +724,7 @@ static void TileLoop_Trees(TileIndex tile)
if (_settings_game.construction.extra_tree_placement == ETP_NO_GROWTH_NO_SPREAD) return;
if (GetTreeCounter(tile) < 15) {
AddTreeCounter(tile, 1);
return;
}
SetTreeCounter(tile, 0);
if ((cycle & 15) != 15) return;
switch (GetTreeGrowth(tile)) {
case 3: // regular sized tree
@@ -746,7 +744,7 @@ static void TileLoop_Trees(TileIndex tile)
SetTreeGrowth(tile, 0);
break;
}
FALLTHROUGH;
[[fallthrough]];
case 2: { // add a neighbouring tree
if (!CanPlantExtraTrees(tile)) break;
@@ -826,7 +824,7 @@ bool DecrementTreeCounter()
/* byte underflow */
byte old_trees_tick_ctr = _trees_tick_ctr;
_trees_tick_ctr -= ScaleByMapSize(1);
_trees_tick_ctr -= Map::ScaleBySize(1);
return old_trees_tick_ctr <= _trees_tick_ctr;
}
@@ -835,19 +833,19 @@ void OnTick_Trees()
/* Don't spread trees if that's not allowed */
if (_settings_game.construction.extra_tree_placement == ETP_NO_SPREAD || _settings_game.construction.extra_tree_placement == ETP_NO_GROWTH_NO_SPREAD) return;
uint32 r;
uint32_t r;
TileIndex tile;
TreeType tree;
/* Skip some tree ticks for map sizes below 256 * 256. 64 * 64 is 16 times smaller, so
* this is the maximum number of ticks that are skipped. Number of ticks to skip is
* inversely proportional to map size, so that is handled to create a mask. */
int skip = ScaleByMapSize(16);
if (skip < 16 && (_tick_counter & (16 / skip - 1)) != 0) return;
int skip = Map::ScaleBySize(16);
if (skip < 16 && (TimerGameTick::counter & (16 / skip - 1)) != 0) return;
/* place a tree at a random rainforest spot */
if (_settings_game.game_creation.landscape == LT_TROPIC) {
for (uint c = ScaleByMapSize(1); c > 0; c--) {
for (uint c = Map::ScaleBySize(1); c > 0; c--) {
if ((r = Random(), tile = RandomTileSeed(r), GetTropicZone(tile) == TROPICZONE_RAINFOREST) &&
CanPlantTreesOnTile(tile, false) &&
(tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TREE_INVALID) {
@@ -866,12 +864,12 @@ void OnTick_Trees()
}
}
static TrackStatus GetTileTrackStatus_Trees(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
static TrackStatus GetTileTrackStatus_Trees(TileIndex, TransportType, uint, DiagDirection)
{
return 0;
}
static void ChangeTileOwner_Trees(TileIndex tile, Owner old_owner, Owner new_owner)
static void ChangeTileOwner_Trees(TileIndex, Owner, Owner)
{
/* not used */
}
@@ -881,7 +879,7 @@ void InitializeTrees()
_trees_tick_ctr = 0;
}
static CommandCost TerraformTile_Trees(TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new)
static CommandCost TerraformTile_Trees(TileIndex tile, DoCommandFlag flags, int, Slope)
{
return Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile);
}