OpenTTD Source: src/misc.cpp Source File

OpenTTD Source 13.2.1

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"
28 #include "linkgraph/linkgraphschedule.h"
29 #include "station_kdtree.h"
30 #include "town_kdtree.h"
31 #include "viewport_kdtree.h"
32 #include "newgrf_profiling.h"
33
34 #include "safeguards.h"
35
36
37 extern TileIndex _cur_tileloop_tile;
38 extern void MakeNewgameSettingsLive();
39
40 void InitializeSound();
41 void InitializeMusic();
42 void InitializeVehicles();
43 void InitializeRailGui();
44 void InitializeRoadGui();
45 void InitializeAirportGui();
46 void InitializeDockGui();
47 void InitializeGraphGui();
48 void InitializeObjectGui();
49 void InitializeTownGui();
50 void InitializeIndustries();
51 void InitializeObjects();
52 void InitializeTrees();
53 void InitializeCompanies();
54 void InitializeCheats();
55 void InitializeNPF();
56 void InitializeOldNames();
57
58 void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settings)
59 {
60 /* Make sure there isn't any window that can influence anything
61 * related to the new game we're about to start/load. */
62 UnInitWindowSystem();
63
64 AllocateMap(size_x, size_y);
65
66 _pause_mode = PM_UNPAUSED;
67 _game_speed = 100;
68 _tick_counter = 0;
69 _cur_tileloop_tile = 1;
70 _thd.redsq = INVALID_TILE;
71 if (reset_settings) MakeNewgameSettingsLive();
72
73 _newgrf_profilers.clear();
74
75 if (reset_date) {
76 SetDate(ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1), 0);
77 InitializeOldNames();
78 }
79
80 LinkGraphSchedule::Clear();
81 PoolBase::Clean(PT_NORMAL);
82
83 RebuildStationKdtree();
84 RebuildTownKdtree();
85 RebuildViewportKdtree();
86
87 ResetPersistentNewGRFData();
88
89 InitializeSound();
90 InitializeMusic();
91
92 InitializeVehicles();
93
94 InitNewsItemStructs();
95 InitializeLandscape();
96 InitializeRailGui();
97 InitializeRoadGui();
98 InitializeAirportGui();
99 InitializeDockGui();
100 InitializeGraphGui();
101 InitializeObjectGui();
102 InitializeTownGui();
103 InitializeAIGui();
104 InitializeTrees();
105 InitializeIndustries();
106 InitializeObjects();
107 InitializeBuildingCounts();
108
109 InitializeNPF();
110
111 InitializeCompanies();
112 AI::Initialize();
113 Game::Initialize();
114 InitializeCheats();
115
116 InitTextEffects();
117 NetworkInitChatMessage();
118 InitializeAnimatedTiles();
119
120 InitializeEconomy();
121
122 ResetObjectToPlace();
123
124 GamelogReset();
125 GamelogStartAction(GLAT_START);
126 GamelogRevision();
127 GamelogMode();
128 GamelogGRFAddList(_grfconfig);
129 GamelogStopAction();
130 }
game.hpp
InitializeCompanies
void InitializeCompanies()
Initialize the pool of companies.
Definition: company_cmd.cpp:626
LinkGraphSchedule::Clear
static void Clear()
Clear all link graphs and jobs from the schedule.
Definition: linkgraphschedule.cpp:121
newgrf_house.h
station_kdtree.h
GamelogMode
void GamelogMode()
Logs a change in game mode (scenario editor or game)
Definition: gamelog.cpp:455
NetworkInitChatMessage
void NetworkInitChatMessage()
Initialize all buffers of the chat visualisation.
Definition: network_chat_gui.cpp:115
ResetPersistentNewGRFData
void ResetPersistentNewGRFData()
Reset NewGRF data which is stored persistently in savegames.
Definition: newgrf.cpp:8729
SetDate
void SetDate(Date date, DateFract fract)
Set the date.
Definition: date.cpp:37
ai_gui.hpp
InitNewsItemStructs
void InitNewsItemStructs()
Initialize the news-items data structures.
Definition: news_gui.cpp:634
INVALID_TILE
static constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:108
TileIndex
The index/ID of a Tile.
Definition: tile_type.h:85
UnInitWindowSystem
void UnInitWindowSystem()
Close down the windowing system.
Definition: window.cpp:1859
economy_func.h
gamelog.h
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition: settings_type.h:587
ai.hpp
PM_UNPAUSED
@ PM_UNPAUSED
A normal unpaused game.
Definition: openttd.h:61
gfx_func.h
InitializeOldNames
void InitializeOldNames()
Initialize the old names table memory.
Definition: strings_sl.cpp:110
InitializeEconomy
void InitializeEconomy()
Resets economy to initial values.
Definition: economy.cpp:946
tilehighlight_func.h
ConvertYMDToDate
Date ConvertYMDToDate(Year year, Month month, Day day)
Converts a tuple of Year, Month and Day to a Date.
Definition: date.cpp:149
_pause_mode
PauseMode _pause_mode
The current pause mode.
Definition: gfx.cpp:50
AI::Initialize
static void Initialize()
Initialize the AI system.
Definition: ai_core.cpp:163
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:54
GamelogStartAction
void GamelogStartAction(GamelogActionType at)
Stores information about new action, but doesn't allocate it Action is allocated only when there is a...
Definition: gamelog.cpp:69
safeguards.h
PoolBase::Clean
static void Clean(PoolType)
Clean all pools of given type.
Definition: pool_func.cpp:30
date_func.h
linkgraphschedule.h
stdafx.h
InitializeCheats
void InitializeCheats()
Reinitialise all the cheats.
Definition: cheat.cpp:19
landscape.h
GamelogStopAction
void GamelogStopAction()
Stops logging of any changes.
Definition: gamelog.cpp:78
animated_tile_func.h
texteff.hpp
PT_NORMAL
@ PT_NORMAL
Normal pool containing game objects.
Definition: pool_type.hpp:19
InitializeMusic
void InitializeMusic()
Prepare the music system for use.
Definition: music_gui.cpp:443
InitializeAIGui
void InitializeAIGui()
Reset the AI windows to their initial state.
Definition: ai_gui.cpp:1486
newgrf.h
GamelogGRFAddList
void GamelogGRFAddList(const GRFConfig *newg)
Logs adding of list of GRFs.
Definition: gamelog.cpp:681
GameCreationSettings::starting_year
Year starting_year
starting date
Definition: settings_type.h:313
GamelogReset
void GamelogReset()
Resets and frees all memory allocated - used before loading or starting a new game.
Definition: gamelog.cpp:115
_grfconfig
GRFConfig * _grfconfig
First item in list of current GRF set up.
Definition: newgrf_config.cpp:171
window_func.h
InitializeObjectGui
void InitializeObjectGui()
Reset all data of the object GUI.
Definition: object_gui.cpp:763
InitializeObjects
void InitializeObjects()
Initialize/reset the objects.
Definition: object_cmd.cpp:71
InitializeRailGui
void InitializeRailGui()
Initialize rail building GUI settings.
Definition: rail_gui.cpp:2133
GamelogRevision
void GamelogRevision()
Logs a change in game revision.
Definition: gamelog.cpp:438
pool_type.hpp
_tick_counter
uint64 _tick_counter
Ever incrementing tick counter for setting off various events.
Definition: date.cpp:30
newgrf_profiling.h
AllocateMap
void AllocateMap(uint size_x, uint size_y)
(Re)allocates a map with the given dimension
Definition: map.cpp:39
ResetObjectToPlace
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
Definition: viewport.cpp:3434
InitializeAnimatedTiles
void InitializeAnimatedTiles()
Initialize all animated tile variables to some known begin point.
Definition: animated_tile.cpp:74
town_kdtree.h
network_func.h
TileHighlightData::redsq
TileIndex redsq
The tile that has to get a red selection.
Definition: tilehighlight_type.h:72
GLAT_START
@ GLAT_START
Game created.
Definition: gamelog.h:17
_game_speed
uint16 _game_speed
Current game-speed; 100 is 1x, 0 is infinite.
Definition: gfx.cpp:40
news_func.h
Game::Initialize
static void Initialize()
Initialize the Game system.
Definition: game_core.cpp:57