<?php
include ('logue.php'); 
include ('entete2.php');
include ('evolutionbats.php');
include ('siege.php');
$sql = "SELECT pts,siege_lvl,fer_ressource,or_ressource,ada_ressource,ura_ressource, robo_lvl FROM matgraph_users WHERE id='$planete' ";
$res = mysql_query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
$row = mysql_fetch_array($res); 
if ($row[siege_lvl] =="0") {
$Depense_fer_ressource = "900000";
$Depense_or_ressource = "900000";
$Depense_ada_ressource = "500000";
$Depense_ura_ressource = "10000";
}
else {
$Depense_fer_ressource = round((450000 * ( bcpow( 2, ($row[siege_lvl] + 1),3))),0);
$Depense_or_ressource = round((450000 * ( bcpow( 2, ($row[siege_lvl] + 1),3))),0);
$Depense_ada_ressource = round((250000 * ( bcpow( 2, ($row[siege_lvl] + 1),3))),0);
$Depense_ura_ressource = round((5000 * ( bcpow( 2, ($row[siege_lvl] + 1),3))),0);
}
$New_fer_ressource = ($row[fer_ressource] - $Depense_fer_ressource) ;
$New_or_ressource = ($row[or_ressource] - $Depense_or_ressource) ;
$New_ada_ressource = ($row[ada_ressource] - $Depense_ada_ressource) ;
$New_ura_ressource = ($row[ura_ressource] - $Depense_ura_ressource) ;
if ($row[siege_lvl]  == "0") {
$siege_evolution =  strftime("%Y-%m-%d %H:%M:%S", time()+ (129600));
}
else {
$siege_evolution =  strftime("%Y-%m-%d %H:%M:%S", time()+ (round(129600 * (bcpow(2, ($row[siege_lvl]),3)) * (bcpow(0.9, $row[robo_lvl],3)) )));
} 
if ($row[fer_ressource] >= $Depense_fer_ressource && $row[or_ressource] >= $Depense_or_ressource && $row[ada_ressource] >= $Depense_ada_ressource && $row[ura_ressource] >= $Depense_ura_ressource && $evolution < 0) {
$sql = "UPDATE matgraph_users SET siege_evolution='$siege_evolution', fer_ressource=$New_fer_ressource, or_ressource=$New_or_ressource, ada_ressource=$New_ada_ressource, ura_ressource=$New_ura_ressource WHERE id='$planete'";
$res = mysql_query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error()); }
echo '<script language="javascript" type="text/javascript">
<!--
window.location.replace("batiments.php");
-->
</script>';
?>