OpenTTD Source
12.0-beta2
|
Go to the documentation of this file.
47 static char gamelog_revision[48] = { 0 };
48 static_assert(
lengthof(gamelog_revision) > GAMELOG_REVISION_LENGTH);
50 if (IsReleasedVersion()) {
51 return _openttd_revision;
52 }
else if (gamelog_revision[0] == 0) {
54 assert(_openttd_revision_modified < 3);
55 gamelog_revision[0] =
"gum"[_openttd_revision_modified];
57 strecat(gamelog_revision, _openttd_revision_hash,
lastof(gamelog_revision));
59 gamelog_revision[GAMELOG_REVISION_LENGTH - 1] =
'\0';
61 return gamelog_revision;
90 void GamelogStopAnyAction()
100 for (uint i = 0; i < gamelog_actions; i++) {
102 for (uint j = 0; j < la->
changes; j++) {
109 free(gamelog_action);
138 if (md5sum !=
nullptr) {
140 buf +=
seprintf(buf, last,
"GRF ID %08X, checksum %s",
BSWAP32(grfid), txt);
146 buf +=
seprintf(buf, last,
", filename: %s (md5sum matches)", gc->
filename);
150 buf +=
seprintf(buf, last,
", filename: %s (matches GRFID only)", gc->
filename);
152 buf +=
seprintf(buf, last,
", unknown GRF");
163 "GRF config changed",
167 "emergency savegame",
197 proc(
"---- gamelog start ----");
209 for (
const LoggedChange *lc = la->change; lc != lcend; lc++) {
213 default: NOT_REACHED();
215 buf +=
seprintf(buf,
lastof(buffer),
"New game mode: %u landscape: %u",
216 (uint)lc->mode.mode, (uint)lc->mode.landscape);
220 buf +=
seprintf(buf,
lastof(buffer),
"Revision text changed to %s, savegame version %u, ",
221 lc->revision.text, lc->revision.slver);
223 switch (lc->revision.modified) {
229 buf +=
seprintf(buf,
lastof(buffer),
"modified, _openttd_newgrf_version = 0x%08x", lc->revision.newgrf);
234 switch (lc->oldver.type) {
235 default: NOT_REACHED();
237 buf +=
seprintf(buf,
lastof(buffer),
"OTTD savegame without gamelog: version %u, %u",
238 GB(lc->oldver.version, 8, 16),
GB(lc->oldver.version, 0, 8));
252 lc->oldver.type ==
SGT_TTDP1 ?
"old" :
"new");
253 if (lc->oldver.version != 0) {
254 buf +=
seprintf(buf,
lastof(buffer),
", TTDP version %u.%u.%u.%u",
255 GB(lc->oldver.version, 24, 8),
GB(lc->oldver.version, 20, 4),
256 GB(lc->oldver.version, 16, 4),
GB(lc->oldver.version, 0, 16));
263 buf +=
seprintf(buf,
lastof(buffer),
"Setting changed: %s : %d -> %d", lc->setting.name, lc->setting.oldval, lc->setting.newval);
270 GrfIDMapping::Pair *gm = grf_names.
Find(lc->grfrem.grfid);
271 if (gm != grf_names.End() && !gm->second.was_missing) buf +=
seprintf(buf,
lastof(buffer),
". Gamelog inconsistency: GrfID was already added!");
272 grf_names[lc->grfadd.grfid] = gc;
277 GrfIDMapping::Pair *gm = grf_names.
Find(lc->grfrem.grfid);
279 buf =
PrintGrfInfo(buf,
lastof(buffer), lc->grfrem.grfid,
nullptr, gm != grf_names.End() ? gm->second.gc :
nullptr);
280 if (gm == grf_names.End()) {
281 buf +=
seprintf(buf,
lastof(buffer),
". Gamelog inconsistency: GrfID was never added!");
285 gm->second.was_missing =
true;
295 buf +=
seprintf(buf,
lastof(buffer),
"Compatible NewGRF loaded: ");
296 buf =
PrintGrfInfo(buf,
lastof(buffer), lc->grfcompat.grfid, lc->grfcompat.md5sum, gc);
297 if (!grf_names.
Contains(lc->grfcompat.grfid)) buf +=
seprintf(buf,
lastof(buffer),
". Gamelog inconsistency: GrfID was never added!");
298 grf_names[lc->grfcompat.grfid] = gc;
303 GrfIDMapping::Pair *gm = grf_names.
Find(lc->grfrem.grfid);
305 buf =
PrintGrfInfo(buf,
lastof(buffer), lc->grfparam.grfid,
nullptr, gm != grf_names.End() ? gm->second.gc :
nullptr);
306 if (gm == grf_names.End()) buf +=
seprintf(buf,
lastof(buffer),
". Gamelog inconsistency: GrfID was never added!");
311 GrfIDMapping::Pair *gm = grf_names.
Find(lc->grfrem.grfid);
312 buf +=
seprintf(buf,
lastof(buffer),
"GRF order changed: %08X moved %d places %s",
313 BSWAP32(lc->grfmove.grfid),
abs(lc->grfmove.offset), lc->grfmove.offset >= 0 ?
"down" :
"up" );
314 buf =
PrintGrfInfo(buf,
lastof(buffer), lc->grfmove.grfid,
nullptr, gm != grf_names.End() ? gm->second.gc :
nullptr);
315 if (gm == grf_names.End()) buf +=
seprintf(buf,
lastof(buffer),
". Gamelog inconsistency: GrfID was never added!");
320 GrfIDMapping::Pair *gm = grf_names.
Find(lc->grfrem.grfid);
321 switch (lc->grfbug.bug) {
322 default: NOT_REACHED();
324 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);
327 buf =
PrintGrfInfo(buf,
lastof(buffer), lc->grfbug.grfid,
nullptr, gm != grf_names.End() ? gm->second.gc :
nullptr);
328 if (gm == grf_names.End()) buf +=
seprintf(buf,
lastof(buffer),
". Gamelog inconsistency: GrfID was never added!");
340 proc(
"---- gamelog end ----");
344 static void GamelogPrintConsoleProc(
const char *s)
357 static void GamelogPrintDebugProc(
const char *s)
427 for (
const LoggedChange *lc = la->change; lc != lcend; lc++) {
432 return (emergency !=
nullptr);
443 if (lc ==
nullptr)
return;
445 memset(lc->revision.text, 0,
sizeof(lc->revision.text));
448 lc->revision.modified = _openttd_revision_modified;
449 lc->revision.newgrf = _openttd_newgrf_version;
460 if (lc ==
nullptr)
return;
462 lc->
mode.mode = _game_mode;
474 if (lc ==
nullptr)
return;
491 if (lc ==
nullptr)
return;
493 lc->setting.name =
stredup(name.c_str());
494 lc->setting.oldval = oldval;
495 lc->setting.newval = newval;
510 for (
const LoggedChange *lc = la->change; lc != lcend; lc++) {
516 rev->revision.modified != _openttd_revision_modified ||
517 rev->revision.newgrf != _openttd_newgrf_version) {
533 for (
const LoggedChange *lc = la->change; lc != lcend; lc++) {
553 if (lc ==
nullptr)
return;
555 lc->grfbug.data = data;
556 lc->grfbug.grfid = grfid;
557 lc->grfbug.bug = bug;
574 for (
const LoggedChange *lc = la->change; lc != lcend; lc++) {
575 if (lc->ct ==
GLCT_GRFBUG && lc->grfbug.grfid == grfid &&
609 if (lc ==
nullptr)
return;
611 lc->grfrem.grfid = grfid;
625 if (lc ==
nullptr)
return;
640 if (lc ==
nullptr)
return;
655 if (lc ==
nullptr)
return;
657 lc->grfmove.grfid = grfid;
658 lc->grfmove.offset = offset;
671 if (lc ==
nullptr)
return;
673 lc->grfparam.grfid = grfid;
685 for (; newg !=
nullptr; newg = newg->
next) {
729 while (o < ol->n && n < nl->n) {
735 for (oi = 0; oi < ol->n; oi++) {
748 for (ni = 0; ni < nl->n; ni++) {
764 assert(ni > n && ni < nl->n);
765 assert(oi > o && oi < ol->n);
806 void GamelogInfo(
LoggedAction *gamelog_action, uint gamelog_actions, uint32 *last_ottd_rev,
byte *ever_modified,
bool *removed_newgrfs)
808 const LoggedAction *laend = &gamelog_action[gamelog_actions];
809 for (
const LoggedAction *la = gamelog_action; la != laend; la++) {
811 for (
const LoggedChange *lc = la->change; lc != lcend; lc++) {
816 *last_ottd_rev = lc->revision.newgrf;
817 *ever_modified = std::max(*ever_modified, lc->revision.modified);
821 *removed_newgrfs =
true;
@ GLCT_GRFADD
Removed GRF.
void GamelogSetting(const std::string &name, int32 oldval, int32 newval)
Logs change in game settings.
@ GLCT_GRFBUG
GRF bug triggered.
static bool IsLoggableGrfConfig(const GRFConfig *g)
Decides if GRF should be logged.
void GamelogPrintProc(const char *s)
Callback for printing text.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
byte mode
new game mode - Editor x Game
const GRFConfig * FindGRFConfig(uint32 grfid, FindGRFConfigMode mode, const uint8 *md5sum, uint32 desired_version)
Find a NewGRF in the scanned list.
byte landscape
the landscape we're currently in
@ GLCT_GRFMOVE
GRF order changed.
uint8 num_params
Number of used parameters.
void GamelogMode()
Logs a change in game mode (scenario editor or game)
uint _gamelog_actions
number of actions
static void GamelogGRFBug(uint32 grfid, byte bug, uint64 data)
Logs triggered GRF bug.
uint16 tick
Tick when it happened.
void GamelogFree(LoggedAction *gamelog_action, uint gamelog_actions)
Frees the memory allocated by a gamelog.
@ GLCT_EMERGENCY
Emergency savegame.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
@ SGT_TTDP1
TTDP savegame ( -//- ) (data at NW border)
static GRFList * GenerateGRFList(const GRFConfig *grfc)
Generates GRFList.
const GRFConfig * gc
GRFConfig, if known.
@ GLCT_REVISION
Changed game revision string.
@ GCS_NOT_FOUND
GRF file was not found in the local cache.
GRFIdentifier ident
grfid and md5sum to uniquely identify newgrfs
GRFStatus status
NOSAVE: GRFStatus, enum.
GamelogActionType at
Type of action.
const SaveLoadVersion SAVEGAME_VERSION
current savegame version
@ GLAT_SETTING
Setting changed.
uint8 md5sum[16]
MD5 checksum of file to distinguish files with the same GRF ID (eg. newer version of GRF)
uint32 grfid
GRF ID (defined by Action 0x08)
SavegameType _savegame_type
type of savegame we are loading
Implementation of simple mapping class.
GameCreationSettings game_creation
settings used during the creation of a game (map)
void GamelogGRFRemove(uint32 grfid)
Logs removal of a GRF.
void GamelogPrint(GamelogPrintProc *proc)
Prints active gamelog.
@ FGCM_ANY
Use first found.
Basic data to distinguish a GRF.
uint32 changes
Number of changes in this action.
static void GamelogGRFMove(uint32 grfid, int32 offset)
Logs changing GRF order.
SavegameType
Types of save games.
Information about GRF, used in the game and (part of it) in savegames.
uint8 flags
NOSAVE: GCF_Flags, bitset.
@ GLAT_NONE
No logging active; in savegames, end of list.
bool GamelogTestEmergency()
Finds out if current game is a loaded emergency savegame.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
void GamelogStartAction(GamelogActionType at)
Stores information about new action, but doesn't allocate it Action is allocated only when there is a...
void GamelogEmergency()
Logs a emergency savegame.
uint16 _tick_counter
Ever incrementing (and sometimes wrapping) tick counter for setting off various events.
static LoggedChange * GamelogChange(GamelogChangeType ct)
Allocates new LoggedChange and new LoggedAction if needed.
SaveLoadVersion
SaveLoad versions Previous savegame versions, the trunk revision where they were introduced and the r...
static int _gamelog_print_level
gamelog debug level we need to print stuff
void GamelogPrintConsole()
Print the gamelog data to the console.
void Erase(Pair *pair)
Removes given pair from this map.
GamelogChangeType
Type of logged change.
void GamelogTestRevision()
Finds out if current revision is different than last revision stored in the savegame.
uint32 _ttdp_version
version of TTDP savegame (if applicable)
bool was_missing
Grf was missing during some gameload in the past.
LoggedChange * change
First logged change in this action.
@ GLAT_EMERGENCY
Emergency savegame.
static uint32 BSWAP32(uint32 x)
Perform a 32 bits endianness bitswap on x.
@ GLCT_GRFCOMPAT
Loading compatible GRF.
LoggedAction * _gamelog_action
first logged action
void GamelogStopAction()
Stops logging of any changes.
@ SGT_TTD
TTD savegame (can be detected incorrectly)
static GamelogActionType _gamelog_action_type
action to record if anything changes
void GamelogPrintDebug(int level)
Prints gamelog to debug output.
GamelogChangeType ct
Type of change logged in this struct.
@ GLCT_GRFPARAM
GRF parameter changed.
@ GLAT_CHEAT
Cheat was used.
void GamelogGRFCompatible(const GRFIdentifier *newg)
Logs loading compatible GRF (the same ID, but different MD5 hash)
byte _sl_minor_version
the minor savegame version, DO NOT USE!
GRFIdentifier grfadd
ID and md5sum of added GRF.
static char * PrintGrfInfo(char *buf, const char *last, uint grfid, const uint8 *md5sum, const GRFConfig *gc)
Prints GRF ID, checksum and filename if found.
struct GRFConfig * next
NOSAVE: Next item in the linked list.
void GamelogGRFUpdate(const GRFConfig *oldc, const GRFConfig *newc)
Compares two NewGRF lists and logs any change.
static const char *const la_text[]
Text messages for various logged actions.
static void GamelogGRFParameters(uint32 grfid)
Logs change in GRF parameters.
@ GLCT_OLDVER
Loaded from savegame without logged data.
@ GLAT_GRFBUG
GRF bug was triggered.
void GamelogGRFAddList(const GRFConfig *newg)
Logs adding of list of GRFs.
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
void GamelogGRFAdd(const GRFConfig *newg)
Logs adding of a GRF.
void GamelogReset()
Resets and frees all memory allocated - used before loading or starting a new game.
GRFIdentifier grfcompat
ID and new md5sum of changed GRF.
static T * ReallocT(T *t_ptr, size_t num_elements)
Simplified reallocation function that allocates the specified number of elements of the given type.
static T abs(const T a)
Returns the absolute value of (scalar) variable.
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
std::vector< Pair >::const_iterator Find(const T &key) const
Finds given key in this map.
#define Debug(name, level, format_string,...)
Ouptut a line of debugging information.
#define lengthof(x)
Return the length of an fixed size array.
@ GLAT_END
So we know how many GLATs are there.
Information about the presence of a Grf at a certain point during gamelog history Note about missing ...
void GamelogOldver()
Logs loading from savegame without gamelog.
void GamelogTestMode()
Finds last stored game mode or landscape.
void GamelogRevision()
Logs a change in game revision.
@ GLCT_SETTING
Non-networksafe setting value changed.
char * md5sumToString(char *buf, const char *last, const uint8 md5sum[16])
Convert the md5sum to a hexadecimal string representation.
@ FGCM_EXACT
Only find Grfs matching md5sum.
char * filename
Filename - either with or without full path.
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
Contains information about one logged change.
static const TextColour CC_WARNING
Colour for warning lines.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
char * strecat(char *dst, const char *src, const char *last)
Appends characters from one string to another.
static LoggedAction * _current_action
current action we are logging, nullptr when there is no action active
@ GLCT_MODE
Scenario editor x Game, different landscape.
GamelogActionType
The actions we log.
#define lastof(x)
Get the last element of an fixed size array.
@ GBUG_VEH_LENGTH
Length of rail vehicle changes when not inside a depot.
@ SGT_TTDP2
TTDP savegame in new format (data at SE border)
SaveLoadVersion _sl_version
the major savegame version identifier
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.
@ GLAT_START
Game created.
static const char * GetGamelogRevisionString()
Return the revision string for the current client version, for use in gamelog.
Contains information about one logged action that caused at least one logged change.
@ GCF_STATIC
GRF file is used statically (can be used in any MP game)
uint32 param[0x80]
GRF parameters.
List of GRFs using array of pointers instead of linked list.
bool GamelogGRFBugReverse(uint32 grfid, uint16 internal_id)
Logs GRF bug - rail vehicle has different length after reversing.
bool Contains(const T &key) const
Tests whether a key is assigned in this map.
void IConsolePrint(TextColour colour_code, const std::string &string)
Handle the printing of text entered into the console or redirected there by any other means.