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