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