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