OpenTTD
misc.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #include "stdafx.h"
11 #include "landscape.h"
12 #include "news_func.h"
13 #include "ai/ai.hpp"
14 #include "ai/ai_gui.hpp"
15 #include "newgrf.h"
16 #include "newgrf_house.h"
17 #include "economy_func.h"
18 #include "date_func.h"
19 #include "texteff.hpp"
20 #include "gfx_func.h"
21 #include "gamelog.h"
22 #include "animated_tile_func.h"
23 #include "tilehighlight_func.h"
24 #include "network/network_func.h"
25 #include "window_func.h"
26 #include "core/pool_type.hpp"
27 #include "game/game.hpp"
29 #include "station_kdtree.h"
30 #include "town_kdtree.h"
31 #include "viewport_kdtree.h"
32 
33 #include "safeguards.h"
34 
35 
36 extern TileIndex _cur_tileloop_tile;
37 extern void MakeNewgameSettingsLive();
38 
39 void InitializeSound();
40 void InitializeMusic();
41 void InitializeVehicles();
42 void InitializeRailGui();
43 void InitializeRoadGui();
44 void InitializeAirportGui();
45 void InitializeDockGui();
46 void InitializeGraphGui();
47 void InitializeObjectGui();
48 void InitializeTownGui();
49 void InitializeIndustries();
50 void InitializeObjects();
51 void InitializeTrees();
52 void InitializeCompanies();
53 void InitializeCheats();
54 void InitializeNPF();
55 void InitializeOldNames();
56 
57 void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settings)
58 {
59  /* Make sure there isn't any window that can influence anything
60  * related to the new game we're about to start/load. */
62 
63  AllocateMap(size_x, size_y);
64 
66  _fast_forward = 0;
67  _tick_counter = 0;
68  _cur_tileloop_tile = 1;
69  _thd.redsq = INVALID_TILE;
70  if (reset_settings) MakeNewgameSettingsLive();
71 
72  if (reset_date) {
75  }
76 
79 
80  RebuildStationKdtree();
81  RebuildTownKdtree();
82  RebuildViewportKdtree();
83 
85 
86  InitializeSound();
88 
89  InitializeVehicles();
90 
92  InitializeLandscape();
94  InitializeRoadGui();
95  InitializeAirportGui();
96  InitializeDockGui();
97  InitializeGraphGui();
99  InitializeTownGui();
100  InitializeAIGui();
101  InitializeTrees();
102  InitializeIndustries();
104  InitializeBuildingCounts();
105 
106  InitializeNPF();
107 
109  AI::Initialize();
112 
113  InitTextEffects();
116 
118 
120 
121  GamelogReset();
123  GamelogRevision();
124  GamelogMode();
127 }
void InitializeRailGui()
Initialize rail building GUI settings.
Definition: rail_gui.cpp:1885
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:79
GRFConfig * _grfconfig
First item in list of current GRF set up.
Declarations for accessing the k-d tree of towns.
Functions related to dates.
Window for configuring the AIs
Functions to be called to log possibly unsafe game events.
void InitializeOldNames()
Initialize the old names table memory.
Definition: strings_sl.cpp:116
void GamelogStartAction(GamelogActionType at)
Stores information about new action, but doesn&#39;t allocate it Action is allocated only when there is a...
Definition: gamelog.cpp:69
void InitializeCompanies()
Initialize the pool of companies.
void GamelogRevision()
Logs a change in game revision.
Definition: gamelog.cpp:433
void AllocateMap(uint size_x, uint size_y)
(Re)allocates a map with the given dimension
Definition: map.cpp:39
static void Initialize()
Initialize the AI system.
Definition: ai_core.cpp:161
void InitializeAIGui()
Reset the AI windows to their initial state.
Definition: ai_gui.cpp:1542
static void Clean(PoolType)
Clean all pools of given type.
Definition: pool_func.cpp:30
void ResetPersistentNewGRFData()
Reset NewGRF data which is stored persistently in savegames.
Definition: newgrf.cpp:8642
Declarations for accessing the k-d tree of stations.
Normal pool containing game objects.
Definition: pool_type.hpp:20
Definition of Pool, structure used to access PoolItems, and PoolItem, base structure for Vehicle...
void InitializeEconomy()
Resets economy to initial values.
Definition: economy.cpp:927
Game created.
Definition: gamelog.h:17
void SetDate(Date date, DateFract fract)
Set the date.
Definition: date.cpp:35
Tile animation!
void GamelogReset()
Resets and frees all memory allocated - used before loading or starting a new game.
Definition: gamelog.cpp:110
void InitializeCheats()
Reinitialise all the cheats.
Definition: cheat.cpp:19
A normal unpaused game.
Definition: openttd.h:56
Functions related to NewGRF houses.
Functions related to the gfx engine.
void InitNewsItemStructs()
Initialize the news-items data structures.
Definition: news_gui.cpp:625
void GamelogMode()
Logs a change in game mode (scenario editor or game)
Definition: gamelog.cpp:450
Definition of base types and functions in a cross-platform compatible way.
A number of safeguards to prevent using unsafe methods.
Declaration of link graph schedule used for cargo distribution.
void GamelogGRFAddList(const GRFConfig *newg)
Logs adding of list of GRFs.
Definition: gamelog.cpp:676
PauseMode _pause_mode
The current pause mode.
Definition: gfx.cpp:47
void UnInitWindowSystem()
Close down the windowing system.
Definition: window.cpp:1914
void GamelogStopAction()
Stops logging of any changes.
Definition: gamelog.cpp:78
void InitializeMusic()
Prepare the music system for use.
Definition: music_gui.cpp:444
static void Initialize()
Initialize the Game system.
Definition: game_core.cpp:57
uint16 _tick_counter
Ever incrementing (and sometimes wrapping) tick counter for setting off various events.
Definition: date.cpp:28
void NetworkInitChatMessage()
Initialize all buffers of the chat visualisation.
void InitializeObjects()
Initialize/reset the objects.
Definition: object_cmd.cpp:68
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:78
Functions related to the economy.
TileIndex redsq
The tile that has to get a red selection.
void InitializeAnimatedTiles()
Initialize all animated tile variables to some known begin point.
static void Clear()
Clear all link graphs and jobs from the schedule.
Functions related to OTTD&#39;s landscape.
Base functions for all Games.
Network functions used by other parts of OpenTTD.
Base functions for all AIs.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:83
GameCreationSettings game_creation
settings used during the creation of a game (map)
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows)...
Definition: viewport.cpp:3353
Date ConvertYMDToDate(Year year, Month month, Day day)
Converts a tuple of Year, Month and Day to a Date.
Definition: date.cpp:147
Functions related to tile highlights.
Window functions not directly related to making/drawing windows.
Functions related to text effects.
void InitializeObjectGui()
Reset all data of the object GUI.
Definition: object_gui.cpp:531
Functions related to news.
Year starting_year
starting date
Base for the NewGRF implementation.