OpenTTD Source 20260208-master-g43af8e94d0
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
9
10#ifndef GAMELOG_INTERNAL_H
11#define GAMELOG_INTERNAL_H
12
13#include "gamelog.h"
14#include "landscape_type.h"
15
23struct 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
32struct LoggedChange {
33 LoggedChange(GamelogChangeType type = GLCT_NONE) : ct(type) {}
34 virtual ~LoggedChange() = default;
35
42 virtual void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) = 0;
43
45};
46
47struct LoggedChangeMode : LoggedChange {
48 LoggedChangeMode() : LoggedChange(GLCT_MODE) {}
49 LoggedChangeMode(uint8_t mode, LandscapeType landscape) :
50 LoggedChange(GLCT_MODE), mode(mode), landscape(landscape) {}
51 void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override;
52
53 uint8_t mode = 0;
55};
56
57struct LoggedChangeRevision : LoggedChange {
58 LoggedChangeRevision() : LoggedChange(GLCT_REVISION) {}
59 LoggedChangeRevision(const std::string &text, uint32_t newgrf, uint16_t slver, uint8_t modified) :
61 void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override;
62
63 std::string text{};
64 uint32_t newgrf = 0;
65 uint16_t slver = 0;
66 uint8_t modified = 0;
67};
68
69struct LoggedChangeOldVersion : LoggedChange {
70 LoggedChangeOldVersion() : LoggedChange(GLCT_OLDVER) {}
71 LoggedChangeOldVersion(uint32_t type, uint32_t version) :
72 LoggedChange(GLCT_OLDVER), type(type), version(version) {}
73 void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override;
74
75 uint32_t type = 0;
76 uint32_t version = 0;
77};
78
79struct LoggedChangeGRFAdd : LoggedChange, GRFIdentifier {
80 LoggedChangeGRFAdd() : LoggedChange(GLCT_GRFADD) {}
81 LoggedChangeGRFAdd(const GRFIdentifier &ident) :
82 LoggedChange(GLCT_GRFADD), GRFIdentifier(ident) {}
83 void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override;
84};
85
86struct LoggedChangeGRFRemoved : LoggedChange {
87 LoggedChangeGRFRemoved() : LoggedChange(GLCT_GRFREM) {}
88 LoggedChangeGRFRemoved(uint32_t grfid) :
89 LoggedChange(GLCT_GRFREM), grfid(grfid) {}
90 void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override;
91
92 uint32_t grfid = 0;
93};
94
95struct LoggedChangeGRFChanged : LoggedChange, GRFIdentifier {
96 LoggedChangeGRFChanged() : LoggedChange(GLCT_GRFCOMPAT) {}
97 LoggedChangeGRFChanged(const GRFIdentifier &ident) :
98 LoggedChange(GLCT_GRFCOMPAT), GRFIdentifier(ident) {}
99 void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override;
100};
101
102struct LoggedChangeGRFParameterChanged : LoggedChange {
103 LoggedChangeGRFParameterChanged() : LoggedChange(GLCT_GRFPARAM) {}
104 LoggedChangeGRFParameterChanged(uint32_t grfid) :
105 LoggedChange(GLCT_GRFPARAM), grfid(grfid) {}
106 void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override;
107
108 uint32_t grfid = 0;
109};
110
111struct LoggedChangeGRFMoved : LoggedChange {
112 LoggedChangeGRFMoved() : LoggedChange(GLCT_GRFMOVE) {}
113 LoggedChangeGRFMoved(uint32_t grfid, int32_t offset) :
114 LoggedChange(GLCT_GRFMOVE), grfid(grfid), offset(offset) {}
115 void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override;
116
117 uint32_t grfid = 0;
118 int32_t offset = 0;
119};
120
121struct LoggedChangeSettingChanged : LoggedChange {
122 LoggedChangeSettingChanged() : LoggedChange(GLCT_SETTING) {}
123 LoggedChangeSettingChanged(const std::string &name, int32_t oldval, int32_t newval) :
124 LoggedChange(GLCT_SETTING), name(name), oldval(oldval), newval(newval) {}
125 void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override;
126
127 std::string name{};
128 int32_t oldval = 0;
129 int32_t newval = 0;
130};
131
132struct LoggedChangeGRFBug : LoggedChange {
133 LoggedChangeGRFBug() : LoggedChange(GLCT_GRFBUG) {}
134 LoggedChangeGRFBug(uint64_t data, uint32_t grfid, GRFBug bug) :
135 LoggedChange(GLCT_GRFBUG), data(data), grfid(grfid), bug(bug) {}
136 void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override;
137
138 uint64_t data = 0;
139 uint32_t grfid = 0;
141};
142
143struct LoggedChangeEmergencySave : LoggedChange {
144 LoggedChangeEmergencySave() : LoggedChange(GLCT_EMERGENCY) {}
145 void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override;
146};
147
148
151 std::vector<std::unique_ptr<LoggedChange>> change;
153 uint64_t tick = 0;
154};
155
157 std::vector<LoggedAction> action;
158};
159
160#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
Types related to the landscape.
LandscapeType
Landscape types.
GRFBug
Encountered GRF bugs.
Information about GRF, used in the game and (part of it) in savegames.
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.
void FormatTo(std::back_insert_iterator< std::string > &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override
Format the content of this change into the given output.
Definition gamelog.cpp:302
void FormatTo(std::back_insert_iterator< std::string > &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override
Format the content of this change into the given output.
Definition gamelog.cpp:229
GRFBug bug
type of bug,
void FormatTo(std::back_insert_iterator< std::string > &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override
Format the content of this change into the given output.
Definition gamelog.cpp:291
uint64_t data
additional data
uint32_t grfid
ID of problematic GRF.
void FormatTo(std::back_insert_iterator< std::string > &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override
Format the content of this change into the given output.
Definition gamelog.cpp:262
void FormatTo(std::back_insert_iterator< std::string > &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override
Format the content of this change into the given output.
Definition gamelog.cpp:281
uint32_t grfid
ID of moved GRF.
int32_t offset
offset, positive = move down
void FormatTo(std::back_insert_iterator< std::string > &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override
Format the content of this change into the given output.
Definition gamelog.cpp:272
uint32_t grfid
ID of GRF with changed parameters.
uint32_t grfid
ID of removed GRF.
void FormatTo(std::back_insert_iterator< std::string > &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override
Format the content of this change into the given output.
Definition gamelog.cpp:240
LandscapeType landscape
landscape (temperate, arctic, ...)
void FormatTo(std::back_insert_iterator< std::string > &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override
Format the content of this change into the given output.
Definition gamelog.cpp:170
uint8_t mode
new game mode - Editor x Game
void FormatTo(std::back_insert_iterator< std::string > &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override
Format the content of this change into the given output.
Definition gamelog.cpp:191
uint32_t type
type of savegame,
uint32_t version
major and minor version OR ttdp version
std::string text
revision string, _openttd_revision
void FormatTo(std::back_insert_iterator< std::string > &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override
Format the content of this change into the given output.
Definition gamelog.cpp:176
uint16_t slver
_sl_version
uint32_t newgrf
_openttd_newgrf_version
uint8_t modified
_openttd_revision_modified
std::string name
name of the setting
void FormatTo(std::back_insert_iterator< std::string > &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override
Format the content of this change into the given output.
Definition gamelog.cpp:223
virtual void FormatTo(std::back_insert_iterator< std::string > &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type)=0
Format the content of this change into the given output.