You're right; seeing the code
did inspire me to go take my own swing at it, although your code definitely looks nicely configurable and robust. I just wanted to try see how well I could use my existing extensions towards the problem.
My design uses my "findpath.h" extension (although I found a bug in it while writing today's code, so a new version is up at HBE), which in turn uses the character scripting system.
My grammar is pretty much the same as yours:
Code: Select all
verb "go", "walk"
* DoGo
* "to" anything DoGoto
* "in"/"into"/"inside"/"through" object DoEnter
* "out"/"off" object DoGo
* "out"/"outside" DoExit
* anything DoGoto
Now, my only concern with that is that I ran into some problems in "The Next Day" where using the anything token caused me some trouble where there were objects-similarly-named-to-rooms because in Hugo, a nearby object always overrides a not-nearby room, no matter how much parser_rank-tweaking you do. It's very possible that my problems were caused by bad code, though.
The next bit of code is:
Code: Select all
include "findpath.h"
routine DoGoTo
{
if object.type ~= room
{
if FindObject(object)
{
! &DoGo *should* redirect to DoEnter in applicable circumstances
return Perform(&DoGo, object)
}
"You can't go to that!"
return false
}
elseif object = location
{
"You are already there."
return false
}
local a
MakePath(location,object)
a = SetPath(player)
If not a
{
"You can't get there from here."
return false
}
! take the first step of our journey
RunScripts
! check that we have more steps in our journey and that nothing
! important has happened
while ( (FindScript(player)~= MAX_SCRIPTS) and event_flag ~= 2)
{
main
}
}
! replaced CharMove to allow usage for the player character
replace CharMove(char, dir)
{
#ifclear NO_OBJLIB
local newroom, a
if dir.type ~= direction
return
newroom = parent(char).(dir.dir_to)
if newroom.type = door
{
a = newroom
newroom = a.between #((parent(char) = \
a.between #1) + 1)
if a is not open
{
if char in location or newroom = location
{
self = a
""
OMessage(door, 5)
}
}
elseif newroom = location or char in location
a = 0
}
if char in location and not a
{
Message(&CharMove, 1, char, dir)
if not event_flag
event_flag = true
}
if char = player
{
MovePlayer(newroom)
}
else
move char to newroom
#ifset DEBUG
if debug_flags & D_SCRIPTS
{
print "["; CThe(char); IsorAre(char, true); " now in: ";
print capital parent(char).name; ".]"
}
#endif
if char ~= player
{
if char in location and not a
{
Message(&CharMove, 2, char, dir)
event_flag = true
}
elseif char in location
event_flag = true
}
#endif ! ifclear NO_OBJLIB
run parent(char).after
return true
}
So, my system uses "findpath.h" to write the path steps to a character script for the player character. If you need to interrupt the walking, you have to set event_flag to 2.
Anyhow, the funniest side effect of doing it this way is that the player character picks up NPC's supernatural ability to go through doors, opening and closing them without using up a turn.