xref: /386bsd/usr/src/games/battlestar/com1.c (revision a2142627)
1 /*
2  * Copyright (c) 1983 Regents of the University of California.
3  * 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 
34 #ifndef lint
35 static char sccsid[] = "@(#)com1.c	5.3 (Berkeley) 6/1/90";
36 #endif /* not lint */
37 
38 #include "externs.h"
39 
move(thataway,token)40 move(thataway, token)
41 int thataway, token;
42 {
43 	wordnumber++;
44 	if ((!notes[CANTMOVE] && !notes[LAUNCHED]) || testbit(location[position].objects, LAND) || fuel > 0 && notes[LAUNCHED])
45 		if (thataway) {
46 			position = thataway;
47 			newway(token);
48 			time++;
49 		}
50 		else {
51 			puts("You can't go this way.");
52 			newway(token);
53 			whichway(location[position]);
54 			return(0);
55 		}
56 	else if (notes[CANTMOVE] && !notes[LAUNCHED])
57 		puts("You aren't able to move; you better drop something.");
58 	else
59 		puts("You are out of fuel; now you will rot in space forever!");
60 	return(1);
61 }
62 
convert(tothis)63 convert(tothis)		/* Converts day to night and vice versa. 	    */
64 int tothis;		/* Day objects are permanent.  Night objects are added*/
65 {			/* at dusk, and subtracted at dawn.		*/
66 	register struct objs *p;
67 	register i, j;
68 
69 	if (tothis == TONIGHT) {
70 		for (i = 1; i <= NUMOFROOMS; i++)
71 			for (j = 0; j < NUMOFWORDS; j++)
72 				nightfile[i].objects[j] = dayfile[i].objects[j];
73 		for (p = nightobjs; p->room != 0; p++)
74 			setbit(nightfile[p->room].objects, p->obj);
75 		location = nightfile;
76 	} else {
77 		for (i = 1; i <= NUMOFROOMS; i++)
78 			for (j = 0; j < NUMOFWORDS; j++)
79 				dayfile[i].objects[j] = nightfile[i].objects[j];
80 		for (p = nightobjs; p->room != 0; p++)
81 			clearbit(dayfile[p->room].objects, p->obj);
82 		location = dayfile;
83 	}
84 }
85 
news()86 news()
87 {
88 	register int n;
89 	int hurt;
90 
91 	if (time > 30 && position < 32){
92 		puts("An explosion of shuddering magnitude splinters bulkheads and");
93 		puts("ruptures the battlestar's hull.  You are sucked out into the");
94 		puts("frozen void of space and killed.");
95 		die();
96 	}
97 	if (time > 20 && position < 32)
98 		puts("Explosions rock the battlestar.");
99 	if (time > snooze){
100 		puts("You drop from exhaustion...");
101 		zzz();
102 	}
103 	if (time > snooze - 5)
104 		puts("You're getting tired.");
105 	if (time > (rythmn + CYCLE)) {
106 		if (location == nightfile) {
107 			convert(TODAY);
108 			if (OUTSIDE && time - rythmn - CYCLE < 10) {
109 				puts("Dew lit sunbeams stretch out from a watery sunrise and herald the dawn.");
110 				puts("You awake from a misty dream-world into stark reality.");
111 				puts("It is day.");
112 			}
113 		} else {
114 			convert(TONIGHT);
115 			clearbit(location[POOLS].objects, BATHGOD);
116 			if (OUTSIDE && time - rythmn - CYCLE < 10) {
117 				puts("The dying sun sinks into the ocean, leaving a blood stained sunset.");
118 				puts("The sky slowly fades from orange to violet to black.  A few stars");
119 				puts("flicker on, and it is night.");
120 				puts("The world seems completly different at night.");
121 			}
122 		}
123 		rythmn = time - time % CYCLE;
124 	}
125 	if (!wiz && !tempwiz)
126 		if ((testbit(inven,TALISMAN) || testbit(wear,TALISMAN)) && (testbit(inven,MEDALION) || testbit(wear,MEDALION)) && (testbit(inven,AMULET) || testbit(wear,AMULET))){
127 			tempwiz = 1;
128 			puts("The three amulets glow and reenforce each other in power.\nYou are now a wizard.");
129 	}
130 	if (testbit(location[position].objects,ELF)){
131 		printf("%s\n",objdes[ELF]);
132 		fight(ELF,rnd(30));
133 	}
134 	if (testbit(location[position].objects,DARK)){
135 		printf("%s\n",objdes[DARK]);
136 		fight(DARK,100);
137 	}
138 	if (testbit(location[position].objects,WOODSMAN)){
139 		printf("%s\n",objdes[WOODSMAN]);
140 		fight(WOODSMAN,50);
141 	}
142 	switch(position){
143 
144 		case 267:
145 		case 257:	/* entering a cave */
146 		case 274:
147 		case 246:
148 			notes[CANTSEE] = 1;
149 			break;
150 		case 160:
151 		case 216:	/* leaving a cave */
152 		case 230:
153 		case 231:
154 		case 232:
155 			notes[CANTSEE] = 0;
156 			break;
157 	}
158 	if (testbit(location[position].objects, GIRL))
159 		meetgirl = 1;
160 	if (meetgirl && CYCLE * 1.5 - time < 10){
161 		setbit(location[GARDEN].objects,GIRLTALK);
162 		setbit(location[GARDEN].objects,LAMPON);
163 		setbit(location[GARDEN].objects,ROPE);
164 	}
165 	if (position == DOCK && (beenthere[position] || time > CYCLE)){
166 		clearbit(location[DOCK].objects, GIRL);
167 		clearbit(location[DOCK].objects,MAN);
168 	}
169 	if (meetgirl && time - CYCLE * 1.5 > 10){
170 		clearbit(location[GARDEN].objects,GIRLTALK);
171 		clearbit(location[GARDEN].objects,LAMPON);
172 		clearbit(location[GARDEN].objects,ROPE);
173 		meetgirl = 0;
174 	}
175 	if (testbit(location[position].objects,CYLON)){
176 		puts("Oh my God, you're being shot at by an alien spacecraft!");
177 		printf("The targeting computer says we have %d seconds to attack!\n",clock);
178 		fflush(stdout);
179 		sleep(1);
180 		if (!visual()){
181 			hurt = rnd(NUMOFINJURIES);
182 			injuries[hurt] = 1;
183 			puts("Laser blasts sear the cockpit, and the alien veers off in a victory roll.");
184 			puts("The viper shudders under a terrible explosion.");
185 			printf("I'm afraid you have suffered %s.\n", ouch[hurt]);
186 		}
187 		else
188 			clearbit(location[position].objects,CYLON);
189 	}
190 	if (injuries[SKULL] && injuries[INCISE] && injuries[NECK]){
191 		puts("I'm afraid you have suffered fatal injuries.");
192 		die();
193 	}
194 	for (n=0; n < NUMOFINJURIES; n++)
195 		if (injuries[n] == 1){
196 			injuries[n] = 2;
197 			if (WEIGHT > 5)
198 				WEIGHT -= 5;
199 			else
200 				WEIGHT = 0;
201 		}
202 	if (injuries[ARM] == 2){
203 		CUMBER -= 5;
204 		injuries[ARM]++;
205 	}
206 	if (injuries[RIBS] == 2){
207 		CUMBER -= 2;
208 		injuries[RIBS]++;
209 	}
210 	if (injuries[SPINE] == 2){
211 		WEIGHT = 0;
212 		injuries[SPINE]++;
213 	}
214 	if (carrying > WEIGHT || encumber > CUMBER)
215 		notes[CANTMOVE] = 1;
216 	else
217 		notes[CANTMOVE] = 0;
218 }
219 
crash()220 crash()
221 {
222 	int hurt1,hurt2;
223 
224 	fuel--;
225 	if (!location[position].flyhere || (testbit(location[position].objects,LAND) && fuel <= 0)){
226 		if (!location[position].flyhere)
227 			puts("You're flying too low.  We're going to crash!");
228 		else{
229 			puts("You're out of fuel.  We'll have to crash land!");
230 			if (!location[position].down){
231 				puts("Your viper strikes the ground and explodes into firey fragments.");
232 				puts("Thick black smoke billows up from the wreckage.");
233 				die();
234 			}
235 			position = location[position].down;
236 		}
237 		notes[LAUNCHED] = 0;
238 		setbit(location[position].objects,CRASH);
239 		time += rnd(CYCLE/4);
240 		puts("The viper explodes into the ground and you lose consciousness...");
241 		zzz();
242 		hurt1 = rnd(NUMOFINJURIES - 2) + 2;
243 		hurt2 = rnd(NUMOFINJURIES - 2) + 2;
244 		injuries[hurt1] = 1;
245 		injuries[hurt2] = 1;
246 		injuries[0] = 1;	/* abrasions */
247 		injuries[1] = 1;	/* lacerations */
248 		printf("I'm afraid you have suffered %s and %s.\n",ouch[hurt1],ouch[hurt2]);
249 	}
250 }
251