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