Home | History | Annotate | Line # | Download | only in trek
abandon.c revision 1.2
      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, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  * 1. Redistributions of source code must retain the above copyright
      9  *    notice, this list of conditions and the following disclaimer.
     10  * 2. Redistributions in binary form must reproduce the above copyright
     11  *    notice, this list of conditions and the following disclaimer in the
     12  *    documentation and/or other materials provided with the distribution.
     13  * 3. All advertising materials mentioning features or use of this software
     14  *    must display the following acknowledgement:
     15  *	This product includes software developed by the University of
     16  *	California, Berkeley and its contributors.
     17  * 4. Neither the name of the University nor the names of its contributors
     18  *    may be used to endorse or promote products derived from this software
     19  *    without specific prior written permission.
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31  * SUCH DAMAGE.
     32  */
     33 
     34 #ifndef lint
     35 /*static char sccsid[] = "from: @(#)abandon.c	5.4 (Berkeley) 6/1/90";*/
     36 static char rcsid[] = "$Id: abandon.c,v 1.2 1993/08/01 18:50:53 mycroft Exp $";
     37 #endif /* not lint */
     38 
     39 # include	"trek.h"
     40 
     41 /*
     42 **  Abandon Ship
     43 **
     44 **	The ship is abandoned.  If your current ship is the Faire
     45 **	Queene, or if your shuttlecraft is dead, you're out of
     46 **	luck.  You need the shuttlecraft in order for the captain
     47 **	(that's you!!) to escape.
     48 **
     49 **	Your crew can beam to an inhabited starsystem in the
     50 **	quadrant, if there is one and if the transporter is working.
     51 **	If there is no inhabited starsystem, or if the transporter
     52 **	is out, they are left to die in outer space.
     53 **
     54 **	These currently just count as regular deaths, but they
     55 **	should count very heavily against you.
     56 **
     57 **	If there are no starbases left, you are captured by the
     58 **	Klingons, who torture you mercilessly.  However, if there
     59 **	is at least one starbase, you are returned to the
     60 **	Federation in a prisoner of war exchange.  Of course, this
     61 **	can't happen unless you have taken some prisoners.
     62 **
     63 **	Uses trace flag 40
     64 */
     65 
     66 abandon()
     67 {
     68 	register struct quad	*q;
     69 	register int		i;
     70 	int			j;
     71 	register struct event	*e;
     72 
     73 	if (Ship.ship == QUEENE)
     74 		return (printf("You may not abandon ye Faire Queene\n"));
     75 	if (Ship.cond != DOCKED)
     76 	{
     77 		if (damaged(SHUTTLE))
     78 			return (out(SHUTTLE));
     79 		printf("Officers escape in shuttlecraft\n");
     80 		/* decide on fate of crew */
     81 		q = &Quad[Ship.quadx][Ship.quady];
     82 		if (q->qsystemname == 0 || damaged(XPORTER))
     83 		{
     84 			printf("Entire crew of %d left to die in outer space\n",
     85 				Ship.crew);
     86 			Game.deaths += Ship.crew;
     87 		}
     88 		else
     89 		{
     90 			printf("Crew beams down to planet %s\n", systemname(q));
     91 		}
     92 	}
     93 	/* see if you can be exchanged */
     94 	if (Now.bases == 0 || Game.captives < 20 * Game.skill)
     95 		lose(L_CAPTURED);
     96 	/* re-outfit new ship */
     97 	printf("You are hereby put in charge of an antiquated but still\n");
     98 	printf("  functional ship, the Fairie Queene.\n");
     99 	Ship.ship = QUEENE;
    100 	Ship.shipname = "Fairie Queene";
    101 	Param.energy = Ship.energy = 3000;
    102 	Param.torped = Ship.torped = 6;
    103 	Param.shield = Ship.shield = 1250;
    104 	Ship.shldup = 0;
    105 	Ship.cloaked = 0;
    106 	Ship.warp = 5.0;
    107 	Ship.warp2 = 25.0;
    108 	Ship.warp3 = 125.0;
    109 	Ship.cond = GREEN;
    110 	/* clear out damages on old ship */
    111 	for (i = 0; i < MAXEVENTS; i++)
    112 	{
    113 		e = &Event[i];
    114 		if (e->evcode != E_FIXDV)
    115 			continue;
    116 		unschedule(e);
    117 	}
    118 	/* get rid of some devices and redistribute probabilities */
    119 	i = Param.damprob[SHUTTLE] + Param.damprob[CLOAK];
    120 	Param.damprob[SHUTTLE] = Param.damprob[CLOAK] = 0;
    121 	while (i > 0)
    122 		for (j = 0; j < NDEV; j++)
    123 		{
    124 			if (Param.damprob[j] != 0)
    125 			{
    126 				Param.damprob[j] += 1;
    127 				i--;
    128 				if (i <= 0)
    129 					break;
    130 			}
    131 		}
    132 	/* pick a starbase to restart at */
    133 	i = ranf(Now.bases);
    134 	Ship.quadx = Now.base[i].x;
    135 	Ship.quady = Now.base[i].y;
    136 	/* setup that quadrant */
    137 	while (1)
    138 	{
    139 		initquad(1);
    140 		Sect[Ship.sectx][Ship.secty] = EMPTY;
    141 		for (i = 0; i < 5; i++)
    142 		{
    143 			Ship.sectx = Etc.starbase.x + ranf(3) - 1;
    144 			if (Ship.sectx < 0 || Ship.sectx >= NSECTS)
    145 				continue;
    146 			Ship.secty = Etc.starbase.y + ranf(3) - 1;
    147 			if (Ship.secty < 0 || Ship.secty >= NSECTS)
    148 				continue;
    149 			if (Sect[Ship.sectx][Ship.secty] == EMPTY)
    150 			{
    151 				Sect[Ship.sectx][Ship.secty] = QUEENE;
    152 				dock();
    153 				compkldist(0);
    154 				return;
    155 			}
    156 		}
    157 	}
    158 }
    159