Annotation of 43BSDReno/games/trek/schedule.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1980 Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms are permitted provided
                      6:  * that: (1) source distributions retain this entire copyright notice and
                      7:  * comment, and (2) distributions including binaries display the following
                      8:  * acknowledgement:  ``This product includes software developed by the
                      9:  * University of California, Berkeley and its contributors'' in the
                     10:  * documentation or other materials provided with the distribution and in
                     11:  * all advertising materials mentioning features or use of this software.
                     12:  * Neither the name of the University nor the names of its contributors may
                     13:  * be used to endorse or promote products derived from this software without
                     14:  * specific prior written permission.
                     15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
                     16:  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
                     17:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     18:  */
                     19: 
                     20: #ifndef lint
                     21: static char sccsid[] = "@(#)schedule.c 5.4 (Berkeley) 6/1/90";
                     22: #endif /* not lint */
                     23: 
                     24: # include      "trek.h"
                     25: 
                     26: /*
                     27: **  SCHEDULE AN EVENT
                     28: **
                     29: **     An event of type 'type' is scheduled for time NOW + 'offset'
                     30: **     into the first available slot.  'x', 'y', and 'z' are
                     31: **     considered the attributes for this event.
                     32: **
                     33: **     The address of the slot is returned.
                     34: */
                     35: 
                     36: struct event *schedule(type, offset, x, y, z)
                     37: int    type;
                     38: double offset;
                     39: char   x, y;
                     40: char   z;
                     41: {
                     42:        register struct event   *e;
                     43:        register int            i;
                     44:        double                  date;
                     45: 
                     46:        date = Now.date + offset;
                     47:        for (i = 0; i < MAXEVENTS; i++)
                     48:        {
                     49:                e = &Event[i];
                     50:                if (e->evcode)
                     51:                        continue;
                     52:                /* got a slot */
                     53: #              ifdef xTRACE
                     54:                if (Trace)
                     55:                        printf("schedule: type %d @ %.2f slot %d parm %d %d %d\n",
                     56:                                type, date, i, x, y, z);
                     57: #              endif
                     58:                e->evcode = type;
                     59:                e->date = date;
                     60:                e->x = x;
                     61:                e->y = y;
                     62:                e->systemname = z;
                     63:                Now.eventptr[type] = e;
                     64:                return (e);
                     65:        }
                     66:        syserr("Cannot schedule event %d parm %d %d %d", type, x, y, z);
                     67: }
                     68: 
                     69: 
                     70: /*
                     71: **  RESCHEDULE AN EVENT
                     72: **
                     73: **     The event pointed to by 'e' is rescheduled to the current
                     74: **     time plus 'offset'.
                     75: */
                     76: 
                     77: reschedule(e1, offset)
                     78: struct event   *e1;
                     79: double         offset;
                     80: {
                     81:        double                  date;
                     82:        register struct event   *e;
                     83: 
                     84:        e = e1;
                     85: 
                     86:        date = Now.date + offset;
                     87:        e->date = date;
                     88: #      ifdef xTRACE
                     89:        if (Trace)
                     90:                printf("reschedule: type %d parm %d %d %d @ %.2f\n",
                     91:                        e->evcode, e->x, e->y, e->systemname, date);
                     92: #      endif
                     93:        return;
                     94: }
                     95: 
                     96: 
                     97: /*
                     98: **  UNSCHEDULE AN EVENT
                     99: **
                    100: **     The event at slot 'e' is deleted.
                    101: */
                    102: 
                    103: unschedule(e1)
                    104: struct event   *e1;
                    105: {
                    106:        register struct event   *e;
                    107: 
                    108:        e = e1;
                    109: 
                    110: #      ifdef xTRACE
                    111:        if (Trace)
                    112:                printf("unschedule: type %d @ %.2f parm %d %d %d\n",
                    113:                        e->evcode, e->date, e->x, e->y, e->systemname);
                    114: #      endif
                    115:        Now.eventptr[e->evcode & E_EVENT] = 0;
                    116:        e->date = 1e50;
                    117:        e->evcode = 0;
                    118:        return;
                    119: }
                    120: 
                    121: 
                    122: /*
                    123: **  Abreviated schedule routine
                    124: **
                    125: **     Parameters are the event index and a factor for the time
                    126: **     figure.
                    127: */
                    128: 
                    129: struct event *xsched(ev1, factor, x, y, z)
                    130: int    ev1;
                    131: int    factor;
                    132: int    x, y, z;
                    133: {
                    134:        register int    ev;
                    135: 
                    136:        ev = ev1;
                    137:        return (schedule(ev, -Param.eventdly[ev] * Param.time * log(franf()) / factor, x, y, z));
                    138: }
                    139: 
                    140: 
                    141: /*
                    142: **  Simplified reschedule routine
                    143: **
                    144: **     Parameters are the event index, the initial date, and the
                    145: **     division factor.  Look at the code to see what really happens.
                    146: */
                    147: 
                    148: xresched(e1, ev1, factor)
                    149: struct event   *e1;
                    150: int            ev1;
                    151: int            factor;
                    152: {
                    153:        register int            ev;
                    154:        register struct event   *e;
                    155: 
                    156:        ev = ev1;
                    157:        e = e1;
                    158:        reschedule(e, -Param.eventdly[ev] * Param.time * log(franf()) / factor);
                    159: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.