Phantasia (part 2 of 3)

8-01-83"Edward E 9723i estes at tty3b.UUCP
Sat Sep 8 08:13:50 AEST 1984


----------CUT-----------CUT------------CUT------------CUT---------CUT--------
: This is a shar archieve.  Extract with sh, not csh.
: The rest of this file will extract:
: func0.c func1.c
echo extracting - func0.c
sed 's/^X//' > func0.c << '!EOR!'
X/*
X * func0.c	Phantasia support routines
X */
X
X#include "phant.h"
X
Xvoid	treasure(stat,treastyp,size)		/* select a treasure */
Xreg	struct	stats	*stat;
Xshort	treastyp;
Xreg	int	size;
X{
Xreg	int	which;
Xint	ch;
Xdouble	temp, temp2;
Xchar	aline[35];
XFILE	*fp;
X
X	which = roll(1,3);
X	move(3,0);
X	clrtobot();
X	move(5,0);
X	if (rnd() > 0.65)	/* gold and gems */
X		if (treastyp > 7)	/* gems */
X			{
X			temp = roll(1,(treastyp - 7)*(treastyp - 7)*(size - 1)/4);
X			printw("You have discovered %.0f gems!  Will you pick them up ? ",temp);
X			ch = rgetch();
X			addch('\n');
X			if (toupper(ch) == 'Y')
X				if (rnd() < treastyp/40 + 0.05)	/* cursed */
X					{
X					addstr("They were cursed!\n");
X					goto CURSE;
X					}
X				else
X					stat->gem += temp;
X			return;
X			}
X		else	/* gold */
X			{
X			temp = roll(treastyp*10,treastyp*treastyp*10*(size - 1));
X			printw("You have found %.0f gold pieces.  Do you want to pick them up ? ",temp);
X			ch = rgetch();
X			addch('\n');
X			if (toupper(ch) == 'Y')
X				if (rnd() < treastyp/35 + 0.04)	/* cursed */
X					{
X					addstr("They were cursed!\n");
X					goto CURSE;
X					}
X				else
X					{
X					stat->gld += floor(0.9 * temp);
X					fp = fopen(goldfile,"r");
X					fread((char *) &temp2,sizeof(double),1,fp);
X					fclose(fp);
X					fp = fopen(goldfile,"w");
X					temp2 += floor(temp/10);
X					fwrite((char *) &temp2,sizeof(double),1,fp);
X					fclose(fp);
X					}
X			return;
X			}
X	else	/* other treasures */
X		{
X		addstr("You have found some treasure.  Do you want to inspect it ? ");
X		ch = rgetch();
X		addch('\n');
X		if (toupper(ch) != 'Y')
X			return;
X		else
X			if (rnd() < 0.08 && treastyp != 4)
X				{
X				addstr("It was cursed!\n");
X				goto CURSE;
X				}
X			else
X				switch(treastyp)
X					{
X					case 1:
X						switch(which)
X							{
X							case 1:
X								addstr("You've discovered a power booster!\n");
X								stat->man += roll(size*4,size*30);
X								break;
X							case 2:
X								addstr("You have encountered a druid.\n");
X								stat->exp += roll(0,2000 + size*400);
X								break;
X							case 3:
X								addstr("You have found a holy orb.\n");
X								stat->sin = max(0,stat->sin - 0.25);
X								break;
X							}
X						break;
X					case 2:
X						switch (which)
X							{
X							case 1:
X								addstr("You have found an amulet.\n");
X								++stat->amu;
X								break;
X							case 2:
X								addstr("You've found some holy water!\n");
X								++stat->hw;
X								break;
X							case 3:
X								addstr("You've met a hermit!\n");
X								stat->sin *= 0.75;
X								stat->man += 12*size;
X								break;
X							}
X						break;
X					case 3:
X						switch (which)
X							{
X							case 1:
X								temp = roll(7,30 + size/10);
X								printw("You've found a +%.0f shield!\n",temp);
X								if (temp >= stat->shd)
X									stat->shd = temp;
X								else
X									somebetter();
X								break;
X							case 2:
X								addstr("You have rescued a virgin.  Will you be honorable ? ");
X								ch = rgetch();
X								if (toupper(ch) == 'Y')
X									stat->vrg = TRUE;
X								else
X									{
X									stat->exp += 2000*size;
X									++stat->sin;
X									}
X								break;
X							case 3:
X								addstr("You've discovered some athelas!\n");
X								--stat->psn;
X								break;
X							}
X						break;
X					case 4:
X						addstr("You've found a scroll.  Will you read it ? ");
X						ch = rgetch();
X						addch('\n');
X						if (toupper(ch) == 'Y')
X							switch ((int) roll(1,6))
X								{
X								case 1:
X									addstr("It throws up a shield for you next monster.\n");
X									paws(8);
X									longjmp(fightenv,2);
X									/*NOTREACHED*/
X								case 2:
X									addstr("It makes you invisible for you next monster.\n");
X									paws(8);
X									speed = 1e6;
X									longjmp(fightenv,0);
X									/*NOTREACHED*/
X								case 3:
X									addstr("It increases your strength ten fold to fight your next monster.\n");
X									paws(8);
X									strength *= 10;
X									longjmp(fightenv,0);
X									/*NOTREACHED*/
X								case 4:
X									addstr("It is a general knowledge scroll.\n");
X									stat->brn += roll(2,size);
X									stat->mag += roll(1,size/2);
X									break;
X							case 5:
X								addstr("It tells you how to pick your next monster.\n");
X								addstr("Which monster do you want [0-99] ? ");
X								which = inflt();
X								which = min(99,max(0,which));
X								fight(stat,which);
X								break;
X							case 6:
X								addstr("It was cursed!\n");
X								goto CURSE;
X							}
X						break;
X					case 5:
X						switch (which)
X							{
X							case 1:
X								temp = roll(size/4+5,size/2 + 9);
X								printw("You've discovered a +%.0f dagger.\n",temp);
X								if (temp >= stat->swd)
X									stat->swd = temp;
X								else
X									somebetter();
X								break;
X							case 2:
X								temp = roll(7.5 + size*3,size * 2 + 160);
X								printw("You have found some +%.0f armour!\n",temp);
X								if (temp >= stat->shd)
X									stat->shd = temp;
X								else
X									somebetter();
X								break;
X							case 3:
X								addstr("You've found a tablet.\n");
X								stat->brn += 4.5*size;
X								break;
X							}
X						break;
X					case 6:
X						switch (which)
X							{
X							case 1:
X								addstr("You've found a priest.\n");
X								stat->nrg = stat->mxn + stat->shd;
X								stat->sin /= 2;
X								stat->man += 24*size;
X								stat->brn += size;
X								break;
X							case 2:
X								addstr("You have come upon Robin Hood!\n");
X								stat->shd += size*2;
X								stat->str += size/2.5 + 1;
X								break;
X							case 3:
X									temp = roll(2 + size/4,size/1.2 + 10);
X								printw("You have found a +%.0f axe!\n",temp);
X								if (temp >= stat->swd)
X									stat->swd = temp;
X								else
X									somebetter();
X								break;
X							}
X						break;
X					case 7:
X						switch (which)
X							{
X							case 1:
X								addstr("You've discovered a charm!\n");
X								++stat->chm;
X								break;
X							case 2:
X								addstr("You have encountered Merlyn!\n");
X								stat->brn += size + 5;
X								stat->mag += size/3 + 5;
X								stat->man += size*10;
X								break;
X							case 3:
X								temp = roll(5+size/3,size/1.5 + 20);
X								printw("You have found a +%.0f war hammer!\n",temp);
X								if (temp >= stat->swd)
X									stat->swd = temp;
X								else
X									somebetter();
X								break;
X							}
X						break;
X					case 8:
X						switch (which)
X							{
X							case 1:
X								addstr("You have found a healing potion.\n");
X								stat->psn = min(-2,stat->psn-2);
X								break;
X							case 2:
X								addstr("You have discovered a transporter.  Do you wish to go anywhere ? ");
X								ch = rgetch();
X								addch('\n');
X								if (toupper(ch) == 'Y')
X									{
X									addstr("X Y Coordinates ? ");
X									getstring(aline,80);
X									sscanf(aline,"%F %F",&stat->x,&stat->y);
X									stat->x = floor(stat->x);
X									stat->y = floor(stat->y);
X									}
X								break;
X							case 3:
X								temp = roll(10 + size/1.2,size*3 + 30);
X								printw("You've found a +%.0f sword!\n",temp);
X								if (temp >= stat->swd)
X									stat->swd = temp;
X								else
X									somebetter();
X								break;
X							}
X						break;
X					case 10:
X					case 11:
X					case 12:
X					case 13:
X						if (rnd() < 0.33)
X							{
X							if (treastyp == 10)
X								{
X								addstr("You've found a pair of elven boots!\n");
X								stat->quk += 2;
X								break;
X								}
X							else if (treastyp == 11 && !stat->pal)
X								{
X								addstr("You've acquired Saruman's palantir.\n");
X								stat->pal = TRUE;
X								break;
X								}
X							else if (!stat->rng.type && stat->typ < 20 && (treastyp == 12 || treastyp == 13))
X								{
X								if (treastyp == 12)
X									if (rnd() < 0.8)
X										{
X										which = NAZREG;
X										temp = 15;
X										}
X									else
X										{
X										which = NAZBAD;
X										temp = 10 + rngcalc(stat->typ) + roll(0,5);
X										}
X								else
X									if (rnd() > 0.9)
X										{
X										which = DLREG;
X										temp = 0;
X										}
X									else
X										{
X										which = DLBAD;
X										temp = 15 + rngcalc(stat->typ) + roll(0,5);
X										}
X									addstr("You've discovered a ring.  Will you pick it up ? ");
X									ch = rgetch();
X									addch('\n');
X									if (toupper(ch) == 'Y')
X										{
X										stat->rng.type = which;
X										stat->rng.duration = temp;
X										}
X								}
X							break;
X							}
X						case 9:
X							switch (which)
X								{
X								case 1:
X									if (!(stat->lvl > 1000 || stat->crn > floor((double) stat->lvl/100)
X											|| stat->lvl < 10))
X										{
X										addstr("You have found a golden crown!\n");
X										++stat->crn;
X										break;
X										}
X								case 2:
X									addstr("You've been blessed!\n");
X									stat->bls = TRUE;
X									stat->sin /=3;
X									stat->nrg = stat->mxn + stat->shd;
X									stat->man += 100*size;
X									break;
X								case 3:
X									temp = roll(1,size/5+5);
X									temp = min(temp,99);
X									printw("You have discovered some +%.0f quicksilver!\n",temp);
X									if (temp >= stat->quks)
X										stat->quks = temp;
X									else
X										somebetter();
X									break;
X								}
X							break;
X						}
X		refresh();
X		return;
X		}
XCURSE:	if (stat->chm)
X		{
X		addstr("But your charm saved you!\n");
X		--stat->chm;
X		}
X	else if (stat->amu)
X		{
X		addstr("But your amulet saved you!\n");
X		--stat->amu;
X		}
X	else
X		{
X		stat->nrg = (stat->mxn + stat->shd)/10;
X		stat->psn += 0.25;
X		}
X}
X
Xvoid	callmonster(which,size,mons)		/* fill a structure with monster 'which' of size 'size' */
Xreg	int	which, size;
Xreg	struct	mstats	*mons;
X{
XFILE	*fp;
Xchar	instr[100];
X
X	which = min(which,99);
X	fp = fopen(monsterfile,"r");
X	for (++which; which; --which)
X		fgets(instr,100,fp);
X	strncpy(mons->name,instr,24);
X	mons->name[24] = '\0';
X	sscanf(instr + 24,"%F%F%F%F%F%d%d%d",&mons->str,&mons->brn,&mons->spd,&mons->hit,
X		&mons->exp,&mons->trs,&mons->typ,&mons->flk);
X	if (mons->typ == 2)	/* Modnar */
X		{
X		mons->str *= rnd() + 0.5;
X		mons->brn *= rnd() + 0.5;
X		mons->spd *= rnd() + 0.5;
X		mons->hit *= rnd() + 0.5;
X		mons->exp *= rnd() + 0.5;
X		mons->trs *= rnd();
X		}
X	else if (mons->typ == 3)	/* mimic */
X		{
X		fseek(fp,0L,0);
X		for (which = roll(0,100); which; --which)
X			fgets(instr,100,fp);
X		strncpy(mons->name,instr,24);
X		}
X	trunc(mons->name);
X	mons->str += (size-1)*mons->str/2;
X	mons->brn *= size;
X	mons->spd += size * 1.e-9;
X	mons->hit *= size;
X	mons->exp *= size;
X	fclose(fp);
X}
X
Xstruct	/* lookup table for rolling stats and making increases upon gaining levels */
X	{
X	struct
X		{
X		int	base;
X		int	interval;
X		float	increase;
X		} quick,      strength,      manna,	    energy,	   brains,	  magic;
X	} table[7] =
X		{
X/* mag. usr: */ 30, 6, 0.0,   20, 6, 2.0,    50,51,75.0,    30,16,20.0,    60,26, 6.0,	  5, 5,2.75,
X/* fighter:  */ 30, 6, 0.0,   40,16, 3.0,    30,21,40.0,    45,26,30.0,    25,21, 3.0,	  3, 4, 1.5,
X/* elf:      */ 32, 7, 0.0,   35,11, 2.5,    45,46,65.0,    30,21,25.0,    40,26, 4.0,	  4, 4, 2.0,
X/* dwarf:    */ 25, 6, 0.0,   45,21, 5.0,    25,21,30.0,    60,41,35.0,    20,21, 2.5,	  2, 4, 1.0,
X/* halfling: */ 34, 0, 0.0,   20, 6, 2.0,    25,21,30.0,    55,36,30.0,    40,36, 4.5,	  1, 4, 1.0,
X/* exprmnto: */ 27, 0, 0.0,   25, 0, 0.0,    100,0, 0.0,    35, 0, 0.0,    25, 0, 0.0,	  2, 0, 0.0,
X/* super:    */ 38, 0, 0.0,   65, 0, 0.0,    100,0, 0.0,    80, 0, 0.0,    85, 0, 0.0,	  9, 0, 0.0
X		};
X
Xvoid	genchar(res,type)				/* init a charac struct */
Xint	type;
Xreg	struct	stats	*res;
X{
Xregister int	subscript;
X
X	if (type < '1' || type > '6')
X		if (type != '7' || !su)
X			type = '2';	/* fighter is default */
X	subscript = type - '1';
X	res->quk = roll(table[subscript].quick.base,table[subscript].quick.interval);
X	res->str = roll(table[subscript].strength.base,table[subscript].strength.interval);
X	res->man = roll(table[subscript].manna.base,table[subscript].manna.interval);
X	res->mxn = res->nrg = roll(table[subscript].energy.base,table[subscript].energy.interval);
X	res->brn = roll(table[subscript].brains.base,table[subscript].brains.interval);
X	res->mag = roll(table[subscript].magic.base,table[subscript].magic.interval);
X	res->typ = subscript;
X	if (subscript < 6)
X		++res->typ;
X	if (type == '5')
X		res->exp = roll(600,200);	/* give halfling some exp. */
X}
X
Xvoid	movelvl(stat)				/* update stats for new level */
Xreg	struct	stats	*stat;
X{
Xreg	int	type;
Xreg	unsigned new;
Xdouble	inc;
X
X	changed = TRUE;
X	type = abs(stat->typ);
X	if (type < 6)
X		;	/* normal */
X	else if (type < 10)
X		type = roll(1,5);	/* experimento */
X	else if (type < 20)
X		{
X		type -= 10;	/* king */
X		if (type > 5)
X			type = roll(1,5);	/* experimento */
X		}
X	else if (type < 26)
X		type -= 20;	/* council of wise */
X	else
X		type = roll(1,5);	/* everything else */
X	new = level(stat->exp);
X	inc = new - stat->lvl;
X	--type; 		/* set up for subscripting into table */
X	stat->str += table[type].strength.increase * inc;
X	stat->man += table[type].manna.increase * inc;
X	stat->brn += table[type].brains.increase * inc;
X	stat->mag += table[type].magic.increase * inc;
X	stat->mxn += table[type].energy.increase * inc;
X	stat->nrg = stat->mxn + stat->shd;
X	if ((stat->lvl = min(10000,new)) >= 1000)
X		{	/* no longer able to be king */
X		stat->gld += stat->crn * 5000;
X		stat->crn = 0;
X		stat->typ = abs(stat->typ);
X		}
X	if (stat->lvl >= 3000 && stat->typ < 20)
X		{	/* make a member of the council */
X		mvaddstr(6,0,"You have made it to the Council of the Wise.\nGood Luck on your search for the Holy Grail.\n");
X		stat->rng.type = 0;
X		stat->rng.duration = 3;
X		stat->typ = abs(stat->typ) + (stat->typ > 10 ? 10 :20);
X		}
X}
X
Xchar	*printloc(x,y)			/* return a pointer to a string specifying location */
Xdouble	x,y;		/* also, set some global flags */
X{
Xreg	int	size, loc;
Xreg	char	*label;
Xstatic	char	res[80],
X		*nametable[4][4] =	 /* names of places */
X		{
X		"Anorien",	"Ithilien",	"Rohan",	"Lorien",
X		"Gondor",	"Mordor",	"Dunland",	"Rovanion",
X		"South Gondor", "Khand",	"Eriador",	"The Iron Hills",
X		"Far Harad",	"Near Harad",	"The Northern Waste", "Rhun"
X		};
X
X	throne = beyond = marsh = FALSE;
X	if (wmhl)
X		return (strcpy(res," is in the Wormholes"));
X	else if (valhala)
X		return (strcpy(res," is in Valhala"));
X	else if ((size = circ(x,y)) >= 1000)
X		{
X		if (max(abs(x),abs(y)) > 1100000)
X			{
X			label = "The Point of No Return";
X			beyond = TRUE;
X			}
X		else
X			label = "The Ashen Mountains";
X		}
X	else if (size >= 55)
X		label = "Morannon";
X	else if (size >= 35)
X		label = "Kennaquahair";
X	else if (size >= 20)
X		{
X		label = "The Dead Marshes";
X		marsh = TRUE;
X		}
X	else if (size >= 9)
X		label = "The Outer Waste";
X	else if (size >= 5)
X		label = "The Moors Adventurous";
X	else
X		{
X		if (!x && !y)
X			{
X			label = "The Lord's Chamber";
X			throne = TRUE;
X			}
X		else
X			{
X			loc = (x > 0) + 2 * (y >= 0);
X			label = nametable[size-1][loc];
X			}
X		}
X	sprintf(res," is in %s  (%.0f,%.0f)",label,x,y);
X	return (res);
X}
X
Xvoid	initchar(stat)				/* put in some default values */
Xreg	struct	stats	*stat;
X{
X	stat->x = roll(-125,251);
X	stat->y = roll(-125,251);
X	stat->exp = stat->lvl = stat->sin = 0;
X	stat->crn = stat->psn = 0;
X	stat->rng.type = NONE;
X	stat->rng.duration = 0;
X	stat->blind = stat->vrg = stat->pal = FALSE;
X	stat->hw = stat->amu = stat->bls = 0;
X	stat->chm = 0;
X	stat->gem = 0.1;
X	stat->gld = roll(25,50) + roll(0,25) + 0.1;
X	stat->quks = stat->swd = stat->shd = 0;
X	stat->typ = 0;
X	stat->status = stat->tampered = OFF;
X	stat->scratch1 = stat->scratch2 = 0.0;
X	stat->wormhole = 0;
X	stat->age = 0;
X	stat->degen = 1;
X}
X
Xvoid	trade(stat)				/* trading post */
Xreg	struct	stats	*stat;
X{
Xstatic	struct
X		{
X		char	*item;
X		int	cost;
X		}	menu[] =
X			{
X			"Manna",1,
X			"Shield",5,
X			"Book",200,
X			"Sword",500,
X			"Charm",1000,
X			"Quiksilver",2500,
X			"Blessing",7000,
X			"Gem",1000	/* this is only to ease changing the value of gems */
X			};
Xdouble	temp;
Xint	ch;
Xreg	int	size, loop;
Xbool	cheat = FALSE;
X
X	changed = TRUE;
X	clear();
X	addstr("You are at a trading post. All purchases must be made with gold.");
X	size = sqrt(abs(stat->x/100)) + 1;
X	size = min(7,size);
X	mvprintw(4,0,"L:Leave  P:Purchase  S:Sell Gems ? ");
X	move(6,0);
X	for (loop = 0; loop < size; ++loop)
X		printw("(%d) %-10s: %6d\n",loop+1,menu[loop].item,menu[loop].cost);
XPROMPT:	mvprintw(1,0,"Gold:  %9.0f  Gems:  %9.0f  Level:   %6u  Charms: %6d\n",stat->gld,stat->gem,stat->lvl,stat->chm);
X	printw("Shield:%9.0f  Sword: %9.0f  Quicksilver:%3d  Blessed: %s",
X		stat->shd,stat->swd,stat->quks,(stat->bls ? " True" : "False"));
X	move(4,36);
X	ch = rgetch();
X	move(15,0);
X	clrtobot();
X	switch(toupper(ch))
X		{
X		case 'L':
X		case '\n':
X			stat->x -= floor(stat->x/10);
X			stat->y -= floor(stat->y/10);
X			return;
X		case 'P':
X			mvaddstr(15,0,"What what would you like to buy ? ");
X			ch = rgetch();
X			move(15,0);
X			clrtoeol();
X			if (ch - '0' > size)
X				addstr("Sorry, this merchant doesn't have that.");
X			else
X				switch (toupper(ch))
X					{
X					case '1':
X						printw("Manna is one per %d gold piece.  How many do you want (%.0f max) ? ",menu[0].cost,floor(stat->gld/menu[0].cost));
X						temp = inflt();
X						if (temp * menu[0].cost > stat->gld || temp < 0)
X							goto CHEAT;
X						else
X							{
X							stat->gld -= floor(temp) * menu[0].cost;
X							if (rnd() < 0.02)
X								goto DISHON;
X							else
X								stat->man += floor(temp);
X							}
X						break;
X					case '2':
X						printw("Shields are %d per +1.  How many do you want (%.0f max) ? ",menu[1].cost,floor(stat->gld/menu[1].cost));
X						temp = inflt();
X						if (!temp)
X							break;
X						if (temp * menu[1].cost > stat->gld || temp < 0)
X							goto CHEAT;
X						else
X							{
X							stat->gld -= floor(temp) * menu[1].cost;
X							if (rnd() < 0.02)
X								goto DISHON;
X							else
X								stat->shd = floor(temp);
X							}
X						break;
X					case '3':
X						printw("A book costs %d gp.  How many do you want (%.0f max) ? ",menu[2].cost,floor(stat->gld/menu[2].cost));
X						temp = inflt();
X						if (temp * menu[2].cost > stat->gld || temp < 0)
X							goto CHEAT;
X						else
X							{
X							stat->gld -= floor(temp) * menu[2].cost;
X							if (rnd() < 0.02)
X								goto DISHON;
X							else
X								if (rnd()*temp > stat->lvl/10 && temp != 1)
X									{
X									printw("\nYou blew your mind!\n");
X									stat->brn /= 5;
X									}
X								else
X									stat->brn += floor(temp)*roll(25,10);
X							}
X						break;
X					case '4':
X						printw("Swords are %d gp per +1.  How many + do you want (%.0f max) ? ",menu[3].cost,floor(stat->gld/menu[3].cost));
X						temp = inflt();
X						if (!temp)
X							break;
X						if (temp * menu[3].cost > stat->gld || temp < 0)
X							goto CHEAT;
X						else
X							{
X							stat->gld -= floor(temp) * menu[3].cost;
X							if (rnd() < 0.02)
X								goto DISHON;
X							else
X								stat->swd = floor(temp);
X							}
X						break;
X					case '5':
X						printw("A charm costs %d gp.  How many do you want (%.0f max) ? ",menu[4].cost,floor(stat->gld/menu[4].cost));
X						temp = inflt();
X						if (temp * menu[4].cost > stat->gld || temp < 0)
X							goto CHEAT;
X						else
X							{
X							stat->gld -= floor(temp) * menu[4].cost;
X							if (rnd() < 0.02)
X								goto DISHON;
X							else
X								stat->chm += floor(temp);
X							}
X						break;
X					case '6':
X						printw("Quicksilver is %d gp per +1.  How many + do you want (%.0f max) ? ",menu[5].cost,floor(stat->gld/menu[5].cost));
X						temp = inflt();
X						if (!temp)
X							break;
X						if (temp * menu[5].cost > stat->gld || temp < 0)
X							goto CHEAT;
X						else
X							{
X							stat->gld -= floor(temp) * menu[5].cost;
X							if (rnd() < 0.02)
X								goto DISHON;
X							else
X								stat->quks = min(99,floor(temp));
X							}
X						break;
X					case '7':
X						printw("A blessing requires a %d gp donation.  Still want one ? ",menu[6].cost);
X						ch = rgetch();
X						if (toupper(ch) == 'Y')
X							if (stat->gld < menu[6].cost)
X								goto CHEAT;
X							else
X								{
X								stat->gld -= menu[6].cost;
X								if (rnd() < 0.02)
X									goto DISHON;
X								else
X									stat->bls = TRUE;
X								}
X						break;
X					}
X			break;
X		case 'S':
X			mvprintw(15,0,"A gem is worth %d gp.  How many do you want to sell (%.0f max) ? ",menu[7].cost,stat->gem);
X			temp = inflt();
X			if (temp > stat->gem || temp < 0)
X				goto CHEAT;
X			else
X				{
X				stat->gem -= floor(temp);
X				stat->gld += floor(temp) * menu[7].cost;
X				}
X		}
X	goto PROMPT;
X
XCHEAT:	move(17,0);
X	if (!cheat)
X		{
X		addstr("Come on, merchants aren't stupid.  Stop cheating.\n");
X		cheat = TRUE;
X		goto PROMPT;
X		}
X	else
X		{
X		addstr("You had your chance.  This merchant happens to be\n");
X		printw("a %.0f level magic user, and you made %s mad!\n",roll(size*10,size*20),(rnd() < 0.5) ? "him" : "her");
X		stat->x += roll(-250,500)*size;
X		stat->y += roll(-250,500)*size;
X		stat->nrg = min(size*20,stat->mxn);
X		++stat->sin;
X		paws(23);
X		}
X	return;
X
XDISHON:	mvaddstr(17,0,"The merchant stole your money!");
X	refresh();
X	stat->x -= floor(stat->x/10);
X	stat->y -= floor(stat->y/10);
X	sleep(2);
X}
X
Xvoid	printstats(stat)				/* show characteristics */
Xreg	struct	stats	*stat;
X{
X	mvprintw(0,0,"%s%s\n",stat->name,printloc(stat->x,stat->y));
X	mvprintw(1,0,"Level :%7u   Energy  :%9.0f(%9.0f)  Manna:%9.0f  Users:%3d\n",
X		stat->lvl,stat->nrg,stat->mxn + stat->shd,stat->man,users);
X	mvprintw(2,0,"Quick :%3.0f(%3d)  Strength:%9.0f(%9.0f)  Gold :%9.0f    ",
X		speed,stat->quk + stat->quks,strength,stat->str + stat->swd,stat->gld);
X	switch (stat->status)
X		{
X		case PLAYING:
X			if (stat->nrg < 0.2 * (stat->mxn + stat->shd))
X				addstr("Low Energy\n");
X			else if (stat->blind)
X				addstr("Blind\n");
X			else
X				clrtoeol();
X			break;
X		case CLOAKED:
X			addstr("Cloaked\n");
X			break;
X		case INBATTLE:
X			addstr("In Battle\n");
X			break;
X		case OFF:
X			addstr("Off\n");
X		}
X}
X
Xvoid	showall(stat)				/* show special items */
Xreg	struct	stats	*stat;
X{
Xstatic	char	*flags[] =
X			{
X			"False",
X			" True"
X			};
X
X	mvprintw(6,0,"Type: %3d  --  ",stat->typ);
X	switch (abs(stat->typ))
X		{
X		case 1:
X		case 11:
X		case 21:
X			addstr("Magic User");
X			break;
X		case 2:
X		case 12:
X		case 22:
X			addstr("Fighter");
X			break;
X		case 3:
X		case 13:
X		case 23:
X			addstr("Elf");
X			break;
X		case 4:
X		case 14:
X		case 24:
X			addstr("Dwarf");
X			break;
X		case 5:
X		case 15:
X		case 25:
X			addstr("Halfling");
X			break;
X		case 6:
X		case 16:
X		case 26:
X			addstr("Experimento");
X			break;
X		case 90:
X			addstr("Ex-Valar");
X			break;
X		case 99:
X			addstr("Valar");
X		}
X	if (stat->typ > 10 && stat->typ < 90)
X		if (stat->typ > 20)
X			addstr(" (Council of Wise)");
X		else
X			addstr(" (King)");
X		addch('\n');
X	mvprintw(7,0,"Experience: %9.0f",stat->exp);
X	mvprintw(8,0,"Brains    : %9.0f",stat->brn);
X	mvprintw(9,0,"Magic Lvl : %9.0f",stat->mag);
X	mvprintw(10,0,"Sin       : %9.5f",stat->sin);
X	mvprintw(11,0,"Poison    : %9.5f",stat->psn);
X	mvprintw(12,0,"Gems      : %9.0f",stat->gem);
X	mvprintw(13,0,"Age       : %9d",stat->age);
X	mvprintw(7,40,"Holy Water: %9d",stat->hw);
X	mvprintw(8,40,"Amulets   : %9d",stat->amu);
X	mvprintw(9,40,"Charms    : %9d",stat->chm);
X	mvprintw(10,40,"Crowns    : %9d",stat->crn);
X	mvprintw(11,40,"Shield    : %9.0f",stat->shd);
X	mvprintw(12,40,"Sword     : %9.0f",stat->swd);
X	mvprintw(13,40,"Quickslver: %9d",stat->quks);
X
X	mvprintw(14,0,"Blessing: %s   Ring: %s   Virgin: %s   Palantir: %s",
X		flags[stat->bls],flags[stat->rng.type != 0],flags[stat->vrg],flags[stat->pal]);
X}
X
Xvoid	neatstuff(stat) 			/* random things */
Xreg	struct	stats	*stat;
X{
Xdouble	temp;
Xint	ch;
X
X	switch ((int) roll(0,100))
X		{
X		case 1:
X		case 2:
X			if (stat->psn > 0)
X				{
X				mvaddstr(5,0,"You've found a medic!  How much will you offer to be cured ? ");
X				temp = inflt();
X				if (temp < 0 || temp > stat->gld)
X					{
X					mvaddstr(6,0,"He was not amused, and made you worse.\n");
X					++stat->psn;
X					}
X				else if (rnd()/2.0 > (temp + 1)/max(stat->gld,1))
X					mvaddstr(6,0,"Sorry, he wasn't interested.\n");
X				else
X					{
X					mvaddstr(6,0,"He accepted.");
X					stat->psn = max(0,stat->psn-1);
X					stat->gld -= floor(temp);
X					}
X				}
X			break;
X		case 3:
X			mvaddstr(6,0,"You've been caught raping and pillaging!\n");
X			stat->exp += 4000;
X			stat->sin += 0.5;
X			break;
X		case 4:
X			temp = roll(6,50);
X			mvprintw(5,0,"You've found %.0f gold pieces, want them ? ",temp);
X			clrtoeol();
X			ch = rgetch();
X			if (toupper(ch) == 'Y')
X				stat->gld += temp;
X			break;
X		case 5:
X			if (stat->sin > 1)
X				{
X				mvaddstr(6,0,"You've found a Holy Orb!\n");
X				stat->sin -= 0.25;
X				}
X			break;
X		case 6:
X			if (stat->psn < 1)
X				{
X				mvaddstr(6,0,"You've been hit with a plague!\n");
X				++stat->psn;
X				}
X			break;
X		case 7:
X			mvaddstr(6,0,"You've found some holy water.\n");
X			++stat->hw;
X			break;
X		case 8:
X			mvaddstr(6,0,"You've met a Guru. . .");
X			if (rnd()*stat->sin > 1)
X				addstr("You disgusted him with your sins!\n");
X			else if (stat->psn > 0)
X				{
X				addstr("He looked kindly upon you, and cured you.\n");
X				stat->psn = 0;
X				}
X			else
X				{
X				addstr("He rewarded you for your virtue.\n");
X				stat->man += 50;
X				stat->shd += 2;
X				}
X			break;
X		case 9:
X			mvaddstr(6,0,"You've found an amulet.\n");
X			++stat->amu;
X			break;
X		case 10:
X			if (stat->blind)
X				{
X				mvaddstr(6,0,"You've regained your sight!\n");
X				stat->blind = FALSE;
X				}
X			break;
X		default:
X			if (stat->psn > 0)
X				stat->nrg -= min(stat->psn*stat->mxn/45,0.9*stat->mxn);
X			stat->nrg = max(stat->nrg,floor(stat->mxn/11));
X		}
X}
!EOR!
echo extracting - func1.c
sed 's/^X//' > func1.c << '!EOR!'
X/*
X * func1.c	Phantasia support routines
X */
X
X#include "phant.h"
X
Xbool	findname(name)				/* return TRUE if name in use */
Xreg	char	*name;
X{
XFILE	*fp;
Xstruct	stats	buf;
X
X	fp = fopen(peoplefile,"r");
X	while (fread((char *) &buf,sizeof(buf),1,fp))
X		if (!strcmp(buf.name,name))
X			{
X			fclose(fp);
X			mvaddstr(21,0,"Name already in use.\n");
X			refresh();
X			return (TRUE);
X			}
X	fclose(fp);
X	return (FALSE);
X}
X
Xint	findspace()				/* allocate space for a character in peoplefile */
X{
XFILE	*fp;
Xstruct	stats	buf;
Xreg	int	loc;
X
X	loc = 0;
X	fp = fopen(peoplefile,"r");
X	while (fread((char *) &buf,sizeof(buf),1,fp))
X		{
X		if (!strcmp(buf.name,"<null>"))
X			{
X			fclose(fp);
X			return (loc);
X			}
X		else
X			++loc;
X		}
X	fclose(fp);
X	fp = fopen(peoplefile,ACCESS);
X	fseek(fp,(long) loc * sizeof(buf),0);
X	initchar(&buf);
X	strcpy(buf.name,"inuse");
X	fwrite((char *) &buf,sizeof(buf),1,fp);
X	fclose(fp);
X	return (loc);
X}
X
Xint	findchar(stat)				/* retrieve a character from file */
Xreg	struct	stats	*stat;
X{
Xreg	int	loc = 0, loop;
Xchar	name[21];
XFILE	*fp;
X
X	if (fp = fopen(peoplefile,"r"))
X		{
X		clear();
X		mvprintw(10,0,"What was your character's name ? ");
X		getstring(name,21);
X		trunc(name);
X		while (fread((char *) stat,sizeof(*stat),1,fp))
X			{
X			if (!strcmp(stat->name,name))
X				{
X				move(11,0);
X				refresh();
X				fclose(fp);
X				nocrmode();
X				for (loop = 0; loop < 2; ++loop)
X					if (!strcmp(getpass("Password ? "),stat->pswd))
X						{
X						crmode();
X						return (loc);
X						}
X					else
X						printf("No good.\n");
X				exit1();
X				/*NOTREACHED*/
X				}
X			++loc;
X			}
X		}
X	fclose(fp);
X	addstr("\n\nNot found.\n");
X	exit1();
X/*NOTREACHED*/
X}
X
Xvoid	leave(stat)				/* save character in file */
Xreg	struct	stats	*stat;
X{
Xlong	ltemp;
X
X	if (!stat->lvl)
X		strcpy(stat->name,"<null>");
X	stat->status = OFF;
X	time(&ltemp);
X	stat->age += ltemp - secs;
X	update(stat,fileloc);
X	exit1();
X	/*NOTREACHED*/
X}
X
Xvoid	talk(name)				/* send message to all players */
Xreg	char	*name;
X{
XFILE	*fp;
Xchar	aline[160];
X
X	mvaddstr(5,0,"Message ? ");
X	getstring(aline,160);
X	fp = fopen(messfile,"w");
X	if (*aline)
X		fprintf(fp,"%s:  %s",name,aline);
X	fclose(fp);
X}
X
Xvoid	death(stat)				/* remove a player after dying */
Xreg	struct	stats	*stat;
X{
XFILE	*fp;
Xchar	aline[100];
Xint	ch;
Xreg	int	loop;
Xlong	ltemp;
X
X	clear();
X	if (stat->typ == 99)
X		if (stat->rng.duration)
X			{
X			addstr("Valar should be more cautious.  You've been killed.\n");
X			printw("You only have %d more chance(s).\n",--stat->rng.duration);
X			paws(3);
X			stat->nrg = stat->mxn;
X			return;
X			}
X		else
X			{
X			addstr("You had your chances, but Valar aren't totally\n");
X			addstr("immortal.  You are now left to wither and die . . .\n");
X			paws(3);
X			stat->brn = stat->lvl /25;
X			stat->nrg = stat->mxn;
X			stat->quks = stat->swd = 0;
X			stat->typ = 90;
X			return;
X			}
X	if (stat->lvl > 9999)
X		addstr("Characters greater than level 10K must be retired.  Sorry.");
X	switch(stat->rng.type)
X		{
X		case -DLREG:
X		case -NAZREG:
X			mvaddstr(4,0,"Your ring saved you from death!\n");
X			refresh();
X			stat->rng.type = NONE;
X			stat->nrg = stat->mxn/12+1;
X			stat->crn -= (stat->crn > 0);
X			return;
X		case DLBAD:
X		case -DLBAD:
X		case NAZBAD:
X		case -NAZBAD:
X		case -SPOILED:
X		case SPOILED:
X			mvaddstr(4,0,"Your ring has taken control of you and turned you into a monster!\n");
X			fp = fopen(monsterfile,"r");
X			for (loop = 0; loop <= 13; ++loop)
X				fgets(aline,100,fp);
X			ltemp = ftell(fp);
X			fclose(fp);
X			fp = fopen(monsterfile,ACCESS);
X			fseek(fp,ltemp,0);
X			fprintf(fp,"%-20s",stat->name);
X			fclose(fp);
X		}
X	initchar(stat);
X	fp = fopen(lastdead,"w");
X	fprintf(fp,"%s   Login:  %s",stat->name,stat->login);
X	fclose(fp);
X	strcpy(stat->name,"<null>");
X	update(stat,fileloc);
X	clear();
X	move(10,0);
X	switch ((int) roll(1,5))
X		{
X		case 1:
X			addstr("You've crapped out!  ");
X			break;
X		case 2:
X			addstr("You have been disemboweled.  ");
X			break;
X		case 3:
X			addstr("You've been mashed, mauled, and spit upon.  (You're dead.)\n");
X			break;
X		case 4:
X			addstr("You died!  ");
X			break;
X		case 5:
X			addstr("You're a complete failure -- you've died!!\n");
X		}
X	addstr("Care to give it another try ? ");
X	ch = rgetch();
X	if (toupper(ch) == 'Y')
X		{
X		endwin();
X		execl(gameprog,"phantasia","-s",0);
X		}
X	exit1();
X	/*NOTREACHED*/
X}
X
Xvoid	update(stat,place)			/* update charac file */
Xreg	struct	stats	*stat;
Xreg	int	place;
X{
XFILE	*fp;
X
X	fp = fopen(peoplefile,ACCESS);
X	fseek(fp,(long) place*sizeof(*stat),0);
X	fwrite((char *) stat,sizeof(*stat),1,fp);
X	fclose(fp);
X}
X
Xvoid	printplayers(stat)			/* show users */
Xreg	struct	stats	*stat;
X{
XFILE	*fp;
Xstruct	stats	buf;
Xreg	int	loop = 0;
Xdouble	loc;
Xlong	ltmp;
Xint	ch;
X
X	if (stat->blind)
X		{
X		mvaddstr(6,0,"You can't see anyone.\n");
X		return;
X		}
X	loc = circ(stat->x,stat->y);
X	mvaddstr(6,0,"Name                         X         Y       Lvl  Type  Login\n");
X	fp = fopen(peoplefile,"r");
X	while (fread((char *) &buf,sizeof(buf),1,fp))
X		{
X		if (buf.status)
X			{
X			ch = (buf.status == CLOAKED) ? '?' : 'W';
X			if (stat->typ > 10 || buf.typ > 10 || loc >= circ(buf.x,buf.y) || stat->pal)
X				if (buf.status != CLOAKED || (stat->typ == 99 && stat->pal))
X					if (buf.typ == 99)
X						addstr("The Valar is watching you. . .\n");
X					else if (buf.wormhole)
X						printw("%-20s         %c         %c    %6u  %3d   %-9s\n",
X							buf.name,ch,ch,buf.lvl,buf.typ,buf.login);
X					else
X						printw("%-20s  %8.0f  %8.0f    %6u  %3d   %-9s\n",
X							buf.name,buf.x,buf.y,buf.lvl,buf.typ,buf.login);
X				else
X					if (buf.typ == 99)
X						--loop;
X					else
X						printw("%-20s         ?         ?    %6u  %3d   %-9s\n",
X							buf.name,buf.lvl,buf.typ,buf.login);
X			++loop;
X			}
X		}
X	fclose(fp);
X	time(&ltmp);
X	printw("Total users = %d    %s\n",loop,ctime(&ltmp));
X	refresh();
X}
X
X
Xvoid	printhelp()				/* print help file */
X{
XFILE	*fp;
Xchar	instr[100];
X
X	fp = fopen(helpfile,"r");
X	while (fgets(instr,100,fp))
X		fputs(instr,stdout);
X	fclose(fp);
X}
X
Xvoid	titlestuff()				/* print out a header */
X{
XFILE	*fp;
Xchar	instr[80], hiname[21], nxtname[21], aline[80];
Xbool	cowfound = FALSE, kingfound = FALSE;
Xstruct	stats	buf;
Xdouble	hiexp, nxtexp;
Xunsigned	hilvl, nxtlvl;
Xreg	int	loop;
X
X	mvaddstr(0,15,"W e l c o m e   t o   P h a n t a s i a (vers. 3.2)!");
X	fp = fopen(motd,"r");
X	if (fgets(instr,80,fp))
X		mvaddstr(2,40 - strlen(instr)/2,instr);
X	fclose(fp);
X	fp = fopen(peoplefile,"r");
X	while (fread((char *) &buf,sizeof(buf),1,fp))
X		if (buf.typ > 10 && buf.typ < 20)
X			{
X			sprintf(instr,"The present ruler is %s  Level:%d",buf.name,buf.lvl);
X			mvaddstr(4,40 - strlen(instr)/2,instr);
X			kingfound = TRUE;
X			break;
X			}
X	if (!kingfound)
X		mvaddstr(4,24,"There is no ruler at this time.");
X	fseek(fp,0L,0);
X	while (fread((char *) &buf,sizeof(buf),1,fp))
X		if (buf.typ == 99)
X			{
X			sprintf(instr,"The Valar is %s   Login:  %s",buf.name,buf.login);
X			mvaddstr(6,40 - strlen(instr)/2,instr);
X			break;
X			}
X	fseek(fp,0L,0);
X	while (fread((char *) &buf,sizeof(buf),1,fp))
X		if (buf.typ > 20 && buf.typ < 90)
X			{
X			if (!cowfound)
X				{
X				mvaddstr(8,30,"Council of the Wise:");
X				loop = 10;
X				cowfound = TRUE;
X				}
X			/* This assumes a finite (<=7) number of C.O.W.: */
X			sprintf(instr,"%s   Login:  %s",buf.name,buf.login);
X			mvaddstr(loop++,40 - strlen(instr)/2,instr);
X			}
X	fseek(fp,0L,0);
X	*nxtname = *hiname = '\0';
X	hiexp = 0.0;
X	nxtlvl = hilvl = 0;
X	while (fread((char *) &buf,sizeof(buf),1,fp))
X		if (buf.exp > hiexp && buf.typ < 20)
X			{
X			nxtexp = hiexp;
X			hiexp = buf.exp;
X			nxtlvl = hilvl;
X			hilvl = buf.lvl;
X			strcpy(nxtname,hiname);
X			strcpy(hiname,buf.name);
X			}
X		else if (buf.exp > nxtexp && buf.typ < 20)
X			{
X			nxtexp = buf.exp;
X			nxtlvl = buf.lvl;
X			strcpy(nxtname,buf.name);
X			}
X	fclose(fp);
X	mvaddstr(17,28,"Highest characters are:");
X	sprintf(instr,"%s  Level:%d   and   %s  Level:%d",hiname,hilvl,nxtname,nxtlvl);
X	mvaddstr(19,40 - strlen(instr)/2,instr);
X	fp = fopen(lastdead,"r");
X	fgets(aline,80,fp);
X	sprintf(instr,"The last character to die is %s",aline);
X	mvaddstr(21,40 - strlen(instr)/2,instr);
X	fclose(fp);
X	refresh();
X}
X
X
X
Xvoid	printmonster()				/* do a monster list on the terminal */
X{
XFILE	*fp;
Xreg	int	count = 0;
Xchar	instr[100];
X
X	puts(" #  Name                    Str     Brains  Quick   Hits    Exp     Treas   Type    Flock%\n");
X	fp = fopen(monsterfile,"r");
X	while (fgets(instr,100,fp))
X		printf("%2d  %s",count++,instr);
X	fclose(fp);
X}
X
Xvoid	exit1() 				/* exit, but cleanup */
X{
X	move(23,0);
X	refresh();
X	nocrmode();
X	endwin();
X	exit(0);
X	/*NOTREACHED*/
X}
X
Xvoid	init1() 				/* set up for screen updating */
X{
X		/* catch/ingnore signals */
X#ifdef	BSD41
X	sigignore(SIGQUIT);
X	sigignore(SIGALRM);
X	sigignore(SIGTERM);
X	sigignore(SIGTSTP);
X	sigignore(SIGTTIN);
X	sigignore(SIGTTOU);
X	sighold(SIGINT);
X#endif
X#ifdef	BSD42
X	signal(SIGQUIT,interrupt,1);
X	signal(SIGALRM,interrupt,1);
X	signal(SIGTERM,interrupt,1);
X	signal(SIGTSTP,interrupt,1);
X	signal(SIGTTIN,interrupt,1);
X	signal(SIGTTOU,interrupt,1);
X	signal(SIGINT,interrupt,1);
X#endif
X#ifdef	USG3
X	signal(SIGINT,SIG_IGN);
X	signal(SIGQUIT,SIG_IGN);
X	signal(SIGTERM,SIG_IGN);
X	signal(SIGALRM,SIG_IGN);
X#endif
X#ifdef	USG5
X	signal(SIGINT,SIG_IGN);
X	signal(SIGQUIT,SIG_IGN);
X	signal(SIGTERM,SIG_IGN);
X	signal(SIGALRM,SIG_IGN);
X#endif
X	srand((unsigned) time((long *) NULL));	/* prime random numbers */
X	initscr();
X	noecho();
X	crmode();
X	clear();
X	refresh();
X}
X
Xvoid	getstring(cp,mx)				/* get a string from the stdscr at current y,x */
Xreg	char	*cp;
Xreg	int	mx;
X{
Xreg	int	loop = 0, x, y, xorig;
Xint	ch;
X
X	getyx(stdscr,y,xorig);
X	clrtoeol();
X	refresh();
X	while((ch = getch()) != '\n' && loop < mx - 1)
X		switch (ch)
X			{
X			case '\033':	/* escape */
X			case '\010':	/* backspace */
X				if (loop)
X					{
X					--loop;
X					getyx(stdscr,y,x);
X					mvaddch(y,x-1,' ');
X					move(y,x-1);
X					refresh();
X					}
X				break;
X			case '\030':	/* ctrl-x */
X				loop = 0;
X				move(y,xorig);
X				clrtoeol();
X				refresh();
X				break;
X			default:
X				if (ch >= ' ') /* printing char */
X					{
X					addch(ch);
X					cp[loop++] = ch;
X					refresh();
X					}
X			}
X	cp[loop] = '\0';
X}
X
X
Xvoid	showusers()				/* print a list of all characters */
X{
Xstruct	stats	buf;
XFILE	*fp;
X
X	if (fp = fopen(peoplefile,"r"))
X		{
X		puts("Current characters on file are:\n");
X		while (fread((char *) &buf,sizeof(buf),1,fp))
X			if (strcmp("<null>",buf.name))
X				printf("%-20s   Login: %-9s  Level: %6u\n",buf.name,buf.login,buf.lvl);
X		fclose(fp);
X		}
X}
X
Xvoid	kingstuff(stat) 			/* stuff upon entering throne */
Xreg	struct 	stats	*stat;
X{
XFILE	*fp;
Xstruct	stats	buf;
Xstruct	nrgvoid	vbuf;
Xreg	int	loc = 0;
X
X	if (stat->typ < 10)	/* check to see if king -- assumes crown */
X		{
X		fp = fopen(peoplefile,"r");
X		while (fread((char *) &buf,sizeof(buf),1,fp))
X			if (buf.typ > 10 && buf.typ < 20)	/* found old king */
X				if (buf.status != OFF)
X					{
X					mvaddstr(6,0,"The king is playing, so you cannot steal his throne\n");
X					stat->x = stat->y = 9;
X					move(3,0);
X					fclose(fp);
X					return;
X					}
X				else
X					{
X					buf.typ -= 10;
X					if (buf.crn)
X						--buf.crn;
X					fclose(fp);
X					update(&buf,loc);
XKING:				stat->typ = abs(stat->typ) + 10;
X					mvaddstr(6,0,"You have become king!\n");
X					fp = fopen(messfile,"w");
X					fprintf(fp,"All hail the new king!");
X					fclose(fp);
X					/* clear all energy voids */
X					fp = fopen(voidfile,"r");
X					fread((char *) &vbuf,sizeof(vbuf),1,fp);
X					fclose(fp);
X					fp = fopen(voidfile,"w");
X					fwrite((char *) &vbuf,sizeof(vbuf),1,fp);
X					fclose(fp);
X					goto EXIT;
X					}
X			else
X				++loc;
X		fclose(fp);	  /* old king not found -- install new one */
X		goto KING;
X		}
XEXIT:	mvaddstr(3,0,"0:Decree  ");
X}
X
Xvoid	paws(where)				/* wait for input to continue */
Xint	where;
X{
X	mvaddstr(where,0,"-- more --");
X	rgetch();
X}
X
Xvoid	cstat() 				/* examine/change stats of a character */
X{
Xstruct	stats charac;
Xchar	s[60], flag[2];
XFILE	*fp;
Xreg	int	loc = 0;
Xint	c, temp, today;
Xlong	ltemp;
Xdouble	dtemp;
X
X	flag[0] = 'F';	flag[1] = 'T';
X	mvaddstr(10,0,"Which character do you want to look at ? ");
X	getstring(s,60);
X	if (fp = fopen(peoplefile,"r"))
X		while (fread((char *) &charac,sizeof(charac),1,fp))
X			if (!strcmp(s,charac.name))
X				goto FOUND;
X			else
X				++loc;
X	mvaddstr(11,0,"Not found.");
X	exit1();
X	/*NOTREACHED*/
X
XFOUND:	fclose(fp);
X	time(&ltemp);
X	today = localtime(&ltemp)->tm_yday;
X	if (!su)
X		strcpy(charac.pswd,"XXXXXXXX");
X	clear();
XTOP:	mvprintw(0,0,"a:Name         %s\n",charac.name);
X	printw("b:Password     %s\n",charac.pswd);
X	printw(" :Login        %s\n",charac.login);
X	temp = today - charac.lastused;
X	if (temp < 0)
X		temp += 365;
X	printw("c:Used         %d\n",temp);
X	mvprintw(5,0,"d:Experience   %.0f\n",charac.exp);
X	printw("e:Level        %d\n",charac.lvl);
X	printw("f:Strength     %.0f\n",charac.str);
X	printw("g:Sword        %.0f\n",charac.swd);
X	printw("h:Quickness    %d\n",charac.quk);
X	printw("i:Quikslvr     %d\n",charac.quks);
X	printw("j:Energy       %.0f\n",charac.nrg);
X	printw("k:Max-Nrg      %.0f\n",charac.mxn);
X	printw("l:Shield       %.0f\n",charac.shd);
X	printw("m:Magic        %.0f\n",charac.mag);
X	printw("n:Manna        %.0f\n",charac.man);
X	printw("o:Brains       %.0f\n",charac.brn);
X	mvprintw(0,40,"p:X-coord      %.0f\n",charac.x);
X	mvprintw(1,40,"q:Y-coord      %.0f\n",charac.y);
X	if (su)
X		mvprintw(2,40,"r:Wormhole     %d\n",charac.wormhole);
X	else
X		mvprintw(2,40,"r:Wormhole     %c\n",flag[charac.wormhole != 0]);
X	mvprintw(3,40,"s:Type         %d\n",charac.typ);
X	mvprintw(5,40,"t:Sin          %0.3f\n",charac.sin);
X	mvprintw(6,40,"u:Poison       %0.3f\n",charac.psn);
X	mvprintw(7,40,"v:Gold         %.0f\n",charac.gld);
X	mvprintw(8,40,"w:Gem          %.0f\n",charac.gem);
X	mvprintw(9,40,"x:Holy Water   %d\n",charac.hw);
X	mvprintw(10,40,"y:Charms       %d\n",charac.chm);
X	mvprintw(11,40,"z:Crowns       %d\n",charac.crn);
X	mvprintw(12,40,"1:Amulets      %d\n",charac.amu);
X	mvprintw(13,40,"2:Age          %d\n",charac.age);
X	mvprintw(18,5,"3:Virgin %c  4:Blessed %c  5:Ring %c  6:Blind %c  7:Palantir %c",
X		flag[charac.vrg],flag[charac.bls],flag[charac.rng.type != 0],flag[charac.blind],flag[charac.pal]);
X	if (!su)
X		exit1();
X	mvaddstr(15,40,"!:Quit");
X	mvaddstr(16,40,"?:Delete");
X	mvaddstr(19,30,"8:Duration");
X	mvaddstr(21,0,"What would you like to change? ");
X	c = rgetch();
X	switch(c)
X		{
X		case 'p':	/* change x coord */
X			mvprintw(23,0,"x = %f; x = ",charac.x);
X			dtemp = inflt();
X			if (dtemp != 0.0)
X				charac.x = dtemp;
X			break;
X		case 'q':	/* change y coord */
X			mvprintw(23,0,"y = %f; y = ",charac.y);
X			dtemp = inflt();
X			if (dtemp != 0.0)
X				charac.y = dtemp;
X			break;
X		case 'd':	/* change Experience */
X			mvprintw(23,0,"exp = %f; exp = ",charac.exp);
X			dtemp = inflt();
X			if (dtemp != 0.0)
X				charac.exp = dtemp;
X			break;
X		case 'e':	/* change level */
X			mvprintw(23,0,"lvl = %d; lvl;= ",charac.lvl);
X			dtemp = inflt();
X			if (dtemp != 0.0)
X				charac.lvl = dtemp;
X			break;
X		case 'h':	/* change quickness */
X			mvprintw(23,0,"quk = %d; quk;= ",charac.quk);
X			dtemp = inflt();
X			if (dtemp != 0.0)
X				charac.quk = dtemp;
X			break;
X		case 'f':	/* change strength */
X			mvprintw(23,0,"str = %f; str;= ",charac.str);
X			dtemp = inflt();
X			if (dtemp != 0.0)
X				charac.str = dtemp;
X			break;
X		case 't':	/* change Sin */
X			mvprintw(23,0,"sin = %f; sin;= ",charac.sin);
X			dtemp = inflt();
X			if (dtemp != 0.0)
X				charac.sin = dtemp;
X			break;
X		case 'n':	/* change manna */
X			mvprintw(23,0,"man = %f; man;= ",charac.man);
X			dtemp = inflt();
X			if (dtemp != 0.0)
X				charac.man = dtemp;
X			break;
X		case 'v':	/* change gold */
X			mvprintw(23,0,"gld = %f; gld;= ",charac.gld);
X			dtemp = inflt();
X			if (dtemp != 0.0)
X				charac.gld = dtemp;
X			break;
X		case 'j':	/* change energy */
X			mvprintw(23,0,"nrg = %f; nrg;= ",charac.nrg);
X			dtemp = inflt();
X			if (dtemp != 0.0)
X				charac.nrg = dtemp;
X			break;
X		case 'k':	/* change Maximum energy */
X			mvprintw(23,0,"mxn = %f; mxn;= ",charac.mxn);
X			dtemp = inflt();
X			if (dtemp != 0.0)
X				charac.mxn = dtemp;
X			break;
X		case 'm':	/* change magic */
X			mvprintw(23,0,"mag = %f; mag;= ",charac.mag);
X			dtemp = inflt();
X			if (dtemp != 0.0)
X				charac.mag = dtemp;
X			break;
X		case 'o':	/* change brains */
X			mvprintw(23,0,"brn = %f; brn;= ",charac.brn);
X			dtemp = inflt();
X			if (dtemp != 0.0)
X				charac.brn = dtemp;
X			break;
X		case 'z':	/* change crowns */
X			mvprintw(23,0,"crn = %d; crn;= ",charac.crn);
X			dtemp = inflt();
X			if (dtemp != 0.0)
X				charac.crn = dtemp;
X			break;
X		case '5':	/* change ring type */
X			mvprintw(23,0,"rng-type = %d; rng-type;= ",charac.rng.type);
X			dtemp = inflt();
X			if (dtemp != 0.0)
X				charac.rng.type = dtemp;
X			break;
X		case '8':	/* change ring duration */
X			mvprintw(23,0,"rng-duration = %d; rng-duration;= ",charac.rng.duration);
X			dtemp = inflt();
X			if (dtemp != 0.0)
X				charac.rng.duration = dtemp;
X			break;
X		case '7':	/* change palantir */
X			mvprintw(23,0,"pal = %d; pal;= ",charac.pal);
X			dtemp = inflt();
X			if (dtemp != 0.0)
X				{
X				charac.pal = dtemp;
X				charac.pal = (charac.pal != 0);
X				}
X			break;
X		case 'u':	/* change poison */
X			mvprintw(23,0,"psn = %f; psn;= ",charac.psn);
X			dtemp = inflt();
X			if (dtemp != 0.0)
X				charac.psn = dtemp;
X			break;
X		case 'x':	/* change holy water */
X			mvprintw(23,0,"hw = %d; hw;= ",charac.hw);
X			dtemp = inflt();
X			if (dtemp != 0.0)
X				charac.hw = dtemp;
X			break;
X		case '1':	/* change amulet */
X			mvprintw(23,0,"amu = %d; amu;= ",charac.amu);
X			dtemp = inflt();
X			if (dtemp != 0.0)
X				charac.amu = dtemp;
X			break;
X		case '4':	/* change Blessing */
X			mvprintw(23,0,"bls = %d; bls;= ",charac.bls);
X			dtemp = inflt();
X			if (dtemp != 0.0)
X				{
X				charac.bls = dtemp;
X				charac.bls = (charac.bls != 0);
X				}
X			break;
X		case 'y':	/* change Charm */
X			mvprintw(23,0,"chm = %d; chm;= ",charac.chm);
X			dtemp = inflt();
X			if (dtemp != 0.0)
X				charac.chm = dtemp;
X			break;
X		case 'w':	/* change Gems */
X			mvprintw(23,0,"gem = %f; gem;= ",charac.gem);
X			dtemp = inflt();
X			if (dtemp != 0.0)
X				charac.gem = dtemp;
X			break;
X		case 'i':	/* change Quicksilver */
X			mvprintw(23,0,"quks = %d; quks;= ",charac.quks);
X			dtemp = inflt();
X			if (dtemp != 0.0)
X				charac.quks = dtemp;
X			break;
X		case 'g':	/* change swords */
X			mvprintw(23,0,"swd = %f; swd;= ",charac.swd);
X			dtemp = inflt();
X			if (dtemp != 0.0)
X				charac.swd = dtemp;
X			break;
X		case 'l':	/* change shields */
X			mvprintw(23,0,"shd = %f; shd;= ",charac.shd);
X			dtemp = inflt();
X			if (dtemp != 0.0)
X				charac.shd = dtemp;
X			break;
X		case 's':	/* change type */
X			mvprintw(23,0,"typ = %d; typ;= ",charac.typ);
X			dtemp = inflt();
X			if (dtemp != 0.0)
X				charac.typ = dtemp;
X			break;
X		case '3':	/* change virgin */
X			mvprintw(23,0,"vrg = %d; vrg;= ",charac.vrg);
X			dtemp = inflt();
X			if (dtemp != 0.0)
X				{
X				charac.vrg = dtemp;
X				charac.vrg = (charac.vrg != 0);
X				}
X			break;
X		case 'c':	/* change last-used */
X			mvprintw(23,0,"last-used = %d; last-used;= ",charac.lastused);
X			dtemp = inflt();
X			if (dtemp != 0.0)
X				charac.lastused = dtemp;
X			break;
X		case 'b':		/* change password */
X			mvaddstr(23,0,"New password: ");
X			getstring(s,60);
X			if (*s)
X				strcpy(charac.pswd,s);
X			break;
X		case 'a':		/* change name */
X			mvaddstr(23,0,"New name: ");
X			getstring(s,60);
X			if (*s)
X				strcpy(charac.name,s);
X			break;
X		case 'r':	/* change wormhole */
X			mvprintw(23,0,"wormhole = %d; wormhole;= ",charac.wormhole);
X			dtemp = inflt();
X			if (dtemp != 0.0)
X				charac.wormhole = dtemp;
X			break;
X		case '2':	/* change age */
X			mvprintw(23,0,"age = %d; age;= ",charac.age);
X			dtemp = inflt();
X			if (dtemp != 0.0)
X				charac.age = dtemp;
X			break;
X		case '6':	/* change blindness */
X			mvprintw(23,0,"blind = %d; blind;= ",charac.blind);
X			dtemp = inflt();
X			if (dtemp != 0.0)
X				{
X				charac.blind = dtemp;
X				charac.blind = (charac.blind != 0);
X				}
X			break;
X		case '!':	/* quit, update */
X			goto LEAVE;
X		case '?':	/* delete char */
X			strcpy(charac.name,"<null>");
X			initchar(&charac);
X			goto LEAVE;
X		}
X	goto TOP;
XLEAVE:	charac.status = OFF;
X	update(&charac,loc);
X}
X
Xunsigned level(expr)			/* calculate level */
Xdouble	expr;
X{
X	if (expr < 1.1e+7)
X		return (pow((expr/1000.0), 0.4875));
X	else
X		return (pow((expr/1250.0), 0.4865));
X}
X
Xvoid	trunc(str)				/* remove blank spaces at the end of str[] */
Xreg	char	*str;
X{
Xreg	int	loop;
X	loop = strlen(str) - 1;
X	while (str[--loop] == ' ')
X		str[loop] = '\0';
X}
X
Xdouble	inflt()				/* get a floating point # from the terminal */
X{
Xchar	aline[80];
Xdouble	res;
X	getstring(aline,80);
X	if (sscanf(aline,"%F",&res) < 1)
X		res = 0;
X	return (res);
X}
X
Xvoid	checkmov(stat)				/* see if beyond PONR */
Xreg	struct	stats	*stat;
X{
X	if (beyond)
X		{
X		stat->x = sgn(stat->x) * max(abs(stat->x),1.1e+6);
X		stat->y = sgn(stat->y) * max(abs(stat->y),1.1e+6);
X		}
X}
Xvoid	scramble(stat)			/* mix up some stats */
Xreg	struct	stats	*stat;
X{
Xdouble	buf[5],	temp;
Xreg	int	first, second;
Xreg	double	*bp;
X
X	bp = buf;
X	*bp++ = stat->str;
X	*bp++ = stat->man;
X	*bp++ = stat->brn;
X	*bp++ = stat->mag;
X	*bp++ = stat->nrg;
X
X	bp = buf;
X	first = roll(0,5);
X	second = roll(0,5);
X	temp = bp[first];
X	bp[first] = bp[second];
X	bp[second] = temp;
X
X	stat->str = *bp++;
X	stat->man = *bp++;
X	stat->brn = *bp++;
X	stat->mag = *bp++;
X	stat->nrg = *bp++;
X}
!EOR!



More information about the Comp.sources.unix mailing list