Remove some more unused headers.
[dragonfly.git] / games / battlestar / room.c
CommitLineData
6693db17 1/*-
984263bc
MD
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.
6693db17 13 * 3. Neither the name of the University nor the names of its contributors
984263bc
MD
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
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.
1de703da
MD
28 *
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 $
5c7cac79 31 * $DragonFly: src/games/battlestar/room.c,v 1.3 2006/08/08 16:47:20 pavalos Exp $
984263bc
MD
32 */
33
984263bc
MD
34#include "externs.h"
35
36void
5c7cac79 37writedes(void)
984263bc
MD
38{
39 int compass;
40 const char *p;
41 unsigned int c;
42
43 printf("\n\t%s\n", location[position].name);
44 if (beenthere[position] < 3) {
45 compass = NORTH;
6693db17
SW
46 for (p = location[position].desc; (c = *p++) != 0;)
47 if (c != '-' && c != '*' && c != '+') {
984263bc 48 putchar((int)c);
6693db17 49 } else {
984263bc
MD
50 if (c != '*')
51 printf("%s", truedirec(compass, c));
52 compass++;
53 }
54 }
55}
56
57void
5c7cac79 58printobjs(void)
984263bc 59{
6693db17 60 unsigned int *p;
984263bc
MD
61 int n;
62
6693db17 63 p = location[position].objects;
984263bc
MD
64 printf("\n");
65 for (n = 0; n < NUMOFOBJECTS; n++)
66 if (testbit(p, n) && objdes[n])
67 puts(objdes[n]);
68}
69
70void
5c7cac79 71whichway(struct room here)
984263bc 72{
6693db17
SW
73 switch (direction) {
74 case NORTH:
75 left = here.west;
76 right = here.east;
77 ahead = here.north;
78 back = here.south;
79 break;
80
81 case SOUTH:
82 left = here.east;
83 right = here.west;
84 ahead = here.south;
85 back = here.north;
86 break;
87
88 case EAST:
89 left = here.north;
90 right = here.south;
91 ahead = here.east;
92 back = here.west;
93 break;
94
95 case WEST:
96 left = here.south;
97 right = here.north;
98 ahead = here.west;
99 back = here.east;
100 break;
984263bc
MD
101 }
102}
103
104const char *
5c7cac79 105truedirec(int way, unsigned int option)
984263bc 106{
6693db17
SW
107 switch (way) {
108 case NORTH:
109 switch (direction) {
984263bc 110 case NORTH:
6693db17
SW
111 return ("ahead");
112 case SOUTH:
113 return (option == '+' ? "behind you" : "back");
114 case EAST:
115 return ("left");
116 case WEST:
117 return ("right");
118 }
984263bc 119
6693db17
SW
120 case SOUTH:
121 switch (direction) {
122 case NORTH:
123 return (option == '+' ? "behind you" : "back");
984263bc 124 case SOUTH:
6693db17
SW
125 return ("ahead");
126 case EAST:
127 return ("right");
128 case WEST:
129 return ("left");
130 }
984263bc 131
6693db17
SW
132 case EAST:
133 switch (direction) {
134 case NORTH:
135 return ("right");
136 case SOUTH:
137 return ("left");
984263bc 138 case EAST:
6693db17
SW
139 return ("ahead");
140 case WEST:
141 return (option == '+' ? "behind you" : "back");
142 }
984263bc 143
6693db17
SW
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");
984263bc 152 case WEST:
6693db17
SW
153 return ("ahead");
154 }
984263bc 155
6693db17
SW
156 default:
157 printf("Error: room %d. More than four directions wanted.",
158 position);
159 return ("!!");
160 }
984263bc
MD
161}
162
163void
5c7cac79 164newway(int thisway)
984263bc 165{
6693db17
SW
166 switch (direction) {
167 case NORTH:
168 switch (thisway) {
169 case LEFT:
170 direction = WEST;
984263bc 171 break;
6693db17
SW
172 case RIGHT:
173 direction = EAST;
984263bc 174 break;
6693db17
SW
175 case BACK:
176 direction = SOUTH;
984263bc 177 break;
6693db17
SW
178 }
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;
191 }
192 break;
193 case EAST:
194 switch (thisway) {
195 case LEFT:
196 direction = NORTH;
984263bc 197 break;
6693db17
SW
198 case RIGHT:
199 direction = SOUTH;
200 break;
201 case BACK:
202 direction = WEST;
203 break;
204 }
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;
217 }
218 break;
219 }
984263bc 220}