Action Queuing
version 3 by Jesse McGrew
Version 3 of Action Queuing by Jesse McGrew begins here.
"Allows actions to be stored in a queue and run later, for the player or any other actor. Includes an example of a team of movers placing objects around a house."
Use queued action debugging translates as (- Constant QA_DEBUG; -).
Table of Queued Actions
| index | actor | action-number | noun | second |
| a number | a person | a number | a miscellaneous-value | a miscellaneous-value |
| with 99 blank rows. |
To queue (act - action):
(- Queue{act} -).
To queue (act - action) immediately:
(- FQueue{act} -).
To queue (x - person) trying the current action:
(- QueueI7_TryAction(0, {x}, action, noun, second); -).
To queue (x - person) trying the current action immediately:
(- FQueueI7_TryAction(0, {x}, action, noun, second); -).
To perform the next queued action, following unsuccessful attempt rules:
repeat through Table of Queued Actions in index order
begin;
let actE be the action-number entry; let actorE be the actor entry; let nE be the noun entry; let sE be the second entry;
blank out the whole row;
if following unsuccessful attempt rules, perform the queued action actE by actorE with nE and sE, following unsuccessful attempt rules;
otherwise perform the queued action actE by actorE with nE and sE;
stop;
end repeat.
To perform the next queued action for (x - person), following unsuccessful attempt rules:
repeat through Table of Queued Actions in index order
begin;
if the actor entry is x
begin;
let actE be the action-number entry; let nE be the noun entry; let sE be the second entry;
blank out the whole row;
if following unsuccessful attempt rules, perform the queued action actE by x with nE and sE, following unsuccessful attempt rules;
otherwise perform the queued action actE by x with nE and sE;
stop;
end if;
end repeat.
To perform the next queued action for every person, following unsuccessful attempt rules:
repeat with x running through people
begin;
if any actions are queued for x
begin;
if following unsuccessful attempt rules, perform the next queued action for x, following unsuccessful attempt rules;
otherwise perform the next queued action for x;
end if;
end repeat.
To delete the first queued action for (x - person):
repeat through Table of Queued Actions in index order
begin;
if the actor entry is x
begin;
blank out the whole row;
stop;
end if;
end repeat.
To delete the last queued action for (x - person):
repeat through Table of Queued Actions in reverse index order
begin;
if the actor entry is x
begin;
blank out the whole row;
stop;
end if;
end repeat.
To delete all queued actions for (x - person):
repeat through Table of Queued Actions
begin;
if the actor entry is x, blank out the whole row;
end repeat.
To clear the action queue:
repeat through Table of Queued Actions
begin;
blank out the whole row;
end repeat.
To perform the queued action (action - number) by (x - object) with (noun - miscellaneous-value) and (second - miscellaneous-value), following unsuccessful attempt rules:
(- UnsuccI7_TryAction({phrase options}, 0, {x}, {action}, {noun}, {second}); -).
To decide which number is number of actions queued for (x - person):
let N be 0;
repeat through Table of Queued Actions
begin;
if the actor entry is x, increase N by 1;
end repeat;
decide on N.
To decide whether any actions are queued for (x - person):
if the number of actions queued for x is 0, decide no;
otherwise decide yes.
To decide whether no actions are queued for (x - person):
if the number of actions queued for x is 0, decide yes;
otherwise decide no.
To decide whether (act - action) is queued:
(- (CheckQ{act}{-delete}{-delete}, 1)) -).
To decide whether (act - action) is not queued:
(- (CheckQ{act}{-delete}{-delete}, 1)==false) -).
To decide whether (act - action) is queued next for (x - object):
(- (CheckQNext{act}{-delete}{-delete}, {x})) -).
To decide whether (act - action) is not queued next for (x - object):
(- (CheckQNext{act}{-delete}{-delete}, {x})==false) -).
To decide whether (act - action) is queued at least (N - number) times:
(- (CheckQ{act}{-delete}{-delete}, {N})) -).
To decide whether (act - action) is not queued at least (N - number) times:
(- (CheckQ{act}{-delete}{-delete}, {N})==false) -).
Include (-
Constant queued_actions = (+Table of Queued Actions+);
Global next_qa_index = 1;
Global next_fqa_index = 0;
#Ifdef QA_DEBUG;
[ ActionName ac i;
i=FindAction(ac);
if (i==0) "(bad action)";
print (string) ActionData-->(i+4);
if (ActionData-->(i+6)~=$ffff) {
print " it ";
print (string) ActionData-->(i+6);
}
];
#Endif;
[ QueueI7_TryAction req by ac n s row;
if (TableBlankRows(queued_actions)==0) {
print "[*** No space left for actions. Add more blank rows to the Table of Queued Actions. ***]^";
rfalse;
}
#Ifdef QA_DEBUG; print "[queuing action (", req, ", ", (name) by, ", ", (ActionName) ac, ", ", (name) n, ", ", (name) s, ")]^"; #Endif;
row = TableBlankRow(queued_actions);
TableLookUpEntry(queued_actions, 1, row, 1, next_qa_index++);
TableLookUpEntry(queued_actions, 2, row, 1, by);
TableLookUpEntry(queued_actions, 3, row, 1, ac);
TableLookUpEntry(queued_actions, 4, row, 1, n);
TableLookUpEntry(queued_actions, 5, row, 1, s);
return row;
];
[ FQueueI7_TryAction req by ac n s row;
row = QueueI7_TryAction(req, by, ac, n, s);
if (row==0) rfalse;
--next_qa_index;
TableLookUpEntry( queued_actions, 1, row, 1, next_fqa_index-- );
return row;
];
[ UnsuccI7_TryAction opt req by ac n s;
#Ifdef QA_DEBUG; print "[performing queued action (", opt, ", ", req, ", ", (name) by, ", ", (ActionName) ac, ", ", (name) n, ", ", (name) s, ")]^"; #Endif;
if (opt==0) return I7_TryAction(req, by, ac, n, s);
@push actor; @push act_requester; @push inp1; @push inp2;
actor = by; if (req) act_requester = player; else act_requester = 0;
! print inp1, inp2, "^";
by = FindAction(ac);
if (by) {
if (ActionData-->(by+2) == 7) inp1 = n; else inp1 = 1;
if (ActionData-->(by+3) == 7) inp2 = s; else inp2 = 1;
}
! print "Made by ITA: ", inp1, inp2, "^";
if (InformLibrary.begin_action(ac, n, s)==false && actor~=player) {
@push action; @push noun; @push second;
action=ac; noun=n; second=s;
ProcessRulebook(UNABLE_RB);
@pull second; @pull noun; @pull action;
}
! <(ac) n s>;
! print inp1, inp2, "^";
@pull inp2; @pull inp1; @pull act_requester; @pull actor;
];
[ CheckQI7_TryAction req by ac n s count i max v;
if (count==0) rtrue;
max=TableRows(queued_actions);
for ( i=1:i<=max:i++ ) {
if (CheckQRow(i, by, ac, n, s)) {
! this one matches..
if ( --count==0 ) rtrue;
}
}
rfalse;
];
[ CheckQNextI7_TryAction req by0 ac n s by i v;
for ( i=TableNextRow(queued_actions, 1, 0, 1): i: i=TableNextRow(queued_actions, 1, i, 1) ) {
v=TableLookUpEntry(queued_actions, 2, i);
if (metaclass(by)==Routine) {
if (by(v)==false) continue;
} else {
if (by~=v) continue;
}
return CheckQRow(i, by, ac, n, s);
}
rfalse;
];
[ CheckQRow i by ac n s v;
if (TableRowIsBlank(queued_actions, i)) rfalse;
v=TableLookUpEntry(queued_actions, 2, i);
if (metaclass(by)==Routine) {
if (by(v)==false) rfalse;
} else {
if (by~=v) rfalse;
}
v=TableLookUpEntry(queued_actions, 3, i);
if (metaclass(ac)==Routine) {
if (ac(v)==false) rfalse;
} else {
if (ac~=v) rfalse;
}
v=TableLookUpEntry(queued_actions, 4, i);
if (metaclass(n)==Routine) {
if (n(v)==false) rfalse;
} else {
if (n~=v) rfalse;
}
v=TableLookUpEntry(queued_actions, 5, i);
if (metaclass(s)==Routine) {
if (s(v)==false) rfalse;
} else {
if (s~=v) rfalse;
}
rtrue;
];
-).
Action Queuing by Jesse McGrew ends here.