// have an array which keeps track of 'when the delvers enter the
// monsters will be...', and choose ones which haven't been chosen
// as often rather than completely randomly.

if (!isset($system)) {
$system="tt";
}

$level=array();
$mr=array();
$pow=array();
$rn=array();
$rb=array();
$tr=array();
$eye=array();
$eyeval=500;
$eyedesc=array(
1=> array ("Stealing Fae Glamour","If the target of this Eye is an elf, leprechaun or fairy, he or she will lose 1 dice worth of CHR, and the Eye will <b>gain</b> a charge instead of losing it. Unlike most Eyes, being hit by this Eye <i>doesn't</i> make the target immune.<br>If the target is a statted creature who rolls their initial CHR with a multiplier of x 1 or less, the target will gain 1 dice worth of LK. Their LK will slowly fall to their normal level, at the rate of 1 point every 24 hours."),
2=> array ("Overwhelming Horror","Anyone hit by this beam must make a save on INT, at the level of the character holding it, or be overcome with fear and horror of that character. Anyone overcome by such fear will run from the character as fast as they can, at all costs, and will only fight if cornered. The effect will last 1-6 minutes of in-game time.<br>If a Monster-Rated monster is holding the Eye, divide its MR by 30, rounding up, and treat that as its level. If the victim is a Monster-Rated monster, the character holding it should make a save on CHR, at a level equal to the target's MR divided by 30 and rounded up. If both holder and victim are Monster Rated, the one with the higher MR will prevail."),
3=> array ("Arriving By the Nameless Path","Anyone hit by this beam will notice no change in themselves or their environment whatsoever. Yet they will find that when travelling, they reach their destination in half the time they would otherwise. Anyone travelling with them will likewise arrive in half the time. The effect will last 1-6 weeks, and won't 'stack' - two characters who've been hit by this Eye and travel together won't arrive in a quarter of the time for example."),
4=> array ("Overcoming All Physical Adversity","Anyone hit by this beam, if they're sick, will instantly be cured of their sickness. If they're not sick, they will heal any wounds at twice the normal rate for the next 1-6 days. If they're not sick or wounded, the beam will have no effect."),
5=> array ("the Ecstatic Madness of Love","Anyone hit by this beam, if they're statted, will treat their CHR and LK as if they were double their real value, but also treat their INT and DEX as if they were half their real value (rounded up), for 1-6 days of in-game time."),
6=> array ("Climbing the Wall of Tongues","Any statted creature hit by this beam will find, for 1-6 days of in-game time, that they can work out what any other creature who has also been hit by the beam is saying, and manage to communicate with them, even if the two characters have no language in common."),
7=> array ("Neither Rising Nor Falling","Anyone hit by this beam will be unable to move upwards or downwards for any significant distance, for a number of hours equal to the roll of 2 dice. They may, however, be carried. Otherwise they must stay on the same dungeon level."),
8=> array ("Striving With Chivalry","Any creature hit by this beam will be unable to use ranged weapons, magic items or spells in combat, for a number of minutes equal to the roll of a dice. If they fight anyone who breaks any of these 'rules', they will be freed from the Eye's effects at the end of the relevant Combat Round."),
);
$eyenum=8;
$mo=array();
$traps=array(
1=> "A hidden trapdoor in this room will open if @@FD steps on it.<br><br>The victim will fall down to room @@L, taking @@D damage. Armour will reduce this damage, shields won't.<br><br>If the room is searched, the trapdoor will be found on a successful level @@1 save on INT.<br><br>If the trapdoor isn't found, a successful level @@2 save on LK will avoid it. Characters must make this roll every time they walk across the room without having found the trap, or if they search and no one finds the trap. If more than one character fails their LK save, the victim will be the one who misses it by the most. If the group is walking across the room in single file, only the person in the lead need save.<br><br>If the trapdoor is sprung, a level @@3 save on @@DS will allow the victim to leap free.<br><br>Once the trapdoor is discovered, delvers may choose to leap down deliberately. If they do so, they should make a level @@4 save on DEX. If they succeed, they take no damage. If they fail, roll for damage as above but halve the result (round up).<br><br>Climbing up from the room below requires a level @@5 save on DEX. Failure doesn't result in any damage, but will make enough noise that the GM should roll twice for wandering monsters. If any result, they'll arrive in @@TT minutes. This roll is as well as, not instead of, the regular roll for wandering monsters.",
2=> "A hideous wailing starts up as soon as anyone enters the room. The GM should roll twice for wandering monsters immediately, then roll every five minutes of in-game time, as long as the delvers stay in the room. Any monsters that result will arrive in @@TT minutes. This roll is as well as, not instead of, the regular roll for wandering monsters.<br><br>Searching the room for the mechanism to turn the alarm off requires a successful level @@1 save on the lower of INT or LK.",
3=> "Invisible beams of light cross the centre of the room, at about knee height for a human. If anyone breaks the beams, a jet of liquid will spray at them from the walls. A successful level @@1 save on @@DS is required to dodge. If they fail, they won't suffer any damage, but their clothes, skin and/or armour will be soaked in the liquid. Its strong, meaty smell means that the GM should roll for wandering monsters twice as often as usual. The victim will also be unable to hide. This will last until the liquid has been washed off (which will take an hour), or three days have passed. Clothing or armour can of course be abandoned. 'Smoking' clothes over a fire will also get rid of the smell in an hour.",
4=> "A machine in the centre of the room will shoot laser beams at anyone who enters, which do @@D damage. It will shoot @@6 beams per Combat Round. If there's more than one target, choose randomly. Treat this as a missile attack, with the machine having a DEX of @@MD. Any object bigger than a human fist thrown into its gears will jam it up (throwing stars aren't big enough, a throwing knife is). Treat the machine as a 'gigantic' target. If the delvers haven't encountered one before, a level @@2 save on INT will reveal the machine's function as a guardian used by the Ancients. Once it has shot at least once, a level @@3 save on INT will reveal the effect of the beams.",
5=> "A machine in the centre of the room will shoot beams at anyone who enters. Anyone hit by a beam will fall unconscious. They'll wake up in 10 minutes. If the entire party is hit by the beams, they'll wake up in area @@L. It will shoot @@6 beams per Combat Round. It will ignore unconscious characters. If there's more than one target, choose randomly. Treat this as a missile attack, with the machine having a DEX of @@MD. Any object bigger than a human fist thrown into its gears will jam it up (throwing stars aren't big enough, a throwing knife is). Treat the machine as a 'gigantic' target. If the delvers haven't encountered one before, a level @@2 save on INT will reveal the machine's function as a guardian used by the Ancients. Once it has shot at least once, a level @@3 save on INT will reveal the effect of the beams.",
6=> "A machine in the centre of the room will shoot beams at anyone who enters. Anyone hit by a beam will fall unconscious, and take @@6 damage (armour or shields won't reduce the damage). They'll wake up in 10 minutes. If the entire party is hit by the beams, they'll wake up outside the dungeon. It will shoot @@6 beams per Combat Round. It will ignore unconscious characters. If there's more than one target, choose randomly. Treat this as a missile attack, with the machine having a DEX of @@MD. Any object bigger than a human fist thrown into its gears will jam it up (throwing stars aren't big enough, a throwing knife is). Treat the machine as a 'gigantic' target. If the delvers haven't encountered one before, a level @@2 save on INT will reveal the machine's function as a guardian used by the Ancients. Once it has shot at least once, a level @@3 save on INT will reveal the effect of the beams.",
7=> "A machine in the centre of the room will shoot rays of pure logic at anyone who enters. Anyone hit by a ray must make a level @@1 save on the lower of INT or CHA. If they fail, they'll be unable to cast spells, learn any spells, or use any magic items. Fairies will also be unable to fly. After 12 hours of in-game time they can make the save again, adding 2 to their roll. If they fail again, they can try again in 12 hours with a bonus of 4, and so on until they make the save. A delver who's hit by a ray but has already failed their save will instead take @@D damage, reduced as normal by shields and armour.<br><br>The machine will shoot @@6 beams per Combat Round. If there's more than one target, choose randomly. Treat this as a missile attack, with the machine having a DEX of @@MD. Any object bigger than a human fist thrown into its gears will jam it up (throwing stars aren't big enough, a throwing knife is). Treat the machine as a 'gigantic' target.<br><br>If the delvers haven't encountered one before, a level @@2 save on INT will reveal the machine's function as a guardian used by the Ancients. Once it has shot at least once, a level @@3 save on INT will reveal the effect of the beams.",
8=> "When the delvers first enter the room, unless the group is entirely Warriors bolts of lightning will shoot from the walls, aimed at all the Rogues and Wizards in the group. A successful level @@1 save on @@DS is required to dodge. If a delver fails they won't suffer any damage, but they'll be unable to use any magic (including using runestones, but not including learning spells from scrolls) for 6 hours of in-game time.",
9=> "A dart will fly out of the room at @@FD who steps on a particular part of the floor.<br><br>Anyone who crosses the room must make a level @@1 save on LK to avoid stepping on the relevant part of the floor (unless the delvers move in single file, in which case only the character in front needs to save, or they've already triggered the trap once and know where to avoid).<br><br>A level @@6 roll on @@DS is required to dodge the dart.<br><br>If the delvers search the room, roll for the delvers one at a time in a random order. Each delver should make a level @@2 roll on INT to find the mechanism which releases the darts. If they fail they should make the LK save to avoid stepping on the wrong part of the floor and setting it off.<br><br>Anyone who keeps an eye on the walls will notice where the dart comes from, meaning that they can find the mechanism easily. Disabling the mechanism once it's found doesn't require any roll. The dart does @@D dice worth of damage, reduced as normal by armour and shields. The trap can be triggered any number of times.",
10=> "As the delvers cross this room, it will suddenly be filled with magic light. Anyone who fails to make a level @@1 save on INT, and so avert their eyes in time, will be dazzled for 1-6 hours of in-game time. A dazzled character won't be blind, but will see spots in front of their eyes, find it difficult to focus etc. This means that, whenever they make a saving roll related to a physical action (including rolls to hit with a missile weapon), they add one level to the difficulty. They also take 5 from their Hit Point Total when fighting hand-to-hand.<br><br>Once the delvers have experienced this kind of trap once, they'll be prepared for it and don't need to save.",
11=> "As the delvers cross this room, it will suddenly be filled with magic light. Anyone who fails to make a level @@1 save on @@DS, and so avert their eyes in time, will be dazzled for 1-6 hours of in-game time. A dazzled character won't be blind, but will see spots in front of their eyes, find it difficult to focus etc. This means that, whenever they make a saving roll related to a physical action (including rolls to hit with a missile weapon), they add one level to the difficulty. They also take 5 from their Hit Point Total when fighting hand-to-hand.<br><br>Once the delvers have experienced this kind of trap once, they'll be prepared for it and don't need to save.",
);
$trapnum=11;
// @@L a room on the lower level, or choose another trap if this is rolled on the lowest level.
// @@1, @@2, @@3, @@4, @@5 random numbers, 0 to current level.
// @@6 as above, but a minimum result of two.
// @@D damage
// @@DS means SPD if using SPD, DEX if not.
// @@TT means 'travel time'
// @@FD means randomly "any delver", or "any delver bigger than a fairy".
// @@MD machine DEX: ($level*5)+(10-20)

$lltraps=array(
1=> "<b>Basic Arrow Trap</b> An arrow fires from a hidden location, attacking as a level 1 Fighter, for 1d6 damage.",
2=> "<b>Bricks From Ceiling</b> Every character in a 3 yard/metre radius must save vs petrify or suffer 2d6 damage.",
3=> "<b>Camouflaged Pit Trap</b> This pit is @XX feet deep.",
4=> "<b>Poison Dart Trap</b> A dart fires from a hidden location, dealing 1d4 damage, and the character must save vs poison or die.",
5=> "<b>Poison Needle Trap</b> The character must save vs poison or die.",
6=> "<b>Rolling Rock Trap</b> A rock rolls out from a hidden location, and the characters must save vs petrify or suffer 2d6 damage.",
7=> "<b>Spiked Pit Trap</b> This pit is @XX feet deep, and has @YY spikes (1d6 damage each in addition to the damage from falling).",
8=> "<b>Scything Blade Trap</b> Each character must save vs petrify or suffer 1d8 damage.",
);
$lltrapnum=8;

$mftraps=array(
1=> "<b>Anti-Gravity Trap</b> An automated motion sensor causes the gravity in this room to reverse. Characters 'fall' upwards, suffering 1d6 damage per yard/metre 'fallen'. The gravity will return to normal in 1-6 minutes, causing the same damage unless the characters can 'climb' out of the room.",
2=> "<b>Cryo-Freeze Trap</b> A covered pit causes a character to fall into a small chamber, which seals automatically. The character will be frozen automatically, and will stay that way until they can be thawed out.",
3=> "<b>Decompression Chamber</b> Hidden, sliding doors will seal this room off, and all air will leave the room. Characters will suffer 1d4 damage per round, as well as the possibility of suffocation. Characters suffocate in CON/2 rounds (rounded down), unless they can break down one of the doors.",
4=> "<b>Electrified Walls</b> The walls of this room are electrified, and if touched will do 4d6 damage. Anyone who searches the room. A successful save vs breath attacks halves the damage (rounded down). Assume that anyone who searches the room touches the walls, unless they say otherwise beforehand. Touching the walls is necessary to find secret doors.",
5=> "<b>Gas Trap</b> When the characters enter this room, a gas trap is triggered which mimics the effects of a blood agent grenade (see p118 of Mutant Future).",
6=> "<b>Gas Trap</b> When the characters enter this room, a gas trap is triggered which mimics the effects of a nerve gas grenade (see p118 and 119 of Mutant Future).",
7=> "<b>Gas Trap</b> When the characters enter this room, a gas trap is triggered which mimics the effects of a bio-toxin bomb (see p120 of Mutant Future).",
8=> "<b>Laser Gun Trap</b> A laser in the wall fires on characters who enter the room. It attacks as a monster with 4 Hit Dice, and does 5d6 damage. It has an AC of 5 and 12 Hit Points.",
9=> "<b>Motion-Sensing Rifles</b> An automatic rifle in the wall fires on characters who enter the room. It attacks as a monster with 4 Hit Dice, and does 1d12 damage. It has an AC of 5 and 15 Hit Points.",
10=> "<b>Radiation Trap</b> A radiation-emitting globe drops and suspends from the ceiling releasing a blast of class @UU radiation each round (see p51 of Mutant Future). It has an AC of 5 and 30 Hit Points.",
11=> "<b>Warp-Field Scything Blade</b> Each character must save vs petrify or suffer 30 damage.",
);
$mftrapnum=11;

// $traps is for Tunnels & Trolls.
// $lltraps and $mftraps are for LL/MF -
// $mftraps tend to appear on higher levels.
// @XX is a number close to the level number x 10.
// @YY is 2-5.
// @UU is 1-10.

$magicitems=array();
$artifacts=array();
// both these arrays are numerical.
// they're the number of items of various
// kinds present in a horde of treasure.
// the numbers match up with $llitemsd and $mfitemsd respectively.

// have to make sure $firstnum<>$secondnum, and $thirdnum<>$fourthnum
// otherwise might get infinite loop, where it's trying to get one
// that's unused, but the only ones left are forbidden combinations.

$apphum=array(
1=> "a dwarf",
2=> "an elf",
3=> "a hobbit",
4=> "a baby",
5=> "a child of around ten years old",
6=> "a beautiful woman",
7=> "a strong, handsome youth",
8=> "a wrinkled crone",
9=> "a wizened old man",
10=> "whoever is standing closest to it at any given time",
11=> "a person that could be either a boy or a young woman",
12=> "a person that could either be a feminine-looking young man, or a masculine-looking woman",
13=> "whoever the delver standing closest to it will respond best to (eg a parent, first love, or favourite teacher)",
);
$humapp=13;

if ($system=="ll") {
$apphum[3]="a halfling";
}

$appcha=array(
1=> "has the body of @@HU, but a head like @@AN.",
2=> "has the body of @@HU, but a head which looks like @@PL.",
3=> "has a body which looks like @@EI, but with the face of @@HU.",
4=> "looks like a wooden carving of @@EH.",
5=> "looks like a wooden puppet of @@EA.",
6=> "looks like a child's doll of @@EA.",
7=> "looks like @@AN, but can talk, use weapons etc.",
8=> "looks like @@EH, but insubstantial and ghostly.",
9=> "looks like the animated corpse of @@EA.",
10=> "looks like @@EA, but fiery and demonic.",
11=> "takes the form of @@HU, but may revert to its true form, which looks like @@EI.",
12=> "looks like the offspring of @@AN and @@A2.",
13=> "looks like @@PL which has grown into the shape of @@EA.",
14=> "looks like a statue^ of @@PL.",
15=> "looks like a statue of @@HU.",
16=> "looks like a statue^^ of @@AN.",
17=> "looks like a hedge, cut into the shape of @@AN.",
18=> "looks like @@HU above the waist, @@EI below.",
19=> "looks like the offspring of a human and @@AN.",
20=> "looks like the disembodied head of @@EA.",
21=> "is a robot, built to resemble @@EH.",
22=> "looks like @@HU on one side of its body, @@H2 on the other.",
23=> "looks like @@HU on one side of its body, @@AN on the other.",
24=> "looks like @@HU, wearing a mask of @@AN.",
25=> "looks like @@AN, wearing a mask of @@HU.",
26=> "looks like @@AN, wearing a mask of @@A2.",
27=> "looks like @@A2, wearing a mask of @@AN.",
);

