# genworld.h File Reference

Functions related to world/map generation. More...

`#include "company_type.h"`

Go to the source code of this file.

## Data Structures
struct | GenWorldInfo
| Properties of current genworld process. More...
## Typedefs
typedef void | GWDoneProc ()
| Procedure called when the genworld process finishes.
typedef void | GWAbortProc ()
| Called when genworld is aborted.
## Enumerations
enum | { LG_ORIGINAL = 0, LG_TERRAGENESIS = 1, GENERATE_NEW_SEED = UINT_MAX, GENWORLD_REDRAW_TIMEOUT = 200 }
| Constants related to world generation. More...
enum | GenWorldMode { GWM_NEWGAME = 0, GWM_EMPTY = 1, GWM_RANDOM = 2, GWM_HEIGHTMAP = 3 }
| Modes for GenerateWorld. More...
enum | GenWorldProgress { GWP_MAP_INIT, GWP_LANDSCAPE, GWP_ROUGH_ROCKY, GWP_TOWN, GWP_INDUSTRY, GWP_UNMOVABLE, GWP_TREE, GWP_GAME_INIT, GWP_RUNTILELOOP, GWP_GAME_START, GWP_CLASS_COUNT }
| Current stage of world generation process. More...
## Functions
static bool | IsGeneratingWorld ()
| Check if we are currently in the process of generating a world.
bool | IsGenerateWorldThreaded ()
| Tells if the world generation is done in a thread or not.
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 | GenerateWorld (GenWorldMode mode, uint size_x, uint size_y, bool reset_settings=true)
| Generate a world.
void | AbortGeneratingWorld ()
| Initializes the abortion process.
bool | IsGeneratingWorldAborted ()
| Is the generation being aborted?
void | HandleGeneratingWorldAbortion ()
| Really handle the abortion, i.e.
void | SetGeneratingWorldProgress (GenWorldProgress cls, uint total)
| Set the total of a stage of the world generation.
void | IncreaseGeneratingWorldProgress (GenWorldProgress cls)
| Increases the current stage of the world generation with one.
void | PrepareGenerateWorldProgress ()
| Initializes the progress counters to the starting point.
void | ShowGenerateWorldProgress ()
| Show the window where a user can follow the process of the map generation.
void | StartNewGameWithoutGUI (uint seed)
void | ShowCreateScenario ()
void | StartScenarioEditor ()
## Variables
class ThreadMutex * | _genworld_mapgen_mutex
| Rights for the map generation.
class ThreadMutex * | _genworld_paint_mutex
| Rights for the painting.

## Detailed Description

Functions related to world/map generation.

Definition in file genworld.h.

## Enumeration Type Documentation

anonymous enum

Constants related to world generation.

Enumerator:

  LG_ORIGINAL | The original landscape generator.
  LG_TERRAGENESIS | TerraGenesis Perlin landscape generator.
  GENERATE_NEW_SEED | Create a new random seed.
  GENWORLD_REDRAW_TIMEOUT | Timeout between redraws.

Definition at line 18 of file genworld.h.

enum GenWorldMode

Modes for GenerateWorld.

Enumerator:

  GWM_NEWGAME | Generate a map for a new game.
  GWM_EMPTY | Generate an empty map (sea-level).
  GWM_RANDOM | Generate a random map for SE.
  GWM_HEIGHTMAP | Generate a newgame from a heightmap.

Definition at line 30 of file genworld.h.

enum GenWorldProgress

Current stage of world generation process.

Enumerator:

  GWP_MAP_INIT | Initialize/allocate the map, start economy.
  GWP_LANDSCAPE | Create the landscape.
  GWP_ROUGH_ROCKY | Make rough and rocky areas.
  GWP_TOWN | Generate towns.
  GWP_INDUSTRY | Generate industries.
  GWP_UNMOVABLE | Generate unmovables (radio tower, light houses).
  GWP_TREE | Generate trees.
  GWP_GAME_INIT | Initialize the game.
  GWP_RUNTILELOOP | Runs the tile loop 1280 times to make snow etc.
  GWP_GAME_START | Really prepare to start the game.

Definition at line 56 of file genworld.h.

## Function Documentation

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 275 of file genworld.cpp.

References _GenerateWorld(), _settings_game, GenWorldInfo::abort, GenWorldInfo::abortp, GenWorldInfo::active, ThreadMutex::BeginCritical(), COMPANY_SPECTATOR, ConvertYMDToDate(), DeleteAllNonVitalWindows(), ThreadMutex::EndCritical(), FindWindowById(), GameSettings::game_creation, BlitterFactoryBase::GetCurrentBlitter(), HideVitalWindows(), HT_NONE, ThreadObject::Join(), GenWorldInfo::lc, LoadStringWidthTable(), MapSizeX(), MapSizeY(), GenWorldInfo::mode, ThreadObject::New(), OWNER_NONE, PrepareGenerateWorldProgress(), GenWorldInfo::quit_thread, ResetWindowSystem(), SetLocalCompany(), ShowGenerateWorldProgress(), GenWorldInfo::size_x, GenWorldInfo::size_y, GameCreationSettings::starting_year, GenWorldInfo::thread, GenWorldInfo::threaded, and TileXY().

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 209 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 199 of file genworld.cpp.

References GenWorldInfo::proc.

void HandleGeneratingWorldAbortion | ( |  | ) |

Really handle the abortion, i.e.

clean up some of the mess

Definition at line 253 of file genworld.cpp.

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

Referenced by _GenerateWorld().

void IncreaseGeneratingWorldProgress | ( | GenWorldProgress | cls | ) |

Increases the current stage of the world generation with one.

Parameters:

  | cls | the current class we are in.

Warning: this function isn't clever. Don't go from class 4 to 3. Go upwards, always. Also, progress works if total is zero, total works if progress is zero.

Definition at line 1332 of file genworld_gui.cpp.

Referenced by _GenerateWorld(), GenerateLandscape(), GenerateTerrainPerlin(), GenerateTowns(), PlaceInitialIndustry(), and PlaceTreesRandomly().

bool IsGenerateWorldThreaded | ( |  | ) |

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

Returns:
  the 'threaded' status

Definition at line 68 of file genworld.cpp.

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

static bool IsGeneratingWorld | ( |  | ) | `[inline, static]`

Check if we are currently in the process of generating a world.

Returns:
  are we generating world?

Definition at line 74 of file genworld.h.

References _gw, and GenWorldInfo::active.

Referenced by DoCommandP(), DrawDirtyBlocks(), HandleAutoscroll(), HandleKeypress(), HandleMouseEvents(), HasRoadTypesAvail(), and StateGameLoop().

bool IsGeneratingWorldAborted | ( |  | ) |

Is the generation being aborted?

Returns:
  the 'aborted' status

Definition at line 245 of file genworld.cpp.

References GenWorldInfo::abort.

void SetGeneratingWorldProgress | ( | GenWorldProgress | cls,
|  | uint | total |
| ) |  |  |

Set the total of a stage of the world generation.

Parameters:

  | cls | the current class we are in.
  | total | Set the total expected items for this class.

Warning: this function isn't clever. Don't go from class 4 to 3. Go upwards, always. Also, progress works if total is zero, total works if progress is zero.

Definition at line 1318 of file genworld_gui.cpp.

Referenced by _GenerateWorld(), GenerateIndustries(), GenerateLandscape(), GenerateTowns(), and GenerateTrees().

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 218 of file genworld.cpp.

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