2009-05-25 02:55:03 +04:00
|
|
|
/* $NetBSD: events.c,v 1.11 2009/05/24 22:55:03 dholland Exp $ */
|
1995-04-22 14:58:17 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1995-04-22 14:58:17 +04:00
|
|
|
* Copyright (c) 1980, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 13:36:50 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1993-03-21 12:45:37 +03:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1997-10-13 01:24:24 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifndef lint
|
1995-04-22 14:58:17 +04:00
|
|
|
#if 0
|
|
|
|
static char sccsid[] = "@(#)events.c 8.1 (Berkeley) 5/31/93";
|
|
|
|
#else
|
2009-05-25 02:55:03 +04:00
|
|
|
__RCSID("$NetBSD: events.c,v 1.11 2009/05/24 22:55:03 dholland Exp $");
|
1995-04-22 14:58:17 +04:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
1997-10-13 01:24:24 +04:00
|
|
|
#include <stdio.h>
|
1997-10-14 02:05:26 +04:00
|
|
|
#include <string.h>
|
1997-10-13 01:24:24 +04:00
|
|
|
#include <math.h>
|
|
|
|
#include "getpar.h"
|
|
|
|
#include "trek.h"
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
** CAUSE TIME TO ELAPSE
|
|
|
|
**
|
|
|
|
** This routine does a hell of a lot. It elapses time, eats up
|
|
|
|
** energy, regenerates energy, processes any events that occur,
|
|
|
|
** and so on.
|
2008-01-28 04:15:55 +03:00
|
|
|
**
|
|
|
|
** 'timewarp' is set if called in a time warp.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
|
1997-10-13 01:24:24 +04:00
|
|
|
int
|
2008-01-28 04:15:55 +03:00
|
|
|
events(int timewarp)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-13 01:24:24 +04:00
|
|
|
int i;
|
|
|
|
char *p;
|
|
|
|
int j = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
struct kling *k;
|
|
|
|
double rtime;
|
|
|
|
double xdate;
|
|
|
|
double idate;
|
1997-10-13 01:24:24 +04:00
|
|
|
struct event *ev = NULL;
|
1993-03-21 12:45:37 +03:00
|
|
|
int ix, iy;
|
1997-10-13 01:24:24 +04:00
|
|
|
struct quad *q;
|
|
|
|
struct event *e;
|
1993-03-21 12:45:37 +03:00
|
|
|
int evnum;
|
|
|
|
int restcancel;
|
|
|
|
|
|
|
|
/* if nothing happened, just allow for any Klingons killed */
|
2009-05-25 01:44:56 +04:00
|
|
|
if (Move.time <= 0.0) {
|
1993-03-21 12:45:37 +03:00
|
|
|
Now.time = Now.resource / Now.klings;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* indicate that the cloaking device is now working */
|
|
|
|
Ship.cloakgood = 1;
|
|
|
|
|
|
|
|
/* idate is the initial date */
|
|
|
|
idate = Now.date;
|
|
|
|
|
|
|
|
/* schedule attacks if resting too long */
|
|
|
|
if (Move.time > 0.5 && Move.resting)
|
|
|
|
schedule(E_ATTACK, 0.5, 0, 0, 0);
|
|
|
|
|
|
|
|
/* scan the event list */
|
2009-05-25 01:44:56 +04:00
|
|
|
while (1) {
|
1993-03-21 12:45:37 +03:00
|
|
|
restcancel = 0;
|
|
|
|
evnum = -1;
|
|
|
|
/* xdate is the date of the current event */
|
|
|
|
xdate = idate + Move.time;
|
|
|
|
|
|
|
|
/* find the first event that has happened */
|
2009-05-25 01:44:56 +04:00
|
|
|
for (i = 0; i < MAXEVENTS; i++) {
|
1993-03-21 12:45:37 +03:00
|
|
|
e = &Event[i];
|
|
|
|
if (e->evcode == 0 || (e->evcode & E_GHOST))
|
|
|
|
continue;
|
2009-05-25 01:44:56 +04:00
|
|
|
if (e->date < xdate) {
|
1993-03-21 12:45:37 +03:00
|
|
|
xdate = e->date;
|
|
|
|
ev = e;
|
|
|
|
evnum = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
e = ev;
|
|
|
|
|
|
|
|
/* find the time between events */
|
|
|
|
rtime = xdate - Now.date;
|
|
|
|
|
|
|
|
/* decrement the magic "Federation Resources" pseudo-variable */
|
|
|
|
Now.resource -= Now.klings * rtime;
|
|
|
|
/* and recompute the time left */
|
|
|
|
Now.time = Now.resource / Now.klings;
|
|
|
|
|
|
|
|
/* move us up to the next date */
|
|
|
|
Now.date = xdate;
|
|
|
|
|
|
|
|
/* check for out of time */
|
|
|
|
if (Now.time <= 0.0)
|
|
|
|
lose(L_NOTIME);
|
2009-05-25 00:39:43 +04:00
|
|
|
#ifdef xTRACE
|
1993-03-21 12:45:37 +03:00
|
|
|
if (evnum >= 0 && Trace)
|
|
|
|
printf("xdate = %.2f, evcode %d params %d %d %d\n",
|
|
|
|
xdate, e->evcode, e->x, e->y, e->systemname);
|
2009-05-25 00:39:43 +04:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/* if evnum < 0, no events occurred */
|
|
|
|
if (evnum < 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* otherwise one did. Find out what it is */
|
2009-05-25 01:44:56 +04:00
|
|
|
switch (e->evcode & E_EVENT) {
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
case E_SNOVA: /* supernova */
|
|
|
|
/* cause the supernova to happen */
|
1997-10-13 01:24:24 +04:00
|
|
|
snova(-1, 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
/* and schedule the next one */
|
|
|
|
xresched(e, E_SNOVA, 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case E_LRTB: /* long range tractor beam */
|
|
|
|
/* schedule the next one */
|
|
|
|
xresched(e, E_LRTB, Now.klings);
|
|
|
|
/* LRTB cannot occur if we are docked */
|
2009-05-25 01:44:56 +04:00
|
|
|
if (Ship.cond != DOCKED) {
|
1993-03-21 12:45:37 +03:00
|
|
|
/* pick a new quadrant */
|
|
|
|
i = ranf(Now.klings) + 1;
|
2009-05-25 01:44:56 +04:00
|
|
|
for (ix = 0; ix < NQUADS; ix++) {
|
|
|
|
for (iy = 0; iy < NQUADS; iy++) {
|
1993-03-21 12:45:37 +03:00
|
|
|
q = &Quad[ix][iy];
|
|
|
|
if (q->stars >= 0)
|
2009-05-25 02:55:03 +04:00
|
|
|
if ((i -= q->klings)
|
|
|
|
<= 0)
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i <= 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* test for LRTB to same quadrant */
|
|
|
|
if (Ship.quadx == ix && Ship.quady == iy)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* nope, dump him in the new quadrant */
|
|
|
|
Ship.quadx = ix;
|
|
|
|
Ship.quady = iy;
|
2009-05-25 02:55:03 +04:00
|
|
|
printf("\n%s caught in long range tractor "
|
|
|
|
"beam\n",
|
|
|
|
Ship.shipname);
|
|
|
|
printf("*** Pulled to quadrant %d,%d\n",
|
|
|
|
Ship.quadx, Ship.quady);
|
1993-03-21 12:45:37 +03:00
|
|
|
Ship.sectx = ranf(NSECTS);
|
|
|
|
Ship.secty = ranf(NSECTS);
|
|
|
|
initquad(0);
|
|
|
|
/* truncate the move time */
|
|
|
|
Move.time = xdate - idate;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case E_KATSB: /* Klingon attacks starbase */
|
|
|
|
/* if out of bases, forget it */
|
2009-05-25 01:44:56 +04:00
|
|
|
if (Now.bases <= 0) {
|
1993-03-21 12:45:37 +03:00
|
|
|
unschedule(e);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check for starbase and Klingons in same quadrant */
|
2009-05-25 01:44:56 +04:00
|
|
|
for (i = 0; i < Now.bases; i++) {
|
1993-03-21 12:45:37 +03:00
|
|
|
ix = Now.base[i].x;
|
|
|
|
iy = Now.base[i].y;
|
|
|
|
/* see if a Klingon exists in this quadrant */
|
|
|
|
q = &Quad[ix][iy];
|
|
|
|
if (q->klings <= 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* see if already distressed */
|
2009-05-25 01:44:56 +04:00
|
|
|
for (j = 0; j < MAXEVENTS; j++) {
|
1993-03-21 12:45:37 +03:00
|
|
|
e = &Event[j];
|
|
|
|
if ((e->evcode & E_EVENT) != E_KDESB)
|
|
|
|
continue;
|
|
|
|
if (e->x == ix && e->y == iy)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (j < MAXEVENTS)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* got a potential attack */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
e = ev;
|
2009-05-25 01:44:56 +04:00
|
|
|
if (i >= Now.bases) {
|
2009-05-25 02:55:03 +04:00
|
|
|
/*
|
|
|
|
* not now; wait a while and see if
|
|
|
|
* some Klingons move in
|
|
|
|
*/
|
1993-03-21 12:45:37 +03:00
|
|
|
reschedule(e, 0.5 + 3.0 * franf());
|
|
|
|
break;
|
|
|
|
}
|
2009-05-25 02:55:03 +04:00
|
|
|
/*
|
|
|
|
* schedule a new attack, and a destruction of
|
|
|
|
* the base
|
|
|
|
*/
|
1993-03-21 12:45:37 +03:00
|
|
|
xresched(e, E_KATSB, 1);
|
|
|
|
e = xsched(E_KDESB, 1, ix, iy, 0);
|
|
|
|
|
|
|
|
/* report it if we can */
|
2009-05-25 01:44:56 +04:00
|
|
|
if (!damaged(SSRADIO)) {
|
2009-05-25 02:55:03 +04:00
|
|
|
printf("\nUhura: Captain, we have received a "
|
|
|
|
"distress signal\n");
|
|
|
|
printf(" from the starbase in quadrant "
|
|
|
|
"%d,%d.\n",
|
1993-03-21 12:45:37 +03:00
|
|
|
ix, iy);
|
|
|
|
restcancel++;
|
2009-05-25 01:44:56 +04:00
|
|
|
} else {
|
2009-05-25 02:55:03 +04:00
|
|
|
/*
|
|
|
|
* SSRADIO out, make it so we can't see the
|
|
|
|
* distress call but it's still there!!!
|
|
|
|
*/
|
1993-03-21 12:45:37 +03:00
|
|
|
e->evcode |= E_HIDDEN;
|
2009-05-25 01:44:56 +04:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case E_KDESB: /* Klingon destroys starbase */
|
|
|
|
unschedule(e);
|
|
|
|
q = &Quad[e->x][e->y];
|
2009-05-25 02:55:03 +04:00
|
|
|
/*
|
|
|
|
* if the base has mysteriously gone away, or if the
|
|
|
|
* Klingon got tired and went home, ignore this event
|
|
|
|
*/
|
1993-03-21 12:45:37 +03:00
|
|
|
if (q->bases <=0 || q->klings <= 0)
|
|
|
|
break;
|
|
|
|
/* are we in the same quadrant? */
|
2009-05-25 01:44:56 +04:00
|
|
|
if (e->x == Ship.quadx && e->y == Ship.quady) {
|
1993-03-21 12:45:37 +03:00
|
|
|
/* yep, kill one in this quadrant */
|
|
|
|
printf("\nSpock: ");
|
|
|
|
killb(Ship.quadx, Ship.quady);
|
2009-05-25 01:44:56 +04:00
|
|
|
} else {
|
1993-03-21 12:45:37 +03:00
|
|
|
/* kill one in some other quadrant */
|
|
|
|
killb(e->x, e->y);
|
2009-05-25 01:44:56 +04:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case E_ISSUE: /* issue a distress call */
|
|
|
|
xresched(e, E_ISSUE, 1);
|
|
|
|
/* if we already have too many, throw this one away */
|
|
|
|
if (Ship.distressed >= MAXDISTR)
|
|
|
|
break;
|
2009-05-25 02:55:03 +04:00
|
|
|
/* try a bunch of times to find something suitable */
|
2009-05-25 01:44:56 +04:00
|
|
|
for (i = 0; i < 100; i++) {
|
1993-03-21 12:45:37 +03:00
|
|
|
ix = ranf(NQUADS);
|
|
|
|
iy = ranf(NQUADS);
|
|
|
|
q = &Quad[ix][iy];
|
2009-05-25 02:55:03 +04:00
|
|
|
/*
|
|
|
|
* need a quadrant which is not the current
|
|
|
|
* one, which has some inhabited stars which
|
|
|
|
* are not already under attack, which is not
|
|
|
|
* supernova'ed, and which has some Klingons
|
|
|
|
* in it
|
|
|
|
*/
|
|
|
|
if (!((ix == Ship.quadx && iy == Ship.quady) ||
|
|
|
|
q->stars < 0 ||
|
|
|
|
(q->qsystemname & Q_DISTRESSED) ||
|
|
|
|
(q->qsystemname & Q_SYSTEM) == 0 ||
|
|
|
|
q->klings <= 0))
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i >= 100)
|
|
|
|
/* can't seem to find one; ignore this call */
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* got one!! Schedule its enslavement */
|
|
|
|
Ship.distressed++;
|
|
|
|
e = xsched(E_ENSLV, 1, ix, iy, q->qsystemname);
|
|
|
|
q->qsystemname = (e - Event) | Q_DISTRESSED;
|
|
|
|
|
|
|
|
/* tell the captain about it if we can */
|
2009-05-25 01:44:56 +04:00
|
|
|
if (!damaged(SSRADIO)) {
|
2009-05-25 02:55:03 +04:00
|
|
|
printf("\nUhura: Captain, starsystem %s in "
|
|
|
|
"quadrant %d,%d is under attack\n",
|
1993-03-21 12:45:37 +03:00
|
|
|
Systemname[e->systemname], ix, iy);
|
|
|
|
restcancel++;
|
2009-05-25 01:44:56 +04:00
|
|
|
} else {
|
1993-03-21 12:45:37 +03:00
|
|
|
/* if we can't tell him, make it invisible */
|
|
|
|
e->evcode |= E_HIDDEN;
|
2009-05-25 01:44:56 +04:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case E_ENSLV: /* starsystem is enslaved */
|
|
|
|
unschedule(e);
|
|
|
|
/* see if current distress call still active */
|
|
|
|
q = &Quad[e->x][e->y];
|
2009-05-25 01:44:56 +04:00
|
|
|
if (q->klings <= 0) {
|
1993-03-21 12:45:37 +03:00
|
|
|
/* no Klingons, clean up */
|
|
|
|
/* restore the system name */
|
|
|
|
q->qsystemname = e->systemname;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* play stork and schedule the first baby */
|
2009-05-25 02:55:03 +04:00
|
|
|
e = schedule(E_REPRO, Param.eventdly[E_REPRO] * franf(),
|
|
|
|
e->x, e->y, e->systemname);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/* report the disaster if we can */
|
2009-05-25 01:44:56 +04:00
|
|
|
if (!damaged(SSRADIO)) {
|
2009-05-25 02:55:03 +04:00
|
|
|
printf("\nUhura: We've lost contact with "
|
|
|
|
"starsystem %s\n",
|
1993-03-21 12:45:37 +03:00
|
|
|
Systemname[e->systemname]);
|
|
|
|
printf(" in quadrant %d,%d.\n",
|
|
|
|
e->x, e->y);
|
2009-05-25 01:44:56 +04:00
|
|
|
} else
|
1993-03-21 12:45:37 +03:00
|
|
|
e->evcode |= E_HIDDEN;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case E_REPRO: /* Klingon reproduces */
|
|
|
|
/* see if distress call is still active */
|
|
|
|
q = &Quad[e->x][e->y];
|
2009-05-25 01:44:56 +04:00
|
|
|
if (q->klings <= 0) {
|
1993-03-21 12:45:37 +03:00
|
|
|
unschedule(e);
|
|
|
|
q->qsystemname = e->systemname;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
xresched(e, E_REPRO, 1);
|
|
|
|
/* reproduce one Klingon */
|
|
|
|
ix = e->x;
|
|
|
|
iy = e->y;
|
2009-05-25 01:44:56 +04:00
|
|
|
if (Now.klings == 127) {
|
|
|
|
/* full right now */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (q->klings >= MAXKLQUAD) {
|
1993-03-21 12:45:37 +03:00
|
|
|
/* this quadrant not ok, pick an adjacent one */
|
2009-05-25 01:44:56 +04:00
|
|
|
for (i = ix - 1; i <= ix + 1; i++) {
|
1993-03-21 12:45:37 +03:00
|
|
|
if (i < 0 || i >= NQUADS)
|
|
|
|
continue;
|
2009-05-25 01:44:56 +04:00
|
|
|
for (j = iy - 1; j <= iy + 1; j++) {
|
1993-03-21 12:45:37 +03:00
|
|
|
if (j < 0 || j >= NQUADS)
|
|
|
|
continue;
|
|
|
|
q = &Quad[i][j];
|
2009-05-25 02:55:03 +04:00
|
|
|
/*
|
|
|
|
* check for this quad ok (not
|
|
|
|
* full & no snova)
|
|
|
|
*/
|
|
|
|
if (q->klings >= MAXKLQUAD ||
|
|
|
|
q->stars < 0)
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (j <= iy + 1)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (j > iy + 1)
|
|
|
|
/* cannot create another yet */
|
|
|
|
break;
|
|
|
|
ix = i;
|
|
|
|
iy = j;
|
|
|
|
}
|
|
|
|
/* deliver the child */
|
|
|
|
q->klings++;
|
|
|
|
Now.klings++;
|
2009-05-25 01:44:56 +04:00
|
|
|
if (ix == Ship.quadx && iy == Ship.quady) {
|
1993-03-21 12:45:37 +03:00
|
|
|
/* we must position Klingon */
|
|
|
|
sector(&ix, &iy);
|
|
|
|
Sect[ix][iy] = KLINGON;
|
|
|
|
k = &Etc.klingon[Etc.nkling++];
|
|
|
|
k->x = ix;
|
|
|
|
k->y = iy;
|
|
|
|
k->power = Param.klingpwr;
|
|
|
|
k->srndreq = 0;
|
2009-05-25 02:55:03 +04:00
|
|
|
compkldist(Etc.klingon[0].dist ==
|
|
|
|
Etc.klingon[0].avgdist ? 0 : 1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* recompute time left */
|
|
|
|
Now.time = Now.resource / Now.klings;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case E_SNAP: /* take a snapshot of the galaxy */
|
|
|
|
xresched(e, E_SNAP, 1);
|
1997-10-13 01:24:24 +04:00
|
|
|
p = (char *) Etc.snapshot;
|
|
|
|
memcpy(p, Quad, sizeof (Quad));
|
|
|
|
p += sizeof(Quad);
|
|
|
|
memcpy(p, Event, sizeof (Event));
|
|
|
|
p += sizeof(Event);
|
|
|
|
memcpy(p, &Now, sizeof (Now));
|
1993-03-21 12:45:37 +03:00
|
|
|
Game.snap = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case E_ATTACK: /* Klingons attack during rest period */
|
2009-05-25 01:44:56 +04:00
|
|
|
if (!Move.resting) {
|
1993-03-21 12:45:37 +03:00
|
|
|
unschedule(e);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
attack(1);
|
|
|
|
reschedule(e, 0.5);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case E_FIXDV:
|
|
|
|
i = e->systemname;
|
|
|
|
unschedule(e);
|
|
|
|
|
|
|
|
/* de-damage the device */
|
|
|
|
printf("%s reports repair work on the %s finished.\n",
|
|
|
|
Device[i].person, Device[i].name);
|
|
|
|
|
|
|
|
/* handle special processing upon fix */
|
2009-05-25 01:44:56 +04:00
|
|
|
switch (i) {
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
case LIFESUP:
|
|
|
|
Ship.reserves = Param.reserves;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SINS:
|
|
|
|
if (Ship.cond == DOCKED)
|
|
|
|
break;
|
2009-05-25 02:55:03 +04:00
|
|
|
printf("Spock has tried to recalibrate your "
|
|
|
|
"Space Internal Navigation System,\n");
|
|
|
|
printf(" but he has no standard base to "
|
|
|
|
"calibrate to. Suggest you get\n");
|
|
|
|
printf(" to a starbase immediately so that "
|
|
|
|
"you can properly recalibrate.\n");
|
1993-03-21 12:45:37 +03:00
|
|
|
Ship.sinsbad = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SSRADIO:
|
|
|
|
restcancel = dumpssradio();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-05-25 02:55:03 +04:00
|
|
|
if (restcancel && Move.resting &&
|
|
|
|
getynpar("Spock: Shall we cancel our rest period"))
|
1993-03-21 12:45:37 +03:00
|
|
|
Move.time = xdate - idate;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* unschedule an attack during a rest period */
|
1997-10-13 01:24:24 +04:00
|
|
|
if ((e = Now.eventptr[E_ATTACK]) != NULL)
|
1993-03-21 12:45:37 +03:00
|
|
|
unschedule(e);
|
|
|
|
|
2009-05-25 01:44:56 +04:00
|
|
|
if (!timewarp) {
|
1993-03-21 12:45:37 +03:00
|
|
|
/* eat up energy if cloaked */
|
|
|
|
if (Ship.cloaked)
|
|
|
|
Ship.energy -= Param.cloakenergy * Move.time;
|
|
|
|
|
|
|
|
/* regenerate resources */
|
|
|
|
rtime = 1.0 - exp(-Param.regenfac * Move.time);
|
|
|
|
Ship.shield += (Param.shield - Ship.shield) * rtime;
|
|
|
|
Ship.energy += (Param.energy - Ship.energy) * rtime;
|
|
|
|
|
|
|
|
/* decrement life support reserves */
|
|
|
|
if (damaged(LIFESUP) && Ship.cond != DOCKED)
|
|
|
|
Ship.reserves -= Move.time;
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|