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