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