This page displays the source code for the Tunnels & Trolls dungeon generator.
source code for index.php
 
<head>
<link rel="shortcut icon" href="http://www.apolitical.info/webgame/favicon.ico" type="image/vnd.microsoft.icon">
<title>Random Dungeon Generator, by Age of Fable.</title>
</head>
<body>
<div align="center"><a href="http://www.apolitical.info/webgame" onMouseover="window.status='back to the starting page'; return true">return to Age of Fable</a> . <a href="http://www.apolitical.info/webgame?mode=7" onMouseover="window.status='back to the library'; return true">return to library</a> . <a href="http://www.apolitical.info/webgame/dungeon/sourcecode" target="_blank" onMouseover="window.status='view the sourcecode'; return true">view the sourcecode</a></div>
<div>&nbsp</div>
<?php
print "<div align=\"center\"><img src=\"http://www.apolitical.info/webgame/dungeon/title";
if ($mode>1) {
print "-ll";
}
print ".jpg\" border=1></div><div align=\"center\">character pictures by ";
if ($mode>1) {
print "<a href=\"http://www.threeheadedtroll.com\" target=\"_blank\">Jason Braun</a></div>";
} else {
print "<a href=\"http://www.gwindel.eu\" target=\"_blank\">gwindel</a></div>";
}
?>
<form name="input" action="create" method="get">
<table align="center">
<tr><td align="right">What level of character should the dungeon be designed for?</td>
<td width=10></td>
<td><input type="text" size=2 name="s" value=1></td></tr>
<tr><td align="right">What group size should the dungeon be designed for?</td>
<td width=10></td>
<td><input type="text" size=2 name="c" value=4></td></tr>
<tr><td align="right">How many levels should the dungeon have?</td>
<td width=10></td>
<td><input type="text" size=2 name="l" value=4></td></tr>
<tr><td align="right">Roughly how many areas should each level have?</td>
<td width=10></td>
<td><input type="text" size=2 name="r" value=20></td></tr>
<?php
if ($mode==2) {
print "<input type=\"hidden\" name=\"system\" value=\"ll\">";
} else {
print "<tr><td align=\"right\">What attributes should monsters have?</td>";
print "<td width=10></td>";
print "<td><input type=\"radio\" name=\"stormr\" value=3>MR only<br>";
print "<input type=\"radio\" name=\"stormr\" value=1>full stats<br>";
print "<input type=\"radio\" name=\"stormr\" value=2 checked>either</td></tr>";
print "<tr><td align=\"right\">Should Wizardry be used as an attribute?</td>";
print "<td width=10></td>";
print "<td><input type=\"radio\" name=\"wiz\" value=1 checked>Yes<br>";
print "<input type=\"radio\" name=\"wiz\" value=0>No<td></tr>";
print "<tr><td align=\"right\">Should Speed contribute to combat adds?</td>";
print "<td width=10></td>";
print "<td><input type=\"radio\" name=\"spd\" value=1 checked>Yes<br>";
print "<input type=\"radio\" name=\"spd\" value=0>No</td></tr>";
print "<tr><td align=\"right\">What should the default method of working out<br>Monster Rated monsters' dice and adds be?</td>";
print "<td width=10></td>";
print "<td><input type=\"radio\" name=\"adds\" value=1>4th edition<br>";
print "<input type=\"radio\" name=\"adds\" value=4 checked>5th edition<br>";
print "<input type=\"radio\" name=\"adds\" value=3>7th edition</td></tr>";
}
?>
<tr><td align="right">Gods</td>
<td width=10></td>
<td><input type="radio" name="godd" value=1 checked>Specific - eg "Thoth, the ibis-headed god of magic."<br>
<input type="radio" name="godd" value=0>General - eg "The god of magic."<br>
<input type="radio" name="godd" value=2>No gods.</td></tr>
</table>
<div align="center"><input type="submit" value="submit"></div>
</form>
<div align="center">If you want a world to put your dungeon in, you could use my <a href="http://www.apolitical.info/webgame/map" target="_blank">Random Map Generator</a>.</div>
<div>&nbsp</div>
<div align="center">A lot of the ideas in the dungeon generator come from my collection of <a href="http://www.apolitical.info/webgame/tables" target="_blank">random tables</a>.</div>
<?php
$line="<div>&nbsp</div>";
print $line;
if (!isset($mode)) {
print "<div align=\"center\"><a href=\"http://www.apolitical.info/webgame/dungeon?mode=1\">Credits, and What's Tunnels & Trolls?</a></div>";
} elseif ($mode==1) {
print "Tunnels & Trolls is a pen-and-paper role-playing game that's been around since the 70s. The main attraction of it is that it's very easy, unlike Dungeons & Dragons and other similar games. There's a free set of cut-down rules at <a href=\"http://www.freedungeons.com/rules\" target=\"_blank\">freedungeons.com</a>. The main things that are in this generator, and aren't in the rules there, are:";
print "<ul>";
print "<li>A lot of people use an extra attribute, called Wizardry (or WIZ), which is reduced when you cast spells (Strength is used this way in the freedungeons rules).";
print "<li>You can count Speed towards your Combat Adds in the same way that Strength, Dexterity and Luck are counted. If you use this rule, you might also want to let characters increase their SPD (by the new level number) when they gain a level.";
print "<li>As well as Warriors and Wizards, there are Rogues. Rogues aren't thieves (as in a lot of games). Instead, they're halfway between Warriors and Wizards. They can use any weapon like Warriors, but they don't get the Warrior's bonus for armour. They can learn spells, but they don't start knowing all the first level spells like Wizards do. They also can't automatically buy spells - they have to find them during their adventures.";
print "<li>As well as humans, dwarves, elves and hobbits, you can be a fairy or a leprechaun.";
print "<ul><li>Fairies change their attributes as follows: STR x 1/4, LK x 3/2, CON x 1/4, DEX x 3/2.";
print "<li> Leprechauns change their attributes as follows: STR x 1/2, CON x 3/2, DEX x 3/2.";
print "<li> Fairies can fly, if their equipment weighs less than half of their Weight Possible.";
print "<li> Leprechauns have to be Wizards - but, like Rogues, they can't buy spells automatically. They start knowing the spell Wink-Wing, and it only 'costs' them 5 WIZ points (or 5 STR, if you're not using WIZ).";
print "</ul>";
print "<li>Spite Damage: fights where both sides are heavily armoured can end in stalemate. Spite Damage is designed to get around this. When characters are fighting hand-to-hand, each 6 rolled (by either side) counts as an extra point of damage, which isn't reduced by armour. Hit Point Totals are still compared in the normal way.";
print "</ul>";
print "The main places on the internet where people talk about Tunnels & Trolls seem to be the <a href=\"http://trollbridge.proboards44.com\" target=\"_blank\">Trollbridge forum</a>, and the <a href=\"http://games.groups.yahoo.com/group/radiofreetrollworld\" target=\"_blank\">Radio Free Trollworld</a> email list. I'm on Trollbridge, so if you want to ask me a question you can do it via that.";
print $line;
print "You can buy the rules, which have some extra equipment and spells etc, from <a href=\"http://www.flyingbuffalo.com/tandt.htm\" target=\"_blank\">Flying Buffalo Inc.</a> (also known as FBI). Another site that sells Tunnels & Trolls stuff is <a href=\"http://www.geocities.com/hobbit_lands\" target=\"_blank\">Outlaw Press</a>.";
print $line;
print "Tunnels & Trolls is by Ken St Andre, with editing by Liz Danforth. The misfire table for pistols and the rules for bullwhips are adapted from material by Toad-Killer-Dog from Trollbridge. Some extra equipment by Outlaw Press. Some jewels taken from a list by mahrundl from Trollbridge. The 'Eyes' are inspired by those in M.A.R. Barker's <a href=\"http://www.tekumel.com\" target=\"_blank\">Tekumel</a>. Magic of Odand adapted, 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). Everything else by Age of Fable.";
print $line;
print "<div align=\"center\"><a href=\"http://www.apolitical.info/webgame/dungeon\">close this</a>";
} elseif ($mode==2) {
print "<div align=\"center\"><a href=\"http://www.apolitical.info/webgame/dungeon?mode=3\">What Are Labyrinth Lord and Mutant Future?</a></div>";
} else {
print "Labyrinth Lord and Mutant Future are free pen-and-paper role-playing games. Labyrinth Lord repeats the rules from an old version of Dungeons & Dragons.";
print $line;
print "Mutant Future is set after a nuclear war. It's not supposed to be realistic: characters can be robots, intelligent plants, mutants with powers like being able to fly, and so on. It's similar to an old game called Gamma World. However the rules of Mutant Future are almost the same as the rules for Labyrinth Lord. So you can use the same adventure for either game. The main difference is that in Mutant Future you start a lot more powerful than in Labyrinth Lord.";
print $line;
print "This generator creates dungeons that are sort of half-and-half - with both magic and technology.";
print $line;
print "You should look at Section 9 of Mutant Future especially, because it gives rules for combining the two games (by making the 'mutant' characters less powerful).";
print $line;
print "The rules for Labyrinth Lord are <a href=\"http://www.goblinoidgames.com/labyrinthlord.htm\" target=\"_blank\">here</a>, the Mutant Future rules are <a href=\"http://www.goblinoidgames.com/mutantfuture.htm\" target=\"_blank\">here</a>. Both games are in pdf format, which needs Acrobat Reader. In the highly unlikely event that your computer doesn't have Acrobat Reader, it's <a href=\"http://www.adobe.com/products/acrobat/readstep2.html\" target=\"_blank\">here</a> (and also free).";
print $line;
print "<div align=\"center\"><a href=\"http://www.apolitical.info/webgame/dungeon?mode=2\">close this</a>";
}
?>
<div>&nbsp</div>
<div align="center"><a href="http://www.apolitical.info/webgame" onMouseover="window.status='back to the starting page'; return true">return to Age of Fable</a> . <a href="http://www.apolitical.info/webgame?mode=7" onMouseover="window.status='back to the library'; return true">return to library</a> . <a href="http://www.apolitical.info/webgame/dungeon/sourcecode" target="_blank" onMouseover="window.status='view the sourcecode'; return true">view the sourcecode</a></div>
<div>&nbsp</div>
<div align="center">
<!--the code for the 'Project Wonderful' ad is here in the original page.-->
</body>
 
