OpenTTD Source  20240919-master-gdf0233f4c2
gamelog_internal.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_INTERNAL_H
11 #define GAMELOG_INTERNAL_H
12 
13 #include "gamelog.h"
14 
22 struct GRFPresence {
23  const GRFConfig *gc;
24  bool was_missing;
25 
26  GRFPresence(const GRFConfig *gc) : gc(gc), was_missing(false) {}
27  GRFPresence() = default;
28 };
29 using GrfIDMapping = std::map<uint32_t, GRFPresence>;
30 
31 struct LoggedChange {
32  LoggedChange(GamelogChangeType type = GLCT_NONE) : ct(type) {}
33  virtual ~LoggedChange() {}
34  virtual void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) = 0;
35 
37 };
38 
41  LoggedChangeMode(uint8_t mode, uint8_t landscape) :
43  void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override;
44 
45  uint8_t mode;
46  uint8_t landscape;
47 };
48 
51  LoggedChangeRevision(const std::string &text, uint32_t newgrf, uint16_t slver, uint8_t modified) :
52  LoggedChange(GLCT_REVISION), text(text), newgrf(newgrf), slver(slver), modified(modified) {}
53  void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override;
54 
55  std::string text;
56  uint32_t newgrf;
57  uint16_t slver;
58  uint8_t modified; //< _openttd_revision_modified
59 };
60 
63  LoggedChangeOldVersion(uint32_t type, uint32_t version) :
65  void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override;
66 
67  uint32_t type;
68  uint32_t version;
69 };
70 
73  LoggedChangeGRFAdd(const GRFIdentifier &ident) :
75  void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override;
76 };
77 
80  LoggedChangeGRFRemoved(uint32_t grfid) :
82  void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override;
83 
84  uint32_t grfid;
85 };
86 
91  void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override;
92 };
93 
98  void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override;
99 
100  uint32_t grfid;
101 };
102 
105  LoggedChangeGRFMoved(uint32_t grfid, int32_t offset) :
107  void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override;
108 
109  uint32_t grfid;
110  int32_t offset;
111 };
112 
115  LoggedChangeSettingChanged(const std::string &name, int32_t oldval, int32_t newval) :
117  void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override;
118 
119  std::string name;
120  int32_t oldval;
121  int32_t newval;
122 };
123 
126  LoggedChangeGRFBug(uint64_t data, uint32_t grfid, uint8_t bug) :
128  void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override;
129 
130  uint64_t data;
131  uint32_t grfid;
132  uint8_t bug;
133 };
134 
137  void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override;
138 };
139 
140 
142 struct LoggedAction {
143  std::vector<std::unique_ptr<LoggedChange>> change;
145  uint64_t tick;
146 };
147 
149  std::vector<LoggedAction> action;
150 };
151 
152 #endif /* GAMELOG_INTERNAL_H */
LoggedChangeGRFBug::grfid
uint32_t grfid
ID of problematic GRF.
Definition: gamelog_internal.h:131
LoggedChangeMode
Definition: gamelog_internal.h:39
GamelogChangeType
GamelogChangeType
Type of logged change.
Definition: gamelog.h:29
GLCT_GRFBUG
@ GLCT_GRFBUG
GRF bug triggered.
Definition: gamelog.h:39
LoggedChangeGRFRemoved::grfid
uint32_t grfid
ID of removed GRF.
Definition: gamelog_internal.h:84
LoggedChangeRevision::newgrf
uint32_t newgrf
_openttd_newgrf_version
Definition: gamelog_internal.h:56
GRFPresence::gc
const GRFConfig * gc
GRFConfig, if known.
Definition: gamelog_internal.h:23
LoggedChangeSettingChanged::name
std::string name
name of the setting
Definition: gamelog_internal.h:119
LoggedAction::at
GamelogActionType at
Type of action.
Definition: gamelog_internal.h:144
GLCT_OLDVER
@ GLCT_OLDVER
Loaded from savegame without logged data.
Definition: gamelog.h:32
gamelog.h
GLCT_GRFADD
@ GLCT_GRFADD
Removed GRF.
Definition: gamelog.h:34
GamelogInternalData
Definition: gamelog_internal.h:148
LoggedChangeGRFBug::data
uint64_t data
additional data
Definition: gamelog_internal.h:130
GRFIdentifier
Basic data to distinguish a GRF.
Definition: newgrf_config.h:83
LoggedChangeSettingChanged
Definition: gamelog_internal.h:113
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
LoggedChangeGRFMoved
Definition: gamelog_internal.h:103
GLCT_GRFCOMPAT
@ GLCT_GRFCOMPAT
Loading compatible GRF.
Definition: gamelog.h:36
LoggedChangeRevision
Definition: gamelog_internal.h:49
LoggedChangeSettingChanged::newval
int32_t newval
new value
Definition: gamelog_internal.h:121
LoggedChangeMode::mode
uint8_t mode
new game mode - Editor x Game
Definition: gamelog_internal.h:45
LoggedChangeGRFParameterChanged::grfid
uint32_t grfid
ID of GRF with changed parameters.
Definition: gamelog_internal.h:100
LoggedChangeGRFBug::bug
uint8_t bug
type of bug,
Definition: gamelog_internal.h:132
GLCT_GRFPARAM
@ GLCT_GRFPARAM
GRF parameter changed.
Definition: gamelog.h:37
LoggedChangeGRFBug
Definition: gamelog_internal.h:124
LoggedChangeGRFMoved::grfid
uint32_t grfid
ID of moved GRF.
Definition: gamelog_internal.h:109
GLCT_EMERGENCY
@ GLCT_EMERGENCY
Emergency savegame.
Definition: gamelog.h:40
GRFPresence::was_missing
bool was_missing
Grf was missing during some gameload in the past.
Definition: gamelog_internal.h:24
GLCT_GRFMOVE
@ GLCT_GRFMOVE
GRF order changed.
Definition: gamelog.h:38
GLCT_REVISION
@ GLCT_REVISION
Changed game revision string.
Definition: gamelog.h:31
LoggedChangeGRFChanged
Definition: gamelog_internal.h:87
GLCT_GRFREM
@ GLCT_GRFREM
Added GRF.
Definition: gamelog.h:35
LoggedChangeOldVersion
Definition: gamelog_internal.h:61
LoggedChangeGRFAdd
Definition: gamelog_internal.h:71
GLCT_SETTING
@ GLCT_SETTING
Non-networksafe setting value changed.
Definition: gamelog.h:33
LoggedChangeGRFRemoved
Definition: gamelog_internal.h:78
LoggedChangeSettingChanged::oldval
int32_t oldval
old value
Definition: gamelog_internal.h:120
LoggedChangeGRFParameterChanged
Definition: gamelog_internal.h:94
LoggedChangeOldVersion::version
uint32_t version
major and minor version OR ttdp version
Definition: gamelog_internal.h:68
GamelogActionType
GamelogActionType
The actions we log.
Definition: gamelog.h:16
GLCT_MODE
@ GLCT_MODE
Scenario editor x Game, different landscape.
Definition: gamelog.h:30
GRFPresence
Information about the presence of a Grf at a certain point during gamelog history Note about missing ...
Definition: gamelog_internal.h:22
LoggedChangeRevision::text
std::string text
revision string, _openttd_revision
Definition: gamelog_internal.h:55
LoggedChange
Definition: gamelog_internal.h:31
LoggedChangeEmergencySave
Definition: gamelog_internal.h:135
LoggedChangeOldVersion::type
uint32_t type
type of savegame,
Definition: gamelog_internal.h:67
LoggedChangeRevision::slver
uint16_t slver
_sl_version
Definition: gamelog_internal.h:57
LoggedAction
Contains information about one logged action that caused at least one logged change.
Definition: gamelog_internal.h:142
LoggedChangeMode::landscape
uint8_t landscape
landscape (temperate, arctic, ...)
Definition: gamelog_internal.h:46
LoggedChangeGRFMoved::offset
int32_t offset
offset, positive = move down
Definition: gamelog_internal.h:110
LoggedAction::tick
uint64_t tick
Tick when it happened.
Definition: gamelog_internal.h:145
LoggedAction::change
std::vector< std::unique_ptr< LoggedChange > > change
Logged changes in this action.
Definition: gamelog_internal.h:143