room.c revision 1.11 1 /* $NetBSD: room.c,v 1.11 2003/08/07 09:37:03 agc 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.11 2003/08/07 09:37:03 agc Exp $");
38 #endif
39 #endif /* not lint */
40
41 #include "extern.h"
42
43 void
44 writedes()
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(truedirec(compass, c));
62 compass++;
63 }
64 }
65 }
66
67 void
68 printobjs()
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(here)
81 struct room here;
82 {
83 switch (direction) {
84
85 case NORTH:
86 left = here.west;
87 right = here.east;
88 ahead = here.north;
89 back = here.south;
90 break;
91
92 case SOUTH:
93 left = here.east;
94 right = here.west;
95 ahead = here.south;
96 back = here.north;
97 break;
98
99 case EAST:
100 left = here.north;
101 right = here.south;
102 ahead = here.east;
103 back = here.west;
104 break;
105
106 case WEST:
107 left = here.south;
108 right = here.north;
109 ahead = here.west;
110 back = here.east;
111 break;
112
113 }
114 }
115
116 const char *
117 truedirec(way, option)
118 int way;
119 char option;
120 {
121 switch (way) {
122
123 case NORTH:
124 switch (direction) {
125 case NORTH:
126 return ("ahead");
127 case SOUTH:
128 return (option == '+' ? "behind you" :
129 "back");
130 case EAST:
131 return ("left");
132 case WEST:
133 return ("right");
134 }
135
136 case SOUTH:
137 switch (direction) {
138 case NORTH:
139 return (option == '+' ? "behind you" :
140 "back");
141 case SOUTH:
142 return ("ahead");
143 case EAST:
144 return ("right");
145 case WEST:
146 return ("left");
147 }
148
149 case EAST:
150 switch (direction) {
151 case NORTH:
152 return ("right");
153 case SOUTH:
154 return ("left");
155 case EAST:
156 return ("ahead");
157 case WEST:
158 return (option == '+' ? "behind you" :
159 "back");
160 }
161
162 case WEST:
163 switch (direction) {
164 case NORTH:
165 return ("left");
166 case SOUTH:
167 return ("right");
168 case EAST:
169 return (option == '+' ? "behind you" :
170 "back");
171 case WEST:
172 return ("ahead");
173 }
174
175 default:
176 printf("Error: room %d. More than four directions wanted.", position);
177 return ("!!");
178 }
179 }
180
181 void
182 newway(thisway)
183 int thisway;
184 {
185 switch (direction) {
186
187 case NORTH:
188 switch (thisway) {
189 case LEFT:
190 direction = WEST;
191 break;
192 case RIGHT:
193 direction = EAST;
194 break;
195 case BACK:
196 direction = SOUTH;
197 break;
198 }
199 break;
200 case SOUTH:
201 switch (thisway) {
202 case LEFT:
203 direction = EAST;
204 break;
205 case RIGHT:
206 direction = WEST;
207 break;
208 case BACK:
209 direction = NORTH;
210 break;
211 }
212 break;
213 case EAST:
214 switch (thisway) {
215 case LEFT:
216 direction = NORTH;
217 break;
218 case RIGHT:
219 direction = SOUTH;
220 break;
221 case BACK:
222 direction = WEST;
223 break;
224 }
225 break;
226 case WEST:
227 switch (thisway) {
228 case LEFT:
229 direction = SOUTH;
230 break;
231 case RIGHT:
232 direction = NORTH;
233 break;
234 case BACK:
235 direction = EAST;
236 break;
237 }
238 break;
239 }
240 }
241