source code for create.php
 
<head>
<title>Tunnels & Trolls Random Dungeon Generator, by Age of Fable.</title>
</head>
<body>
<div align="center"><a href="http://www.apolitical.info/webgame" onMouseover="window.status='back to the starting page'; return true">return to Age of Fable</a> . <a href="http://www.apolitical.info/webgame?mode=7" onMouseover="window.status='back to the library'; return true">return to library</a></div>
<div>&nbsp</div>
<?php
// LL/MF MONSTERS SHOULD HAVE CHANCE TO ALTER THE TEMPERATURE,
// ALSO STATUES (maybe jewel, normal, or statue)
// however none of the other special stuff.

// searching for secret doors LL.
// Thieves have listed chance + x%. All other characters have x%
// or Thieves have chance of level + ... others level - ...
// or Thieves have listed chance, no one else chance.

// features to add:

// magic instruments - extra magic items in general.

// if the creature does extra damage to unarmoured foes, or poison, and uses weapons, specify whether the power is in their weapons.

// if a creature is ghostly or demonic, their weapon (if they have one) may have effects in the same way as their armour.

// 'stuck in body' - reduce chance or eliminate if the creature
// wears armour and/or has tough skin (may require re-ordering).
//
// poison darts which generate damage total, but don't do damage.
// instead, if damage gets through armour and shields, delusion.
// (for example, forbidden to climb stairs).

// as per Trollbridge, 'first aid' rules - probably have a manual
// of first aid, which requires a week eg to study.

// book on herbs. once leave dungeon can take a week and
// make a save and if succeed pay half cost for poisons.
// book on first aid, as above.
// put these in same bit as phrasebook.

// poison: put who can recognise as poison / specific poison,
// and effect of drinking. Ditto holy water.

// mythic items.

// 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.<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."),
);
$eyenum=7;
$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.

$unguarded=array(
1=> array (2,4,100,1,4,10,50,1,4,7,1,4,5,3),
2=> array (2,6,100,1,6,100,50,1,6,13,1,6,8,5),
3=> array (2,8,100,2,4,100,50,1,6,15,1,6,10,7),
4=> array (1,8,1000,3,4,100,100,1,8,20,1,8,10,7),
5=> array (1,8,1000,3,4,100,100,1,8,20,1,8,10,7),
6=> array (1,8,2000,1,4,1000,100,1,8,30,1,8,15,15),
7=> array (1,8,2000,1,4,1000,100,1,8,30,1,8,15,15),
8=> array (1,8,4000,2,4,1000,100,2,6,40,2,6,20,20),
9=> array (1,8,4000,2,4,1000,100,2,6,40,2,6,20,20),
);
// $unguarded is an array representing LL/MF unprotected treasure
// (this includes treasure in the same room as a trap).
// slots 0-2 silver pieces: 2d4 x 100 would be 2,4,100 eg.
// 3-6 gold pieces, in the same format - slot 6 is % chance.
// 7-9 gems: 1d4 (30% chance) would be 1,4,30 eg.
// 10-12 jewelry: in the same format.
// 13: percentage chance of a magic item or artifact
// (always 1, always any).

$llitems=array(
1=> array ("potion",21),
2=> array ("ring",26),
3=> array ("scroll",57),
4=> array ("rodstavewand",62),
5=> array ("misc magic",67),
6=> array ("sword",88),
7=> array ("misc weapon",93),
8=> array ("armour",101),
);
// 0=type (never printed - only used 'internally')
// 1='any magic item's are this type of item
// if d100 is under this number, and not under the equivalent
// number for the previous entry.
// only used for LL/MF.

$mfitems=array(
1=> array ("firearm",6),
2=> array ("melee",18),
3=> array ("pistol",26),
4=> array ("rifle",34),
5=> array ("armour",42),
6=> array ("power",51),
7=> array ("grenade",60),
8=> array ("bomb",69),
9=> array ("gizmo",80),
10=> array ("chem",91),
11=> array ("foodjunk",101),
);
// means the same as for $llitems.

$bditems=array();
// this is number of items or artifacts.
// it's added to when doing treasure type,
// then broken down.
// 1 - any
// 2 - any except weapons
// 3 - armour, sword or weapon (for MF, not grenades or bombs)
// 4 - scroll for LL, gizmos for MF
// 5 - potion for LL, drugs & chemicals for MF


$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 $llitems and $mfitems respectively.

$llgems=array(
1=> array (" pearl","pearls",10,16),
2=> array ("n opal","opals",25,31),
3=> array (" sapphire","sapphires",50,46),
4=> array (" topaz","topazes",75,61),
5=> array ("n amethyst","amethysts",100,76),
6=> array (" piece of jade","pieces of jade",250,86),
7=> array (" ruby","rubies",500,91),
8=> array ("n emerald","emeralds",750,96),
9=> array (" diamond","diamonds",1000,101),
);
// 0 = singular, 1=plural, 2=value,
// 3=it's this gem if d100 is under this number
// (and it isn't the previous one)

$lljewels=array(
1=> array ("ring","rings",1,4,10),
2=> array ("ring","rings",1,4,10),
3=> array ("brooch","brooches",2,4,10),
4=> array ("bracelet","bracelets",1,4,100),
5=> array ("set of earrings","sets of earrings",2,4,100),
6=> array ("pendant","pendants",2,6,100),
7=> array ("necklace","necklaces",3,6,100),
8=> array ("necklace","necklaces",3,6,100),
9=> array ("necklace","necklaces",3,6,100),
10=> array ("necklace","necklaces",3,6,100),
);
// 0: singular, 1: plural
// 2-4: value of 1d4 x 10gp is 1,4,10 eg.
// only used for LL/MF.

$ament=array ("null","Chaotic","Neutral","Lawful");
$saves=array ("null","Fighter","Magic-User","Cleric","Thief","Dwarf","Elf");
$whoard=array();
$lhoard=array();
$llavtr=array();
$wnenca=array();
$wnencb=array();
$lnenca=array();
$lnencb=array();
// if the number encountered is 2d4, for example,
// $wnenca will be 2 and $wnencb will be 4 (for wandering),
// $lnenca will be 2 and $lnencb will be 4 (for lair).
$hdice=array();
$hdiceadd=array();
$diceface=array("null",1,3,4,6,8,10,12);
$dicenum=7;
$attackdice=array();
$attacknum=array();
$thpsame=array("null",20,30,35,60,60,75,75,80);
$thpwand=array("null",20,40,50,60,70,80,85,90);
$minhd=array("null",0,1,2,2,2,2,3,4);
$maxhd=array("null",2,3,4,5,7,9,11,12);
$treasuretypes=array(
1=> array ("I",0.14),
2=> array ("II",1),
3=> array ("III",3.25),
4=> array ("IV",4.5),
5=> array ("V",35),
6=> array ("VI",119.4985),
7=> array ("VII",266.3525),
8=> array ("VIII",1125),
9=> array ("IX",2250),
10=> array ("X",12921.7),
11=> array ("XI",247.1),
12=> array ("XII",362.5),
13=> array ("XIII",46.25),
14=> array ("XIV",4012.8625),
15=> array ("XV",48354.625),
16=> array ("XVI",24074.675),
17=> array ("XVII",6746.5),
18=> array ("XVIII",3175.2875),
19=> array ("XIX",4215.1),
20=> array ("XX",1149.8),
21=> array ("XXI",1608.025),
22=> array ("XXII",12357.0625),
);
// the 2nd element is average value, with magic items
// being counted as being worth 1000gp each.

