MFC: Make apps using '#define _POSIX_C_SOURCE' compile.
[dragonfly.git] / games / battlestar / room.c
blobe1a71009062ea3288bd9552874635c15ff03b974
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. 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.
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.
33 * @(#)room.c 8.1 (Berkeley) 5/31/93
34 * $FreeBSD: src/games/battlestar/room.c,v 1.7.2.2 2001/03/05 11:45:36 kris Exp $
35 * $DragonFly: src/games/battlestar/room.c,v 1.3 2006/08/08 16:47:20 pavalos Exp $
38 #include "externs.h"
40 void
41 writedes(void)
43 int compass;
44 const char *p;
45 unsigned int c;
47 printf("\n\t%s\n", location[position].name);
48 if (beenthere[position] < 3) {
49 compass = NORTH;
50 for ((p = location[position].desc); (c = *p++);)
51 if (c != '-' && c != '*' && c != '+')
52 putchar((int)c);
53 else {
54 if (c != '*')
55 printf("%s", truedirec(compass, c));
56 compass++;
61 void
62 printobjs(void)
64 unsigned int *p = location[position].objects;
65 int n;
67 printf("\n");
68 for (n = 0; n < NUMOFOBJECTS; n++)
69 if (testbit(p, n) && objdes[n])
70 puts(objdes[n]);
73 void
74 whichway(struct room here)
76 switch(direction) {
78 case NORTH:
79 left = here.west;
80 right = here.east;
81 ahead = here.north;
82 back = here.south;
83 break;
85 case SOUTH:
86 left = here.east;
87 right = here.west;
88 ahead = here.south;
89 back = here.north;
90 break;
92 case EAST:
93 left = here.north;
94 right = here.south;
95 ahead = here.east;
96 back = here.west;
97 break;
99 case WEST:
100 left = here.south;
101 right = here.north;
102 ahead = here.west;
103 back = here.east;
104 break;
109 const char *
110 truedirec(int way, unsigned int option)
112 switch(way) {
114 case NORTH:
115 switch(direction) {
116 case NORTH:
117 return("ahead");
118 case SOUTH:
119 return(option == '+' ? "behind you" : "back");
120 case EAST:
121 return("left");
122 case WEST:
123 return("right");
126 case SOUTH:
127 switch(direction) {
128 case NORTH:
129 return(option == '+' ? "behind you" : "back");
130 case SOUTH:
131 return("ahead");
132 case EAST:
133 return("right");
134 case WEST:
135 return("left");
138 case EAST:
139 switch(direction) {
140 case NORTH:
141 return("right");
142 case SOUTH:
143 return("left");
144 case EAST:
145 return("ahead");
146 case WEST:
147 return(option == '+' ? "behind you" : "back");
150 case WEST:
151 switch(direction) {
152 case NORTH:
153 return("left");
154 case SOUTH:
155 return("right");
156 case EAST:
157 return(option == '+' ? "behind you" : "back");
158 case WEST:
159 return("ahead");
162 default:
163 printf("Error: room %d. More than four directions wanted.", position);
164 return("!!");
168 void
169 newway(int thisway)
171 switch(direction){
173 case NORTH:
174 switch(thisway){
175 case LEFT:
176 direction = WEST;
177 break;
178 case RIGHT:
179 direction = EAST;
180 break;
181 case BACK:
182 direction = SOUTH;
183 break;
185 break;
186 case SOUTH:
187 switch(thisway){
188 case LEFT:
189 direction = EAST;
190 break;
191 case RIGHT:
192 direction = WEST;
193 break;
194 case BACK:
195 direction = NORTH;
196 break;
198 break;
199 case EAST:
200 switch(thisway){
201 case LEFT:
202 direction = NORTH;
203 break;
204 case RIGHT:
205 direction = SOUTH;
206 break;
207 case BACK:
208 direction = WEST;
209 break;
211 break;
212 case WEST:
213 switch(thisway){
214 case LEFT:
215 direction = SOUTH;
216 break;
217 case RIGHT:
218 direction = NORTH;
219 break;
220 case BACK:
221 direction = EAST;
222 break;
224 break;