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