<?php

if($row['fer_destruction'] !== "0000-00-00 00:00:00" OR $row['exfer_destruction'] !== "0000-00-00 00:00:00" OR $row['or_destruction'] !== "0000-00-00 00:00:00" OR $row['exor_destruction'] !== "0000-00-00 00:00:00" OR $row['ada_destruction'] !== "0000-00-00 00:00:00" OR $row['ura_destruction'] !== "0000-00-00 00:00:00" OR $row['labo_destruction'] !== "0000-00-00 00:00:00" OR $row['robo_destruction'] !== "0000-00-00 00:00:00" OR $row['siege_destruction'] !== "0000-00-00 00:00:00" OR $row['chantier_destruction'] !== "0000-00-00 00:00:00" OR $row['hangarfer_destruction'] !== "0000-00-00 00:00:00" OR $row['hangaror_destruction'] !== "0000-00-00 00:00:00" OR $row['hangarada_destruction'] !== "0000-00-00 00:00:00" OR $row['hangarura_destruction'] !== "0000-00-00 00:00:00" OR $row['mili_destruction'] !== "0000-00-00 00:00:00" OR $row['silo_destruction'] !== "0000-00-00 00:00:00" OR $row['defense_destruction'] !== "0000-00-00 00:00:00") {
include 'destruction.php';
}


$datetime = $row['date'];

ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $datetime, $thetime);
$time = mktime($thetime[4],$thetime[5],$thetime[6],$thetime[2],$thetime[3],$thetime[1]);

$diftemps = time() - $time;
$difheure = round($diftemps / 3600,1);
// fer
$datetimefer2 = $row['fer_evolution'];

ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $datetimefer2, $thetime);
$timefer2 = mktime($thetime[4],$thetime[5],$thetime[6],$thetime[2],$thetime[3],$thetime[1]);

$diftempsfer2 = time() - $timefer2;
$diftempsfer3 = $timefer2 - $time;

$debug_texte = $debug_texte . "<br>vTime : $time";
$debug_texte = $debug_texte . "<br>time() : ".time();
$debug_texte = $debug_texte . "<br>vDiftemps : $diftemps";
$debug_texte = $debug_texte . "<br>vDifheure : $difheure";
$debug_texte = $debug_texte . "<br>vDatetimefer2 : $datetimefer2";
$debug_texte = $debug_texte . "<br>vDiftempsfer2 : $diftempsfer2";
$debug_texte = $debug_texte . "<br>vDiftempsfer3 : $diftempsfer3";

// exfer
$datetimeexfer2 = $row['exfer_evolution'];

ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $datetimeexfer2, $thetime);
$timeexfer2 = mktime($thetime[4],$thetime[5],$thetime[6],$thetime[2],$thetime[3],$thetime[1]);

$diftempsexfer2 = time() - $timeexfer2;
$diftempsexfer3 = $timeexfer2 - $time;

$debug_texte = $debug_texte . "<br>vDatetimeexfer2 : $datetimeexfer2";
$debug_texte = $debug_texte . "<br>vDiftempsexfer2 : $diftempsexfer2";
$debug_texte = $debug_texte . "<br>vDiftempsexfer3 : $diftempsexfer3";

// or
$datetimeor2 = $row['or_evolution'];

ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $datetimeor2, $thetime);
$timeor2 = mktime($thetime[4],$thetime[5],$thetime[6],$thetime[2],$thetime[3],$thetime[1]);

$diftempsor2 = time() - $timeor2;
$diftempsor3 = $timeor2 - $time;
// exor
$datetimeexor2 = $row['exor_evolution'];

ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $datetimeexor2, $thetime);
$timeexor2 = mktime($thetime[4],$thetime[5],$thetime[6],$thetime[2],$thetime[3],$thetime[1]);

$diftempsexor2 = time() - $timeexor2;
$diftempsexor3 = $timeexor2 - $time;
// ada
$datetimeada2 = $row['ada_evolution'];

ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $datetimeada2, $thetime);
$timeada2 = mktime($thetime[4],$thetime[5],$thetime[6],$thetime[2],$thetime[3],$thetime[1]);

$diftempsada2 = time() - $timeada2;
$diftempsada3 = $timeada2 - $time;

//ura
$datetimeura2 = $row['ura_evolution'];

ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $datetimeura2, $thetime);
$timeura2 = mktime($thetime[4],$thetime[5],$thetime[6],$thetime[2],$thetime[3],$thetime[1]);

$diftempsura2 = time() - $timeura2;
$diftempsura3 = $timeura2 - $time;

//central
$datetimecentral2 = $row['central_evolution'];
ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $datetimecentral2, $thetime);
$timecentral2 = mktime($thetime[4],$thetime[5],$thetime[6],$thetime[2],$thetime[3],$thetime[1]);
$diftempscentral2 = time() - $timecentral2;
$diftempscentral3 = $timecentral2 - $time;

//fission
$datetimefission2 = $row['fission_evolution'];

ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $datetimefission2, $thetime);
$timefission2 = mktime($thetime[4],$thetime[5],$thetime[6],$thetime[2],$thetime[3],$thetime[1]);
$diftempsfission2 = time() - $timefission2;
$diftempsfission3 = $timefission2 - $time;

//labo
$datetimelabo2 = $row['labo_evolution'];
ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $datetimelabo2, $thetime);
$timelabo2 = mktime($thetime[4],$thetime[5],$thetime[6],$thetime[2],$thetime[3],$thetime[1]);
$diftempslabo2 = time() - $timelabo2;
$diftempslabo3 = $timelabo2 - $time;

//robo
$datetimerobo2 = $row['robo_evolution'];
ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $datetimerobo2, $thetime);
$timerobo2 = mktime($thetime[4],$thetime[5],$thetime[6],$thetime[2],$thetime[3],$thetime[1]);
$diftempsrobo2 = time() - $timerobo2;
$diftempsrobo3 = $timerobo2 - $time;

//siege
$datetimesiege2 = $row['siege_evolution'];
ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $datetimesiege2, $thetime);
$timesiege2 = mktime($thetime[4],$thetime[5],$thetime[6],$thetime[2],$thetime[3],$thetime[1]);
$diftempssiege2 = time() - $timesiege2;
$diftempssiege3 = $timesiege2 - $time;

//chantier
$datetimechantier2 = $row['chantier_evolution'];
ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $datetimechantier2, $thetime);
$timechantier2 = mktime($thetime[4],$thetime[5],$thetime[6],$thetime[2],$thetime[3],$thetime[1]);
$diftempschantier2 = time() - $timechantier2;
$diftempschantier3 = $timechantier2 - $time;

//hangarfer
$datetimehangarfer2 = $row['hangarfer_evolution'];
ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $datetimehangarfer2, $thetime);
$timehangarfer2 = mktime($thetime[4],$thetime[5],$thetime[6],$thetime[2],$thetime[3],$thetime[1]);
$diftempshangarfer2 = time() - $timehangarfer2;
$diftempshangarfer3 = $timehangarfer2 - $time;

