room.c 4.7 KB

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