OpenTTD Source 20241224-master-gee860a5c8e
Gamelog Class Reference

Public Member Functions

void StartAction (GamelogActionType at)
 Stores information about new action, but doesn't allocate it Action is allocated only when there is at least one change.
 
void StopAction ()
 Stops logging of any changes.
 
void StopAnyAction ()
 
void Reset ()
 Resets and frees all memory allocated - used before loading or starting a new game.
 
void Print (std::function< void(const std::string &)> proc)
 Prints active gamelog.
 
void PrintDebug (int level)
 Prints gamelog to debug output.
 
void PrintConsole ()
 Print the gamelog data to the console.
 
void Emergency ()
 Logs a emergency savegame.
 
bool TestEmergency ()
 Finds out if current game is a loaded emergency savegame.
 
void Revision ()
 Logs a change in game revision.
 
void Mode ()
 Logs a change in game mode (scenario editor or game)
 
void Oldver ()
 Logs loading from savegame without gamelog.
 
void Setting (const std::string &name, int32_t oldval, int32_t newval)
 Logs change in game settings.
 
void GRFUpdate (const GRFConfig *oldg, const GRFConfig *newg)
 Compares two NewGRF lists and logs any change.
 
void GRFAddList (const GRFConfig *newg)
 Logs adding of list of GRFs.
 
void GRFRemove (uint32_t grfid)
 Logs removal of a GRF.
 
void GRFAdd (const GRFConfig *newg)
 Logs adding of a GRF.
 
void GRFBug (uint32_t grfid, uint8_t bug, uint64_t data)
 Logs triggered GRF bug.
 
bool GRFBugReverse (uint32_t grfid, uint16_t internal_id)
 Logs GRF bug - rail vehicle has different length after reversing.
 
void GRFCompatible (const GRFIdentifier *newg)
 Logs loading compatible GRF (the same ID, but different MD5 hash)
 
void GRFMove (uint32_t grfid, int32_t offset)
 Logs changing GRF order.
 
void GRFParameters (uint32_t grfid)
 Logs change in GRF parameters.
 
void TestRevision ()
 Finds out if current revision is different than last revision stored in the savegame.
 
void TestMode ()
 Finds last stored game mode or landscape.
 
void Info (uint32_t *last_ottd_rev, uint8_t *ever_modified, bool *removed_newgrfs)
 Get some basic information from the given gamelog.
 
const GRFIdentifierGetOverriddenIdentifier (const GRFConfig *c)
 Try to find the overridden GRF identifier of the given GRF.
 

Private Member Functions

void Change (std::unique_ptr< LoggedChange > &&change)
 Allocates a new LoggedAction if needed, and add the change when action is active.
 

Private Attributes

std::unique_ptr< GamelogInternalDatadata
 
GamelogActionType action_type
 
struct LoggedActioncurrent_action
 

Friends

struct GLOGChunkHandler
 

Detailed Description

Definition at line 49 of file gamelog.h.

Constructor & Destructor Documentation

◆ Gamelog()

Gamelog::Gamelog ( )

Definition at line 33 of file gamelog.cpp.

◆ ~Gamelog()

Gamelog::~Gamelog ( )

Definition at line 40 of file gamelog.cpp.

Member Function Documentation

◆ Change()

void Gamelog::Change ( std::unique_ptr< LoggedChange > &&  change)
private

Allocates a new LoggedAction if needed, and add the change when action is active.

Parameters
changeThe actual change.

Definition at line 335 of file gamelog.cpp.

References LoggedAction::at, LoggedAction::change, TimerGameTick::counter, GLAT_NONE, and LoggedAction::tick.

Referenced by Emergency(), GRFAdd(), GRFBug(), GRFCompatible(), GRFMove(), GRFParameters(), GRFRemove(), Mode(), Oldver(), Revision(), and Setting().

◆ Emergency()

void Gamelog::Emergency ( )

Logs a emergency savegame.

Definition at line 352 of file gamelog.cpp.

References Change(), GLAT_EMERGENCY, GLAT_NONE, StartAction(), and StopAction().

Referenced by CrashLog::WriteSavegame().

◆ GetOverriddenIdentifier()

const GRFIdentifier * Gamelog::GetOverriddenIdentifier ( const GRFConfig c)

Try to find the overridden GRF identifier of the given GRF.