//hangaror
$datetimehangaror2 = $row['hangaror_evolution'];
ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $datetimehangaror2, $thetime);
$timehangaror2 = mktime($thetime[4],$thetime[5],$thetime[6],$thetime[2],$thetime[3],$thetime[1]);
$diftempshangaror2 = time() - $timehangaror2;
$diftempshangaror3 = $timehangaror2 - $time;

//hangarada
$datetimehangarada2 = $row['hangarada_evolution'];
ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $datetimehangarada2, $thetime);
$timehangarada2 = mktime($thetime[4],$thetime[5],$thetime[6],$thetime[2],$thetime[3],$thetime[1]);
$diftempshangarada2 = time() - $timehangarada2;
$diftempshangarada3 = $timehangarada2 - $time;

//hangarura
$datetimehangarura2 = $row['hangarura_evolution'];
ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $datetimehangarura2, $thetime);
$timehangarura2 = mktime($thetime[4],$thetime[5],$thetime[6],$thetime[2],$thetime[3],$thetime[1]);
$diftempshangarura2 = time() - $timehangarura2;
$diftempshangarura3 = $timehangarura2 - $time;

//silo
$datetimesilo2 = $row['silo_evolution'];
ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $datetimesilo2, $thetime);
$timesilo2 = mktime($thetime[4],$thetime[5],$thetime[6],$thetime[2],$thetime[3],$thetime[1]);
$diftempssilo2 = time() - $timesilo2;
$diftempssilo3 = $timesilo2 - $time;

// defense
$datetimedefense2 = $row['defense_evolution'];
ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $datetimedefense2, $thetime);
$timedefense2 = mktime($thetime[4],$thetime[5],$thetime[6],$thetime[2],$thetime[3],$thetime[1]);
$diftempsdefense2 = time() - $timedefense2;
$diftempsdefense3 = $timedefense2 - $time;

// mili
$datetimemili2 = $row['mili_evolution'];
ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $datetimemili2, $thetime);
$timemili2 = mktime($thetime[4],$thetime[5],$thetime[6],$thetime[2],$thetime[3],$thetime[1]);
$diftempsmili2 = time() - $timemili2;
$diftempsmili3 = $timemili2 - $time;

//terri
$datetimeterri2 = $row['terri_evolution'];
ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $datetimeterri2, $thetime);
$timeterri2 = mktime($thetime[4],$thetime[5],$thetime[6],$thetime[2],$thetime[3],$thetime[1]);
$diftempsterri2 = time() - $timeterri2;
$diftempsterri3 = $timeterri2 - $time;



// fer
if ($timefer2 == "-1" && $diftempsfer2 > 0 ){
	if ($row['fer_lvl'] == "0") {
		$new9fer_ressource = $row['fer_ressource'] + (20 * $diftemps / 3600);
	}
	else {
		$new9fer_ressource = $row['fer_ressource'] + ((($row['fer_on'] * 100 * ( bcpow( 1.18, $row['fer_lvl'],3))) + 20) * $diftemps / 3600);
	}
	$debug_texte = $debug_texte . "<br>vTimefer2 == -1 et vDiftempsfer2 > 0";
	$debug_texte = $debug_texte . "<br>vNew9fer_ressource : $new9fer_ressource";
}
if ($timefer2 > 0 && $diftempsfer2 <= 0){
	if ($row['fer_lvl'] == "0") {
		$new9fer_ressource = $row['fer_ressource'] + (20 * $diftemps / 3600);
	}
	else {
		$new9fer_ressource = $row['fer_ressource'] + ((($row['fer_on'] * 100 * ( bcpow( 1.18,($row['fer_lvl']),3))) + 20) * $diftemps / 3600);
	}
	$debug_texte = $debug_texte . "<br>vTimefer2 > 0 et vDiftempsfer2 < 0";
	$debug_texte = $debug_texte . "<br>vNew9fer_ressource : $new9fer_ressource";
}
if ($timefer2 > 0 && $diftempsfer2 > 0){
	$new9fer_ressource2 = ((($row['fer_on'] * 100 * ( bcpow( 1.18, ($row['fer_lvl'] + 1),3))) + 20) * $diftempsfer2 / 3600);
	$new9fer_ressource3 = ((($row['fer_on'] * 100 * ( bcpow( 1.18, $row['fer_lvl'],3))) + 20) * $diftempsfer3 / 3600);

	if($debug == 1) {
		echo"<br>Temps 2:$diftempsfer2 3:$diftempsfer3";
		echo"<br>Fer Base: ".$row['fer_ressource']." 2:$new9fer_ressource2 3:$new9fer_ressource3";
	}
	$new9fer_ressource = $row['fer_ressource'] + $new9fer_ressource2 + $new9fer_ressource3 ;

	$debug_texte = $debug_texte . "<br>vTimefer2 > 0 et vDiftempsfer2 > 0";
	$debug_texte = $debug_texte . "<br>vRowfer_ressource : ".$row['fer_ressource'];
	$debug_texte = $debug_texte . "<br>vNew9fer_ressource2 : $new9fer_ressource2";
	$debug_texte = $debug_texte . "<br>vNew9fer_ressource3 : $new9fer_ressource3";
	$debug_texte = $debug_texte . "<br>vNew9fer_ressource : $new9fer_ressource";
	/*$fer_total = floor($new9fer_ressource);
	$fer_ressource = floor($row[fer_ressource]);
	$fer_ressource1 = floor($new9fer_ressource2);
	$fer_ressource2 = floor($new9fer_ressource3);
	echo"<br><br> $fer_total = $fer_ressource + $fer_ressource1 + $fer_ressource2 ;<br><br>";*/

$New_fer_lvl = $row['fer_lvl'] + 1 ;

if ($row['fer_lvl'] == "0") {
$New_fer_energie = "-30" ;
}
else {
$New_fer_energie = round((-30 * (bcpow(1.18, $row['fer_lvl'],3)) + $row['fer_energie']),0);
}
if ($row['fer_lvl'] =="0") {
$Depense_fer_ressource = "60";
$Depense_or_ressource = "15";
}
else {
$Depense_fer_ressource = round((60 * ( bcpow( 1.45, ($row['fer_lvl'] + 1),3))),0);
$Depense_or_ressource = round((15 * ( bcpow( 1.45, ($row['fer_lvl'] + 1),3))),0);
}
$new_pts_bats= $Depense_fer_ressource + $Depense_or_ressource + $row2['pts_bats'];

	$sql = "UPDATE matgraph_users SET fer_lvl=$New_fer_lvl, fer_energie=$New_fer_energie, fer_evolution = \"0000-00-00 00:00:00\" WHERE id='$planete' LIMIT 1";
	$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
	$sql2 = "UPDATE matgraph_users SET pts_bats=$new_pts_bats WHERE id='$idlogin' LIMIT 1";
	$res2 = db_mysql_Query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
}

