4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
10 /** @file gamelog_entries.h Declaration of gamelog entries, for use in saveload/gamelog_sl.cpp */
12 #ifndef GAMELOG_ENTRIES_H
13 #define GAMELOG_ENTRIES_H
17 #include "date_func.h"
18 #include "settings_type.h"
19 #include "network/core/config.h"
20 #include "saveload/saveload_data.h"
22 #include "string_func.h"
24 extern const uint16 SAVEGAME_VERSION
; ///< current savegame version
26 /** Gamelog entry base class for entries with tick information. */
27 struct GamelogEntryTimed
: GamelogEntry
{
30 GamelogEntryTimed(GamelogEntryType t
) : GamelogEntry(t
), tick(_tick_counter
) { }
32 void PrependTick(GamelogPrintBuffer
*buf
);
35 /** Gamelog entry for game start */
36 struct GamelogEntryStart
: GamelogEntryTimed
{
37 GamelogEntryStart() : GamelogEntryTimed(GLOG_START
) { }
39 void Print(GamelogPrintBuffer
*buf
);
42 /** Gamelog entry after game start */
43 struct GamelogEntryStarted
: GamelogEntry
{
44 GamelogEntryStarted() : GamelogEntry(GLOG_STARTED
) { }
46 void Print(GamelogPrintBuffer
*buf
);
49 /** Gamelog entry for game load */
50 struct GamelogEntryLoad
: GamelogEntryTimed
{
51 GamelogEntryLoad() : GamelogEntryTimed(GLOG_LOAD
) { }
53 void Print(GamelogPrintBuffer
*buf
);
56 /** Gamelog entry after game load */
57 struct GamelogEntryLoaded
: GamelogEntry
{
58 GamelogEntryLoaded() : GamelogEntry(GLOG_LOADED
) { }
60 void Print(GamelogPrintBuffer
*buf
);
63 /** Gamelog entry for mode switch between scenario editor and game */
64 struct GamelogEntryMode
: GamelogEntry
{
65 byte mode
; ///< new game mode (editor or game)
66 byte landscape
; ///< landscape (temperate, arctic, ...)
68 GamelogEntryMode() : GamelogEntry(GLOG_MODE
), mode(_game_mode
),
69 landscape(_settings_game
.game_creation
.landscape
) { }
71 void Print(GamelogPrintBuffer
*buf
);
74 /** Gamelog entry for game revision string */
75 struct GamelogEntryRevision
: GamelogEntry
{
76 char text
[NETWORK_REVISION_LENGTH
]; ///< revision string,
77 uint32 newgrf
; ///< newgrf version
78 uint16 slver
; ///< savegame version
79 byte modified
; ///< modified flag
81 GamelogEntryRevision() : GamelogEntry(GLOG_REVISION
),
82 newgrf(_openttd_newgrf_version
),
83 slver(SAVEGAME_VERSION
),
84 modified(_openttd_revision_modified
) {
85 memset(this->text
, 0, sizeof(this->text
));
86 strecpy(this->text
, _openttd_revision
, lastof(this->text
));
89 void Print(GamelogPrintBuffer
*buf
);
92 /** Gamelog entry for game revision string (legacy) */
93 struct GamelogEntryLegacyRev
: GamelogEntry
{
94 char text
[NETWORK_REVISION_LENGTH
]; ///< revision string,
95 uint32 newgrf
; ///< openttd newgrf version
96 uint16 slver
; ///< openttd savegame version
97 byte modified
; ///< modified flag
99 /* This entry should only be generated from savegames. */
100 GamelogEntryLegacyRev() : GamelogEntry(GLOG_LEGACYREV
),
101 newgrf(), slver(), modified() { }
103 void Print(GamelogPrintBuffer
*buf
);
106 /** Gamelog entry for savegames without log */
107 struct GamelogEntryOldVer
: GamelogEntry
{
108 uint32 type
; ///< type of savegame
109 uint32 version
; ///< combined ottd or ttdp version
111 GamelogEntryOldVer() : GamelogEntry(GLOG_OLDVER
), type(), version() { }
113 GamelogEntryOldVer(const SavegameTypeVersion
*stv
) :
114 GamelogEntry(GLOG_OLDVER
) {
115 this->type
= stv
->type
;
118 case SGT_TTDP2
: this->version
= stv
->ttdp
.version
; break;
119 case SGT_OTTD
: this->version
= (stv
->ottd
.version
<< 8) || (stv
->ottd
.minor_version
& 0xFF); break;
120 default: this->version
= 0; break;
124 void Print(GamelogPrintBuffer
*buf
);
127 /** Gamelog entry for emergency savegames. */
128 struct GamelogEntryEmergency
: GamelogEntryTimed
{
129 GamelogEntryEmergency() : GamelogEntryTimed(GLOG_EMERGENCY
) { }
131 void Print(GamelogPrintBuffer
*buf
);
134 /** Gamelog entry for settings change */
135 struct GamelogEntrySetting
: GamelogEntryTimed
{
136 char *name
; ///< name of the setting
137 int32 oldval
; ///< old value
138 int32 newval
; ///< new value
140 GamelogEntrySetting() : GamelogEntryTimed(GLOG_SETTING
),
141 name(NULL
), oldval(), newval() { }
143 GamelogEntrySetting(const char *name
, int32 oldval
, int32 newval
) :
144 GamelogEntryTimed(GLOG_SETTING
),
145 name(strdup(name
)), oldval(oldval
), newval(newval
) { }
147 ~GamelogEntrySetting() {
151 void Print(GamelogPrintBuffer
*buf
);
154 /** Gamelog entry for cheating */
155 struct GamelogEntryCheat
: GamelogEntryTimed
{
156 GamelogEntryCheat() : GamelogEntryTimed(GLOG_CHEAT
) { }
158 void Print(GamelogPrintBuffer
*buf
);
161 /** Gamelog entry for GRF config change begin */
162 struct GamelogEntryGRFBegin
: GamelogEntryTimed
{
163 GamelogEntryGRFBegin() : GamelogEntryTimed(GLOG_GRFBEGIN
) { }
165 void Print(GamelogPrintBuffer
*buf
);
168 /** Gamelog entry for GRF config change end */
169 struct GamelogEntryGRFEnd
: GamelogEntry
{
170 GamelogEntryGRFEnd() : GamelogEntry(GLOG_GRFEND
) { }
172 void Print(GamelogPrintBuffer
*buf
);
175 /** Gamelog entry for GRF addition */
176 struct GamelogEntryGRFAdd
: GamelogEntry
{
177 GRFIdentifier grf
; ///< ID and md5sum of added GRF
179 GamelogEntryGRFAdd() : GamelogEntry(GLOG_GRFADD
), grf() { }
181 GamelogEntryGRFAdd(const GRFIdentifier
*ident
) :
182 GamelogEntry(GLOG_GRFADD
), grf(*ident
) { }
184 void Print(GamelogPrintBuffer
*buf
);
187 /** Gamelog entry for GRF removal */
188 struct GamelogEntryGRFRemove
: GamelogEntry
{
189 uint32 grfid
; ///< ID of removed GRF
191 GamelogEntryGRFRemove(uint32 grfid
= 0) :
192 GamelogEntry(GLOG_GRFREM
), grfid(grfid
) { }
194 void Print(GamelogPrintBuffer
*buf
);
197 /** Gamelog entry for compatible GRF load */
198 struct GamelogEntryGRFCompat
: GamelogEntry
{
199 GRFIdentifier grf
; ///< ID and new md5sum of changed GRF
201 GamelogEntryGRFCompat() : GamelogEntry(GLOG_GRFCOMPAT
), grf() { }
203 GamelogEntryGRFCompat(const GRFIdentifier
*ident
) :
204 GamelogEntry(GLOG_GRFCOMPAT
), grf(*ident
) { }
206 void Print(GamelogPrintBuffer
*buf
);
209 /** Gamelog entry for GRF parameter changes */
210 struct GamelogEntryGRFParam
: GamelogEntry
{
211 uint32 grfid
; ///< ID of GRF with changed parameters
213 GamelogEntryGRFParam(uint32 grfid
= 0) :
214 GamelogEntry(GLOG_GRFPARAM
), grfid(grfid
) { }
216 void Print(GamelogPrintBuffer
*buf
);
219 /** Gamelog entry for GRF order change */
220 struct GamelogEntryGRFMove
: GamelogEntry
{
221 uint32 grfid
; ///< ID of moved GRF
222 int32 offset
; ///< offset, positive = move down
224 GamelogEntryGRFMove() : GamelogEntry(GLOG_GRFMOVE
), grfid(), offset() { }
226 GamelogEntryGRFMove(uint32 grfid
, int32 offset
) :
227 GamelogEntry(GLOG_GRFMOVE
), grfid(grfid
), offset(offset
) { }
229 void Print(GamelogPrintBuffer
*buf
);
232 /** Gamelog entry for GRF bugs */
233 struct GamelogEntryGRFBug
: GamelogEntryTimed
{
234 uint64 data
; ///< additional data
235 uint32 grfid
; ///< ID of problematic GRF
236 byte bug
; ///< type of bug, @see enum GRFBugs
238 GamelogEntryGRFBug() : GamelogEntryTimed(GLOG_GRFBUG
),
239 data(), grfid(), bug() { }
241 GamelogEntryGRFBug(uint32 grfid
, byte bug
, uint64 data
) :
242 GamelogEntryTimed(GLOG_GRFBUG
),
243 data(data
), grfid(grfid
), bug(bug
) { }
245 void Print(GamelogPrintBuffer
*buf
);
248 /** Get a new GamelogEntry by type (when loading a savegame) */
249 GamelogEntry
*GamelogEntryByType(uint type
);
251 #endif /* GAMELOG_ENTRIES_H */