!! * Copyright Notice
!! timepiece.h 981031
!! Copyright 1998 Erik Hetzner <
[email protected]>
!! This library may be freely distributed, modified, and used. A
!! z-code binary that uses it may be distributed in any manner,
!! provided that credit is given. Any modifications of the library
!! itself for distribution must have this same license and give credit
!! to all authors.
!! * Intro
!! timepiece.h is a library that provides a number of class for
!! implementing timepieces; that is, watches, clocks, & all the
!! like. It uses my very own printtime.h library, and L. Ross
!! Raszewski's timewait.h library. It has the following features:
!! - provides for clocks that can display time in twenty-four hour,
!! analog or twelve-hour format. This is performed by an after
!! routine for Examine, so that after your description, the time is
!! printed;
!! - timepieces can be set to any time, even a time different from the
!! game's time. If the tp_canset attribute is set, the piece can
!! be set to any time, and the time still advances at the same
!! time as game time;
!! - timepieces can run fast or slow; this is controlled by the
!! tp_mn and tp_mn_per properties--the time piece adds tp_mn
!! to its time every tp_mn_per minutes. If tp_mn is negative, the
!! timepiece loses time, and vice-versa;
!! - timepieces can be synchronized (set to each others values);
!! - certain timepieces can be used to change the game time; ie:
!! when one sets them, one sets the time for the game. Also, if
!! these pieces run fast or slows, the games time does too. (Kind
!! of silly & pointless, but at least it's complete! :)
!!
!! * Usage
!! Example the attached example game source to see how this thing
!! works. It should be evident. Here are the attributes and properties
!! that the Timepiece class defines:
!! ** Properties
!! tp_type: set this to any routine; it should print the time in
!! some format; see printtime.h.
!! tp_mn: minutes to change (for slow/fast timepieces).
!! tp_mm_per: per minute (for slow/fast timepieces).
!! tp_dev: deviation from game time--this is an internal variable,
!! you probably ought not to set it yourself.
!! daemon: updates the timepiece if necessary. You must call
!! StartDaemon (someClock) if you want a slow or fast watch.
!! ** Attributes
!! tp_canset: can we set its time?
!! tp_gametime: will setting it set game time?
!! ** Constants, Routines
!! GAMESPEED: sets the pace of the game; used when calling
!! SetTime(). See inform designer's manual for more details.
!!
!! * Todo/Bugs/Less-documented Features/Quirks
!! - When you change the game time, each clock with a differnt time
!! changes its time as well; this is because different times are
!! stored as the offset from game time.
!! - Fix any bugs (it hasn't been tested that well).
!! - Add fine tuning for clocks: ie, set them an hour ahead, an hour
!! behind, a minute forward, &c.
!! - Allow clocks rate to be adjusted--ie allow the player to change the
!! tp_mn and tp_mn_per properties.
!! - Add an alarm mechanism.
!! - Find a useful application for this... :)
!!
!! If you have any suggestions or bug reports, please please please
!! write to me at
[email protected]. This secodn release has
!! eliminated numerous bugs and cleaned things up, but there's still
!! trouble.
!! --Example game source--
!Constant Story "Time, Time, Time!";
!Constant Headline "^Copyright 1998 Erik Hetzner^^";
!
!Include "Parser";
!Include "Verblib";
!Include "Grammar";
!Include ">timepiece.h";
!
!Object House "Hall of Clocks"
! with description "A long, stately hall, filled to the brim with \
! clocks and mechanisms. This hall would fit well in a \
! museum, and indeed is one.",
! has light;
!
!!! This pocketwatch can be opened and closed.
!Object -> pocketwatch "pocket watch"
! class Timepiece
! with after [;
! Examine:
! if (self hasnt open) {
! print (The) self, " is closed.^";
! rtrue;
! }
! ],
! tp_type AnalogTime,
! name "watch" "timepiece" "pocketwatch" "pocket",
! description "A small gold pocket watch with a long \
! gold chain. In the back is etched the intitals \
! of your grandfather, whose watch this was
! originally.",
! has openable;
!
!!! This is an inaccurate wristwatch.
!Object -> wristwatch "wrist watch"
! class Timepiece
! with tp_type AnalogTime,
! tp_mn 1, ! gains one minute
! tp_mn_per 60, ! per hour.
! name "wristwatch" "wrist watch"
! "timepiece" "watch" "wrist",
! description "A small, elegant wristwach. It has \
! a brown leather band and a black dial set on \
! a white face.",
! has tp_canset ! we can set this watch right.
! clothing; ! we can wear it.
!
!!! This clock keeps the game time.
!Object -> clock "clock"
! class Timepiece
! with tp_type AnalogTime,
! name "clock",
! description "A cheap clock; ugly & plastic.",
! has static
! tp_gametime ! This is the master clock; it keeps the game time.
! tp_canset; ! A magic clock; it can change the game time.
!
!
!!! This watch can switch from military to digital time at the press of
!!! a button.
!Object -> digitalWatch "digital watch"
! class Timepiece
! with before [;
! Push:
! if (self.tp_type == Digital12colonTime) {
! self.tp_type = Digital24noTime;
! print "The watch switches to military time.^";
! } else {
! self.tp_type = Digital12colonTime;
! print "The watch switches to 12 hour time.^";
! } rtrue;
! ],
! Tp_type Digital12colonTime,
! name "watch" "digital watch" "digital" "button",
! description "A plastic digital watch. It has \
! a button to change the time format from military \
! to 12 hour.",
! has clothing; ! can be worn
!
![ Initialise;
! Location = House;
! SetTime(11*60, 5);
! StartDaemon(wristwatch);
!];
!! --end example--
Include ">waittime.h";
Include ">printtime.h";
Ifndef GAMESPEED;
Constant GAMESPEED 1;
Endif;
Property tp_type;
Property tp_dev;
Property tp_mn; ! minutes to change (+/-)
Property tp_mn_per; ! per minutes.
Attribute tp_gametime;
Attribute tp_canset;
Class Timepiece
with before [;
SetTo:
if (self has tp_canset) {
if (second ofclass Timepiece)
parsed_number = (second.tp_dev + the_time);
if (self has tp_gametime) {
SetTime((parsed_number), GAMESPEED);
self.tp_dev = 0;
"The game's time has been set to ", (AnalogTime)
the_time, ".";
}
else {
self.tp_dev = (parsed_number - the_time);
print_ret (The) self, " has been set to ",
(AnalogTime) ((self.tp_dev + the_time)%(60*24)),
".";
}
}
else {
print (The) self, " is set right; if you do that, \
you'll just lose all sense of time.^";
rtrue;
}
],
after [;
Examine:
print "^", (The) self, " reads ";
self.tp_type ((self.tp_dev + the_time)%(60*24));
".";
],
daemon [;
if ((the_time%60)%self.tp_mn_per == 0)
self.tp_dev = self.tp_dev + self.tp_mn;
if (self has tp_gametime)
SetTime((self.tp_dev + the_time, GAMESPEED));
],
tp_dev 0,
tp_mn 0,
tp_mn_per 0;
[ isTimepiece;
if (noun ofclass Timepiece) rtrue;
else rfalse;
];
Extend "set" first
* noun = isTimepiece "to" noun = isTimepiece -> SetTo
* noun = isTimepiece "to" parsetime -> SetTo;
Verb "synchronize" "sync"
* noun = isTimepiece "to" noun = isTimepiece -> SetTo;