Data Structures | Typedefs | Functions | Variables

# gamelog.cpp File Reference

Definition of functions used for logging of important changes in the game. More...

`#include "stdafx.h"`
`#include "saveload/saveload.h"`
`#include "string_func.h"`
`#include "settings_type.h"`
`#include "gamelog_internal.h"`
`#include "console_func.h"`
`#include "debug.h"`
`#include "date_func.h"`
`#include "rev.h"`
`#include <stdarg.h>`

Go to the source code of this file.

## Data Structures
struct | GRFPresence
| Information about the presence of a Grf at a certain point during gamelog history Note about missing Grfs: Changes to missing Grfs are not logged including manual removal of the Grf. More...
struct | GRFList
| List of GRFs using array of pointers instead of linked list. More...
## Typedefs
typedef SmallMap< uint32, GRFPresence > | GrfIDMapping
## Functions
void | GamelogStartAction (GamelogActionType at)
| Stores information about new action, but doesn't allocate it Action is allocated only when there is at least one change.
void | GamelogStopAction ()
| Stops logging of any changes.
void | GamelogFree (LoggedAction *gamelog_action, uint gamelog_actions)
| Frees the memory allocated by a gamelog.
void | GamelogReset ()
| Resets and frees all memory allocated - used before loading or starting a new game.
static void | AddDebugText (char *buf, const char *s,...) WARN_FORMAT(2
static void | PrintGrfInfo (char *buf, uint grfid, const uint8 *md5sum, const GRFConfig *gc)
| Prints GRF ID, checksum and filename if found.
| assert_compile (lengthof(la_text)==GLAT_END)
void | GamelogPrint (GamelogPrintProc *proc)
| Prints active gamelog.
static void | GamelogPrintConsoleProc (const char *s)
void | GamelogPrintConsole ()
| Print the gamelog data to the console.
static void | GamelogPrintDebugProc (const char *s)
void | GamelogPrintDebug (int level)
| Prints gamelog to debug output.
static LoggedChange * | GamelogChange (GamelogChangeType ct)
| Allocates new LoggedChange and new LoggedAction if needed.
void | GamelogEmergency ()
| Logs a emergency savegame.
bool | GamelogTestEmergency ()
| Finds out if current game is a loaded emergency savegame.
void | GamelogRevision ()
| Logs a change in game revision.
void | GamelogMode ()
| Logs a change in game mode (scenario editor or game).
void | GamelogOldver ()
| Logs loading from savegame without gamelog.
void | GamelogSetting (const char *name, int32 oldval, int32 newval)
| Logs change in game settings.
void | GamelogTestRevision ()
| Finds out if current revision is different than last revision stored in the savegame.
void | GamelogTestMode ()
| Finds last stored game mode or landscape.
static void | GamelogGRFBug (uint32 grfid, byte bug, uint64 data)
| Logs triggered GRF bug.
bool | GamelogGRFBugReverse (uint32 grfid, uint16 internal_id)
| Logs GRF bug - rail vehicle has different length after reversing.
static bool | IsLoggableGrfConfig (const GRFConfig *g)
| Decides if GRF should be logged.
void | GamelogGRFRemove (uint32 grfid)
| Logs removal of a GRF.
void | GamelogGRFAdd (const GRFConfig *newg)
| Logs adding of a GRF.
void | GamelogGRFCompatible (const GRFIdentifier *newg)
| Logs loading compatible GRF (the same ID, but different MD5 hash).
static void | GamelogGRFMove (uint32 grfid, int32 offset)
| Logs changing GRF order.
static void | GamelogGRFParameters (uint32 grfid)
| Logs change in GRF parameters.
void | GamelogGRFAddList (const GRFConfig *newg)
| Logs adding of list of GRFs.
static GRFList * | GenerateGRFList (const GRFConfig *grfc)
| Generates GRFList.
void | GamelogGRFUpdate (const GRFConfig *oldc, const GRFConfig *newc)
| Compares two NewGRF lists and logs any change.
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.
## Variables
const uint16 | SAVEGAME_VERSION
| current savegame version
SavegameType | _savegame_type
| type of savegame we are loading
uint32 | _ttdp_version
| version of TTDP savegame (if applicable)
uint16 | _sl_version
| the major savegame version identifier
byte | _sl_minor_version
| the minor savegame version, DO NOT USE!
static GamelogActionType | _gamelog_action_type = GLAT_NONE
| action to record if anything changes
LoggedAction * | _gamelog_action = NULL
| first logged action
uint | _gamelog_actions = 0
| number of actions
static LoggedAction * | _current_action = NULL
| current action we are logging, NULL when there is no action active
static const uint | GAMELOG_BUF_LEN = 1024
| length of buffer for one line of text
static uint | _dbgofs = 0
| offset in current output buffer
static const char *const | la_text []
| Text messages for various logged actions.
static int | _gamelog_print_level = 0
| gamelog debug level we need to print stuff

## Detailed Description

Definition of functions used for logging of important changes in the game.

Definition in file gamelog.cpp.

## Function Documentation

static LoggedChange* GamelogChange | ( | GamelogChangeType | ct | ) | `[static]`

Allocates new LoggedChange and new LoggedAction if needed.

If there is no action active, NULL is returned.

Parameters:

  | ct | type of change

Returns:
  new LoggedChange, or NULL if there is no action active

Definition at line 369 of file gamelog.cpp.

References _gamelog_action_type, _gamelog_actions, _tick_counter, LoggedAction::at, LoggedAction::change, LoggedAction::changes, LoggedChange::ct, GLAT_NONE, ReallocT(), and LoggedAction::tick.

Referenced by GamelogEmergency(), GamelogGRFAdd(), GamelogGRFBug(), GamelogGRFCompatible(), GamelogGRFMove(), GamelogGRFParameters(), GamelogGRFRemove(), GamelogMode(), GamelogOldver(), GamelogRevision(), and GamelogSetting().

void GamelogGRFAdd | ( | const GRFConfig * | newg | ) |

Logs adding of a GRF.

Parameters:

  | newg | added GRF

Definition at line 605 of file gamelog.cpp.

References _gamelog_action_type, GamelogChange(), GLAT_GRF, GLAT_LOAD, GLAT_START, GLCT_GRFADD, LoggedChange::grfadd, GRFConfig::ident, and IsLoggableGrfConfig().

Referenced by GamelogGRFAddList(), and GamelogGRFUpdate().

void GamelogGRFAddList | ( | const GRFConfig * | newg | ) |

Logs adding of list of GRFs.

Useful when old savegame is loaded or when new game is started

Parameters:

  | newg | head of GRF linked list

Definition at line 668 of file gamelog.cpp.

References _gamelog_action_type, GamelogGRFAdd(), GLAT_LOAD, GLAT_START, and GRFConfig::next.

Referenced by AfterLoadGame().

static void GamelogGRFBug | ( | uint32 | grfid,
|  | byte | bug,
|  | uint64 | data |
| ) |  |  | `[static]`

Logs triggered GRF bug.

Parameters:

  | grfid | ID of problematic GRF
  | bug | type of bug,

See also:
  enum GRFBugs

Parameters:

  | data | additional data

Definition at line 535 of file gamelog.cpp.

References _gamelog_action_type, GamelogChange(), GLAT_GRFBUG, and GLCT_GRFBUG.

Referenced by GamelogGRFBugReverse().

bool GamelogGRFBugReverse | ( | uint32 | grfid,
|  | uint16 | internal_id |
| ) |  |  |

Logs GRF bug - rail vehicle has different length after reversing.

Ensures this is logged only once for each GRF and engine type This check takes some time, but it is called pretty seldom, so it doesn't matter that much (ideally it shouldn't be called at all).

