the 2nd part ..
function LossCalc(&$player, &$ploss)
{
global $trplst;
for ($i = 0; $i < 4; $i++)
$player[$trplst[$i]] -= $ploss[$trplst[$i]];
}
function DealLand($type)
{
global $landloss, $buildgain, $enemy, $users;
// destroy structures
destroyBuildings('homes',7,70,$type);
destroyBuildings('GoldMines',7,70,$type);
destroyBuildings('MilitaryAcademies',7,50,$type);
destroyBuildings('Barracks',7,70,$type);
destroyBuildings('MageTowers',7,60,$type);
destroyBuildings('Farms',7,30,$type);
destroyBuildings('Towers',7,60,$type);
destroyBuildings('freeland',10,0,$type); // 3rd argument MUST be 0 - calculate gained freeland below
$users[freeland] += $landloss - $buildgain;
// update total land counts
$users[land] += $landloss;
$enemy[land] -= $landloss;
}
// To handle destroying buildings during successful attacks
function destroyBuildings ($type, $pcloss, $pcgain, $atktype)
{
global $landloss, $buildgain, $enemy, $users;
$pcloss /= 100;
$pcgain /= 100;
if (($atktype == 'cavalry') || ($atktype == 'siege') || ($atktype == 'naval'))
{ // these attacks destroy extra buildings, but fewer are gained
if ($atktype == 'siege')
{
$pcloss *= 1.25;
$pcgain *= 0.72;
}
elseif (($type == 'towers') || ($type == 'mage_towers'))
{
$pcloss *= 1.3;
$pcgain *= 9/13;
}
else $pcgain *= 0.9;
}
if ($enemy[$type] > 0)
$loss = mt_rand(1,ceil($enemy[$type] * $pcloss + 2));
if ($loss > $enemy[$type])
$loss = $enemy[$type];
$gain = ceil($loss * $pcgain);
$enemy[$type] -= $loss;
$landloss += $loss;
if ($atktype == Standard) // only gain buildings with standard attack
{
$users[$type] += $gain;
$buildgain += $gain;
}
}
function printedreport()
{
global $users, $uloss, $uera, $enemy, $eloss, $eera, $landloss, $buildgain, $trplst;
if ($landloss)
print "Your army breaks through $enemy[empire]'s defenses and captures $landloss acres of land! In the effort, you lost:<br>\n";
else print "After a failing struggle, your army is repelled by $enemy[empire]'s defenses. In the attempt, you lost:<br>\n";
for ($i = 0; $i < 4; $i++)
{
$trp = $trplst[$i];
if ($uloss[$trp]) print commas($uloss[$trp])." $uera[$trp]<br>\n";
}
print "In their defense, $enemy[empire] lost:<br>\n";
for ($i = 0; $i < 4; $i++)
{
$trp = $trplst[$i];
if ($eloss[$trp]) print commas($eloss[$trp])." $eera[$trp]<br>\n";
}
if ($buildgain)
print "You also captured $buildgain structures!<br>\n";
if ($enemy[land] == 0)
{
?><span class="cgood"><b><?=$enemy[empire]?> (#<?=$enemy[num]?>)</b> has been destroyed!</span><br>
<? $users[kills]++;
}
}
// To print the attack table
function printRow ($type)
{
global $users, $uera;
?>
<tr><td><?=$uera[$type]?></td>
<td class="aright"><?=commas($users[$type])?></td>
<td class="aright"><input type="text" name="usent[<?=$type?>]" size="8" value="0"></td></tr>
<?
}
// *************
// End Functions
// *************
if ($users[turnsused] <= $config[protection]) // are they under protection?
TheEnd("Cannot use offensive actions while under protection!");
if ($users[disabled] == 2) // are they admin?
TheEnd("Administrative accounts cannot use offensive actions!");
if ($do_attack)
{
if ($users[turns] < 2) // enough turns?
TheEnd("Not enough turns!");
if (!$target) // specified target?
TheEnd("You must specify a target!");
if ($target == $users[num]) // attacking self?
TheEnd("Cannot attack yourself!");
if ($users[health] <= 10)
TheEnd("You do not have enough health to attack.");
$enemy = loadUser($target);
$erace = loadRace($enemy[race]);
$eera = loadEra($enemy[era]); // load enemy info
if ($enemy[land] == 0)
TheEnd("That empire has already been destroyed!");
if (($enemy[era] != $users[era]) && ($users[gate] <= $time) && ($enemy[gate] <= $time))
TheEnd("Need to open a Time Gate first!");
if ($enemy[disabled] >= 2)
TheEnd("Cannot attack disabled empires!");
if ($enemy[turnsused] <= $config[protection])
TheEnd("Cannot attack empires under new player protection!");
if ($enemy[vacation] > $config[vacationdelay])
TheEnd("Cannot attack empires on vacation!");
$warflag = 0;
$netmult = 20;
$uclan = loadClan($users[clan]);
if ($enemy[clan])
ClanCheck();
if ($enemy[networth] > $users[networth] * $netmult)
TheEnd("Your Generals flatly refuse to attack such a strong opponent!");
if ($users[networth] > $enemy[networth] * $netmult)
TheEnd("Your Generals politely refuse your orders to attack a defenseless empire!");
if ($warflag == 0)
{
if ($enemy[attacks] > 20)
TheEnd("Too many recent attacks on that empire. Try again in one hour.");
$revolt = 1;
if ($users[networth] > $enemy[networth] * 2.5)
{ // Shame is less powerful than fear
?><span class="cwarn">Your military is ashamed by your attack on such a weak opponent. Many desert!</span><br>
<? $revolt = 1 - $users[networth] / $enemy[networth] / 125;
}
elseif ($enemy[networth] > $users[networth] * 2.5)
{
?><span class="cwarn">Your military trembles at your attack on such a strong opponent. Many desert!</span><br>
<? $revolt = 1 - $enemy[networth] / $users[networth] / 100;
}
if ($revolt < .9)
$revolt = .9;
for ($i = 0; $i < 4; $i++)
$users[$trplst[$i]] = round($users[$trplst[$i]] * $revolt);
}
readInput($attacktype);
Attack($attacktype);
// record losses
losscalc($users, $uloss);
losscalc($enemy, $eloss);
if (!$landloss)
$landloss = 0;
switch ($attacktype)
{
case 'Standard':addNews(302,$users,$enemy,$landloss,$el oss[infantry],$eloss[cavalry],$eloss[siege],$eloss[naval],$uloss[infantry],$uloss[cavalry],$uloss[siege],$uloss[naval]); break;
case 'Surprise':addNews(303,$users,$enemy,$landloss,$el oss[infantry],$eloss[cavalry],$eloss[siege],$eloss[naval],$uloss[infantry],$uloss[cavalry],$uloss[siege],$uloss[naval]); break;
case 'infantry': addNews(304,$users,$enemy,$landloss,$eloss[infantry],$uloss[infantry]); break;
case 'cavalry': addNews(305,$users,$enemy,$landloss,$eloss[cavalry],$uloss[cavalry]); break;
case 'siege': addNews(306,$users,$enemy,$landloss,$eloss[siege],$uloss[siege]); break;
case 'naval': addNews(307,$users,$enemy,$landloss,$eloss[naval],$uloss[naval]); break;
}
if ($enemy[land] == 0)
addNews(301,$users,$enemy,0);
$users[attacks] -= 2;
if ($users[attacks] < 0)
$users[attacks] = 0;
$users[offtotal]++;
if ($landloss)
$users[offsucc]++;
else $enemy[defsucc]++;
$enemy[deftotal]++;
$users[health] -= 8;
saveUserDataNet($users,"networth infantry cavalry siege naval land homes mines academies barracks mage_towers farms towers freeland offsucc offtotal attacks health kills");
saveUserDataNet($enemy,"networth infantry cavalry siege naval land homes mines academies barracks mage_towers farms towers freeland defsucc deftotal attacks");
taketurns(2,attack);
}
?>
<form method="post" action="<?=$config[main]?>?action=military">
<table class="inputtable">
<tr><td colspan="3" class="acenter">Empire number to attack? <input type="text" name="target" size="5" value="<?php echo $_GET['prof_target']; ?>"></td></tr>
<tr><td colspan="3" class="acenter">Attack Type: <select name="attacktype" size="1">
<option value="Standard"><?=$atknames[Standard]?></option>
<option value="Surprise"><?=$atknames[Surprise]?> (no allies)</option>
<option value="infantry"><?=$atknames[infantry]?></option>
<option value="cavalry"><?=$atknames[cavalry]?></option>
<option value="siege"><?=$atknames[siege]?></option>
<option value="naval"><?=$atknames[naval]?></option>
</select></td></tr>
<tr><th class="aleft">Unit</th>
<th class="aright">Owned</th>
<th class="aright">Send</th></tr>
<?
for($i = 0; $i < 4; $i++)
printRow($trplst[$i]);
?>
<tr><td colspan="3" class="acenter"><input type="checkbox" name="sendall" value="1">Send Everything</td></tr>
<tr><td colspan="3" class="acenter"><input type="submit" name="do_attack" value="Send Attack"></td></tr>
</table>
</form>
<hr>
<form method="post" action="<?=$config[main]?>?action=military">
<table class="inputtable">
<tr><td class="acenter">Empire to cast spell on? <input type="text" name="target" size="5"></td></tr>
<tr><td><select name="spell_num" size="1">
<option value="0">Select a Spell</option>
<?
for ($i = 1; $i <= 12; $i++)
if ($sptype[$i] == 'o')
printMRow($i);
?>
</select></td></tr>
<tr><td class="acenter"><input type="submit" name="do_spell" value="Cast Spell"></td></tr>
</table>
</form>
<?
if ($users[shield] > $time)
print "<i>We currently have a shield against magic which will last for ".round(($users[shield]-$time)/3600,1)." more hours.</i><br>\n";
print "<i>The health of our forces and people is at $users[health]%!</i><br>\n";
if ($users[gate] > $time)
print "<i>We currently have an open time portal which will last for ".round(($users[gate]-$time)/3600,1)." more hours.</i><br>\n";
TheEnd("");
?>
you can check the game as well
www.eraoferadication.co.cc
fierce .