2 * fight.c Phantasia monster fighting routines
10 /************************************************************************
12 / FUNCTION NAME: encounter()
14 / FUNCTION: monster battle routine
16 / AUTHOR: E. A. Estes, 2/20/86
19 / int particular - particular monster to fight if >= 0
23 / MODULES CALLED: monsthits(), playerhits(), readmessage(), callmonster(),
24 / writerecord(), pickmonster(), displaystats(), pow(), cancelmonster(),
25 / awardtreasure(), more(), death(), wmove(), setjmp(), drandom(), printw(),
26 / longjmp(), wrefresh(), mvprintw(), wclrtobot()
28 / GLOBAL INPUTS: Curmonster, Whichmonster, LINES, Lines, Circle, Shield,
29 / Player, *stdscr, Fileloc, Fightenv[], *Enemyname
31 / GLOBAL OUTPUTS: Curmonster, Whichmonster, Lines, Shield, Player, Luckout
34 / Choose a monster and check against some special types.
35 / Arbitrate between monster and player. Watch for either
38 *************************************************************************/
43 bool firsthit = Player.p_blessing; /* set if player gets the first hit */
44 int flockcnt = 1; /* how many time flocked */
46 /* let others know what we are doing */
47 Player.p_status = S_MONSTER;
48 writerecord(&Player, Fileloc);
54 Shield = 0.0; /* no shield up yet */
57 /* monster is specified */
58 Whichmonster = particular;
60 /* pick random monster */
61 Whichmonster = pickmonster();
63 setjmp(Fightenv); /* this is to enable changing fight state */
66 clrtobot(); /* clear bottom area of screen */
69 callmonster(Whichmonster); /* set up monster to fight */
71 Luckout = FALSE; /* haven't tried to luckout yet */
73 if (Curmonster.m_type == SM_MORGOTH)
74 mvprintw(4, 0, "You've encountered %s, Bane of the Council and Valar.\n",
77 if (Curmonster.m_type == SM_UNICORN)
81 printw("You just subdued %s, thanks to the virgin.\n", Enemyname);
82 Player.p_virgin = FALSE;
86 printw("You just saw %s running away!\n", Enemyname);
87 Curmonster.m_experience = 0.0;
88 Curmonster.m_treasuretype = 0;
92 /* not a special monster */
94 /* print header, and arbitrate between player and monster */
96 mvprintw(6, 0, "You are being attacked by %s, EXP: %.0f (Size: %.0f)\n",
97 Enemyname, Curmonster.m_experience, Circle);
100 mvprintw(1, 26, "%20.0f", Player.p_energy + Shield); /* overprint energy */
103 if (Curmonster.m_type == SM_DARKLORD
105 && Player.p_charms > 0)
106 /* overpower Dark Lord with blessing and charm */
108 mvprintw(7, 0, "You just overpowered %s!", Enemyname);
110 Player.p_blessing = FALSE;
115 /* allow paralyzed monster to wake up */
116 Curmonster.m_speed = MIN(Curmonster.m_speed + 1.0, Curmonster.m_maxspeed);
118 if (drandom() * Curmonster.m_speed > drandom() * Player.p_speed
119 /* monster is faster */
120 && Curmonster.m_type != SM_DARKLORD
122 && Curmonster.m_type != SM_SHRIEKER
125 /* monster gets a hit */
128 /* player gets a hit */
136 if (Lines > LINES - 2)
137 /* near bottom of screen - pause */
144 if (Player.p_energy <= 0.0)
150 break; /* fight ends if the player is saved from death */
153 if (Curmonster.m_energy <= 0.0)
158 /* give player credit for killing monster */
159 Player.p_experience += Curmonster.m_experience;
161 if (drandom() < Curmonster.m_flock / 100.0)
166 longjmp(Fightenv, 0);
169 else if (Circle > 1.0
170 && Curmonster.m_treasuretype > 0
171 && drandom() > 0.2 + pow(0.4, (double) (flockcnt / 3 + Circle / 3.0)))
172 /* monster has treasure; this takes # of flocks and size into account */
178 /* pause before returning */
179 getyx(stdscr, Lines, flockcnt);
182 Player.p_ring.ring_inuse = FALSE; /* not using ring */
184 /* clean up the screen */
189 /************************************************************************
191 / FUNCTION NAME: pickmonster()
193 / FUNCTION: choose a monster based upon where we are
195 / AUTHOR: E. A. Estes, 2/20/86
199 / RETURN VALUE: monster number to call
201 / MODULES CALLED: floor(), drandom()
203 / GLOBAL INPUTS: Marsh, Circle, Player
205 / GLOBAL OUTPUTS: none
208 / Certain monsters can be found in certain areas of the grid.
209 / We take care of rolling them here.
210 / Unfortunately, this routine assumes that the monster data
211 / base is arranged in a particular order. If the data base
212 / is altered (to add monsters, or make them tougher), this
213 / routine may also need to be changed.
215 *************************************************************************/
219 if (Player.p_specialtype == SC_VALAR)
220 /* even chance of any monster */
221 return((int) ROLL(0.0, 100.0));
225 return((int) ROLL(0.0, 15.0));
227 else if (Circle > 24)
228 /* even chance of all non-water monsters */
229 return((int) ROLL(14.0, 86.0));
231 else if (Circle > 15)
232 /* chance of all non-water monsters, weighted toward middle */
233 return((int) (ROLL(0.0, 50.0) + ROLL(14.0, 37.0)));
236 /* not all non-water monsters, weighted toward middle */
237 return((int) (ROLL(0.0, 50.0) + ROLL(14.0, 26.0)));
240 /* even chance of some tamer non-water monsters */
241 return((int) ROLL(14.0, 50.0));
244 /* even chance of some of the tamest non-water monsters */
245 return((int) ROLL(14.0, 25.0));
248 /************************************************************************
250 / FUNCTION NAME: playerhits()
252 / FUNCTION: prompt player for action in monster battle, and process
254 / AUTHOR: E. A. Estes, 12/4/85
260 / MODULES CALLED: hitmonster(), throwspell(), inputoption(), cancelmonster(),
261 / floor(), wmove(), drandom(), altercoordinates(), waddstr(), mvprintw(),
262 / wclrtoeol(), wclrtobot()
264 / GLOBAL INPUTS: Curmonster, Lines, Player, *stdscr, Luckout, *Enemyname
266 / GLOBAL OUTPUTS: Curmonster, Lines, Player, Luckout
269 / Process all monster battle options.
271 *************************************************************************/
275 double inflict; /* damage inflicted */
278 mvaddstr(7, 0, "1:Melee 2:Skirmish 3:Evade 4:Spell 5:Nick ");
281 /* haven't tried to luckout yet */
282 if (Curmonster.m_type == SM_MORGOTH)
283 /* cannot luckout against Morgoth */
286 addstr("6:Luckout ");
289 if (Player.p_ring.ring_type != R_NONE)
290 /* player has a ring */
291 addstr("7:Use Ring ");
298 clrtobot(); /* clear any messages from before */
300 mvaddstr(4, 0, "\n\n"); /* clear status area */
304 case 'T': /* timeout; lose turn */
308 case '1': /* melee */
309 /* melee affects monster's energy and strength */
310 inflict = ROLL(Player.p_might / 2.0 + 5.0, 1.3 * Player.p_might)
311 + (Player.p_ring.ring_inuse ? Player.p_might : 0.0);
313 Curmonster.m_melee += inflict;
314 Curmonster.m_strength = Curmonster.m_o_strength
315 - Curmonster.m_melee / Curmonster.m_o_energy
316 * Curmonster.m_o_strength / 4.0;
320 case '2': /* skirmish */
321 /* skirmish affects monter's energy and speed */
322 inflict = ROLL(Player.p_might / 3.0 + 3.0, 1.1 * Player.p_might)
323 + (Player.p_ring.ring_inuse ? Player.p_might : 0.0);
325 Curmonster.m_skirmish += inflict;
326 Curmonster.m_maxspeed = Curmonster.m_o_speed
327 - Curmonster.m_skirmish / Curmonster.m_o_energy
328 * Curmonster.m_o_speed / 4.0;
332 case '3': /* evade */
333 /* use brains and speed to try to evade */
334 if ((Curmonster.m_type == SM_DARKLORD
335 || Curmonster.m_type == SM_SHRIEKER
336 /* can always run from D. L. and shrieker */
337 || drandom() * Player.p_speed * Player.p_brains
338 > drandom() * Curmonster.m_speed * Curmonster.m_brains)
339 && (Curmonster.m_type != SM_MIMIC))
340 /* cannot run from mimic */
342 mvaddstr(Lines++, 0, "You got away!");
344 altercoordinates(0.0, 0.0, A_NEAR);
347 mvprintw(Lines++, 0, "%s is still after you!", Enemyname);
352 case '4': /* magic spell */
357 /* hit 1 plus sword; give some experience */
358 inflict = 1.0 + Player.p_sword;
359 Player.p_experience += floor(Curmonster.m_experience / 10.0);
360 Curmonster.m_experience *= 0.92;
361 /* monster gets meaner */
362 Curmonster.m_maxspeed += 2.0;
363 Curmonster.m_speed = (Curmonster.m_speed < 0.0) ? 0.0 : Curmonster.m_speed + 2.0;
364 if (Curmonster.m_type == SM_DARKLORD)
365 /* Dark Lord; doesn't like to be nicked */
368 "You hit %s %.0f times, and made him mad!", Enemyname, inflict);
369 Player.p_quickness /= 2.0;
370 altercoordinates(0.0, 0.0, A_FAR);
378 case '6': /* luckout */
380 mvaddstr(Lines++, 0, "You already tried that.");
384 if (Curmonster.m_type == SM_MORGOTH)
387 if (drandom() < Player.p_sin / 100.0)
389 mvprintw(Lines++, 0, "%s accepted!", Enemyname);
393 mvaddstr(Lines++, 0, "Nope, he's not interested.");
396 /* normal monster; use brains for success */
398 if ((drandom() + 0.333) * Player.p_brains
399 < (drandom() + 0.333) * Curmonster.m_brains)
400 mvprintw(Lines++, 0, "You blew it, %s.", Player.p_name);
403 mvaddstr(Lines++, 0, "You made it!");
404 Curmonster.m_energy = 0.0;
410 case '7': /* use ring */
411 if (Player.p_ring.ring_type != R_NONE)
413 mvaddstr(Lines++, 0, "Now using ring.");
414 Player.p_ring.ring_inuse = TRUE;
415 if (Player.p_ring.ring_type != R_DLREG)
417 --Player.p_ring.ring_duration;
424 /************************************************************************
426 / FUNCTION NAME: monsthits()
428 / FUNCTION: process a monster hitting the player
430 / AUTHOR: E. A. Estes, 12/4/85
436 / MODULES CALLED: cancelmonster(), scramblestats(), more(), floor(), wmove(),
437 / drandom(), altercoordinates(), longjmp(), waddstr(), mvprintw(),
440 / GLOBAL INPUTS: Curmonster, Lines, Circle, Shield, Player, *stdscr,
441 / Fightenv[], *Enemyname
443 / GLOBAL OUTPUTS: Curmonster, Whichmonster, Lines, Shield, Player,
447 / Handle all special monsters here. If the monster is not a special
448 / one, simply roll a hit against the player.
450 *************************************************************************/
454 double inflict; /* damage inflicted */
457 switch (Curmonster.m_type)
458 /* may be a special monster */
461 /* hits just enough to kill player */
462 inflict = (Player.p_energy + Shield) * 1.02;
466 /* call a big monster */
468 "Shrieeeek!! You scared it, and it called one of its friends.");
470 Whichmonster = (int) ROLL(70.0, 30.0);
471 longjmp(Fightenv, 0);
475 /* take experience away */
476 inflict = ROLL(10.0, Curmonster.m_strength);
477 inflict = MIN(Player.p_experience, inflict);
479 "%s took away %.0f experience points.", Enemyname, inflict);
480 Player.p_experience -= inflict;
484 if (Player.p_holywater > 0)
485 /* holy water kills when monster tries to hit */
487 mvprintw(Lines++, 0, "Your holy water killed it!");
488 --Player.p_holywater;
489 Curmonster.m_energy = 0.0;
503 /* else special things */
504 switch (Curmonster.m_type)
507 /* takes some of the player's strength */
508 inflict = ROLL(1.0, (Circle - 1.0) / 2.0);
509 inflict = MIN(Player.p_strength, inflict);
510 mvprintw(Lines++, 0, "%s sapped %0.f of your strength!",
512 Player.p_strength -= inflict;
513 Player.p_might -= inflict;
517 if (Player.p_palantir)
518 /* take away palantir */
520 mvprintw(Lines++, 0, "Wormtongue stole your palantir!");
521 Player.p_palantir = FALSE;
523 else if (drandom() > 0.5)
524 /* gems turn to gold */
527 "%s transformed your gems into gold!", Enemyname);
528 Player.p_gold += Player.p_gems;
532 /* scramble some stats */
534 mvprintw(Lines++, 0, "%s scrambled your stats!", Enemyname);
540 /* transport player */
541 mvprintw(Lines++, 0, "%s transported you!", Enemyname);
542 altercoordinates(0.0, 0.0, A_FAR);
547 /* suck up some mana */
548 inflict = ROLL(0, 7.5 * Circle);
549 inflict = MIN(Player.p_mana, floor(inflict));
551 "%s sucked up %.0f of your mana!", Enemyname, inflict);
552 Player.p_mana -= inflict;
556 /* try to take ring if player has one */
557 if (Player.p_ring.ring_type != R_NONE)
558 /* player has a ring */
560 mvaddstr(Lines++, 0, "Will you relinguish your ring ? ");
561 ch = getanswer("YN", FALSE);
565 Player.p_ring.ring_type = R_NONE;
566 Player.p_ring.ring_inuse = FALSE;
572 /* otherwise, take some brains */
574 "%s neutralized 1/5 of your brain!", Enemyname);
575 Player.p_brains *= 0.8;
579 /* take some gold and gems */
581 "%s took half your gold and gems and flew off.", Enemyname);
582 Player.p_gold /= 2.0;
583 Player.p_gems /= 2.0;
588 /* steal a gold piece and run */
590 "%s stole one gold piece and ran away.", Enemyname);
591 Player.p_gold = MAX(0.0, Player.p_gold - 1.0);
596 /* bite and (medium) poison */
598 "%s has bitten and poisoned you!", Enemyname);
599 Player.p_poison -= 1.0;
603 /* bite and (small) poison */
604 mvprintw(Lines++, 0, "%s bit and poisoned you!", Enemyname);
605 Player.p_poison += 0.25;
610 mvprintw(Lines++, 0, "%s farted and scampered off.", Enemyname);
611 Player.p_energy /= 2.0; /* damage from fumes */
616 if (Player.p_ring.ring_type != R_NONE)
617 /* try to steal ring */
620 "%s tried to steal your ring, ", Enemyname);
622 addstr("but was unsuccessful.");
625 addstr("and ran away with it!");
626 Player.p_ring.ring_type = R_NONE;
633 /* inflict damage through shield */
634 inflict = ROLL(15.0, Circle * 10.0);
635 inflict = MIN(inflict, Player.p_energy);
636 mvprintw(Lines++, 0, "%s sapped %.0f of your energy.",
638 Player.p_energy -= inflict;
642 /* take all metal treasures */
644 "%s took all your metal treasures!", Enemyname);
653 /* (large) poison and take a quickness */
655 "%s poisoned you, and took one quik.", Enemyname);
656 Player.p_poison += 5.0;
657 Player.p_quickness -= 1.0;
661 /* fly away, and leave either a Jubjub bird or Bonnacon */
663 "%s flew away, and left you to contend with one of its friends.",
665 Whichmonster = 55 + (drandom() > 0.5) ? 22 : 0;
666 longjmp(Fightenv, 0);
670 /* partially regenerate monster */
672 "%s partially regenerated his energy.!", Enemyname);
673 Curmonster.m_energy +=
674 floor((Curmonster.m_o_energy - Curmonster.m_energy) / 2.0);
675 Curmonster.m_strength = Curmonster.m_o_strength;
676 Curmonster.m_melee = Curmonster.m_skirmish = 0.0;
677 Curmonster.m_maxspeed = Curmonster.m_o_speed;
681 if (!Player.p_blindness)
684 mvprintw(Lines++, 0, "%s blinded you!", Enemyname);
685 Player.p_blindness = TRUE;
686 Enemyname = "A monster";
693 /* fall through to here if monster inflicts a normal hit */
694 inflict = drandom() * Curmonster.m_strength + 0.5;
696 mvprintw(Lines++, 0, "%s hit you %.0f times!", Enemyname, inflict);
698 if ((Shield -= inflict) < 0)
700 Player.p_energy += Shield;
705 /************************************************************************
707 / FUNCTION NAME: cancelmonster()
709 / FUNCTION: mark current monster as no longer active
711 / AUTHOR: E. A. Estes, 12/4/85
717 / MODULES CALLED: none
719 / GLOBAL INPUTS: none
721 / GLOBAL OUTPUTS: Curmonster
724 / Clear current monster's energy, experience, treasure type, and
725 / flock. This is the same as having the monster run away.
727 *************************************************************************/
731 Curmonster.m_energy = 0.0;
732 Curmonster.m_experience = 0.0;
733 Curmonster.m_treasuretype = 0;
734 Curmonster.m_flock = 0.0;
737 /************************************************************************
739 / FUNCTION NAME: hitmonster()
741 / FUNCTION: inflict damage upon current monster
743 / AUTHOR: E. A. Estes, 12/4/85
746 / double inflict - damage to inflict upon monster
750 / MODULES CALLED: monsthits(), wmove(), strcmp(), waddstr(), mvprintw()
752 / GLOBAL INPUTS: Curmonster, Lines, Player, *stdscr, *Enemyname
754 / GLOBAL OUTPUTS: Curmonster, Lines
757 / Hit monster specified number of times. Handle when monster dies,
758 / and a few special monsters.
760 *************************************************************************/
765 mvprintw(Lines++, 0, "You hit %s %.0f times!", Enemyname, inflict);
766 Curmonster.m_energy -= inflict;
767 if (Curmonster.m_energy > 0.0)
769 if (Curmonster.m_type == SM_DARKLORD || Curmonster.m_type == SM_SHRIEKER)
770 /* special monster didn't die */
774 /* monster died. print message. */
776 if (Curmonster.m_type == SM_MORGOTH)
777 mvaddstr(Lines++, 0, "You have defeated Morgoth, but he may return. . .");
779 /* all other types of monsters */
781 mvprintw(Lines++, 0, "You killed it. Good work, %s.", Player.p_name);
783 if (Curmonster.m_type == SM_MIMIC
784 && strcmp(Curmonster.m_name, "A Mimic") != 0
785 && !Player.p_blindness)
786 mvaddstr(Lines++, 0, "The body slowly changes into the form of a mimic.");
791 /************************************************************************
793 / FUNCTION NAME: throwspell()
795 / FUNCTION: throw a magic spell
797 / AUTHOR: E. A. Estes, 12/4/85
803 / MODULES CALLED: hitmonster(), cancelmonster(), sqrt(), floor(), wmove(),
804 / drandom(), altercoordinates(), longjmp(), infloat(), waddstr(), mvprintw(),
807 / GLOBAL INPUTS: Curmonster, Whichmonster, Nomana[], Player, *stdscr,
808 / Fightenv[], Illspell[], *Enemyname
810 / GLOBAL OUTPUTS: Curmonster, Whichmonster, Shield, Player
813 / Prompt player and process magic spells.
815 *************************************************************************/
819 double inflict; /* damage inflicted */
820 double dtemp; /* for dtemporary calculations */
823 mvaddstr(7, 0, "\n\n"); /* clear menu area */
825 if (Player.p_magiclvl >= ML_ALLORNOTHING)
826 mvaddstr(7, 0, "1:All or Nothing ");
827 if (Player.p_magiclvl >= ML_MAGICBOLT)
828 addstr("2:Magic Bolt ");
829 if (Player.p_magiclvl >= ML_FORCEFIELD)
830 addstr("3:Force Field ");
831 if (Player.p_magiclvl >= ML_XFORM)
832 addstr("4:Transform ");
833 if (Player.p_magiclvl >= ML_INCRMIGHT)
834 addstr("5:Increase Might\n");
835 if (Player.p_magiclvl >= ML_INVISIBLE)
836 mvaddstr(8, 0, "6:Invisibility ");
837 if (Player.p_magiclvl >= ML_XPORT)
838 addstr("7:Transport ");
839 if (Player.p_magiclvl >= ML_PARALYZE)
840 addstr("8:Paralyze ");
841 if (Player.p_specialtype >= SC_COUNCIL)
843 mvaddstr(4, 0, "Spell ? ");
845 ch = getanswer(" ", TRUE);
847 mvaddstr(7, 0, "\n\n"); /* clear menu area */
849 if (Curmonster.m_type == SM_MORGOTH && ch != '3')
850 /* can only throw force field against Morgoth */
855 case '1': /* all or nothing */
856 if (drandom() < 0.25)
859 inflict = Curmonster.m_energy * 1.01 + 1.0;
861 if (Curmonster.m_type == SM_DARKLORD)
862 /* all or nothing doesn't quite work against D. L. */
866 /* failure -- monster gets stronger and quicker */
868 Curmonster.m_o_strength = Curmonster.m_strength *= 2.0;
869 Curmonster.m_maxspeed *= 2.0;
870 Curmonster.m_o_speed *= 2.0;
872 /* paralyzed monsters wake up a bit */
873 Curmonster.m_speed = MAX(1.0, Curmonster.m_speed * 2.0);
876 if (Player.p_mana >= MM_ALLORNOTHING)
877 /* take a mana if player has one */
878 Player.p_mana -= MM_ALLORNOTHING;
883 case '2': /* magic bolt */
884 if (Player.p_magiclvl < ML_MAGICBOLT)
889 /* prompt for amount to expend */
891 mvaddstr(4, 0, "How much mana for bolt? ");
892 dtemp = floor(infloat());
894 while (dtemp < 0.0 || dtemp > Player.p_mana);
896 Player.p_mana -= dtemp;
898 if (Curmonster.m_type == SM_DARKLORD)
899 /* magic bolts don't work against D. L. */
902 inflict = dtemp * ROLL(15.0, sqrt(Player.p_magiclvl / 3.0 + 1.0));
903 mvaddstr(5, 0, "Magic Bolt fired!\n");
908 case '3': /* force field */
909 if (Player.p_magiclvl < ML_FORCEFIELD)
911 else if (Player.p_mana < MM_FORCEFIELD)
915 Player.p_mana -= MM_FORCEFIELD;
916 Shield = (Player.p_maxenergy + Player.p_shield) * 4.2 + 45.0;
917 mvaddstr(5, 0, "Force Field up.\n");
921 case '4': /* transform */
922 if (Player.p_magiclvl < ML_XFORM)
924 else if (Player.p_mana < MM_XFORM)
928 Player.p_mana -= MM_XFORM;
929 Whichmonster = (int) ROLL(0.0, 100.0);
930 longjmp(Fightenv, 0);
935 case '5': /* increase might */
936 if (Player.p_magiclvl < ML_INCRMIGHT)
938 else if (Player.p_mana < MM_INCRMIGHT)
942 Player.p_mana -= MM_INCRMIGHT;
944 (1.2 * (Player.p_strength + Player.p_sword)
945 + 5.0 - Player.p_might) / 2.0;
946 mvprintw(5, 0, "New strength: %.0f\n", Player.p_might);
950 case '6': /* invisible */
951 if (Player.p_magiclvl < ML_INVISIBLE)
953 else if (Player.p_mana < MM_INVISIBLE)
957 Player.p_mana -= MM_INVISIBLE;
959 (1.2 * (Player.p_quickness + Player.p_quksilver)
960 + 5.0 - Player.p_speed) / 2.0;
961 mvprintw(5, 0, "New quickness: %.0f\n", Player.p_speed);
965 case '7': /* transport */
966 if (Player.p_magiclvl < ML_XPORT)
968 else if (Player.p_mana < MM_XPORT)
972 Player.p_mana -= MM_XPORT;
973 if (Player.p_brains + Player.p_magiclvl
974 < Curmonster.m_experience / 200.0 * drandom())
976 mvaddstr(5, 0, "Transport backfired!\n");
977 altercoordinates(0.0, 0.0, A_FAR);
982 mvprintw(5, 0, "%s is transported.\n", Enemyname);
984 /* monster didn't drop its treasure */
985 Curmonster.m_treasuretype = 0;
987 Curmonster.m_energy = 0.0;
992 case '8': /* paralyze */
993 if (Player.p_magiclvl < ML_PARALYZE)
995 else if (Player.p_mana < MM_PARALYZE)
999 Player.p_mana -= MM_PARALYZE;
1000 if (Player.p_magiclvl >
1001 Curmonster.m_experience / 1000.0 * drandom())
1003 mvprintw(5, 0, "%s is held.\n", Enemyname);
1004 Curmonster.m_speed = -2.0;
1007 mvaddstr(5, 0, "Monster unaffected.\n");
1011 case '9': /* specify */
1012 if (Player.p_specialtype < SC_COUNCIL)
1014 else if (Player.p_mana < MM_SPECIFY)
1018 Player.p_mana -= MM_SPECIFY;
1019 mvaddstr(5, 0, "Which monster do you want [0-99] ? ");
1020 Whichmonster = (int) infloat();
1021 Whichmonster = MAX(0, MIN(99, Whichmonster));
1022 longjmp(Fightenv, 0);
1029 /************************************************************************
1031 / FUNCTION NAME: callmonster()
1033 / FUNCTION: read monster from file, and fill structure
1035 / AUTHOR: E. A. Estes, 2/25/86
1038 / int which - which monster to call
1040 / RETURN VALUE: none
1042 / MODULES CALLED: truncstring(), fread(), fseek(), floor(), drandom(),
1045 / GLOBAL INPUTS: Curmonster, Circle, Player, *Monstfp
1047 / GLOBAL OUTPUTS: Curmonster, Player, *Enemyname
1050 / Read specified monster from monster database and fill up
1051 / current monster structure.
1052 / Adjust statistics based upon current size.
1053 / Handle some special monsters.
1055 *************************************************************************/
1060 struct monster Othermonster; /* to find a name for mimics */
1062 which = MIN(which, 99); /* make sure within range */
1064 /* fill structure */
1065 fseek(Monstfp, (long) which * (long) SZ_MONSTERSTRUCT, 0);
1066 fread((char *) &Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp);
1068 /* handle some special monsters */
1069 if (Curmonster.m_type == SM_MODNAR)
1071 if (Player.p_specialtype < SC_COUNCIL)
1072 /* randomize some stats */
1074 Curmonster.m_strength *= drandom() + 0.5;
1075 Curmonster.m_brains *= drandom() + 0.5;
1076 Curmonster.m_speed *= drandom() + 0.5;
1077 Curmonster.m_energy *= drandom() + 0.5;
1078 Curmonster.m_experience *= drandom() + 0.5;
1079 Curmonster.m_treasuretype =
1080 (int) ROLL(0.0, (double) Curmonster.m_treasuretype);
1083 /* make Modnar into Morgoth */
1085 strcpy(Curmonster.m_name, "Morgoth");
1086 Curmonster.m_strength = drandom() * (Player.p_maxenergy + Player.p_shield) / 1.4
1087 + drandom() * (Player.p_maxenergy + Player.p_shield) / 1.5;
1088 Curmonster.m_brains = Player.p_brains;
1089 Curmonster.m_energy = Player.p_might * 30.0;
1090 Curmonster.m_type = SM_MORGOTH;
1091 Curmonster.m_speed = Player.p_speed * 1.1
1092 + (Player.p_specialtype == SC_EXVALAR) ? Player.p_speed : 0.0;
1093 Curmonster.m_flock = 0.0;
1094 Curmonster.m_treasuretype = 0;
1095 Curmonster.m_experience = 0.0;
1098 else if (Curmonster.m_type == SM_MIMIC)
1099 /* pick another name */
1101 which = (int) ROLL(0.0, 100.0);
1102 fseek(Monstfp, (long) which * (long) SZ_MONSTERSTRUCT, 0);
1103 fread(&Othermonster, SZ_MONSTERSTRUCT, 1, Monstfp);
1104 strcpy(Curmonster.m_name, Othermonster.m_name);
1107 truncstring(Curmonster.m_name);
1109 if (Curmonster.m_type != SM_MORGOTH)
1110 /* adjust stats based on which circle player is in */
1112 Curmonster.m_strength *= (1.0 + Circle / 2.0);
1113 Curmonster.m_brains *= Circle;
1114 Curmonster.m_speed += Circle * 1.e-9;
1115 Curmonster.m_energy *= Circle;
1116 Curmonster.m_experience *= Circle;
1119 if (Player.p_blindness)
1120 /* cannot see monster if blind */
1121 Enemyname = "A monster";
1123 Enemyname = Curmonster.m_name;
1125 if (Player.p_speed <= 0.0)
1126 /* make Player.p_speed positive */
1128 Curmonster.m_speed += -Player.p_speed;
1129 Player.p_speed = 1.0;
1132 /* fill up the rest of the structure */
1133 Curmonster.m_o_strength = Curmonster.m_strength;
1134 Curmonster.m_o_speed = Curmonster.m_maxspeed = Curmonster.m_speed;
1135 Curmonster.m_o_energy = Curmonster.m_energy;
1136 Curmonster.m_melee = Curmonster.m_skirmish = 0.0;
1139 /************************************************************************
1141 / FUNCTION NAME: awardtreasure()
1143 / FUNCTION: select a treasure
1145 / AUTHOR: E. A. Estes, 12/4/85
1149 / RETURN VALUE: none
1151 / MODULES CALLED: pickmonster(), collecttaxes(), more(), cursedtreasure(),
1152 / floor(), wmove(), drandom(), sscanf(), printw(), altercoordinates(),
1153 / longjmp(), infloat(), waddstr(), getanswer(), getstring(), wclrtobot()
1155 / GLOBAL INPUTS: Somebetter[], Curmonster, Whichmonster, Circle, Player,
1156 / *stdscr, Databuf[], *Statptr, Fightenv[]
1158 / GLOBAL OUTPUTS: Whichmonster, Shield, Player
1161 / Roll up a treasure based upon monster type and size, and
1162 / certain player statistics.
1163 / Handle cursed treasure.
1165 *************************************************************************/
1169 int whichtreasure; /* calculated treasure to grant */
1170 int temp; /* temporary */
1172 double treasuretype; /* monster's treasure type */
1173 double gold = 0.0; /* gold awarded */
1174 double gems = 0.0; /* gems awarded */
1175 double dtemp; /* for temporary calculations */
1177 whichtreasure = (int) ROLL(1.0, 3.0); /* pick a treasure */
1178 treasuretype = (double) Curmonster.m_treasuretype;
1184 if (drandom() > 0.65)
1187 if (Curmonster.m_treasuretype > 7)
1190 gems = ROLL(1.0, (treasuretype - 7.0)
1191 * (treasuretype - 7.0) * (Circle - 1.0) / 4.0);
1192 printw("You have discovered %.0f gems!", gems);
1197 gold = ROLL(treasuretype * 10.0, treasuretype
1198 * treasuretype * 10.0 * (Circle - 1.0));
1199 printw("You have found %.0f gold pieces.", gold);
1202 addstr(" Do you want to pick them up ? ");
1203 ch = getanswer("NY", FALSE);
1207 if (drandom() < treasuretype / 35.0 + 0.04)
1210 addstr("They were cursed!\n");
1214 collecttaxes(gold, gems);
1220 /* other treasures */
1222 addstr("You have found some treasure. Do you want to inspect it ? ");
1223 ch = getanswer("NY", FALSE);
1229 if (drandom() < 0.08 && Curmonster.m_treasuretype != 4)
1231 addstr("It was cursed!\n");
1236 switch (Curmonster.m_treasuretype)
1238 case 1: /* treasure type 1 */
1239 switch (whichtreasure)
1242 addstr("You've discovered a power booster!\n");
1243 Player.p_mana += ROLL(Circle * 4.0, Circle * 30.0);
1247 addstr("You have encountered a druid.\n");
1248 Player.p_experience +=
1249 ROLL(0.0, 2000.0 + Circle * 400.0);
1253 addstr("You have found a holy orb.\n");
1254 Player.p_sin = MAX(0.0, Player.p_sin - 0.25);
1258 /* end treasure type 1 */
1260 case 2: /* treasure type 2 */
1261 switch (whichtreasure)
1264 addstr("You have found an amulet.\n");
1269 addstr("You've found some holy water!\n");
1270 ++Player.p_holywater;
1274 addstr("You've met a hermit!\n");
1275 Player.p_sin *= 0.75;
1276 Player.p_mana += 12.0 * Circle;
1280 /* end treasure type 2 */
1282 case 3: /* treasure type 3 */
1283 switch (whichtreasure)
1286 dtemp = ROLL(7.0, 30.0 + Circle / 10.0);
1287 printw("You've found a +%.0f shield!\n", dtemp);
1288 if (dtemp >= Player.p_shield)
1289 Player.p_shield = dtemp;
1295 addstr("You have rescued a virgin. Will you be honorable ? ");
1296 ch = getanswer("NY", FALSE);
1299 Player.p_virgin = TRUE;
1302 Player.p_experience += 2000.0 * Circle;
1308 addstr("You've discovered some athelas!\n");
1313 /* end treasure type 3 */
1315 case 4: /* treasure type 4 */
1316 addstr("You've found a scroll. Will you read it ? ");
1317 ch = getanswer("NY", FALSE);
1321 switch ((int) ROLL(1, 6))
1324 addstr("It throws up a shield for you next monster.\n");
1325 getyx(stdscr, whichtreasure, ch);
1326 more(whichtreasure);
1328 (Player.p_maxenergy + Player.p_energy) * 5.5 + Circle * 50.0;
1329 Whichmonster = pickmonster();
1330 longjmp(Fightenv, 0);
1334 addstr("It makes you invisible for you next monster.\n");
1335 getyx(stdscr, whichtreasure, ch);
1336 more(whichtreasure);
1337 Player.p_speed = 1e6;
1338 Whichmonster = pickmonster();
1339 longjmp(Fightenv, 0);
1343 addstr("It increases your strength ten fold to fight your next monster.\n");
1344 getyx(stdscr, whichtreasure, ch);
1345 more(whichtreasure);
1346 Player.p_might *= 10.0;
1347 Whichmonster = pickmonster();
1348 longjmp(Fightenv, 0);
1352 addstr("It is a general knowledge scroll.\n");
1353 Player.p_brains += ROLL(2.0, Circle);
1354 Player.p_magiclvl += ROLL(1.0, Circle / 2.0);
1358 addstr("It tells you how to pick your next monster.\n");
1359 addstr("Which monster do you want [0-99] ? ");
1360 Whichmonster = (int) infloat();
1361 Whichmonster = MIN(99, MAX(0, Whichmonster));
1362 longjmp(Fightenv, 0);
1365 addstr("It was cursed!\n");
1370 /* end treasure type 4 */
1372 case 5: /* treasure type 5 */
1373 switch (whichtreasure)
1376 dtemp = ROLL(Circle / 4.0 + 5.0, Circle / 2.0 + 9.0);
1377 printw("You've discovered a +%.0f dagger.\n", dtemp);
1378 if (dtemp >= Player.p_sword)
1379 Player.p_sword = dtemp;
1385 dtemp = ROLL(7.5 + Circle * 3.0, Circle * 2.0 + 160.0);
1386 printw("You have found some +%.0f armour!\n", dtemp);
1387 if (dtemp >= Player.p_shield)
1388 Player.p_shield = dtemp;
1394 addstr("You've found a tablet.\n");
1395 Player.p_brains += 4.5 * Circle;
1399 /* end treasure type 5 */
1401 case 6: /* treasure type 6 */
1402 switch (whichtreasure)
1405 addstr("You've found a priest.\n");
1406 Player.p_energy = Player.p_maxenergy + Player.p_shield;
1407 Player.p_sin /= 2.0;
1408 Player.p_mana += 24.0 * Circle;
1409 Player.p_brains += Circle;
1413 addstr("You have come upon Robin Hood!\n");
1414 Player.p_shield += Circle * 2.0;
1415 Player.p_strength += Circle / 2.5 + 1.0;
1419 dtemp = ROLL(2.0 + Circle / 4.0, Circle / 1.2 + 10.0);
1420 printw("You have found a +%.0f axe!\n", dtemp);
1421 if (dtemp >= Player.p_sword)
1422 Player.p_sword = dtemp;
1428 /* end treasure type 6 */
1430 case 7: /* treasure type 7 */
1431 switch (whichtreasure)
1434 addstr("You've discovered a charm!\n");
1439 addstr("You have encountered Merlyn!\n");
1440 Player.p_brains += Circle + 5.0;
1441 Player.p_magiclvl += Circle / 3.0 + 5.0;
1442 Player.p_mana += Circle * 10.0;
1446 dtemp = ROLL(5.0 + Circle / 3.0, Circle / 1.5 + 20.0);
1447 printw("You have found a +%.0f war hammer!\n", dtemp);
1448 if (dtemp >= Player.p_sword)
1449 Player.p_sword = dtemp;
1455 /* end treasure type 7 */
1457 case 8: /* treasure type 8 */
1458 switch (whichtreasure)
1461 addstr("You have found a healing potion.\n");
1462 Player.p_poison = MIN(-2.0, Player.p_poison - 2.0);
1466 addstr("You have discovered a transporter. Do you wish to go anywhere ? ");
1467 ch = getanswer("NY", FALSE);
1473 addstr("X Y Coordinates ? ");
1474 getstring(Databuf, SZ_DATABUF);
1475 sscanf(Databuf, "%lf %lf", &x, &y);
1476 altercoordinates(x, y, A_FORCED);
1481 dtemp = ROLL(10.0 + Circle / 1.2, Circle * 3.0 + 30.0);
1482 printw("You've found a +%.0f sword!\n", dtemp);
1483 if (dtemp >= Player.p_sword)
1484 Player.p_sword = dtemp;
1490 /* end treasure type 8 */
1495 case 13: /* treasure types 10 - 13 */
1496 if (drandom() < 0.33)
1498 if (Curmonster.m_treasuretype == 10)
1500 addstr("You've found a pair of elven boots!\n");
1501 Player.p_quickness += 2.0;
1504 else if (Curmonster.m_treasuretype == 11
1505 && !Player.p_palantir)
1507 addstr("You've acquired Saruman's palantir.\n");
1508 Player.p_palantir = TRUE;
1511 else if (Player.p_ring.ring_type == R_NONE
1512 && Player.p_specialtype < SC_COUNCIL
1513 && (Curmonster.m_treasuretype == 12
1514 || Curmonster.m_treasuretype == 13))
1515 /* roll up a ring */
1517 if (drandom() < 0.8)
1520 if (Curmonster.m_treasuretype == 12)
1522 whichtreasure = R_NAZREG;
1527 whichtreasure = R_DLREG;
1534 whichtreasure = R_BAD;
1535 temp = 15 + Statptr->c_ringduration + (int) ROLL(0,5);
1538 addstr("You've discovered a ring. Will you pick it up ? ");
1539 ch = getanswer("NY", FALSE);
1544 Player.p_ring.ring_type = whichtreasure;
1545 Player.p_ring.ring_duration = temp;
1551 /* end treasure types 10 - 13 */
1552 /* fall through to treasure type 9 if no treasure from above */
1554 case 9: /* treasure type 9 */
1555 switch (whichtreasure)
1558 if (Player.p_level <= 1000.0
1559 && Player.p_crowns <= 3
1560 && Player.p_level >= 10.0)
1562 addstr("You have found a golden crown!\n");
1566 /* fall through otherwise */
1569 addstr("You've been blessed!\n");
1570 Player.p_blessing = TRUE;
1571 Player.p_sin /= 3.0;
1572 Player.p_energy = Player.p_maxenergy + Player.p_shield;
1573 Player.p_mana += 100.0 * Circle;
1577 dtemp = ROLL(1.0, Circle / 5.0 + 5.0);
1578 dtemp = MIN(dtemp, 99.0);
1579 printw("You have discovered some +%.0f quicksilver!\n",dtemp);
1580 if (dtemp >= Player.p_quksilver)
1581 Player.p_quksilver = dtemp;
1587 /* end treasure type 9 */
1592 /************************************************************************
1594 / FUNCTION NAME: cursedtreasure()
1596 / FUNCTION: take care of cursed treasure
1598 / AUTHOR: E. A. Estes, 12/4/85
1602 / RETURN VALUE: none
1604 / MODULES CALLED: waddstr()
1606 / GLOBAL INPUTS: Player, *stdscr
1608 / GLOBAL OUTPUTS: Player
1611 / Handle cursed treasure. Look for amulets and charms to save
1612 / the player from the curse.
1614 *************************************************************************/
1618 if (Player.p_charms > 0)
1620 addstr("But your charm saved you!\n");
1623 else if (Player.p_amulets > 0)
1625 addstr("But your amulet saved you!\n");
1630 Player.p_energy = (Player.p_maxenergy + Player.p_shield) / 10.0;
1631 Player.p_poison += 0.25;
1635 /************************************************************************
1637 / FUNCTION NAME: scramblestats()
1639 / FUNCTION: scramble some selected statistics
1641 / AUTHOR: E. A. Estes, 12/4/85
1645 / RETURN VALUE: none
1647 / MODULES CALLED: floor(), drandom()
1649 / GLOBAL INPUTS: Player
1651 / GLOBAL OUTPUTS: Player
1654 / Swap a few player statistics randomly.
1656 *************************************************************************/
1660 double dbuf[6]; /* to put statistic in */
1661 double dtemp1, dtemp2; /* for swapping values */
1662 int first, second; /* indices for swapping */
1663 double *dptr; /* pointer for filling and emptying buf[] */
1667 *dptr++ = Player.p_strength;
1668 *dptr++ = Player.p_mana;
1669 *dptr++ = Player.p_brains;
1670 *dptr++ = Player.p_magiclvl;
1671 *dptr++ = Player.p_energy;
1672 *dptr = Player.p_sin;
1674 /* pick values to swap */
1675 first = (int) ROLL(0, 5);
1676 second = (int) ROLL(0, 5);
1680 dtemp1 = dptr[first];
1681 /* this expression is split to prevent a compiler loop on some compilers */
1682 dtemp2 = dptr[second];
1683 dptr[first] = dtemp2;
1684 dptr[second] = dtemp1;
1687 Player.p_strength = *dptr++;
1688 Player.p_mana = *dptr++;
1689 Player.p_brains = *dptr++;
1690 Player.p_magiclvl = *dptr++;
1691 Player.p_energy = *dptr++;
1692 Player.p_sin = *dptr;