Annotation of src/games/battlestar/room.c, Revision 1.11
1.11 ! agc 1: /* $NetBSD: room.c,v 1.10 2000/09/17 23:03:43 jsm Exp $ */
1.3 cgd 2:
1.1 cgd 3: /*
1.3 cgd 4: * Copyright (c) 1983, 1993
5: * The Regents of the University of California. All rights reserved.
1.1 cgd 6: *
7: * Redistribution and use in source and binary forms, with or without
8: * modification, are permitted provided that the following conditions
9: * are met:
10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
12: * 2. Redistributions in binary form must reproduce the above copyright
13: * notice, this list of conditions and the following disclaimer in the
14: * documentation and/or other materials provided with the distribution.
1.11 ! agc 15: * 3. Neither the name of the University nor the names of its contributors
1.1 cgd 16: * may be used to endorse or promote products derived from this software
17: * without specific prior written permission.
18: *
19: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29: * SUCH DAMAGE.
30: */
31:
1.5 lukem 32: #include <sys/cdefs.h>
1.1 cgd 33: #ifndef lint
1.3 cgd 34: #if 0
1.4 tls 35: static char sccsid[] = "@(#)room.c 8.2 (Berkeley) 4/28/95";
1.3 cgd 36: #else
1.11 ! agc 37: __RCSID("$NetBSD: room.c,v 1.10 2000/09/17 23:03:43 jsm Exp $");
1.3 cgd 38: #endif
1.6 lukem 39: #endif /* not lint */
1.1 cgd 40:
1.4 tls 41: #include "extern.h"
1.1 cgd 42:
1.5 lukem 43: void
1.1 cgd 44: writedes()
45: {
1.6 lukem 46: int compass;
1.7 hubertf 47: const char *p;
1.6 lukem 48: int c;
1.1 cgd 49:
50: printf("\n\t%s\n", location[position].name);
1.10 jsm 51: if (beenthere[position] < ROOMDESC || verbose) {
1.1 cgd 52: compass = NORTH;
1.5 lukem 53: for (p = location[position].desc; (c = *p++) != 0;)
1.9 jsm 54: if (c != '-' && c != '*' && c != '+') {
55: if (c == '=')
56: putchar('-');
57: else
58: putchar(c);
59: } else {
1.1 cgd 60: if (c != '*')
61: printf(truedirec(compass, c));
62: compass++;
63: }
64: }
65: }
66:
1.5 lukem 67: void
1.1 cgd 68: printobjs()
69: {
1.5 lukem 70: unsigned int *p = location[position].objects;
1.6 lukem 71: int n;
1.1 cgd 72:
73: printf("\n");
74: for (n = 0; n < NUMOFOBJECTS; n++)
75: if (testbit(p, n) && objdes[n])
76: puts(objdes[n]);
77: }
78:
1.5 lukem 79: void
1.1 cgd 80: whichway(here)
1.5 lukem 81: struct room here;
1.1 cgd 82: {
1.6 lukem 83: switch (direction) {
1.1 cgd 84:
1.6 lukem 85: case NORTH:
86: left = here.west;
87: right = here.east;
88: ahead = here.north;
89: back = here.south;
90: break;
91:
92: case SOUTH:
93: left = here.east;
94: right = here.west;
95: ahead = here.south;
96: back = here.north;
97: break;
98:
99: case EAST:
100: left = here.north;
101: right = here.south;
102: ahead = here.east;
103: back = here.west;
104: break;
105:
106: case WEST:
107: left = here.south;
108: right = here.north;
109: ahead = here.west;
110: back = here.east;
111: break;
1.1 cgd 112:
113: }
114: }
115:
1.7 hubertf 116: const char *
1.1 cgd 117: truedirec(way, option)
1.6 lukem 118: int way;
119: char option;
1.1 cgd 120: {
1.6 lukem 121: switch (way) {
1.1 cgd 122:
1.6 lukem 123: case NORTH:
124: switch (direction) {
1.1 cgd 125: case NORTH:
1.6 lukem 126: return ("ahead");
127: case SOUTH:
128: return (option == '+' ? "behind you" :
129: "back");
130: case EAST:
131: return ("left");
132: case WEST:
133: return ("right");
134: }
1.1 cgd 135:
1.6 lukem 136: case SOUTH:
137: switch (direction) {
138: case NORTH:
139: return (option == '+' ? "behind you" :
140: "back");
1.1 cgd 141: case SOUTH:
1.6 lukem 142: return ("ahead");
143: case EAST:
144: return ("right");
145: case WEST:
146: return ("left");
147: }
1.1 cgd 148:
1.6 lukem 149: case EAST:
150: switch (direction) {
151: case NORTH:
152: return ("right");
153: case SOUTH:
154: return ("left");
1.1 cgd 155: case EAST:
1.6 lukem 156: return ("ahead");
157: case WEST:
158: return (option == '+' ? "behind you" :
159: "back");
160: }
1.1 cgd 161:
1.6 lukem 162: case WEST:
163: switch (direction) {
164: case NORTH:
165: return ("left");
166: case SOUTH:
167: return ("right");
168: case EAST:
169: return (option == '+' ? "behind you" :
170: "back");
1.1 cgd 171: case WEST:
1.6 lukem 172: return ("ahead");
173: }
1.1 cgd 174:
1.6 lukem 175: default:
176: printf("Error: room %d. More than four directions wanted.", position);
177: return ("!!");
178: }
1.1 cgd 179: }
180:
1.5 lukem 181: void
1.1 cgd 182: newway(thisway)
1.6 lukem 183: int thisway;
1.1 cgd 184: {
1.6 lukem 185: switch (direction) {
1.1 cgd 186:
1.6 lukem 187: case NORTH:
188: switch (thisway) {
189: case LEFT:
190: direction = WEST;
191: break;
192: case RIGHT:
193: direction = EAST;
194: break;
195: case BACK:
196: direction = SOUTH;
197: break;
198: }
199: break;
200: case SOUTH:
201: switch (thisway) {
202: case LEFT:
203: direction = EAST;
204: break;
205: case RIGHT:
206: direction = WEST;
207: break;
208: case BACK:
209: direction = NORTH;
210: break;
211: }
212: break;
213: case EAST:
214: switch (thisway) {
215: case LEFT:
216: direction = NORTH;
217: break;
218: case RIGHT:
219: direction = SOUTH;
220: break;
221: case BACK:
222: direction = WEST;
223: break;
224: }
225: break;
226: case WEST:
227: switch (thisway) {
228: case LEFT:
229: direction = SOUTH;
1.1 cgd 230: break;
1.6 lukem 231: case RIGHT:
232: direction = NORTH;
1.1 cgd 233: break;
1.6 lukem 234: case BACK:
235: direction = EAST;
1.1 cgd 236: break;
1.6 lukem 237: }
238: break;
239: }
1.1 cgd 240: }
CVSweb <webmaster@jp.NetBSD.org>