121275Sdist /* 221275Sdist * Copyright (c) 1980 Regents of the University of California. 334205Sbostic * All rights reserved. 434205Sbostic * 5*42605Sbostic * %sccs.include.redist.c% 621275Sdist */ 721275Sdist 811668Smckusick #ifndef lint 9*42605Sbostic static char sccsid[] = "@(#)dock.c 5.4 (Berkeley) 06/01/90"; 1034205Sbostic #endif /* not lint */ 1111668Smckusick 1211668Smckusick # include "trek.h" 1311668Smckusick 1411668Smckusick /* 1511668Smckusick ** DOCK TO STARBASE 1611668Smckusick ** 1711668Smckusick ** The starship is docked to a starbase. For this to work you 1811668Smckusick ** must be adjacent to a starbase. 1911668Smckusick ** 2011668Smckusick ** You get your supplies replenished and your captives are 2111668Smckusick ** disembarked. Note that your score is updated now, not when 2211668Smckusick ** you actually take the captives. 2311668Smckusick ** 2411668Smckusick ** Any repairs that need to be done are rescheduled to take 2511668Smckusick ** place sooner. This provides for the faster repairs when you 2611668Smckusick ** are docked. 2711668Smckusick */ 2811668Smckusick 2911668Smckusick dock() 3011668Smckusick { 3111668Smckusick register int i, j; 3211668Smckusick int ok; 3311668Smckusick register struct event *e; 3411668Smckusick 3511668Smckusick if (Ship.cond == DOCKED) 3611668Smckusick return (printf("Chekov: But captain, we are already docked\n")); 3711668Smckusick /* check for ok to dock, i.e., adjacent to a starbase */ 3811668Smckusick ok = 0; 3911668Smckusick for (i = Ship.sectx - 1; i <= Ship.sectx + 1 && !ok; i++) 4011668Smckusick { 4111668Smckusick if (i < 0 || i >= NSECTS) 4211668Smckusick continue; 4311668Smckusick for (j = Ship.secty - 1; j <= Ship.secty + 1; j++) 4411668Smckusick { 4511668Smckusick if (j < 0 || j >= NSECTS) 4611668Smckusick continue; 4711668Smckusick if (Sect[i][j] == BASE) 4811668Smckusick { 4911668Smckusick ok++; 5011668Smckusick break; 5111668Smckusick } 5211668Smckusick } 5311668Smckusick } 5411668Smckusick if (!ok) 5511668Smckusick return (printf("Chekov: But captain, we are not adjacent to a starbase.\n")); 5611668Smckusick 5711668Smckusick /* restore resources */ 5811668Smckusick Ship.energy = Param.energy; 5911668Smckusick Ship.torped = Param.torped; 6011668Smckusick Ship.shield = Param.shield; 6111668Smckusick Ship.crew = Param.crew; 6212344Slayer Game.captives += Param.brigfree - Ship.brigfree; 6311668Smckusick Ship.brigfree = Param.brigfree; 6411668Smckusick 6511668Smckusick /* reset ship's defenses */ 6611668Smckusick Ship.shldup = 0; 6711668Smckusick Ship.cloaked = 0; 6811668Smckusick Ship.cond = DOCKED; 6911668Smckusick Ship.reserves = Param.reserves; 7011668Smckusick 7111668Smckusick /* recalibrate space inertial navigation system */ 7211668Smckusick Ship.sinsbad = 0; 7311668Smckusick 7411668Smckusick /* output any saved radio messages */ 7511668Smckusick dumpssradio(); 7611668Smckusick 7711668Smckusick /* reschedule any device repairs */ 7811668Smckusick for (i = 0; i < MAXEVENTS; i++) 7911668Smckusick { 8011668Smckusick e = &Event[i]; 8111668Smckusick if (e->evcode != E_FIXDV) 8211668Smckusick continue; 8311668Smckusick reschedule(e, (e->date - Now.date) * Param.dockfac); 8411668Smckusick } 8511668Smckusick return; 8611668Smckusick } 8711668Smckusick 8811668Smckusick 8911668Smckusick /* 9011668Smckusick ** LEAVE A STARBASE 9111668Smckusick ** 9211668Smckusick ** This is the inverse of dock(). The main function it performs 9311668Smckusick ** is to reschedule any damages so that they will take longer. 9411668Smckusick */ 9511668Smckusick 9611668Smckusick undock() 9711668Smckusick { 9811668Smckusick register struct event *e; 9911668Smckusick register int i; 10011668Smckusick 10111668Smckusick if (Ship.cond != DOCKED) 10211668Smckusick { 10311668Smckusick printf("Sulu: Pardon me captain, but we are not docked.\n"); 10411668Smckusick return; 10511668Smckusick } 10611668Smckusick Ship.cond = GREEN; 10711668Smckusick Move.free = 0; 10811668Smckusick 10911668Smckusick /* reschedule device repair times (again) */ 11011668Smckusick for (i = 0; i < MAXEVENTS; i++) 11111668Smckusick { 11211668Smckusick e = &Event[i]; 11311668Smckusick if (e->evcode != E_FIXDV) 11411668Smckusick continue; 11511668Smckusick reschedule(e, (e->date - Now.date) / Param.dockfac); 11611668Smckusick } 11711668Smckusick return; 11811668Smckusick } 119