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