Conditional Undo
version 3/080626 by Jesse McGrew
Version 3/080626 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: change the prevent undo flag to true.
To do not prevent undo: change the prevent undo flag to 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).
After reading a command (this is the reset the prevent undo flag rule):
change the prevent undo flag to 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.
Include (-
Constant ALLOWUNDO_ACT = (+deciding whether to allow undo+);
Constant CANTUNDO_MSG = "That action cannot be undone.^^";
[ AllowUndo flag;
BeginActivity(ALLOWUNDO_ACT);
flag = ~~((+prevent undo flag+));
say__p = 0;
if (ForActivity(ALLOWUNDO_ACT))
flag = RulebookSucceeded();
if (flag == 0 && ~~say__p)
print (string) CANTUNDO_MSG;
EndActivity(ALLOWUNDO_ACT);
return flag;
];
-).
Include (-
[ Perform_Undo;
#ifdef PREVENT_UNDO; L__M(##Miscellany, 70); return; #endif;
if (turns == 1) { L__M(##Miscellany, 11); return; }
if (undo_flag == 0) { L__M(##Miscellany, 6); return; }
if (undo_flag == 1) { L__M(##Miscellany, 7); return; }
if (~~AllowUndo()) return;
if (VM_Undo() == 0) L__M(##Miscellany, 7);
];
-) instead of "Perform Undo" in "OutOfWorld.i6t".
Conditional Undo ends here.