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