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