// exfer
if ($timeexfer2 == "-1" && $diftempsexfer2 > 0 ){
	if ($row['exfer_lvl'] == "0") {
	$newexfer_ressource = 0;
	}
	else {
	$newexfer_ressource = 0 + ((($row['exfer_on'] * 500 * ( bcpow( 1.2, $row['exfer_lvl'],3)))) * $diftemps / 3600);
	}}
if ($timeexfer2 > 0 && $diftempsexfer2 <= 0){
	if ($row['exfer_lvl'] == "0") {
	$newexfer_ressource = 0 ;
	}
	else {
	$newexfer_ressource = 0 + ((($row['exfer_on'] * 500 * ( bcpow( 1.2,($row['exfer_lvl']),3)))) * $diftemps / 3600);
	}}
if ($timeexfer2 > 0 && $diftempsexfer2 > 0){
	$newexfer_ressource2 = ((($row['exfer_on'] * 500 * ( bcpow( 1.2, ($row['exfer_lvl'] + 1),3)))) * $diftempsexfer2 / 3600);
	$newexfer_ressource3 = ((($row['exfer_on'] * 500 * ( bcpow( 1.2, $row['exfer_lvl'] ,3)))) * $diftempsexfer3 / 3600);
	$newexfer_ressource = $newexfer_ressource2 + $newexfer_ressource3 ;

$New_exfer_lvl = $row['exfer_lvl'] + 1 ;
if ($row['exfer_lvl'] =="0") {
$Depense_fer_ressource = "35000";
$Depense_or_ressource = "15000";
$Depense_ada_ressource = "1000";
}
else {
$Depense_fer_ressource = round((30000 * ( bcpow( 1.2, ($row['exfer_lvl'] + 1),3))),0);
$Depense_or_ressource = round((20000 * ( bcpow( 1.2, ($row['exfer_lvl'] + 1)))),0);
$Depense_ada_ressource = round((1000 * ( bcpow( 1.2, ($row['exfer_lvl'] + 1)))),0);
}
$new_pts_bats= $Depense_fer_ressource + $Depense_or_ressource + $Depense_ada_ressource + $row2[pts_bats];
if ($row['exfer_lvl'] == "0") {
$New_exfer_energie = "-200" ;
}
else {
$New_exfer_energie = round((-200 * (bcpow(1.18, $row['exfer_lvl'],3)) + $row['exfer_energie']),0);
}
	$sql = "UPDATE matgraph_users SET exfer_lvl=$New_exfer_lvl, exfer_energie=$New_exfer_energie, exfer_evolution = \"0000-00-00 00:00:00\" WHERE id='$planete' LIMIT 1";
	$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
	$sql2 = "UPDATE matgraph_users SET pts_bats=$new_pts_bats WHERE id='$idlogin' LIMIT 1";
	$res2 = db_mysql_Query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
}
// or
if ($timeor2 == "-1" && $diftempsor2 > 0 ){
	if ($row['or_lvl'] == "0") {
	$new9or_ressource = $row['or_ressource'] + (10 * $diftemps / 3600);
	}
	else {
	$new9or_ressource = $row['or_ressource'] + ((($row['or_on'] * 90 * ( bcpow( 1.15, $row['or_lvl'],3))) + 10) * $diftemps / 3600);
	}}
if ($timeor2 > 0 && $diftempsor2 <= 0){
	if ($row[or_lvl] == "0") {
	$new9or_ressource = $row['or_ressource'] + (10 * $diftemps / 3600);
	}
	else {
	$new9or_ressource = $row['or_ressource'] + ((($row[or_on] * 90 * ( bcpow( 1.15,($row['or_lvl']),3))) + 10) * $diftemps / 3600);
	}}
if ($timeor2 > 0 && $diftempsor2 > 0){
	$new9or_ressource2 = ((($row['or_on'] * 90 * ( bcpow( 1.15, ($row['or_lvl'] + 1),3))) + 10) * $diftempsor2 / 3600);
	$new9or_ressource3 = ((($row['or_on'] * 90 * ( bcpow( 1.15, $row['or_lvl'],3))) + 10) * $diftempsor3 / 3600);
	$new9or_ressource = $row['or_ressource'] + $new9or_ressource2 + $new9or_ressource3 ;
	/*$fer_total = floor($new9or_ressource);
	$fer_ressource = floor($row[or_ressource]);
	$fer_ressource1 = floor($new9or_ressource2);
	$fer_ressource2 = floor($new9or_ressource3);
	echo"$fer_total = $fer_ressource + $fer_ressource1 + $fer_ressource2 ;";*/

$New_or_lvl = $row['or_lvl'] + 1 ;
if ($row['or_lvl'] =="0") {
$Depense_fer_ressource = "50";
$Depense_or_ressource = "25";
}
else {
$Depense_fer_ressource = round((50 * ( bcpow( 1.5, ($row['or_lvl'] + 1),3))),0);
$Depense_or_ressource = round((25 * ( bcpow( 1.5, ($row['or_lvl'] + 1),3))),0);
}
$new_pts_bats= $Depense_fer_ressource + $Depense_or_ressource + $row2[pts_bats];
if ($row['or_lvl'] == "0") {
$New_or_energie = "-26" ;
}
else {
$New_or_energie = round((-26 * (bcpow(1.14, $row['or_lvl'],3)) + $row[or_energie]),0);
}
	$sql = "UPDATE matgraph_users SET or_lvl=$New_or_lvl,or_energie=$New_or_energie, or_evolution = \"0000-00-00 00:00:00\" WHERE id='$planete' LIMIT 1";
	$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
	$sql2 = "UPDATE matgraph_users SET pts_bats=$new_pts_bats WHERE id='$idlogin' LIMIT 1";
	$res2 = db_mysql_Query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
}
// exor
if ($timeexor2 == "-1" && $diftempsexor2 > 0 ){
	if ($row['exor_lvl'] == "0") {
	$newexor_ressource = 0;
	}
	else {
	$newexor_ressource = 0 + ((($row[exor_on] * 500 * ( bcpow( 1.25, $row['exor_lvl'],3)))) * $diftemps / 3600);
	}}
if ($timeexor2 > 0 && $diftempsexor2 <= 0){
	if ($row['exor_lvl'] == "0") {
	$newexor_ressource = 0;
	}
	else {
	$newexor_ressource = 0 + ((($row[exor_on] * 500 * ( bcpow( 1.25,($row['exor_lvl']),3)))) * $diftemps / 3600);
	}}