$monmor=array(
1=> array ("null",5,6,6,7,7,7,7,7,7,7,8,8,8,9,9,9,10,11,12,12),
2=> array ("null",5,6,7,7,7,7,7,7,8,8,8,8,9,9,9,9,10,11,12,12),
3=> array ("null",6,6,7,7,8,8,8,8,9,9,9,10,10,10,11,12,12,12,12,12),
4=> array ("null",6,6,7,8,8,8,8,9,9,9,9,10,10,10,11,12,12,12,12,12),
5=> array ("null",6,6,7,8,8,8,8,9,9,9,9,10,10,10,11,12,12,12,12,12),
6=> array ("null",7,7,7,8,8,8,9,9,9,9,10,10,10,10,11,12,12,12,12,12),
);
// $monmor[$x][1-20] determines the morale
// of a monster whose home level is level $x.

$monsp=array(
1=> array ("null",60,60,60,60,60,60,90,90,90,90,90,90,90,90,120,120,180,180,210,210),
2=> array ("null",60,60,60,60,60,90,90,90,90,90,120,120,120,120,120,180,180,210,210,210),
3=> array ("null",60,60,60,60,90,90,90,90,120,120,120,120,150,150,180,180,210,210,210,210),
4=> array ("null",60,60,60,60,90,90,90,90,120,120,120,150,150,150,180,210,240,240,240,300),
5=> array ("null",60,60,60,60,90,90,90,90,120,120,120,150,150,150,180,210,240,240,240,300),
6=> array ("null",60,60,60,90,90,90,90,90,120,120,150,150,180,180,210,240,240,240,300,300),
7=> array ("null",60,60,60,90,90,90,90,90,120,120,150,150,180,180,210,240,240,240,300,300),
8=> array ("null",60,60,90,90,120,120,120,120,120,120,180,180,180,210,210,240,240,240,300,300),
);
// $monsp does the same for speed.
// if the creature has two speeds, this array generates the
// higher one.

$cleric=array(
1=> array ("null","Cure Light Wounds","Detect Evil (Cleric version)","Detect Magic","Light","Protection From Evil","Purify Food and Drink","Remove Fear","Resist Cold"),
2=> array ("null","Bless","Find Traps","Know Alignment","Hold Person","Resist Fire","Silence 15' Radius","Snake Charm","Speak with Animal"),
3=> array ("null","Animal Growth","Animate Dead","Continual Light","Dispel Magic","Locate Object","Remove Curse","Striking"),
4=> array ("null","Create Food and Water","Cure Serious Wounds","Detect Lie","Lower Water","Neutralize Poison","Protection from Evil 10' Radius","Speak With Plants","Sticks to Snakes"),
5=> array ("null","Commune","Cure Critical Wounds","Dispel Evil","Flame Strike","Insect Plague","Quest","Raise Dead","True Seeing"),
6=> array ("null","Animate Objects","Blade Barrier","Conjure Animals","Find the Path","Heal","Part Water","Stone Tell","Word of Recall"),
7=> array ("null","Control Weather","Earthquake","Holy Word","Regenerate","Restoration","Resurrection","Symbol (Cleric version)","Wind Walk"),
);
// there are 7 levels, each with 8 spells.

$elfmu=array(
1=> array ("null","Charm Person","Detect Magic","Floating Disc","Hold Portal","Light","Magic Missile","Protection from Evil","Read Languages","Read Magic","Shield","Sleep","Ventriloquism"),
2=> array ("null","Arcane Lock","Continual Light","Detect Evil (Elf/Magic-User version)","Detect Invisible","ESP","Invisibility","Knock","Levitate","Locate Object","Mirror Image","Phantasmal Force","Web"),
3=> array ("null","Clairvoyance","Dispel Magic","Fire Ball","Fly","Haste","Hold Person","Infravision","Invisibility 10' Radius","Lightning Bolt","Protection from Evil 10' Radius","Protection from Normal Missiles","Water Breathing"),
4=> array ("null","Arcane Eye","Charm Monster","Confusion","Dimension Door","Hallucinatory Terrain","Massmorph","Plant Growth","Polymorph Others","Polymorph Self","Remove Curse","Wall of Fire","Wall of Ice"),
5=> array ("null","Animate Dead","Cloudkill","Conjure Elemental","Contact Other Plane","Feeblemind","Hold Monster","Magic Jar","Passwall","Telekinesis","Teleport","Transmute Rock to Mud","Wall of Stone"),
6=> array ("null","Anti-Magic Shell","Control Weather","Death Spell","Disintegrate","Geas","Invisible Stalker","Lower Water","Move Earth","Part Water","Project Image","Reincarnation","Stone to Flesh"),
7=> array ("null","Grasping Hand","Delayed Blast Fireball","Instant Summons","Duo-Dimension","Limited Wish","Mass Invisibility","Magic Sword","Phase Door","Power Word Stun","Reverse Gravity","Simulacrum","Statue"),
8=> array ("null","Antipathy/Sympathy","Clenched Fist","Clone","Glass Like Steel","Incendiary Cloud","Irresistible Dance","Mass Charm","Maze","Mind Blank","Polymorph Any Object","Symbol (Elf/Magic-User version)","Trap the Soul"),
9=> array ("null","Crushing Hand","Imprisonment","Meteor Swarm","Power Word Kill","Prismatic Sphere","Shape Change","Temporal Stasis","Time Stop","Wish"),
);
// there are 9 levels, each with 12 spells,
// except for level 9, which has only 9 spells.

