HB/pages/includes/ressources.php

216 lines
8.4 KiB
PHP
Raw Blame History

<?php
$id=$_SESSION['id'];
$g=$_SESSION['galaxy'];
$s=$_SESSION['ss'];
$p=$_SESSION['pos'];
$race=$_SESSION['race'];
require_once('../fonctions.php');
require('../connectBDD.php');
require_once 'noms.php';
$appel = mysql_query("SELECT * FROM planete WHERE id_user='$id' AND galaxie='$g' AND ss='$s'AND position='$p' ");
$ressource=mysql_fetch_array($appel);
$mine_m = $ressource['mine_m'];
$coeff_mine_m = $ressource['coeff_mine_m'];
if ($coeff_mine_m < 0) $coeff_mine_m = 0;
if ($coeff_mine_m > 1) $coeff_mine_m = 1;
$mine_c = $ressource['mine_c'];
$coeff_mine_c = $ressource['coeff_mine_c'];
if ($coeff_mine_c < 0) $coeff_mine_c = 0;
if ($coeff_mine_c > 1) $coeff_mine_c = 1;
$mine_h = $ressource['mine_h'];
$coeff_mine_h = $ressource['coeff_mine_h'];
if ($coeff_mine_h < 0) $coeff_mine_h = 0;
if ($coeff_mine_h > 1) $coeff_mine_h = 1;
$centrale_s = $ressource['centrale_s'];
$coeff_centrale_s = $ressource['coeff_centrale_s'];
if ($coeff_centrale_s < 0) $coeff_centrale_s = 0;
if ($coeff_centrale_s > 1) $coeff_centrale_s = 1;
$centrale_f = $ressource['centrale_f'];
$coeff_centrale_f = $ressource['coeff_centrale_f'];
$coeff_energie_f = $ressource['coeff_centrale_f'];
if ($coeff_centrale_f < 0) $coeff_centrale_f = 0;
if ($coeff_centrale_f > 1) $coeff_centrale_f = 1;
if ($coeff_energie_f < 0) $coeff_energie_f = 0;
if ($coeff_energie_f > 1) $coeff_energie_f = 1;
$temps_actuel = time();
$temps_ancien = $ressource['timestamp'];
$temps_ecoule = $temps_actuel - $temps_ancien;
$cap = (pow(2,$ressource['silo'])*100000);
$metal = $ressource['metal'];
$cristal = $ressource['cristal'];
$hydrogene = $ressource['hydrogene'];
$conso_h = 0;
//---------------Productions--------
if ($mine_m > 0) $energie_m = ceil(exp(0.28*$mine_m)*10); else $energie_m= 0;
if ($mine_c > 0) $energie_c = ceil(exp(0.28*$mine_c)*10); else $energie_c= 0;
if ($mine_h > 0) $energie_h = ceil(exp(0.2849*$mine_h)*13); else $energie_h= 0;
if ($centrale_f > 0) $energie_f = ceil(exp(0.297*$centrale_f)*25); else $energie_f = 0;
if ($centrale_s > 0) $energie_s = ceil(exp(0.28*$centrale_s)*22); else $energie_s = 0;
//Calcul de la consomation d'<27>nergie
$nrj = $energie_m + $energie_c + $energie_h;
//Calcul de la production d'<27>nergie
$t = $energie_s * $coeff_centrale_s + $energie_f * $coeff_centrale_f;
if ($nrj == 0) $coeff = 0;
else $coeff = $t / $nrj;
if ($coeff < 0) $coeff = 0;
elseif ($coeff == 0) $coeff = 0;
elseif ($coeff > 1) $coeff = 1;
//Calcul des proportions
$point = $coeff * 3;
if ($coeff_mine_m + $coeff_mine_c + $coeff_mine_h != 0) {
$p_mine_m = $coeff_mine_m / ($coeff_mine_m + $coeff_mine_c + $coeff_mine_h);
$p_mine_c = $coeff_mine_c / ($coeff_mine_m + $coeff_mine_c + $coeff_mine_h);
$p_mine_h = $coeff_mine_h / ($coeff_mine_m + $coeff_mine_c + $coeff_mine_h);
}
else {
$p_mine_m = 0.33333333;
$p_mine_c = 0.33333333;
$p_mine_h = 0.33333333;
}
$Ncoeff_mine_m = $point * $p_mine_m;
$Ncoeff_mine_c = $point * $p_mine_c;
$Ncoeff_mine_h = $point * $p_mine_h;
if ($Ncoeff_mine_m > 1) $Ncoeff_mine_m = 1;
if ($Ncoeff_mine_c > 1) $Ncoeff_mine_c = 1;
if ($Ncoeff_mine_h > 1) $Ncoeff_mine_h = 1;
//if ($Ncoeff_mine_m < $coeff_mine_m) {
mysql_query("UPDATE planete SET coeff_mine_m='$Ncoeff_mine_m' WHERE id_user='$id' AND galaxie='$g' AND ss='$s'AND position='$p'");
$coeff_mine_m = $Ncoeff_mine_m;
//}
//if ($Ncoeff_mine_c < $coeff_mine_c) {
mysql_query("UPDATE planete SET coeff_mine_c='$Ncoeff_mine_c' WHERE id_user='$id' AND galaxie='$g' AND ss='$s'AND position='$p'");
$coeff_mine_c = $Ncoeff_mine_c;
//}
//if ($Ncoeff_mine_h < $coeff_mine_h) {
mysql_query("UPDATE planete SET coeff_mine_h='$Ncoeff_mine_h' WHERE id_user='$id' AND galaxie='$g' AND ss='$s'AND position='$p'");
$coeff_mine_h = $Ncoeff_mine_h;
//}
$alert_metal = false;
if ($metal >= $cap) {
$prod_met=0;
$metal = $cap;
$alert_metal = true;
}
else {
if ($mine_m < 0) $prod_met = 0.011*$temps_ecoule;
else $prod_met = ((ceil(pow(1.1,$mine_m)*35*$mine_m)/3600)*$temps_ecoule)*$coeff_mine_m;
}
$alert_cristal = false;
if ($cristal >= $cap) {
$prod_cri=0;
$cristal = $cap;
$alert_cristal = true;
}
else {
if ($mine_c < 0) $prod_cri = 0.0055*$temps_ecoule;
else $prod_cri = ((ceil(pow(1.1,$mine_c)*23*$mine_c)/3600)*$temps_ecoule)*$coeff_mine_c;
}
$alert_hydrogene = false;
if ($hydrogene >= $cap) {
$prod_hy=0;
$hydrogene = $cap;
$alert_hydrogene = true;
}
else {
if ($mine_h < 0) $prod_hy = 0;
else $prod_hy = (((ceil(pow(1.1,$mine_h)*14*($mine_h+0.7))/3600)*$temps_ecoule) - $conso_h) * $coeff_mine_h;
if ($mine_h == 0) $prod_hy=0;
if ($prod_hy < 0) $prod_hy = 0;
}
if ($centrale_f > 0) $conso_h = ((ceil(pow(1.34,($centrale_f-1))*9)/3600)*$temps_ecoule) * $coeff_energie_f;
else $conso_h = 0;
$prod_mineh = $prod_hy;
$prod_hysv = $prod_hy;
$prod_hy -= $conso_h;
if ($hydrogene+$prod_hy < 0) {
$prod_hy = $prod_hysv;
$conso_h = 0;
$coeff_energie_f = 0;
}
elseif (ceil(pow(1.34,($centrale_f-1))*9) <= $hydrogene/5 && $coeff_energie_f == 0) {
$coeff_energie_f = 1;
}
$a=$metal+$prod_met;
$b=$cristal+$prod_cri;
$c=$hydrogene+$prod_hy;
$u = ($energie_s*$coeff_energie_s+$energie_f*$coeff_energie_f);
//---------------M.A.J--------------
mysql_query("UPDATE planete SET timestamp='$temps_actuel', metal='$a', cristal='$b', hydrogene='$c', coeff='$coeff', energie='$t', coeff_centrale_f='$coeff_energie_f' WHERE id_user='$id' AND galaxie='$g' AND ss='$s'AND position='$p'");
$req = mysql_query("SELECT id, galaxie, ss, position, nom_planete FROM planete WHERE id_user='$id'");
$reqIsol = mysql_query("SELECT id FROM planete WHERE id_user='$id' AND isolement != '0'");
$RES_IMAGE = $image;
$Aplan_ref = ''; $Aplan_value = ''; $Aplan_img = ''; $Aplan_more = ''; $Aplan_nom = '';
for ($i=0; $i < mysql_num_rows($req); $i++) {
$x = mysql_query("SELECT * FROM planete WHERE id_user='$id' ORDER BY id DESC LIMIT $i,1");
$d = mysql_fetch_array($x);
if ($d['isolement'] != 0 && $d['isolement']+(mysql_num_rows($req)-10)*7200 <= time()) {
$Aplan_value .= $d['id'].' ';
$Aplan_img .= $d['image'].' ';
if ($d['galaxie'] == $_SESSION['galaxy'] && $d['ss'] == $_SESSION['ss'] && $d['position'] == $_SESSION['pos']) $Aplan_more .= ' selected="selected";';
else $Aplan_more .= ';';
$Aplan_ref .= '['.$d['galaxie'].':'.$d['ss'].':'.$d['position'].'];';
$Aplan_nom .= $d['nom_planete'].'|';
$nextIsol = $d['isolement'] + (mysql_num_rows($req)-10)*7200 + rand(83000,170000);
mysql_query("UPDATE planete SET isolement='$nextIsol' WHERE id_user='$id' AND galaxie='".$d['galaxie']."' AND ss='".$d['ss']."'AND position='".$d['position']."'");
}
elseif ($d['isolement']+(mysql_num_rows($req)-10)*7200 < time() || $d['isolement'] == 0) {
$Aplan_value .= $d['id'].' ';
$Aplan_img .= $d['image'].' ';
if ($d['galaxie'] == $_SESSION['galaxy'] && $d['ss'] == $_SESSION['ss'] && $d['position'] == $_SESSION['pos']) $Aplan_more .= ' selected="selected";';
else $Aplan_more .= ';';
$Aplan_ref .= '['.$d['galaxie'].':'.$d['ss'].':'.$d['position'].'];';
$Aplan_nom .= $d['nom_planete'].'|';
}
elseif ($d['galaxie'] == $_SESSION['galaxy'] && $d['ss'] == $_SESSION['ss'] && $d['position'] == $_SESSION['pos']) {
$time = time();
mysql_query("UPDATE planete SET isolement='$time' WHERE id_user='$id' AND galaxie='".$d['galaxie']."' AND ss='".$d['ss']."'AND position='".$d['position']."'");
}
}
$Aplan_value = split(' ',trim($Aplan_value));
$Aplan_img = split(' ',trim($Aplan_img));
$Aplan_more = split(';',trim($Aplan_more));
$Aplan_nom = explode('|',trim($Aplan_nom));
$Aplan_ref = split(';',trim($Aplan_ref));
$NOM_METAL = $ressourc[0];
$NOM_CRISTAL = $ressourc[1];
$NOM_HYDROGENE = $ressourc[2];
$NOM_ENERGIE = $ressourc[3];
if ($alert_metal) $RES_METAL = '<span style="color: #FF0000; text-decoration: blink; border: none; float: none; display: inline; margin: auto;">'.separerNombres(floor($a)).'</span>';
else $RES_METAL = separerNombres(floor($a));
if ($alert_cristal) $RES_CRISTAL = '<span style="color: #FF0000; text-decoration: blink; border: none; float: none; display: inline; margin: auto;">'.separerNombres(floor($b)).'</span>';
else $RES_CRISTAL = separerNombres(floor($b));
if ($alert_hydrogene) $RES_HYDROGENE = '<span style="color: #FF0000; text-decoration: blink; border: none; float: none; display: inline; margin: auto;">'.separerNombres(floor($c)).'</span>';
else $RES_HYDROGENE = separerNombres(floor($c));
// $RES_ENERGIE = separerNombres(intval($t-$nrj)).'/'.separerNombres($t);
$RES_ENERGIE = separerNombres(intval($nrj)).'/'.separerNombres($u);
mysql_close();
?>