Re: Inform: Question about scope


25 Sep 1995 09:57:49 GMT

Christopher E. Forman (ceforma@rs6000.cmp.ilstu.edu) wrote:
> Is there a simple function in Inform to check if a particular item is
> in scope?

Below are some useful functions for getting information about the object
tree. In most cases, you can use a test like
`(LineOfSight(thing,player)==1)' to determine if `thing' is in scope.

! Inside(o,p) returns 1 if object o is contained (indirectly) in p.

[ Inside o p;
while (o ~= p or 0) {
o = parent(o)
}
if (o ~= p) rfalse;
];

! MaxBox(o) walks up the object tree starting at o until it comes to
! a room or an opaque container, which it returns. Thus it returns
! the smallest opaque container surrounding o. Use MaxBox for
! visibility tests: two objects can see each other if and only if
! they have the same MaxBox.

[ MaxBox o;
do {
o = parent(o)
} until (o == 0 || parent(o) == 0 || (o ~= player &&
o hasnt transparent && o hasnt supporter && o hasnt open));
return o;
];

! MaxContainer(o) returns the smallest room or closed container
! surrounding o. Use MaxContainer for physical access: two objects
! can, in principle, touch if they have the same MaxContainer.

[ MaxContainer o;
do {
o = parent(o);
} until (o == 0 || parent(o) == 0 || (o ~= player &&
o hasnt supporter && o hasnt open));
return o;
];

! LineOfSight(x,y) returns 1 if object x can see object y; 0
! otherwise.

[ LineOfSight x y a b;
a = MaxBox(x);
b = MaxBox(y);
if (a ~= b || HasLight(a) == 0) rfalse;
];

However, these functions are defeated by objects put into scope by the
`add_to_scope' property and the `InScope' function. I can't think of
any more general solution than Replacing the `AddToScope' and
`PlaceInScope' functions and overloading the meaning of the
`add_to_scope' property yet again.

--
Gareth Rees