$advantage=array(
1=> array ("baked bread","hobbits and humans"),
2=> array ("a forest","humans, fairies, leprechauns and elves"),
3=> array ("a city","humans"),
);
$advnum=3;
$rd=array();
$mwidth=10;
$shrine=array();
$language=array(
1=> "Common",
2=> "Dwarvish",
3=> "Elvish",
4=> "Orcish",
5=> "Hobbit",
6=> "Leprechaun",
);
$langnum=6;
if ($system=="ll") {
$language[5]="Goblin";
$language[6]="Halfling";
$language[7]="Gnome";
$language[8]="Kobold";
$language[9]="Gnoll";
$language[10]="Hobgoblin";
$language[11]="Chaotic";
$language[12]="Neutral";
$language[13]="Lawful";
$langnum=13;
}
$stats=array();
$crmag=array();
$crlang=array();
$crarmour=array();
$crsize=array();
$sizetext=array(
1=> array (3,"roughly fairy-sized","fairies",4),
2=> array (10,"roughly leprechaun-sized","leprechauns",3),
3=> array (15,"roughly hobbit-sized","hobbits",3),
4=> array (20,"roughly dwarf-sized","dwarves",2),
5=> array (30,"roughly human-sized","humans and elves",2),
6=> array (60,"gigantic","XXX",1),
);
$sizecats=6;
$grp=array();
$enc=array();
$wmtable=array();
$wmll=array();
$levmark=array();
$levgoal=array();
$table=array(
1=> array (1,"N/A","N/A","N/A"),
2=> array (2,"N/A","N/A","N/A"),
3=> array (3,1,1,3),
4=> array (6,1,1,6),
5=> array (9,1,3,3),
6=> array (12,1,6,2),
7=> array (18,1,6,3),
8=> array (24,6,2,2),
9=> array (27,3,3,3),
10=> array (36,1,6,6),
);
$splus=array();
$mrtype=array();
$desc=array();
$spt=array();
$namefirst=array(
1 => "Abber",
2 => "Abomin",
3 => "Albin",
4 => "Arach",
5 => "Arg",
6 => "Arimas",
7 => "Ash",
8 => "Atlan",
9 => "Auton",
10 => "Baph",
11 => "Bar",
12 => "Basil",
13 => "Blu",
14 => "Bru",
15 => "Bucen",
16 => "Cac+",
17 => "Capr+",
18 => "Car",
19 => "Carn+",
20 => "Cary",
21 => "Cato",
22 => "Cer",
23 => "Cha",
24 => "Chi",
25 => "Chiro",
26 => "Col",
27 => "Cyn",
28 => "Degen",
29 => "Der",
30 => "Dich",
31 => "Dodec",
32 => "Dol",
33 => "Dr+",
34 => "Drac",
35 => "Fom",
36 => "Gor",
37 => "Gorg",
38 => "Gr+",
39 => "Har",
40 => "Hecat+",
41 => "Hecaton",
42 => "Hell+",
43 => "Hipp",
44 => "Hyper",
45 => "Ich",
46 => "Icht",
47 => "Jugger",
48 => "Mal",
49 => "Manti",
50 => "Megalo",
51 => "Min",
52 => "Mor",
53 => "Mus",
54 => "Myr",
55 => "Nyct",
56 => "Olym",
57 => "Olymp",
58 => "Per",
59 => "Ple",
60 => "Pyr+",
61 => "Quin",
62 => "Rhab",
63 => "Rhin",
64 => "Sagit",
65 => "Scor",
66 => "Sti",
67 => "Tant+",
68 => "Tetr+",
69 => "Tri",
70 => "Trag",
71 => "Trog",
72 => "Un",
73 => "Urs"
);
$firstnum=73;
$namesecond=array(
1 => "ban",
2 => "banian",
3 => "barian",
4 => "basti",
5 => "beria",
6 => "beros",
7 => "bian",
8 => "blepas",
9 => "borean",
10 => "can",
11 => "cephal",
12 => "cephalon",
13 => "ceros",
14 => "chios",
15 => "clope",
16 => "clops",
17 => "core",
18 => "corn",
19 => "cornean",
20 => "crit",
21 => "crota",
22 => "cus",
23 => "dosian",
24 => "dra",
25 => "dyte",
26 => "ean",
27 => "gog",
28 => "gon",
29 => "gryph",
30 => "lian",
31 => "lid",
32 => "liph",
33 => "lith",
34 => "lock",
35 => "mander",
36 => "mar",
37 => "massu",
38 => "median",
39 => "mera",
40 => "mia",
41 => "mian",
42 => "midon",
43 => "mur",
44 => "mure",
45 => "nasm",
46 => "naut",
47 => "neon",
48 => "niad",
49 => "nian",
50 => "nid",
51 => "nite",
52 => "nix",
53 => "path",
54 => "pax",
55 => "phalon",
56 => "phant",
57 => "pheros",
58 => "phin",
59 => "phon",
60 => "pian",
61 => "pion",
62 => "poid",
63 => "pusa",
64 => "rate",
65 => "raton",
66 => "ratos",
67 => "rax",
68 => "rena",
69 => "rete",
70 => "roid",
71 => "ron",
72 => "rone",
73 => "ronian",
74 => "ront",
75 => "ros",
76 => "rost",
77 => "saur",
78 => "seid",
79 => "sk",
80 => "soid",
81 => "ssus",
82 => "st",
83 => "stomos",
84 => "tanian",
85 => "tarian",
86 => "taur",
87 => "tauride",
88 => "taurine",
89 => "teon",
90 => "tep",
91 => "tesk",
92 => "tetra",
93 => "theon",
94 => "thid",
95 => "thoid",
96 => "thol",
97 => "tid",
98 => "toid",
99 => "tomian",
100 => "ton",
101 => "tor",
102 => "tos",
103 => "trice",
104 => "tyr",
105 => "vern",
106 => "vore",
);
$secondnum=106;
$vowels=array(
1=> "a",
2=> "e",
3=> "i",
4=> "o",
5=> "u",
6=> "y",
7=> "ae",
8=> "ai",
9=> "ao",
10=> "au",
11=> "ea",
12=> "ee",
13=> "ei",
14=> "eo",
15=> "eau",
16=> "ia",
17=> "ie",
18=> "io",
19=> "oa",
20=> "oe",
21=> "oi",
22=> "oo",
23=> "ou",
24=> "ua",
25=> "ue",
26=> "ui",
27=> "uo",
);
$vnum=27;

$namethird=array(
1=> "Shambling",
2=> "Whispering",
3=> "Slithering",
4=> "Shadow",
5=> "Bright",
6=> "Sun",
7=> "Light",
8=> "Gibbering",
9=> "Screaming",
10=> "Foul",
11=> "Shining",
12=> "Golden",
13=> "Bronze",
14=> "Hungry",
15=> "Merciful",
16=> "Compassionate",
17=> "Peaceful",
18=> "Beautiful",
19=> "Pitiful",
20=> "Twisted",
21=> "Nameless",
22=> "Hopeful",
23=> "Harmonious",
24=> "-With-Two-Voices",
25=> "Watchful",
26=> "Velvet",
27=> "Silk",
28=> "Harsh",
29=> "Ancient",
30=> "Imperial",
31=> "Lost",
32=> "-Who-Waits",
33=> "Conquering",
34=> "Silent",
35=> "-in-Yellow",
36=> "Greedy",
37=> "Mad",
38=> "Green",
39=> "Fat",
40=> "Barrow-",
41=> "Proud",
42=> "Love's",
43=> "Purple",
44=> "-in-the-Green",
45=> "-on-the-Hill",
46=> "-o'-the-Isles",
47=> "Floating",
48=> "-in-the-Dark",
49=> "Cave",
50=> "Thin",
51=> "Burrowing",
52=> "'s Mercy",
53=> "'s Ruin",
54=> "High",
55=> "-of-the-Ancients",
// entries from here on are only for MF/LL
56=> "Electric",
57=> "Gamma",
58=> "Radiation",
59=> "Brain",
60=> "Xeno",
61=> "Clone",
62=> "Waste",
63=> "Toxic",
64=> "Cybernetic",
65=> "Cyber-",
);
$thirdnum=55;
if ($system=="ll") {
$thirdnum=65;
}

$namefourth=array(
1=> "Mother",
2=> "Sister",
3=> "Companion",
4=> "Hag",
5=> "Protector",
6=> "Servant",
7=> "Heart",
8=> "Eye",
9=> "Knight",
10=> "King",
11=> "Champion",
12=> "Judge",
13=> "Sower",
14=> "Hand",
15=> "Finger",
16=> "Warrior",
17=> "Forgiver",
18=> "Sleeper",
19=> "Lady",
20=> "Gentleman",
21=> "Drinker",
22=> "Emperor",
23=> "Guide",
24=> "Bird",
25=> "Duke",
26=> "Duchess",
27=> "Hisser",
28=> "Peacock",
29=> "Dandy",
30=> "Conqueror",
31=> "Worm",
32=> "Folk",
// entries from here on are only for MF/LL
33=> "Dog",
34=> "Leech",
35=> "Scavenger",
36=> "Cyborg",
37=> "Android",
38=> "Commando",
39=> "Spawn",
);
$fourthnum=32;
if ($system=="ll") {
$fourthnum=39;
}

// 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.

$namecount=array();
$crname=array();
$crnick=array();
$xlow=array();
$xhigh=array();
$ylow=array();
$yhigh=array();
$mrdesc=array(
"null",
"only gets its full adds for the first Combat Round. After that, it gets half its adds. Its dice are treated normally.",
"always gets @@D dice and @@A adds, regardless of how wounded it is.",
"always gets @@D dice. Its adds are based on its current MR.",
"gets both dice and adds based on its current MR.",
);
if ($adds==1) {
$mrdesc[4]="gets its full adds in every Combat Round.";
$mrdesc[2]="gets @@D dice and @@A adds each Combat Round, regardless of how wounded it is or what round it is.";
}
$appani=array(
1=> "an amoeba",
2=> "an ant",
3=> "an ape",
4=> "an armadillo",
5=> "a bat",
6=> "a bee",
7=> "a bird of paradise",
8=> "a blowfly",
9=> "a butterfly",
10=> "a cat",
11=> "a scorpion",
12=> "a crocodile",
13=> "a crow",
14=> "a dog",
15=> "a elephant",
16=> "a crow",
17=> "a shark",
18=> "a horse",
19=> "a camel",
20=> "a zebra",
21=> "an iguana",
22=> "a jackal",
23=> "a kangaroo",
24=> "a mouse",
25=> "an owl",
26=> "a parrot",
27=> "a rhinoceros",
28=> "a scarab/dung beetle",
29=> "a seagull",
30=> "a snail",
31=> "a snake",
32=> "a spider",
33=> "a tiger",
34=> "a lion",
35=> "a jaguar",
36=> "a turtle",
37=> "a vulture",
38=> "a walrus",
39=> "a warthog",
40=> "a wolf",
41=> "a rabbit",
42=> "an octopus",
43=> "an angel",
44=> "a bear",
45=> "a deer",
46=> "an ox",
47=> "a skeleton",
48=> "a grasshopper",
49=> "a triceratops",
50=> "a tyrannosaurus rex",
);
$aniapp=50;

