Chris sez time is volatile
[unix-history] / usr / src / games / trek / schedule.c
CommitLineData
bb0cfa24
DF
1/*
2 * Copyright (c) 1980 Regents of the University of California.
e9fb6bea
KB
3 * All rights reserved.
4 *
b2e7427f 5 * %sccs.include.redist.c%
bb0cfa24
DF
6 */
7
b8401192 8#ifndef lint
b2e7427f 9static char sccsid[] = "@(#)schedule.c 5.4 (Berkeley) %G%";
e9fb6bea 10#endif /* not lint */
b8401192
KM
11
12# include "trek.h"
13
14/*
15** SCHEDULE AN EVENT
16**
17** An event of type 'type' is scheduled for time NOW + 'offset'
18** into the first available slot. 'x', 'y', and 'z' are
19** considered the attributes for this event.
20**
21** The address of the slot is returned.
22*/
23
24struct event *schedule(type, offset, x, y, z)
25int type;
06d69904 26double offset;
b8401192
KM
27char x, y;
28char z;
29{
30 register struct event *e;
31 register int i;
06d69904 32 double date;
b8401192
KM
33
34 date = Now.date + offset;
35 for (i = 0; i < MAXEVENTS; i++)
36 {
37 e = &Event[i];
38 if (e->evcode)
39 continue;
40 /* got a slot */
41# ifdef xTRACE
42 if (Trace)
43 printf("schedule: type %d @ %.2f slot %d parm %d %d %d\n",
44 type, date, i, x, y, z);
45# endif
46 e->evcode = type;
47 e->date = date;
48 e->x = x;
49 e->y = y;
50 e->systemname = z;
51 Now.eventptr[type] = e;
52 return (e);
53 }
54 syserr("Cannot schedule event %d parm %d %d %d", type, x, y, z);
55}
56
57
58/*
59** RESCHEDULE AN EVENT
60**
61** The event pointed to by 'e' is rescheduled to the current
62** time plus 'offset'.
63*/
64
65reschedule(e1, offset)
66struct event *e1;
06d69904 67double offset;
b8401192 68{
06d69904 69 double date;
b8401192
KM
70 register struct event *e;
71
72 e = e1;
73
74 date = Now.date + offset;
75 e->date = date;
76# ifdef xTRACE
77 if (Trace)
78 printf("reschedule: type %d parm %d %d %d @ %.2f\n",
79 e->evcode, e->x, e->y, e->systemname, date);
80# endif
81 return;
82}
83
84
85/*
86** UNSCHEDULE AN EVENT
87**
88** The event at slot 'e' is deleted.
89*/
90
91unschedule(e1)
92struct event *e1;
93{
94 register struct event *e;
95
96 e = e1;
97
98# ifdef xTRACE
99 if (Trace)
100 printf("unschedule: type %d @ %.2f parm %d %d %d\n",
101 e->evcode, e->date, e->x, e->y, e->systemname);
102# endif
103 Now.eventptr[e->evcode & E_EVENT] = 0;
104 e->date = 1e50;
105 e->evcode = 0;
106 return;
107}
108
109
110/*
111** Abreviated schedule routine
112**
113** Parameters are the event index and a factor for the time
114** figure.
115*/
116
117struct event *xsched(ev1, factor, x, y, z)
118int ev1;
119int factor;
120int x, y, z;
121{
122 register int ev;
123
124 ev = ev1;
125 return (schedule(ev, -Param.eventdly[ev] * Param.time * log(franf()) / factor, x, y, z));
126}
127
128
129/*
130** Simplified reschedule routine
131**
132** Parameters are the event index, the initial date, and the
133** division factor. Look at the code to see what really happens.
134*/
135
136xresched(e1, ev1, factor)
137struct event *e1;
138int ev1;
139int factor;
140{
141 register int ev;
142 register struct event *e;
143
144 ev = ev1;
145 e = e1;
146 reschedule(e, -Param.eventdly[ev] * Param.time * log(franf()) / factor);
147}