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