<?	
include ('logue.php'); 
include ('entete2.php');
include ('ressource.php');
include ('entete.php');

$sql2 = "SELECT hangarfer_lvl,hangarfer_evolution,hangaror_lvl,hangaror_evolution,hangarada_lvl,hangarada_evolution,hangaror_lvl,hangarura_lvl,hangarura_evolution 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); 

echo"<style>
input {
border:1px solid #7E7E7E;
background-color:#000000;
font-family:'trebuchet ms',sans-serif;
color:white;
}
textarea {
border:1px solid #7E7E7E;
background-color:#000000;
font-family:'trebuchet ms',sans-serif;
color:white;
}
select, option {
background-color:#000000;
color:white;
}
</style>
<STYLE TYPE=text/css>
.Style1 {color: #0000FF}
.Style2 {color: #FF0000}
</STYLE>";
echo"<div align=\"center\"><form name=\"colo\" method=\"post\" action=\"colonie.php\" target=\"_parent\">
<table align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
   <tr>
     <td width=\"100\" rowspan=\"2\" valign=\"middle\">
       <div align=\"center\">
         <input name=\"page\" value=\"" . $PHP_SELF . "\" type=\"hidden\" id=\"page\">
         <select name=\"idcolo\" onchange=submit()>";
include ('colo2.php'); 
$sql = "SELECT fer_lvl,robo_lvl,exfer_lvl FROM matgraph_users WHERE id='$planete'";
$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
$row = mysql_fetch_array($res); 
// fer
if ($row[fer_lvl] =="0") {
$fer_lvl = "0";
}
else {
$fer_lvl = $row[fer_lvl];
}
$fer_lvl22 = $fer_lvl+1;
$fer_lvl23 = $fer_lvl+2;
$fer_lvl24 = $fer_lvl+3;
$fer_lvl25 = $fer_lvl+4;
//conso 
if ($row[fer_lvl] == "0") {
$besoin_fer_energie2 = "0" ; }
else {
$besoin_fer_energie2 = round((30 * (bcpow(1.18, $row[fer_lvl],3))),0);
}
$besoin_fer_energie = 1 * $besoin_fer_energie2 ;
$besoin_fer_energie22 = round((30 * (bcpow(1.18, ($row[fer_lvl] + 1),3))),0);
$besoin_fer_energie23 = round((30 * (bcpow(1.18, ($row[fer_lvl] + 2) ,3))),0);
$besoin_fer_energie24 = round((30 * (bcpow(1.18, ($row[fer_lvl] + 3),3))),0);
$besoin_fer_energie25 = round((30 * (bcpow(1.18, ($row[fer_lvl] + 4),3))),0);
//prod
	if ($row[fer_lvl] == "0") {
	$new9fer_ressource = (20);
	}
	else {
	$new9fer_ressource = round(((100 * ( bcpow( 1.18, $row[fer_lvl],3))) + 20),0);
	}
	$new9fer_ressource22 = round((((100 * ( bcpow( 1.18, ($row[fer_lvl]+1),3))) + 20)),0);
	$new9fer_ressource23 = round((((100 * ( bcpow( 1.18, ($row[fer_lvl]+2),3))) + 20)),0);
	$new9fer_ressource24 = round((((100 * ( bcpow( 1.18, ($row[fer_lvl]+3),3))) + 20)),0);
	$new9fer_ressource25 = round((((100 * ( bcpow( 1.18, ($row[fer_lvl]+4),3))) + 20)),0);


// cout
if ($row[fer_lvl] =="0") {
$besoin2_fer_fer = 60;
$besoin2_fer_or = 15;
}
else {
$besoin2_fer_fer = round((60 * ( bcpow( 1.45, ($row[fer_lvl] + 1),3))),0);
$besoin2_fer_or = round((15 * ( bcpow( 1.45, ($row[fer_lvl] + 1),3))),0);
}
/*
$manque_fer = $newwfer_ressource - $besoin2_fer_fer ;
$manque_or = $newwor_ressource - $besoin2_fer_or ;

if($manque_fer > 0 && $manque_or > 0) {
if($manque_fer > 0) {
	if ($row[fer_lvl] == "0") {
	$temps_fer = $manque_fer / 20 * 3600;
	}
	else {
	$temps_fer = ($manque_fer / (($row[fer_on] * 100 * ( bcpow( 1.18, $row[fer_lvl],3))) + 20)) * 3600;
	}



} */

echo"<table width=\"618\"  border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
  <tr>
    <td colspan=\"4\" style =\"background-color:#222222;\"><div align=\"center\"><b>Mine de Fer </b>(Niveau $fer_lvl)</div></td>
  </tr>
  <tr>
    <td width=\"72\" height=\"120\"><img src=\"imgs/fer.gif\" width=\"120\" height=\"120\"></td>
    <td width=\"1119\" colspan=\"2\">Le fer est la matière première la plus utilisée : elle sert comme principal composant des infrastructures et dans la construction des coques des vaisseaux.La mine de fer demande moins d'énergie que les autres mines et produit pourtant plus de matière première, cependant celle-ci est très importante. Chaque niveau permet de rendre la mine plus profonde et de récupérer de plus en plus de fer, plus abondant en se rapprochant du centre de la planète.
Cependant, la mine de fer devient de moins en moins rentable et surtout a partir du niveau 20 : trop se rapprocher du centre de la planète pourrait causer des problèmes.
Pour les grands empires, des recherches devront être faites pour trouver un autre moyen d'extraction.</td>
  </tr>
</table>
<br>
<table width=\"618\"  border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
  <tr style =\"background-color:#222222;\">
    <td width=\"93\" height=\"21\" align=\"center\">Niveau : </td>
    <td>Consommation d'energie par heure : </td>
    <td>Production par heure : </td>
  </tr>
  <tr style =\"background-color:#000000;\">
    <td width=\"93\" height=\"21\" align=\"center\">$fer_lvl</td>
    <td width=289>$besoin_fer_energie</td>
    <td width=\"210\">$new9fer_ressource</td>
  </tr>
  <tr style =\"background-color:#111111;\">
    <td width=\"93\" height=\"21\" align=\"center\">$fer_lvl22</td>
    <td>$besoin_fer_energie22</td>
    <td width=\"210\">$new9fer_ressource22</td>
  </tr>
  <tr style =\"background-color:#000000;\">
    <td width=\"93\" height=\"21\" align=\"center\">$fer_lvl23</td>
    <td>$besoin_fer_energie23</td>
    <td width=210>$new9fer_ressource23</td>
  </tr>
  <tr style =\"background-color:#111111;\">
    <td width=\"93\" height=\"21\" align=\"center\">$fer_lvl24</td>
    <td>$besoin_fer_energie24</td>
    <td width=\"210\">$new9fer_ressource24</td>
  </tr>
  <tr style =\"background-color:#000000;\">
    <td width=\"93\" height=\"21\" align=\"center\">$fer_lvl25</td>
    <td>$besoin_fer_energie25</td>
    <td width=\"210\">$new9fer_ressource25</td>
  </tr>
</table>";
// robo
if ($row[robo_lvl] =="0") {
$robo_lvl = "0";
}
else {
$robo_lvl = $row[robo_lvl];
}
// exfer
if ($row[exfer_lvl] =="0") {
$exfer_lvl = "0";
}
else {
$exfer_lvl = $row[exfer_lvl];
}
if ($row[fer_lvl] =="0") {
$besoin_fer_fer = number_format((60/3), 0, ',', ' ');
$besoin_fer_or = number_format((15/3), 0, ',', ' ');
}
else {
$besoin_fer_fer = number_format(round(((60/3) * ( bcpow( 1.45, $fer_lvl,3))),0), 0, ',', ' ');
$besoin_fer_or = number_format(round(((15/3) * ( bcpow( 1.45, $fer_lvl,3))),0), 0, ',', ' ');
}
include ('siege.php');
//FER 
$temps1fer = (108/3 * $siege_temps_evolution * (bcpow(1.5, $fer_lvl,3)));
if ($robo_lvl == "0") {
$stimefer = (round($temps1fer));
}
else {
$stimefer = (round($temps1fer*(bcpow(0.9, $robo_lvl,3))));
} 
$etimefer = $stimefer;
$eminfer = $etimefer / 60;

if ( floor($eminfer) != $eminfer )
  $esecfer = floor( ($eminfer - floor( $eminfer )) * 60);

  if ( $eminfer > 60 ) {

    $ehourfer = floor( $eminfer / 60 );
    $eminfer = $eminfer - ( 60 * $ehourfer );

    if ( $ehourfer > 24 ) {
      $edayfer = floor( $ehourfer / 24);
      $ehourfer = $ehourfer - ( 24 * $edayfer );
    }

  }

$etimefer ="";

if (!empty($edayfer) )
  $etimefer.="$edayfer j ";

if (!empty($ehourfer) )
  $etimefer.="$ehourfer h ";

if ($eminfer != 0)
  $etimefer.= floor($eminfer)." min. ";

if (!empty($esecfer) ) 
  $etimefer.="$esecfer sec. ";
  
if($fer_lvl == 20) {
if($exfer_lvl > 0) {
$valid = "no"; }
else {
$valid = "yes"; }}
else {
$valid = "yes"; }
if($fer_lvl > 0 AND $valid == "yes" ) {
echo"<br><table width=\"618\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
  <tr>
    <td style =\"background-color:#222222;\"><div align=\"center\">Destruction de batiment : </div></td>
  </tr>
  <tr>
    <td><div align=\"center\">Gain : Fer : <b>$besoin_fer_fer</b> ; Or : <b>$besoin_fer_or</b> ; Temps : <b>$etimefer</b> </div></td>
  </tr>
  <tr>
    <td style =\"background-color:#111111;\"><div align=\"center\"><a href=\"Destructionfer.php\" target=\"_parent\">Détruire le niveau $fer_lvl</a></div></td>
  </tr>
</table>";	}
?>