Parameters
cthe GRF to get the 'previous' version of.
Returns
the GRF identifier or c if none could be found.

Definition at line 712 of file gamelog.cpp.

References LoggedAction::at, LoggedAction::change, GLAT_LOAD, GLCT_GRFCOMPAT, GRFIdentifier::grfid, and GRFConfig::ident.

Referenced by HandleSavegameLoadCrash().

◆ GRFAdd()

void Gamelog::GRFAdd ( const GRFConfig newg)

Logs adding of a GRF.

Parameters
newgadded GRF

Definition at line 528 of file gamelog.cpp.

References Change(), GLAT_GRF, GLAT_LOAD, GLAT_START, GRFConfig::ident, and IsLoggableGrfConfig().

Referenced by GRFAddList(), and GRFUpdate().

◆ GRFAddList()

void Gamelog::GRFAddList ( 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 578 of file gamelog.cpp.

References GLAT_LOAD, GLAT_START, GRFAdd(), and GRFConfig::next.

Referenced by AfterLoadGame().

◆ GRFBug()

void Gamelog::GRFBug ( uint32_t  grfid,
uint8_t  bug,
uint64_t  data 
)

Logs triggered GRF bug.

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

Definition at line 466 of file gamelog.cpp.

References Change(), and GLAT_GRFBUG.

Referenced by GRFBugReverse().

◆ GRFBugReverse()

bool Gamelog::GRFBugReverse ( uint32_t  grfid,
uint16_t  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 482 of file gamelog.cpp.

References LoggedChangeGRFBug::bug, LoggedChangeGRFBug::data, GBUG_VEH_LENGTH, GLAT_GRFBUG, GLCT_GRFBUG, GRFBug(), LoggedChangeGRFBug::grfid, StartAction(), and StopAction().

Referenced by VehicleLengthChanged().

◆ GRFCompatible()

void Gamelog::GRFCompatible ( const GRFIdentifier newg)

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

Parameters
newgnew (updated) GRF

Definition at line 542 of file gamelog.cpp.

References Change(), GLAT_GRF, and GLAT_LOAD.

Referenced by AfterLoadGame(), and GRFUpdate().

◆ GRFMove()

void Gamelog::GRFMove ( uint32_t  grfid,
int32_t  offset 
)

Logs changing GRF order.

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

Definition at line 554 of file gamelog.cpp.

References Change(), and GLAT_GRF.

Referenced by GRFUpdate().

◆ GRFParameters()

void Gamelog::GRFParameters ( uint32_t  grfid)

Logs change in GRF parameters.

Details about parameters changed are not stored

Parameters
grfidID of GRF to store

Definition at line 566 of file gamelog.cpp.

References Change(), and GLAT_GRF.

Referenced by GRFUpdate().

◆ GRFRemove()

void Gamelog::GRFRemove ( uint32_t  grfid)

Logs removal of a GRF.

Parameters
grfidID of removed GRF

Definition at line 517 of file gamelog.cpp.

References Change(), GLAT_GRF, and GLAT_LOAD.

Referenced by AfterLoadGame(), and GRFUpdate().

◆ GRFUpdate()

void Gamelog::GRFUpdate ( const GRFConfig oldc,
const GRFConfig newc 
)

Compares two NewGRF lists and logs any change.

Parameters
oldcoriginal GRF list
newcnew GRF list

Definition at line 606 of file gamelog.cpp.

References GenerateGRFList(), GRFAdd(), GRFCompatible(), GRFIdentifier::grfid, GRFMove(), GRFParameters(), GRFRemove(), GRFConfig::ident, GRFIdentifier::md5sum, and GRFConfig::param.

Referenced by NewGRFConfirmationCallback().

◆ Info()

void Gamelog::Info ( uint32_t *  last_ottd_rev,
uint8_t *  ever_modified,
bool *  removed_newgrfs 
)

Get some basic information from the given gamelog.

Parameters
[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 685 of file gamelog.cpp.

References GLCT_GRFREM, GLCT_REVISION, and LoggedChangeRevision::newgrf.

◆ Mode()

void Gamelog::Mode ( )

Logs a change in game mode (scenario editor or game)

Definition at line 389 of file gamelog.cpp.

References _settings_game, Change(), GameSettings::game_creation, GLAT_CHEAT, GLAT_LOAD, GLAT_START, and GameCreationSettings::landscape.

Referenced by TestMode().

◆ Oldver()

void Gamelog::Oldver ( )

Logs loading from savegame without gamelog.

Definition at line 399 of file gamelog.cpp.

References _savegame_type, _sl_minor_version, _sl_version, _ttdp_version, Change(), GLAT_LOAD, and SGT_OTTD.

Referenced by AfterLoadGame().

◆ Print()

void Gamelog::Print ( std::function< void(const std::string &)>  proc)

Prints active gamelog.

Parameters
procthe procedure to draw with

Definition at line 147 of file gamelog.cpp.

References GLAT_END, and la_text.

Referenced by PrintConsole(), PrintDebug(), and SurveyGamelog().

◆ PrintConsole()

void Gamelog::PrintConsole ( )

Print the gamelog data to the console.

Definition at line 310 of file gamelog.cpp.

References CC_WARNING, IConsolePrint(), and Print().

◆ PrintDebug()

void Gamelog::PrintDebug ( 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 323 of file gamelog.cpp.

References Debug, and Print().

Referenced by AfterLoadGame(), and StopAction().

◆ Reset()

void Gamelog::Reset ( )

Resets and frees all memory allocated - used before loading or starting a new game.

Definition at line 94 of file gamelog.cpp.

References GLAT_NONE.

Referenced by LoadCheckData::Clear(), DoLoad(), SaveOrLoad(), and ShutdownGame().

◆ Revision()

void Gamelog::Revision ( )

Logs a change in game revision.

Definition at line 378 of file gamelog.cpp.

References Change(), GetGamelogRevisionString(), GLAT_LOAD, GLAT_START, and SAVEGAME_VERSION.

Referenced by TestRevision().

◆ Setting()

void Gamelog::Setting ( const std::string &  name,
int32_t  oldval,
int32_t  newval 
)

Logs change in game settings.

Only non-networksafe settings are logged

Parameters
namesetting name
oldvalold setting value
newvalnew setting value

Definition at line 413 of file gamelog.cpp.

References Change(), and GLAT_SETTING.

Referenced by IntSettingDesc::ChangeValue().

◆ StartAction()

void Gamelog::StartAction ( 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 65 of file gamelog.cpp.

References GLAT_NONE.

Referenced by IntSettingDesc::ChangeValue(), DoLoad(), Emergency(), GRFBugReverse(), NewGRFConfirmationCallback(), and SaveOrLoad().

◆ StopAction()

void Gamelog::StopAction ( )

Stops logging of any changes.

Definition at line 74 of file gamelog.cpp.

References GLAT_NONE, and PrintDebug().

Referenced by IntSettingDesc::ChangeValue(), DoLoad(), Emergency(), GRFBugReverse(), NewGRFConfirmationCallback(), and SaveOrLoad().

◆ StopAnyAction()

void Gamelog::StopAnyAction ( )

Definition at line 86 of file gamelog.cpp.

◆ TestEmergency()

bool Gamelog::TestEmergency ( )

Finds out if current game is a loaded emergency savegame.

Definition at line 364 of file gamelog.cpp.

References GLCT_EMERGENCY.

Referenced by HandleCrash(), and HandleCrash().

◆ TestMode()

void Gamelog::TestMode ( )

Finds last stored game mode or landscape.

Any change is logged

Definition at line 446 of file gamelog.cpp.

References _settings_game, GameSettings::game_creation, GLCT_MODE, LoggedChangeMode::landscape, GameCreationSettings::landscape, Mode(), and LoggedChangeMode::mode.

Referenced by AfterLoadGame().

◆ TestRevision()

void Gamelog::TestRevision ( )

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

References GetGamelogRevisionString(), GLCT_REVISION, LoggedChangeRevision::newgrf, Revision(), and LoggedChangeRevision::text.

Referenced by AfterLoadGame().

Friends And Related Symbol Documentation

◆ GLOGChunkHandler

friend struct GLOGChunkHandler
friend

Definition at line 96 of file gamelog.h.

Field Documentation

◆ action_type

GamelogActionType Gamelog::action_type
private

Definition at line 52 of file gamelog.h.

◆ current_action

struct LoggedAction* Gamelog::current_action
private

Definition at line 53 of file gamelog.h.

◆ data

std::unique_ptr<GamelogInternalData> Gamelog::data
private

Definition at line 51 of file gamelog.h.


The documentation for this class was generated from the following files: