34 this->data = std::make_unique<GamelogInternalData>();
36 this->current_action =
nullptr;
48 if (IsReleasedVersion()) {
49 return _openttd_revision;
53 assert(_openttd_revision_modified < 3);
54 return fmt::format(
"{}{}",
55 "gum"[_openttd_revision_modified],
56 _openttd_revision_hash);
67 this->action_type = at;
77 bool print = this->current_action !=
nullptr;
79 this->current_action =
nullptr;
85void Gamelog::StopAnyAction()
96 this->data->action.clear();
97 this->current_action =
nullptr;
107static void AddGrfInfo(std::back_insert_iterator<std::string> &output_iterator,
GrfID grfid,
const MD5Hash *md5sum,
const GRFConfig *gc)
109 if (md5sum !=
nullptr) {
116 fmt::format_to(output_iterator,
", filename: {} (md5sum matches)", gc->
filename);
120 fmt::format_to(output_iterator,
", filename: {} (matches GRFID only)", gc->
filename);
122 fmt::format_to(output_iterator,
", unknown GRF");
132 "GRF config changed",
136 "emergency savegame",
147 proc(
"---- gamelog start ----");
154 for (
auto &lc : la.
change) {
156 auto output_iterator = std::back_inserter(message);
157 lc->FormatTo(output_iterator, grf_names, la.
at);
163 proc(
"---- gamelog end ----");
170 fmt::format_to(output_iterator,
"New game mode: {} landscape: {}", this->
mode, this->
landscape);
176 fmt::format_to(output_iterator,
"Revision text changed to {}, savegame version {}, ",
180 case 0: fmt::format_to(output_iterator,
"not ");
break;
181 case 1: fmt::format_to(output_iterator,
"maybe ");
break;
185 fmt::format_to(output_iterator,
"modified, _openttd_newgrf_version = 0x{:08x}", this->
newgrf);
191 fmt::format_to(output_iterator,
"Conversion from ");
192 switch (this->
type) {
193 default: NOT_REACHED();
195 fmt::format_to(output_iterator,
"OTTD savegame without gamelog: version {}, {}",
200 fmt::format_to(output_iterator,
"TTO savegame");
204 fmt::format_to(output_iterator,
"TTD savegame");
209 fmt::format_to(output_iterator,
"TTDP savegame, {} format",
212 fmt::format_to(output_iterator,
", TTDP version {}.{}.{}.{}",
223 fmt::format_to(output_iterator,
"Setting changed: {} : {} -> {}", this->
name, this->
oldval, this->
newval);
230 fmt::format_to(output_iterator,
"Added NewGRF: ");
232 auto gm = grf_names.find(this->
grfid);
233 if (gm != grf_names.end() && !gm->second.was_missing) fmt::format_to(output_iterator,
". Gamelog inconsistency: GrfID was already added!");
234 grf_names[this->
grfid] = gc;
240 auto gm = grf_names.find(this->
grfid);
242 fmt::format_to(output_iterator,
"Missing NewGRF: ");
244 fmt::format_to(output_iterator,
"Removed NewGRF: ");
246 AddGrfInfo(output_iterator, this->
grfid,
nullptr, gm != grf_names.end() ? gm->second.gc :
nullptr);
247 if (gm == grf_names.end()) {
248 fmt::format_to(output_iterator,
". Gamelog inconsistency: GrfID was never added!");
252 gm->second.was_missing =
true;
263 fmt::format_to(output_iterator,
"Compatible NewGRF loaded: ");
265 if (grf_names.count(this->grfid) == 0) fmt::format_to(output_iterator,
". Gamelog inconsistency: GrfID was never added!");
266 grf_names[this->
grfid] = gc;
272 auto gm = grf_names.find(this->
grfid);
273 fmt::format_to(output_iterator,
"GRF parameter changed: ");
274 AddGrfInfo(output_iterator, this->
grfid,
nullptr, gm != grf_names.end() ? gm->second.gc :
nullptr);
275 if (gm == grf_names.end()) fmt::format_to(output_iterator,
". Gamelog inconsistency: GrfID was never added!");
281 auto gm = grf_names.find(this->
grfid);
282 fmt::format_to(output_iterator,
"GRF order changed: {} moved {} places {}",
284 AddGrfInfo(output_iterator, this->
grfid,
nullptr, gm != grf_names.end() ? gm->second.gc :
nullptr);
285 if (gm == grf_names.end()) fmt::format_to(output_iterator,
". Gamelog inconsistency: GrfID was never added!");
291 auto gm = grf_names.find(this->
grfid);
294 fmt::format_to(output_iterator,
"Rail vehicle changes length outside a depot: GRF ID {}, internal ID 0x{:X}",
FormatArrayAsHex(this->
grfid), this->
data);
295 AddGrfInfo(output_iterator, this->
grfid,
nullptr, gm != grf_names.end() ? gm->second.gc :
nullptr);
296 if (gm == grf_names.end()) fmt::format_to(output_iterator,
". Gamelog inconsistency: GrfID was never added!");
308 this->
Print([](
const std::string &s) {
321 this->
Print([severity](
const std::string &s) {
333 if (this->current_action ==
nullptr) {
336 this->current_action = &this->data->action.emplace_back();
337 this->current_action->at = this->action_type;
341 this->current_action->change.push_back(std::move(change));
353 this->
Change(std::make_unique<LoggedChangeEmergencySave>());
364 for (
const auto &lc : la.
change) {
379 this->
Change(std::make_unique<LoggedChangeRevision>(
390 this->
Change(std::make_unique<LoggedChangeMode>(_game_mode,
_settings_game.game_creation.landscape));
414 this->
Change(std::make_unique<LoggedChangeSettingChanged>(name, oldval, newval));
427 for (
const auto &lc : la.
change) {
433 rev->
modified != _openttd_revision_modified ||
434 rev->
newgrf != _openttd_newgrf_version) {
448 for (
const auto &lc : la.
change) {
467 this->
Change(std::make_unique<LoggedChangeGRFBug>(data, grfid, bug));
482 for (
const auto &lc : la.
change) {
518 this->
Change(std::make_unique<LoggedChangeGRFRemoved>(grfid));
531 this->
Change(std::make_unique<LoggedChangeGRFAdd>(newg.
ident));
543 this->
Change(std::make_unique<LoggedChangeGRFChanged>(newg));
555 this->
Change(std::make_unique<LoggedChangeGRFMoved>(grfid, offset));
567 this->
Change(std::make_unique<LoggedChangeGRFParameterChanged>(grfid));
579 for (
const auto &c : newg) {
591 std::vector<const GRFConfig *> list;
592 for (
const auto &g : grfc) {
611 while (o < ol.size() && n < nl.size()) {
617 for (oi = 0; oi < ol.size(); oi++) {
618 if (ol[oi]->ident.grfid == nl[n]->ident.grfid)
break;
625 if (oi == ol.size()) {
630 for (ni = 0; ni < nl.size(); ni++) {
631 if (nl[ni]->ident.grfid == ol[o]->ident.grfid)
break;
638 if (ni == nl.size()) {
646 assert(ni > n && ni < nl.size());
647 assert(oi > o && oi < ol.size());
654 this->
GRFMove(ol[o++]->ident.grfid, ni);
656 this->
GRFMove(nl[n++]->ident.grfid, -(
int)oi);
673 while (o < ol.size()) this->
GRFRemove(ol[o++]->ident.grfid);
674 while (n < nl.size()) this->
GRFAdd (*nl[n++]);
683void Gamelog::Info(uint32_t *last_ottd_rev, uint8_t *ever_modified,
bool *removed_newgrfs)
686 for (
const auto &lc : la.
change) {
692 *last_ottd_rev = rev->
newgrf;
693 *ever_modified = std::max(*ever_modified, rev->
modified);
698 *removed_newgrfs =
true;
715 for (
const auto &lc : la.
change) {
static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
void TestRevision()
Finds out if current revision is different than last revision stored in the savegame.
const GRFIdentifier & GetOverriddenIdentifier(const GRFConfig &c)
Try to find the overridden GRF identifier of the given GRF.
void PrintDebug(Severity severity)
Prints gamelog to debug output.
bool GRFBugReverse(GrfID grfid, uint16_t internal_id)
Logs GRF bug - rail vehicle has different length after reversing.
void Mode()
Logs a change in game mode (scenario editor or game).
void Info(uint32_t *last_ottd_rev, uint8_t *ever_modified, bool *removed_newgrfs)
Get some basic information from the given gamelog.
void PrintConsole()
Print the gamelog data to the console.
void GRFParameters(GrfID grfid)
Logs change in GRF parameters.
void Revision()
Logs a change in game revision.
void StartAction(GamelogActionType at)
Stores information about new action, but doesn't allocate it Action is allocated only when there is a...
void Reset()
Resets and frees all memory allocated - used before loading or starting a new game.
void GRFRemove(GrfID grfid)
Logs removal of a GRF.
void GRFMove(GrfID grfid, int32_t offset)
Logs changing GRF order.
void GRFAddList(const GRFConfigList &newg)
Logs adding of list of GRFs.
~Gamelog()
Needs to be manually defined due to incomplete definition of GamelogInternalData in the header.
void GRFCompatible(const GRFIdentifier &newg)
Logs loading compatible GRF (the same ID, but different MD5 hash).
void Oldver()
Logs loading from savegame without gamelog.
void Emergency()
Logs a emergency savegame.
void TestMode()
Finds last stored game mode or landscape.
void StopAction()
Stops logging of any changes.
void GRFBug(GrfID grfid, ::GRFBug bug, uint64_t data)
Logs triggered GRF bug.
void Setting(const std::string &name, int32_t oldval, int32_t newval)
Logs change in game settings.
void Print(std::function< void(const std::string &)> proc)
Prints active gamelog.
void GRFAdd(const GRFConfig &newg)
Logs adding of a GRF.
void GRFUpdate(const GRFConfigList &oldg, const GRFConfigList &newg)
Compares two NewGRF lists and logs any change.
void Change(std::unique_ptr< LoggedChange > &&change)
Allocates a new LoggedAction if needed, and add the change when action is active.
bool TestEmergency()
Finds out if current game is a loaded emergency savegame.
static TickCounter counter
Monotonic counter, in ticks, since start of game.
void IConsolePrint(ExtendedTextColour colour_code, const std::string &string)
Handle the printing of text entered into the console or redirected there by any other means.
Console functions used outside of the console code.
static const TextColour CC_WARNING
Colour for warning lines.
Functions related to debugging.
#define Debug(facility, severity, format_string,...)
Output a line of debugging information.
@ Gamelog
Gamelog message facility.
Severity
Debug message severity levels.
@ Debug1
Debug #1 - High level debug messages.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
EnumClassIndexContainer< std::array< T, to_underlying(N)>, Index > EnumIndexArray
A typedef for EnumClassIndexContainer using std::array as the backing container type.
uint32_t _ttdp_version
version of TTDP savegame (if applicable)
SaveLoadVersion _sl_version
the major savegame version identifier
uint8_t _sl_minor_version
the minor savegame version, DO NOT USE!
static std::string GetGamelogRevisionString()
Return the revision string for the current client version, for use in gamelog.
Gamelog _gamelog
Gamelog instance.
static bool IsLoggableGrfConfig(const GRFConfig &g)
Decides if GRF should be logged.
static constexpr EnumIndexArray< std::string_view, GamelogActionType, GamelogActionType::End > la_text
Text messages for various logged actions.
SavegameType _savegame_type
type of savegame we are loading
static std::vector< const GRFConfig * > GenerateGRFList(const GRFConfigList &grfc)
Generates GRFList.
const SaveLoadVersion SAVEGAME_VERSION
current savegame version
static void AddGrfInfo(std::back_insert_iterator< std::string > &output_iterator, GrfID grfid, const MD5Hash *md5sum, const GRFConfig *gc)
Adds the GRF ID, checksum and filename if found to the output iterator.
@ GRFCompat
Loading compatible GRF.
@ Revision
Changed game revision string.
@ Mode
Scenario editor x Game, different landscape.
@ Emergency
Emergency savegame.
@ GRFBug
GRF bug triggered.
GamelogActionType
The actions we log.
@ Setting
Setting changed.
@ None
No logging active; in savegames, end of list.
@ Emergency
Emergency savegame.
@ GRFBug
GRF bug was triggered.
Declaration shared among gamelog.cpp and saveload/gamelog_sl.cpp.
std::map< GrfID, GRFPresence > GrfIDMapping
A mapping from GrfID to the GRFPresence.
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
const GRFConfig * FindGRFConfig(GrfID grfid, FindGRFConfigMode mode, const MD5Hash *md5sum, uint32_t desired_version)
Find a NewGRF in the scanned list.
@ NotFound
GRF file was not found in the local cache.
@ Static
GRF file is used statically (can be used in any MP game).
GRFBug
Encountered GRF bugs.
@ VehLength
Length of rail vehicle changes when not inside a depot.
@ Exact
Only find Grfs matching md5sum.
Label< struct GrfIDTag > GrfID
The unique identifier of a NewGRF.
Declaration of OTTD revision dependent variables.
A number of safeguards to prevent using unsafe methods.
Functions/types related to saving and loading games.
SavegameType
Types of save games.
@ TTDP1
TTDP savegame ( -//- ) (data at NW border).
@ TTD
TTD savegame (can be detected incorrectly).
@ TTDP2
TTDP savegame in new format (data at SE border).
SaveLoadVersion
SaveLoad versions Previous savegame versions, the trunk revision where they were introduced and the r...
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Types related to global configuration settings.
Definition of base types and functions in a cross-platform compatible way.
std::string FormatArrayAsHex(std::span< const uint8_t > data)
Format a byte array into a continuous hex string.
Functions related to low-level strings.
Information about GRF, used in the game and (part of it) in savegames.
std::vector< uint32_t > param
GRF parameters.
GRFStatus status
NOSAVE: GRFStatus, enum.
GRFConfigFlags flags
NOSAVE: GCF_Flags, bitset.
std::string filename
Filename - either with or without full path.
GRFIdentifier ident
grfid and md5sum to uniquely identify newgrfs
Basic data to distinguish a GRF.
GrfID grfid
GRF ID (defined by Action 0x08).
MD5Hash md5sum
MD5 checksum of file to distinguish files with the same GRF ID (eg. newer version of GRF).
Contains information about one logged action that caused at least one logged change.
uint64_t tick
Tick when it happened.
std::vector< std::unique_ptr< LoggedChange > > change
Logged changes in this action.
GamelogActionType at
Type of action.
void FormatTo(std::back_insert_iterator< std::string > &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override
Format the content of this change into the given output.
void FormatTo(std::back_insert_iterator< std::string > &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override
Format the content of this change into the given output.
A log entry for a NewGRF bug.
void FormatTo(std::back_insert_iterator< std::string > &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override
Format the content of this change into the given output.
GrfID grfid
ID of problematic GRF.
uint64_t data
additional data
A log entry for a NewGRF that was changed.
void FormatTo(std::back_insert_iterator< std::string > &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override
Format the content of this change into the given output.
void FormatTo(std::back_insert_iterator< std::string > &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override
Format the content of this change into the given output.
int32_t offset
offset, positive = move down
GrfID grfid
ID of moved GRF.
void FormatTo(std::back_insert_iterator< std::string > &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override
Format the content of this change into the given output.
GrfID grfid
ID of GRF with changed parameters.
GrfID grfid
ID of removed GRF.
void FormatTo(std::back_insert_iterator< std::string > &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override
Format the content of this change into the given output.
Log element for the change of the game mode and landscape.
LandscapeType landscape
landscape (temperate, arctic, ...)
void FormatTo(std::back_insert_iterator< std::string > &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override
Format the content of this change into the given output.
GameMode mode
new game mode - Editor x Game
void FormatTo(std::back_insert_iterator< std::string > &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override
Format the content of this change into the given output.
uint32_t type
type of savegame,
uint32_t version
major and minor version OR ttdp version
A log entry for a change in OpenTTD version.
std::string text
revision string, _openttd_revision
void FormatTo(std::back_insert_iterator< std::string > &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override
Format the content of this change into the given output.
uint16_t slver
_sl_version
uint32_t newgrf
_openttd_newgrf_version
uint8_t modified
_openttd_revision_modified
std::string name
name of the setting
void FormatTo(std::back_insert_iterator< std::string > &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override
Format the content of this change into the given output.
Definition of the tick-based game-timer.