/**
 * This function prepares the fight, sets up options and gives hook a hook to change options on a per-player basis.
 *
 * @param array $options The options given by a module or basics.
 * @return array The complete options.
 */
function prepare_fight($options = false)
{
    global $companions;
    $basicoptions = array("maxattacks" => getsetting("maxattacks", 4));
    if (!is_array($options)) {
        $options = array();
    }
    $fightoptions = $options + $basicoptions;
    $fightoptions = modulehook("fightoptions", $fightoptions);
    // We'll also reset the companions here...
    prepare_companions();
    return $fightoptions;
}
                    output("`b`^%s`\$ surprises you and gets the first round of attack!`0`b`n`n", $badguy['creaturename']);
                }
                $op = "run";
            }
            $options['didsurprise'] = 1;
        }
    }
}
$needtostopfighting = false;
if ($op != "newtarget") {
    // Run through as many rounds as needed.
    do {
        //we need to restore and calculate here to reflect changes that happen throughout the course of multiple rounds.
        restore_buff_fields();
        calculate_buff_fields();
        prepare_companions();
        $newenemies = array();
        // Run the beginning of round buffs (this also calculates all modifiers)
        foreach ($enemies as $index => $badguy) {
            if ($badguy['dead'] == false && $badguy['creaturehealth'] > 0) {
                if (isset($badguy['alwaysattacks']) && $badguy['alwaysattacks'] == true) {
                } else {
                    $roundcounter++;
                }
                if ($roundcounter > $options['maxattacks'] && $badguy['istarget'] == false) {
                    $newcompanions = $companions;
                } else {
                    $buffset = activate_buffs("roundstart");
                    if ($badguy['creaturehealth'] <= 0 || $session['user']['hitpoints'] <= 0) {
                        $creaturedmg = 0;
                        $selfdmg = 0;