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