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

📄 player1.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
📖 第 1 页 / 共 2 页
字号:
		umask(omask);	} else {		syncfile = fopen(file, "r+");		people = 1;	}	lastsync = 0;	for (n=0; n < scene[game].vessels; n++) {		nation[scene[game].ship[n].nationality + 1] = n + 1;		if ((scene[game].ship[n].file =  (struct File *) calloc(1, sizeof(struct File))) == NULL) {			puts("OUT OF MEMORY");			exit(0);		}		scene[game].ship[n].file -> captured = -1;	}	if (!nation[2])		nation[2] = nation[1];	if (!nation[3])		nation[3] = nation[2];	if (people > 0) {		puts("Synchronizing with the other players...");		fflush(stdout);		sync();		capn = 1;		for (n=0; n < scene[game].vessels && capn; n++) {			capn = scene[game].ship[n].file -> captain[0];			if (scene[game].ship[n].file -> struck || scene[game].ship[n].file -> captured > -1)				capn = 1;		}		if (!capn)			player = n-1;		else {			puts("All ships taken in that scenario.");			for (n=0; n < scene[game].vessels; n++)				free(scene[game].ship[n].file);			people = 0;			for (n=0; n < 5; n++)				nation[n] = 0;			fclose(syncfile);			goto reprint;		}	} else		player = 0;	while (randomize) {		static char *color[] =			{ "(American)", "(British)", "(Spanish)", "(French)" };		puts(scene[game].name);		putchar('\n');		for (n=0; n < scene[game].vessels; n++) {			printf("  %2d:  %-10s %-15s  (%-2d pts)   ",				n,				color[scene[game].ship[n].nationality],				scene[game].ship[n].shipname,				specs[scene[game].ship[n].shipnum].pts);			if(scene[game].ship[n].file -> captain[0])				puts(scene[game].ship[n].file -> captain);			else if (scene[game].ship[n].file -> struck)				puts("(struck)");			else if(scene[game].ship[n].file -> captured > -1)				puts("(captured)");			else				puts("(available)");		}		putchar('\n');		printf("Which ship do you want (0-%d)? ",scene[game].vessels-1);		fflush(stdout);		if (scanf("%d",&player) != 1 || player < 0 || player >= scene[game].vessels) {			while (getchar() != '\n');			puts("Say what?");		} else {			while (getchar() != '\n');			sync();			if (scene[game].ship[player].file -> captain[0] || scene[game].ship[player].file -> struck || scene[game].ship[player].file -> captured > -1)				puts("Sorry, that ship is taken.");			else				break;		}	}	signal(SIGHUP, choke);	signal(SIGINT, choke);	signal(SIGQUIT, choke);	signal(SIGCHLD, child);	Write(FILES + player, 1, 0, "begin");  /* he now exists */	if (people)		Write(SCENARIO, 0, 8, scene[game].people + 1);	sync();	printf("Your ship is the %s, a %s (%s crew).\n", scene[game].ship[player].shipname, info(player, message), quality(player));	if ((nameptr = (char *) getenv("NAME")) && *nameptr)		strcpy(comm,nameptr);	else {		fputs("Your name, Captain? ", stdout);		fflush(stdout);		gets(comm);		if (!*comm) strcpy(comm, "no name");	}	comm[19] = '\0';	for (k=0; k < 2; k++) {		printf("\nInitial broadside %s (grape, chain, round, double): ", (k ? "right" : "left"));		fflush(stdout);		scanf("%s", file);		switch(*file) {		case 'g':			load = GRAPE;			break;		case 'c':			load = CHAIN;			break;		case 'r':			load = ROUND;			break;		case 'd':			load = DOUBLE;			break;		}		if (k) {			scene[game].ship[player].file -> loadR = load;			scene[game].ship[player].file -> readyR = ready;		} else {			scene[game].ship[player].file -> loadL = load;			scene[game].ship[player].file -> readyL = ready;		}	}	Write(FILES + player, 1, 0, comm);	if (!people && !nodriver) {		char num[10];		sprintf(num, "%d", game);		if (!fork()) {			if (debug)				execl(DEBUGDRIVER, DRIVERNAME, num, 0);			else				execl(DRIVER, DRIVERNAME, num, 0);			perror(DRIVER);			kill(pid, SIGKILL);			exit(1);		}	}	initscr();	view = newwin(ROWSINVIEW, COLSINVIEW, 2, 1);	slot = newwin(ROWSINVIEW, 3, 2, 1+COLSINVIEW);	done_curses++;	noecho();	crmode();	board();	sprintf(message, "Captain %s assuming command",comm);	Write(FILES + player, 1, 164, message);	windspeed = scene[game].windspeed;	winddir = scene[game].winddir;	turn = scene[game].turn;	iplotships();	/* new turn */}/* * Returns the NUMBER of the closest ship */closestenemy(fromship, side, anyship)int fromship;char side, anyship;{	register int n, olddist = 30000, ident, captured;	register int dist, eclosest = 30000;	if ((ident = scene[game].ship[fromship].file -> captured) < 0)		ident = fromship;	for (n=0; n < scene[game].vessels; n++) {		if ((captured = scene[game].ship[n].file -> captured) < 0)			captured = n;		if (n != fromship && pos[n].dir && (scene[game].ship[ident].nationality != scene[game].ship[captured].nationality || anyship)) {			if (!side || gunsbear(fromship, n) == side) {				dist = range(fromship, n);				if (dist < olddist) {					eclosest = n;					olddist = dist;				}			}		}	}	if (!side && olddist == 30000)		leave(2);	return(eclosest);}main(argc, argv)int argc;char ** argv;{	register int crew, aheadfirst, ma, n;	int ta;	char message[60], ch;	int uid;	char nodrive = 0, randomize = 0, debug = 0;	char *badstring();	extern char _sobuf[];	setbuf(stdout, _sobuf);	while (*++argv && **argv == '-')		switch (*++*argv) {		case 'd':			nodrive = 1;			break;		case 'D':			debug++;			break;		case 'x':			randomize = 1;			break;		default:			printf("Unknown flag '%s'\n",*argv);			break;		}	if (*argv)		game = atoi(*argv);	else		game = -1;	initialize(nodrive, randomize, debug);	Signal("Aye aye, Sir", 0, 0);	for(;;) {		move(numscroll++,0);		clearline();		addch('~');		move(--numscroll,0);		refresh();		ch = getch();		switch(ch) {		case 'm':			crew = specs[scene[game].ship[player].shipnum].crew3;			if (crew && !grappled(player) && !fouled(player) && windspeed) {				ta = maxturns(player);				aheadfirst = ta & 0100000;				ma = maxmove(player, pos[player].dir, 0);				ta &= 077777;				acceptmove(ma, ta, aheadfirst);			} else				Signal("Unable to move", 0, 0);			break;		case 's':			acceptsignal();			break;		case 'g':			grapungrap();			break;		case 'u':			unfoulplayer();			break;		case 'v':			version();			break;		case 'b':			boarding();			break;		case 'f':			acceptcombat();			break;		case 'l':			loadplayer();			break;		case 'c':			changesail();			break;		case 'r':			repair();			break;		case 'B':			Signal("'Hands to stations!'", 0, 0);			unboard(player, player, 1);	/* cancel DBP's */			unboard(player, player, 0);	/* cancel offense */			break;		case '\f':			signal(SIGALRM, SIG_IGN);			viewrow = pos[player].row - ROWSINVIEW / 2;			viewcol = pos[player].col - COLSINVIEW / 2;			board();			plotships(); /* don't create new turn */			break;		case 'L':			scene[game].ship[player].file -> loadL = 0;			scene[game].ship[player].file -> loadR = 0;			scene[game].ship[player].file -> readyL = 0;			scene[game].ship[player].file -> readyR = 0;			Signal("Broadsides unloaded", 0, 0);			break;		case 'q':			Signal("Type 'Q' to quit", 0, 0);			break;		case 'Q':			leave(0);			break;		case 'I':			for (n = 0; n < scene[game].vessels; n++)				eyeball(player, n);			break;		case 'i':			n = closestenemy(player, 0, 1);			eyeball(player, n);			break;		}		signalflags();		lost();	}}char *saywhat(n)int n;{	if(scene[game].ship[n].file -> captain[0])		return(scene[game].ship[n].file -> captain);	else if (scene[game].ship[n].file -> struck)		return("(struck)");	else if(scene[game].ship[n].file -> captured > -1)		return("(captured)");	else		return("(computer)");}eyeball(player, n)int player, n;{	char message[80];	register i;	if (scene[game].ship[n].shipdir) {		sprintf(message, "%d, %s", range(player, n), saywhat(n));		Signal("Sail ho! (range %s)", -1, message);		switch(scene[game].ship[n].nationality) {		case 0:			strcpy(message, "American ");			break;		case 1:			strcpy(message, "British ");			break;		case 2:			strcpy(message, "Spanish ");			break;		case 3:			strcpy(message, "French ");			break;		default:			strcpy(message, "Gremlin ");			break;		}		switch(specs[scene[game].ship[n].shipnum].class) {		case 1:		case 2:			strcat(message, "Ship of the Line ");			break;		case 3:		case 4:			strcat(message, "Frigate ");			break;		case 5:		case 6:			strcat(message, "Sloop ");			break;		}		switch(portside(player, n, 1) - pos[player].dir) {		case -7:		case 1:			strcat(message, "off the starboard bow.");			break;		case -6:		case 2:			strcat(message, "off the starboard beam.");			break;		case -5:		case 3:			strcat(message, "off the starboard quarter.");			break;		case -4:		case 4:			strcat(message, "dead astern.");			break;		case -3:		case 5:			strcat(message, "off the port quarter.");			break;		case -2:		case 6:			strcat(message, "off the port beam.");			break;		case -1:		case 7:			strcat(message, "off the port bow.");			break;		case 0:			strcat(message, "dead ahead.");			break;		}		Signal(message, 0, 0);	}}

⌨️ 快捷键说明

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