1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32: #include <sys/cdefs.h>
33: #ifndef lint
34: #if 0
35: static char sccsid[] = "@(#)schedule.c 8.1 (Berkeley) 5/31/93";
36: #else
37: __RCSID("$NetBSD: schedule.c,v 1.5 2003/08/07 09:37:53 agc Exp $");
38: #endif
39: #endif
40:
41: #include <stdio.h>
42: #include <math.h>
43: #include <err.h>
44: #include "trek.h"
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56: struct event *schedule(type, offset, x, y, z)
57: int type;
58: double offset;
59: char x, y;
60: char z;
61: {
62: struct event *e;
63: int i;
64: double date;
65:
66: date = Now.date + offset;
67: for (i = 0; i < MAXEVENTS; i++)
68: {
69: e = &Event[i];
70: if (e->evcode)
71: continue;
72:
73: # ifdef xTRACE
74: if (Trace)
75: printf("schedule: type %d @ %.2f slot %d parm %d %d %d\n",
76: type, date, i, x, y, z);
77: # endif
78: e->evcode = type;
79: e->date = date;
80: e->x = x;
81: e->y = y;
82: e->systemname = z;
83: Now.eventptr[type] = e;
84: return (e);
85: }
86: errx(1, "Cannot schedule event %d parm %d %d %d", type, x, y, z);
87: }
88:
89:
90:
91:
92:
93:
94:
95:
96:
97: void
98: reschedule(e1, offset)
99: struct event *e1;
100: double offset;
101: {
102: double date;
103: struct event *e;
104:
105: e = e1;
106:
107: date = Now.date + offset;
108: e->date = date;
109: # ifdef xTRACE
110: if (Trace)
111: printf("reschedule: type %d parm %d %d %d @ %.2f\n",
112: e->evcode, e->x, e->y, e->systemname, date);
113: # endif
114: return;
115: }
116:
117:
118:
119:
120:
121:
122:
123:
124: void
125: unschedule(e1)
126: struct event *e1;
127: {
128: struct event *e;
129:
130: e = e1;
131:
132: # ifdef xTRACE
133: if (Trace)
134: printf("unschedule: type %d @ %.2f parm %d %d %d\n",
135: e->evcode, e->date, e->x, e->y, e->systemname);
136: # endif
137: Now.eventptr[e->evcode & E_EVENT] = 0;
138: e->date = 1e50;
139: e->evcode = 0;
140: return;
141: }
142:
143:
144:
145:
146:
147:
148:
149:
150:
151: struct event *xsched(ev1, factor, x, y, z)
152: int ev1;
153: int factor;
154: int x, y, z;
155: {
156: int ev;
157:
158: ev = ev1;
159: return (schedule(ev, -Param.eventdly[ev] * Param.time * log(franf()) / factor, x, y, z));
160: }
161:
162:
163:
164:
165:
166:
167:
168:
169:
170: void
171: xresched(e1, ev1, factor)
172: struct event *e1;
173: int ev1;
174: int factor;
175: {
176: int ev;
177: struct event *e;
178:
179: ev = ev1;
180: e = e1;
181: reschedule(e, -Param.eventdly[ev] * Param.time * log(franf()) / factor);
182: }