$apppla=array(
1=> "a rose",
2=> "a venus flytrap",
3=> "a water lily",
4=> "a leaf",
5=> "a sunflower",
6=> "a sakura/cherry blossom tree",
7=> "a mushroom",
8=> "a weeping willow",
9=> "a bunch of flowers",
10=> "a laurel wreath",
11=> "a tree (with green leaves)",
12=> "a tree (with autumn leaves)",
13=> "a tree (with no leaves)",
14=> "a palm tree",
15=> "a hedge",
16=> "a clump of seaweed",
17=> "a patch of mould",
18=> "a pile of leaves",
19=> "a dandelion",
20=> "a haystack",
21=> "a four-leaf clover",
22=> "a tumbleweed",
23=> "a wooden hut",
24=> "a piece of driftwood",
);
$plaapp=24;

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

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.",
);
// @@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=26;

$sname=array("null","STR","INT","LK","CON","DEX","CHR","SPD","WIZ");
$attnum=7+$wiz;
if ($system=="ll") {
$sname[3]="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",
);
$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"=> "15 minutes",
"Hot and dry"=> "hour",
"Cold"=> "hour",
"Mild"=> "30 minutes",
"Desert-like"=> "hour of in-game time at night or in the early morning, once every 2 hours of in-game time otherwise",
);
$cnum=5;
$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;

$sett=array(
1=> "city",
2=> "town",
3=> "village",
4=> "castle",
5=> "temple",
);
$settnum=5;

$ruins=array(
1=> "airport",
2=> "military base",
3=> "bomb shelter",
4=> "factory",
5=> "holiday resort",
6=> "farm",
7=> "hospital",
8=> "mine",
9=> "missile base",
10=> "power plant",
11=> "shopping mall",
12=> "spaceport",
);
$ruinnum=12;

$map=array();
$stairs=array();
$exit=array();
$doors=array();
$doorsymbol=array("null","+","#","%");
$exitsave=array();
$stype=array(
1=> "non-printing",
2=> "wall",
3=> "tunnel",
4=> "wall",
5=> "non-printing",
6=> "wall",
7=> "corner",
8=> "2only",
9=> "corner",
10=> "wall",
11=> "tunnel",
12=> "2only",
13=> "centre",
14=> "2only",
15=> "tunnel",
16=> "wall",
17=> "corner",
18=> "2only",
19=> "corner",
20=> "wall",
21=> "non-printing",
22=> "wall",
23=> "tunnel",
24=> "wall",
25=> "non-printing",
);

$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.

// slot 0 is singular, 1 is plural
// 2 is value, 3 is weight.
$misceqpt=array(
1=> array ("A day's worth of rations","days worth of rations",10,20),
2=> array ("A 5 foot/1.5 metre rope","ropes (each 5 feet/1.5 metres long)",.5,25),
3=> array ("A 10 foot/3 metre rope","ropes (each 10 feet/3 metres long)",1,50),
4=> array ("A pair of calf-high boots (wearable by any creature from leprechaun to human size)","pairs of calf-high boots (wearable by any creature from leprechaun to human size)",10,40),
5=> array ("A pair of calf-high boots (wearable by fairy-sized creatures)","pairs of calf-high boots (wearable by fairy-sized creatures)",10,4),
6=> array ("A blanket","blankets",2,20),
7=> array ("A copper flask (holds 1 pint/half a litre)","copper flasks (each holds 1 pint/half a litre)",5,2),
8=> array ("A compass","compasses",5,1),
9=> array ("A set of lock picks (anyone using these may add 5 to their roll when trying to pick a lock)","sets of lock picks (anyone using these may add 5 to their roll when trying to pick a lock)",35,35),
10=> array ("A tent (including poles), big enough for four humans","tents (including poles), each big enough for four humans",40,250),
11=> array ("A small hand-mirror","small hand-mirrors",5,1),
12=> array ("A drinking horn","drinking horns",4,15),
13=> array ("A piece of chalk","pieces of chalk",1,0),
14=> array ("A wooden dice","wooden dice",1,0),
15=> array ("A wooden cup","wooden cups",2,1),
16=> array ("A six-foot/2 metre long wooden pole","wooden poles, each 6 feet/2 metres long",7,40),
17=> array ("A metal spoon","metal spoons",2,0),
18=> array ("A metal fork","metal forks",2,0),
19=> array ("A metal knife (for eating with - it's no use in combat)","metal knives (for eating with - they're no use in combat)",2,0),
20=> array ("A chalk-board (8 by 8 inches/20 by 20 cm)","chalk-boards (8 by 8 inches/20 by 20 cm)",2,9),
);
$eqptnum=20;

// 0 is name, 1 is weight, 2 is value.
$music=array(
1=> array ("bagpipes",30,500),
2=> array ("small harp",100,100),
3=> array ("large harp",1000,1000),
4=> array ("drum",20,10),
5=> array ("flute",5,50),
6=> array ("sitar",50,500),
7=> array ("lute",50,300),
8=> array ("pan pipes",5,50),
);
$musnum=8;

$arm=array (
1=> array ("helmet",1,1,10,25),
2=> array ("helmet",2,1,15,35),
3=> array ("helmet",3,1,20,50),
4=> array ("shield",3,1,10,75),
5=> array ("shield",4,5,35,300),
6=> array ("shield",5,5,65,450),
7=> array ("shield",6,6,100,550),
8=> array ("breastplate",1,1,15,50),
9=> array ("full suit of armour",2,1,30,70),
10=> array ("breastplate",3,1,30,150),
11=> array ("breastplate",4,2,70,240),
12=> array ("breastplate",4,3,35,500),
13=> array ("full suit of armour",5,1,40,170),
14=> array ("breastplate",5,2,200,570),
15=> array ("full suit of armour",6,3,90,270),
16=> array ("breastplate",6,6,150,800),
17=> array ("full suit of armour",7,6,70,720),
18=> array ("full suit of armour",8,4,385,860),
19=> array ("breastplate",8,5,100,900),
20=> array ("full suit of armour",9,11,285,1160),
21=> array ("full suit of armour",11,10,480,950),
22=> array ("full suit of armour",14,12,600,1200),
);
$armnum=22;
// 0 is broad type, 1 is protection, 2 is STR required
// 3 is cost, 4 is weight

$handw=array(
1=> array ("sword",6,2,22,18,0,135,150,0,2),
2=> array ("sword",6,1,21,18,0,125,165,0,2),
3=> array ("sword",6,0,21,18,0,120,170,0,2),
4=> array ("sword",5,2,17,14,0,110,160,0,2),
5=> array ("sword",5,0,16,12,0,90,150,0,2),
6=> array ("sword",3,4,15,10,0,70,120,0,1),
7=> array ("sword",3,2,10,7,0,50,70,0,1),
8=> array ("sword",3,0,7,3,0,35,30,0,1),
9=> array ("sword",4,4,12,13,0,75,110,0,1),
10=> array ("sword",4,0,10,11,0,60,100,0,1),
11=> array ("sword",3,4,10,14,0,80,20,0,1),
12=> array ("axe",6,3,21,10,0,140,220,0,2),
13=> array ("hatchet",2,2,7,5,10,28,35,15,1),
14=> array ("mace",5,2,17,3,0,120,200,0,2),
15=> array ("hammer",5,1,16,3,0,85,300,0,1),
16=> array ("morning star",5,0,17,11,0,140,110,0,1),
17=> array ("mace",3,4,12,7,0,120,125,0,1),
18=> array ("club",3,0,5,2,0,15,50,0,1),
19=> array ("polearm",7,0,14,13,0,210,300,0,2),
20=> array ("polearm",6,5,15,12,0,250,190,0,2),
21=> array ("pike",6,0,16,12,0,160,100,0,2),
22=> array ("staff",2,0,2,8,0,10,50,0,1),
23=> array ("club",2,0,2,1,0,10,20,0,1),
24=> array ("trident",4,3,10,10,10,60,75,10,1),
25=> array ("dagger",2,5,7,10,0,30,25,0,1),
26=> array ("dagger",2,5,6,6,30,30,20,10,1),
27=> array ("dagger",2,4,2,4,0,25,10,0,1),
28=> array ("dagger",2,3,1,4,23,20,33,10,1),
29=> array ("dagger",2,1,1,4,10,18,16,10,1),
30=> array ("dagger",2,-2,1,1,8,5,10,10,1),
);
$handnum=30;