Parameters:

  | grfid | the broken NewGRF
  | internal_id | the internal ID of whatever's broken in the NewGRF

Returns:
  true iff a unique record was done

Definition at line 556 of file gamelog.cpp.

References _gamelog_actions, LoggedAction::change, GamelogGRFBug(), GamelogStartAction(), GamelogStopAction(), GBUG_VEH_LENGTH, GLAT_GRFBUG, and GLCT_GRFBUG.

Referenced by VehicleLengthChanged().

void GamelogGRFCompatible | ( | const GRFIdentifier * | newg | ) |

Logs loading compatible GRF (the same ID, but different MD5 hash).

Parameters:

  | newg | new (updated) GRF

Definition at line 622 of file gamelog.cpp.

References _gamelog_action_type, GamelogChange(), GLAT_GRF, GLAT_LOAD, GLCT_GRFCOMPAT, and LoggedChange::grfcompat.

Referenced by AfterLoadGame(), and GamelogGRFUpdate().

static void GamelogGRFMove | ( | uint32 | grfid,
|  | int32 | offset |
| ) |  |  | `[static]`

Logs changing GRF order.

Parameters:

  | grfid | GRF that is moved
  | offset | how far it is moved, positive = moved down

Definition at line 637 of file gamelog.cpp.

References _gamelog_action_type, GamelogChange(), GLAT_GRF, and GLCT_GRFMOVE.

