}
$victory = false;
$defeat = false;
if ($enemycounter > 0) {
    output("`\$`c`b~ ~ ~ Fight ~ ~ ~`b`c`0");
    modulehook("battle", $enemies);
    foreach ($enemies as $index => $badguy) {
        if ($badguy['creaturehealth'] > 0 && $session['user']['hitpoints'] > 0) {
            output("`@You have encountered `^%s`@ which lunges at you with `%%s`@!`0`n", $badguy['creaturename'], $badguy['creatureweapon']);
        }
    }
    output_notl("`n");
    show_enemies($enemies);
}
suspend_buffs($options['type'] == 'pvp' ? "allowinpvp" : false);
suspend_companions($options['type'] == 'pvp' ? "allowinpvp" : false);
// Now that the bufflist is sane, see if we should add in the bodyguard.
$inn = (int) httpget('inn');
if ($options['type'] == 'pvp' && $inn == 1) {
    apply_bodyguard($badguy['bodyguardlevel']);
}
$surprised = false;
if ($op != "run" && $op != "fight" && $op != "newtarget") {
    if (count($enemies) > 1) {
        $surprised = true;
        output("`b`^YOUR ENEMIES`\$ surprise you and get the first round of attack!`0`b`n`n");
    } else {
        // Let's try this instead.Biggest change is that it adds possibility of
        // being surprised to all fights.
        if (!array_key_exists('didsurprise', $options) || !$options['didsurprise']) {
            // By default, surprise is 50/50
         }
     }
 }
 if ($op == "fight") {
     $battle = true;
 }
 if ($op == "run") {
     output("`\$Your pride prevents you from running from this conflict!`0");
     $op = "fight";
     $battle = true;
 }
 if ($battle) {
     require_once "lib/battle-skills.php";
     require_once "lib/extended-battle.php";
     suspend_buffs('allowintrain', "`&Your pride prevents you from using extra abilities during the fight!`0`n");
     suspend_companions("allowintrain");
     if (!$victory) {
         require_once "battle.php";
     }
     if ($victory) {
         $badguy['creaturelose'] = substitute_array($badguy['creaturelose']);
         output_notl("`b`&");
         output($badguy['creaturelose']);
         output_notl("`0`b`n");
         output("`b`\$You have defeated %s!`0`b`n", $badguy['creaturename']);
         $session['user']['level']++;
         $session['user']['maxhitpoints'] += 10;
         $session['user']['soulpoints'] += 5;
         $session['user']['attack']++;
         $session['user']['defense']++;
         // Fix the multimaster bug
    addnav("Login Screen", "index.php?r=" . $r);
} else {
    if ($session['user']['alive']) {
        addnav("Continue");
        villagenav();
    } else {
        tlschema("nav");
        if ($session['user']['sex'] == 1) {
            addnav("`!`bYou're dead, Jane!`b`0");
        } else {
            addnav("`!`bYou're dead, Jim!`b`0");
        }
        addnav("S?Land of Shades", "shades.php");
        // addnav("G?The Graveyard","graveyard.php");
        require_once "lib/extended-battle.php";
        suspend_companions("allowinshades", true);
        addnav("Log out", "login.php?op=logout");
        tlschema();
    }
}
// addnav("News");
// addnav("Previous News","news.php?offset=".($offset+1)."&r=".$r);
// if ($offset>0){
// addnav("Next News","news.php?offset=".($offset-1)."&r=".$r);
// }
if ($session['user']['loggedin']) {
    addnav("Preferences", "prefs.php");
}
addnav("About this game", "about.php");
tlschema("nav");
if ($session['user']['superuser'] & SU_EDIT_COMMENTS) {