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