OpenTTD: src/genworld.cpp File Reference

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

Functions | Variables
genworld.cpp File Reference

Functions to generate a map. More...

`#include "stdafx.h"`
`#include "landscape.h"`
`#include "company_func.h"`
`#include "genworld.h"`
`#include "gfxinit.h"`
`#include "window_func.h"`
`#include "network/network.h"`
`#include "heightmap.h"`
`#include "viewport_func.h"`
`#include "date_func.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 "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 "string_func.h"`
`#include "safeguards.h"`

Go to the source code of this file.

## 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 the next competitor now.
void | StartupDisasters ()
void | InitializeGame (uint size_x, uint size_y, bool reset_date, bool reset_settings)
bool | IsGenerateWorldThreaded ()
| Tells if the world generation is done in a thread or not.
static void | CleanupGeneration ()
| Clean up the 'mess' of generation.
static void | _GenerateWorld (void *)
| 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 | WaitTillGeneratedWorld ()
| This will wait for the thread to finish up his work.
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.

## Variables
GenWorldInfo | _gw
| Please only use this variable in genworld.h and genworld.cpp and nowhere else.
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

static void CleanupGeneration | ( |  | ) |
| static

Clean up the 'mess' of generation.

That is, show windows again, reset thread variables, and delete the progress window.

Definition at line 76 of file genworld.cpp.

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

Referenced by _GenerateWorld(), and HandleGeneratingWorldAbortion().

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 2116 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(), and BuildIndustryWindow::OnClick().

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 300 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(), ScaleByMapSize(), SetGeneratingWorldProgress(), TP_IMPROVED, TP_NONE, TP_ORIGINAL, and GameCreationSettings::tree_placer.

Referenced by _GenerateWorld().

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

Generate a world.

Parameters

  mode | The mode of world generation (see GenWorldMode).
  size_x | The X-size of the map.
  size_y | The Y-size of the map.
  reset_settings | Whether to reset the game configuration (used for restart)

Definition at line 298 of file genworld.cpp.

References _GenerateWorld(), _local_company, _modal_progress_work_mutex, GenWorldInfo::abort, GenWorldInfo::abortp, ThreadMutex::BeginCritical(), COMPANY_SPECTATOR, DEBUG, DeleteAllNonVitalWindows(), ThreadMutex::EndCritical(), FindWindowById(), VideoDriver::GetInstance(), GfxLoadSprites(), HasModalProgress(), HideVitalWindows(), HT_NONE, ThreadObject::Join(), GenWorldInfo::lc, LoadStringWidthTable(), MapSizeX(), MapSizeY(), GenWorldInfo::mode, ThreadObject::New(), PrepareGenerateWorldProgress(), GenWorldInfo::quit_thread, ResetWindowSystem(), ScrollMainWindowToTile(), SetLocalCompany(), SetModalProgress(), SetObjectToPlace(), SetupColoursAndInitialWindow(), ShowGenerateWorldProgress(), GenWorldInfo::size_x, GenWorldInfo::size_y, GenWorldInfo::thread, GenWorldInfo::threaded, TileXY(), UnshowCriticalError(), and WC_MAIN_WINDOW.

Referenced by LoadIntroGame(), and openttd_main().

void GenerateWorldSetAbortCallback | ( | GWAbortProc * | proc | ) |

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

Parameters

  proc | callback procedure

Definition at line 233 of file genworld.cpp.

References GenWorldInfo::abortp.

Referenced by GenerateTerrainPerlin().

void GenerateWorldSetCallback | ( | GWDoneProc * | proc | ) |

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

Parameters

  proc | callback procedure

Definition at line 223 of file genworld.cpp.

References GenWorldInfo::proc.

void HandleGeneratingWorldAbortion | ( |  | ) |

Really handle the abortion, i.e.

clean up some of the mess

Definition at line 277 of file genworld.cpp.

References _switch_mode, GenWorldInfo::abortp, CleanupGeneration(), ThreadObject::Exit(), SM_EDITOR, SM_MENU, and GenWorldInfo::thread.

Referenced by _GenerateWorld().

bool IsGenerateWorldThreaded | ( |  | ) |

Tells if the world generation is done in a thread or not.

Returns
  the 'threaded' status

Definition at line 67 of file genworld.cpp.

References GenWorldInfo::quit_thread, and GenWorldInfo::threaded.

bool IsGeneratingWorldAborted | ( |  | ) |

Is the generation being aborted?

Returns
  the 'aborted' status

Definition at line 269 of file genworld.cpp.

References GenWorldInfo::abort.

void StartupCompanies | ( |  | ) |

Start the next competitor now.

Definition at line 583 of file company_cmd.cpp.

References _next_competitor_start.

Referenced by _GenerateWorld().

void WaitTillGeneratedWorld | ( |  | ) |

This will wait for the thread to finish up his work.

It will not continue till the work is done.

Definition at line 242 of file genworld.cpp.

References _modal_progress_paint_mutex, _modal_progress_work_mutex, ThreadMutex::BeginCritical(), ThreadMutex::EndCritical(), ThreadObject::Join(), GenWorldInfo::quit_thread, GenWorldInfo::thread, and GenWorldInfo::threaded.

Referenced by LoadIntroGame(), and openttd_main().

## Variable Documentation

bool _generating_world

Whether we are generating the map or not.

Definition at line 61 of file genworld.cpp.

Referenced by _GenerateWorld(), BuildTownHouse(), CanFollowRoad(), CheckIfIndustryTilesAreFree(), CleanupGeneration(), ClosestTownFromTile(), CmdBuildObject(), CmdDeleteTown(), CmdFoundTown(), CmdTerraformLand(), CreateNewIndustryHelper(), DoCommandP(), DoCommandPInternal(), DoCreateNewIndustry(), GenerateDesertArea(), GenerateTownName(), GetTerrainType(), HouseScopeResolver::GetVariable(), GrowTown(), GrowTownInTile(), HasRoadTypesAvail(), InitializeGRFSpecial(), ObjectSpec::IsEverAvailable(), IsRoadAllowedHere(), BuildIndustryWindow::OnClick(), FoundTownWindow::OnClick(), BuildIndustryWindow::OnPlaceObject(), ResetLandscapeConfirmationCallback(), TownLayoutAllows2x2HouseHere(), TownLayoutAllowsHouseHere(), and UpdateNearestTownForRoadTiles().

GenWorldInfo _gw

Please only use this variable in genworld.h and genworld.cpp and nowhere else.

For speed improvements we need it to be global, but in no way the meaning of it is to use it anywhere else besides in the genworld.h and genworld.cpp!

Definition at line 58 of file genworld.cpp.