if ($timeexor2 > 0 && $diftempsexor2 > 0){
	$newexor_ressource2 = ((($row[exor_on] * 500 * ( bcpow( 1.25, ($row['exor_lvl'] + 1),3)))) * $diftempsexor2 / 3600);
	$newexor_ressource3 = ((($row[exor_on] * 500 * ( bcpow( 1.25, $row['exor_lvl'] ,3)))) * $diftempsexor3 / 3600);
	$newexor_ressource = $newexor_ressource2 + $newexor_ressource3 ;

$New_exor_lvl = $row['exor_lvl'] + 1 ;
if ($row['exor_lvl'] =="0") {
$Depense_fer_ressource = "32000";
$Depense_or_ressource = "20000";
$Depense_ada_ressource = "1500";
}
else {
$Depense_fer_ressource = round((32000 * ( bcpow( 1.3, ($row['exor_lvl'] + 1),3))),0);
$Depense_or_ressource = round((20000 * ( bcpow( 1.3, ($row['exor_lvl'] + 1),3))),0);
$Depense_ada_ressource = round((1500 * ( bcpow( 1.3, ($row['exor_lvl'] + 1),3))),0);
}
$new_pts_bats= $Depense_fer_ressource + $Depense_or_ressource + $Depense_ada_ressource + $row2[pts_bats];
if ($row['exor_lvl'] == "0") {
$New_exor_energie = "-150" ;
}
else {
$New_exor_energie = round((-150 * (bcpow(1.14, $row['exor_lvl'],3)) + $row[exor_energie]),0);
}
	$sql = "UPDATE matgraph_users SET exor_lvl=$New_exor_lvl,exor_energie=$New_exor_energie, exor_evolution = \"0000-00-00 00:00:00\" WHERE id='$planete' LIMIT 1";
	$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
	$sql2 = "UPDATE matgraph_users SET pts_bats=$new_pts_bats WHERE id='$idlogin' LIMIT 1";
	$res2 = db_mysql_Query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
}
// ada
if ($timeada2 == "-1" && $diftempsada2 > 0 ){
	if ($row['ada_lvl'] == "0") {
	$newada_ressource = $row[ada_ressource] + (5 * $diftemps / 3600);
	}
	else {
	$newada_ressource = $row[ada_ressource] + ((($row[ada_on] * 100 * ( bcpow( 1.2, $row['ada_lvl'],3))) + 5) * $diftemps / 3600);
	}}
if ($timeada2 > 0 && $diftempsada2 <= 0){
	if ($row['ada_lvl'] == "0") {
	$newada_ressource = $row[ada_ressource] + (5 * $diftemps / 3600);
	}
	else {
	$newada_ressource = $row[ada_ressource] + ((($row[ada_on] * 100 * ( bcpow( 1.2,($row['ada_lvl']),3))) + 5) * $diftemps / 3600);
	}}
if ($timeada2 > 0 && $diftempsada2 > 0){
	$newada_ressource2 = ((($row[ada_on] * 100 * ( bcpow( 1.2, ($row['ada_lvl'] + 1) ,3))) + 5) * $diftempsada2 / 3600);
	$newada_ressource3 = ((($row[ada_on] * 100 * ( bcpow( 1.2, $row['ada_lvl'] ,3))) + 5) * $diftempsada3 / 3600);
	$newada_ressource = $row[ada_ressource] + $newada_ressource2 + $newada_ressource3 ;

$New_ada_lvl = $row['ada_lvl'] + 1 ;
if ($row['ada_lvl'] == "0") {
$New_ada_energie = "-40" ;
}
else {
$New_ada_energie = round((-40 * (bcpow(1.12, $row['ada_lvl'],3)) + $row[ada_energie]),0);
}
if ($row['ada_lvl'] =="0") {
$Depense_fer_ressource = "500";
$Depense_or_ressource = "160";
}
else {
$Depense_fer_ressource = round((500 * ( bcpow( 1.45, ($row['ada_lvl'] + 1),3))),0);
$Depense_or_ressource = round((160 * ( bcpow( 1.45, ($row['ada_lvl'] + 1),3))),0);
}
$new_pts_bats= $Depense_fer_ressource + $Depense_or_ressource + $row2[pts_bats];
	$sql = "UPDATE matgraph_users SET ada_lvl=$New_ada_lvl, ada_energie=$New_ada_energie, ada_evolution = \"0000-00-00 00:00:00\" WHERE id='$planete' LIMIT 1";
	$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
	$sql2 = "UPDATE matgraph_users SET pts_bats=$new_pts_bats WHERE id='$idlogin' LIMIT 1";
	$res2 = db_mysql_Query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
}
// ura
if ($row['fission_lvl'] == "0") {
$coutfission = "0" ;
}
else {
$coutfission = (20 * ( bcpow( 1.3, $row['fission_lvl'],3))) ;
}
if ($timeura2 == "-1" && $diftempsura2 > 0 ){
	if ($row['ura_lvl'] == "0") {
	$newura_ressource = $row[ura_ressource] + (2 * $diftemps / 3600);
	}
	else {
	$newura_ressource = $row[ura_ressource] + ((($row[ura_on] * 100 * ( bcpow( 1.2, $row['ura_lvl'],3))) + 2 - $coutfission) * $diftemps / 3600);
	}}
if ($timeura2 > 0 && $diftempsura2 <= 0){
	if ($row['ura_lvl'] == "0") {
	$newura_ressource = $row[ura_ressource] + (2 * $diftemps / 3600);
	}
	else {
	$newura_ressource = $row[ura_ressource] + ((($row[ura_on] * 100 * ( bcpow( 1.2,($row['ura_lvl']),3))) + 2 - $coutfission) * $diftemps / 3600);
	}}
if ($timeura2 > 0 && $diftempsura2 > 0){
	$newura_ressource2 = ((($row[ura_on] * 100 * ( bcpow( 1.2, ($row['ura_lvl'] + 1) ,3))) + 2 - $coutfission) * $diftempsura2 / 3600);
	$newura_ressource3 = ((($row[ura_on] * 100 * ( bcpow( 1.2, $row['ura_lvl'],3))) + 2 - $coutfission) * $diftempsura3 / 3600);
	$newura_ressource = $row[ura_ressource] + $newura_ressource2 + $newura_ressource3 ;

$New_ura_lvl = $row['ura_lvl'] + 1 ;
if ($row['ura_lvl'] =="0") {
$Depense_fer_ressource = "500";
$Depense_or_ressource = "300";
$Depense_ada_ressource = "100";
}
else {
$Depense_fer_ressource = round((500 * ( bcpow( 1.4, ($row['ura_lvl'] + 1),3))),0);
$Depense_or_ressource = round((300 * ( bcpow( 1.4, ($row['ura_lvl'] + 1),3))),0);
$Depense_ada_ressource = round((100 * ( bcpow( 1.4, ($row['ura_lvl'] + 1),3))),0);
}
$new_pts_bats= $Depense_fer_ressource + $Depense_or_ressource + $Depense_ada_ressource + $row2[pts_bats];
if ($row['ura_lvl'] == "0") {
$New_ura_energie = "-68" ;
}
else {
$New_ura_energie = round((-68 * (bcpow(1.1, $row['ura_lvl'],3)) + $row[ura_energie]),0);
}
	$sql = "UPDATE matgraph_users SET ura_lvl=$New_ura_lvl, ura_energie=$New_ura_energie, ura_evolution = \"0000-00-00 00:00:00\" WHERE id='$planete' LIMIT 1";
	$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
	$sql2 = "UPDATE matgraph_users SET pts_bats=$new_pts_bats WHERE id='$idlogin' LIMIT 1";
	$res2 = db_mysql_Query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
}

