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