// 26 and 27 are because, if there's a theme, only $a2 can be set.

// @@EA means either @@HU or @@AN.
// @@EH means either @@HU, @@AN, or @@PL.
// @@EI means either @@AN or @@PL.
// @@A2 same list as @@AN, but can't be the same choice.
// @@H2 same list as @@HU, but can't be the same choice.
$chaapp=27;

$sname=array("null","STR","INT","LK","CON","DEX","CHR","SPD","WIZ");
$attnum=7+$wiz;
if ($system=="ll") {
$sname[3]="WIL/WIS";
$sname[6]="CHA";
$attnum=6;
}
$shallow=array();
$deep=array();
$climates=array(
1=> "Desert-like",
2=> "Hot and dry",
3=> "Hot and damp",
4=> "Mild",
5=> "Cold",
6=> "Logical",
);
$climated=array(
"Desert-like"=> "During the early morning, the STR requirement for armour is doubled. From mid-morning to sunset, the STR requirement for armour is tripled. Shields aren't affected in either case. Delvers whose armour is now too heavy will have time to remove it or get to an area with a lower temperature.<br><br>At night, the temperature drops rapidly: every hour of in-game time, unless the delvers have made a fire, each delver must make a save on CON @@2. If they fail, they take damage equal to the amount they failed by (critical failure counts as a failure by at least 1).",
"Hot and dry"=> "The STR requirement for armour is doubled. Shields aren't affected. Delvers whose armour is now too heavy will have time to remove it or get to an area with a lower temperature.",
"Hot and damp"=> "The STR requirement for armour is multiplied by 3/2. Delvers whose armour is now too heavy will have time to remove it or get to an area with a lower temperature.<br><br>Every hour of in-game time, every delver with any wounds (not damage due to other sources such as cold) must make a save on CON @@1. If they fail, they've become sick (characters who are sick don't need to keep making the save). They immediately lose 1-3 CON, and will not recover CON in the usual way. If a sick delver moves to an area of mild temperature, they may make a save on their <i>maximum</i> CON at the same level every four hours of in-game time. If they succeed, they're no longer sick, and will heal normally.",
"Mild"=> "Delvers won't suffer any ill effects from the temperature.",
"Cold"=> "Every hour of in-game time, unless the delvers have made a fire, each delver must make a save on CON @@2. If they fail, they take damage equal to the amount they failed by (critical failure counts as a failure by at least 1).",
);

if ($system=="ll") {
$climated["Desert-like"]="During the early morning, characters must have a CON of at least 11 to be able to wear metal armour. From mid-morning to sunset, characters must have a CON of at least 11 to wear <i>any</i> armour, and CON of at least 14 to wear metal armour. Characters whose armour is now too heavy will have time to remove it or get to an area with a lower temperature before they pass out.<br><br>At night, the temperature drops rapidly: every hour of in-game time, unless the delvers have made a fire, each delver must roll 2d10. If the result is higher than their CON, they take damage equal to the difference. A successful save vs Poison or Death will halve the damage (rounded up).";
$climated["Hot and dry"]="Characters must have a CON of at least 11 to be able to wear metal armour. Characters whose armour is now too heavy will have time to remove it or get to an area with a lower temperature before they pass out.";
$climated["Hot and damp"]="Every hour of in-game time, every delver with any wounds (not damage due to other sources such as cold) must make a save vs Poison or Death. If they fail, they've become sick (characters who are sick don't need to keep making the save). They immediately lose 1-3 Hit Points, treat their STR as being 1d6 lower than its real value, and will not recover Hit Points in the usual way. If a sick delver moves to an area of mild temperature, they may make a save vs Poison or Death every four hours of in-game time. If they succeed, they're no longer sick (however they don't get their lost Hit Points back instantly - they have to wait for them to heal normally).";
$climated["Mild"]="The party won't suffer any ill effects from the temperature";
$climated["Cold"]="Every hour of in-game time, unless the delvers have made a fire, each delver must roll 2d10. If the result is higher than their CON, they take damage equal to the difference. A successful save vs Poison or Death will halve the damage (rounded up).";
}

$climatew=array(
"Hot and damp"=> "10 minutes",
"Hot and dry"=> "40 minutes",
"Cold"=> "40 minutes",
"Mild"=> "20 minutes",
"Desert-like"=> "40 minutes of in-game time at night or in the early morning, once every 80 minutes of in-game time otherwise",
);
$cnum=5;
if ($system=="tt") {
// 'logical' levels are only for Tunnels & Trolls.
$cnum=6;
if (rand(1,3)==1) {
$climatew["Logical"]="15 minutes";
} elseif (rand(1,2)==1) {
$climatew["Logical"]="30 minutes";
} else {
$climatew["Logical"]="hour";
}
$climated["Logical"]=$climated["Logical"]."all spells cast in this environment ";
if (rand(1,3)==1) {
$ec1=rand(1,6);
$ec2=rand(1,6)+rand(1,6);
$climated["Logical"]=$climated["Logical"]."need ".$ec1." extra INT and ".$ec2." extra DEX compared to their normal requirements. If a spell-caster tries to cast a spell but doesn't have the INT and/or DEX, they waste a Combat Round but don't pay any cost.";
} elseif (rand(1,2)==1) {
$ec=rand(1,6)+rand(1,6);
$climated["Logical"]=$climated["Logical"]."will cost an extra ".$ec." ".$sname[1+(7*$wiz)].".";
} else {
$ec=rand(1,5);
$climated["Logical"]=$climated["Logical"]."have a ".$ec." in 6 chance of failure. If a spell fails the spell-caster pays half the ".$sname[1+(7*$wiz)].", rounded down. Trying to cast a spell and failing still takes a whole Combat Round.";
}
$climated["Logical"]=$climated["Logical"]."<br><br>Warriors won't notice anything different. Wizards and Rogues will know that there'll be some problem with casting spells, but won't know what until they actually try to cast one. Creatures of the dungeon that can cast spells will know what the effects will be.";
}
$lclimate=array();
$ss=2;
$dshr=array();
$entrance=array (
1=> "@@A used by an evil cult as a means of sacrificing people.",
2=> "@@A easy to find guides, maps etc, since the locals make a lot of their income from equipping adventurers.",
3=> "under a @@T. The entrance has been exposed by accident.",
4=> "under a @@T. It's entered via a trapdoor in a cellar.",
5=> "under a @@T. It's entered via a secret door in a public building.",
6=> "inside the body of a giant @@B.",
7=> "entered via @@C lair.",
8=> "behind a waterfall.",
9=> "in an abandoned mine.",
10=> "accidentally discovered during extensions to a mine.",
11=> "in an extinct volcano.",
12=> "entered by a secret cave. The cave can only be entered via the water.",
13=> "on another plane of existence, and entered and exited by a magic portal.",
14=> "@@A widely advertised by the occupants of the dungeon, in order to attract adventurers to their doom.",
15=> "in a tomb.",
16=> "entered via a stairway inside a hollowed-out tree.",
);
$ennum=16;

$gods=array(
1=> array ("Thoth","ibis-headed","god","magic","@@Lfor the next 4 hours of in-game time all spells the delver casts have their cost reducted by an amount equal to the level of the save (to a minimum cost of 1). For example, if the delver makes a level 3 save, for 4 hours all spells cost them 3 less."),
2=> array ("Guan Yin","motherly","goddess","compassion","The save is based on how wounded the character is: divide the amount of CON they've lost by 10, and round down (minimum 0). If the save succeeds, and if the delver can refrain from killing any living thing for 24 hours of in-game time (robots don't count), they'll be healed back to their full CON. If the save fails the delver won't lose CON. Instead, they'll be <i>unable</i> to wound any living thing for 24 hours. They can still contribute to the delvers' Hit Point Total using hand-to-hand weapons (defending themselves but not attacking). However if the delvers win a round, the damage is reduced by the total amount that this delver contributed, to a minimum of zero."),
3=> array ("Ra","falcon-headed","god","the sun","@@Lfor the next 4 hours the delver is immune to the damaging effects of cold, and the increase in STR required for armour in the heat."),
4=> array ("Hestia","virginal","goddess","the home","@@Lthis area will be free from wandering monsters for the next 24 hours."),
5=> array ("Hermes","swift-footed","god","thieves","@@Lthe delver may count one future failed save of the same level or less as a success, if the save was made to hide, outrun someone, search an area or disarm a trap."),
6=> array ("Kali","fierce","goddess","destruction","@@Lin a future Combat Round where the delver is fighting hand-to-hand, they can invoke the blessing of destruction. For that round, their strike contributes to the delvers' Hit Point Total, but does its damage as a minimum, in the same way as a Take That You Fiend spell. Armour and shields still reduce the damage."),
7=> array ("Loki","sly","god","transformation","@@Lthe next creature encountered will perceive the delvers as members of their own species."),
8=> array ("Fortuna","veiled and blind","goddess","luck","@@Lthe delver may count one future failed LK save of the same level or less as a success."),
9=> array ("Xipe Totec","flayed and bloody","god","agriculture","@@Lthe delver is blessed with corn sufficient for a number of meals equal to the level they made the save at."),
10=> array ("Freya","golden-haired","goddess","wealth","@@Lthe delver is told the location of the nearest gold (other than that carried by the delvers, or in a vending machine), and what monsters and/or traps are guarding it. Note that this applies only to gold, not to treasure in general."),
11=> array ("Lug","royal","god","every skill","The save is made at a level equal to the character's level. If it succeeds, for one future Combat Round or saving roll, the delver may use any of INT, DEX, or STR in place of any other. If the delver gains a level before using this blessing, and if your game uses Talents, they gain two Talents instead of one and the blessing is 'used up.'"),
12=> array ("Diana","graceful","goddess","hunting","The save is made at the character's level. If it succeeds, the delver may count one future missed missile attack as a hit. If they fail, they don't lose CON. Instead, they are cursed to be hunted: the GM should roll for wandering monsters twice as often, until two groups of wandering monsters have been defeated."),
13=> array ("Prometheus","brave","god","fire","The save is made at a level equal to the character's level. If it succeeds, the character can cast the Wall of Fire spell once, with no cost, regardless of their Type and attributes."),
14=> array ("Sophia","winged","goddess","wisdom","@@Lthe delver may count one future failed INT save of the same level or less as a success."),
15=> array ("Baron Samedi","skull-faced","god","death and resurrection","This shrine can bring anyone back to life who's been dead for an hour or less. The level of the save depends on the delver or creature being resurrected. For Monster Rated monsters, look at their MR. For creatures or delvers with full attributes, look at the total of their INT, STR, and LK. In either case, divide by 10 and round down. If it succeeds, the subject is brought back to life, with 1 CON or 1 MR."),

16=> array ("Pan","goat-legged","god","nature","The save is based on how wounded the character is: divide the amount of CON they've lost by 10, and round down (minimum 0). If the save succeeds, the delver will heal twice as quickly as they would otherwise. This effect will last until they're back to their full CON, or until they wound any natural creature (robots, and creatures described as 'insubstantial and ghostly', 'fiery and demonic', or as looking like a wooden puppet or carving or a doll, don't count).<br><br>If the save fails, the delver doesn't lose CON. Instead, every exit from this area is covered with a wall of thorns, which will take four hours for one human to cut through. Dwarves, elves and hobbits will work twice as fast. Fairies and leprechauns will work half as fast. Any creature trying to walk through it will fall asleep for 1-6 days (like the Wall of Thorns spell, but without any chance of avoiding this effect). If the GM rolls wandering monsters while the thorns are present, they should randomise which exit they come from, and secretly roll a dice:<br><br>* 1-2 they start cutting through the thorns.<br>* 3-4 they try to walk through the thorns and fall asleep.<br>* 5-6 they leave."),
);
$gnum=16;
// if $godd==0, only slots 3 and 4 are used,
// and it's random whether a given deity is a god or goddess.

$poisons=array(
1=> array ("curare",100,"Curare doubles the effect of an edged weapon, after damage reduction for armour and/or shields"),
2=> array ("spider venom",150,"If the damage from a weapon coated in spider venom isn't reduced to zero by armour or shields, the victim will be unaffected in the next combat round, their Hit Point Total will be halved the round after that, and they will be totally paralysed the round after that"),
3=> array ("Hellfire Juice",500,"Any weapon coated in Hellfire Juice (even bashing weapons like clubs) will multiply their damage by 3/2, after damage reduction for armour and/or shields"),
4=> array ("dragon venom",1000,"Dragon venom multiplies the effect of an edged weapon by four, after damage reduction for armour and/or shields"),
);
$poisnum=4;
// 0 is name, 1 is cost, 2 is effect.

$xspells=array(
1=> array ("Ariana's Spectral Aquarium",10,"This spell creates a floating globe of water, filled with twenty ghostly fish. The water is drinkable, and the ghostly fish can be 'eaten'. Each fish has a 1 in 18 chance of being poisonous (roll 2 dice - the fish is poisonous if the two dice add up to exactly 3). A poisonous fish does a number of dice damage equal to the level of the caster. Wearing a holy symbol will grant immunity to the poison. The ghost-fish have no taste or nutritional value, but they allow the eater to fly for 1d3 minutes, or become 1 foot tall for 1d6 minutes (eater's choice). Creatures with cat features will value the globe and ghost-fish at a total of 100gp per level of the caster."),
2=> array ("Bran's Melancholy Vista",20,"Supernatural shadows fill an area 333 yards/metres in diameter (in the open), or 1 level of a dungeon, for one hour. The effective distance of all light sources (even magical ones) will be cut in half. Even in direct sunlight trees and buildings will cast thick, shifting shadows and the light will be like twilight. Generally saving rolls to hide will be 2 levels lower, or saving rolls to notice someone will be 2 levels higher."),
3=> array ("Accalon's Vexatious Globes",10,"Three stones rise from the ground and circle the caster for up to 1 hour. One is blue, and allows the caster to add 3 to all saving rolls they make, except ranged weapon attacks. One is green, and acts as a shield, absorbing two damage. The third is black, and will absorb the first spell cast at the caster, after which it disappears. The stones can be attacked directly: they're about the size of a rabbit or rat, and have 10 hit points and the equivalent of 2 points of armour. The stones mean that the caster effectively takes up twice as much room as they would otherwise."),
4=> array ("Sigrid's Hermetical Cocoon",20,"The caster may trap any single creature, except for statted creatures whose level is higher than the caster, in a magical cocoon. The cocoon will resist all spells, but can be physically attacked. It has 100 hit points, and the equivalent of 2 points of armour. If the cocoon isn't destroyed within 6 hours, the GM should roll a dice to see how the victim emerges:<br>1 Dead<br>2 With 3 dice more CON or MR<br>3 With half the STR or MR.<br>4 With wings (roll again: 1-3 bat-like 4-6 bird-like). They can fly if they're carrying half their Weight Possible or less. If the victim already has wings, they emerge without them.<br>5 As a different person of the victim's kindred (level 1 if relevant), with a desire to serve the caster.<br>6 As a beautiful spray of colours which will last for 7 days, and have a hypnotic effect. All statted creatures who see it must make a save against INT at the caster's level, or watch the colours until they fade."),
5=> array ("Idril's Scintillant Cage",15,"In a circle designated by the caster, no more than 13 yards/metres in radius, spectral crystals grow from the ground and trap anyone within the circle. The effect lasts for 10 minutes. Creatures inside can see and breathe, but can't move. There's a 25% chance that a spell cast into or through the cage will reflect back at the caster."),
6=> array ("Sobekhotep's Audacious Deceit",15,"Roll one dice and multiply by 10 minutes. For that period, any silver object within 20 yards/metres that the caster sees will teleport into their backpack, pockets etc. For each robot or machine, roll 1 dice: on a 6, it contains a vital silver part and is destroyed by this spell. Normal weapons, armour and shields are not made of silver. While the spell is in effect, the caster must treat their CHR as 5 less than its real value when dealing with any creature with bird-like features."),
7=> array ("The Incomparable Banquet of King Ranjit",10,"This spell creates a delicious and huge banquet, more than enough to feed everyone in the room. For the purposes of trading, most creatures will treat the banquet as being worth 80gp. Creatures with hobbit-like features will treat it as worth 120gp. The food is high-quality and nourishing, but doesn't bewitch the eater. For example, someone who is attacked will stop eating in order to defend themselves or run away. If the party is being chased by Monster Rated creatures, there is normally a 2 in 6 chance they'll break off their pursuit to eat the banquet. Statted creatures will normally do the same if they fail a level 0 save on INT - level 1 for creatures with hobbit-like features. The caster may cast the spell in order to eat the banquet themselves. However it creates the kind of food that won't last long and can't easily be transported, such as large cakes, so it's unlikely to provide more than 1 meal per person."),
8=> array ("Sigrid's Indolent Cartography",10,"This spell creates a piece of parchment, with an entirely accurate map on it. The map will depict the current dungeon level, a single settlement, or an area of wilderness centred on the caster (depending on whether the spell is cast in a dungeon, settlement or wilderness). If the spell is used to create a map of wilderness, the area shown will be 56km/35 miles east-west by 80km/50 miles north-south. All maps will show the caster's current location, a key, and a scale. Dungeon maps will show all walls and tunnels, and any exits up or down. Illusory walls will be shown on the map as if they were real walls. The contents of the rooms, such as traps, monsters and treasure, won't be shown. Maps of settlements will include street and district names, and major landmarks. Wilderness maps will show the type of terrain, but no man-made features such as roads or towns. The location of dungeons may or may not be shown on wilderness maps: natural features such as the entrances to cave systems will be, artificial structures won't be."),
);
$xspnum=8;
$elweir=6;
// First $elweir are spells from 'Eldritch Weirdness', converted to T&T.
// 0 = name, 1 = cost, 2 = detailed description.
// these spells have no level (their cost is the same for any caster)

$diplo=array("null","at war","hostile","allied","strongly allied","wary");
$dipnum=5;
$dipused=array();
$dipex=array(
1=> "If the two species come into contact, they'll fight each other or run. If the delvers are perceived as being allied with one species by the other, they'll have a -10 penalty on their CHR rolls. If the delvers present evidence that they've attacked one of the species to the other, they'll have a +6 bonus on their CHR rolls",
2=> "If the two species come into contact, they'll often end up fighting each other. They certainly won't allow the other species to pass through their territory. If the delvers are perceived as being allied with one species by the other, they'll have a -6 penalty on their CHR rolls. If the delvers are being chased by one species, the other will usually shelter them, if only out of spite",
3=> "The two species are quite friendly. They'll at least listen to the other species' opinion and discuss with them if possible, when deciding what to do with the delvers. If the delvers are perceived as being hostile to one species, they'll have a -10 penalty on their CHR rolls when dealing with the other",
4=> "The two species will regard an attack on each other as an attack on them. They'll usually respect the decision of the other species in regard to how to treat the delvers",
5=> "The two species would like to destroy each other, but fear the results of open conflict. If the delvers are perceived as being allied with one species by the other, they'll have a -6 penalty on their CHR rolls. The creatures are likely to help the delvers with any plan which will weaken the other species, but only if they can do so in a way that allows them to deny involvement",
);
if ($system=="ll") {
for ($z=1;$z<=5;$z++) {
$dipex[$z]=str_replace("their CHR rolls","their Monster Reaction rolls",$dipex[$z]);
$dipex[$z]=str_replace("they'll have a -10 penalty on","they must add 5 to",$dipex[$z]);
$dipex[$z]=str_replace("they'll have a -6 penalty on","they must add 3 to",$dipex[$z]);
$dipex[$z]=str_replace("they'll have a +6 bonus on","they can take 3 from",$dipex[$z]);
}
}
$isdiplo=array();

$doing=array(
1=> array ("@sleeping",1,1000),
2=> array ("@having sex",2,1000),
3=> array ("@arguing about their relationship",2,2),
4=> array ("@arguing about politics",2,1000),
5=> array ("@arguing about religion",2,1000),
6=> array ("@arguing about money",2,1000),
7=> array ("@arguing",2,1000),
8=> array ("@gambling with dice",2,1000),
9=> array ("@gambling on a race between small animals (eg snails or rats)",2,1000),
10=> array ("@gambling on a fight between small animals (eg snails or rats)",2,1000),
11=> array ("@re-setting the dungeon: setting up treasure, removing adventurers' bodies and so on"),
12=> array ("@fighting",2,1000),
13=> array ("two of the creatures will be fighting, the others will be cheering them on",5,1000),
14=> array ("two of the creatures will be fighting, the others will be cheering them on and gambling on the result",5,1000),
15=> array ("two of the creatures will be fighting to the death while the others cheer them on",5,1000),
16=> array ("@alert and guarding the area",1,1000),
17=> array ("@trading",2,1000),
18=> array ("@getting drunk and fighting",5,1000),
19=> array ("@recovering from a fight (divide CON or MR by 2)",1,1000),
20=> array ("@exercising",1,1000),
21=> array ("@training for combat",1,1000),
22=> array ("@silently meditating",1,1000),
23=> array ("@about to sacrifice an animal",1,1000),
24=> array ("@about to sacrifice one of their number",5,1000),
25=> array ("@engaging in a solemn religious ritual",4,1000),
26=> array ("@engaging in a boisterous and ecstatic religious ritual",6,1000),
27=> array ("@waiting in ambush for the delvers",1,1000),
28=> array ("@washing",1,1000),
29=> array ("@listening to one of their number tell a story",3,1000),
30=> array ("@listening to one of their number recite a poem",3,1000),
31=> array ("@listening, bored and resentful, as one of their number lectures them",5,1000),
32=> array ("@listening, respectfully silent and attentive, as one of their number lectures them",5,1000),
33=> array ("@plotting against their rulers",2,5),
34=> array ("@playing sport",5,1000),
35=> array ("@lying as if dead, but will spring to life as soon as the delvers enter",1,1000),
36=> array ("@eating",1,1000),
37=> array ("@eating and getting drunk",1,1000),
38=> array ("@getting drunk",1,1000),
39=> array ("@playing <i>Filing & Photocopying</i>, the game of adventure in a strange world where technology is real and magic doesn't work",3,1000),
);
$donum=39;

if (rand(1,2)==1 AND $system=="tt") {
$doing[39][0]=$doing[39][0].". If the delvers end up playing the game, after their first session (which will take 2-12 hours) they will gain 2 INT, but lose 2 CHR";
}

if ($system=="ll") {
$doing[19][0]="@recovering from a fight (treat the HP given as the maximum. For current HP, divide by two and round up)";
}

// determine $questobject, and add it to $entstr
// (needs to be seperate as well, so
// can put it in a room of the dungeon).
if (rand(1,2)==1) {
$questobject="the ".$object[rand(1,$objnum)]." of ".$oname[rand(1,$onames)];
$entstr=$entstr." The heroes are seeking ".$questobject.".";
} else {
for ($z=1;$z<=27;$z++) {
for ($y=1;$y<=3;$y++) {
if ($ancients[$y][$z][1]=="t") {
$ancients[$y][$z][1]=1;
} else {
$ancients[$y][$z][1]=0;
}
}
}
do {
$ok=1;
$questobject="";
$tandm=0;
for ($z=1;$z<=3;$z++) {
$y=rand(1,27);
$questobject.=$ancients[$z][$y][0];
$tandm+=$ancients[$z][$y][1];
}
if ($tandm<1 OR $tandm>2) {
$ok=0;
}
} while ($ok==0);
$questobject="the ".ucwords($questobject);
$entstr=$entstr." The heroes are seeking a lost device of the Ancients - ".$questobject.".";
}

// $level is used for variables which affect individuals -
// for example "characters must make a level x saving roll on Luck..",

// $mr[$x] is the total Monster Rating for a group which
// will be roughly the same power as the party (hopefully), on
// $level $x, for T&T.

// $pow[$x] is the 'power' of species $x, for T&T.
// it's compared to $mr[the current level]
// to see how big the groups should be.
// It also determines the creature's size.

// $rn[$x] is the exact number of areas on level $x.
// $rn[0] is the total number of areas in the dungeon.

// $rb[$x][$y] is the broad type of encounter in
// room $y of level $x.
// $rd[$x][$y] is the string printed out to describe the same room.
// $tr[$x][$y] is the value of the treasure in the same room.
// $mo[$x][$y][0] is the type of creature in the same room.
// $mo[$x][$y][1] is the number of creatures in the same room.

// $shrine[$x] is whether the xth god has at least 1 shrine.
// $snum[$x] is how many shrines the xth god has in the dungeon.
// need both $shrine and $snum, because $shrine temporarily uses value
// 2, to indicate 'have rolled on this level, but doesn't increase
// likelihood until next level'.

// $traps[1-$trapnum] is the details of different traps.

// $mwidth is the maximum width that the dungeon can be
// (so it won't print off the page)

// for species $x, $stats[$x][0] is either
// 1 (for Monster Rated monsters), or
// 2 (for statted monsters).
// 1: $stats[$x][1] is the MR. $stats[2-8] aren't used.
// 2: $stats[$x][1-7 or 8] is the number for each stat.

// $crmag[$x][$y] is 1 if species $x knows spell $y.

// $splus is only used for statted monsters -
// it's the adds. $splus[$x][$y] is used with $stats[$x][$y].

// $crlang[$x][$y] is whether creature number $x speaks language $y.

// $crarmour[$x][1-4] defines whether the species ever
// wears armour, and if so what its characteristics are:

// $crsize[$x] is a number from 1-6
// (matched to $sizetext[that number][1]),
// giving what size the creature is.
// $sizetext[$y][0] is a number, compared to a number generated by
// each creature based on its stats, to see what size it is.
// $sizetext[$y][1] is a description "this creature is roughly..."
// $sizetext[$y][2] is the plural "remember that...can use its armour"
// $sizetext[$y][3] is the DEX roll to hit it at point-blank range
// based on 5th edition.

// $mrtype are only used for Monster Rated monsters -
// it governs how their stats respond to losing MR.
// used in conjunction with $mrdesc

// $shallow[$x] and $deep[$x] give the range
// of levels where species $x can be found.

// $desc[$x] is the description of species $x: what it looks like,
// and any special combat abilities (except that in $mrtype[$x]).

// $htoh[$x] is set to 1 if species $x is a standard creature
// which won't have weapons or armour (ie one which begins with "+").

// $lclimate[$x] is the climate on level $x.

// $rv - room variance: by what % can the number of areas on a level
// vary from $r.

// $sp - on average, should be a different species for each $sp areas.

// $sn - how many species in the dungeon.

// $grp[$x][$y] is the average size of a
// group of members of species $x on level $y.

// $enc[$x][$y] is how many areas have species $x on level $y.

// $enc[$species][$level] is how many areas have species $species on level $level.

// $wmtable[$level][0] is the number of monsters
// who appear on level $level.
// $wmtable[$level][$species] is the number of 'slots' that
// monster $species has in the w.m. table for level $level.
// if creature $species's territory includes level $level
// (based on $deep[$species] and $shallow[$species]), then
// $enc[$species][$level]+$wmtable[$level][$species] must be >0.

// if creature $x's territory includes level $y (based on $deep[$x]
// and $shallow[$x]), then $enc[$x][$y]+$wmtable[$y][$x] must be >0.

// this one must be first in the list in order
// for 'while in this form' to make sense.
if (str_replace("revert","XXX",$y)<>$y AND $stats[$x][0]==2 AND rand(1,2)==1) {
do {
$att1=$sname[rand(1,$attnum)];
$att2=$sname[rand(1,$attnum)];
$att3=$sname[rand(1,$attnum)];
} while ($att1==$att2 OR $att2==$att3 OR $att3==$att1 OR $att1=="CON" OR $att2=="CON" OR $att3=="CON");
$y=$y." While in its true form, its ".$att1." ";
if (rand(1,2)==1) {
$y=$y."is doubled, but its ".$att2." and ".$att3." are";
} else {
$y=$y."is multiplied by 3/2, but its ".$att2." is";
}
$y=$y." halved (round down for both).";
}

// this one likewise.
if (str_replace("statue","XXX",$y)<>$y) {
if (rand(1,3)==1) {
if (str_replace("statue^","XXX",$y)<>$y) {
if (str_replace("statue^^","XXX",$y)<>$y) {
$z=str_replace("a ","",$an);
$z=str_replace("an ","",$z);
$y=$y." In death, its corpse will look like that of a normal ".$z.".";
} else {
$z=str_replace("a ","",$pl);
$z=str_replace("an ","",$z);
$y=$y." If it dies, its corpse will look like a normal ".$z.".";
}
} else {
$y=$y." In death, it will look like a normal corpse rather than a statue.";
}
} elseif (rand(1,2)==1) {
$y=$y." If it dies, its corpse will be indistinguishable from an actual statue. It will be worth ";
$y=$y.($level[rand($shallow[$x],$deep[$x])]*100*rand(1,6));
$y=$y." gold pieces, and weigh the same as ";
$y=$y.(rand(75,350)*10);
$y=$y." coins.";
} else {
$y=$y." If it dies, its corpse will wither until all that's left is a single ";
$a=rand(1,$jnum);
$b=rand(1,4);
$base=$jewel[$a][1];
if ($base<25) {
$y=$y."semi-";
}
$y=$y."precious stone (".$jewel[$a][0].", weighing the same as ";
if ($b==1) {
$y=$y."a coin";
} else {
$y=$y.$b." coins";
}
$y=$y." and worth ".($b*$base)." gold pieces).";
}
}
}

// for any system.
$y=str_replace("^","",$y);
$y=str_replace("the disembodied head of a skeleton","a disembodied skull",$y);
$y=str_replace("a child's doll of a human child","a child's doll",$y);

if ($system=="tt") {
$a=rand(1,10);
if ($a==1) {
do {
$z=$sname[rand(1,$attnum)];
} while ($z=="CON" OR ($spd==0 AND $z=="SPD"));
$y=$y."<br><br>Half the damage that this creature does (rounded down) comes off ".$z." instead of CON.";
if ($z=="STR") {
$y=$y." If this brings a delver's STR below the amount they need to wear their armour, they'll collapse on the floor and be unable to act, but not suffer any damage. The creature will ignore them until and unless all other delvers have been dealt with. If it means they can't use their shield, they'll get no benefit from the shield and their shield arm will be useless, but again they won't suffer any damage.";
}
if ($z=="STR" or $z=="DEX") {
$y=$y." If a delver can no longer use their weapon, they'll drop it.";
}
} elseif ($a==2) {
$y=$y."<br><br>For any Combat Round where one of these creatures does any damage, and at least one of their opponents is wearing armour (shields don't count), roll 1 dice.<br><br>1-2 Treat the damage as normal.<br>3-4 Armoured opponents take no damage, but their armour permanently absorbs 1 less damage. If it now absorbs no damage, it will fall off.<br>5-6 Armoured opponents take no damage.";
} elseif ($a==3) {
$y=$y."<br><br>If this creature does any damage to an opponent who isn't wearing any armour (and the damage isn't reduced to zero by a shield) that opponent takes an extra ".max(2,$level[rand($shallow[$x],$deep[$x])])." points of damage.";
} elseif ($a==4) {
$y=$y."<br><br>If this creature does hand-to-hand damage to a single character who knows any spells, and the damage isn't reduced to zero by armour and shields, that character has a ".(rand(1,5))." in 6 chance of forgetting a single randomly-chosen spell instead of taking the damage. Rogues can forget any spell. Wizards can forget any spell of level 2 or above (if they don't know any, they'll take the damage instead). The character will be able to re-learn the spell.";
}
$armour=0;
if (str_replace("robot","XXX",$y)<>$y) {
$armour+=rand(1,3);
}
if (str_replace("turtle","XXX",$y)<>$y) {
$armour+=rand(1,3);
}
if (str_replace("statue","XXX",$y)<>$y) {
$armour+=rand(1,3);
}
if (str_replace("scarab","XXX",$y)<>$y) {
$armour+=rand(1,3);
}
if (str_replace("rhino","XXX",$y)<>$y) {
$armour+=rand(1,3);
}
if (str_replace("triceratops","XXX",$y)<>$y) {
$armour+=rand(1,3);
}
if (str_replace("doll","XXX",$y)<>$y) {
$armour=0;
}
$z=$level[rand($shallow[$x],$deep[$x])];
$a=rand(1,6);
$toughskin=0;
if ($armour>0 AND $z>$a) {
$toughskin=$armour+$z-$a;
$y=$y."<br><br>Its tough skin acts as armour, stopping ".($armour+$z-$a)." points of damage.";
}

if (str_replace("animated corpse","XXX",$y)<>$y OR str_replace("disembodied","XXX",$y)<>$y) {
$z=$level[rand($shallow[$x],$deep[$x])];
$z=rand(0,$z);
$y=$y."<br><br>On first meeting the creature, or a group of the creatures, all delvers must make a level ".$z." save on ";
if ($wiz==1) {
$y=$y."WIZ";
} else {
$y=$y."INT";
}
$y=$y.". Any delvers who fail will have to subtract the amount they failed by from any saving rolls, or rolls to generate a Hit Point Total, that they make when dealing with the species. Each time a delver who failed meets a different member of this species (or group of them), they may make the save again, and take the better result.";
}

$wooden=0;
if (str_replace("wood","XXX",$y)<>$y) {
$wooden=1;
}

if (str_replace("tree","XXX",$y)<>$y AND str_replace("statue","XXX",$y)==$y AND str_replace("ghost","XXX",$y)==$y AND str_replace("robot","XXX",$y)==$y) {
$wooden=1;
}

if ($wooden==1 AND rand(1,2)==1) {
$z=$level[rand($shallow[$x],$deep[$x])];
$z=rand(0,$z);
$y=$y."<br><br>If this creature";
if (str_replace("true form","XXX",$y)<>$y) {
$y=$y." reverts to its true form, and in that form it";
}
$y=$y." loses a Combat Round against a delver with a bladed or pointed weapon and survives, there's a ";

// 'a head' rather than 'head', because of 'disembodied head'.
if (str_replace("waist","XXX",$y)==$y AND str_replace("a head","XXX",$y)==$y) {
$y=$y."50%";
$a="their wooden";
} else {
$y=$y."1 in 3";
$a="the wooden part of their";
}
$y=$y." chance that the weapon will get stuck in ".$a." body. If it does, a delver can try and pull it out. This takes the delver the whole round. The delver must make a level ".$z." save against the higher of STR or DEX. If they fail by more than 5, or roll a critical failure, the weapon breaks. If they succeed by more than 5, the creature takes damage as if they'd been hit again with the weapon (this doesn't count towards the party's Hit Point Total). If they succeed by more than 10, the creature splits in two and dies.";
}

if (str_replace("robot","XXX",$y)<>$y OR str_replace("ghost","XXX",$y)<>$y OR str_replace("animated corpse","XXX",$y)<>$y OR str_replace("demon","XXX",$y)<>$y OR str_replace("statue","XXX",$y)<>$y) {
$poison=$level[rand($shallow[$x],$deep[$x])];
$z=rand(1,6)+rand(1,6);
if ($poison>$z) {
$y=$y."<br><br>This creature is completely immune to poison.";
} elseif (($poison*2)>$z) {
$y=$y."<br><br>Every time this creature is wounded by a poisoned weapon, they have a 50% chance of suffering no ill effects from the poison.";
}
}

$rcommand=0;
if ((str_replace("robot","XXX",$y)<>$y AND rand(1,3)==1) OR (str_replace("puppet","XXX",$y)<>$y AND rand(1,2)==1)) {
$y=$y."<br><br>Delvers can attempt to command these creatures if they share a language with them. They must ";
$rcommand=1;
if ($stats[$x][0]==1) {
$z=$level[rand($shallow[$x],$deep[$x])];
$z=rand(0,$z);
$y=$y."make a level ".$z." save on CHR. The delver subtracts two from their roll for each of the creatures present. If they make the roll,";
} else {
$y=$y."roll two dice, with doubles adding and rolling over, and add their CHR. The creatures do the same with their INT. If the delver's total is higher than any single creature's total,";
}
$y=$y." the creatures will obey the delver without question for an hour. Otherwise, all creatures present will be 'immune' to further attempts for two hours.";
$y=$y." A failed attempt, or a successful attempt which 'runs out', won't affect normal diplomacy with the creatures. However the delvers' treatment of them while they're under command can have a negative effect.";
}

if (str_replace("robot","XXX",$y)<>$y) {
if (rand(1,6)==1) {
$y=$y."<br><br>These creatures regard vending machines as gods. They'll stop anyone trying to break into them, at the risk of their own lives. ";
if ($rcommand==1) {;
$y=$y." This applies even if they're under the command of the delver trying to break in - although once the delver stops they'll still obey them. ";
}
$y=$y."They'll also want to put at least some money into the machines every time they pass one. If they're with a group of delvers who refuse, for the next 24 hours the creature will treat the delvers as if their CHR was 2 points lower than its real value. This penalty is added each time the delvers refuse to 'make an offering to the god' - even if the delvers pass the same machine several times.";
} elseif (rand(1,5)==1) {
$y=$y."<br><br>These creatures regard vending machines as hateful oppressors. They'll always try to break into them when they see one. They'll attack anyone on sight who tries to put money into one, or even mentions having done so.";
if ($rcommand==1) {
$y=$y." This applies even if they're under the command of the delver trying to put money in - although once the delver stops they'll still obey them.";
}
}
}

if ((str_replace("scorpion","XXX",$y)<>$y AND str_replace("disembodied","XXX",$y)==$y) OR (str_replace("snake","XXX",$y)<>"$y" AND rand(1,2)==1)) {
$poison=$level[rand($shallow[$x],$deep[$x])];
$z=rand(1,6)+rand(1,6);
if ($poison>$z*2) {
$y=$y."<br><br>This creature's weapons are poisoned. If it wins a Combat Round, it does double damage <i>after</i> the damage is reduced by armour and shields.";
} elseif ($poison>$z*1.5) {
$y=$y."<br><br>This creature's weapons are poisoned. If it wins a Combat Round, it does 1.5 times normal damage <i>after</i> the damage is reduced by armour and shields.";
} elseif ($poison>$z) {
$y=$y."<br><br>This creature's weapons contain a mild poison. If it wins a Combat Round, and a delver doesn't reduce its damage to zero with armour and shield, they become sick. While sick, they don't recover any attributes from normal healing. Every four hours they may make a level ".$z." save on CON. If they succeed, they're no longer sick.";
}
}
}

