date and time created 83/03/23 15:01:54 by mckusick
[unix-history] / usr / src / games / trek / damage.c
CommitLineData
344554fb
KM
1#ifndef lint
2static char sccsid[] = "@(#)damage.c 4.1 (Berkeley) %G%";
3#endif not lint
4
5# include "trek.h"
6
7/*
8** Schedule Ship.damages to a Device
9**
10** Device `dev1' is damaged in an amount `dam'. Dam is measured
11** in stardates, and is an additional amount of damage. It should
12** be the amount to occur in non-docked mode. The adjustment
13** to docked mode occurs automatically if we are docked.
14**
15** Note that the repair of the device occurs on a DATE, meaning
16** that the dock() and undock() have to reschedule the event.
17*/
18
19damage(dev1, dam)
20int dev1; /* device index */
21float dam; /* time to repair */
22{
23 register int i;
24 register struct event *e;
25 int f;
26 register int dev;
27
28 /* ignore zero damages */
29 if (dam <= 0.0)
30 return;
31 dev = dev1;
32
33 printf("\t%s damaged\n", Device[dev].name);
34
35 /* find actual length till it will be fixed */
36 if (Ship.cond == DOCKED)
37 dam =* Param.dockfac;
38 /* set the damage flag */
39 f = damaged(dev);
40 if (!f)
41 {
42 /* new damages -- schedule a fix */
43 schedule(E_FIXDV, dam, 0, 0, dev);
44 return;
45 }
46 /* device already damaged -- add to existing damages */
47 /* scan for old damages */
48 for (i = 0; i < MAXEVENTS; i++)
49 {
50 e = &Event[i];
51 if (e->evcode != E_FIXDV || e->systemname != dev)
52 continue;
53 /* got the right one; add on the new damages */
54 reschedule(e, e->date - Now.date + dam);
55 return;
56 }
57 syserr("Cannot find old damages %d\n", dev);
58}