]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - phantasia/fight.c
sprinkle static and prune some dead code
[bsdgames-darwin.git] / phantasia / fight.c
1 /* $NetBSD: fight.c,v 1.11 2009/05/25 23:08:45 dholland Exp $ */
2
3 /*
4 * fight.c Phantasia monster fighting routines
5 */
6
7 #include "include.h"
8 #undef bool
9 #include <curses.h>
10
11 void
12 encounter(int particular)
13 {
14 volatile bool firsthit = Player.p_blessing; /* set if player gets
15 * the first hit */
16 volatile int flockcnt = 1; /* how many time flocked */
17
18 /* let others know what we are doing */
19 Player.p_status = S_MONSTER;
20 writerecord(&Player, Fileloc);
21
22 #ifdef SYS5
23 flushinp();
24 #endif
25
26 Shield = 0.0; /* no shield up yet */
27
28 if (particular >= 0)
29 /* monster is specified */
30 Whichmonster = particular;
31 else
32 /* pick random monster */
33 Whichmonster = pickmonster();
34
35 setjmp(Fightenv); /* this is to enable changing fight state */
36
37 move(6, 0);
38 clrtobot(); /* clear bottom area of screen */
39
40 Lines = 9;
41 callmonster(Whichmonster); /* set up monster to fight */
42
43 Luckout = FALSE; /* haven't tried to luckout yet */
44
45 if (Curmonster.m_type == SM_MORGOTH)
46 mvprintw(4, 0, "You've encountered %s, Bane of the Council and Valar.\n",
47 Enemyname);
48
49 if (Curmonster.m_type == SM_UNICORN) {
50 if (Player.p_virgin) {
51 printw("You just subdued %s, thanks to the virgin.\n", Enemyname);
52 Player.p_virgin = FALSE;
53 } else {
54 printw("You just saw %s running away!\n", Enemyname);
55 Curmonster.m_experience = 0.0;
56 Curmonster.m_treasuretype = 0;
57 }
58 } else
59 /* not a special monster */
60 for (;;)
61 /* print header, and arbitrate between player and
62 * monster */
63 {
64 mvprintw(6, 0, "You are being attacked by %s, EXP: %.0f (Size: %.0f)\n",
65 Enemyname, Curmonster.m_experience, Circle);
66
67 displaystats();
68 mvprintw(1, 26, "%20.0f", Player.p_energy + Shield); /* overprint energy */
69 readmessage();
70
71 if (Curmonster.m_type == SM_DARKLORD
72 && Player.p_blessing
73 && Player.p_charms > 0)
74 /* overpower Dark Lord with blessing and charm */
75 {
76 mvprintw(7, 0, "You just overpowered %s!", Enemyname);
77 Lines = 8;
78 Player.p_blessing = FALSE;
79 --Player.p_charms;
80 break;
81 }
82 /* allow paralyzed monster to wake up */
83 Curmonster.m_speed = MIN(Curmonster.m_speed + 1.0, Curmonster.m_maxspeed);
84
85 if (drandom() * Curmonster.m_speed > drandom() * Player.p_speed
86 /* monster is faster */
87 && Curmonster.m_type != SM_DARKLORD
88 /* not D. L. */
89 && Curmonster.m_type != SM_SHRIEKER
90 /* not mimic */
91 && !firsthit)
92 /* monster gets a hit */
93 monsthits();
94 else
95 /* player gets a hit */
96 {
97 firsthit = FALSE;
98 playerhits();
99 }
100
101 refresh();
102
103 if (Lines > LINES - 2)
104 /* near bottom of screen - pause */
105 {
106 more(Lines);
107 move(Lines = 8, 0);
108 clrtobot();
109 }
110 if (Player.p_energy <= 0.0)
111 /* player died */
112 {
113 more(Lines);
114 death(Enemyname);
115 cancelmonster();
116 break; /* fight ends if the player is saved
117 * from death */
118 }
119 if (Curmonster.m_energy <= 0.0)
120 /* monster died */
121 break;
122 }
123
124 /* give player credit for killing monster */
125 Player.p_experience += Curmonster.m_experience;
126
127 if (drandom() < Curmonster.m_flock / 100.0)
128 /* monster flocks */
129 {
130 more(Lines);
131 ++flockcnt;
132 longjmp(Fightenv, 0);
133 /* NOTREACHED */
134 } else
135 if (Circle > 1.0
136 && Curmonster.m_treasuretype > 0
137 && drandom() > 0.2 + pow(0.4, (double) (flockcnt / 3 + Circle / 3.0)))
138 /* monster has treasure; this takes # of flocks and
139 * size into account */
140 {
141 more(Lines);
142 awardtreasure();
143 }
144 /* pause before returning */
145 getyx(stdscr, Lines, flockcnt);
146 more(Lines + 1);
147
148 Player.p_ring.ring_inuse = FALSE; /* not using ring */
149
150 /* clean up the screen */
151 move(4, 0);
152 clrtobot();
153 }
154
155 int
156 pickmonster(void)
157 {
158 if (Player.p_specialtype == SC_VALAR)
159 /* even chance of any monster */
160 return ((int) ROLL(0.0, 100.0));
161
162 if (Marsh)
163 /* water monsters */
164 return ((int) ROLL(0.0, 15.0));
165
166 else
167 if (Circle > 24)
168 /* even chance of all non-water monsters */
169 return ((int) ROLL(14.0, 86.0));
170
171 else
172 if (Circle > 15)
173 /* chance of all non-water monsters, weighted
174 * toward middle */
175 return ((int) (ROLL(0.0, 50.0) + ROLL(14.0, 37.0)));
176
177 else
178 if (Circle > 8)
179 /* not all non-water monsters,
180 * weighted toward middle */
181 return ((int) (ROLL(0.0, 50.0) + ROLL(14.0, 26.0)));
182
183 else
184 if (Circle > 3)
185 /* even chance of some tamer
186 * non-water monsters */
187 return ((int) ROLL(14.0, 50.0));
188
189 else
190 /* even chance of some of the
191 * tamest non-water monsters */
192 return ((int) ROLL(14.0, 25.0));
193 }
194
195 void
196 playerhits(void)
197 {
198 double inflict; /* damage inflicted */
199 int ch; /* input */
200
201 mvaddstr(7, 0, "1:Melee 2:Skirmish 3:Evade 4:Spell 5:Nick ");
202
203 if (!Luckout) {
204 /* haven't tried to luckout yet */
205 if (Curmonster.m_type == SM_MORGOTH)
206 /* cannot luckout against Morgoth */
207 addstr("6:Ally ");
208 else
209 addstr("6:Luckout ");
210 }
211
212 if (Player.p_ring.ring_type != R_NONE)
213 /* player has a ring */
214 addstr("7:Use Ring ");
215 else
216 clrtoeol();
217
218 ch = inputoption();
219
220 move(8, 0);
221 clrtobot(); /* clear any messages from before */
222 Lines = 9;
223 mvaddstr(4, 0, "\n\n"); /* clear status area */
224
225 switch (ch) {
226 case 'T': /* timeout; lose turn */
227 break;
228
229 case ' ':
230 case '1': /* melee */
231 /* melee affects monster's energy and strength */
232 inflict = ROLL(Player.p_might / 2.0 + 5.0, 1.3 * Player.p_might)
233 + (Player.p_ring.ring_inuse ? Player.p_might : 0.0);
234
235 Curmonster.m_melee += inflict;
236 Curmonster.m_strength = Curmonster.m_o_strength
237 - Curmonster.m_melee / Curmonster.m_o_energy
238 * Curmonster.m_o_strength / 4.0;
239 hitmonster(inflict);
240 break;
241
242 case '2': /* skirmish */
243 /* skirmish affects monter's energy and speed */
244 inflict = ROLL(Player.p_might / 3.0 + 3.0, 1.1 * Player.p_might)
245 + (Player.p_ring.ring_inuse ? Player.p_might : 0.0);
246
247 Curmonster.m_skirmish += inflict;
248 Curmonster.m_maxspeed = Curmonster.m_o_speed
249 - Curmonster.m_skirmish / Curmonster.m_o_energy
250 * Curmonster.m_o_speed / 4.0;
251 hitmonster(inflict);
252 break;
253
254 case '3': /* evade */
255 /* use brains and speed to try to evade */
256 if ((Curmonster.m_type == SM_DARKLORD
257 || Curmonster.m_type == SM_SHRIEKER
258 /* can always run from D. L. and shrieker */
259 || drandom() * Player.p_speed * Player.p_brains
260 > drandom() * Curmonster.m_speed * Curmonster.m_brains)
261 && (Curmonster.m_type != SM_MIMIC))
262 /* cannot run from mimic */
263 {
264 mvaddstr(Lines++, 0, "You got away!");
265 cancelmonster();
266 altercoordinates(0.0, 0.0, A_NEAR);
267 } else
268 mvprintw(Lines++, 0, "%s is still after you!", Enemyname);
269
270 break;
271
272 case 'M':
273 case '4': /* magic spell */
274 throwspell();
275 break;
276
277 case '5': /* nick */
278 /* hit 1 plus sword; give some experience */
279 inflict = 1.0 + Player.p_sword;
280 Player.p_experience += floor(Curmonster.m_experience / 10.0);
281 Curmonster.m_experience *= 0.92;
282 /* monster gets meaner */
283 Curmonster.m_maxspeed += 2.0;
284 Curmonster.m_speed = (Curmonster.m_speed < 0.0) ? 0.0 : Curmonster.m_speed + 2.0;
285 if (Curmonster.m_type == SM_DARKLORD)
286 /* Dark Lord; doesn't like to be nicked */
287 {
288 mvprintw(Lines++, 0,
289 "You hit %s %.0f times, and made him mad!", Enemyname, inflict);
290 Player.p_quickness /= 2.0;
291 altercoordinates(0.0, 0.0, A_FAR);
292 cancelmonster();
293 } else
294 hitmonster(inflict);
295 break;
296
297 case 'B':
298 case '6': /* luckout */
299 if (Luckout)
300 mvaddstr(Lines++, 0, "You already tried that.");
301 else {
302 Luckout = TRUE;
303 if (Curmonster.m_type == SM_MORGOTH)
304 /* Morgoth; ally */
305 {
306 if (drandom() < Player.p_sin / 100.0) {
307 mvprintw(Lines++, 0, "%s accepted!", Enemyname);
308 cancelmonster();
309 } else
310 mvaddstr(Lines++, 0, "Nope, he's not interested.");
311 } else
312 /* normal monster; use brains for success */
313 {
314 if ((drandom() + 0.333) * Player.p_brains
315 < (drandom() + 0.333) * Curmonster.m_brains)
316 mvprintw(Lines++, 0, "You blew it, %s.", Player.p_name);
317 else {
318 mvaddstr(Lines++, 0, "You made it!");
319 Curmonster.m_energy = 0.0;
320 }
321 }
322 }
323 break;
324
325 case '7': /* use ring */
326 if (Player.p_ring.ring_type != R_NONE) {
327 mvaddstr(Lines++, 0, "Now using ring.");
328 Player.p_ring.ring_inuse = TRUE;
329 if (Player.p_ring.ring_type != R_DLREG)
330 /* age ring */
331 --Player.p_ring.ring_duration;
332 }
333 break;
334 }
335
336 }
337
338 void
339 monsthits(void)
340 {
341 double inflict; /* damage inflicted */
342 int ch; /* input */
343
344 switch (Curmonster.m_type)
345 /* may be a special monster */
346 {
347 case SM_DARKLORD:
348 /* hits just enough to kill player */
349 inflict = (Player.p_energy + Shield) * 1.02;
350 goto SPECIALHIT;
351
352 case SM_SHRIEKER:
353 /* call a big monster */
354 mvaddstr(Lines++, 0,
355 "Shrieeeek!! You scared it, and it called one of its friends.");
356 more(Lines);
357 Whichmonster = (int) ROLL(70.0, 30.0);
358 longjmp(Fightenv, 0);
359 /* NOTREACHED */
360
361 case SM_BALROG:
362 /* take experience away */
363 inflict = ROLL(10.0, Curmonster.m_strength);
364 inflict = MIN(Player.p_experience, inflict);
365 mvprintw(Lines++, 0,
366 "%s took away %.0f experience points.", Enemyname, inflict);
367 Player.p_experience -= inflict;
368 return;
369
370 case SM_FAERIES:
371 if (Player.p_holywater > 0)
372 /* holy water kills when monster tries to hit */
373 {
374 mvprintw(Lines++, 0, "Your holy water killed it!");
375 --Player.p_holywater;
376 Curmonster.m_energy = 0.0;
377 return;
378 }
379 break;
380
381 case SM_NONE:
382 /* normal hit */
383 break;
384
385 default:
386 if (drandom() > 0.2)
387 /* normal hit */
388 break;
389
390 /* else special things */
391 switch (Curmonster.m_type) {
392 case SM_LEANAN:
393 /* takes some of the player's strength */
394 inflict = ROLL(1.0, (Circle - 1.0) / 2.0);
395 inflict = MIN(Player.p_strength, inflict);
396 mvprintw(Lines++, 0, "%s sapped %.0f of your strength!",
397 Enemyname, inflict);
398 Player.p_strength -= inflict;
399 Player.p_might -= inflict;
400 break;
401
402 case SM_SARUMAN:
403 if (Player.p_palantir)
404 /* take away palantir */
405 {
406 mvprintw(Lines++, 0, "Wormtongue stole your palantir!");
407 Player.p_palantir = FALSE;
408 } else
409 if (drandom() > 0.5)
410 /* gems turn to gold */
411 {
412 mvprintw(Lines++, 0,
413 "%s transformed your gems into gold!", Enemyname);
414 Player.p_gold += Player.p_gems;
415 Player.p_gems = 0.0;
416 } else
417 /* scramble some stats */
418 {
419 mvprintw(Lines++, 0, "%s scrambled your stats!", Enemyname);
420 scramblestats();
421 }
422 break;
423
424 case SM_THAUMATURG:
425 /* transport player */
426 mvprintw(Lines++, 0, "%s transported you!", Enemyname);
427 altercoordinates(0.0, 0.0, A_FAR);
428 cancelmonster();
429 break;
430
431 case SM_VORTEX:
432 /* suck up some mana */
433 inflict = ROLL(0, 7.5 * Circle);
434 inflict = MIN(Player.p_mana, floor(inflict));
435 mvprintw(Lines++, 0,
436 "%s sucked up %.0f of your mana!", Enemyname, inflict);
437 Player.p_mana -= inflict;
438 break;
439
440 case SM_NAZGUL:
441 /* try to take ring if player has one */
442 if (Player.p_ring.ring_type != R_NONE)
443 /* player has a ring */
444 {
445 mvaddstr(Lines++, 0, "Will you relinguish your ring ? ");
446 ch = getanswer("YN", FALSE);
447 if (ch == 'Y')
448 /* take ring away */
449 {
450 Player.p_ring.ring_type = R_NONE;
451 Player.p_ring.ring_inuse = FALSE;
452 cancelmonster();
453 break;
454 }
455 }
456 /* otherwise, take some brains */
457 mvprintw(Lines++, 0,
458 "%s neutralized 1/5 of your brain!", Enemyname);
459 Player.p_brains *= 0.8;
460 break;
461
462 case SM_TIAMAT:
463 /* take some gold and gems */
464 mvprintw(Lines++, 0,
465 "%s took half your gold and gems and flew off.", Enemyname);
466 Player.p_gold /= 2.0;
467 Player.p_gems /= 2.0;
468 cancelmonster();
469 break;
470
471 case SM_KOBOLD:
472 /* steal a gold piece and run */
473 mvprintw(Lines++, 0,
474 "%s stole one gold piece and ran away.", Enemyname);
475 Player.p_gold = MAX(0.0, Player.p_gold - 1.0);
476 cancelmonster();
477 break;
478
479 case SM_SHELOB:
480 /* bite and (medium) poison */
481 mvprintw(Lines++, 0,
482 "%s has bitten and poisoned you!", Enemyname);
483 Player.p_poison -= 1.0;
484 break;
485
486 case SM_LAMPREY:
487 /* bite and (small) poison */
488 mvprintw(Lines++, 0, "%s bit and poisoned you!", Enemyname);
489 Player.p_poison += 0.25;
490 break;
491
492 case SM_BONNACON:
493 /* fart and run */
494 mvprintw(Lines++, 0, "%s farted and scampered off.", Enemyname);
495 Player.p_energy /= 2.0; /* damage from fumes */
496 cancelmonster();
497 break;
498
499 case SM_SMEAGOL:
500 if (Player.p_ring.ring_type != R_NONE)
501 /* try to steal ring */
502 {
503 mvprintw(Lines++, 0,
504 "%s tried to steal your ring, ", Enemyname);
505 if (drandom() > 0.1)
506 addstr("but was unsuccessful.");
507 else {
508 addstr("and ran away with it!");
509 Player.p_ring.ring_type = R_NONE;
510 cancelmonster();
511 }
512 }
513 break;
514
515 case SM_SUCCUBUS:
516 /* inflict damage through shield */
517 inflict = ROLL(15.0, Circle * 10.0);
518 inflict = MIN(inflict, Player.p_energy);
519 mvprintw(Lines++, 0, "%s sapped %.0f of your energy.",
520 Enemyname, inflict);
521 Player.p_energy -= inflict;
522 break;
523
524 case SM_CERBERUS:
525 /* take all metal treasures */
526 mvprintw(Lines++, 0,
527 "%s took all your metal treasures!", Enemyname);
528 Player.p_crowns = 0;
529 Player.p_sword =
530 Player.p_shield =
531 Player.p_gold = 0.0;
532 cancelmonster();
533 break;
534
535 case SM_UNGOLIANT:
536 /* (large) poison and take a quickness */
537 mvprintw(Lines++, 0,
538 "%s poisoned you, and took one quik.", Enemyname);
539 Player.p_poison += 5.0;
540 Player.p_quickness -= 1.0;
541 break;
542
543 case SM_JABBERWOCK:
544 /* fly away, and leave either a Jubjub bird or
545 * Bonnacon */
546 mvprintw(Lines++, 0,
547 "%s flew away, and left you to contend with one of its friends.",
548 Enemyname);
549 Whichmonster = 55 + ((drandom() > 0.5) ? 22 : 0);
550 longjmp(Fightenv, 0);
551 /* NOTREACHED */
552
553 case SM_TROLL:
554 /* partially regenerate monster */
555 mvprintw(Lines++, 0,
556 "%s partially regenerated his energy.!", Enemyname);
557 Curmonster.m_energy +=
558 floor((Curmonster.m_o_energy - Curmonster.m_energy) / 2.0);
559 Curmonster.m_strength = Curmonster.m_o_strength;
560 Curmonster.m_melee = Curmonster.m_skirmish = 0.0;
561 Curmonster.m_maxspeed = Curmonster.m_o_speed;
562 break;
563
564 case SM_WRAITH:
565 if (!Player.p_blindness)
566 /* make blind */
567 {
568 mvprintw(Lines++, 0, "%s blinded you!", Enemyname);
569 Player.p_blindness = TRUE;
570 Enemyname = "A monster";
571 }
572 break;
573 }
574 return;
575 }
576
577 /* fall through to here if monster inflicts a normal hit */
578 inflict = drandom() * Curmonster.m_strength + 0.5;
579 SPECIALHIT:
580 mvprintw(Lines++, 0, "%s hit you %.0f times!", Enemyname, inflict);
581
582 if ((Shield -= inflict) < 0) {
583 Player.p_energy += Shield;
584 Shield = 0.0;
585 }
586 }
587
588 void
589 cancelmonster(void)
590 {
591 Curmonster.m_energy = 0.0;
592 Curmonster.m_experience = 0.0;
593 Curmonster.m_treasuretype = 0;
594 Curmonster.m_flock = 0.0;
595 }
596
597 void
598 hitmonster(double inflict)
599 {
600 mvprintw(Lines++, 0, "You hit %s %.0f times!", Enemyname, inflict);
601 Curmonster.m_energy -= inflict;
602 if (Curmonster.m_energy > 0.0) {
603 if (Curmonster.m_type == SM_DARKLORD || Curmonster.m_type == SM_SHRIEKER)
604 /* special monster didn't die */
605 monsthits();
606 } else
607 /* monster died. print message. */
608 {
609 if (Curmonster.m_type == SM_MORGOTH)
610 mvaddstr(Lines++, 0, "You have defeated Morgoth, but he may return. . .");
611 else
612 /* all other types of monsters */
613 {
614 mvprintw(Lines++, 0, "You killed it. Good work, %s.", Player.p_name);
615
616 if (Curmonster.m_type == SM_MIMIC
617 && strcmp(Curmonster.m_name, "A Mimic") != 0
618 && !Player.p_blindness)
619 mvaddstr(Lines++, 0, "The body slowly changes into the form of a mimic.");
620 }
621 }
622 }
623
624 void
625 throwspell(void)
626 {
627 double inflict; /* damage inflicted */
628 double dtemp; /* for dtemporary calculations */
629 int ch; /* input */
630
631 inflict = 0;
632 mvaddstr(7, 0, "\n\n"); /* clear menu area */
633
634 if (Player.p_magiclvl >= ML_ALLORNOTHING)
635 mvaddstr(7, 0, "1:All or Nothing ");
636 if (Player.p_magiclvl >= ML_MAGICBOLT)
637 addstr("2:Magic Bolt ");
638 if (Player.p_magiclvl >= ML_FORCEFIELD)
639 addstr("3:Force Field ");
640 if (Player.p_magiclvl >= ML_XFORM)
641 addstr("4:Transform ");
642 if (Player.p_magiclvl >= ML_INCRMIGHT)
643 addstr("5:Increase Might\n");
644 if (Player.p_magiclvl >= ML_INVISIBLE)
645 mvaddstr(8, 0, "6:Invisibility ");
646 if (Player.p_magiclvl >= ML_XPORT)
647 addstr("7:Transport ");
648 if (Player.p_magiclvl >= ML_PARALYZE)
649 addstr("8:Paralyze ");
650 if (Player.p_specialtype >= SC_COUNCIL)
651 addstr("9:Specify");
652 mvaddstr(4, 0, "Spell ? ");
653
654 ch = getanswer(" ", TRUE);
655
656 mvaddstr(7, 0, "\n\n"); /* clear menu area */
657
658 if (Curmonster.m_type == SM_MORGOTH && ch != '3')
659 /* can only throw force field against Morgoth */
660 ILLSPELL();
661 else
662 switch (ch) {
663 case '1': /* all or nothing */
664 if (drandom() < 0.25)
665 /* success */
666 {
667 inflict = Curmonster.m_energy * 1.01 + 1.0;
668
669 if (Curmonster.m_type == SM_DARKLORD)
670 /* all or nothing doesn't quite work
671 * against D. L. */
672 inflict *= 0.9;
673 } else
674 /* failure -- monster gets stronger and
675 * quicker */
676 {
677 Curmonster.m_o_strength = Curmonster.m_strength *= 2.0;
678 Curmonster.m_maxspeed *= 2.0;
679 Curmonster.m_o_speed *= 2.0;
680
681 /* paralyzed monsters wake up a bit */
682 Curmonster.m_speed = MAX(1.0, Curmonster.m_speed * 2.0);
683 }
684
685 if (Player.p_mana >= MM_ALLORNOTHING)
686 /* take a mana if player has one */
687 Player.p_mana -= MM_ALLORNOTHING;
688
689 hitmonster(inflict);
690 break;
691
692 case '2': /* magic bolt */
693 if (Player.p_magiclvl < ML_MAGICBOLT)
694 ILLSPELL();
695 else {
696 do
697 /* prompt for amount to expend */
698 {
699 mvaddstr(4, 0, "How much mana for bolt? ");
700 dtemp = floor(infloat());
701 }
702 while (dtemp < 0.0 || dtemp > Player.p_mana);
703
704 Player.p_mana -= dtemp;
705
706 if (Curmonster.m_type == SM_DARKLORD)
707 /* magic bolts don't work against D.
708 * L. */
709 inflict = 0.0;
710 else
711 inflict = dtemp * ROLL(15.0, sqrt(Player.p_magiclvl / 3.0 + 1.0));
712 mvaddstr(5, 0, "Magic Bolt fired!\n");
713 hitmonster(inflict);
714 }
715 break;
716
717 case '3': /* force field */
718 if (Player.p_magiclvl < ML_FORCEFIELD)
719 ILLSPELL();
720 else
721 if (Player.p_mana < MM_FORCEFIELD)
722 NOMANA();
723 else {
724 Player.p_mana -= MM_FORCEFIELD;
725 Shield = (Player.p_maxenergy + Player.p_shield) * 4.2 + 45.0;
726 mvaddstr(5, 0, "Force Field up.\n");
727 }
728 break;
729
730 case '4': /* transform */
731 if (Player.p_magiclvl < ML_XFORM)
732 ILLSPELL();
733 else
734 if (Player.p_mana < MM_XFORM)
735 NOMANA();
736 else {
737 Player.p_mana -= MM_XFORM;
738 Whichmonster = (int) ROLL(0.0, 100.0);
739 longjmp(Fightenv, 0);
740 /* NOTREACHED */
741 }
742 break;
743
744 case '5': /* increase might */
745 if (Player.p_magiclvl < ML_INCRMIGHT)
746 ILLSPELL();
747 else
748 if (Player.p_mana < MM_INCRMIGHT)
749 NOMANA();
750 else {
751 Player.p_mana -= MM_INCRMIGHT;
752 Player.p_might +=
753 (1.2 * (Player.p_strength + Player.p_sword)
754 + 5.0 - Player.p_might) / 2.0;
755 mvprintw(5, 0, "New strength: %.0f\n", Player.p_might);
756 }
757 break;
758
759 case '6': /* invisible */
760 if (Player.p_magiclvl < ML_INVISIBLE)
761 ILLSPELL();
762 else
763 if (Player.p_mana < MM_INVISIBLE)
764 NOMANA();
765 else {
766 Player.p_mana -= MM_INVISIBLE;
767 Player.p_speed +=
768 (1.2 * (Player.p_quickness + Player.p_quksilver)
769 + 5.0 - Player.p_speed) / 2.0;
770 mvprintw(5, 0, "New quickness: %.0f\n", Player.p_speed);
771 }
772 break;
773
774 case '7': /* transport */
775 if (Player.p_magiclvl < ML_XPORT)
776 ILLSPELL();
777 else
778 if (Player.p_mana < MM_XPORT)
779 NOMANA();
780 else {
781 Player.p_mana -= MM_XPORT;
782 if (Player.p_brains + Player.p_magiclvl
783 < Curmonster.m_experience / 200.0 * drandom()) {
784 mvaddstr(5, 0, "Transport backfired!\n");
785 altercoordinates(0.0, 0.0, A_FAR);
786 cancelmonster();
787 } else {
788 mvprintw(5, 0, "%s is transported.\n", Enemyname);
789 if (drandom() < 0.3)
790 /* monster didn't drop
791 * its treasure */
792 Curmonster.m_treasuretype = 0;
793
794 Curmonster.m_energy = 0.0;
795 }
796 }
797 break;
798
799 case '8': /* paralyze */
800 if (Player.p_magiclvl < ML_PARALYZE)
801 ILLSPELL();
802 else
803 if (Player.p_mana < MM_PARALYZE)
804 NOMANA();
805 else {
806 Player.p_mana -= MM_PARALYZE;
807 if (Player.p_magiclvl >
808 Curmonster.m_experience / 1000.0 * drandom()) {
809 mvprintw(5, 0, "%s is held.\n", Enemyname);
810 Curmonster.m_speed = -2.0;
811 } else
812 mvaddstr(5, 0, "Monster unaffected.\n");
813 }
814 break;
815
816 case '9': /* specify */
817 if (Player.p_specialtype < SC_COUNCIL)
818 ILLSPELL();
819 else
820 if (Player.p_mana < MM_SPECIFY)
821 NOMANA();
822 else {
823 Player.p_mana -= MM_SPECIFY;
824 mvaddstr(5, 0, "Which monster do you want [0-99] ? ");
825 Whichmonster = (int) infloat();
826 Whichmonster = MAX(0, MIN(99, Whichmonster));
827 longjmp(Fightenv, 0);
828 /* NOTREACHED */
829 }
830 break;
831 }
832 }
833
834 void
835 callmonster(int which)
836 {
837 struct monster Othermonster; /* to find a name for mimics */
838
839 which = MIN(which, 99); /* make sure within range */
840
841 /* fill structure */
842 fseek(Monstfp, (long) which * (long) SZ_MONSTERSTRUCT, SEEK_SET);
843 fread((char *) &Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp);
844
845 /* handle some special monsters */
846 if (Curmonster.m_type == SM_MODNAR) {
847 if (Player.p_specialtype < SC_COUNCIL)
848 /* randomize some stats */
849 {
850 Curmonster.m_strength *= drandom() + 0.5;
851 Curmonster.m_brains *= drandom() + 0.5;
852 Curmonster.m_speed *= drandom() + 0.5;
853 Curmonster.m_energy *= drandom() + 0.5;
854 Curmonster.m_experience *= drandom() + 0.5;
855 Curmonster.m_treasuretype =
856 (int) ROLL(0.0, (double) Curmonster.m_treasuretype);
857 } else
858 /* make Modnar into Morgoth */
859 {
860 strcpy(Curmonster.m_name, "Morgoth");
861 Curmonster.m_strength = drandom() * (Player.p_maxenergy + Player.p_shield) / 1.4
862 + drandom() * (Player.p_maxenergy + Player.p_shield) / 1.5;
863 Curmonster.m_brains = Player.p_brains;
864 Curmonster.m_energy = Player.p_might * 30.0;
865 Curmonster.m_type = SM_MORGOTH;
866 Curmonster.m_speed = Player.p_speed * 1.1
867 + ((Player.p_specialtype == SC_EXVALAR) ? Player.p_speed : 0.0);
868 Curmonster.m_flock = 0.0;
869 Curmonster.m_treasuretype = 0;
870 Curmonster.m_experience = 0.0;
871 }
872 } else
873 if (Curmonster.m_type == SM_MIMIC)
874 /* pick another name */
875 {
876 which = (int) ROLL(0.0, 100.0);
877 fseek(Monstfp, (long) which * (long) SZ_MONSTERSTRUCT, SEEK_SET);
878 fread(&Othermonster, SZ_MONSTERSTRUCT, 1, Monstfp);
879 strcpy(Curmonster.m_name, Othermonster.m_name);
880 }
881 truncstring(Curmonster.m_name);
882
883 if (Curmonster.m_type != SM_MORGOTH)
884 /* adjust stats based on which circle player is in */
885 {
886 Curmonster.m_strength *= (1.0 + Circle / 2.0);
887 Curmonster.m_brains *= Circle;
888 Curmonster.m_speed += Circle * 1.e-9;
889 Curmonster.m_energy *= Circle;
890 Curmonster.m_experience *= Circle;
891 }
892 if (Player.p_blindness)
893 /* cannot see monster if blind */
894 Enemyname = "A monster";
895 else
896 Enemyname = Curmonster.m_name;
897
898 if (Player.p_speed <= 0.0)
899 /* make Player.p_speed positive */
900 {
901 Curmonster.m_speed += -Player.p_speed;
902 Player.p_speed = 1.0;
903 }
904 /* fill up the rest of the structure */
905 Curmonster.m_o_strength = Curmonster.m_strength;
906 Curmonster.m_o_speed = Curmonster.m_maxspeed = Curmonster.m_speed;
907 Curmonster.m_o_energy = Curmonster.m_energy;
908 Curmonster.m_melee = Curmonster.m_skirmish = 0.0;
909 }
910
911 void
912 awardtreasure(void)
913 {
914 int whichtreasure; /* calculated treasure to grant */
915 int temp; /* temporary */
916 int ch; /* input */
917 double treasuretype; /* monster's treasure type */
918 double gold = 0.0; /* gold awarded */
919 double gems = 0.0; /* gems awarded */
920 double dtemp; /* for temporary calculations */
921
922 whichtreasure = (int) ROLL(1.0, 3.0); /* pick a treasure */
923 treasuretype = (double) Curmonster.m_treasuretype;
924
925 move(4, 0);
926 clrtobot();
927 move(6, 0);
928
929 if (drandom() > 0.65)
930 /* gold and gems */
931 {
932 if (Curmonster.m_treasuretype > 7)
933 /* gems */
934 {
935 gems = ROLL(1.0, (treasuretype - 7.0)
936 * (treasuretype - 7.0) * (Circle - 1.0) / 4.0);
937 printw("You have discovered %.0f gems!", gems);
938 } else
939 /* gold */
940 {
941 gold = ROLL(treasuretype * 10.0, treasuretype
942 * treasuretype * 10.0 * (Circle - 1.0));
943 printw("You have found %.0f gold pieces.", gold);
944 }
945
946 addstr(" Do you want to pick them up ? ");
947 ch = getanswer("NY", FALSE);
948 addstr("\n\n");
949
950 if (ch == 'Y') {
951 if (drandom() < treasuretype / 35.0 + 0.04)
952 /* cursed */
953 {
954 addstr("They were cursed!\n");
955 cursedtreasure();
956 } else
957 collecttaxes(gold, gems);
958 }
959
960 return;
961 } else
962 /* other treasures */
963 {
964 addstr("You have found some treasure. Do you want to inspect it ? ");
965 ch = getanswer("NY", FALSE);
966 addstr("\n\n");
967
968 if (ch != 'Y')
969 return;
970 else
971 if (drandom() < 0.08 && Curmonster.m_treasuretype != 4) {
972 addstr("It was cursed!\n");
973 cursedtreasure();
974 return;
975 } else
976 switch (Curmonster.m_treasuretype) {
977 case 1: /* treasure type 1 */
978 switch (whichtreasure) {
979 case 1:
980 addstr("You've discovered a power booster!\n");
981 Player.p_mana += ROLL(Circle * 4.0, Circle * 30.0);
982 break;
983
984 case 2:
985 addstr("You have encountered a druid.\n");
986 Player.p_experience +=
987 ROLL(0.0, 2000.0 + Circle * 400.0);
988 break;
989
990 case 3:
991 addstr("You have found a holy orb.\n");
992 Player.p_sin = MAX(0.0, Player.p_sin - 0.25);
993 break;
994 }
995 break;
996 /* end treasure type 1 */
997
998 case 2: /* treasure type 2 */
999 switch (whichtreasure) {
1000 case 1:
1001 addstr("You have found an amulet.\n");
1002 ++Player.p_amulets;
1003 break;
1004
1005 case 2:
1006 addstr("You've found some holy water!\n");
1007 ++Player.p_holywater;
1008 break;
1009
1010 case 3:
1011 addstr("You've met a hermit!\n");
1012 Player.p_sin *= 0.75;
1013 Player.p_mana += 12.0 * Circle;
1014 break;
1015 }
1016 break;
1017 /* end treasure type 2 */
1018
1019 case 3: /* treasure type 3 */
1020 switch (whichtreasure) {
1021 case 1:
1022 dtemp = ROLL(7.0, 30.0 + Circle / 10.0);
1023 printw("You've found a +%.0f shield!\n", dtemp);
1024 if (dtemp >= Player.p_shield)
1025 Player.p_shield = dtemp;
1026 else
1027 SOMEBETTER();
1028 break;
1029
1030 case 2:
1031 addstr("You have rescued a virgin. Will you be honorable ? ");
1032 ch = getanswer("NY", FALSE);
1033 addstr("\n\n");
1034 if (ch == 'Y')
1035 Player.p_virgin = TRUE;
1036 else {
1037 Player.p_experience += 2000.0 * Circle;
1038 ++Player.p_sin;
1039 }
1040 break;
1041
1042 case 3:
1043 addstr("You've discovered some athelas!\n");
1044 --Player.p_poison;
1045 break;
1046 }
1047 break;
1048 /* end treasure type 3 */
1049
1050 case 4: /* treasure type 4 */
1051 addstr("You've found a scroll. Will you read it ? ");
1052 ch = getanswer("NY", FALSE);
1053 addstr("\n\n");
1054
1055 if (ch == 'Y')
1056 switch ((int) ROLL(1, 6)) {
1057 case 1:
1058 addstr("It throws up a shield for you next monster.\n");
1059 getyx(stdscr, whichtreasure, ch);
1060 more(whichtreasure);
1061 Shield =
1062 (Player.p_maxenergy + Player.p_energy) * 5.5 + Circle * 50.0;
1063 Whichmonster = pickmonster();
1064 longjmp(Fightenv, 0);
1065 /* NOTREACHED */
1066
1067 case 2:
1068 addstr("It makes you invisible for you next monster.\n");
1069 getyx(stdscr, whichtreasure, ch);
1070 more(whichtreasure);
1071 Player.p_speed = 1e6;
1072 Whichmonster = pickmonster();
1073 longjmp(Fightenv, 0);
1074 /* NOTREACHED */
1075
1076 case 3:
1077 addstr("It increases your strength ten fold to fight your next monster.\n");
1078 getyx(stdscr, whichtreasure, ch);
1079 more(whichtreasure);
1080 Player.p_might *= 10.0;
1081 Whichmonster = pickmonster();
1082 longjmp(Fightenv, 0);
1083 /* NOTREACHED */
1084
1085 case 4:
1086 addstr("It is a general knowledge scroll.\n");
1087 Player.p_brains += ROLL(2.0, Circle);
1088 Player.p_magiclvl += ROLL(1.0, Circle / 2.0);
1089 break;
1090
1091 case 5:
1092 addstr("It tells you how to pick your next monster.\n");
1093 addstr("Which monster do you want [0-99] ? ");
1094 Whichmonster = (int) infloat();
1095 Whichmonster = MIN(99, MAX(0, Whichmonster));
1096 longjmp(Fightenv, 0);
1097
1098 case 6:
1099 addstr("It was cursed!\n");
1100 cursedtreasure();
1101 break;
1102 }
1103 break;
1104 /* end treasure type 4 */
1105
1106 case 5: /* treasure type 5 */
1107 switch (whichtreasure) {
1108 case 1:
1109 dtemp = ROLL(Circle / 4.0 + 5.0, Circle / 2.0 + 9.0);
1110 printw("You've discovered a +%.0f dagger.\n", dtemp);
1111 if (dtemp >= Player.p_sword)
1112 Player.p_sword = dtemp;
1113 else
1114 SOMEBETTER();
1115 break;
1116
1117 case 2:
1118 dtemp = ROLL(7.5 + Circle * 3.0, Circle * 2.0 + 160.0);
1119 printw("You have found some +%.0f armour!\n", dtemp);
1120 if (dtemp >= Player.p_shield)
1121 Player.p_shield = dtemp;
1122 else
1123 SOMEBETTER();
1124 break;
1125
1126 case 3:
1127 addstr("You've found a tablet.\n");
1128 Player.p_brains += 4.5 * Circle;
1129 break;
1130 }
1131 break;
1132 /* end treasure type 5 */
1133
1134 case 6: /* treasure type 6 */
1135 switch (whichtreasure) {
1136 case 1:
1137 addstr("You've found a priest.\n");
1138 Player.p_energy = Player.p_maxenergy + Player.p_shield;
1139 Player.p_sin /= 2.0;
1140 Player.p_mana += 24.0 * Circle;
1141 Player.p_brains += Circle;
1142 break;
1143
1144 case 2:
1145 addstr("You have come upon Robin Hood!\n");
1146 Player.p_shield += Circle * 2.0;
1147 Player.p_strength += Circle / 2.5 + 1.0;
1148 break;
1149
1150 case 3:
1151 dtemp = ROLL(2.0 + Circle / 4.0, Circle / 1.2 + 10.0);
1152 printw("You have found a +%.0f axe!\n", dtemp);
1153 if (dtemp >= Player.p_sword)
1154 Player.p_sword = dtemp;
1155 else
1156 SOMEBETTER();
1157 break;
1158 }
1159 break;
1160 /* end treasure type 6 */
1161
1162 case 7: /* treasure type 7 */
1163 switch (whichtreasure) {
1164 case 1:
1165 addstr("You've discovered a charm!\n");
1166 ++Player.p_charms;
1167 break;
1168
1169 case 2:
1170 addstr("You have encountered Merlyn!\n");
1171 Player.p_brains += Circle + 5.0;
1172 Player.p_magiclvl += Circle / 3.0 + 5.0;
1173 Player.p_mana += Circle * 10.0;
1174 break;
1175
1176 case 3:
1177 dtemp = ROLL(5.0 + Circle / 3.0, Circle / 1.5 + 20.0);
1178 printw("You have found a +%.0f war hammer!\n", dtemp);
1179 if (dtemp >= Player.p_sword)
1180 Player.p_sword = dtemp;
1181 else
1182 SOMEBETTER();
1183 break;
1184 }
1185 break;
1186 /* end treasure type 7 */
1187
1188 case 8: /* treasure type 8 */
1189 switch (whichtreasure) {
1190 case 1:
1191 addstr("You have found a healing potion.\n");
1192 Player.p_poison = MIN(-2.0, Player.p_poison - 2.0);
1193 break;
1194
1195 case 2:
1196 addstr("You have discovered a transporter. Do you wish to go anywhere ? ");
1197 ch = getanswer("NY", FALSE);
1198 addstr("\n\n");
1199 if (ch == 'Y') {
1200 double x, y;
1201
1202 addstr("X Y Coordinates ? ");
1203 getstring(Databuf, SZ_DATABUF);
1204 sscanf(Databuf, "%lf %lf", &x, &y);
1205 altercoordinates(x, y, A_FORCED);
1206 }
1207 break;
1208
1209 case 3:
1210 dtemp = ROLL(10.0 + Circle / 1.2, Circle * 3.0 + 30.0);
1211 printw("You've found a +%.0f sword!\n", dtemp);
1212 if (dtemp >= Player.p_sword)
1213 Player.p_sword = dtemp;
1214 else
1215 SOMEBETTER();
1216 break;
1217 }
1218 break;
1219 /* end treasure type 8 */
1220
1221 case 10:
1222 case 11:
1223 case 12:
1224 case 13: /* treasure types 10 - 13 */
1225 if (drandom() < 0.33) {
1226 if (Curmonster.m_treasuretype == 10) {
1227 addstr("You've found a pair of elven boots!\n");
1228 Player.p_quickness += 2.0;
1229 break;
1230 } else
1231 if (Curmonster.m_treasuretype == 11
1232 && !Player.p_palantir) {
1233 addstr("You've acquired Saruman's palantir.\n");
1234 Player.p_palantir = TRUE;
1235 break;
1236 } else
1237 if (Player.p_ring.ring_type == R_NONE
1238 && Player.p_specialtype < SC_COUNCIL
1239 && (Curmonster.m_treasuretype == 12
1240 || Curmonster.m_treasuretype == 13))
1241 /* roll
1242 * up
1243 * a
1244 * ring
1245 * */
1246 {
1247 if (drandom() < 0.8)
1248 /* r
1249 * e
1250 * g
1251 * u
1252 * l
1253 * a
1254 * r
1255 *
1256 * ri
1257 * n
1258 * g
1259 * s
1260 * */
1261 {
1262 if (Curmonster.m_treasuretype == 12) {
1263 whichtreasure = R_NAZREG;
1264 temp = 35;
1265 } else {
1266 whichtreasure = R_DLREG;
1267 temp = 0;
1268 }
1269 } else
1270 /* b
1271 * a
1272 * d
1273 *
1274 * ri
1275 * n
1276 * g
1277 * s
1278 * */
1279 {
1280 whichtreasure = R_BAD;
1281 temp = 15 + Statptr->c_ringduration + (int) ROLL(0, 5);
1282 }
1283
1284 addstr("You've discovered a ring. Will you pick it up ? ");
1285 ch = getanswer("NY", FALSE);
1286 addstr("\n\n");
1287
1288 if (ch == 'Y') {
1289 Player.p_ring.ring_type = whichtreasure;
1290 Player.p_ring.ring_duration = temp;
1291 }
1292 break;
1293 }
1294 }
1295 /* end treasure types 10 - 13 */
1296 /* fall through to treasure type 9 if
1297 * no treasure from above */
1298
1299 case 9: /* treasure type 9 */
1300 switch (whichtreasure) {
1301 case 1:
1302 if (Player.p_level <= 1000.0
1303 && Player.p_crowns <= 3
1304 && Player.p_level >= 10.0) {
1305 addstr("You have found a golden crown!\n");
1306 ++Player.p_crowns;
1307 break;
1308 }
1309 /* fall through otherwise */
1310
1311 case 2:
1312 addstr("You've been blessed!\n");
1313 Player.p_blessing = TRUE;
1314 Player.p_sin /= 3.0;
1315 Player.p_energy = Player.p_maxenergy + Player.p_shield;
1316 Player.p_mana += 100.0 * Circle;
1317 break;
1318
1319 case 3:
1320 dtemp = ROLL(1.0, Circle / 5.0 + 5.0);
1321 dtemp = MIN(dtemp, 99.0);
1322 printw("You have discovered some +%.0f quicksilver!\n", dtemp);
1323 if (dtemp >= Player.p_quksilver)
1324 Player.p_quksilver = dtemp;
1325 else
1326 SOMEBETTER();
1327 break;
1328 }
1329 break;
1330 /* end treasure type 9 */
1331 }
1332 }
1333 }
1334
1335 void
1336 cursedtreasure(void)
1337 {
1338 if (Player.p_charms > 0) {
1339 addstr("But your charm saved you!\n");
1340 --Player.p_charms;
1341 } else
1342 if (Player.p_amulets > 0) {
1343 addstr("But your amulet saved you!\n");
1344 --Player.p_amulets;
1345 } else {
1346 Player.p_energy =
1347 (Player.p_maxenergy + Player.p_shield) / 10.0;
1348 Player.p_poison += 0.25;
1349 }
1350 }
1351
1352 void
1353 scramblestats(void)
1354 {
1355 double dbuf[6]; /* to put statistic in */
1356 double dtemp1, dtemp2; /* for swapping values */
1357 int first, second; /* indices for swapping */
1358 double *dptr; /* pointer for filling and emptying buf[] */
1359
1360 /* fill buffer */
1361 dptr = &dbuf[0];
1362 *dptr++ = Player.p_strength;
1363 *dptr++ = Player.p_mana;
1364 *dptr++ = Player.p_brains;
1365 *dptr++ = Player.p_magiclvl;
1366 *dptr++ = Player.p_energy;
1367 *dptr = Player.p_sin;
1368
1369 /* pick values to swap */
1370 first = (int) ROLL(0, 5);
1371 second = (int) ROLL(0, 5);
1372
1373 /* swap values */
1374 dptr = &dbuf[0];
1375 dtemp1 = dptr[first];
1376 /* this expression is split to prevent a compiler loop on some
1377 * compilers */
1378 dtemp2 = dptr[second];
1379 dptr[first] = dtemp2;
1380 dptr[second] = dtemp1;
1381
1382 /* empty buffer */
1383 Player.p_strength = *dptr++;
1384 Player.p_mana = *dptr++;
1385 Player.p_brains = *dptr++;
1386 Player.p_magiclvl = *dptr++;
1387 Player.p_energy = *dptr++;
1388 Player.p_sin = *dptr;
1389 }