//central
if ($timecentral2 == "-1" && $diftempscentral2 > 0) {
$New_central_lvl = ($row['central_lvl'] + 1) ;
$Energie_central = $row[central_energie] ;
}
if ($timecentral2 > 0 && $diftempscentral2 <= 0) {
$Energie_central = $row[central_energie];
}
if ($timecentral2 > 0 && $diftempscentral2 > 0) {
$New_central_lvl = $row['central_lvl'] + 1 ;
if ($row['central_lvl'] =="0") {
$Depense_fer_ressource = "52";
$Depense_or_ressource = "30";
}
else {
$Depense_fer_ressource = round((52 * ( bcpow( 1.6, ($row['central_lvl'] + 1),3))),0);
$Depense_or_ressource = round((30 * ( bcpow( 1.6, ($row['central_lvl'] + 1),3))),0);
}

if ($row['central_lvl'] == "0") {
$New_central_energie = "(200/3)" ;
}
else {
$New_central_energie = round(((200/3) * (bcpow(1.2, $row['central_lvl'],3)) + $row[central_energie]),0);
}
$new_pts_bats= $Depense_fer_ressource + $Depense_or_ressource + $row2[pts_bats];
$sql = "UPDATE matgraph_users SET central_lvl=$New_central_lvl, central_energie=$New_central_energie, central_evolution = \"0000-00-00 00:00:00\" WHERE id='$planete' LIMIT 1";
$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
$sql2 = "UPDATE matgraph_users SET pts_bats=$new_pts_bats WHERE id='$idlogin' LIMIT 1";
	$res2 = db_mysql_Query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
}
else {
$New_central_energie = $row[central_energie] ;
}
//fission
if ($timefission2 == "-1" && $diftempsfission2 > 0) {
$New_fission_lvl = ($row['fission_lvl'] + 1) ;
$Energie_fission = $row[fission_energie] ;
}
if ($timefission2 > 0 && $diftempsfission2 <= 0) {
$Energie_fission = $row[fission_energie];
}
if ($timefission2 > 0 && $diftempsfission2 > 0) {
$New_fission_lvl = $row['fission_lvl'] + 1 ;
if ($row['fission_lvl'] == "0") {
$Depense_fer_ressource = "5200";
$Depense_or_ressource = "3000";
$Depense_ada_ressource = "750";
}
else {
$Depense_fer_ressource = round((5200 * ( bcpow( 1.6, ($row['fission_lvl'] + 1),3))),0);
$Depense_or_ressource = round((3000 * ( bcpow( 1.6, ($row['fission_lvl'] + 1),3))),0);
$Depense_ada_ressource = round((750 * ( bcpow( 1.6, ($row['fission_lvl'] + 1),3))),0);
}

if ($row['fission_lvl'] == "0") {
$New_fission_energie = "(300)" ;
}
else {
$New_fission_energie = round(((300) * (bcpow(1.3, $row['fission_lvl'],3)) + $row[fission_energie]),0);
}
$new_pts_bats= $Depense_fer_ressource + $Depense_or_ressource + $row2[pts_bats];
$sql = "UPDATE matgraph_users SET fission_lvl=$New_fission_lvl, fission_energie=$New_fission_energie, fission_evolution = \"0000-00-00 00:00:00\" WHERE id='$planete' LIMIT 1";
$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
$sql2 = "UPDATE matgraph_users SET pts_bats=$new_pts_bats WHERE id='$idlogin' LIMIT 1";
	$res2 = db_mysql_Query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
}
else {
$New_fission_energie = $row[fission_energie] ;
}

// labo

if ($timelabo2 > 0 && $diftempslabo2 > 0){
$New_labo_lvl = $row['labo_lvl'] + 1 ;
if ($row['labo_lvl'] =="0") {
$Depense_fer_ressource = "200";
$Depense_or_ressource = "400";
$Depense_ada_ressource = "200";
}
else {
$Depense_fer_ressource = round((200 * ( bcpow( 1.75, ($row['labo_lvl'] + 1),3))),0);
$Depense_or_ressource = round((400 * ( bcpow( 1.75, ($row['labo_lvl'] + 1),3))),0);
$Depense_ada_ressource = round((200 * ( bcpow( 1.75, ($row['labo_lvl'] + 1),3))),0);
}
$new_pts_bats= $Depense_fer_ressource + $Depense_or_ressource + $Depense_ada_ressource + $row2[pts_bats];
$sql = "UPDATE matgraph_users SET labo_lvl=$New_labo_lvl, labo_evolution = \"0000-00-00 00:00:00\" WHERE id='$planete' LIMIT 1";
$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
$sql2 = "UPDATE matgraph_users SET pts_bats=$new_pts_bats WHERE id='$idlogin' LIMIT 1";
	$res2 = db_mysql_Query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
}
// robo

if ($timerobo2 > 0 && $diftempsrobo2 > 0){
$New_robo_lvl = $row['robo_lvl'] + 1 ;
if ($row['robo_lvl'] =="0") {
$Depense_fer_ressource = "100";
$Depense_or_ressource = "200";
$Depense_ada_ressource = "100";
}
else {
$Depense_fer_ressource = round((100 * ( bcpow( 1.9, ($row['robo_lvl'] + 1),3))),0);
$Depense_or_ressource = round((200 * ( bcpow( 1.9, ($row['robo_lvl'] + 1),3))),0);
$Depense_ada_ressource = round((100 * ( bcpow( 1.9, ($row['robo_lvl'] + 1),3))),0);
}
$new_pts_bats= $Depense_fer_ressource + $Depense_or_ressource + $Depense_ada_ressource + $row2[pts_bats];
$sql = "UPDATE matgraph_users SET robo_lvl=$New_robo_lvl, robo_evolution = \"0000-00-00 00:00:00\" WHERE id='$planete' LIMIT 1";
$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
$sql2 = "UPDATE matgraph_users SET pts_bats=$new_pts_bats WHERE id='$idlogin' LIMIT 1";
	$res2 = db_mysql_Query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
}
// siege

if ($timesiege2 > 0 && $diftempssiege2 > 0){
$New_siege_lvl = $row[siege_lvl] + 1 ;
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_pts_bats= $Depense_fer_ressource + $Depense_or_ressource + $Depense_ada_ressource + $Depense_ura_ressource + $row2[pts_bats];
$sql = "UPDATE matgraph_users SET siege_lvl=$New_siege_lvl, siege_evolution = \"0000-00-00 00:00:00\" WHERE id='$planete' LIMIT 1";
$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
$sql2 = "UPDATE matgraph_users SET pts_bats=$new_pts_bats WHERE id='$idlogin' LIMIT 1";
	$res2 = db_mysql_Query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
}
// chantier

