OpenTTD Source  20241121-master-g67a0fccfad
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 */
Functions to be called to log fundamental changes to the game.
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_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
Information about GRF, used in the game and (part of it) in savegames.
Basic data to distinguish a GRF.
Definition: newgrf_config.h:82
Information about the presence of a Grf at a certain point during gamelog history Note about missing ...
bool was_missing
Grf was missing during some gameload in the past.
const GRFConfig * gc
GRFConfig, if known.
Contains information about one logged action that caused at least one logged change.
uint64_t tick
Tick when it happened.
std::vector< std::unique_ptr< LoggedChange > > change
Logged changes in this action.
GamelogActionType at
Type of action.
uint8_t bug
type of bug,
uint64_t data
additional data
uint32_t grfid
ID of problematic GRF.
uint32_t grfid
ID of moved GRF.
int32_t offset
offset, positive = move down
uint32_t grfid
ID of GRF with changed parameters.
uint32_t grfid
ID of removed GRF.
uint8_t landscape
landscape (temperate, arctic, ...)
uint8_t mode
new game mode - Editor x Game
uint32_t type
type of savegame,
uint32_t version
major and minor version OR ttdp version
std::string text
revision string, _openttd_revision
uint16_t slver
_sl_version
uint32_t newgrf
_openttd_newgrf_version
std::string name
name of the setting