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