OpenTTD Source: src/gamelog_internal.h Source File

OpenTTD Source 14.0-beta1

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
36 GamelogChangeType ct;
37 };
38
39 struct LoggedChangeMode : LoggedChange {
40 LoggedChangeMode() : LoggedChange(GLCT_MODE) {}
41 LoggedChangeMode(byte mode, byte landscape) :
42 LoggedChange(GLCT_MODE), mode(mode), landscape(landscape) {}
43 void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override;
44
45 byte mode;
46 byte landscape;
47 };
48
49 struct LoggedChangeRevision : LoggedChange {
50 LoggedChangeRevision() : LoggedChange(GLCT_REVISION) {}
51 LoggedChangeRevision(const std::string &text, uint32_t newgrf, uint16_t slver, byte 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 byte modified; //< _openttd_revision_modified
59 };
60
61 struct LoggedChangeOldVersion : LoggedChange {
62 LoggedChangeOldVersion() : LoggedChange(GLCT_OLDVER) {}
63 LoggedChangeOldVersion(uint32_t type, uint32_t version) :
64 LoggedChange(GLCT_OLDVER), type(type), version(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
71 struct LoggedChangeGRFAdd : LoggedChange, GRFIdentifier {
72 LoggedChangeGRFAdd() : LoggedChange(GLCT_GRFADD) {}
73 LoggedChangeGRFAdd(const GRFIdentifier &ident) :
74 LoggedChange(GLCT_GRFADD), GRFIdentifier(ident) {}
75 void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override;
76 };
77
78 struct LoggedChangeGRFRemoved : LoggedChange {
79 LoggedChangeGRFRemoved() : LoggedChange(GLCT_GRFREM) {}
80 LoggedChangeGRFRemoved(uint32_t grfid) :
81 LoggedChange(GLCT_GRFREM), grfid(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
87 struct LoggedChangeGRFChanged : LoggedChange, GRFIdentifier {
88 LoggedChangeGRFChanged() : LoggedChange(GLCT_GRFCOMPAT) {}
89 LoggedChangeGRFChanged(const GRFIdentifier &ident) :
90 LoggedChange(GLCT_GRFCOMPAT), GRFIdentifier(ident) {}
91 void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override;
92 };
93
94 struct LoggedChangeGRFParameterChanged : LoggedChange {
95 LoggedChangeGRFParameterChanged() : LoggedChange(GLCT_GRFPARAM) {}
96 LoggedChangeGRFParameterChanged(uint32_t grfid) :
97 LoggedChange(GLCT_GRFPARAM), grfid(grfid) {}
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
103 struct LoggedChangeGRFMoved : LoggedChange {
104 LoggedChangeGRFMoved() : LoggedChange(GLCT_GRFMOVE) {}
105 LoggedChangeGRFMoved(uint32_t grfid, int32_t offset) :
106 LoggedChange(GLCT_GRFMOVE), grfid(grfid), offset(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
113 struct LoggedChangeSettingChanged : LoggedChange {
114 LoggedChangeSettingChanged() : LoggedChange(GLCT_SETTING) {}
115 LoggedChangeSettingChanged(const std::string &name, int32_t oldval, int32_t newval) :
116 LoggedChange(GLCT_SETTING), name(name), oldval(oldval), newval(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
124 struct LoggedChangeGRFBug : LoggedChange {
125 LoggedChangeGRFBug() : LoggedChange(GLCT_GRFBUG) {}
126 LoggedChangeGRFBug(uint64_t data, uint32_t grfid, byte bug) :
127 LoggedChange(GLCT_GRFBUG), data(data), grfid(grfid), bug(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 byte bug;
133 };
134
135 struct LoggedChangeEmergencySave : LoggedChange {
136 LoggedChangeEmergencySave() : LoggedChange(GLCT_EMERGENCY) {}
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;
144 GamelogActionType at;
145 uint64_t tick;
146 };
147
148 struct GamelogInternalData {
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
LoggedChangeGRFBug::bug
byte bug
type of bug,
Definition: gamelog_internal.h:132
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
LoggedChangeMode::mode
byte mode
new game mode - Editor x Game
Definition: gamelog_internal.h:45
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
LoggedChangeMode::landscape
byte landscape
landscape (temperate, arctic, ...)
Definition: gamelog_internal.h:46
LoggedChangeSettingChanged::newval
int32_t newval
new value
Definition: gamelog_internal.h:121
LoggedChangeGRFParameterChanged::grfid
uint32_t grfid
ID of GRF with changed parameters.
Definition: gamelog_internal.h:100
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
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