1 /* $OpenBSD: room.c,v 1.11 2015/12/31 17:51:19 mestre Exp $ */
2 /* $NetBSD: room.c,v 1.3 1995/03/21 15:07:54 cgd 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 <stdio.h>
34
35 #include "extern.h"
36
37 void
writedes(void)38 writedes(void)
39 {
40 int compass;
41 const char *p;
42 int c;
43
44 printf("\n\t%s\n", location[position].name);
45 if (beenthere[position] < ROOMDESC || verbose) {
46 compass = NORTH;
47 for (p = location[position].desc; (c = *p++) != 0;)
48 if (c != '-' && c != '*' && c != '+') {
49 if (c == '=')
50 putchar('-');
51 else
52 putchar(c);
53 } else {
54 if (c != '*')
55 printf("%s", truedirec(compass, c));
56 compass++;
57 }
58 }
59 }
60
61 void
printobjs(void)62 printobjs(void)
63 {
64 unsigned int *p = location[position].objects;
65 int n;
66
67 printf("\n");
68 for (n = 0; n < NUMOFOBJECTS; n++)
69 if (TestBit(p, n) && objdes[n])
70 puts(objdes[n]);
71 }
72
73 void
whichway(struct room here)74 whichway(struct room here)
75 {
76 switch (direction) {
77
78 case NORTH:
79 left = here.west;
80 right = here.east;
81 ahead = here.north;
82 back = here.south;
83 break;
84
85 case SOUTH:
86 left = here.east;
87 right = here.west;
88 ahead = here.south;
89 back = here.north;
90 break;
91
92 case EAST:
93 left = here.north;
94 right = here.south;
95 ahead = here.east;
96 back = here.west;
97 break;
98
99 case WEST:
100 left = here.south;
101 right = here.north;
102 ahead = here.west;
103 back = here.east;
104 break;
105
106 }
107 }
108
109 const char *
truedirec(int way,char option)110 truedirec(int way, char option)
111 {
112 switch (way) {
113
114 case NORTH:
115 switch (direction) {
116 case NORTH:
117 return ("ahead");
118 case SOUTH:
119 return (option == '+' ? "behind you" : "back");
120 case EAST:
121 return ("left");
122 case WEST:
123 return ("right");
124 }
125
126 case SOUTH:
127 switch (direction) {
128 case NORTH:
129 return (option == '+' ? "behind you" : "back");
130 case SOUTH:
131 return ("ahead");
132 case EAST:
133 return ("right");
134 case WEST:
135 return ("left");
136 }
137
138 case EAST:
139 switch (direction) {
140 case NORTH:
141 return ("right");
142 case SOUTH:
143 return ("left");
144 case EAST:
145 return ("ahead");
146 case WEST:
147 return (option == '+' ? "behind you" : "back");
148 }
149
150 case WEST:
151 switch (direction) {
152 case NORTH:
153 return ("left");
154 case SOUTH:
155 return ("right");
156 case EAST:
157 return (option == '+' ? "behind you" : "back");
158 case WEST:
159 return ("ahead");
160 }
161
162 default:
163 printf("Error: room %d. More than four directions wanted.", position);
164 return ("!!");
165 }
166 }
167
168 void
newway(int thisway)169 newway(int thisway)
170 {
171 switch (direction) {
172
173 case NORTH:
174 switch (thisway) {
175 case LEFT:
176 direction = WEST;
177 break;
178 case RIGHT:
179 direction = EAST;
180 break;
181 case BACK:
182 direction = SOUTH;
183 break;
184 }
185 break;
186 case SOUTH:
187 switch (thisway) {
188 case LEFT:
189 direction = EAST;
190 break;
191 case RIGHT:
192 direction = WEST;
193 break;
194 case BACK:
195 direction = NORTH;
196 break;
197 }
198 break;
199 case EAST:
200 switch (thisway) {
201 case LEFT:
202 direction = NORTH;
203 break;
204 case RIGHT:
205 direction = SOUTH;
206 break;
207 case BACK:
208 direction = WEST;
209 break;
210 }
211 break;
212 case WEST:
213 switch (thisway) {
214 case LEFT:
215 direction = SOUTH;
216 break;
217 case RIGHT:
218 direction = NORTH;
219 break;
220 case BACK:
221 direction = EAST;
222 break;
223 }
224 break;
225 }
226 }
227