// put nets in later, as they have their own rules.

// 0 is broad type, 1 is dice, 2 is adds, 3 is STR required,
// 4 is DEX to use hand-to-hand, 5 is DEX to throw, 6 is cost,
// 7 is weight, 8 is range, 9 is 'handedness'.

$rangew=array(
1=> array ("javelin",2,0,5,7,"self",10,30,40,1),
2=> array ("sling staff",3,0,5,11,"stone",5,100,150,2),
3=> array ("sling",3,0,5,11,"stone",1,10,100,1),
4=> array ("throwing star",1,0,2,10,"self",30,10,10,1),
5=> array ("throwing knife",4,0,8,15,"self",180,125,30,1),
6=> array ("crossbow",8,0,15,10,"bolt",600,250,100,2),
7=> array ("crossbow",5,0,15,10,"bolt",250,180,100,2),
8=> array ("crossbow",4,0,12,10,"bolt",170,120,90,2),
9=> array ("bow",6,0,25,17,"arrow",200,70,100,2),
10=> array ("bow",4,3,15,15,"arrow",100,60,140,2),
11=> array ("bow",2,0,9,15,"arrow",50,30,60,2),
12=> array ("bullwhip",0,0,0,15,"self",30,45,5,1),
13=> array ("pistol",5,15,10,8,"self",1000,50,"any",1),
);
$rangenum=13;

// 0 is broad type, 1 is dice, 2 is adds, 3 is STR required,
// 4 is DEX required, 5 is ammunition - "self" means it's 'ammunition'
// in itself (eg javelins and throwing stars), anything else refers
// to the $ammo array. 6 is cost, 7 is weight, 8 is range, 9 is
// 'handedness'.

$ammo=array(
'stone'=> array ("100 sling stones",3,50),
'bolt'=> array ("10 crossbow bolts",5,10),
'arrow'=> array ("24 arrows",40,10),
);
// 0 is name to print, 1 is value, 2 is weight.

$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.

$jewel=array (
1 => array ("rose pink quartz",1),
2 => array ("smokey quartz",2),
3 => array ("green quartz",3),
4 => array ("citrine",4),
5 => array ("alexandrite",5),
6 => array ("jasper",6),
7 => array ("cat's eye",7),
8 => array ("agate",8),
9 => array ("peridot",9),
10 => array ("mother-of-pearl",10),
11 => array ("sardonyx",11),
12 => array ("carnelian",12),
13 => array ("amber",13),
14 => array ("chalcenody",14),
15 => array ("coral",15),
16 => array ("jet",16),
17 => array ("malachite",17),
18 => array ("lapis lazuli",18),
19 => array ("garnet",19),
20 => array ("black onyx",20),
21 => array ("topaz",20),
22 => array ("turquoise",21),
23 => array ("amethyst",21),
24 => array ("opal",22),
25 => array ("sea opal",22),
26 => array ("black opal",23),
27 => array ("aquamarine",23),
28 => array ("tiger's eye",24),
29 => array ("tanzanite",24),
30 => array ("jade",25),
31 => array ("black jade",35),
32 => array ("pearl",45),
33 => array ("ruby",55),
34 => array ("fire opal",65),
35 => array ("blue sapphire",75),
36 => array ("white sapphire",85),
37 => array ("diamond",95),
38 => array ("emerald",100),
);
$jnum=37;
// 0 is name, 1 is 'base value' (multiplied by 1-4)

$spells=array(
1=> array ("Detect Magic",1,0),
2=> array ("Lock Tight",1,1),
3=> array ("Knock Knock",1,2),
4=> array ("Will-o-the-wisp",1,1),
5=> array ("Oh There It Is",1,4),
6=> array ("Take That You Fiend",1,6),
7=> array ("Vorpal Blade",1,5),
8=> array ("Oh-Go-Away",1,5),
9=> array ("Omnipotent Eye",2,5),
10=> array ("Hidey Hole",2,10),
11=> array ("Cateyes",2,6),
12=> array ("Glue-You",2,8),
13=> array ("Little Feets",2,8),
14=> array ("Mirage",2,8),
15=> array ("Poor Baby",2,2),
16=> array ("Whammy",2,10),
17=> array ("Magic Fangs",2,1),
18=> array ("Curses Foiled",3,7),
19=> array ("Slush Yuck",3,15),
20=> array ("Rock-a-bye",3,11),
21=> array ("Dis-Spell",3,11),
22=> array ("Blasting Power",3,8),
23=> array ("Freeze Pleeze",3,8),
24=> array ("Fly Me",3,7),
25=> array ("Healing Feeling",3,14),
26=> array ("Too-Bad Toxin",4,7),
27=> array ("Wink-wing",4,14),
28=> array ("Smog",4,11),
29=> array ("Dum-Dum",4,8),
30=> array ("Double-double",4,18),
31=> array ("Protective Pentagram",4,12),
32=> array ("Upsidaisy",4,9),
33=> array ("Mind Pox",5,39),
34=> array ("Dear God",5,30),
35=> array ("ESP",5,20),
36=> array ("Second Sight",5,25),
37=> array ("Breaker Breaker",5,25),
38=> array ("Wall of Fire",6,26),
39=> array ("Wall of Ice",6,26),
40=> array ("Wall of Thorns",6,14),
41=> array ("Wall of Stone",6,20),
42=> array ("Wall of Iron",6,23),
43=> array ("Zappathingum",7,24),
44=> array ("Zapparmour",8,30),
45=> array ("Zombie Zonk",8,36),
46=> array ("Medusa",9,30),
47=> array ("Death Spell",9,40),
48=> array ("Hellbomb Bursts",10,36),
49=> array ("Bigger Is Better",11,33),
);
$spnum=49;
// 0 is name, 1 is level, 2 is cost
// (used for some potions)

$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 result is 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."),
);
$xspnum=6;
// these 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)

// next one: someone's Splendid Ectoplasm.

$ewspells=array();
// whether extra spells are mentioned anywhere
// (ie do I need to give the detailed description)

$diplo=array("null","at war","hostile","allied","strongly allied");
$dipnum=4;
$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 will 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 get 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",
);
$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)";
}

$object=array(
1=> "Gem",
2=> "Cup",
3=> "Scroll",
4=> "Crown",
5=> "Wand",
6=> "Stone",
7=> "Scarab",
8=> "Mirror",
9=> "Necklace",
);
$objnum=9;

$oname=array(
1=> "Yashub-yahad",
2=> "Black Jenkin",
3=> "Beketmut",
4=> "Seostris",
5=> "Agathangelos",
6=> "Chariton",
7=> "Arah-Sammat",
8=> "Sharrat-sippar",
9=> "Ashmadu",
10=> "Baasha",
11=> "Eira",
12=> "Eydis",
13=> "Ingegard",
14=> "Hrothgar",
15=> "Aredhel",
16=> "Idril",
17=> "Mithrellas",
18=> "Tinuviel",
19=> "Aegnor",
20=> "Beleg",
21=> "Egalmoth",
22=> "Glorfindel",
23=> "Mablung",
24=> "Menegilda",
25=> "Bandobras",
26=> "White Buffalo",
27=> "Crow-Mother-Spirit",
28=> "Coyote-Chasing-Deer",
29=> "Feathered-Water-Snake",
30=> "Gorgol",
31=> "Aelwyd",
32=> "Banon",
33=> "Cadwyn",
34=> "Cerwen",
35=> "Delyth",
36=> "Caerwyn",
37=> "Conwy",
38=> "Corryn",
39=> "He-Who-Should-Not-Have-Been-Born",
);
$onames=39;

$llclasses=array(
1=> "Fighters",
2=> "Magic-Users",
3=> "Clerics",
4=> "Thieves",
5=> "Dwarves",
6=> "Elves",
7=> "Halflings",
8=> "Mutant Humans",
9=> "Mutant Animals",
10=> "Mutant Plants",
11=> "Replicants",
);
$llclassnum=11;
$retainer=array();

// the following tables are all mutations, which are used for
// retainers and will be used for monsters.

// for all these arrays, 0 = name, 1 = level manifested
// (the latter is only used for monsters).

