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

📄 fight.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 3 页
字号:
			    break;			    }			}		    /* otherwise, take some brains */		    mvprintw(Lines++, 0,			"%s neutralized 1/5 of your brain!", Enemyname);		    Player.p_brains *= 0.8;		    break;		case SM_TIAMAT:		    /* take some gold and gems */		    mvprintw(Lines++, 0,			"%s took half your gold and gems and flew off.", Enemyname);		    Player.p_gold /= 2.0;		    Player.p_gems /= 2.0;		    cancelmonster();		    break;		case SM_KOBOLD:		    /* steal a gold piece and run */		    mvprintw(Lines++, 0,			"%s stole one gold piece and ran away.", Enemyname);		    Player.p_gold = MAX(0.0, Player.p_gold - 1.0);		    cancelmonster();		    break;		case SM_SHELOB:		    /* bite and (medium) poison */		    mvprintw(Lines++, 0,			"%s has bitten and poisoned you!", Enemyname);		    Player.p_poison -= 1.0;		    break;		case SM_LAMPREY:		    /*  bite and (small) poison */		    mvprintw(Lines++, 0, "%s bit and poisoned you!", Enemyname);		    Player.p_poison += 0.25;		    break;		case SM_BONNACON:		    /* fart and run */		    mvprintw(Lines++, 0, "%s farted and scampered off.", Enemyname);		    Player.p_energy /= 2.0;		/* damage from fumes */		    cancelmonster();		    break;		case SM_SMEAGOL:		    if (Player.p_ring.ring_type != R_NONE)			/* try to steal ring */			{			mvprintw(Lines++, 0,			    "%s tried to steal your ring, ", Enemyname);			if (drandom() > 0.1)			    addstr("but was unsuccessful.");			else			    {			    addstr("and ran away with it!");			    Player.p_ring.ring_type = R_NONE;			    cancelmonster();			    }			}		    break;		case SM_SUCCUBUS:		    /* inflict damage through shield */		    inflict = ROLL(15.0, Circle * 10.0);		    inflict = MIN(inflict, Player.p_energy);		    mvprintw(Lines++, 0, "%s sapped %.0f of your energy.",			Enemyname, inflict);		    Player.p_energy -= inflict;		    break;		case SM_CERBERUS:		    /* take all metal treasures */		    mvprintw(Lines++, 0,			"%s took all your metal treasures!", Enemyname);		    Player.p_crowns = 0;		    Player.p_sword =		    Player.p_shield =		    Player.p_gold = 0.0;		    cancelmonster();		    break;		case SM_UNGOLIANT:		    /* (large) poison and take a quickness */		    mvprintw(Lines++, 0,			"%s poisoned you, and took one quik.", Enemyname);		    Player.p_poison += 5.0;		    Player.p_quickness -= 1.0;		    break;		case SM_JABBERWOCK:		    /* fly away, and leave either a Jubjub bird or Bonnacon */		    mvprintw(Lines++, 0,			"%s flew away, and left you to contend with one of its friends.",			Enemyname);		    Whichmonster = 55 + (drandom() > 0.5) ? 22 : 0;		    longjmp(Fightenv, 0);		    /*NOTREACHED*/		case SM_TROLL:		    /* partially regenerate monster */		    mvprintw(Lines++, 0,			"%s partially regenerated his energy.!", Enemyname);		    Curmonster.m_energy +=			floor((Curmonster.m_o_energy - Curmonster.m_energy) / 2.0);		    Curmonster.m_strength = Curmonster.m_o_strength;		    Curmonster.m_melee = Curmonster.m_skirmish = 0.0;		    Curmonster.m_maxspeed = Curmonster.m_o_speed;		    break;		case SM_WRAITH:		    if (!Player.p_blindness)			/* make blind */			{			mvprintw(Lines++, 0, "%s blinded you!", Enemyname);			Player.p_blindness = TRUE;			Enemyname = "A monster";			}		    break;		}	    return;	}    /* fall through to here if monster inflicts a normal hit */    inflict = drandom() * Curmonster.m_strength + 0.5;SPECIALHIT:    mvprintw(Lines++, 0, "%s hit you %.0f times!", Enemyname, inflict);    if ((Shield -= inflict) < 0)	{	Player.p_energy += Shield;	Shield = 0.0;	}}/**//************************************************************************// FUNCTION NAME: cancelmonster()// FUNCTION: mark current monster as no longer active// AUTHOR: E. A. Estes, 12/4/85// ARGUMENTS: none// RETURN VALUE: none// MODULES CALLED: none// GLOBAL INPUTS: none// GLOBAL OUTPUTS: Curmonster// DESCRIPTION:/	Clear current monster's energy, experience, treasure type, and/	flock.  This is the same as having the monster run away.//************************************************************************/cancelmonster(){    Curmonster.m_energy = 0.0;    Curmonster.m_experience = 0.0;    Curmonster.m_treasuretype = 0;    Curmonster.m_flock = 0.0;}/**//************************************************************************// FUNCTION NAME: hitmonster()// FUNCTION: inflict damage upon current monster// AUTHOR: E. A. Estes, 12/4/85// ARGUMENTS:/	double inflict - damage to inflict upon monster// RETURN VALUE: none// MODULES CALLED: monsthits(), wmove(), strcmp(), waddstr(), mvprintw()// GLOBAL INPUTS: Curmonster, Lines, Player, *stdscr, *Enemyname// GLOBAL OUTPUTS: Curmonster, Lines// DESCRIPTION:/	Hit monster specified number of times.  Handle when monster dies,/	and a few special monsters.//************************************************************************/hitmonster(inflict)double	inflict;{    mvprintw(Lines++, 0, "You hit %s %.0f times!", Enemyname, inflict);    Curmonster.m_energy -= inflict;    if (Curmonster.m_energy > 0.0)	{	if (Curmonster.m_type == SM_DARKLORD || Curmonster.m_type == SM_SHRIEKER)	    /* special monster didn't die */	    monsthits();	}    else	/* monster died.  print message. */	{	if (Curmonster.m_type == SM_MORGOTH)	    mvaddstr(Lines++, 0, "You have defeated Morgoth, but he may return. . .");	else	    /* all other types of monsters */	    {	    mvprintw(Lines++, 0, "You killed it.  Good work, %s.", Player.p_name);	    if (Curmonster.m_type == SM_MIMIC		&& strcmp(Curmonster.m_name, "A Mimic") != 0		&& !Player.p_blindness)		mvaddstr(Lines++, 0, "The body slowly changes into the form of a mimic.");	    }	}}/**//************************************************************************// FUNCTION NAME: throwspell()// FUNCTION: throw a magic spell// AUTHOR: E. A. Estes, 12/4/85// ARGUMENTS: none// RETURN VALUE: none// MODULES CALLED: hitmonster(), cancelmonster(), sqrt(), floor(), wmove(), /	drandom(), altercoordinates(), longjmp(), infloat(), waddstr(), mvprintw(), /	getanswer()// GLOBAL INPUTS: Curmonster, Whichmonster, Nomana[], Player, *stdscr, /	Fightenv[], Illspell[], *Enemyname// GLOBAL OUTPUTS: Curmonster, Whichmonster, Shield, Player// DESCRIPTION:/	Prompt player and process magic spells.//************************************************************************/throwspell(){double	inflict;	/* damage inflicted */double	dtemp;		/* for dtemporary calculations */int	ch;		/* input */    mvaddstr(7, 0, "\n\n");		/* clear menu area */    if (Player.p_magiclvl >= ML_ALLORNOTHING)	mvaddstr(7, 0, "1:All or Nothing  ");    if (Player.p_magiclvl >= ML_MAGICBOLT)	addstr("2:Magic Bolt  ");    if (Player.p_magiclvl >= ML_FORCEFIELD)	addstr("3:Force Field  ");    if (Player.p_magiclvl >= ML_XFORM)	addstr("4:Transform  ");    if (Player.p_magiclvl >= ML_INCRMIGHT)	addstr("5:Increase Might\n");    if (Player.p_magiclvl >= ML_INVISIBLE)	mvaddstr(8, 0, "6:Invisibility  ");    if (Player.p_magiclvl >= ML_XPORT)	addstr("7:Transport  ");    if (Player.p_magiclvl >= ML_PARALYZE)	addstr("8:Paralyze  ");    if (Player.p_specialtype >= SC_COUNCIL)	addstr("9:Specify");    mvaddstr(4, 0, "Spell ? ");    ch = getanswer(" ", TRUE);    mvaddstr(7, 0, "\n\n");		/* clear menu area */    if (Curmonster.m_type == SM_MORGOTH && ch != '3')	/* can only throw force field against Morgoth */	ILLSPELL();    else	switch (ch)	    {	    case '1':   /* all or nothing */		if (drandom() < 0.25)		    /* success */		    {		    inflict = Curmonster.m_energy * 1.01 + 1.0;		    if (Curmonster.m_type == SM_DARKLORD)			/* all or nothing doesn't quite work against D. L. */			inflict *= 0.9;		    }		else		    /* failure -- monster gets stronger and quicker */		    {		    Curmonster.m_o_strength = Curmonster.m_strength *= 2.0;		    Curmonster.m_maxspeed *= 2.0;		    Curmonster.m_o_speed *= 2.0;		    /* paralyzed monsters wake up a bit */		    Curmonster.m_speed = MAX(1.0, Curmonster.m_speed * 2.0);		    }		if (Player.p_mana >= MM_ALLORNOTHING)		    /* take a mana if player has one */		    Player.p_mana -= MM_ALLORNOTHING;		hitmonster(inflict);		break;	    case '2':   /* magic bolt */		if (Player.p_magiclvl < ML_MAGICBOLT)		    ILLSPELL();		else		    {		    do			/* prompt for amount to expend */			{			mvaddstr(4, 0, "How much mana for bolt? ");			dtemp = floor(infloat());			}		    while (dtemp < 0.0 || dtemp > Player.p_mana);		    Player.p_mana -= dtemp;		    if (Curmonster.m_type == SM_DARKLORD)			/* magic bolts don't work against D. L. */			inflict = 0.0;		    else			inflict = dtemp * ROLL(15.0, sqrt(Player.p_magiclvl / 3.0 + 1.0));		    mvaddstr(5, 0, "Magic Bolt fired!\n");		    hitmonster(inflict);		    }		break;	    case '3':   /* force field */		if (Player.p_magiclvl < ML_FORCEFIELD)		    ILLSPELL();		else if (Player.p_mana < MM_FORCEFIELD)		    NOMANA();		else		    {		    Player.p_mana -= MM_FORCEFIELD;		    Shield = (Player.p_maxenergy + Player.p_shield) * 4.2 + 45.0;		    mvaddstr(5, 0, "Force Field up.\n");		    }		break;	    case '4':   /* transform */		if (Player.p_magiclvl < ML_XFORM)		    ILLSPELL();		else if (Player.p_mana < MM_XFORM)		    NOMANA();		else		    {		    Player.p_mana -= MM_XFORM;		    Whichmonster = (int) ROLL(0.0, 100.0);		    longjmp(Fightenv, 0);		    /*NOTREACHED*/		    }		break;	    case '5':   /* increase might */		if (Player.p_magiclvl < ML_INCRMIGHT)		    ILLSPELL();		else if (Player.p_mana < MM_INCRMIGHT)		    NOMANA();		else		    {		    Player.p_mana -= MM_INCRMIGHT;		    Player.p_might +=			(1.2 * (Player.p_strength + Player.p_sword)			+ 5.0 - Player.p_might) / 2.0;		    mvprintw(5, 0, "New strength:  %.0f\n", Player.p_might);		    }		break;	    case '6':   /* invisible */		if (Player.p_magiclvl < ML_INVISIBLE)		    ILLSPELL();		else if (Player.p_mana < MM_INVISIBLE)		    NOMANA();		else		    {		    Player.p_mana -= MM_INVISIBLE;		    Player.p_speed +=			(1.2 * (Player.p_quickness + Player.p_quksilver)			+ 5.0 - Player.p_speed) / 2.0;		    mvprintw(5, 0, "New quickness:  %.0f\n", Player.p_speed);		    }		break;	    case '7':   /* transport */		if (Player.p_magiclvl < ML_XPORT)		    ILLSPELL();		else if (Player.p_mana < MM_XPORT)		    NOMANA();		else		    {		    Player.p_mana -= MM_XPORT;		    if (Player.p_brains + Player.p_magiclvl			< Curmonster.m_experience / 200.0 * drandom())			{			mvaddstr(5, 0, "Transport backfired!\n");			altercoordinates(0.0, 0.0, A_FAR);			cancelmonster();			}		    else			{			mvprintw(5, 0, "%s is transported.\n", Enemyname);			if (drandom() < 0.3)			    /* monster didn't drop its treasure */			    Curmonster.m_treasuretype = 0;			Curmonster.m_energy = 0.0;			}		    }		break;	    case '8':   /* paralyze */		if (Player.p_magiclvl < ML_PARALYZE)		    ILLSPELL();		else if (Player.p_mana < MM_PARALYZE)		    NOMANA();		else		    {		    Player.p_mana -= MM_PARALYZE;		    if (Player.p_magiclvl >			Curmonster.m_experience / 1000.0 * drandom())			{			mvprintw(5, 0, "%s is held.\n", Enemyname);			Curmonster.m_speed = -2.0;			}		    else			mvaddstr(5, 0, "Monster unaffected.\n");		    }		break;	    case '9':   /* specify */		if (Player.p_specialtype < SC_COUNCIL)		    ILLSPELL();		else if (Player.p_mana < MM_SPECIFY)		    NOMANA();		else		    {		    Player.p_mana -= MM_SPECIFY;		    mvaddstr(5, 0, "Which monster do you want [0-99] ? ");		    Whichmonster = (int) infloat();		    Whichmonster = MAX(0, MIN(99, Whichmonster));		    longjmp(Fightenv, 0);		    /*NOTREACHED*/		    }		break;	    }}/**//************************************************************************// FUNCTION NAME: callmonster()// FUNCTION: read monster from file, and fill structure// AUTHOR: E. A. Estes, 2/25/86// ARGUMENTS:/	int which - which monster to call// RETURN VALUE: none// MODULES CALLED: truncstring(), fread(), fseek(), floor(), drandom(), /	strcpy()// GLOBAL INPUTS: Curmonster, Circle, Player, *Monstfp// GLOBAL OUTPUTS: Curmonster, Player, *Enemyname// DESCRIPTION:/	Read specified monster from monster database and fill up/	current monster structure./	Adjust statistics based upon current size./	Handle some special monsters.//************************************************************************/callmonster(which)int	which;{struct monster	Othermonster;		/* to find a name for mimics */    which = MIN(which, 99);		/* make sure within range */    /* fill structure */    fseek(Monstfp, (long) which * (long) SZ_MONSTERSTRUCT, 0);    fread((char *) &Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp);    /* handle some special monsters */    if (Curmonster.m_type == SM_MODNAR)	{	if (Player.p_specialtype < SC_COUNCIL)	    /* randomize some stats */	    {	    Curmonster.m_strength *= drandom() + 0.5;	    Curmonster.m_brains *= drandom() + 0.5;	    Curmonster.m_speed *= drandom() + 0.5;	    Curmonster.m_energy *= drandom() + 0.5;	    Curmonster.m_experience *= drandom() + 0.5;	    Curmonster.m_treasuretype =		(int) ROLL(0.0, (double) Curmonster.m_treasuretype);	    }	else	    /* make Modnar into Morgoth */	    {	    strcpy(Curmonster.m_name, "Morgoth");	    Curmonster.m_strength = drandom() * (Player.p_maxenergy + Player.p_shield) / 1.4		+ drandom() * (Player.p_maxenergy + Player.p_shield) / 1.5;	    Curmonster.m_brains = Player.p_brains;	    Curmonster.m_energy = Player.p_might * 30.0;	    Curmonster.m_type = SM_MORGOTH;	    Curmonster.m_speed = Player.p_speed * 1.1		+ (Player.p_specialtype == SC_EXVALAR) ? Player.p_speed : 0.0;	    Curmonster.m_flock = 0.0;	    Curmonster.m_treasuretype = 0;	    Curmonster.m_experience = 0.0;	    }	}    else if (Curmonster.m_type == SM_MIMIC)	/* pick another name */	{	which = (int) ROLL(0.0, 100.0);	fseek(Monstfp, (long) which * (long) SZ_MONSTERSTRUCT, 0);	fread(&Othermonster, SZ_MONSTERSTRUCT, 1, Monstfp);	strcpy(Curmonster.m_name, Othermonster.m_name);	}    truncstring(Curmonster.m_name);    if (Curmonster.m_type != SM_MORGOTH)	/* adjust stats based on which circle player is in */	{	Curmonster.m_strength *= (1.0 + Circle / 2.0);	Curmonster.m_brains *= Circle;	Curmonster.m_speed += Circle * 1.e-9;	Curmonster.m_energy *= Circle;	Curmonster.m_experience *= Circle;	}    if (Player.p_blindness)	/* cannot see monster if blind */	Enemyname = "A monster";    else	Enemyname = Curmonster.m_name;    if (Player.p_speed <= 0.0)	/* make Player.p_speed positive */	{	Curmonster.m_speed += -Player.p_speed;	Player.p_speed = 1.0;	}

⌨️ 快捷键说明

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