games: Massive style(9) cleanup commit. Reduces differences to NetBSD.
[dragonfly.git] / games / trek / abandon.c
blob0fa9fecbc96180ad28bd1ea43db48acfcb6459eb
1 /*-
2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
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. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
29 * @(#)abandon.c 8.1 (Berkeley) 5/31/93
30 * $FreeBSD: src/games/trek/abandon.c,v 1.4 1999/11/30 03:49:43 billf Exp $
31 * $DragonFly: src/games/trek/abandon.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
34 #include "trek.h"
37 ** Abandon Ship
39 ** The ship is abandoned. If your current ship is the Faire
40 ** Queene, or if your shuttlecraft is dead, you're out of
41 ** luck. You need the shuttlecraft in order for the captain
42 ** (that's you!!) to escape.
44 ** Your crew can beam to an inhabited starsystem in the
45 ** quadrant, if there is one and if the transporter is working.
46 ** If there is no inhabited starsystem, or if the transporter
47 ** is out, they are left to die in outer space.
49 ** These currently just count as regular deaths, but they
50 ** should count very heavily against you.
52 ** If there are no starbases left, you are captured by the
53 ** Klingons, who torture you mercilessly. However, if there
54 ** is at least one starbase, you are returned to the
55 ** Federation in a prisoner of war exchange. Of course, this
56 ** can't happen unless you have taken some prisoners.
58 ** Uses trace flag 40
61 void
62 abandon(int v __unused)
64 struct quad *q;
65 int i;
66 int j;
67 struct event *e;
69 if (Ship.ship == QUEENE) {
70 printf("You may not abandon ye Faire Queene\n");
71 return;
73 if (Ship.cond != DOCKED) {
74 if (damaged(SHUTTLE)) {
75 out(SHUTTLE);
76 return;
78 printf("Officers escape in shuttlecraft\n");
79 /* decide on fate of crew */
80 q = &Quad[Ship.quadx][Ship.quady];
81 if (q->qsystemname == 0 || damaged(XPORTER)) {
82 printf("Entire crew of %d left to die in outer space\n",
83 Ship.crew);
84 Game.deaths += Ship.crew;
85 } else {
86 printf("Crew beams down to planet %s\n", systemname(q));
89 /* see if you can be exchanged */
90 if (Now.bases == 0 || Game.captives < 20 * Game.skill)
91 lose(L_CAPTURED);
92 /* re-outfit new ship */
93 printf("You are hereby put in charge of an antiquated but still\n");
94 printf(" functional ship, the Fairie Queene.\n");
95 Ship.ship = QUEENE;
96 Ship.shipname = "Fairie Queene";
97 Param.energy = Ship.energy = 3000;
98 Param.torped = Ship.torped = 6;
99 Param.shield = Ship.shield = 1250;
100 Ship.shldup = 0;
101 Ship.cloaked = 0;
102 Ship.warp = 5.0;
103 Ship.warp2 = 25.0;
104 Ship.warp3 = 125.0;
105 Ship.cond = GREEN;
106 /* clear out damages on old ship */
107 for (i = 0; i < MAXEVENTS; i++) {
108 e = &Event[i];
109 if (e->evcode != E_FIXDV)
110 continue;
111 unschedule(e);
113 /* get rid of some devices and redistribute probabilities */
114 i = Param.damprob[SHUTTLE] + Param.damprob[CLOAK];
115 Param.damprob[SHUTTLE] = Param.damprob[CLOAK] = 0;
116 while (i > 0)
117 for (j = 0; j < NDEV; j++) {
118 if (Param.damprob[j] != 0) {
119 Param.damprob[j] += 1;
120 i--;
121 if (i <= 0)
122 break;
125 /* pick a starbase to restart at */
126 i = ranf(Now.bases);
127 Ship.quadx = Now.base[i].x;
128 Ship.quady = Now.base[i].y;
129 /* setup that quadrant */
130 while (1) {
131 initquad(1);
132 Sect[Ship.sectx][Ship.secty] = EMPTY;
133 for (i = 0; i < 5; i++) {
134 Ship.sectx = Etc.starbase.x + ranf(3) - 1;
135 if (Ship.sectx < 0 || Ship.sectx >= NSECTS)
136 continue;
137 Ship.secty = Etc.starbase.y + ranf(3) - 1;
138 if (Ship.secty < 0 || Ship.secty >= NSECTS)
139 continue;
140 if (Sect[Ship.sectx][Ship.secty] == EMPTY) {
141 Sect[Ship.sectx][Ship.secty] = QUEENE;
142 dock(0);
143 compkldist(0);
144 return;