! Chooo.h by Krister Fundin (
[email protected])
!
! This is an object oriented extension to the ChooseObjects entry point.
! Adopting it only requires a couple of simple steps:
!
! 1. In your ChooseObjects routine, start by generating a default return
! value. If you, for instance, want to exclude scenery from "all" lists,
! then this could be done here. If you don't want to make any such global
! decisions, just choose a default of 0 if the "code" argument is 0 or 1,
! or a number like 5 if the code is 2.
!
! 2. Add this line to the end of your ChooseObjects routine:
!
! return ChooseObjectsOO(code, default);
!
! where the second argument is the default value you decided on earlier.
!
! 3. In any object or class for which you want to return something else
! than the default value, give it one of the methods choose_noun(),
! choose_second() or choose_multi().
!
! choose_noun()
! Is called when the code is 2 and the object under consideration is a
! noun. Return 1 to 9 or false to not make a decision.
!
! choose_second(noun)
! Is called when the code is 2 and the object under consideration is a
! second. The noun is given as the first argument. Return 1 to 9 or false
! to not make a decision.
!
! choose_multi(code)
! Is called when code is 0 or 1. The code is passed as the first argument.
! Return 1 to force the object to be included in the "all" list, 2 to
! force it to be excluded, or false to not make a decision.
!
! These three methods are all additive. If an object returns false, and
! one of its superclasses has its own method, that superclass is asked to
! do the same decision. If it also returns false, the process is repeated.
! If no decision is made, the default value supplied to ChooseObjectsOO()
! is returned. You can also force the default value to be chosen by
! returning -1 from any of these methods.
!
! In all three methods, you can use action_to_be to check the action. It
! is also possible to use the same implied switch syntax as in before and
! after routines.
!
! As you can see, the object oriented interface doesn't completely replace
! the old entry point interface but rather augments it. First, a decision
! is made on a global level, then the object has a chance to override that
! decision.
!
! Krister Fundin, 2005
property additive choose_noun;
property additive choose_second;
property additive choose_multi;
[ ChooseObjectsOO obj code default par ret s;
! set the action for easy switching
s = action;
action = action_to_be;
! check if we have reversed grammar
if (action_reversed)
par = 1-parameters;
else
par = parameters;
! call the appropriate method
if (code == 2)
{
if (par == 0)
ret = obj.choose_noun();
else
ret = obj.choose_second(inputobjs-->2);
}
else
{
ret = obj.choose_multi(code);
}
! restore old action
action = s;
! uncomment for debugging
!print (name) obj, ": code = ", code, ", ret = ", ret,
! ", default = ", default;
!new_line;
! if we have a value, return it, else return the default
if (ret && ret ~= -1)
return ret;
else
return default;
];