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

📄 interplayer.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * interplayer.c - player to player routines for Phantasia */#include "include.h"/************************************************************************// FUNCTION NAME: checkbattle()// FUNCTION: check to see if current player should battle another// AUTHOR: E. A. Estes, 12/4/85// ARGUMENTS: none// RETURN VALUE: none// MODULES CALLED: battleplayer(), fread(), fseek()// GLOBAL INPUTS: Other, Users, Player, Fileloc, *Playersfp// GLOBAL OUTPUTS: Users// DESCRIPTION:/	Seach player file for a foe at the same coordinates as the/	current player./	Also update user count.//************************************************************************/checkbattle(){long	foeloc = 0L;		/* location in file of person to fight */    Users = 0;    fseek(Playersfp, 0L, 0);    while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)	{	if (Other.p_status != S_OFF	    && Other.p_status != S_NOTUSED	    && Other.p_status != S_HUNGUP	    && (Other.p_status != S_CLOAKED || Other.p_specialtype != SC_VALAR))	    /* player is on and not a cloaked valar */	    {	    ++Users;	    if (Player.p_x == Other.p_x		&& Player.p_y == Other.p_y		/* same coordinates */		&& foeloc != Fileloc		/* not self */		&& Player.p_status == S_PLAYING		&& (Other.p_status == S_PLAYING || Other.p_status == S_INBATTLE)		/* both are playing */		&& Other.p_specialtype != SC_VALAR		&& Player.p_specialtype != SC_VALAR)		/* neither is valar */		{		battleplayer(foeloc);		return;		}	    }	foeloc += SZ_PLAYERSTRUCT;	}}/**//************************************************************************// FUNCTION NAME: battleplayer()// FUNCTION: inter-terminal battle with another player// AUTHOR: E. A. Estes, 2/15/86// ARGUMENTS:/	long foeplace - location in player file of person to battle// RETURN VALUE: none// MODULES CALLED: readrecord(), readmessage(), writerecord(), collecttaxes(), /	displaystats(), fabs(), more(), death(), sleep(), wmove(), waddch(), printw(), /	myturn(), altercoordinates(), waddstr(), wrefresh(), mvprintw(), /	getanswer(), wclrtoeol(), wclrtobot()// GLOBAL INPUTS: Foestrikes, LINES, Lines, Other, Shield, Player, *stdscr, /	Fileloc, *Enemyname// GLOBAL OUTPUTS: Foestrikes, Lines, Shield, Player, Luckout, *Enemyname// DESCRIPTION:/	Inter-terminal battle is a very fragile and slightly klugy thing./	At any time, one player is master and the other is slave./	We pick who is master first by speed and level.  After that,/	the slave waits for the master to relinquish its turn, and/	the slave becomes master, and so on.//	The items in the player structure which control the handshake are:/	    p_tampered:/		master increments this to relinquish control/	    p_istat:/		master sets this to specify particular action/	    p_1scratch:/		set to total damage inflicted so far; changes to indicate action//************************************************************************/battleplayer(foeplace)long	foeplace;{double	dtemp;		/* for temporary calculations */double	oldhits = 0.0;	/* previous damage inflicted by foe */register int	loop;	/* for timing out */int	ch;		/* input */short	oldtampered;	/* old value of foe's p_tampered */    Lines = 8;    Luckout = FALSE;    mvaddstr(4, 0, "Preparing for battle!\n");    refresh();#ifdef SYS5    flushinp();#endif    /* set up variables, file, etc. */    Player.p_status = S_INBATTLE;    Shield = Player.p_energy;    /* if p_tampered is not 0, someone else may try to change it (king, etc.) */    Player.p_tampered = oldtampered = 1;    Player.p_1scratch = 0.0;    Player.p_istat = I_OFF;    readrecord(&Other, foeplace);    if (fabs(Player.p_level - Other.p_level) > 20.0)	/* see if players are greatly mismatched */	{	dtemp = (Player.p_level - Other.p_level) / MAX(Player.p_level, Other.p_level);	if (dtemp < -0.5)	    /* foe outweighs this one */	    Player.p_speed *= 2.0;	}    writerecord(&Player, Fileloc);		/* write out all our info */    if (Player.p_blindness)	Enemyname = "someone";    else	Enemyname = Other.p_name;    mvprintw(6, 0, "You have encountered %s   Level: %.0f\n", Enemyname, Other.p_level);    refresh();    for (loop = 0; Other.p_status != S_INBATTLE && loop < 30; ++loop)	/* wait for foe to respond */	{	readrecord(&Other, foeplace);	sleep(1);	}    if (Other.p_status != S_INBATTLE)	/* foe did not respond */	{	mvprintw(5, 0, "%s is not responding.\n", Enemyname);	goto LEAVE;	}    /* else, we are ready to battle */    move(4, 0);    clrtoeol();    /*     * determine who is first master     * if neither player is faster, check level     * if neither level is greater, battle is not allowed     * (this should never happen, but we have to handle it)     */    if (Player.p_speed > Other.p_speed)	Foestrikes = FALSE;    else if (Other.p_speed > Player.p_speed)	Foestrikes = TRUE;    else if (Player.p_level > Other.p_level)	Foestrikes = FALSE;    else if (Other.p_level > Player.p_level)	Foestrikes = TRUE;    else	/* no one is faster */	{	printw("You can't fight %s yet.", Enemyname);	goto LEAVE;	}    for (;;)	{	displaystats();	readmessage();	mvprintw(1, 26, "%20.0f", Shield);	/* overprint energy */	if (!Foestrikes)	    /* take action against foe */	    myturn();	else	    /* wait for foe to take action */	    {	    mvaddstr(4, 0, "Waiting...\n");	    clrtoeol();	    refresh();	    for (loop = 0; loop < 20; ++loop)		/* wait for foe to act */		{		readrecord(&Other, foeplace);		if (Other.p_1scratch != oldhits)		    /* p_1scratch changes to indicate action */		    break;		else		    /* wait and try again */		    {		    sleep(1);		    addch('.');		    refresh();		    }		}	    if (Other.p_1scratch == oldhits)		{		/* timeout */		mvaddstr(22, 0, "Timeout: waiting for response.  Do you want to wait ? ");		ch = getanswer("NY", FALSE);		move(22, 0);		clrtobot();		if (ch == 'Y')		    continue;		else		    break;		}	    else		/* foe took action */		{		switch (Other.p_istat)		    {		    case I_RAN:		/* foe ran away */			mvprintw(Lines++, 0, "%s ran away!", Enemyname);			break;		    case I_STUCK:	/* foe tried to run, but couldn't */			mvprintw(Lines++, 0, "%s tried to run away.", Enemyname);			break;		    case I_BLEWIT:	/* foe tried to luckout, but didn't */			mvprintw(Lines++, 0, "%s tried to luckout!", Enemyname);			break;		    default:			dtemp = Other.p_1scratch - oldhits;			mvprintw(Lines++, 0, "%s hit you %.0f times!", Enemyname, dtemp);			Shield -= dtemp;			break;		    }		oldhits = Other.p_1scratch;	/* keep track of old hits */		if (Other.p_tampered != oldtampered)		    /* p_tampered changes to relinquish turn */		    {		    oldtampered = Other.p_tampered;		    Foestrikes = FALSE;		    }		}	    }	/* decide what happens next */	refresh();	if (Lines > LINES - 2)	    {	    more(Lines);	    move(Lines = 8, 0);	    clrtobot();	    }	if (Other.p_istat == I_KILLED || Shield < 0.0)	    /* we died */	    {	    Shield = -2.0;		/* insure this value is negative */	    break;	    }	if (Player.p_istat == I_KILLED)	    /* we killed foe; award treasre */	    {	    mvprintw(Lines++, 0, "You killed %s!", Enemyname);	    Player.p_experience += Other.p_experience;	    Player.p_crowns += (Player.p_level < 1000.0) ? Other.p_crowns : 0;	    Player.p_amulets += Other.p_amulets;	    Player.p_charms += Other.p_charms;	    collecttaxes(Other.p_gold, Other.p_gems);	    Player.p_sword = MAX(Player.p_sword, Other.p_sword);	    Player.p_shield = MAX(Player.p_shield, Other.p_shield);	    Player.p_quksilver = MAX(Player.p_quksilver, Other.p_quksilver);	    if (Other.p_virgin && !Player.p_virgin)		{		mvaddstr(Lines++, 0, "You have rescued a virgin.  Will you be honorable ? ");		if ((ch = getanswer("YN", FALSE)) == 'Y')		    Player.p_virgin = TRUE;		else		    {		    ++Player.p_sin;		    Player.p_experience += 8000.0;		    }		}	    sleep(3);     		/* give other person time to die */	    break;	    }	else if (Player.p_istat == I_RAN || Other.p_istat == I_RAN)	    /* either player ran away */	    break;	}LEAVE:    /* clean up things and leave */    writerecord(&Player, Fileloc);	/* update a final time */    altercoordinates(0.0, 0.0, A_NEAR);	/* move away from battle site */    Player.p_energy = Shield;		/* set energy to actual value */    Player.p_tampered = T_OFF;		/* clear p_tampered */    more(Lines);			/* pause */    move(4, 0);    clrtobot();				/* clear bottom area of screen */    if (Player.p_energy < 0.0)	/* we are dead */	death("Interterminal battle");}/**//************************************************************************// FUNCTION NAME: myturn()// FUNCTION: process players action against foe in battle// AUTHOR: E. A. Estes, 2/7/86// ARGUMENTS: none// RETURN VALUE: none// MODULES CALLED: writerecord(), inputoption(), floor(), wmove(), drandom(), /	waddstr(), wrefresh(), mvprintw(), wclrtoeol(), wclrtobot()// GLOBAL INPUTS: Lines, Other, Player, *stdscr, Fileloc, Luckout, /	*Enemyname// GLOBAL OUTPUTS: Foestrikes, Lines, Player, Luckout// DESCRIPTION:/	Take action action against foe, and decide who is master/	for next iteration.//************************************************************************/myturn(){double	dtemp;		/* for temporary calculations */int	ch;		/* input */    mvaddstr(7, 0, "1:Fight  2:Run Away!  3:Power Blast  ");    if (Luckout)	clrtoeol();    else	addstr("4:Luckout  ");    ch = inputoption();    move(Lines = 8, 0);    clrtobot();    switch (ch)	{	default:	/* fight */	    dtemp = ROLL(2.0, Player.p_might);HIT:			    mvprintw(Lines++, 0, "You hit %s %.0f times!", Enemyname, dtemp);	    Player.p_sin += 0.5;	    Player.p_1scratch += dtemp;	    Player.p_istat = I_OFF;	    break;	case '2':	/* run away */	    Player.p_1scratch -= 1.0;	/* change this to indicate action */	    if (drandom() > 0.25)		{		mvaddstr(Lines++, 0, "You got away!");		Player.p_istat = I_RAN;		}	    else		{		mvprintw(Lines++, 0, "%s is still after you!", Enemyname);		Player.p_istat = I_STUCK;		}	    break;	case '3':	/* power blast */	    dtemp = MIN(Player.p_mana, Player.p_level * 5.0);	    Player.p_mana -= dtemp;	    dtemp *= (drandom() + 0.5) * Player.p_magiclvl * 0.2 + 2.0;	    mvprintw(Lines++, 0, "You blasted %s !", Enemyname);	    goto HIT;	case '4':	/* luckout */	    if (Luckout || drandom() > 0.1)		{		if (Luckout)		    mvaddstr(Lines++, 0, "You already tried that!");		else		    {		    mvaddstr(Lines++, 0, "Not this time . . .");		    Luckout = TRUE;		    }		Player.p_1scratch -= 1.0;		Player.p_istat = I_BLEWIT;		}	    else		{		mvaddstr(Lines++, 0, "You just lucked out!");		Player.p_1scratch = Other.p_energy * 1.1;		}	    break;	}    refresh();    Player.p_1scratch = floor(Player.p_1scratch);	/* clean up any mess */    if (Player.p_1scratch > Other.p_energy)	Player.p_istat = I_KILLED;    else if (drandom() * Player.p_speed < drandom() * Other.p_speed)	/* relinquish control */	{	++Player.p_tampered;	Foestrikes = TRUE;	}    writerecord(&Player, Fileloc);			/* let foe know what we did */}/**//************************************************************************// FUNCTION NAME: checktampered()// FUNCTION: check if current player has been tampered with// AUTHOR: E. A. Estes, 12/4/85// ARGUMENTS: none// RETURN VALUE: none// MODULES CALLED: readrecord(), fread(), fseek(), tampered(), writevoid()// GLOBAL INPUTS: *Energyvoidfp, Other, Player, Fileloc, Enrgyvoid// GLOBAL OUTPUTS: Enrgyvoid// DESCRIPTION:/	Check for energy voids, holy grail, and tampering by other/	players.//************************************************************************/checktampered(){long	loc = 0L;		/* location in energy void file */    /* first check for energy voids */    fseek(Energyvoidfp, 0L, 0);    while (fread((char *) &Enrgyvoid, SZ_VOIDSTRUCT, 1, Energyvoidfp) == 1)	if (Enrgyvoid.ev_active	    && Enrgyvoid.ev_x == Player.p_x	    && Enrgyvoid.ev_y == Player.p_y)	    /* sitting on one */	    {	    if (loc > 0L)		/* not the holy grail; inactivate energy void */		{		Enrgyvoid.ev_active = FALSE;		writevoid(&Enrgyvoid, loc);		tampered(T_NRGVOID, 0.0, 0.0);		}	    else if (Player.p_status != S_CLOAKED)		/* holy grail */		tampered(T_GRAIL, 0.0, 0.0);	    break;	    }	else	    loc += SZ_VOIDSTRUCT;    /* now check for other things */    readrecord(&Other, Fileloc);    if (Other.p_tampered != T_OFF)	tampered(Other.p_tampered, Other.p_1scratch, Other.p_2scratch);}/**//************************************************************************// FUNCTION NAME: tampered()// FUNCTION: take care of tampering by other players// AUTHOR: E. A. Estes, 12/4/85// ARGUMENTS:/	int what - what type of tampering/	double arg1, arg2 - rest of tampering info// RETURN VALUE: none// MODULES CALLED: writerecord(), more(), fread(), death(), fseek(), sleep(), /	floor(), wmove(), waddch(), drandom(), printw(), altercoordinates(), /	waddstr(), wrefresh(), encounter(), writevoid()// GLOBAL INPUTS: Other, Player, *stdscr, Enrgyvoid, *Playersfp// GLOBAL OUTPUTS: Other, Player, Changed, Enrgyvoid// DESCRIPTION:/	Take care of energy voids, holy grail, decree and intervention/	action on current player.//************************************************************************/tampered(what, arg1, arg2)int	what;double	arg1;double	arg2;{long	loc;			/* location in file of other players */    Changed = TRUE;    move(4,0);    Player.p_tampered = T_OFF;	/* no longer tampered with */    switch (what)	{	case T_NRGVOID:	    addstr("You've hit an energy void !\n");	    Player.p_mana /= 3.0;	    Player.p_energy /= 2.0;	    Player.p_gold = floor(Player.p_gold/1.25) + 0.1;	    altercoordinates(0.0, 0.0, A_NEAR);	    break;	case T_TRANSPORT:	    addstr("The king transported you !  ");	    if (Player.p_charms > 0)		{		addstr("But your charm saved you. . .\n");		--Player.p_charms;		}	    else		{		altercoordinates(0.0, 0.0, A_FAR);		addch('\n');		}	    break;	case T_BESTOW:	    printw("The king has bestowed %.0f gold pieces on you !\n", arg1);	    Player.p_gold += arg1;	    break;	case T_CURSED:	    addstr("You've been cursed !  ");	    if (Player.p_blessing)		{		addstr("But your blessing saved you. . .\n");		Player.p_blessing = FALSE;		}	    else		{		addch('\n');		Player.p_poison += 2.0;		Player.p_energy = 10.0;		Player.p_maxenergy  *= 0.95;		Player.p_status = S_PLAYING;	/* no longer cloaked */		}	    break;	case T_VAPORIZED:	    addstr("You have been vaporized!\n");	    more(7);	    death("Vaporization");	    break;	case T_MONSTER:	    addstr("The Valar zapped you with a monster!\n");	    more(7);	    encounter((int) arg1);	    return;	case T_BLESSED:	    addstr("The Valar has blessed you!\n");	    Player.p_energy = (Player.p_maxenergy *= 1.05) + Player.p_shield;

⌨️ 快捷键说明

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