hammer2(8): Document cleanup command.
[dragonfly.git] / games / battlestar / room.c
blob5f333196de5d22be9a5166652481ee9238a98975
1 /*-
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
29 * @(#)room.c 8.1 (Berkeley) 5/31/93
30 * $FreeBSD: src/games/battlestar/room.c,v 1.7.2.2 2001/03/05 11:45:36 kris Exp $
31 * $DragonFly: src/games/battlestar/room.c,v 1.3 2006/08/08 16:47:20 pavalos Exp $
34 #include "externs.h"
36 void
37 writedes(void)
39 int compass;
40 const char *p;
41 unsigned int c;
43 printf("\n\t%s\n", location[position].name);
44 if (beenthere[position] < 3) {
45 compass = NORTH;
46 for (p = location[position].desc; (c = *p++) != 0;)
47 if (c != '-' && c != '*' && c != '+') {
48 putchar((int)c);
49 } else {
50 if (c != '*')
51 printf("%s", truedirec(compass, c));
52 compass++;
57 void
58 printobjs(void)
60 unsigned int *p;
61 int n;
63 p = location[position].objects;
64 printf("\n");
65 for (n = 0; n < NUMOFOBJECTS; n++)
66 if (testbit(p, n) && objdes[n])
67 puts(objdes[n]);
70 void
71 whichway(struct room here)
73 switch (direction) {
74 case NORTH:
75 left = here.west;
76 right = here.east;
77 ahead = here.north;
78 back = here.south;
79 break;
81 case SOUTH:
82 left = here.east;
83 right = here.west;
84 ahead = here.south;
85 back = here.north;
86 break;
88 case EAST:
89 left = here.north;
90 right = here.south;
91 ahead = here.east;
92 back = here.west;
93 break;
95 case WEST:
96 left = here.south;
97 right = here.north;
98 ahead = here.west;
99 back = here.east;
100 break;
104 const char *
105 truedirec(int way, unsigned int option)
107 switch (way) {
108 case NORTH:
109 switch (direction) {
110 case NORTH:
111 return ("ahead");
112 case SOUTH:
113 return (option == '+' ? "behind you" : "back");
114 case EAST:
115 return ("left");
116 case WEST:
117 return ("right");
120 case SOUTH:
121 switch (direction) {
122 case NORTH:
123 return (option == '+' ? "behind you" : "back");
124 case SOUTH:
125 return ("ahead");
126 case EAST:
127 return ("right");
128 case WEST:
129 return ("left");
132 case EAST:
133 switch (direction) {
134 case NORTH:
135 return ("right");
136 case SOUTH:
137 return ("left");
138 case EAST:
139 return ("ahead");
140 case WEST:
141 return (option == '+' ? "behind you" : "back");
144 case WEST:
145 switch (direction) {
146 case NORTH:
147 return ("left");
148 case SOUTH:
149 return ("right");
150 case EAST:
151 return (option == '+' ? "behind you" : "back");
152 case WEST:
153 return ("ahead");
156 default:
157 printf("Error: room %d. More than four directions wanted.",
158 position);
159 return ("!!");
163 void
164 newway(int thisway)
166 switch (direction) {
167 case NORTH:
168 switch (thisway) {
169 case LEFT:
170 direction = WEST;
171 break;
172 case RIGHT:
173 direction = EAST;
174 break;
175 case BACK:
176 direction = SOUTH;
177 break;
179 break;
180 case SOUTH:
181 switch (thisway) {
182 case LEFT:
183 direction = EAST;
184 break;
185 case RIGHT:
186 direction = WEST;
187 break;
188 case BACK:
189 direction = NORTH;
190 break;
192 break;
193 case EAST:
194 switch (thisway) {
195 case LEFT:
196 direction = NORTH;
197 break;
198 case RIGHT:
199 direction = SOUTH;
200 break;
201 case BACK:
202 direction = WEST;
203 break;
205 break;
206 case WEST:
207 switch (thisway) {
208 case LEFT:
209 direction = SOUTH;
210 break;
211 case RIGHT:
212 direction = NORTH;
213 break;
214 case BACK:
215 direction = EAST;
216 break;
218 break;