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