diff options
author | smatz <smatz@openttd.org> | 2008-07-24 15:19:26 +0000 |
---|---|---|
committer | smatz <smatz@openttd.org> | 2008-07-24 15:19:26 +0000 |
commit | aae2aa64c4281583ea31d668d85301fe7996bd2e (patch) | |
tree | 881cc1be79243d58238de4eda1a24345c93a5735 /src/gamelog.cpp | |
parent | 9bee9948986c4c4905c53b6214311e2ddb6d6e8d (diff) | |
download | openttd-aae2aa64c4281583ea31d668d85301fe7996bd2e.tar.xz |
(svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
Diffstat (limited to 'src/gamelog.cpp')
-rw-r--r-- | src/gamelog.cpp | 77 |
1 files changed, 73 insertions, 4 deletions
diff --git a/src/gamelog.cpp b/src/gamelog.cpp index f612f8951..029f43b70 100644 --- a/src/gamelog.cpp +++ b/src/gamelog.cpp @@ -39,6 +39,7 @@ enum GamelogChangeType { GLCT_GRFCOMPAT, ///< Loading compatible GRF GLCT_GRFPARAM, ///< GRF parameter changed GLCT_GRFMOVE, ///< GRF order changed + GLCT_GRFBUG, ///< GRF bug triggered GLCT_END, ///< So we know how many GLCTs are there GLCT_NONE = 0xFF, ///< In savegames, end of list }; @@ -79,6 +80,11 @@ struct LoggedChange { int32 oldval; ///< old value int32 newval; ///< new value } patch; + struct { + uint64 data; ///< additional data + uint32 grfid; ///< ID of problematic GRF + byte bug; ///< type of bug, @see enum GRFBugs + } grfbug; }; }; @@ -198,7 +204,8 @@ static const char *la_text[] = { "game loaded", "GRF config changed", "cheat was used", - "patch settings changed" + "patch settings changed", + "GRF bug triggered", }; assert_compile(lengthof(la_text) == GLAT_END); @@ -300,6 +307,15 @@ void GamelogPrint(GamelogPrintProc *proc) BSWAP32(lc->grfmove.grfid), abs(lc->grfmove.offset), lc->grfmove.offset >= 0 ? "down" : "up" ); PrintGrfFilename(buf, lc->grfmove.grfid); break; + + case GLCT_GRFBUG: + switch (lc->grfbug.bug) { + default: NOT_REACHED(); + case GBUG_VEH_LENGTH: + AddDebugText(buf, "Rail vehicle changes length outside a depot: GRF ID %08X, internal ID 0x%X", BSWAP32(lc->grfbug.grfid), (uint)lc->grfbug.data); + PrintGrfFilename(buf, lc->grfbug.grfid); + break; + } } proc(buf); @@ -469,6 +485,51 @@ void GamelogTestMode() } +/** Logs triggered GRF bug. + * @param grfid ID of problematic GRF + * @param bug type of bug, @see enum GRFBugs + * @param data additional data + */ +static void GamelogGRFBug(uint32 grfid, byte bug, uint64 data) +{ + assert(_gamelog_action_type == GLAT_GRFBUG); + + LoggedChange *lc = GamelogChange(GLCT_GRFBUG); + if (lc == NULL) return; + + lc->grfbug.data = data; + lc->grfbug.grfid = grfid; + lc->grfbug.bug = bug; +} + +/** 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). + * @param engine engine to log + * @return true iff a unique record was done + */ +bool GamelogGRFBugReverse(uint32 grfid, uint16 internal_id) +{ + const LoggedAction *laend = &_gamelog_action[_gamelog_actions]; + for (const LoggedAction *la = _gamelog_action; la != laend; la++) { + const LoggedChange *lcend = &la->change[la->changes]; + for (const LoggedChange *lc = la->change; lc != lcend; lc++) { + if (lc->ct == GLCT_GRFBUG && lc->grfbug.grfid == grfid && + lc->grfbug.bug == GBUG_VEH_LENGTH && lc->grfbug.data == internal_id) { + return false; + } + } + } + + GamelogStartAction(GLAT_GRFBUG); + GamelogGRFBug(grfid, GBUG_VEH_LENGTH, internal_id); + GamelogStopAction(); + + return true; +} + + /** Decides if GRF should be logged * @param g grf to determine * @return true iff GRF is not static and is loaded @@ -724,8 +785,15 @@ static const SaveLoad _glog_grfparam_desc[] = { }; static const SaveLoad _glog_grfmove_desc[] = { - SLE_VAR(LoggedChange, grfmove.grfid, SLE_UINT32), - SLE_VAR(LoggedChange, grfmove.offset, SLE_INT32), + SLE_VAR(LoggedChange, grfmove.grfid, SLE_UINT32), + SLE_VAR(LoggedChange, grfmove.offset, SLE_INT32), + SLE_END() +}; + +static const SaveLoad _glog_grfbug_desc[] = { + SLE_VAR(LoggedChange, grfbug.data, SLE_UINT64), + SLE_VAR(LoggedChange, grfbug.grfid, SLE_UINT32), + SLE_VAR(LoggedChange, grfbug.bug, SLE_UINT8), SLE_END() }; @@ -738,7 +806,8 @@ static const SaveLoad *_glog_desc[] = { _glog_grfrem_desc, _glog_grfcompat_desc, _glog_grfparam_desc, - _glog_grfmove_desc + _glog_grfmove_desc, + _glog_grfbug_desc, }; assert_compile(lengthof(_glog_desc) == GLCT_END); |