forked from halo-battle/game
Version 1.9g
This commit is contained in:
parent
d028822d0b
commit
4c9814a99c
800 changed files with 237325 additions and 1949 deletions
360
game/Class/class.file.php
Normal file
360
game/Class/class.file.php
Normal file
|
|
@ -0,0 +1,360 @@
|
|||
<?php
|
||||
/***************************************************************************
|
||||
* class.file.php
|
||||
* ----------------
|
||||
* begin : Samedi 11 octobre 2008
|
||||
* update : Samedi 11 octobre 2008
|
||||
* email : nemunaire@gmail.com
|
||||
*
|
||||
*
|
||||
***************************************************************************/
|
||||
class File{
|
||||
/**
|
||||
* Ajoute $nombre objets $objet dans la file $file
|
||||
* @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 "alli_batiments": $court = "abat"; $calc = "alli_batiment"; global ${$calc.'LIMIT'}; $exist = $this->file_exist($objet, "file_".$court); break;
|
||||
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;
|
||||
}
|
||||
|
||||
//On vérifie la taille maximale de la file d'attente
|
||||
if (!empty($this->technologies['techno_inge'])) {
|
||||
if (($this->technologies['techno_inge'] & 131072) == 131072) $max = 5;
|
||||
elseif (($this->technologies['techno_inge'] & 65536) == 65536) $max = 4;
|
||||
elseif (($this->technologies['techno_inge'] & 32768) == 32768) $max = 3;
|
||||
else $max = 2;
|
||||
}
|
||||
else $max = 3;
|
||||
|
||||
if ($file == "technologies") {
|
||||
global ${$file.'CALC'};
|
||||
|
||||
$file_tech = $nombre;
|
||||
$nombre = 1;
|
||||
|
||||
if (empty($technologiesCALC[$file_tech][$objet])) return 1;
|
||||
|
||||
//Vérification des conditions de recherche
|
||||
if (!(($this->technologies[$file_tech] & $technologiesCALC[$file_tech][$objet][1]) == $technologiesCALC[$file_tech][$objet][1] && !($this->technologies[$file_tech] & $technologiesCALC[$file_tech][$objet][0] && $this->technologies[$file_tech] != 0))) return 1;
|
||||
}
|
||||
else {
|
||||
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 que l'on ait pas dépassé le nombre maximal de niveau
|
||||
if (!empty(${$calc.'LIMIT'}[$objet]) && ${$file}[$objet] >= ${$calc.'LIMIT'}[$objet]) return 1;
|
||||
|
||||
//Calcul du prochain niveau de l'objet
|
||||
$n = $this->{$file}[$objet] + 1;
|
||||
}
|
||||
|
||||
//Vérification qu'il n'y ait pas déjà une instance de l'objet déjà en construction
|
||||
if ($exist) return 2;
|
||||
|
||||
//Vérification que le nombre ne soit pas négatif
|
||||
if ($nombre < 0) return 5;
|
||||
|
||||
//Actualisation du temps s'il n'y a pas d'objet en file
|
||||
if (count($this->{"file_".$court}) < 2) $this->{"file_".$court}[0] = time();
|
||||
|
||||
|
||||
if ($file == "alli_batiments" || $file == "batiments") {
|
||||
eval(${$calc.'CALC'}[$objet][0]);
|
||||
eval(${$calc.'CALC'}[$objet][1]);
|
||||
eval(${$calc.'CALC'}[$objet][2]);
|
||||
$d = 0;
|
||||
}
|
||||
elseif ($file == "technologies") {
|
||||
$a = $b = $c = 0;
|
||||
$d = $technologiesCALC[$file_tech][$objet][2];
|
||||
}
|
||||
else {
|
||||
$a = ${$calc.'CALC'}[$objet][0];
|
||||
$b = ${$calc.'CALC'}[$objet][1];
|
||||
$c = ${$calc.'CALC'}[$objet][2];
|
||||
$d = 0;
|
||||
}
|
||||
|
||||
//On applique les bonus politiques aux temps et coûts
|
||||
if (isset($this->politique) && $this->politique == 1 && ($file == "casernes" || $file == "terrestres" || $file == "vaisseaux")) {
|
||||
$a *= 0.9;
|
||||
$b *= 0.9;
|
||||
$c *= 0.9;
|
||||
}
|
||||
|
||||
//Vérification du nombre maximum d'entraînement possible de cette unité sur cette planète
|
||||
if ($nombre > 1) {
|
||||
if ($a) $nombre = min(floor($this->metal/$a), $nombre);
|
||||
if ($b) $nombre = min(floor($this->cristal/$b), $nombre);
|
||||
if ($c) $nombre = min(floor($this->hydrogene/$c), $nombre);
|
||||
if ($d) $nombre = min(floor($this->credits/$d), $nombre);
|
||||
}
|
||||
|
||||
//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;
|
||||
elseif ($this->credits < $d * $nombre) return 3;
|
||||
else {
|
||||
//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 ($file == "technologies" && $max <= count($this->{"file_".$court})) return 4; //Vérification de la taille de la file d'attente
|
||||
elseif ($file == "technologies") $this->{"file_".$court}[] = array($objet, $file_tech);
|
||||
elseif ($nb > 1 && $objet == $this->{"file_".$court}[$nb-1][0]) {
|
||||
$this->{"file_".$court}[$nb-1][1] += $nombre;
|
||||
}
|
||||
elseif ($max <= count($this->{"file_".$court})) return 4; //Vérification de la taille de la file d'attente
|
||||
else $this->{"file_".$court}[] = array($objet, $nombre);
|
||||
|
||||
//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;
|
||||
$this->credits -= $d * $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 "alli_batiments": $court = "abat"; $calc = "alli_batiment"; $exist = $this->file_exist($objet, "file_".$court); break;
|
||||
case "batiments": $court = "bat"; $calc = "batiment"; $exist = $this->file_exist($objet, "file_".$court); break;
|
||||
case "technologies": $court = "tech"; $calc = "technolo"; $exist = true; 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;
|
||||
}
|
||||
|
||||
//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;
|
||||
|
||||
//On gère les files de type arbre
|
||||
if ($file == "technologies") {
|
||||
if (isset($this->{"file_".$court}[$objet])) {
|
||||
global ${$file.'CALC'};
|
||||
//On réinitialise le temps si c'est la première
|
||||
if ($objet == 1) $this->{"file_".$court}[0] = time();
|
||||
|
||||
$i = $objet;
|
||||
$filearbre = $this->{"file_".$court}[$objet+1][1];
|
||||
$objet = $this->{"file_".$court}[$objet+1][0];
|
||||
|
||||
if (!$this->file_exist($objet, $filearbre)) return 0;
|
||||
|
||||
unset($this->{"file_".$court}[$i+1]);
|
||||
$this->{"file_".$court} = array_merge($this->{"file_".$court});
|
||||
}
|
||||
}
|
||||
else {
|
||||
global ${$calc}, ${$calc.'CALC'};
|
||||
|
||||
for($i = $w; $i > 0; $i--) {
|
||||
if($this->{"file_".$court}[$i][0] == $objet){
|
||||
$nombre = min(abs($nombre), $this->{"file_".$court}[$i][1]);
|
||||
|
||||
if($this->{"file_".$court}[$i][1] <= $nombre) {
|
||||
unset($this->{"file_".$court}[$i]);
|
||||
$this->{"file_".$court} = array_merge($this->{"file_".$court});
|
||||
}
|
||||
else $this->{"file_".$court}[$i][1] -= $nombre;
|
||||
|
||||
if ($i == 1) $this->{"file_".$court}[0] = time();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Calcul du prochain niveau de l'objet
|
||||
$n = $this->{$file}[$objet] + 1;
|
||||
}
|
||||
|
||||
if (!in_array("file_".$court, $this->modif)) $this->modif[] = "file_".$court;
|
||||
|
||||
if ($file == "batiments") {
|
||||
eval(${$calc.'CALC'}[$objet][0]);
|
||||
eval(${$calc.'CALC'}[$objet][1]);
|
||||
eval(${$calc.'CALC'}[$objet][2]);
|
||||
$d = 0;
|
||||
}
|
||||
elseif ($file == "technologies") {
|
||||
$a = $b = $c = 0;
|
||||
$d = $technologiesCALC[$filearbre][$objet][2];
|
||||
}
|
||||
else {
|
||||
$a = ${$calc.'CALC'}[$objet][0];
|
||||
$b = ${$calc.'CALC'}[$objet][1];
|
||||
$c = ${$calc.'CALC'}[$objet][2];
|
||||
$d = 0;
|
||||
}
|
||||
|
||||
//On applique les bonus politiques aux temps et coûts
|
||||
if (isset($this->politique) && $this->politique == 1 && ($file == "casernes" || $file == "terrestres" || $file == "vaisseaux")) {
|
||||
$a *= 0.9;
|
||||
$b *= 0.9;
|
||||
$c *= 0.9;
|
||||
}
|
||||
|
||||
//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;
|
||||
$this->credits += $d * $nombre;
|
||||
|
||||
return $nombre;
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifie l'existance dans la file $file d'attente de $objet
|
||||
* @param int $objet ID à vérifier
|
||||
* @param string $file Nom de la file d'attente
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function file_exist($objet, $file){
|
||||
//On traite le cas d'une file type arbre
|
||||
if (is_numeric($file)) {
|
||||
foreach($this->file_tech as $key => $bout){
|
||||
if ($key == 0) continue;
|
||||
if($objet == $bout[0] && $file == $bout[1]) return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (count($this->$file) <= 1) return false;
|
||||
foreach($this->$file as $key => $bout){
|
||||
if ($key == 0) continue;
|
||||
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 "alli_batiments": $court = "abat"; $calc = "alli_batiment"; $exist = $this->file_exist($objet, "file_".$court); break;
|
||||
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;
|
||||
}
|
||||
|
||||
if (empty($this->{"file_".$court}[0])) return false;
|
||||
|
||||
//Calcul du temps écoulé depuis le dernier entrainement validé
|
||||
$tps = time() - $this->{"file_".$court}[0];
|
||||
|
||||
if ($file == "technologies") {
|
||||
global ${$file.'CALC'};
|
||||
|
||||
foreach($this->{"file_".$court} as $key => $bout) {
|
||||
if ($key == 0) continue;
|
||||
|
||||
//Récupération du temps de recherche
|
||||
$sec = $technologiesCALC[$bout[1]][$bout[0]][3] / (1 + $planete->batiments[6] * 0.005);
|
||||
|
||||
//On applique les bonus politiques aux temps et coûts
|
||||
if (isset($this->politique) && $this->politique == 1 && ($file == "casernes" || $file == "terrestres" || $file == "vaisseaux")) {
|
||||
$sec *= 0.9;
|
||||
}
|
||||
|
||||
//Accélération du temps de construction
|
||||
$sec /= VITESSE;
|
||||
|
||||
if ($sec < $tps) {
|
||||
$this->{$file}[$bout[1]] += $technologiesCALC[$bout[1]][$bout[0]][0];
|
||||
$this->{"file_".$court}[0] += $sec;
|
||||
unset($this->{"file_".$court}[$key]); //CAUSE DE PROBLEME POSSIBLE !
|
||||
$this->{"file_".$court} = array_merge($this->{"file_".$court});
|
||||
|
||||
if (!in_array($file, $this->modifUser)) $this->modifUser[] = $file;
|
||||
if (!in_array("file_".$court, $this->modif)) $this->modif[] = "file_".$court;
|
||||
}
|
||||
else break;
|
||||
}
|
||||
if (in_array("file_".$court, $this->modif)) $this->actualiser(false);
|
||||
}
|
||||
else {
|
||||
global ${$calc}, ${$calc.'CALC'};
|
||||
|
||||
foreach($this->{"file_".$court} as $key => $bout) {
|
||||
if ($key == 0) continue;
|
||||
|
||||
$n = $this->{$file}[$bout[0]] + 1; //Extraction du niveau en cours
|
||||
eval(${$calc.'CALC'}[$bout[0]][3]); //Récupération du temps de construction
|
||||
|
||||
//var_dump($bout[0], $n);
|
||||
|
||||
//Accélération du temps de construction
|
||||
$sec = floor($sec/VITESSE);
|
||||
|
||||
if ($sec * $bout[1] < $tps) {
|
||||
//S'il s'agit d'un silo, on sauvegarde le temps pour utilisation par le script de production
|
||||
if ($file == "batiments" && $bout[0] == 10) $timestamp_lastSilo = $this->{"file_".$court}[0];
|
||||
if ($file == "batiments" && $bout[0] == 0) $timestamp_mineM = $this->{"file_".$court}[0];
|
||||
if ($file == "batiments" && $bout[0] == 1) $timestamp_mineC = $this->{"file_".$court}[0];
|
||||
if ($file == "batiments" && $bout[0] == 2) $timestamp_mineH = $this->{"file_".$court}[0];
|
||||
$this->{$file}[$bout[0]] += $bout[1];
|
||||
$this->{"file_".$court}[0] += $bout[1] * $sec;
|
||||
$tps -= $bout[1] * $sec;
|
||||
unset($this->{"file_".$court}[$key]);
|
||||
|
||||
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]) {
|
||||
//TODO Trouver plus simple que la ligne en dessous
|
||||
for($j=0 ; $j * $sec < $tps ; $j++) {}
|
||||
$j--;
|
||||
$this->{"file_".$court}[$key][1] -= $j;
|
||||
$this->{$file}[$bout[0]] += $j;
|
||||
$this->{"file_".$court}[0] += $j * $sec;
|
||||
$tps -= $j * $sec;
|
||||
|
||||
if (!in_array($file, $this->modif)) $this->modif[] = $file;
|
||||
if (!in_array("file_".$court, $this->modif)) $this->modif[] = "file_".$court;
|
||||
|
||||
//Comme la première attente n'est pas terminée, on stoppe la vérification
|
||||
break;
|
||||
}
|
||||
else break;
|
||||
}
|
||||
//On actualise seulement s'il y a eu une modification de faite
|
||||
if (in_array($file, $this->modif)) $this->actualiser(false);
|
||||
$this->{"file_".$court} = array_merge($this->{"file_".$court});
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue