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