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