$rw=rand(1,$rangenum);
if ($stats[$x][1]>=$rangew[$rw][3] AND $stats[$x][5]>=$rangew[$rw][4] AND str_replace("disembodied","XXX",$desc[$x])==$desc[$x] AND $htoh[$x]<>1) {
$rww=$rangew[$rw][7];
$am=$rangew[$rw][5];
if ($am<>"self") {
$rww+=$ammo[$am][2];
}
if ($stats[$x][1]*100>=$ww+$rww) {
$ww+=$rww;
$wname=$rangew[$rw][0];
print "They'll also carry a ".$wname." (";
if ($wname<>"bullwhip") {
print $rangew[$rw][1]." dice + ".$rangew[$rw][2].", ";
}
print "used ".$rangew[$rw][9]."-handed, min. STR ".$rangew[$rw][3]." DEX ".$rangew[$rw][4].", range ".$rangew[$rw][8]." yards/metres, weight ".$rangew[$rw][7]." value ".$rangew[$rw][6]."gp)";
if ($wname=="bullwhip") {
print "<br><br>Wizards can't use bullwhips. Bullwhips do no damage. Instead, the creature wielding it can try and wrap it around an opponent's weapon and pull the weapon out of their hands (it's no use against an opponent fighting with fists, claws etc). To do this, they make a DEX saving roll as if they were using a missile weapon. However, if the victim has a shield, the difficulty of the roll is increased by the damage reduction of the shield (armour doesn't have any effect).<br><br>If the attacker makes the save, they compare their STR to the STR of their opponent. If the target weapon is 1-handed, and the attacker's STR is at least half that of the defender, the defender's weapon is yanked out of their hand. If the target weapon is 2-handed, the bullwhip wielder's STR must be at least equal to the opponent's STR. In either case, if the attacker's STR isn't high enough the attack has no effect.";
} elseif ($wname=="pistol") {
print "<br><br>Pistols are mechanical contrivances of the gnomes. They fire anything that's put in them (stones, bits of metal etc). Their range is effectively limitless: if you can see it you can shoot at it. However, if the range is more than 50 yards/metres the shooter rolls on LK rather than DEX, and uses LK adds rather than DEX adds to modify damage. If the shooter's roll to hit is a critical failure, they should roll 2 dice:<br>2-3: The weapon starts to fire late, and will do so until it's unloaded and re-loaded. If this is done in combat, it will take an entire Combat Round. Until then, add 1 to the level of all saving rolls to hit.<br>4-6: The pistol is jammed. It must be unloaded and re-loaded before it can be used again. This will take the whole of the next Combat Round.<br>7-8: It gives a flash and a bang, but doesn't shoot. The shooter should make a level 1 saving roll on INT. If they make it, treat as '2-3' above. If they fail, they instinctively look down the barrel to see what the problem is - the weapon then goes off, and the shooter takes full damage, not reduced by armour or shields.<br>9-10: The weapon doesn't shoot - this Combat Round is wasted.<br>11: The pistol jams, and will be unusable until it's repaired (the gnomes are the only ones who know anything about these devices).<br>12: The pistol explodes, and the weapon's user takes the full dice and adds of the weapon in damage (reduced by armour but not shields).";
}
if ($am<>"self") {
print ", and ".$ammo[$am][0]." (weight ".$ammo[$am][2]." total value ".$ammo[$am][1]."gp)";
}
print $line;
}
}
}
if ($stats[$x][0]==2) {
$int=$stats[$x][2];
if ($int>12) {
$lang=min($langnum,$int-12);
} else {
$lang=1;
}
} else {
$lang=min(rand(1,3),rand(1,3));
}
}

if ($crarmour[$x][0]>0 AND $htoh[$x]<>1 AND $system=="tt") {
$ghostprint=0;
if (str_replace("ghost","XXX",$desc[$x])<>$desc[$x]) {
$ghostprint=rand(1,3);
}
if ($stats[$x][0]==1 OR ($stats[$x][1]>=$crarmour[$x][2] AND $stats[$x][1]*100>=$crarmour[$x][3]+$ww)) {
print "These creatures wear ";
if (str_replace("disembodied","XXX",$desc[$x])<>$desc[$x]) {
print "a helmet";
} else {
print "armour";
}
print " which absorbs ".$crarmour[$x][1]." damage";
if ($toughskin>0) {
print " (a total of ".($toughskin+$crarmour[$x][1])." with their tough skin)";
}
if ($ghostprint==1) {
print ".";
} else {
print ", weighs the same as ".$crarmour[$x][3]." coins, and is worth ".$crarmour[$x][4]." gold.";
if ($crsize[$x]<3 OR str_replace("disembodied","XXX",$desc[$x])==$desc[$x]) {
print " It requires ".$crarmour[$x][2]." STR for a non-Monster-Rated creature to wear.";
}
}
}
print $line;
if ($ghostprint==1) {
print "If this creature is 'killed', its armour will fade away with it.";
} elseif ($ghostprint==2) {
print "If this creature is 'killed', its armour will retain some traces of magic. Any statted creature who tries to wear its armour must make a level ";
$tlev=$level[rand($shallow[$x],$deep[$x])];
print rand(0,$tlev)." save on ";
if ($wiz==1) {
print "WIZ";
} else {
print "CHR";
}
print ". If they fail, they take the difference in damage - half, rounded down, coming off LK - and can't put the armour on. If they succeed, they can wear the armour safely from then on. ";
} elseif ($ghostprint==3) {
print "If this creature is 'killed', its armour will become substantial and may be worn. ";
}
if (str_replace("demon","XXX",$desc[$x])<>$desc[$x]) {
if (rand(1,3)==1) {
print "If this creature is 'killed', its armour will forever retain some of the foul odour of the abyss. Anyone who wears it will have ".(3+$level[rand(1,$l)])." less CHR while they wear it, and afterwards until they've bathed. ";
} elseif (rand(1,2)==1) {
print "If this creature is 'killed', its armour will forever retain some of the heat of the inferno. Any statted creature who tries to wear its armour must make a level ";
$tlev=$level[rand($shallow[$x],$deep[$x])];
print rand(0,$tlev)." save on ";
if ($wiz==1) {
print "WIZ";
} else {
print "CON";
}
print ". If they fail, they take the difference in damage - half, rounded down, coming off CHR - and can't put the armour on. If they succeed, they can wear the armour safely from then on. ";
}
}
if ($ghostprint<>1) {
if (str_replace("disembodied","XXX",$desc[$x])==$desc[$x]) {
if ($sizetext[$crsize[$x]][2]<>"XXX") {
print ucfirst($sizetext[$crsize[$x]][2]).", and c";
} else {
print "C";
}
print "reatures described as '".$sizetext[$crsize[$x]][1]."', can wear these creatures' armour.";
} elseif ($crsize[$x]<3) {
if ($sizetext[$crsize[$x]+4][2]<>"XXX") {
print ucfirst($sizetext[$crsize[$x]+4][2]).", and c";
} else {
print "C";
}
print "reatures described as '".$sizetext[$crsize[$x]+4][1]."', can wear these creatures' helms.";
} else {
print "These creatures' helmets are too large for anyone to wear (but the delvers can still sell them, for example to wizards, bored nobles looking for novelty cooking pots, and people who find the phrase 'these creatures' helmets are too large for anyone' hilarious).";
}
}
print $line;
}
if ($spt[$x]>0) {
print "This creature alters the air wherever it goes. It will always be <i>".$climates[$spt[$x]]."</i> in the presence of this creature.";
print $line;
print "If two creatures who alter the air meet, compare their ";
if ($system=="ll") {
print "Hit Dice (use current Hit Points to break ties)";
} else {
print "CHR ";
if ($wiz==1) {
print "or WIZ, whichever's higher ";
}
print "for statted creatures, or MR divided by ".(7+$wiz)." for Monster-Rated creatures";
}
print ". The one with the highest number will affect the air.";
print $line;
print "Changing the air in this way doesn't alter how often the GM should roll for wandering monsters.";
print $line;
}
}
print $line;
if ($system=="tt" and $fullstat==1) {
print "<b>Using Dungeon Species In Other Adventures</b>";
print $line;
print "If you want to give the statted creatures of the dungeon individual attributes (for example to use them as player characters), use the following multipliers:";
print $line;
print "<table border=4 cellspacing=4 cellpadding=4>";
print "<tr><td>Species</td>";
for ($y=1;$y<=$attnum;$y++) {
print "<td>".$sname[$y]."</td>";
}
print "</td></tr>";
for ($z=1;$z<=$sn;$z++) {
if ($stats[$z][0]==2) {
print "<tr><td>".$crname[$z]."</td>";
for ($y=1;$y<=$attnum;$y++) {
print "<td>x ";
$a=max(1,round($stats[$z][$y]/2.625));
if ($a%4==0) {
print ($a/4);
} elseif ($a%2==0) {
print ($a/2)."/2";
} else {
print $a."/4";
}
print "</td>";
}
print "</tr>";
}
}
print "</table>";
print $line;
print $line;
}
print "<b>Mission</b>";
print $line;
print $entstr;
print $line;
print $line;
print "<b>Diplomacy:</b>";
print $line;
if ($system=="tt") {
print "When a delver is negotiating with one of the creatures in the dungeon, unless the GM decides otherwise they should make a CHR check, at the level listed below.";
print $line;
print "Success means that the creatures will allow the delvers to move through their territory.<br>";
print "Beating the target number by at least 6 means that the creatures will actively aid the delvers - for example, they may share their food.<br>";
print "Beating the target number by at least 12 means that the creatures will go to some risk for the delvers - for example, one of them might act as a guide.<br>";
print "Failure means that the creatures will tell the delvers to return the way they came at once, and fight them if they don't.<br>";
print "Missing the target number by at least 6 means that the creatures will attack, without giving the delvers the opportunity to leave.";
} elseif ($system=="ll") {
print "When one of the party is negotiating with one of the creatures in the dungeon, unless the GM decides otherwise they should roll on the Monster Reaction Table (p52 of Labyrinth Lord, or p45 of Mutant Future). The roll is modified based on the party member's Charisma. There are also modifiers listed below for each species in the dungeon.<br><br>The creatures in the dungeon won't treat mutants differently. Don't use the 'Charisma and Racial Modifier Table' on p11 of Mutant Future.";
print $line;
print "A result of 'Friendly, helpful' means that the monsters will actively help the party. For example, they might share their food. If the result is zero or less (obviously only possible with adjustments to the roll), the monsters will go to some risk for them. For example, one of them might act as a guide.<br>";
print "A result of 'Indifferent, uninterested' means that the monsters will allow the party to move through their territory. If they want, the party can continue negotiating with them, making a new roll. They don't get any bonuses for any gifts they originally gave, but can give more.<br>";
print "A result of 'Neutral, uncertain' means that the monsters will allow the party to move through their territory as above. The difference is that with this result, and the two below, the monsters won't be interested in further negotiation.<br>";
print "A result of 'Unfriendly, may attack' means that the monsters will tell the party to return the way they came at once, and fight them if they don't.<br>";
print "A result of 'Hostile, attacks' means that the monsters will attack the party, without giving them a chance to leave.";
print $line;
print "If the party successfully negotiates with a group of monsters, they should get the same XP they would have gotten for defeating them. However, if the party gave any gifts to the monsters, the XP value of the gifts is subtracted from this. If this results in the encounter having a negative XP value, raise it to zero.";

// find average hoard values for monster groups on each level.
for ($z=1;$z<=$l;$z++) {
$a=0;
$b=0;
for ($y=1;$y<=$sn;$y++) {
if ($shallow[$y]<=$z AND $deep[$y]>=$z) {
$a++;
$b+=$treasuretypes[$lhoard[$y]][1];
}
}
$llavtr[$z]=$b/$a;
}
}
print $line;
print "If the delver lacks a common language with the creatures, as well as the penalties listed below they'll find it difficult or impossible to exchange any complex information.";
print $line;
for ($z=1;$z<=$sn;$z++) {
print "(".$z.") ".$crname[$z].", or ".$crnick[$z];
if ($z<=$standardused) {
print " (".$stplural[$standardsn[$z]].")";
}
print $line;
$host=$level[rand($shallow[$z],$deep[$z])];
if ($system=="tt") {
print "CHR save at level ".$host.".<br>";
print "Add 1 to the delver's roll for each ";
$avtr=$level[rand($shallow[$z],$deep[$z])]*rand(70,100)*$c;
// this should be the average treasure
// value of one group of monsters.
} elseif ($system=="ll") {
$host=$host-4;
if (rand(1,2)==1) {
$host=rand(-2,2);
}
if ($host>0) {
print "Add ".$host." to the Monster Reaction roll, but take 1 from the roll for each ";
} elseif ($host<0) {
print "Take ".-$host." from the Monster Reaction roll, and another 1 for each ";
} else {
print "Take 1 from the Monster Reaction roll for each ";
}
// LL/MF gift value goes here.
$avtr=$llavtr[rand($shallow[$z],$deep[$z])];
$avtr=$avtr*rand(80,120)/100;
$avtr=max(100,$avtr);
}
$avtr=$avtr/5;
$avtr=round($avtr/10)*10;
print $avtr."gp worth of gifts the adventurers give.<br>";
if ($system=="tt") {
if (rand(1,2)==1 AND $stats[$z][0]==2) {
print "If the delver's ";
do {
$a=$sname[rand(1,$attnum)];
} while ($a=="CHR");
print $a." is higher than the creatures', the delver can add ".rand(5,10)." to their roll.<br>";
}
print "If the delvers lack a common language with the creatures, they should take ".(rand(1,6)+rand(1,6))." from their roll.";
} elseif ($system=="ll") {
print "They'll treat magic items ";
if (rand(1,2)==1) {
print "and technological artifacts as if they had a value of ".(rand(80,120)*10)."gp.<br>";
} else {
print "as if they had a value of ".(rand(80,120)*10)."gp, and technological artifacts as if they had a value of ".(rand(80,120)*10)."gp.<br>";
}
print "If the party member lacks a common language with the monsters, they should add ".(rand(1,6)+rand(1,6))." to their roll.";
}
print $line;
}
print "For the purposes of trading and giving gifts, the creatures of the dungeon will treat ".$questobject." as if it had a value of ";
if ($system=="tt") {
print ($level[$l]*1000);
} elseif ($system=="ll") {
print round ($llavtr[$l]/10)*10;
}
print " gp.";
print $line;
print $line;

// make one or more of the tunnels on level 1 into 'entrances/exits'.
$difent=rand(1,round($exit[1][0]/2));
for ($z=1;$z<=$difent;$z++) {
do {
$y=rand(1,$exit[1][0]);
} while ($exit[1][$y]<>"");
if ($z==1) {
$exit[1][$y]="This is the entrance the delvers will find or be shown.";
} else {
$exit[1][$y]="This is another entrance to / exit from the dungeon.";
}
$oddeven=1-$oddeven;
}

// wandering monsters.
$donmon=0;
if (rand(1,3)==1) {
$ttt=$ttt."This tunnel is never used. There's no need to roll for wandering monsters while in here.";
$donmon=1;
} elseif (rand(1,2)==1 AND $d<>$d2) {
// is there any species that lives on both levels?
// if so, choose such a species.
// group size is anything in range defined by
// $grp of both levels.

// who can tell if changing levels?
if ($d<>$d2) {
$diff=rand($level[$d],$level[$d2]);
$diff=rand(round($diff/2),$diff);
$slev=($level[$d]+$level[$d2])/2;
if (rand(1,2)==1) {
$slev=ceil($slev);
} else {
$slev=floor($slev);
}
$slev=8+rand(1,2*$slev);
if (rand(1,12)==1) {
if ($system=="tt") {
$ttt=$ttt." This tunnel is enchanted so that delvers other than dwarves won't notice it's going up or down unless they make a level ".$diff." save on ";
if ($wiz==1) {
$ttt=$ttt."WIZ.";
} else {
$ttt=$ttt."INT.";
}
} elseif ($system=="ll") {
$ttt=$ttt." This tunnel is enchanted so that the party might not notice that it's going up or down. The GM should secretly ";
if (rand(1,2)==1) {
$ttt=$ttt." make a Save vs Spells, using the highest save in the party. If the save fail";
} else {
$ttt=$ttt." roll on the Mental Attack Table (Mutant Future, p55), with the Attacker's Will being ".$slev." and the Defender's Will being the highest value in the party. If the attack succeed";
}
$ttt=$ttt."s, non-Dwarf members of the party won't notice the tunnel sloping. The GM should roll 1d6 for each Dwarf in the party, if any. They will notice on a 1 or 2.";
}
} elseif (rand(1,11)==1) {
if ($system=="tt") {
$ttt=$ttt." This tunnel is enchanted so that delvers other than dwarves won't notice it's going up or down - and dwarves will only notice if they make a level ".$diff." save on ";
if ($wiz==1) {
$ttt=$ttt."WIZ.";
} else {
$ttt=$ttt."INT.";
}
} elseif ($system=="ll") {
$ttt=$ttt." This tunnel is enchanted so that non-Dwarf members of the party won't notice it's going up or down. Dwarves will only notice if ";
if (rand(1,2)==1) {
$ttt=$ttt."the GM rolls a 1 or 2 on 1d6";
} elseif (rand(1,2)==1) {
$ttt=$ttt."they make a Save vs Spells (the GM should secretly roll for them)";
} else {
$ttt=$ttt."they successfully defend against a Mental Attack, counting the Attacker's WIL/WIS as ".$slev." (the GM should secretly roll on the Mental Attack Table on p55 of Mutant Future)";
}
$ttt=$ttt.". If there's more than one Dwarf in the party, roll for each one.";
}
} elseif (rand(1,3)==1) {
if (rand(1,30)>$ttgap) {
if (rand(1,30)>$ttgap) {
if ($system=="tt") {
$ttt=$ttt." This tunnel slopes so subtly that delvers other than dwarves won't notice it's going up or down - and dwarves will only notice if they make a level ".$diff." save on INT.";
} elseif ($system=="ll") {
$ttt=$ttt." This tunnel slopes so subtly that party members other than Dwarves won't notice it's going up or down - and Dwarves will only notice on a 1 or 2 on 1d6.";
}
} else {
if ($system=="tt") {
$ttt=$ttt." This tunnel slopes so subtly that delvers other than dwarves won't notice it's going up or down unless they make a level ".$diff." save on INT.";
} elseif ($system=="ll") {
$ttt=$ttt." This tunnel slopes so subtly that party members other than Dwarves only have a 2 in 6 chance of noticing that it's going up or down (Dwarves will notice 100% of the time).";
}
}
}
}
}
$e1=$e1.$ttt;
$e2=$e2.$ttt;

// warning for tunnels between distant levels.
if (abs($d-$d2)>rand(1,3)) {
do {
$z=rand(1,$sn);
} while ($shallow[$z]>min($d,$d2) OR $deep[$z]<min($d,$d2));
do {
$y=rand(1,$langnum);
} while ($crlang[$z][$y]<>1);
$warn=" There's a warning painted on the wall of the area leading to the tunnel, in ".$language[$y].".";
if ($d>$d2) {
$e2=$e2.$warn;
} else {
$e1=$e1.$warn;
}
}

$stairs[$z][$r1]=$stairs[$z][$r1]."<br><br>A ".$a." leads down to room ".$newroom.". The journey takes ".$tt." minutes. For wandering monsters, count the stairs as part of level ".($z+1).".";
if ($system=="tt") {
$stairs[$z][$r1]=$stairs[$z][$r1]." If 'gigantic' wandering monsters are generated, they'll be at the bottom rather than on the stairs.";
}
$stairs[$z][$r1]=$stairs[$z][$r1].$ext;

$stairs[$z+1][$r2]=$stairs[$z+1][$r2]. "<br><br>A ".$a." leads up to room ".$oldroom.". The journey takes ".($tt*7/5)." minutes. For wandering monsters, count the stairs as part of level ".($z+1).".";
if ($system=="tt") {
$stairs[$z+1][$r2]=$stairs[$z+1][$r2]." If 'gigantic' wandering monsters are generated, they'll be at the top rather than on the stairs.";
}
$stairs[$z+1][$r2]=$stairs[$z+1][$r2].$ext;
}
}

// fill $rb ie rooms,
// and generate monsters (can't be done room-by-room, because
// of requirement that as many monsters as possible appear).

// adjust wandering monster table so that it
// has a number of slots exactly equal to $levgoal.
while ($wmtable[$x][0]<>$levgoal[$x]) {
do {
$z=rand(1,$sn);
} while ($wmtable[$x][$z]<1);
if ($levgoal[$x]>$wmtable[$x][0]) {
$wmtable[$x][0]++;
$wmtable[$x][$z]++;
} else {
$wmtable[$x][0]--;
$wmtable[$x][$z]--;
}
}

}