$phtemp=array();
$pltemp=array();

// these arrays have a value of 1 if the mutation
// in question has already been used for this mutant.


$bph1=array(
1=> "Aberrant Form - Enlarged Parts (legs and feet: +60' movement)",
2=> "Aberrant Form - Enlarged Parts (arms and hands: +2 damage)",
3=> "Aberrant Form - Extra Parts (heart and lungs: +1 CON)",
4=> "Aberrant Form - Natural Weapon (stinging tail: 1d6 damage)",
5=> "Dwarfism",
6=> "Echolocation",
7=> "Epidermal Photosynthesis",
8=> "Gigantism",
9=> "Night Vision",
10=> "Prehensile Tail",
11=> "Spiny Growth",
12=> "Thermal Vision",
13=> "Ultraviolet Vision",
);
// can't have both Dwarfism and Gigantism.

$bph2=array(
1=> "Energy Retaining Cell Structure",
2=> "Fragrance Development",
3=> "Increased Balance",
4=> "Increased Physical Attribute (Strength)",
5=> "Increased Physical Attribute (Dexterity)",
6=> "Increased Physical Attribute (Constitution)",
7=> "Increased Sense (Vision)",
8=> "Increased Sense (Hearing)",
9=> "Increased Sense (Smell)",
10=> "Increased Sense (Touch)",
11=> "Increased Sense (Taste)",
12=> "Natural Armour",
13=> "Optic Emissions (bright eyes)",
14=> "Shriek",
15=> "Toxic Weapon",
16=> "Unique Sense (detect radiation)",
17=> "Unique Sense (detect water)",
18=> "Unique Sense (detect gold - note that this doesn't apply to treasure in general)",
19=> "Unique Sense (detect living beings)",
);

$bph3=array(
1=> "Chameleon Epidermis",
2=> "Complete Wing Development",
3=> "Density Alteration (self)",
4=> "Dermal Poison Slime",
5=> "Dual Headed",
6=> "Energy Ray",
7=> "Metamorph",
8=> "Optic Emissions (gamma eyes)",
9=> "Parasitic Control",
10=> "Quickness",
11=> "Reflective Epidermis",
12=> "Regenerative Capability",
);
// Metamorph - randomly choose an animal from the list.

$bme2=array(
1=> "Ability Boost",
2=> "Acute Hyper Healing",
3=> "Combat Empathy",
4=> "Empathy",
5=> "Increased Willpower",
6=> "Intellectual Affinity",
7=> "Know Direction",
8=> "Mental Barrier",
9=> "Mental Phantasm",
10=> "Metaconcert",
11=> "Mind Thrust",
12=> "Neural Telepathy",
);

$bme3=array(
1=> "Accumulated Resistance",
2=> "Ancestral Form",
3=> "Body Adjustment",
4=> "Control Light Waves",
5=> "Control Weather",
6=> "Damage Turning",
7=> "Density Alteration (others)",
8=> "Disintegration",
9=> "Dual Cerebellum",
10=> "Flight, Psionic",
11=> "Force Screen",
12=> "Force Screen, Greater",
13=> "Killing Sphere",
14=> "Neural Telekinesis",
15=> "Plane Shift",
16=> "Posession",
17=> "Precognition",
18=> "Mind Reflection",
19=> "Quick Mind",
20=> "Teleport",
21=> "Temperature Control",
22=> "Vampiric Field",
);
// can't have Force Screen and ..Greater

$bpl1=array(
1=> "Natural Vegetal Weapons",
2=> "Projectile Thorns",
);

$bpl2=array(
1=> "Dermal Acid Sap",
2=> "Injected Poison Sap",
3=> "Prehensile Tendrils",
);

$bpl3=array(
1=> "Carnivore",
2=> "Chameleon Metamorph",
3=> "Grenade-like Fruit",
4=> "Poisonous Spores",
5=> "Radioactive Emissions",
6=> "Thermal Emissions",
);

$dph1=array(
1=> "Albinism",
2=> "Bizarre Appearance",
3=> "Obese",
4=> "Pituitary Deformation",
5=> "Simian Deformity",
);

$dph2=array(
1=> "Epidermal Susceptibility",
2=> "Frailty",
3=> "Increased Caloric Needs",
4=> "Poison Susceptibility",
5=> "Prey Scent",
);

$dph3=array(
1=> "Hemophilia",
2=> "Pain Insensitivity",
3=> "Pain Sensitivity",
4=> "Reduced Immune System",
5=> "Reduced Oxygen Efficiency",
6=> "Sensory Deficiency",
7=> "Slow Mutant",
8=> "Vision Impairment",
);
// can't have Pain Sensitivity and ..Insensitivity.

$dme3=array(
1=> "Atrophied Cerebellum",
2=> "Dual Cerebellum (defective)",
3=> "Mind Refelction (defective)",
4=> "Negative Empathy",
5=> "Phantasmal Damage",
6=> "Phobia",
7=> "Weak Will",
);
// Dual Cerebellum (defective) is incompatible with
// the 'working' version. Mind Reflection isn't.

$dpl3=array(
1=> "Nocturnal",
2=> "Thermal Sensitivity",
);


// determine the nature of the dungeon.
if (rand(1,2)==1 OR $system<>"ll") {
$thisent=rand(1,$ennum);
if (str_replace("@@A","XXX",$entrance[$thisent])==$entrance[$thisent]) {
$entstr=$entrance[$thisent];
} else {
do {
$othent=rand(1,$ennum);
} while (str_replace("@@A","XXX",$entrance[$othent])<>$entrance[$othent]);
$entstr=$entrance[$othent]." It's ".str_replace("@@A","",$entrance[$thisent]);
}
$entstr=str_replace("@@T",$sett[rand(1,$settnum)],$entstr);
if (str_replace("@@B","XXX",$entstr)<>$entstr) {
$z=$appani[rand(1,$aniapp)];
$z=str_replace("a ","",$z);
$z=str_replace("an ","",$z);
$entstr=str_replace("@@B",$z,$entstr);
}
if (str_replace("@@C","XXX",$entstr)<>$entstr) {
$entstr=str_replace("@@C",$appani[rand(1,$aniapp)],$entstr);
}
if (str_replace("temple","XXX",$entstr)<>$entstr) {
$type=rand(1,$gnum);
if ($godd==0) {
$gods[$type][2]="the god";
if (rand(1,2)==1) {
$gods[$type][2]=$gods[$type][2]."dess";
}
$x=$gods[$type][2]." of ".$gods[$type][3];
} else {
$x=$gods[$type][0];
}
$entstr=str_replace("temple","temple dedicated to ".$x,$entstr);
$dedi=$type;
$shrine[$type]=1;
$manygods=1;
}
} else {
$entstr="the ruins of an ancient ".$ruins[rand(1,$ruinnum)];
if (rand(1,3)==1) {
$entstr=$entstr.", whose inhabitants have been raiding a nearby ".$sett[rand(1,$settnum)];
}
$entstr=$entstr.".";
}
$entstr="The dungeon is ".$entstr;

// determine $questobject, and add it to $entstr
// (needs to be seperate as well, so
// can put it in a room of the dungeon).

$questobject="the ".$object[rand(1,$objnum)]." of ".$oname[rand(1,$onames)];
$entstr=$entstr." The heroes are seeking ".$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:

// $crarmour[$x][1] is protection. 0 means 'never wears armour'.
// [2] is STR required.
// [3] is weight.
// [4] is value.

// $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]).

// $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.

// $table[$x][0] is the number of slots in the $xth possible table.
// $table[$x][1-3] are dice:
// 1 = not rolled
// 2 = "1-3" then "4-6"
// 3 = "1-2", "3-4", "5-6"
// 6 = increments normally.

// $ha - handicap. This is a percentage. An average group of monsters
// should be $ha% as effective as the group of delvers that the
// dungeon is designed for.

// $ss - how many different temperature save strings there are.

// $exit[$x][0] gives the number of tunnels leading from/to level $x.

// $stype is an array for deciding what part of the square the
// computer is currently printing.

// $doors[$x][$y][$d][1-4] gives the type of exit (if any), from
// room $x, $y on level $d.
// 1 is an illusory wall,
// 2 is a locked door (STR + armour to break, or DEX to pick),
// 3 is a secret door (higher of INT or LK to find).
// 4 is a porticullus trap.

// $exitsave[$t][$d] gives the level of save
// necessary for exit type $t, on level $d.

// $dshr[$x] is where the shrine to god number $dedi is on level $x.
// it should usually not be used (because $dedi usually isn't).

