command1.c revision 1.2 1 1.2 agc /* $NetBSD: command1.c,v 1.2 2003/08/07 09:37:00 agc Exp $ */
2 1.1 tv
3 1.1 tv /*
4 1.1 tv * Copyright (c) 1983, 1993
5 1.1 tv * The Regents of the University of California. All rights reserved.
6 1.1 tv *
7 1.1 tv * Redistribution and use in source and binary forms, with or without
8 1.1 tv * modification, are permitted provided that the following conditions
9 1.1 tv * are met:
10 1.1 tv * 1. Redistributions of source code must retain the above copyright
11 1.1 tv * notice, this list of conditions and the following disclaimer.
12 1.1 tv * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 tv * notice, this list of conditions and the following disclaimer in the
14 1.1 tv * documentation and/or other materials provided with the distribution.
15 1.2 agc * 3. Neither the name of the University nor the names of its contributors
16 1.1 tv * may be used to endorse or promote products derived from this software
17 1.1 tv * without specific prior written permission.
18 1.1 tv *
19 1.1 tv * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 1.1 tv * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 1.1 tv * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.1 tv * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 1.1 tv * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.1 tv * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 1.1 tv * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.1 tv * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.1 tv * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.1 tv * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.1 tv * SUCH DAMAGE.
30 1.1 tv */
31 1.1 tv
32 1.1 tv #include <sys/cdefs.h>
33 1.1 tv #ifndef lint
34 1.1 tv #if 0
35 1.1 tv static char sccsid[] = "@(#)com1.c 8.2 (Berkeley) 4/28/95";
36 1.1 tv #else
37 1.2 agc __RCSID("$NetBSD: command1.c,v 1.2 2003/08/07 09:37:00 agc Exp $");
38 1.1 tv #endif
39 1.1 tv #endif /* not lint */
40 1.1 tv
41 1.1 tv #include "extern.h"
42 1.1 tv
43 1.1 tv int
44 1.1 tv moveplayer(thataway, token)
45 1.1 tv int thataway, token;
46 1.1 tv {
47 1.1 tv wordnumber++;
48 1.1 tv if ((!notes[CANTMOVE] && !notes[LAUNCHED]) ||
49 1.1 tv testbit(location[position].objects, LAND) ||
50 1.1 tv (fuel > 0 && notes[LAUNCHED])) {
51 1.1 tv if (thataway) {
52 1.1 tv position = thataway;
53 1.1 tv newway(token);
54 1.1 tv ourtime++;
55 1.1 tv } else {
56 1.1 tv puts("You can't go this way.");
57 1.1 tv newway(token);
58 1.1 tv whichway(location[position]);
59 1.1 tv return (0);
60 1.1 tv }
61 1.1 tv } else {
62 1.1 tv if (notes[CANTMOVE] && !notes[LAUNCHED])
63 1.1 tv puts("You aren't able to move; you better drop something.");
64 1.1 tv else
65 1.1 tv puts("You are out of fuel; now you will rot in space forever!");
66 1.1 tv }
67 1.1 tv return (1);
68 1.1 tv }
69 1.1 tv
70 1.1 tv void
71 1.1 tv convert(tothis) /* Converts day to night and vice versa. */
72 1.1 tv int tothis; /* Day objects are permanent. Night objects
73 1.1 tv * are added */
74 1.1 tv { /* at dusk, and subtracted at dawn. */
75 1.1 tv const struct objs *p;
76 1.1 tv unsigned int i, j;
77 1.1 tv
78 1.1 tv if (tothis == TONIGHT) {
79 1.1 tv for (i = 1; i <= NUMOFROOMS; i++)
80 1.1 tv for (j = 0; j < NUMOFWORDS; j++)
81 1.1 tv nightfile[i].objects[j] = dayfile[i].objects[j];
82 1.1 tv for (p = nightobjs; p->room != 0; p++)
83 1.1 tv setbit(nightfile[p->room].objects, p->obj);
84 1.1 tv location = nightfile;
85 1.1 tv } else {
86 1.1 tv for (i = 1; i <= NUMOFROOMS; i++)
87 1.1 tv for (j = 0; j < NUMOFWORDS; j++)
88 1.1 tv dayfile[i].objects[j] = nightfile[i].objects[j];
89 1.1 tv for (p = nightobjs; p->room != 0; p++)
90 1.1 tv clearbit(dayfile[p->room].objects, p->obj);
91 1.1 tv location = dayfile;
92 1.1 tv }
93 1.1 tv }
94 1.1 tv
95 1.1 tv void
96 1.1 tv news()
97 1.1 tv {
98 1.1 tv int n;
99 1.1 tv int hurt;
100 1.1 tv
101 1.1 tv if (ourtime > 30 && position < 32) {
102 1.1 tv puts("An explosion of shuddering magnitude splinters bulkheads and");
103 1.1 tv puts("ruptures the battlestar's hull. You are sucked out into the");
104 1.1 tv puts("frozen void of space and killed.");
105 1.1 tv die();
106 1.1 tv }
107 1.1 tv if (ourtime > 20 && position < 32)
108 1.1 tv puts("Explosions rock the battlestar.");
109 1.1 tv if (ourtime > snooze) {
110 1.1 tv puts("You drop from exhaustion...");
111 1.1 tv zzz();
112 1.1 tv }
113 1.1 tv if (ourtime > snooze - 5)
114 1.1 tv puts("You're getting tired.");
115 1.1 tv if (ourtime > (rythmn + CYCLE)) {
116 1.1 tv if (location == nightfile) {
117 1.1 tv convert(TODAY);
118 1.1 tv if (OUTSIDE && ourtime - rythmn - CYCLE < 10) {
119 1.1 tv puts("Dew lit sunbeams stretch out from a watery sunrise and herald the dawn.");
120 1.1 tv puts("You awake from a misty dream-world into stark reality.");
121 1.1 tv puts("It is day.");
122 1.1 tv }
123 1.1 tv } else {
124 1.1 tv convert(TONIGHT);
125 1.1 tv clearbit(location[POOLS].objects, BATHGOD);
126 1.1 tv if (OUTSIDE && ourtime - rythmn - CYCLE < 10) {
127 1.1 tv puts("The dying sun sinks into the ocean, leaving a blood-stained sunset.");
128 1.1 tv puts("The sky slowly fades from orange to violet to black. A few stars");
129 1.1 tv puts("flicker on, and it is night.");
130 1.1 tv puts("The world seems completely different at night.");
131 1.1 tv }
132 1.1 tv }
133 1.1 tv rythmn = ourtime - ourtime % CYCLE;
134 1.1 tv }
135 1.1 tv if (!wiz && !tempwiz)
136 1.1 tv if ((testbit(inven, TALISMAN) || testbit(wear, TALISMAN)) && (testbit(inven, MEDALION) || testbit(wear, MEDALION)) && (testbit(inven, AMULET) || testbit(wear, AMULET))) {
137 1.1 tv tempwiz = 1;
138 1.1 tv puts("The three amulets glow and reenforce each other in power.\nYou are now a wizard.");
139 1.1 tv }
140 1.1 tv if (testbit(location[position].objects, ELF)) {
141 1.1 tv printf("%s\n", objdes[ELF]);
142 1.1 tv fight(ELF, rnd(30));
143 1.1 tv }
144 1.1 tv if (testbit(location[position].objects, DARK)) {
145 1.1 tv printf("%s\n", objdes[DARK]);
146 1.1 tv fight(DARK, 100);
147 1.1 tv }
148 1.1 tv if (testbit(location[position].objects, WOODSMAN)) {
149 1.1 tv printf("%s\n", objdes[WOODSMAN]);
150 1.1 tv fight(WOODSMAN, 50);
151 1.1 tv }
152 1.1 tv switch (position) {
153 1.1 tv
154 1.1 tv case 267:
155 1.1 tv case 257: /* entering a cave */
156 1.1 tv case 274:
157 1.1 tv case 246:
158 1.1 tv notes[CANTSEE] = 1;
159 1.1 tv break;
160 1.1 tv case 160:
161 1.1 tv case 216: /* leaving a cave */
162 1.1 tv case 230:
163 1.1 tv case 231:
164 1.1 tv case 232:
165 1.1 tv notes[CANTSEE] = 0;
166 1.1 tv break;
167 1.1 tv }
168 1.1 tv if (testbit(location[position].objects, GIRL))
169 1.1 tv meetgirl = 1;
170 1.1 tv if (meetgirl && CYCLE * 1.5 - ourtime < 10) {
171 1.1 tv setbit(location[GARDEN].objects, GIRLTALK);
172 1.1 tv setbit(location[GARDEN].objects, LAMPON);
173 1.1 tv setbit(location[GARDEN].objects, ROPE);
174 1.1 tv }
175 1.1 tv if (position == DOCK && (beenthere[position] || ourtime > CYCLE)) {
176 1.1 tv clearbit(location[DOCK].objects, GIRL);
177 1.1 tv clearbit(location[DOCK].objects, MAN);
178 1.1 tv }
179 1.1 tv if (meetgirl && ourtime - CYCLE * 1.5 > 10) {
180 1.1 tv clearbit(location[GARDEN].objects, GIRLTALK);
181 1.1 tv clearbit(location[GARDEN].objects, LAMPON);
182 1.1 tv clearbit(location[GARDEN].objects, ROPE);
183 1.1 tv meetgirl = 0;
184 1.1 tv }
185 1.1 tv if (testbit(location[position].objects, CYLON)) {
186 1.1 tv puts("Oh my God, you're being shot at by an alien spacecraft!");
187 1.1 tv printf("The targeting computer says we have %d seconds to attack!\n",
188 1.1 tv ourclock);
189 1.1 tv fflush(stdout);
190 1.1 tv sleep(1);
191 1.1 tv if (!visual()) {
192 1.1 tv hurt = rnd(NUMOFINJURIES);
193 1.1 tv injuries[hurt] = 1;
194 1.1 tv puts("Laser blasts sear the cockpit, and the alien veers off in a victory roll.");
195 1.1 tv puts("The viper shudders under a terrible explosion.");
196 1.1 tv printf("I'm afraid you have suffered %s.\n", ouch[hurt]);
197 1.1 tv } else
198 1.1 tv clearbit(location[position].objects, CYLON);
199 1.1 tv }
200 1.1 tv if (injuries[SKULL] && injuries[INCISE] && injuries[NECK]) {
201 1.1 tv puts("I'm afraid you have suffered fatal injuries.");
202 1.1 tv die();
203 1.1 tv }
204 1.1 tv for (n = 0; n < NUMOFINJURIES; n++)
205 1.1 tv if (injuries[n] == 1) {
206 1.1 tv injuries[n] = 2;
207 1.1 tv if (WEIGHT > 5)
208 1.1 tv WEIGHT -= 5;
209 1.1 tv else
210 1.1 tv WEIGHT = 0;
211 1.1 tv }
212 1.1 tv if (injuries[ARM] == 2) {
213 1.1 tv if (CUMBER > 5)
214 1.1 tv CUMBER -= 5;
215 1.1 tv else
216 1.1 tv CUMBER = 0;
217 1.1 tv injuries[ARM]++;
218 1.1 tv }
219 1.1 tv if (injuries[RIBS] == 2) {
220 1.1 tv if (CUMBER > 2)
221 1.1 tv CUMBER -= 2;
222 1.1 tv else
223 1.1 tv CUMBER = 0;
224 1.1 tv injuries[RIBS]++;
225 1.1 tv }
226 1.1 tv if (injuries[SPINE] == 2) {
227 1.1 tv WEIGHT = 0;
228 1.1 tv injuries[SPINE]++;
229 1.1 tv }
230 1.1 tv if (carrying > WEIGHT || encumber > CUMBER)
231 1.1 tv notes[CANTMOVE] = 1;
232 1.1 tv else
233 1.1 tv notes[CANTMOVE] = 0;
234 1.1 tv }
235 1.1 tv
236 1.1 tv void
237 1.1 tv crash()
238 1.1 tv {
239 1.1 tv int hurt1, hurt2;
240 1.1 tv
241 1.1 tv fuel--;
242 1.1 tv if (!location[position].flyhere ||
243 1.1 tv (testbit(location[position].objects, LAND) && fuel <= 0)) {
244 1.1 tv if (!location[position].flyhere)
245 1.1 tv puts("You're flying too low. We're going to crash!");
246 1.1 tv else {
247 1.1 tv puts("You're out of fuel. We'll have to crash land!");
248 1.1 tv if (!location[position].down) {
249 1.1 tv puts("Your viper strikes the ground and explodes into fiery fragments.");
250 1.1 tv puts("Thick black smoke billows up from the wreckage.");
251 1.1 tv die();
252 1.1 tv }
253 1.1 tv position = location[position].down;
254 1.1 tv }
255 1.1 tv notes[LAUNCHED] = 0;
256 1.1 tv setbit(location[position].objects, CRASH);
257 1.1 tv ourtime += rnd(CYCLE / 4);
258 1.1 tv puts("The viper explodes into the ground and you lose consciousness...");
259 1.1 tv zzz();
260 1.1 tv hurt1 = rnd(NUMOFINJURIES - 2) + 2;
261 1.1 tv hurt2 = rnd(NUMOFINJURIES - 2) + 2;
262 1.1 tv injuries[hurt1] = 1;
263 1.1 tv injuries[hurt2] = 1;
264 1.1 tv injuries[0] = 1;/* abrasions */
265 1.1 tv injuries[1] = 1;/* lacerations */
266 1.1 tv printf("I'm afraid you have suffered %s and %s.\n",
267 1.1 tv ouch[hurt1], ouch[hurt2]);
268 1.1 tv }
269 1.1 tv }
270