386BSD 0.1 development
[unix-history] / usr / othersrc / games / battlestar / room.c
CommitLineData
2a1cfdf5
WJ
1/*
2 * Copyright (c) 1983 Regents of the University of California.
3 * 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
35static char sccsid[] = "@(#)room.c 5.3 (Berkeley) 6/1/90";
36#endif /* not lint */
37
38#include "externs.h"
39
40writedes()
41{
42 int compass;
43 register char *p;
44 register c;
45
46 printf("\n\t%s\n", location[position].name);
47 if (beenthere[position] < 3) {
48 compass = NORTH;
49 for (p = location[position].desc; c = *p++;)
50 if (c != '-' && c != '*' && c != '+')
51 putchar(c);
52 else {
53 if (c != '*')
54 printf(truedirec(compass, c));
55 compass++;
56 }
57 }
58}
59
60printobjs()
61{
62 register unsigned int *p = location[position].objects;
63 register n;
64
65 printf("\n");
66 for (n = 0; n < NUMOFOBJECTS; n++)
67 if (testbit(p, n) && objdes[n])
68 puts(objdes[n]);
69}
70
71whichway(here)
72struct room here;
73{
74 switch(direction) {
75
76 case NORTH:
77 left = here.west;
78 right = here.east;
79 ahead = here.north;
80 back = here.south;
81 break;
82
83 case SOUTH:
84 left = here.east;
85 right = here.west;
86 ahead = here.south;
87 back = here.north;
88 break;
89
90 case EAST:
91 left = here.north;
92 right = here.south;
93 ahead = here.east;
94 back = here.west;
95 break;
96
97 case WEST:
98 left = here.south;
99 right = here.north;
100 ahead = here.west;
101 back = here.east;
102 break;
103
104 }
105}
106
107char *
108truedirec(way, option)
109int way;
110char option;
111{
112 switch(way) {
113
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");
124 }
125
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");
136 }
137
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");
148 }
149
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");
160 }
161
162 default:
163 printf("Error: room %d. More than four directions wanted.", position);
164 return("!!");
165 }
166}
167
168newway(thisway)
169int thisway;
170{
171 switch(direction){
172
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;
184 }
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;
197 }
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;
210 }
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;
223 }
224 break;
225 }
226}