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