OpenTTD Source 20261112-master-gbcbec5e63f
gamelog.cpp
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#include "stdafx.h"
11#include "saveload/saveload.h"
12#include "string_func.h"
13#include "settings_type.h"
14#include "gamelog_internal.h"
15#include "console_func.h"
16#include "debug.h"
18#include "rev.h"
19
20#include "safeguards.h"
21
23
25
26extern uint32_t _ttdp_version;
28extern uint8_t _sl_minor_version;
29
31
32Gamelog::Gamelog()
33{
34 this->data = std::make_unique<GamelogInternalData>();
35 this->action_type = GamelogActionType::None;
36 this->current_action = nullptr;
37}
38
40Gamelog::~Gamelog() = default;
41
46static std::string GetGamelogRevisionString()
47{
48 if (IsReleasedVersion()) {
49 return _openttd_revision;
50 }
51
52 /* Prefix character indication revision status */
53 assert(_openttd_revision_modified < 3);
54 return fmt::format("{}{}",
55 "gum"[_openttd_revision_modified], // g = "git", u = "unknown", m = "modified"
56 _openttd_revision_hash);
57}
58
65{
66 assert(this->action_type == GamelogActionType::None); // do not allow starting new action without stopping the previous first
67 this->action_type = at;
68}
69
74{
75 assert(this->action_type != GamelogActionType::None); // nobody should try to stop if there is no action in progress
76
77 bool print = this->current_action != nullptr;
78
79 this->current_action = nullptr;
80 this->action_type = GamelogActionType::None;
81
82 if (print) this->PrintDebug(Severity::Debug1);
83}
84
85void Gamelog::StopAnyAction()
86{
87 if (this->action_type != GamelogActionType::None) this->StopAction();
88}
89
94{
95 assert(this->action_type == GamelogActionType::None);
96 this->data->action.clear();
97 this->current_action = nullptr;
98}
99
107static void AddGrfInfo(std::back_insert_iterator<std::string> &output_iterator, GrfID grfid, const MD5Hash *md5sum, const GRFConfig *gc)
108{
109 if (md5sum != nullptr) {
110 fmt::format_to(output_iterator, "GRF ID {}, checksum {}", FormatArrayAsHex(grfid), FormatArrayAsHex(*md5sum));
111 } else {
112 fmt::format_to(output_iterator, "GRF ID {}", FormatArrayAsHex(grfid));
113 }
114
115 if (gc != nullptr) {
116 fmt::format_to(output_iterator, ", filename: {} (md5sum matches)", gc->filename);
117 } else {
119 if (gc != nullptr) {
120 fmt::format_to(output_iterator, ", filename: {} (matches GRFID only)", gc->filename);
121 } else {
122 fmt::format_to(output_iterator, ", unknown GRF");
123 }
124 }
125}
126
127
130 "new game started",
131 "game loaded",
132 "GRF config changed",
133 "cheat was used",
134 "settings changed",
135 "GRF bug triggered",
136 "emergency savegame",
137};
138
143void Gamelog::Print(std::function<void(const std::string &)> proc)
144{
145 GrfIDMapping grf_names;
146
147 proc("---- gamelog start ----");
148
149 for (const LoggedAction &la : this->data->action) {
150 assert(la.at < GamelogActionType::End);
151
152 proc(fmt::format("Tick {}: {}", la.tick, la_text[la.at]));
153
154 for (auto &lc : la.change) {
155 std::string message;
156 auto output_iterator = std::back_inserter(message);
157 lc->FormatTo(output_iterator, grf_names, la.at);
158
159 proc(message);
160 }
161 }
162
163 proc("---- gamelog end ----");
164}
165
166
167/* virtual */ void LoggedChangeMode::FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &, GamelogActionType)
168{
169 /* Changing landscape, or going from scenario editor to game or back. */
170 fmt::format_to(output_iterator, "New game mode: {} landscape: {}", this->mode, this->landscape);
171}
172
173/* virtual */ void LoggedChangeRevision::FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &, GamelogActionType)
174{
175 /* The game was loaded in a different version than before. */
176 fmt::format_to(output_iterator, "Revision text changed to {}, savegame version {}, ",
177 this->text, this->slver);
178
179 switch (this->modified) {
180 case 0: fmt::format_to(output_iterator, "not "); break;
181 case 1: fmt::format_to(output_iterator, "maybe "); break;
182 default: break;
183 }
184
185 fmt::format_to(output_iterator, "modified, _openttd_newgrf_version = 0x{:08x}", this->newgrf);
186}
187
188/* virtual */ void LoggedChangeOldVersion::FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &, GamelogActionType)
189{
190 /* The game was loaded from before 0.7.0-beta1. */
191 fmt::format_to(output_iterator, "Conversion from ");
192 switch (this->type) {
193 default: NOT_REACHED();
195 fmt::format_to(output_iterator, "OTTD savegame without gamelog: version {}, {}",
196 GB(this->version, 8, 16), GB(this->version, 0, 8));
197 break;
198
200 fmt::format_to(output_iterator, "TTO savegame");
201 break;
202
204 fmt::format_to(output_iterator, "TTD savegame");
205 break;
206
209 fmt::format_to(output_iterator, "TTDP savegame, {} format",
210 this->type == SavegameType::TTDP1 ? "old" : "new");
211 if (this->version != 0) {
212 fmt::format_to(output_iterator, ", TTDP version {}.{}.{}.{}",
213 GB(this->version, 24, 8), GB(this->version, 20, 4),
214 GB(this->version, 16, 4), GB(this->version, 0, 16));
215 }
216 break;
217 }
218}
219
220/* virtual */ void LoggedChangeSettingChanged::FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &, GamelogActionType)
221{
222 /* A setting with the SettingFlag::NoNetwork flag got changed; these settings usually affect NewGRFs, such as road side or wagon speed limits. */
223 fmt::format_to(output_iterator, "Setting changed: {} : {} -> {}", this->name, this->oldval, this->newval);
224}
225
226/* virtual */ void LoggedChangeGRFAdd::FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType)
227{
228 /* A NewGRF got added to the game, either at the start of the game (never an issue), or later on when it could be an issue. */
229 const GRFConfig *gc = FindGRFConfig(this->grfid, FindGRFConfigMode::Exact, &this->md5sum);
230 fmt::format_to(output_iterator, "Added NewGRF: ");
231 AddGrfInfo(output_iterator, this->grfid, &this->md5sum, gc);
232 auto gm = grf_names.find(this->grfid);
233 if (gm != grf_names.end() && !gm->second.was_missing) fmt::format_to(output_iterator, ". Gamelog inconsistency: GrfID was already added!");
234 grf_names[this->grfid] = gc;
235}
236
237/* virtual */ void LoggedChangeGRFRemoved::FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type)
238{
239 /* A NewGRF got removed from the game, either manually or by it missing when loading the game. */
240 auto gm = grf_names.find(this->grfid);
241 if (action_type == GamelogActionType::Load) {
242 fmt::format_to(output_iterator, "Missing NewGRF: ");
243 } else {
244 fmt::format_to(output_iterator, "Removed NewGRF: ");
245 }
246 AddGrfInfo(output_iterator, this->grfid, nullptr, gm != grf_names.end() ? gm->second.gc : nullptr);
247 if (gm == grf_names.end()) {
248 fmt::format_to(output_iterator, ". Gamelog inconsistency: GrfID was never added!");
249 } else {
250 if (action_type == GamelogActionType::Load) {
251 /* Missing grfs on load are not removed from the configuration */
252 gm->second.was_missing = true;
253 } else {
254 grf_names.erase(gm);
255 }
256 }
257}
258
259/* virtual */ void LoggedChangeGRFChanged::FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType)
260{
261 /* Another version of the same NewGRF got loaded. */
262 const GRFConfig *gc = FindGRFConfig(this->grfid, FindGRFConfigMode::Exact, &this->md5sum);
263 fmt::format_to(output_iterator, "Compatible NewGRF loaded: ");
264 AddGrfInfo(output_iterator, this->grfid, &this->md5sum, gc);
265 if (grf_names.count(this->grfid) == 0) fmt::format_to(output_iterator, ". Gamelog inconsistency: GrfID was never added!");
266 grf_names[this->grfid] = gc;
267}
268
269/* virtual */ void LoggedChangeGRFParameterChanged::FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType)
270{
271 /* A parameter of a NewGRF got changed after the game was started. */
272 auto gm = grf_names.find(this->grfid);
273 fmt::format_to(output_iterator, "GRF parameter changed: ");
274 AddGrfInfo(output_iterator, this->grfid, nullptr, gm != grf_names.end() ? gm->second.gc : nullptr);
275 if (gm == grf_names.end()) fmt::format_to(output_iterator, ". Gamelog inconsistency: GrfID was never added!");
276}
277
278/* virtual */ void LoggedChangeGRFMoved::FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType)
279{
280 /* The order of NewGRFs got changed, which might cause some other NewGRFs to behave differently. */
281 auto gm = grf_names.find(this->grfid);
282 fmt::format_to(output_iterator, "GRF order changed: {} moved {} places {}",
283 FormatArrayAsHex(this->grfid), abs(this->offset), this->offset >= 0 ? "down" : "up" );
284 AddGrfInfo(output_iterator, this->grfid, nullptr, gm != grf_names.end() ? gm->second.gc : nullptr);
285 if (gm == grf_names.end()) fmt::format_to(output_iterator, ". Gamelog inconsistency: GrfID was never added!");
286}
287
288/* virtual */ void LoggedChangeGRFBug::FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType)
289{
290 /* A specific bug in a NewGRF, that could cause wide spread problems, has been noted during the execution of the game. */
291 auto gm = grf_names.find(this->grfid);
292 assert(this->bug == GRFBug::VehLength);
293
294 fmt::format_to(output_iterator, "Rail vehicle changes length outside a depot: GRF ID {}, internal ID 0x{:X}", FormatArrayAsHex(this->grfid), this->data);
295 AddGrfInfo(output_iterator, this->grfid, nullptr, gm != grf_names.end() ? gm->second.gc : nullptr);
296 if (gm == grf_names.end()) fmt::format_to(output_iterator, ". Gamelog inconsistency: GrfID was never added!");
297}
298
299/* virtual */ void LoggedChangeEmergencySave::FormatTo(std::back_insert_iterator<std::string> &, GrfIDMapping &, GamelogActionType)
300{
301 /* At one point the savegame was made during the handling of a game crash.
302 * The generic code already mentioned the emergency savegame, and there is no extra information to log. */
303}
304
307{
308 this->Print([](const std::string &s) {
310 });
311}
312
320{
321 this->Print([severity](const std::string &s) {
322 Debug(Facility::Gamelog, severity, "{}", s);
323 });
324}
325
326
331void Gamelog::Change(std::unique_ptr<LoggedChange> &&change)
332{
333 if (this->current_action == nullptr) {
334 if (this->action_type == GamelogActionType::None) return;
335
336 this->current_action = &this->data->action.emplace_back();
337 this->current_action->at = this->action_type;
338 this->current_action->tick = TimerGameTick::counter;
339 }
340
341 this->current_action->change.push_back(std::move(change));
342}
343
344
349{
350 /* Terminate any active action */
351 if (this->action_type != GamelogActionType::None) this->StopAction();
353 this->Change(std::make_unique<LoggedChangeEmergencySave>());
354 this->StopAction();
355}
356
362{
363 for (const LoggedAction &la : this->data->action) {
364 for (const auto &lc : la.change) {
365 if (lc->ct == GamelogChangeType::Emergency) return true;
366 }
367 }
368
369 return false;
370}
371
376{
377 assert(this->action_type == GamelogActionType::Start || this->action_type == GamelogActionType::Load);
378
379 this->Change(std::make_unique<LoggedChangeRevision>(
380 GetGamelogRevisionString(), _openttd_newgrf_version, to_underlying(SAVEGAME_VERSION), _openttd_revision_modified));
381}
382
387{
388 assert(this->action_type == GamelogActionType::Start || this->action_type == GamelogActionType::Load || this->action_type == GamelogActionType::Cheat);
389
390 this->Change(std::make_unique<LoggedChangeMode>(_game_mode, _settings_game.game_creation.landscape));
391}
392
397{
398 assert(this->action_type == GamelogActionType::Load);
399
400 this->Change(std::make_unique<LoggedChangeOldVersion>(_savegame_type,
401 (_savegame_type == SavegameType::OTTD ? (static_cast<uint32_t>(_sl_version) << 8 | _sl_minor_version) : _ttdp_version)));
402}
403
410void Gamelog::Setting(const std::string &name, int32_t oldval, int32_t newval)
411{
412 assert(this->action_type == GamelogActionType::Setting);
413
414 this->Change(std::make_unique<LoggedChangeSettingChanged>(name, oldval, newval));
415}
416
417
423{
424 const LoggedChangeRevision *rev = nullptr;
425
426 for (const LoggedAction &la : this->data->action) {
427 for (const auto &lc : la.change) {
428 if (lc->ct == GamelogChangeType::Revision) rev = static_cast<const LoggedChangeRevision *>(lc.get());
429 }
430 }
431
432 if (rev == nullptr || rev->text != GetGamelogRevisionString() ||
433 rev->modified != _openttd_revision_modified ||
434 rev->newgrf != _openttd_newgrf_version) {
435 this->Revision();
436 }
437}
438
444{
445 const LoggedChangeMode *mode = nullptr;
446
447 for (const LoggedAction &la : this->data->action) {
448 for (const auto &lc : la.change) {
449 if (lc->ct == GamelogChangeType::Mode) mode = static_cast<const LoggedChangeMode *>(lc.get());
450 }
451 }
452
453 if (mode == nullptr || mode->mode != _game_mode || mode->landscape != _settings_game.game_creation.landscape) this->Mode();
454}
455
456
463void Gamelog::GRFBug(GrfID grfid, ::GRFBug bug, uint64_t data)
464{
465 assert(this->action_type == GamelogActionType::GRFBug);
466
467 this->Change(std::make_unique<LoggedChangeGRFBug>(data, grfid, bug));
468}
469
479bool Gamelog::GRFBugReverse(GrfID grfid, uint16_t internal_id)
480{
481 for (const LoggedAction &la : this->data->action) {
482 for (const auto &lc : la.change) {
483 if (lc->ct == GamelogChangeType::GRFBug) {
484 LoggedChangeGRFBug *bug = static_cast<LoggedChangeGRFBug *>(lc.get());
485 if (bug->grfid == grfid && bug->bug == GRFBug::VehLength && bug->data == internal_id) {
486 return false;
487 }
488 }
489 }
490 }
491
493 this->GRFBug(grfid, GRFBug::VehLength, internal_id);
494 this->StopAction();
495
496 return true;
497}
498
499
505static inline bool IsLoggableGrfConfig(const GRFConfig &g)
506{
508}
509
515{
516 assert(this->action_type == GamelogActionType::Load || this->action_type == GamelogActionType::GRF);
517
518 this->Change(std::make_unique<LoggedChangeGRFRemoved>(grfid));
519}
520
525void Gamelog::GRFAdd(const GRFConfig &newg)
526{
527 assert(this->action_type == GamelogActionType::Load || this->action_type == GamelogActionType::Start || this->action_type == GamelogActionType::GRF);
528
529 if (!IsLoggableGrfConfig(newg)) return;
530
531 this->Change(std::make_unique<LoggedChangeGRFAdd>(newg.ident));
532}
533
540{
541 assert(this->action_type == GamelogActionType::Load || this->action_type == GamelogActionType::GRF);
542
543 this->Change(std::make_unique<LoggedChangeGRFChanged>(newg));
544}
545
551void Gamelog::GRFMove(GrfID grfid, int32_t offset)
552{
553 assert(this->action_type == GamelogActionType::GRF);
554
555 this->Change(std::make_unique<LoggedChangeGRFMoved>(grfid, offset));
556}
557
564{
565 assert(this->action_type == GamelogActionType::GRF);
566
567 this->Change(std::make_unique<LoggedChangeGRFParameterChanged>(grfid));
568}
569
575void Gamelog::GRFAddList(const GRFConfigList &newg)
576{
577 assert(this->action_type == GamelogActionType::Start || this->action_type == GamelogActionType::Load);
578
579 for (const auto &c : newg) {
580 this->GRFAdd(*c);
581 }
582}
583
589static std::vector<const GRFConfig *> GenerateGRFList(const GRFConfigList &grfc)
590{
591 std::vector<const GRFConfig *> list;
592 for (const auto &g : grfc) {
593 if (IsLoggableGrfConfig(*g)) list.push_back(g.get());
594 }
595
596 return list;
597}
598
604void Gamelog::GRFUpdate(const GRFConfigList &oldc, const GRFConfigList &newc)
605{
606 std::vector<const GRFConfig *> ol = GenerateGRFList(oldc);
607 std::vector<const GRFConfig *> nl = GenerateGRFList(newc);
608
609 uint o = 0, n = 0;
610
611 while (o < ol.size() && n < nl.size()) {
612 const GRFConfig &og = *ol[o];
613 const GRFConfig &ng = *nl[n];
614
615 if (og.ident.grfid != ng.ident.grfid) {
616 uint oi, ni;
617 for (oi = 0; oi < ol.size(); oi++) {
618 if (ol[oi]->ident.grfid == nl[n]->ident.grfid) break;
619 }
620 if (oi < o) {
621 /* GRF was moved, this change has been logged already */
622 n++;
623 continue;
624 }
625 if (oi == ol.size()) {
626 /* GRF couldn't be found in the OLD list, GRF was ADDED */
627 this->GRFAdd(*nl[n++]);
628 continue;
629 }
630 for (ni = 0; ni < nl.size(); ni++) {
631 if (nl[ni]->ident.grfid == ol[o]->ident.grfid) break;
632 }
633 if (ni < n) {
634 /* GRF was moved, this change has been logged already */
635 o++;
636 continue;
637 }
638 if (ni == nl.size()) {
639 /* GRF couldn't be found in the NEW list, GRF was REMOVED */
640 this->GRFRemove(ol[o++]->ident.grfid);
641 continue;
642 }
643
644 /* o < oi < ol->n
645 * n < ni < nl->n */
646 assert(ni > n && ni < nl.size());
647 assert(oi > o && oi < ol.size());
648
649 ni -= n; // number of GRFs it was moved downwards
650 oi -= o; // number of GRFs it was moved upwards
651
652 if (ni >= oi) { // prefer the one that is moved further
653 /* GRF was moved down */
654 this->GRFMove(ol[o++]->ident.grfid, ni);
655 } else {
656 this->GRFMove(nl[n++]->ident.grfid, -(int)oi);
657 }
658 } else {
659 if (og.ident.md5sum != ng.ident.md5sum) {
660 /* md5sum changed, probably loading 'compatible' GRF */
661 this->GRFCompatible(nl[n]->ident);
662 }
663
664 if (og.param != ng.param) {
665 this->GRFParameters(ol[o]->ident.grfid);
666 }
667
668 o++;
669 n++;
670 }
671 }
672
673 while (o < ol.size()) this->GRFRemove(ol[o++]->ident.grfid); // remaining GRFs were removed ...
674 while (n < nl.size()) this->GRFAdd (*nl[n++]); // ... or added
675}
676
683void Gamelog::Info(uint32_t *last_ottd_rev, uint8_t *ever_modified, bool *removed_newgrfs)
684{
685 for (const LoggedAction &la : this->data->action) {
686 for (const auto &lc : la.change) {
687 switch (lc->ct) {
688 default: break;
689
691 const LoggedChangeRevision *rev = static_cast<const LoggedChangeRevision *>(lc.get());
692 *last_ottd_rev = rev->newgrf;
693 *ever_modified = std::max(*ever_modified, rev->modified);
694 break;
695 }
696
698 *removed_newgrfs = true;
699 break;
700 }
701 }
702 }
703}
704
711{
712 const LoggedAction &la = this->data->action.back();
713 if (la.at != GamelogActionType::Load) return c.ident;
714
715 for (const auto &lc : la.change) {
716 if (lc->ct != GamelogChangeType::GRFCompat) continue;
717
718 const LoggedChangeGRFChanged &grf = *static_cast<const LoggedChangeGRFChanged *>(lc.get());
719 if (grf.grfid == c.ident.grfid) return grf;
720 }
721
722 return c.ident;
723}
static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
void TestRevision()
Finds out if current revision is different than last revision stored in the savegame.
Definition gamelog.cpp:422
const GRFIdentifier & GetOverriddenIdentifier(const GRFConfig &c)
Try to find the overridden GRF identifier of the given GRF.
Definition gamelog.cpp:710
void PrintDebug(Severity severity)
Prints gamelog to debug output.
Definition gamelog.cpp:319
bool GRFBugReverse(GrfID grfid, uint16_t internal_id)
Logs GRF bug - rail vehicle has different length after reversing.
Definition gamelog.cpp:479
void Mode()
Logs a change in game mode (scenario editor or game).
Definition gamelog.cpp:386
void Info(uint32_t *last_ottd_rev, uint8_t *ever_modified, bool *removed_newgrfs)
Get some basic information from the given gamelog.
Definition gamelog.cpp:683
void PrintConsole()
Print the gamelog data to the console.
Definition gamelog.cpp:306
void GRFParameters(GrfID grfid)
Logs change in GRF parameters.
Definition gamelog.cpp:563
void Revision()
Logs a change in game revision.
Definition gamelog.cpp:375
void StartAction(GamelogActionType at)
Stores information about new action, but doesn't allocate it Action is allocated only when there is a...
Definition gamelog.cpp:64
void Reset()
Resets and frees all memory allocated - used before loading or starting a new game.
Definition gamelog.cpp:93
void GRFRemove(GrfID grfid)
Logs removal of a GRF.
Definition gamelog.cpp:514
void GRFMove(GrfID grfid, int32_t offset)
Logs changing GRF order.
Definition gamelog.cpp:551
void GRFAddList(const GRFConfigList &newg)
Logs adding of list of GRFs.
Definition gamelog.cpp:575
~Gamelog()
Needs to be manually defined due to incomplete definition of GamelogInternalData in the header.
void GRFCompatible(const GRFIdentifier &newg)
Logs loading compatible GRF (the same ID, but different MD5 hash).
Definition gamelog.cpp:539
void Oldver()
Logs loading from savegame without gamelog.
Definition gamelog.cpp:396
void Emergency()
Logs a emergency savegame.
Definition gamelog.cpp:348
void TestMode()
Finds last stored game mode or landscape.
Definition gamelog.cpp:443
void StopAction()
Stops logging of any changes.
Definition gamelog.cpp:73
void GRFBug(GrfID grfid, ::GRFBug bug, uint64_t data)
Logs triggered GRF bug.
Definition gamelog.cpp:463
void Setting(const std::string &name, int32_t oldval, int32_t newval)
Logs change in game settings.
Definition gamelog.cpp:410
void Print(std::function< void(const std::string &)> proc)
Prints active gamelog.
Definition gamelog.cpp:143
void GRFAdd(const GRFConfig &newg)
Logs adding of a GRF.
Definition gamelog.cpp:525
void GRFUpdate(const GRFConfigList &oldg, const GRFConfigList &newg)
Compares two NewGRF lists and logs any change.
Definition gamelog.cpp:604
void Change(std::unique_ptr< LoggedChange > &&change)
Allocates a new LoggedAction if needed, and add the change when action is active.
Definition gamelog.cpp:331
bool TestEmergency()
Finds out if current game is a loaded emergency savegame.
Definition gamelog.cpp:361
static TickCounter counter
Monotonic counter, in ticks, since start of game.
void IConsolePrint(ExtendedTextColour colour_code, const std::string &string)
Handle the printing of text entered into the console or redirected there by any other means.
Definition console.cpp:91
Console functions used outside of the console code.
static const TextColour CC_WARNING
Colour for warning lines.
Functions related to debugging.
#define Debug(facility, severity, format_string,...)
Output a line of debugging information.
Definition debug.h:36
@ Gamelog
Gamelog message facility.
Definition debug_type.h:40
Severity
Debug message severity levels.
Definition debug_type.h:14
@ Debug1
Debug #1 - High level debug messages.
Definition debug_type.h:20
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
Definition enum_type.hpp:21
EnumClassIndexContainer< std::array< T, to_underlying(N)>, Index > EnumIndexArray
A typedef for EnumClassIndexContainer using std::array as the backing container type.
uint32_t _ttdp_version
version of TTDP savegame (if applicable)
Definition saveload.cpp:83
SaveLoadVersion _sl_version
the major savegame version identifier
Definition saveload.cpp:84
uint8_t _sl_minor_version
the minor savegame version, DO NOT USE!
Definition saveload.cpp:85
static std::string GetGamelogRevisionString()
Return the revision string for the current client version, for use in gamelog.
Definition gamelog.cpp:46
Gamelog _gamelog
Gamelog instance.
Definition gamelog.cpp:30
static bool IsLoggableGrfConfig(const GRFConfig &g)
Decides if GRF should be logged.
Definition gamelog.cpp:505
static constexpr EnumIndexArray< std::string_view, GamelogActionType, GamelogActionType::End > la_text
Text messages for various logged actions.
Definition gamelog.cpp:129
SavegameType _savegame_type
type of savegame we are loading
Definition saveload.cpp:80
static std::vector< const GRFConfig * > GenerateGRFList(const GRFConfigList &grfc)
Generates GRFList.
Definition gamelog.cpp:589
const SaveLoadVersion SAVEGAME_VERSION
current savegame version
static void AddGrfInfo(std::back_insert_iterator< std::string > &output_iterator, GrfID grfid, const MD5Hash *md5sum, const GRFConfig *gc)
Adds the GRF ID, checksum and filename if found to the output iterator.
Definition gamelog.cpp:107
@ GRFCompat
Loading compatible GRF.
Definition gamelog.h:38
@ Revision
Changed game revision string.
Definition gamelog.h:33
@ GRFRem
Added GRF.
Definition gamelog.h:37
@ Mode
Scenario editor x Game, different landscape.
Definition gamelog.h:32
@ Emergency
Emergency savegame.
Definition gamelog.h:42
@ GRFBug
GRF bug triggered.
Definition gamelog.h:41
GamelogActionType
The actions we log.
Definition gamelog.h:18
@ Setting
Setting changed.
Definition gamelog.h:23
@ Cheat
Cheat was used.
Definition gamelog.h:22
@ None
No logging active; in savegames, end of list.
Definition gamelog.h:27
@ End
End marker.
Definition gamelog.h:26
@ GRF
GRF changed.
Definition gamelog.h:21
@ Emergency
Emergency savegame.
Definition gamelog.h:25
@ Start
Game created.
Definition gamelog.h:19
@ GRFBug
GRF bug was triggered.
Definition gamelog.h:24
@ Load
Game loaded.
Definition gamelog.h:20
Declaration shared among gamelog.cpp and saveload/gamelog_sl.cpp.
std::map< GrfID, GRFPresence > GrfIDMapping
A mapping from GrfID to the GRFPresence.
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
Definition math_func.hpp:23
const GRFConfig * FindGRFConfig(GrfID grfid, FindGRFConfigMode mode, const MD5Hash *md5sum, uint32_t desired_version)
Find a NewGRF in the scanned list.
@ NotFound
GRF file was not found in the local cache.
@ Static
GRF file is used statically (can be used in any MP game).
GRFBug
Encountered GRF bugs.
@ VehLength
Length of rail vehicle changes when not inside a depot.
@ Exact
Only find Grfs matching md5sum.
@ Any
Use first found.
Label< struct GrfIDTag > GrfID
The unique identifier of a NewGRF.
Definition newgrf_type.h:17
Declaration of OTTD revision dependent variables.
A number of safeguards to prevent using unsafe methods.
Functions/types related to saving and loading games.
SavegameType
Types of save games.
Definition saveload.h:432
@ TTDP1
TTDP savegame ( -//- ) (data at NW border).
Definition saveload.h:434
@ TTO
TTO savegame.
Definition saveload.h:437
@ TTD
TTD savegame (can be detected incorrectly).
Definition saveload.h:433
@ TTDP2
TTDP savegame in new format (data at SE border).
Definition saveload.h:435
@ OTTD
OTTD savegame.
Definition saveload.h:436
SaveLoadVersion
SaveLoad versions Previous savegame versions, the trunk revision where they were introduced and the r...
Definition saveload.h:35
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:61
Types related to global configuration settings.
Definition of base types and functions in a cross-platform compatible way.
std::string FormatArrayAsHex(std::span< const uint8_t > data)
Format a byte array into a continuous hex string.
Definition string.cpp:76
Functions related to low-level strings.
Information about GRF, used in the game and (part of it) in savegames.
std::vector< uint32_t > param
GRF parameters.
GRFStatus status
NOSAVE: GRFStatus, enum.
GRFConfigFlags flags
NOSAVE: GCF_Flags, bitset.
std::string filename
Filename - either with or without full path.
GRFIdentifier ident
grfid and md5sum to uniquely identify newgrfs
Basic data to distinguish a GRF.
GrfID grfid
GRF ID (defined by Action 0x08).
MD5Hash md5sum
MD5 checksum of file to distinguish files with the same GRF ID (eg. newer version of GRF).
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:299
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:226
A log entry for a NewGRF bug.
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:288
GrfID grfid
ID of problematic GRF.
uint64_t data
additional data
A log entry for a NewGRF that was changed.
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:259
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:278
int32_t offset
offset, positive = move down
GrfID grfid
ID of moved 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:269
GrfID grfid
ID of GRF with changed parameters.
GrfID 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:237
Log element for the change of the game mode and landscape.
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:167
GameMode 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:188
uint32_t type
type of savegame,
uint32_t version
major and minor version OR ttdp version
A log entry for a change in OpenTTD 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:173
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:220
Definition of the tick-based game-timer.