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