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

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

Revision 1.1, Tue Feb 19 06:05:26 2008 UTC (12 years, 7 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-tag8, yamt-pagecache-base9, yamt-pagecache-base8, yamt-pagecache-base7, yamt-pagecache-base6, yamt-pagecache-base5, yamt-pagecache-base4, yamt-pagecache-base3, yamt-pagecache-base2, yamt-pagecache-base, yamt-pagecache, wrstuden-revivesa-base-3, wrstuden-revivesa-base-2, wrstuden-revivesa-base-1, wrstuden-revivesa-base, wrstuden-revivesa, tls-maxphys-base, tls-maxphys, tls-earlyentropy-base, tls-earlyentropy, riastradh-xf86-video-intel-2-7-1-pre-2-21-15, riastradh-drm2-base3, riastradh-drm2-base2, riastradh-drm2-base1, riastradh-drm2-base, riastradh-drm2, prg-localcount2-base3, prg-localcount2-base2, prg-localcount2-base1, prg-localcount2-base, prg-localcount2, phil-wifi-base, phil-wifi-20200421, phil-wifi-20200411, phil-wifi-20200406, phil-wifi-20191119, phil-wifi-20190609, phil-wifi, pgoyette-localcount-base, pgoyette-localcount-20170426, pgoyette-localcount-20170320, pgoyette-localcount-20170107, pgoyette-localcount-20161104, pgoyette-localcount-20160806, pgoyette-localcount-20160726, pgoyette-localcount, pgoyette-compat-merge-20190127, pgoyette-compat-base, pgoyette-compat-20190127, pgoyette-compat-20190118, pgoyette-compat-1226, pgoyette-compat-1126, pgoyette-compat-1020, pgoyette-compat-0930, pgoyette-compat-0906, pgoyette-compat-0728, pgoyette-compat-0625, pgoyette-compat-0521, pgoyette-compat-0502, pgoyette-compat-0422, pgoyette-compat-0415, pgoyette-compat-0407, pgoyette-compat-0330, pgoyette-compat-0322, pgoyette-compat-0315, pgoyette-compat, perseant-stdc-iso10646-base, perseant-stdc-iso10646, netbsd-9-base, netbsd-9-0-RELEASE, netbsd-9-0-RC2, netbsd-9-0-RC1, netbsd-9, netbsd-8-base, netbsd-8-2-RELEASE, netbsd-8-1-RELEASE, netbsd-8-1-RC1, netbsd-8-0-RELEASE, netbsd-8-0-RC2, netbsd-8-0-RC1, netbsd-8, netbsd-7-nhusb-base-20170116, netbsd-7-nhusb-base, netbsd-7-nhusb, netbsd-7-base, netbsd-7-2-RELEASE, netbsd-7-1-RELEASE, netbsd-7-1-RC2, netbsd-7-1-RC1, netbsd-7-1-2-RELEASE, netbsd-7-1-1-RELEASE, netbsd-7-1, netbsd-7-0-RELEASE, netbsd-7-0-RC3, netbsd-7-0-RC2, netbsd-7-0-RC1, netbsd-7-0-2-RELEASE, netbsd-7-0-1-RELEASE, netbsd-7-0, netbsd-7, 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-nb8-mediatek-base, matt-nb8-mediatek, 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, localcount-20160914, keiichi-mipv6-base, keiichi-mipv6, jym-xensuspend-nbase, jym-xensuspend-base, jym-xensuspend, is-mlppp-base, is-mlppp, hpcarm-cleanup-nbase, hpcarm-cleanup-base, cherry-xenmp-base, cherry-xenmp, bouyer-socketcan-base1, bouyer-socketcan-base, bouyer-socketcan, bouyer-quota2-nbase, bouyer-quota2-base, bouyer-quota2, agc-symver-base, agc-symver, HEAD
Branch point for: matt-armv6

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

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

/*
 * action.c 		Larn is copyrighted 1986 by Noah Morgan.
 * 
 * Routines in this file:
 * 
 * ...
 */
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: action.c,v 1.1 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 ohear(void);

/*
 * act_remove_gems
 *
 * Remove gems from a throne.
 *
 * arg is zero if there is a gnome king associated with the throne.
 *
 * Assumes that cursors() has been called previously, and that a check
 * has been made that the throne actually has gems.
 */
void
act_remove_gems(int arg)
{
	int i, k;

	k = rnd(101);
	if (k < 25) {
		for (i = 0; i < rnd(4); i++)
			creategem();	/* gems pop off the
					 * throne */
		item[playerx][playery] = ODEADTHRONE;
		know[playerx][playery] = 0;
	} else if (k < 40 && arg == 0) {
		createmonster(GNOMEKING);
		item[playerx][playery] = OTHRONE2;
		know[playerx][playery] = 0;
	} else
		lprcat("\nnothing happens");
}

/*
 * act_sit_throne
 *
 * Sit on a throne.
 *
 * arg is zero if there is a gnome king associated with the throne
 *
 * Assumes that cursors() has been called previously.
 */
void
act_sit_throne(int arg)
{
	int k;

	k = rnd(101);
	if (k < 30 && arg == 0) {
		createmonster(GNOMEKING);
		item[playerx][playery] = OTHRONE2;
		know[playerx][playery] = 0;
	} else if (k < 35) {
		lprcat("\nZaaaappp!  You've been teleported!\n");
		beep();
		oteleport(0);
	} else
		lprcat("\nnothing happens");
}

/*
 * Code to perform the action of drinking at a fountain.  Assumes that
 * cursors() has already been called, and that a check has been made
 * that the player is actually standing at a live fountain.
 */
void
act_drink_fountain(void)
{
	int x;

	if (rnd(1501) < 2) {
		lprcat("\nOops!  You seem to have caught the dreadful sleep!");
		beep();
		lflush();
		sleep(3);
		died(280);
		return;
	}
	x = rnd(100);
	if (x < 7) {
		c[HALFDAM] += 200 + rnd(200);
		lprcat("\nYou feel a sickness coming on");
	} else if (x < 13)
		quaffpotion(23);	/* see invisible */
	else if (x < 45)
		lprcat("\nnothing seems to have happened");
	else if (rnd(3) != 2)
		fntchange(1);	/* change char levels upward	 */
	else
		fntchange(-1);	/* change char levels
				 * downward	 */
	if (rnd(12) < 3) {
		lprcat("\nThe fountains bubbling slowly quiets");
		item[playerx][playery] = ODEADFOUNTAIN;	/* dead fountain */
		know[playerx][playery] = 0;
	}
}

/*
 * Code to perform the action of washing at a fountain.  Assumes that
 * cursors() has already been called and that a check has been made
 * that the player is actually standing at a live fountain.
 */
void
act_wash_fountain(void)
{
	int x;

	if (rnd(100) < 11) {
		x = rnd((level << 2) + 2);
		lprintf("\nOh no!  The water was foul!  You suffer %ld hit points!", (long) x);
		lastnum = 273;
		losehp(x);
		bottomline();
		cursors();
	} else if (rnd(100) < 29)
		lprcat("\nYou got the dirt off!");
	else if (rnd(100) < 31)
		lprcat("\nThis water seems to be hard water!  The dirt didn't come off!");
	else if (rnd(100) < 34)
		createmonster(WATERLORD);	/* make water lord		 */
	else
		lprcat("\nnothing seems to have happened");
}

/*
 * Perform the actions associated with altar desecration.
 */
void
act_desecrate_altar(void)
{
	if (rnd(100) < 60) {
		createmonster(makemonst(level + 2) + 8);
		c[AGGRAVATE] += 2500;
	} else if (rnd(101) < 30) {
		lprcat("\nThe altar crumbles into a pile of dust before your eyes");
		forget();	/* remember to destroy
				 * the altar	 */
	} else
		lprcat("\nnothing happens");
}

/*
 * Perform the actions associated with praying at an altar and giving
 * a donation.
 */
void
act_donation_pray(void)
{
	long amt;

	lprcat("\n\n");
	cursor(1, 24);
	cltoeoln();
	cursor(1, 23);
	cltoeoln();
	lprcat("how much do you donate? ");
	amt = readnum((long) c[GOLD]);
	if (amt < 0 || c[GOLD] < amt) {
		lprcat("\nYou don't have that much!");
		return;
	}
	c[GOLD] -= amt;
	if (amt < c[GOLD] / 10 || amt < rnd(50)) {
		createmonster(makemonst(level + 1));
		c[AGGRAVATE] += 200;
	} else if (rnd(101) > 50) {
		ohear();
		return;
	} else if (rnd(43) == 5) {
		if (c[WEAR])
			lprcat("\nYou feel your armor vibrate for a moment");
		enchantarmor();
		return;
	} else if (rnd(43) == 8) {
		if (c[WIELD])
			lprcat("\nYou feel your weapon vibrate for a moment");
		enchweapon();
		return;
	} else
		lprcat("\nThank You.");
	bottomline();
}

/*
 *  Performs the actions associated with 'just praying' at the altar.  Called
 *  when the user responds 'just pray' when in prompt mode, or enters 0 to
 *  the money prompt when praying.
 *
 *  Assumes cursors(), and that any leading \n have been printed.
 */
void
act_just_pray(void)
{
	if (rnd(100) < 75)
		lprcat("\nnothing happens");
	else if (rnd(13) < 4)
		ohear();
	else if (rnd(43) == 10) {
		if (c[WEAR])
			lprcat("\nYou feel your armor vibrate for a moment");
		enchantarmor();
		return;
	} else if (rnd(43) == 10) {
		if (c[WIELD])
			lprcat("\nYou feel your weapon vibrate for a moment");
		enchweapon();
		return;
	} else
		createmonster(makemonst(level + 1));
}

/*
 * Function to cast a +3 protection on the player
 */
static void
ohear(void)
{
	lprcat("\nYou have been heard!");
	if (c[ALTPRO] == 0)
		c[MOREDEFENSES] += 3;
	c[ALTPRO] += 500;	/* protection field */
	bottomline();
}

/*
 * Performs the act of ignoring an altar.
 *
 * Assumptions:  cursors() has been called.
 */
void
act_ignore_altar(void)
{
	if (rnd(100) < 30) {
		createmonster(makemonst(level + 1));
		c[AGGRAVATE] += rnd(450);
	} else
		lprcat("\nnothing happens");
}

/*
 * Performs the act of opening a chest.  
 *
 * Parameters:   x,y location of the chest to open.
 * Assumptions:  cursors() has been called previously
 */
void
act_open_chest(int x, int y)
{
	int i, k;

	k = rnd(101);
	if (k < 40) {
		lprcat("\nThe chest explodes as you open it");
		beep();
		i = rnd(10);
		lastnum = 281;	/* in case he dies */
		lprintf("\nYou suffer %ld hit points damage!", (long) i);
		checkloss(i);
		switch (rnd(10)) {	/* see if he gets a
					 * curse */
		case 1:
			c[ITCHING] += rnd(1000) + 100;
			lprcat("\nYou feel an irritation spread over your skin!");
			beep();
			break;

		case 2:
			c[CLUMSINESS] += rnd(1600) + 200;
			lprcat("\nYou begin to lose hand to eye coordination!");
			beep();
			break;

		case 3:
			c[HALFDAM] += rnd(1600) + 200;
			beep();
			lprcat("\nA sickness engulfs you!");
			break;
		};
		item[x][y] = know[x][y] = 0;
		if (rnd(100) < 69)
			creategem();	/* gems from the chest */
		dropgold(rnd(110 * iarg[x][y] + 200));
		for (i = 0; i < rnd(4); i++)
			something(iarg[x][y] + 2);
	} else
		lprcat("\nnothing happens");
}