OpenTTD Source  20241120-master-g6d3adc6169
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 */
void TestRevision()
Finds out if current revision is different than last revision stored in the savegame.
Definition: gamelog.cpp:425
void GRFBug(uint32_t grfid, uint8_t bug, uint64_t data)
Logs triggered GRF bug.
Definition: gamelog.cpp:466
void Mode()
Logs a change in game mode (scenario editor or game)
Definition: gamelog.cpp:389
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
void PrintDebug(int level)
Prints gamelog to debug output.
Definition: gamelog.cpp:323
void GRFAddList(const GRFConfig *newg)
Logs adding of list of GRFs.
Definition: gamelog.cpp:578
void PrintConsole()
Print the gamelog data to the console.
Definition: gamelog.cpp:310
void GRFCompatible(const GRFIdentifier *newg)
Logs loading compatible GRF (the same ID, but different MD5 hash)
Definition: gamelog.cpp:542
void GRFParameters(uint32_t grfid)
Logs change in GRF parameters.
Definition: gamelog.cpp:566
void Revision()
Logs a change in game revision.
Definition: gamelog.cpp:378
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
void Reset()
Resets and frees all memory allocated - used before loading or starting a new game.
Definition: gamelog.cpp:94
const GRFIdentifier * GetOverriddenIdentifier(const GRFConfig *c)
Try to find the overridden GRF identifier of the given GRF.
Definition: gamelog.cpp:712
void GRFRemove(uint32_t grfid)
Logs removal of a GRF.
Definition: gamelog.cpp:517
void GRFUpdate(const GRFConfig *oldg, const GRFConfig *newg)
Compares two NewGRF lists and logs any change.
Definition: gamelog.cpp:606
void Oldver()
Logs loading from savegame without gamelog.
Definition: gamelog.cpp:399
void Emergency()
Logs a emergency savegame.
Definition: gamelog.cpp:352
bool GRFBugReverse(uint32_t grfid, uint16_t internal_id)
Logs GRF bug - rail vehicle has different length after reversing.
Definition: gamelog.cpp:482
void TestMode()
Finds last stored game mode or landscape.
Definition: gamelog.cpp:446
void StopAction()
Stops logging of any changes.
Definition: gamelog.cpp:74
void Setting(const std::string &name, int32_t oldval, int32_t newval)
Logs change in game settings.
Definition: gamelog.cpp:413
void Print(std::function< void(const std::string &)> proc)
Prints active gamelog.
Definition: gamelog.cpp:147
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
bool TestEmergency()
Finds out if current game is a loaded emergency savegame.
Definition: gamelog.cpp:364
void GRFMove(uint32_t grfid, int32_t offset)
Logs changing GRF order.
Definition: gamelog.cpp:554
void GRFAdd(const GRFConfig *newg)
Logs adding of a GRF.
Definition: gamelog.cpp:528
Gamelog _gamelog
Gamelog instance.
Definition: gamelog.cpp:31
GamelogChangeType
Type of logged change.
Definition: gamelog.h:29
@ GLCT_MODE
Scenario editor x Game, different landscape.
Definition: gamelog.h:30
@ GLCT_OLDVER
Loaded from savegame without logged data.
Definition: gamelog.h:32
@ GLCT_SETTING
Non-networksafe setting value changed.
Definition: gamelog.h:33
@ GLCT_GRFCOMPAT
Loading compatible GRF.
Definition: gamelog.h:36
@ GLCT_GRFADD
Removed GRF.
Definition: gamelog.h:34
@ GLCT_END
So we know how many GLCTs are there.
Definition: gamelog.h:41
@ GLCT_EMERGENCY
Emergency savegame.
Definition: gamelog.h:40
@ GLCT_GRFPARAM
GRF parameter changed.
Definition: gamelog.h:37
@ GLCT_GRFMOVE
GRF order changed.
Definition: gamelog.h:38
@ GLCT_GRFREM
Added GRF.
Definition: gamelog.h:35
@ GLCT_GRFBUG
GRF bug triggered.
Definition: gamelog.h:39
@ GLCT_REVISION
Changed game revision string.
Definition: gamelog.h:31
@ GLCT_NONE
In savegames, end of list.
Definition: gamelog.h:42
GamelogActionType
The actions we log.
Definition: gamelog.h:16
@ GLAT_GRFBUG
GRF bug was triggered.
Definition: gamelog.h:22
@ GLAT_START
Game created.
Definition: gamelog.h:17
@ GLAT_NONE
No logging active; in savegames, end of list.
Definition: gamelog.h:25
@ GLAT_GRF
GRF changed.
Definition: gamelog.h:19
@ GLAT_END
So we know how many GLATs are there.
Definition: gamelog.h:24
@ GLAT_LOAD
Game loaded.
Definition: gamelog.h:18
@ GLAT_CHEAT
Cheat was used.
Definition: gamelog.h:20
@ GLAT_EMERGENCY
Emergency savegame.
Definition: gamelog.h:23
@ GLAT_SETTING
Setting changed.
Definition: gamelog.h:21
Functions to find and configure NewGRFs.
Information about GRF, used in the game and (part of it) in savegames.
Basic data to distinguish a GRF.
Definition: newgrf_config.h:82
Contains information about one logged action that caused at least one logged change.
std::vector< std::unique_ptr< LoggedChange > > change
Logged changes in this action.
GamelogActionType at
Type of action.