room.c revision 1.8 1 1.8 jsm /* $NetBSD: room.c,v 1.8 2000/09/08 17:22:02 jsm 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.8 jsm __RCSID("$NetBSD: room.c,v 1.8 2000/09/08 17:22:02 jsm Exp $");
42 1.3 cgd #endif
43 1.6 lukem #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.6 lukem int compass;
51 1.7 hubertf const char *p;
52 1.6 lukem int c;
53 1.1 cgd
54 1.1 cgd printf("\n\t%s\n", location[position].name);
55 1.8 jsm if (beenthere[position] < ROOMDESC) {
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.6 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.6 lukem switch (direction) {
85 1.1 cgd
86 1.6 lukem case NORTH:
87 1.6 lukem left = here.west;
88 1.6 lukem right = here.east;
89 1.6 lukem ahead = here.north;
90 1.6 lukem back = here.south;
91 1.6 lukem break;
92 1.6 lukem
93 1.6 lukem case SOUTH:
94 1.6 lukem left = here.east;
95 1.6 lukem right = here.west;
96 1.6 lukem ahead = here.south;
97 1.6 lukem back = here.north;
98 1.6 lukem break;
99 1.6 lukem
100 1.6 lukem case EAST:
101 1.6 lukem left = here.north;
102 1.6 lukem right = here.south;
103 1.6 lukem ahead = here.east;
104 1.6 lukem back = here.west;
105 1.6 lukem break;
106 1.6 lukem
107 1.6 lukem case WEST:
108 1.6 lukem left = here.south;
109 1.6 lukem right = here.north;
110 1.6 lukem ahead = here.west;
111 1.6 lukem back = here.east;
112 1.6 lukem break;
113 1.1 cgd
114 1.1 cgd }
115 1.1 cgd }
116 1.1 cgd
117 1.7 hubertf const char *
118 1.1 cgd truedirec(way, option)
119 1.6 lukem int way;
120 1.6 lukem char option;
121 1.1 cgd {
122 1.6 lukem switch (way) {
123 1.1 cgd
124 1.6 lukem case NORTH:
125 1.6 lukem switch (direction) {
126 1.1 cgd case NORTH:
127 1.6 lukem return ("ahead");
128 1.6 lukem case SOUTH:
129 1.6 lukem return (option == '+' ? "behind you" :
130 1.6 lukem "back");
131 1.6 lukem case EAST:
132 1.6 lukem return ("left");
133 1.6 lukem case WEST:
134 1.6 lukem return ("right");
135 1.6 lukem }
136 1.1 cgd
137 1.6 lukem case SOUTH:
138 1.6 lukem switch (direction) {
139 1.6 lukem case NORTH:
140 1.6 lukem return (option == '+' ? "behind you" :
141 1.6 lukem "back");
142 1.1 cgd case SOUTH:
143 1.6 lukem return ("ahead");
144 1.6 lukem case EAST:
145 1.6 lukem return ("right");
146 1.6 lukem case WEST:
147 1.6 lukem return ("left");
148 1.6 lukem }
149 1.1 cgd
150 1.6 lukem case EAST:
151 1.6 lukem switch (direction) {
152 1.6 lukem case NORTH:
153 1.6 lukem return ("right");
154 1.6 lukem case SOUTH:
155 1.6 lukem return ("left");
156 1.1 cgd case EAST:
157 1.6 lukem return ("ahead");
158 1.6 lukem case WEST:
159 1.6 lukem return (option == '+' ? "behind you" :
160 1.6 lukem "back");
161 1.6 lukem }
162 1.1 cgd
163 1.6 lukem case WEST:
164 1.6 lukem switch (direction) {
165 1.6 lukem case NORTH:
166 1.6 lukem return ("left");
167 1.6 lukem case SOUTH:
168 1.6 lukem return ("right");
169 1.6 lukem case EAST:
170 1.6 lukem return (option == '+' ? "behind you" :
171 1.6 lukem "back");
172 1.1 cgd case WEST:
173 1.6 lukem return ("ahead");
174 1.6 lukem }
175 1.1 cgd
176 1.6 lukem default:
177 1.6 lukem printf("Error: room %d. More than four directions wanted.", position);
178 1.6 lukem return ("!!");
179 1.6 lukem }
180 1.1 cgd }
181 1.1 cgd
182 1.5 lukem void
183 1.1 cgd newway(thisway)
184 1.6 lukem int thisway;
185 1.1 cgd {
186 1.6 lukem switch (direction) {
187 1.1 cgd
188 1.6 lukem case NORTH:
189 1.6 lukem switch (thisway) {
190 1.6 lukem case LEFT:
191 1.6 lukem direction = WEST;
192 1.6 lukem break;
193 1.6 lukem case RIGHT:
194 1.6 lukem direction = EAST;
195 1.6 lukem break;
196 1.6 lukem case BACK:
197 1.6 lukem direction = SOUTH;
198 1.6 lukem break;
199 1.6 lukem }
200 1.6 lukem break;
201 1.6 lukem case SOUTH:
202 1.6 lukem switch (thisway) {
203 1.6 lukem case LEFT:
204 1.6 lukem direction = EAST;
205 1.6 lukem break;
206 1.6 lukem case RIGHT:
207 1.6 lukem direction = WEST;
208 1.6 lukem break;
209 1.6 lukem case BACK:
210 1.6 lukem direction = NORTH;
211 1.6 lukem break;
212 1.6 lukem }
213 1.6 lukem break;
214 1.6 lukem case EAST:
215 1.6 lukem switch (thisway) {
216 1.6 lukem case LEFT:
217 1.6 lukem direction = NORTH;
218 1.6 lukem break;
219 1.6 lukem case RIGHT:
220 1.6 lukem direction = SOUTH;
221 1.6 lukem break;
222 1.6 lukem case BACK:
223 1.6 lukem direction = WEST;
224 1.6 lukem break;
225 1.6 lukem }
226 1.6 lukem break;
227 1.6 lukem case WEST:
228 1.6 lukem switch (thisway) {
229 1.6 lukem case LEFT:
230 1.6 lukem direction = SOUTH;
231 1.1 cgd break;
232 1.6 lukem case RIGHT:
233 1.6 lukem direction = NORTH;
234 1.1 cgd break;
235 1.6 lukem case BACK:
236 1.6 lukem direction = EAST;
237 1.1 cgd break;
238 1.6 lukem }
239 1.6 lukem break;
240 1.6 lukem }
241 1.1 cgd }
242