Commit | Line | Data |
---|---|---|
344554fb | 1 | #ifndef lint |
06d69904 | 2 | static char sccsid[] = "@(#)damage.c 4.3 (Berkeley) %G%"; |
344554fb KM |
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 | ||
19 | damage(dev1, dam) | |
20 | int dev1; /* device index */ | |
06d69904 | 21 | double dam; /* time to repair */ |
344554fb KM |
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) | |
35b95499 | 37 | dam *= Param.dockfac; |
344554fb KM |
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 | } |