xref: /csrg-svn/games/battlestar/com7.c (revision 69064)
118725Sedward /*
260750Sbostic  * Copyright (c) 1983, 1993
360750Sbostic  *	The Regents of the University of California.  All rights reserved.
434234Sbostic  *
542567Sbostic  * %sccs.include.redist.c%
618725Sedward  */
718725Sedward 
817381Sedward #ifndef lint
9*69064Sbostic static char sccsid[] = "@(#)com7.c	8.2 (Berkeley) 04/28/95";
1034234Sbostic #endif /* not lint */
1117381Sedward 
12*69064Sbostic #include "extern.h"
1317381Sedward 
fight(enemy,strength)1417381Sedward fight(enemy,strength)
1517381Sedward int enemy,strength;
1617381Sedward {
1717381Sedward 	int lifeline = 0;
1817381Sedward 	int hurt;
1917381Sedward 	char auxbuf[LINELENGTH];
2017381Sedward 	char *next;
2117381Sedward 	int i;
2217381Sedward 	int exhaustion;
2317381Sedward 
2417381Sedward fighton:
2517381Sedward 	time++;
2617381Sedward 	snooze -= 5;
2717381Sedward 	if (snooze > time)
2817381Sedward 		exhaustion = CYCLE/(snooze - time);
2917381Sedward 	else {
3017441Sedward 		puts("You collapse exhausted, and he pulverizes your skull.");
3117381Sedward 		die();
3217381Sedward 	}
3317381Sedward 	if (snooze - time < 20)
3417441Sedward 		puts("You look tired! I hope you're able to fight.");
3517381Sedward 	next = getcom(auxbuf, LINELENGTH, "<fight!>-: ", 0);
3617381Sedward 	for (i=0; next && i < 10; i++)
3717381Sedward 		next = getword(next, words[i], -1);
3817381Sedward 	parse();
3917381Sedward 	switch(wordvalue[wordnumber]){
4017381Sedward 
4117381Sedward 		case KILL:
4217381Sedward 		case SMITE:
4317381Sedward 			if (testbit(inven,TWO_HANDED))
4417381Sedward 				hurt = rnd(70) - 2 * card(injuries,NUMOFINJURIES) - ucard(wear) - exhaustion;
4517381Sedward 			else if (testbit(inven,SWORD) || testbit(inven, BROAD))
4617381Sedward 				hurt = rnd(50)%(WEIGHT-carrying)-card(injuries,NUMOFINJURIES)-encumber - exhaustion;
4717381Sedward 			else if (testbit(inven,KNIFE) || testbit(inven,MALLET) || testbit(inven,CHAIN) || testbit(inven,MACE) || testbit(inven,HALBERD))
4817381Sedward 				hurt = rnd(15) - card(injuries,NUMOFINJURIES) - exhaustion;
4917381Sedward 			else
5017381Sedward 				hurt = rnd(7) - encumber;
5117381Sedward 			if (hurt < 5)
5217381Sedward 				switch(rnd(3)){
5317381Sedward 
5417381Sedward 					case 0:
5517381Sedward 						puts("You swung wide and missed.");
5617381Sedward 						break;
5717381Sedward 					case 1:
5817381Sedward 						puts("He checked your blow. CLASH! CLANG!");
5917381Sedward 						break;
6017381Sedward 					case 2:
6117381Sedward 						puts("His filthy tunic hangs by one less thread.");
6217381Sedward 						break;
6317381Sedward 				}
6417381Sedward 			else if (hurt < 10){
6517381Sedward 				switch(rnd(3)){
6617381Sedward 					case 0:
6717381Sedward 						puts("He's bleeding.");
6817381Sedward 						break;
6917381Sedward 					case 1:
7017381Sedward 						puts("A trickle of blood runs down his face.");
7117381Sedward 						break;
7217381Sedward 					case 2:
7317381Sedward 						puts("A huge purple bruise is forming on the side of his face.");
7417381Sedward 						break;
7517381Sedward 				}
7617381Sedward 				lifeline++;
7717381Sedward 			}
7817381Sedward 			else if (hurt < 20){
7917381Sedward 				switch(rnd(3)){
8017381Sedward 					case 0:
8117381Sedward 						puts("He staggers back quavering.");
8217381Sedward 						break;
8317381Sedward 					case 1:
8417381Sedward 						puts("He jumps back with his hand over the wound.");
8517381Sedward 						break;
8617381Sedward 					case 2:
8717381Sedward 						puts("His shirt falls open with a swath across the chest.");
8817381Sedward 						break;
8917381Sedward 				}
9017381Sedward 				lifeline += 5;
9117381Sedward 			}
9217381Sedward 			else if (hurt < 30){
9317381Sedward 				switch(rnd(3)){
9417381Sedward 					case 0:
9517381Sedward 						printf("A bloody gash opens up on his %s side.\n",(rnd(2) ? "left" : "right"));
9617381Sedward 						break;
9717381Sedward 					case 1:
9817381Sedward 						puts("The steel bites home and scrapes along his ribs.");
9917381Sedward 						break;
10017381Sedward 					case 2:
10117441Sedward 						puts("You pierce him, and his breath hisses through clenched teeth.");
10217381Sedward 						break;
10317381Sedward 				}
10417381Sedward 				lifeline += 10;
10517381Sedward 			}
10617381Sedward 			else if (hurt < 40){
10717381Sedward 				switch(rnd(3)){
10817381Sedward 					case 0:
10917381Sedward 						puts("You smite him to the ground.");
11017381Sedward 						if (strength - lifeline > 20)
11117381Sedward 							puts("But in a flurry of steel he regains his feet!");
11217381Sedward 						break;
11317381Sedward 					case 1:
11417381Sedward 						puts("The force of your blow sends him to his knees.");
11517381Sedward 						puts("His arm swings lifeless at his side.");
11617381Sedward 						break;
11717381Sedward 					case 2:
11817381Sedward 						puts("Clutching his blood drenched shirt, he collapses stunned.");
11917381Sedward 						break;
12017381Sedward 				}
12117381Sedward 				lifeline += 20;
12217381Sedward 			}
12317381Sedward 			else {
12417381Sedward 				switch(rnd(3)){
12517381Sedward 					case 0:
12617381Sedward 						puts("His ribs crack under your powerful swing, flooding his lungs with blood.");
12717381Sedward 						break;
12817381Sedward 					case 1:
12917381Sedward 						puts("You shatter his upheld arm in a spray of blood.  The blade continues deep");
13017381Sedward 						puts("into his back, severing the spinal cord.");
13117381Sedward 						lifeline += 25;
13217381Sedward 						break;
13317381Sedward 					case 2:
13417381Sedward 						puts("With a mighty lunge the steel slides in, and gasping, he falls to the ground.");
13517381Sedward 						lifeline += 25;
13617381Sedward 						break;
13717381Sedward 				}
13817381Sedward 				lifeline += 30;
13917381Sedward 			}
14017381Sedward 			break;
14117381Sedward 
14217381Sedward 		case BACK:
14317381Sedward 			if (enemy == DARK && lifeline > strength * 0.33){
14417381Sedward 				puts("He throws you back against the rock and pummels your face.");
14517381Sedward 				if (testbit(inven,AMULET) || testbit(wear,AMULET)){
14617381Sedward 					printf("Lifting the amulet from you, ");
14717381Sedward 					if (testbit(inven,MEDALION) || testbit(wear,MEDALION)){
14817381Sedward 						puts("his power grows and the walls of\nthe earth tremble.");
14917381Sedward 						puts("When he touches the medallion, your chest explodes and the foundations of the\nearth collapse.");
15017381Sedward 						puts("The planet is consumed by darkness.");
15117381Sedward 						die();
15217381Sedward 					}
15317381Sedward 					if (testbit(inven,AMULET)){
15417381Sedward 						clearbit(inven,AMULET);
15517381Sedward 						carrying -= objwt[AMULET];
15617381Sedward 						encumber -= objcumber[AMULET];
15717381Sedward 					}
15817381Sedward 					else
15917381Sedward 						clearbit(wear,AMULET);
16017381Sedward 					puts("he flees down the dark caverns.");
16117381Sedward 					clearbit(location[position].objects,DARK);
16217381Sedward 					injuries[SKULL] = 1;
16317381Sedward 					followfight = time;
16417381Sedward 					return (0);
16517381Sedward 				}
16617381Sedward 				else{
16717381Sedward 					puts("I'm afraid you have been killed.");
16817381Sedward 					die();
16917381Sedward 				}
17017381Sedward 			}
17117381Sedward 			else{
17217381Sedward 				puts("You escape stunned and disoriented from the fight.");
17317381Sedward 				puts("A victorious bellow echoes from the battlescene.");
17417381Sedward 				if (back && position != back)
17517381Sedward 					move(back,BACK);
17617381Sedward 				else if (ahead &&position != ahead)
17717381Sedward 					move(ahead,AHEAD);
17817381Sedward 				else if (left && position != left)
17917381Sedward 					move(left,LEFT);
18017381Sedward 				else if (right && position != right)
18117381Sedward 					move(right,RIGHT);
18217381Sedward 				else
18317381Sedward 					move(location[position].down,AHEAD);
18417381Sedward 				return(0);
18517381Sedward 			}
18617381Sedward 
18717381Sedward 		case SHOOT:
18817381Sedward 			if (testbit(inven,LASER)){
18917381Sedward 				if (strength - lifeline <= 50){
19017381Sedward 					printf("The %s took a direct hit!\n",objsht[enemy]);
19117381Sedward 					lifeline += 50;
19217381Sedward 				}
19317381Sedward 				else {
19417381Sedward 					puts("With his bare hand he deflects the laser blast and whips the pistol from you!");
19517381Sedward 					clearbit(inven,LASER);
19617381Sedward 					setbit(location[position].objects,LASER);
19717381Sedward 					carrying -= objwt[LASER];
19817381Sedward 					encumber -= objcumber[LASER];
19917381Sedward 				}
20017381Sedward 			}
20117381Sedward 			else
20217381Sedward 				puts("Unfortunately, you don't have a blaster handy.");
20317381Sedward 			break;
20417381Sedward 
20517381Sedward 		case DROP:
20617381Sedward 		case DRAW:
20717381Sedward 			cypher();
20817381Sedward 			time--;
20917381Sedward 			break;
21017381Sedward 
21117381Sedward 		default:
21217381Sedward 			puts("You don't have a chance, he is too quick.");
21317381Sedward 			break;
21417381Sedward 
21517381Sedward 	}
21617381Sedward 	if (lifeline >= strength){
21717381Sedward 		printf("You have killed the %s.\n", objsht[enemy]);
21817381Sedward 		if (enemy == ELF || enemy == DARK)
21917381Sedward 			puts("A watery black smoke consumes his body and then vanishes with a peal of thunder!");
22017381Sedward 		clearbit(location[position].objects,enemy);
22117381Sedward 		power += 2;
22217381Sedward 		notes[JINXED]++;
22317381Sedward 		return(0);
22417381Sedward 	}
22517381Sedward 	puts("He attacks...");
22617381Sedward 	/* some embellisments */
22717381Sedward 	hurt = rnd(NUMOFINJURIES) - (testbit(inven,SHIELD) != 0) - (testbit(wear,MAIL) != 0) - (testbit(wear,HELM) != 0);
22817381Sedward 	hurt += (testbit(wear,AMULET) != 0) + (testbit(wear,MEDALION) != 0) + (testbit(wear,TALISMAN) != 0);
22917381Sedward 	hurt = hurt < 0 ? 0 : hurt;
23017381Sedward 	hurt =	hurt >= NUMOFINJURIES ? NUMOFINJURIES -1 : hurt;
23117381Sedward 	if (!injuries[hurt]){
23217381Sedward 		injuries[hurt] = 1;
23317381Sedward 		printf("I'm afraid you have suffered %s.\n", ouch[hurt]);
23417381Sedward 	}
23517381Sedward 	else
23617381Sedward 		puts("You emerge unscathed.");
23717381Sedward 	if (injuries[SKULL] && injuries[INCISE] && injuries[NECK]){
23817381Sedward 		puts("I'm afraid you have suffered fatal injuries.");
23917381Sedward 		die();
24017381Sedward 	}
24117381Sedward 	goto fighton;
24217381Sedward }
243