OpenTTD Source 20260311-master-g511d3794ce
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) {}
35 virtual ~LoggedChange() = default;
36
43 virtual void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) = 0;
44
46};
47
48struct LoggedChangeMode : LoggedChange {
49 LoggedChangeMode() : LoggedChange(GLCT_MODE) {}
50 LoggedChangeMode(uint8_t mode, LandscapeType landscape) :
51 LoggedChange(GLCT_MODE), mode(mode), landscape(landscape) {}
52 void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override;
53
54 uint8_t mode = 0;
56};
57
58struct LoggedChangeRevision : LoggedChange {
59 LoggedChangeRevision() : LoggedChange(GLCT_REVISION) {}
60 LoggedChangeRevision(const std::string &text, uint32_t newgrf, uint16_t slver, uint8_t modified) :
62 void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override;
63
64 std::string text{};
65 uint32_t newgrf = 0;
66 uint16_t slver = 0;
67 uint8_t modified = 0;
68};
69
70struct LoggedChangeOldVersion : LoggedChange {
71 LoggedChangeOldVersion() : LoggedChange(GLCT_OLDVER) {}
72 LoggedChangeOldVersion(uint32_t type, uint32_t version) :
73 LoggedChange(GLCT_OLDVER), type(type), version(version) {}
74 void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override;
75
76 uint32_t type = 0;
77 uint32_t version = 0;
78};
79
80struct LoggedChangeGRFAdd : LoggedChange, GRFIdentifier {
81 LoggedChangeGRFAdd() : LoggedChange(GLCT_GRFADD) {}
82 LoggedChangeGRFAdd(const GRFIdentifier &ident) :
83 LoggedChange(GLCT_GRFADD), GRFIdentifier(ident) {}
84 void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override;
85};
86
87struct LoggedChangeGRFRemoved : LoggedChange {
88 LoggedChangeGRFRemoved() : LoggedChange(GLCT_GRFREM) {}
89 LoggedChangeGRFRemoved(uint32_t grfid) :
90 LoggedChange(GLCT_GRFREM), grfid(grfid) {}
91 void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override;
92
93 uint32_t grfid = 0;
94};
95
96struct LoggedChangeGRFChanged : LoggedChange, GRFIdentifier {
97 LoggedChangeGRFChanged() : LoggedChange(GLCT_GRFCOMPAT) {}
98 LoggedChangeGRFChanged(const GRFIdentifier &ident) :
99 LoggedChange(GLCT_GRFCOMPAT), GRFIdentifier(ident) {}
100 void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override;
101};
102
103struct LoggedChangeGRFParameterChanged : LoggedChange {
104 LoggedChangeGRFParameterChanged() : LoggedChange(GLCT_GRFPARAM) {}
105 LoggedChangeGRFParameterChanged(uint32_t grfid) :
106 LoggedChange(GLCT_GRFPARAM), grfid(grfid) {}
107 void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override;
108
109 uint32_t grfid = 0;
110};
111
112struct LoggedChangeGRFMoved : LoggedChange {
113 LoggedChangeGRFMoved() : LoggedChange(GLCT_GRFMOVE) {}
114 LoggedChangeGRFMoved(uint32_t grfid, int32_t offset) :
115 LoggedChange(GLCT_GRFMOVE), grfid(grfid), offset(offset) {}
116 void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override;
117
118 uint32_t grfid = 0;
119 int32_t offset = 0;
120};
121
122struct LoggedChangeSettingChanged : LoggedChange {
123 LoggedChangeSettingChanged() : LoggedChange(GLCT_SETTING) {}
124 LoggedChangeSettingChanged(const std::string &name, int32_t oldval, int32_t newval) :
125 LoggedChange(GLCT_SETTING), name(name), oldval(oldval), newval(newval) {}
126 void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override;
127
128 std::string name{};
129 int32_t oldval = 0;
130 int32_t newval = 0;
131};
132
133struct LoggedChangeGRFBug : LoggedChange {
134 LoggedChangeGRFBug() : LoggedChange(GLCT_GRFBUG) {}
135 LoggedChangeGRFBug(uint64_t data, uint32_t grfid, GRFBug bug) :
136 LoggedChange(GLCT_GRFBUG), data(data), grfid(grfid), bug(bug) {}
137 void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override;
138
139 uint64_t data = 0;
140 uint32_t grfid = 0;
142};
143
144struct LoggedChangeEmergencySave : LoggedChange {
145 LoggedChangeEmergencySave() : LoggedChange(GLCT_EMERGENCY) {}
146 void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override;
147};
148
149
152 std::vector<std::unique_ptr<LoggedChange>> change;
154 uint64_t tick = 0;
155};
156
158 std::vector<LoggedAction> action;
159};
160
161#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:304
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:231
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:293
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:264
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:283
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:274
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:242
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:172
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:193
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:178
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:225
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.
virtual ~LoggedChange()=default
Ensure the destructor of the sub classes are called as well.