#include <curses.h>
#include <math.h>
#include <setjmp.h>
#include <string.h>
#include "macros.h"
#include "phantdefs.h"
#include "phantglobs.h"
static jmp_buf Fightenv;
void
encounter(int particular)
{
int flockcnt = 1;
volatile bool firsthit = Player.p_blessing;
Player.p_status = S_MONSTER;
writerecord(&Player, Fileloc);
Shield = 0.0;
if (particular >= 0)
Whichmonster = particular;
else
Whichmonster = pickmonster();
setjmp(Fightenv);
move(6, 0);
clrtobot();
Lines = 9;
callmonster(Whichmonster);
Luckout = FALSE;
if (Curmonster.m_type == SM_MORGOTH)
mvprintw(4, 0, "You've encountered %s, Bane of the Council and Valar.\n",
Enemyname);
if (Curmonster.m_type == SM_UNICORN) {
if (Player.p_virgin) {
printw("You just subdued %s, thanks to the virgin.\n", Enemyname);
Player.p_virgin = FALSE;
} else {
printw("You just saw %s running away!\n", Enemyname);
Curmonster.m_experience = 0.0;
Curmonster.m_treasuretype = 0;
}
} else
for (;;)
{
mvprintw(6, 0, "You are being attacked by %s, EXP: %.0f (Size: %.0f)\n",
Enemyname, Curmonster.m_experience, Circle);
displaystats();
mvprintw(1, 26, "%20.0f", Player.p_energy + Shield);
readmessage();
if (Curmonster.m_type == SM_DARKLORD
&& Player.p_blessing
&& Player.p_charms > 0)
{
mvprintw(7, 0, "You just overpowered %s!", Enemyname);
Lines = 8;
Player.p_blessing = FALSE;
--Player.p_charms;
break;
}
Curmonster.m_speed = MIN(Curmonster.m_speed + 1.0, Curmonster.m_maxspeed);
if (drandom() * Curmonster.m_speed > drandom() * Player.p_speed
&& Curmonster.m_type != SM_DARKLORD
&& Curmonster.m_type != SM_SHRIEKER
&& !firsthit)
monsthits();
else
{
firsthit = FALSE;
playerhits();
}
refresh();
if (Lines > LINES - 2)
{
more(Lines);
move(Lines = 8, 0);
clrtobot();
}
if (Player.p_energy <= 0.0)
{
more(Lines);
death(Enemyname);
cancelmonster();
break;
}
if (Curmonster.m_energy <= 0.0)
break;
}
Player.p_experience += Curmonster.m_experience;
if (drandom() < Curmonster.m_flock / 100.0)
{
more(Lines);
++flockcnt;
longjmp(Fightenv, 1);
} else
if (Circle > 1.0
&& Curmonster.m_treasuretype > 0
&& drandom() > 0.2 + pow(0.4, (double) (flockcnt / 3 + Circle / 3.0)))
{
more(Lines);
awardtreasure();
}
getyx(stdscr, Lines, flockcnt);
more(Lines + 1);
Player.p_ring.ring_inuse = FALSE;
move(4, 0);
clrtobot();
}
int
pickmonster(void)
{
if (Player.p_specialtype == SC_VALAR)
return ((int) ROLL(0.0, 100.0));
if (Marsh)
return ((int) ROLL(0.0, 15.0));
else if (Circle > 24)
return ((int) ROLL(14.0, 86.0));
else if (Circle > 15)
return ((int) (ROLL(0.0, 50.0) + ROLL(14.0, 37.0)));
else if (Circle > 8)
return ((int) (ROLL(0.0, 50.0) + ROLL(14.0, 26.0)));
else if (Circle > 3)
return ((int) ROLL(14.0, 50.0));
else
return ((int) ROLL(14.0, 25.0));
}
void
playerhits(void)
{
double inflict;
int ch;
mvaddstr(7, 0, "1:Melee 2:Skirmish 3:Evade 4:Spell 5:Nick ");
if (!Luckout) {
if (Curmonster.m_type == SM_MORGOTH)
addstr("6:Ally ");
else
addstr("6:Luckout ");
}
if (Player.p_ring.ring_type != R_NONE)
addstr("7:Use Ring ");
else
clrtoeol();
ch = inputoption();
move(8, 0);
clrtobot();
Lines = 9;
mvaddstr(4, 0, "\n\n");
switch (ch) {
case 'T':
break;
case ' ':
case '1':
inflict = ROLL(Player.p_might / 2.0 + 5.0, 1.3 * Player.p_might)
+ (Player.p_ring.ring_inuse ? Player.p_might : 0.0);
Curmonster.m_melee += inflict;
Curmonster.m_strength = Curmonster.m_o_strength
- Curmonster.m_melee / Curmonster.m_o_energy
* Curmonster.m_o_strength / 4.0;
hitmonster(inflict);
break;
case '2':
inflict = ROLL(Player.p_might / 3.0 + 3.0, 1.1 * Player.p_might)
+ (Player.p_ring.ring_inuse ? Player.p_might : 0.0);
Curmonster.m_skirmish += inflict;
Curmonster.m_maxspeed = Curmonster.m_o_speed
- Curmonster.m_skirmish / Curmonster.m_o_energy
* Curmonster.m_o_speed / 4.0;
hitmonster(inflict);
break;
case '3':
if ((Curmonster.m_type == SM_DARKLORD
|| Curmonster.m_type == SM_SHRIEKER
|| drandom() * Player.p_speed * Player.p_brains
> drandom() * Curmonster.m_speed * Curmonster.m_brains)
&& (Curmonster.m_type != SM_MIMIC))
{
mvaddstr(Lines++, 0, "You got away!");
cancelmonster();
altercoordinates(0.0, 0.0, A_NEAR);
} else
mvprintw(Lines++, 0, "%s is still after you!", Enemyname);
break;
case 'M':
case '4':
throwspell();
break;
case '5':
inflict = 1.0 + Player.p_sword;
Player.p_experience += floor(Curmonster.m_experience / 10.0);
Curmonster.m_experience *= 0.92;
Curmonster.m_maxspeed += 2.0;
Curmonster.m_speed = (Curmonster.m_speed < 0.0) ? 0.0 : Curmonster.m_speed + 2.0;
if (Curmonster.m_type == SM_DARKLORD)
{
mvprintw(Lines++, 0,
"You hit %s %.0f times, and made him mad!", Enemyname, inflict);
Player.p_quickness /= 2.0;
altercoordinates(0.0, 0.0, A_FAR);
cancelmonster();
} else
hitmonster(inflict);
break;
case 'B':
case '6':
if (Luckout)
mvaddstr(Lines++, 0, "You already tried that.");
else {
Luckout = TRUE;
if (Curmonster.m_type == SM_MORGOTH)
{
if (drandom() < Player.p_sin / 100.0) {
mvprintw(Lines++, 0, "%s accepted!", Enemyname);
cancelmonster();
} else
mvaddstr(Lines++, 0, "Nope, he's not interested.");
} else
{
if ((drandom() + 0.333) * Player.p_brains
< (drandom() + 0.333) * Curmonster.m_brains)
mvprintw(Lines++, 0, "You blew it, %s.", Player.p_name);
else {
mvaddstr(Lines++, 0, "You made it!");
Curmonster.m_energy = 0.0;
}
}
}
break;
case '7':
if (Player.p_ring.ring_type != R_NONE) {
mvaddstr(Lines++, 0, "Now using ring.");
Player.p_ring.ring_inuse = TRUE;
if (Player.p_ring.ring_type != R_DLREG)
--Player.p_ring.ring_duration;
}
break;
}
}
void
monsthits(void)
{
double inflict;
int ch;
switch (Curmonster.m_type)
{
case SM_DARKLORD:
inflict = (Player.p_energy + Shield) * 1.02;
goto SPECIALHIT;
case SM_SHRIEKER:
mvaddstr(Lines++, 0,
"Shrieeeek!! You scared it, and it called one of its friends.");
more(Lines);
Whichmonster = (int) ROLL(70.0, 30.0);
longjmp(Fightenv, 1);
case SM_BALROG:
inflict = ROLL(10.0, Curmonster.m_strength);
inflict = MIN(Player.p_experience, inflict);
mvprintw(Lines++, 0,
"%s took away %.0f experience points.", Enemyname, inflict);
Player.p_experience -= inflict;
return;
case SM_FAERIES:
if (Player.p_holywater > 0)
{
mvprintw(Lines++, 0, "Your holy water killed it!");
--Player.p_holywater;
Curmonster.m_energy = 0.0;
return;
}
break;
case SM_NONE:
break;
default:
if (drandom() > 0.2)
break;
switch (Curmonster.m_type) {
case SM_LEANAN:
inflict = ROLL(1.0, (Circle - 1.0) / 2.0);
inflict = MIN(Player.p_strength, inflict);
mvprintw(Lines++, 0, "%s sapped %0.f of your strength!",
Enemyname, inflict);
Player.p_strength -= inflict;
Player.p_might -= inflict;
break;
case SM_SARUMAN:
if (Player.p_palantir)
{
mvprintw(Lines++, 0, "Wormtongue stole your palantir!");
Player.p_palantir = FALSE;
} else
if (drandom() > 0.5)
{
mvprintw(Lines++, 0,
"%s transformed your gems into gold!", Enemyname);
Player.p_gold += Player.p_gems;
Player.p_gems = 0.0;
} else
{
mvprintw(Lines++, 0, "%s scrambled your stats!", Enemyname);
scramblestats();
}
break;
case SM_THAUMATURG:
mvprintw(Lines++, 0, "%s transported you!", Enemyname);
altercoordinates(0.0, 0.0, A_FAR);
cancelmonster();
break;
case SM_VORTEX:
inflict = ROLL(0, 7.5 * Circle);
inflict = MIN(Player.p_mana, floor(inflict));
mvprintw(Lines++, 0,
"%s sucked up %.0f of your mana!", Enemyname, inflict);
Player.p_mana -= inflict;
break;
case SM_NAZGUL:
if (Player.p_ring.ring_type != R_NONE)
{
mvaddstr(Lines++, 0, "Will you relinguish your ring ? ");
ch = getanswer("YN", FALSE);
if (ch == 'Y')
{
Player.p_ring.ring_type = R_NONE;
Player.p_ring.ring_inuse = FALSE;
cancelmonster();
break;
}
}
mvprintw(Lines++, 0,
"%s neutralized 1/5 of your brain!", Enemyname);
Player.p_brains *= 0.8;
break;
case SM_TIAMAT:
mvprintw(Lines++, 0,
"%s took half your gold and gems and flew off.", Enemyname);
Player.p_gold /= 2.0;
Player.p_gems /= 2.0;
cancelmonster();
break;
case SM_KOBOLD:
mvprintw(Lines++, 0,
"%s stole one gold piece and ran away.", Enemyname);
Player.p_gold = MAX(0.0, Player.p_gold - 1.0);
cancelmonster();
break;
case SM_SHELOB:
mvprintw(Lines++, 0,
"%s has bitten and poisoned you!", Enemyname);
Player.p_poison -= 1.0;
break;
case SM_LAMPREY:
mvprintw(Lines++, 0, "%s bit and poisoned you!", Enemyname);
Player.p_poison += 0.25;
break;
case SM_BONNACON:
mvprintw(Lines++, 0, "%s farted and scampered off.", Enemyname);
Player.p_energy /= 2.0;
cancelmonster();
break;
case SM_SMEAGOL:
if (Player.p_ring.ring_type != R_NONE)
{
mvprintw(Lines++, 0,
"%s tried to steal your ring, ", Enemyname);
if (drandom() > 0.1)
addstr("but was unsuccessful.");
else {
addstr("and ran away with it!");
Player.p_ring.ring_type = R_NONE;
cancelmonster();
}
}
break;
case SM_SUCCUBUS:
inflict = ROLL(15.0, Circle * 10.0);
inflict = MIN(inflict, Player.p_energy);
mvprintw(Lines++, 0, "%s sapped %.0f of your energy.",
Enemyname, inflict);
Player.p_energy -= inflict;
break;
case SM_CERBERUS:
mvprintw(Lines++, 0,
"%s took all your metal treasures!", Enemyname);
Player.p_crowns = 0;
Player.p_sword =
Player.p_shield =
Player.p_gold = 0.0;
cancelmonster();
break;
case SM_UNGOLIANT:
mvprintw(Lines++, 0,
"%s poisoned you, and took one quik.", Enemyname);
Player.p_poison += 5.0;
Player.p_quickness -= 1.0;
break;
case SM_JABBERWOCK:
mvprintw(Lines++, 0,
"%s flew away, and left you to contend with one of its friends.",
Enemyname);
Whichmonster = 55 + ((drandom() > 0.5) ? 22 : 0);
longjmp(Fightenv, 1);
case SM_TROLL:
mvprintw(Lines++, 0,
"%s partially regenerated his energy.!", Enemyname);
Curmonster.m_energy +=
floor((Curmonster.m_o_energy - Curmonster.m_energy) / 2.0);
Curmonster.m_strength = Curmonster.m_o_strength;
Curmonster.m_melee = Curmonster.m_skirmish = 0.0;
Curmonster.m_maxspeed = Curmonster.m_o_speed;
break;
case SM_WRAITH:
if (!Player.p_blindness)
{
mvprintw(Lines++, 0, "%s blinded you!", Enemyname);
Player.p_blindness = TRUE;
Enemyname = "A monster";
}
break;
}
return;
}
inflict = drandom() * Curmonster.m_strength + 0.5;
SPECIALHIT:
mvprintw(Lines++, 0, "%s hit you %.0f times!", Enemyname, inflict);
if ((Shield -= inflict) < 0) {
Player.p_energy += Shield;
Shield = 0.0;
}
}
void
cancelmonster(void)
{
Curmonster.m_energy = 0.0;
Curmonster.m_experience = 0.0;
Curmonster.m_treasuretype = 0;
Curmonster.m_flock = 0.0;
}
void
hitmonster(double inflict)
{
mvprintw(Lines++, 0, "You hit %s %.0f times!", Enemyname, inflict);
Curmonster.m_energy -= inflict;
if (Curmonster.m_energy > 0.0) {
if (Curmonster.m_type == SM_DARKLORD || Curmonster.m_type == SM_SHRIEKER)
monsthits();
} else
{
if (Curmonster.m_type == SM_MORGOTH)
mvaddstr(Lines++, 0, "You have defeated Morgoth, but he may return. . .");
else
{
mvprintw(Lines++, 0, "You killed it. Good work, %s.", Player.p_name);
if (Curmonster.m_type == SM_MIMIC
&& strcmp(Curmonster.m_name, "A Mimic") != 0
&& !Player.p_blindness)
mvaddstr(Lines++, 0, "The body slowly changes into the form of a mimic.");
}
}
}
void
throwspell(void)
{
double inflict;
double dtemp;
int ch;
inflict = 0;
mvaddstr(7, 0, "\n\n");
if (Player.p_magiclvl >= ML_ALLORNOTHING)
mvaddstr(7, 0, "1:All or Nothing ");
if (Player.p_magiclvl >= ML_MAGICBOLT)
addstr("2:Magic Bolt ");
if (Player.p_magiclvl >= ML_FORCEFIELD)
addstr("3:Force Field ");
if (Player.p_magiclvl >= ML_XFORM)
addstr("4:Transform ");
if (Player.p_magiclvl >= ML_INCRMIGHT)
addstr("5:Increase Might\n");
if (Player.p_magiclvl >= ML_INVISIBLE)
mvaddstr(8, 0, "6:Invisibility ");
if (Player.p_magiclvl >= ML_XPORT)
addstr("7:Transport ");
if (Player.p_magiclvl >= ML_PARALYZE)
addstr("8:Paralyze ");
if (Player.p_specialtype >= SC_COUNCIL)
addstr("9:Specify");
mvaddstr(4, 0, "Spell ? ");
ch = getanswer(" ", TRUE);
mvaddstr(7, 0, "\n\n");
if (Curmonster.m_type == SM_MORGOTH && ch != '3')
ILLSPELL();
else
switch (ch) {
case '1':
if (drandom() < 0.25)
{
inflict = Curmonster.m_energy * 1.01 + 1.0;
if (Curmonster.m_type == SM_DARKLORD)
inflict *= 0.9;
} else
{
Curmonster.m_o_strength = Curmonster.m_strength *= 2.0;
Curmonster.m_maxspeed *= 2.0;
Curmonster.m_o_speed *= 2.0;
Curmonster.m_speed = MAX(1.0, Curmonster.m_speed * 2.0);
}
if (Player.p_mana >= MM_ALLORNOTHING)
Player.p_mana -= MM_ALLORNOTHING;
hitmonster(inflict);
break;
case '2':
if (Player.p_magiclvl < ML_MAGICBOLT)
ILLSPELL();
else {
do
{
mvaddstr(4, 0, "How much mana for bolt? ");
dtemp = floor(infloat());
}
while (dtemp < 0.0 || dtemp > Player.p_mana);
Player.p_mana -= dtemp;
if (Curmonster.m_type == SM_DARKLORD)
inflict = 0.0;
else
inflict = dtemp * ROLL(15.0, sqrt(Player.p_magiclvl / 3.0 + 1.0));
mvaddstr(5, 0, "Magic Bolt fired!\n");
hitmonster(inflict);
}
break;
case '3':
if (Player.p_magiclvl < ML_FORCEFIELD)
ILLSPELL();
else if (Player.p_mana < MM_FORCEFIELD)
NOMANA();
else {
Player.p_mana -= MM_FORCEFIELD;
Shield = (Player.p_maxenergy + Player.p_shield) * 4.2 + 45.0;
mvaddstr(5, 0, "Force Field up.\n");
}
break;
case '4':
if (Player.p_magiclvl < ML_XFORM)
ILLSPELL();
else if (Player.p_mana < MM_XFORM)
NOMANA();
else {
Player.p_mana -= MM_XFORM;
Whichmonster = (int) ROLL(0.0, 100.0);
longjmp(Fightenv, 1);
}
break;
case '5':
if (Player.p_magiclvl < ML_INCRMIGHT)
ILLSPELL();
else if (Player.p_mana < MM_INCRMIGHT)
NOMANA();
else {
Player.p_mana -= MM_INCRMIGHT;
Player.p_might +=
(1.2 * (Player.p_strength + Player.p_sword)
+ 5.0 - Player.p_might) / 2.0;
mvprintw(5, 0, "New strength: %.0f\n", Player.p_might);
}
break;
case '6':
if (Player.p_magiclvl < ML_INVISIBLE)
ILLSPELL();
else if (Player.p_mana < MM_INVISIBLE)
NOMANA();
else {
Player.p_mana -= MM_INVISIBLE;
Player.p_speed +=
(1.2 * (Player.p_quickness + Player.p_quksilver)
+ 5.0 - Player.p_speed) / 2.0;
mvprintw(5, 0, "New quickness: %.0f\n", Player.p_speed);
}
break;
case '7':
if (Player.p_magiclvl < ML_XPORT)
ILLSPELL();
else if (Player.p_mana < MM_XPORT)
NOMANA();
else {
Player.p_mana -= MM_XPORT;
if (Player.p_brains + Player.p_magiclvl
< Curmonster.m_experience / 200.0 * drandom()) {
mvaddstr(5, 0, "Transport backfired!\n");
altercoordinates(0.0, 0.0, A_FAR);
cancelmonster();
} else {
mvprintw(5, 0, "%s is transported.\n", Enemyname);
if (drandom() < 0.3)
Curmonster.m_treasuretype = 0;
Curmonster.m_energy = 0.0;
}
}
break;
case '8':
if (Player.p_magiclvl < ML_PARALYZE)
ILLSPELL();
else if (Player.p_mana < MM_PARALYZE)
NOMANA();
else {
Player.p_mana -= MM_PARALYZE;
if (Player.p_magiclvl >
Curmonster.m_experience / 1000.0 * drandom()) {
mvprintw(5, 0, "%s is held.\n", Enemyname);
Curmonster.m_speed = -2.0;
} else
mvaddstr(5, 0, "Monster unaffected.\n");
}
break;
case '9':
if (Player.p_specialtype < SC_COUNCIL)
ILLSPELL();
else if (Player.p_mana < MM_SPECIFY)
NOMANA();
else {
Player.p_mana -= MM_SPECIFY;
mvaddstr(5, 0, "Which monster do you want [0-99] ? ");
Whichmonster = (int) infloat();
Whichmonster = MAX(0, MIN(99, Whichmonster));
longjmp(Fightenv, 1);
}
break;
}
}
void
callmonster(int which)
{
struct monster Othermonster;
which = MIN(which, 99);
fseek(Monstfp, (long) which * (long) SZ_MONSTERSTRUCT, SEEK_SET);
fread(&Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp);
if (Curmonster.m_type == SM_MODNAR) {
if (Player.p_specialtype < SC_COUNCIL)
{
Curmonster.m_strength *= drandom() + 0.5;
Curmonster.m_brains *= drandom() + 0.5;
Curmonster.m_speed *= drandom() + 0.5;
Curmonster.m_energy *= drandom() + 0.5;
Curmonster.m_experience *= drandom() + 0.5;
Curmonster.m_treasuretype =
(int) ROLL(0.0, (double) Curmonster.m_treasuretype);
} else
{
strlcpy(Curmonster.m_name, "Morgoth",
sizeof Curmonster.m_name);
Curmonster.m_strength = drandom() * (Player.p_maxenergy + Player.p_shield) / 1.4
+ drandom() * (Player.p_maxenergy + Player.p_shield) / 1.5;
Curmonster.m_brains = Player.p_brains;
Curmonster.m_energy = Player.p_might * 30.0;
Curmonster.m_type = SM_MORGOTH;
Curmonster.m_speed = Player.p_speed * 1.1
+ ((Player.p_specialtype == SC_EXVALAR) ? Player.p_speed : 0.0);
Curmonster.m_flock = 0.0;
Curmonster.m_treasuretype = 0;
Curmonster.m_experience = 0.0;
}
} else
if (Curmonster.m_type == SM_MIMIC)
{
which = (int) ROLL(0.0, 100.0);
fseek(Monstfp, (long) which * (long) SZ_MONSTERSTRUCT, SEEK_SET);
fread(&Othermonster, SZ_MONSTERSTRUCT, 1, Monstfp);
strlcpy(Curmonster.m_name, Othermonster.m_name,
sizeof Curmonster.m_name);
}
truncstring(Curmonster.m_name);
if (Curmonster.m_type != SM_MORGOTH)
{
Curmonster.m_strength *= (1.0 + Circle / 2.0);
Curmonster.m_brains *= Circle;
Curmonster.m_speed += Circle * 1.e-9;
Curmonster.m_energy *= Circle;
Curmonster.m_experience *= Circle;
}
if (Player.p_blindness)
Enemyname = "A monster";
else
Enemyname = Curmonster.m_name;
if (Player.p_speed <= 0.0)
{
Curmonster.m_speed += -Player.p_speed;
Player.p_speed = 1.0;
}
Curmonster.m_o_strength = Curmonster.m_strength;
Curmonster.m_o_speed = Curmonster.m_maxspeed = Curmonster.m_speed;
Curmonster.m_o_energy = Curmonster.m_energy;
Curmonster.m_melee = Curmonster.m_skirmish = 0.0;
}
void
awardtreasure(void)
{
int whichtreasure;
int temp;
int ch;
double treasuretype;
double gold = 0.0;
double gems = 0.0;
double dtemp;
whichtreasure = (int) ROLL(1.0, 3.0);
treasuretype = (double) Curmonster.m_treasuretype;
move(4, 0);
clrtobot();
move(6, 0);
if (drandom() > 0.65)
{
if (Curmonster.m_treasuretype > 7)
{
gems = ROLL(1.0, (treasuretype - 7.0)
* (treasuretype - 7.0) * (Circle - 1.0) / 4.0);
printw("You have discovered %.0f gems!", gems);
} else
{
gold = ROLL(treasuretype * 10.0, treasuretype
* treasuretype * 10.0 * (Circle - 1.0));
printw("You have found %.0f gold pieces.", gold);
}
addstr(" Do you want to pick them up ? ");
ch = getanswer("NY", FALSE);
addstr("\n\n");
if (ch == 'Y') {
if (drandom() < treasuretype / 35.0 + 0.04)
{
addstr("They were cursed!\n");
cursedtreasure();
}
else
collecttaxes(gold, gems);
}
return;
}
else
{
addstr("You have found some treasure. Do you want to inspect it ? ");
ch = getanswer("NY", FALSE);
addstr("\n\n");
if (ch != 'Y')
return;
else
if (drandom() < 0.08 && Curmonster.m_treasuretype != 4)
{
addstr("It was cursed!\n");
cursedtreasure();
return;
}
else
switch (Curmonster.m_treasuretype) {
case 1:
switch (whichtreasure) {
case 1:
addstr("You've discovered a power booster!\n");
Player.p_mana += ROLL(Circle * 4.0, Circle * 30.0);
break;
case 2:
addstr("You have encountered a druid.\n");
Player.p_experience +=
ROLL(0.0, 2000.0 + Circle * 400.0);
break;
case 3:
addstr("You have found a holy orb.\n");
Player.p_sin = MAX(0.0, Player.p_sin - 0.25);
break;
}
break;
case 2:
switch (whichtreasure) {
case 1:
addstr("You have found an amulet.\n");
++Player.p_amulets;
break;
case 2:
addstr("You've found some holy water!\n");
++Player.p_holywater;
break;
case 3:
addstr("You've met a hermit!\n");
Player.p_sin *= 0.75;
Player.p_mana += 12.0 * Circle;
break;
}
break;
case 3:
switch (whichtreasure) {
case 1:
dtemp = ROLL(7.0, 30.0 + Circle / 10.0);
printw("You've found a +%.0f shield!\n", dtemp);
if (dtemp >= Player.p_shield)
Player.p_shield = dtemp;
else
SOMEBETTER();
break;
case 2:
addstr("You have rescued a virgin. Will you be honorable ? ");
ch = getanswer("NY", FALSE);
addstr("\n\n");
if (ch == 'Y')
Player.p_virgin = TRUE;
else
{
Player.p_experience += 2000.0 * Circle;
++Player.p_sin;
}
break;
case 3:
addstr("You've discovered some athelas!\n");
--Player.p_poison;
break;
}
break;
case 4:
addstr("You've found a scroll. Will you read it ? ");
ch = getanswer("NY", FALSE);
addstr("\n\n");
if (ch == 'Y')
switch ((int) ROLL(1, 6)) {
case 1:
addstr("It throws up a shield for you next monster.\n");
getyx(stdscr, whichtreasure, ch);
more(whichtreasure);
Shield =
(Player.p_maxenergy + Player.p_energy) * 5.5 + Circle * 50.0;
Whichmonster = pickmonster();
longjmp(Fightenv, 1);
case 2:
addstr("It makes you invisible for you next monster.\n");
getyx(stdscr, whichtreasure, ch);
more(whichtreasure);
Player.p_speed = 1e6;
Whichmonster = pickmonster();
longjmp(Fightenv, 1);
case 3:
addstr("It increases your strength ten fold to fight your next monster.\n");
getyx(stdscr, whichtreasure, ch);
more(whichtreasure);
Player.p_might *= 10.0;
Whichmonster = pickmonster();
longjmp(Fightenv, 1);
case 4:
addstr("It is a general knowledge scroll.\n");
Player.p_brains += ROLL(2.0, Circle);
Player.p_magiclvl += ROLL(1.0, Circle / 2.0);
break;
case 5:
addstr("It tells you how to pick your next monster.\n");
addstr("Which monster do you want [0-99] ? ");
Whichmonster = (int) infloat();
Whichmonster = MIN(99, MAX(0, Whichmonster));
longjmp(Fightenv, 1);
case 6:
addstr("It was cursed!\n");
cursedtreasure();
break;
}
break;
case 5:
switch (whichtreasure) {
case 1:
dtemp = ROLL(Circle / 4.0 + 5.0, Circle / 2.0 + 9.0);
printw("You've discovered a +%.0f dagger.\n", dtemp);
if (dtemp >= Player.p_sword)
Player.p_sword = dtemp;
else
SOMEBETTER();
break;
case 2:
dtemp = ROLL(7.5 + Circle * 3.0, Circle * 2.0 + 160.0);
printw("You have found some +%.0f armour!\n", dtemp);
if (dtemp >= Player.p_shield)
Player.p_shield = dtemp;
else
SOMEBETTER();
break;
case 3:
addstr("You've found a tablet.\n");
Player.p_brains += 4.5 * Circle;
break;
}
break;
case 6:
switch (whichtreasure) {
case 1:
addstr("You've found a priest.\n");
Player.p_energy = Player.p_maxenergy + Player.p_shield;
Player.p_sin /= 2.0;
Player.p_mana += 24.0 * Circle;
Player.p_brains += Circle;
break;
case 2:
addstr("You have come upon Robin Hood!\n");
Player.p_shield += Circle * 2.0;
Player.p_strength += Circle / 2.5 + 1.0;
break;
case 3:
dtemp = ROLL(2.0 + Circle / 4.0, Circle / 1.2 + 10.0);
printw("You have found a +%.0f axe!\n", dtemp);
if (dtemp >= Player.p_sword)
Player.p_sword = dtemp;
else
SOMEBETTER();
break;
}
break;
case 7:
switch (whichtreasure) {
case 1:
addstr("You've discovered a charm!\n");
++Player.p_charms;
break;
case 2:
addstr("You have encountered Merlyn!\n");
Player.p_brains += Circle + 5.0;
Player.p_magiclvl += Circle / 3.0 + 5.0;
Player.p_mana += Circle * 10.0;
break;
case 3:
dtemp = ROLL(5.0 + Circle / 3.0, Circle / 1.5 + 20.0);
printw("You have found a +%.0f war hammer!\n", dtemp);
if (dtemp >= Player.p_sword)
Player.p_sword = dtemp;
else
SOMEBETTER();
break;
}
break;
case 8:
switch (whichtreasure) {
case 1:
addstr("You have found a healing potion.\n");
Player.p_poison = MIN(-2.0, Player.p_poison - 2.0);
break;
case 2:
addstr("You have discovered a transporter. Do you wish to go anywhere ? ");
ch = getanswer("NY", FALSE);
addstr("\n\n");
if (ch == 'Y') {
double x, y;
addstr("X Y Coordinates ? ");
getstring(Databuf, SZ_DATABUF);
sscanf(Databuf, "%lf %lf", &x, &y);
altercoordinates(x, y, A_FORCED);
}
break;
case 3:
dtemp = ROLL(10.0 + Circle / 1.2, Circle * 3.0 + 30.0);
printw("You've found a +%.0f sword!\n", dtemp);
if (dtemp >= Player.p_sword)
Player.p_sword = dtemp;
else
SOMEBETTER();
break;
}
break;
case 10:
case 11:
case 12:
case 13:
if (drandom() < 0.33) {
if (Curmonster.m_treasuretype == 10) {
addstr("You've found a pair of elven boots!\n");
Player.p_quickness += 2.0;
break;
}
else if (Curmonster.m_treasuretype == 11
&& !Player.p_palantir)
{
addstr("You've acquired Saruman's palantir.\n");
Player.p_palantir = TRUE;
break;
}
else if (Player.p_ring.ring_type == R_NONE
&& Player.p_specialtype < SC_COUNCIL
&& (Curmonster.m_treasuretype == 12
|| Curmonster.m_treasuretype == 13))
{
if (drandom() < 0.8)
{
if (Curmonster.m_treasuretype == 12)
{
whichtreasure = R_NAZREG;
temp = 35;
}
else
{
whichtreasure = R_DLREG;
temp = 0;
}
}
else
{
whichtreasure = R_BAD;
temp = 15 + Statptr->c_ringduration + (int) ROLL(0,5);
}
addstr("You've discovered a ring. Will you pick it up ? ");
ch = getanswer("NY", FALSE);
addstr("\n\n");
if (ch == 'Y')
{
Player.p_ring.ring_type = whichtreasure;
Player.p_ring.ring_duration = temp;
}
break;
}
}
case 9:
switch (whichtreasure)
{
case 1:
if (Player.p_level <= 1000.0
&& Player.p_crowns <= 3
&& Player.p_level >= 10.0)
{
addstr("You have found a golden crown!\n");
++Player.p_crowns;
break;
}
case 2:
addstr("You've been blessed!\n");
Player.p_blessing = TRUE;
Player.p_sin /= 3.0;
Player.p_energy = Player.p_maxenergy + Player.p_shield;
Player.p_mana += 100.0 * Circle;
break;
case 3:
dtemp = ROLL(1.0, Circle / 5.0 + 5.0);
dtemp = MIN(dtemp, 99.0);
printw("You have discovered some +%.0f quicksilver!\n",dtemp);
if (dtemp >= Player.p_quksilver)
Player.p_quksilver = dtemp;
else
SOMEBETTER();
break;
}
break;
}
}
}
void
cursedtreasure(void)
{
if (Player.p_charms > 0) {
addstr("But your charm saved you!\n");
--Player.p_charms;
} else
if (Player.p_amulets > 0) {
addstr("But your amulet saved you!\n");
--Player.p_amulets;
} else {
Player.p_energy =
(Player.p_maxenergy + Player.p_shield) / 10.0;
Player.p_poison += 0.25;
}
}
void
scramblestats(void)
{
double dbuf[6];
double dtemp1, dtemp2;
int first, second;
double *dptr;
dptr = &dbuf[0];
*dptr++ = Player.p_strength;
*dptr++ = Player.p_mana;
*dptr++ = Player.p_brains;
*dptr++ = Player.p_magiclvl;
*dptr++ = Player.p_energy;
*dptr = Player.p_sin;
first = (int) ROLL(0, 5);
second = (int) ROLL(0, 5);
dptr = &dbuf[0];
dtemp1 = dptr[first];
dtemp2 = dptr[second];
dptr[first] = dtemp2;
dptr[second] = dtemp1;
Player.p_strength = *dptr++;
Player.p_mana = *dptr++;
Player.p_brains = *dptr++;
Player.p_magiclvl = *dptr++;
Player.p_energy = *dptr++;
Player.p_sin = *dptr;
}