OpenTTD
gamelog.cpp
Go to the documentation of this file.
1 /* $Id$ */
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 SaveLoadVersion SAVEGAME_VERSION;
27 
29 
30 extern uint32 _ttdp_version;
32 extern byte _sl_minor_version;
33 
34 
36 
38 uint _gamelog_actions = 0;
39 static LoggedAction *_current_action = NULL;
40 
41 
46 static const char * GetGamelogRevisionString()
47 {
48  /* Allocate a buffer larger than necessary (git revision hash is 40 bytes) to avoid truncation later */
49  static char gamelog_revision[48] = { 0 };
50  assert_compile(lengthof(gamelog_revision) > GAMELOG_REVISION_LENGTH);
51 
52  if (IsReleasedVersion()) {
53  return _openttd_revision;
54  } else if (gamelog_revision[0] == 0) {
55  /* Prefix character indication revision status */
56  assert(_openttd_revision_modified < 3);
57  gamelog_revision[0] = "gum"[_openttd_revision_modified]; // g = "git", u = "unknown", m = "modified"
58  /* Append the revision hash */
59  strecat(gamelog_revision, _openttd_revision_hash, lastof(gamelog_revision));
60  /* Truncate string to GAMELOG_REVISION_LENGTH bytes */
61  gamelog_revision[GAMELOG_REVISION_LENGTH - 1] = '\0';
62  }
63  return gamelog_revision;
64 }
65 
72 {
73  assert(_gamelog_action_type == GLAT_NONE); // do not allow starting new action without stopping the previous first
75 }
76 
81 {
82  assert(_gamelog_action_type != GLAT_NONE); // nobody should try to stop if there is no action in progress
83 
84  bool print = _current_action != NULL;
85 
86  _current_action = NULL;
88 
89  if (print) GamelogPrintDebug(5);
90 }
91 
95 void GamelogFree(LoggedAction *gamelog_action, uint gamelog_actions)
96 {
97  for (uint i = 0; i < gamelog_actions; i++) {
98  const LoggedAction *la = &gamelog_action[i];
99  for (uint j = 0; j < la->changes; j++) {
100  const LoggedChange *lc = &la->change[j];
101  if (lc->ct == GLCT_SETTING) free(lc->setting.name);
102  }
103  free(la->change);
104  }
105 
106  free(gamelog_action);
107 }
108 
113 {
114  assert(_gamelog_action_type == GLAT_NONE);
115  GamelogFree(_gamelog_action, _gamelog_actions);
116 
117  _gamelog_action = NULL;
118  _gamelog_actions = 0;
119  _current_action = NULL;
120 }
121 
131 static char *PrintGrfInfo(char *buf, const char *last, uint grfid, const uint8 *md5sum, const GRFConfig *gc)
132 {
133  char txt[40];
134 
135  if (md5sum != NULL) {
136  md5sumToString(txt, lastof(txt), md5sum);
137  buf += seprintf(buf, last, "GRF ID %08X, checksum %s", BSWAP32(grfid), txt);
138  } else {
139  buf += seprintf(buf, last, "GRF ID %08X", BSWAP32(grfid));
140  }
141 
142  if (gc != NULL) {
143  buf += seprintf(buf, last, ", filename: %s (md5sum matches)", gc->filename);
144  } else {
145  gc = FindGRFConfig(grfid, FGCM_ANY);
146  if (gc != NULL) {
147  buf += seprintf(buf, last, ", filename: %s (matches GRFID only)", gc->filename);
148  } else {
149  buf += seprintf(buf, last, ", unknown GRF");
150  }
151  }
152  return buf;
153 }
154 
155 
157 static const char * const la_text[] = {
158  "new game started",
159  "game loaded",
160  "GRF config changed",
161  "cheat was used",
162  "settings changed",
163  "GRF bug triggered",
164  "emergency savegame",
165 };
166 
167 assert_compile(lengthof(la_text) == GLAT_END);
168 
176 struct GRFPresence{
177  const GRFConfig *gc;
178  bool was_missing;
179 
180  GRFPresence(const GRFConfig *gc) : gc(gc), was_missing(false) {}
181 };
183 
189 {
190  char buffer[1024];
191  GrfIDMapping grf_names;
192 
193  proc("---- gamelog start ----");
194 
195  const LoggedAction *laend = &_gamelog_action[_gamelog_actions];
196 
197  for (const LoggedAction *la = _gamelog_action; la != laend; la++) {
198  assert((uint)la->at < GLAT_END);
199 
200  seprintf(buffer, lastof(buffer), "Tick %u: %s", (uint)la->tick, la_text[(uint)la->at]);
201  proc(buffer);
202 
203  const LoggedChange *lcend = &la->change[la->changes];
204 
205  for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
206  char *buf = buffer;
207 
208  switch (lc->ct) {
209  default: NOT_REACHED();
210  case GLCT_MODE:
211  buf += seprintf(buf, lastof(buffer), "New game mode: %u landscape: %u",
212  (uint)lc->mode.mode, (uint)lc->mode.landscape);
213  break;
214 
215  case GLCT_REVISION:
216  buf += seprintf(buf, lastof(buffer), "Revision text changed to %s, savegame version %u, ",
217  lc->revision.text, lc->revision.slver);
218 
219  switch (lc->revision.modified) {
220  case 0: buf += seprintf(buf, lastof(buffer), "not "); break;
221  case 1: buf += seprintf(buf, lastof(buffer), "maybe "); break;
222  default: break;
223  }
224 
225  buf += seprintf(buf, lastof(buffer), "modified, _openttd_newgrf_version = 0x%08x", lc->revision.newgrf);
226  break;
227 
228  case GLCT_OLDVER:
229  buf += seprintf(buf, lastof(buffer), "Conversion from ");
230  switch (lc->oldver.type) {
231  default: NOT_REACHED();
232  case SGT_OTTD:
233  buf += seprintf(buf, lastof(buffer), "OTTD savegame without gamelog: version %u, %u",
234  GB(lc->oldver.version, 8, 16), GB(lc->oldver.version, 0, 8));
235  break;
236 
237  case SGT_TTO:
238  buf += seprintf(buf, lastof(buffer), "TTO savegame");
239  break;
240 
241  case SGT_TTD:
242  buf += seprintf(buf, lastof(buffer), "TTD savegame");
243  break;
244 
245  case SGT_TTDP1:
246  case SGT_TTDP2:
247  buf += seprintf(buf, lastof(buffer), "TTDP savegame, %s format",
248  lc->oldver.type == SGT_TTDP1 ? "old" : "new");
249  if (lc->oldver.version != 0) {
250  buf += seprintf(buf, lastof(buffer), ", TTDP version %u.%u.%u.%u",
251  GB(lc->oldver.version, 24, 8), GB(lc->oldver.version, 20, 4),
252  GB(lc->oldver.version, 16, 4), GB(lc->oldver.version, 0, 16));
253  }
254  break;
255  }
256  break;
257 
258  case GLCT_SETTING:
259  buf += seprintf(buf, lastof(buffer), "Setting changed: %s : %d -> %d", lc->setting.name, lc->setting.oldval, lc->setting.newval);
260  break;
261 
262  case GLCT_GRFADD: {
263  const GRFConfig *gc = FindGRFConfig(lc->grfadd.grfid, FGCM_EXACT, lc->grfadd.md5sum);
264  buf += seprintf(buf, lastof(buffer), "Added NewGRF: ");
265  buf = PrintGrfInfo(buf, lastof(buffer), lc->grfadd.grfid, lc->grfadd.md5sum, gc);
266  GrfIDMapping::Pair *gm = grf_names.Find(lc->grfrem.grfid);
267  if (gm != grf_names.End() && !gm->second.was_missing) buf += seprintf(buf, lastof(buffer), ". Gamelog inconsistency: GrfID was already added!");
268  grf_names[lc->grfadd.grfid] = gc;
269  break;
270  }
271 
272  case GLCT_GRFREM: {
273  GrfIDMapping::Pair *gm = grf_names.Find(lc->grfrem.grfid);
274  buf += seprintf(buf, lastof(buffer), la->at == GLAT_LOAD ? "Missing NewGRF: " : "Removed NewGRF: ");
275  buf = PrintGrfInfo(buf, lastof(buffer), lc->grfrem.grfid, NULL, gm != grf_names.End() ? gm->second.gc : NULL);
276  if (gm == grf_names.End()) {
277  buf += seprintf(buf, lastof(buffer), ". Gamelog inconsistency: GrfID was never added!");
278  } else {
279  if (la->at == GLAT_LOAD) {
280  /* Missing grfs on load are not removed from the configuration */
281  gm->second.was_missing = true;
282  } else {
283  grf_names.Erase(gm);
284  }
285  }
286  break;
287  }
288 
289  case GLCT_GRFCOMPAT: {
290  const GRFConfig *gc = FindGRFConfig(lc->grfadd.grfid, FGCM_EXACT, lc->grfadd.md5sum);
291  buf += seprintf(buf, lastof(buffer), "Compatible NewGRF loaded: ");
292  buf = PrintGrfInfo(buf, lastof(buffer), lc->grfcompat.grfid, lc->grfcompat.md5sum, gc);
293  if (!grf_names.Contains(lc->grfcompat.grfid)) buf += seprintf(buf, lastof(buffer), ". Gamelog inconsistency: GrfID was never added!");
294  grf_names[lc->grfcompat.grfid] = gc;
295  break;
296  }
297 
298  case GLCT_GRFPARAM: {
299  GrfIDMapping::Pair *gm = grf_names.Find(lc->grfrem.grfid);
300  buf += seprintf(buf, lastof(buffer), "GRF parameter changed: ");
301  buf = PrintGrfInfo(buf, lastof(buffer), lc->grfparam.grfid, NULL, gm != grf_names.End() ? gm->second.gc : NULL);
302  if (gm == grf_names.End()) buf += seprintf(buf, lastof(buffer), ". Gamelog inconsistency: GrfID was never added!");
303  break;
304  }
305 
306  case GLCT_GRFMOVE: {
307  GrfIDMapping::Pair *gm = grf_names.Find(lc->grfrem.grfid);
308  buf += seprintf(buf, lastof(buffer), "GRF order changed: %08X moved %d places %s",
309  BSWAP32(lc->grfmove.grfid), abs(lc->grfmove.offset), lc->grfmove.offset >= 0 ? "down" : "up" );
310  buf = PrintGrfInfo(buf, lastof(buffer), lc->grfmove.grfid, NULL, gm != grf_names.End() ? gm->second.gc : NULL);
311  if (gm == grf_names.End()) buf += seprintf(buf, lastof(buffer), ". Gamelog inconsistency: GrfID was never added!");
312  break;
313  }
314 
315  case GLCT_GRFBUG: {
316  GrfIDMapping::Pair *gm = grf_names.Find(lc->grfrem.grfid);
317  switch (lc->grfbug.bug) {
318  default: NOT_REACHED();
319  case GBUG_VEH_LENGTH:
320  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);
321  break;
322  }
323  buf = PrintGrfInfo(buf, lastof(buffer), lc->grfbug.grfid, NULL, gm != grf_names.End() ? gm->second.gc : NULL);
324  if (gm == grf_names.End()) buf += seprintf(buf, lastof(buffer), ". Gamelog inconsistency: GrfID was never added!");
325  break;
326  }
327 
328  case GLCT_EMERGENCY:
329  break;
330  }
331 
332  proc(buffer);
333  }
334  }
335 
336  proc("---- gamelog end ----");
337 }
338 
339 
340 static void GamelogPrintConsoleProc(const char *s)
341 {
343 }
344 
347 {
348  GamelogPrint(&GamelogPrintConsoleProc);
349 }
350 
351 static int _gamelog_print_level = 0;
352 
353 static void GamelogPrintDebugProc(const char *s)
354 {
355  DEBUG(gamelog, _gamelog_print_level, "%s", s);
356 }
357 
358 
365 void GamelogPrintDebug(int level)
366 {
367  _gamelog_print_level = level;
368  GamelogPrint(&GamelogPrintDebugProc);
369 }
370 
371 
379 {
380  if (_current_action == NULL) {
381  if (_gamelog_action_type == GLAT_NONE) return NULL;
382 
383  _gamelog_action = ReallocT(_gamelog_action, _gamelog_actions + 1);
384  _current_action = &_gamelog_action[_gamelog_actions++];
385 
386  _current_action->at = _gamelog_action_type;
387  _current_action->tick = _tick_counter;
388  _current_action->change = NULL;
389  _current_action->changes = 0;
390  }
391 
392  _current_action->change = ReallocT(_current_action->change, _current_action->changes + 1);
393 
394  LoggedChange *lc = &_current_action->change[_current_action->changes++];
395  lc->ct = ct;
396 
397  return lc;
398 }
399 
400 
405 {
406  /* Terminate any active action */
411 }
412 
417 {
418  const LoggedChange *emergency = NULL;
419 
420  const LoggedAction *laend = &_gamelog_action[_gamelog_actions];
421  for (const LoggedAction *la = _gamelog_action; la != laend; la++) {
422  const LoggedChange *lcend = &la->change[la->changes];
423  for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
424  if (lc->ct == GLCT_EMERGENCY) emergency = lc;
425  }
426  }
427 
428  return (emergency != NULL);
429 }
430 
435 {
437 
439  if (lc == NULL) return;
440 
441  memset(lc->revision.text, 0, sizeof(lc->revision.text));
442  strecpy(lc->revision.text, GetGamelogRevisionString(), lastof(lc->revision.text));
443  lc->revision.slver = SAVEGAME_VERSION;
444  lc->revision.modified = _openttd_revision_modified;
445  lc->revision.newgrf = _openttd_newgrf_version;
446 }
447 
452 {
454 
456  if (lc == NULL) return;
457 
458  lc->mode.mode = _game_mode;
459  lc->mode.landscape = _settings_game.game_creation.landscape;
460 }
461 
466 {
467  assert(_gamelog_action_type == GLAT_LOAD);
468 
470  if (lc == NULL) return;
471 
472  lc->oldver.type = _savegame_type;
473  lc->oldver.version = (_savegame_type == SGT_OTTD ? ((uint32)_sl_version << 8 | _sl_minor_version) : _ttdp_version);
474 }
475 
482 void GamelogSetting(const char *name, int32 oldval, int32 newval)
483 {
485 
487  if (lc == NULL) return;
488 
489  lc->setting.name = stredup(name);
490  lc->setting.oldval = oldval;
491  lc->setting.newval = newval;
492 }
493 
494 
500 {
501  const LoggedChange *rev = NULL;
502 
503  const LoggedAction *laend = &_gamelog_action[_gamelog_actions];
504  for (const LoggedAction *la = _gamelog_action; la != laend; la++) {
505  const LoggedChange *lcend = &la->change[la->changes];
506  for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
507  if (lc->ct == GLCT_REVISION) rev = lc;
508  }
509  }
510 
511  if (rev == NULL || strcmp(rev->revision.text, GetGamelogRevisionString()) != 0 ||
512  rev->revision.modified != _openttd_revision_modified ||
513  rev->revision.newgrf != _openttd_newgrf_version) {
514  GamelogRevision();
515  }
516 }
517 
523 {
524  const LoggedChange *mode = NULL;
525 
526  const LoggedAction *laend = &_gamelog_action[_gamelog_actions];
527  for (const LoggedAction *la = _gamelog_action; la != laend; la++) {
528  const LoggedChange *lcend = &la->change[la->changes];
529  for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
530  if (lc->ct == GLCT_MODE) mode = lc;
531  }
532  }
533 
534  if (mode == NULL || mode->mode.mode != _game_mode || mode->mode.landscape != _settings_game.game_creation.landscape) GamelogMode();
535 }
536 
537 
544 static void GamelogGRFBug(uint32 grfid, byte bug, uint64 data)
545 {
547 
549  if (lc == NULL) return;
550 
551  lc->grfbug.data = data;
552  lc->grfbug.grfid = grfid;
553  lc->grfbug.bug = bug;
554 }
555 
565 bool GamelogGRFBugReverse(uint32 grfid, uint16 internal_id)
566 {
567  const LoggedAction *laend = &_gamelog_action[_gamelog_actions];
568  for (const LoggedAction *la = _gamelog_action; la != laend; la++) {
569  const LoggedChange *lcend = &la->change[la->changes];
570  for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
571  if (lc->ct == GLCT_GRFBUG && lc->grfbug.grfid == grfid &&
572  lc->grfbug.bug == GBUG_VEH_LENGTH && lc->grfbug.data == internal_id) {
573  return false;
574  }
575  }
576  }
577 
579  GamelogGRFBug(grfid, GBUG_VEH_LENGTH, internal_id);
581 
582  return true;
583 }
584 
585 
591 static inline bool IsLoggableGrfConfig(const GRFConfig *g)
592 {
593  return !HasBit(g->flags, GCF_STATIC) && g->status != GCS_NOT_FOUND;
594 }
595 
600 void GamelogGRFRemove(uint32 grfid)
601 {
603 
605  if (lc == NULL) return;
606 
607  lc->grfrem.grfid = grfid;
608 }
609 
614 void GamelogGRFAdd(const GRFConfig *newg)
615 {
617 
618  if (!IsLoggableGrfConfig(newg)) return;
619 
621  if (lc == NULL) return;
622 
623  lc->grfadd = newg->ident;
624 }
625 
632 {
634 
636  if (lc == NULL) return;
637 
638  lc->grfcompat = *newg;
639 }
640 
646 static void GamelogGRFMove(uint32 grfid, int32 offset)
647 {
648  assert(_gamelog_action_type == GLAT_GRF);
649 
651  if (lc == NULL) return;
652 
653  lc->grfmove.grfid = grfid;
654  lc->grfmove.offset = offset;
655 }
656 
662 static void GamelogGRFParameters(uint32 grfid)
663 {
664  assert(_gamelog_action_type == GLAT_GRF);
665 
667  if (lc == NULL) return;
668 
669  lc->grfparam.grfid = grfid;
670 }
671 
677 void GamelogGRFAddList(const GRFConfig *newg)
678 {
680 
681  for (; newg != NULL; newg = newg->next) {
682  GamelogGRFAdd(newg);
683  }
684 }
685 
687 struct GRFList {
688  uint n;
689  const GRFConfig *grf[];
690 };
691 
696 static GRFList *GenerateGRFList(const GRFConfig *grfc)
697 {
698  uint n = 0;
699  for (const GRFConfig *g = grfc; g != NULL; g = g->next) {
700  if (IsLoggableGrfConfig(g)) n++;
701  }
702 
703  GRFList *list = (GRFList*)MallocT<byte>(sizeof(GRFList) + n * sizeof(GRFConfig*));
704 
705  list->n = 0;
706  for (const GRFConfig *g = grfc; g != NULL; g = g->next) {
707  if (IsLoggableGrfConfig(g)) list->grf[list->n++] = g;
708  }
709 
710  return list;
711 }
712 
718 void GamelogGRFUpdate(const GRFConfig *oldc, const GRFConfig *newc)
719 {
720  GRFList *ol = GenerateGRFList(oldc);
721  GRFList *nl = GenerateGRFList(newc);
722 
723  uint o = 0, n = 0;
724 
725  while (o < ol->n && n < nl->n) {
726  const GRFConfig *og = ol->grf[o];
727  const GRFConfig *ng = nl->grf[n];
728 
729  if (og->ident.grfid != ng->ident.grfid) {
730  uint oi, ni;
731  for (oi = 0; oi < ol->n; oi++) {
732  if (ol->grf[oi]->ident.grfid == nl->grf[n]->ident.grfid) break;
733  }
734  if (oi < o) {
735  /* GRF was moved, this change has been logged already */
736  n++;
737  continue;
738  }
739  if (oi == ol->n) {
740  /* GRF couldn't be found in the OLD list, GRF was ADDED */
741  GamelogGRFAdd(nl->grf[n++]);
742  continue;
743  }
744  for (ni = 0; ni < nl->n; ni++) {
745  if (nl->grf[ni]->ident.grfid == ol->grf[o]->ident.grfid) break;
746  }
747  if (ni < n) {
748  /* GRF was moved, this change has been logged already */
749  o++;
750  continue;
751  }
752  if (ni == nl->n) {
753  /* GRF couldn't be found in the NEW list, GRF was REMOVED */
754  GamelogGRFRemove(ol->grf[o++]->ident.grfid);
755  continue;
756  }
757 
758  /* o < oi < ol->n
759  * n < ni < nl->n */
760  assert(ni > n && ni < nl->n);
761  assert(oi > o && oi < ol->n);
762 
763  ni -= n; // number of GRFs it was moved downwards
764  oi -= o; // number of GRFs it was moved upwards
765 
766  if (ni >= oi) { // prefer the one that is moved further
767  /* GRF was moved down */
768  GamelogGRFMove(ol->grf[o++]->ident.grfid, ni);
769  } else {
770  GamelogGRFMove(nl->grf[n++]->ident.grfid, -(int)oi);
771  }
772  } else {
773  if (memcmp(og->ident.md5sum, ng->ident.md5sum, sizeof(og->ident.md5sum)) != 0) {
774  /* md5sum changed, probably loading 'compatible' GRF */
775  GamelogGRFCompatible(&nl->grf[n]->ident);
776  }
777 
778  if (og->num_params != ng->num_params || memcmp(og->param, ng->param, og->num_params * sizeof(og->param[0])) != 0) {
779  GamelogGRFParameters(ol->grf[o]->ident.grfid);
780  }
781 
782  o++;
783  n++;
784  }
785  }
786 
787  while (o < ol->n) GamelogGRFRemove(ol->grf[o++]->ident.grfid); // remaining GRFs were removed ...
788  while (n < nl->n) GamelogGRFAdd (nl->grf[n++]); // ... or added
789 
790  free(ol);
791  free(nl);
792 }
793 
802 void GamelogInfo(LoggedAction *gamelog_action, uint gamelog_actions, uint32 *last_ottd_rev, byte *ever_modified, bool *removed_newgrfs)
803 {
804  const LoggedAction *laend = &gamelog_action[gamelog_actions];
805  for (const LoggedAction *la = gamelog_action; la != laend; la++) {
806  const LoggedChange *lcend = &la->change[la->changes];
807  for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
808  switch (lc->ct) {
809  default: break;
810 
811  case GLCT_REVISION:
812  *last_ottd_rev = lc->revision.newgrf;
813  *ever_modified = max(*ever_modified, lc->revision.modified);
814  break;
815 
816  case GLCT_GRFREM:
817  *removed_newgrfs = true;
818  break;
819  }
820  }
821  }
822 }
void GamelogPrint(GamelogPrintProc *proc)
Prints active gamelog.
Definition: gamelog.cpp:188
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:416
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:662
void GamelogEmergency()
Logs a emergency savegame.
Definition: gamelog.cpp:404
byte landscape
the landscape we&#39;re currently in
GamelogChangeType ct
Type of change logged in this struct.
static char * strecat(char *dst, const char *src, const char *last)
Appends characters from one string to another.
Definition: depend.cpp:99
SaveLoadVersion
SaveLoad versions Previous savegame versions, the trunk revision where they were introduced and the r...
Definition: saveload.h:31
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:409
Functions related to debugging.
static void GamelogGRFMove(uint32 grfid, int32 offset)
Logs changing GRF order.
Definition: gamelog.cpp:646
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:71
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:427
SaveLoadVersion _sl_version
the major savegame version identifier
Definition: saveload.cpp:62
static bool IsLoggableGrfConfig(const GRFConfig *g)
Decides if GRF should be logged.
Definition: gamelog.cpp:591
uint32 changes
Number of changes in this action.
void GamelogRevision()
Logs a change in game revision.
Definition: gamelog.cpp:434
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:321
List of GRFs using array of pointers instead of linked list.
Definition: gamelog.cpp:687
#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:365
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:465
SavegameType
Types of save games.
Definition: saveload.h:320
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:378
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:544
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.
GRF bug was triggered.
Definition: gamelog.h:24
Game created.
Definition: gamelog.h:19
TTO savegame.
Definition: saveload.h:325
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:802
Functions related to low-level strings.
void GamelogSetting(const char *name, int32 oldval, int32 newval)
Logs change in game settings.
Definition: gamelog.cpp:482
void GamelogReset()
Resets and frees all memory allocated - used before loading or starting a new game.
Definition: gamelog.cpp:112
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:351
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:346
void GamelogFree(LoggedAction *gamelog_action, uint gamelog_actions)
Frees the memory allocated by a gamelog.
Definition: gamelog.cpp:95
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:614
void GamelogMode()
Logs a change in game mode (scenario editor or game)
Definition: gamelog.cpp:451
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:63
Information about the presence of a Grf at a certain point during gamelog history Note about missing ...
Definition: gamelog.cpp:176
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:178
TTDP savegame in new format (data at SE border)
Definition: saveload.h:323
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:138
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:58
void GamelogGRFAddList(const GRFConfig *newg)
Logs adding of list of GRFs.
Definition: gamelog.cpp:677
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:631
const SaveLoadVersion SAVEGAME_VERSION
current savegame version
OTTD savegame.
Definition: saveload.h:324
#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:499
uint32 _ttdp_version
version of TTDP savegame (if applicable)
Definition: saveload.cpp:61
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:80
#define DEBUG(name, level,...)
Output a line of debugging information.
Definition: debug.h:36
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:131
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:322
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:565
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:177
void GamelogGRFRemove(uint32 grfid)
Logs removal of a GRF.
Definition: gamelog.cpp:600
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:522
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.
static const char * GetGamelogRevisionString()
Return the revision string for the current client version, for use in gamelog.
Definition: gamelog.cpp:46
GRF order changed.
void GamelogGRFUpdate(const GRFConfig *oldc, const GRFConfig *newc)
Compares two NewGRF lists and logs any change.
Definition: gamelog.cpp:718
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:157
static GRFList * GenerateGRFList(const GRFConfig *grfc)
Generates GRFList.
Definition: gamelog.cpp:696
Use first found.