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