<html>
<body>
<?php
$attacktype = $_POST["attacktype"];
$arace = $_POST["arace"];
$drace = $_POST["drace"];
$aland = $_POST["aland"];
$dland = $_POST["dland"];
$ahuts = $_POST["ahuts"];
$aleaders = $_POST["aleaders"];
$rats = $_POST["rats"];
$weasels = $_POST["weasels"];
$stoats = $_POST["stoats"];
$skiffs = $_POST["skiffs"];
$leaders = $_POST["leaders"];
$towers = $_POST["towers"];
//show/hide js
?>
<script type="text/javascript">
function ChangeDropdowns(value){
if(value=="leada"){
document.getElementById('leaders').style.display='block';
document.getElementById('military').style.display='none';
}else{
document.getElementById('leaders').style.display='none';
document.getElementById('military').style.display='block';
}
}
</script>
<?
//Additions:
//at war? $uoffense *= 1.2;
//A few functions stolen from funcs:
// remove commas, make integer
function fixInputNum(&$num) {
$num = str_replace(",", "", $num);
if (ereg("k\$", $num))
$num = round(substr($num, 0, -1)) * 1000;
else if (ereg("mil\$", $num))
$num = round(substr($num, 0, -3)) * 1000000;
else if (ereg("bil\$", $num))
$num = round(substr($num, 0, -3)) * 1000000000;
else if (ereg("tril\$", $num))
$num = round(substr($num, 0, -3)) * 1000000000000;
$num = round($num);
$num = round(abs($num));
}
// adds commas to a number
function commas($str) {
return number_format($str, 0, ".", ",");
}
?>
<form action="willitbreak.php" method="post">
Attacking Race:
<select name="arace" size="1">
<option <? if ($arace == "Rat") echo "selected"; ?> value="Rat">Rat</option>
<option <? if ($arace == "Painted One") echo "selected"; ?> value="Painted One">Painted One</option>
<option <? if ($arace == "Stoat") echo "selected"; ?> value="Stoat">Stoat</option>
<option <? if ($arace == "Fox") echo "selected"; ?> value="Fox">Fox</option>
<option <? if ($arace == "Wildcat") echo "selected"; ?> value="Wildcat">Wildcat</option>
<option <? if ($arace == "Lizard") echo "selected"; ?> value="Lizard">Lizard</option>
<option <? if ($arace == "Wolf") echo "selected"; ?> value="Wolf">Wolf</option>
<option <? if ($arace == "Marten") echo "selected"; ?> value="Marten">Marten</option>
<option <? if ($arace == "Magpie") echo "selected"; ?> value="Magpie">Magpie</option>
<option <? if ($arace == "Ferret") echo "selected"; ?> value="Ferret">Ferret</option>
</select>
<br>
Defending Race:
<select name="drace" size="1">
<option <? if ($drace == "Rat") echo "selected"; ?> value="Rat">Rat</option>
<option <? if ($drace == "Painted One") echo "selected"; ?> value="Painted One">Painted One</option>
<option <? if ($drace == "Stoat") echo "selected"; ?> value="Stoat">Stoat</option>
<option <? if ($drace == "Fox") echo "selected"; ?> value="Fox">Fox</option>
<option <? if ($drace == "Wildcat") echo "selected"; ?> value="Wildcat">Wildcat</option>
<option <? if ($drace == "Lizard") echo "selected"; ?> value="Lizard">Lizard</option>
<option <? if ($drace == "Wolf") echo "selected"; ?> value="Wolf">Wolf</option>
<option <? if ($drace == "Marten") echo "selected"; ?> value="Marten">Marten</option>
<option <? if ($drace == "Magpie") echo "selected"; ?> value="Magpie">Magpie</option>
<option <? if ($drace == "Ferret") echo "selected"; ?> value="Ferret">Ferret</option>
</select>
<br>
Attack Type:
<select name="attacktype" size="1" onchange="ChangeDropdowns(this.value);">
<?/*<option <? if ($attacktype == "Standard") echo "selected"; ?> value="Standard">Standard</option>
<option <? if ($attacktype == "Surprise") echo "selected"; ?> value="Surprise">Surprise (no allies)</option>*/?>
<option <? if ($attacktype == "armtrp") echo "selected"; ?> value="armtrp">Guerilla Strike</option>
<option <? if ($attacktype == "lndtrp") echo "selected"; ?> value="lndtrp">Bombardment</option>
<option <? if ($attacktype == "flytrp") echo "selected"; ?> value="flytrp">Frontal Assault</option>
<option <? if ($attacktype == "seatrp") echo "selected"; ?> value="seatrp">Naval Assult</option>
<option <? if ($attacktype == "leada") echo "selected"; ?> value="leada">Leader Attack</option>
</select>
<br>
<div id = "military" <? if ($attacktype == "leada") echo "style=\"display:none;\"" ?>>
Defender's Troops:
<br>
Rats: <input type="text" name="rats" value="<?php echo $rats;?>"><br>
Weasels: <input type="text" name="weasels" value="<?php echo $weasels;?>"><br>
Stoats: <input type="text" name="stoats" value="<?php echo $stoats;?>"><br>
Skiffs: <input type="text" name="skiffs" value="<?php echo $skiffs;?>"><br>
Towers: <input type="text" name="towers" value="<?php echo $towers;?>"><br>
</div>
<div id = "leaders" <? if ($attacktype != "leada") echo "style=\"display:none;\"" ?>>
Attacker's land: <input type="text" name="aland" value="<?php echo $aland;?>"><br>
Attacker's huts: <input type="text" name="ahuts" value="<?php echo $ahuts;?>"><br>
Attacker's leaders: <input type="text" name="aleaders" value="<?php echo $aleaders;?>"><br>
Defender's land: <input type="text" name="dland" value="<?php echo $dland;?>"><br>
Defender's leaders: <input type="text" name="leaders" value="<?php echo $leaders;?>"><br>
Defender's Towers: <input type="text" name="dtowers" value="<?php echo $towers;?>"><br>
</div>
<input type="submit">
</form>
<p> </p>
<?if (isset($attacktype)){
//if ($attacktype == 'Surprise') {
// $offpts *= 1.25;
//}
$uoffense = 0;
$edefense = 0;
fixInputNum($rats);
fixInputNum($weasels);
fixInputNum($stoats);
fixInputNum($skiffs);
fixInputNum($leaders);
fixInputNum($towers);
if($attacktype == "armtrp"){ //rats 2:1
$uoffense = $rats * (1/2);
}
if($attacktype == "lndtrp"){ //weasels 3:5
$uoffense = $weasels * (5/3);
}
if($attacktype == "flytrp"){ //stoats 5:3
$uoffense = $stoats * (3/5);
}
if($attacktype == "seatrp"){ //skiffs 6:8
$uoffense = $skiffs * (8/6);
}
if($attacktype == "leada"){
}
//RACE BONUS
if($arace == "Rat" or arace == "Stoat")
$abonus = 1.25;
if($arace == "Wildcat" or arace == "Magpie")
$abonus = 1.10;
if($arace == "Painted One" or arace == "Fox" or arace == "Wolf")
$abonus = 1;
if($arace == "Lizard" or arace == "Ferret")
$abonus = 0.95;
if($arace == "Marten")
$abonus = 0.90;
if($drace == "Lizard")
$dbonus = 1.25;
if($drace == "Fox")
$dbonus = 1.15;
if($drace == "Wildcat" or $drace == "Wolf" or $drace == "Ferret")
$dbonus = 1.15;
if($drace == "Painted One")
$dbonus = 1;
if($drace == "Rat" or $drace == "Stoat" or $drace == "Magpie")
$dbonus = 0.95;
if($drace == "Marten")
$dbonus = 0.9;
if($arace == "Wolf")
$ambonus = 1.15;
if($arace == "Marten")
$ambonus = 1.10;
if($arace == "Painted One" or $arace == "Stoat" or $arace == "Fox" or $arace == "Magpie" or $arace == "Ferret")
$ambonus = 1.15;
if($arace == "Rat" or $arace == "Wildcat" or $arace == "Lizard")
$ambonus = 0.90;
if($drace == "Wolf")
$dmbonus = 1.25;
if($drace == "Wildcat")
$dmbonus = 1.20;
if($drace == "Stoat" or $arace == "Fox" or $arace == "Marten")
$dmbonus = 1.15;
if($drace == "Painted One")
$dmbonus = 1;
if($drace == "Rat" or $arace == "Magpie" or $arace == "Ferret")
$dmbonus = 0.90;
if($drace == "Lizard")
$dmbonus = 0.85;
//Towers
$tdefense = $towers * 500; //* min(1, $rats / (100 * $towers + 1)); //assume towers are manned
$uoffense = $uoffense + $tdefense;
$tdefense = $tdefense * 1.05; //display only
//Calc race bonus
$racedef = $uoffense - round($uoffense / $dbonus);
$uoffense = $uoffense * 1.05;
$raceoff = $uoffense - round($uoffense / $abonus);
$uoffense = $uoffense + $racedef - $raceoff;
?>What the Attacker needs to break:<br><?
if($attacktype == "armtrp"){
echo "Rats: " . commas($uoffense);
}
if($attacktype == "lndtrp"){
echo "Weasels: " . commas($uoffense);
}
if($attacktype == "flytrp"){
echo "Stoats: " . commas($uoffense);
}
if($attacktype == "seatrp"){
echo "Skiffs: " . commas($uoffense);
}
if($attacktype == "leada"){
$lratio = $aleaders / $ahuts * $ambonus;
//$uratio > $eratio * 2.2;
// for offense, wizards/avgland
$eratio = $leaders / $dland * 1.05 * $dmbonus;
$eratio *= (1+($dtowers/($dland * 2)));
$uoffense = (($eratio * 2.2) * (($aland + $dland) / 2) * $ambonus);
echo "Leaders: " . commas($uoffense);
//display thing for the end
$dbonus = $dmbonus;
$abonus = $ambonus;
$racedef = $leaders * ($dmbonus - 1);
$raceoff = $uoffense * ($ambonus-1);
$tdefense = "a bit";
}
?>
<br>
<br>
Defending <?echo $drace;?> adds <? echo ($dbonus-1)*100 ?>% (<? echo commas($racedef); ?> troops) to Defense
<br>
Attacking <?echo $arace;?> adds <? echo ($abonus-1)*100 ?>% (<? echo commas($raceoff); ?> troops) to Attack
<br>
Towers add <?echo commas($tdefense); ?> to Defense
<br>
<? if($attacktype != "leada"){ ?>
Enemy's Ratio: <? echo $eratio ?>
<? }
} //isset attacktype end
?>
</body>
</html>