xref: /netbsd-src/games/battlestar/room.c (revision 481fca6e59249d8ffcf24fef7cfbe7b131bfb080)
1 /*	$NetBSD: room.c,v 1.7 1999/02/10 01:36:50 hubertf 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. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *	This product includes software developed by the University of
18  *	California, Berkeley and its contributors.
19  * 4. Neither the name of the University nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  */
35 
36 #include <sys/cdefs.h>
37 #ifndef lint
38 #if 0
39 static char sccsid[] = "@(#)room.c	8.2 (Berkeley) 4/28/95";
40 #else
41 __RCSID("$NetBSD: room.c,v 1.7 1999/02/10 01:36:50 hubertf Exp $");
42 #endif
43 #endif				/* not lint */
44 
45 #include "extern.h"
46 
47 void
48 writedes()
49 {
50 	int     compass;
51 	const char   *p;
52 	int     c;
53 
54 	printf("\n\t%s\n", location[position].name);
55 	if (beenthere[position] < 3) {
56 		compass = NORTH;
57 		for (p = location[position].desc; (c = *p++) != 0;)
58 			if (c != '-' && c != '*' && c != '+')
59 				putchar(c);
60 			else {
61 				if (c != '*')
62 					printf(truedirec(compass, c));
63 				compass++;
64 			}
65 	}
66 }
67 
68 void
69 printobjs()
70 {
71 	unsigned int *p = location[position].objects;
72 	int     n;
73 
74 	printf("\n");
75 	for (n = 0; n < NUMOFOBJECTS; n++)
76 		if (testbit(p, n) && objdes[n])
77 			puts(objdes[n]);
78 }
79 
80 void
81 whichway(here)
82 	struct room here;
83 {
84 	switch (direction) {
85 
86 	case NORTH:
87 		left = here.west;
88 		right = here.east;
89 		ahead = here.north;
90 		back = here.south;
91 		break;
92 
93 	case SOUTH:
94 		left = here.east;
95 		right = here.west;
96 		ahead = here.south;
97 		back = here.north;
98 		break;
99 
100 	case EAST:
101 		left = here.north;
102 		right = here.south;
103 		ahead = here.east;
104 		back = here.west;
105 		break;
106 
107 	case WEST:
108 		left = here.south;
109 		right = here.north;
110 		ahead = here.west;
111 		back = here.east;
112 		break;
113 
114 	}
115 }
116 
117 const char   *
118 truedirec(way, option)
119 	int     way;
120 	char    option;
121 {
122 	switch (way) {
123 
124 	case NORTH:
125 		switch (direction) {
126 		case NORTH:
127 			return ("ahead");
128 		case SOUTH:
129 			return (option == '+' ? "behind you" :
130 			    "back");
131 		case EAST:
132 			return ("left");
133 		case WEST:
134 			return ("right");
135 		}
136 
137 	case SOUTH:
138 		switch (direction) {
139 		case NORTH:
140 			return (option == '+' ? "behind you" :
141 			    "back");
142 		case SOUTH:
143 			return ("ahead");
144 		case EAST:
145 			return ("right");
146 		case WEST:
147 			return ("left");
148 		}
149 
150 	case EAST:
151 		switch (direction) {
152 		case NORTH:
153 			return ("right");
154 		case SOUTH:
155 			return ("left");
156 		case EAST:
157 			return ("ahead");
158 		case WEST:
159 			return (option == '+' ? "behind you" :
160 			    "back");
161 		}
162 
163 	case WEST:
164 		switch (direction) {
165 		case NORTH:
166 			return ("left");
167 		case SOUTH:
168 			return ("right");
169 		case EAST:
170 			return (option == '+' ? "behind you" :
171 			    "back");
172 		case WEST:
173 			return ("ahead");
174 		}
175 
176 	default:
177 		printf("Error: room %d.  More than four directions wanted.", position);
178 		return ("!!");
179 	}
180 }
181 
182 void
183 newway(thisway)
184 	int     thisway;
185 {
186 	switch (direction) {
187 
188 	case NORTH:
189 		switch (thisway) {
190 		case LEFT:
191 			direction = WEST;
192 			break;
193 		case RIGHT:
194 			direction = EAST;
195 			break;
196 		case BACK:
197 			direction = SOUTH;
198 			break;
199 		}
200 		break;
201 	case SOUTH:
202 		switch (thisway) {
203 		case LEFT:
204 			direction = EAST;
205 			break;
206 		case RIGHT:
207 			direction = WEST;
208 			break;
209 		case BACK:
210 			direction = NORTH;
211 			break;
212 		}
213 		break;
214 	case EAST:
215 		switch (thisway) {
216 		case LEFT:
217 			direction = NORTH;
218 			break;
219 		case RIGHT:
220 			direction = SOUTH;
221 			break;
222 		case BACK:
223 			direction = WEST;
224 			break;
225 		}
226 		break;
227 	case WEST:
228 		switch (thisway) {
229 		case LEFT:
230 			direction = SOUTH;
231 			break;
232 		case RIGHT:
233 			direction = NORTH;
234 			break;
235 		case BACK:
236 			direction = EAST;
237 			break;
238 		}
239 		break;
240 	}
241 }
242