OpenTTD
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 
29 
30 extern uint32 _ttdp_version;
31 extern uint16 _sl_version;
32 extern byte _sl_minor_version;
33 
34 
36 
38 uint _gamelog_actions = 0;
39 static LoggedAction *_current_action = NULL;
40 
41 
48 {
49  assert(_gamelog_action_type == GLAT_NONE); // do not allow starting new action without stopping the previous first
51 }
52 
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;
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 
89 {
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 };
159 
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 {
319 }
320 
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 
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 
381 {
382  /* Terminate any active action */
387 }
388 
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 
411 {
413 
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 
428 {
430 
432  if (lc == NULL) return;
433 
434  lc->mode.mode = _game_mode;
435  lc->mode.landscape = _settings_game.game_creation.landscape;
436 }
437 
442 {
443  assert(_gamelog_action_type == GLAT_LOAD);
444 
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 {
461 
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 
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 
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 {
523 
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 
555  GamelogGRFBug(grfid, GBUG_VEH_LENGTH, internal_id);
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 {
579 
581  if (lc == NULL) return;
582 
583  lc->grfrem.grfid = grfid;
584 }
585 
590 void GamelogGRFAdd(const GRFConfig *newg)
591 {
593 
594  if (!IsLoggableGrfConfig(newg)) return;
595 
597  if (lc == NULL) return;
598 
599  lc->grfadd = newg->ident;
600 }
601 
608 {
610 
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 
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 
643  if (lc == NULL) return;
644 
645  lc->grfparam.grfid = grfid;
646 }
647 
653 void GamelogGRFAddList(const GRFConfig *newg)
654 {
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 }
void GamelogPrint(GamelogPrintProc *proc)
Prints active gamelog.
Definition: gamelog.cpp:164
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:77
GRF bug triggered.
bool GamelogTestEmergency()
Finds out if current game is a loaded emergency savegame.
Definition: gamelog.cpp:392
Loaded from savegame without logged data.
static GamelogActionType _gamelog_action_type
action to record if anything changes
Definition: gamelog.cpp:35
static LoggedAction * _current_action
current action we are logging, NULL when there is no action active
Definition: gamelog.cpp:39
bool Contains(const T &key) const
Tests whether a key is assigned in this map.
static void GamelogGRFParameters(uint32 grfid)
Logs change in GRF parameters.
Definition: gamelog.cpp:638
void GamelogEmergency()
Logs a emergency savegame.
Definition: gamelog.cpp:380
byte landscape
the landscape we&#39;re currently in
GamelogChangeType ct
Type of change logged in this struct.
const Pair * Find(const T &key) const
Finds given key in this map.
Functions related to dates.
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
Definition: string.cpp:398
Functions related to debugging.
uint16 _sl_version
the major savegame version identifier
Definition: saveload.cpp:275
static void GamelogGRFMove(uint32 grfid, int32 offset)
Logs changing GRF order.
Definition: gamelog.cpp:622
void GamelogStartAction(GamelogActionType at)
Stores information about new action, but doesn&#39;t allocate it Action is allocated only when there is a...
Definition: gamelog.cpp:47
Implementation of simple mapping class.
GRFStatus status
NOSAVE: GRFStatus, enum.
char * md5sumToString(char *buf, const char *last, const uint8 md5sum[16])
Convert the md5sum to a hexadecimal string representation.
Definition: string.cpp:416
static bool IsLoggableGrfConfig(const GRFConfig *g)
Decides if GRF should be logged.
Definition: gamelog.cpp:567
uint32 changes
Number of changes in this action.
void GamelogRevision()
Logs a change in game revision.
Definition: gamelog.cpp:410
GRF file is used statically (can be used in any MP game)
Definition: newgrf_config.h:26
GRF parameter changed.
TTD savegame (can be detected incorrectly)
Definition: saveload.h:41
List of GRFs using array of pointers instead of linked list.
Definition: gamelog.cpp:663
#define lastof(x)
Get the last element of an fixed size array.
Definition: depend.cpp:50
Removed GRF.
void GamelogPrintDebug(int level)
Prints gamelog to debug output.
Definition: gamelog.cpp:341
GRF file was not found in the local cache.
Definition: newgrf_config.h:38
Loading compatible GRF.
void GamelogOldver()
Logs loading from savegame without gamelog.
Definition: gamelog.cpp:441
SavegameType
Types of save games.
Definition: saveload.h:40
const GRFConfig * FindGRFConfig(uint32 grfid, FindGRFConfigMode mode, const uint8 *md5sum, uint32 desired_version)
Find a NewGRF in the scanned list.
Non-networksafe setting value changed.
GRFIdentifier ident
grfid and md5sum to uniquely identify newgrfs
static T max(const T a, const T b)
Returns the maximum of two values.
Definition: math_func.hpp:26
GRFIdentifier grfcompat
ID and new md5sum of changed GRF.
static LoggedChange * GamelogChange(GamelogChangeType ct)
Allocates new LoggedChange and new LoggedAction if needed.
Definition: gamelog.cpp:354
Basic data to distinguish a GRF.
Definition: newgrf_config.h:84
uint _gamelog_actions
number of actions
Definition: gamelog.cpp:38
const T * End() const
Get the pointer behind the last valid item (const)
Cheat was used.
Definition: gamelog.h:22
static void GamelogGRFBug(uint32 grfid, byte bug, uint64 data)
Logs triggered GRF bug.
Definition: gamelog.cpp:520
struct GRFConfig * next
NOSAVE: Next item in the linked list.
GamelogActionType
The actions we log.
Definition: gamelog.h:18
GRFIdentifier grfadd
ID and md5sum of added GRF.
const uint16 SAVEGAME_VERSION
current savegame version
GRF bug was triggered.
Definition: gamelog.h:24
Game created.
Definition: gamelog.h:19
TTO savegame.
Definition: saveload.h:45
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:778
Functions related to low-level strings.
void GamelogSetting(const char *name, int32 oldval, int32 newval)
Logs change in game settings.
Definition: gamelog.cpp:458
void GamelogReset()
Resets and frees all memory allocated - used before loading or starting a new game.
Definition: gamelog.cpp:88
Functions/types related to saving and loading games.
uint8 num_params
Number of used parameters.
static int _gamelog_print_level
gamelog debug level we need to print stuff
Definition: gamelog.cpp:327
Contains information about one logged action that caused at least one logged change.
void GamelogPrintConsole()
Print the gamelog data to the console.
Definition: gamelog.cpp:322
void GamelogFree(LoggedAction *gamelog_action, uint gamelog_actions)
Frees the memory allocated by a gamelog.
Definition: gamelog.cpp:71
Information about GRF, used in the game and (part of it) in savegames.
Added GRF.
Simple pair of data.
void IConsolePrint(TextColour colour_code, const char *string)
Handle the printing of text entered into the console or redirected there by any other means...
Definition: console.cpp:88
Types related to global configuration settings.
void GamelogGRFAdd(const GRFConfig *newg)
Logs adding of a GRF.
Definition: gamelog.cpp:590
void GamelogMode()
Logs a change in game mode (scenario editor or game)
Definition: gamelog.cpp:427
Definition of base types and functions in a cross-platform compatible way.
byte _sl_minor_version
the minor savegame version, DO NOT USE!
Definition: saveload.cpp:276
Information about the presence of a Grf at a certain point during gamelog history Note about missing ...
Definition: gamelog.cpp:152
A number of safeguards to prevent using unsafe methods.
Game loaded.
Definition: gamelog.h:20
byte mode
new game mode - Editor x Game
bool was_missing
Grf was missing during some gameload in the past.
Definition: gamelog.cpp:154
TTDP savegame in new format (data at SE border)
Definition: saveload.h:43
Emergency savegame.
uint8 flags
NOSAVE: GCF_Flags, bitset.
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
Definition: string.cpp:126
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:113
Console functions used outside of the console code.
uint16 tick
Tick when it happened.
SavegameType _savegame_type
type of savegame we are loading
Definition: saveload.cpp:271
void GamelogGRFAddList(const GRFConfig *newg)
Logs adding of list of GRFs.
Definition: gamelog.cpp:653
Scenario editor x Game, different landscape.
So we know how many GLATs are there.
Definition: gamelog.h:26
void GamelogGRFCompatible(const GRFIdentifier *newg)
Logs loading compatible GRF (the same ID, but different MD5 hash)
Definition: gamelog.cpp:607
OTTD savegame.
Definition: saveload.h:44
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:42
void GamelogTestRevision()
Finds out if current revision is different than last revision stored in the savegame.
Definition: gamelog.cpp:475
uint32 _ttdp_version
version of TTDP savegame (if applicable)
Definition: saveload.cpp:274
Emergency savegame.
Definition: gamelog.h:25
Changed game revision string.
GRF changed.
Definition: gamelog.h:21
void GamelogStopAction()
Stops logging of any changes.
Definition: gamelog.cpp:56
#define DEBUG(name, level,...)
Output a line of debugging information.
Definition: debug.h:39
LoggedAction * _gamelog_action
first logged action
Definition: gamelog.cpp:37
uint16 _tick_counter
Ever incrementing (and sometimes wrapping) tick counter for setting off various events.
Definition: date.cpp:30
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:107
Setting changed.
Definition: gamelog.h:23
void Erase(Pair *pair)
Removes given pair from this map.
GamelogActionType at
Type of action.
TTDP savegame ( -//- ) (data at NW border)
Definition: saveload.h:42
GamelogChangeType
Type of logged change.
LoggedChange * change
First logged change in this action.
Contains information about one logged change.
static T abs(const T a)
Returns the absolute value of (scalar) variable.
Definition: math_func.hpp:83
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
bool GamelogGRFBugReverse(uint32 grfid, uint16 internal_id)
Logs GRF bug - rail vehicle has different length after reversing.
Definition: gamelog.cpp:541
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
Definition: depend.cpp:68
char * filename
Filename - either with or without full path.
const GRFConfig * gc
GRFConfig, if known.
Definition: gamelog.cpp:153
void GamelogGRFRemove(uint32 grfid)
Logs removal of a GRF.
Definition: gamelog.cpp:576
uint32 grfid
GRF ID (defined by Action 0x08)
Definition: newgrf_config.h:85
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: depend.cpp:114
declaration of OTTD revision dependent variables
Declaration shared among gamelog.cpp and saveload/gamelog_sl.cpp.
uint32 param[0x80]
GRF parameters.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
No logging active; in savegames, end of list.
Definition: gamelog.h:27
GameCreationSettings game_creation
settings used during the creation of a game (map)
void GamelogTestMode()
Finds last stored game mode or landscape.
Definition: gamelog.cpp:498
static uint32 BSWAP32(uint32 x)
Perform a 32 bits endianness bitswap on x.
Length of rail vehicle changes when not inside a depot.
Definition: newgrf_config.h:45
void GamelogPrintProc(const char *s)
Callback for printing text.
Definition: gamelog.h:40
uint8 md5sum[16]
MD5 checksum of file to distinguish files with the same GRF ID (eg. newer version of GRF) ...
Definition: newgrf_config.h:86
Only find Grfs matching md5sum.
GRF order changed.
void GamelogGRFUpdate(const GRFConfig *oldc, const GRFConfig *newc)
Compares two NewGRF lists and logs any change.
Definition: gamelog.cpp:694
static const TextColour CC_WARNING
Colour for warning lines.
Definition: console_type.h:27
static const char *const la_text[]
Text messages for various logged actions.
Definition: gamelog.cpp:133
static GRFList * GenerateGRFList(const GRFConfig *grfc)
Generates GRFList.
Definition: gamelog.cpp:672
Use first found.