<?php
if(!defined('INDEX')) { header('Location: ../'); exit; }
$page = 'description';
$titre = 'D&eacute;tails';

function tableauProd($ibat,$nivo){
	$temps_ecoule = 3600;
	$return = array();
	$c = $nivo-2 < 1 ? 1 : $nivo-2;
	$a = $c + 6;

	if ($ibat == 0) {
		for ($c; $c < $a; $c++) {
			$b = ((ceil(pow(1.1,$c)*35*$c)/3600)*$temps_ecoule)*1.5;
			$h = (((ceil(pow(1.1,$c)*35*$c)/3600)*$temps_ecoule)*1.5) - (((ceil(pow(1.1,($c-1))*35*($c-1))/3600)*$temps_ecoule)*1.5);

			$p = ceil(exp(0.28*$c)*10);
			$g = ceil(exp(0.28*$c)*10) - ceil(exp(0.28*($c-1))*10);

			if ($c == $nivo) $return[] = array($c, $b, $h, $p, $g, true);
			else $return[] = array($c, $b, $h, $p, $g, false);
		}
	}
	elseif ($ibat == 1) {
		for ($c; $c < $a; $c++) {
			$b = ((ceil(pow(1.1,$c)*23*$c)/3600)*$temps_ecoule)*1.5;
			$h = (((ceil(pow(1.1,$c)*23*$c)/3600)*$temps_ecoule)*1.5) - (((ceil(pow(1.1,($c-1))*23*($c-1))/3600)*$temps_ecoule)*1.5);

			$p = ceil(exp(0.28*$c)*10);
			$g = (ceil(exp(0.28*$c)*10)) - (ceil(exp(0.28*($c-1))*10));

			if ($c == $nivo) $return[] = array($c, $b, $h, $p, $g, true);
			else $return[] = array($c, $b, $h, $p, $g, false);
		}
	}
	elseif ($ibat == 2) {
		for ($c; $c < $a; $c++) {
			$b = (((ceil(pow(1.1,$c)*14*($c+0.7))/3600)*$temps_ecoule))*1.5;
			$h = ((((ceil(pow(1.1,$c)*14*($c+0.7))/3600)*$temps_ecoule))*1.5) - ((((ceil(pow(1.1,($c-1))*14*(($c-1)+0.7))/3600)*$temps_ecoule))*1.5);

			$p = ceil(exp(0.2849*$c)*13);
			$g = (ceil(exp(0.2849*$c)*13)) - (ceil(exp(0.2849*($c-1))*13));

			if ($c == $nivo) $return[] = array($c, $b, $h, $p, $g, true);
			else $return[] = array($c, $b, $h, $p, $g, false);
		}
	}
	elseif ($ibat == 3) {
		for ($c; $c < $a; $c++) {
			$b = ceil(exp(0.297*$c)*25);
			$h = ceil(exp(0.297*$c)*25) - ceil(exp(0.297*($c-1))*25);

			if ($c == $nivo) $return[] = array($c, $b, $h, 0, 0, true);
			else $return[] = array($c, $b, $h, 0, 0, false);
		}
	}
	elseif ($ibat == 4) {
		for ($c; $c < $a; $c++) {
			$b = ceil(exp(0.28*$c)*22);
			$h = ceil(exp(0.28*$c)*22) - ceil(exp(0.28*($c-1))*22);

			$p = ((ceil(pow(1.34,($c-1))*9)/3600)*$temps_ecoule);
			$g = ((ceil(pow(1.34,($c-1))*9)/3600)*$temps_ecoule) - ((ceil(pow(1.34,($c-2))*9)/3600)*$temps_ecoule);

			if ($c == $nivo) $return[] = array($c, $b, $h, $p, $g, true);
			else $return[] = array($c, $b, $h, $p, $g, false);
		}
	}
	else $return = '';

	if ($return == '') return false;
	else return $return;
}

if (empty($_GET['r']) || ($_GET['r'] != 'humain' && $_GET['r'] != 'covenant')) $_GET['r'] = $planete->race;
$race = $_GET['r'];
if ($race != $planete->race) include(_FCORE."../game/noms.php");
$template->assign('raceAff', $race);

