main.c revision 1.3 1 1.3 cgd /* $NetBSD: main.c,v 1.3 1995/04/24 12:24:37 cgd Exp $ */
2 1.2 cgd
3 1.1 jtc /*
4 1.1 jtc * Phantasia 3.3.2 -- Interterminal fantasy game
5 1.1 jtc *
6 1.1 jtc * Edward A. Estes
7 1.1 jtc * AT&T, March 12, 1986
8 1.1 jtc */
9 1.1 jtc
10 1.1 jtc /* DISCLAIMER:
11 1.1 jtc *
12 1.1 jtc * This game is distributed for free as is. It is not guaranteed to work
13 1.1 jtc * in every conceivable environment. It is not even guaranteed to work
14 1.1 jtc * in ANY environment.
15 1.1 jtc *
16 1.1 jtc * This game is distributed without notice of copyright, therefore it
17 1.1 jtc * may be used in any manner the recipient sees fit. However, the
18 1.1 jtc * author assumes no responsibility for maintaining or revising this
19 1.1 jtc * game, in its original form, or any derivitives thereof.
20 1.1 jtc *
21 1.1 jtc * The author shall not be responsible for any loss, cost, or damage,
22 1.1 jtc * including consequential damage, caused by reliance on this material.
23 1.1 jtc *
24 1.1 jtc * The author makes no warranties, express or implied, including warranties
25 1.1 jtc * of merchantability or fitness for a particular purpose or use.
26 1.1 jtc *
27 1.1 jtc * AT&T is in no way connected with this game.
28 1.1 jtc */
29 1.1 jtc
30 1.1 jtc #include <sys/types.h>
31 1.1 jtc #include <pwd.h>
32 1.1 jtc
33 1.1 jtc /*
34 1.1 jtc * The program allocates as much file space as it needs to store characters,
35 1.1 jtc * so the possibility exists for the character file to grow without bound.
36 1.1 jtc * The file is purged upon normal entry to try to avoid that problem.
37 1.1 jtc * A similar problem exists for energy voids. To alleviate the problem here,
38 1.1 jtc * the void file is cleared with every new king, and a limit is placed
39 1.1 jtc * on the size of the energy void file.
40 1.1 jtc */
41 1.1 jtc
42 1.1 jtc /*
43 1.1 jtc * Put one line of text into the file 'motd' for announcements, etc.
44 1.1 jtc */
45 1.1 jtc
46 1.1 jtc /*
47 1.1 jtc * The scoreboard file is updated when someone dies, and keeps track
48 1.1 jtc * of the highest character to date for that login.
49 1.1 jtc * Being purged from the character file does not cause the scoreboard
50 1.1 jtc * to be updated.
51 1.1 jtc */
52 1.1 jtc
53 1.1 jtc /*
54 1.1 jtc * All source files are set up for 'vi' with shiftwidth=4, tabstop=8.
55 1.1 jtc */
56 1.1 jtc
57 1.1 jtc /**/
59 1.1 jtc
60 1.1 jtc /*
61 1.1 jtc * main.c Main routines for Phantasia
62 1.1 jtc */
63 1.1 jtc
64 1.1 jtc #include "include.h"
65 1.1 jtc
66 1.1 jtc /***************************************************************************
67 1.1 jtc / FUNCTION NAME: main()
68 1.1 jtc /
69 1.1 jtc / FUNCTION: initialize state, and call main process
70 1.1 jtc /
71 1.1 jtc / AUTHOR: E. A. Estes, 12/4/85
72 1.1 jtc /
73 1.1 jtc / ARGUMENTS:
74 1.1 jtc / int argc - argument count
75 1.1 jtc / char **argv - argument vector
76 1.1 jtc /
77 1.1 jtc / RETURN VALUE: none
78 1.1 jtc /
79 1.1 jtc / MODULES CALLED: monstlist(), checkenemy(), activelist(),
80 1.1 jtc / throneroom(), checkbattle(), readmessage(), changestats(), writerecord(),
81 1.1 jtc / tradingpost(), adjuststats(), recallplayer(), displaystats(), checktampered(),
82 1.1 jtc / fabs(), rollnewplayer(), time(), exit(), sqrt(), floor(), wmove(),
83 1.1 jtc / signal(), strcat(), purgeoldplayers(), getuid(), isatty(), wclear(),
84 1.1 jtc / strcpy(), system(), altercoordinates(), cleanup(), waddstr(), procmain(),
85 1.1 jtc / playinit(), leavegame(), localtime(), getanswer(), neatstuff(), initialstate(),
86 1.1 jtc / scorelist(), titlelist()
87 1.1 jtc /
88 1.1 jtc / GLOBAL INPUTS: *Login, Throne, Wizard, Player, *stdscr, Changed, Databuf[],
89 1.1 jtc / Fileloc, Stattable[]
90 1.1 jtc /
91 1.1 jtc / GLOBAL OUTPUTS: Wizard, Player, Changed, Fileloc, Timeout, *Statptr
92 1.1 jtc /
93 1.1 jtc / DESCRIPTION:
94 1.1 jtc / Process arguments, initialize program, and loop forever processing
95 1.1 jtc / player input.
96 1.1 jtc /
97 1.1 jtc /***************************************************************************/
98 1.1 jtc
99 1.1 jtc main(argc, argv)
100 1.1 jtc int argc;
101 1.1 jtc char **argv;
102 1.1 jtc {
103 1.1 jtc bool noheader = FALSE; /* set if don't want header */
104 1.1 jtc bool headeronly = FALSE; /* set if only want header */
105 1.3 cgd bool examine = FALSE; /* set if examine a character */
106 1.1 jtc time_t seconds; /* for time of day */
107 1.1 jtc double dtemp; /* for temporary calculations */
108 1.1 jtc
109 1.1 jtc initialstate(); /* init globals */
110 1.1 jtc
111 1.1 jtc /* process arguments */
112 1.1 jtc while (--argc && (*++argv)[0] == '-')
113 1.1 jtc switch ((*argv)[1])
114 1.1 jtc {
115 1.1 jtc case 's': /* short */
116 1.1 jtc noheader = TRUE;
117 1.1 jtc break;
118 1.1 jtc
119 1.1 jtc case 'H': /* Header */
120 1.1 jtc headeronly = TRUE;
121 1.1 jtc break;
122 1.1 jtc
123 1.1 jtc case 'a': /* all users */
124 1.1 jtc activelist();
125 1.1 jtc cleanup(TRUE);
126 1.1 jtc /*NOTREACHED*/
127 1.1 jtc
128 1.1 jtc case 'p': /* purge old players */
129 1.1 jtc purgeoldplayers();
130 1.1 jtc cleanup(TRUE);
131 1.1 jtc /*NOTREACHED*/
132 1.1 jtc
133 1.1 jtc case 'S': /* set 'Wizard' */
134 1.1 jtc Wizard = !getuid();
135 1.1 jtc break;
136 1.1 jtc
137 1.1 jtc case 'x': /* examine */
138 1.1 jtc examine = TRUE;
139 1.1 jtc break;
140 1.1 jtc
141 1.1 jtc case 'm': /* monsters */
142 1.1 jtc monstlist();
143 1.1 jtc cleanup(TRUE);
144 1.1 jtc /*NOTREACHED*/
145 1.1 jtc
146 1.1 jtc case 'b': /* scoreboard */
147 1.1 jtc scorelist();
148 1.1 jtc cleanup(TRUE);
149 1.1 jtc /*NOTREACHED*/
150 1.1 jtc }
151 1.1 jtc
152 1.1 jtc if (!isatty(0)) /* don't let non-tty's play */
153 1.1 jtc cleanup(TRUE);
154 1.1 jtc /*NOTREACHED*/
155 1.1 jtc
156 1.1 jtc playinit(); /* set up to catch signals, init curses */
157 1.1 jtc
158 1.1 jtc if (examine)
159 1.1 jtc {
160 1.1 jtc changestats(FALSE);
161 1.1 jtc cleanup(TRUE);
162 1.1 jtc /*NOTREACHED*/
163 1.1 jtc }
164 1.1 jtc
165 1.1 jtc if (!noheader)
166 1.1 jtc {
167 1.1 jtc titlelist();
168 1.1 jtc purgeoldplayers(); /* clean up old characters */
169 1.1 jtc }
170 1.1 jtc
171 1.1 jtc if (headeronly)
172 1.1 jtc cleanup(TRUE);
173 1.1 jtc /*NOTREACHED*/
174 1.1 jtc
175 1.1 jtc do
176 1.1 jtc /* get the player structure filled */
177 1.1 jtc {
178 1.1 jtc Fileloc = -1L;
179 1.1 jtc
180 1.1 jtc mvaddstr(22, 17, "Do you have a character to run [Q = Quit] ? ");
181 1.1 jtc
182 1.1 jtc switch (getanswer("NYQ", FALSE))
183 1.1 jtc {
184 1.1 jtc case 'Y':
185 1.1 jtc Fileloc = recallplayer();
186 1.1 jtc break;
187 1.1 jtc
188 1.1 jtc case 'Q':
189 1.1 jtc cleanup(TRUE);
190 1.1 jtc /*NOTREACHED*/
191 1.1 jtc
192 1.1 jtc default:
193 1.1 jtc Fileloc = rollnewplayer();
194 1.1 jtc break;
195 1.1 jtc }
196 1.1 jtc clear();
197 1.1 jtc }
198 1.1 jtc while (Fileloc < 0L);
199 1.1 jtc
200 1.1 jtc if (Player.p_level > 5.0)
201 1.1 jtc /* low level players have long timeout */
202 1.1 jtc Timeout = TRUE;
203 1.1 jtc
204 1.1 jtc /* update some important player statistics */
205 1.1 jtc strcpy(Player.p_login, Login);
206 1.1 jtc time(&seconds);
207 1.1 jtc Player.p_lastused = localtime(&seconds)->tm_yday;
208 1.1 jtc Player.p_status = S_PLAYING;
209 1.1 jtc writerecord(&Player, Fileloc);
210 1.1 jtc
211 1.1 jtc Statptr = &Stattable[Player.p_type]; /* initialize pointer */
212 1.1 jtc
213 1.1 jtc /* catch interrupts */
214 1.1 jtc #ifdef BSD41
215 1.1 jtc sigset(SIGINT, interrupt);
216 1.1 jtc #endif
217 1.1 jtc #ifdef BSD42
218 1.1 jtc signal(SIGINT, interrupt);
219 1.1 jtc #endif
220 1.1 jtc #ifdef SYS3
221 1.1 jtc signal(SIGINT, interrupt);
222 1.1 jtc #endif
223 1.1 jtc #ifdef SYS5
224 1.1 jtc signal(SIGINT, interrupt);
225 1.1 jtc #endif
226 1.1 jtc
227 1.1 jtc altercoordinates(Player.p_x, Player.p_y, A_FORCED); /* set some flags */
228 1.1 jtc
229 1.1 jtc clear();
230 1.1 jtc
231 1.1 jtc for (;;)
232 1.1 jtc /* loop forever, processing input */
233 1.1 jtc {
234 1.1 jtc
235 1.1 jtc adjuststats(); /* cleanup stats */
236 1.1 jtc
237 1.1 jtc if (Throne && Player.p_crowns == 0 && Player.p_specialtype != SC_KING)
238 1.1 jtc /* not allowed on throne -- move */
239 1.1 jtc {
240 1.1 jtc mvaddstr(5,0,"You're not allowed in the Lord's Chamber without a crown.\n");
241 1.1 jtc altercoordinates(0.0, 0.0, A_NEAR);
242 1.1 jtc }
243 1.1 jtc
244 1.1 jtc checktampered(); /* check for energy voids, etc. */
245 1.1 jtc
246 1.1 jtc if (Player.p_status != S_CLOAKED
247 1.1 jtc /* not cloaked */
248 1.1 jtc && (dtemp = fabs(Player.p_x)) == fabs(Player.p_y)
249 1.1 jtc /* |x| = |y| */
250 1.1 jtc && !Throne)
251 1.1 jtc /* not on throne */
252 1.1 jtc {
253 1.1 jtc dtemp = sqrt(dtemp / 100.0);
254 1.1 jtc if (floor(dtemp) == dtemp)
255 1.1 jtc /* |x| / 100 == n*n; at a trading post */
256 1.1 jtc {
257 1.1 jtc tradingpost();
258 1.1 jtc clear();
259 1.1 jtc }
260 1.1 jtc }
261 1.1 jtc
262 1.1 jtc checkbattle(); /* check for player to player battle */
263 1.1 jtc neatstuff(); /* gurus, medics, etc. */
264 1.1 jtc
265 1.1 jtc if (Player.p_status == S_CLOAKED)
266 1.1 jtc /* costs 3 mana per turn to be cloaked */
267 1.1 jtc if (Player.p_mana > 3.0)
268 1.1 jtc Player.p_mana -= 3.0;
269 1.1 jtc else
270 1.1 jtc /* ran out of mana, uncloak */
271 1.1 jtc {
272 1.1 jtc Player.p_status = S_PLAYING;
273 1.1 jtc Changed = TRUE;
274 1.1 jtc }
275 1.1 jtc
276 1.1 jtc if (Player.p_status != S_PLAYING && Player.p_status != S_CLOAKED)
277 1.1 jtc /* change status back to S_PLAYING */
278 1.1 jtc {
279 1.1 jtc Player.p_status = S_PLAYING;
280 1.1 jtc Changed = TRUE;
281 1.1 jtc }
282 1.1 jtc
283 1.1 jtc if (Changed)
284 1.1 jtc /* update file only if important stuff has changed */
285 1.1 jtc {
286 1.1 jtc writerecord(&Player, Fileloc);
287 1.1 jtc Changed = FALSE;
288 1.1 jtc continue;
289 1.1 jtc }
290 1.1 jtc
291 1.1 jtc readmessage(); /* read message, if any */
292 1.1 jtc
293 1.1 jtc displaystats(); /* print statistics */
294 1.1 jtc
295 1.1 jtc move(6, 0);
296 1.1 jtc
297 1.1 jtc if (Throne)
298 1.1 jtc /* maybe make king, print prompt, etc. */
299 1.1 jtc throneroom();
300 1.1 jtc
301 1.1 jtc /* print status line */
302 1.1 jtc addstr("1:Move 2:Players 3:Talk 4:Stats 5:Quit ");
303 1.1 jtc if (Player.p_level >= MEL_CLOAK && Player.p_magiclvl >= ML_CLOAK)
304 1.1 jtc addstr("6:Cloak ");
305 1.1 jtc if (Player.p_level >= MEL_TELEPORT && Player.p_magiclvl >= ML_TELEPORT)
306 1.1 jtc addstr("7:Teleport ");
307 1.1 jtc if (Player.p_specialtype >= SC_COUNCIL || Wizard)
308 1.1 jtc addstr("8:Intervene ");
309 1.1 jtc
310 1.1 jtc procmain(); /* process input */
311 1.1 jtc }
312 1.1 jtc }
313 1.1 jtc /**/
315 1.1 jtc /************************************************************************
316 1.1 jtc /
317 1.1 jtc / FUNCTION NAME: initialstate()
318 1.1 jtc /
319 1.1 jtc / FUNCTION: initialize some important global variable
320 1.1 jtc /
321 1.1 jtc / AUTHOR: E. A. Estes, 12/4/85
322 1.1 jtc /
323 1.1 jtc / ARGUMENTS: none
324 1.1 jtc /
325 1.1 jtc / RETURN VALUE: none
326 1.1 jtc /
327 1.1 jtc / MODULES CALLED: time(), fopen(), srandom(), error(), getuid(), getlogin(),
328 1.1 jtc / getpwuid()
329 1.1 jtc /
330 1.1 jtc / GLOBAL INPUTS:
331 1.1 jtc /
332 1.1 jtc / GLOBAL OUTPUTS: *Energyvoidfp, Echo, Marsh, *Login, Users, Beyond,
333 1.1 jtc / Throne, Wizard, Changed, Okcount, Timeout, Windows, *Monstfp, *Messagefp,
334 1.1 jtc / *Playersfp
335 1.1 jtc /
336 1.1 jtc / DESCRIPTION:
337 1.1 jtc / Set global flags, and open files which remain open.
338 1.1 jtc /
339 1.1 jtc /************************************************************************/
340 1.1 jtc
341 1.1 jtc initialstate()
342 1.1 jtc {
343 1.1 jtc Beyond = FALSE;
344 1.1 jtc Marsh = FALSE;
345 1.1 jtc Throne = FALSE;
346 1.1 jtc Changed = FALSE;
347 1.1 jtc Wizard = FALSE;
348 1.1 jtc Timeout = FALSE;
349 1.1 jtc Users = 0;
350 1.1 jtc Windows = FALSE;
351 1.1 jtc Echo = TRUE;
352 1.1 jtc
353 1.1 jtc /* setup login name */
354 1.1 jtc if ((Login = getlogin()) == NULL)
355 1.1 jtc Login = getpwuid(getuid())->pw_name;
356 1.1 jtc
357 1.1 jtc /* open some files */
358 1.1 jtc if ((Playersfp = fopen(_PATH_PEOPLE, "r+")) == NULL)
359 1.1 jtc error(_PATH_PEOPLE);
360 1.1 jtc /*NOTREACHED*/
361 1.1 jtc
362 1.1 jtc if ((Monstfp = fopen(_PATH_MONST, "r+")) == NULL)
363 1.1 jtc error(_PATH_MONST);
364 1.1 jtc /*NOTREACHED*/
365 1.1 jtc
366 1.1 jtc if ((Messagefp = fopen(_PATH_MESS, "r")) == NULL)
367 1.1 jtc error(_PATH_MESS);
368 1.1 jtc /*NOTREACHED*/
369 1.1 jtc
370 1.1 jtc if ((Energyvoidfp = fopen(_PATH_VOID, "r+")) == NULL)
371 1.1 jtc error(_PATH_VOID);
372 1.3 cgd /*NOTREACHED*/
373 1.1 jtc
374 1.1 jtc srandom((unsigned) time(NULL)); /* prime random numbers */
375 1.1 jtc }
376 1.1 jtc /**/
378 1.1 jtc /************************************************************************
379 1.1 jtc /
380 1.1 jtc / FUNCTION NAME: rollnewplayer()
381 1.1 jtc /
382 1.1 jtc / FUNCTION: roll up a new character
383 1.1 jtc /
384 1.1 jtc / AUTHOR: E. A. Estes, 12/4/85
385 1.1 jtc /
386 1.1 jtc / ARGUMENTS: none
387 1.1 jtc /
388 1.1 jtc / RETURN VALUE: none
389 1.1 jtc /
390 1.1 jtc / MODULES CALLED: initplayer(), allocrecord(), truncstring(), fabs(), wmove(),
391 1.1 jtc / wclear(), sscanf(), strcmp(), genchar(), waddstr(), findname(), mvprintw(),
392 1.1 jtc / getanswer(), getstring()
393 1.1 jtc /
394 1.1 jtc / GLOBAL INPUTS: Other, Wizard, Player, *stdscr, Databuf[]
395 1.1 jtc /
396 1.1 jtc / GLOBAL OUTPUTS: Echo
397 1.1 jtc /
398 1.1 jtc / DESCRIPTION:
399 1.1 jtc / Prompt player, and roll up new character.
400 1.1 jtc /
401 1.1 jtc /************************************************************************/
402 1.1 jtc
403 1.1 jtc long
404 1.1 jtc rollnewplayer()
405 1.1 jtc {
406 1.1 jtc int chartype; /* character type */
407 1.1 jtc int ch; /* input */
408 1.1 jtc
409 1.1 jtc initplayer(&Player); /* initialize player structure */
410 1.1 jtc
411 1.1 jtc clear();
412 1.1 jtc mvaddstr(4, 21, "Which type of character do you want:");
413 1.1 jtc mvaddstr(8, 4, "1:Magic User 2:Fighter 3:Elf 4:Dwarf 5:Halfling 6:Experimento ");
414 1.1 jtc if (Wizard) {
415 1.1 jtc addstr("7:Super ? ");
416 1.1 jtc chartype = getanswer("1234567", FALSE);
417 1.1 jtc }
418 1.1 jtc else {
419 1.1 jtc addstr("? ");
420 1.1 jtc chartype = getanswer("123456", FALSE);
421 1.1 jtc }
422 1.1 jtc
423 1.1 jtc do
424 1.1 jtc {
425 1.1 jtc genchar(chartype); /* roll up a character */
426 1.1 jtc
427 1.1 jtc /* print out results */
428 1.1 jtc mvprintw(12, 14,
429 1.1 jtc "Strength : %2.0f Quickness: %2.0f Mana : %2.0f\n",
430 1.1 jtc Player.p_strength, Player.p_quickness, Player.p_mana);
431 1.1 jtc mvprintw(13, 14,
432 1.1 jtc "Energy Level: %2.0f Brains : %2.0f Magic Level: %2.0f\n",
433 1.1 jtc Player.p_energy, Player.p_brains, Player.p_magiclvl);
434 1.1 jtc
435 1.1 jtc if (Player.p_type == C_EXPER || Player.p_type == C_SUPER)
436 1.1 jtc break;
437 1.1 jtc
438 1.1 jtc mvaddstr(14, 14, "Type '1' to keep >");
439 1.1 jtc ch = getanswer(" ", TRUE);
440 1.1 jtc }
441 1.1 jtc while (ch != '1');
442 1.1 jtc
443 1.1 jtc if (Player.p_type == C_EXPER || Player.p_type == C_SUPER)
444 1.1 jtc /* get coordinates for experimento */
445 1.1 jtc for (;;)
446 1.1 jtc {
447 1.1 jtc mvaddstr(16, 0, "Enter the X Y coordinates of your experimento ? ");
448 1.1 jtc getstring(Databuf, SZ_DATABUF);
449 1.1 jtc sscanf(Databuf, "%lf %lf", &Player.p_x, &Player.p_y);
450 1.1 jtc
451 1.1 jtc if (fabs(Player.p_x) > D_EXPER || fabs(Player.p_y) > D_EXPER)
452 1.1 jtc mvaddstr(17, 0, "Invalid coordinates. Try again.\n");
453 1.1 jtc else
454 1.1 jtc break;
455 1.1 jtc }
456 1.1 jtc
457 1.1 jtc for (;;)
458 1.1 jtc /* name the new character */
459 1.1 jtc {
460 1.1 jtc mvprintw(18, 0,
461 1.1 jtc "Give your character a name [up to %d characters] ? ", SZ_NAME - 1);
462 1.1 jtc getstring(Player.p_name, SZ_NAME);
463 1.1 jtc truncstring(Player.p_name); /* remove trailing blanks */
464 1.1 jtc
465 1.1 jtc if (Player.p_name[0] == '\0')
466 1.1 jtc /* no null names */
467 1.1 jtc mvaddstr(19, 0, "Invalid name.");
468 1.1 jtc else if (findname(Player.p_name, &Other) >= 0L)
469 1.1 jtc /* cannot have duplicate names */
470 1.1 jtc mvaddstr(19, 0, "Name already in use.");
471 1.1 jtc else
472 1.1 jtc /* name is acceptable */
473 1.1 jtc break;
474 1.1 jtc
475 1.1 jtc addstr(" Pick another.\n");
476 1.1 jtc }
477 1.1 jtc
478 1.1 jtc /* get a password for character */
479 1.1 jtc Echo = FALSE;
480 1.1 jtc
481 1.1 jtc do
482 1.1 jtc {
483 1.1 jtc mvaddstr(20, 0, "Give your character a password [up to 8 characters] ? ");
484 1.1 jtc getstring(Player.p_password, SZ_PASSWORD);
485 1.1 jtc mvaddstr(21, 0, "One more time to verify ? ");
486 1.1 jtc getstring(Databuf, SZ_PASSWORD);
487 1.1 jtc }
488 1.1 jtc while (strcmp(Player.p_password, Databuf) != 0);
489 1.1 jtc
490 1.1 jtc Echo = TRUE;
491 1.1 jtc
492 1.1 jtc return(allocrecord());
493 1.1 jtc }
494 1.1 jtc /**/
496 1.1 jtc /************************************************************************
497 1.1 jtc /
498 1.1 jtc / FUNCTION NAME: procmain()
499 1.1 jtc /
500 1.1 jtc / FUNCTION: process input from player
501 1.1 jtc /
502 1.1 jtc / AUTHOR: E. A. Estes, 12/4/85
503 1.1 jtc /
504 1.1 jtc / ARGUMENTS: none
505 1.1 jtc /
506 1.1 jtc / RETURN VALUE: none
507 1.1 jtc /
508 1.1 jtc / MODULES CALLED: dotampered(), changestats(), inputoption(), allstatslist(),
509 1.1 jtc / fopen(), wmove(), drandom(), sscanf(), fclose(), altercoordinates(),
510 1.1 jtc / waddstr(), fprintf(), distance(), userlist(), leavegame(), encounter(),
511 1.1 jtc / getstring(), wclrtobot()
512 1.1 jtc /
513 1.1 jtc / GLOBAL INPUTS: Circle, Illcmd[], Throne, Wizard, Player, *stdscr,
514 1.1 jtc / Databuf[], Illmove[]
515 1.1 jtc /
516 1.1 jtc / GLOBAL OUTPUTS: Player, Changed
517 1.1 jtc /
518 1.1 jtc / DESCRIPTION:
519 1.1 jtc / Process main menu options.
520 1.1 jtc /
521 1.1 jtc /************************************************************************/
522 1.1 jtc
523 1.1 jtc procmain()
524 1.1 jtc {
525 1.1 jtc int ch; /* input */
526 1.1 jtc double x; /* desired new x coordinate */
527 1.1 jtc double y; /* desired new y coordinate */
528 1.1 jtc double temp; /* for temporary calculations */
529 1.1 jtc FILE *fp; /* for opening files */
530 1.1 jtc register int loop; /* a loop counter */
531 1.1 jtc bool hasmoved = FALSE; /* set if player has moved */
532 1.1 jtc
533 1.1 jtc ch = inputoption();
534 1.1 jtc mvaddstr(4, 0, "\n\n"); /* clear status area */
535 1.1 jtc
536 1.1 jtc move(7, 0);
537 1.1 jtc clrtobot(); /* clear data on bottom area of screen */
538 1.1 jtc
539 1.1 jtc if (Player.p_specialtype == SC_VALAR && (ch == '1' || ch == '7'))
540 1.1 jtc /* valar cannot move */
541 1.1 jtc ch = ' ';
542 1.1 jtc
543 1.1 jtc switch (ch)
544 1.1 jtc {
545 1.1 jtc case 'K': /* move up/north */
546 1.1 jtc case 'N':
547 1.1 jtc x = Player.p_x;
548 1.1 jtc y = Player.p_y + MAXMOVE();
549 1.1 jtc hasmoved = TRUE;
550 1.1 jtc break;
551 1.1 jtc
552 1.1 jtc case 'J': /* move down/south */
553 1.1 jtc case 'S':
554 1.1 jtc x = Player.p_x;
555 1.1 jtc y = Player.p_y - MAXMOVE();
556 1.1 jtc hasmoved = TRUE;
557 1.1 jtc break;
558 1.1 jtc
559 1.1 jtc case 'L': /* move right/east */
560 1.1 jtc case 'E':
561 1.1 jtc x = Player.p_x + MAXMOVE();
562 1.1 jtc y = Player.p_y;
563 1.1 jtc hasmoved = TRUE;
564 1.1 jtc break;
565 1.1 jtc
566 1.1 jtc case 'H': /* move left/west */
567 1.1 jtc case 'W':
568 1.1 jtc x = Player.p_x - MAXMOVE();
569 1.1 jtc y = Player.p_y;
570 1.1 jtc hasmoved = TRUE;
571 1.1 jtc break;
572 1.1 jtc
573 1.1 jtc default: /* rest */
574 1.1 jtc Player.p_energy += (Player.p_maxenergy + Player.p_shield) / 15.0
575 1.1 jtc + Player.p_level / 3.0 + 2.0;
576 1.1 jtc Player.p_energy =
577 1.1 jtc MIN(Player.p_energy, Player.p_maxenergy + Player.p_shield);
578 1.1 jtc
579 1.1 jtc if (Player.p_status != S_CLOAKED)
580 1.1 jtc /* cannot find mana if cloaked */
581 1.1 jtc {
582 1.1 jtc Player.p_mana += (Circle + Player.p_level) / 4.0;
583 1.1 jtc
584 1.1 jtc if (drandom() < 0.2 && Player.p_status == S_PLAYING && !Throne)
585 1.1 jtc /* wandering monster */
586 1.1 jtc encounter(-1);
587 1.1 jtc }
588 1.1 jtc break;
589 1.1 jtc
590 1.1 jtc case 'X': /* change/examine a character */
591 1.1 jtc changestats(TRUE);
592 1.1 jtc break;
593 1.1 jtc
594 1.1 jtc case '1': /* move */
595 1.1 jtc for (loop = 3; loop; --loop)
596 1.1 jtc {
597 1.1 jtc mvaddstr(4, 0, "X Y Coordinates ? ");
598 1.1 jtc getstring(Databuf, SZ_DATABUF);
599 1.1 jtc
600 1.1 jtc if (sscanf(Databuf, "%lf %lf", &x, &y) != 2)
601 1.1 jtc mvaddstr(5, 0, "Try again\n");
602 1.1 jtc else if (distance(Player.p_x, x, Player.p_y, y) > MAXMOVE())
603 1.1 jtc ILLMOVE();
604 1.1 jtc else
605 1.1 jtc {
606 1.1 jtc hasmoved = TRUE;
607 1.1 jtc break;
608 1.1 jtc }
609 1.1 jtc }
610 1.1 jtc break;
611 1.1 jtc
612 1.1 jtc case '2': /* players */
613 1.1 jtc userlist(TRUE);
614 1.1 jtc break;
615 1.1 jtc
616 1.1 jtc case '3': /* message */
617 1.1 jtc mvaddstr(4, 0, "Message ? ");
618 1.1 jtc getstring(Databuf, SZ_DATABUF);
619 1.1 jtc /* we open the file for writing to erase any data which is already there */
620 1.1 jtc fp = fopen(_PATH_MESS, "w");
621 1.1 jtc if (Databuf[0] != '\0')
622 1.1 jtc fprintf(fp, "%s: %s", Player.p_name, Databuf);
623 1.1 jtc fclose(fp);
624 1.1 jtc break;
625 1.1 jtc
626 1.1 jtc case '4': /* stats */
627 1.1 jtc allstatslist();
628 1.1 jtc break;
629 1.1 jtc
630 1.1 jtc case '5': /* good-bye */
631 1.1 jtc leavegame();
632 1.1 jtc /*NOTREACHED*/
633 1.1 jtc
634 1.1 jtc case '6': /* cloak */
635 1.1 jtc if (Player.p_level < MEL_CLOAK || Player.p_magiclvl < ML_CLOAK)
636 1.1 jtc ILLCMD();
637 1.1 jtc else if (Player.p_status == S_CLOAKED)
638 1.1 jtc Player.p_status = S_PLAYING;
639 1.1 jtc else if (Player.p_mana < MM_CLOAK)
640 1.1 jtc mvaddstr(5, 0, "No mana left.\n");
641 1.1 jtc else
642 1.1 jtc {
643 1.1 jtc Changed = TRUE;
644 1.1 jtc Player.p_mana -= MM_CLOAK;
645 1.1 jtc Player.p_status = S_CLOAKED;
646 1.1 jtc }
647 1.1 jtc break;
648 1.1 jtc
649 1.1 jtc case '7': /* teleport */
650 1.1 jtc /*
651 1.1 jtc * conditions for teleport
652 1.1 jtc * - 20 per (level plus magic level)
653 1.1 jtc * - OR council of the wise or valar or ex-valar
654 1.1 jtc * - OR transport from throne
655 1.1 jtc * transports from throne cost no mana
656 1.1 jtc */
657 1.1 jtc if (Player.p_level < MEL_TELEPORT || Player.p_magiclvl < ML_TELEPORT)
658 1.1 jtc ILLCMD();
659 1.1 jtc else
660 1.1 jtc for (loop = 3; loop; --loop)
661 1.1 jtc {
662 1.1 jtc mvaddstr(4, 0, "X Y Coordinates ? ");
663 1.1 jtc getstring(Databuf, SZ_DATABUF);
664 1.1 jtc
665 1.1 jtc if (sscanf(Databuf, "%lf %lf", &x, &y) == 2)
666 1.1 jtc {
667 1.1 jtc temp = distance(Player.p_x, x, Player.p_y, y);
668 1.1 jtc if (!Throne
669 1.1 jtc /* can transport anywhere from throne */
670 1.1 jtc && Player.p_specialtype <= SC_COUNCIL
671 1.1 jtc /* council, valar can transport anywhere */
672 1.1 jtc && temp > (Player.p_level + Player.p_magiclvl) * 20.0)
673 1.1 jtc /* can only move 20 per exp. level + mag. level */
674 1.1 jtc ILLMOVE();
675 1.1 jtc else
676 1.1 jtc {
677 1.1 jtc temp = (temp / 75.0 + 1.0) * 20.0; /* mana used */
678 1.1 jtc
679 1.1 jtc if (!Throne && temp > Player.p_mana)
680 1.1 jtc mvaddstr(5, 0, "Not enough power for that distance.\n");
681 1.1 jtc else
682 1.1 jtc {
683 1.1 jtc if (!Throne)
684 1.1 jtc Player.p_mana -= temp;
685 1.1 jtc hasmoved = TRUE;
686 1.1 jtc break;
687 1.1 jtc }
688 1.1 jtc }
689 1.1 jtc }
690 1.1 jtc }
691 1.1 jtc break;
692 1.1 jtc
693 1.1 jtc case 'C':
694 1.1 jtc case '9': /* monster */
695 1.1 jtc if (Throne)
696 1.1 jtc /* no monsters while on throne */
697 1.1 jtc mvaddstr(5, 0, "No monsters in the chamber!\n");
698 1.1 jtc else if (Player.p_specialtype != SC_VALAR)
699 1.1 jtc /* the valar cannot call monsters */
700 1.1 jtc {
701 1.1 jtc Player.p_sin += 1e-6;
702 1.1 jtc encounter(-1);
703 1.1 jtc }
704 1.1 jtc break;
705 1.1 jtc
706 1.1 jtc case '0': /* decree */
707 1.1 jtc if (Wizard || Player.p_specialtype == SC_KING && Throne)
708 1.1 jtc /* kings must be on throne to decree */
709 1.1 jtc dotampered();
710 1.1 jtc else
711 1.1 jtc ILLCMD();
712 1.1 jtc break;
713 1.1 jtc
714 1.1 jtc case '8': /* intervention */
715 1.1 jtc if (Wizard || Player.p_specialtype >= SC_COUNCIL)
716 1.1 jtc dotampered();
717 1.1 jtc else
718 1.1 jtc ILLCMD();
719 1.1 jtc break;
720 1.1 jtc }
721 1.1 jtc
722 1.1 jtc if (hasmoved)
723 1.1 jtc /* player has moved -- alter coordinates, and do random monster */
724 1.1 jtc {
725 1.1 jtc altercoordinates(x, y, A_SPECIFIC);
726 1.1 jtc
727 1.1 jtc if (drandom() < 0.2 && Player.p_status == S_PLAYING && !Throne)
728 1.1 jtc encounter(-1);
729 1.1 jtc }
730 1.1 jtc }
731 1.1 jtc /**/
733 1.1 jtc /************************************************************************
734 1.1 jtc /
735 1.1 jtc / FUNCTION NAME: titlelist()
736 1.1 jtc /
737 1.1 jtc / FUNCTION: print title page
738 1.1 jtc /
739 1.1 jtc / AUTHOR: E. A. Estes, 12/4/85
740 1.1 jtc /
741 1.1 jtc / ARGUMENTS: none
742 1.1 jtc /
743 1.1 jtc / RETURN VALUE: none
744 1.1 jtc /
745 1.1 jtc / MODULES CALLED: fread(), fseek(), fopen(), fgets(), wmove(), strcpy(),
746 1.1 jtc / fclose(), strlen(), waddstr(), sprintf(), wrefresh()
747 1.1 jtc /
748 1.1 jtc / GLOBAL INPUTS: Lines, Other, *stdscr, Databuf[], *Playersfp
749 1.1 jtc /
750 1.1 jtc / GLOBAL OUTPUTS: Lines
751 1.1 jtc /
752 1.1 jtc / DESCRIPTION:
753 1.1 jtc / Print important information about game, players, etc.
754 1.1 jtc /
755 1.1 jtc /************************************************************************/
756 1.1 jtc
757 1.1 jtc titlelist()
758 1.1 jtc {
759 1.1 jtc register FILE *fp; /* used for opening various files */
760 1.1 jtc bool councilfound = FALSE; /* set if we find a member of the council */
761 1.1 jtc bool kingfound = FALSE; /* set if we find a king */
762 1.1 jtc double hiexp, nxtexp; /* used for finding the two highest players */
763 1.1 jtc double hilvl, nxtlvl; /* used for finding the two highest players */
764 1.1 jtc char hiname[21], nxtname[21];/* used for finding the two highest players */
765 1.1 jtc
766 1.1 jtc mvaddstr(0, 14, "W e l c o m e t o P h a n t a s i a (vers. 3.3.2)!");
767 1.1 jtc
768 1.1 jtc /* print message of the day */
769 1.1 jtc if ((fp = fopen(_PATH_MOTD, "r")) != NULL
770 1.1 jtc && fgets(Databuf, SZ_DATABUF, fp) != NULL)
771 1.1 jtc {
772 1.1 jtc mvaddstr(2, 40 - strlen(Databuf) / 2, Databuf);
773 1.1 jtc fclose(fp);
774 1.1 jtc }
775 1.1 jtc
776 1.1 jtc /* search for king */
777 1.1 jtc fseek(Playersfp, 0L, 0);
778 1.1 jtc while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
779 1.1 jtc if (Other.p_specialtype == SC_KING && Other.p_status != S_NOTUSED)
780 1.1 jtc /* found the king */
781 1.1 jtc {
782 1.1 jtc sprintf(Databuf, "The present ruler is %s Level:%.0f",
783 1.1 jtc Other.p_name, Other.p_level);
784 1.1 jtc mvaddstr(4, 40 - strlen(Databuf) / 2, Databuf);
785 1.1 jtc kingfound = TRUE;
786 1.1 jtc break;
787 1.1 jtc }
788 1.1 jtc
789 1.1 jtc if (!kingfound)
790 1.1 jtc mvaddstr(4, 24, "There is no ruler at this time.");
791 1.1 jtc
792 1.1 jtc /* search for valar */
793 1.1 jtc fseek(Playersfp, 0L, 0);
794 1.1 jtc while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
795 1.1 jtc if (Other.p_specialtype == SC_VALAR && Other.p_status != S_NOTUSED)
796 1.1 jtc /* found the valar */
797 1.1 jtc {
798 1.1 jtc sprintf(Databuf, "The Valar is %s Login: %s", Other.p_name, Other.p_login);
799 1.1 jtc mvaddstr(6, 40 - strlen(Databuf) / 2 , Databuf);
800 1.1 jtc break;
801 1.1 jtc }
802 1.1 jtc
803 1.1 jtc /* search for council of the wise */
804 1.1 jtc fseek(Playersfp, 0L, 0);
805 1.1 jtc Lines = 10;
806 1.1 jtc while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
807 1.1 jtc if (Other.p_specialtype == SC_COUNCIL && Other.p_status != S_NOTUSED)
808 1.1 jtc /* found a member of the council */
809 1.1 jtc {
810 1.1 jtc if (!councilfound)
811 1.1 jtc {
812 1.1 jtc mvaddstr(8, 30, "Council of the Wise:");
813 1.1 jtc councilfound = TRUE;
814 1.1 jtc }
815 1.1 jtc
816 1.1 jtc /* This assumes a finite (<=5) number of C.O.W.: */
817 1.1 jtc sprintf(Databuf, "%s Login: %s", Other.p_name, Other.p_login);
818 1.1 jtc mvaddstr(Lines++, 40 - strlen(Databuf) / 2, Databuf);
819 1.1 jtc }
820 1.1 jtc
821 1.1 jtc /* search for the two highest players */
822 1.1 jtc nxtname[0] = hiname[0] = '\0';
823 1.1 jtc hiexp = 0.0;
824 1.1 jtc nxtlvl = hilvl = 0;
825 1.1 jtc
826 1.1 jtc fseek(Playersfp, 0L, 0);
827 1.1 jtc while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
828 1.1 jtc if (Other.p_experience > hiexp && Other.p_specialtype <= SC_KING && Other.p_status != S_NOTUSED)
829 1.1 jtc /* highest found so far */
830 1.1 jtc {
831 1.1 jtc nxtexp = hiexp;
832 1.1 jtc hiexp = Other.p_experience;
833 1.1 jtc nxtlvl = hilvl;
834 1.1 jtc hilvl = Other.p_level;
835 1.1 jtc strcpy(nxtname, hiname);
836 1.1 jtc strcpy(hiname, Other.p_name);
837 1.1 jtc }
838 1.1 jtc else if (Other.p_experience > nxtexp
839 1.1 jtc && Other.p_specialtype <= SC_KING
840 1.1 jtc && Other.p_status != S_NOTUSED)
841 1.1 jtc /* next highest found so far */
842 1.1 jtc {
843 1.1 jtc nxtexp = Other.p_experience;
844 1.1 jtc nxtlvl = Other.p_level;
845 1.1 jtc strcpy(nxtname, Other.p_name);
846 1.1 jtc }
847 1.1 jtc
848 1.1 jtc mvaddstr(15, 28, "Highest characters are:");
849 1.1 jtc sprintf(Databuf, "%s Level:%.0f and %s Level:%.0f",
850 1.1 jtc hiname, hilvl, nxtname, nxtlvl);
851 1.1 jtc mvaddstr(17, 40 - strlen(Databuf) / 2, Databuf);
852 1.1 jtc
853 1.1 jtc /* print last to die */
854 1.1 jtc if ((fp = fopen(_PATH_LASTDEAD,"r")) != NULL
855 1.1 jtc && fgets(Databuf, SZ_DATABUF, fp) != NULL)
856 1.1 jtc {
857 1.1 jtc mvaddstr(19, 25, "The last character to die was:");
858 1.1 jtc mvaddstr(20, 40 - strlen(Databuf) / 2,Databuf);
859 1.1 jtc fclose(fp);
860 1.1 jtc }
861 1.1 jtc
862 1.1 jtc refresh();
863 1.1 jtc }
864 1.1 jtc /**/
866 1.1 jtc /************************************************************************
867 1.1 jtc /
868 1.1 jtc / FUNCTION NAME: recallplayer()
869 1.1 jtc /
870 1.1 jtc / FUNCTION: find a character on file
871 1.1 jtc /
872 1.1 jtc / AUTHOR: E. A. Estes, 12/4/85
873 1.1 jtc /
874 1.1 jtc / ARGUMENTS: none
875 1.1 jtc /
876 1.1 jtc / RETURN VALUE: none
877 1.1 jtc /
878 1.1 jtc / MODULES CALLED: writerecord(), truncstring(), more(), death(), wmove(),
879 1.1 jtc / wclear(), strcmp(), printw(), cleanup(), waddstr(), findname(), mvprintw(),
880 1.1 jtc / getanswer(), getstring()
881 1.1 jtc /
882 1.1 jtc / GLOBAL INPUTS: Player, *stdscr, Databuf[]
883 1.1 jtc /
884 1.1 jtc / GLOBAL OUTPUTS: Echo, Player
885 1.1 jtc /
886 1.1 jtc / DESCRIPTION:
887 1.1 jtc / Search for a character of a certain name, and check password.
888 1.1 jtc /
889 1.1 jtc /************************************************************************/
890 1.1 jtc
891 1.1 jtc long
892 1.1 jtc recallplayer()
893 1.1 jtc {
894 1.1 jtc long loc = 0L; /* location in player file */
895 1.1 jtc register int loop; /* loop counter */
896 1.1 jtc int ch; /* input */
897 1.1 jtc
898 1.1 jtc clear();
899 1.1 jtc mvprintw(10, 0, "What was your character's name ? ");
900 1.1 jtc getstring(Databuf, SZ_NAME);
901 1.1 jtc truncstring(Databuf);
902 1.1 jtc
903 1.1 jtc if ((loc = findname(Databuf, &Player)) >= 0L)
904 1.1 jtc /* found character */
905 1.1 jtc {
906 1.1 jtc Echo = FALSE;
907 1.1 jtc
908 1.1 jtc for (loop = 0; loop < 2; ++loop)
909 1.1 jtc {
910 1.1 jtc /* prompt for password */
911 1.1 jtc mvaddstr(11, 0, "Password ? ");
912 1.1 jtc getstring(Databuf, SZ_PASSWORD);
913 1.1 jtc if (strcmp(Databuf, Player.p_password) == 0)
914 1.1 jtc /* password good */
915 1.1 jtc {
916 1.1 jtc Echo = TRUE;
917 1.1 jtc
918 1.1 jtc if (Player.p_status != S_OFF)
919 1.1 jtc /* player did not exit normally last time */
920 1.1 jtc {
921 1.1 jtc clear();
922 1.1 jtc addstr("Your character did not exit normally last time.\n");
923 1.1 jtc addstr("If you think you have good cause to have your character saved,\n");
924 1.1 jtc printw("you may quit and mail your reason to 'root'.\n");
925 1.1 jtc addstr("Otherwise, continuing spells certain death.\n");
926 1.1 jtc addstr("Do you want to quit ? ");
927 1.1 jtc ch = getanswer("YN", FALSE);
928 1.1 jtc if (ch == 'Y')
929 1.1 jtc {
930 1.1 jtc Player.p_status = S_HUNGUP;
931 1.1 jtc writerecord(&Player, loc);
932 1.1 jtc cleanup(TRUE);
933 1.1 jtc /*NOTREACHED*/
934 1.1 jtc }
935 1.1 jtc death("Stupidity");
936 1.1 jtc /*NOTREACHED*/
937 1.1 jtc }
938 1.1 jtc return(loc);
939 1.1 jtc }
940 1.1 jtc else
941 1.1 jtc mvaddstr(12, 0, "No good.\n");
942 1.1 jtc }
943 1.1 jtc
944 1.1 jtc Echo = TRUE;
945 1.1 jtc }
946 1.1 jtc else
947 1.1 jtc mvaddstr(11, 0, "Not found.\n");
948 1.1 jtc
949 1.1 jtc more(13);
950 1.1 jtc return(-1L);
951 1.1 jtc }
952 1.1 jtc /**/
954 1.1 jtc /************************************************************************
955 1.1 jtc /
956 1.1 jtc / FUNCTION NAME: neatstuff()
957 1.1 jtc /
958 1.1 jtc / FUNCTION: do random stuff
959 1.1 jtc /
960 1.1 jtc / AUTHOR: E. A. Estes, 3/3/86
961 1.1 jtc /
962 1.1 jtc / ARGUMENTS: none
963 1.1 jtc /
964 1.1 jtc / RETURN VALUE: none
965 1.1 jtc /
966 1.1 jtc / MODULES CALLED: collecttaxes(), floor(), wmove(), drandom(), infloat(),
967 1.1 jtc / waddstr(), mvprintw(), getanswer()
968 1.1 jtc /
969 1.1 jtc / GLOBAL INPUTS: Player, *stdscr, *Statptr
970 1.1 jtc /
971 1.1 jtc / GLOBAL OUTPUTS: Player
972 1.1 jtc /
973 1.1 jtc / DESCRIPTION:
974 1.1 jtc / Handle gurus, medics, etc.
975 1.1 jtc /
976 1.1 jtc /************************************************************************/
977 1.1 jtc
978 1.1 jtc neatstuff()
979 1.1 jtc {
980 1.1 jtc double temp; /* for temporary calculations */
981 1.1 jtc int ch; /* input */
982 1.1 jtc
983 1.1 jtc switch ((int) ROLL(0.0, 100.0))
984 1.1 jtc {
985 1.1 jtc case 1:
986 1.1 jtc case 2:
987 1.1 jtc if (Player.p_poison > 0.0)
988 1.1 jtc {
989 1.1 jtc mvaddstr(4, 0, "You've found a medic! How much will you offer to be cured ? ");
990 1.1 jtc temp = floor(infloat());
991 1.1 jtc if (temp < 0.0 || temp > Player.p_gold)
992 1.1 jtc /* negative gold, or more than available */
993 1.1 jtc {
994 1.1 jtc mvaddstr(6, 0, "He was not amused, and made you worse.\n");
995 1.1 jtc Player.p_poison += 1.0;
996 1.1 jtc }
997 1.1 jtc else if (drandom() / 2.0 > (temp + 1.0) / MAX(Player.p_gold, 1))
998 1.1 jtc /* medic wants 1/2 of available gold */
999 1.1 jtc mvaddstr(5, 0, "Sorry, he wasn't interested.\n");
1000 1.1 jtc else
1001 1.1 jtc {
1002 1.1 jtc mvaddstr(5, 0, "He accepted.");
1003 1.1 jtc Player.p_poison = MAX(0.0, Player.p_poison - 1.0);
1004 1.1 jtc Player.p_gold -= temp;
1005 1.1 jtc }
1006 1.1 jtc }
1007 1.1 jtc break;
1008 1.1 jtc
1009 1.1 jtc case 3:
1010 1.1 jtc mvaddstr(4, 0, "You've been caught raping and pillaging!\n");
1011 1.1 jtc Player.p_experience += 4000.0;
1012 1.1 jtc Player.p_sin += 0.5;
1013 1.1 jtc break;
1014 1.1 jtc
1015 1.1 jtc case 4:
1016 1.1 jtc temp = ROLL(10.0, 75.0);
1017 1.1 jtc mvprintw(4, 0, "You've found %.0f gold pieces, want them ? ", temp);
1018 1.1 jtc ch = getanswer("NY", FALSE);
1019 1.1 jtc
1020 1.1 jtc if (ch == 'Y')
1021 1.1 jtc collecttaxes(temp, 0.0);
1022 1.1 jtc break;
1023 1.1 jtc
1024 1.1 jtc case 5:
1025 1.1 jtc if (Player.p_sin > 1.0)
1026 1.1 jtc {
1027 1.1 jtc mvaddstr(4, 0, "You've found a Holy Orb!\n");
1028 1.1 jtc Player.p_sin -= 0.25;
1029 1.1 jtc }
1030 1.1 jtc break;
1031 1.1 jtc
1032 1.1 jtc case 6:
1033 1.1 jtc if (Player.p_poison < 1.0)
1034 1.1 jtc {
1035 1.1 jtc mvaddstr(4, 0, "You've been hit with a plague!\n");
1036 1.1 jtc Player.p_poison += 1.0;
1037 1.1 jtc }
1038 1.1 jtc break;
1039 1.1 jtc
1040 1.1 jtc case 7:
1041 1.1 jtc mvaddstr(4, 0, "You've found some holy water.\n");
1042 1.1 jtc ++Player.p_holywater;
1043 1.1 jtc break;
1044 1.1 jtc
1045 1.1 jtc case 8:
1046 1.1 jtc mvaddstr(4, 0, "You've met a Guru. . .");
1047 1.1 jtc if (drandom() * Player.p_sin > 1.0)
1048 1.1 jtc addstr("You disgusted him with your sins!\n");
1049 1.1 jtc else if (Player.p_poison > 0.0)
1050 1.1 jtc {
1051 1.1 jtc addstr("He looked kindly upon you, and cured you.\n");
1052 1.1 jtc Player.p_poison = 0.0;
1053 1.1 jtc }
1054 1.1 jtc else
1055 1.1 jtc {
1056 1.1 jtc addstr("He rewarded you for your virtue.\n");
1057 1.1 jtc Player.p_mana += 50.0;
1058 1.1 jtc Player.p_shield += 2.0;
1059 1.1 jtc }
1060 1.1 jtc break;
1061 1.1 jtc
1062 1.1 jtc case 9:
1063 1.1 jtc mvaddstr(4, 0, "You've found an amulet.\n");
1064 1.1 jtc ++Player.p_amulets;
1065 1.1 jtc break;
1066 1.1 jtc
1067 1.1 jtc case 10:
1068 1.1 jtc if (Player.p_blindness)
1069 1.1 jtc {
1070 1.1 jtc mvaddstr(4, 0, "You've regained your sight!\n");
1071 1.1 jtc Player.p_blindness = FALSE;
1072 1.1 jtc }
1073 1.1 jtc break;
1074 1.1 jtc
1075 1.1 jtc default: /* deal with poison */
1076 1.1 jtc if (Player.p_poison > 0.0)
1077 1.1 jtc {
1078 1.1 jtc temp = Player.p_poison * Statptr->c_weakness
1079 1.1 jtc * Player.p_maxenergy / 600.0;
1080 1.1 jtc if (Player.p_energy > Player.p_maxenergy / 10.0
1081 1.1 jtc && temp + 5.0 < Player.p_energy)
1082 1.1 jtc Player.p_energy -= temp;
1083 1.1 jtc }
1084 1.1 jtc break;
1085 1.1 jtc }
1086 1.1 jtc }
1087 1.1 jtc /**/
1089 1.1 jtc /************************************************************************
1090 1.1 jtc /
1091 1.1 jtc / FUNCTION NAME: genchar()
1092 1.1 jtc /
1093 1.1 jtc / FUNCTION: generate a random character
1094 1.1 jtc /
1095 1.1 jtc / AUTHOR: E. A. Estes, 12/4/85
1096 1.1 jtc /
1097 1.1 jtc / ARGUMENTS:
1098 1.1 jtc / int type - ASCII value of character type to generate
1099 1.1 jtc /
1100 1.1 jtc / RETURN VALUE: none
1101 1.1 jtc /
1102 1.1 jtc / MODULES CALLED: floor(), drandom()
1103 1.1 jtc /
1104 1.1 jtc / GLOBAL INPUTS: Wizard, Player, Stattable[]
1105 1.1 jtc /
1106 1.1 jtc / GLOBAL OUTPUTS: Player
1107 1.1 jtc /
1108 1.1 jtc / DESCRIPTION:
1109 1.1 jtc / Use the lookup table for rolling stats.
1110 1.1 jtc /
1111 1.1 jtc /************************************************************************/
1112 1.1 jtc
1113 1.1 jtc genchar(type)
1114 1.1 jtc int type;
1115 1.1 jtc {
1116 1.1 jtc register int subscript; /* used for subscripting into Stattable */
1117 1.1 jtc register struct charstats *statptr;/* for pointing into Stattable */
1118 1.1 jtc
1119 1.1 jtc subscript = type - '1';
1120 1.1 jtc
1121 1.1 jtc if (subscript < C_MAGIC || subscript > C_EXPER)
1122 1.1 jtc if (subscript != C_SUPER || !Wizard)
1123 1.1 jtc /* fighter is default */
1124 1.1 jtc subscript = C_FIGHTER;
1125 1.1 jtc
1126 1.1 jtc statptr = &Stattable[subscript];
1127 1.1 jtc
1128 1.1 jtc Player.p_quickness =
1129 1.1 jtc ROLL(statptr->c_quickness.base, statptr->c_quickness.interval);
1130 1.1 jtc Player.p_strength =
1131 1.1 jtc ROLL(statptr->c_strength.base, statptr->c_strength.interval);
1132 1.1 jtc Player.p_mana =
1133 1.1 jtc ROLL(statptr->c_mana.base, statptr->c_mana.interval);
1134 1.1 jtc Player.p_maxenergy =
1135 1.1 jtc Player.p_energy =
1136 1.1 jtc ROLL(statptr->c_energy.base, statptr->c_energy.interval);
1137 1.1 jtc Player.p_brains =
1138 1.1 jtc ROLL(statptr->c_brains.base, statptr->c_brains.interval);
1139 1.1 jtc Player.p_magiclvl =
1140 1.1 jtc ROLL(statptr->c_magiclvl.base, statptr->c_magiclvl.interval);
1141 1.1 jtc
1142 1.1 jtc Player.p_type = subscript;
1143 1.1 jtc
1144 1.1 jtc if (Player.p_type == C_HALFLING)
1145 1.1 jtc /* give halfling some experience */
1146 1.1 jtc Player.p_experience = ROLL(600.0, 200.0);
1147 1.1 jtc }
1148 1.1 jtc /**/
1150 1.1 jtc /************************************************************************
1151 1.1 jtc /
1152 1.1 jtc / FUNCTION NAME: playinit()
1153 1.1 jtc /
1154 1.1 jtc / FUNCTION: initialize for playing game
1155 1.1 jtc /
1156 1.1 jtc / AUTHOR: E. A. Estes, 12/4/85
1157 1.1 jtc /
1158 1.1 jtc / ARGUMENTS: none
1159 1.1 jtc /
1160 1.1 jtc / RETURN VALUE: none
1161 1.1 jtc /
1162 1.1 jtc / MODULES CALLED: signal(), wclear(), noecho(), crmode(), initscr(),
1163 1.1 jtc / wrefresh()
1164 1.1 jtc /
1165 1.1 jtc / GLOBAL INPUTS: *stdscr, ill_sig()
1166 1.1 jtc /
1167 1.1 jtc / GLOBAL OUTPUTS: Windows
1168 1.1 jtc /
1169 1.1 jtc / DESCRIPTION:
1170 1.1 jtc / Catch a bunch of signals, and turn on curses stuff.
1171 1.1 jtc /
1172 1.1 jtc /************************************************************************/
1173 1.1 jtc
1174 1.1 jtc playinit()
1175 1.1 jtc {
1176 1.1 jtc /* catch/ingnore signals */
1177 1.1 jtc
1178 1.1 jtc #ifdef BSD41
1179 1.1 jtc sigignore(SIGQUIT);
1180 1.1 jtc sigignore(SIGALRM);
1181 1.1 jtc sigignore(SIGTERM);
1182 1.1 jtc sigignore(SIGTSTP);
1183 1.1 jtc sigignore(SIGTTIN);
1184 1.1 jtc sigignore(SIGTTOU);
1185 1.1 jtc sighold(SIGINT);
1186 1.1 jtc sigset(SIGHUP, ill_sig);
1187 1.1 jtc sigset(SIGTRAP, ill_sig);
1188 1.1 jtc sigset(SIGIOT, ill_sig);
1189 1.1 jtc sigset(SIGEMT, ill_sig);
1190 1.1 jtc sigset(SIGFPE, ill_sig);
1191 1.1 jtc sigset(SIGBUS, ill_sig);
1192 1.1 jtc sigset(SIGSEGV, ill_sig);
1193 1.1 jtc sigset(SIGSYS, ill_sig);
1194 1.1 jtc sigset(SIGPIPE, ill_sig);
1195 1.1 jtc #endif
1196 1.1 jtc #ifdef BSD42
1197 1.1 jtc signal(SIGQUIT, ill_sig);
1198 1.1 jtc signal(SIGALRM, SIG_IGN);
1199 1.1 jtc signal(SIGTERM, SIG_IGN);
1200 1.1 jtc signal(SIGTSTP, SIG_IGN);
1201 1.1 jtc signal(SIGTTIN, SIG_IGN);
1202 1.1 jtc signal(SIGTTOU, SIG_IGN);
1203 1.1 jtc signal(SIGINT, ill_sig);
1204 1.1 jtc signal(SIGHUP, SIG_DFL);
1205 1.1 jtc signal(SIGTRAP, ill_sig);
1206 1.1 jtc signal(SIGIOT, ill_sig);
1207 1.1 jtc signal(SIGEMT, ill_sig);
1208 1.1 jtc signal(SIGFPE, ill_sig);
1209 1.1 jtc signal(SIGBUS, ill_sig);
1210 1.1 jtc signal(SIGSEGV, ill_sig);
1211 1.1 jtc signal(SIGSYS, ill_sig);
1212 1.1 jtc signal(SIGPIPE, ill_sig);
1213 1.1 jtc #endif
1214 1.1 jtc #ifdef SYS3
1215 1.1 jtc signal(SIGINT, SIG_IGN);
1216 1.1 jtc signal(SIGQUIT, SIG_IGN);
1217 1.1 jtc signal(SIGTERM, SIG_IGN);
1218 1.1 jtc signal(SIGALRM, SIG_IGN);
1219 1.1 jtc signal(SIGHUP, ill_sig);
1220 1.1 jtc signal(SIGTRAP, ill_sig);
1221 1.1 jtc signal(SIGIOT, ill_sig);
1222 1.1 jtc signal(SIGEMT, ill_sig);
1223 1.1 jtc signal(SIGFPE, ill_sig);
1224 1.1 jtc signal(SIGBUS, ill_sig);
1225 1.1 jtc signal(SIGSEGV, ill_sig);
1226 1.1 jtc signal(SIGSYS, ill_sig);
1227 1.1 jtc signal(SIGPIPE, ill_sig);
1228 1.1 jtc #endif
1229 1.1 jtc #ifdef SYS5
1230 1.1 jtc signal(SIGINT, SIG_IGN);
1231 1.1 jtc signal(SIGQUIT, SIG_IGN);
1232 1.1 jtc signal(SIGTERM, SIG_IGN);
1233 1.1 jtc signal(SIGALRM, SIG_IGN);
1234 1.1 jtc signal(SIGHUP, ill_sig);
1235 1.1 jtc signal(SIGTRAP, ill_sig);
1236 1.1 jtc signal(SIGIOT, ill_sig);
1237 1.1 jtc signal(SIGEMT, ill_sig);
1238 1.1 jtc signal(SIGFPE, ill_sig);
1239 1.1 jtc signal(SIGBUS, ill_sig);
1240 1.1 jtc signal(SIGSEGV, ill_sig);
1241 1.1 jtc signal(SIGSYS, ill_sig);
1242 1.1 jtc signal(SIGPIPE, ill_sig);
1243 1.1 jtc #endif
1244 1.1 jtc
1245 1.1 jtc initscr(); /* turn on curses */
1246 1.1 jtc noecho(); /* do not echo input */
1247 1.1 jtc crmode(); /* do not process erase, kill */
1248 1.1 jtc clear();
1249 1.1 jtc refresh();
1250 1.1 jtc Windows = TRUE; /* mark the state */
1251 1.1 jtc }
1252 1.1 jtc
1253 1.1 jtc /**/
1255 1.1 jtc /************************************************************************
1256 1.1 jtc /
1257 1.1 jtc / FUNCTION NAME: cleanup()
1258 1.1 jtc /
1259 1.1 jtc / FUNCTION: close some files, and maybe exit
1260 1.1 jtc /
1261 1.1 jtc / AUTHOR: E. A. Estes, 12/4/85
1262 1.1 jtc /
1263 1.1 jtc / ARGUMENTS:
1264 1.1 jtc / bool doexit - exit flag
1265 1.1 jtc /
1266 1.1 jtc / RETURN VALUE: none
1267 1.1 jtc /
1268 1.1 jtc / MODULES CALLED: exit(), wmove(), fclose(), endwin(), nocrmode(), wrefresh()
1269 1.1 jtc /
1270 1.1 jtc / GLOBAL INPUTS: *Energyvoidfp, LINES, *stdscr, Windows, *Monstfp,
1271 1.1 jtc / *Messagefp, *Playersfp
1272 1.1 jtc /
1273 1.1 jtc / GLOBAL OUTPUTS: none
1274 1.1 jtc /
1275 1.1 jtc / DESCRIPTION:
1276 1.1 jtc / Close all open files. If we are "in curses" terminate curses.
1277 1.1 jtc / If 'doexit' is set, exit, otherwise return.
1278 1.1 jtc /
1279 1.1 jtc /************************************************************************/
1280 1.1 jtc
1281 1.1 jtc cleanup(doexit)
1282 1.1 jtc bool doexit;
1283 1.1 jtc {
1284 1.1 jtc if (Windows)
1285 1.1 jtc {
1286 1.1 jtc move(LINES - 2, 0);
1287 1.1 jtc refresh();
1288 1.1 jtc nocrmode();
1289 1.1 jtc endwin();
1290 1.1 jtc }
1291
1292 fclose(Playersfp);
1293 fclose(Monstfp);
1294 fclose(Messagefp);
1295 fclose(Energyvoidfp);
1296
1297 if (doexit)
1298 exit(0);
1299 /*NOTREACHED*/
1300 }
1301