OpenTTD Source: src/gamelog.h Source File

OpenTTD Source 15.3

gamelog.h
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#ifndef GAMELOG_H
11#define GAMELOG_H
12
13#include "newgrf_config.h"
14
16 enum GamelogActionType : uint8_t {
17 GLAT_START,
18 GLAT_LOAD,
19 GLAT_GRF,
20 GLAT_CHEAT,
21 GLAT_SETTING,
22 GLAT_GRFBUG,
23 GLAT_EMERGENCY,
24 GLAT_END,
25 GLAT_NONE = 0xFF,
26};
27
29 enum GamelogChangeType : uint8_t {
30 GLCT_MODE,
31 GLCT_REVISION,
32 GLCT_OLDVER,
33 GLCT_SETTING,
34 GLCT_GRFADD,
35 GLCT_GRFREM,
36 GLCT_GRFCOMPAT,
37 GLCT_GRFPARAM,
38 GLCT_GRFMOVE,
39 GLCT_GRFBUG,
40 GLCT_EMERGENCY,
41 GLCT_END,
42 GLCT_NONE = 0xFF,
43};
44
45struct LoggedChange;
46struct LoggedAction;
47struct GamelogInternalData;
48
49 class Gamelog {
50private:
51 std::unique_ptr<GamelogInternalData> data;
52 GamelogActionType action_type;
53 struct LoggedAction *current_action;
54
55 void Change(std::unique_ptr<LoggedChange> &&change);
56
57public:
58 Gamelog();
59 ~Gamelog();
60
61 void StartAction(GamelogActionType at);
62 void StopAction();
63 void StopAnyAction();
64
65 void Reset();
66
67 void Print(std::function<void(const std::string &)> proc);
68 void PrintDebug(int level);
69 void PrintConsole();
70
71 void Emergency();
72 bool TestEmergency();
73
74 void Revision();
75 void Mode();
76 void Oldver();
77 void Setting(const std::string &name, int32_t oldval, int32_t newval);
78
79 void GRFUpdate(const GRFConfigList &oldg, const GRFConfigList &newg);
80 void GRFAddList(const GRFConfigList &newg);
81 void GRFRemove(uint32_t grfid);
82 void GRFAdd(const GRFConfig &newg);
83 void GRFBug(uint32_t grfid, ::GRFBug bug, uint64_t data);
84 bool GRFBugReverse(uint32_t grfid, uint16_t internal_id);
85 void GRFCompatible(const GRFIdentifier &newg);
86 void GRFMove(uint32_t grfid, int32_t offset);
87 void GRFParameters(uint32_t grfid);
88
89 void TestRevision();
90 void TestMode();
91
92 void Info(uint32_t *last_ottd_rev, uint8_t *ever_modified, bool *removed_newgrfs);
93 const GRFIdentifier &GetOverriddenIdentifier(const GRFConfig &c);
94
95 /* Saveload handler for gamelog needs access to internal data. */
96 friend struct GLOGChunkHandler;
97};
98
99extern Gamelog _gamelog;
100
101#endif /* GAMELOG_H */
Gamelog
Definition gamelog.h:49
Gamelog::TestRevision
void TestRevision()
Finds out if current revision is different than last revision stored in the savegame.
Definition gamelog.cpp:425
Gamelog::GetOverriddenIdentifier
const GRFIdentifier & GetOverriddenIdentifier(const GRFConfig &c)
Try to find the overridden GRF identifier of the given GRF.
Definition gamelog.cpp:712
Gamelog::Mode
void Mode()
Logs a change in game mode (scenario editor or game)
Definition gamelog.cpp:389
Gamelog::Info
void Info(uint32_t *last_ottd_rev, uint8_t *ever_modified, bool *removed_newgrfs)
Get some basic information from the given gamelog.
Definition gamelog.cpp:685
Gamelog::PrintDebug
void PrintDebug(int level)
Prints gamelog to debug output.
Definition gamelog.cpp:323
Gamelog::PrintConsole
void PrintConsole()
Print the gamelog data to the console.
Definition gamelog.cpp:310
Gamelog::GRFParameters
void GRFParameters(uint32_t grfid)
Logs change in GRF parameters.
Definition gamelog.cpp:566
Gamelog::Revision
void Revision()
Logs a change in game revision.
Definition gamelog.cpp:378
Gamelog::StartAction
void StartAction(GamelogActionType at)
Stores information about new action, but doesn't allocate it Action is allocated only when there is a...
Definition gamelog.cpp:65
Gamelog::Reset
void Reset()
Resets and frees all memory allocated - used before loading or starting a new game.
Definition gamelog.cpp:94
Gamelog::GRFRemove
void GRFRemove(uint32_t grfid)
Logs removal of a GRF.
Definition gamelog.cpp:517
Gamelog::GRFAddList
void GRFAddList(const GRFConfigList &newg)
Logs adding of list of GRFs.
Definition gamelog.cpp:578
Gamelog::GRFCompatible
void GRFCompatible(const GRFIdentifier &newg)
Logs loading compatible GRF (the same ID, but different MD5 hash)
Definition gamelog.cpp:542
Gamelog::Oldver
void Oldver()
Logs loading from savegame without gamelog.
Definition gamelog.cpp:399
Gamelog::Emergency
void Emergency()
Logs a emergency savegame.
Definition gamelog.cpp:352
Gamelog::GRFBugReverse
bool GRFBugReverse(uint32_t grfid, uint16_t internal_id)
Logs GRF bug - rail vehicle has different length after reversing.
Definition gamelog.cpp:482
Gamelog::TestMode
void TestMode()
Finds last stored game mode or landscape.
Definition gamelog.cpp:446
Gamelog::StopAction
void StopAction()
Stops logging of any changes.
Definition gamelog.cpp:74
Gamelog::Setting
void Setting(const std::string &name, int32_t oldval, int32_t newval)
Logs change in game settings.
Definition gamelog.cpp:413
Gamelog::Print
void Print(std::function< void(const std::string &)> proc)
Prints active gamelog.
Definition gamelog.cpp:147
Gamelog::GRFAdd
void GRFAdd(const GRFConfig &newg)
Logs adding of a GRF.
Definition gamelog.cpp:528
Gamelog::GRFUpdate
void GRFUpdate(const GRFConfigList &oldg, const GRFConfigList &newg)
Compares two NewGRF lists and logs any change.
Definition gamelog.cpp:606
Gamelog::Change
void Change(std::unique_ptr< LoggedChange > &&change)
Allocates a new LoggedAction if needed, and add the change when action is active.
Definition gamelog.cpp:335
Gamelog::TestEmergency
bool TestEmergency()
Finds out if current game is a loaded emergency savegame.
Definition gamelog.cpp:364
Gamelog::GRFMove
void GRFMove(uint32_t grfid, int32_t offset)
Logs changing GRF order.
Definition gamelog.cpp:554
_gamelog
Gamelog _gamelog
Gamelog instance.
Definition gamelog.cpp:31
GamelogChangeType
GamelogChangeType
Type of logged change.
Definition gamelog.h:29
GLCT_MODE
@ GLCT_MODE
Scenario editor x Game, different landscape.
Definition gamelog.h:30
GLCT_OLDVER
@ GLCT_OLDVER
Loaded from savegame without logged data.
Definition gamelog.h:32
GLCT_SETTING
@ GLCT_SETTING
Non-networksafe setting value changed.
Definition gamelog.h:33
GLCT_GRFCOMPAT
@ GLCT_GRFCOMPAT
Loading compatible GRF.
Definition gamelog.h:36
GLCT_GRFADD
@ GLCT_GRFADD
Removed GRF.
Definition gamelog.h:34
GLCT_END
@ GLCT_END
So we know how many GLCTs are there.
Definition gamelog.h:41
GLCT_EMERGENCY
@ GLCT_EMERGENCY
Emergency savegame.
Definition gamelog.h:40
GLCT_GRFPARAM
@ GLCT_GRFPARAM
GRF parameter changed.
Definition gamelog.h:37
GLCT_GRFMOVE
@ GLCT_GRFMOVE
GRF order changed.
Definition gamelog.h:38
GLCT_GRFREM
@ GLCT_GRFREM
Added GRF.
Definition gamelog.h:35
GLCT_GRFBUG
@ GLCT_GRFBUG
GRF bug triggered.
Definition gamelog.h:39
GLCT_REVISION
@ GLCT_REVISION
Changed game revision string.
Definition gamelog.h:31
GLCT_NONE
@ GLCT_NONE
In savegames, end of list.
Definition gamelog.h:42
GamelogActionType
GamelogActionType
The actions we log.
Definition gamelog.h:16
GLAT_GRFBUG
@ GLAT_GRFBUG
GRF bug was triggered.
Definition gamelog.h:22
GLAT_START
@ GLAT_START
Game created.
Definition gamelog.h:17
GLAT_NONE
@ GLAT_NONE
No logging active; in savegames, end of list.
Definition gamelog.h:25
GLAT_GRF
@ GLAT_GRF
GRF changed.
Definition gamelog.h:19
GLAT_END
@ GLAT_END
So we know how many GLATs are there.
Definition gamelog.h:24
GLAT_LOAD
@ GLAT_LOAD
Game loaded.
Definition gamelog.h:18
GLAT_CHEAT
@ GLAT_CHEAT
Cheat was used.
Definition gamelog.h:20
GLAT_EMERGENCY
@ GLAT_EMERGENCY
Emergency savegame.
Definition gamelog.h:23
GLAT_SETTING
@ GLAT_SETTING
Setting changed.
Definition gamelog.h:21
newgrf_config.h
Functions to find and configure NewGRFs.
GRFBug
GRFBug
Encountered GRF bugs.
Definition newgrf_config.h:42
GLOGChunkHandler
Definition gamelog_sl.cpp:377
GRFConfig
Information about GRF, used in the game and (part of it) in savegames.
Definition newgrf_config.h:158
GRFIdentifier
Basic data to distinguish a GRF.
Definition newgrf_config.h:83
GamelogInternalData
Definition gamelog_internal.h:149
LoggedAction
Contains information about one logged action that caused at least one logged change.
Definition gamelog_internal.h:143
LoggedChange
Definition gamelog_internal.h:32