What I usually do is declare an object called the "heartbeat" which is a
daemon that runs throughout the game. First, I make up some new
attributes then have the daemon take care of it. This is straight from
my game, "Knight of Ages" where the main character you play is a
vampire, so sunlight is quite important...
Attribute outdoors; ! Is this a room where the sunlight will show
! through?
Attribute lit; ! Is this place lit always, even at night?
Attribute sunlight; ! Leave this alone. The heartbeat will set it.
Constant SUNRISE 360; ! 6am
Constant SUNSET 1140; ! 7pm
Object heartbeat "Vampire Heart"
with number 0,
daemon [ o saw_it;
if (the_time == SUNRISE && self hasnt sunlight)
{
give self sunlight;
saw_it = 0;
for (o = player+1: o <= top_object: o++)
{
if (o has outdoors)
{
give o sunlight;
if (myloc() == o)
{
saw_it = 1;
print "You squint in pain as you spot the sun rise.^";
}
if (o hasnt light)
give o light;
}
}
if (saw_it == 0) print "You sense that the sun has risen.^";
}
if (the_time == SUNSET && self has sunlight)
{
give self ~sunlight;
saw_it = 0;
for (o = player+1: o <= top_object: o++)
{
if (o has outdoors)
{
give o ~sunlight;
if (myloc() == o)
{
saw_it = 1;
print "You feel thankful as the sun slowly vanishes \
past the horizon.^";
}
if (o hasnt lit)
give o ~light;
}
}
if (saw_it == 0) print "You sense the sun setting under the \
horizon...^";
}
[.....] (this daemon also manages the vampire's hunger as well)
( I give the heartbeat sunlight and ~sunlight to note whether the sun
has risen or not, simply because in my game, there are two turns per
minute, and I don't want the sun message printing twice. )
So now, every room that is set 'outdoors' will now have sunlight as
well (when the sun rises), and you can vary your rooms accordingly:
Object some_room "Some Room"
with describe [;
print "A very nice room, blah blah blah.^";
if (daytime() == 1) ! or self has sunlight (see below)
"The sun peeks through the windows, hurting your eyes.";
"You gaze into the stars through the round windows.";
], etc.
[..]
daytime() is a short routine that will check the time to see if it's
during the day. This may be useful rather than checking for sunlight
because some parts of the map will not be touched by sunlight,
i.e. sewers, etc.
[ daytime;
if (the_time >= SUNRISE && the_time < SUNSET) rtrue;
rfalse;
];
Of course, if it's a dark dungeon underground, there is no need for a
describe property which uses daytime() or sunlight, since sun will never
go there. But here is an example where you NEED to use daytime() as
opposed to checking for the 'sunlight' attribute:
Object ddsew "Deep Dark Sewer"
with describe [;
print "You find yourself in a tunneling sewer system, twisting \
north-south.^";
if (daytime() == 1)
"You notice tiny rays of sunlight peeking through some \
misplaced stones.";
rtrue;
];
In this case, the dark sewer is NEVER lit unless by a torch or
something, and it is not outdoors, so when the sun rises, nothing will
change. In fact, the vampire can wander through the sewers without
worry since there is no sun. However, if you wanted to have a little
cosmetic thing such as a few tiny rays of light peeking through, you
would have to use daytime() since this room will never be set 'sunlight'
by the heartbeat daemon.
Anyway, hope this comes to use for someone. If you are interested in
receiving my game when it's complete, e-mail me and I'll add you to a
list. When it's complete, you will receive a UUencoded "knight.z5" file
in the mail.
have fun!
-- --- Sam Hulick ------------- shulick@indiana.edu --------------------- Systems Consultant | Homepage: Indiana College Placement | http://copper.ucs.indiana.edu/~shulick/ and Assessment Center | PGP public key available on request