⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 player1.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
📖 第 1 页 / 共 2 页
字号:
#ifndef lintstatic	char *sccsid = "@(#)player1.c	1.10 83/07/03";#endif#include "player.h"#include <sys/types.h>WINDOW *view,*slot;char done_curses = 0;acceptcombat(){	int crew[3], men = 0, rangeofshot, target, temp;	int n, r, guns[2], load[2], car[2], roll[2];	int ready[2], index, rakehim, sternrake;	int shootat[2], hit[2], closest[2], ship;	int hhits = 0, ghits = 0, rhits = 0, chits = 0;	int buf;	struct shipspecs *ptr;	struct File *ptr1;	ptr = &specs[scene[game].ship[player].shipnum];	ptr1 = scene[game].ship[player].file;	crew[0] = ptr -> crew1;	crew[1] = ptr -> crew2;	crew[2] = ptr -> crew3;	ready[0] = ptr1 -> readyL;	ready[1] = ptr1 -> readyR;	load[0] = ptr1 -> loadL;	load[1] = ptr1 -> loadR;	guns[0] = ptr -> gunL;	guns[1] = ptr -> gunR;	car[0] = ptr -> carL;	car[1] = ptr -> carR;	for (n = 0; n < 3; n++) {		if (ptr1 -> OBP[n].turnsent)			men += ptr1 -> OBP[n].mensent;	}	for (n = 0; n < 3; n++) {		if (ptr1 -> DBP[n].turnsent)			men += ptr1 -> DBP[n].mensent;	}	if (men) {		crew[0] = men/100 ? 0 : crew[0] != 0;		crew[1] = (men%100)/10 ? 0 : crew[1] != 0;		crew[2] = men%10 ? 0 : crew[2] != 0;	}	for (r = 0; r < 2; r++) {		if ((guns[r] || car[r]) && crew[2] && load[r] && ready[r] <= 0 && !ptr1 -> struck && ((closest[r] = closestenemy(player, (r ? 'r' : 'l'), 1)) != 30000)) {			switch(load[r]) {			case GRAPE:				rangeofshot = 1;				break;			case CHAIN:				rangeofshot = 3;				break;			case DOUBLE:				rangeofshot = 1;				break;			case ROUND:				rangeofshot = 10;				break;			}			if ((target = range(player, closest[r])) <= rangeofshot && !scene[game].ship[closest[r]].file -> struck && (guns[r] || (car[r] && target < 3))) {				Signal("%s (%c%c) within range of %s broadside.", closest[r], (r?"right":"left"));				if (load[r] > CHAIN && target < 6) {					Signal("Aim for hull or rigging? ", -1, 0);					while ((buf = getch()) == EOF);					addch(buf);					if(buf == 'r')						shootat[r] = RIGGING;					else if (buf == 'h')						shootat[r] = HULL;					else {						shootat[r] = -1;						Signal("'Avast there! Hold your fire.'", -1, 0);					}				} else {					shootat[r] = RIGGING;					Signal("Fire? ", -1, 0);					while ((buf = getch()) == EOF);					addch(buf);					if (buf == 'n') {						shootat[r] = -1;						Signal("Belay that! Hold your fire.", -1, 0);					}				}				if (shootat[r] != -1) {					fired = 1;					rakehim = gunsbear(player, closest[r]) && !gunsbear(closest[r], player);					temp = portside(closest[r], player, 1) - pos[closest[r]].dir + 1;					if (temp < 1)						temp += 8;					if (temp > 8)						temp -= 8;					sternrake = temp > 4 && temp < 6;					if (rakehim && !sternrake)						Signal("Raking the %s!", closest[r], 0);					else if (rakehim && sternrake)						Signal("Stern Rake! %s splintering!", closest[r], 0);					index = guns[r];					if (target < 3)						index += car[r];					index = (index - 1)/3;					index = index > 8 ? 8 : index;					if (!rakehim)						hit[r] = HDT[index][target-1];					else						hit[r] = HDTrake[index][target-1];					if (rakehim && sternrake)						hit[r]++;					hit[r] += QUAL[index][ptr -> qual-1];					for (n=0; n < 3 && ptr1 -> captured < 0; n++)						if (!crew[n])							if (index <= 5)								hit[r]--;							else								hit[r] -= 2;					if (ready[r] <= -30000)						if (index <= 3)							hit[r]++;						else							hit[r] += 2;					if (ptr1 -> captured > -1)						if (index <= 1)							hit[r]--;						else							hit[r] -= 2;					hit[r] += AMMO[index][load[r] - 1];					if (((temp = ptr -> class) >= 5 || temp == 1) && windspeed == 5)						hit[r]--;					if (windspeed == 6 && temp == 4)						hit[r] -= 2;					if (windspeed == 6 && temp <= 3)						hit[r]--;					if (hit[r] >= 0) {						roll[r] = die();						if (load[r] == GRAPE)							chits = hit[r];						else {							struct Tables *t;							hit[r] = hit[r] > 10 ? 10 : hit[r];							t = &(shootat[r] ? RigTable : HullTable)[hit[r]][roll[r]-1];							chits = t->C;							rhits = t->R;							hhits = t->H;							ghits = t->G;							if (scene[game].ship[closest[r]].file -> FS)								rhits *= 2;							if (load[r] == CHAIN) {								ghits = 0;								hhits = 0;							}						}						table(shootat[r], load[r], hit[r], closest[r], player, roll[r]);					}					numscroll = 18;					move(numscroll++, 0);					clearline();					printw("Damage inflicted on the %s:", scene[game].ship[closest[r]].shipname);					move(numscroll++, 0);					clearline();					printw("\t%d HULL, %d GUNS, %d CREW, %d RIGGING", hhits, ghits, chits, rhits);					load[r] = 0;					if (!r) {						ptr1 -> loadL = 0;						ptr1 -> readyL = 0;					} else {						ptr1 -> loadR = 0;						ptr1 -> readyR = 0;					}				}			} else {				load[r] = 0;				Signal("Unable to fire %s broadside", -1, (r?"right":"left"));			}		} else			Signal("Unable to fire %s broadside", -1, (r?"right":"left"));	}}leave(conditions)int conditions;{	FILE *fp;	int people;	float net;	char * capn;	char message[60];	register int n;	struct logs log[10], temp;	signal(SIGHUP, SIG_IGN);	signal(SIGINT, SIG_IGN);	signal(SIGQUIT, SIG_IGN);	signal(SIGALRM, SIG_IGN);	signal(SIGCHLD, SIG_IGN);	if (conditions != -1) {		capn = scene[game].ship[player].file -> captain;		sprintf(message,"Captain %s relinquishing.",capn);		Write(FILES + player, 1, 164, message);		if (fp = fopen(LOGFILE, "r+")) {			net = (float) (scene[game].ship[player].file -> points) / specs[scene[game].ship[player].shipnum].pts;			people = getw(fp);			n = fread(log, sizeof(struct logs), 10, fp);			for (; n < 10; n++)				log[n].fname[0] = log[n].uid = log[n].fshipnum = log[n].fgamenum = log[n].netpoints = 0;			rewind(fp);			if(people < 0)				putw(1, fp);			else				putw(people+1, fp);			for (n=0; n < 10; n++)				if (net > (float) log[n].netpoints / specs[scene[log[n].fgamenum].ship[log[n].fshipnum].shipnum].pts) {					fwrite(log, sizeof(struct logs), n, fp);					strcpy(temp.fname, capn);					temp.uid = getuid();					temp.fshipnum = player;					temp.fgamenum = game;					temp.netpoints = scene[game].ship[player].file -> points;					fwrite(&temp, sizeof(struct logs), 1, fp);					fwrite(log + n, sizeof(struct logs), 9 - n, fp);					break;				}			fclose(fp);		}		Write(FILES + player, 1, 0, " ");		Write(SCENARIO, 0, 8, scene[game].people - 1);		if (done_curses) {			screen();			Signal("It looks like you've had it!", -1, 0);			if (conditions == 1)				Signal("Your ship was captured.", -1, 0);			else if (conditions == 2)				Signal("No more enemies.", -1, 0);			else if (conditions == 3)				Signal("Hurricane!  All ships destroyed.",					-1, 0);			else if (conditions == 4)				Signal("The driver died.", -1, 0);			move(0, LINES-1);			numscroll = LINES;			clearline();			refresh();		} else {			if (conditions == 4)				printf("The driver died.\n");		}		fclose(syncfile);	}	if (done_curses) {		nocrmode();		echo();		endwin();	}	exit(0);}choke(){	leave(0);}#include <sys/wait.h>child(){	union wait status;	int pid;	signal(SIGCHLD, SIG_IGN);	do {		pid = wait3(&status, WNOHANG|WUNTRACED, 0);		if (pid < 0 || pid > 0 && !WIFSTOPPED(status))			leave(4);	} while (pid != 0);	signal(SIGCHLD, child);}grapungrap(){	register int n, k, l, number, captured;	int buf;	for (n=0; n < scene[game].vessels ; n++) {		if (n != player && (range(player, n) <= 1 || grapple(player, n))) {			if ((captured = scene[game].ship[n].file -> captured) < 0)				captured = n;			Signal("Attempt to grapple or ungrapple %s (%c%c): ", n, 0);			while ((buf = getch()) == EOF);			addch(buf);			if (buf == 'g') {				number = die() < 3;				if (!number && scene[game].ship[player].nationality == scene[game].ship[captured].nationality)					number = 1;				if (number) {					for (l=0; l < 10 && scene[game].ship[player].file -> grapples[l].turnfoul; l++);					if (!scene[game].ship[player].file -> grapples[l].turnfoul) {						Write(FILES + player, 0, 124 + l*4, turn);						Write(FILES + player, 0, 124 + l*4 + 2, n);					}					for (l=0; l < 10 && scene[game].ship[n].file -> grapples[l].turnfoul; l++);					if (!scene[game].ship[n].file -> grapples[l].turnfoul) {						Write(FILES + n, 0, 124 + l*4, turn);						Write(FILES + n, 0, 124 + l*4 + 2, player);					}				}				if (number) {					Signal("Attempt succeeds!", 0, 0);					makesignal("grappled with %s (%c%c)", n, player);				} else					Signal("Attempt fails.", 0, 0);			}			if (buf == 'u') {				for (k=0; k < 10; k++) {					if (scene[game].ship[player].file -> grapples[k].turnfoul && n == scene[game].ship[player].file -> grapples[k].toship) {						if (die() < 3 || scene[game].ship[player].nationality == scene[game].ship[captured].nationality) {							cleangrapple(player, n, k);							Signal("Attempt succeeds!", 0, 0);							makesignal("ungrappling with %s (%c%c)", n, player);						} else							Signal("Attempt fails.", 0, 0);					}				}			}		}	}}unfoulplayer(){	register int n, toship;	int buf;	for (n=0; n < 10; n++) {		if (scene[game].ship[player].file -> fouls[n].turnfoul) {			Signal("Attempt to unfoul with the %s (%c%c)? ", (toship = scene[game].ship[player].file -> fouls[n].toship), 0);			while ((buf = getch()) == EOF);			addch(buf);			if (buf == 'y' && die() < 3) {				cleanfoul(player, toship, n);				Signal("Attempt succeeds!", 0, 0);				makesignal("unfouling %s (%c%c)", toship, player);			} else if (buf == 'y')				Signal("Attempt fails.", 0, 0);		}	}}initialize(nodriver, randomize, debug)char randomize, nodriver, debug;{	char comm[80], file[25], capn;	char message[60];	int load = ROUND, ready = -30000;	int people = 0;	int pid;	register int n;	register int k;	char *nameptr;	srand(pid = getpid());	if (game < 0) {		puts("Choose a scenario:\n");		puts("\n\tNUMBER\tSHIPS\tIN PLAY\tTITLE");		for (n=0; n < NUMOFSCENES; n++) {			sprintf(file, "/tmp/.%d", n);			printf("\t%d):\t%d", n, scene[n].vessels);			if (access(file, 0) >= 0)				printf("\tYES");			else				printf("\tno");			printf("\t%s\n", scene[n].name);		}reprint:		printf("\nScenario number? ");		fflush(stdout);		scanf("%d", &game);		while (getchar() != '\n');	}	if (game < 0 || game >= NUMOFSCENES) {		puts("Very funny.");		exit(1);	}	sprintf(file, "/tmp/.%d", game);	if (access(file, 0) < 0) {		int omask;#ifdef SETUID		omask = umask(077);#else		omask = umask(011);#endif		syncfile = fopen(file, "w+");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -