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/>.
8 /** @file gamelog_internal.h Declaration shared among gamelog.cpp and saveload/gamelog_sl.cpp */
10 #ifndef GAMELOG_INTERNAL_H
11 #define GAMELOG_INTERNAL_H
16 * Information about the presence of a Grf at a certain point during gamelog history
17 * Note about missing Grfs:
18 * Changes to missing Grfs are not logged including manual removal of the Grf.
19 * So if the gamelog tells a Grf is missing we do not know whether it was readded or completely removed
20 * at some later point.
23 const GRFConfig
*gc
; ///< GRFConfig, if known
24 bool was_missing
; ///< Grf was missing during some gameload in the past
26 GRFPresence(const GRFConfig
*gc
) : gc(gc
), was_missing(false) {}
27 GRFPresence() = default;
29 using GrfIDMapping
= std::map
<uint32_t, GRFPresence
>;
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;
39 struct LoggedChangeMode
: LoggedChange
{
40 LoggedChangeMode() : LoggedChange(GLCT_MODE
) {}
41 LoggedChangeMode(uint8_t mode
, uint8_t 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
;
45 uint8_t mode
; ///< new game mode - Editor x Game
46 uint8_t landscape
; ///< landscape (temperate, arctic, ...)
49 struct LoggedChangeRevision
: LoggedChange
{
50 LoggedChangeRevision() : LoggedChange(GLCT_REVISION
) {}
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
;
55 std::string text
; ///< revision string, _openttd_revision
56 uint32_t newgrf
; ///< _openttd_newgrf_version
57 uint16_t slver
; ///< _sl_version
58 uint8_t modified
; //< _openttd_revision_modified
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
;
67 uint32_t type
; ///< type of savegame, @see SavegameType
68 uint32_t version
; ///< major and minor version OR ttdp version
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
;
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
;
84 uint32_t grfid
; ///< ID of removed GRF
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
;
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
;
100 uint32_t grfid
; ///< ID of GRF with changed parameters
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
;
109 uint32_t grfid
; ///< ID of moved GRF
110 int32_t offset
; ///< offset, positive = move down
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
;
119 std::string name
; ///< name of the setting
120 int32_t oldval
; ///< old value
121 int32_t newval
; ///< new value
124 struct LoggedChangeGRFBug
: LoggedChange
{
125 LoggedChangeGRFBug() : LoggedChange(GLCT_GRFBUG
) {}
126 LoggedChangeGRFBug(uint64_t data
, uint32_t grfid
, uint8_t 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
;
130 uint64_t data
; ///< additional data
131 uint32_t grfid
; ///< ID of problematic GRF
132 uint8_t bug
; ///< type of bug, @see enum GRFBugs
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
;
141 /** Contains information about one logged action that caused at least one logged change */
142 struct LoggedAction
{
143 std::vector
<std::unique_ptr
<LoggedChange
>> change
; ///< Logged changes in this action
144 GamelogActionType at
; ///< Type of action
145 uint64_t tick
; ///< Tick when it happened
148 struct GamelogInternalData
{
149 std::vector
<LoggedAction
> action
;
152 #endif /* GAMELOG_INTERNAL_H */