fierce
New Member
- Messages
- 222
- Reaction score
- 0
- Points
- 0
I got error in my game ..ppl can't attack each other ..the reason are the errors in the military.php .. I'm not very good with it so I'd like you to look @ it ..
<?
//register globals
$do_attack = $_POST['do_attack'];
$target = $_POST['target'];
$attacktype = $_POST['attacttype'];
$sendall = $_POST['sendall'];
$spell_num = $_POST['spell_num'];
$usent = $_POST['usent'];
$do_spell = $_POST['do_spell'];
include("header.php");
include("magicfun.php");
$atknames[Standard] = "Standard Attack";
$atknames[Surprise] = "Surprise Attack";
$atknames[infantry] = "Infantry Strike";
$atknames[cavalry] = "Cavalry Assault";
$atknames[siege] = "Siege Onslaught";
$atknames[naval] = "Hydro Assault";
// era of troops, quantity of troops, type of troops, offense or defense
function CalcPoints($era, $quantity, $ttype, $atype)
{
$type = $atype."_".$ttype;
return $quantity * $era[$type];
}
function ClanCheck() // Need to set warflag and netmult
{
global $warflag, $netmult, $users, $uclan, $enemy;
if ($users[clan] == $enemy[clan])
TheEnd("Cannot attack empires in your clan!");
if (($uclan[ally1] == $enemy[clan]) || ($uclan[ally2] == $enemy[clan]) || ($uclan[ally3] == $enemy[clan]))
TheEnd("Your Generals quietly ignore your orders to attack an Ally.");
if (($uclan[war1] == $enemy[clan]) || ($uclan[war2] == $enemy[clan]) || ($uclan[war3] == $enemy[clan]))
{
$warflag = 1.2;
$netmult = 50;
}
}
function ReadInput ($type)
{
global $users, $usent, $enemy, $esent, $sendall, $trplst;
for ($i = 0; $i < 4; $i++)
{
$trp = $trplst[$i];
$esent[$trp] = $enemy[$trp];
if ($enemy[forces] > 0) // if enemy shares forces, he can't use them for defense
$esent[$trp] *= 0.9;
if ($sendall) // send everything?
$usent[$trp] = $users[$trp];
}
if (($type != 'Standard') && ($type != 'Surprise'))
{
for ($i = 0; $i < 4; $i++)
{
$trp = $trplst[$i];
if ($type != $trp)
{
$usent[$trp] = 0;
$esent[$trp] = 0;
}
}
}
for ($i = 0; $i < 4; $i++)
CheckQuantity($trplst[$i]);
}
function CheckQuantity($type)
{
global $users, $uera, $usent;
fixInputNum($usent[$type]);
$esent[$type] = round($esent[$type]);
if ($usent[$type] < 0)
TheEnd("Cannot attack with a negative number of units!");
if ($usent[$type] > $users[$type])
TheEnd("You do not have that many $uera[$type]!");
}
function Attack($type)
{
global $users, $uera, $usent, $enemy, $eera, $esent, $playerdb, $datetime, $time, $trplst, $warflag;
$uoffense = 0;
$edefense = 0;
for ($i = 0; $i < 4; $i++)
{
$uoffense += CalcPoints($uera,$usent[$trplst[$i]],$trplst[$i],o);
$edefense += CalcPoints($eera,$esent[$trplst[$i]],$trplst[$i],d);
}
if ($uoffense == 0)
TheEnd("Must attack with something!".$trplst[1]."".$uoffense."".$edefense);
$uoffense *= $users[health] / 100;
$edefense *= $enemy[health] / 100;
if ($warflag)
$uoffense *= 1.2;
if ($users[era] != $enemy[era]) // only step through time gate if necessary
{
if ($users[gate] > $time) // your time gate?
print "Stepping through your open time gate,<br>
";
elseif ($enemy[gate] > $time) // or enemy's time gate?
print "Stepping through your enemy's open time gate,<br>
";
}
if ($type == "Surprise") // surprise attack?
{
$offpts *= 1.25;
$helping = 0;
$users[health] -= 5;
}
elseif (($enemy[clan]) && ($enemy[forces] == 1)) // enemy has allies and sharing forces?
{
$dbally = mysql_query("SELECT infantry,cavalry,siege,naval,num,era,race,clan,gate FROM $playerdb WHERE clan=$enemy[clan] AND forces>0 AND num!=$enemy[num] AND land>0;");
$helping = mysql_num_rows($dbally);
}
if ($helping) // add up allies
{
print "$helping empires rushing to defend your target,<br>
";
$emaxdefense = $edefense * 2;
while ($ally = mysql_fetch_array($dbally))
{
$ad = 0;
if (($enemy[gate] > $time) || ($ally[gate] > $time) || ($enemy[era] == $ally[era]))
{ // defense is limited to eras as well
addNews(300,$users,$ally,$enemy[num]);
$arace = loadRace($ally[race]); // adjust according to ally race
$aera = loadEra($ally[era]); // and era
for($i = 0; $i < 4; $i++)
$ad += allyHelp($trplst[$i],$helping) * ($ally[health] / 100);
$ad = round($ad * $arace[defense]);
$edefense += $ad;
}
}
if ($edefense > $emaxdefense) // limit ally defense
$edefense = $emaxdefense;
}
$tdefense = $enemy[towers] * 500 * min(1,$enemy[infantry] / (100*$users[towers]+1)); // and add in towers
$edefense += $tdefense;
if ($warflag == 0) // war == infinite attacks
$enemy[attacks]++;
dobattle($uoffense,$edefense,$type,$tdefense);
}
function AllyHelp ($type, $numallies)
{
global $enemy, $esent, $ally, $aera;
$amt = round($ally[$type] * .1);
if ($amt > $esent[$type] / $numallies)
$amt = $esent[$type] / $numallies;
return CalcPoints($aera,$amt,$type,d);
}
/*
dobattle(Offense_Points, Defense_Points, Attack_Type)
This function:
determines who won
calls detloss() to determine troop losses
calls dealland() if attack was successful
*/
function dobattle ($op, $dp, $type, $towp)
{
$emod = sqrt($op/($dp+1)); // modification to enemy losses
$umod = sqrt(($dp-$towp)/($op+1)); // modification to attacker losses (towers not included)
switch ($type)
{
case infantry:
detloss(.1155, .0705, $umod, $emod, infantry);
break;
case cavalry:
detloss(.0985, .0530, $umod, $emod, cavalry);
break;
case siege:
detloss(.0688, .0445, $umod, $emod, siege);
break;
case naval:
detloss(.0450, .0355, $umod, $emod, naval);
break;
case Surprise:
$umod *= 1.2; // fall through
case Standard:
detloss(.1455, .0805, $umod, $emod, infantry);
detloss(.1285, .0730, $umod, $emod, cavalry);
detloss(.0788, .0675, $umod, $emod, siege);
detloss(.0650, .0555, $umod, $emod, naval);
break;
}
if($op > $dp * 1.05)
{
dealland($type);
}
printedreport();
}
/*
This function determines the loss of specific types of troops
It handles the attacker and defender in one run through
*/
function detloss($uper, $eper, $umod, $emod, $type)
{
global $uloss, $eloss, $usent, $esent;
if ($usent[$type] > 0) // can't lose more than you send... send none, lose none
$uloss[$type] = min(mt_rand(0,(ceil($usent[$type] * $uper * $umod)+1)), $usent[$type]);
else $uloss[$type] = 0;
$maxkill = round(.9*$usent[$type]) + mt_rand(0, round(.2*$usent[$type] + 1)); // max kills determination (90% - 110%)
if ($esent[$type] > 0) // he can't lose more than he defended with, or attacker can kill
$eloss[$type] = min(mt_rand(0,ceil($esent[$type] * $eper * $emod)), $esent[$type], $maxkill);
else $eloss[$type] = 0; // no troops, no losses}
I will post the other part of the php in the 2nd post coz it's rly big ..
4 every found error I will give 50 credits .
Thx in advance,
fierce .
<?
//register globals
$do_attack = $_POST['do_attack'];
$target = $_POST['target'];
$attacktype = $_POST['attacttype'];
$sendall = $_POST['sendall'];
$spell_num = $_POST['spell_num'];
$usent = $_POST['usent'];
$do_spell = $_POST['do_spell'];
include("header.php");
include("magicfun.php");
$atknames[Standard] = "Standard Attack";
$atknames[Surprise] = "Surprise Attack";
$atknames[infantry] = "Infantry Strike";
$atknames[cavalry] = "Cavalry Assault";
$atknames[siege] = "Siege Onslaught";
$atknames[naval] = "Hydro Assault";
// era of troops, quantity of troops, type of troops, offense or defense
function CalcPoints($era, $quantity, $ttype, $atype)
{
$type = $atype."_".$ttype;
return $quantity * $era[$type];
}
function ClanCheck() // Need to set warflag and netmult
{
global $warflag, $netmult, $users, $uclan, $enemy;
if ($users[clan] == $enemy[clan])
TheEnd("Cannot attack empires in your clan!");
if (($uclan[ally1] == $enemy[clan]) || ($uclan[ally2] == $enemy[clan]) || ($uclan[ally3] == $enemy[clan]))
TheEnd("Your Generals quietly ignore your orders to attack an Ally.");
if (($uclan[war1] == $enemy[clan]) || ($uclan[war2] == $enemy[clan]) || ($uclan[war3] == $enemy[clan]))
{
$warflag = 1.2;
$netmult = 50;
}
}
function ReadInput ($type)
{
global $users, $usent, $enemy, $esent, $sendall, $trplst;
for ($i = 0; $i < 4; $i++)
{
$trp = $trplst[$i];
$esent[$trp] = $enemy[$trp];
if ($enemy[forces] > 0) // if enemy shares forces, he can't use them for defense
$esent[$trp] *= 0.9;
if ($sendall) // send everything?
$usent[$trp] = $users[$trp];
}
if (($type != 'Standard') && ($type != 'Surprise'))
{
for ($i = 0; $i < 4; $i++)
{
$trp = $trplst[$i];
if ($type != $trp)
{
$usent[$trp] = 0;
$esent[$trp] = 0;
}
}
}
for ($i = 0; $i < 4; $i++)
CheckQuantity($trplst[$i]);
}
function CheckQuantity($type)
{
global $users, $uera, $usent;
fixInputNum($usent[$type]);
$esent[$type] = round($esent[$type]);
if ($usent[$type] < 0)
TheEnd("Cannot attack with a negative number of units!");
if ($usent[$type] > $users[$type])
TheEnd("You do not have that many $uera[$type]!");
}
function Attack($type)
{
global $users, $uera, $usent, $enemy, $eera, $esent, $playerdb, $datetime, $time, $trplst, $warflag;
$uoffense = 0;
$edefense = 0;
for ($i = 0; $i < 4; $i++)
{
$uoffense += CalcPoints($uera,$usent[$trplst[$i]],$trplst[$i],o);
$edefense += CalcPoints($eera,$esent[$trplst[$i]],$trplst[$i],d);
}
if ($uoffense == 0)
TheEnd("Must attack with something!".$trplst[1]."".$uoffense."".$edefense);
$uoffense *= $users[health] / 100;
$edefense *= $enemy[health] / 100;
if ($warflag)
$uoffense *= 1.2;
if ($users[era] != $enemy[era]) // only step through time gate if necessary
{
if ($users[gate] > $time) // your time gate?
print "Stepping through your open time gate,<br>
";
elseif ($enemy[gate] > $time) // or enemy's time gate?
print "Stepping through your enemy's open time gate,<br>
";
}
if ($type == "Surprise") // surprise attack?
{
$offpts *= 1.25;
$helping = 0;
$users[health] -= 5;
}
elseif (($enemy[clan]) && ($enemy[forces] == 1)) // enemy has allies and sharing forces?
{
$dbally = mysql_query("SELECT infantry,cavalry,siege,naval,num,era,race,clan,gate FROM $playerdb WHERE clan=$enemy[clan] AND forces>0 AND num!=$enemy[num] AND land>0;");
$helping = mysql_num_rows($dbally);
}
if ($helping) // add up allies
{
print "$helping empires rushing to defend your target,<br>
";
$emaxdefense = $edefense * 2;
while ($ally = mysql_fetch_array($dbally))
{
$ad = 0;
if (($enemy[gate] > $time) || ($ally[gate] > $time) || ($enemy[era] == $ally[era]))
{ // defense is limited to eras as well
addNews(300,$users,$ally,$enemy[num]);
$arace = loadRace($ally[race]); // adjust according to ally race
$aera = loadEra($ally[era]); // and era
for($i = 0; $i < 4; $i++)
$ad += allyHelp($trplst[$i],$helping) * ($ally[health] / 100);
$ad = round($ad * $arace[defense]);
$edefense += $ad;
}
}
if ($edefense > $emaxdefense) // limit ally defense
$edefense = $emaxdefense;
}
$tdefense = $enemy[towers] * 500 * min(1,$enemy[infantry] / (100*$users[towers]+1)); // and add in towers
$edefense += $tdefense;
if ($warflag == 0) // war == infinite attacks
$enemy[attacks]++;
dobattle($uoffense,$edefense,$type,$tdefense);
}
function AllyHelp ($type, $numallies)
{
global $enemy, $esent, $ally, $aera;
$amt = round($ally[$type] * .1);
if ($amt > $esent[$type] / $numallies)
$amt = $esent[$type] / $numallies;
return CalcPoints($aera,$amt,$type,d);
}
/*
dobattle(Offense_Points, Defense_Points, Attack_Type)
This function:
determines who won
calls detloss() to determine troop losses
calls dealland() if attack was successful
*/
function dobattle ($op, $dp, $type, $towp)
{
$emod = sqrt($op/($dp+1)); // modification to enemy losses
$umod = sqrt(($dp-$towp)/($op+1)); // modification to attacker losses (towers not included)
switch ($type)
{
case infantry:
detloss(.1155, .0705, $umod, $emod, infantry);
break;
case cavalry:
detloss(.0985, .0530, $umod, $emod, cavalry);
break;
case siege:
detloss(.0688, .0445, $umod, $emod, siege);
break;
case naval:
detloss(.0450, .0355, $umod, $emod, naval);
break;
case Surprise:
$umod *= 1.2; // fall through
case Standard:
detloss(.1455, .0805, $umod, $emod, infantry);
detloss(.1285, .0730, $umod, $emod, cavalry);
detloss(.0788, .0675, $umod, $emod, siege);
detloss(.0650, .0555, $umod, $emod, naval);
break;
}
if($op > $dp * 1.05)
{
dealland($type);
}
printedreport();
}
/*
This function determines the loss of specific types of troops
It handles the attacker and defender in one run through
*/
function detloss($uper, $eper, $umod, $emod, $type)
{
global $uloss, $eloss, $usent, $esent;
if ($usent[$type] > 0) // can't lose more than you send... send none, lose none
$uloss[$type] = min(mt_rand(0,(ceil($usent[$type] * $uper * $umod)+1)), $usent[$type]);
else $uloss[$type] = 0;
$maxkill = round(.9*$usent[$type]) + mt_rand(0, round(.2*$usent[$type] + 1)); // max kills determination (90% - 110%)
if ($esent[$type] > 0) // he can't lose more than he defended with, or attacker can kill
$eloss[$type] = min(mt_rand(0,ceil($esent[$type] * $eper * $emod)), $esent[$type], $maxkill);
else $eloss[$type] = 0; // no troops, no losses}
I will post the other part of the php in the 2nd post coz it's rly big ..
4 every found error I will give 50 credits .
Thx in advance,
fierce .