if (isset($_GET['b']) && is_numeric($_GET['b']) && $_GET['b'] < count($batiment)) {
	$template->assign('type', 'batiments');
	$t = $_GET['b'];
	$template->assign('t', $t);
	$template->assign('image', $batimeni[$t]);
	$template->assign('nom', $batiment[$t]);
	$template->assign('niveau', $planete->batiments[$t]);
	$template->assign('description', $batimede[$t]);
	$template->assign('tableau_prod', tableauProd($t, $planete->batiments[$t]));

	$n = $planete->batiments[$t] + 1;
	$a = 0; $b = 0; $c = 0; $sec = 0;
	eval($batimentCALC[$t][0]);
	eval($batimentCALC[$t][1]);
	eval($batimentCALC[$t][2]);
	eval($batimentCALC[$t][3]);
	$template->assign('ressourcesNext', array(separerNombres($a), separerNombres($b), separerNombres($c), sec($sec)));

	$template->assign('etat', readDeblok($batimentTECH[$t], $planete));
}
elseif (isset($_GET['t']) && is_numeric($_GET['t']) && $_GET['t'] < count($technolo)) {
	$template->assign('type', 'technologies');
	$t = $_GET['t'];
	$template->assign('image', $technoli[$t]);
	$template->assign('nom', $technolo[$t]);
	$template->assign('niveau', $planete->technologies[$t]);
	$template->assign('description', $technode[$t]);

	$n = $planete->technologies[$t] + 1;
	$a = 0; $b = 0; $c = 0; $sec = 0;
	eval($technoloCALC[$t][0]);
	eval($technoloCALC[$t][1]);
	eval($technoloCALC[$t][2]);
	eval($technoloCALC[$t][3]);
	$template->assign('ressourcesNext', array(separerNombres($a), separerNombres($b), separerNombres($c), sec($sec)));

	$template->assign('etat', readDeblok($technoloTECH[$t], $planete));
}
elseif (isset($_GET['v']) && is_numeric($_GET['v']) && $_GET['v'] < count($nomvaisn)) {
	$template->assign('type', 'vaisseaux');
	$t = $_GET['v'];
	$template->assign('image', $nomvaisi[$t]);
	$template->assign('nom', $nomvaisn[$t]);
	$template->assign('niveau', $planete->vaisseaux[$t]);
	$template->assign('description', $nomvaisd[$t]);

	$n = $planete->vaisseaux[$t] + 1;
	$a = $nomvaisnCALC[$t][0]; $b = $nomvaisnCALC[$t][1]; $c = $nomvaisnCALC[$t][2]; $sec = 0;
	eval($nomvaisnCALC[$t][3]);
	$template->assign('ressourcesNext', array(separerNombres($a), separerNombres($b), separerNombres($c), sec($sec)));

	$template->assign('etat', readDeblok($nomvaisnTECH[$t], $planete));
	$template->assign('caract', array($nomvais_at[$t], $nomvais_bc[$t], $nomvais_pv[$t], $nomvais_rs[$t]));
}
elseif (isset($_GET['d']) && is_numeric($_GET['d']) && $_GET['d'] < count($nomterrn)) {
	$template->assign('type', 'terrestre');
	$t = $_GET['d'];
	$template->assign('image', $nomterri[$t]);
	$template->assign('nom', $nomterrn[$t]);
	$template->assign('niveau', $planete->terrestres[$t]);
	$template->assign('description', $nomterde[$t]);

	$n = $planete->terrestres[$t] + 1;
	$a = $nomterrnCALC[$t][0]; $b = $nomterrnCALC[$t][1]; $c = $nomterrnCALC[$t][2]; $sec = 0;
	eval($nomterrnCALC[$t][3]);
	$template->assign('ressourcesNext', array(separerNombres($a), separerNombres($b), separerNombres($c), sec($sec)));

	$template->assign('etat', readDeblok($nomterrnTECH[$t], $planete));
	if ($t-8 >= 0) {
		$t -= 8;
		$template->assign('caract', array($defense_at[$t], $defense_bc[$t], $defense_pv[$t]));
	}
}
elseif (isset($_GET['c']) && is_numeric($_GET['c']) && $_GET['c'] < count($casernen)) {
	$template->assign('type', 'caserne');
	$t = $_GET['c'];
	$template->assign('image', $casernei[$t]);
	$template->assign('nom', $casernen[$t]);
	$template->assign('niveau', $planete->casernes[$t]);
	$template->assign('description', $casernde[$t]);

	$n = $planete->casernes[$t] + 1;
	$a = $casernenCALC[$t][0]; $b = $casernenCALC[$t][1]; $c = $casernenCALC[$t][2]; $sec = 0;
	eval($casernenCALC[$t][3]);
	$template->assign('ressourcesNext', array(separerNombres($a), separerNombres($b), separerNombres($c), sec($sec)));

	$template->assign('etat', readDeblok($casernenTECH[$t], $planete));
	if ($t-8 >= 0) {
		$t -= 8;
		$template->assign('caract', array('!!', '!!', '!!'));
	}
}
else {
	header('Location: ?p=accueil');
}
?>