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 = nullptr;
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 != nullptr;
85 
86  _current_action = nullptr;
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 = nullptr;
118  _gamelog_actions = 0;
119  _current_action = nullptr;
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 != nullptr) {
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 != nullptr) {
143  buf += seprintf(buf, last, ", filename: %s (md5sum matches)", gc->filename);
144  } else {
145  gc = FindGRFConfig(grfid, FGCM_ANY);
146  if (gc != nullptr) {
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  GRFPresence() = default;
182 };
184 
190 {
191  char buffer[1024];
192  GrfIDMapping grf_names;
193 
194  proc("---- gamelog start ----");
195 
196  const LoggedAction *laend = &_gamelog_action[_gamelog_actions];
197 
198  for (const LoggedAction *la = _gamelog_action; la != laend; la++) {
199  assert((uint)la->at < GLAT_END);
200 
201  seprintf(buffer, lastof(buffer), "Tick %u: %s", (uint)la->tick, la_text[(uint)la->at]);
202  proc(buffer);
203 
204  const LoggedChange *lcend = &la->change[la->changes];
205 
206  for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
207  char *buf = buffer;
208 
209  switch (lc->ct) {
210  default: NOT_REACHED();
211  case GLCT_MODE:
212  buf += seprintf(buf, lastof(buffer), "New game mode: %u landscape: %u",
213  (uint)lc->mode.mode, (uint)lc->mode.landscape);
214  break;
215 
216  case GLCT_REVISION:
217  buf += seprintf(buf, lastof(buffer), "Revision text changed to %s, savegame version %u, ",
218  lc->revision.text, lc->revision.slver);
219 
220  switch (lc->revision.modified) {
221  case 0: buf += seprintf(buf, lastof(buffer), "not "); break;
222  case 1: buf += seprintf(buf, lastof(buffer), "maybe "); break;
223  default: break;
224  }
225 
226  buf += seprintf(buf, lastof(buffer), "modified, _openttd_newgrf_version = 0x%08x", lc->revision.newgrf);
227  break;
228 
229  case GLCT_OLDVER:
230  buf += seprintf(buf, lastof(buffer), "Conversion from ");
231  switch (lc->oldver.type) {
232  default: NOT_REACHED();
233  case SGT_OTTD:
234  buf += seprintf(buf, lastof(buffer), "OTTD savegame without gamelog: version %u, %u",
235  GB(lc->oldver.version, 8, 16), GB(lc->oldver.version, 0, 8));
236  break;
237 
238  case SGT_TTO:
239  buf += seprintf(buf, lastof(buffer), "TTO savegame");
240  break;
241 
242  case SGT_TTD:
243  buf += seprintf(buf, lastof(buffer), "TTD savegame");
244  break;
245 
246  case SGT_TTDP1:
247  case SGT_TTDP2:
248  buf += seprintf(buf, lastof(buffer), "TTDP savegame, %s format",
249  lc->oldver.type == SGT_TTDP1 ? "old" : "new");
250  if (lc->oldver.version != 0) {
251  buf += seprintf(buf, lastof(buffer), ", TTDP version %u.%u.%u.%u",
252  GB(lc->oldver.version, 24, 8), GB(lc->oldver.version, 20, 4),
253  GB(lc->oldver.version, 16, 4), GB(lc->oldver.version, 0, 16));
254  }
255  break;
256  }
257  break;
258 
259  case GLCT_SETTING:
260  buf += seprintf(buf, lastof(buffer), "Setting changed: %s : %d -> %d", lc->setting.name, lc->setting.oldval, lc->setting.newval);
261  break;
262 
263  case GLCT_GRFADD: {
264  const GRFConfig *gc = FindGRFConfig(lc->grfadd.grfid, FGCM_EXACT, lc->grfadd.md5sum);
265  buf += seprintf(buf, lastof(buffer), "Added NewGRF: ");
266  buf = PrintGrfInfo(buf, lastof(buffer), lc->grfadd.grfid, lc->grfadd.md5sum, gc);
267  GrfIDMapping::Pair *gm = grf_names.Find(lc->grfrem.grfid);
268  if (gm != grf_names.End() && !gm->second.was_missing) buf += seprintf(buf, lastof(buffer), ". Gamelog inconsistency: GrfID was already added!");
269  grf_names[lc->grfadd.grfid] = gc;
270  break;
271  }
272 
273  case GLCT_GRFREM: {
274  GrfIDMapping::Pair *gm = grf_names.Find(lc->grfrem.grfid);
275  buf += seprintf(buf, lastof(buffer), la->at == GLAT_LOAD ? "Missing NewGRF: " : "Removed NewGRF: ");
276  buf = PrintGrfInfo(buf, lastof(buffer), lc->grfrem.grfid, nullptr, gm != grf_names.End() ? gm->second.gc : nullptr);
277  if (gm == grf_names.End()) {
278  buf += seprintf(buf, lastof(buffer), ". Gamelog inconsistency: GrfID was never added!");
279  } else {
280  if (la->at == GLAT_LOAD) {
281  /* Missing grfs on load are not removed from the configuration */
282  gm->second.was_missing = true;
283  } else {
284  grf_names.Erase(gm);
285  }
286  }
287  break;
288  }
289 
290  case GLCT_GRFCOMPAT: {
291  const GRFConfig *gc = FindGRFConfig(lc->grfadd.grfid, FGCM_EXACT, lc->grfadd.md5sum);
292  buf += seprintf(buf, lastof(buffer), "Compatible NewGRF loaded: ");
293  buf = PrintGrfInfo(buf, lastof(buffer), lc->grfcompat.grfid, lc->grfcompat.md5sum, gc);
294  if (!grf_names.Contains(lc->grfcompat.grfid)) buf += seprintf(buf, lastof(buffer), ". Gamelog inconsistency: GrfID was never added!");
295  grf_names[lc->grfcompat.grfid] = gc;
296  break;
297  }
298 
299  case GLCT_GRFPARAM: {
300  GrfIDMapping::Pair *gm = grf_names.Find(lc->grfrem.grfid);
301  buf += seprintf(buf, lastof(buffer), "GRF parameter changed: ");
302  buf = PrintGrfInfo(buf, lastof(buffer), lc->grfparam.grfid, nullptr, gm != grf_names.End() ? gm->second.gc : nullptr);
303  if (gm == grf_names.End()) buf += seprintf(buf, lastof(buffer), ". Gamelog inconsistency: GrfID was never added!");
304  break;
305  }
306 
307  case GLCT_GRFMOVE: {
308  GrfIDMapping::Pair *gm = grf_names.Find(lc->grfrem.grfid);
309  buf += seprintf(buf, lastof(buffer), "GRF order changed: %08X moved %d places %s",
310  BSWAP32(lc->grfmove.grfid), abs(lc->grfmove.offset), lc->grfmove.offset >= 0 ? "down" : "up" );
311  buf = PrintGrfInfo(buf, lastof(buffer), lc->grfmove.grfid, nullptr, gm != grf_names.End() ? gm->second.gc : nullptr);
312  if (gm == grf_names.End()) buf += seprintf(buf, lastof(buffer), ". Gamelog inconsistency: GrfID was never added!");
313  break;
314  }
315 
316  case GLCT_GRFBUG: {
317  GrfIDMapping::Pair *gm = grf_names.Find(lc->grfrem.grfid);
318  switch (lc->grfbug.bug) {
319  default: NOT_REACHED();
320  case GBUG_VEH_LENGTH:
321  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);
322  break;
323  }
324  buf = PrintGrfInfo(buf, lastof(buffer), lc->grfbug.grfid, nullptr, gm != grf_names.End() ? gm->second.gc : nullptr);
325  if (gm == grf_names.End()) buf += seprintf(buf, lastof(buffer), ". Gamelog inconsistency: GrfID was never added!");
326  break;
327  }
328 
329  case GLCT_EMERGENCY:
330  break;
331  }
332 
333  proc(buffer);
334  }
335  }
336 
337  proc("---- gamelog end ----");
338 }
339 
340 
341 static void GamelogPrintConsoleProc(const char *s)
342 {
344 }
345 
348 {
349  GamelogPrint(&GamelogPrintConsoleProc);
350 }
351 
352 static int _gamelog_print_level = 0;
353 
354 static void GamelogPrintDebugProc(const char *s)
355 {
356  DEBUG(gamelog, _gamelog_print_level, "%s", s);
357 }
358 
359 
366 void GamelogPrintDebug(int level)
367 {
368  _gamelog_print_level = level;
369  GamelogPrint(&GamelogPrintDebugProc);
370 }
371 
372 
380 {
381  if (_current_action == nullptr) {
382  if (_gamelog_action_type == GLAT_NONE) return nullptr;
383 
384  _gamelog_action = ReallocT(_gamelog_action, _gamelog_actions + 1);
385  _current_action = &_gamelog_action[_gamelog_actions++];
386 
387  _current_action->at = _gamelog_action_type;
388  _current_action->tick = _tick_counter;
389  _current_action->change = nullptr;
390  _current_action->changes = 0;
391  }
392 
393  _current_action->change = ReallocT(_current_action->change, _current_action->changes + 1);
394 
395  LoggedChange *lc = &_current_action->change[_current_action->changes++];
396  lc->ct = ct;
397 
398  return lc;
399 }
400 
401 
406 {
407  /* Terminate any active action */
412 }
413 
418 {
419  const LoggedChange *emergency = nullptr;
420 
421  const LoggedAction *laend = &_gamelog_action[_gamelog_actions];
422  for (const LoggedAction *la = _gamelog_action; la != laend; la++) {
423  const LoggedChange *lcend = &la->change[la->changes];
424  for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
425  if (lc->ct == GLCT_EMERGENCY) emergency = lc;
426  }
427  }
428 
429  return (emergency != nullptr);
430 }
431 
436 {
438 
440  if (lc == nullptr) return;
441 
442  memset(lc->revision.text, 0, sizeof(lc->revision.text));
443  strecpy(lc->revision.text, GetGamelogRevisionString(), lastof(lc->revision.text));
444  lc->revision.slver = SAVEGAME_VERSION;
445  lc->revision.modified = _openttd_revision_modified;
446  lc->revision.newgrf = _openttd_newgrf_version;
447 }
448 
453 {
455 
457  if (lc == nullptr) return;
458 
459  lc->mode.mode = _game_mode;
460  lc->mode.landscape = _settings_game.game_creation.landscape;
461 }
462 
467 {
468  assert(_gamelog_action_type == GLAT_LOAD);
469 
471  if (lc == nullptr) return;
472 
473  lc->oldver.type = _savegame_type;
474  lc->oldver.version = (_savegame_type == SGT_OTTD ? ((uint32)_sl_version << 8 | _sl_minor_version) : _ttdp_version);
475 }
476 
483 void GamelogSetting(const char *name, int32 oldval, int32 newval)
484 {
486 
488  if (lc == nullptr) return;
489 
490  lc->setting.name = stredup(name);
491  lc->setting.oldval = oldval;
492  lc->setting.newval = newval;
493 }
494 
495 
501 {
502  const LoggedChange *rev = nullptr;
503 
504  const LoggedAction *laend = &_gamelog_action[_gamelog_actions];
505  for (const LoggedAction *la = _gamelog_action; la != laend; la++) {
506  const LoggedChange *lcend = &la->change[la->changes];
507  for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
508  if (lc->ct == GLCT_REVISION) rev = lc;
509  }
510  }
511 
512  if (rev == nullptr || strcmp(rev->revision.text, GetGamelogRevisionString()) != 0 ||
513  rev->revision.modified != _openttd_revision_modified ||
514  rev->revision.newgrf != _openttd_newgrf_version) {
515  GamelogRevision();
516  }
517 }
518 
524 {
525  const LoggedChange *mode = nullptr;
526 
527  const LoggedAction *laend = &_gamelog_action[_gamelog_actions];
528  for (const LoggedAction *la = _gamelog_action; la != laend; la++) {
529  const LoggedChange *lcend = &la->change[la->changes];
530  for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
531  if (lc->ct == GLCT_MODE) mode = lc;
532  }
533  }
534 
535  if (mode == nullptr || mode->mode.mode != _game_mode || mode->mode.landscape != _settings_game.game_creation.landscape) GamelogMode();
536 }
537 
538 
545 static void GamelogGRFBug(uint32 grfid, byte bug, uint64 data)
546 {
548 
550  if (lc == nullptr) return;
551 
552  lc->grfbug.data = data;
553  lc->grfbug.grfid = grfid;
554  lc->grfbug.bug = bug;
555 }
556 
566 bool GamelogGRFBugReverse(uint32 grfid, uint16 internal_id)
567 {
568  const LoggedAction *laend = &_gamelog_action[_gamelog_actions];
569  for (const LoggedAction *la = _gamelog_action; la != laend; la++) {
570  const LoggedChange *lcend = &la->change[la->changes];
571  for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
572  if (lc->ct == GLCT_GRFBUG && lc->grfbug.grfid == grfid &&
573  lc->grfbug.bug == GBUG_VEH_LENGTH && lc->grfbug.data == internal_id) {
574  return false;
575  }
576  }
577  }
578 
580  GamelogGRFBug(grfid, GBUG_VEH_LENGTH, internal_id);
582 
583  return true;
584 }
585 
586 
592 static inline bool IsLoggableGrfConfig(const GRFConfig *g)
593 {
594  return !HasBit(g->flags, GCF_STATIC) && g->status != GCS_NOT_FOUND;
595 }
596 
601 void GamelogGRFRemove(uint32 grfid)
602 {
604 
606  if (lc == nullptr) return;
607 
608  lc->grfrem.grfid = grfid;
609 }
610 
615 void GamelogGRFAdd(const GRFConfig *newg)
616 {
618 
619  if (!IsLoggableGrfConfig(newg)) return;
620 
622  if (lc == nullptr) return;
623 
624  lc->grfadd = newg->ident;
625 }
626 
633 {
635 
637  if (lc == nullptr) return;
638 
639  lc->grfcompat = *newg;
640 }
641 
647 static void GamelogGRFMove(uint32 grfid, int32 offset)
648 {
649  assert(_gamelog_action_type == GLAT_GRF);
650 
652  if (lc == nullptr) return;
653 
654  lc->grfmove.grfid = grfid;
655  lc->grfmove.offset = offset;
656 }
657 
663 static void GamelogGRFParameters(uint32 grfid)
664 {
665  assert(_gamelog_action_type == GLAT_GRF);
666 
668  if (lc == nullptr) return;
669 
670  lc->grfparam.grfid = grfid;
671 }
672 
678 void GamelogGRFAddList(const GRFConfig *newg)
679 {
681 
682  for (; newg != nullptr; newg = newg->next) {
683  GamelogGRFAdd(newg);
684  }
685 }
686 
688 struct GRFList {
689  uint n;
690  const GRFConfig *grf[];
691 };
692 
697 static GRFList *GenerateGRFList(const GRFConfig *grfc)
698 {
699  uint n = 0;
700  for (const GRFConfig *g = grfc; g != nullptr; g = g->next) {
701  if (IsLoggableGrfConfig(g)) n++;
702  }
703 
704  GRFList *list = (GRFList*)MallocT<byte>(sizeof(GRFList) + n * sizeof(GRFConfig*));
705 
706  list->n = 0;
707  for (const GRFConfig *g = grfc; g != nullptr; g = g->next) {
708  if (IsLoggableGrfConfig(g)) list->grf[list->n++] = g;
709  }
710 
711  return list;
712 }
713 
719 void GamelogGRFUpdate(const GRFConfig *oldc, const GRFConfig *newc)
720 {
721  GRFList *ol = GenerateGRFList(oldc);
722  GRFList *nl = GenerateGRFList(newc);
723 
724  uint o = 0, n = 0;
725 
726  while (o < ol->n && n < nl->n) {
727  const GRFConfig *og = ol->grf[o];
728  const GRFConfig *ng = nl->grf[n];
729 
730  if (og->ident.grfid != ng->ident.grfid) {
731  uint oi, ni;
732  for (oi = 0; oi < ol->n; oi++) {
733  if (ol->grf[oi]->ident.grfid == nl->grf[n]->ident.grfid) break;
734  }
735  if (oi < o) {
736  /* GRF was moved, this change has been logged already */
737  n++;
738  continue;
739  }
740  if (oi == ol->n) {
741  /* GRF couldn't be found in the OLD list, GRF was ADDED */
742  GamelogGRFAdd(nl->grf[n++]);
743  continue;
744  }
745  for (ni = 0; ni < nl->n; ni++) {
746  if (nl->grf[ni]->ident.grfid == ol->grf[o]->ident.grfid) break;
747  }
748  if (ni < n) {
749  /* GRF was moved, this change has been logged already */
750  o++;
751  continue;
752  }
753  if (ni == nl->n) {
754  /* GRF couldn't be found in the NEW list, GRF was REMOVED */
755  GamelogGRFRemove(ol->grf[o++]->ident.grfid);
756  continue;
757  }
758 
759  /* o < oi < ol->n
760  * n < ni < nl->n */
761  assert(ni > n && ni < nl->n);
762  assert(oi > o && oi < ol->n);
763 
764  ni -= n; // number of GRFs it was moved downwards
765  oi -= o; // number of GRFs it was moved upwards
766 
767  if (ni >= oi) { // prefer the one that is moved further
768  /* GRF was moved down */
769  GamelogGRFMove(ol->grf[o++]->ident.grfid, ni);
770  } else {
771  GamelogGRFMove(nl->grf[n++]->ident.grfid, -(int)oi);
772  }
773  } else {
774  if (memcmp(og->ident.md5sum, ng->ident.md5sum, sizeof(og->ident.md5sum)) != 0) {
775  /* md5sum changed, probably loading 'compatible' GRF */
776  GamelogGRFCompatible(&nl->grf[n]->ident);
777  }
778 
779  if (og->num_params != ng->num_params || memcmp(og->param, ng->param, og->num_params * sizeof(og->param[0])) != 0) {
780  GamelogGRFParameters(ol->grf[o]->ident.grfid);
781  }
782 
783  o++;
784  n++;
785  }
786  }
787 
788  while (o < ol->n) GamelogGRFRemove(ol->grf[o++]->ident.grfid); // remaining GRFs were removed ...
789  while (n < nl->n) GamelogGRFAdd (nl->grf[n++]); // ... or added
790 
791  free(ol);
792  free(nl);
793 }
794 
803 void GamelogInfo(LoggedAction *gamelog_action, uint gamelog_actions, uint32 *last_ottd_rev, byte *ever_modified, bool *removed_newgrfs)
804 {
805  const LoggedAction *laend = &gamelog_action[gamelog_actions];
806  for (const LoggedAction *la = gamelog_action; la != laend; la++) {
807  const LoggedChange *lcend = &la->change[la->changes];
808  for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
809  switch (lc->ct) {
810  default: break;
811 
812  case GLCT_REVISION:
813  *last_ottd_rev = lc->revision.newgrf;
814  *ever_modified = max(*ever_modified, lc->revision.modified);
815  break;
816 
817  case GLCT_GRFREM:
818  *removed_newgrfs = true;
819  break;
820  }
821  }
822  }
823 }
void GamelogPrint(GamelogPrintProc *proc)
Prints active gamelog.
Definition: gamelog.cpp:189
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:81
GRF bug triggered.
bool GamelogTestEmergency()
Finds out if current game is a loaded emergency savegame.
Definition: gamelog.cpp:417
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, nullptr when there is no action active
Definition: gamelog.cpp:39
static void GamelogGRFParameters(uint32 grfid)
Logs change in GRF parameters.
Definition: gamelog.cpp:663
void GamelogEmergency()
Logs a emergency savegame.
Definition: gamelog.cpp:405
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
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.
std::vector< Pair >::const_iterator Find(const T &key) const
Finds given key in this map.
static void GamelogGRFMove(uint32 grfid, int32 offset)
Logs changing GRF order.
Definition: gamelog.cpp:647
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:63
static bool IsLoggableGrfConfig(const GRFConfig *g)
Decides if GRF should be logged.
Definition: gamelog.cpp:592
uint32 changes
Number of changes in this action.
void GamelogRevision()
Logs a change in game revision.
Definition: gamelog.cpp:435
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:333
List of GRFs using array of pointers instead of linked list.
Definition: gamelog.cpp:688
#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:366
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:466
SavegameType
Types of save games.
Definition: saveload.h:332
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:379
Basic data to distinguish a GRF.
Definition: newgrf_config.h:84
uint _gamelog_actions
number of actions
Definition: gamelog.cpp:38
Cheat was used.
Definition: gamelog.h:22
static void GamelogGRFBug(uint32 grfid, byte bug, uint64 data)
Logs triggered GRF bug.
Definition: gamelog.cpp:545
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:337
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:803
Functions related to low-level strings.
void GamelogSetting(const char *name, int32 oldval, int32 newval)
Logs change in game settings.
Definition: gamelog.cpp:483
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:352
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:347
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:86
bool Contains(const T &key) const
Tests whether a key is assigned in this map.
Types related to global configuration settings.
void GamelogGRFAdd(const GRFConfig *newg)
Logs adding of a GRF.
Definition: gamelog.cpp:615
void GamelogMode()
Logs a change in game mode (scenario editor or game)
Definition: gamelog.cpp:452
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:64
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:335
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:59
void GamelogGRFAddList(const GRFConfig *newg)
Logs adding of list of GRFs.
Definition: gamelog.cpp:678
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:632
const SaveLoadVersion SAVEGAME_VERSION
current savegame version
OTTD savegame.
Definition: saveload.h:336
#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:500
uint32 _ttdp_version
version of TTDP savegame (if applicable)
Definition: saveload.cpp:62
Emergency savegame.
Definition: gamelog.h:25
Changed game revision string.
GRF changed.
Definition: gamelog.h:21
void Erase(Pair *pair)
Removes given pair from this map.
void GamelogStopAction()
Stops logging of any changes.
Definition: gamelog.cpp:80
#define DEBUG(name, level,...)
Output a line of debugging information.
Definition: debug.h:37
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
GamelogActionType at
Type of action.
TTDP savegame ( -//- ) (data at NW border)
Definition: saveload.h:334
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:566
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:601
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:131
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:523
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:719
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:697
Use first found.