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