1
!Modified to work with the 6/3 library by Nicholas Daley
2
!-------------------------------------------------------------------------
3
! WaitTime - an Inform library to provide understanding of English time
4
! strings, and give an enhanced Wait command. Time games only!
5
! #include it just after Grammar.
6
! by L. Ross Raszewski, 1996. Based on TimeWait.h by Andrew
8
!The ParseTime and WaitMoves functions are taken from TimeWait with only
9
!minimal modification. I worked this out after I found that I couldn't get
10
!Andrew's library to work. I updated some of the code which I believe was,
11
!outdated, and changed all the Wait subs so that they call WaitMovesSub.
12
!tw_waiting is used both as a sort of pseudo-global as Mr. Clover intended,
13
!and as an indicator. I set up my programs to update the time through the
14
!TimePass routine by featuring the line:
15
! if (tw_waiting hasnt locked) SetTime(the_time+1);
16
! give tw_waiting ~locked;
17
!If an attempt is made to "Wait 0", or a function is called that is not meant
18
!to take any time, tw_waiting is given "locked", and the clock is not advanced.
19
!As with Andrew's TimeWait, any message that should halt the waiting process
20
!can give tw_waiting the "on" attribute, and discontinue waiting. TimeWait
21
!featured a call to Time(), and wouldn't compile until I changed it to
22
!TimePasses(). Even when I changed it, the program was still prone to getting
23
!stuck in infinite loops, which is why I converted the time passage into moves.
24
!the command "Wait 10" or "Wait 10 minutes" should now be equivalent to the player
25
!Typing "Wait" ten times. During testing, I realized that calling TimePasses()
26
!did not perform all the tasks that occur at the end of the turn, so I changed it
27
!again to End_Turn_Sequence(). I think this will make it operate satisfactorily.
28
!Also, I have added a MAX_WAIT, which should be defined as a constant before
29
!inclusion. Attempts to wait more than that many (minutes) will generate a
30
!"That's too long" message. Inspired by "A Mind Forever Voyaging", I added
31
!a response to "Wait 0". I'm not sure, but I think having a time passage rate
32
!other than 0 will give the program problems. If you want more than 1 minute
33
!to pass for each turn, some modification of the code will be necessary (Don't
34
!ask me how, I'm surprised I even got this far!).
35
!-------------------------------------------------------------------------
36
object tw_waiting "tw";
37
#IFNDEF MAX_WAIT; Constant MAX_WAIT 1000; #ENDIF;
38
!Action routines for Wait command...
41
if (noun > MAX_WAIT) {give tw_waiting locked; "That's too long to wait.";};
43
{print "Time doesn't pass.^";give tw_waiting locked;rtrue;};
46
print "Time passes.^";
48
for (i=noun:(i>1)&&(deadflag==0)&&(tw_waiting hasnt on):i--)
52
InformLibrary.End_Turn_Sequence();
54
#ifdef EndTurnSequence;
57
Message fatalerror "waittime.h requires \
58
InformLibrary.End_Turn_Sequence() or \
59
EndTurnSequence() to be defined (this should be done \
60
by the Inform Library)";
68
if ((tw_waiting has on)&&(i>1)&&(deadflag==0))
69
print "^(waiting stopped)^";
78
if (parsed_number>=the_time) noun=parsed_number-the_time;
79
if (parsed_number<the_time)
80
{parsed_number=the_time-parsed_number;
81
noun=1440-parsed_number;
87
!ParseTime takes data from the next words (using wn) and returns a
88
!the_time format time number, or -1 for unrecognisable. It can recognise
89
!time expressed in any of the following formats:
90
!!a. <"0"-"59">|<"one"-"twenty">|"half"|"quarter" ["minutes"|"minute"]
91
! "past"|"to" <"1"-"12">|<"one"-"twelve"> ["am"|"pm"]
92
!b. <"1"-"12">|<"one"-"twelve"> ["o'clock"] ["am"|"pm"]
93
!c. <"1"-"12">|<"one"-"twelve"> <"0"-"59">|<"one"-"twenty"> ["am"|"pm"]
94
!d. <"1"-"12">":"<"0"-"59"> ["am"|"pm"]
95
!e. "midnight"|"midday"|"noon"
96
!!If no am/pm is specified, the next time likely to come up is chosen; that
97
!is, the one that's just ahead of the current time. However, if this
98
!happens, the tw_waiting object is given the 'general' attribute. Thus you
99
!can change the time returned by twelve hours in an action like SetClock
101
!!The next dictionary command is there to allow us to compare a typed
102
!string with "o'clock", something we can't normally do as it is bounded by
105
constant tw_oclock 'o^clock';
107
[ ParseTime i j k flg loop dig hr mn;
108
give tw_waiting ~general;
110
if (i=='midday' or 'noon' or 'midnight') ! then case (e) applies
117
parsed_number=(hr*60+mn);
121
k=(wn-1)*4+1; ! test for case (d)
126
for (loop=0:loop<k:loop++)
132
if ((k>2)&&(k<6)&&(flg==1)) ! then case (d) applies
142
if (dig=='0') { hr=hr+0; jump tw_diglph; }
143
if (dig=='1') { hr=hr+1; jump tw_diglph; }
144
if (dig=='2') { hr=hr+2; jump tw_diglph; }
145
if (dig=='3') { hr=hr+3; jump tw_diglph; }
146
if (dig=='4') { hr=hr+4; jump tw_diglph; }
147
if (dig=='5') { hr=hr+5; jump tw_diglph; }
148
if (dig=='6') { hr=hr+6; jump tw_diglph; }
149
if (dig=='7') { hr=hr+7; jump tw_diglph; }
150
if (dig=='8') { hr=hr+8; jump tw_diglph; }
151
if (dig=='9') { hr=hr+9; jump tw_diglph; }
152
if (dig~=':') return -1;
157
if (dig=='0') { mn=mn+0; jump tw_digokm; }
158
if (dig=='1') { mn=mn+1; jump tw_digokm; }
159
if (dig=='2') { mn=mn+2; jump tw_digokm; }
160
if (dig=='3') { mn=mn+3; jump tw_digokm; }
161
if (dig=='4') { mn=mn+4; jump tw_digokm; }
162
if (dig=='5') { mn=mn+5; jump tw_digokm; }
163
if (dig=='6') { mn=mn+6; jump tw_digokm; }
164
if (dig=='7') { mn=mn+7; jump tw_digokm; }
165
if (dig=='8') { mn=mn+8; jump tw_digokm; }
166
if (dig=='9') { mn=mn+9; jump tw_digokm; }
170
} ! decode digital time
175
if ((j==tw_oclock or -1)||(j=='am' or 'pm')) ! then case (c) applies
185
if (k~=-1000) ! then case (b) applies
190
else ! well, must be case (a)
195
if (i=='twenty-five')
197
if (i=='half' or 'thirty')
199
if (j=='minute' or 'minutes')
200
j=NextWord(); ! ignore 'minutes'
203
if (j~='past' or 'to')
215
if ((hr>12)||(hr<1)||(mn>59)||(mn<0))
219
if (hr==12) ! now sort out am/pm
225
if (i~='am') ! am or pm implied, then?
227
give tw_waiting general;