1 /* 2 * Copyright (c) 1980 Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that this notice is preserved and that due credit is given 7 * to the University of California at Berkeley. The name of the University 8 * may not be used to endorse or promote products derived from this 9 * software without specific prior written permission. This software 10 * is provided ``as is'' without express or implied warranty. 11 */ 12 13 #ifndef lint 14 static char sccsid[] = "@(#)damage.c 5.2 (Berkeley) 05/05/88"; 15 #endif /* not lint */ 16 17 # include "trek.h" 18 19 /* 20 ** Schedule Ship.damages to a Device 21 ** 22 ** Device `dev1' is damaged in an amount `dam'. Dam is measured 23 ** in stardates, and is an additional amount of damage. It should 24 ** be the amount to occur in non-docked mode. The adjustment 25 ** to docked mode occurs automatically if we are docked. 26 ** 27 ** Note that the repair of the device occurs on a DATE, meaning 28 ** that the dock() and undock() have to reschedule the event. 29 */ 30 31 damage(dev1, dam) 32 int dev1; /* device index */ 33 double dam; /* time to repair */ 34 { 35 register int i; 36 register struct event *e; 37 int f; 38 register int dev; 39 40 /* ignore zero damages */ 41 if (dam <= 0.0) 42 return; 43 dev = dev1; 44 45 printf("\t%s damaged\n", Device[dev].name); 46 47 /* find actual length till it will be fixed */ 48 if (Ship.cond == DOCKED) 49 dam *= Param.dockfac; 50 /* set the damage flag */ 51 f = damaged(dev); 52 if (!f) 53 { 54 /* new damages -- schedule a fix */ 55 schedule(E_FIXDV, dam, 0, 0, dev); 56 return; 57 } 58 /* device already damaged -- add to existing damages */ 59 /* scan for old damages */ 60 for (i = 0; i < MAXEVENTS; i++) 61 { 62 e = &Event[i]; 63 if (e->evcode != E_FIXDV || e->systemname != dev) 64 continue; 65 /* got the right one; add on the new damages */ 66 reschedule(e, e->date - Now.date + dam); 67 return; 68 } 69 syserr("Cannot find old damages %d\n", dev); 70 } 71