[BACK]Return to moreobj.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / games / larn

File: [cvs.NetBSD.org] / src / games / larn / moreobj.c (download)

Revision 1.11, Tue Feb 19 06:05:26 2008 UTC (11 years, 9 months ago) by dholland
Branch: MAIN
CVS Tags: yamt-pf42-baseX, yamt-pf42-base4, yamt-pf42-base3, yamt-pf42-base2, yamt-pf42-base, yamt-pf42, yamt-pagecache-base5, yamt-pagecache-base4, yamt-pagecache-base3, yamt-pagecache-base2, yamt-pagecache-base, wrstuden-revivesa-base-3, wrstuden-revivesa-base-2, wrstuden-revivesa-base-1, wrstuden-revivesa-base, wrstuden-revivesa, netbsd-6-base, netbsd-6-1-RELEASE, netbsd-6-1-RC4, netbsd-6-1-RC3, netbsd-6-1-RC2, netbsd-6-1-RC1, netbsd-6-1-5-RELEASE, netbsd-6-1-4-RELEASE, netbsd-6-1-3-RELEASE, netbsd-6-1-2-RELEASE, netbsd-6-1-1-RELEASE, netbsd-6-1, netbsd-6-0-RELEASE, netbsd-6-0-RC2, netbsd-6-0-RC1, netbsd-6-0-6-RELEASE, netbsd-6-0-5-RELEASE, netbsd-6-0-4-RELEASE, netbsd-6-0-3-RELEASE, netbsd-6-0-2-RELEASE, netbsd-6-0-1-RELEASE, netbsd-6-0, netbsd-6, netbsd-5-base, netbsd-5-2-RELEASE, netbsd-5-2-RC1, netbsd-5-2-3-RELEASE, netbsd-5-2-2-RELEASE, netbsd-5-2-1-RELEASE, netbsd-5-2, netbsd-5-1-RELEASE, netbsd-5-1-RC4, netbsd-5-1-RC3, netbsd-5-1-RC2, netbsd-5-1-RC1, netbsd-5-1-5-RELEASE, netbsd-5-1-4-RELEASE, netbsd-5-1-3-RELEASE, netbsd-5-1-2-RELEASE, netbsd-5-1-1-RELEASE, netbsd-5-1, netbsd-5-0-RELEASE, netbsd-5-0-RC4, netbsd-5-0-RC3, netbsd-5-0-RC2, netbsd-5-0-RC1, netbsd-5-0-2-RELEASE, netbsd-5-0-1-RELEASE, netbsd-5-0, netbsd-5, mjf-devfs2-base, mjf-devfs2, matt-premerge-20091211, matt-nb6-plus-nbase, matt-nb6-plus-base, matt-nb6-plus, matt-nb5-pq3-base, matt-nb5-pq3, matt-nb5-mips64-u2-k2-k4-k7-k8-k9, matt-nb5-mips64-u1-k1-k5, matt-nb5-mips64-premerge-20101231, matt-nb5-mips64-premerge-20091211, matt-nb5-mips64-k15, matt-nb5-mips64, matt-nb4-mips64-k7-u2a-k9b, matt-mips64-premerge-20101231, matt-mips64-base2, matt-armv6-nbase, keiichi-mipv6-base, keiichi-mipv6, jym-xensuspend-nbase, jym-xensuspend-base, jym-xensuspend, hpcarm-cleanup-nbase, hpcarm-cleanup-base, cherry-xenmp-base, cherry-xenmp, bouyer-quota2-nbase, bouyer-quota2-base, bouyer-quota2
Branch point for: yamt-pagecache
Changes since 1.10: +13 -182 lines

Split some code from moreobj.c into action.c, as per larn 12.2.

/*	$NetBSD: moreobj.c,v 1.11 2008/02/19 06:05:26 dholland Exp $	*/

/*
 * moreobj.c 		Larn is copyrighted 1986 by Noah Morgan.
 * 
 * Routines in this file:
 * 
 * oaltar() othrone() ochest() ofountain()
 */
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: moreobj.c,v 1.11 2008/02/19 06:05:26 dholland Exp $");
#endif				/* not lint */
#include <stdlib.h>
#include <unistd.h>
#include "header.h"
#include "extern.h"

static void fch(int, long *);

/*
 *	subroutine to process an altar object
 */
void
oaltar()
{

	lprcat("\nDo you (p) pray  (d) desecrate");
	iopts();
	while (1) {
		while (1)
			switch (ttgetch()) {
			case 'p':
				lprcat(" pray\nDo you (m) give money or (j) just pray? ");
				while (1)
					switch (ttgetch()) {
					case 'j':
						act_just_pray();
						return;

					case 'm':
						act_donation_pray();
						return;

					case '\33':
						return;
					};

			case 'd':
				lprcat(" desecrate");
				act_desecrate_altar();
				return;

			case 'i':
			case '\33':
				ignore();
				act_ignore_altar();
				return;
			};
	}
}

