OpenTTD Source: src/gamelog_internal.h Source File

OpenTTD Source 15.3

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