Merge from vendor branch OPENSSL:
[games.git] / games / trek / abandon.c
1 /*
2  * Copyright (c) 1980, 1993
3  *      The Regents of the University of California.  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  * @(#)abandon.c        8.1 (Berkeley) 5/31/93
34  * $FreeBSD: src/games/trek/abandon.c,v 1.4 1999/11/30 03:49:43 billf Exp $
35  * $DragonFly: src/games/trek/abandon.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
36  */
37
38 # include       "trek.h"
39
40 /*
41 **  Abandon Ship
42 **
43 **      The ship is abandoned.  If your current ship is the Faire
44 **      Queene, or if your shuttlecraft is dead, you're out of
45 **      luck.  You need the shuttlecraft in order for the captain
46 **      (that's you!!) to escape.
47 **
48 **      Your crew can beam to an inhabited starsystem in the
49 **      quadrant, if there is one and if the transporter is working.
50 **      If there is no inhabited starsystem, or if the transporter
51 **      is out, they are left to die in outer space.
52 **
53 **      These currently just count as regular deaths, but they
54 **      should count very heavily against you.
55 **
56 **      If there are no starbases left, you are captured by the
57 **      Klingons, who torture you mercilessly.  However, if there
58 **      is at least one starbase, you are returned to the
59 **      Federation in a prisoner of war exchange.  Of course, this
60 **      can't happen unless you have taken some prisoners.
61 **
62 **      Uses trace flag 40
63 */
64
65 abandon()
66 {
67         struct quad     *q;
68         int             i;
69         int                     j;
70         struct event    *e;
71
72         if (Ship.ship == QUEENE)
73                 return (printf("You may not abandon ye Faire Queene\n"));
74         if (Ship.cond != DOCKED)
75         {
76                 if (damaged(SHUTTLE))
77                         return (out(SHUTTLE));
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                 {
83                         printf("Entire crew of %d left to die in outer space\n",
84                                 Ship.crew);
85                         Game.deaths += Ship.crew;
86                 }
87                 else
88                 {
89                         printf("Crew beams down to planet %s\n", systemname(q));
90                 }
91         }
92         /* see if you can be exchanged */
93         if (Now.bases == 0 || Game.captives < 20 * Game.skill)
94                 lose(L_CAPTURED);
95         /* re-outfit new ship */
96         printf("You are hereby put in charge of an antiquated but still\n");
97         printf("  functional ship, the Fairie Queene.\n");
98         Ship.ship = QUEENE;
99         Ship.shipname = "Fairie Queene";
100         Param.energy = Ship.energy = 3000;
101         Param.torped = Ship.torped = 6;
102         Param.shield = Ship.shield = 1250;
103         Ship.shldup = 0;
104         Ship.cloaked = 0;
105         Ship.warp = 5.0;
106         Ship.warp2 = 25.0;
107         Ship.warp3 = 125.0;
108         Ship.cond = GREEN;
109         /* clear out damages on old ship */
110         for (i = 0; i < MAXEVENTS; i++)
111         {
112                 e = &Event[i];
113                 if (e->evcode != E_FIXDV)
114                         continue;
115                 unschedule(e);
116         }
117         /* get rid of some devices and redistribute probabilities */
118         i = Param.damprob[SHUTTLE] + Param.damprob[CLOAK];
119         Param.damprob[SHUTTLE] = Param.damprob[CLOAK] = 0;
120         while (i > 0)
121                 for (j = 0; j < NDEV; j++)
122                 {
123                         if (Param.damprob[j] != 0)
124                         {
125                                 Param.damprob[j] += 1;
126                                 i--;
127                                 if (i <= 0)
128                                         break;
129                         }
130                 }
131         /* pick a starbase to restart at */
132         i = ranf(Now.bases);
133         Ship.quadx = Now.base[i].x;
134         Ship.quady = Now.base[i].y;
135         /* setup that quadrant */
136         while (1)
137         {
138                 initquad(1);
139                 Sect[Ship.sectx][Ship.secty] = EMPTY;
140                 for (i = 0; i < 5; i++)
141                 {
142                         Ship.sectx = Etc.starbase.x + ranf(3) - 1;
143                         if (Ship.sectx < 0 || Ship.sectx >= NSECTS)
144                                 continue;
145                         Ship.secty = Etc.starbase.y + ranf(3) - 1;
146                         if (Ship.secty < 0 || Ship.secty >= NSECTS)
147                                 continue;
148                         if (Sect[Ship.sectx][Ship.secty] == EMPTY)
149                         {
150                                 Sect[Ship.sectx][Ship.secty] = QUEENE;
151                                 dock();
152                                 compkldist(0);
153                                 return;
154                         }
155                 }
156         }
157 }