Ok, to get this working how I'd like, it took some finessing of WhatsIn and SpecialDesc. Working with important but complicated routines like WhatsIn and Parse always make me feel like trying to fix a leaky boat, but I'm sure whatever new leaks I spring will bring us closer to better routines in the long run.
Here are the updated routines:
Code: Select all
!\ Added some code so that if the obj is the only child of a parent, it still
checks (and lists) any children of that obj. \!
replace SpecialDesc(obj)
{
local a, c, flag, printed_blankline
if FORMAT & LIST_F
return
list_count = 0
for a in obj
{
if a is not hidden
{
c++
flag = true
}
else
flag = false
if FORMAT & INVENTORY_F and obj = player and flag
{
if &a.inv_desc
Indent
if a.inv_desc
{
if FORMAT & LIST_F: print newline
AddSpecialDesc(a)
}
}
elseif a is not moved and flag
{
if &a.initial_desc
{
print newline
override_indent = false
if FORMAT & INVENTORY_F and FORMAT & NOINDENT_F and not printed_blankline
print ""
printed_blankline = true
Indent
}
if a.initial_desc
AddSpecialDesc(a)
}
}
list_count = c - list_count
if not list_count and c
{
for a in obj
{
if children(a) and a is not quiet and (a is platform or a is transparent or (a is container and a is open)) and
not a.list_contents
{
WhatsIn(a)
list_count = 0
}
}
}
}
! changed a carriage return to 'print newline'
replace WhatsIn(obj)
{
local i, totallisted
local initial_list_nest
if FORMAT & NORECURSE_F
return
for i in obj
{
i is not already_listed
if i is not hidden
totallisted++
}
if totallisted = 0
return
list_count = totallisted
if obj is not container or (obj is container and obj is platform) or
(obj is container and (obj is not openable or
(obj is openable and
(obj is open or obj is transparent)))) and
(obj ~= player or FORMAT & INVENTORY_F) and obj is not quiet
{
SpecialDesc(obj)
! If list_count is 0 now, but totallisted was not, something must have been
! printed by SpecialDesc
if list_count = 0
{
if FORMAT & INVENTORY_F and not (FORMAT & LIST_F) and
list_nest = 0
{
! print ""
print newline
}
return totallisted
}
if obj.list_contents
return totallisted
initial_list_nest = list_nest
if FORMAT & LIST_F
{
if list_nest
{
! Indent the first time so that it lines up with
! paragraph indentation:
i = list_nest
if list_nest = 1 and not (FORMAT & NOINDENT_F)
{
Indent
i--
}
print to (i * 2); ! INDENT_SIZE);
}
}
else
{
Indent
}
if obj.contains_desc ! custom heading
{
if FORMAT & LIST_F
RLibMessage(&WhatsIn, 1 ) ! ":"
}
else
{
if obj = player
{
if FORMAT & LIST_F and list_count < totallisted
print "\n";
! "You are carrying..."
Message(&WhatsIn, 1, totallisted)
if FORMAT & LIST_F
RLibMessage(&WhatsIn, 1 ) ! ":"
}
elseif obj is living and not obj.prep
{
! "X has..."
Message(&WhatsIn, 2, obj, totallisted)
if FORMAT & LIST_F
RLibMessage(&WhatsIn, 1 ) ! ":"
}
else
{
if list_count < totallisted
! "Also sitting on/in..."
Message(&Whatsin, 3, obj)
else
! "Sitting on/in..."
Message(&Whatsin, 4, obj)
The(obj)
FORMAT = FORMAT | ISORARE_F
}
}
ListObjects(obj)
list_nest = initial_list_nest
}
return totallisted
}
This gives us a couple options. If we code the coat like this:
Code: Select all
object coat "coat"
{
is clothing, worn, container, open
in you
nouns "coat", "jacket", "windbreaker", "pockets", "pocket"
adjective "synthetic"
article "your"
long_desc
{
"An inexpensive synthetic windbreaker with two large pockets."
}
inv_desc
{
if self is worn
{
print "You are wearing ";
}
else ! if it isn't worn, we can treat it like a regular object
{
return false
}
print Art(self); "."
}
contains_desc
{
"Inside the coat's pockets ";
if Children(self) > 1
{
print "are";
}
else
{
print "is";
}
}
capacity 10
}
It'll default to responses like this, where the coat's children may be listed after everything else the player is carrying:
> i
You are wearing your coat.
You are also carrying some toast. Inside the coat’s pockets is your keychain.
>
That may not be ideal, but it's workable. Still, we can use list_contents to determine when and how we want the coat's children to be listed. It's nice and powerful that way:
Code: Select all
object coat "coat"
{
is clothing, worn, container, open
in you
nouns "coat", "jacket", "windbreaker", "pockets", "pocket"
adjective "synthetic"
article "your"
long_desc
{
"An inexpensive synthetic windbreaker with two large pockets."
}
inv_desc
{
if self is worn
{
print "You are wearing ";
}
else ! if it isn't worn, we can treat it like a regular object
{
return false
}
print Art(self); ".";
if children(self)
{
print AFTER_PERIOD;
run self.contains_desc
ListObjects(self)
}
else
""
}
list_contents
{
if (verbroutine = &DoLookIn,&DoLook) or self is not worn and
verbroutine ~= &DoLookAround
{
return false
}
return true
}
contains_desc
{
"Inside the coat's pockets ";
if Children(self) > 1
{
print "are";
}
else
{
print "is";
}
}
capacity 10
}
This results in:
> i
You are wearing your coat. Inside the coat’s pockets is your keychain.
You are also carrying some toast.
>
Let me know if you have any other thoughts on this.
EDIT: Added the list_contents code above to also allow &DoLook