OpenTTD
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>
#include "safeguards.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, GRFPresenceGrfIDMapping
 

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. More...
 
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 char * PrintGrfInfo (char *buf, const char *last, uint grfid, const uint8 *md5sum, const GRFConfig *gc)
 Prints GRF ID, checksum and filename if found. More...
 
 assert_compile (lengthof(la_text)==GLAT_END)
 
void GamelogPrint (GamelogPrintProc *proc)
 Prints active gamelog. More...
 
static void GamelogPrintConsoleProc (const char *s)
 
void GamelogPrintConsole ()
 Print the gamelog data to the console. More...
 
static void GamelogPrintDebugProc (const char *s)
 
void GamelogPrintDebug (int level)
 Prints gamelog to debug output. More...
 
static LoggedChangeGamelogChange (GamelogChangeType ct)
 Allocates new LoggedChange and new LoggedAction if needed. More...
 
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. More...
 
void GamelogTestRevision ()
 Finds out if current revision is different than last revision stored in the savegame. More...
 
void GamelogTestMode ()
 Finds last stored game mode or landscape. More...
 
static void GamelogGRFBug (uint32 grfid, byte bug, uint64 data)
 Logs triggered GRF bug. More...
 
bool GamelogGRFBugReverse (uint32 grfid, uint16 internal_id)
 Logs GRF bug - rail vehicle has different length after reversing. More...
 
static bool IsLoggableGrfConfig (const GRFConfig *g)
 Decides if GRF should be logged. More...
 
void GamelogGRFRemove (uint32 grfid)
 Logs removal of a GRF. More...
 
void GamelogGRFAdd (const GRFConfig *newg)
 Logs adding of a GRF. More...
 
void GamelogGRFCompatible (const GRFIdentifier *newg)
 Logs loading compatible GRF (the same ID, but different MD5 hash) More...
 
static void GamelogGRFMove (uint32 grfid, int32 offset)
 Logs changing GRF order. More...
 
static void GamelogGRFParameters (uint32 grfid)
 Logs change in GRF parameters. More...
 
void GamelogGRFAddList (const GRFConfig *newg)
 Logs adding of list of GRFs. More...
 
static GRFListGenerateGRFList (const GRFConfig *grfc)
 Generates GRFList. More...
 
void GamelogGRFUpdate (const GRFConfig *oldc, const GRFConfig *newc)
 Compares two NewGRF lists and logs any change. More...
 
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. More...
 

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 char *const la_text []
 Text messages for various logged actions. More...
 
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

◆ GamelogChange()

static LoggedChange* GamelogChange ( GamelogChangeType  ct)
static

Allocates new LoggedChange and new LoggedAction if needed.

If there is no action active, NULL is returned.

Parameters
cttype of change
Returns
new LoggedChange, or NULL if there is no action active

Definition at line 354 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()

void GamelogGRFAdd ( const GRFConfig newg)

Logs adding of a GRF.

Parameters
newgadded GRF

Definition at line 590 of file gamelog.cpp.

Referenced by GamelogGRFUpdate().

◆ GamelogGRFAddList()

void GamelogGRFAddList ( const GRFConfig newg)

Logs adding of list of GRFs.

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

Parameters
newghead of GRF linked list

Definition at line 653 of file gamelog.cpp.

◆ GamelogGRFBug()

static void GamelogGRFBug ( uint32  grfid,
byte  bug,
uint64  data 
)
static

Logs triggered GRF bug.

Parameters
grfidID of problematic GRF
bugtype of bug,
See also
enum GRFBugs
Parameters
dataadditional data

Definition at line 520 of file gamelog.cpp.

Referenced by GamelogGRFBugReverse().

◆ 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
grfidthe broken NewGRF
internal_idthe internal ID of whatever's broken in the NewGRF
Returns
true iff a unique record was done

Definition at line 541 of file gamelog.cpp.

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

Referenced by VehicleLengthChanged().

◆ GamelogGRFCompatible()

void GamelogGRFCompatible ( const GRFIdentifier newg)

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

Parameters
newgnew (updated) GRF

Definition at line 607 of file gamelog.cpp.

◆ GamelogGRFMove()

static void GamelogGRFMove ( uint32  grfid,
int32  offset 
)
static

Logs changing GRF order.