Referenced by GamelogGRFUpdate().

static void GamelogGRFParameters | ( | uint32 | grfid | ) | `[static]`

Logs change in GRF parameters.

Details about parameters changed are not stored

Parameters:

  | grfid | ID of GRF to store

Definition at line 653 of file gamelog.cpp.

References _gamelog_action_type, GamelogChange(), GLAT_GRF, and GLCT_GRFPARAM.

Referenced by GamelogGRFUpdate().

void GamelogGRFRemove | ( | uint32 | grfid | ) |

Logs removal of a GRF.

Parameters:

  | grfid | ID of removed GRF

Definition at line 591 of file gamelog.cpp.

References _gamelog_action_type, GamelogChange(), GLAT_GRF, GLAT_LOAD, and GLCT_GRFREM.

Referenced by AfterLoadGame(), and GamelogGRFUpdate().

void GamelogGRFUpdate | ( | const GRFConfig * | oldc,
|  | const GRFConfig * | newc |
| ) |  |  |

Compares two NewGRF lists and logs any change.

Parameters:

  | oldc | original GRF list
  | newc | new GRF list

Definition at line 709 of file gamelog.cpp.

References free(), GamelogGRFAdd(), GamelogGRFCompatible(), GamelogGRFMove(), GamelogGRFParameters(), GamelogGRFRemove(), GenerateGRFList(), GRFIdentifier::grfid, GRFConfig::ident, GRFIdentifier::md5sum, GRFConfig::num_params, and GRFConfig::param.

Referenced by NewGRFConfirmationCallback().

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.

Parameters:

  | gamelog_action | Pointer to the gamelog to extract information from.
  | gamelog_actions | Number of actions in the given gamelog.
  `[out]` | last_ottd_rev | OpenTTD NewGRF version from the binary that saved the savegame last.
  `[out]` | ever_modified | Max value of 'modified' from all binaries that ever saved this savegame.
  `[out]` | removed_newgrfs | Set to true if any NewGRFs have been removed.

Definition at line 793 of file gamelog.cpp.

References LoggedAction::change, GLCT_GRFREM, GLCT_REVISION, and max().

void GamelogPrint | ( | GamelogPrintProc * | proc | ) |

Prints active gamelog.

Parameters:

  | proc | the procedure to draw with

Definition at line 178 of file gamelog.cpp.

References _dbgofs, _gamelog_actions, abs(), BSWAP32(), SmallMap< T, U, S >::Contains(), SmallVector< T, S >::End(), SmallMap< T, U, S >::Erase(), FGCM_EXACT, SmallMap< T, U, S >::Find(), FindGRFConfig(), GAMELOG_BUF_LEN, GB(), GBUG_VEH_LENGTH, GLAT_END, GLAT_LOAD, GLCT_EMERGENCY, GLCT_GRFADD, GLCT_GRFBUG, GLCT_GRFCOMPAT, GLCT_GRFMOVE, GLCT_GRFPARAM, GLCT_GRFREM, GLCT_MODE, GLCT_OLDVER, GLCT_REVISION, GLCT_SETTING, la_text, PrintGrfInfo(), SGT_OTTD, SGT_TTD, SGT_TTDP1, SGT_TTDP2, and SGT_TTO.

