OpenTTD
gamelog.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #include "stdafx.h"
11 #include "saveload/saveload.h"
12 #include "string_func.h"
13 #include "settings_type.h"
14 #include "gamelog_internal.h"
15 #include "console_func.h"
16 #include "debug.h"
17 #include "date_func.h"
18 #include "rev.h"
19 
20 #include <stdarg.h>
21 
22 #include "safeguards.h"
23 
24 extern const SaveLoadVersion SAVEGAME_VERSION;
25 
27 
28 extern uint32 _ttdp_version;
30 extern byte _sl_minor_version;
31 
32 
34 
36 uint _gamelog_actions = 0;
37 static LoggedAction *_current_action = nullptr;
38 
39 
44 static const char * GetGamelogRevisionString()
45 {
46  /* Allocate a buffer larger than necessary (git revision hash is 40 bytes) to avoid truncation later */
47  static char gamelog_revision[48] = { 0 };
48  assert_compile(lengthof(gamelog_revision) > GAMELOG_REVISION_LENGTH);
49 
50  if (IsReleasedVersion()) {
51  return _openttd_revision;
52  } else if (gamelog_revision[0] == 0) {
53  /* Prefix character indication revision status */
54  assert(_openttd_revision_modified < 3);
55  gamelog_revision[0] = "gum"[_openttd_revision_modified]; // g = "git", u = "unknown", m = "modified"
56  /* Append the revision hash */
57  strecat(gamelog_revision, _openttd_revision_hash, lastof(gamelog_revision));
58  /* Truncate string to GAMELOG_REVISION_LENGTH bytes */
59  gamelog_revision[GAMELOG_REVISION_LENGTH - 1] = '\0';
60  }
61  return gamelog_revision;
62 }
63 
70 {
71  assert(_gamelog_action_type == GLAT_NONE); // do not allow starting new action without stopping the previous first
73 }
74 
79 {
80  assert(_gamelog_action_type != GLAT_NONE); // nobody should try to stop if there is no action in progress
81 
82  bool print = _current_action != nullptr;
83 
84  _current_action = nullptr;
86 
87  if (print) GamelogPrintDebug(5);
88 }
89 
93 void GamelogFree(LoggedAction *gamelog_action, uint gamelog_actions)
94 {
95  for (uint i = 0; i < gamelog_actions; i++) {
96  const LoggedAction *la = &gamelog_action[i];
97  for (uint j = 0; j < la->changes; j++) {
98  const LoggedChange *lc = &la->change[j];
99  if (lc->ct == GLCT_SETTING) free(lc->setting.name);
100  }
101  free(la->change);
102  }
103 
104  free(gamelog_action);
105 }
106 
111 {
112  assert(_gamelog_action_type == GLAT_NONE);
113  GamelogFree(_gamelog_action, _gamelog_actions);
114 
115  _gamelog_action = nullptr;
116  _gamelog_actions = 0;
117  _current_action = nullptr;
118 }
119 
129 static char *PrintGrfInfo(char *buf, const char *last, uint grfid, const uint8 *md5sum, const GRFConfig *gc)
130 {
131  char txt[40];
132 
133  if (md5sum != nullptr) {
134  md5sumToString(txt, lastof(txt), md5sum);
135  buf += seprintf(buf, last, "GRF ID %08X, checksum %s", BSWAP32(grfid), txt);
136  } else {
137  buf += seprintf(buf, last, "GRF ID %08X", BSWAP32(grfid));
138  }
139 
140  if (gc != nullptr) {
141  buf += seprintf(buf, last, ", filename: %s (md5sum matches)", gc->filename);
142  } else {
143  gc = FindGRFConfig(grfid, FGCM_ANY);
144  if (gc != nullptr) {
145  buf += seprintf(buf, last, ", filename: %s (matches GRFID only)", gc->filename);
146  } else {
147  buf += seprintf(buf, last, ", unknown GRF");
148  }
149  }
150  return buf;
151 }
152 
153 
155 static const char * const la_text[] = {
156  "new game started",
157  "game loaded",
158  "GRF config changed",
159  "cheat was used",
160  "settings changed",
161  "GRF bug triggered",
162  "emergency savegame",
163 };
164 
165 assert_compile(lengthof(la_text) == GLAT_END);
166 
174 struct GRFPresence{
175  const GRFConfig *gc;
176  bool was_missing;
177 
178  GRFPresence(const GRFConfig *gc) : gc(gc), was_missing(false) {}
179  GRFPresence() = default;
180 };
182 
188 {
189  char buffer[1024];
190  GrfIDMapping grf_names;
191 
192  proc("---- gamelog start ----");
193 
194  const LoggedAction *laend = &_gamelog_action[_gamelog_actions];
195 
196  for (const LoggedAction *la = _gamelog_action; la != laend; la++) {
197  assert((uint)la->at < GLAT_END);
198 
199  seprintf(buffer, lastof(buffer), "Tick %u: %s", (uint)la->tick, la_text[(uint)la->at]);
200  proc(buffer);
201 
202  const LoggedChange *lcend = &la->change[la->changes];
203 
204  for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
205  char *buf = buffer;
206 
207  switch (lc->ct) {
208  default: NOT_REACHED();
209  case GLCT_MODE:
210  buf += seprintf(buf, lastof(buffer), "New game mode: %u landscape: %u",
211  (uint)lc->mode.mode, (uint)lc->mode.landscape);
212  break;
213 
214  case GLCT_REVISION:
215  buf += seprintf(buf, lastof(buffer), "Revision text changed to %s, savegame version %u, ",
216  lc->revision.text, lc->revision.slver);
217 
218  switch (lc->revision.modified) {
219  case 0: buf += seprintf(buf, lastof(buffer), "not "); break;
220  case 1: buf += seprintf(buf, lastof(buffer), "maybe "); break;
221  default: break;
222  }
223 
224  buf += seprintf(buf, lastof(buffer), "modified, _openttd_newgrf_version = 0x%08x", lc->revision.newgrf);
225  break;
226 
227  case GLCT_OLDVER:
228  buf += seprintf(buf, lastof(buffer), "Conversion from ");
229  switch (lc->oldver.type) {
230  default: NOT_REACHED();
231  case SGT_OTTD:
232  buf += seprintf(buf, lastof(buffer), "OTTD savegame without gamelog: version %u, %u",
233  GB(lc->oldver.version, 8, 16), GB(lc->oldver.version, 0, 8));
234  break;
235 
236  case SGT_TTO:
237  buf += seprintf(buf, lastof(buffer), "TTO savegame");
238  break;
239 
240  case SGT_TTD:
241  buf += seprintf(buf, lastof(buffer), "TTD savegame");
242  break;
243 
244  case SGT_TTDP1:
245  case SGT_TTDP2:
246  buf += seprintf(buf, lastof(buffer), "TTDP savegame, %s format",
247  lc->oldver.type == SGT_TTDP1 ? "old" : "new");
248  if (lc->oldver.version != 0) {
249  buf += seprintf(buf, lastof(buffer), ", TTDP version %u.%u.%u.%u",
250  GB(lc->oldver.version, 24, 8), GB(lc->oldver.version, 20, 4),
251  GB(lc->oldver.version, 16, 4), GB(lc->oldver.version, 0, 16));
252  }
253  break;
254  }
255  break;
256 
257  case GLCT_SETTING:
258  buf += seprintf(buf, lastof(buffer), "Setting changed: %s : %d -> %d", lc->setting.name, lc->setting.oldval, lc->setting.newval);
259  break;
260 
261  case GLCT_GRFADD: {
262  const GRFConfig *gc = FindGRFConfig(lc->grfadd.grfid, FGCM_EXACT, lc->grfadd.md5sum);
263  buf += seprintf(buf, lastof(buffer), "Added NewGRF: ");
264  buf = PrintGrfInfo(buf, lastof(buffer), lc->grfadd.grfid, lc->grfadd.md5sum, gc);
265  GrfIDMapping::Pair *gm = grf_names.Find(lc->grfrem.grfid);
266  if (gm != grf_names.End() && !gm->second.was_missing) buf += seprintf(buf, lastof(buffer), ". Gamelog inconsistency: GrfID was already added!");
267  grf_names[lc->grfadd.grfid] = gc;
268  break;
269  }
270 
271  case GLCT_GRFREM: {
272  GrfIDMapping::Pair *gm = grf_names.Find(lc->grfrem.grfid);
273  buf += seprintf(buf, lastof(buffer), la->at == GLAT_LOAD ? "Missing NewGRF: " : "Removed NewGRF: ");
274  buf = PrintGrfInfo(buf, lastof(buffer), lc->grfrem.grfid, nullptr, gm != grf_names.End() ? gm->second.gc : nullptr);
275  if (gm == grf_names.End()) {
276  buf += seprintf(buf, lastof(buffer), ". Gamelog inconsistency: GrfID was never added!");
277  } else {
278  if (la->at == GLAT_LOAD) {
279  /* Missing grfs on load are not removed from the configuration */
280  gm->second.was_missing = true;
281  } else {
282  grf_names.Erase(gm);
283  }
284  }
285  break;
286  }
287 
288  case GLCT_GRFCOMPAT: {
289  const GRFConfig *gc = FindGRFConfig(lc->grfadd.grfid, FGCM_EXACT, lc->grfadd.md5sum);
290  buf += seprintf(buf, lastof(buffer), "Compatible NewGRF loaded: ");
291  buf = PrintGrfInfo(buf, lastof(buffer), lc->grfcompat.grfid, lc->grfcompat.md5sum, gc);
292  if (!grf_names.Contains(lc->grfcompat.grfid)) buf += seprintf(buf, lastof(buffer), ". Gamelog inconsistency: GrfID was never added!");
293  grf_names[lc->grfcompat.grfid] = gc;
294  break;
295  }
296 
297  case GLCT_GRFPARAM: {
298  GrfIDMapping::Pair *gm = grf_names.Find(lc->grfrem.grfid);
299  buf += seprintf(buf, lastof(buffer), "GRF parameter changed: ");
300  buf = PrintGrfInfo(buf, lastof(buffer), lc->grfparam.grfid, nullptr, gm != grf_names.End() ? gm->second.gc : nullptr);
301  if (gm == grf_names.End()) buf += seprintf(buf, lastof(buffer), ". Gamelog inconsistency: GrfID was never added!");
302  break;
303  }
304 
305  case GLCT_GRFMOVE: {
306  GrfIDMapping::Pair *gm = grf_names.Find(lc->grfrem.grfid);
307  buf += seprintf(buf, lastof(buffer), "GRF order changed: %08X moved %d places %s",
308  BSWAP32(lc->grfmove.grfid), abs(lc->grfmove.offset), lc->grfmove.offset >= 0 ? "down" : "up" );
309  buf = PrintGrfInfo(buf, lastof(buffer), lc->grfmove.grfid, nullptr, gm != grf_names.End() ? gm->second.gc : nullptr);
310  if (gm == grf_names.End()) buf += seprintf(buf, lastof(buffer), ". Gamelog inconsistency: GrfID was never added!");
311  break;
312  }
313 
314  case GLCT_GRFBUG: {
315  GrfIDMapping::Pair *gm = grf_names.Find(lc->grfrem.grfid);
316  switch (lc->grfbug.bug) {
317  default: NOT_REACHED();
318  case GBUG_VEH_LENGTH:
319  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);
320  break;
321  }
322  buf = PrintGrfInfo(buf, lastof(buffer), lc->grfbug.grfid, nullptr, gm != grf_names.End() ? gm->second.gc : nullptr);
323  if (gm == grf_names.End()) buf += seprintf(buf, lastof(buffer), ". Gamelog inconsistency: GrfID was never added!");
324  break;
325  }
326 
327  case GLCT_EMERGENCY:
328  break;
329  }
330 
331  proc(buffer);
332  }
333  }
334 
335  proc("---- gamelog end ----");
336 }
337 
338 
339 static void GamelogPrintConsoleProc(const char *s)
340 {
342 }
343 
346 {
347  GamelogPrint(&GamelogPrintConsoleProc);
348 }
349 
350 static int _gamelog_print_level = 0;
351 
352 static void GamelogPrintDebugProc(const char *s)
353 {
354  DEBUG(gamelog, _gamelog_print_level, "%s", s);
355 }
356 
357 
364 void GamelogPrintDebug(int level)
365 {
366  _gamelog_print_level = level;
367  GamelogPrint(&GamelogPrintDebugProc);
368 }
369 
370 
378 {
379  if (_current_action == nullptr) {
380  if (_gamelog_action_type == GLAT_NONE) return nullptr;
381 
382  _gamelog_action = ReallocT(_gamelog_action, _gamelog_actions + 1);
383  _current_action = &_gamelog_action[_gamelog_actions++];
384 
385  _current_action->at = _gamelog_action_type;
386  _current_action->tick = _tick_counter;
387  _current_action->change = nullptr;
388  _current_action->changes = 0;
389  }
390 
391  _current_action->change = ReallocT(_current_action->change, _current_action->changes + 1);
392 
393  LoggedChange *lc = &_current_action->change[_current_action->changes++];
394  lc->ct = ct;
395 
396  return lc;
397 }
398 
399 
404 {
405  /* Terminate any active action */
410 }
411 
416 {
417  const LoggedChange *emergency = nullptr;
418 
419  const LoggedAction *laend = &_gamelog_action[_gamelog_actions];
420  for (const LoggedAction *la = _gamelog_action; la != laend; la++) {
421  const LoggedChange *lcend = &la->change[la->changes];
422  for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
423  if (lc->ct == GLCT_EMERGENCY) emergency = lc;
424  }
425  }
426 
427  return (emergency != nullptr);
428 }
429 
434 {
436 
438  if (lc == nullptr) return;
439 
440  memset(lc->revision.text, 0, sizeof(lc->revision.text));
441  strecpy(lc->revision.text, GetGamelogRevisionString(), lastof(lc->revision.text));
442  lc->revision.slver = SAVEGAME_VERSION;
443  lc->revision.modified = _openttd_revision_modified;
444  lc->revision.newgrf = _openttd_newgrf_version;
445 }
446 
451 {
453 
455  if (lc == nullptr) return;
456 
457  lc->mode.mode = _game_mode;
458  lc->mode.landscape = _settings_game.game_creation.landscape;
459 }
460 
465 {
466  assert(_gamelog_action_type == GLAT_LOAD);
467 
469  if (lc == nullptr) return;
470 
471  lc->oldver.type = _savegame_type;
472  lc->oldver.version = (_savegame_type == SGT_OTTD ? ((uint32)_sl_version << 8 | _sl_minor_version) : _ttdp_version);
473 }
474 
481 void GamelogSetting(const char *name, int32 oldval, int32 newval)
482 {
484 
486  if (lc == nullptr) return;
487 
488  lc->setting.name = stredup(name);
489  lc->setting.oldval = oldval;
490  lc->setting.newval = newval;
491 }
492 
493 
499 {
500  const LoggedChange *rev = nullptr;
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_REVISION) rev = lc;
507  }
508  }
509 
510  if (rev == nullptr || strcmp(rev->revision.text, GetGamelogRevisionString()) != 0 ||
511  rev->revision.modified != _openttd_revision_modified ||
512  rev->revision.newgrf != _openttd_newgrf_version) {
513  GamelogRevision();
514  }
515 }
516 
522 {
523  const LoggedChange *mode = nullptr;
524 
525  const LoggedAction *laend = &_gamelog_action[_gamelog_actions];
526  for (const LoggedAction *la = _gamelog_action; la != laend; la++) {
527  const LoggedChange *lcend = &la->change[la->changes];
528  for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
529  if (lc->ct == GLCT_MODE) mode = lc;
530  }
531  }
532 
533  if (mode == nullptr || mode->mode.mode != _game_mode || mode->mode.landscape != _settings_game.game_creation.landscape) GamelogMode();
534 }
535 
536 
543 static void GamelogGRFBug(uint32 grfid, byte bug, uint64 data)
544 {
546 
548  if (lc == nullptr) return;
549 
550  lc->grfbug.data = data;
551  lc->grfbug.grfid = grfid;
552  lc->grfbug.bug = bug;
553 }
554 
564 bool GamelogGRFBugReverse(uint32 grfid, uint16 internal_id)
565 {
566  const LoggedAction *laend = &_gamelog_action[_gamelog_actions];
567  for (const LoggedAction *la = _gamelog_action; la != laend; la++) {
568  const LoggedChange *lcend = &la->change[la->changes];
569  for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
570  if (lc->ct == GLCT_GRFBUG && lc->grfbug.grfid == grfid &&
571  lc->grfbug.bug == GBUG_VEH_LENGTH && lc->grfbug.data == internal_id) {
572  return false;
573  }
574  }
575  }
576 
578  GamelogGRFBug(grfid, GBUG_VEH_LENGTH, internal_id);
580 
581  return true;
582 }
583 
584 
590 static inline bool IsLoggableGrfConfig(const GRFConfig *g)
591 {
592  return !HasBit(g->flags, GCF_STATIC) && g->status != GCS_NOT_FOUND;
593 }
594 
599 void GamelogGRFRemove(uint32 grfid)
600 {
602 
604  if (lc == nullptr) return;
605 
606  lc->grfrem.grfid = grfid;
607 }
608 
613 void GamelogGRFAdd(const GRFConfig *newg)
614 {
616 
617  if (!IsLoggableGrfConfig(newg)) return;
618 
620  if (lc == nullptr) return;
621 
622  lc->grfadd = newg->ident;
623 }
624 
631 {
633 
635  if (lc == nullptr) return;
636 
637  lc->grfcompat = *newg;
638 }
639 
645 static void GamelogGRFMove(uint32 grfid, int32 offset)
646 {
647  assert(_gamelog_action_type == GLAT_GRF);
648 
650  if (lc == nullptr) return;
651 
652  lc->grfmove.grfid = grfid;
653  lc->grfmove.offset = offset;
654 }
655 
661 static void GamelogGRFParameters(uint32 grfid)
662 {
663  assert(_gamelog_action_type == GLAT_GRF);
664 
666  if (lc == nullptr) return;
667 
668  lc->grfparam.grfid = grfid;
669 }
670 
676 void GamelogGRFAddList(const GRFConfig *newg)
677 {
679 
680  for (; newg != nullptr; newg = newg->next) {
681  GamelogGRFAdd(newg);
682  }
683 }
684 
686 struct GRFList {
687  uint n;
688  const GRFConfig *grf[];
689 };
690 
695 static GRFList *GenerateGRFList(const GRFConfig *grfc)
696 {
697  uint n = 0;
698  for (const GRFConfig *g = grfc; g != nullptr; g = g->next) {
699  if (IsLoggableGrfConfig(g)) n++;
700  }
701 
702  GRFList *list = (GRFList*)MallocT<byte>(sizeof(GRFList) + n * sizeof(GRFConfig*));
703 
704  list->n = 0;
705  for (const GRFConfig *g = grfc; g != nullptr; g = g->next) {
706  if (IsLoggableGrfConfig(g)) list->grf[list->n++] = g;
707  }
708 
709  return list;
710 }
711 
717 void GamelogGRFUpdate(const GRFConfig *oldc, const GRFConfig *newc)
718 {
719  GRFList *ol = GenerateGRFList(oldc);
720  GRFList *nl = GenerateGRFList(newc);
721 
722  uint o = 0, n = 0;
723 
724  while (o < ol->n && n < nl->n) {
725  const GRFConfig *og = ol->grf[o];
726  const GRFConfig *ng = nl->grf[n];
727 
728  if (og->ident.grfid != ng->ident.grfid) {
729  uint oi, ni;
730  for (oi = 0; oi < ol->n; oi++) {
731  if (ol->grf[oi]->ident.grfid == nl->grf[n]->ident.grfid) break;
732  }
733  if (oi < o) {
734  /* GRF was moved, this change has been logged already */
735  n++;
736  continue;
737  }
738  if (oi == ol->n) {
739  /* GRF couldn't be found in the OLD list, GRF was ADDED */
740  GamelogGRFAdd(nl->grf[n++]);
741  continue;
742  }
743  for (ni = 0; ni < nl->n; ni++) {
744  if (nl->grf[ni]->ident.grfid == ol->grf[o]->ident.grfid) break;
745  }
746  if (ni < n) {
747  /* GRF was moved, this change has been logged already */
748  o++;
749  continue;
750  }
751  if (ni == nl->n) {
752  /* GRF couldn't be found in the NEW list, GRF was REMOVED */
753  GamelogGRFRemove(ol->grf[o++]->ident.grfid);
754  continue;
755  }
756 
757  /* o < oi < ol->n
758  * n < ni < nl->n */
759  assert(ni > n && ni < nl->n);
760  assert(oi > o && oi < ol->n);
761 
762  ni -= n; // number of GRFs it was moved downwards
763  oi -= o; // number of GRFs it was moved upwards
764 
765  if (ni >= oi) { // prefer the one that is moved further
766  /* GRF was moved down */
767  GamelogGRFMove(ol->grf[o++]->ident.grfid, ni);
768  } else {
769  GamelogGRFMove(nl->grf[n++]->ident.grfid, -(int)oi);
770  }
771  } else {
772  if (memcmp(og->ident.md5sum, ng->ident.md5sum, sizeof(og->ident.md5sum)) != 0) {
773  /* md5sum changed, probably loading 'compatible' GRF */
774  GamelogGRFCompatible(&nl->grf[n]->ident);
775  }
776 
777  if (og->num_params != ng->num_params || memcmp(og->param, ng->param, og->num_params * sizeof(og->param[0])) != 0) {
778  GamelogGRFParameters(ol->grf[o]->ident.grfid);
779  }
780 
781  o++;
782  n++;
783  }
784  }
785 
786  while (o < ol->n) GamelogGRFRemove(ol->grf[o++]->ident.grfid); // remaining GRFs were removed ...
787  while (n < nl->n) GamelogGRFAdd (nl->grf[n++]); // ... or added
788 
789  free(ol);
790  free(nl);
791 }
792 
801 void GamelogInfo(LoggedAction *gamelog_action, uint gamelog_actions, uint32 *last_ottd_rev, byte *ever_modified, bool *removed_newgrfs)
802 {
803  const LoggedAction *laend = &gamelog_action[gamelog_actions];
804  for (const LoggedAction *la = gamelog_action; la != laend; la++) {
805  const LoggedChange *lcend = &la->change[la->changes];
806  for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
807  switch (lc->ct) {
808  default: break;
809 
810  case GLCT_REVISION:
811  *last_ottd_rev = lc->revision.newgrf;
812  *ever_modified = max(*ever_modified, lc->revision.modified);
813  break;
814 
815  case GLCT_GRFREM:
816  *removed_newgrfs = true;
817  break;
818  }
819  }
820  }
821 }
void GamelogPrint(GamelogPrintProc *proc)
Prints active gamelog.
Definition: gamelog.cpp:187
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:79
GRF bug triggered.
bool GamelogTestEmergency()
Finds out if current game is a loaded emergency savegame.
Definition: gamelog.cpp:415
Loaded from savegame without logged data.
static GamelogActionType _gamelog_action_type
action to record if anything changes
Definition: gamelog.cpp:33
static LoggedAction * _current_action
current action we are logging, nullptr when there is no action active
Definition: gamelog.cpp:37
static void GamelogGRFParameters(uint32 grfid)
Logs change in GRF parameters.
Definition: gamelog.cpp:661
void GamelogEmergency()
Logs a emergency savegame.
Definition: gamelog.cpp:403
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:97
SaveLoadVersion
SaveLoad versions Previous savegame versions, the trunk revision where they were introduced and the r...
Definition: saveload.h:29
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:407
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:645
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:69
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:425
SaveLoadVersion _sl_version
the major savegame version identifier
Definition: saveload.cpp:61
static bool IsLoggableGrfConfig(const GRFConfig *g)
Decides if GRF should be logged.
Definition: gamelog.cpp:590
uint32 changes
Number of changes in this action.
void GamelogRevision()
Logs a change in game revision.
Definition: gamelog.cpp:433
GRF file is used statically (can be used in any MP game)
Definition: newgrf_config.h:24
GRF parameter changed.
TTD savegame (can be detected incorrectly)
Definition: saveload.h:331
List of GRFs using array of pointers instead of linked list.
Definition: gamelog.cpp:686
#define lastof(x)
Get the last element of an fixed size array.
Definition: depend.cpp:48
Removed GRF.
void GamelogPrintDebug(int level)
Prints gamelog to debug output.
Definition: gamelog.cpp:364
GRF file was not found in the local cache.
Definition: newgrf_config.h:36
Loading compatible GRF.
void GamelogOldver()
Logs loading from savegame without gamelog.
Definition: gamelog.cpp:464
SavegameType
Types of save games.
Definition: saveload.h:330
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:24
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:377
Basic data to distinguish a GRF.
Definition: newgrf_config.h:82
uint _gamelog_actions
number of actions
Definition: gamelog.cpp:36
Cheat was used.
Definition: gamelog.h:20
static void GamelogGRFBug(uint32 grfid, byte bug, uint64 data)
Logs triggered GRF bug.
Definition: gamelog.cpp:543
struct GRFConfig * next
NOSAVE: Next item in the linked list.
GamelogActionType
The actions we log.
Definition: gamelog.h:16
GRFIdentifier grfadd
ID and md5sum of added GRF.
GRF bug was triggered.
Definition: gamelog.h:22
Game created.
Definition: gamelog.h:17
TTO savegame.
Definition: saveload.h:335
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:801
Functions related to low-level strings.
void GamelogSetting(const char *name, int32 oldval, int32 newval)
Logs change in game settings.
Definition: gamelog.cpp:481
void GamelogReset()
Resets and frees all memory allocated - used before loading or starting a new game.
Definition: gamelog.cpp:110
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:350
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:345
void GamelogFree(LoggedAction *gamelog_action, uint gamelog_actions)
Frees the memory allocated by a gamelog.
Definition: gamelog.cpp:93
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:84
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:613
void GamelogMode()
Logs a change in game mode (scenario editor or game)
Definition: gamelog.cpp:450
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:62
Information about the presence of a Grf at a certain point during gamelog history Note about missing ...
Definition: gamelog.cpp:174
A number of safeguards to prevent using unsafe methods.
Game loaded.
Definition: gamelog.h:18
byte mode
new game mode - Editor x Game
bool was_missing
Grf was missing during some gameload in the past.
Definition: gamelog.cpp:176
TTDP savegame in new format (data at SE border)
Definition: saveload.h:333
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:136
static T * ReallocT(T *t_ptr, size_t num_elements)
Simplified reallocation function that allocates the specified number of elements of the given type...
Definition: alloc_func.hpp:111
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:57
void GamelogGRFAddList(const GRFConfig *newg)
Logs adding of list of GRFs.
Definition: gamelog.cpp:676
Scenario editor x Game, different landscape.
So we know how many GLATs are there.
Definition: gamelog.h:24
void GamelogGRFCompatible(const GRFIdentifier *newg)
Logs loading compatible GRF (the same ID, but different MD5 hash)
Definition: gamelog.cpp:630
const SaveLoadVersion SAVEGAME_VERSION
current savegame version
OTTD savegame.
Definition: saveload.h:334
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:40
void GamelogTestRevision()
Finds out if current revision is different than last revision stored in the savegame.
Definition: gamelog.cpp:498
uint32 _ttdp_version
version of TTDP savegame (if applicable)
Definition: saveload.cpp:60
Emergency savegame.
Definition: gamelog.h:23
Changed game revision string.
GRF changed.
Definition: gamelog.h:19
void Erase(Pair *pair)
Removes given pair from this map.
void GamelogStopAction()
Stops logging of any changes.
Definition: gamelog.cpp:78
#define DEBUG(name, level,...)
Output a line of debugging information.
Definition: debug.h:35
LoggedAction * _gamelog_action
first logged action
Definition: gamelog.cpp:35
uint16 _tick_counter
Ever incrementing (and sometimes wrapping) tick counter for setting off various events.
Definition: date.cpp:28
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:129
Setting changed.
Definition: gamelog.h:21
GamelogActionType at
Type of action.
TTDP savegame ( -//- ) (data at NW border)
Definition: saveload.h:332
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:81
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:564
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
Definition: depend.cpp:66
char * filename
Filename - either with or without full path.
const GRFConfig * gc
GRFConfig, if known.
Definition: gamelog.cpp:175
void GamelogGRFRemove(uint32 grfid)
Logs removal of a GRF.
Definition: gamelog.cpp:599
uint32 grfid
GRF ID (defined by Action 0x08)
Definition: newgrf_config.h:83
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: depend.cpp:129
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:25
GameCreationSettings game_creation
settings used during the creation of a game (map)
void GamelogTestMode()
Finds last stored game mode or landscape.
Definition: gamelog.cpp:521
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:43
void GamelogPrintProc(const char *s)
Callback for printing text.
Definition: gamelog.h:38
uint8 md5sum[16]
MD5 checksum of file to distinguish files with the same GRF ID (eg. newer version of GRF) ...
Definition: newgrf_config.h:84
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:44
GRF order changed.
void GamelogGRFUpdate(const GRFConfig *oldc, const GRFConfig *newc)
Compares two NewGRF lists and logs any change.
Definition: gamelog.cpp:717
static const TextColour CC_WARNING
Colour for warning lines.
Definition: console_type.h:25
static const char *const la_text[]
Text messages for various logged actions.
Definition: gamelog.cpp:155
static GRFList * GenerateGRFList(const GRFConfig *grfc)
Generates GRFList.
Definition: gamelog.cpp:695
Use first found.