Home | History | Annotate | Line # | Download | only in larn
action.c revision 1.1.4.2
      1  1.1.4.2  matt /*	$NetBSD: action.c,v 1.1.4.2 2008/03/23 00:25:43 matt Exp $	*/
      2  1.1.4.2  matt 
      3  1.1.4.2  matt /*
      4  1.1.4.2  matt  * action.c 		Larn is copyrighted 1986 by Noah Morgan.
      5  1.1.4.2  matt  *
      6  1.1.4.2  matt  * Routines in this file:
      7  1.1.4.2  matt  *
      8  1.1.4.2  matt  * ...
      9  1.1.4.2  matt  */
     10  1.1.4.2  matt #include <sys/cdefs.h>
     11  1.1.4.2  matt #ifndef lint
     12  1.1.4.2  matt __RCSID("$NetBSD: action.c,v 1.1.4.2 2008/03/23 00:25:43 matt Exp $");
     13  1.1.4.2  matt #endif				/* not lint */
     14  1.1.4.2  matt #include <stdlib.h>
     15  1.1.4.2  matt #include <unistd.h>
     16  1.1.4.2  matt #include "header.h"
     17  1.1.4.2  matt #include "extern.h"
     18  1.1.4.2  matt 
     19  1.1.4.2  matt static void ohear(void);
     20  1.1.4.2  matt 
     21  1.1.4.2  matt /*
     22  1.1.4.2  matt  * act_remove_gems
     23  1.1.4.2  matt  *
     24  1.1.4.2  matt  * Remove gems from a throne.
     25  1.1.4.2  matt  *
     26  1.1.4.2  matt  * arg is zero if there is a gnome king associated with the throne.
     27  1.1.4.2  matt  *
     28  1.1.4.2  matt  * Assumes that cursors() has been called previously, and that a check
     29  1.1.4.2  matt  * has been made that the throne actually has gems.
     30  1.1.4.2  matt  */
     31  1.1.4.2  matt void
     32  1.1.4.2  matt act_remove_gems(int arg)
     33  1.1.4.2  matt {
     34  1.1.4.2  matt 	int i, k;
     35  1.1.4.2  matt 
     36  1.1.4.2  matt 	k = rnd(101);
     37  1.1.4.2  matt 	if (k < 25) {
     38  1.1.4.2  matt 		for (i = 0; i < rnd(4); i++)
     39  1.1.4.2  matt 			creategem();	/* gems pop off the
     40  1.1.4.2  matt 					 * throne */
     41  1.1.4.2  matt 		item[playerx][playery] = ODEADTHRONE;
     42  1.1.4.2  matt 		know[playerx][playery] = 0;
     43  1.1.4.2  matt 	} else if (k < 40 && arg == 0) {
     44  1.1.4.2  matt 		createmonster(GNOMEKING);
     45  1.1.4.2  matt 		item[playerx][playery] = OTHRONE2;
     46  1.1.4.2  matt 		know[playerx][playery] = 0;
     47  1.1.4.2  matt 	} else
     48  1.1.4.2  matt 		lprcat("\nnothing happens");
     49  1.1.4.2  matt }
     50  1.1.4.2  matt 
     51  1.1.4.2  matt /*
     52  1.1.4.2  matt  * act_sit_throne
     53  1.1.4.2  matt  *
     54  1.1.4.2  matt  * Sit on a throne.
     55  1.1.4.2  matt  *
     56  1.1.4.2  matt  * arg is zero if there is a gnome king associated with the throne
     57  1.1.4.2  matt  *
     58  1.1.4.2  matt  * Assumes that cursors() has been called previously.
     59  1.1.4.2  matt  */
     60  1.1.4.2  matt void
     61  1.1.4.2  matt act_sit_throne(int arg)
     62  1.1.4.2  matt {
     63  1.1.4.2  matt 	int k;
     64  1.1.4.2  matt 
     65  1.1.4.2  matt 	k = rnd(101);
     66  1.1.4.2  matt 	if (k < 30 && arg == 0) {
     67  1.1.4.2  matt 		createmonster(GNOMEKING);
     68  1.1.4.2  matt 		item[playerx][playery] = OTHRONE2;
     69  1.1.4.2  matt 		know[playerx][playery] = 0;
     70  1.1.4.2  matt 	} else if (k < 35) {
     71  1.1.4.2  matt 		lprcat("\nZaaaappp!  You've been teleported!\n");
     72  1.1.4.2  matt 		beep();
     73  1.1.4.2  matt 		oteleport(0);
     74  1.1.4.2  matt 	} else
     75  1.1.4.2  matt 		lprcat("\nnothing happens");
     76  1.1.4.2  matt }
     77  1.1.4.2  matt 
     78  1.1.4.2  matt /*
     79  1.1.4.2  matt  * Code to perform the action of drinking at a fountain.  Assumes that
     80  1.1.4.2  matt  * cursors() has already been called, and that a check has been made
     81  1.1.4.2  matt  * that the player is actually standing at a live fountain.
     82  1.1.4.2  matt  */
     83  1.1.4.2  matt void
     84  1.1.4.2  matt act_drink_fountain(void)
     85  1.1.4.2  matt {
     86  1.1.4.2  matt 	int x;
     87  1.1.4.2  matt 
     88  1.1.4.2  matt 	if (rnd(1501) < 2) {
     89  1.1.4.2  matt 		lprcat("\nOops!  You seem to have caught the dreadful sleep!");
     90  1.1.4.2  matt 		beep();
     91  1.1.4.2  matt 		lflush();
     92  1.1.4.2  matt 		sleep(3);
     93  1.1.4.2  matt 		died(280);
     94  1.1.4.2  matt 		return;
     95  1.1.4.2  matt 	}
     96  1.1.4.2  matt 	x = rnd(100);
     97  1.1.4.2  matt 	if (x < 7) {
     98  1.1.4.2  matt 		c[HALFDAM] += 200 + rnd(200);
     99  1.1.4.2  matt 		lprcat("\nYou feel a sickness coming on");
    100  1.1.4.2  matt 	} else if (x < 13)
    101  1.1.4.2  matt 		quaffpotion(23);	/* see invisible */
    102  1.1.4.2  matt 	else if (x < 45)
    103  1.1.4.2  matt 		lprcat("\nnothing seems to have happened");
    104  1.1.4.2  matt 	else if (rnd(3) != 2)
    105  1.1.4.2  matt 		fntchange(1);	/* change char levels upward	 */
    106  1.1.4.2  matt 	else
    107  1.1.4.2  matt 		fntchange(-1);	/* change char levels
    108  1.1.4.2  matt 				 * downward	 */
    109  1.1.4.2  matt 	if (rnd(12) < 3) {
    110  1.1.4.2  matt 		lprcat("\nThe fountains bubbling slowly quiets");
    111  1.1.4.2  matt 		item[playerx][playery] = ODEADFOUNTAIN;	/* dead fountain */
    112  1.1.4.2  matt 		know[playerx][playery] = 0;
    113  1.1.4.2  matt 	}
    114  1.1.4.2  matt }
    115  1.1.4.2  matt 
    116  1.1.4.2  matt /*
    117  1.1.4.2  matt  * Code to perform the action of washing at a fountain.  Assumes that
    118  1.1.4.2  matt  * cursors() has already been called and that a check has been made
    119  1.1.4.2  matt  * that the player is actually standing at a live fountain.
    120  1.1.4.2  matt  */
    121  1.1.4.2  matt void
    122  1.1.4.2  matt act_wash_fountain(void)
    123  1.1.4.2  matt {
    124  1.1.4.2  matt 	int x;
    125  1.1.4.2  matt 
    126  1.1.4.2  matt 	if (rnd(100) < 11) {
    127  1.1.4.2  matt 		x = rnd((level << 2) + 2);
    128  1.1.4.2  matt 		lprintf("\nOh no!  The water was foul!  You suffer %ld hit points!", (long) x);
    129  1.1.4.2  matt 		lastnum = 273;
    130  1.1.4.2  matt 		losehp(x);
    131  1.1.4.2  matt 		bottomline();
    132  1.1.4.2  matt 		cursors();
    133  1.1.4.2  matt 	} else if (rnd(100) < 29)
    134  1.1.4.2  matt 		lprcat("\nYou got the dirt off!");
    135  1.1.4.2  matt 	else if (rnd(100) < 31)
    136  1.1.4.2  matt 		lprcat("\nThis water seems to be hard water!  The dirt didn't come off!");
    137  1.1.4.2  matt 	else if (rnd(100) < 34)
    138  1.1.4.2  matt 		createmonster(WATERLORD);	/* make water lord		 */
    139  1.1.4.2  matt 	else
    140  1.1.4.2  matt 		lprcat("\nnothing seems to have happened");
    141  1.1.4.2  matt }
    142  1.1.4.2  matt 
    143  1.1.4.2  matt /*
    144  1.1.4.2  matt  * Perform the actions associated with altar desecration.
    145  1.1.4.2  matt  */
    146  1.1.4.2  matt void
    147  1.1.4.2  matt act_desecrate_altar(void)
    148  1.1.4.2  matt {
    149  1.1.4.2  matt 	if (rnd(100) < 60) {
    150  1.1.4.2  matt 		createmonster(makemonst(level + 2) + 8);
    151  1.1.4.2  matt 		c[AGGRAVATE] += 2500;
    152  1.1.4.2  matt 	} else if (rnd(101) < 30) {
    153  1.1.4.2  matt 		lprcat("\nThe altar crumbles into a pile of dust before your eyes");
    154  1.1.4.2  matt 		forget();	/* remember to destroy
    155  1.1.4.2  matt 				 * the altar	 */
    156  1.1.4.2  matt 	} else
    157  1.1.4.2  matt 		lprcat("\nnothing happens");
    158  1.1.4.2  matt }
    159  1.1.4.2  matt 
    160  1.1.4.2  matt /*
    161  1.1.4.2  matt  * Perform the actions associated with praying at an altar and giving
    162  1.1.4.2  matt  * a donation.
    163  1.1.4.2  matt  */
    164  1.1.4.2  matt void
    165  1.1.4.2  matt act_donation_pray(void)
    166  1.1.4.2  matt {
    167  1.1.4.2  matt 	long amt;
    168  1.1.4.2  matt 
    169  1.1.4.2  matt 	lprcat("\n\n");
    170  1.1.4.2  matt 	cursor(1, 24);
    171  1.1.4.2  matt 	cltoeoln();
    172  1.1.4.2  matt 	cursor(1, 23);
    173  1.1.4.2  matt 	cltoeoln();
    174  1.1.4.2  matt 	lprcat("how much do you donate? ");
    175  1.1.4.2  matt 	amt = readnum((long) c[GOLD]);
    176  1.1.4.2  matt 	if (amt < 0 || c[GOLD] < amt) {
    177  1.1.4.2  matt 		lprcat("\nYou don't have that much!");
    178  1.1.4.2  matt 		return;
    179  1.1.4.2  matt 	}
    180  1.1.4.2  matt 	c[GOLD] -= amt;
    181  1.1.4.2  matt 	if (amt < c[GOLD] / 10 || amt < rnd(50)) {
    182  1.1.4.2  matt 		createmonster(makemonst(level + 1));
    183  1.1.4.2  matt 		c[AGGRAVATE] += 200;
    184  1.1.4.2  matt 	} else if (rnd(101) > 50) {
    185  1.1.4.2  matt 		ohear();
    186  1.1.4.2  matt 		return;
    187  1.1.4.2  matt 	} else if (rnd(43) == 5) {
    188  1.1.4.2  matt 		if (c[WEAR])
    189  1.1.4.2  matt 			lprcat("\nYou feel your armor vibrate for a moment");
    190  1.1.4.2  matt 		enchantarmor();
    191  1.1.4.2  matt 		return;
    192  1.1.4.2  matt 	} else if (rnd(43) == 8) {
    193  1.1.4.2  matt 		if (c[WIELD])
    194  1.1.4.2  matt 			lprcat("\nYou feel your weapon vibrate for a moment");
    195  1.1.4.2  matt 		enchweapon();
    196  1.1.4.2  matt 		return;
    197  1.1.4.2  matt 	} else
    198  1.1.4.2  matt 		lprcat("\nThank You.");
    199  1.1.4.2  matt 	bottomline();
    200  1.1.4.2  matt }
    201  1.1.4.2  matt 
    202  1.1.4.2  matt /*
    203  1.1.4.2  matt  *  Performs the actions associated with 'just praying' at the altar.  Called
    204  1.1.4.2  matt  *  when the user responds 'just pray' when in prompt mode, or enters 0 to
    205  1.1.4.2  matt  *  the money prompt when praying.
    206  1.1.4.2  matt  *
    207  1.1.4.2  matt  *  Assumes cursors(), and that any leading \n have been printed.
    208  1.1.4.2  matt  */
    209  1.1.4.2  matt void
    210  1.1.4.2  matt act_just_pray(void)
    211  1.1.4.2  matt {
    212  1.1.4.2  matt 	if (rnd(100) < 75)
    213  1.1.4.2  matt 		lprcat("\nnothing happens");
    214  1.1.4.2  matt 	else if (rnd(13) < 4)
    215  1.1.4.2  matt 		ohear();
    216  1.1.4.2  matt 	else if (rnd(43) == 10) {
    217  1.1.4.2  matt 		if (c[WEAR])
    218  1.1.4.2  matt 			lprcat("\nYou feel your armor vibrate for a moment");
    219  1.1.4.2  matt 		enchantarmor();
    220  1.1.4.2  matt 		return;
    221  1.1.4.2  matt 	} else if (rnd(43) == 10) {
    222  1.1.4.2  matt 		if (c[WIELD])
    223  1.1.4.2  matt 			lprcat("\nYou feel your weapon vibrate for a moment");
    224  1.1.4.2  matt 		enchweapon();
    225  1.1.4.2  matt 		return;
    226  1.1.4.2  matt 	} else
    227  1.1.4.2  matt 		createmonster(makemonst(level + 1));
    228  1.1.4.2  matt }
    229  1.1.4.2  matt 
    230  1.1.4.2  matt /*
    231  1.1.4.2  matt  * Function to cast a +3 protection on the player
    232  1.1.4.2  matt  */
    233  1.1.4.2  matt static void
    234  1.1.4.2  matt ohear(void)
    235  1.1.4.2  matt {
    236  1.1.4.2  matt 	lprcat("\nYou have been heard!");
    237  1.1.4.2  matt 	if (c[ALTPRO] == 0)
    238  1.1.4.2  matt 		c[MOREDEFENSES] += 3;
    239  1.1.4.2  matt 	c[ALTPRO] += 500;	/* protection field */
    240  1.1.4.2  matt 	bottomline();
    241  1.1.4.2  matt }
    242  1.1.4.2  matt 
    243  1.1.4.2  matt /*
    244  1.1.4.2  matt  * Performs the act of ignoring an altar.
    245  1.1.4.2  matt  *
    246  1.1.4.2  matt  * Assumptions:  cursors() has been called.
    247  1.1.4.2  matt  */
    248  1.1.4.2  matt void
    249  1.1.4.2  matt act_ignore_altar(void)
    250  1.1.4.2  matt {
    251  1.1.4.2  matt 	if (rnd(100) < 30) {
    252  1.1.4.2  matt 		createmonster(makemonst(level + 1));
    253  1.1.4.2  matt 		c[AGGRAVATE] += rnd(450);
    254  1.1.4.2  matt 	} else
    255  1.1.4.2  matt 		lprcat("\nnothing happens");
    256  1.1.4.2  matt }
    257  1.1.4.2  matt 
    258  1.1.4.2  matt /*
    259  1.1.4.2  matt  * Performs the act of opening a chest.
    260  1.1.4.2  matt  *
    261  1.1.4.2  matt  * Parameters:   x,y location of the chest to open.
    262  1.1.4.2  matt  * Assumptions:  cursors() has been called previously
    263  1.1.4.2  matt  */
    264  1.1.4.2  matt void
    265  1.1.4.2  matt act_open_chest(int x, int y)
    266  1.1.4.2  matt {
    267  1.1.4.2  matt 	int i, k;
    268  1.1.4.2  matt 
    269  1.1.4.2  matt 	k = rnd(101);
    270  1.1.4.2  matt 	if (k < 40) {
    271  1.1.4.2  matt 		lprcat("\nThe chest explodes as you open it");
    272  1.1.4.2  matt 		beep();
    273  1.1.4.2  matt 		i = rnd(10);
    274  1.1.4.2  matt 		lastnum = 281;	/* in case he dies */
    275  1.1.4.2  matt 		lprintf("\nYou suffer %ld hit points damage!", (long) i);
    276  1.1.4.2  matt 		checkloss(i);
    277  1.1.4.2  matt 		switch (rnd(10)) {	/* see if he gets a
    278  1.1.4.2  matt 					 * curse */
    279  1.1.4.2  matt 		case 1:
    280  1.1.4.2  matt 			c[ITCHING] += rnd(1000) + 100;
    281  1.1.4.2  matt 			lprcat("\nYou feel an irritation spread over your skin!");
    282  1.1.4.2  matt 			beep();
    283  1.1.4.2  matt 			break;
    284  1.1.4.2  matt 
    285  1.1.4.2  matt 		case 2:
    286  1.1.4.2  matt 			c[CLUMSINESS] += rnd(1600) + 200;
    287  1.1.4.2  matt 			lprcat("\nYou begin to lose hand to eye coordination!");
    288  1.1.4.2  matt 			beep();
    289  1.1.4.2  matt 			break;
    290  1.1.4.2  matt 
    291  1.1.4.2  matt 		case 3:
    292  1.1.4.2  matt 			c[HALFDAM] += rnd(1600) + 200;
    293  1.1.4.2  matt 			beep();
    294  1.1.4.2  matt 			lprcat("\nA sickness engulfs you!");
    295  1.1.4.2  matt 			break;
    296  1.1.4.2  matt 		};
    297  1.1.4.2  matt 		item[x][y] = know[x][y] = 0;
    298  1.1.4.2  matt 		if (rnd(100) < 69)
    299  1.1.4.2  matt 			creategem();	/* gems from the chest */
    300  1.1.4.2  matt 		dropgold(rnd(110 * iarg[x][y] + 200));
    301  1.1.4.2  matt 		for (i = 0; i < rnd(4); i++)
    302  1.1.4.2  matt 			something(iarg[x][y] + 2);
    303  1.1.4.2  matt 	} else
    304  1.1.4.2  matt 		lprcat("\nnothing happens");
    305  1.1.4.2  matt }
    306