[Bug] (Minor) Restore move route index skip

👋 I'll use these phrases:
  • "Passive route" = an event's autonomous movement route.
  • "Active route" = a forced move route; a move route applied via, for example, the Set Movement Route command.
User: @caethyril
Bug:
  • When an active move route ends, the passive route (if any) is restored. However, the passive route's index is immediately incremented, meaning that one move command is always skipped. This can result in unreliable behaviour.
How to replicate/demo
Code explanation
  • processMoveCommand is unconditionally followed by advanceMoveRouteIndex:
    Spoiler: rpg_objects.js, updateRoutineMove & advanceMoveRouteIndex
    JavaScript:
    Game_Character.prototype.updateRoutineMove = function() {
        if (this._waitCount > 0) {
            this._waitCount--;
        } else {
            this.setMovementSuccess(true);
            var command = this._moveRoute.list[this._moveRouteIndex];
            if (command) {
                this.processMoveCommand(command);
                this.advanceMoveRouteIndex();
            }
        }
    };
    
    Game_Character.prototype.advanceMoveRouteIndex = function() {
        var moveRoute = this._moveRoute;
        if (moveRoute && (this.isMovementSucceeded() || moveRoute.skippable)) {
            var numCommands = moveRoute.list.length - 1;
            this._moveRouteIndex++;
            if (moveRoute.repeat && this._moveRouteIndex >= numCommands) {
                this._moveRouteIndex = 0;
            }
        }
    };
    The memorize/restore routines simply take the current index value:
    Spoiler: rpg_objects.js, memorize & restoreMoveRoute
    JavaScript:
    Game_Character.prototype.memorizeMoveRoute = function() {
        this._originalMoveRoute       = this._moveRoute;
        this._originalMoveRouteIndex  = this._moveRouteIndex;
    };
    
    Game_Character.prototype.restoreMoveRoute = function() {
        this._moveRoute          = this._originalMoveRoute;
        this._moveRouteIndex     = this._originalMoveRouteIndex;
        this._originalMoveRoute  = null;
    };
    Thus when the passive route is restored, its index is effectively set to "original + 1". However, at that point the original index has not been processed, because it was replaced by the first command of the active route.
Two possible fixes
  1. Subtract one from the original move route index on memorisation:
    Spoiler: Option 1
    JavaScript:
    Game_Character.prototype.memorizeMoveRoute = function() {
        this._originalMoveRoute       = this._moveRoute;
        this._originalMoveRouteIndex  = this._moveRouteIndex - 1;  // <- edit 1 of 1
    };
  2. Alternatively, subtract one from the index on restore:
    Spoiler: Option 2
    JavaScript:
    Game_Character.prototype.restoreMoveRoute = function() {
        this._moveRoute          = this._originalMoveRoute;
        this._moveRouteIndex     = this._originalMoveRouteIndex - 1;  // <- edit 1 of 1
        this._originalMoveRoute  = null;
    };
It looks like this bug is also present in v0.9.5 of the RMMZ code (I don't think there's a forum for that yet, though). 😅

Original thread: https://forums.rpgmakerweb.com/threads/bug-minor-restore-move-route-index-skip.125011/