Tuesday, July 15, 2014

More Roodylib updates

First off, you may have noticed that I've been using pastebin lately for larger pieces of code.  I'm in the process of looking at gist (github's source code sharing thingy) and may switch over to that soon (it seems it does a better job of preserving tabs, although you can still keep pastebin's tabs if you click through to the raw format).  Ideally, eventually I'll have some kind of syntax highlighting on here, too.

Anyhow, let's talk about the things I've added to Roodylib!

New DoOpen Behavior

While taking a look at another look at Cryptozookeeper, that mailbox in the first room reminded me how much I don't like Hugo's default opening behavior.  Funny how my perfect example goes so far back, but I've always liked Zork's "Opening the <blank> reveals a..." text.

So I added this code to do it:

replace DoOpen
{
local tempformat, light_check, skip_ahead
if not CheckReach(object): return false
if object is not openable
{
VMessage(&DoOpen, 1) ! "You can't open that."
return
}
elseif object is open
VMessage(&DoOpen, 2) ! "It's already open."
elseif object is locked
VMessage(&DoOpen, 3) ! "It's locked."
else
{
object is open
object is moved
local i
if not Contains(object,player) and object is not transparent
{
for i in object
{
if i is not hidden
break
}
}
if i
{
if not light_source
light_check = FindLight(location) ! in case the light source
! has been revealed
}
if not object.after
{
if not i or object is quiet
{
VMessage(&DoOpen, 4) ! "Opened."
}
else
{
local x
list_count = 0
for x in object
{
if x is not hidden
list_count++
}
parser_data[PARSER_STATUS] &= ~PRONOUNS_SET
RLibMessage(&DoOpen,1) ! "opening the <blank> reveals"
ListObjects(object)
object = -1 ! so the last pronoun assigned stays
skip_ahead = true
}
}
else
skip_ahead = true ! object.after has to list the contents
! if it exists
if i and object is not quiet and
not skip_ahead
{
print ""
parser_data[PARSER_STATUS] &= ~PRONOUNS_SET
tempformat = FORMAT
FORMAT = FORMAT | NOINDENT_F
list_nest = 0
WhatsIn(object)
FORMAT = tempformat
object = -1 ! so the last pronoun assigned stays
}
}
if light_check
{
Perform(&DoLookAround)
}
return true
}
view raw DoOpen hosted with ❤ by GitHub

See, it even properly sets the pronoun now

Initially, I wanted the contents to be listed even if there was an object.after, so you could have something like:

"The mailbox squeaks open.

Inside the mailbox is..."

But since the original Hugo library didn't do that, I don't want to break all of the existing games out there more than I have to (of course, you can put the content-listing code in your object.after property routine, which is what those old games already do... it's just uglier).

As of right now, I'm thinking this will be a default behavior, but if people hate it, I'll put in some way to turn it off.

Anchorhead-style Auto-Examination of Picked Up Items

The other day, I was looking at the tips section of Hugo By Example, and I was reminded of this neat little thing that Anchorhead does that I wouldn't mind seeing in more games.  In the game, for certain items, if you hadn't examined them before picking them up, picking them up automatically examines them.  I think it's a cute time-saving device, and I figured there's no reason it can't be thrown into Roodylib for convenience.  To use it, all you have to do is set the AUTOMATIC_EXAMINE flag.

Here is the code that makes it work:

#ifset AUTOMATIC_EXAMINE
attribute examined
#endif
! in the player_character object...
#ifset AUTOMATIC_EXAMINE ! objects are examined automatically when picked
react_after ! up
{
if verbroutine = &DoLook and object and word[1] ~= "undo"
{
if object is not examined
object is examined
}
return false
}
#endif
! in DoGet
#ifset AUTOMATIC_EXAMINE ! unexamined objects are automatically examined
if object is not examined and &object.long_desc
{
! "You pick up the <object>.";
RLibMessage(&DoGet,2)
print AFTER_PERIOD;
Perform(&DoLook, object)
}
else
#endif
! "Taken."
VMessage(&DoGet, 8)

Actually, more Zork-style stuff

I also haven't liked how it's always on the author's shoulders to specify whether a container is open. Even though, in this day and age, all objects should have a long_desc anyway, I've updated DoLook so that if an object doesn't have one, openable containers automatically tell you if they are open or closed.

replace DoLook
{
local i,skip_ahead, no_fullstop
if not light_source
VMessage(&DoLook, 1) ! "It's too dark to see anything."
else
{
if ( object is transparent or !(object is living, transparent) or
object is platform or (object is container and
(object is open or object is not openable))) and
object is not quiet ! and object is not already_listed
{
for i in object
{
if i is not hidden
break
}
}
if not object.long_desc
{
#ifclear FORCE_DEFAULT_MESSAGE
! if (object is container or object is platform) and
if object is container and
object is not quiet and object is not living
{
if (object is openable,open)
{
print "It's open.";
if not i
Indent
}
Perform(&DoLookIn,object) ! so we get "it is closed." if closed
object = -1 ! so pronouns are set to any contents
skip_ahead = true
}
elseif i
no_fullstop = true
else
#endif
! "Looks just like you'd expect..."
VMessage(&DoLook, 2)
}
if i and object ~= player and not skip_ahead
{
parser_data[PARSER_STATUS] &= ~PRONOUNS_SET
local tempformat
tempformat = FORMAT
FORMAT = FORMAT | NOINDENT_F
list_nest = 0
if not no_fullstop
print ""
WhatsIn(object)
object = -1
FORMAT = tempformat
}
run object.after
#ifclear NO_LOOK_TURNS
return true
#endif
}
}

mailbox with object.after property routine and the above DoLook code
Pretty sure that's all I wanted to talk about for now! New Roodylib update coming soon!

No comments:

Post a Comment