$rv=25;
$sp=5;
$ha=60;

$ra=$r*$rv/100;

for ($x=1;$x<=$l;$x++) {
$level[$x]=$s+$x-1;
$rn[$x]=rand(round($r-$ra),round($r+$ra));
$rn[0]+=$rn[$x];
$lclimate[$x]=rand(1,$cnum);

// these should only be if $system is "tt"
$z=31.5*$c;
$bonus=1.5*(($level[$x]*($level[$x]+1)/2)-1);
$z+=($bonus*$c);
$mr[$x]=$z*$ha/100;
//

}

for ($x=1;$x<=$gnum;$x++) {
if (str_replace("@@L","XXX",$gods[$x][4])<>$gods[$x][4]) {
$z=$s-1+rand(1,3)-rand(1,3);
if ($z==0) {
$z="";
} elseif ($z>0) {
$z=", plus ".$z;
} else {
$z=", minus ".-$z." (with a minimum of 1)";
}
$gods[$x][4]=str_replace("@@L","The save is made at a level equal to the dungeon level the shrine is on".$z.". If it succeeds, ",$gods[$x][4]);
}
}

for ($x=1;$x<=$ss;$x++) {
$z="at the level of the dungeon";
$a=rand(0,$s)-1;
if ($a<0) {
$z=$z." minus ".abs($a);
} elseif ($a>0) {
$z=$z." plus ".$a;
}
for ($y=1;$y<=$cnum;$y++) {
$climated[$climates[$y]]=str_replace("@@".$x,$z,$climated[$climates[$y]]);
}
}

$sn=max(6,round($rn[0]/$sp));

// generate names for each species.

// 'ambient temperature' ($spt array) done here as well.

for ($x=1;$x<=$sn;$x++) {
if (rand(1,10)==1) {
$spt[$x]=rand(1,$cnum);
}
do {
$nok=1;

$sofar=floor(($x-1)/$firstnum);
do {
$z=rand(1,$firstnum);
} while ($namecount[$z][1]>$sofar);
$namecount[$z][1]++;
$x1=$namefirst[$z];

if (str_replace("+","XXX",$x1)<>$x1) {
$x1=str_replace("+","",$x1);
$x2=$vowels[rand(1,$vnum)];
} else {
$x2="";
if (rand(1,2)==1) {
$x2=$vowels[rand(1,$vnum)];
}
}

$sofar=floor(($x-1)/$secondnum);
do {
$z=rand(1,$secondnum);
} while ($namecount[$z][2]>$sofar);
$namecount[$z][2]++;
$x3=$namesecond[$z];

$crname[$x]=$x1.$x2.$x3;
$crname[$x]=str_replace("uu","u",$crname[$x]);
$crname[$x]=str_replace("ii","i",$crname[$x]);
$crname[$x]=str_replace("yy","y",$crname[$x]);
$crname[$x]=str_replace("cc","c",$crname[$x]);
$crname[$x]=str_replace("tt","t",$crname[$x]);
if (strlen($crname[$x])<5) {
$nok=0;
} elseif (substr($crname[$x],0,2)=="Dr" AND substr($crname[$x],-3)=="gon") {
$nok=0;
} elseif (substr($crname[$x],0,2)=="Un" AND substr($crname[$x],-4)=="corn") {
$nok=0;
} else {
for ($y=1;$y<$x;$y++) {
if ($crname[$x]==$crname[$y]) {
$nok=0;
}
}
}
if ($nok==1) {
$sofar=floor(($x-1)/$thirdnum);
do {
$z=rand(1,$thirdnum);
} while ($namecount[$z][3]>$sofar);
$namecount[$z][3]++;
$x3=$namethird[$z];

$sofar=floor(($x-1)/$fourthnum);
do {
$z=rand(1,$fourthnum);
} while ($namecount[$z][4]>$sofar);
$namecount[$z][4]++;
$x4=$namefourth[$z];

if ($x3=="Imperial" AND $x4=="Emperor") {
$nok=0;
} elseif ($x3=="Conquering" AND $x4=="Conqueror") {
$nok=0;
} elseif ($x3=="Cyber-" AND $x4=="Cyborg") {
$nok=0;

} else {
$crnick[$x]=$x3." ".$x4;
if (str_replace("Barrow-","XXX",$crnick[$x])<>$crnick[$x] OR str_replace("Cyber-","XXX",$crnick[$x])<>$crnick[$x]) {
$crnick[$x]=str_replace(" ","",$crnick[$x]);
} elseif (str_replace("-","XXX",$crnick[$x])<>$crnick[$x]) {
$crnick[$x]=$x4.$x3;
} elseif (str_replace("'s","XXX",$crnick[$x])<>$crnick[$x] AND $x3<>"Love's") {
$crnick[$x]=$x4.$x3;
}
for ($y=1;$y<$x;$y++) {
if ($crnick[$x]==$crnick[$y]) {
$nok=0;
}
}
}
}
} while ($nok==0);
};


// define levels for each species.
for ($x=1;$x<=$sn;$x++) {
$y=rand(1,$l);
$z=rand(1,$l);
if (rand(1,3)==1) {
$y=1;
} elseif (rand(1,2)==1) {
$y=$l;
}
$shallow[$x]=min($y,$z);
$deep[$x]=max($y,$z);
}

// look at $deep and $shallow, to make sure that each
// level has at least one monster. alter if necessary.
for ($x=1;$x<=$l;$x++) {
$nearest=$l;
for ($y=1;$y<=$sn;$y++) {
if ($shallow[$y]<=$x AND $deep[$y]>=$x) {
$nearest=0;
} else {
$nearest=min($nearest,abs($shallow[$y]-$x),abs($deep[$y]-$x));
}
}
if ($nearest>0) {
do {
$y=rand(1,$sn);
} while (abs($shallow[$y]-$x)>$nearest AND abs($deep[$y]-$x)>$nearest);
$shallowdist=abs($shallow[$y]-$x);
$deepdist=abs($deep[$y]-$x);
if ($shallowdist<$deepdist) {
$shallow[$y]=$x;
} else {
$deep[$y]=$x;
}
}
}


// define stats for each species.
for ($x=1;$x<=$sn;$x++) {
$stats[$x][0]=rand(1,2);
if ($stormr==1) {
$stats[$x][0]=2;
} elseif ($stormr==3) {
$stats[$x][0]=1;
}
if ($stats[$x][0]==2) {
$anystat=1;
for ($y=1;$y<=$attnum;$y++) {
do {
$stats[$x][$y]=rand(1,5);
$splus[$x][$y]=rand(1,6)-rand(1,6);
} while ($stats[$x][$y]+$splus[$x][$y]<1);
// ie no chance of getting 0 or less.
}
$y=$level[rand($shallow[$x],$deep[$x])];
$y=rand(1,$y);
if ($y>1) {
for ($z=2;$z<=$y;$z++) {

// levelling gives one of the following bonuses:
// half new number to both STR and CON (1,4) - '0'
// new number to STR (1)
// half to INT (2)
// twice to LK (3)
// new number to CON (4)
// half to DEX (5)
// half to CHR (6)
// new number to SPD (7) (doesn't happen in rules)
// new number to WIZ (8)

$lbon=$z;
do {
$watt=rand(0,$attnum);
} while ($watt==7 AND $spd==0);
// ie if SPD doesn't contribute to combat adds,
// monsters won't 'level up' their Speed.

if ($watt==3) {
$lbon=$lbon*2;
} elseif ($watt<>1 AND $watt<>4 AND $watt<>8 AND $watt<>7) {
$lbon=$lbon/2;
// half rounded down in rules.
}

if ($watt==0) {
$splus[$x][1]+=$lbon;
$splus[$x][4]+=$lbon;
} else {
$splus[$x][$watt]+=$lbon;
}
}
}

for ($z=1;$z<=$attnum;$z++) {
$stats[$x][$z]=(3.5*$stats[$x][$z])+$splus[$x][$z];
if (rand(1,2)==1) {
$stats[$x][$z]=floor($stats[$x][$z]);
} else {
$stats[$x][$z]=ceil($stats[$x][$z]);
}
}

$con=$stats[$x][4];
$phys=$con;
for ($z=1;$z<=5+(2*$spd);$z=$z+2) {
$phys+=$stats[$x][$z];
}
$pow[$x]=3*$phys/(4+$spd);
$int=$stats[$x][2];
$dex=$stats[$x][5];
$sus=1+(7*$wiz);
$sfu=$sta