/*
	subroutine to process a throne object
 */
void
othrone(arg)
	int             arg;
{

	lprcat("\nDo you (p) pry off jewels, (s) sit down");
	iopts();
	while (1) {
		while (1)
			switch (ttgetch()) {
			case 'p':
				lprcat(" pry off");
				act_remove_gems(arg);
				return;

			case 's':
				lprcat(" sit down");
				act_sit_throne(arg);
				return;

			case 'i':
			case '\33':
				ignore();
				return;
			};
	}
}

void
odeadthrone()
{
	int    k;

	lprcat("\nDo you (s) sit down");
	iopts();
	while (1) {
		while (1)
			switch (ttgetch()) {
			case 's':
				lprcat(" sit down");
				k = rnd(101);
				if (k < 35) {
					lprcat("\nZaaaappp!  You've been teleported!\n");
					beep();
					oteleport(0);
				} else
					lprcat("\nnothing happens");
				return;

			case 'i':
			case '\33':
				ignore();
				return;
			};
	}
}

/*
	subroutine to process a throne object
 */
void
ochest()
{

	lprcat("\nDo you (t) take it, (o) try to open it");
	iopts();
	while (1) {
		while (1)
			switch (ttgetch()) {
			case 'o':
				lprcat(" open it");
				act_open_chest(playerx, playery);
				return;

			case 't':
				lprcat(" take");
				if (take(OCHEST, iarg[playerx][playery]) == 0)
					item[playerx][playery] = know[playerx][playery] = 0;
				return;

			case 'i':
			case '\33':
				ignore();
				return;
			};
	}
}

/*
	process a fountain object
 */
void
ofountain()
{

	cursors();
	lprcat("\nDo you (d) drink, (w) wash yourself");
	iopts();
	while (1)
		switch (ttgetch()) {
		case 'd':
			lprcat("drink");
			act_drink_fountain();
			return;

		case '\33':
		case 'i':
			ignore();
			return;

		case 'w':
			lprcat("wash yourself");
			act_wash_fountain();
			return;
		}
}

/*
	***
	FCH
	***

	subroutine to process an up/down of a character attribute for ofountain
 */
static void
fch(how, x)
	int             how;
	long           *x;
{
	if (how < 0) {
		lprcat(" went down by one!");
		--(*x);
	} else {
		lprcat(" went up by one!");
		(*x)++;
	}
	bottomline();
}

/*
	a subroutine to raise or lower character levels
	if x > 0 they are raised   if x < 0 they are lowered
 */
void
fntchange(how)
	int             how;
{
	long   j;
	lprc('\n');
	switch (rnd(9)) {
	case 1:
		lprcat("Your strength");
		fch(how, &c[0]);
		break;
	case 2:
		lprcat("Your intelligence");
		fch(how, &c[1]);
		break;
	case 3:
		lprcat("Your wisdom");
		fch(how, &c[2]);
		break;
	case 4:
		lprcat("Your constitution");
		fch(how, &c[3]);
		break;
	case 5:
		lprcat("Your dexterity");
		fch(how, &c[4]);
		break;
	case 6:
		lprcat("Your charm");
		fch(how, &c[5]);
		break;
	case 7:
		j = rnd(level + 1);
		if (how < 0) {
			lprintf("You lose %ld hit point", (long) j);
			if (j > 1)
				lprcat("s!");
			else
				lprc('!');
			losemhp((int) j);
		} else {
			lprintf("You gain %ld hit point", (long) j);
			if (j > 1)
				lprcat("s!");
			else
				lprc('!');
			raisemhp((int) j);
		}
		bottomline();
		break;

	case 8:
		j = rnd(level + 1);
		if (how > 0) {
			lprintf("You just gained %ld spell", (long) j);
			raisemspells((int) j);
			if (j > 1)
				lprcat("s!");
			else
				lprc('!');
		} else {
			lprintf("You just lost %ld spell", (long) j);
			losemspells((int) j);
			if (j > 1)
				lprcat("s!");
			else
				lprc('!');
		}
		bottomline();
		break;

	case 9:
		j = 5 * rnd((level + 1) * (level + 1));
		if (how < 0) {
			lprintf("You just lost %ld experience point", (long) j);
			if (j > 1)
				lprcat("s!");
			else
				lprc('!');
			loseexperience((long) j);
		} else {
			lprintf("You just gained %ld experience point", (long) j);
			if (j > 1)
				lprcat("s!");
			else
				lprc('!');
			raiseexperience((long) j);
		}
		break;
	}
	cursors();
}