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