if ($monstrooms>0 AND $system=="tt") {
// define $levmt - it can be 1,2, or 3.
// 1: there aren't enough areas for all the monsters -
// every monster type can appear only in 1 room, or
// in no rooms if they're on the w.m. table.

// 2: every monster that makes its home on this level is
// in the wandering monster table -
// areas can be assigned randomly.

// 3: any other situation -
// monsters are assigned randomly, but it's then checked.

if ($rb[$x][$y]==4) {
$rd[$x][$y]="There's a natural pool here. For as long as the delvers stay here the GM should roll for wandering monsters twice as often as usual. But any results of creatures that are robots, 'fiery and demonic', or 'insubstantial and ghostly' should count as no wandering monster. Any robot, or 'fiery and demonic' creature who enters the pool will take ".rand(1,3)." dice worth of damage (reduced by tough skin, but not by armour or shields) each Combat Round.";
} elseif ($rb[$x][$y]==3 OR $rb[$x][$y]==5 OR $rb[$x][$y]==10) {
$anyshrine=1;
if (isset($dedi) AND $y==$dshr[$x]) {
$type=$dedi;
} else {
if ($manygods==0) {
$target=0;
} elseif ($manygods==$gnum) {
$target=1;
} else {
$target=min(1,rand(0,$manygods));
}
do {
$type=rand(1,$gnum);
} while ($shrine[$type]<>$target AND ($shrine[$type]<>2 OR $target<>0));
}
$snum[$type]++;
$a="There's a shrine to ";
if ($godd==0 AND $shrine[$type]==0) {
$gods[$type][2]="the god";
if (rand(1,2)==1) {
$gods[$type][2]=$gods[$type][2]."dess";
}
}
if ($godd==0) {
$a=$a.$gods[$type][2]." of ".$gods[$type][3];
} else {
$a=$a.$gods[$type][0];
}
if ($shrine[$type]<>1) {
$shrine[$type]=2;
}
$rd[$x][$y]=$a." here.";
} elseif ($rb[$x][$y]==11) {
$rwidth=rand(3,12);
$rdepth=$rwidth;
$a="There are no direct threats here. However, malicious spirits that live here might use their magic to disorient the delvers. If the delvers have a compass they'll be safe. If not, the delver with the highest ";
$att=rand(1,3+$wiz);
if ($att==1) {
$a=$a."INT";
} elseif ($att==2) {
$a=$a."CHR";
} elseif ($att==3) {
$a=$a."LK";
} else {
$a=$a."WIZ";
}
$a=$a." should make a level ".rand(max(1,floor($level[$x]/2)),$level[$x])." saving roll. If they fail, the delvers will lose their sense of direction while in this room. When they leave, regardless of which direction they say they want to go in, they'll actually head in a random direction (movement up or down staircases is excepted). Once they reach another room or intersection their sense of direction will return to normal.<br><br>This could result in the delvers believing that the corridor they came down has disappeared behind them.";
$rd[$x][$y]=$a;
}
if ($rb[$x][$y]==5 OR $rb[$x][$y]==10) {
$rd[$x][$y]=$rd[$x][$y]."<br><br>";
}
if ($rb[$x][$y]==2 OR $rb[$x][$y]==5 OR $rb[$x][$y]==9) {
if ($system=="tt") {
do {
$ok=1;
$z=$traps[rand(1,$trapnum)];
if ($x==$l AND str_replace("@@L","XXX",$z)<>$z) {
$ok=0;
}
} while ($ok==0);
if ($spd==1) {
$z=str_replace("@@DS","SPD",$z);
} else {
$z=str_replace("@@DS","DEX",$z);
}
if ($adds==4) {
$z=str_replace("'gigantic' target","'gigantic' target (in 5th edition rules, a level 1 DEX save to hit at point-blank range)",$z);
}
$fd="any delver";
if (rand(1,2)==1) {
$fd=$fd." bigger than a fairy";
}
$z=str_replace("@@FD",$fd,$z);
$a=rand(1,$rn[$x+1]);
$bb=0;
for ($aa=1;$aa<=$x;$aa++) {
$bb+=$rn[$aa];
}
if ($a+$bb>99) {
$rstring=floor(($a+$bb)/10);
$a=chr($rstring+55).($a+$bb-(10*$rstring));
} else {
$a+=$bb;
}
$z=str_replace("@@L",$a,$z);
for ($a=1;$a<=6;$a++) {
$aa=max(0,$level[$x]+rand(1,3)-rand(1,3));
if ($a==6) {
$aa=max(2,$aa);
}
$z=str_replace("@@".$a,$aa,$z);
}
$z=str_replace("@@D",rand(1,4)." dice worth of ",$z);
$z=str_replace("@@TT",$traveltime,$z);
$z=str_replace("@@MD",rand(10,20)+(5*$x),$z);
} elseif ($system=="ll") {
if (rand(1,6)>($level[$x]-2)) {
$z=$lltraps[rand(1,$lltrapnum)];
} else {
$z=$mftraps[rand(1,$mftrapnum)];
}
$dummyx=$level[$x]+rand(1,3)-rand(1,3);
$dummyx=max(1,$dummyx);
$dummyx=$dummyx*10;
$z=str_replace("@XX",$dummyx,$z);
$z=str_replace("@YY",rand(2,5),$z);
$z=str_replace("@UU",rand(1,10),$z);
}
$rd[$x][$y]=$rd[$x][$y].$z;
$z=rand(1,$sn);
if ($shallow[$z]<=$x AND $deep[$z]>=$x) {
$rd[$x][$y]=$rd[$x][$y]."<br><br>Any ".$crname[$z]." (species ".$z;
if ($z<=$standardused) {
$rd[$x][$y]=$rd[$x][$y].": ".$stplural[$standardsn[$z]];
}
$rd[$x][$y]=$rd[$x][$y].") can tell the delvers about this trap.";
}
} elseif ($rb[$x][$y]==6) {
$z=rand(1,4);
if ($z==1) {
$b="Roll periodically for wandering monsters as normal.";
} elseif ($z==2) {
$b="It's rarely used. Roll for wandering monsters only half as often as usual.";
} elseif ($z==3) {
$b="However it's often used. Roll for wandering monsters twice as often as usual.";
} else {
do {
$a=rand(1,$sn);
} while ($wmtable[$x][$a]<1);
$cr=$crname[$a];
$b="It's most often used by the ".$cr;
if (substr($cr,-1)=="s" OR substr($cr,-1)=="x") {
$b=$b."e";
}
$b=$b."s (species ".$a;
if ($a<=$standardused) {
$b=$b.": ".$stplural[$standardsn[$a]];
}
$b=$b."). Roll for wandering monsters as usual. However, if the result is an encounter with any other creatures, there's a 50% chance that the delvers will meet";
if ($grp[$a][$x]==1) {
$b=$b." a";
$f=substr($cr,0,1);
if ($f=="A" OR $f=="E" OR $f=="I" OR $f=="O" OR $f=="U") {
$b=$b."n";
}
}
$b=$b." ".$cr;
if ($grp[$a][$x]>1) {
if (substr($cr,-1)=="s" OR substr($cr,-1)=="x") {
$b=$b."e";
}
$b=$b."s";
}
$b=$b." instead.";
}
$rd[$x][$y]="There are no dangers in this room. ".$b;
} elseif ($rb[$x][$y]==7) {
if ($magshop>0) {
$rd[$x][$y]="If the delvers haven't been to the mysterious shop yet, they'll find it here - refer to the description for <b>".$magshop."</b> for details. If they have already been, this area will be empty (roll for wandering monsters as usual).";
} else {
$z="The first time that the delvers visit this area, they'll find themselves unexpectedly in a shop, tended by what appears to be an elderly ";
if (rand(1,3)==1) {
$z=$z."human";
} elseif (rand(1,2)==1) {
$z=$z."dwarf";
} else {
$z=$z."hobbit";
}
$z=$z." ";
if (rand(1,2)==1) {
$z=$z."woman";
} else {
$z=$z."male";
}
$z=$z.". If the delvers are threatening, the shop and shopkeeper will instantly disappear.<br><br>The shop will have literally everything that it is possible for delvers to buy in your game world. For ridiculous items, for example a large sailing ship, the shopkeeper might 'think they have one left', and 'have to have a look out the back', but the item will always be found. All items will be sold at standard prices. If your campaign has different prices for different areas, use the prices for a very large city. The first time a delver tries to haggle, if any do, they should make a level ";
$z=$z.rand(1,$level[$l]);
$z=$z." save on CHR. If they make it by 10 or more, all items will be sold at 20% off standard price. If they make it by less, items will be sold at 10% off standard price. If they fail by 10 or more, items will be sold at standard price plus 20%. If they fail by a lesser amount, the markup on standard price will be 10%. This single save will apply to all items bought by all delvers.<br><br>Don't roll for wandering monsters while the delvers are in the shop. Nor should any time pass in the outside world.<br><br>If the delvers ask, the shopkeeper will allow them to rest here overnight, on couches out the back. However when they wake up, they'll find shop and shopkeeper gone and themselves back in the dungeon.<br><br>Once the delvers leave, if they return to this area they won't find no trace of shop or shopkeeper.<br><br>Once the delvers leave the dungeon, if they bought anything from the shop, roll one dice (once for all items, not once for each item). On a 1 or 2, the items are perfectly normal. On a 3 or 4, the items turn out to be worthless - swords are really sticks, a delver who thought they were wearing armour has leaves stuck to their clothing with mud, and so on (any benefit they got from the items in the dungeon doesn't cancel though). The delvers will also find any money they spent back in their coin-purse. On a 5 or 6, the items are worthless as for 3 or 4, but the delvers don't get their money back. If they return to the area where the shop was, they'll find the money there.<br><br>The following refers to the area when the shop isn't there:";
$rd[$x][$y]=$z;
for ($z=1;$z<$x;$z++) {
$magshop+=$rn[$z];
}
$magshop+=$y;
if ($magshop>99) {
$rstring=floor(($magshop)/10);
$a=chr($rstring+55).($magshop-(10*$rstring));
}
}
} elseif ($rb[$x][$y]==1 OR $rb[$x][$y]==10) {
$b=$mo[$y][$x][1];
do {
$a=rand(1,$donum);
if ($rb[$x][$y]==10 AND rand(1,3)>1) {
$a=rand(22,26);
}
} while ($doing[$a][1]>$b OR $doing[$a][2]<$b);
$cr=$crname[$mo[$y][$x][0]];
$cn=$mo[$y][$x][1];
if ($cn==1) {
$f=substr($cr,0,1);
if ($f=="A" OR $f=="E" OR $f=="I" OR $f=="O" OR $f=="U") {
$cr="There's an ".$cr;
} else {
$cr="There's a ".$cr;
}
} else {
if (substr($cr,-1)=="s" OR substr($cr,-1)=="x") {
$cr=$cr."e";
}
$cr="There are ".$cn." ".$cr."s";
}
$do=$doing[$a][0].".";
if ($cn>1) {
$do=str_replace("@","they'll be ",$do);
} else {
$do=str_replace("@","it'll be ",$do);
}
$rd[$x][$y]=$rd[$x][$y].$cr." (species ".$mo[$y][$x][0];
if ($mo[$y][$x][0]<=$standardused) {
$rd[$x][$y]=$rd[$x][$y].": ".$stplural[$standardsn[$mo[$y][$x][0]]];
}
$rd[$x][$y]=$rd[$x][$y].") here";
if ($system=="ll") {
$rd[$x][$y]=$rd[$x][$y]." (HP ";
for ($rnu=1;$rnu<=$cn;$rnu++) {
$hp=$hdiceadd[$mo[$y][$x][0]];
if ($hdice[$mo[$y][$x][0]]==0) {
$hp=rand(1,4);
} else {
for ($anu=1;$anu<=$hdice[$mo[$y][$x][0]];$anu++) {
$hp+=rand(1,8);
}
}
$hp=max(1,$hp);
$rd[$x][$y]=$rd[$x][$y].$hp;
if ($rnu<$cn) {
$rd[$x][$y]=$rd[$x][$y].", ";
}
}
$rd[$x][$y]=$rd[$x][$y].")";
}
$rd[$x][$y]=$rd[$x][$y].". When the delvers first enter this area, ".$do;
$crt=$spt[$mo[$y][$x][0]];
if ($crt>0 AND $crt<>$lclimate[$x]) {
$rd[$x][$y]=$rd[$x][$y]."<br><br>Remember that these creatures' presence makes the area <i>".$climates[$crt]."</i>.";
}

if (rand(1,10)==1) {
$paradox=rand(4,6);
while (rand(1,2)==1) {
$paradox=$paradox+(rand(0,1)*2)-1;
}
$rd[$x][$y]=$rd[$x][$y]."<br><br>This area is slightly unstuck in time. Its paradox limit is ".(max(2,$paradox)).". Please refer to the notes at the start of the adventure (under 'Unstuck in Time').";
$unstuck=1;
}

// alter $rwidth and $rdepth if necessary.
$spsz=$sizetext[$crsize[$mo[$y][$x][0]]][0];
$crspace=$spsz*$mo[$y][$x][1]/7.5;
while ($rwidth*$rdepth<$crspace) {
if (rand(1,3)>1) {
$rwidth++;
$rdepth++;
} elseif (rand(1,2)==1) {
$rdepth++;
} else {
$rwidth++;
}
};
$rheight=max($rheight,$spsz/15);
}
if ($rb[$x][$y]==9) {
$rd[$x][$y]=$rd[$x][$y]."<br><br>";
}
if ($rb[$x][$y]==8 OR $rb[$x][$y]==9) {
$z="There's a hireling vending machine here, belonging to the Koka Kobold Company. It dispenses robotic servants if fed enough coins.";
$cost=$level[$x]*rand(8,12);
$mcha=rand(1,6)+rand(1,6)+rand(1,6)+$level[$x];
$tou=$level[$x]*rand(8,12);
$car=$level[$x]*rand(8,12)*rand(8,12)*rand(8,12);
$vlang=$language[rand(2,$langnum)];
$z=$z." It will only speak, or allow a delver to give it coins, if they have enough CHR to command the servants (";
if (rand(1,2)==1) {
$z=$z.$mcha." or more).";
} else {
$leeway=floor($mcha/3);
$without=$mcha+rand(1,$leeway);
$with=$mcha-rand(1,$leeway);
$z=$z."at least ".$without." CHR for delvers who don't speak ".$vlang.", at least ".$with." for those that do. A book of phrases will be of no use in this situation).";
}
$z=$z."<br><br>The servants are ".$sizetext[rand(2,$sizecats-1)][1].", and look like a robotic version of ".$appani[rand(1,$aniapp)].". They have MRs of ".$tou.", and can carry the weight of up to ".$car." coins. They'll obey any command (subject to the note on CHR above). They can't speak.<br><br>The machine itself will answer questions about cost provided they're in ".$vlang.". If the delvers ask how tough the servants are or how much they can carry, it'll respond with bland advertising phrases (for example 'our servants are so tough they'll take a beating and keep on going').";
if (rand(1,2)==1) {
$mdex=rand(1,6)+rand(1,6)+rand(1,6)+$level[x];
$z=$z." A DEX of at least ".$mdex." is required to actually feed the coins into the machine's mouth once someone with enough CHR has approached it. This is because once that happens it will talk almost incessantly, repeating advertising slogans if it isn't asked anything. One delver can talk to the machine while another feeds it coins, if one delver has enough CHR but not DEX and another delver has the opposite problem.";
}
$z=$z." The servants cost ".$cost."gp each. The machine will take any coins, but won't give change.";
if (rand(1,2)==1) {
$z=$z."<br><br>The machine is frequently out of order. Whoever is paying the machine should make a level ".rand(1,$level[x])." save on ";
if (rand(1,2)==1) {
$z=$z."INT";
} else {
$z=$z."LK";
}
$z=$z.". If they fail, they'll pay half the cost (rounded down) before realising that the machine is out of order. If they make it by 5 or more, the hireling will appear when they've only paid half the cost (rounded down).";
}
if (rand(1,2)==1) {
$z=$z."<br><br>Trying to break into the machine will be futile.";
} else {
$z=$z."<br><br>If a delver tries to break into the machine, they should make a level ".rand(1,$level[$x])." save on STR. The attempt, whether it succeeds or not, will take ".(rand(1,4)*5)." minutes. If they succeed, the machine will cough up coins: roll ".rand(1,rand(1,$level[$x]))." dice for the value in gold pieces. Then roll again: 1-2 gold coins, 3-4 silver coins (10 for each gp worth) 5-6 copper coins (100 for each gp worth). A critical failure will mean that there are no more coins in the machine, except for any that the delvers have put in themselves. Whether they succeed or not, the GM should roll for wandering monsters for each attempt (as well as, not instead of, the usual roll for wandering monsters). Any monsters that result will arrive in ".$traveltime." minutes (from the start of the attempt, not from the end). The delvers can use coins gained this way to pay for a hireling, or pay and then try and get their coins back.";
}
$rd[$x][$y]=$rd[$x][$y].$z;
}

$z="";
if ($tr[$x][$y]>0 OR $eye[$x][$y]==1) {
$z="<br><br>Treasure in this area";
// where is the treasure (unfinished -
// for most rooms, could be hidden or on display)
$a=$rb[$x][$y];
if ($a==3 OR $a==5) {
$z=$z." (in front of the shrine)";
}
$z=$z.":".$line;
if ($a==8 OR $a==9) {
$z=$z."This list doesn't count any coins in the vending machine.".$line;
}
}

do {
if (rand(1,11)==1) {
if ($pipeweed==0) {
if ($trleft<20) {
$ok=0;
} else {
$trleft-=20;
$pipeweed=1;
$z=$z."* A pouch of pipe-weed. If a hobbit has matches or a tinder-box, they can smoke it (you can assume that all hobbits carry a pipe). It will last for an hour of in-game time. During that time, the pleasant odour and soothing effect mean that the hobbit can treat their INT and CHR as being 3 higher than their real value. The hobbit will also be immune to effects which cause fear or anger (for example the spell <i>Oh-Go-Away</i> won't work on them). The pipe-weed will also mask any other strong smell (but the smell will still be there once the pipe-weed is gone). The downside of it is that its strong smell will make it impossible for the hobbit to hide. Weight 0 value 20.<br>";
}
}
} elseif (rand(1,10)==1) {
// poison.
$rpo=rand(1,$poisnum);
if ($poisons[$rpo][3]<>"used") {
if ($trleft<$poisons[$rpo][1]) {
$ok=0;
} else {
$poisons[$rpo][3]="used";
$pnum=rand(1,min(rand(1,6),floor($trleft/$poisons[$rpo][1])));
$trleft-=$poisons[$rpo][1]*$pnum;
if ($pnum==1) {
$z=$z."* Poison: a vial of ".$poisons[$rpo][0];
} else {
$z=$z."* Poison: ".$pnum." vials of ".$poisons[$rpo][0];
}
$z=$z.". ".$poisons[$rpo][2].". weight 1 value ".$poisons[$rpo][1];
if ($pnum>1) {
$z=$z." per vial.";
}
$z=$z."<br>";
}
}
} elseif (rand(1,9)==1) {
if ($blackbread==0) {
if ($trleft<8) {
$ok=0;
} else {
$tfleft-=8;
$blackbread=1;
$z=$z."* A loaf of Dwarven black bread. Any dwarf who finds this food must make a level ".rand(1,$level[$x])." save on INT. If they fail they'll eat the bread, and lose ".max(2,rand(1,6*$level[$x]))." points of ";
if ($spd==1 AND rand(1,2)==1) {
$z=$z."SPD";
} else {
$z=$z."CON";
}
$z=$z.". They'll recover the lost points over 24 hours. If a delver is reduced to 0 or less as a result of eating the loaf, they won't die - rather, they'll fall unconscious until 24 hours after they've eaten the bread. The loaf counts as 1 day's food, and so anyone can choose to eat it. weight 20 value 8<br>";
}
}
} elseif (rand(1,8)==1) {
if (rand(1,6)==1) {
if ($trleft<50) {
$ok=0;
} else {
$tfleft-=50;
do {
$inlang=$language[rand(2,$langnum)];
if (rand(1,2)==1) {
$inlang="Common";
}
$learnlang=$language[rand(1,$langnum)];
} while ($inlang==$learnlang);
if (rand(1,3)==1) {
$z=$z."* A book on herbalism, written in ".$inlang.". Anyone who can read ".$inlang." and has an INT of at least ".(rand(8,12)+(rand(1,3)*$level[rand(1,$l)]))." can find a suitable wilderness area and study it. This will take a month of in-game time. Afterwards, they'll have a general knowledge of herbs. From then on, if they have access to wild herbs they pay half-price for all poisons, because they can gather some of the ingredients themselves.<br>";
} else {
$z=$z."* A book of ".$learnlang." phrases, written in ".$inlang.". Anyone who reads ".$inlang." and has an INT of at least ".(rand(8,12)+(rand(1,3)*$level[rand(1,$l)]))." can communicate in ".$learnlang.", on a very basic level, using this book. Delvers who use this book to communicate with creatures in the dungeon will get half the penalty (rounded down) for lacking a common language (weight 5 value 50).<br>";
}
}
}
} elseif (rand(1,7)==1) {
// miscellaneous magic items.

if ($trleft>999 AND rand(1,6)==1 AND $foldship==0) {
$trleft-=1000;
$foldship=1;
$z=$z."* A fold-up ship. This magic item fits in a backpack, but unfolds to become a seaworthy ship, with room for 10 people to sleep below decks, and folds up again. When folded it looks a bit like a folded fan. weight 50 value 1000<br>";
} elseif ($trleft>199 AND rand(1,3)==1 AND $holyitem==0) {
if (rand(1,2)==1) {
if ($trleft>199) {
$z=$z."* A vial of holy water. If it's splashed on a creature who's 'fiery and demonic', 'insubstantial and ghostly', or looks like 'an animated corpse', the creature will lose all armour (including that from tough skin) if it has any, or lose half its CON or MR if not. The delver must be at pointblank range (5 yards/metres or less) to use the holy water, but doesn't have to make a roll to hit. They can also use a 1-handed weapon in the same Combat Round, if they have a free hand - their Hit Point Total for the round will be halved (round up). There's enough water for one use. weight 10 value 200.<br>";
$trleft-=200;
$holyitem=1;
} else {
$ok=0;
}
} else {
$protection=rand(5,10);
$value=$protection*10;
if ($trleft>=$value) {
$z=$z."* A holy symbol. A delver who wears one of these symbols will have ".$protection." extra points of armour against wounds caused by creatures whose description includes any of the following words or phrases: 'fiery and demonic', 'insubstantial and ghostly', 'animated corpse', 'skull' or 'skeleton'. However these creatures will be able to sense the presence of this symbol, which means that the delver won't be able to hide from them. If any delver is wearing one, everyone in the group will treat their CHR as 5 less than its real value when dealing with such creatures. weight 10 value ".$value."<br>";
$trleft-=$value;
$holyitem=1;
} else {
$ok=0;
}
}
} else {
if ($trleft<125) {
$ok=0;
} elseif (rand(1,3)==1) {
$potype=rand(1,3);
$value=150*($potype+1);
if ($trleft<$value) {
$ok=0;
} else {
$trleft-=$value;
$z=$z."* A potion. Any statted character who drinks it ";
if ($potype==2) {
$z=$z." permanently gains an ability which has the same effect as the spell";
do {
$spok=1;
$splike=rand(1,$spnum+$xspnum);
if ($splike<=$spnum) {
if ($level[$x]<$spells[$splike][1] OR $spells[$splike][2]==0) {
$spok=0;
} else {
$spname=$spells[$splike][0];
$spcost=$spells[$splike][2];
}
} else {
$ewspell++;
$ewspells[$splike-$spnum]=1;
$spname=$xspells[$splike-$spnum][0];
$spcost=$xspells[$splike-$spnum][1];
}
} while ($spok==0);
$z=$z." <i>".$spname."</i>";
if ($splike>$spnum) {
$z=$z." (see 'Magic of Odand' above)";
}
$z=$z.". The character will temporarily lose ".$spcost." points of ";
do {
$pattr=$sname[rand(1,$attnum)];
} while (($wiz==0 AND $pattr=="STR") OR $pattr=="WIZ");
$z=$z.$pattr." each time they use this ability";
} else {
$z=$z."makes all rolls as if their ";
do {
$att1=$sname[rand(1,$attnum)];
} while ($att1=="CON");
$z=$z.$att1." was double its real value";
if ($potype==1) {
do {
$att2=$sname[rand(1,$attnum)];
} while ($att2=="CON" OR $att1==$att2);
$z=$z.", but must also treat their ".$att2." as if it was half its real value (rounded down),";
}
$ptime=rand(1,6);
$z=$z." for ";
if ($ptime>1) {
$z=$z.$ptime." hours";
} else {
$z=$z."an hour";
}
$z=$z." of in-game time";
}
$z=$z.". There's enough of the potion for one drink.";
if (rand(1,3)==1) {
$z=$z." There's no way to tell what the potion will do before it's drunk.";
} elseif (rand(1,2)==1) {
$lev1=$level[rand(1,$l)];
$lev2=round($lev1/2);
$plev=max(2,rand($lev2,$lev1));
$z=$z." Any Wizard or Rogue of at least level ".$plev." will be able to tell what the potion's effect will be. Any Wizard or Rogue of at least level ".($plev+rand(1,3))." will be able to tell ";
if ($potype==2) {
$z=$z."how much, and what attribute, the ability will cost.";
} else {
$z=$z."how long the effect will last.";
}
} else {
$z=$z." Any character with an ";
$attr=rand(1,2+$wiz);
if ($z==1) {
$z=$z."INT";
} elseif ($z==2) {
$z=$z."LK";
} else {
$z=$z."WIZ";
}
$z=$z." of at least ";
$lev=rand(1,$level[$l]);
$sreq=10;
if ($lev>1) {
for ($levn=2;$levn<=$lev;$levn++) {
$sreq+=$levn;
}
}
$z=$z.$sreq." will be able to tell what the potion's effect will be. If they have at least ".($sreq+rand(1,6)+rand(1,6))." they'll be able to tell ";
if ($potype==2) {
$z=$z."how much, and what attribute, the ability will cost.";
} else {
$z=$z."how long the effect will last.";
}
}
$z=$z." Weight.".(5*rand(1,20))." value ".$value."gp<br>";
}
} else {
$lev=max(1,floor($trleft/500)+1);
if ($lev>1) {
$lev=max(rand(1,$lev),rand(1,$lev));
}
do {
$spok=1;
$a=rand(1,$spnum+$xspnum);
$cost=max(125,500*($lev-1));
if ($a<=$spnum) {
$spdes="level ".$lev." spell <i>".$spells[$a][0]."</i>";
if ($spells[$a][1]<>$lev) {
$spok=0;
}
} else {
$spdes="spell <i>".$xspells[$a-$spnum][0]."</i> (see 'Magic of Odand' above)";
$ewspell++;
$ewspells[$a-$spnum]=1;
}
} while ($spok==0);
do {
$b=2;
$perm=rand(0,2);
// $perm:
// 0: scroll which is destroyed once read.
// 1: permanent scroll (x2 value)
// 2: runestone:
// $rstype:
// 1 Wizards only.
// 2 Wizards or Rogues.
// 3 anyone.
// $attype:
// 1 needs INT and DEX.
// 2 needs one attribute only.
// 3 needs no attributes (Odand spells always like this)
if ($perm==1) {
$b=4;
} if ($perm==2) {
do {
$rstype=rand(1,3);
$attype=rand(1,3);
if (str_replace("Odand","XXX",$spdes)<>$spdes) {
$attype=3;
}
} while ($attype==1 AND $rstype<>3);
$b=$rstype+$attype+1;
}
$newcost=round($cost*$b/2);
} while ($newcost>$trleft);
$int=8+($lev*2);
$dex=7+$lev;
$trleft-=$newcost;
$z=$z."* A ";
if ($perm==2) {
$z=$z."runestone. The ".$spdes." is locked into the stone.<br>Any ";
$a=0;
$b=0;
if (rand(1,2)==1) {
$z=$z."delver";
$a=1;
} else {
$z=$z."Rogue or Wizard";
}
if (rand(1,3)==1) {
$z=$z." with ";
if ($wiz==1 AND rand(1,3)==1) {
$z=$z."WIZ";
} elseif (rand(1,2)==1) {
$z=$z."INT";
} else {
$z=$z."CHR";
}
$z=$z." of at least ".rand(1,6)*$lev;
} elseif (rand(1,2)==1) {
$z=$z." of at least level ".(max(2,rand(1,round($lev*3/2))));
} else {
$b=1;
}
$z=$z." will be able to tell what spell is locked in the stone.<br>If a ";
if ($rstype==1) {
$z=$z."Wizard";
} elseif ($rstype==2) {
$z=$z."Rogue or Wizard";
} else {
$z=$z."delver (even a Warrior)";
}
if ($attype==1) {
$z=$z." with INT of at least ".$int." and DEX of at least ".$dex;
} elseif ($attype==2) {
if (rand(1,3)==1) {
$z=$z." with INT of at least ".$int;
} elseif (rand(1,2)==1) {
$z=$z." with DEX of at least ".$dex;
} else {
$z=$z." with CHR of at least ".rand($dex,$int);
}
}
$z=$z." holds the stone and concentrates,";
if ($a*$b==1) {
$z=$z." and if they know what spell is locked inside (including if someone who knows tells them),";
}
$z=$z." they can cast the spell without having to learn it. The spell still costs the holder the normal amount of ";
if ($wiz==1) {
$z=$z."WIZ";
} else {
$z=$z."STR";
}
if ($a*$b==0 AND str_replace("Odand","XXX",$spdes)==$spdes) {
$z=$z.".<br>The delver holding the stone can simply guess spells until they hit the right one, but for each wrong guess they'll temporarily lose ".rand(1,3)." ";
$watt=rand(1,2+$wiz);
if ($watt==1) {
$z=$z."CON";
} elseif ($watt==2) {
$z=$z."STR";
} else {
$z=$z."WIZ";
}
}
} else {
$z=$z."scroll, which contains instructions on how to cast the ".$spdes.". Any Rogue ";
if ($lev>1 OR str_replace("Odand","XXX",$spdes)<>$spdes) {
$z=$z."or Wizard ";
}
if (str_replace("Odand","XXX",$spdes)==$spdes) {
$z=$z."with INT of at least ".$int;
}
$z=$z."can read and learn the spell";
if ($lev==1 AND str_replace("Odand","XXX",$spdes)==$spdes) {
$z=$z." (Wizards will already know it)";
}
if (str_replace("Odand","XXX",$spdes)==$spdes) {
$z=$z.". The spell requires an INT of at least ".$int." and DEX of at least ".($lev+7)." to cast";
}
if ($perm==0) {
$z=$z.". Once one person has learned the spell, the scroll will ";
if (rand(1,3)==1) {
$z=$z." disappear";
} elseif (rand(1,2)==1) {
$z=$z." burst into flame";
} else {
$z=$z." crumble into dust";
}
$z=$z.". If ";
if (str_replace("Odand","XXX",$spdes)==$spdes) {
$z=$z."someone reads the scroll who can't learn the spell, either because they're a Warrior or because of their INT";
} else {
$z=$z."a Warrior reads the scroll";
}
$z=$z.", this won't destroy it. If someone reads the scroll who could learn the spell, but already knows it, this won't destroy the scroll either - and in this case, the reader will learn that the scroll is one which 'self-destructs'";
}
}
$z=$z.". weight 20 value ".$newcost."gp<br>";
}
}
} elseif (rand(1,6)==1) {
// ranged weapons, or ammunition for them.
$rw=rand(1,$rangenum);
$am=$rangew[$rw][5];
if ($am<>"self" AND rand(1,2)==1) {
$value=$ammo[$am][1];
if ($value>$trleft) {
$ok=0;
} else {
$trleft-=$value;
$z=$z."* ".$ammo[$am][0]." (weight ".$ammo[$am][2]." total value ".$value."gp)<br>";
}
} else {
$value=$rangew[$rw][6];
$value=round(rand($value*$lmul,$value*$hmul)/100);
$rmany=floor($trleft/$value);
if ($rmany==0) {
$ok=0;
} else {
$rmany=rand(1,min(rand(1,6),$rmany));
$trleft-=$rmany*$value;
$z=$z."* ";
$wname=$rangew[$rw][0];
if ($rmany==1) {
$z=$z."A ".$wname;
} else {
$z=$z.$rmany." ".$wname."s";
}
$z=$z." (";
$weight=$rangew[$rw][7];
$weight=round(rand($weight*$lmul,$weight*$hmul)/100);
$range=$rangew[$rw][8];
if ($range<>"any") {
$range=round(rand($range*$lmul,$range*$hmul)/100);
}
$dex=$rangew[$rw][4];
$dex=round(rand($dex*$lmul,$dex*$hmul)/100);
$str=$rangew[$rw][3];
$str=round(rand($str*$lmul,$str*$hmul)/100);
if ($wname<>"bullwhip") {
$damage=(7*$rangew[$rw][1])+(2*$rangew[$rw][2]);
$damage=round(rand($damage*$lmul,$damage*$hmul)/100);
$damage=$damage/2;
if (round($damage)==$damage AND $damage<7) {
$dd=2;
$da=$damage-7;
} else {
$dd=1;
if (round($damage)==$damage) {
$dd=2;
}
do {
$dd+=2;
} while ($dd*3.5<=$damage);
$dd-=2;
$da=$damage-(3.5*$dd);
}
$z=$z.$dd." dice ";
if ($da>=0) {
$z=$z."+ ";
} else {
$z=$z."- ";
}
$z=$z.abs($da).", ";
}
$z=$z."used ".$rangew[$rw][9]."-handed, min. STR ".$str." DEX ".$dex.", range ".$range." yards/metres, weight ".$weight." value ".$value."gp";
if ($rmany>1) {
$z=$z." each";
}
$z=$z.")<br>";
if ($wname=="bullwhip") {
$z=$z."Wizards can't use bullwhips. Bullwhips do no damage. Instead, the character wielding it can try and wrap it around an opponent's weapon and pull the weapon out of their hands (it's no use against an opponent fighting with fists, claws etc). To do this, they make a DEX saving roll as if they were using a missile weapon. However, if the victim has a shield, the difficulty of the roll is increased by the damage reduction of the shield (armour doesn't have any effect).<br>If the attacker makes the save, they compare their STR to the STR of their opponent. If the target weapon is 1-handed, and the attacker's STR is at least half that of the defender, the defender's weapon is yanked out of their hand. If the target weapon is 2-handed, the bullwhip wielder's STR must be equal to the opponent's STR. In either case, if the attacker's STR isn't high enough the attack has no effect.<br>";
} elseif ($wname=="pistol") {
$z=$z."Pistols are mechanical contrivances of the gnomes. They fire anything that's put in them (stones, bits of metal etc). Their range is effectively limitless: if you can see it you can shoot at it. However, if the range is more than 50 yards/metres the shooter rolls on LK rather than DEX, and uses LK adds rather than DEX adds to modify damage. If the shooter's roll to hit is a critical failure, they should roll 2 dice:<br>2-3: The weapon starts to fire late, and will do so until it's unloaded and re-loaded. If this is done in combat, it will take an entire Combat Round. Until then, add 1 to the level of all saving rolls to hit.<br>4-6: The pistol is jammed. It must be unloaded and re-loaded before it can be used again. This will take the whole of the next Combat Round.<br>7-8: It gives a flash and a bang, but doesn't shoot. The shooter should make a level 1 saving roll on INT. If they make it, treat as '2-3' above. If they fail, they instinctively look down the barrel to see what the problem is - the weapon then goes off, and the shooter takes full damage, not reduced by armour or shields.<br>9-10: The weapon doesn't shoot - this Combat Round is wasted.<br>11: The pistol jams, and will be unusable until it's repaired (the gnomes are the only ones who know anything about these devices).<br>12: The pistol explodes, and the weapon's user takes the full dice and adds of the weapon in damage (reduced by armour but not shields).<br>";
}
}
}
} elseif (rand(1,5)==1) {
// jewel
$a=rand(1,$jnum);
if ($jewel[$a][2]<>"used") {
$jsize=rand(1,4);
$base=$jewel[$a][1];
$value=$jsize*$base;
if ($value>$trleft) {
$ok=0;
} else {
$jmany=rand(1,min(rand(1,6),floor($trleft/$value)));
$z=$z."* ";
if ($base<25) {
$z=$z."Semi-";
}
$z=$z."Precious Stone";
if ($jmany>1) {
$z=$z."s (".$jmany.")";
}
$z=$z.": ".$jewel[$a][0].". weight ".$jsize." value ".$value." gp";
if ($jmany>1) {
$z=$z." (each)";
}
$z=$z."<br>";
$jewel[$a][2]="used";
$trleft-=($value*$jmany);
}
}
} elseif (rand(1,4)==1) {
// musical instrument
$mm=0;
$a=rand(1,$musnum);
$value=$music[$a][2];
if ($music[$a][3]<>"used") {
// if (rand(1,6)==1) {
// $value=$value*5;
// $mm=1;
// }
if ($value>$trleft) {
$ok=0;
} else {
$mmany=1;
if ($mm==0) {
$mmax=floor($trleft/$value);
if ($mmax==1) {
$mmany=1;
} else {
$mmany=rand(1,min(rand(1,6),$mmax));
}
}
if ($music[$a][0]=="pan pipes") {
$z=$z."* ";
if ($mmany==1) {
$z=$z."P";
} else {
$z=$z.$mmany." sets of p";
}
$z=$z."an pipes";
} elseif ($music[$a][0]=="bagpipes") {
$z=$z."* ";
if ($mmany==1) {
$z=$z."B";
} else {
$z=$z.$mmany." set of b";
}
$z=$z."agpipes";
} else {
if ($mmany==1) {
$z=$z."* A ".$music[$a][0];
} else {
$z=$z."* ".$mmany." ".$music[$a][0]."s";
}
}
$z=$z.". weight ".$music[$a][1]." value ".$value."gp";
if ($mmany>1) {
$z=$z." (each)";
} elseif ($mm==1) {
$z=$z." MAGIC: NOT DONE";
}
$z=$z."<br>";
$music[$a][3]="used";
$trleft-=($mmany*$value);
}
}
} elseif (rand(1,3)==1) {
// armour or shields
// note that $armnum =
// total number of different pieces of armour
// whereas $arnum =
// how many identical pieces in the list of
// treasure.
$a=rand(1,$armnum);
$atype=$arm[$a][0];
$protection=$arm[$a][1];
$streq=$arm[$a][2];
$value=$arm[$a][3];
$weight=$arm[$a][4];

if ($x==$questlevel AND $y==$questroom) {
$rd[$x][$y]=$rd[$x][$y]."<br><br>The most important thing in this room, from the delvers' point of view, is <b>".$questobject."</b>";
if ($system=="tt") {
$rd[$x][$y]=$rd[$x][$y]." (weight ".rand(5,50).")";
}
$rd[$x][$y]=$rd[$x][$y].".";
}
// maybe put some kind of protection -
// spell, invisible, supernaturally heavy etc.

$z="<br><br>";
if ($system=="tt") {
$attr="LK";
if (rand(1,2)==1) {
$attr="INT";
}
$hlev=max(rand(0,$level[$x]),rand(0,$level[$x]));
if (rand(1,3)==1) {
$z=$z."This area has nowhere to hide";
if (rand(1,2)==1) {
$z=$z.", except for fairies, who stay hidden from a casual search if they make a successful level ".$hlev." save on ".$attr;
}
$z=$z.".";
} else {
if (rand(1,2)==1) {
$z=$z."This area is easy to hide in. Any delver can hide well enough that a casual search won't find them. A thorough search won't find a delver who makes a successful level ".$hlev." save on ".$attr.". Hobbits add 5 to their roll. Fairies don't have to make this save.";
} else {
$z=$z."This area is hard to hide in. A thorough search will find any delver. A casual search won't find a delver who makes a successful level ".$hlev." save on ".$attr.". Hobbits add 5 to their roll. Fairies automatically stay hidden from a casual search, and can make this save to stay hidden from a thorough search.";
}
}
} elseif ($system=="ll") {
if (rand(1,3)==1) {
$z=$z."This area has nowhere to hide.";
} elseif (rand(1,2)==1) {
$z=$z."Thieves can try and hide in this area, using their normal chance to Hide in Shadows. ";
if (rand(1,6)==1) {
$z=$z." Halflings have a 90% chance of hiding successfully. ";
} else {
$z=$z." Halflings hide on a 1 or 2 on 1d6. ";
}
$z=$z." No one else will be able to hide in this area.";
} else {
if (rand(1,2)==1) {
$z=$z."Thieves and Halflings can hide in this area. They succeed without having to roll. Anyone else can attempt to hide, rolling as if they were a Thief of their level trying to Hide in Shadows.";
} else {
$z=$z."Thieves can hide in this area. They succeed without having to roll. Anyone else can attempt to hide, rolling as if they were a Thief of their level trying to Hide in Shadows. Halflings, however, have at least a ";
if (rand(1,6)==1) {
$z=$z."90";
} else {
$z=$z."33";
}
$z=$z."% chance to hide regardless of their level.";
}
}
}
$rd[$x][$y]="This area is ".$rwidth." yards/metres east-west by ".$rdepth." yards/metres north-south, and ".$rheight." yards/metres high.<br><br>".$rd[$x][$y].$z;
}
for ($y=1;$y<=$gnum;$y++) {
if ($shrine[$y]==2) {
$shrine[$y]=1;
$manygods++;
}
}
}

if ($system=="ll") {
print "<b>Retainers</b>";
print $line;
// if (rand(1,3)==1) {
// $noretainers=1;
// print "The dungeon has such a bad reputation that no retainers can be hired. Retainers from a previous adventure must make an extra morale check, or they too will refuse to go in.";
// } else {
$anyr=0;
while ($anyr==0) {
for ($z=1;$z<=$llclassnum;$z++) {
if (rand(1,3)==1) {
$retainer[$z]=1;
$anyr++;
}
}
}
if ($anyr<3) {
print "The only retainers that can be hired are ";
} else {
print "The following retainers can be hired: ";
}
$sofar=0;
for ($z=1;$z<=$llclassnum;$z++) {
if ($retainer[$z]==1) {
$sofar++;
if ($anyr>1 AND $sofar==$anyr) {
print " and ";
}
print $llclasses[$z];
if ($sofar<$anyr) {
print ", ";
}
}
}
print ".";
print $line;
for ($z=8;$z<=11;$z++) {
if ($retainer[$z]==1) {
$duc=0;
print $llclasses[$z]." from this area will ";
if ($z==9) {
print "look like ".$appani[rand(1,$aniapp)].", and ";
} elseif ($z==10) {
print "look like ".$apppla[rand(1,$plaapp)].", and ";
}
print "have the following mutations:";
print $line;

if ($anyshrine==1) {
print "<b>Shrines</b>";
print $line;
print "When a delver prays at a shrine that they haven't prayed at before, they should make a saving roll on CHR at the level given below. If they fail, the god smites them and they lose CON equal to the number they missed by (some gods might have other results of failure listed). If they succeed, they gain the benefit listed below.";
print $line;
for ($z=1;$z<=$gnum;$z++) {
if ($shrine[$z]==1) {
print "<i>";
if ($godd==1) {
print $gods[$z][0]."</i>, the ".$gods[$z][1]." ".$gods[$z][2]." of ".$gods[$z][3];
} else {
print ucfirst($gods[$z][2])." of ".$gods[$z][3]."</i>";
}
print ": ".$gods[$z][4];
print $line;
if ($godd==1) {
print $gods[$z][0];
} else {
print ucfirst($gods[$z][2]);
}
print " ";
$genpun=0;
$pu=rand(1,3);
if ($pu==1) {
print "won't punish any delver who takes offerings from their shrine";
if (rand(1,2)==1) {
print ", or destroys it.";
} else {
print ". However, if a delver destroys the shrine, they ";
$pu=rand(4,5);
}
}
if ($pu==2 OR $pu==4) {
if ($pu==2) {
print "might punish delvers who take offerings from their shrine";
if (rand(1,2)==1) {
$pu=5;
} else {
print ", or destroy it";
}
} else {
print " might be punished";
}
print ". The delver or delvers responsible should make a save on ";
if ($wiz==1 AND rand(1,2)==1) {
print "WIZ";
} else {
print "CHR";
}
print " at the level of the dungeon ";
$a=$s-1+rand(1,3)-rand(1,3);
if ($a>0) {
print " plus ".$a;
} elseif ($a<0) {
print " minus ".-$a." (with a minimum of 1)";
}
print ". They're punished if they fail.";
if ($pu==5) {
print " If a delver destroys the shrine, they ";
}
}
if ($pu==3) {
print "will punish any delver who takes offerings from their shrine, or destroys the shrine.";
}
if ($pu==5) {
print " will definitely be punished.";
}
print " ";
if ($pu>1) {
if ($godd==1) {
print $gods[$z][0]."'";
if (substr($gods[$z][0],-1)<>"s") {
print "s";
}
} else {
print ucfirst($gods[$z][2])."'s";
}
print " punishment will be that the delver will ";
if (rand(1,2)==1) {
$attl=rand(1,$attnum);
print "lose points from their ".$sname[$attl].", equal to the dungeon level x 2";
if ($s==1) {
print ".";
} else {
print ", plus ".((2*$s)-2).".";
}
print " This loss affects the delver's maximum score in the attribute, as well as their current score. That is, it won't heal.";
} else {
do {
$attl=rand(1,$attnum);
} while ($attl==4);
print "halve their ".$sname[$attl]." (rounded down) for ".(rand(1,6)*$level[rand(1,$l)])." hours of in-game time. This loss affects the delver's maximum score in the attribute, as well as their current score. At the end of this time, the maximum score will instantly return to normal. However, the current score will only recover at the normal rate (see 'Recovering Lost Attribute Points' below).";
}
}
print $line;
if (rand(1,2)==1 OR ($godd==1 AND $gods[$z][0]=="Pan")) {
$anygodm++;
$godinst=$music[rand(1,$musnum)][0];
if ($godd==1 AND $gods[$z][0]=="Pan") {
$godinst="pan pipes";
}
$godinst=str_replace("small ","",$godinst);
$godinst=str_replace("large ","",$godinst);
if ($godd==1) {
$gods[$z][5]=$gods[$z][0];
} else {
$gods[$z][5]=$gods[$z][2]." of ".$gods[$z][3];
}
$gods[$z][5]=$gods[$z][5]." loves the sound of the ".$godinst.".";
print ucfirst($gods[$z][5])." A delver who plays one near their shrine should make a level ".$level[rand(1,$l)]." saving roll on DEX. If they make it, the next delver to pray at the shrine takes ".rand(5,12)." from the difficulty of the roll. If a delver tries to please them with music and fails, no delver can get a bonus in this way for the next 12 hours of in-game time.";
print $line;
}
}
}

if ($dr==1) {
print "<b>War In Heaven:</b>";
print $line;
print "If any delver has prayed at ";
if ($snum[$goda]==2) {
print "both";
} else {
$z=rand(2,$snum[$goda]);
if ($z<$snum[$goda]) {
print $z." or more";
} else {
print "all ".$z;
}
}
print " shrines to ";
if ($godd==1) {
print $gods[$goda][0];
} else {
print $gods[$goda][2]." of ".$gods[$goda][3];
}
print ", and been successful at ";
if ($snum[$goda]==2) {
print "both";
} else {
if ($z==$snum[$goda]) {
print "at least ".ceil($z/2);
} else {
print "more of them than they've failed at";
}
}
print ", then ";
if ($godd==1) {
print $gods[$goda][0];
} else {
print $gods[$goda][2];
}
print " will appear, and charge the delver to destroy ";
if ($snum[$godb]==1) {
print "the shrine to ";
} else {
if ($snum[$godb]==2) {
print "both";
} else {
print "all ".$snum[$godb];
}
print " shrines to ";
}
if ($godd==1) {
print $gods[$godb][0];
} else {
print $gods[$godb][2]." of ".$gods[$godb][3];
}
print ". If the delver refuses, ";
if ($godd==1) {
print $gods[$goda][0];
} else {
print $gods[$goda][2];
}
print " will refuse to hear their prayers for 1-6 weeks of in-game time. If they accept but leave the dungeon before they've completed their task, ";
if ($godd==1) {
print $gods[$goda][0];
} else {
print $gods[$goda][2];
}
print " will ignore them for 2-12 weeks. If they succeed, they'll be blessed with ";
print $snum[$godb]*rand(200,300);
print " Adventure Points. ";
if ($godd==1) {
print $gods[$goda][0];
} else {
print ucfirst($gods[$goda][2]);
}
print " will tell the delver which level";
if ($snum[$godb]==1) {
print " the shrine is";
} else {
print "s the shrines are";
}
print " on, but not any more detailed directions.";
print $line;
}
print $line;
}
if ($system=="tt") {
print "<b>Poison</b>";
print $line;
print "A vial of poison has enough poison to coat a dagger, throwing star or throwing knife 6 times, or any larger weapon 3 times, or 72 arrows or crossbow bolts. When a hand-to-hand weapon is coated, the poison will last until the weapon does damage which isn't reduced to zero by armour or shields, or until 3 Combat Rounds have passed, whichever comes first.";
print $line;
print $line;
print "<b>Notes on Treasure</b>";
print $line;
print "Statted monsters might be guarding treasure which includes weapons, armour and shields which they can use, and which is better than their own equipment, potions which would help them, or other items which would be useful in combat. In this case, the GM should make a level 1 saving roll on INT for the monsters. If they succeed, they'll use the treasure if it comes to combat.";
print $line;
print "Scrolls are written in a magical language, which all Rogues and Wizards will be able to read. If statted creatures are guarding a scroll, and have enough INT to learn the spell:";
print "<ul><li>if the scroll is one that disappears once its spell is learned, they've been unable to read it.";
print "<li>Otherwise, they've read the scroll and know the spell.</ul>";
print $line;
print $line;
print "<b>Recovering Lost Attribute Points</b>";
print $line;
$spf="STR";
if ($wiz==1) {
$spf="WIZ";
}
print "Unless the GM rules otherwise, characters will recover 1 point of lost ".$spf." every 10 minutes, as long as the ".$spf." was lost casting spells. ".$spf." lost for any other reason, and any other reduced attribute (eg CON reduced from combat), recovers at 1 point per day.";
print $line;
print $line;
}
if ($anyeye==1) {
print "<b>Eyes</b>";
print $line;
print "Eyes are devices built by the Ancients. They look like oversized gems, with a switch on one side which activates the device, and a stylised eye on the other, as shown. <img src=\"http://www.apolitical.info/webgame/dungeon/eye.jpg\" align=\"left\">";
print $line;
print "Each Eye shoots a beam. The beams from different types of Eyes have different effects. However the Eyes themselves, and the beams, look identical.";
print $line;
print "Each Eye has 3-18 'charges'. The GM should roll 3";
if ($system=="tt") {
print " dice";
} elseif ($system=="ll") {
print "d6";
}
print " and keep track of the number of charges left. If an Eye has no charges left it can still be used. However the GM should roll a ";
if ($system=="tt") {
print "dice";
} elseif ($system=="ll") {
print "d6";
}
print ":<br>1-4 The Eye works as normal.";
print "<br>5 The Eye closes, never to work again (such an Eye will also be un-sellable).";
print "<br>6 The Eye explodes, doing 4";
if ($system=="tt") {
print " dice";
} elseif ($system=="ll") {
print "d6";
}
print " worth of damage to the character holding it, and 2";
if ($system=="tt") {
print " dice";
} elseif ($system=="ll") {
print "d6";
}
print " to any character within 3 yards/metres (";
if ($system=="tt") {
print "reduced by armour as normal";
} else {
print "save vs Breath Attacks for half damage";
}
print ").".$line;
print "It takes two hands to hold an Eye. Trying to hit a target with the beam is treated as a normal missile attack. Its range is effectively infinite - if you can see it, the beam will reach.";
print $line;
print "Most Eyes have an effect which lasts for a variable time. There's no way to tell how long the effect of an Eye will last. If a character is hit by an Eye, they're immune to that type of Eye until the effect wears off. If they're hit by an Eye while immune, roll again for how long the effect will last, and take whichever lasts longer, the new roll or the existing roll. But don't apply the effect again.";
print $line;
print $line;
}
if ($unstuck==1) {
print "<b>Unstuck In Time</b>";
print $line;
print "If a room is marked as being 'unstuck in time', this means several things:";
print $line;
print "For as long as the delvers stay here, no time will pass in the outside world. This means that there'll be no wandering monsters.";
print $line;
print "If the delvers leave and come back, things will be 'reset' to exactly as when the delvers first arrived. If they killed a creature it will be alive with no memory of meeting the delvers, if they carried off treasure they'll still have it, but identical treasure will be in the room. The delvers can only get experience for defeating a given creature once.";
print $line;
print "This means that the delvers might end up with multiple copies of the same treasure, or with multiple copies of the same creature accompanying them. Each area will have a 'paradox limit'. This is the maximum number of copies of the same creature or object that can exist in the same place at the same time.";
print $line;
print "Once this limit is exceeded, the GM should roll a dice:";
print "<br>1-2 the multiple items are treated as normal from now on, and don't count towards the paradox limit.";
print "<br>3-4 all 'copies' disappear, leaving only one.";
print "<br>5-6 all copies, including the original, explode, doing 1-3 damage each to anyone within two metres/yards (damage reduced as normal).";
print $line;
print "The GM should roll on this table seperately for each set of copies - however, treat up to 100 coins as 1 object.";
print $line;
print "The GM should also roll on this table if the delvers leave the dungeon with multiple copies of any object or creature.";
print $line;
print $line;
}
if ($system=="tt") {
print "<b>Chases</b>";
print $line;
print "It's likely that at some point the characters will have to run away from some of the creatures in the dungeon, or that creatures will run away from them.";
print $line;
print "If the characters are running away from, or chasing, a statted creature, both character and creature should roll 2 dice and add their SPD (doubles add and re-roll). The highest total is the faster.";
print $line;
print "If characters have lost at least half their CON, or are carrying half or more of their Weight Possible, they roll as normal but halve their final result. This applies to both delvers and non-player characters. If characters are both heavily wounded and carrying a heavy load, the result is still only halved rather than quartered.";
print $line;
print "If the characters are running away from, or chasing, a Monster Rated creature, the character should make a SR on SPD. The level of the save is the Monster Rating divided by 30, rounded up.";
print $line;
print "If characters have lost at least half their CON, or are carrying half or more of their Weight Possible, add 2 to the level of the save. Again, if a character meets both conditions, only 2 levels are added to their save, not 4. However if the Monster Rated creature has lost at least half its MR, take 2 from the level of the save.";
print $line;
print $line;
}
if ($system=="tt") {
print "<b>Searching and Hiding</b>";
print $line;
$z=rand(2,7);
print "Searching a single area will take ".($z*5)." minutes of in-game time for a thorough search. Before rolling, delvers can choose to take less time, taking 5 from their dice roll for";
if ($z>1) {
print " each";
}
print " five minutes saved.";
if ($z>1) {
print " Five minutes is the minimum time for a search.";
}
print " Delvers can search as many times as they want (remember to roll for wandering monsters).";
print $line;
print "If there's more than one hidden feature in the room, the delver should only roll once. However, this roll is compared to the relevant level and attribute for each feature.";
print $line;
print "If the delvers hide, they might have to make saving rolls (as given in the descriptions for the individual areas). If more than one creature is searching for them, the delvers subtract 2 from their roll for each 'extra' searcher.";
print $line;
print "The GM should bear in mind that the delvers might be able to cast the spell <i>Oh There It Is</i> instead of searching, and that some creatures in the dungeon might also know the spell.";
} elseif ($system=="ll") {
print "<b>Secret Doors and Illusory Walls</b>";
}
print $line;
print "If creatures are in an area with a secret door or illusory wall, or if the area is 'frequently used' by them, assume that all members of that species know about the feature. Otherwise creatures won't know about the feature.";
print $line;
print $line;
if ($ewspell>0) {
print "<b>Magic of Odand</b>";
print $line;
if ($ewspell==1) {
print "This spell comes from the parallel world of Odand. It has no level. It costs";
} else {
print "These spells come from the parallel world of Odand. They have no level. They cost";
}
print " the same regardless of the caster's level, can't be bought from the Wizard's Guild, and have no minimum INT or DEX to learn or cast. However, they can't be cast by one who has their hands bound.";
print $line;
$fromew=0;
$fromme=0;
for ($a=1;$a<=$xspnum;$a++) {
if ($ewspells[$a]==1) {
if ($a<=$elweir) {
$fromew=1;
} else {
$fromme=1;
}
print "<i>".$xspells[$a][0]." (".$xspells[$a][1]." ";
if ($wiz==1) {
print "WIZ";
} else {
print "STR";
}
print " to cast)</i> ".$xspells[$a][2];
print $line;
}
}
if ($fromew==1) {
if ($fromme==1) {
print "Partly a";
} else {
print "A";
}
print "dapted, with permission, from <a href=\"http://www.lulu.com/content/2791099\" target=\"_blank\">Eldritch Weirdness</a> by Matthew J. Finch (originally written for Dungeons & Dragons).";
}
print $line;
print $line;
};
// print levels
// details of messages on walls are generated here, because
// messages depend on what shrines are in the dungeon.
print "<b><big>Maps</big></b>";
print $line;

if ($system=="tt") {
print "Travelling from one area or intersection to an adjacent one will take ".$traveltime." minutes of in-game time. Travelling between levels will take a varying amount of time, given below. The delvers will move at half speed if any delver is carrying half or more of their Weight Possible, or has lost half or more of their CON. A delver who's both heavily wounded and carrying a heavy load will still move at half-speed, not quarter-speed.";
} elseif ($system=="ll") {
print "If a character has a Turn Movement of 60', they can travel from one area or intersection to an adjacent one in ".$traveltime." minutes of in-game time. Travelling between levels will take a varying amount of time, given below. Characters with a different movement will take more or less time, as per the Movement and Encumbrance Table on p44 of Labyrinth Lord or p36 of Mutant Future.";
}
print $line;
print "Note that the map isn't to scale. Corridors would be much longer if they were in scale to the rooms, and the rooms are actually different sizes.";
print $line;
$rs=0;
$rm=0;
for ($d=1;$d<=$l;$d++) {
$ex=0;
print "<b><big>Level ".$d."</big></b>";
print $line;
print "This level is <i>".$climates[$lclimate[$d]]."</i>.</div>";
print $line;
if (rand(1,2)==1 AND $system=="tt") {
$ad=rand(1,$advnum);
print "It smells subtly like ".$advantage[$ad][0].". This means that ".$advantage[$ad][1]." will feel more at home. Every hour of in-game time, they can re-roll one saving roll or roll in combat that they make. Dwarves, on the other hand, will feel like there's something wrong. If a dwarf succeeds on a saving roll, their next roll will be 1 level more difficult. This includes rolls to hit with ranged weapons.";
print $line;
}
$wide=max(2,rand(1,6));
print "The corridors on this level are wide enough for ".$wide." ";
if ($system=="ll") {
print "characters to walk side-by-side.";
} else {
print "humans to walk side-by-side.";
if ($d==1) {
print " For this purpose, count dwarves and hobbits as 3/4 of a human, and leprechauns as 1/2. Fairies count as 0 if they're flying, 1/3 otherwise. When fighting, every delver counts as 1 except for fairies, who count as 0 if flying or 1/2 if not. Gigantic creatures count as 2 humans whether fighting or not.";
}
}
print $line;
if ($d>1 AND $system=="tt") {
print "When the delvers first enter this level, they should each be given ".($level[$d]*100)." AP.";
print $line;
}
print "Roll for wandering monsters every ".$climatew[$climates[$lclimate[$d]]];
if ($climates[$lclimate[$d]]<>"Desert-like") {
print " of in-game time";
}
// create and print wandering monster table for this level.
if ($system=="tt") {
print ". Note that this includes when the delvers are dealing with creatures.";
print $line;
$mark=$levmark[$d];
$goal=$levgoal[$d];
$b=0;
if ($goal==1) {
print "On a five or six, the delvers encounter ";
} elseif ($goal==2) {
print "On a five, the delvers encounter ";
} else {
print "On a five or six, roll";
for ($z=1;$z<=3;$z++) {
if ($table[$mark][$z]>1) {
$b++;
}
}
if ($b==1) {
print " again";
} else {
print " ".$b." dice";
}
print " on the following table:";
print $line;
print "<table border=4 cellspacing=4 cellpadding=4><tr><td>";
if ($b>1) {
print "1st ";
}
print "roll</td>";
if ($b>1) {
print "<td>2nd roll</td>";
if ($b==3) {
print "<td>3rd roll</td>";
}
}
print "<td>result</td></tr>";
}
$curr=0;
for ($z=1;$z<=$sn;$z++) {
for ($a=1;$a<=$wmtable[$d][$z];$a++) {
$curr++;
if ($goal==2 AND $curr==2) {
print "<br><br>On a six, they encounter ";
} elseif ($goal>2) {
print "<tr>";
for ($colu=1;$colu<=3;$colu++) {
if ($table[$mark][$colu]<>1) {
print "<td>";
$period=1;
if ($colu<3) {
for ($oco=3;$oco>$colu;$oco--) {
$period=$period*$table[$mark][$oco];
}
}
$incr=6/$table[$mark][$colu];