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