OpenTTD Source 20250312-master-gcdcc6b491d
genworld.cpp File Reference

Functions to generate a map. More...

#include "stdafx.h"
#include "landscape.h"
#include "company_func.h"
#include "town_cmd.h"
#include "signs_cmd.h"
#include "3rdparty/nlohmann/json.hpp"
#include "strings_func.h"
#include "genworld.h"
#include "gfxinit.h"
#include "window_func.h"
#include "network/network.h"
#include "heightmap.h"
#include "viewport_func.h"
#include "timer/timer_game_calendar.h"
#include "timer/timer_game_tick.h"
#include "engine_func.h"
#include "water.h"
#include "video/video_driver.hpp"
#include "tilehighlight_func.h"
#include "saveload/saveload.h"
#include "void_map.h"
#include "town.h"
#include "newgrf.h"
#include "newgrf_house.h"
#include "core/random_func.hpp"
#include "core/backup_type.hpp"
#include "progress.h"
#include "error.h"
#include "game/game.hpp"
#include "game/game_instance.hpp"
#include "newgrf_railtype.h"
#include "newgrf_roadtype.h"
#include "string_func.h"
#include "thread.h"
#include "tgp.h"
#include "safeguards.h"

Go to the source code of this file.

Data Structures

struct  GenWorldInfo
 Properties of current genworld process. More...
 
class  AbortGenerateWorldSignal
 
struct  ExternalTownData
 Town data imported from JSON files and used to place towns. More...
 

Functions

void GenerateClearTile ()
 
void GenerateIndustries ()
 This function will create random industries during game creation.
 
void GenerateObjects ()
 
void GenerateTrees ()
 Place new trees.
 
void StartupEconomy ()
 
void StartupCompanies ()
 Start of a new game.
 
void StartupDisasters ()
 
void InitializeGame (uint size_x, uint size_y, bool reset_date, bool reset_settings)
 
static void CleanupGeneration ()
 Generation is done; show windows again and delete the progress window.
 
static void _GenerateWorld ()
 The internal, real, generate function.
 
void GenerateWorldSetCallback (GWDoneProc *proc)
 Set here the function, if any, that you want to be called when landscape generation is done.
 
void GenerateWorldSetAbortCallback (GWAbortProc *proc)
 Set here the function, if any, that you want to be called when landscape generation is aborted.
 
void AbortGeneratingWorld ()
 Initializes the abortion process.
 
bool IsGeneratingWorldAborted ()
 Is the generation being aborted?
 
void HandleGeneratingWorldAbortion ()
 Really handle the abortion, i.e.
 
void GenerateWorld (GenWorldMode mode, uint size_x, uint size_y, bool reset_settings)
 Generate a world.
 
static bool TryFoundTownNearby (TileIndex tile, void *user_data)
 Helper for CircularTileSearch to found a town on or near a given tile.
 
void LoadTownData ()
 Load town data from _file_to_saveload, place towns at the appropriate locations, and expand them to their target populations.
 

Variables

bool _generating_world
 Whether we are generating the map or not.
 

Detailed Description

Functions to generate a map.

Definition in file genworld.cpp.

Function Documentation

◆ _GenerateWorld()

static void _GenerateWorld ( )
static

◆ AbortGeneratingWorld()

void AbortGeneratingWorld ( )

Initializes the abortion process.

Definition at line 257 of file genworld.cpp.

References GenWorldInfo::abort.

◆ CleanupGeneration()

static void CleanupGeneration ( )
static

Generation is done; show windows again and delete the progress window.

Definition at line 79 of file genworld.cpp.

References _generating_world, GenWorldInfo::abortp, CloseWindowByClass(), MarkWholeScreenDirty(), GenWorldInfo::proc, SetModalProgress(), SetMouseCursorBusy(), ShowFirstError(), and WC_MODAL_PROGRESS.

Referenced by _GenerateWorld().

◆ GenerateClearTile()

void GenerateClearTile ( )

Definition at line 307 of file clear_cmd.cpp.

◆ GenerateIndustries()

void GenerateIndustries ( )

This function will create random industries during game creation.

