Conditional Undo

version 4/140510 by Jesse McGrew

  • Home page
  • Complete text



  • Version 4/140510 of Conditional Undo by Jesse McGrew begins here.
    "Allows fine-grained control over whether to allow commands to be undone."
    Deciding whether to allow undo is an activity.
    The for deciding whether to allow undo rules have outcomes allow undo (success) and deny undo (failure).
    The for deciding whether to allow undo rules have default no outcome.
    The prevent undo flag is a truth state which varies.
    To prevent undo: now the prevent undo flag is true.
    To do not prevent undo: now the prevent undo flag is false.
    To decide whether undo is prevented: decide on the prevent undo flag.
    Deciding whether the action prevents undo is an activity.
    The for deciding whether the action prevents undo rules have outcomes it does not (failure) and it does (success).
    The for deciding whether the action prevents undo rules have default no outcome.
    After reading a command (this is the reset the prevent undo flag rule):
        now the prevent undo flag is false.
    Every turn (this is the decide whether the action prevents undo rule):
        begin the deciding whether the action prevents undo activity;
        unless handling the deciding whether the action prevents undo activity:
            if the rule succeeded, prevent undo;
            if the rule failed, do not prevent undo;
        end the deciding whether the action prevents undo activity.
    The Conditional Undo decision rule translates into I6 as "AllowUndo" with
        "That action cannot be undone.[paragraph break]" (A).
    Include (-
    Constant ALLOWUNDO_ACT = (+deciding whether to allow undo+);
    [ AllowUndo flag;
        BeginActivity(ALLOWUNDO_ACT);
        flag = ~~((+prevent undo flag+));
        say__p = 0;
        if (ForActivity(ALLOWUNDO_ACT))
            flag = RulebookSucceeded();
        if (flag == 0 && ~~say__p)
            AllowUndoM('A');
        EndActivity(ALLOWUNDO_ACT);
        return flag;
    ];
    -).
    Include (-
    [ Perform_Undo;
        #ifdef PREVENT_UNDO; IMMEDIATELY_UNDO_RM('A'); new_line; return; #endif;
        if (IterationsOfTurnSequence == 0) { IMMEDIATELY_UNDO_RM('B'); new_line; return; }
        if (undo_flag == 0) { IMMEDIATELY_UNDO_RM('C'); new_line; return; }
        if (undo_flag == 1) { IMMEDIATELY_UNDO_RM('D'); new_line; return; }
        if (~~AllowUndo()) return;
        if (VM_Undo() == 0) { IMMEDIATELY_UNDO_RM('A'); new_line; }
    ];
    -) instead of "Perform Undo" in "OutOfWorld.i6t".
    Conditional Undo ends here.