1 /* $NetBSD: fight.c,v 1.13 2009/08/31 08:27:16 dholland Exp $ */
4 * fight.c Phantasia monster fighting routines
10 static void awardtreasure(void);
11 static void callmonster(int);
12 static void cancelmonster(void);
13 static void cursedtreasure(void);
14 static void hitmonster(double);
15 static void monsthits(void);
16 static int pickmonster(void);
17 static void playerhits(void);
18 static void scramblestats(void);
19 static void throwspell(void);
22 * FUNCTION: monster battle routine
25 * int particular - particular monster to fight if >= 0
27 * GLOBAL INPUTS: Curmonster, Whichmonster, LINES, Lines, Circle, Shield,
28 * Player, *stdscr, Fileloc, Fightenv[], *Enemyname
30 * GLOBAL OUTPUTS: Curmonster, Whichmonster, Lines, Shield, Player, Luckout
33 * Choose a monster and check against some special types.
34 * Arbitrate between monster and player. Watch for either
39 encounter(int particular)
41 volatile bool firsthit = Player.p_blessing; /* set if player gets the first hit */
42 int flockcnt = 1; /* how many time flocked */
44 /* let others know what we are doing */
45 Player.p_status = S_MONSTER;
46 writerecord(&Player, Fileloc);
52 Shield = 0.0; /* no shield up yet */
55 /* monster is specified */
56 Whichmonster = particular;
58 /* pick random monster */
59 Whichmonster = pickmonster();
61 setjmp(Fightenv); /* this is to enable changing fight state */
64 clrtobot(); /* clear bottom area of screen */
67 callmonster(Whichmonster); /* set up monster to fight */
69 Luckout = FALSE; /* haven't tried to luckout yet */
71 if (Curmonster.m_type == SM_MORGOTH)
72 mvprintw(4, 0, "You've encountered %s, Bane of the Council and Valar.\n",
75 if (Curmonster.m_type == SM_UNICORN) {
76 if (Player.p_virgin) {
77 printw("You just subdued %s, thanks to the virgin.\n", Enemyname);
78 Player.p_virgin = FALSE;
80 printw("You just saw %s running away!\n", Enemyname);
81 Curmonster.m_experience = 0.0;
82 Curmonster.m_treasuretype = 0;
85 /* not a special monster */
87 /* print header, and arbitrate between player and monster */
88 mvprintw(6, 0, "You are being attacked by %s, EXP: %.0f (Size: %.0f)\n",
89 Enemyname, Curmonster.m_experience, Circle);
92 mvprintw(1, 26, "%20.0f", Player.p_energy + Shield); /* overprint energy */
95 if (Curmonster.m_type == SM_DARKLORD
97 && Player.p_charms > 0) {
98 /* overpower Dark Lord with blessing and charm */
99 mvprintw(7, 0, "You just overpowered %s!", Enemyname);
101 Player.p_blessing = FALSE;
106 /* allow paralyzed monster to wake up */
107 Curmonster.m_speed = MIN(Curmonster.m_speed + 1.0, Curmonster.m_maxspeed);
109 if (drandom() * Curmonster.m_speed > drandom() * Player.p_speed
110 /* monster is faster */
111 && Curmonster.m_type != SM_DARKLORD
113 && Curmonster.m_type != SM_SHRIEKER
116 /* monster gets a hit */
119 /* player gets a hit */
126 if (Lines > LINES - 2) {
127 /* near bottom of screen - pause */
133 if (Player.p_energy <= 0.0) {
138 break; /* fight ends if the player is saved from death */
141 if (Curmonster.m_energy <= 0.0)
146 /* give player credit for killing monster */
147 Player.p_experience += Curmonster.m_experience;
149 if (drandom() < Curmonster.m_flock / 100.0) {
153 longjmp(Fightenv, 0);
155 } else if (Circle > 1.0 &&
156 Curmonster.m_treasuretype > 0 &&
157 drandom() > 0.2 + pow(0.4, (double)(flockcnt / 3 + Circle / 3.0))) {
158 /* monster has treasure; this takes # of flocks and size into account */
163 /* pause before returning */
164 getyx(stdscr, Lines, flockcnt);
167 Player.p_ring.ring_inuse = FALSE; /* not using ring */
169 /* clean up the screen */
175 * FUNCTION: choose a monster based upon where we are
177 * RETURN VALUE: monster number to call
179 * GLOBAL INPUTS: Marsh, Circle, Player
182 * Certain monsters can be found in certain areas of the grid.
183 * We take care of rolling them here.
184 * Unfortunately, this routine assumes that the monster data
185 * base is arranged in a particular order. If the data base
186 * is altered (to add monsters, or make them tougher), this
187 * routine may also need to be changed.
193 if (Player.p_specialtype == SC_VALAR)
194 /* even chance of any monster */
195 return ((int)ROLL(0.0, 100.0));
199 return ((int)ROLL(0.0, 15.0));
201 else if (Circle > 24)
202 /* even chance of all non-water monsters */
203 return ((int)ROLL(14.0, 86.0));
205 else if (Circle > 15)
206 /* chance of all non-water monsters, weighted toward middle */
207 return ((int)(ROLL(0.0, 50.0) + ROLL(14.0, 37.0)));
210 /* not all non-water monsters, weighted toward middle */
211 return ((int)(ROLL(0.0, 50.0) + ROLL(14.0, 26.0)));
214 /* even chance of some tamer non-water monsters */
215 return ((int)ROLL(14.0, 50.0));
218 /* even chance of some of the tamest non-water monsters */
219 return ((int)ROLL(14.0, 25.0));
223 * FUNCTION: prompt player for action in monster battle, and process
225 * GLOBAL INPUTS: Curmonster, Lines, Player, *stdscr, Luckout, *Enemyname
227 * GLOBAL OUTPUTS: Curmonster, Lines, Player, Luckout
230 * Process all monster battle options.
236 double inflict; /* damage inflicted */
239 mvaddstr(7, 0, "1:Melee 2:Skirmish 3:Evade 4:Spell 5:Nick ");
242 /* haven't tried to luckout yet */
243 if (Curmonster.m_type == SM_MORGOTH)
244 /* cannot luckout against Morgoth */
247 addstr("6:Luckout ");
250 if (Player.p_ring.ring_type != R_NONE)
251 /* player has a ring */
252 addstr("7:Use Ring ");
259 clrtobot(); /* clear any messages from before */
261 mvaddstr(4, 0, "\n\n"); /* clear status area */
264 case 'T': /* timeout; lose turn */
268 case '1': /* melee */
269 /* melee affects monster's energy and strength */
270 inflict = ROLL(Player.p_might / 2.0 + 5.0, 1.3 * Player.p_might) +
271 (Player.p_ring.ring_inuse ? Player.p_might : 0.0);
273 Curmonster.m_melee += inflict;
274 Curmonster.m_strength = Curmonster.m_o_strength -
275 Curmonster.m_melee / Curmonster.m_o_energy *
276 Curmonster.m_o_strength / 4.0;
280 case '2': /* skirmish */
281 /* skirmish affects monter's energy and speed */
282 inflict = ROLL(Player.p_might / 3.0 + 3.0, 1.1 * Player.p_might) +
283 (Player.p_ring.ring_inuse ? Player.p_might : 0.0);
285 Curmonster.m_skirmish += inflict;
286 Curmonster.m_maxspeed = Curmonster.m_o_speed -
287 Curmonster.m_skirmish / Curmonster.m_o_energy *
288 Curmonster.m_o_speed / 4.0;
292 case '3': /* evade */
293 /* use brains and speed to try to evade */
294 if ((Curmonster.m_type == SM_DARKLORD ||
295 Curmonster.m_type == SM_SHRIEKER
296 /* can always run from D. L. and shrieker */
297 || drandom() * Player.p_speed * Player.p_brains
298 > drandom() * Curmonster.m_speed * Curmonster.m_brains) &&
299 (Curmonster.m_type != SM_MIMIC)) {
300 /* cannot run from mimic */
301 mvaddstr(Lines++, 0, "You got away!");
303 altercoordinates(0.0, 0.0, A_NEAR);
305 mvprintw(Lines++, 0, "%s is still after you!", Enemyname);
310 case '4': /* magic spell */
315 /* hit 1 plus sword; give some experience */
316 inflict = 1.0 + Player.p_sword;
317 Player.p_experience += floor(Curmonster.m_experience / 10.0);
318 Curmonster.m_experience *= 0.92;
319 /* monster gets meaner */
320 Curmonster.m_maxspeed += 2.0;
321 Curmonster.m_speed = (Curmonster.m_speed < 0.0) ? 0.0 : Curmonster.m_speed + 2.0;
322 if (Curmonster.m_type == SM_DARKLORD) {
323 /* Dark Lord; doesn't like to be nicked */
325 "You hit %s %.0f times, and made him mad!", Enemyname, inflict);
326 Player.p_quickness /= 2.0;
327 altercoordinates(0.0, 0.0, A_FAR);
334 case '6': /* luckout */
336 mvaddstr(Lines++, 0, "You already tried that.");
339 if (Curmonster.m_type == SM_MORGOTH) {
341 if (drandom() < Player.p_sin / 100.0) {
342 mvprintw(Lines++, 0, "%s accepted!", Enemyname);
345 mvaddstr(Lines++, 0, "Nope, he's not interested.");
347 /* normal monster; use brains for success */
348 if ((drandom() + 0.333) * Player.p_brains
349 < (drandom() + 0.333) * Curmonster.m_brains)
350 mvprintw(Lines++, 0, "You blew it, %s.", Player.p_name);
352 mvaddstr(Lines++, 0, "You made it!");
353 Curmonster.m_energy = 0.0;
359 case '7': /* use ring */
360 if (Player.p_ring.ring_type != R_NONE) {
361 mvaddstr(Lines++, 0, "Now using ring.");
362 Player.p_ring.ring_inuse = TRUE;
363 if (Player.p_ring.ring_type != R_DLREG)
365 --Player.p_ring.ring_duration;
372 * FUNCTION: process a monster hitting the player
374 * GLOBAL INPUTS: Curmonster, Lines, Circle, Shield, Player, *stdscr,
375 * Fightenv[], *Enemyname
377 * GLOBAL OUTPUTS: Curmonster, Whichmonster, Lines, Shield, Player,
381 * Handle all special monsters here. If the monster is not a special
382 * one, simply roll a hit against the player.
388 double inflict; /* damage inflicted */
391 switch (Curmonster.m_type) {
392 /* may be a special monster */
394 /* hits just enough to kill player */
395 inflict = (Player.p_energy + Shield) * 1.02;
399 /* call a big monster */
401 "Shrieeeek!! You scared it, and it called one of its friends.");
403 Whichmonster = (int)ROLL(70.0, 30.0);
404 longjmp(Fightenv, 0);
408 /* take experience away */
409 inflict = ROLL(10.0, Curmonster.m_strength);
410 inflict = MIN(Player.p_experience, inflict);
412 "%s took away %.0f experience points.", Enemyname, inflict);
413 Player.p_experience -= inflict;
417 if (Player.p_holywater > 0) {
418 /* holy water kills when monster tries to hit */
419 mvprintw(Lines++, 0, "Your holy water killed it!");
420 --Player.p_holywater;
421 Curmonster.m_energy = 0.0;
435 /* else special things */
436 switch (Curmonster.m_type) {
438 /* takes some of the player's strength */
439 inflict = ROLL(1.0, (Circle - 1.0) / 2.0);
440 inflict = MIN(Player.p_strength, inflict);
441 mvprintw(Lines++, 0, "%s sapped %0.f of your strength!",
443 Player.p_strength -= inflict;
444 Player.p_might -= inflict;
448 if (Player.p_palantir) {
449 /* take away palantir */
450 mvprintw(Lines++, 0, "Wormtongue stole your palantir!");
451 Player.p_palantir = FALSE;
452 } else if (drandom() > 0.5) {
453 /* gems turn to gold */
455 "%s transformed your gems into gold!", Enemyname);
456 Player.p_gold += Player.p_gems;
459 /* scramble some stats */
460 mvprintw(Lines++, 0, "%s scrambled your stats!", Enemyname);
466 /* transport player */
467 mvprintw(Lines++, 0, "%s transported you!", Enemyname);
468 altercoordinates(0.0, 0.0, A_FAR);
473 /* suck up some mana */
474 inflict = ROLL(0, 7.5 * Circle);
475 inflict = MIN(Player.p_mana, floor(inflict));
477 "%s sucked up %.0f of your mana!", Enemyname, inflict);
478 Player.p_mana -= inflict;
482 /* try to take ring if player has one */
483 if (Player.p_ring.ring_type != R_NONE) {
484 /* player has a ring */
485 mvaddstr(Lines++, 0, "Will you relinguish your ring ? ");
486 ch = getanswer("YN", FALSE);
489 Player.p_ring.ring_type = R_NONE;
490 Player.p_ring.ring_inuse = FALSE;
496 /* otherwise, take some brains */
498 "%s neutralized 1/5 of your brain!", Enemyname);
499 Player.p_brains *= 0.8;
503 /* take some gold and gems */
505 "%s took half your gold and gems and flew off.", Enemyname);
506 Player.p_gold /= 2.0;
507 Player.p_gems /= 2.0;
512 /* steal a gold piece and run */
514 "%s stole one gold piece and ran away.", Enemyname);
515 Player.p_gold = MAX(0.0, Player.p_gold - 1.0);
520 /* bite and (medium) poison */
522 "%s has bitten and poisoned you!", Enemyname);
523 Player.p_poison -= 1.0;
527 /* bite and (small) poison */
528 mvprintw(Lines++, 0, "%s bit and poisoned you!", Enemyname);
529 Player.p_poison += 0.25;
534 mvprintw(Lines++, 0, "%s farted and scampered off.", Enemyname);
535 Player.p_energy /= 2.0; /* damage from fumes */
540 if (Player.p_ring.ring_type != R_NONE) {
541 /* try to steal ring */
543 "%s tried to steal your ring, ", Enemyname);
545 addstr("but was unsuccessful.");
547 addstr("and ran away with it!");
548 Player.p_ring.ring_type = R_NONE;
555 /* inflict damage through shield */
556 inflict = ROLL(15.0, Circle * 10.0);
557 inflict = MIN(inflict, Player.p_energy);
558 mvprintw(Lines++, 0, "%s sapped %.0f of your energy.",
560 Player.p_energy -= inflict;
564 /* take all metal treasures */
566 "%s took all your metal treasures!", Enemyname);
575 /* (large) poison and take a quickness */
577 "%s poisoned you, and took one quik.", Enemyname);
578 Player.p_poison += 5.0;
579 Player.p_quickness -= 1.0;
583 /* fly away, and leave either a Jubjub bird or Bonnacon */
585 "%s flew away, and left you to contend with one of its friends.",
587 Whichmonster = (drandom() > 0.5) ? 77 : 55;
588 longjmp(Fightenv, 0);
592 /* partially regenerate monster */
594 "%s partially regenerated his energy.!", Enemyname);
595 Curmonster.m_energy +=
596 floor((Curmonster.m_o_energy - Curmonster.m_energy) / 2.0);
597 Curmonster.m_strength = Curmonster.m_o_strength;
598 Curmonster.m_melee = Curmonster.m_skirmish = 0.0;
599 Curmonster.m_maxspeed = Curmonster.m_o_speed;
603 if (!Player.p_blindness) {
605 mvprintw(Lines++, 0, "%s blinded you!", Enemyname);
606 Player.p_blindness = TRUE;
607 Enemyname = "A monster";
614 /* fall through to here if monster inflicts a normal hit */
615 inflict = drandom() * Curmonster.m_strength + 0.5;
617 mvprintw(Lines++, 0, "%s hit you %.0f times!", Enemyname, inflict);
619 if ((Shield -= inflict) < 0) {
620 Player.p_energy += Shield;
626 * FUNCTION: mark current monster as no longer active
628 * GLOBAL OUTPUTS: Curmonster
631 * Clear current monster's energy, experience, treasure type, and
632 * flock. This is the same as having the monster run away.
638 Curmonster.m_energy = 0.0;
639 Curmonster.m_experience = 0.0;
640 Curmonster.m_treasuretype = 0;
641 Curmonster.m_flock = 0.0;
645 * FUNCTION: inflict damage upon current monster
648 * double inflict - damage to inflict upon monster
650 * GLOBAL INPUTS: Curmonster, Lines, Player, *stdscr, *Enemyname
652 * GLOBAL OUTPUTS: Curmonster, Lines
655 * Hit monster specified number of times. Handle when monster dies,
656 * and a few special monsters.
660 hitmonster(double inflict)
662 mvprintw(Lines++, 0, "You hit %s %.0f times!", Enemyname, inflict);
663 Curmonster.m_energy -= inflict;
664 if (Curmonster.m_energy > 0.0) {
665 if (Curmonster.m_type == SM_DARKLORD || Curmonster.m_type == SM_SHRIEKER)
666 /* special monster didn't die */
669 /* monster died. print message. */
670 if (Curmonster.m_type == SM_MORGOTH)
671 mvaddstr(Lines++, 0, "You have defeated Morgoth, but he may return. . .");
673 /* all other types of monsters */
674 mvprintw(Lines++, 0, "You killed it. Good work, %s.", Player.p_name);
676 if (Curmonster.m_type == SM_MIMIC
677 && strcmp(Curmonster.m_name, "A Mimic") != 0
678 && !Player.p_blindness)
679 mvaddstr(Lines++, 0, "The body slowly changes into the form of a mimic.");
685 * FUNCTION: throw a magic spell
687 * GLOBAL INPUTS: Curmonster, Whichmonster, Nomana[], Player, *stdscr,
688 * Fightenv[], Illspell[], *Enemyname
690 * GLOBAL OUTPUTS: Curmonster, Whichmonster, Shield, Player
693 * Prompt player and process magic spells.
699 double inflict; /* damage inflicted */
700 double dtemp; /* for dtemporary calculations */
704 mvaddstr(7, 0, "\n\n"); /* clear menu area */
706 if (Player.p_magiclvl >= ML_ALLORNOTHING)
707 mvaddstr(7, 0, "1:All or Nothing ");
708 if (Player.p_magiclvl >= ML_MAGICBOLT)
709 addstr("2:Magic Bolt ");
710 if (Player.p_magiclvl >= ML_FORCEFIELD)
711 addstr("3:Force Field ");
712 if (Player.p_magiclvl >= ML_XFORM)
713 addstr("4:Transform ");
714 if (Player.p_magiclvl >= ML_INCRMIGHT)
715 addstr("5:Increase Might\n");
716 if (Player.p_magiclvl >= ML_INVISIBLE)
717 mvaddstr(8, 0, "6:Invisibility ");
718 if (Player.p_magiclvl >= ML_XPORT)
719 addstr("7:Transport ");
720 if (Player.p_magiclvl >= ML_PARALYZE)
721 addstr("8:Paralyze ");
722 if (Player.p_specialtype >= SC_COUNCIL)
724 mvaddstr(4, 0, "Spell ? ");
726 ch = getanswer(" ", TRUE);
728 mvaddstr(7, 0, "\n\n"); /* clear menu area */
730 if (Curmonster.m_type == SM_MORGOTH && ch != '3')
731 /* can only throw force field against Morgoth */
735 case '1': /* all or nothing */
736 if (drandom() < 0.25) {
738 inflict = Curmonster.m_energy * 1.01 + 1.0;
740 if (Curmonster.m_type == SM_DARKLORD)
741 /* all or nothing doesn't quite work against D. L. */
744 /* failure -- monster gets stronger and quicker */
745 Curmonster.m_o_strength = Curmonster.m_strength *= 2.0;
746 Curmonster.m_maxspeed *= 2.0;
747 Curmonster.m_o_speed *= 2.0;
749 /* paralyzed monsters wake up a bit */
750 Curmonster.m_speed = MAX(1.0, Curmonster.m_speed * 2.0);
753 if (Player.p_mana >= MM_ALLORNOTHING)
754 /* take a mana if player has one */
755 Player.p_mana -= MM_ALLORNOTHING;
760 case '2': /* magic bolt */
761 if (Player.p_magiclvl < ML_MAGICBOLT)
765 /* prompt for amount to expend */
766 mvaddstr(4, 0, "How much mana for bolt? ");
767 dtemp = floor(infloat());
768 } while (dtemp < 0.0 || dtemp > Player.p_mana);
770 Player.p_mana -= dtemp;
772 if (Curmonster.m_type == SM_DARKLORD)
773 /* magic bolts don't work against D. L. */
776 inflict = dtemp * ROLL(15.0, sqrt(Player.p_magiclvl / 3.0 + 1.0));
777 mvaddstr(5, 0, "Magic Bolt fired!\n");
782 case '3': /* force field */
783 if (Player.p_magiclvl < ML_FORCEFIELD)
785 else if (Player.p_mana < MM_FORCEFIELD)
788 Player.p_mana -= MM_FORCEFIELD;
789 Shield = (Player.p_maxenergy + Player.p_shield) * 4.2 + 45.0;
790 mvaddstr(5, 0, "Force Field up.\n");
794 case '4': /* transform */
795 if (Player.p_magiclvl < ML_XFORM)
797 else if (Player.p_mana < MM_XFORM)
800 Player.p_mana -= MM_XFORM;
801 Whichmonster = (int)ROLL(0.0, 100.0);
802 longjmp(Fightenv, 0);
807 case '5': /* increase might */
808 if (Player.p_magiclvl < ML_INCRMIGHT)
810 else if (Player.p_mana < MM_INCRMIGHT)
813 Player.p_mana -= MM_INCRMIGHT;
815 (1.2 * (Player.p_strength + Player.p_sword) +
816 5.0 - Player.p_might) / 2.0;
817 mvprintw(5, 0, "New strength: %.0f\n", Player.p_might);
821 case '6': /* invisible */
822 if (Player.p_magiclvl < ML_INVISIBLE)
824 else if (Player.p_mana < MM_INVISIBLE)
827 Player.p_mana -= MM_INVISIBLE;
829 (1.2 * (Player.p_quickness + Player.p_quksilver) +
830 5.0 - Player.p_speed) / 2.0;
831 mvprintw(5, 0, "New quickness: %.0f\n", Player.p_speed);
835 case '7': /* transport */
836 if (Player.p_magiclvl < ML_XPORT)
838 else if (Player.p_mana < MM_XPORT)
841 Player.p_mana -= MM_XPORT;
842 if (Player.p_brains + Player.p_magiclvl
843 < Curmonster.m_experience / 200.0 * drandom()) {
844 mvaddstr(5, 0, "Transport backfired!\n");
845 altercoordinates(0.0, 0.0, A_FAR);
848 mvprintw(5, 0, "%s is transported.\n", Enemyname);
850 /* monster didn't drop its treasure */
851 Curmonster.m_treasuretype = 0;
853 Curmonster.m_energy = 0.0;
858 case '8': /* paralyze */
859 if (Player.p_magiclvl < ML_PARALYZE)
861 else if (Player.p_mana < MM_PARALYZE)
864 Player.p_mana -= MM_PARALYZE;
865 if (Player.p_magiclvl >
866 Curmonster.m_experience / 1000.0 * drandom()) {
867 mvprintw(5, 0, "%s is held.\n", Enemyname);
868 Curmonster.m_speed = -2.0;
870 mvaddstr(5, 0, "Monster unaffected.\n");
874 case '9': /* specify */
875 if (Player.p_specialtype < SC_COUNCIL)
877 else if (Player.p_mana < MM_SPECIFY)
880 Player.p_mana -= MM_SPECIFY;
881 mvaddstr(5, 0, "Which monster do you want [0-99] ? ");
882 Whichmonster = (int)infloat();
883 Whichmonster = MAX(0, MIN(99, Whichmonster));
884 longjmp(Fightenv, 0);
892 * FUNCTION: read monster from file, and fill structure
895 * int which - which monster to call
897 * GLOBAL INPUTS: Curmonster, Circle, Player, *Monstfp
899 * GLOBAL OUTPUTS: Curmonster, Player, *Enemyname
902 * Read specified monster from monster database and fill up
903 * current monster structure.
904 * Adjust statistics based upon current size.
905 * Handle some special monsters.
909 callmonster(int which)
911 struct monster Othermonster; /* to find a name for mimics */
913 which = MIN(which, 99); /* make sure within range */
916 fseek(Monstfp, (long)which * (long)SZ_MONSTERSTRUCT, SEEK_SET);
917 fread((char *)&Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp);
919 /* handle some special monsters */
920 if (Curmonster.m_type == SM_MODNAR) {
921 if (Player.p_specialtype < SC_COUNCIL) {
922 /* randomize some stats */
923 Curmonster.m_strength *= drandom() + 0.5;
924 Curmonster.m_brains *= drandom() + 0.5;
925 Curmonster.m_speed *= drandom() + 0.5;
926 Curmonster.m_energy *= drandom() + 0.5;
927 Curmonster.m_experience *= drandom() + 0.5;
928 Curmonster.m_treasuretype =
929 (int)ROLL(0.0, (double)Curmonster.m_treasuretype);
931 /* make Modnar into Morgoth */
932 strcpy(Curmonster.m_name, "Morgoth");
933 Curmonster.m_strength = drandom() * (Player.p_maxenergy + Player.p_shield) / 1.4
934 + drandom() * (Player.p_maxenergy + Player.p_shield) / 1.5;
935 Curmonster.m_brains = Player.p_brains;
936 Curmonster.m_energy = Player.p_might * 30.0;
937 Curmonster.m_type = SM_MORGOTH;
938 Curmonster.m_speed = Player.p_speed *
939 ((Player.p_specialtype == SC_EXVALAR) ? 2.1 : 1.1);
940 Curmonster.m_flock = 0.0;
941 Curmonster.m_treasuretype = 0;
942 Curmonster.m_experience = 0.0;
944 } else if (Curmonster.m_type == SM_MIMIC) {
945 /* pick another name */
946 which = (int)ROLL(0.0, 100.0);
947 fseek(Monstfp, (long)which * (long)SZ_MONSTERSTRUCT, SEEK_SET);
948 fread(&Othermonster, SZ_MONSTERSTRUCT, 1, Monstfp);
949 strcpy(Curmonster.m_name, Othermonster.m_name);
952 truncstring(Curmonster.m_name);
954 if (Curmonster.m_type != SM_MORGOTH) {
955 /* adjust stats based on which circle player is in */
956 Curmonster.m_strength *= (1.0 + Circle / 2.0);
957 Curmonster.m_brains *= Circle;
958 Curmonster.m_speed += Circle * 1.e-9;
959 Curmonster.m_energy *= Circle;
960 Curmonster.m_experience *= Circle;
963 if (Player.p_blindness)
964 /* cannot see monster if blind */
965 Enemyname = "A monster";
967 Enemyname = Curmonster.m_name;
969 if (Player.p_speed <= 0.0) {
970 /* make Player.p_speed positive */
971 Curmonster.m_speed += -Player.p_speed;
972 Player.p_speed = 1.0;
975 /* fill up the rest of the structure */
976 Curmonster.m_o_strength = Curmonster.m_strength;
977 Curmonster.m_o_speed = Curmonster.m_maxspeed = Curmonster.m_speed;
978 Curmonster.m_o_energy = Curmonster.m_energy;
979 Curmonster.m_melee = Curmonster.m_skirmish = 0.0;
983 * FUNCTION: select a treasure
985 * GLOBAL INPUTS: Somebetter[], Curmonster, Whichmonster, Circle, Player,
986 * *stdscr, Databuf[], *Statptr, Fightenv[]
988 * GLOBAL OUTPUTS: Whichmonster, Shield, Player
991 * Roll up a treasure based upon monster type and size, and
992 * certain player statistics.
993 * Handle cursed treasure.
999 int whichtreasure; /* calculated treasure to grant */
1000 int temp; /* temporary */
1002 double treasuretype; /* monster's treasure type */
1003 double gold = 0.0; /* gold awarded */
1004 double gems = 0.0; /* gems awarded */
1005 double dtemp; /* for temporary calculations */
1007 whichtreasure = (int)ROLL(1.0, 3.0); /* pick a treasure */
1008 treasuretype = (double)Curmonster.m_treasuretype;
1014 if (drandom() > 0.65) {
1016 if (Curmonster.m_treasuretype > 7) {
1018 gems = ROLL(1.0, (treasuretype - 7.0)
1019 * (treasuretype - 7.0) * (Circle - 1.0) / 4.0);
1020 printw("You have discovered %.0f gems!", gems);
1023 gold = ROLL(treasuretype * 10.0, treasuretype
1024 * treasuretype * 10.0 * (Circle - 1.0));
1025 printw("You have found %.0f gold pieces.", gold);
1028 addstr(" Do you want to pick them up ? ");
1029 ch = getanswer("NY", FALSE);
1033 if (drandom() < treasuretype / 35.0 + 0.04) {
1035 addstr("They were cursed!\n");
1038 collecttaxes(gold, gems);
1043 /* other treasures */
1044 addstr("You have found some treasure. Do you want to inspect it ? ");
1045 ch = getanswer("NY", FALSE);
1050 else if (drandom() < 0.08 && Curmonster.m_treasuretype != 4) {
1051 addstr("It was cursed!\n");
1055 switch (Curmonster.m_treasuretype) {
1056 case 1: /* treasure type 1 */
1057 switch (whichtreasure) {
1059 addstr("You've discovered a power booster!\n");
1060 Player.p_mana += ROLL(Circle * 4.0, Circle * 30.0);
1064 addstr("You have encountered a druid.\n");
1065 Player.p_experience +=
1066 ROLL(0.0, 2000.0 + Circle * 400.0);
1070 addstr("You have found a holy orb.\n");
1071 Player.p_sin = MAX(0.0, Player.p_sin - 0.25);
1075 /* end treasure type 1 */
1077 case 2: /* treasure type 2 */
1078 switch (whichtreasure) {
1080 addstr("You have found an amulet.\n");
1085 addstr("You've found some holy water!\n");
1086 ++Player.p_holywater;
1090 addstr("You've met a hermit!\n");
1091 Player.p_sin *= 0.75;
1092 Player.p_mana += 12.0 * Circle;
1096 /* end treasure type 2 */
1098 case 3: /* treasure type 3 */
1099 switch (whichtreasure) {
1101 dtemp = ROLL(7.0, 30.0 + Circle / 10.0);
1102 printw("You've found a +%.0f shield!\n", dtemp);
1103 if (dtemp >= Player.p_shield)
1104 Player.p_shield = dtemp;
1110 addstr("You have rescued a virgin. Will you be honorable ? ");
1111 ch = getanswer("NY", FALSE);
1114 Player.p_virgin = TRUE;
1116 Player.p_experience += 2000.0 * Circle;
1122 addstr("You've discovered some athelas!\n");
1127 /* end treasure type 3 */
1129 case 4: /* treasure type 4 */
1130 addstr("You've found a scroll. Will you read it ? ");
1131 ch = getanswer("NY", FALSE);
1135 switch ((int)ROLL(1, 6)) {
1137 addstr("It throws up a shield for you next monster.\n");
1138 getyx(stdscr, whichtreasure, ch);
1139 more(whichtreasure);
1141 (Player.p_maxenergy + Player.p_energy) * 5.5 + Circle * 50.0;
1142 Whichmonster = pickmonster();
1143 longjmp(Fightenv, 0);
1147 addstr("It makes you invisible for you next monster.\n");
1148 getyx(stdscr, whichtreasure, ch);
1149 more(whichtreasure);
1150 Player.p_speed = 1e6;
1151 Whichmonster = pickmonster();
1152 longjmp(Fightenv, 0);
1156 addstr("It increases your strength ten fold to fight your next monster.\n");
1157 getyx(stdscr, whichtreasure, ch);
1158 more(whichtreasure);
1159 Player.p_might *= 10.0;
1160 Whichmonster = pickmonster();
1161 longjmp(Fightenv, 0);
1165 addstr("It is a general knowledge scroll.\n");
1166 Player.p_brains += ROLL(2.0, Circle);
1167 Player.p_magiclvl += ROLL(1.0, Circle / 2.0);
1171 addstr("It tells you how to pick your next monster.\n");
1172 addstr("Which monster do you want [0-99] ? ");
1173 Whichmonster = (int)infloat();
1174 Whichmonster = MIN(99, MAX(0, Whichmonster));
1175 longjmp(Fightenv, 0);
1178 addstr("It was cursed!\n");
1183 /* end treasure type 4 */
1185 case 5: /* treasure type 5 */
1186 switch (whichtreasure) {
1188 dtemp = ROLL(Circle / 4.0 + 5.0, Circle / 2.0 + 9.0);
1189 printw("You've discovered a +%.0f dagger.\n", dtemp);
1190 if (dtemp >= Player.p_sword)
1191 Player.p_sword = dtemp;
1197 dtemp = ROLL(7.5 + Circle * 3.0, Circle * 2.0 + 160.0);
1198 printw("You have found some +%.0f armour!\n", dtemp);
1199 if (dtemp >= Player.p_shield)
1200 Player.p_shield = dtemp;
1206 addstr("You've found a tablet.\n");
1207 Player.p_brains += 4.5 * Circle;
1211 /* end treasure type 5 */
1213 case 6: /* treasure type 6 */
1214 switch (whichtreasure) {
1216 addstr("You've found a priest.\n");
1217 Player.p_energy = Player.p_maxenergy + Player.p_shield;
1218 Player.p_sin /= 2.0;
1219 Player.p_mana += 24.0 * Circle;
1220 Player.p_brains += Circle;
1224 addstr("You have come upon Robin Hood!\n");
1225 Player.p_shield += Circle * 2.0;
1226 Player.p_strength += Circle / 2.5 + 1.0;
1230 dtemp = ROLL(2.0 + Circle / 4.0, Circle / 1.2 + 10.0);
1231 printw("You have found a +%.0f axe!\n", dtemp);
1232 if (dtemp >= Player.p_sword)
1233 Player.p_sword = dtemp;
1239 /* end treasure type 6 */
1241 case 7: /* treasure type 7 */
1242 switch (whichtreasure) {
1244 addstr("You've discovered a charm!\n");
1249 addstr("You have encountered Merlyn!\n");
1250 Player.p_brains += Circle + 5.0;
1251 Player.p_magiclvl += Circle / 3.0 + 5.0;
1252 Player.p_mana += Circle * 10.0;
1256 dtemp = ROLL(5.0 + Circle / 3.0, Circle / 1.5 + 20.0);
1257 printw("You have found a +%.0f war hammer!\n", dtemp);
1258 if (dtemp >= Player.p_sword)
1259 Player.p_sword = dtemp;
1265 /* end treasure type 7 */
1267 case 8: /* treasure type 8 */
1268 switch (whichtreasure) {
1270 addstr("You have found a healing potion.\n");
1271 Player.p_poison = MIN(-2.0, Player.p_poison - 2.0);
1275 addstr("You have discovered a transporter. Do you wish to go anywhere ? ");
1276 ch = getanswer("NY", FALSE);
1281 addstr("X Y Coordinates ? ");
1282 getstring(Databuf, SZ_DATABUF);
1283 sscanf(Databuf, "%lf %lf", &x, &y);
1284 altercoordinates(x, y, A_FORCED);
1289 dtemp = ROLL(10.0 + Circle / 1.2, Circle * 3.0 + 30.0);
1290 printw("You've found a +%.0f sword!\n", dtemp);
1291 if (dtemp >= Player.p_sword)
1292 Player.p_sword = dtemp;
1298 /* end treasure type 8 */
1303 case 13: /* treasure types 10 - 13 */
1304 if (drandom() < 0.33) {
1305 if (Curmonster.m_treasuretype == 10) {
1306 addstr("You've found a pair of elven boots!\n");
1307 Player.p_quickness += 2.0;
1309 } else if (Curmonster.m_treasuretype == 11 &&
1310 !Player.p_palantir) {
1311 addstr("You've acquired Saruman's palantir.\n");
1312 Player.p_palantir = TRUE;
1314 } else if (Player.p_ring.ring_type == R_NONE &&
1315 Player.p_specialtype < SC_COUNCIL &&
1316 (Curmonster.m_treasuretype == 12 ||
1317 Curmonster.m_treasuretype == 13)) {
1318 /* roll up a ring */
1319 if (drandom() < 0.8) {
1321 if (Curmonster.m_treasuretype == 12) {
1322 whichtreasure = R_NAZREG;
1325 whichtreasure = R_DLREG;
1330 whichtreasure = R_BAD;
1331 temp = 15 + Statptr->c_ringduration + (int)ROLL(0, 5);
1334 addstr("You've discovered a ring. Will you pick it up ? ");
1335 ch = getanswer("NY", FALSE);
1339 Player.p_ring.ring_type = whichtreasure;
1340 Player.p_ring.ring_duration = temp;
1346 /* end treasure types 10 - 13 */
1347 /* fall through to treasure type 9 if no treasure from above */
1350 case 9: /* treasure type 9 */
1351 switch (whichtreasure) {
1353 if (Player.p_level <= 1000.0 &&
1354 Player.p_crowns <= 3 &&
1355 Player.p_level >= 10.0) {
1356 addstr("You have found a golden crown!\n");
1363 addstr("You've been blessed!\n");
1364 Player.p_blessing = TRUE;
1365 Player.p_sin /= 3.0;
1366 Player.p_energy = Player.p_maxenergy + Player.p_shield;
1367 Player.p_mana += 100.0 * Circle;
1371 dtemp = ROLL(1.0, Circle / 5.0 + 5.0);
1372 dtemp = MIN(dtemp, 99.0);
1373 printw("You have discovered some +%.0f quicksilver!\n", dtemp);
1374 if (dtemp >= Player.p_quksilver)
1375 Player.p_quksilver = dtemp;
1381 /* end treasure type 9 */
1387 * FUNCTION: take care of cursed treasure
1389 * GLOBAL INPUTS: Player, *stdscr
1391 * GLOBAL OUTPUTS: Player
1394 * Handle cursed treasure. Look for amulets and charms to save
1395 * the player from the curse.
1399 cursedtreasure(void)
1401 if (Player.p_charms > 0) {
1402 addstr("But your charm saved you!\n");
1404 } else if (Player.p_amulets > 0) {
1405 addstr("But your amulet saved you!\n");
1408 Player.p_energy = (Player.p_maxenergy + Player.p_shield) / 10.0;
1409 Player.p_poison += 0.25;
1414 * FUNCTION: scramble some selected statistics
1416 * GLOBAL INPUTS: Player
1418 * GLOBAL OUTPUTS: Player
1421 * Swap a few player statistics randomly.
1427 double dbuf[6]; /* to put statistic in */
1428 double dtemp1, dtemp2; /* for swapping values */
1429 int first, second; /* indices for swapping */
1430 double *dptr; /* pointer for filling and emptying buf[] */
1434 *dptr++ = Player.p_strength;
1435 *dptr++ = Player.p_mana;
1436 *dptr++ = Player.p_brains;
1437 *dptr++ = Player.p_magiclvl;
1438 *dptr++ = Player.p_energy;
1439 *dptr = Player.p_sin;
1441 /* pick values to swap */
1442 first = (int)ROLL(0, 5);
1443 second = (int)ROLL(0, 5);
1447 dtemp1 = dptr[first];
1448 /* this expression is split to prevent a compiler loop on some compilers */
1449 dtemp2 = dptr[second];
1450 dptr[first] = dtemp2;
1451 dptr[second] = dtemp1;
1454 Player.p_strength = *dptr++;
1455 Player.p_mana = *dptr++;
1456 Player.p_brains = *dptr++;
1457 Player.p_magiclvl = *dptr++;
1458 Player.p_energy = *dptr++;
1459 Player.p_sin = *dptr;