mirror of https://github.com/OpenTTD/OpenTTD
Change: Scale towns/industries by amount of land tiles.
This stops a large map with lots of water being crammed with towns and industries even when set to Very Low.pull/10063/head
parent
cb23bc5e2a
commit
82fa5e7164
|
@ -134,11 +134,13 @@ static void _GenerateWorld()
|
||||||
if (_game_mode != GM_MENU) FlatEmptyWorld(_settings_game.game_creation.se_flat_world_height);
|
if (_game_mode != GM_MENU) FlatEmptyWorld(_settings_game.game_creation.se_flat_world_height);
|
||||||
|
|
||||||
ConvertGroundTilesIntoWaterTiles();
|
ConvertGroundTilesIntoWaterTiles();
|
||||||
|
Map::CountLandTiles();
|
||||||
IncreaseGeneratingWorldProgress(GWP_OBJECT);
|
IncreaseGeneratingWorldProgress(GWP_OBJECT);
|
||||||
|
|
||||||
_settings_game.game_creation.snow_line_height = DEF_SNOWLINE_HEIGHT;
|
_settings_game.game_creation.snow_line_height = DEF_SNOWLINE_HEIGHT;
|
||||||
} else {
|
} else {
|
||||||
GenerateClearTile();
|
GenerateClearTile();
|
||||||
|
Map::CountLandTiles();
|
||||||
|
|
||||||
/* Only generate towns, tree and industries in newgame mode. */
|
/* Only generate towns, tree and industries in newgame mode. */
|
||||||
if (_game_mode != GM_EDITOR) {
|
if (_game_mode != GM_EDITOR) {
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
#include "industry_cmd.h"
|
#include "industry_cmd.h"
|
||||||
#include "landscape_cmd.h"
|
#include "landscape_cmd.h"
|
||||||
#include "terraform_cmd.h"
|
#include "terraform_cmd.h"
|
||||||
|
#include "map_func.h"
|
||||||
#include "timer/timer.h"
|
#include "timer/timer.h"
|
||||||
#include "timer/timer_game_calendar.h"
|
#include "timer/timer_game_calendar.h"
|
||||||
#include "timer/timer_game_economy.h"
|
#include "timer/timer_game_economy.h"
|
||||||
|
@ -2356,7 +2357,7 @@ static uint GetNumberOfIndustries()
|
||||||
|
|
||||||
if (difficulty == ID_CUSTOM) return std::min<uint>(IndustryPool::MAX_SIZE, _settings_game.game_creation.custom_industry_number);
|
if (difficulty == ID_CUSTOM) return std::min<uint>(IndustryPool::MAX_SIZE, _settings_game.game_creation.custom_industry_number);
|
||||||
|
|
||||||
return std::min<uint>(IndustryPool::MAX_SIZE, Map::ScaleBySize(numof_industry_table[difficulty]));
|
return std::min<uint>(IndustryPool::MAX_SIZE, Map::ScaleByLandProportion(Map::ScaleBySize(numof_industry_table[difficulty])));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
11
src/map.cpp
11
src/map.cpp
|
@ -24,6 +24,8 @@
|
||||||
/* static */ uint Map::size; ///< The number of tiles on the map
|
/* static */ uint Map::size; ///< The number of tiles on the map
|
||||||
/* static */ uint Map::tile_mask; ///< _map_size - 1 (to mask the mapsize)
|
/* static */ uint Map::tile_mask; ///< _map_size - 1 (to mask the mapsize)
|
||||||
|
|
||||||
|
/* static */ uint Map::initial_land_count; ///< Initial number of land tiles on the map.
|
||||||
|
|
||||||
/* static */ std::unique_ptr<Tile::TileBase[]> Tile::base_tiles; ///< Base tiles of the map
|
/* static */ std::unique_ptr<Tile::TileBase[]> Tile::base_tiles; ///< Base tiles of the map
|
||||||
/* static */ std::unique_ptr<Tile::TileExtended[]> Tile::extended_tiles; ///< Extended tiles of the map
|
/* static */ std::unique_ptr<Tile::TileExtended[]> Tile::extended_tiles; ///< Extended tiles of the map
|
||||||
|
|
||||||
|
@ -59,6 +61,15 @@
|
||||||
AllocateWaterRegions();
|
AllocateWaterRegions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* static */ void Map::CountLandTiles()
|
||||||
|
{
|
||||||
|
/* Count number of tiles that are land. */
|
||||||
|
Map::initial_land_count = 0;
|
||||||
|
for (const auto tile : Map::Iterate()) {
|
||||||
|
Map::initial_land_count += IsWaterTile(tile) ? 0 : 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
TileIndex TileAdd(TileIndex tile, TileIndexDiff offset)
|
TileIndex TileAdd(TileIndex tile, TileIndexDiff offset)
|
||||||
|
|
|
@ -239,8 +239,11 @@ private:
|
||||||
static uint size; ///< The number of tiles on the map
|
static uint size; ///< The number of tiles on the map
|
||||||
static uint tile_mask; ///< _map_size - 1 (to mask the mapsize)
|
static uint tile_mask; ///< _map_size - 1 (to mask the mapsize)
|
||||||
|
|
||||||
|
static uint initial_land_count; ///< Initial number of land tiles on the map.
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void Allocate(uint size_x, uint size_y);
|
static void Allocate(uint size_x, uint size_y);
|
||||||
|
static void CountLandTiles();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logarithm of the map size along the X side.
|
* Logarithm of the map size along the X side.
|
||||||
|
@ -307,6 +310,16 @@ public:
|
||||||
return Map::SizeY() - 1;
|
return Map::SizeY() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scales the given value by the number of water tiles.
|
||||||
|
* @param n the value to scale
|
||||||
|
* @return the scaled size
|
||||||
|
*/
|
||||||
|
static inline uint ScaleByLandProportion(uint n)
|
||||||
|
{
|
||||||
|
/* Use 64-bit arithmetic to avoid overflow. */
|
||||||
|
return static_cast<uint>(static_cast<uint64_t>(n) * Map::initial_land_count / Map::size);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 'Wraps' the given "tile" so it is within the map.
|
* 'Wraps' the given "tile" so it is within the map.
|
||||||
|
|
|
@ -53,6 +53,7 @@
|
||||||
#include "road_cmd.h"
|
#include "road_cmd.h"
|
||||||
#include "terraform_cmd.h"
|
#include "terraform_cmd.h"
|
||||||
#include "tunnelbridge_cmd.h"
|
#include "tunnelbridge_cmd.h"
|
||||||
|
#include "map_func.h"
|
||||||
#include "timer/timer.h"
|
#include "timer/timer.h"
|
||||||
#include "timer/timer_game_calendar.h"
|
#include "timer/timer_game_calendar.h"
|
||||||
#include "timer/timer_game_economy.h"
|
#include "timer/timer_game_economy.h"
|
||||||
|
@ -2424,7 +2425,7 @@ bool GenerateTowns(TownLayout layout)
|
||||||
{
|
{
|
||||||
uint current_number = 0;
|
uint current_number = 0;
|
||||||
uint difficulty = (_game_mode != GM_EDITOR) ? _settings_game.difficulty.number_towns : 0;
|
uint difficulty = (_game_mode != GM_EDITOR) ? _settings_game.difficulty.number_towns : 0;
|
||||||
uint total = (difficulty == (uint)CUSTOM_TOWN_NUMBER_DIFFICULTY) ? _settings_game.game_creation.custom_town_number : Map::ScaleBySize(_num_initial_towns[difficulty] + (Random() & 7));
|
uint total = (difficulty == (uint)CUSTOM_TOWN_NUMBER_DIFFICULTY) ? _settings_game.game_creation.custom_town_number : Map::ScaleByLandProportion(Map::ScaleBySize(_num_initial_towns[difficulty] + (Random() & 7)));
|
||||||
total = std::min<uint>(TownPool::MAX_SIZE, total);
|
total = std::min<uint>(TownPool::MAX_SIZE, total);
|
||||||
uint32_t townnameparts;
|
uint32_t townnameparts;
|
||||||
TownNames town_names;
|
TownNames town_names;
|
||||||
|
|
Loading…
Reference in New Issue