Version 1.9g

This commit is contained in:
nemunaire 2008-11-08 12:00:00 +01:00
commit 4c9814a99c
800 changed files with 237325 additions and 1949 deletions

View file

@ -23,8 +23,13 @@ class Planete extends User{
$metal,
$cristal,
$hydrogene,
$population,
$alert_ressources = array(false, false, false),
$timestamp,
$timestamp_lastSilo,
$timestamp_lastMineM,
$timestamp_lastMineC,
$timestamp_lastMineH,
$energie,
$energieConso,
$file_tech,
@ -61,7 +66,8 @@ class Planete extends User{
$this->galaxie = $plan["galaxie"];
$this->ss = $plan["ss"];
$this->position = $plan["position"];
$this->isolement = $plan["isolement"];
if (!empty($plan["isolement"])) $this->isolement = unserialize($plan["isolement"]);
else $this->isolement = array();
$this->nom_planete = $plan["nom_planete"];
$this->image = $plan["image"];
$this->cases = $plan["cases"];
@ -70,31 +76,38 @@ class Planete extends User{
$this->metal = $plan["metal"];
$this->cristal = $plan["cristal"];
$this->hydrogene = $plan["hydrogene"];
$this->population = $plan["population"];
$this->timestamp = $plan["timestamp"];
foreach($batimentVAR as $bat){
$this->batiments[] = $plan[$bat];
}
$this->file_bat = explode(';', $plan["file_bat"]);
if (!empty($plan["file_bat"])) $this->file_bat = unserialize($plan["file_bat"]);
else $this->file_bat = array();
$this->coeff_bat = array($plan["coeff_mine_m"], $plan["coeff_mine_c"], $plan["coeff_mine_h"], $plan["coeff_centrale_s"], $plan["coeff_centrale_f"]);
for($i = 0; $i < 5; $i++){
if ($this->coeff_bat[$i] > 1) $this->coeff_bat[$i] = 1;
elseif ($this->coeff_bat[$i] < 0) $this->coeff_bat[$i] = 0;
}
$this->file_tech = explode(';', $plan["file_tech"]);
if (!empty($plan["file_tech"])) $this->file_tech = unserialize($plan["file_tech"]);
else $this->file_tech = array();
foreach($casernenVAR as $cas){
$this->casernes[] = $plan[$cas];
}
$this->file_cas = explode(';', $plan["file_cas"]);
if (!empty($plan["file_cas"])) $this->file_cas = unserialize($plan["file_cas"]);
else $this->file_cas = array();
foreach($nomterrnVAR as $ter){
$this->terrestres[] = $plan[$ter];
}
$this->file_ter = explode(';', $plan["file_ter"]);
if (!empty($plan["file_ter"])) $this->file_ter = unserialize($plan["file_ter"]);
else $this->file_ter = array();
foreach($nomvaisnVAR as $vais){
$this->vaisseaux[] = $plan[$vais];
}
$this->file_vais = explode(';', $plan["file_vais"]);
if (!empty($plan["file_vais"])) $this->file_vais = unserialize($plan["file_vais"]);
else $this->file_vais = array();
$this->actualiser();
}
@ -108,29 +121,6 @@ class Planete extends User{
* @access public
*/
function actualiser($actuFile = true){
//Calcul de la capacité de stockage maximale
$cap = pow(2, $this->batiments[10]) * 100000;
//Calcul du temps écoulé depuis la dernière mise à jour de la planète
$temps_ecoule = time() - $this->timestamp;
$ressources = $this->production($temps_ecoule);
if ($this->metal + $ressources[0] < $cap) $this->metal += $ressources[0];
else {
$this->alert_ressources[0] = true;
$this->metal = $cap;
}
if ($this->cristal + $ressources[1] < $cap) $this->cristal += $ressources[1];
else {
$this->alert_ressources[1] = true;
$this->cristal = $cap;
}
if ($this->hydrogene + $ressources[2] < $cap) $this->hydrogene += $ressources[2];
else {
$this->alert_ressources[2] = true;
$this->hydrogene = $cap;
}
$this->timestamp = time();
//Actualisation des files d'attentes
if ($actuFile) {
$this->file_pret("batiments");
@ -140,6 +130,65 @@ class Planete extends User{
$this->file_pret("vaisseaux");
}
//Calcul de la capacité de stockage maximale
if (!empty($timestamp_lastSilo)) {
$cap = pow(2, $this->batiments[10]-1) * 100000;
$capnouv = pow(2, $this->batiments[10]) * 100000;
}
else $cap = pow(2, $this->batiments[10]) * 100000;
//Calcul du temps écoulé depuis la dernière mise à jour de la planète
$temps_ecoule = time() - $this->timestamp;
$ressources = $this->production($temps_ecoule);
if ($this->metal + $ressources[0] < $cap) $this->metal += $ressources[0];
else {
//Si les capacité de stockage ont changé depuis la dernière actualisation
if (isset($capnouv)) {
$ressources = $this->production(time() - $this->timestamp_lastSilo);
if ($this->metal + $ressources[0] < $capnouv) $this->metal += $ressources[0];
}
else {
$this->alert_ressources[0] = true;
$this->metal = $cap;
}
}
if ($this->cristal + $ressources[1] < $cap) $this->cristal += $ressources[1];
else {
//Si les capacité de stockage ont changé depuis la dernière actualisation
if (isset($capnouv)) {
$ressources = $this->production(time() - $this->timestamp_lastSilo);
if ($this->cristal + $ressources[1] < $capnouv) $this->cristal += $ressources[1];
}
else {
$this->alert_ressources[1] = true;
$this->cristal = $cap;
}
}
if ($this->hydrogene + $ressources[2] < $cap) $this->hydrogene += $ressources[2];
else {
//Si les capacité de stockage ont changé depuis la dernière actualisation
if (isset($capnouv)) {
$ressources = $this->production(time() - $this->timestamp_lastSilo);
if ($this->hydrogene + $ressources[2] < $capnouv) $this->hydrogene += $ressources[2];
}
else {
$this->alert_ressources[2] = true;
$this->hydrogene = $cap;
}
}
if (date('zya') != date('zya', $this->timestamp)) {
//Si la population est à 0, on ajoute des habitants
if ($this->population <= 0) $this->population = 1000;
$this->population = $this->population * 1.0153^max(1, floor((time()-$this->timestamp)/86400));
$this->credits += $this->population/100*exp(0.01)*25;
$this->modif[] = 'population';
}
$this->timestamp = time();
//Calcul du nombre de cases restantes
$this->casesRest = $this->cases;
foreach($this->batiments as $bat){
@ -154,7 +203,6 @@ class Planete extends User{
* @access public
*/
function isolement(){
$isolement = explode(' ', $this->isolement);
$return = false;
if (time() > $isolement[0]) {
@ -191,7 +239,11 @@ class Planete extends User{
}
}
$this->isolement = implode(' ', $isolement);
//On applique les bonus politiques aux productions
if (isset($this->politique) && $this->politique == 1) {
$sec *= 0.9;
}
if (!in_array('isolement', $this->modif)) $this->modif[] = 'isolement';
return $return;
}
@ -205,7 +257,7 @@ class Planete extends User{
*/
function production($temps_ecoule, $retarray = false){
//Accélération de la production
$temps_ecoule *= 10;
$temps_ecoule *= VITESSE;
//Calcul de la consomation d'énergie
if ($this->batiments[0] > 0) $energie_m = ceil(exp(0.28*$this->batiments[0])*10); else $energie_m = 0;
@ -231,7 +283,7 @@ class Planete extends User{
for($i = 0; $i < 3; $i++){
$Ncoeff[$i] = $coeff * $this->coeff_bat[$i];
if ($Ncoeff[$i] > 1) $Ncoeff[$i] = 1;
if ($Ncoeff[$i] < $this->coeff_bat[$i]) {
if ($Ncoeff[$i] < $this->coeff_bat[$i] && $this->batiments[$i] != 0) {
$this->coeff_bat[$i] = $Ncoeff[$i];
if (!in_array('coeff_bat', $this->modif)) $this->modif[] = 'coeff_bat';
}
@ -251,207 +303,34 @@ class Planete extends User{
if ($this->batiments[2] <= 0) $prod_hy = 0;
else $prod_hy = ((ceil(pow(1.1, $this->batiments[2]) * 14 * ($this->batiments[2] + 0.7)) / 3600) * $temps_ecoule) * $this->coeff_bat[2] * 1.5 - $conso_h;
//Augmentation de la production en fonction des technologies
if ($this->technologies[0] & 4) {
$prod_met *= 1.15;
$prod_cri *= 1.15;
$prod_hy *= 1.15;
}
elseif ($this->technologies[0] & 2) {
$prod_met *= 1.10;
$prod_cri *= 1.10;
$prod_hy *= 1.10;
}
elseif ($this->technologies[0] & 1) {
$prod_met *= 1.05;
$prod_cri *= 1.05;
$prod_hy *= 1.05;
}
//Augmentation de la production en fonction de la politique
if ($this->politique == 2) {
$prod_met *= 1.10;
$prod_cri *= 1.10;
$prod_hy *= 1.10;
}
if ($retarray) return array(array(ceil($this->coeff_bat[0]*100), ceil($this->coeff_bat[1]*100), ceil($this->coeff_bat[2]*100), ceil($this->coeff_bat[3]*100), ceil($this->coeff_bat[4]*100)), array($prod_met, $prod_cri, $prod_hy + $conso_h, $energie_s*$this->coeff_bat[3], $energie_f*$this->coeff_bat[4]), array($energie_m*$this->coeff_bat[0], $energie_c*$this->coeff_bat[1], $energie_h*$this->coeff_bat[2], $conso_h, ($energie_s*$this->coeff_bat[3] + $energie_f*$this->coeff_bat[4])-($energie_m*$this->coeff_bat[0] + $energie_c*$this->coeff_bat[1] + $energie_h*$this->coeff_bat[2])));
else return array($prod_met, $prod_cri, $prod_hy);
}
/**
* Calcul les ressources produites en fonction de $temps_ecoule
* @param int $file Nom de la file d'attente
* @param int $objet Id de l'objet à ajouter
* @param int $nombre = 1 Nombre d'objet $objet à ajouter à la file
*
* @return int Numéro de l'erreur
* @access public
*/
function file_addObjet($file, $objet, $nombre = 1){
$planete = $this;
switch($file){
case "batiments": $court = "bat"; $calc = "batiment"; $exist = $this->file_exist($objet, "file_".$court); break;
case "technologies": $court = "tech"; $calc = "technolo"; $exist = $this->file_exist($objet, "file_".$court); break;
case "casernes": $court = "cas"; $calc = "casernen"; $exist = false; break;
case "terrestres": $court = "ter"; $calc = "nomterrn"; $exist = false; break;
case "vaisseaux": $court = "vais"; $calc = "nomvaisn"; $exist = false; break;
default: return 1;
}
global ${$calc}, ${$calc.'CALC'}, ${$calc.'TECH'};
//Vérification des conditions de construction
if (empty(${$calc}[$objet]) || !requestDeblok(${$calc.'TECH'}[$objet], $this)) return 1;
//Vérification qu'il n'y ait pas déjà une instance de l'objet déjà en construction
if ($exist) return 2;
//Actualisation du temps s'il n'y a pas d'objet en file
if (count($this->{"file_".$court}) < 2) $this->{"file_".$court}[0] = time();
//Calcul du prochain niveau de l'objet
$n = $this->{$file}[$objet] + 1;
if ($file == "batiments" || $file == "technologies") {
eval(${$calc.'CALC'}[$objet][0]);
eval(${$calc.'CALC'}[$objet][1]);
eval(${$calc.'CALC'}[$objet][2]);
}
else {
$a = ${$calc.'CALC'}[$objet][0];
$b = ${$calc.'CALC'}[$objet][1];
$c = ${$calc.'CALC'}[$objet][2];
}
//Vérification des ressources de la planète
if ($this->metal < $a * $nombre) return 3;
elseif ($this->cristal < $b * $nombre) return 3;
elseif ($this->hydrogene < $c * $nombre) return 3;
else {
//Mise à jour des ressources de la planète en conséquence à la construction
$this->metal -= $a * $nombre;
$this->cristal -= $b * $nombre;
$this->hydrogene -= $c * $nombre;
//Génération de la file d'attente
$nb = count($this->{"file_".$court});
//Si le dernier objet est identique à celui que l'on veut construire
if (ereg($objet.',', $this->{"file_".$court}[$nb-1])) {
$last = explode(',', $this->{"file_".$court}[$nb-1]);
$last[1] += $nombre;
$this->{"file_".$court}[$nb-1] = implode(',', $last);
}
else $this->{"file_".$court}[] = $objet.','.$nombre;
if (!in_array("file_".$court, $this->modif)) $this->modif[] = "file_".$court;
return 0;
}
}
function file_delObjet($file, $objet, $nombre = 1, $w = 99) {
$planete = $this;
switch($file){
case "batiments": $court = "bat"; $calc = "batiment"; $exist = $this->file_exist($objet, "file_".$court); break;
case "technologies": $court = "tech"; $calc = "technolo"; $exist = $this->file_exist($objet, "file_".$court); break;
case "casernes": $court = "cas"; $calc = "casernen"; $exist = $this->file_exist($objet, "file_".$court); break;
case "terrestres": $court = "ter"; $calc = "nomterrn"; $exist = $this->file_exist($objet, "file_".$court); break;
case "vaisseaux": $court = "vais"; $calc = "nomvaisn"; $exist = $this->file_exist($objet, "file_".$court); break;
default: return false;
}
global ${$calc}, ${$calc.'CALC'};
//Si l'objet n'est pas dans la file d'attente, on annule la suite
if (!$exist) return 0;
if ($w == 99) $w = count($this->{"file_".$court})-1;
for($i = $w; $i > 0; $i--) {
$last = explode(',', $this->{"file_".$court}[$i]);
if($last[0] == $objet){
$nombre = min($nombre, $last[1]);
if($last[1] <= $nombre) {
unset($this->{"file_".$court}[$i]);
$this->{"file_".$court} = array_merge($this->{"file_".$court});
}
else $this->{"file_".$court}[$i] = $objet.','.($last[1]-$nombre);
if ($i == 1) $this->{"file_".$court}[0] = time();
break;
}
}
if (!in_array("file_".$court, $this->modif)) $this->modif[] = "file_".$court;
//Calcul du prochain niveau de l'objet
$n = $this->{$file}[$objet] + 1;
if ($file == "batiments" || $file == "technologies") {
eval(${$calc.'CALC'}[$objet][0]);
eval(${$calc.'CALC'}[$objet][1]);
eval(${$calc.'CALC'}[$objet][2]);
}
else {
$a = ${$calc.'CALC'}[$objet][0];
$b = ${$calc.'CALC'}[$objet][1];
$c = ${$calc.'CALC'}[$objet][2];
}
//Mise à jour des ressources de la planète en conséquence à la construction
$this->metal += $a * $nombre;
$this->cristal += $b * $nombre;
$this->hydrogene += $c * $nombre;
return $nombre;
}
/**
* Vérifie l'existance dans la file $file d'attente de $i
* @param int $i ID à vérifier
* @param string $file Nom de la file d'attente
*
* @return boolean
* @access public
*/
function file_exist($objet, $file){
if (count($this->$file) <= 1) return false;
foreach($this->$file as $bout){
$bout = explode(',', $bout);
if($objet == $bout[0]) return true;
}
return false;
}
/**
* Actualise la file $file en terminant les constructions/entraînements.
* @param string $file Nom de la file d'attente
*
* @return boolean
* @access public
*/
function file_pret($file){
$nanite = 0;
$planete = $this;
switch($file){
case "batiments": $court = "bat"; $calc = "batiment"; break;
case "technologies": $court = "tech"; $calc = "technolo"; break;
case "casernes": $court = "cas"; $calc = "casernen"; break;
case "terrestres": $court = "ter"; $calc = "nomterrn"; break;
case "vaisseaux": $court = "vais"; $calc = "nomvaisn"; break;
default: return false;
}
global ${$calc}, ${$calc.'CALC'};
$nb = count($this->{"file_".$court});
for($i = 1; $i < $nb; $i++){
$obj = explode(',', $this->{"file_".$court}[$i]);
$n = $this->{$file}[$obj[0]] + 1;
eval(${$calc.'CALC'}[$obj[0]][3]);
$tps = time() - $this->{"file_".$court}[0];
//Accélération du temps de construction
$sec /= 10;
if ($sec * $obj[1] < $tps) {
$this->{$file}[$obj[0]] += $obj[1];
unset($this->{"file_".$court}[$i]);
$this->{"file_".$court} = array_merge($this->{"file_".$court});
$this->{"file_".$court}[0] += $obj[1] * $sec;
if (!in_array($file, $this->modif)) $this->modif[] = $file;
if (!in_array("file_".$court, $this->modif)) $this->modif[] = "file_".$court;
}
elseif ($sec < time() - $this->{"file_".$court}[0]) {
for($j=0 ; $j * $sec < $tps ; $j++) {}
$j--;
$this->{"file_".$court}[$i] = $obj[0].','.($obj[1]-$j);
$this->{$file}[$obj[0]] += $j;
$this->{"file_".$court}[0] += $j * $sec;
if (!in_array($file, $this->modif)) $this->modif[] = $file;
if (!in_array("file_".$court, $this->modif)) $this->modif[] = "file_".$court;
}
else {
$this->actualiser(false);
return true;
}
}
}
/**
* Destructeur
*
@ -472,8 +351,8 @@ class Planete extends User{
else $out[] .= $this->modif[$i]." = '".$this->{$this->modif[$i]}."'";
}
else {
if (ereg('file', $this->modif[$i])) {
$prep = implode(';', $this->{$this->modif[$i]});
if (is_array($this->{$this->modif[$i]}) && $this->modif[$i] != "coeff_bat" && $this->modif[$i] != "vaisseaux" && $this->modif[$i] != "terrestres" && $this->modif[$i] != "casernes" && $this->modif[$i] != "technologies" && $this->modif[$i] != "batiments") {
$prep = serialize($this->{$this->modif[$i]});
$bdd->escape($prep);
$out[] .= $this->modif[$i]." = '$prep'";
}
@ -495,7 +374,7 @@ class Planete extends User{
}
}
}
if (!empty($out)) $plan = $bdd->unique_query("UPDATE $table_planete SET ".implode(', ', $out)." WHERE id = ".$this->id.";");
if (!empty($out)) $plan = $bdd->query("UPDATE $table_planete SET ".implode(', ', $out)." WHERE id = ".$this->id.";");
$bdd->deconnexion();
parent::__destruct();
}