1 /* 2 * Copyright (c) 1980, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)schedule.c 8.1 (Berkeley) 05/31/93"; 10 #endif /* not lint */ 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 24 struct event *schedule(type, offset, x, y, z) 25 int type; 26 double offset; 27 char x, y; 28 char z; 29 { 30 register struct event *e; 31 register int i; 32 double date; 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 65 reschedule(e1, offset) 66 struct event *e1; 67 double offset; 68 { 69 double date; 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 91 unschedule(e1) 92 struct 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 117 struct event *xsched(ev1, factor, x, y, z) 118 int ev1; 119 int factor; 120 int 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 136 xresched(e1, ev1, factor) 137 struct event *e1; 138 int ev1; 139 int 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 } 148