It will scale the amount of industries by mapsize and difficulty level.

Definition at line 2446 of file industry_cmd.cpp.

References _industry_builder, _settings_game, GameSettings::difficulty, GetNumberOfIndustries(), GetScaledIndustryGenerationProbability(), GWP_INDUSTRY, ID_FUND_ONLY, DifficultySettings::industry_density, NUM_INDUSTRYTYPES, PlaceInitialIndustry(), RandomRange(), IndustryBuildData::Reset(), and SetGeneratingWorldProgress().

Referenced by _GenerateWorld().

◆ GenerateObjects()

void GenerateObjects ( )

Definition at line 810 of file object_cmd.cpp.

◆ GenerateTrees()

void GenerateTrees ( )

Place new trees.

This function takes care of the selected tree placer algorithm and place randomly the trees for a new game.

Definition at line 476 of file tree_cmd.cpp.

References _settings_game, DEFAULT_RAINFOREST_TREE_STEPS, DEFAULT_TREE_STEPS, GameSettings::game_creation, GB(), GWP_TREE, GameCreationSettings::landscape, PlaceTreeGroups(), PlaceTreesRandomly(), Random, Map::ScaleBySize(), SetGeneratingWorldProgress(), TP_IMPROVED, TP_NONE, TP_ORIGINAL, and GameCreationSettings::tree_placer.

Referenced by _GenerateWorld().

◆ GenerateWorld()

void GenerateWorld ( GenWorldMode  mode,
uint  size_x,
uint  size_y,
bool  reset_settings 
)

◆ GenerateWorldSetAbortCallback()

void GenerateWorldSetAbortCallback ( GWAbortProc proc)

Set here the function, if any, that you want to be called when landscape generation is aborted.

Parameters
proccallback procedure

Definition at line 249 of file genworld.cpp.

References GenWorldInfo::abortp.

Referenced by GenerateTerrainPerlin().

◆ GenerateWorldSetCallback()

void GenerateWorldSetCallback ( GWDoneProc proc)

Set here the function, if any, that you want to be called when landscape generation is done.

Parameters
proccallback procedure

Definition at line 239 of file genworld.cpp.

References GenWorldInfo::proc.

◆ HandleGeneratingWorldAbortion()

void HandleGeneratingWorldAbortion ( )

Really handle the abortion, i.e.

clean up some of the mess

Definition at line 274 of file genworld.cpp.

References _switch_mode, GenWorldInfo::abortp, SM_EDITOR, and SM_MENU.

Referenced by _GenerateWorld().

◆ InitializeGame()

void InitializeGame ( uint  size_x,
uint  size_y,
bool  reset_date,
bool  reset_settings 
)

Definition at line 92 of file misc.cpp.

◆ IsGeneratingWorldAborted()

bool IsGeneratingWorldAborted ( )

Is the generation being aborted?

Returns
the 'aborted' status

Definition at line 266 of file genworld.cpp.

References GenWorldInfo::abort.

◆ LoadTownData()

◆ StartupCompanies()

void StartupCompanies ( )

Start of a new game.

Definition at line 649 of file company_cmd.cpp.

References _new_competitor_timeout, and TimeoutTimer< TTimerType >::Abort().

Referenced by _GenerateWorld().

◆ StartupDisasters()

void StartupDisasters ( )

Definition at line 952 of file disaster_vehicle.cpp.

◆ StartupEconomy()

void StartupEconomy ( )

Definition at line 912 of file economy.cpp.

◆ TryFoundTownNearby()

static bool TryFoundTownNearby ( TileIndex  tile,
void *  user_data 
)
static

Helper for CircularTileSearch to found a town on or near a given tile.

Parameters
tileThe tile to try founding the town upon.
user_dataThe ExternalTownData to attempt to found.
Returns
True if the town was founded successfully.

Definition at line 368 of file genworld.cpp.

References _settings_game, GameSettings::economy, Execute, ExternalTownData::is_city, ExternalTownData::name, ExternalTownData::town_id, EconomySettings::town_layout, and TSZ_SMALL.

Referenced by LoadTownData().

Variable Documentation

◆ _generating_world