]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - battlestar/room.c
Add RCS identifiers.
[bsdgames-darwin.git] / battlestar / room.c
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
35 /*static char sccsid[] = "from: @(#)room.c 5.3 (Berkeley) 6/1/90";*/
36 static char rcsid[] = "$Id: room.c,v 1.2 1993/08/01 18:55:54 mycroft Exp $";
37 #endif /* not lint */
38
39 #include "externs.h"
40
41 writedes()
42 {
43 int compass;
44 register char *p;
45 register c;
46
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(c);
53 else {
54 if (c != '*')
55 printf(truedirec(compass, c));
56 compass++;
57 }
58 }
59 }
60
61 printobjs()
62 {
63 register unsigned int *p = location[position].objects;
64 register n;
65
66 printf("\n");
67 for (n = 0; n < NUMOFOBJECTS; n++)
68 if (testbit(p, n) && objdes[n])
69 puts(objdes[n]);
70 }
71
72 whichway(here)
73 struct room here;
74 {
75 switch(direction) {
76
77 case NORTH:
78 left = here.west;
79 right = here.east;
80 ahead = here.north;
81 back = here.south;
82 break;
83
84 case SOUTH:
85 left = here.east;
86 right = here.west;
87 ahead = here.south;
88 back = here.north;
89 break;
90
91 case EAST:
92 left = here.north;
93 right = here.south;
94 ahead = here.east;
95 back = here.west;
96 break;
97
98 case WEST:
99 left = here.south;
100 right = here.north;
101 ahead = here.west;
102 back = here.east;
103 break;
104
105 }
106 }
107
108 char *
109 truedirec(way, option)
110 int way;
111 char option;
112 {
113 switch(way) {
114
115 case NORTH:
116 switch(direction) {
117 case NORTH:
118 return("ahead");
119 case SOUTH:
120 return(option == '+' ? "behind you" : "back");
121 case EAST:
122 return("left");
123 case WEST:
124 return("right");
125 }
126
127 case SOUTH:
128 switch(direction) {
129 case NORTH:
130 return(option == '+' ? "behind you" : "back");
131 case SOUTH:
132 return("ahead");
133 case EAST:
134 return("right");
135 case WEST:
136 return("left");
137 }
138
139 case EAST:
140 switch(direction) {
141 case NORTH:
142 return("right");
143 case SOUTH:
144 return("left");
145 case EAST:
146 return("ahead");
147 case WEST:
148 return(option == '+' ? "behind you" : "back");
149 }
150
151 case WEST:
152 switch(direction) {
153 case NORTH:
154 return("left");
155 case SOUTH:
156 return("right");
157 case EAST:
158 return(option == '+' ? "behind you" : "back");
159 case WEST:
160 return("ahead");
161 }
162
163 default:
164 printf("Error: room %d. More than four directions wanted.", position);
165 return("!!");
166 }
167 }
168
169 newway(thisway)
170 int thisway;
171 {
172 switch(direction){
173
174 case NORTH:
175 switch(thisway){
176 case LEFT:
177 direction = WEST;
178 break;
179 case RIGHT:
180 direction = EAST;
181 break;
182 case BACK:
183 direction = SOUTH;
184 break;
185 }
186 break;
187 case SOUTH:
188 switch(thisway){
189 case LEFT:
190 direction = EAST;
191 break;
192 case RIGHT:
193 direction = WEST;
194 break;
195 case BACK:
196 direction = NORTH;
197 break;
198 }
199 break;
200 case EAST:
201 switch(thisway){
202 case LEFT:
203 direction = NORTH;
204 break;
205 case RIGHT:
206 direction = SOUTH;
207 break;
208 case BACK:
209 direction = WEST;
210 break;
211 }
212 break;
213 case WEST:
214 switch(thisway){
215 case LEFT:
216 direction = SOUTH;
217 break;
218 case RIGHT:
219 direction = NORTH;
220 break;
221 case BACK:
222 direction = EAST;
223 break;
224 }
225 break;
226 }
227 }