1 /* 2 * Copyright (c) 1980, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)damage.c 8.1 (Berkeley) 05/31/93"; 10 #endif /* not lint */ 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 */ 28 double dam; /* time to repair */ 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) 44 dam *= Param.dockfac; 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 } 66