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