xref: /netbsd-src/games/trek/abandon.c (revision 50b862e21c853cbd36b7a06588389f4c21b9a079)
1*50b862e2Sdholland /*	$NetBSD: abandon.c,v 1.9 2009/05/24 21:44:56 dholland Exp $	*/
2887dd216Scgd 
361f28255Scgd /*
4887dd216Scgd  * Copyright (c) 1980, 1993
5887dd216Scgd  *	The Regents of the University of California.  All rights reserved.
661f28255Scgd  *
761f28255Scgd  * Redistribution and use in source and binary forms, with or without
861f28255Scgd  * modification, are permitted provided that the following conditions
961f28255Scgd  * are met:
1061f28255Scgd  * 1. Redistributions of source code must retain the above copyright
1161f28255Scgd  *    notice, this list of conditions and the following disclaimer.
1261f28255Scgd  * 2. Redistributions in binary form must reproduce the above copyright
1361f28255Scgd  *    notice, this list of conditions and the following disclaimer in the
1461f28255Scgd  *    documentation and/or other materials provided with the distribution.
15e5aeb4eaSagc  * 3. Neither the name of the University nor the names of its contributors
1661f28255Scgd  *    may be used to endorse or promote products derived from this software
1761f28255Scgd  *    without specific prior written permission.
1861f28255Scgd  *
1961f28255Scgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2061f28255Scgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2161f28255Scgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2261f28255Scgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2361f28255Scgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2461f28255Scgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2561f28255Scgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2661f28255Scgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2761f28255Scgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2861f28255Scgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2961f28255Scgd  * SUCH DAMAGE.
3061f28255Scgd  */
3161f28255Scgd 
32ef383c95Schristos #include <sys/cdefs.h>
3361f28255Scgd #ifndef lint
34887dd216Scgd #if 0
35887dd216Scgd static char sccsid[] = "@(#)abandon.c	8.1 (Berkeley) 5/31/93";
36887dd216Scgd #else
37*50b862e2Sdholland __RCSID("$NetBSD: abandon.c,v 1.9 2009/05/24 21:44:56 dholland Exp $");
38887dd216Scgd #endif
3961f28255Scgd #endif /* not lint */
4061f28255Scgd 
41ef383c95Schristos #include <stdio.h>
4261f28255Scgd #include "trek.h"
4361f28255Scgd 
4461f28255Scgd /*
4561f28255Scgd **  Abandon Ship
4661f28255Scgd **
4761f28255Scgd **	The ship is abandoned.  If your current ship is the Faire
4861f28255Scgd **	Queene, or if your shuttlecraft is dead, you're out of
4961f28255Scgd **	luck.  You need the shuttlecraft in order for the captain
5061f28255Scgd **	(that's you!!) to escape.
5161f28255Scgd **
5261f28255Scgd **	Your crew can beam to an inhabited starsystem in the
5361f28255Scgd **	quadrant, if there is one and if the transporter is working.
5461f28255Scgd **	If there is no inhabited starsystem, or if the transporter
5561f28255Scgd **	is out, they are left to die in outer space.
5661f28255Scgd **
5761f28255Scgd **	These currently just count as regular deaths, but they
5861f28255Scgd **	should count very heavily against you.
5961f28255Scgd **
6061f28255Scgd **	If there are no starbases left, you are captured by the
6161f28255Scgd **	Klingons, who torture you mercilessly.  However, if there
6261f28255Scgd **	is at least one starbase, you are returned to the
6361f28255Scgd **	Federation in a prisoner of war exchange.  Of course, this
6461f28255Scgd **	can't happen unless you have taken some prisoners.
6561f28255Scgd **
6661f28255Scgd **	Uses trace flag 40
6761f28255Scgd */
6861f28255Scgd 
69ef383c95Schristos /*ARGSUSED*/
70ef383c95Schristos void
abandon(int v __unused)71bf0917b6Sdholland abandon(int v __unused)
7261f28255Scgd {
73ef383c95Schristos 	struct quad	*q;
74ef383c95Schristos 	int		i;
7561f28255Scgd 	int		j;
76ef383c95Schristos 	struct event	*e;
7761f28255Scgd 
78ef383c95Schristos 	if (Ship.ship == QUEENE) {
79ef383c95Schristos 		printf("You may not abandon ye Faire Queene\n");
80ef383c95Schristos 		return;
81ef383c95Schristos 	}
82*50b862e2Sdholland 	if (Ship.cond != DOCKED) {
83ef383c95Schristos 		if (damaged(SHUTTLE)) {
84ef383c95Schristos 			out(SHUTTLE);
85ef383c95Schristos 			return;
86ef383c95Schristos 		}
8761f28255Scgd 		printf("Officers escape in shuttlecraft\n");
8861f28255Scgd 		/* decide on fate of crew */
8961f28255Scgd 		q = &Quad[Ship.quadx][Ship.quady];
90*50b862e2Sdholland 		if (q->qsystemname == 0 || damaged(XPORTER)) {
9161f28255Scgd 			printf("Entire crew of %d left to die in outer space\n",
9261f28255Scgd 				Ship.crew);
9361f28255Scgd 			Game.deaths += Ship.crew;
94*50b862e2Sdholland 		} else {
9561f28255Scgd 			printf("Crew beams down to planet %s\n", systemname(q));
9661f28255Scgd 		}
9761f28255Scgd 	}
9861f28255Scgd 	/* see if you can be exchanged */
9961f28255Scgd 	if (Now.bases == 0 || Game.captives < 20 * Game.skill)
10061f28255Scgd 		lose(L_CAPTURED);
10161f28255Scgd 	/* re-outfit new ship */
10261f28255Scgd 	printf("You are hereby put in charge of an antiquated but still\n");
10361f28255Scgd 	printf("  functional ship, the Fairie Queene.\n");
10461f28255Scgd 	Ship.ship = QUEENE;
10561f28255Scgd 	Ship.shipname = "Fairie Queene";
10661f28255Scgd 	Param.energy = Ship.energy = 3000;
10761f28255Scgd 	Param.torped = Ship.torped = 6;
10861f28255Scgd 	Param.shield = Ship.shield = 1250;
10961f28255Scgd 	Ship.shldup = 0;
11061f28255Scgd 	Ship.cloaked = 0;
11161f28255Scgd 	Ship.warp = 5.0;
11261f28255Scgd 	Ship.warp2 = 25.0;
11361f28255Scgd 	Ship.warp3 = 125.0;
11461f28255Scgd 	Ship.cond = GREEN;
11561f28255Scgd 	/* clear out damages on old ship */
116*50b862e2Sdholland 	for (i = 0; i < MAXEVENTS; i++) {
11761f28255Scgd 		e = &Event[i];
11861f28255Scgd 		if (e->evcode != E_FIXDV)
11961f28255Scgd 			continue;
12061f28255Scgd 		unschedule(e);
12161f28255Scgd 	}
12261f28255Scgd 	/* get rid of some devices and redistribute probabilities */
12361f28255Scgd 	i = Param.damprob[SHUTTLE] + Param.damprob[CLOAK];
12461f28255Scgd 	Param.damprob[SHUTTLE] = Param.damprob[CLOAK] = 0;
12561f28255Scgd 	while (i > 0)
126*50b862e2Sdholland 		for (j = 0; j < NDEV; j++) {
127*50b862e2Sdholland 			if (Param.damprob[j] != 0) {
12861f28255Scgd 				Param.damprob[j] += 1;
12961f28255Scgd 				i--;
13061f28255Scgd 				if (i <= 0)
13161f28255Scgd 					break;
13261f28255Scgd 			}
13361f28255Scgd 		}
13461f28255Scgd 	/* pick a starbase to restart at */
13561f28255Scgd 	i = ranf(Now.bases);
13661f28255Scgd 	Ship.quadx = Now.base[i].x;
13761f28255Scgd 	Ship.quady = Now.base[i].y;
13861f28255Scgd 	/* setup that quadrant */
139*50b862e2Sdholland 	while (1) {
14061f28255Scgd 		initquad(1);
14161f28255Scgd 		Sect[Ship.sectx][Ship.secty] = EMPTY;
142*50b862e2Sdholland 		for (i = 0; i < 5; i++) {
14361f28255Scgd 			Ship.sectx = Etc.starbase.x + ranf(3) - 1;
14461f28255Scgd 			if (Ship.sectx < 0 || Ship.sectx >= NSECTS)
14561f28255Scgd 				continue;
14661f28255Scgd 			Ship.secty = Etc.starbase.y + ranf(3) - 1;
14761f28255Scgd 			if (Ship.secty < 0 || Ship.secty >= NSECTS)
14861f28255Scgd 				continue;
149*50b862e2Sdholland 			if (Sect[Ship.sectx][Ship.secty] == EMPTY) {
15061f28255Scgd 				Sect[Ship.sectx][Ship.secty] = QUEENE;
151ef383c95Schristos 				dock(0);
15261f28255Scgd 				compkldist(0);
15361f28255Scgd 				return;
15461f28255Scgd 			}
15561f28255Scgd 		}
15661f28255Scgd 	}
15761f28255Scgd }
158