Home | History | Annotate | Line # | Download | only in battlestar
command6.c revision 1.1
      1  1.1  tv /*	$NetBSD: command6.c,v 1.1 2001/10/19 03:06:11 tv Exp $	*/
      2  1.1  tv 
      3  1.1  tv /*
      4  1.1  tv  * Copyright (c) 1983, 1993
      5  1.1  tv  *	The Regents of the University of California.  All rights reserved.
      6  1.1  tv  *
      7  1.1  tv  * Redistribution and use in source and binary forms, with or without
      8  1.1  tv  * modification, are permitted provided that the following conditions
      9  1.1  tv  * are met:
     10  1.1  tv  * 1. Redistributions of source code must retain the above copyright
     11  1.1  tv  *    notice, this list of conditions and the following disclaimer.
     12  1.1  tv  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  tv  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  tv  *    documentation and/or other materials provided with the distribution.
     15  1.1  tv  * 3. All advertising materials mentioning features or use of this software
     16  1.1  tv  *    must display the following acknowledgement:
     17  1.1  tv  *	This product includes software developed by the University of
     18  1.1  tv  *	California, Berkeley and its contributors.
     19  1.1  tv  * 4. Neither the name of the University nor the names of its contributors
     20  1.1  tv  *    may be used to endorse or promote products derived from this software
     21  1.1  tv  *    without specific prior written permission.
     22  1.1  tv  *
     23  1.1  tv  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  1.1  tv  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  1.1  tv  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  1.1  tv  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  1.1  tv  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  1.1  tv  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  1.1  tv  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  1.1  tv  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  1.1  tv  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  1.1  tv  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  1.1  tv  * SUCH DAMAGE.
     34  1.1  tv  */
     35  1.1  tv 
     36  1.1  tv #include <sys/cdefs.h>
     37  1.1  tv #ifndef lint
     38  1.1  tv #if 0
     39  1.1  tv static char sccsid[] = "@(#)com6.c	8.2 (Berkeley) 4/28/95";
     40  1.1  tv #else
     41  1.1  tv __RCSID("$NetBSD: command6.c,v 1.1 2001/10/19 03:06:11 tv Exp $");
     42  1.1  tv #endif
     43  1.1  tv #endif				/* not lint */
     44  1.1  tv 
     45  1.1  tv #include "extern.h"
     46  1.1  tv #include "pathnames.h"
     47  1.1  tv 
     48  1.1  tv int
     49  1.1  tv launch()
     50  1.1  tv {
     51  1.1  tv 	if (testbit(location[position].objects, VIPER) && !notes[CANTLAUNCH]) {
     52  1.1  tv 		if (fuel > 4) {
     53  1.1  tv 			clearbit(location[position].objects, VIPER);
     54  1.1  tv 			position = location[position].up;
     55  1.1  tv 			notes[LAUNCHED] = 1;
     56  1.1  tv 			ourtime++;
     57  1.1  tv 			fuel -= 4;
     58  1.1  tv 			puts("You climb into the viper and prepare for launch.");
     59  1.1  tv 			puts("With a touch of your thumb the turbo engines ignite, thrusting you back into\nyour seat.");
     60  1.1  tv 			return (1);
     61  1.1  tv 		} else
     62  1.1  tv 			puts("Not enough fuel to launch.");
     63  1.1  tv 	} else
     64  1.1  tv 		puts("Can't launch.");
     65  1.1  tv 	return (0);
     66  1.1  tv }
     67  1.1  tv 
     68  1.1  tv int
     69  1.1  tv land()
     70  1.1  tv {
     71  1.1  tv 	if (notes[LAUNCHED] && testbit(location[position].objects, LAND) &&
     72  1.1  tv 	    location[position].down) {
     73  1.1  tv 		notes[LAUNCHED] = 0;
     74  1.1  tv 		position = location[position].down;
     75  1.1  tv 		setbit(location[position].objects, VIPER);
     76  1.1  tv 		fuel -= 2;
     77  1.1  tv 		ourtime++;
     78  1.1  tv 		puts("You are down.");
     79  1.1  tv 		return (1);
     80  1.1  tv 	} else
     81  1.1  tv 		puts("You can't land here.");
     82  1.1  tv 	return (0);
     83  1.1  tv }
     84  1.1  tv 
     85  1.1  tv void
     86  1.1  tv die()
     87  1.1  tv {				/* endgame */
     88  1.1  tv 	printf("bye.\nYour rating was %s.\n", rate());
     89  1.1  tv 	post(' ');
     90  1.1  tv 	exit(0);
     91  1.1  tv }
     92  1.1  tv 
     93  1.1  tv void
     94  1.1  tv diesig(dummy)
     95  1.1  tv 	int     dummy __attribute__((__unused__));
     96  1.1  tv {
     97  1.1  tv 	die();
     98  1.1  tv }
     99  1.1  tv 
    100  1.1  tv void
    101  1.1  tv live()
    102  1.1  tv {
    103  1.1  tv 	puts("\nYou win!");
    104  1.1  tv 	post('!');
    105  1.1  tv 	exit(0);
    106  1.1  tv }
    107  1.1  tv 
    108  1.1  tv static FILE *score_fp;
    109  1.1  tv 
    110  1.1  tv void
    111  1.1  tv open_score_file()
    112  1.1  tv {
    113  1.1  tv 	score_fp = fopen(_PATH_SCORE, "a");
    114  1.1  tv 	if (score_fp == NULL)
    115  1.1  tv 		warn("open %s for append", _PATH_SCORE);
    116  1.1  tv 	if (score_fp != NULL && fileno(score_fp) < 3)
    117  1.1  tv 		exit(1);
    118  1.1  tv }
    119  1.1  tv 
    120  1.1  tv void
    121  1.1  tv post(ch)
    122  1.1  tv 	char    ch;
    123  1.1  tv {
    124  1.1  tv 	time_t tv;
    125  1.1  tv 	char   *date;
    126  1.1  tv 	sigset_t sigset, osigset;
    127  1.1  tv 
    128  1.1  tv 	sigemptyset(&sigset);
    129  1.1  tv 	sigaddset(&sigset, SIGINT);
    130  1.1  tv 	sigprocmask(SIG_BLOCK, &sigset, &osigset);
    131  1.1  tv 	tv = time(NULL);
    132  1.1  tv 	date = ctime(&tv);
    133  1.1  tv 	date[24] = '\0';
    134  1.1  tv 	if (score_fp != NULL) {
    135  1.1  tv 		fprintf(score_fp, "%s  %8s  %c%20s", date, username, ch, rate());
    136  1.1  tv 		if (wiz)
    137  1.1  tv 			fprintf(score_fp, "   wizard\n");
    138  1.1  tv 		else
    139  1.1  tv 			if (tempwiz)
    140  1.1  tv 				fprintf(score_fp, "   WIZARD!\n");
    141  1.1  tv 			else
    142  1.1  tv 				fprintf(score_fp, "\n");
    143  1.1  tv 	}
    144  1.1  tv 	sigprocmask(SIG_SETMASK, &osigset, (sigset_t *) 0);
    145  1.1  tv }
    146  1.1  tv 
    147  1.1  tv const char   *
    148  1.1  tv rate()
    149  1.1  tv {
    150  1.1  tv 	int     score;
    151  1.1  tv 
    152  1.1  tv 	score = max(max(pleasure, power), ego);
    153  1.1  tv 	if (score == pleasure) {
    154  1.1  tv 		if (score < 5)
    155  1.1  tv 			return ("novice");
    156  1.1  tv 		else if (score < 20)
    157  1.1  tv 			return ("junior voyeur");
    158  1.1  tv 		else if (score < 35)
    159  1.1  tv 			return ("Don Juan");
    160  1.1  tv 		else
    161  1.1  tv 			return ("Marquis De Sade");
    162  1.1  tv 	} else if (score == power) {
    163  1.1  tv 		if (score < 5)
    164  1.1  tv 			return ("serf");
    165  1.1  tv 		else if (score < 8)
    166  1.1  tv 			return ("Samurai");
    167  1.1  tv 		else if (score < 13)
    168  1.1  tv 			return ("Klingon");
    169  1.1  tv 		else if (score < 22)
    170  1.1  tv 			return ("Darth Vader");
    171  1.1  tv 		else
    172  1.1  tv 			return ("Sauron the Great");
    173  1.1  tv 	} else {
    174  1.1  tv 		if (score < 5)
    175  1.1  tv 			return ("Polyanna");
    176  1.1  tv 		else if (score < 10)
    177  1.1  tv 			return ("philanthropist");
    178  1.1  tv 		else if (score < 20)
    179  1.1  tv 			return ("Tattoo");
    180  1.1  tv 		else
    181  1.1  tv 			return ("Mr. Roarke");
    182  1.1  tv 	}
    183  1.1  tv }
    184  1.1  tv 
    185  1.1  tv int
    186  1.1  tv drive()
    187  1.1  tv {
    188  1.1  tv 	if (testbit(location[position].objects, CAR)) {
    189  1.1  tv 		puts("You hop in the car and turn the key.  There is a perceptible grating noise,");
    190  1.1  tv 		puts("and an explosion knocks you unconscious...");
    191  1.1  tv 		clearbit(location[position].objects, CAR);
    192  1.1  tv 		setbit(location[position].objects, CRASH);
    193  1.1  tv 		injuries[5] = injuries[6] = injuries[7] = injuries[8] = 1;
    194  1.1  tv 		ourtime += 15;
    195  1.1  tv 		zzz();
    196  1.1  tv 		return (0);
    197  1.1  tv 	} else
    198  1.1  tv 		puts("There is nothing to drive here.");
    199  1.1  tv 	return (-1);
    200  1.1  tv }
    201  1.1  tv 
    202  1.1  tv int
    203  1.1  tv ride()
    204  1.1  tv {
    205  1.1  tv 	if (testbit(location[position].objects, HORSE)) {
    206  1.1  tv 		puts("You climb onto the stallion and kick it in the guts.  The stupid steed launches");
    207  1.1  tv 		puts("forward through bush and fern.  You are thrown and the horse gallops off.");
    208  1.1  tv 		clearbit(location[position].objects, HORSE);
    209  1.1  tv 		while (!(position = rnd(NUMOFROOMS + 1)) || !OUTSIDE || !beenthere[position] || location[position].flyhere)
    210  1.1  tv 			continue;
    211  1.1  tv 		setbit(location[position].objects, HORSE);
    212  1.1  tv 		if (location[position].north)
    213  1.1  tv 			position = location[position].north;
    214  1.1  tv 		else if (location[position].south)
    215  1.1  tv 			position = location[position].south;
    216  1.1  tv 		else if (location[position].east)
    217  1.1  tv 			position = location[position].east;
    218  1.1  tv 		else
    219  1.1  tv 			position = location[position].west;
    220  1.1  tv 		return (0);
    221  1.1  tv 	} else
    222  1.1  tv 		puts("There is no horse here.");
    223  1.1  tv 	return (-1);
    224  1.1  tv }
    225  1.1  tv 
    226  1.1  tv void
    227  1.1  tv light()
    228  1.1  tv {				/* synonyms = {strike, smoke} *//* for
    229  1.1  tv 				 * matches, cigars */
    230  1.1  tv 	if (testbit(inven, MATCHES) && matchcount) {
    231  1.1  tv 		puts("Your match splutters to life.");
    232  1.1  tv 		ourtime++;
    233  1.1  tv 		matchlight = 1;
    234  1.1  tv 		matchcount--;
    235  1.1  tv 		if (position == 217) {
    236  1.1  tv 			puts("The whole bungalow explodes with an intense blast.");
    237  1.1  tv 			die();
    238  1.1  tv 		}
    239  1.1  tv 	} else
    240  1.1  tv 		puts("You're out of matches.");
    241  1.1  tv }
    242  1.1  tv 
    243  1.1  tv void
    244  1.1  tv dooropen()
    245  1.1  tv {				/* synonyms = {open, unlock} */
    246  1.1  tv 	wordnumber++;
    247  1.1  tv 	if (wordnumber <= wordcount && wordtype[wordnumber] == NOUNS
    248  1.1  tv 	    && wordvalue[wordnumber] == DOOR) {
    249  1.1  tv 		switch(position) {
    250  1.1  tv 		case 189:
    251  1.1  tv 		case 231:
    252  1.1  tv 			if (location[189].north == 231)
    253  1.1  tv 				puts("The door is already open.");
    254  1.1  tv 			else
    255  1.1  tv 				puts("The door does not budge.");
    256  1.1  tv 			break;
    257  1.1  tv 		case 30:
    258  1.1  tv 			if (location[30].west == 25)
    259  1.1  tv 				puts("The door is gone.");
    260  1.1  tv 			else
    261  1.1  tv 				puts("The door is locked tight.");
    262  1.1  tv 			break;
    263  1.1  tv 		case 31:
    264  1.1  tv 			puts("That's one immovable door.");
    265  1.1  tv 			break;
    266  1.1  tv 		case 20:
    267  1.1  tv 			puts("The door is already ajar.");
    268  1.1  tv 			break;
    269  1.1  tv 		default:
    270  1.1  tv 			puts("What door?");
    271  1.1  tv 		}
    272  1.1  tv 	} else
    273  1.1  tv 		puts("That doesn't open.");
    274  1.1  tv }
    275