Merge from vendor branch LESS:
[dragonfly.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  * @(#)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.2 2003/06/17 04:25:23 dillon Exp $
36  */
37
38 #include "externs.h"
39
40 void
41 writedes()
42 {
43         int compass;
44         const char *p;
45         unsigned int 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((int)c);
53                         else {
54                                 if (c != '*')
55                                         printf("%s", truedirec(compass, c));
56                                 compass++;
57                         }
58         }
59 }
60
61 void
62 printobjs()
63 {
64         unsigned int *p = location[position].objects;
65         int n;
66
67         printf("\n");
68         for (n = 0; n < NUMOFOBJECTS; n++)
69                 if (testbit(p, n) && objdes[n])
70                         puts(objdes[n]);
71 }
72
73 void
74 whichway(here)
75 struct room here;
76 {
77         switch(direction) {
78
79                 case NORTH:
80                         left = here.west;
81                         right = here.east;
82                         ahead = here.north;
83                         back = here.south;
84                         break;
85
86                 case SOUTH:
87                         left = here.east;
88                         right = here.west;
89                         ahead = here.south;
90                         back = here.north;
91                         break;
92
93                 case EAST:
94                         left = here.north;
95                         right = here.south;
96                         ahead = here.east;
97                         back = here.west;
98                         break;
99
100                 case WEST:
101                         left = here.south;
102                         right = here.north;
103                         ahead = here.west;
104                         back = here.east;
105                         break;
106
107         }
108 }
109
110 const char *
111 truedirec(way, option)
112 int way;
113 unsigned int option;
114 {
115         switch(way) {
116
117                 case NORTH:
118                         switch(direction) {
119                                 case NORTH:
120                                         return("ahead");
121                                 case SOUTH:
122                                         return(option == '+' ? "behind you" : "back");
123                                 case EAST:
124                                         return("left");
125                                 case WEST:
126                                         return("right");
127                         }
128
129                 case SOUTH:
130                         switch(direction) {
131                                 case NORTH:
132                                         return(option == '+' ? "behind you" : "back");
133                                 case SOUTH:
134                                         return("ahead");
135                                 case EAST:
136                                         return("right");
137                                 case WEST:
138                                         return("left");
139                         }
140
141                 case EAST:
142                         switch(direction) {
143                                 case NORTH:
144                                         return("right");
145                                 case SOUTH:
146                                         return("left");
147                                 case EAST:
148                                         return("ahead");
149                                 case WEST:
150                                         return(option == '+' ? "behind you" : "back");
151                         }
152
153                 case WEST:
154                         switch(direction) {
155                                 case NORTH:
156                                         return("left");
157                                 case SOUTH:
158                                         return("right");
159                                 case EAST:
160                                         return(option == '+' ? "behind you" : "back");
161                                 case WEST:
162                                         return("ahead");
163                         }
164
165                 default:
166                         printf("Error: room %d.  More than four directions wanted.", position);
167                         return("!!");
168       }
169 }
170
171 void
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 }