OpenTTD: src/gamelog.cpp Source File

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

gamelog.cpp
Go to the documentation of this file.
1 /* $Id: gamelog.cpp 26509 2014-04-25 15:40:32Z rubidium $ */
2
3 /*
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/>.
8 */
9
12 #include "stdafx.h"
13 #include "saveload/saveload.h"
14 #include "string_func.h"
15 #include "settings_type.h"
16 #include "gamelog_internal.h"
17 #include "console_func.h"
18 #include "debug.h"
19 #include "date_func.h"
20 #include "rev.h"
21
22 #include <stdarg.h>
23
24 #include "safeguards.h"
25
26 extern const uint16 SAVEGAME_VERSION;
27
28 extern SavegameType _savegame_type;
29
30 extern uint32 _ttdp_version;
31 extern uint16 _sl_version;
32 extern byte _sl_minor_version;
33
34
35 static GamelogActionType _gamelog_action_type = GLAT_NONE;
36
37 LoggedAction *_gamelog_action = NULL;
38 uint _gamelog_actions = 0;
39 static LoggedAction *_current_action = NULL;
40
41
47 void GamelogStartAction(GamelogActionType at)
48 {
49 assert(_gamelog_action_type == GLAT_NONE); // do not allow starting new action without stopping the previous first
50 _gamelog_action_type = at;
51 }
52
56 void GamelogStopAction()
57 {
58 assert(_gamelog_action_type != GLAT_NONE); // nobody should try to stop if there is no action in progress
59
60 bool print = _current_action != NULL;
61
62 _current_action = NULL;
63 _gamelog_action_type = GLAT_NONE;
64
65 if (print) GamelogPrintDebug(5);
66 }
67
71 void GamelogFree(LoggedAction *gamelog_action, uint gamelog_actions)
72 {
73 for (uint i = 0; i < gamelog_actions; i++) {
74 const LoggedAction *la = &gamelog_action[i];
75 for (uint j = 0; j < la->changes; j++) {
76 const LoggedChange *lc = &la->change[j];
77 if (lc->ct == GLCT_SETTING) free(lc->setting.name);
78 }
79 free(la->change);
80 }
81
82 free(gamelog_action);
83 }
84
88 void GamelogReset()
89 {
90 assert(_gamelog_action_type == GLAT_NONE);
91 GamelogFree(_gamelog_action, _gamelog_actions);
92
93 _gamelog_action = NULL;
94 _gamelog_actions = 0;
95 _current_action = NULL;
96 }
97
107 static char *PrintGrfInfo(char *buf, const char *last, uint grfid, const uint8 *md5sum, const GRFConfig *gc)
108 {
109 char txt[40];
110
111 if (md5sum != NULL) {
112 md5sumToString(txt, lastof(txt), md5sum);
113 buf += seprintf(buf, last, "GRF ID %08X, checksum %s", BSWAP32(grfid), txt);
114 } else {
115 buf += seprintf(buf, last, "GRF ID %08X", BSWAP32(grfid));
116 }
117
118 if (gc != NULL) {
119 buf += seprintf(buf, last, ", filename: %s (md5sum matches)", gc->filename);
120 } else {
121 gc = FindGRFConfig(grfid, FGCM_ANY);
122 if (gc != NULL) {
123 buf += seprintf(buf, last, ", filename: %s (matches GRFID only)", gc->filename);
124 } else {
125 buf += seprintf(buf, last, ", unknown GRF");
126 }
127 }
128 return buf;
129 }
130
131
133 static const char * const la_text[] = {
134 "new game started",
135 "game loaded",
136 "GRF config changed",
137 "cheat was used",
138 "settings changed",
139 "GRF bug triggered",
140 "emergency savegame",
141 };
142
143 assert_compile(lengthof(la_text) == GLAT_END);
144
152 struct GRFPresence{
153 const GRFConfig *gc;
154 bool was_missing;
155
156 GRFPresence(const GRFConfig *gc) : gc(gc), was_missing(false) {}
157 };
158 typedef SmallMap<uint32, GRFPresence> GrfIDMapping;
159
164 void GamelogPrint(GamelogPrintProc *proc)
165 {
166 char buffer[1024];
167 GrfIDMapping grf_names;
168
169 proc("---- gamelog start ----");
170
171 const LoggedAction *laend = &_gamelog_action[_gamelog_actions];
172
173 for (const LoggedAction *la = _gamelog_action; la != laend; la++) {
174 assert((uint)la->at < GLAT_END);
175
176 seprintf(buffer, lastof(buffer), "Tick %u: %s", (uint)la->tick, la_text[(uint)la->at]);
177 proc(buffer);
178
179 const LoggedChange *lcend = &la->change[la->changes];
180
181 for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
182 char *buf = buffer;
183
184 switch (lc->ct) {
185 default: NOT_REACHED();
186 case GLCT_MODE:
187 buf += seprintf(buf, lastof(buffer), "New game mode: %u landscape: %u",
188 (uint)lc->mode.mode, (uint)lc->mode.landscape);
189 break;
190
191 case GLCT_REVISION:
192 buf += seprintf(buf, lastof(buffer), "Revision text changed to %s, savegame version %u, ",
193 lc->revision.text, lc->revision.slver);
194
195 switch (lc->revision.modified) {
196 case 0: buf += seprintf(buf, lastof(buffer), "not "); break;
197 case 1: buf += seprintf(buf, lastof(buffer), "maybe "); break;
198 default: break;
199 }
200
201 buf += seprintf(buf, lastof(buffer), "modified, _openttd_newgrf_version = 0x%08x", lc->revision.newgrf);
202 break;
203
204 case GLCT_OLDVER:
205 buf += seprintf(buf, lastof(buffer), "Conversion from ");
206 switch (lc->oldver.type) {
207 default: NOT_REACHED();
208 case SGT_OTTD:
209 buf += seprintf(buf, lastof(buffer), "OTTD savegame without gamelog: version %u, %u",
210 GB(lc->oldver.version, 8, 16), GB(lc->oldver.version, 0, 8));
211 break;
212
213 case SGT_TTO:
214 buf += seprintf(buf, lastof(buffer), "TTO savegame");
215 break;
216
217 case SGT_TTD:
218 buf += seprintf(buf, lastof(buffer), "TTD savegame");
219 break;
220
221 case SGT_TTDP1:
222 case SGT_TTDP2:
223 buf += seprintf(buf, lastof(buffer), "TTDP savegame, %s format",
224 lc->oldver.type == SGT_TTDP1 ? "old" : "new");
225 if (lc->oldver.version != 0) {
226 buf += seprintf(buf, lastof(buffer), ", TTDP version %u.%u.%u.%u",
227 GB(lc->oldver.version, 24, 8), GB(lc->oldver.version, 20, 4),
228 GB(lc->oldver.version, 16, 4), GB(lc->oldver.version, 0, 16));
229 }
230 break;
231 }
232 break;
233
234 case GLCT_SETTING:
235 buf += seprintf(buf, lastof(buffer), "Setting changed: %s : %d -> %d", lc->setting.name, lc->setting.oldval, lc->setting.newval);
236 break;
237
238 case GLCT_GRFADD: {
239 const GRFConfig *gc = FindGRFConfig(lc->grfadd.grfid, FGCM_EXACT, lc->grfadd.md5sum);
240 buf += seprintf(buf, lastof(buffer), "Added NewGRF: ");
241 buf = PrintGrfInfo(buf, lastof(buffer), lc->grfadd.grfid, lc->grfadd.md5sum, gc);
242 GrfIDMapping::Pair *gm = grf_names.Find(lc->grfrem.grfid);
243 if (gm != grf_names.End() && !gm->second.was_missing) buf += seprintf(buf, lastof(buffer), ". Gamelog inconsistency: GrfID was already added!");
244 grf_names[lc->grfadd.grfid] = gc;
245 break;
246 }
247
248 case GLCT_GRFREM: {
249 GrfIDMapping::Pair *gm = grf_names.Find(lc->grfrem.grfid);
250 buf += seprintf(buf, lastof(buffer), la->at == GLAT_LOAD ? "Missing NewGRF: " : "Removed NewGRF: ");
251 buf = PrintGrfInfo(buf, lastof(buffer), lc->grfrem.grfid, NULL, gm != grf_names.End() ? gm->second.gc : NULL);
252 if (gm == grf_names.End()) {
253 buf += seprintf(buf, lastof(buffer), ". Gamelog inconsistency: GrfID was never added!");
254 } else {
255 if (la->at == GLAT_LOAD) {
256 /* Missing grfs on load are not removed from the configuration */
257 gm->second.was_missing = true;
258 } else {
259 grf_names.Erase(gm);
260 }
261 }
262 break;
263 }
264
265 case GLCT_GRFCOMPAT: {
266 const GRFConfig *gc = FindGRFConfig(lc->grfadd.grfid, FGCM_EXACT, lc->grfadd.md5sum);
267 buf += seprintf(buf, lastof(buffer), "Compatible NewGRF loaded: ");
268 buf = PrintGrfInfo(buf, lastof(buffer), lc->grfcompat.grfid, lc->grfcompat.md5sum, gc);
269 if (!grf_names.Contains(lc->grfcompat.grfid)) buf += seprintf(buf, lastof(buffer), ". Gamelog inconsistency: GrfID was never added!");
270 grf_names[lc->grfcompat.grfid] = gc;
271 break;
272 }
273
274 case GLCT_GRFPARAM: {
275 GrfIDMapping::Pair *gm = grf_names.Find(lc->grfrem.grfid);
276 buf += seprintf(buf, lastof(buffer), "GRF parameter changed: ");
277 buf = PrintGrfInfo(buf, lastof(buffer), lc->grfparam.grfid, NULL, gm != grf_names.End() ? gm->second.gc : NULL);
278 if (gm == grf_names.End()) buf += seprintf(buf, lastof(buffer), ". Gamelog inconsistency: GrfID was never added!");
279 break;
280 }
281
282 case GLCT_GRFMOVE: {
283 GrfIDMapping::Pair *gm = grf_names.Find(lc->grfrem.grfid);
284 buf += seprintf(buf, lastof(buffer), "GRF order changed: %08X moved %d places %s",
285 BSWAP32(lc->grfmove.grfid), abs(lc->grfmove.offset), lc->grfmove.offset >= 0 ? "down" : "up" );
286 buf = PrintGrfInfo(buf, lastof(buffer), lc->grfmove.grfid, NULL, gm != grf_names.End() ? gm->second.gc : NULL);
287 if (gm == grf_names.End()) buf += seprintf(buf, lastof(buffer), ". Gamelog inconsistency: GrfID was never added!");
288 break;
289 }
290
291 case GLCT_GRFBUG: {
292 GrfIDMapping::Pair *gm = grf_names.Find(lc->grfrem.grfid);
293 switch (lc->grfbug.bug) {
294 default: NOT_REACHED();
295 case GBUG_VEH_LENGTH:
296 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);
297 break;
298 }
299 buf = PrintGrfInfo(buf, lastof(buffer), lc->grfbug.grfid, NULL, gm != grf_names.End() ? gm->second.gc : NULL);
300 if (gm == grf_names.End()) buf += seprintf(buf, lastof(buffer), ". Gamelog inconsistency: GrfID was never added!");
301 break;
302 }
303
304 case GLCT_EMERGENCY:
305 break;
306 }
307
308 proc(buffer);
309 }
310 }
311
312 proc("---- gamelog end ----");
313 }
314
315
316 static void GamelogPrintConsoleProc(const char *s)
317 {
318 IConsolePrint(CC_WARNING, s);
319 }
320
322 void GamelogPrintConsole()
323 {
324 GamelogPrint(&GamelogPrintConsoleProc);
325 }
326
327 static int _gamelog_print_level = 0;
328
329 static void GamelogPrintDebugProc(const char *s)
330 {
331 DEBUG(gamelog, _gamelog_print_level, "%s", s);
332 }
333
334
341 void GamelogPrintDebug(int level)
342 {
343 _gamelog_print_level = level;
344 GamelogPrint(&GamelogPrintDebugProc);
345 }
346
347
354 static LoggedChange *GamelogChange(GamelogChangeType ct)
355 {
356 if (_current_action == NULL) {
357 if (_gamelog_action_type == GLAT_NONE) return NULL;
358
359 _gamelog_action = ReallocT(_gamelog_action, _gamelog_actions + 1);
360 _current_action = &_gamelog_action[_gamelog_actions++];
361
362 _current_action->at = _gamelog_action_type;
363 _current_action->tick = _tick_counter;
364 _current_action->change = NULL;
365 _current_action->changes = 0;
366 }
367
368 _current_action->change = ReallocT(_current_action->change, _current_action->changes + 1);
369
370 LoggedChange *lc = &_current_action->change[_current_action->changes++];
371 lc->ct = ct;
372
373 return lc;
374 }
375
376
380 void GamelogEmergency()
381 {
382 /* Terminate any active action */
383 if (_gamelog_action_type != GLAT_NONE) GamelogStopAction();
384 GamelogStartAction(GLAT_EMERGENCY);
385 GamelogChange(GLCT_EMERGENCY);
386 GamelogStopAction();
387 }
388
392 bool GamelogTestEmergency()
393 {
394 const LoggedChange *emergency = NULL;
395
396 const LoggedAction *laend = &_gamelog_action[_gamelog_actions];
397 for (const LoggedAction *la = _gamelog_action; la != laend; la++) {
398 const LoggedChange *lcend = &la->change[la->changes];
399 for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
400 if (lc->ct == GLCT_EMERGENCY) emergency = lc;
401 }
402 }
403
404 return (emergency != NULL);
405 }
406
410 void GamelogRevision()
411 {
412 assert(_gamelog_action_type == GLAT_START || _gamelog_action_type == GLAT_LOAD);
413
414 LoggedChange *lc = GamelogChange(GLCT_REVISION);
415 if (lc == NULL) return;
416
417 memset(lc->revision.text, 0, sizeof(lc->revision.text));
418 strecpy(lc->revision.text, _openttd_revision, lastof(lc->revision.text));
419 lc->revision.slver = SAVEGAME_VERSION;
420 lc->revision.modified = _openttd_revision_modified;
421 lc->revision.newgrf = _openttd_newgrf_version;
422 }
423
427 void GamelogMode()
428 {
429 assert(_gamelog_action_type == GLAT_START || _gamelog_action_type == GLAT_LOAD || _gamelog_action_type == GLAT_CHEAT);
430
431 LoggedChange *lc = GamelogChange(GLCT_MODE);
432 if (lc == NULL) return;
433
434 lc->mode.mode = _game_mode;
435 lc->mode.landscape = _settings_game.game_creation.landscape;
436 }
437
441 void GamelogOldver()
442 {
443 assert(_gamelog_action_type == GLAT_LOAD);
444
445 LoggedChange *lc = GamelogChange(GLCT_OLDVER);
446 if (lc == NULL) return;
447
448 lc->oldver.type = _savegame_type;
449 lc->oldver.version = (_savegame_type == SGT_OTTD ? ((uint32)_sl_version << 8 | _sl_minor_version) : _ttdp_version);
450 }
451
458 void GamelogSetting(const char *name, int32 oldval, int32 newval)
459 {
460 assert(_gamelog_action_type == GLAT_SETTING);
461
462 LoggedChange *lc = GamelogChange(GLCT_SETTING);
463 if (lc == NULL) return;
464
465 lc->setting.name = stredup(name);
466 lc->setting.oldval = oldval;
467 lc->setting.newval = newval;
468 }
469
470
475 void GamelogTestRevision()
476 {
477 const LoggedChange *rev = NULL;
478
479 const LoggedAction *laend = &_gamelog_action[_gamelog_actions];
480 for (const LoggedAction *la = _gamelog_action; la != laend; la++) {
481 const LoggedChange *lcend = &la->change[la->changes];
482 for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
483 if (lc->ct == GLCT_REVISION) rev = lc;
484 }
485 }
486
487 if (rev == NULL || strcmp(rev->revision.text, _openttd_revision) != 0 ||
488 rev->revision.modified != _openttd_revision_modified ||
489 rev->revision.newgrf != _openttd_newgrf_version) {
490 GamelogRevision();
491 }
492 }
493
498 void GamelogTestMode()
499 {
500 const LoggedChange *mode = NULL;
501
502 const LoggedAction *laend = &_gamelog_action[_gamelog_actions];
503 for (const LoggedAction *la = _gamelog_action; la != laend; la++) {
504 const LoggedChange *lcend = &la->change[la->changes];
505 for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
506 if (lc->ct == GLCT_MODE) mode = lc;
507 }
508 }
509
510 if (mode == NULL || mode->mode.mode != _game_mode || mode->mode.landscape != _settings_game.game_creation.landscape) GamelogMode();
511 }
512
513
520 static void GamelogGRFBug(uint32 grfid, byte bug, uint64 data)
521 {
522 assert(_gamelog_action_type == GLAT_GRFBUG);
523
524 LoggedChange *lc = GamelogChange(GLCT_GRFBUG);
525 if (lc == NULL) return;
526
527 lc->grfbug.data = data;
528 lc->grfbug.grfid = grfid;
529 lc->grfbug.bug = bug;
530 }
531
541 bool GamelogGRFBugReverse(uint32 grfid, uint16 internal_id)
542 {
543 const LoggedAction *laend = &_gamelog_action[_gamelog_actions];
544 for (const LoggedAction *la = _gamelog_action; la != laend; la++) {
545 const LoggedChange *lcend = &la->change[la->changes];
546 for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
547 if (lc->ct == GLCT_GRFBUG && lc->grfbug.grfid == grfid &&
548 lc->grfbug.bug == GBUG_VEH_LENGTH && lc->grfbug.data == internal_id) {
549 return false;
550 }
551 }
552 }
553
554 GamelogStartAction(GLAT_GRFBUG);
555 GamelogGRFBug(grfid, GBUG_VEH_LENGTH, internal_id);
556 GamelogStopAction();
557
558 return true;
559 }
560
561
567 static inline bool IsLoggableGrfConfig(const GRFConfig *g)
568 {
569 return !HasBit(g->flags, GCF_STATIC) && g->status != GCS_NOT_FOUND;
570 }
571
576 void GamelogGRFRemove(uint32 grfid)
577 {
578 assert(_gamelog_action_type == GLAT_LOAD || _gamelog_action_type == GLAT_GRF);
579
580 LoggedChange *lc = GamelogChange(GLCT_GRFREM);
581 if (lc == NULL) return;
582
583 lc->grfrem.grfid = grfid;
584 }
585
590 void GamelogGRFAdd(const GRFConfig *newg)
591 {
592 assert(_gamelog_action_type == GLAT_LOAD || _gamelog_action_type == GLAT_START || _gamelog_action_type == GLAT_GRF);
593
594 if (!IsLoggableGrfConfig(newg)) return;
595
596 LoggedChange *lc = GamelogChange(GLCT_GRFADD);
597 if (lc == NULL) return;
598
599 lc->grfadd = newg->ident;
600 }
601
607 void GamelogGRFCompatible(const GRFIdentifier *newg)
608 {
609 assert(_gamelog_action_type == GLAT_LOAD || _gamelog_action_type == GLAT_GRF);
610
611 LoggedChange *lc = GamelogChange(GLCT_GRFCOMPAT);
612 if (lc == NULL) return;
613
614 lc->grfcompat = *newg;
615 }
616
622 static void GamelogGRFMove(uint32 grfid, int32 offset)
623 {
624 assert(_gamelog_action_type == GLAT_GRF);
625
626 LoggedChange *lc = GamelogChange(GLCT_GRFMOVE);
627 if (lc == NULL) return;
628
629 lc->grfmove.grfid = grfid;
630 lc->grfmove.offset = offset;
631 }
632
638 static void GamelogGRFParameters(uint32 grfid)
639 {
640 assert(_gamelog_action_type == GLAT_GRF);
641
642 LoggedChange *lc = GamelogChange(GLCT_GRFPARAM);
643 if (lc == NULL) return;
644
645 lc->grfparam.grfid = grfid;
646 }
647
653 void GamelogGRFAddList(const GRFConfig *newg)
654 {
655 assert(_gamelog_action_type == GLAT_START || _gamelog_action_type == GLAT_LOAD);
656
657 for (; newg != NULL; newg = newg->next) {
658 GamelogGRFAdd(newg);
659 }
660 }
661
663 struct GRFList {
664 uint n;
665 const GRFConfig *grf[];
666 };
667
672 static GRFList *GenerateGRFList(const GRFConfig *grfc)
673 {
674 uint n = 0;
675 for (const GRFConfig *g = grfc; g != NULL; g = g->next) {
676 if (IsLoggableGrfConfig(g)) n++;
677 }
678
679 GRFList *list = (GRFList*)MallocT<byte>(sizeof(GRFList) + n * sizeof(GRFConfig*));
680
681 list->n = 0;
682 for (const GRFConfig *g = grfc; g != NULL; g = g->next) {
683 if (IsLoggableGrfConfig(g)) list->grf[list->n++] = g;
684 }
685
686 return list;
687 }
688
694 void GamelogGRFUpdate(const GRFConfig *oldc, const GRFConfig *newc)
695 {
696 GRFList *ol = GenerateGRFList(oldc);
697 GRFList *nl = GenerateGRFList(newc);
698
699 uint o = 0, n = 0;
700
701 while (o < ol->n && n < nl->n) {
702 const GRFConfig *og = ol->grf[o];
703 const GRFConfig *ng = nl->grf[n];
704
705 if (og->ident.grfid != ng->ident.grfid) {
706 uint oi, ni;
707 for (oi = 0; oi < ol->n; oi++) {
708 if (ol->grf[oi]->ident.grfid == nl->grf[n]->ident.grfid) break;
709 }
710 if (oi < o) {
711 /* GRF was moved, this change has been logged already */
712 n++;
713 continue;
714 }
715 if (oi == ol->n) {
716 /* GRF couldn't be found in the OLD list, GRF was ADDED */
717 GamelogGRFAdd(nl->grf[n++]);
718 continue;
719 }
720 for (ni = 0; ni < nl->n; ni++) {
721 if (nl->grf[ni]->ident.grfid == ol->grf[o]->ident.grfid) break;
722 }
723 if (ni < n) {
724 /* GRF was moved, this change has been logged already */
725 o++;
726 continue;
727 }
728 if (ni == nl->n) {
729 /* GRF couldn't be found in the NEW list, GRF was REMOVED */
730 GamelogGRFRemove(ol->grf[o++]->ident.grfid);
731 continue;
732 }
733
734 /* o < oi < ol->n
735 * n < ni < nl->n */
736 assert(ni > n && ni < nl->n);
737 assert(oi > o && oi < ol->n);
738
739 ni -= n; // number of GRFs it was moved downwards
740 oi -= o; // number of GRFs it was moved upwards
741
742 if (ni >= oi) { // prefer the one that is moved further
743 /* GRF was moved down */
744 GamelogGRFMove(ol->grf[o++]->ident.grfid, ni);
745 } else {
746 GamelogGRFMove(nl->grf[n++]->ident.grfid, -(int)oi);
747 }
748 } else {
749 if (memcmp(og->ident.md5sum, ng->ident.md5sum, sizeof(og->ident.md5sum)) != 0) {
750 /* md5sum changed, probably loading 'compatible' GRF */
751 GamelogGRFCompatible(&nl->grf[n]->ident);
752 }
753
754 if (og->num_params != ng->num_params || memcmp(og->param, ng->param, og->num_params * sizeof(og->param[0])) != 0) {
755 GamelogGRFParameters(ol->grf[o]->ident.grfid);
756 }
757
758 o++;
759 n++;
760 }
761 }
762
763 while (o < ol->n) GamelogGRFRemove(ol->grf[o++]->ident.grfid); // remaining GRFs were removed ...
764 while (n < nl->n) GamelogGRFAdd (nl->grf[n++]); // ... or added
765
766 free(ol);
767 free(nl);
768 }
769
778 void GamelogInfo(LoggedAction *gamelog_action, uint gamelog_actions, uint32 *last_ottd_rev, byte *ever_modified, bool *removed_newgrfs)
779 {
780 const LoggedAction *laend = &gamelog_action[gamelog_actions];
781 for (const LoggedAction *la = gamelog_action; la != laend; la++) {
782 const LoggedChange *lcend = &la->change[la->changes];
783 for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
784 switch (lc->ct) {
785 default: break;
786
787 case GLCT_REVISION:
788 *last_ottd_rev = lc->revision.newgrf;
789 *ever_modified = max(*ever_modified, lc->revision.modified);
790 break;
791
792 case GLCT_GRFREM:
793 *removed_newgrfs = true;
794 break;
795 }
796 }
797 }
798 }