]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - phantasia/fight.c
1 /* $NetBSD: fight.c,v 1.11 2009/05/25 23:08:45 dholland Exp $ */
4 * fight.c Phantasia monster fighting routines
12 encounter(int particular
)
14 volatile bool firsthit
= Player
.p_blessing
; /* set if player gets
16 volatile int flockcnt
= 1; /* how many time flocked */
18 /* let others know what we are doing */
19 Player
.p_status
= S_MONSTER
;
20 writerecord(&Player
, Fileloc
);
26 Shield
= 0.0; /* no shield up yet */
29 /* monster is specified */
30 Whichmonster
= particular
;
32 /* pick random monster */
33 Whichmonster
= pickmonster();
35 setjmp(Fightenv
); /* this is to enable changing fight state */
38 clrtobot(); /* clear bottom area of screen */
41 callmonster(Whichmonster
); /* set up monster to fight */
43 Luckout
= FALSE
; /* haven't tried to luckout yet */
45 if (Curmonster
.m_type
== SM_MORGOTH
)
46 mvprintw(4, 0, "You've encountered %s, Bane of the Council and Valar.\n",
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
;
54 printw("You just saw %s running away!\n", Enemyname
);
55 Curmonster
.m_experience
= 0.0;
56 Curmonster
.m_treasuretype
= 0;
59 /* not a special monster */
61 /* print header, and arbitrate between player and
64 mvprintw(6, 0, "You are being attacked by %s, EXP: %.0f (Size: %.0f)\n",
65 Enemyname
, Curmonster
.m_experience
, Circle
);
68 mvprintw(1, 26, "%20.0f", Player
.p_energy
+ Shield
); /* overprint energy */
71 if (Curmonster
.m_type
== SM_DARKLORD
73 && Player
.p_charms
> 0)
74 /* overpower Dark Lord with blessing and charm */
76 mvprintw(7, 0, "You just overpowered %s!", Enemyname
);
78 Player
.p_blessing
= FALSE
;
82 /* allow paralyzed monster to wake up */
83 Curmonster
.m_speed
= MIN(Curmonster
.m_speed
+ 1.0, Curmonster
.m_maxspeed
);
85 if (drandom() * Curmonster
.m_speed
> drandom() * Player
.p_speed
86 /* monster is faster */
87 && Curmonster
.m_type
!= SM_DARKLORD
89 && Curmonster
.m_type
!= SM_SHRIEKER
92 /* monster gets a hit */
95 /* player gets a hit */
103 if (Lines
> LINES
- 2)
104 /* near bottom of screen - pause */
110 if (Player
.p_energy
<= 0.0)
116 break; /* fight ends if the player is saved
119 if (Curmonster
.m_energy
<= 0.0)
124 /* give player credit for killing monster */
125 Player
.p_experience
+= Curmonster
.m_experience
;
127 if (drandom() < Curmonster
.m_flock
/ 100.0)
132 longjmp(Fightenv
, 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 */
144 /* pause before returning */
145 getyx(stdscr
, Lines
, flockcnt
);
148 Player
.p_ring
.ring_inuse
= FALSE
; /* not using ring */
150 /* clean up the screen */
158 if (Player
.p_specialtype
== SC_VALAR
)
159 /* even chance of any monster */
160 return ((int) ROLL(0.0, 100.0));
164 return ((int) ROLL(0.0, 15.0));
168 /* even chance of all non-water monsters */
169 return ((int) ROLL(14.0, 86.0));
173 /* chance of all non-water monsters, weighted
175 return ((int) (ROLL(0.0, 50.0) + ROLL(14.0, 37.0)));
179 /* not all non-water monsters,
180 * weighted toward middle */
181 return ((int) (ROLL(0.0, 50.0) + ROLL(14.0, 26.0)));
185 /* even chance of some tamer
186 * non-water monsters */
187 return ((int) ROLL(14.0, 50.0));
190 /* even chance of some of the
191 * tamest non-water monsters */
192 return ((int) ROLL(14.0, 25.0));
198 double inflict
; /* damage inflicted */
201 mvaddstr(7, 0, "1:Melee 2:Skirmish 3:Evade 4:Spell 5:Nick ");
204 /* haven't tried to luckout yet */
205 if (Curmonster
.m_type
== SM_MORGOTH
)
206 /* cannot luckout against Morgoth */
209 addstr("6:Luckout ");
212 if (Player
.p_ring
.ring_type
!= R_NONE
)
213 /* player has a ring */
214 addstr("7:Use Ring ");
221 clrtobot(); /* clear any messages from before */
223 mvaddstr(4, 0, "\n\n"); /* clear status area */
226 case 'T': /* timeout; lose turn */
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);
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;
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);
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;
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 */
264 mvaddstr(Lines
++, 0, "You got away!");
266 altercoordinates(0.0, 0.0, A_NEAR
);
268 mvprintw(Lines
++, 0, "%s is still after you!", Enemyname
);
273 case '4': /* magic spell */
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 */
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
);
298 case '6': /* luckout */
300 mvaddstr(Lines
++, 0, "You already tried that.");
303 if (Curmonster
.m_type
== SM_MORGOTH
)
306 if (drandom() < Player
.p_sin
/ 100.0) {
307 mvprintw(Lines
++, 0, "%s accepted!", Enemyname
);
310 mvaddstr(Lines
++, 0, "Nope, he's not interested.");
312 /* normal monster; use brains for success */
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
);
318 mvaddstr(Lines
++, 0, "You made it!");
319 Curmonster
.m_energy
= 0.0;
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
)
331 --Player
.p_ring
.ring_duration
;
341 double inflict
; /* damage inflicted */
344 switch (Curmonster
.m_type
)
345 /* may be a special monster */
348 /* hits just enough to kill player */
349 inflict
= (Player
.p_energy
+ Shield
) * 1.02;
353 /* call a big monster */
355 "Shrieeeek!! You scared it, and it called one of its friends.");
357 Whichmonster
= (int) ROLL(70.0, 30.0);
358 longjmp(Fightenv
, 0);
362 /* take experience away */
363 inflict
= ROLL(10.0, Curmonster
.m_strength
);
364 inflict
= MIN(Player
.p_experience
, inflict
);
366 "%s took away %.0f experience points.", Enemyname
, inflict
);
367 Player
.p_experience
-= inflict
;
371 if (Player
.p_holywater
> 0)
372 /* holy water kills when monster tries to hit */
374 mvprintw(Lines
++, 0, "Your holy water killed it!");
375 --Player
.p_holywater
;
376 Curmonster
.m_energy
= 0.0;
390 /* else special things */
391 switch (Curmonster
.m_type
) {
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!",
398 Player
.p_strength
-= inflict
;
399 Player
.p_might
-= inflict
;
403 if (Player
.p_palantir
)
404 /* take away palantir */
406 mvprintw(Lines
++, 0, "Wormtongue stole your palantir!");
407 Player
.p_palantir
= FALSE
;
410 /* gems turn to gold */
413 "%s transformed your gems into gold!", Enemyname
);
414 Player
.p_gold
+= Player
.p_gems
;
417 /* scramble some stats */
419 mvprintw(Lines
++, 0, "%s scrambled your stats!", Enemyname
);
425 /* transport player */
426 mvprintw(Lines
++, 0, "%s transported you!", Enemyname
);
427 altercoordinates(0.0, 0.0, A_FAR
);
432 /* suck up some mana */
433 inflict
= ROLL(0, 7.5 * Circle
);
434 inflict
= MIN(Player
.p_mana
, floor(inflict
));
436 "%s sucked up %.0f of your mana!", Enemyname
, inflict
);
437 Player
.p_mana
-= inflict
;
441 /* try to take ring if player has one */
442 if (Player
.p_ring
.ring_type
!= R_NONE
)
443 /* player has a ring */
445 mvaddstr(Lines
++, 0, "Will you relinguish your ring ? ");
446 ch
= getanswer("YN", FALSE
);
450 Player
.p_ring
.ring_type
= R_NONE
;
451 Player
.p_ring
.ring_inuse
= FALSE
;
456 /* otherwise, take some brains */
458 "%s neutralized 1/5 of your brain!", Enemyname
);
459 Player
.p_brains
*= 0.8;
463 /* take some gold and gems */
465 "%s took half your gold and gems and flew off.", Enemyname
);
466 Player
.p_gold
/= 2.0;
467 Player
.p_gems
/= 2.0;
472 /* steal a gold piece and run */
474 "%s stole one gold piece and ran away.", Enemyname
);
475 Player
.p_gold
= MAX(0.0, Player
.p_gold
- 1.0);
480 /* bite and (medium) poison */
482 "%s has bitten and poisoned you!", Enemyname
);
483 Player
.p_poison
-= 1.0;
487 /* bite and (small) poison */
488 mvprintw(Lines
++, 0, "%s bit and poisoned you!", Enemyname
);
489 Player
.p_poison
+= 0.25;
494 mvprintw(Lines
++, 0, "%s farted and scampered off.", Enemyname
);
495 Player
.p_energy
/= 2.0; /* damage from fumes */
500 if (Player
.p_ring
.ring_type
!= R_NONE
)
501 /* try to steal ring */
504 "%s tried to steal your ring, ", Enemyname
);
506 addstr("but was unsuccessful.");
508 addstr("and ran away with it!");
509 Player
.p_ring
.ring_type
= R_NONE
;
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.",
521 Player
.p_energy
-= inflict
;
525 /* take all metal treasures */
527 "%s took all your metal treasures!", Enemyname
);
536 /* (large) poison and take a quickness */
538 "%s poisoned you, and took one quik.", Enemyname
);
539 Player
.p_poison
+= 5.0;
540 Player
.p_quickness
-= 1.0;
544 /* fly away, and leave either a Jubjub bird or
547 "%s flew away, and left you to contend with one of its friends.",
549 Whichmonster
= 55 + ((drandom() > 0.5) ? 22 : 0);
550 longjmp(Fightenv
, 0);
554 /* partially regenerate monster */
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
;
565 if (!Player
.p_blindness
)
568 mvprintw(Lines
++, 0, "%s blinded you!", Enemyname
);
569 Player
.p_blindness
= TRUE
;
570 Enemyname
= "A monster";
577 /* fall through to here if monster inflicts a normal hit */
578 inflict
= drandom() * Curmonster
.m_strength
+ 0.5;
580 mvprintw(Lines
++, 0, "%s hit you %.0f times!", Enemyname
, inflict
);
582 if ((Shield
-= inflict
) < 0) {
583 Player
.p_energy
+= Shield
;
591 Curmonster
.m_energy
= 0.0;
592 Curmonster
.m_experience
= 0.0;
593 Curmonster
.m_treasuretype
= 0;
594 Curmonster
.m_flock
= 0.0;
598 hitmonster(double inflict
)
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 */
607 /* monster died. print message. */
609 if (Curmonster
.m_type
== SM_MORGOTH
)
610 mvaddstr(Lines
++, 0, "You have defeated Morgoth, but he may return. . .");
612 /* all other types of monsters */
614 mvprintw(Lines
++, 0, "You killed it. Good work, %s.", Player
.p_name
);
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.");
627 double inflict
; /* damage inflicted */
628 double dtemp
; /* for dtemporary calculations */
632 mvaddstr(7, 0, "\n\n"); /* clear menu area */
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
)
652 mvaddstr(4, 0, "Spell ? ");
654 ch
= getanswer(" ", TRUE
);
656 mvaddstr(7, 0, "\n\n"); /* clear menu area */
658 if (Curmonster
.m_type
== SM_MORGOTH
&& ch
!= '3')
659 /* can only throw force field against Morgoth */
663 case '1': /* all or nothing */
664 if (drandom() < 0.25)
667 inflict
= Curmonster
.m_energy
* 1.01 + 1.0;
669 if (Curmonster
.m_type
== SM_DARKLORD
)
670 /* all or nothing doesn't quite work
674 /* failure -- monster gets stronger and
677 Curmonster
.m_o_strength
= Curmonster
.m_strength
*= 2.0;
678 Curmonster
.m_maxspeed
*= 2.0;
679 Curmonster
.m_o_speed
*= 2.0;
681 /* paralyzed monsters wake up a bit */
682 Curmonster
.m_speed
= MAX(1.0, Curmonster
.m_speed
* 2.0);
685 if (Player
.p_mana
>= MM_ALLORNOTHING
)
686 /* take a mana if player has one */
687 Player
.p_mana
-= MM_ALLORNOTHING
;
692 case '2': /* magic bolt */
693 if (Player
.p_magiclvl
< ML_MAGICBOLT
)
697 /* prompt for amount to expend */
699 mvaddstr(4, 0, "How much mana for bolt? ");
700 dtemp
= floor(infloat());
702 while (dtemp
< 0.0 || dtemp
> Player
.p_mana
);
704 Player
.p_mana
-= dtemp
;
706 if (Curmonster
.m_type
== SM_DARKLORD
)
707 /* magic bolts don't work against D.
711 inflict
= dtemp
* ROLL(15.0, sqrt(Player
.p_magiclvl
/ 3.0 + 1.0));
712 mvaddstr(5, 0, "Magic Bolt fired!\n");
717 case '3': /* force field */
718 if (Player
.p_magiclvl
< ML_FORCEFIELD
)
721 if (Player
.p_mana
< MM_FORCEFIELD
)
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");
730 case '4': /* transform */
731 if (Player
.p_magiclvl
< ML_XFORM
)
734 if (Player
.p_mana
< MM_XFORM
)
737 Player
.p_mana
-= MM_XFORM
;
738 Whichmonster
= (int) ROLL(0.0, 100.0);
739 longjmp(Fightenv
, 0);
744 case '5': /* increase might */
745 if (Player
.p_magiclvl
< ML_INCRMIGHT
)
748 if (Player
.p_mana
< MM_INCRMIGHT
)
751 Player
.p_mana
-= MM_INCRMIGHT
;
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
);
759 case '6': /* invisible */
760 if (Player
.p_magiclvl
< ML_INVISIBLE
)
763 if (Player
.p_mana
< MM_INVISIBLE
)
766 Player
.p_mana
-= MM_INVISIBLE
;
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
);
774 case '7': /* transport */
775 if (Player
.p_magiclvl
< ML_XPORT
)
778 if (Player
.p_mana
< MM_XPORT
)
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
);
788 mvprintw(5, 0, "%s is transported.\n", Enemyname
);
790 /* monster didn't drop
792 Curmonster
.m_treasuretype
= 0;
794 Curmonster
.m_energy
= 0.0;
799 case '8': /* paralyze */
800 if (Player
.p_magiclvl
< ML_PARALYZE
)
803 if (Player
.p_mana
< MM_PARALYZE
)
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;
812 mvaddstr(5, 0, "Monster unaffected.\n");
816 case '9': /* specify */
817 if (Player
.p_specialtype
< SC_COUNCIL
)
820 if (Player
.p_mana
< MM_SPECIFY
)
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);
835 callmonster(int which
)
837 struct monster Othermonster
; /* to find a name for mimics */
839 which
= MIN(which
, 99); /* make sure within range */
842 fseek(Monstfp
, (long) which
* (long) SZ_MONSTERSTRUCT
, SEEK_SET
);
843 fread((char *) &Curmonster
, SZ_MONSTERSTRUCT
, 1, Monstfp
);
845 /* handle some special monsters */
846 if (Curmonster
.m_type
== SM_MODNAR
) {
847 if (Player
.p_specialtype
< SC_COUNCIL
)
848 /* randomize some stats */
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
);
858 /* make Modnar into Morgoth */
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;
873 if (Curmonster
.m_type
== SM_MIMIC
)
874 /* pick another name */
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
);
881 truncstring(Curmonster
.m_name
);
883 if (Curmonster
.m_type
!= SM_MORGOTH
)
884 /* adjust stats based on which circle player is in */
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
;
892 if (Player
.p_blindness
)
893 /* cannot see monster if blind */
894 Enemyname
= "A monster";
896 Enemyname
= Curmonster
.m_name
;
898 if (Player
.p_speed
<= 0.0)
899 /* make Player.p_speed positive */
901 Curmonster
.m_speed
+= -Player
.p_speed
;
902 Player
.p_speed
= 1.0;
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;
914 int whichtreasure
; /* calculated treasure to grant */
915 int temp
; /* temporary */
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 */
922 whichtreasure
= (int) ROLL(1.0, 3.0); /* pick a treasure */
923 treasuretype
= (double) Curmonster
.m_treasuretype
;
929 if (drandom() > 0.65)
932 if (Curmonster
.m_treasuretype
> 7)
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
);
941 gold
= ROLL(treasuretype
* 10.0, treasuretype
942 * treasuretype
* 10.0 * (Circle
- 1.0));
943 printw("You have found %.0f gold pieces.", gold
);
946 addstr(" Do you want to pick them up ? ");
947 ch
= getanswer("NY", FALSE
);
951 if (drandom() < treasuretype
/ 35.0 + 0.04)
954 addstr("They were cursed!\n");
957 collecttaxes(gold
, gems
);
962 /* other treasures */
964 addstr("You have found some treasure. Do you want to inspect it ? ");
965 ch
= getanswer("NY", FALSE
);
971 if (drandom() < 0.08 && Curmonster
.m_treasuretype
!= 4) {
972 addstr("It was cursed!\n");
976 switch (Curmonster
.m_treasuretype
) {
977 case 1: /* treasure type 1 */
978 switch (whichtreasure
) {
980 addstr("You've discovered a power booster!\n");
981 Player
.p_mana
+= ROLL(Circle
* 4.0, Circle
* 30.0);
985 addstr("You have encountered a druid.\n");
986 Player
.p_experience
+=
987 ROLL(0.0, 2000.0 + Circle
* 400.0);
991 addstr("You have found a holy orb.\n");
992 Player
.p_sin
= MAX(0.0, Player
.p_sin
- 0.25);
996 /* end treasure type 1 */
998 case 2: /* treasure type 2 */
999 switch (whichtreasure
) {
1001 addstr("You have found an amulet.\n");
1006 addstr("You've found some holy water!\n");
1007 ++Player
.p_holywater
;
1011 addstr("You've met a hermit!\n");
1012 Player
.p_sin
*= 0.75;
1013 Player
.p_mana
+= 12.0 * Circle
;
1017 /* end treasure type 2 */
1019 case 3: /* treasure type 3 */
1020 switch (whichtreasure
) {
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
;
1031 addstr("You have rescued a virgin. Will you be honorable ? ");
1032 ch
= getanswer("NY", FALSE
);
1035 Player
.p_virgin
= TRUE
;
1037 Player
.p_experience
+= 2000.0 * Circle
;
1043 addstr("You've discovered some athelas!\n");
1048 /* end treasure type 3 */
1050 case 4: /* treasure type 4 */
1051 addstr("You've found a scroll. Will you read it ? ");
1052 ch
= getanswer("NY", FALSE
);
1056 switch ((int) ROLL(1, 6)) {
1058 addstr("It throws up a shield for you next monster.\n");
1059 getyx(stdscr
, whichtreasure
, ch
);
1060 more(whichtreasure
);
1062 (Player
.p_maxenergy
+ Player
.p_energy
) * 5.5 + Circle
* 50.0;
1063 Whichmonster
= pickmonster();
1064 longjmp(Fightenv
, 0);
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);
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);
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);
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);
1099 addstr("It was cursed!\n");
1104 /* end treasure type 4 */
1106 case 5: /* treasure type 5 */
1107 switch (whichtreasure
) {
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
;
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
;
1127 addstr("You've found a tablet.\n");
1128 Player
.p_brains
+= 4.5 * Circle
;
1132 /* end treasure type 5 */
1134 case 6: /* treasure type 6 */
1135 switch (whichtreasure
) {
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
;
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;
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
;
1160 /* end treasure type 6 */
1162 case 7: /* treasure type 7 */
1163 switch (whichtreasure
) {
1165 addstr("You've discovered a charm!\n");
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;
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
;
1186 /* end treasure type 7 */
1188 case 8: /* treasure type 8 */
1189 switch (whichtreasure
) {
1191 addstr("You have found a healing potion.\n");
1192 Player
.p_poison
= MIN(-2.0, Player
.p_poison
- 2.0);
1196 addstr("You have discovered a transporter. Do you wish to go anywhere ? ");
1197 ch
= getanswer("NY", FALSE
);
1202 addstr("X Y Coordinates ? ");
1203 getstring(Databuf
, SZ_DATABUF
);
1204 sscanf(Databuf
, "%lf %lf", &x
, &y
);
1205 altercoordinates(x
, y
, A_FORCED
);
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
;
1219 /* end treasure type 8 */
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;
1231 if (Curmonster
.m_treasuretype
== 11
1232 && !Player
.p_palantir
) {
1233 addstr("You've acquired Saruman's palantir.\n");
1234 Player
.p_palantir
= TRUE
;
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))
1247 if (drandom() < 0.8)
1262 if (Curmonster
.m_treasuretype
== 12) {
1263 whichtreasure
= R_NAZREG
;
1266 whichtreasure
= R_DLREG
;
1280 whichtreasure
= R_BAD
;
1281 temp
= 15 + Statptr
->c_ringduration
+ (int) ROLL(0, 5);
1284 addstr("You've discovered a ring. Will you pick it up ? ");
1285 ch
= getanswer("NY", FALSE
);
1289 Player
.p_ring
.ring_type
= whichtreasure
;
1290 Player
.p_ring
.ring_duration
= temp
;
1295 /* end treasure types 10 - 13 */
1296 /* fall through to treasure type 9 if
1297 * no treasure from above */
1299 case 9: /* treasure type 9 */
1300 switch (whichtreasure
) {
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");
1309 /* fall through otherwise */
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
;
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
;
1330 /* end treasure type 9 */
1336 cursedtreasure(void)
1338 if (Player
.p_charms
> 0) {
1339 addstr("But your charm saved you!\n");
1342 if (Player
.p_amulets
> 0) {
1343 addstr("But your amulet saved you!\n");
1347 (Player
.p_maxenergy
+ Player
.p_shield
) / 10.0;
1348 Player
.p_poison
+= 0.25;
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[] */
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
;
1369 /* pick values to swap */
1370 first
= (int) ROLL(0, 5);
1371 second
= (int) ROLL(0, 5);
1375 dtemp1
= dptr
[first
];
1376 /* this expression is split to prevent a compiler loop on some
1378 dtemp2
= dptr
[second
];
1379 dptr
[first
] = dtemp2
;
1380 dptr
[second
] = dtemp1
;
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
;