Parameters
grfidGRF that is moved
offsethow far it is moved, positive = moved down

Definition at line 622 of file gamelog.cpp.

◆ GamelogGRFParameters()

static void GamelogGRFParameters ( uint32  grfid)
static

Logs change in GRF parameters.

Details about parameters changed are not stored

Parameters
grfidID of GRF to store

Definition at line 638 of file gamelog.cpp.

◆ GamelogGRFRemove()

void GamelogGRFRemove ( uint32  grfid)

Logs removal of a GRF.

Parameters
grfidID of removed GRF

Definition at line 576 of file gamelog.cpp.

Referenced by GamelogGRFUpdate().

◆ GamelogGRFUpdate()

void GamelogGRFUpdate ( const GRFConfig oldc,
const GRFConfig newc 
)

Compares two NewGRF lists and logs any change.

Parameters
oldcoriginal GRF list
newcnew GRF list

Definition at line 694 of file gamelog.cpp.

References GamelogGRFAdd(), GamelogGRFRemove(), GenerateGRFList(), GRFIdentifier::grfid, and GRFConfig::ident.

Referenced by NewGRFConfirmationCallback().

◆ GamelogInfo()

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_actionPointer to the gamelog to extract information from.
gamelog_actionsNumber of actions in the given gamelog.
[out]last_ottd_revOpenTTD NewGRF version from the binary that saved the savegame last.
[out]ever_modifiedMax value of 'modified' from all binaries that ever saved this savegame.
[out]removed_newgrfsSet to true if any NewGRFs have been removed.

Definition at line 778 of file gamelog.cpp.

References GLCT_GRFREM, GLCT_REVISION, and max().

◆ GamelogPrint()

void GamelogPrint ( GamelogPrintProc proc)

Prints active gamelog.

Parameters
procthe procedure to draw with

Definition at line 164 of file gamelog.cpp.

References _gamelog_actions.

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

◆ GamelogPrintConsole()

void GamelogPrintConsole ( )

Print the gamelog data to the console.

Definition at line 322 of file gamelog.cpp.

References GamelogPrint().

◆ GamelogPrintDebug()

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
leveldebug level we need to print stuff

Definition at line 341 of file gamelog.cpp.

References _gamelog_print_level, and GamelogPrint().

◆ GamelogSetting()

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

Logs change in game settings.

Only non-networksafe settings are logged

Parameters
namesetting name
oldvalold setting value
newvalnew setting value

Definition at line 458 of file gamelog.cpp.

◆ GamelogStartAction()

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
attype of action

Definition at line 47 of file gamelog.cpp.

Referenced by GamelogEmergency(), GamelogGRFBugReverse(), and NewGRFConfirmationCallback().

◆ GamelogTestMode()

void GamelogTestMode ( )

Finds last stored game mode or landscape.

Any change is logged

Definition at line 498 of file gamelog.cpp.

References _gamelog_actions, GLCT_MODE, and LoggedChange::mode.

◆ GamelogTestRevision()

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 475 of file gamelog.cpp.

References _gamelog_actions, and GLCT_REVISION.

◆ GenerateGRFList()

static GRFList* GenerateGRFList ( const GRFConfig grfc)
static

Generates GRFList.

Parameters
grfchead of GRF linked list

Definition at line 672 of file gamelog.cpp.

References IsLoggableGrfConfig(), and GRFConfig::next.

Referenced by GamelogGRFUpdate().

◆ IsLoggableGrfConfig()

static bool IsLoggableGrfConfig ( const GRFConfig g)
inlinestatic

Decides if GRF should be logged.

Parameters
ggrf to determine
Returns
true iff GRF is not static and is loaded

Definition at line 567 of file gamelog.cpp.

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

Referenced by GenerateGRFList().

◆ PrintGrfInfo()

static char* PrintGrfInfo ( char *  buf,
const char *  last,
uint  grfid,
const uint8 *  md5sum,
const GRFConfig gc 
)
static

Prints GRF ID, checksum and filename if found.

Parameters
bufThe location in the buffer to draw
lastThe end of the buffer
grfidGRF ID
md5sumarray of md5sum to print, if known
gcGrfConfig, if known
Returns
The buffer location.

Definition at line 107 of file gamelog.cpp.

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

Variable Documentation

◆ la_text

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 133 of file gamelog.cpp.