if ($timechantier2 > 0 && $diftempschantier2 > 0){
$New_chantier_lvl = $row['chantier_lvl'] + 1 ;
if ($row['chantier_lvl'] =="0") {
$Depense_fer_ressource = "100";
$Depense_or_ressource = "200";
$Depense_ada_ressource = "100";
}
else {
$Depense_fer_ressource = round((100 * ( bcpow( 1.9, ($row['chantier_lvl'] + 1),3))),0);
$Depense_or_ressource = round((200 * ( bcpow( 1.9, ($row['chantier_lvl'] + 1),3))),0);
$Depense_ada_ressource = round((100 * ( bcpow( 1.9, ($row['chantier_lvl'] + 1),3))),0);
}
$new_pts_bats= $Depense_fer_ressource + $Depense_or_ressource +$New_ada_ressource + $row2[pts_bats];
$sql = "UPDATE matgraph_users SET chantier_lvl=$New_chantier_lvl, chantier_evolution = \"0000-00-00 00:00:00\" WHERE id='$planete' LIMIT 1";
$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
$sql2 = "UPDATE matgraph_users SET pts_bats=$new_pts_bats WHERE id='$idlogin' LIMIT 1";
	$res2 = db_mysql_Query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
}
// hangarfer

if ($timehangarfer2 > 0 && $diftempshangarfer2 > 0){
$New_hangarfer_lvl = $row['hangarfer_lvl'] + 1 ;
if ($row['hangarfer_lvl'] =="0") {
$Depense_fer_ressource = "2000";
}
else {
$Depense_fer_ressource = round((1000 * ( bcpow( 2, ($row['hangarfer_lvl'] + 1),3))),0);
}
$new_pts_bats= $Depense_fer_ressource + $row2[pts_bats];
$sql = "UPDATE matgraph_users SET hangarfer_lvl=$New_hangarfer_lvl, hangarfer_evolution = \"0000-00-00 00:00:00\" WHERE id='$planete' LIMIT 1";
$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
$sql2 = "UPDATE matgraph_users SET pts_bats=$new_pts_bats WHERE id='$idlogin' LIMIT 1";
	$res2 = db_mysql_Query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
}
// hangaror

if ($timehangaror2 > 0 && $diftempshangaror2 > 0){
$New_hangaror_lvl = $row['hangaror_lvl'] + 1 ;
if ($row['hangaror_lvl'] =="0") {
$Depense_fer_ressource = "2000";
$Depense_or_ressource = "1000";
}
else {
$Depense_fer_ressource = round((1000 * ( bcpow( 2, ($row['hangaror_lvl'] + 1),3))),0);
$Depense_or_ressource = round((500 * ( bcpow( 2, ($row['hangaror_lvl'] + 1),3))),0);
}
$new_pts_bats= $Depense_fer_ressource + $Depense_or_ressource + $row2[pts_bats];
$sql = "UPDATE matgraph_users SET hangaror_lvl=$New_hangaror_lvl, hangaror_evolution = \"0000-00-00 00:00:00\" WHERE id='$planete' LIMIT 1";
$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
$sql2 = "UPDATE matgraph_users SET pts_bats=$new_pts_bats WHERE id='$idlogin' LIMIT 1";
	$res2 = db_mysql_Query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
}
// hangarada

if ($timehangarada2 > 0 && $diftempshangarada2 > 0){
$New_hangarada_lvl = $row['hangarada_lvl'] + 1 ;
if ($row['hangarada_lvl'] =="0") {
$Depense_fer_ressource = "2000";
$Depense_or_ressource = "2000";
}
else {
$Depense_fer_ressource = round((1000 * ( bcpow( 2, ($row['hangarada_lvl'] + 1),3))),0);
$Depense_or_ressource = round((1000 * ( bcpow( 2, ($row['hangarada_lvl'] + 1),3))),0);
}
$new_pts_bats= $Depense_fer_ressource + $Depense_or_ressource + $row2[pts_bats];
$sql = "UPDATE matgraph_users SET hangarada_lvl=$New_hangarada_lvl, hangarada_evolution = \"0000-00-00 00:00:00\" WHERE id='$planete' LIMIT 1";
$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
$sql2 = "UPDATE matgraph_users SET pts_bats=$new_pts_bats WHERE id='$idlogin' LIMIT 1";
	$res2 = db_mysql_Query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
}
// hangarura

if ($timehangarura2 > 0 && $diftempshangarura2 > 0){
$New_hangarura_lvl = $row['hangarura_lvl'] + 1 ;
if ($row['hangarura_lvl'] =="0") {
$Depense_fer_ressource = "2000";
$Depense_or_ressource = "1000";
$Depense_ada_ressource = "1000";
}
else {
$Depense_fer_ressource = round((1000 * ( bcpow( 2, ($row['hangarura_lvl'] + 1),3))),0);
$Depense_or_ressource = round((500 * ( bcpow( 2, ($row['hangarura_lvl'] + 1),3))),0);
$Depense_ada_ressource = round((500 * ( bcpow( 2, ($row['hangarura_lvl'] + 1),3))),0);
}
$new_pts_bats= $Depense_fer_ressource + $Depense_or_ressource + $Depense_ada_ressource + $row2[pts_bats];
$sql = "UPDATE matgraph_users SET hangarura_lvl=$New_hangarura_lvl, hangarura_evolution = \"0000-00-00 00:00:00\" WHERE id='$planete' LIMIT 1";
$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
$sql2 = "UPDATE matgraph_users SET pts_bats=$new_pts_bats WHERE id='$idlogin' LIMIT 1";
	$res2 = db_mysql_Query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
}
// silo

