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

📄 misc.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 3 页
字号:
    /* set up flags based upon location */    Throne = Marsh = Beyond = FALSE;    if (Player.p_x == 0.0 && Player.p_y == 0.0)	Throne = TRUE;    else if (Circle < 35 && Circle >= 20)	Marsh = TRUE;    else if (MAX(fabs(Player.p_x), fabs(Player.p_y)) >= D_BEYOND)	Beyond = TRUE;    Changed = TRUE;}/**//************************************************************************// FUNCTION NAME: readrecord()// FUNCTION: read a player structure from file// AUTHOR: E. A. Estes, 12/4/85// ARGUMENTS:/	struct player *playerp - pointer to structure to fill/	int loc - location of record to read// RETURN VALUE: none// MODULES CALLED: fread(), fseek()// GLOBAL INPUTS: *Playersfp// GLOBAL OUTPUTS: none// DESCRIPTION:/	Read structure information from player file.//************************************************************************/readrecord(playerp, loc)register struct player	*playerp;long	loc;{    fseek(Playersfp, loc, 0);    fread((char *) playerp, SZ_PLAYERSTRUCT, 1, Playersfp);}/**//************************************************************************// FUNCTION NAME: adjuststats()// FUNCTION: adjust player statistics// AUTHOR: E. A. Estes, 12/4/85// ARGUMENTS: none// RETURN VALUE: none// MODULES CALLED: death(), floor(), drandom(), explevel(), movelevel()// GLOBAL INPUTS: Player, *Statptr// GLOBAL OUTPUTS: Circle, Player, Timeout// DESCRIPTION:/	Handle adjustment and maximums on various player characteristics.//************************************************************************/adjuststats(){double	dtemp;				/* for temporary calculations */    if (explevel(Player.p_experience) > Player.p_level)	/* move one or more levels */	{	movelevel();	if (Player.p_level > 5.0)	    Timeout = TRUE;	}    if (Player.p_specialtype == SC_VALAR)	/* valar */	Circle = Player.p_level / 5.0;    /* calculate effective quickness */    dtemp = ((Player.p_gold + Player.p_gems / 2.0) - 1000.0) / Statptr->c_goldtote	- Player.p_level;;    dtemp = MAX(0.0, dtemp);		/* gold slows player down */    Player.p_speed = Player.p_quickness + Player.p_quksilver - dtemp;    /* calculate effective strength */    if (Player.p_poison > 0.0)	/* poison makes player weaker */	{	dtemp = 1.0 - Player.p_poison * Statptr->c_weakness / 800.0;	dtemp = MAX(0.1, dtemp);	}    else	dtemp = 1.0;    Player.p_might = dtemp *  Player.p_strength + Player.p_sword;    /* insure that important things are within limits */    Player.p_quksilver = MIN(99.0, Player.p_quksilver);    Player.p_mana = MIN(Player.p_mana,	Player.p_level * Statptr->c_maxmana + 1000.0);    Player.p_brains = MIN(Player.p_brains,	Player.p_level * Statptr->c_maxbrains + 200.0);    Player.p_charms = MIN(Player.p_charms, Player.p_level + 10.0);    /*     * some implementations have problems with floating point compare     * we work around it with this stuff     */    Player.p_gold = floor(Player.p_gold) + 0.1;    Player.p_gems = floor(Player.p_gems) + 0.1;    Player.p_mana = floor(Player.p_mana) + 0.1;    if (Player.p_ring.ring_type != R_NONE)	/* do ring things */	{	/* rest to max */	Player.p_energy = Player.p_maxenergy + Player.p_shield;        if (Player.p_ring.ring_duration <= 0)	    /* clean up expired rings */	    switch (Player.p_ring.ring_type)		{		case R_BAD:	/* ring drives player crazy */		    Player.p_ring.ring_type = R_SPOILED;		    Player.p_ring.ring_duration = (short) ROLL(10.0, 25.0);		    break;		case R_NAZREG:	/* ring disappears */		    Player.p_ring.ring_type = R_NONE;		    break;		case R_SPOILED:	/* ring kills player */		    death("A cursed ring");		    break;		case R_DLREG:	/* this ring doesn't expire */		    Player.p_ring.ring_duration = 0;		    break;		}	}    if (Player.p_age / N_AGE > Player.p_degenerated)	/* age player slightly */	{	++Player.p_degenerated;	if (Player.p_quickness > 23.0)	    Player.p_quickness *= 0.99;	Player.p_strength *= 0.97;	Player.p_brains *= 0.95;	Player.p_magiclvl *= 0.97;	Player.p_maxenergy *= 0.95;	Player.p_quksilver *= 0.95;	Player.p_sword *= 0.93;	Player.p_shield *= 0.93;	}}/**//************************************************************************// FUNCTION NAME: initplayer()// FUNCTION: initialize a character// AUTHOR: E. A. Estes, 12/4/85// ARGUMENTS:/	struct player *playerp - pointer to structure to init// RETURN VALUE: none// MODULES CALLED: floor(), drandom()// GLOBAL INPUTS: none// GLOBAL OUTPUTS: none// DESCRIPTION:/	Put a bunch of default values in the given structure.//************************************************************************/initplayer(playerp)register struct  player   *playerp;{    playerp->p_experience =    playerp->p_level =    playerp->p_strength =    playerp->p_sword =    playerp->p_might =    playerp->p_energy =    playerp->p_maxenergy =    playerp->p_shield =    playerp->p_quickness =    playerp->p_quksilver =    playerp->p_speed =    playerp->p_magiclvl =    playerp->p_mana =    playerp->p_brains =    playerp->p_poison =    playerp->p_gems =    playerp->p_sin =    playerp->p_1scratch =    playerp->p_2scratch = 0.0;    playerp->p_gold = ROLL(50.0, 75.0) + 0.1;	/* give some gold */    playerp->p_x = ROLL(-125.0, 251.0);    playerp->p_y = ROLL(-125.0, 251.0);		/* give random x, y */    /* clear ring */    playerp->p_ring.ring_type = R_NONE;    playerp->p_ring.ring_duration = 0;    playerp->p_ring.ring_inuse = FALSE;    playerp->p_age = 0L;    playerp->p_degenerated = 1;			/* don't degenerate initially */    playerp->p_type = C_FIGHTER;		/* default */    playerp->p_specialtype = SC_NONE;    playerp->p_lives =    playerp->p_crowns =     playerp->p_charms =    playerp->p_amulets =    playerp->p_holywater =    playerp->p_lastused = 0;    playerp->p_status = S_NOTUSED;    playerp->p_tampered = T_OFF;    playerp->p_istat = I_OFF;    playerp->p_palantir =    playerp->p_blessing =    playerp->p_virgin =    playerp->p_blindness = FALSE;    playerp->p_name[0] =    playerp->p_password[0] =    playerp->p_login[0] = '\0';}/**//************************************************************************// FUNCTION NAME: readmessage()// FUNCTION: read message from other players// AUTHOR: E. A. Estes, 12/4/85// ARGUMENTS: none// RETURN VALUE: none// MODULES CALLED: fseek(), fgets(), wmove(), waddstr(), wclrtoeol()// GLOBAL INPUTS: *stdscr, Databuf[], *Messagefp// GLOBAL OUTPUTS: none// DESCRIPTION:/	If there is a message from other players, print it.//************************************************************************/readmessage(){    move(3, 0);    clrtoeol();    fseek(Messagefp, 0L, 0);    if (fgets(Databuf, SZ_DATABUF, Messagefp) != NULL)	addstr(Databuf);}/**//************************************************************************// FUNCTION NAME: error()// FUNCTION: process evironment error// AUTHOR: E. A. Estes, 12/4/85// ARGUMENTS:/	char *whichfile - pointer to name of file which caused error// RETURN VALUE: none// MODULES CALLED: wclear(), cleanup()// GLOBAL INPUTS: errno, *stdscr, printw(), printf(), Windows// GLOBAL OUTPUTS: none// DESCRIPTION:/	Print message about offending file, and exit.//************************************************************************/error(whichfile)	char	*whichfile;{	int	(*funcp) __P((const char *, ...));    if (Windows)	{	funcp = printw;	clear();	}    else	funcp = printf;    (*funcp)("An unrecoverable error has occurred reading %s.  (errno = %d)\n", whichfile, errno);    (*funcp)("Please run 'setup' to determine the problem.\n");    cleanup(TRUE);    /*NOTREACHED*/}/**//************************************************************************// FUNCTION NAME: distance()// FUNCTION: calculate distance between two points// AUTHOR: E. A. Estes, 12/4/85// ARGUMENTS: /	double x1, y1 - x, y coordinates of first point/	double x2, y2 - x, y coordinates of second point// RETURN VALUE: distance between the two points// MODULES CALLED: sqrt()// GLOBAL INPUTS: none// GLOBAL OUTPUTS: none// DESCRIPTION:/	This function is provided because someone's hypot() library function/	fails if x1 == x2 && y1 == y2.//************************************************************************/doubledistance(x1, x2, y1, y2)double	x1, x2, y1, y2;{double	deltax, deltay;    deltax = x1 - x2;    deltay = y1 - y2;    return(sqrt(deltax * deltax + deltay * deltay));}/**//************************************************************************// FUNCTION NAME: ill_sig()// FUNCTION: exit upon trapping an illegal signal// AUTHOR: E. A. Estes, 12/4/85// ARGUMENTS:/	int whichsig - signal which occured to cause jump to here// RETURN VALUE: none// MODULES CALLED: wclear(), printw(), cleanup()// GLOBAL INPUTS: *stdscr// GLOBAL OUTPUTS: none// DESCRIPTION:/	When an illegal signal is caught, print a message, and cleanup.//************************************************************************/ill_sig(whichsig)int whichsig;{    clear();    if (!(whichsig == SIGINT || whichsig == SIGQUIT))	printw("Error: caught signal # %d.\n", whichsig);    cleanup(TRUE);    /*NOTREACHED*/}/**//************************************************************************// FUNCTION NAME: descrstatus()// FUNCTION: return a string describing the player status// AUTHOR: E. A. Estes, 3/3/86// ARGUMENTS:/	struct player playerp - pointer to player structure to describe// RETURN VALUE: string describing player's status// MODULES CALLED: none// GLOBAL INPUTS: none// GLOBAL OUTPUTS: none// DESCRIPTION:/	Return verbal description of player status./	If player status is S_PLAYING, check for low energy and blindness.//************************************************************************/char	*descrstatus(playerp)register struct player	*playerp;{    switch (playerp->p_status)	{	case S_PLAYING:	    if (playerp->p_energy < 0.2 * (playerp->p_maxenergy + playerp->p_shield))		return("Low Energy");	    else if (playerp->p_blindness)		return("Blind");	    else		return("In game");	case S_CLOAKED:	    return("Cloaked");	case S_INBATTLE:	    return("In Battle");	case S_MONSTER:	    return("Encounter");	case S_TRADING:	    return("Trading");	case S_OFF:	    return("Off");	case S_HUNGUP:	    return("Hung up");	default:	    return("");	}}/**//************************************************************************// FUNCTION NAME: drandom()// FUNCTION: return a random floating point number from 0.0 < 1.0// AUTHOR: E. A. Estes, 2/7/86// ARGUMENTS: none// RETURN VALUE: none// MODULES CALLED: random()// GLOBAL INPUTS: none// GLOBAL OUTPUTS: none// DESCRIPTION:/	Convert random integer from library routine into a floating/	point number, and divide by the largest possible random number./	We mask large integers with 32767 to handle sites that return/	31 bit random integers.//************************************************************************/doubledrandom(){    if (sizeof(int) != 2)	/* use only low bits */	return((double) (random() & 0x7fff) / 32768.0);    else	return((double) random() / 32768.0);}/**//************************************************************************// FUNCTION NAME: collecttaxes()// FUNCTION: collect taxes from current player// AUTHOR: E. A. Estes, 2/7/86// ARGUMENTS:/	double gold - amount of gold to tax/	double gems - amount of gems to tax// RETURN VALUE: none// MODULES CALLED: fread(), fseek(), fopen(), floor(), fwrite(), fclose()// GLOBAL INPUTS: Player// GLOBAL OUTPUTS: Player// DESCRIPTION:/	Pay taxes on gold and gems.  If the player does not have enough/	gold to pay taxes on the added gems, convert some gems to gold./	Add taxes to tax data base; add remaining gold and gems to/	player's cache.//************************************************************************/collecttaxes(gold, gems)double	gold;double	gems;{FILE	*fp;		/* to update Goldfile */double	dtemp;		/* for temporary calculations */double	taxes;		/* tax liability */    /* add to cache */    Player.p_gold += gold;    Player.p_gems += gems;    /* calculate tax liability */    taxes = N_TAXAMOUNT / 100.0 * (N_GEMVALUE * gems + gold);    if (Player.p_gold < taxes)	/* not enough gold to pay taxes, must convert some gems to gold */	{	dtemp = floor(taxes / N_GEMVALUE + 1.0); /* number of gems to convert */	if (Player.p_gems >= dtemp)	    /* player has enough to convert */	    {	    Player.p_gems -= dtemp;	    Player.p_gold += dtemp * N_GEMVALUE;	    }	else	    /* take everything; this should never happen */	    {	    Player.p_gold += Player.p_gems * N_GEMVALUE;	    Player.p_gems = 0.0;	    taxes = Player.p_gold;	    }	}    Player.p_gold -= taxes;    if ((fp = fopen(_PATH_GOLD, "r+")) != NULL)	/* update taxes */	{	dtemp = 0.0;	fread((char *) &dtemp, sizeof(double), 1, fp);	dtemp += floor(taxes);	fseek(fp, 0L, 0);	fwrite((char *) &dtemp, sizeof(double), 1, fp);	fclose(fp);	}}

⌨️ 快捷键说明

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