OpenTTD Source  20240917-master-g9ab0a47812
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 <http://www.gnu.org/licenses/>.
6  */
7 
10 #ifndef GAMELOG_H
11 #define GAMELOG_H
12 
13 #include "newgrf_config.h"
14 
16 enum GamelogActionType : uint8_t {
25  GLAT_NONE = 0xFF,
26 };
27 
29 enum GamelogChangeType : uint8_t {
42  GLCT_NONE = 0xFF,
43 };
44 
45 struct LoggedChange;
46 struct LoggedAction;
47 struct GamelogInternalData;
48 
49 class Gamelog {
50 private:
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 
57 public:
58  Gamelog();
59  ~Gamelog();
60 
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 GRFConfig *oldg, const GRFConfig *newg);
80  void GRFAddList(const GRFConfig *newg);
81  void GRFRemove(uint32_t grfid);
82  void GRFAdd(const GRFConfig *newg);
83  void GRFBug(uint32_t grfid, uint8_t 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);
94 
95  /* Saveload handler for gamelog needs access to internal data. */
96  friend struct GLOGChunkHandler;
97 };
98 
99 extern Gamelog _gamelog;
100 
101 #endif /* GAMELOG_H */
GLOGChunkHandler
Definition: gamelog_sl.cpp:377
GLAT_EMERGENCY
@ GLAT_EMERGENCY
Emergency savegame.
Definition: gamelog.h:23
Gamelog::GRFParameters
void GRFParameters(uint32_t grfid)
Logs change in GRF parameters.
Definition: gamelog.cpp:566
GLAT_LOAD
@ GLAT_LOAD
Game loaded.
Definition: gamelog.h:18
GamelogChangeType
GamelogChangeType
Type of logged change.
Definition: gamelog.h:29
GLCT_GRFBUG
@ GLCT_GRFBUG
GRF bug triggered.
Definition: gamelog.h:39
_gamelog
Gamelog _gamelog
Gamelog instance.
Definition: gamelog.cpp:31
LoggedAction::at
GamelogActionType at
Type of action.
Definition: gamelog_internal.h:144
Gamelog::Reset
void Reset()
Resets and frees all memory allocated - used before loading or starting a new game.
Definition: gamelog.cpp:94
GLCT_OLDVER
@ GLCT_OLDVER
Loaded from savegame without logged data.
Definition: gamelog.h:32
newgrf_config.h
GLCT_GRFADD
@ GLCT_GRFADD
Removed GRF.
Definition: gamelog.h:34
GamelogInternalData
Definition: gamelog_internal.h:148
Gamelog::Revision
void Revision()
Logs a change in game revision.
Definition: gamelog.cpp:378
GRFIdentifier
Basic data to distinguish a GRF.
Definition: newgrf_config.h:83
Gamelog::Emergency
void Emergency()
Logs a emergency savegame.
Definition: gamelog.cpp:352
GLAT_SETTING
@ GLAT_SETTING
Setting changed.
Definition: gamelog.h:21
Gamelog::TestEmergency
bool TestEmergency()
Finds out if current game is a loaded emergency savegame.
Definition: gamelog.cpp:364
Gamelog::Setting
void Setting(const std::string &name, int32_t oldval, int32_t newval)
Logs change in game settings.
Definition: gamelog.cpp:413
GLCT_NONE
@ GLCT_NONE
In savegames, end of list.
Definition: gamelog.h:42
GRFConfig
Information about GRF, used in the game and (part of it) in savegames.
Definition: newgrf_config.h:147
GLCT_GRFCOMPAT
@ GLCT_GRFCOMPAT
Loading compatible GRF.
Definition: gamelog.h:36
GLAT_CHEAT
@ GLAT_CHEAT
Cheat was used.
Definition: gamelog.h:20
GLCT_GRFPARAM
@ GLCT_GRFPARAM
GRF parameter changed.
Definition: gamelog.h:37
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::GRFMove
void GRFMove(uint32_t grfid, int32_t offset)
Logs changing GRF order.
Definition: gamelog.cpp:554
Gamelog::GRFRemove
void GRFRemove(uint32_t grfid)
Logs removal of a GRF.
Definition: gamelog.cpp:517
GLCT_EMERGENCY
@ GLCT_EMERGENCY
Emergency savegame.
Definition: gamelog.h:40
Gamelog::PrintDebug
void PrintDebug(int level)
Prints gamelog to debug output.
Definition: gamelog.cpp:323
Gamelog::GRFUpdate
void GRFUpdate(const GRFConfig *oldg, const GRFConfig *newg)
Compares two NewGRF lists and logs any change.
Definition: gamelog.cpp:606
GLCT_GRFMOVE
@ GLCT_GRFMOVE
GRF order changed.
Definition: gamelog.h:38
GLAT_START
@ GLAT_START
Game created.
Definition: gamelog.h:17
GLCT_END
@ GLCT_END
So we know how many GLCTs are there.
Definition: gamelog.h:41
GLCT_REVISION
@ GLCT_REVISION
Changed game revision string.
Definition: gamelog.h:31
GLCT_GRFREM
@ GLCT_GRFREM
Added GRF.
Definition: gamelog.h:35
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
GLAT_GRF
@ GLAT_GRF
GRF changed.
Definition: gamelog.h:19
Gamelog::StopAction
void StopAction()
Stops logging of any changes.
Definition: gamelog.cpp:74
Gamelog::PrintConsole
void PrintConsole()
Print the gamelog data to the console.
Definition: gamelog.cpp:310
Gamelog::TestMode
void TestMode()
Finds last stored game mode or landscape.
Definition: gamelog.cpp:446
Gamelog::Print
void Print(std::function< void(const std::string &)> proc)
Prints active gamelog.
Definition: gamelog.cpp:147
GLCT_SETTING
@ GLCT_SETTING
Non-networksafe setting value changed.
Definition: gamelog.h:33
Gamelog::GetOverriddenIdentifier
const GRFIdentifier * GetOverriddenIdentifier(const GRFConfig *c)
Try to find the overridden GRF identifier of the given GRF.
Definition: gamelog.cpp:712
Gamelog::GRFBug
void GRFBug(uint32_t grfid, uint8_t bug, uint64_t data)
Logs triggered GRF bug.
Definition: gamelog.cpp:466
Gamelog::Oldver
void Oldver()
Logs loading from savegame without gamelog.
Definition: gamelog.cpp:399
Gamelog::GRFAdd
void GRFAdd(const GRFConfig *newg)
Logs adding of a GRF.
Definition: gamelog.cpp:528
GLAT_GRFBUG
@ GLAT_GRFBUG
GRF bug was triggered.
Definition: gamelog.h:22
Gamelog::TestRevision
void TestRevision()
Finds out if current revision is different than last revision stored in the savegame.
Definition: gamelog.cpp:425
Gamelog::GRFCompatible
void GRFCompatible(const GRFIdentifier *newg)
Logs loading compatible GRF (the same ID, but different MD5 hash)
Definition: gamelog.cpp:542
Gamelog::Mode
void Mode()
Logs a change in game mode (scenario editor or game)
Definition: gamelog.cpp:389
GamelogActionType
GamelogActionType
The actions we log.
Definition: gamelog.h:16
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
GLCT_MODE
@ GLCT_MODE
Scenario editor x Game, different landscape.
Definition: gamelog.h:30
GLAT_NONE
@ GLAT_NONE
No logging active; in savegames, end of list.
Definition: gamelog.h:25
Gamelog::GRFAddList
void GRFAddList(const GRFConfig *newg)
Logs adding of list of GRFs.
Definition: gamelog.cpp:578
Gamelog
Definition: gamelog.h:49
LoggedChange
Definition: gamelog_internal.h:31
GLAT_END
@ GLAT_END
So we know how many GLATs are there.
Definition: gamelog.h:24
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
LoggedAction
Contains information about one logged action that caused at least one logged change.
Definition: gamelog_internal.h:142
LoggedAction::change
std::vector< std::unique_ptr< LoggedChange > > change
Logged changes in this action.
Definition: gamelog_internal.h:143