Home | History | Annotate | Line # | Download | only in larn
      1  1.13    rillig /*	$NetBSD: moreobj.c,v 1.13 2021/05/02 12:50:45 rillig Exp $	*/
      2   1.2   mycroft 
      3   1.4  christos /*
      4   1.4  christos  * moreobj.c 		Larn is copyrighted 1986 by Noah Morgan.
      5  1.13    rillig  *
      6   1.4  christos  * Routines in this file:
      7  1.13    rillig  *
      8   1.4  christos  * oaltar() othrone() ochest() ofountain()
      9   1.1       cgd  */
     10   1.4  christos #include <sys/cdefs.h>
     11   1.4  christos #ifndef lint
     12  1.13    rillig __RCSID("$NetBSD: moreobj.c,v 1.13 2021/05/02 12:50:45 rillig Exp $");
     13   1.4  christos #endif				/* not lint */
     14   1.4  christos #include <stdlib.h>
     15   1.4  christos #include <unistd.h>
     16   1.1       cgd #include "header.h"
     17   1.4  christos #include "extern.h"
     18   1.1       cgd 
     19   1.6       jsm static void fch(int, long *);
     20   1.1       cgd 
     21   1.1       cgd /*
     22   1.1       cgd  *	subroutine to process an altar object
     23   1.1       cgd  */
     24   1.4  christos void
     25  1.12  dholland oaltar(void)
     26   1.4  christos {
     27   1.1       cgd 
     28   1.4  christos 	lprcat("\nDo you (p) pray  (d) desecrate");
     29   1.4  christos 	iopts();
     30   1.4  christos 	while (1) {
     31   1.4  christos 		while (1)
     32   1.9  dholland 			switch (ttgetch()) {
     33   1.4  christos 			case 'p':
     34   1.4  christos 				lprcat(" pray\nDo you (m) give money or (j) just pray? ");
     35   1.4  christos 				while (1)
     36   1.9  dholland 					switch (ttgetch()) {
     37   1.4  christos 					case 'j':
     38  1.11  dholland 						act_just_pray();
     39   1.4  christos 						return;
     40   1.4  christos 
     41   1.4  christos 					case 'm':
     42  1.11  dholland 						act_donation_pray();
     43   1.4  christos 						return;
     44   1.4  christos 
     45   1.4  christos 					case '\33':
     46   1.4  christos 						return;
     47   1.4  christos 					};
     48   1.4  christos 
     49   1.4  christos 			case 'd':
     50   1.4  christos 				lprcat(" desecrate");
     51  1.11  dholland 				act_desecrate_altar();
     52   1.4  christos 				return;
     53   1.4  christos 
     54   1.4  christos 			case 'i':
     55   1.4  christos 			case '\33':
     56   1.4  christos 				ignore();
     57  1.11  dholland 				act_ignore_altar();
     58   1.4  christos 				return;
     59   1.4  christos 			};
     60   1.1       cgd 	}
     61   1.4  christos }
     62   1.1       cgd 
     63   1.1       cgd /*
     64   1.1       cgd 	subroutine to process a throne object
     65   1.1       cgd  */
     66   1.4  christos void
     67  1.12  dholland othrone(int arg)
     68   1.4  christos {
     69   1.4  christos 
     70   1.4  christos 	lprcat("\nDo you (p) pry off jewels, (s) sit down");
     71   1.4  christos 	iopts();
     72   1.4  christos 	while (1) {
     73   1.4  christos 		while (1)
     74   1.9  dholland 			switch (ttgetch()) {
     75   1.4  christos 			case 'p':
     76   1.4  christos 				lprcat(" pry off");
     77  1.11  dholland 				act_remove_gems(arg);
     78   1.4  christos 				return;
     79   1.4  christos 
     80   1.4  christos 			case 's':
     81   1.4  christos 				lprcat(" sit down");
     82  1.11  dholland 				act_sit_throne(arg);
     83   1.4  christos 				return;
     84   1.4  christos 
     85   1.4  christos 			case 'i':
     86   1.4  christos 			case '\33':
     87   1.4  christos 				ignore();
     88   1.4  christos 				return;
     89   1.4  christos 			};
     90   1.1       cgd 	}
     91   1.4  christos }
     92   1.1       cgd 
     93   1.4  christos void
     94  1.12  dholland odeadthrone(void)
     95   1.4  christos {
     96   1.4  christos 	int    k;
     97   1.1       cgd 
     98   1.4  christos 	lprcat("\nDo you (s) sit down");
     99   1.4  christos 	iopts();
    100   1.4  christos 	while (1) {
    101   1.4  christos 		while (1)
    102   1.9  dholland 			switch (ttgetch()) {
    103   1.4  christos 			case 's':
    104   1.4  christos 				lprcat(" sit down");
    105   1.4  christos 				k = rnd(101);
    106   1.4  christos 				if (k < 35) {
    107   1.4  christos 					lprcat("\nZaaaappp!  You've been teleported!\n");
    108   1.4  christos 					beep();
    109   1.4  christos 					oteleport(0);
    110   1.4  christos 				} else
    111   1.4  christos 					lprcat("\nnothing happens");
    112   1.4  christos 				return;
    113   1.4  christos 
    114   1.4  christos 			case 'i':
    115   1.4  christos 			case '\33':
    116   1.4  christos 				ignore();
    117   1.4  christos 				return;
    118   1.4  christos 			};
    119   1.1       cgd 	}
    120   1.4  christos }
    121   1.1       cgd 
    122   1.1       cgd /*
    123   1.1       cgd 	subroutine to process a throne object
    124   1.1       cgd  */
    125   1.4  christos void
    126  1.12  dholland ochest(void)
    127   1.4  christos {
    128  1.11  dholland 
    129   1.4  christos 	lprcat("\nDo you (t) take it, (o) try to open it");
    130   1.4  christos 	iopts();
    131   1.4  christos 	while (1) {
    132   1.4  christos 		while (1)
    133   1.9  dholland 			switch (ttgetch()) {
    134   1.4  christos 			case 'o':
    135   1.4  christos 				lprcat(" open it");
    136  1.11  dholland 				act_open_chest(playerx, playery);
    137   1.4  christos 				return;
    138   1.4  christos 
    139   1.4  christos 			case 't':
    140   1.4  christos 				lprcat(" take");
    141   1.4  christos 				if (take(OCHEST, iarg[playerx][playery]) == 0)
    142   1.4  christos 					item[playerx][playery] = know[playerx][playery] = 0;
    143   1.4  christos 				return;
    144   1.4  christos 
    145   1.4  christos 			case 'i':
    146   1.4  christos 			case '\33':
    147   1.4  christos 				ignore();
    148   1.4  christos 				return;
    149   1.4  christos 			};
    150   1.1       cgd 	}
    151   1.4  christos }
    152   1.1       cgd 
    153   1.1       cgd /*
    154  1.10  dholland 	process a fountain object
    155   1.1       cgd  */
    156   1.4  christos void
    157  1.12  dholland ofountain(void)
    158   1.4  christos {
    159  1.11  dholland 
    160   1.1       cgd 	cursors();
    161   1.4  christos 	lprcat("\nDo you (d) drink, (w) wash yourself");
    162   1.4  christos 	iopts();
    163   1.4  christos 	while (1)
    164   1.9  dholland 		switch (ttgetch()) {
    165   1.4  christos 		case 'd':
    166   1.4  christos 			lprcat("drink");
    167  1.11  dholland 			act_drink_fountain();
    168   1.4  christos 			return;
    169   1.1       cgd 
    170   1.1       cgd 		case '\33':
    171   1.4  christos 		case 'i':
    172   1.4  christos 			ignore();
    173   1.4  christos 			return;
    174   1.1       cgd 
    175   1.4  christos 		case 'w':
    176   1.4  christos 			lprcat("wash yourself");
    177  1.11  dholland 			act_wash_fountain();
    178   1.4  christos 			return;
    179   1.1       cgd 		}
    180   1.4  christos }
    181   1.1       cgd 
    182   1.1       cgd /*
    183   1.1       cgd 	***
    184   1.1       cgd 	FCH
    185   1.1       cgd 	***
    186   1.1       cgd 
    187   1.1       cgd 	subroutine to process an up/down of a character attribute for ofountain
    188   1.1       cgd  */
    189   1.1       cgd static void
    190  1.12  dholland fch(int how, long *x)
    191   1.4  christos {
    192   1.4  christos 	if (how < 0) {
    193   1.4  christos 		lprcat(" went down by one!");
    194   1.4  christos 		--(*x);
    195   1.4  christos 	} else {
    196   1.4  christos 		lprcat(" went up by one!");
    197   1.4  christos 		(*x)++;
    198   1.4  christos 	}
    199   1.1       cgd 	bottomline();
    200   1.4  christos }
    201   1.1       cgd 
    202   1.1       cgd /*
    203   1.1       cgd 	a subroutine to raise or lower character levels
    204   1.1       cgd 	if x > 0 they are raised   if x < 0 they are lowered
    205   1.1       cgd  */
    206   1.4  christos void
    207  1.12  dholland fntchange(int how)
    208   1.4  christos {
    209   1.4  christos 	long   j;
    210   1.1       cgd 	lprc('\n');
    211   1.4  christos 	switch (rnd(9)) {
    212   1.4  christos 	case 1:
    213   1.4  christos 		lprcat("Your strength");
    214   1.4  christos 		fch(how, &c[0]);
    215   1.4  christos 		break;
    216   1.4  christos 	case 2:
    217   1.4  christos 		lprcat("Your intelligence");
    218   1.4  christos 		fch(how, &c[1]);
    219   1.4  christos 		break;
    220   1.4  christos 	case 3:
    221   1.4  christos 		lprcat("Your wisdom");
    222   1.4  christos 		fch(how, &c[2]);
    223   1.4  christos 		break;
    224   1.4  christos 	case 4:
    225   1.4  christos 		lprcat("Your constitution");
    226   1.4  christos 		fch(how, &c[3]);
    227   1.4  christos 		break;
    228   1.4  christos 	case 5:
    229   1.4  christos 		lprcat("Your dexterity");
    230   1.4  christos 		fch(how, &c[4]);
    231   1.4  christos 		break;
    232   1.4  christos 	case 6:
    233   1.4  christos 		lprcat("Your charm");
    234   1.4  christos 		fch(how, &c[5]);
    235   1.4  christos 		break;
    236   1.4  christos 	case 7:
    237   1.4  christos 		j = rnd(level + 1);
    238   1.4  christos 		if (how < 0) {
    239   1.7  dholland 			lprintf("You lose %ld hit point", (long) j);
    240   1.4  christos 			if (j > 1)
    241   1.4  christos 				lprcat("s!");
    242   1.4  christos 			else
    243   1.4  christos 				lprc('!');
    244   1.4  christos 			losemhp((int) j);
    245   1.4  christos 		} else {
    246   1.7  dholland 			lprintf("You gain %ld hit point", (long) j);
    247   1.4  christos 			if (j > 1)
    248   1.4  christos 				lprcat("s!");
    249   1.4  christos 			else
    250   1.4  christos 				lprc('!');
    251   1.4  christos 			raisemhp((int) j);
    252   1.4  christos 		}
    253   1.4  christos 		bottomline();
    254   1.4  christos 		break;
    255   1.4  christos 
    256   1.4  christos 	case 8:
    257   1.4  christos 		j = rnd(level + 1);
    258   1.4  christos 		if (how > 0) {
    259   1.7  dholland 			lprintf("You just gained %ld spell", (long) j);
    260   1.4  christos 			raisemspells((int) j);
    261   1.4  christos 			if (j > 1)
    262   1.4  christos 				lprcat("s!");
    263   1.4  christos 			else
    264   1.4  christos 				lprc('!');
    265   1.4  christos 		} else {
    266   1.7  dholland 			lprintf("You just lost %ld spell", (long) j);
    267   1.4  christos 			losemspells((int) j);
    268   1.4  christos 			if (j > 1)
    269   1.4  christos 				lprcat("s!");
    270   1.4  christos 			else
    271   1.4  christos 				lprc('!');
    272   1.4  christos 		}
    273   1.4  christos 		bottomline();
    274   1.4  christos 		break;
    275   1.4  christos 
    276   1.4  christos 	case 9:
    277   1.4  christos 		j = 5 * rnd((level + 1) * (level + 1));
    278   1.4  christos 		if (how < 0) {
    279   1.7  dholland 			lprintf("You just lost %ld experience point", (long) j);
    280   1.4  christos 			if (j > 1)
    281   1.4  christos 				lprcat("s!");
    282   1.4  christos 			else
    283   1.4  christos 				lprc('!');
    284   1.4  christos 			loseexperience((long) j);
    285   1.4  christos 		} else {
    286   1.7  dholland 			lprintf("You just gained %ld experience point", (long) j);
    287   1.4  christos 			if (j > 1)
    288   1.4  christos 				lprcat("s!");
    289   1.4  christos 			else
    290   1.4  christos 				lprc('!');
    291   1.4  christos 			raiseexperience((long) j);
    292   1.1       cgd 		}
    293   1.4  christos 		break;
    294   1.4  christos 	}
    295   1.1       cgd 	cursors();
    296   1.4  christos }
    297