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