if ($timesilo2 > 0 && $diftempssilo2 > 0){
$New_silo_lvl = $row['silo_lvl'] + 1 ;
if ($row['silo_lvl'] =="0") {
$Depense_fer_ressource = "20000";
$Depense_or_ressource = "20000";
$Depense_ada_ressource = "1000";
}
else {
$Depense_fer_ressource = round((20000 * ( bcpow( 1.9, ($row['silo_lvl'] + 1),3))),0);
$Depense_or_ressource = round((20000 * ( bcpow( 1.9, ($row['silo_lvl'] + 1),3))),0);
$Depense_ada_ressource = round((1000 * ( bcpow( 1.9, ($row['silo_lvl'] + 1),3))),0);
}
$new_pts_def= $Depense_fer_ressource + $Depense_or_ressource + $Depense_ada_ressource + $row2[pts_def];
$sql = "UPDATE matgraph_users SET silo_lvl=$New_silo_lvl, silo_evolution = \"0000-00-00 00:00:00\" WHERE id='$planete' LIMIT 1";
$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
$sql2 = "UPDATE matgraph_users SET pts_def=$new_pts_def WHERE id='$idlogin' LIMIT 1";
	$res2 = db_mysql_Query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
}
// terri
if ($timeterri2 > 0 && $diftempsterri2 > 0){
$New_terri_lvl = $row[terri_lvl] + 1 ;
if ($row[terri_lvl] =="0") {
$Depense_fer_ressource = "500000";
$Depense_or_ressource = "500000";
}
else {
$Depense_fer_ressource = round((250000 * ( bcpow( 2, ($row[terri_lvl] + 1),3))),0);
$Depense_or_ressource = round((250000 * ( bcpow( 2, ($row[terri_lvl] + 1),3))),0);
}
$newplace = $row[place] + 30 ;
$new_pts_bats= $Depense_fer_ressource + $Depense_or_ressource + $row2[pts_bats];
$sql = "UPDATE matgraph_users SET place= $newplace, terri_lvl=$New_terri_lvl, terri_evolution = \"0000-00-00 00:00:00\" WHERE id='$planete' LIMIT 1";
$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
	$sql2 = "UPDATE matgraph_users SET pts_bats=$new_pts_bats WHERE id='$idlogin' LIMIT 1";
	$res2 = db_mysql_Query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
}

// defense
if ($timedefense2 > 0 && $diftempsdefense2 > 0){
$New_defense_lvl = $row['defense_lvl'] + 1 ;
if ($row['defense_lvl'] =="0") {
$Depense_fer_ressource = "100";
$Depense_or_ressource = "200";
$Depense_ada_ressource = "100";
}
else {
$Depense_fer_ressource = round((100 * ( bcpow( 1.9, ($row['defense_lvl'] + 1),3))),0);
$Depense_or_ressource = round((200 * ( bcpow( 1.9, ($row['defense_lvl'] + 1),3))),0);
$Depense_ada_ressource = round((100 * ( bcpow( 1.9, ($row['defense_lvl'] + 1),3))),0);
}
$new_pts_bats= $Depense_fer_ressource + $Depense_or_ressource +$New_ada_ressource + $row2[pts_bats];
$sql = "UPDATE matgraph_users SET defense_lvl=$New_defense_lvl, defense_evolution = \"0000-00-00 00:00:00\" WHERE id='$planete' LIMIT 1";
$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
$sql2 = "UPDATE matgraph_users SET pts_bats=$new_pts_bats WHERE id='$idlogin' LIMIT 1";
	$res2 = db_mysql_Query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
}

// mili
if ($timemili2 == "-1" && $diftempsmili2 > 0 ){
	if ($row['mili_lvl'] == "0") {
	$new9mili_nbre = 0;
	}else {
	$new9mili_nbre = (/*$row[mili_nbre] + */((2.5 * ( bcpow( 2, $row['mili_lvl'],3)))) * $diftemps / 3600);
	}
}
if ($timemili2 > 0 && $diftempsmili2 <= 0){
	if ($row['mili_lvl'] == "0") {
	$new9mili_nbre = 0;
	}else {
	$new9mili_nbre = (/*$row[mili_nbre] + */((2.5 * ( bcpow( 2,($row['mili_lvl']),3)))) * $diftemps / 3600);
	}
}
if ($timemili2 > 0 && $diftempsmili2 > 0){
	$new9mili_nbre2 = (((2.5 * ( bcpow( 2, ($row['mili_lvl'] + 1),3)))) * $diftempsmili2 / 3600);
	$new9mili_nbre3 = (((2.5 * ( bcpow( 2, $row['mili_lvl'],3)))) * $diftempsmili3 / 3600);
	$new9mili_nbre = /*$row[mili_nbre] +*/ $new9mili_nbre2 + $new9mili_nbre3 ;

	$New_mili_lvl = $row['mili_lvl'] + 1 ;

	if ($row['mili_lvl'] =="0") {
		$Depense_mili_nbre = "500";
		$Depense_or_nbre = "500";
	}else {
		$Depense_mili_nbre = round((250 * ( bcpow( 2, ($row['mili_lvl'] + 1),3))),0);
		$Depense_or_nbre = round((250 * ( bcpow( 2, ($row['mili_lvl'] + 1),3))),0);
	}
	$new_pts_bats= $Depense_mili_nbre + $Depense_or_nbre + $row2[pts_bats];

	$sql = "UPDATE matgraph_users SET mili_lvl=$New_mili_lvl, mili_evolution = \"0000-00-00 00:00:00\" WHERE id='$planete' LIMIT 1";
	$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
	$sql2 = "UPDATE matgraph_users SET pts_bats=$new_pts_bats WHERE id='$idlogin' LIMIT 1";
	$res2 = db_mysql_Query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
}

MAJ_joueur_militaires($row['mili_lvl'],$row['mili_nbre'],$new9mili_nbre,$diftemps);
/*$capacite_soldat = round((10000 * ( bcpow( 2, $row['mili_lvl'],3))),0) + 10000;
if(($new9mili_nbre+$row[mili_nbre]) > $capacite_soldat)
{
	$surplus = ($new9mili_nbre+$row[mili_nbre]) - $capacite_soldat;
	if($surplus < ($diftemps/60))
	{
		$new9mili_nbre = $capacite_soldat;
		if($surplus > 500)
		{
			echo '<script language=javascript> alert ("Vous avez dépassé la capcité de votre caserne militaire, '.$surplus.' soldats sont mort de faim.");</script>';
		}
	}
	else
	{
		//$dead = $surplus;
		//$new9mili_nbre = $capacite_soldat;
		$dead = ($new9mili_nbre/$capacite_soldat)*$diftemps;
		$new9mili_nbre = $new9mili_nbre - $dead;
		if($dead > 300)
		{
			echo '<script language=javascript> alert ("Vous avez dépassé la capcité de votre caserne militaire, '.$dead.' soldats sont mort de faim, Si vous ne faite pas quelque chose,d\'autre mourront également.");</script>';
		}

	}
}*/

//eppz

if ($row['labo_lvl'] < "5") {
$New_eppz = 0 ; }
else {
$New_eppz = (($row['mili_lvl']) * $diftemps / (3600 * 24 *7)); }

if($New_eppz < 0) {
	$New_eppz = 0;
}

$sql = "UPDATE matgraph_users SET eppz= eppz + $New_eppz WHERE id='$planete' LIMIT 1";
$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());

//ressource double mines
$new2fer_ressource = ($new9fer_ressource + $newexfer_ressource);
$new2or_ressource = ($new9or_ressource + $newexor_ressource);
///////////////////
// ressource hangar
// hangarfer
if ($row['hangarfer_lvl'] =="0") {
$hangarfer_lvl = "0";
}
else {
$hangarfer_lvl = $row['hangarfer_lvl'];
}

