# 2.11BSD#431 - /usr/src/games/battlestar/room.c

##### Functions

    newway            X
    printobjs         X
    strprt            X
    truedirec         X
    whichway          X
    writedes          X

       1: /*
       2:  * Copyright (c) 1983 Regents of the University of California,
       3:  * All rights reserved.  Redistribution permitted subject to
       4:  * the terms of the Berkeley Software License Agreement.
       5:  */
       6:
       7: #if !defined(lint) && !defined(pdp11)
       8: static char sccsid[] = "@(#)room.c	1.3 4/24/85";
       9: #endif
      10:
      11: #include "externs.h"
      12:
      13: #ifdef pdp11
      14: #include <sys/file.h>
      15: #include <sys/types.h>
      16:
      17: static int desc = -1;
      18:
      19: writedes()
      20: {
      21:     int compass;
      22:     register char *p;
      23:     register c;
      24:     char buf[BUFSIZ];
      25:
      26:     if (desc < 0)
      27:         desc = open(BATTLESTRINGS, O_RDONLY, 0666);
      28:
      29:     lseek(desc, (off_t) location[position].name, L_SET);
      30:     read(desc, &buf, sizeof(buf));
      31:     printf("\n\t%s\n", &buf);
      32:     if (beenthere[position] < 3) {
      33:         compass = NORTH;
      34:         lseek(desc, (off_t) location[position].desc, L_SET);
      35:         read(desc, &buf, sizeof(buf));
      36:         for (p = buf; c = *p++;)
      37:             if (c != '-' && c != '*' && c != '+')
      38:                 putchar(c);
      39:             else {
      40:                 if (c != '*')
      41:                     printf(truedirec(compass, c));
      42:                 compass++;
      43:             }
      44:     }
      45: }
      46:
      47: printobjs()
      48: {
      49:     register unsigned int *p = location[position].objects;
      50:     register n;
      51:     char buf[BUFSIZ];
      52:
      53:     printf("\n");
      54:     for (n = 0; n < NUMOFOBJECTS; n++)
      55:         if (testbit(p, n) && objdes[n]) {
      56:             lseek(desc, (off_t) objdes[n], L_SET);
      57:             read(desc, &buf, sizeof(buf));
      58:             puts(&buf);
      59:         }
      60: }
      61:
      62: strprt(n)
      63: int n;
      64: {
      65:     char buf[BUFSIZ];
      66:
      67:     lseek(desc, (off_t) objdes[n], L_SET);
      68:     read(desc, &buf, sizeof(buf));
      69:     printf("%s\n", &buf);
      70: }
      71:
      72: #else pdp11
      73: writedes()
      74: {
      75:     int compass;
      76:     register char *p;
      77:     register c;
      78:
      79:     printf("\n\t%s\n", location[position].name);
      80:     if (beenthere[position] < 3) {
      81:         compass = NORTH;
      82:         for (p = location[position].desc; c = *p++;)
      83:             if (c != '-' && c != '*' && c != '+')
      84:                 putchar(c);
      85:             else {
      86:                 if (c != '*')
      87:                     printf(truedirec(compass, c));
      88:                 compass++;
      89:             }
      90:     }
      91: }
      92:
      93: printobjs()
      94: {
      95:     register unsigned int *p = location[position].objects;
      96:     register n;
      97:
      98:     printf("\n");
      99:     for (n = 0; n < NUMOFOBJECTS; n++)
     100:         if (testbit(p, n) && objdes[n])
     101:             puts(objdes[n]);
     102: }
     103: #endif pdp11
     104:
     105: whichway(here)
     106: struct room here;
     107: {
     108:     switch(direction) {
     109:
     110:         case NORTH:
     111:             left = here.west;
     112:             right = here.east;
     113:             ahead = here.north;
     114:             back = here.south;
     115:             break;
     116:
     117:         case SOUTH:
     118:             left = here.east;
     119:             right = here.west;
     120:             ahead = here.south;
     121:             back = here.north;
     122:             break;
     123:
     124:         case EAST:
     125:             left = here.north;
     126:             right = here.south;
     127:             ahead = here.east;
     128:             back = here.west;
     129:             break;
     130:
     131:         case WEST:
     132:             left = here.south;
     133:             right = here.north;
     134:             ahead = here.west;
     135:             back = here.east;
     136:             break;
     137:
     138:     }
     139: }
     140:
     141: char *
     142: truedirec(way, option)
     143: int way;
     144: char option;
     145: {
     146:     switch(way) {
     147:
     148:         case NORTH:
     149:             switch(direction) {
     150:                 case NORTH:
     151:                     return("ahead");
     152:                 case SOUTH:
     153:                     return(option == '+' ? "behind you" : "back");
     154:                 case EAST:
     155:                     return("left");
     156:                 case WEST:
     157:                     return("right");
     158:             }
     159:
     160:         case SOUTH:
     161:             switch(direction) {
     162:                 case NORTH:
     163:                     return(option == '+' ? "behind you" : "back");
     164:                 case SOUTH:
     165:                     return("ahead");
     166:                 case EAST:
     167:                     return("right");
     168:                 case WEST:
     169:                     return("left");
     170:             }
     171:
     172:         case EAST:
     173:             switch(direction) {
     174:                 case NORTH:
     175:                     return("right");
     176:                 case SOUTH:
     177:                     return("left");
     178:                 case EAST:
     179:                     return("ahead");
     180:                 case WEST:
     181:                     return(option == '+' ? "behind you" : "back");
     182:             }
     183:
     184:         case WEST:
     185:             switch(direction) {
     186:                 case NORTH:
     187:                     return("left");
     188:                 case SOUTH:
     189:                     return("right");
     190:                 case EAST:
     191:                     return(option == '+' ? "behind you" : "back");
     192:                 case WEST:
     193:                     return("ahead");
     194:             }
     195:
     196:         default:
     197:             printf("Error: room %d.  More than four directions wanted.", position);
     198:             return("!!");
     199:       }
     200: }
     201:
     202: newway(thisway)
     203: int thisway;
     204: {
     205:     switch(direction){
     206:
     207:         case NORTH:
     208:             switch(thisway){
     209:                 case LEFT:
     210:                     direction = WEST;
     211:                     break;
     212:                 case RIGHT:
     213:                     direction = EAST;
     214:                     break;
     215:                 case BACK:
     216:                     direction = SOUTH;
     217:                     break;
     218:             }
     219:             break;
     220:         case SOUTH:
     221:             switch(thisway){
     222:                 case LEFT:
     223:                     direction = EAST;
     224:                     break;
     225:                 case RIGHT:
     226:                     direction = WEST;
     227:                     break;
     228:                 case BACK:
     229:                     direction = NORTH;
     230:                     break;
     231:             }
     232:             break;
     233:         case EAST:
     234:             switch(thisway){
     235:                 case LEFT:
     236:                     direction = NORTH;
     237:                     break;
     238:                 case RIGHT:
     239:                     direction = SOUTH;
     240:                     break;
     241:                 case BACK:
     242:                     direction = WEST;
     243:                     break;
     244:             }
     245:             break;
     246:         case WEST:
     247:             switch(thisway){
     248:                 case LEFT:
     249:                     direction = SOUTH;
     250:                     break;
     251:                 case RIGHT:
     252:                     direction = NORTH;
     253:                     break;
     254:                 case BACK:
     255:                     direction = EAST;
     256:                     break;
     257:             }
     258:             break;
     259:       }
     260: }

#### Defined functions

newway defined in line 202; used 2 times

- in /usr/src/games/battlestar/com1.c line 20-25(2)

printobjs defined in line 93; used 2 times

- in /usr/src/games/battlestar/battlestar.c line 45
- in /usr/src/games/battlestar/cypher.c line 243

strprt defined in line 62; used 3 times

- in /usr/src/games/battlestar/com1.c line 105, 113, 121

truedirec defined in line 141; used 4 times

- in line 41, 87
- in /usr/src/games/battlestar/com2.c line 121
- in /usr/src/games/battlestar/externs.h line 236

whichway defined in line 105; used 5 times

- in /usr/src/games/battlestar/battlestar.c line 48
- in /usr/src/games/battlestar/com1.c line 26
- in /usr/src/games/battlestar/com2.c line 103
- in /usr/src/games/battlestar/com3.c line 200-205(2)

writedes defined in line 73; used 2 times

- in /usr/src/games/battlestar/battlestar.c line 44
- in /usr/src/games/battlestar/cypher.c line 242

#### Defined variables

desc defined in line 17; used 12 times

- in line 26-35(7), 56-57(2), 67-68(2), 82

sccsid defined in line 8; never used

Last modified: 1987-08-01 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 1711 |