Referenced by GamelogPrintConsole(), GamelogPrintDebug(), and CrashLog::LogGamelog().

void GamelogPrintConsole | ( |  | ) |

Print the gamelog data to the console.

Definition at line 337 of file gamelog.cpp.

References GamelogPrint().

void GamelogPrintDebug | ( | int | level | ) |

Prints gamelog to debug output.

Code is executed even when there will be no output. It is called very seldom, so it doesn't matter that much. At least it gives more uniform code...

Parameters:

  | level | debug level we need to print stuff

Definition at line 356 of file gamelog.cpp.

References GamelogPrint().

Referenced by AfterLoadGame(), and GamelogStopAction().

void GamelogSetting | ( | const char * | name,
|  | int32 | oldval,
|  | int32 | newval |
| ) |  |  |

Logs change in game settings.

Only non-networksafe settings are logged

Parameters:

  | name | setting name
  | oldval | old setting value
  | newval | new setting value

Definition at line 473 of file gamelog.cpp.

References _gamelog_action_type, GamelogChange(), GLAT_SETTING, and GLCT_SETTING.

Referenced by CmdChangeSetting().

void GamelogStartAction | ( | GamelogActionType | at | ) |

Stores information about new action, but doesn't allocate it Action is allocated only when there is at least one change.

Parameters:

  | at | type of action

Definition at line 45 of file gamelog.cpp.

References _gamelog_action_type, and GLAT_NONE.

Referenced by CmdChangeSetting(), DoLoad(), GamelogEmergency(), GamelogGRFBugReverse(), NewGRFConfirmationCallback(), and SaveOrLoad().

void GamelogTestMode | ( |  | ) |

Finds last stored game mode or landscape.

Any change is logged

Definition at line 513 of file gamelog.cpp.

References _gamelog_actions, _settings_game, LoggedAction::change, GameSettings::game_creation, GamelogMode(), GLCT_MODE, GameCreationSettings::landscape, and LoggedChange::mode.

Referenced by AfterLoadGame().

void GamelogTestRevision | ( |  | ) |

Finds out if current revision is different than last revision stored in the savegame.

Appends GLCT_REVISION when the revision string changed

Definition at line 490 of file gamelog.cpp.

References _gamelog_actions, LoggedAction::change, GamelogRevision(), and GLCT_REVISION.

Referenced by AfterLoadGame().

static GRFList* GenerateGRFList | ( | const GRFConfig * | grfc | ) | `[static]`

Generates GRFList.

Parameters:

  | grfc | head of GRF linked list

Definition at line 687 of file gamelog.cpp.

References IsLoggableGrfConfig(), and GRFConfig::next.

Referenced by GamelogGRFUpdate().

static bool IsLoggableGrfConfig | ( | const GRFConfig * | g | ) | `[inline, static]`

Decides if GRF should be logged.

Parameters:

  | g | grf to determine

Returns:
  true iff GRF is not static and is loaded

Definition at line 582 of file gamelog.cpp.

References GRFConfig::flags, GCF_STATIC, HasBit(), and GRFConfig::status.

Referenced by GamelogGRFAdd(), and GenerateGRFList().

static void PrintGrfInfo | ( | char * | buf,
|  | uint | grfid,
|  | const uint8 * | md5sum,
|  | const GRFConfig * | gc |
| ) |  |  | `[static]`

Prints GRF ID, checksum and filename if found.

Parameters:

  | buf | The location in the _dbgofs buffer to draw
  | grfid | GRF ID
  | md5sum | array of md5sum to print, if known
  | gc | GrfConfig, if known

Definition at line 121 of file gamelog.cpp.

References BSWAP32(), FGCM_ANY, GRFConfig::filename, FindGRFConfig(), lastof, and md5sumToString().

Referenced by GamelogPrint().

## Variable Documentation

const char* const la_text[]`[static]`

Initial value:

     {
      "new game started",
      "game loaded",
      "GRF config changed",
      "cheat was used",
      "settings changed",
      "GRF bug triggered",
      "emergency savegame",
    }

Text messages for various logged actions.

Definition at line 147 of file gamelog.cpp.

Referenced by GamelogPrint().