if ($new2fer_ressource > (100000 *(bcpow(1.5, $row['hangarfer_lvl'],3)))){
$new2fer_ressource = round((100000 *(bcpow(1.5, $row['hangarfer_lvl'],3))),0);
$okk_hangar = "ok";
}
else {
$new2fer_ressource = $new2fer_ressource ;
}
// hangaror
if ($row['hangaror_lvl'] =="0") {
$hangaror_lvl = "0";
}
else {
$hangaror_lvl = $row['hangaror_lvl'];
}

if ($new2or_ressource > (100000 *(bcpow(1.5, $row['hangaror_lvl'],3)))){
$new2or_ressource = round((100000 *(bcpow(1.5, $row['hangaror_lvl'],3))),0);
$okk_hangar = "ok";
}
else {
$new2or_ressource = $new2or_ressource ;
}
// hangarada
if ($row['hangarada_lvl'] == "0") {
$hangarada_lvl = "0";
}
else {
$hangarada_lvl = $row['hangarada_lvl'];
}

if ($newada_ressource > (100000 *(bcpow(1.5, $row['hangarada_lvl'],3)))){
$newwwada_ressource = round((100000 *(bcpow(1.5, $row['hangarada_lvl'],3))),0);
$okk_hangar = "ok";
}
else {
$newwwada_ressource = $newada_ressource ;
}
// hangarura
if ($row['hangarura_lvl'] =="0") {
$hangarura_lvl = "0";
}
else {
$hangarura_lvl = $row['hangarura_lvl'];
}

if ($newura_ressource > (100000 *(bcpow(1.5, $row['hangarura_lvl'],3)))){
$newwwura_ressource = round((100000 *(bcpow(1.5, $row['hangarura_lvl'],3))),0);
$okk_hangar = "ok";
}
else {
$newwwura_ressource = $newura_ressource ;
}
////////////////////
//passage en positif si ressources négatives
if ($new2fer_ressource < 0) {
	$new2fer_ressource = -1*$new2fer_ressource; 
}
if ($new2or_ressource < 0) {
	$new2or_ressource = -1*$new2or_ressource; 
}
if ($newwwada_ressource < 0) {
	$newwwada_ressource = -1*$newwwada_ressource; 
}
if ($newwwura_ressource < 0) {
	$newwwura_ressource = -1*$newwwura_ressource; 
}

//formatage des ressources
$newwfer_ressource = floor($new2fer_ressource) ;
$newwor_ressource = floor($new2or_ressource) ;
$newwada_ressource = floor($newwwada_ressource) ;
$newwura_ressource = floor($newwwura_ressource) ;

$neww3fer_ressource = number_format($new2fer_ressource  , 0, ',', ' ');
$neww3or_ressource = number_format($new2or_ressource , 0, ',', ' ');
$neww3ada_ressource = number_format($newwada_ressource , 0, ',', ' ');
$neww3ura_ressource = number_format($newwura_ressource , 0, ',', ' ');
//

$New_pts = $row2['pts'];

//ressource a ajouté en plus :
$newwfer_ressource_ajout = $new2fer_ressource - $row['fer_ressource'];
$newwor_ressource_ajout = $new2or_ressource - $row['or_ressource'];
$newwada_ressource_ajout = $newwwada_ressource - $row['ada_ressource'];
$newwura_ressource_ajout = $newwwura_ressource - $row['ura_ressource'];


//if ($new2fer_ressource < "1" && $new2or_ressource < "1" ) {
//if(($okk_hangar == "ok") OR ($new2fer_ressource > $row[fer_ressource] && $new2or_ressource > $row[or_ressource])){
$placepris = $row['fer_lvl'] + $row['exfer_lvl'] + $row['or_lvl'] + $row['exor_lvl'] + $row['ada_lvl'] + $row['ura_lvl'] + $row['central_lvl'] + $row['fission_lvl'] + $row['robo_lvl'] + $row['labo_lvl'] + $row['chantier_lvl'] + $row['defense_lvl'] + $row['mili_lvl'] + $row['hangarfer_lvl'] + $row['hangaror_lvl'] + $row['hangarada_lvl'] + $row['hangarura_lvl'] + $row['silo_lvl'] ;
$sql = "UPDATE matgraph_users SET placepris=$placepris, date=now(),fer_ressource=fer_ressource + $newwfer_ressource_ajout, or_ressource=or_ressource + $newwor_ressource_ajout, ada_ressource=ada_ressource + $newwada_ressource_ajout, ura_ressource=ura_ressource + $newwura_ressource_ajout, mili_nbre= mili_nbre + $new9mili_nbre WHERE id='$planete' LIMIT 1";
$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
//}}


$sql9 = "SELECT mili_nbre FROM matgraph_users WHERE id = '$planete'";
$res9 = db_mysql_Query($sql9) or die('Erreur SQL!<br>'.$sql9.'<br>'.mysql_error());
$row9 = mysql_fetch_array($res9); 

if($row9['mili_nbre'] < 0)
{
	$sql = "UPDATE matgraph_users SET mili_nbre = 0 WHERE id='$planete' LIMIT 1";
	$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
}


// Sonde

$sql_sonde = "
SELECT id FROM matgraph_espio_sonde
WHERE idespionneur = $idlogin OR idespionne = $idlogin AND date <= now()";
$res_sonde = db_mysql_Query($sql_sonde)or die('erreur sql<br>'.$sql_sonde.'<br>'.mysql_error());
if( mysql_numrows($res_sonde) > 0 ) {
	$flotte_espio_idlogin = $idlogin;
	include('flotte_espio_calcul.php');
}

include('flotte_ruines_calcul.php');

/*
$sql2 = "SELECT
galaxi,system,position,robo_lvl,chantier_lvl,hangarfer_lvl,hangarfer_evolution,hangaror_lvl,hangaror_evolution,hangarada_lvl,hangarada_evolution,hangaror_lvl,hangarura_lvl,hangarura_evolution,labo_lvl,labo_evolution,fer_energie,or_energie,ada_energie,ura_energie,exfer_energie,exor_energie,central_energie FROM matgraph_users WHERE id='$planete' ";
$res2 = db_mysql_Query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error()) ;
$row2 = mysql_fetch_array($res2) ;


$Total_energie_consom = $row[fer_energie] + $row[or_energie] + $row[exfer_energie] + $row[exor_energie] + $row[ada_energie] + $row[ura_energie] ;
$Total_energie_reste =  round(($New_central_energie + $New_fission_energie + $Total_energie_consom),0) ;
$Total_energie_prod = round(($New_central_energie + $New_fission_energie),0) ;
$Total_energie_reste2 =  number_format(round(($New_central_energie + $New_fission_energie + $Total_energie_consom),0), 0, ',', ' ') ;
$Total_energie_prod2 = number_format(round(($New_central_energie + $New_fission_energie),0), 0, ',', ' ') ;
*/
?>
