OpenTTD Source: src/gamelog.cpp Source File

OpenTTD Source 13.2.1

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 <http://www.gnu.org/licenses/>.
6 */
7
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"
17 #include "date_func.h"
18 #include "rev.h"
19
20 #include <stdarg.h>
21
22 #include "safeguards.h"
23
24 extern const SaveLoadVersion SAVEGAME_VERSION;
25
26 extern SavegameType _savegame_type;
27
28 extern uint32 _ttdp_version;
29 extern SaveLoadVersion _sl_version;
30 extern byte _sl_minor_version;
31
32
33 static GamelogActionType _gamelog_action_type = GLAT_NONE;
34
35 LoggedAction *_gamelog_action = nullptr;
36 uint _gamelog_actions = 0;
37 static LoggedAction *_current_action = nullptr;
38
39
44 static const char * GetGamelogRevisionString()
45 {
46 /* Allocate a buffer larger than necessary (git revision hash is 40 bytes) to avoid truncation later */
47 static char gamelog_revision[48] = { 0 };
48 static_assert(lengthof(gamelog_revision) > GAMELOG_REVISION_LENGTH);
49
50 if (IsReleasedVersion()) {
51 return _openttd_revision;
52 } else if (gamelog_revision[0] == 0) {
53 /* Prefix character indication revision status */
54 assert(_openttd_revision_modified < 3);
55 gamelog_revision[0] = "gum"[_openttd_revision_modified]; // g = "git", u = "unknown", m = "modified"
56 /* Append the revision hash */
57 strecat(gamelog_revision, _openttd_revision_hash, lastof(gamelog_revision));
58 /* Truncate string to GAMELOG_REVISION_LENGTH bytes */
59 gamelog_revision[GAMELOG_REVISION_LENGTH - 1] = '\0';
60 }
61 return gamelog_revision;
62 }
63
69 void GamelogStartAction(GamelogActionType at)
70 {
71 assert(_gamelog_action_type == GLAT_NONE); // do not allow starting new action without stopping the previous first
72 _gamelog_action_type = at;
73 }
74
78 void GamelogStopAction()
79 {
80 assert(_gamelog_action_type != GLAT_NONE); // nobody should try to stop if there is no action in progress
81
82 bool print = _current_action != nullptr;
83
84 _current_action = nullptr;
85 _gamelog_action_type = GLAT_NONE;
86
87 if (print) GamelogPrintDebug(5);
88 }
89
90 void GamelogStopAnyAction()
91 {
92 if (_gamelog_action_type != GLAT_NONE) GamelogStopAction();
93 }
94
98 void GamelogFree(LoggedAction *gamelog_action, uint gamelog_actions)
99 {
100 for (uint i = 0; i < gamelog_actions; i++) {
101 const LoggedAction *la = &gamelog_action[i];
102 for (uint j = 0; j < la->changes; j++) {
103 const LoggedChange *lc = &la->change[j];
104 if (lc->ct == GLCT_SETTING) free(lc->setting.name);
105 }
106 free(la->change);
107 }
108
109 free(gamelog_action);
110 }
111
115 void GamelogReset()
116 {
117 assert(_gamelog_action_type == GLAT_NONE);
118 GamelogFree(_gamelog_action, _gamelog_actions);
119
120 _gamelog_action = nullptr;
121 _gamelog_actions = 0;
122 _current_action = nullptr;
123 }
124
134 static char *PrintGrfInfo(char *buf, const char *last, uint grfid, const uint8 *md5sum, const GRFConfig *gc)
135 {
136 char txt[40];
137
138 if (md5sum != nullptr) {
139 md5sumToString(txt, lastof(txt), md5sum);
140 buf += seprintf(buf, last, "GRF ID %08X, checksum %s", BSWAP32(grfid), txt);
141 } else {
142 buf += seprintf(buf, last, "GRF ID %08X", BSWAP32(grfid));
143 }
144
145 if (gc != nullptr) {
146 buf += seprintf(buf, last, ", filename: %s (md5sum matches)", gc->filename);
147 } else {
148 gc = FindGRFConfig(grfid, FGCM_ANY);
149 if (gc != nullptr) {
150 buf += seprintf(buf, last, ", filename: %s (matches GRFID only)", gc->filename);
151 } else {
152 buf += seprintf(buf, last, ", unknown GRF");
153 }
154 }
155 return buf;
156 }
157
158
160 static const char * const la_text[] = {
161 "new game started",
162 "game loaded",
163 "GRF config changed",
164 "cheat was used",
165 "settings changed",
166 "GRF bug triggered",
167 "emergency savegame",
168 };
169
170 static_assert(lengthof(la_text) == GLAT_END);
171
179 struct GRFPresence{
180 const GRFConfig *gc;
181 bool was_missing;
182
183 GRFPresence(const GRFConfig *gc) : gc(gc), was_missing(false) {}
184 GRFPresence() = default;
185 };
186 typedef SmallMap<uint32, GRFPresence> GrfIDMapping;
187
192 void GamelogPrint(GamelogPrintProc *proc)
193 {
194 char buffer[1024];
195 GrfIDMapping grf_names;
196
197 proc("---- gamelog start ----");
198
199 const LoggedAction *laend = &_gamelog_action[_gamelog_actions];
200
201 for (const LoggedAction *la = _gamelog_action; la != laend; la++) {
202 assert((uint)la->at < GLAT_END);
203
204 seprintf(buffer, lastof(buffer), "Tick %u: %s", (uint)la->tick, la_text[(uint)la->at]);
205 proc(buffer);
206
207 const LoggedChange *lcend = &la->change[la->changes];
208
209 for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
210 char *buf = buffer;
211
212 switch (lc->ct) {
213 default: NOT_REACHED();
214 case GLCT_MODE:
215 buf += seprintf(buf, lastof(buffer), "New game mode: %u landscape: %u",
216 (uint)lc->mode.mode, (uint)lc->mode.landscape);
217 break;
218
219 case GLCT_REVISION:
220 buf += seprintf(buf, lastof(buffer), "Revision text changed to %s, savegame version %u, ",
221 lc->revision.text, lc->revision.slver);
222
223 switch (lc->revision.modified) {
224 case 0: buf += seprintf(buf, lastof(buffer), "not "); break;
225 case 1: buf += seprintf(buf, lastof(buffer), "maybe "); break;
226 default: break;
227 }
228
229 buf += seprintf(buf, lastof(buffer), "modified, _openttd_newgrf_version = 0x%08x", lc->revision.newgrf);
230 break;
231
232 case GLCT_OLDVER:
233 buf += seprintf(buf, lastof(buffer), "Conversion from ");
234 switch (lc->oldver.type) {
235 default: NOT_REACHED();
236 case SGT_OTTD:
237 buf += seprintf(buf, lastof(buffer), "OTTD savegame without gamelog: version %u, %u",
238 GB(lc->oldver.version, 8, 16), GB(lc->oldver.version, 0, 8));
239 break;
240
241 case SGT_TTO:
242 buf += seprintf(buf, lastof(buffer), "TTO savegame");
243 break;
244
245 case SGT_TTD:
246 buf += seprintf(buf, lastof(buffer), "TTD savegame");
247 break;
248
249 case SGT_TTDP1:
250 case SGT_TTDP2:
251 buf += seprintf(buf, lastof(buffer), "TTDP savegame, %s format",
252 lc->oldver.type == SGT_TTDP1 ? "old" : "new");
253 if (lc->oldver.version != 0) {
254 buf += seprintf(buf, lastof(buffer), ", TTDP version %u.%u.%u.%u",
255 GB(lc->oldver.version, 24, 8), GB(lc->oldver.version, 20, 4),
256 GB(lc->oldver.version, 16, 4), GB(lc->oldver.version, 0, 16));
257 }
258 break;
259 }
260 break;
261
262 case GLCT_SETTING:
263 buf += seprintf(buf, lastof(buffer), "Setting changed: %s : %d -> %d", lc->setting.name, lc->setting.oldval, lc->setting.newval);
264 break;
265
266 case GLCT_GRFADD: {
267 const GRFConfig *gc = FindGRFConfig(lc->grfadd.grfid, FGCM_EXACT, lc->grfadd.md5sum);
268 buf += seprintf(buf, lastof(buffer), "Added NewGRF: ");
269 buf = PrintGrfInfo(buf, lastof(buffer), lc->grfadd.grfid, lc->grfadd.md5sum, gc);
270 GrfIDMapping::Pair *gm = grf_names.Find(lc->grfrem.grfid);
271 if (gm != grf_names.End() && !gm->second.was_missing) buf += seprintf(buf, lastof(buffer), ". Gamelog inconsistency: GrfID was already added!");
272 grf_names[lc->grfadd.grfid] = gc;
273 break;
274 }
275
276 case GLCT_GRFREM: {
277 GrfIDMapping::Pair *gm = grf_names.Find(lc->grfrem.grfid);
278 buf += seprintf(buf, lastof(buffer), la->at == GLAT_LOAD ? "Missing NewGRF: " : "Removed NewGRF: ");
279 buf = PrintGrfInfo(buf, lastof(buffer), lc->grfrem.grfid, nullptr, gm != grf_names.End() ? gm->second.gc : nullptr);
280 if (gm == grf_names.End()) {
281 buf += seprintf(buf, lastof(buffer), ". Gamelog inconsistency: GrfID was never added!");
282 } else {
283 if (la->at == GLAT_LOAD) {
284 /* Missing grfs on load are not removed from the configuration */
285 gm->second.was_missing = true;
286 } else {
287 grf_names.Erase(gm);
288 }
289 }
290 break;
291 }
292
293 case GLCT_GRFCOMPAT: {
294 const GRFConfig *gc = FindGRFConfig(lc->grfadd.grfid, FGCM_EXACT, lc->grfadd.md5sum);
295 buf += seprintf(buf, lastof(buffer), "Compatible NewGRF loaded: ");
296 buf = PrintGrfInfo(buf, lastof(buffer), lc->grfcompat.grfid, lc->grfcompat.md5sum, gc);
297 if (!grf_names.Contains(lc->grfcompat.grfid)) buf += seprintf(buf, lastof(buffer), ". Gamelog inconsistency: GrfID was never added!");
298 grf_names[lc->grfcompat.grfid] = gc;
299 break;
300 }
301
302 case GLCT_GRFPARAM: {
303 GrfIDMapping::Pair *gm = grf_names.Find(lc->grfrem.grfid);
304 buf += seprintf(buf, lastof(buffer), "GRF parameter changed: ");
305 buf = PrintGrfInfo(buf, lastof(buffer), lc->grfparam.grfid, nullptr, gm != grf_names.End() ? gm->second.gc : nullptr);
306 if (gm == grf_names.End()) buf += seprintf(buf, lastof(buffer), ". Gamelog inconsistency: GrfID was never added!");
307 break;
308 }
309
310 case GLCT_GRFMOVE: {
311 GrfIDMapping::Pair *gm = grf_names.Find(lc->grfrem.grfid);
312 buf += seprintf(buf, lastof(buffer), "GRF order changed: %08X moved %d places %s",
313 BSWAP32(lc->grfmove.grfid), abs(lc->grfmove.offset), lc->grfmove.offset >= 0 ? "down" : "up" );
314 buf = PrintGrfInfo(buf, lastof(buffer), lc->grfmove.grfid, nullptr, gm != grf_names.End() ? gm->second.gc : nullptr);
315 if (gm == grf_names.End()) buf += seprintf(buf, lastof(buffer), ". Gamelog inconsistency: GrfID was never added!");
316 break;
317 }
318
319 case GLCT_GRFBUG: {
320 GrfIDMapping::Pair *gm = grf_names.Find(lc->grfrem.grfid);
321 switch (lc->grfbug.bug) {
322 default: NOT_REACHED();
323 case GBUG_VEH_LENGTH:
324 buf += seprintf(buf, lastof(buffer), "Rail vehicle changes length outside a depot: GRF ID %08X, internal ID 0x%X", BSWAP32(lc->grfbug.grfid), (uint)lc->grfbug.data);
325 break;
326 }
327 buf = PrintGrfInfo(buf, lastof(buffer), lc->grfbug.grfid, nullptr, gm != grf_names.End() ? gm->second.gc : nullptr);
328 if (gm == grf_names.End()) buf += seprintf(buf, lastof(buffer), ". Gamelog inconsistency: GrfID was never added!");
329 break;
330 }
331
332 case GLCT_EMERGENCY:
333 break;
334 }
335
336 proc(buffer);
337 }
338 }
339
340 proc("---- gamelog end ----");
341 }
342
343
344 static void GamelogPrintConsoleProc(const char *s)
345 {
346 IConsolePrint(CC_WARNING, s);
347 }
348
350 void GamelogPrintConsole()
351 {
352 GamelogPrint(&GamelogPrintConsoleProc);
353 }
354
355 static int _gamelog_print_level = 0;
356
357 static void GamelogPrintDebugProc(const char *s)
358 {
359 Debug(gamelog, _gamelog_print_level, "{}", s);
360 }
361
362
369 void GamelogPrintDebug(int level)
370 {
371 _gamelog_print_level = level;
372 GamelogPrint(&GamelogPrintDebugProc);
373 }
374
375
382 static LoggedChange *GamelogChange(GamelogChangeType ct)
383 {
384 if (_current_action == nullptr) {
385 if (_gamelog_action_type == GLAT_NONE) return nullptr;
386
387 _gamelog_action = ReallocT(_gamelog_action, _gamelog_actions + 1);
388 _current_action = &_gamelog_action[_gamelog_actions++];
389
390 _current_action->at = _gamelog_action_type;
391 _current_action->tick = _tick_counter;
392 _current_action->change = nullptr;
393 _current_action->changes = 0;
394 }
395
396 _current_action->change = ReallocT(_current_action->change, _current_action->changes + 1);
397
398 LoggedChange *lc = &_current_action->change[_current_action->changes++];
399 lc->ct = ct;
400
401 return lc;
402 }
403
404
408 void GamelogEmergency()
409 {
410 /* Terminate any active action */
411 if (_gamelog_action_type != GLAT_NONE) GamelogStopAction();
412 GamelogStartAction(GLAT_EMERGENCY);
413 GamelogChange(GLCT_EMERGENCY);
414 GamelogStopAction();
415 }
416
420 bool GamelogTestEmergency()
421 {
422 const LoggedChange *emergency = nullptr;
423
424 const LoggedAction *laend = &_gamelog_action[_gamelog_actions];
425 for (const LoggedAction *la = _gamelog_action; la != laend; la++) {
426 const LoggedChange *lcend = &la->change[la->changes];
427 for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
428 if (lc->ct == GLCT_EMERGENCY) emergency = lc;
429 }
430 }
431
432 return (emergency != nullptr);
433 }
434
438 void GamelogRevision()
439 {
440 assert(_gamelog_action_type == GLAT_START || _gamelog_action_type == GLAT_LOAD);
441
442 LoggedChange *lc = GamelogChange(GLCT_REVISION);
443 if (lc == nullptr) return;
444
445 memset(lc->revision.text, 0, sizeof(lc->revision.text));
446 strecpy(lc->revision.text, GetGamelogRevisionString(), lastof(lc->revision.text));
447 lc->revision.slver = SAVEGAME_VERSION;
448 lc->revision.modified = _openttd_revision_modified;
449 lc->revision.newgrf = _openttd_newgrf_version;
450 }
451
455 void GamelogMode()
456 {
457 assert(_gamelog_action_type == GLAT_START || _gamelog_action_type == GLAT_LOAD || _gamelog_action_type == GLAT_CHEAT);
458
459 LoggedChange *lc = GamelogChange(GLCT_MODE);
460 if (lc == nullptr) return;
461
462 lc->mode.mode = _game_mode;
463 lc->mode.landscape = _settings_game.game_creation.landscape;
464 }
465
469 void GamelogOldver()
470 {
471 assert(_gamelog_action_type == GLAT_LOAD);
472
473 LoggedChange *lc = GamelogChange(GLCT_OLDVER);
474 if (lc == nullptr) return;
475
476 lc->oldver.type = _savegame_type;
477 lc->oldver.version = (_savegame_type == SGT_OTTD ? ((uint32)_sl_version << 8 | _sl_minor_version) : _ttdp_version);
478 }
479
486 void GamelogSetting(const std::string &name, int32 oldval, int32 newval)
487 {
488 assert(_gamelog_action_type == GLAT_SETTING);
489
490 LoggedChange *lc = GamelogChange(GLCT_SETTING);
491 if (lc == nullptr) return;
492
493 lc->setting.name = stredup(name.c_str());
494 lc->setting.oldval = oldval;
495 lc->setting.newval = newval;
496 }
497
498
503 void GamelogTestRevision()
504 {
505 const LoggedChange *rev = nullptr;
506
507 const LoggedAction *laend = &_gamelog_action[_gamelog_actions];
508 for (const LoggedAction *la = _gamelog_action; la != laend; la++) {
509 const LoggedChange *lcend = &la->change[la->changes];
510 for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
511 if (lc->ct == GLCT_REVISION) rev = lc;
512 }
513 }
514
515 if (rev == nullptr || strcmp(rev->revision.text, GetGamelogRevisionString()) != 0 ||
516 rev->revision.modified != _openttd_revision_modified ||
517 rev->revision.newgrf != _openttd_newgrf_version) {
518 GamelogRevision();
519 }
520 }
521
526 void GamelogTestMode()
527 {
528 const LoggedChange *mode = nullptr;
529
530 const LoggedAction *laend = &_gamelog_action[_gamelog_actions];
531 for (const LoggedAction *la = _gamelog_action; la != laend; la++) {
532 const LoggedChange *lcend = &la->change[la->changes];
533 for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
534 if (lc->ct == GLCT_MODE) mode = lc;
535 }
536 }
537
538 if (mode == nullptr || mode->mode.mode != _game_mode || mode->mode.landscape != _settings_game.game_creation.landscape) GamelogMode();
539 }
540
541
548 static void GamelogGRFBug(uint32 grfid, byte bug, uint64 data)
549 {
550 assert(_gamelog_action_type == GLAT_GRFBUG);
551
552 LoggedChange *lc = GamelogChange(GLCT_GRFBUG);
553 if (lc == nullptr) return;
554
555 lc->grfbug.data = data;
556 lc->grfbug.grfid = grfid;
557 lc->grfbug.bug = bug;
558 }
559
569 bool GamelogGRFBugReverse(uint32 grfid, uint16 internal_id)
570 {
571 const LoggedAction *laend = &_gamelog_action[_gamelog_actions];
572 for (const LoggedAction *la = _gamelog_action; la != laend; la++) {
573 const LoggedChange *lcend = &la->change[la->changes];
574 for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
575 if (lc->ct == GLCT_GRFBUG && lc->grfbug.grfid == grfid &&
576 lc->grfbug.bug == GBUG_VEH_LENGTH && lc->grfbug.data == internal_id) {
577 return false;
578 }
579 }
580 }
581
582 GamelogStartAction(GLAT_GRFBUG);
583 GamelogGRFBug(grfid, GBUG_VEH_LENGTH, internal_id);
584 GamelogStopAction();
585
586 return true;
587 }
588
589
595 static inline bool IsLoggableGrfConfig(const GRFConfig *g)
596 {
597 return !HasBit(g->flags, GCF_STATIC) && g->status != GCS_NOT_FOUND;
598 }
599
604 void GamelogGRFRemove(uint32 grfid)
605 {
606 assert(_gamelog_action_type == GLAT_LOAD || _gamelog_action_type == GLAT_GRF);
607
608 LoggedChange *lc = GamelogChange(GLCT_GRFREM);
609 if (lc == nullptr) return;
610
611 lc->grfrem.grfid = grfid;
612 }
613
618 void GamelogGRFAdd(const GRFConfig *newg)
619 {
620 assert(_gamelog_action_type == GLAT_LOAD || _gamelog_action_type == GLAT_START || _gamelog_action_type == GLAT_GRF);
621
622 if (!IsLoggableGrfConfig(newg)) return;
623
624 LoggedChange *lc = GamelogChange(GLCT_GRFADD);
625 if (lc == nullptr) return;
626
627 lc->grfadd = newg->ident;
628 }
629
635 void GamelogGRFCompatible(const GRFIdentifier *newg)
636 {
637 assert(_gamelog_action_type == GLAT_LOAD || _gamelog_action_type == GLAT_GRF);
638
639 LoggedChange *lc = GamelogChange(GLCT_GRFCOMPAT);
640 if (lc == nullptr) return;
641
642 lc->grfcompat = *newg;
643 }
644
650 static void GamelogGRFMove(uint32 grfid, int32 offset)
651 {
652 assert(_gamelog_action_type == GLAT_GRF);
653
654 LoggedChange *lc = GamelogChange(GLCT_GRFMOVE);
655 if (lc == nullptr) return;
656
657 lc->grfmove.grfid = grfid;
658 lc->grfmove.offset = offset;
659 }
660
666 static void GamelogGRFParameters(uint32 grfid)
667 {
668 assert(_gamelog_action_type == GLAT_GRF);
669
670 LoggedChange *lc = GamelogChange(GLCT_GRFPARAM);
671 if (lc == nullptr) return;
672
673 lc->grfparam.grfid = grfid;
674 }
675
681 void GamelogGRFAddList(const GRFConfig *newg)
682 {
683 assert(_gamelog_action_type == GLAT_START || _gamelog_action_type == GLAT_LOAD);
684
685 for (; newg != nullptr; newg = newg->next) {
686 GamelogGRFAdd(newg);
687 }
688 }
689
691 struct GRFList {
692 uint n;
693 const GRFConfig *grf[];
694 };
695
700 static GRFList *GenerateGRFList(const GRFConfig *grfc)
701 {
702 uint n = 0;
703 for (const GRFConfig *g = grfc; g != nullptr; g = g->next) {
704 if (IsLoggableGrfConfig(g)) n++;
705 }
706
707 GRFList *list = (GRFList*)MallocT<byte>(sizeof(GRFList) + n * sizeof(GRFConfig*));
708
709 list->n = 0;
710 for (const GRFConfig *g = grfc; g != nullptr; g = g->next) {
711 if (IsLoggableGrfConfig(g)) list->grf[list->n++] = g;
712 }
713
714 return list;
715 }
716
722 void GamelogGRFUpdate(const GRFConfig *oldc, const GRFConfig *newc)
723 {
724 GRFList *ol = GenerateGRFList(oldc);
725 GRFList *nl = GenerateGRFList(newc);
726
727 uint o = 0, n = 0;
728
729 while (o < ol->n && n < nl->n) {
730 const GRFConfig *og = ol->grf[o];
731 const GRFConfig *ng = nl->grf[n];
732
733 if (og->ident.grfid != ng->ident.grfid) {
734 uint oi, ni;
735 for (oi = 0; oi < ol->n; oi++) {
736 if (ol->grf[oi]->ident.grfid == nl->grf[n]->ident.grfid) break;
737 }
738 if (oi < o) {
739 /* GRF was moved, this change has been logged already */
740 n++;
741 continue;
742 }
743 if (oi == ol->n) {
744 /* GRF couldn't be found in the OLD list, GRF was ADDED */
745 GamelogGRFAdd(nl->grf[n++]);
746 continue;
747 }
748 for (ni = 0; ni < nl->n; ni++) {
749 if (nl->grf[ni]->ident.grfid == ol->grf[o]->ident.grfid) break;
750 }
751 if (ni < n) {
752 /* GRF was moved, this change has been logged already */
753 o++;
754 continue;
755 }
756 if (ni == nl->n) {
757 /* GRF couldn't be found in the NEW list, GRF was REMOVED */
758 GamelogGRFRemove(ol->grf[o++]->ident.grfid);
759 continue;
760 }
761
762 /* o < oi < ol->n
763 * n < ni < nl->n */
764 assert(ni > n && ni < nl->n);
765 assert(oi > o && oi < ol->n);
766
767 ni -= n; // number of GRFs it was moved downwards
768 oi -= o; // number of GRFs it was moved upwards
769
770 if (ni >= oi) { // prefer the one that is moved further
771 /* GRF was moved down */
772 GamelogGRFMove(ol->grf[o++]->ident.grfid, ni);
773 } else {
774 GamelogGRFMove(nl->grf[n++]->ident.grfid, -(int)oi);
775 }
776 } else {
777 if (memcmp(og->ident.md5sum, ng->ident.md5sum, sizeof(og->ident.md5sum)) != 0) {
778 /* md5sum changed, probably loading 'compatible' GRF */
779 GamelogGRFCompatible(&nl->grf[n]->ident);
780 }
781
782 if (og->num_params != ng->num_params || memcmp(og->param, ng->param, og->num_params * sizeof(og->param[0])) != 0) {
783 GamelogGRFParameters(ol->grf[o]->ident.grfid);
784 }
785
786 o++;
787 n++;
788 }
789 }
790
791 while (o < ol->n) GamelogGRFRemove(ol->grf[o++]->ident.grfid); // remaining GRFs were removed ...
792 while (n < nl->n) GamelogGRFAdd (nl->grf[n++]); // ... or added
793
794 free(ol);
795 free(nl);
796 }
797
806 void GamelogInfo(LoggedAction *gamelog_action, uint gamelog_actions, uint32 *last_ottd_rev, byte *ever_modified, bool *removed_newgrfs)
807 {
808 const LoggedAction *laend = &gamelog_action[gamelog_actions];
809 for (const LoggedAction *la = gamelog_action; la != laend; la++) {
810 const LoggedChange *lcend = &la->change[la->changes];
811 for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
812 switch (lc->ct) {
813 default: break;
814
815 case GLCT_REVISION:
816 *last_ottd_rev = lc->revision.newgrf;
817 *ever_modified = std::max(*ever_modified, lc->revision.modified);
818 break;
819
820 case GLCT_GRFREM:
821 *removed_newgrfs = true;
822 break;
823 }
824 }
825 }
826 }
GLCT_GRFADD
@ GLCT_GRFADD
Removed GRF.
Definition: gamelog_internal.h:21
GamelogSetting
void GamelogSetting(const std::string &name, int32 oldval, int32 newval)
Logs change in game settings.
Definition: gamelog.cpp:486
gamelog_internal.h
GLCT_GRFBUG
@ GLCT_GRFBUG
GRF bug triggered.
Definition: gamelog_internal.h:26
IsLoggableGrfConfig
static bool IsLoggableGrfConfig(const GRFConfig *g)
Decides if GRF should be logged.
Definition: gamelog.cpp:595
GamelogPrintProc
void GamelogPrintProc(const char *s)
Callback for printing text.
Definition: gamelog.h:39
GLAT_GRF
@ GLAT_GRF
GRF changed.
Definition: gamelog.h:19
SGT_OTTD
@ SGT_OTTD
OTTD savegame.
Definition: saveload.h:377
GB
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:32
LoggedChange::mode
byte mode
new game mode - Editor x Game
Definition: gamelog_internal.h:40
GLAT_LOAD
@ GLAT_LOAD
Game loaded.
Definition: gamelog.h:18
FindGRFConfig
const GRFConfig * FindGRFConfig(uint32 grfid, FindGRFConfigMode mode, const uint8 *md5sum, uint32 desired_version)
Find a NewGRF in the scanned list.
Definition: newgrf_config.cpp:745
GameCreationSettings::landscape
byte landscape
the landscape we're currently in
Definition: settings_type.h:328
GLCT_GRFMOVE
@ GLCT_GRFMOVE
GRF order changed.
Definition: gamelog_internal.h:25
GRFConfig::num_params
uint8 num_params
Number of used parameters.
Definition: newgrf_config.h:177
GamelogMode
void GamelogMode()
Logs a change in game mode (scenario editor or game)
Definition: gamelog.cpp:455
_gamelog_actions
uint _gamelog_actions
number of actions
Definition: gamelog.cpp:36
GamelogGRFBug
static void GamelogGRFBug(uint32 grfid, byte bug, uint64 data)
Logs triggered GRF bug.
Definition: gamelog.cpp:548
GamelogFree
void GamelogFree(LoggedAction *gamelog_action, uint gamelog_actions)
Frees the memory allocated by a gamelog.
Definition: gamelog.cpp:98
GLCT_EMERGENCY
@ GLCT_EMERGENCY
Emergency savegame.
Definition: gamelog_internal.h:27
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
SGT_TTDP1
@ SGT_TTDP1
TTDP savegame ( -//- ) (data at NW border)
Definition: saveload.h:375
GenerateGRFList
static GRFList * GenerateGRFList(const GRFConfig *grfc)
Generates GRFList.
Definition: gamelog.cpp:700
GRFPresence::gc
const GRFConfig * gc
GRFConfig, if known.
Definition: gamelog.cpp:180
GLCT_REVISION
@ GLCT_REVISION
Changed game revision string.
Definition: gamelog_internal.h:18
saveload.h
GCS_NOT_FOUND
@ GCS_NOT_FOUND
GRF file was not found in the local cache.
Definition: newgrf_config.h:37
GRFConfig::ident
GRFIdentifier ident
grfid and md5sum to uniquely identify newgrfs
Definition: newgrf_config.h:163
GRFConfig::status
GRFStatus status
NOSAVE: GRFStatus, enum.
Definition: newgrf_config.h:174
LoggedAction::at
GamelogActionType at
Type of action.
Definition: gamelog_internal.h:83
SAVEGAME_VERSION
const SaveLoadVersion SAVEGAME_VERSION
current savegame version
GLAT_SETTING
@ GLAT_SETTING
Setting changed.
Definition: gamelog.h:21
GRFIdentifier::md5sum
uint8 md5sum[16]
MD5 checksum of file to distinguish files with the same GRF ID (eg. newer version of GRF)
Definition: newgrf_config.h:85
GRFIdentifier::grfid
uint32 grfid
GRF ID (defined by Action 0x08)
Definition: newgrf_config.h:84
_savegame_type
SavegameType _savegame_type
type of savegame we are loading
Definition: saveload.cpp:62
SmallMap
Implementation of simple mapping class.
Definition: smallmap_type.hpp:26
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition: settings_type.h:587
GamelogGRFRemove
void GamelogGRFRemove(uint32 grfid)
Logs removal of a GRF.
Definition: gamelog.cpp:604
GamelogPrint
void GamelogPrint(GamelogPrintProc *proc)
Prints active gamelog.
Definition: gamelog.cpp:192
FGCM_ANY
@ FGCM_ANY
Use first found.
Definition: newgrf_config.h:203
GRFIdentifier
Basic data to distinguish a GRF.
Definition: newgrf_config.h:83
LoggedAction::changes
uint32 changes
Number of changes in this action.
Definition: gamelog_internal.h:82
GamelogGRFMove
static void GamelogGRFMove(uint32 grfid, int32 offset)
Logs changing GRF order.
Definition: gamelog.cpp:650
SavegameType
SavegameType
Types of save games.
Definition: saveload.h:373
GRFConfig
Information about GRF, used in the game and (part of it) in savegames.
Definition: newgrf_config.h:155
SGT_TTO
@ SGT_TTO
TTO savegame.
Definition: saveload.h:378
GRFConfig::flags
uint8 flags
NOSAVE: GCF_Flags, bitset.
Definition: newgrf_config.h:173
GLAT_NONE
@ GLAT_NONE
No logging active; in savegames, end of list.
Definition: gamelog.h:25
GamelogTestEmergency
bool GamelogTestEmergency()
Finds out if current game is a loaded emergency savegame.
Definition: gamelog.cpp:420
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:54
GamelogStartAction
void GamelogStartAction(GamelogActionType at)
Stores information about new action, but doesn't allocate it Action is allocated only when there is a...
Definition: gamelog.cpp:69
GamelogEmergency
void GamelogEmergency()
Logs a emergency savegame.
Definition: gamelog.cpp:408
safeguards.h
GamelogChange
static LoggedChange * GamelogChange(GamelogChangeType ct)
Allocates new LoggedChange and new LoggedAction if needed.
Definition: gamelog.cpp:382
SaveLoadVersion
SaveLoadVersion
SaveLoad versions Previous savegame versions, the trunk revision where they were introduced and the r...
Definition: saveload.h:34
_gamelog_print_level
static int _gamelog_print_level
gamelog debug level we need to print stuff
Definition: gamelog.cpp:355
GamelogPrintConsole
void GamelogPrintConsole()
Print the gamelog data to the console.
Definition: gamelog.cpp:350
SmallMap::Erase
void Erase(Pair *pair)
Removes given pair from this map.
Definition: smallmap_type.hpp:99
GamelogChangeType
GamelogChangeType
Type of logged change.
Definition: gamelog_internal.h:16
settings_type.h
LoggedAction::tick
uint64 tick
Tick when it happened.
Definition: gamelog_internal.h:84
GamelogTestRevision
void GamelogTestRevision()
Finds out if current revision is different than last revision stored in the savegame.
Definition: gamelog.cpp:503
_ttdp_version
uint32 _ttdp_version
version of TTDP savegame (if applicable)
Definition: saveload.cpp:65
GRFPresence::was_missing
bool was_missing
Grf was missing during some gameload in the past.
Definition: gamelog.cpp:181
date_func.h
stdafx.h
LoggedAction::change
LoggedChange * change
First logged change in this action.
Definition: gamelog_internal.h:81
GLAT_EMERGENCY
@ GLAT_EMERGENCY
Emergency savegame.
Definition: gamelog.h:23
BSWAP32
static uint32 BSWAP32(uint32 x)
Perform a 32 bits endianness bitswap on x.
Definition: bitmath_func.hpp:390
GLCT_GRFCOMPAT
@ GLCT_GRFCOMPAT
Loading compatible GRF.
Definition: gamelog_internal.h:23
_gamelog_action
LoggedAction * _gamelog_action
first logged action
Definition: gamelog.cpp:35
GamelogStopAction
void GamelogStopAction()
Stops logging of any changes.
Definition: gamelog.cpp:78
SGT_TTD
@ SGT_TTD
TTD savegame (can be detected incorrectly)
Definition: saveload.h:374
string_func.h
_gamelog_action_type
static GamelogActionType _gamelog_action_type
action to record if anything changes
Definition: gamelog.cpp:33
rev.h
GamelogPrintDebug
void GamelogPrintDebug(int level)
Prints gamelog to debug output.
Definition: gamelog.cpp:369
LoggedChange::ct
GamelogChangeType ct
Type of change logged in this struct.
Definition: gamelog_internal.h:37
GLCT_GRFPARAM
@ GLCT_GRFPARAM
GRF parameter changed.
Definition: gamelog_internal.h:24
GLAT_CHEAT
@ GLAT_CHEAT
Cheat was used.
Definition: gamelog.h:20
GamelogGRFCompatible
void GamelogGRFCompatible(const GRFIdentifier *newg)
Logs loading compatible GRF (the same ID, but different MD5 hash)
Definition: gamelog.cpp:635
_sl_minor_version
byte _sl_minor_version
the minor savegame version, DO NOT USE!
Definition: saveload.cpp:67
LoggedChange::grfadd
GRFIdentifier grfadd
ID and md5sum of added GRF.
Definition: gamelog_internal.h:53
PrintGrfInfo
static char * PrintGrfInfo(char *buf, const char *last, uint grfid, const uint8 *md5sum, const GRFConfig *gc)
Prints GRF ID, checksum and filename if found.
Definition: gamelog.cpp:134
GRFConfig::next
struct GRFConfig * next
NOSAVE: Next item in the linked list.
Definition: newgrf_config.h:183
GamelogGRFUpdate
void GamelogGRFUpdate(const GRFConfig *oldc, const GRFConfig *newc)
Compares two NewGRF lists and logs any change.
Definition: gamelog.cpp:722
la_text
static const char *const la_text[]
Text messages for various logged actions.
Definition: gamelog.cpp:160
GamelogGRFParameters
static void GamelogGRFParameters(uint32 grfid)
Logs change in GRF parameters.
Definition: gamelog.cpp:666
GLCT_OLDVER
@ GLCT_OLDVER
Loaded from savegame without logged data.
Definition: gamelog_internal.h:19
GLAT_GRFBUG
@ GLAT_GRFBUG
GRF bug was triggered.
Definition: gamelog.h:22
GamelogGRFAddList
void GamelogGRFAddList(const GRFConfig *newg)
Logs adding of list of GRFs.
Definition: gamelog.cpp:681
seprintf
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
Definition: string.cpp:554
GamelogGRFAdd
void GamelogGRFAdd(const GRFConfig *newg)
Logs adding of a GRF.
Definition: gamelog.cpp:618
GamelogReset
void GamelogReset()
Resets and frees all memory allocated - used before loading or starting a new game.
Definition: gamelog.cpp:115
LoggedChange::grfcompat
GRFIdentifier grfcompat
ID and new md5sum of changed GRF.
Definition: gamelog_internal.h:57
ReallocT
static T * ReallocT(T *t_ptr, size_t num_elements)
Simplified reallocation function that allocates the specified number of elements of the given type.
Definition: alloc_func.hpp:111
abs
static T abs(const T a)
Returns the absolute value of (scalar) variable.
Definition: math_func.hpp:21
stredup
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
Definition: string.cpp:138
SmallMap::Find
std::vector< Pair >::const_iterator Find(const T &key) const
Finds given key in this map.
Definition: smallmap_type.hpp:41
Debug
#define Debug(name, level, format_string,...)
Ouptut a line of debugging information.
Definition: debug.h:37
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:386
GLAT_END
@ GLAT_END
So we know how many GLATs are there.
Definition: gamelog.h:24
GRFPresence
Information about the presence of a Grf at a certain point during gamelog history Note about missing ...
Definition: gamelog.cpp:179
GamelogOldver
void GamelogOldver()
Logs loading from savegame without gamelog.
Definition: gamelog.cpp:469
GamelogTestMode
void GamelogTestMode()
Finds last stored game mode or landscape.
Definition: gamelog.cpp:526
GamelogRevision
void GamelogRevision()
Logs a change in game revision.
Definition: gamelog.cpp:438
GLCT_SETTING
@ GLCT_SETTING
Non-networksafe setting value changed.
Definition: gamelog_internal.h:20
md5sumToString
char * md5sumToString(char *buf, const char *last, const uint8 md5sum[16])
Convert the md5sum to a hexadecimal string representation.
Definition: string.cpp:572
FGCM_EXACT
@ FGCM_EXACT
Only find Grfs matching md5sum.
Definition: newgrf_config.h:199
GRFConfig::filename
char * filename
Filename - either with or without full path.
Definition: newgrf_config.h:165
console_func.h
strecpy
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
Definition: string.cpp:113
LoggedChange
Contains information about one logged change.
Definition: gamelog_internal.h:36
CC_WARNING
static const TextColour CC_WARNING
Colour for warning lines.
Definition: console_type.h:25
free
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: stdafx.h:470
_tick_counter
uint64 _tick_counter
Ever incrementing tick counter for setting off various events.
Definition: date.cpp:30
strecat
char * strecat(char *dst, const char *src, const char *last)
Appends characters from one string to another.
Definition: string.cpp:85
_current_action
static LoggedAction * _current_action
current action we are logging, nullptr when there is no action active
Definition: gamelog.cpp:37
GLCT_GRFREM
@ GLCT_GRFREM
Added GRF.
Definition: gamelog_internal.h:22
GLCT_MODE
@ GLCT_MODE
Scenario editor x Game, different landscape.
Definition: gamelog_internal.h:17
GamelogActionType
GamelogActionType
The actions we log.
Definition: gamelog.h:16
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:402
GBUG_VEH_LENGTH
@ GBUG_VEH_LENGTH
Length of rail vehicle changes when not inside a depot.
Definition: newgrf_config.h:44
SGT_TTDP2
@ SGT_TTDP2
TTDP savegame in new format (data at SE border)
Definition: saveload.h:376
_sl_version
SaveLoadVersion _sl_version
the major savegame version identifier
Definition: saveload.cpp:66
GamelogInfo
void GamelogInfo(LoggedAction *gamelog_action, uint gamelog_actions, uint32 *last_ottd_rev, byte *ever_modified, bool *removed_newgrfs)
Get some basic information from the given gamelog.
Definition: gamelog.cpp:806
GLAT_START
@ GLAT_START
Game created.
Definition: gamelog.h:17
GetGamelogRevisionString
static const char * GetGamelogRevisionString()
Return the revision string for the current client version, for use in gamelog.
Definition: gamelog.cpp:44
LoggedAction
Contains information about one logged action that caused at least one logged change.
Definition: gamelog_internal.h:80
GCF_STATIC
@ GCF_STATIC
GRF file is used statically (can be used in any MP game)
Definition: newgrf_config.h:25
debug.h
GRFConfig::param
uint32 param[0x80]
GRF parameters.
Definition: newgrf_config.h:176
GRFList
List of GRFs using array of pointers instead of linked list.
Definition: gamelog.cpp:691
GamelogGRFBugReverse
bool GamelogGRFBugReverse(uint32 grfid, uint16 internal_id)
Logs GRF bug - rail vehicle has different length after reversing.
Definition: gamelog.cpp:569
SmallMap::Contains
bool Contains(const T &key) const
Tests whether a key is assigned in this map.
Definition: smallmap_type.hpp:79
IConsolePrint
void IConsolePrint(TextColour 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:94