xref: /dragonfly/games/trek/abandon.c (revision 4318c66eac379e15105fe145d406dfef81b795f6)
1 /*        @(#)abandon.c       8.1 (Berkeley) 5/31/93                                      */
2 /*        $NetBSD: abandon.c,v 1.9 2009/05/24 21:44:56 dholland Exp $ */
3 
4 /*
5  * Copyright (c) 1980, 1993
6  *        The Regents of the University of California.  All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of the University nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  */
32 
33 #include <stdio.h>
34 #include "trek.h"
35 
36 /*
37 **  Abandon Ship
38 **
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.
43 **
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.
48 **
49 **        These currently just count as regular deaths, but they
50 **        should count very heavily against you.
51 **
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.
57 **
58 **        Uses trace flag 40
59 */
60 
61 /*ARGSUSED*/
62 void
abandon(int v __unused)63 abandon(int v __unused)
64 {
65           struct quad         *q;
66           int                 i;
67           int                 j;
68           struct event        *e;
69 
70           if (Ship.ship == QUEENE) {
71                     printf("You may not abandon ye Faire Queene\n");
72                     return;
73           }
74           if (Ship.cond != DOCKED) {
75                     if (damaged(SHUTTLE)) {
76                               out(SHUTTLE);
77                               return;
78                     }
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                               printf("Entire crew of %d left to die in outer space\n",
84                                         Ship.crew);
85                               Game.deaths += Ship.crew;
86                     } else {
87                               printf("Crew beams down to planet %s\n", systemname(q));
88                     }
89           }
90           /* see if you can be exchanged */
91           if (Now.bases == 0 || Game.captives < 20 * Game.skill)
92                     lose(L_CAPTURED);
93           /* re-outfit new ship */
94           printf("You are hereby put in charge of an antiquated but still\n");
95           printf("  functional ship, the Fairie Queene.\n");
96           Ship.ship = QUEENE;
97           Ship.shipname = "Fairie Queene";
98           Param.energy = Ship.energy = 3000;
99           Param.torped = Ship.torped = 6;
100           Param.shield = Ship.shield = 1250;
101           Ship.shldup = 0;
102           Ship.cloaked = 0;
103           Ship.warp = 5.0;
104           Ship.warp2 = 25.0;
105           Ship.warp3 = 125.0;
106           Ship.cond = GREEN;
107           /* clear out damages on old ship */
108           for (i = 0; i < MAXEVENTS; i++) {
109                     e = &Event[i];
110                     if (e->evcode != E_FIXDV)
111                               continue;
112                     unschedule(e);
113           }
114           /* get rid of some devices and redistribute probabilities */
115           i = Param.damprob[SHUTTLE] + Param.damprob[CLOAK];
116           Param.damprob[SHUTTLE] = Param.damprob[CLOAK] = 0;
117           while (i > 0)
118                     for (j = 0; j < NDEV; j++) {
119                               if (Param.damprob[j] != 0) {
120                                         Param.damprob[j] += 1;
121                                         i--;
122                                         if (i <= 0)
123                                                   break;
124                               }
125                     }
126           /* pick a starbase to restart at */
127           i = ranf(Now.bases);
128           Ship.quadx = Now.base[i].x;
129           Ship.quady = Now.base[i].y;
130           /* setup that quadrant */
131           while (1) {
132                     initquad(1);
133                     Sect[Ship.sectx][Ship.secty] = EMPTY;
134                     for (i = 0; i < 5; i++) {
135                               Ship.sectx = Etc.starbase.x + ranf(3) - 1;
136                               if (Ship.sectx < 0 || Ship.sectx >= NSECTS)
137                                         continue;
138                               Ship.secty = Etc.starbase.y + ranf(3) - 1;
139                               if (Ship.secty < 0 || Ship.secty >= NSECTS)
140                                         continue;
141                               if (Sect[Ship.sectx][Ship.secty] == EMPTY) {
142                                         Sect[Ship.sectx][Ship.secty] = QUEENE;
143                                         dock(0);
144                                         compkldist(0);
145                                         return;
146                               }
147                     }
148           }
149 }
150