Home | History | Annotate | Line # | Download | only in battlestar
cypher.c revision 1.6
      1  1.6  lukem /*	$NetBSD: cypher.c,v 1.6 1997/10/11 02:07:11 lukem 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[] = "@(#)cypher.c	8.2 (Berkeley) 4/28/95";
     40  1.3    cgd #else
     41  1.6  lukem __RCSID("$NetBSD: cypher.c,v 1.6 1997/10/11 02:07:11 lukem 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 int
     48  1.1    cgd cypher()
     49  1.1    cgd {
     50  1.6  lukem 	int     n;
     51  1.6  lukem 	int     junk;
     52  1.6  lukem 	int     lflag = -1;
     53  1.6  lukem 	char    buffer[10];
     54  1.1    cgd 
     55  1.1    cgd 	while (wordtype[wordnumber] == ADJS)
     56  1.1    cgd 		wordnumber++;
     57  1.1    cgd 	while (wordnumber <= wordcount) {
     58  1.6  lukem 		switch (wordvalue[wordnumber]) {
     59  1.1    cgd 
     60  1.6  lukem 		case UP:
     61  1.6  lukem 			if (location[position].access || wiz || tempwiz) {
     62  1.6  lukem 				if (!location[position].access)
     63  1.6  lukem 					puts("Zap!  A gust of wind lifts you up.");
     64  1.6  lukem 				if (!move(location[position].up, AHEAD))
     65  1.6  lukem 					return (-1);
     66  1.6  lukem 			} else {
     67  1.6  lukem 				puts("There is no way up");
     68  1.6  lukem 				return (-1);
     69  1.6  lukem 			}
     70  1.6  lukem 			lflag = 0;
     71  1.6  lukem 			break;
     72  1.6  lukem 
     73  1.6  lukem 		case DOWN:
     74  1.6  lukem 			if (!move(location[position].down, AHEAD))
     75  1.6  lukem 				return (-1);
     76  1.6  lukem 			lflag = 0;
     77  1.6  lukem 			break;
     78  1.6  lukem 
     79  1.6  lukem 		case LEFT:
     80  1.6  lukem 			if (!move(left, LEFT))
     81  1.6  lukem 				return (-1);
     82  1.6  lukem 			lflag = 0;
     83  1.6  lukem 			break;
     84  1.6  lukem 
     85  1.6  lukem 		case RIGHT:
     86  1.6  lukem 			if (!move(right, RIGHT))
     87  1.6  lukem 				return (-1);
     88  1.6  lukem 			lflag = 0;
     89  1.6  lukem 			break;
     90  1.6  lukem 
     91  1.6  lukem 		case AHEAD:
     92  1.6  lukem 			if (!move(ahead, AHEAD))
     93  1.6  lukem 				return (-1);
     94  1.6  lukem 			lflag = 0;
     95  1.6  lukem 			break;
     96  1.6  lukem 
     97  1.6  lukem 		case BACK:
     98  1.6  lukem 			if (!move(back, BACK))
     99  1.6  lukem 				return (-1);
    100  1.6  lukem 			lflag = 0;
    101  1.6  lukem 			break;
    102  1.6  lukem 
    103  1.6  lukem 		case SHOOT:
    104  1.6  lukem 			if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) {
    105  1.6  lukem 				for (n = 0; n < NUMOFOBJECTS; n++)
    106  1.6  lukem 					if (testbit(location[position].objects, n) && *objsht[n]) {
    107  1.6  lukem 						wordvalue[wordnumber + 1] = n;
    108  1.6  lukem 						wordnumber = shoot();
    109  1.6  lukem 					}
    110  1.1    cgd 				wordnumber++;
    111  1.1    cgd 				wordnumber++;
    112  1.6  lukem 			} else
    113  1.6  lukem 				shoot();
    114  1.6  lukem 			break;
    115  1.6  lukem 
    116  1.6  lukem 		case TAKE:
    117  1.6  lukem 			if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) {
    118  1.6  lukem 				for (n = 0; n < NUMOFOBJECTS; n++)
    119  1.6  lukem 					if (testbit(location[position].objects, n) && *objsht[n]) {
    120  1.6  lukem 						wordvalue[wordnumber + 1] = n;
    121  1.6  lukem 						wordnumber = take(location[position].objects);
    122  1.6  lukem 					}
    123  1.1    cgd 				wordnumber++;
    124  1.1    cgd 				wordnumber++;
    125  1.6  lukem 			} else
    126  1.6  lukem 				take(location[position].objects);
    127  1.6  lukem 			break;
    128  1.6  lukem 
    129  1.6  lukem 		case DROP:
    130  1.6  lukem 
    131  1.6  lukem 			if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) {
    132  1.6  lukem 				for (n = 0; n < NUMOFOBJECTS; n++)
    133  1.6  lukem 					if (testbit(inven, n)) {
    134  1.6  lukem 						wordvalue[wordnumber + 1] = n;
    135  1.6  lukem 						wordnumber = drop("Dropped");
    136  1.6  lukem 					}
    137  1.1    cgd 				wordnumber++;
    138  1.1    cgd 				wordnumber++;
    139  1.6  lukem 			} else
    140  1.6  lukem 				drop("Dropped");
    141  1.6  lukem 			break;
    142  1.6  lukem 
    143  1.6  lukem 
    144  1.6  lukem 		case KICK:
    145  1.6  lukem 		case THROW:
    146  1.6  lukem 			if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) {
    147  1.6  lukem 				for (n = 0; n < NUMOFOBJECTS; n++)
    148  1.6  lukem 					if (testbit(inven, n) ||
    149  1.6  lukem 					    (testbit(location[position].objects, n) && *objsht[n])) {
    150  1.6  lukem 						wordvalue[wordnumber + 1] = n;
    151  1.6  lukem 						wordnumber = throw(wordvalue[wordnumber] == KICK ? "Kicked" : "Thrown");
    152  1.6  lukem 					}
    153  1.6  lukem 				wordnumber += 2;
    154  1.6  lukem 			} else
    155  1.6  lukem 				throw(wordvalue[wordnumber] == KICK ? "Kicked" : "Thrown");
    156  1.6  lukem 			break;
    157  1.6  lukem 
    158  1.6  lukem 		case TAKEOFF:
    159  1.6  lukem 			if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) {
    160  1.6  lukem 				for (n = 0; n < NUMOFOBJECTS; n++)
    161  1.6  lukem 					if (testbit(wear, n)) {
    162  1.6  lukem 						wordvalue[wordnumber + 1] = n;
    163  1.6  lukem 						wordnumber = takeoff();
    164  1.6  lukem 					}
    165  1.6  lukem 				wordnumber += 2;
    166  1.6  lukem 			} else
    167  1.6  lukem 				takeoff();
    168  1.6  lukem 			break;
    169  1.1    cgd 
    170  1.1    cgd 
    171  1.6  lukem 		case DRAW:
    172  1.6  lukem 
    173  1.6  lukem 			if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) {
    174  1.6  lukem 				for (n = 0; n < NUMOFOBJECTS; n++)
    175  1.6  lukem 					if (testbit(wear, n)) {
    176  1.6  lukem 						wordvalue[wordnumber + 1] = n;
    177  1.6  lukem 						wordnumber = draw();
    178  1.6  lukem 					}
    179  1.6  lukem 				wordnumber += 2;
    180  1.6  lukem 			} else
    181  1.6  lukem 				draw();
    182  1.6  lukem 			break;
    183  1.1    cgd 
    184  1.1    cgd 
    185  1.6  lukem 		case PUTON:
    186  1.6  lukem 
    187  1.6  lukem 			if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) {
    188  1.6  lukem 				for (n = 0; n < NUMOFOBJECTS; n++)
    189  1.6  lukem 					if (testbit(location[position].objects, n) && *objsht[n]) {
    190  1.6  lukem 						wordvalue[wordnumber + 1] = n;
    191  1.6  lukem 						wordnumber = puton();
    192  1.6  lukem 					}
    193  1.6  lukem 				wordnumber += 2;
    194  1.6  lukem 			} else
    195  1.6  lukem 				puton();
    196  1.6  lukem 			break;
    197  1.6  lukem 
    198  1.6  lukem 		case WEARIT:
    199  1.6  lukem 
    200  1.6  lukem 			if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) {
    201  1.6  lukem 				for (n = 0; n < NUMOFOBJECTS; n++)
    202  1.6  lukem 					if (testbit(inven, n)) {
    203  1.6  lukem 						wordvalue[wordnumber + 1] = n;
    204  1.6  lukem 						wordnumber = wearit();
    205  1.6  lukem 					}
    206  1.6  lukem 				wordnumber += 2;
    207  1.6  lukem 			} else
    208  1.6  lukem 				wearit();
    209  1.6  lukem 			break;
    210  1.1    cgd 
    211  1.1    cgd 
    212  1.6  lukem 		case EAT:
    213  1.6  lukem 
    214  1.6  lukem 			if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) {
    215  1.6  lukem 				for (n = 0; n < NUMOFOBJECTS; n++)
    216  1.6  lukem 					if (testbit(inven, n)) {
    217  1.6  lukem 						wordvalue[wordnumber + 1] = n;
    218  1.6  lukem 						wordnumber = eat();
    219  1.1    cgd 					}
    220  1.6  lukem 				wordnumber += 2;
    221  1.6  lukem 			} else
    222  1.6  lukem 				eat();
    223  1.6  lukem 			break;
    224  1.6  lukem 
    225  1.6  lukem 
    226  1.6  lukem 		case PUT:
    227  1.6  lukem 			put();
    228  1.6  lukem 			break;
    229  1.6  lukem 
    230  1.6  lukem 
    231  1.6  lukem 		case INVEN:
    232  1.6  lukem 			if (ucard(inven)) {
    233  1.6  lukem 				puts("You are holding:\n");
    234  1.6  lukem 				for (n = 0; n < NUMOFOBJECTS; n++)
    235  1.6  lukem 					if (testbit(inven, n))
    236  1.6  lukem 						printf("\t%s\n", objsht[n]);
    237  1.6  lukem 				printf("\n= %d kilogram%s (%d%%)\n", carrying, (carrying == 1 ? "." : "s."), (WEIGHT ? carrying * 100 / WEIGHT : -1));
    238  1.6  lukem 				printf("Your arms are %d%% full.\n", encumber * 100 / CUMBER);
    239  1.6  lukem 			} else
    240  1.6  lukem 				puts("You aren't carrying anything.");
    241  1.6  lukem 
    242  1.6  lukem 			if (ucard(wear)) {
    243  1.6  lukem 				puts("\nYou are wearing:\n");
    244  1.6  lukem 				for (n = 0; n < NUMOFOBJECTS; n++)
    245  1.6  lukem 					if (testbit(wear, n))
    246  1.6  lukem 						printf("\t%s\n", objsht[n]);
    247  1.6  lukem 			} else
    248  1.6  lukem 				puts("\nYou are stark naked.");
    249  1.6  lukem 			if (card(injuries, NUMOFINJURIES)) {
    250  1.6  lukem 				puts("\nYou have suffered:\n");
    251  1.6  lukem 				for (n = 0; n < NUMOFINJURIES; n++)
    252  1.6  lukem 					if (injuries[n])
    253  1.6  lukem 						printf("\t%s\n", ouch[n]);
    254  1.6  lukem 				printf("\nYou can still carry up to %d kilogram%s\n", WEIGHT, (WEIGHT == 1 ? "." : "s."));
    255  1.6  lukem 			} else
    256  1.6  lukem 				puts("\nYou are in perfect health.");
    257  1.6  lukem 			break;
    258  1.6  lukem 
    259  1.6  lukem 		case USE:
    260  1.6  lukem 			lflag = use();
    261  1.6  lukem 			break;
    262  1.6  lukem 
    263  1.6  lukem 		case LOOK:
    264  1.6  lukem 			if (!notes[CANTSEE] || testbit(inven, LAMPON) ||
    265  1.6  lukem 			    testbit(location[position].objects, LAMPON)
    266  1.6  lukem 			    || matchlight) {
    267  1.6  lukem 				beenthere[position] = 2;
    268  1.6  lukem 				writedes();
    269  1.6  lukem 				printobjs();
    270  1.6  lukem 				if (matchlight) {
    271  1.6  lukem 					puts("\nYour match splutters out.");
    272  1.6  lukem 					matchlight = 0;
    273  1.6  lukem 				}
    274  1.6  lukem 			} else
    275  1.6  lukem 				puts("I can't see anything.");
    276  1.6  lukem 			return (-1);
    277  1.6  lukem 			break;
    278  1.1    cgd 
    279  1.6  lukem 		case SU:
    280  1.6  lukem 			if (wiz || tempwiz) {
    281  1.1    cgd 				printf("\nRoom (was %d) = ", position);
    282  1.6  lukem 				fgets(buffer, 10, stdin);
    283  1.1    cgd 				if (*buffer != '\n')
    284  1.6  lukem 					sscanf(buffer, "%d", &position);
    285  1.5  lukem 				printf("Time (was %d) = ", ourtime);
    286  1.6  lukem 				fgets(buffer, 10, stdin);
    287  1.1    cgd 				if (*buffer != '\n')
    288  1.6  lukem 					sscanf(buffer, "%d", &ourtime);
    289  1.6  lukem 				printf("Fuel (was %d) = ", fuel);
    290  1.6  lukem 				fgets(buffer, 10, stdin);
    291  1.1    cgd 				if (*buffer != '\n')
    292  1.6  lukem 					sscanf(buffer, "%d", &fuel);
    293  1.6  lukem 				printf("Torps (was %d) = ", torps);
    294  1.6  lukem 				fgets(buffer, 10, stdin);
    295  1.1    cgd 				if (*buffer != '\n')
    296  1.6  lukem 					sscanf(buffer, "%d", &torps);
    297  1.6  lukem 				printf("CUMBER (was %d) = ", CUMBER);
    298  1.6  lukem 				fgets(buffer, 10, stdin);
    299  1.1    cgd 				if (*buffer != '\n')
    300  1.6  lukem 					sscanf(buffer, "%d", &CUMBER);
    301  1.6  lukem 				printf("WEIGHT (was %d) = ", WEIGHT);
    302  1.6  lukem 				fgets(buffer, 10, stdin);
    303  1.1    cgd 				if (*buffer != '\n')
    304  1.6  lukem 					sscanf(buffer, "%d", &WEIGHT);
    305  1.5  lukem 				printf("Clock (was %d) = ", ourclock);
    306  1.6  lukem 				fgets(buffer, 10, stdin);
    307  1.1    cgd 				if (*buffer != '\n')
    308  1.6  lukem 					sscanf(buffer, "%d", &ourclock);
    309  1.6  lukem 				printf("Wizard (was %d, %d) = ", wiz, tempwiz);
    310  1.6  lukem 				fgets(buffer, 10, stdin);
    311  1.6  lukem 				if (*buffer != '\n') {
    312  1.6  lukem 					sscanf(buffer, "%d", &junk);
    313  1.1    cgd 					if (!junk)
    314  1.1    cgd 						tempwiz = wiz = 0;
    315  1.1    cgd 				}
    316  1.1    cgd 				printf("\nDONE.\n");
    317  1.6  lukem 				return (0);
    318  1.6  lukem 			} else
    319  1.6  lukem 				puts("You aren't a wizard.");
    320  1.6  lukem 			break;
    321  1.6  lukem 
    322  1.6  lukem 		case SCORE:
    323  1.6  lukem 			printf("\tPLEASURE\tPOWER\t\tEGO\n");
    324  1.6  lukem 			printf("\t%3d\t\t%3d\t\t%3d\n\n", pleasure, power, ego);
    325  1.6  lukem 			printf("This gives you the rating of %s in %d turns.\n", rate(), ourtime);
    326  1.6  lukem 			printf("You have visited %d out of %d rooms this run (%d%%).\n", card(beenthere, NUMOFROOMS), NUMOFROOMS, card(beenthere, NUMOFROOMS) * 100 / NUMOFROOMS);
    327  1.6  lukem 			break;
    328  1.6  lukem 
    329  1.6  lukem 		case KNIFE:
    330  1.6  lukem 		case KILL:
    331  1.6  lukem 			murder();
    332  1.6  lukem 			break;
    333  1.6  lukem 
    334  1.6  lukem 		case UNDRESS:
    335  1.6  lukem 		case RAVAGE:
    336  1.6  lukem 			ravage();
    337  1.6  lukem 			break;
    338  1.6  lukem 
    339  1.6  lukem 		case SAVE:
    340  1.6  lukem 			save();
    341  1.6  lukem 			break;
    342  1.6  lukem 
    343  1.6  lukem 		case FOLLOW:
    344  1.6  lukem 			lflag = follow();
    345  1.6  lukem 			break;
    346  1.6  lukem 
    347  1.6  lukem 		case GIVE:
    348  1.6  lukem 			give();
    349  1.6  lukem 			break;
    350  1.6  lukem 
    351  1.6  lukem 		case KISS:
    352  1.6  lukem 			kiss();
    353  1.6  lukem 			break;
    354  1.6  lukem 
    355  1.6  lukem 		case LOVE:
    356  1.6  lukem 			love();
    357  1.6  lukem 			break;
    358  1.6  lukem 
    359  1.6  lukem 		case RIDE:
    360  1.6  lukem 			lflag = ride();
    361  1.6  lukem 			break;
    362  1.6  lukem 
    363  1.6  lukem 		case DRIVE:
    364  1.6  lukem 			lflag = drive();
    365  1.6  lukem 			break;
    366  1.6  lukem 
    367  1.6  lukem 		case LIGHT:
    368  1.6  lukem 			light();
    369  1.6  lukem 			break;
    370  1.6  lukem 
    371  1.6  lukem 		case LAUNCH:
    372  1.6  lukem 			if (!launch())
    373  1.6  lukem 				return (-1);
    374  1.6  lukem 			else
    375  1.6  lukem 				lflag = 0;
    376  1.6  lukem 			break;
    377  1.6  lukem 
    378  1.6  lukem 		case LANDIT:
    379  1.6  lukem 			if (!land())
    380  1.6  lukem 				return (-1);
    381  1.6  lukem 			else
    382  1.6  lukem 				lflag = 0;
    383  1.6  lukem 			break;
    384  1.6  lukem 
    385  1.6  lukem 		case TIME:
    386  1.6  lukem 			chime();
    387  1.6  lukem 			break;
    388  1.6  lukem 
    389  1.6  lukem 		case SLEEP:
    390  1.6  lukem 			zzz();
    391  1.6  lukem 			break;
    392  1.6  lukem 
    393  1.6  lukem 		case DIG:
    394  1.6  lukem 			dig();
    395  1.6  lukem 			break;
    396  1.6  lukem 
    397  1.6  lukem 		case JUMP:
    398  1.6  lukem 			lflag = jump();
    399  1.6  lukem 			break;
    400  1.6  lukem 
    401  1.6  lukem 		case BURY:
    402  1.6  lukem 			bury();
    403  1.6  lukem 			break;
    404  1.6  lukem 
    405  1.6  lukem 		case SWIM:
    406  1.6  lukem 			puts("Surf's up!");
    407  1.6  lukem 			break;
    408  1.6  lukem 
    409  1.6  lukem 		case DRINK:
    410  1.6  lukem 			drink();
    411  1.6  lukem 			break;
    412  1.6  lukem 
    413  1.6  lukem 		case QUIT:
    414  1.6  lukem 			die();
    415  1.6  lukem 
    416  1.6  lukem 		default:
    417  1.6  lukem 			puts("How's that?");
    418  1.6  lukem 			return (-1);
    419  1.6  lukem 			break;
    420  1.6  lukem 
    421  1.1    cgd 
    422  1.1    cgd 		}
    423  1.1    cgd 		if (wordnumber < wordcount && *words[wordnumber++] == ',')
    424  1.1    cgd 			continue;
    425  1.6  lukem 		else
    426  1.6  lukem 			return (lflag);
    427  1.6  lukem 	}
    428  1.6  lukem 	return (lflag);
    429  1.1    cgd }
    430