forked from halo-battle/game
Version 1.10c
This commit is contained in:
parent
4c9814a99c
commit
2a066a7498
148 changed files with 2174 additions and 134960 deletions
|
|
@ -9,6 +9,20 @@
|
|||
*
|
||||
***************************************************************************/
|
||||
class File{
|
||||
var $file;
|
||||
|
||||
function File($file){
|
||||
$this->file = unserialize($file);
|
||||
}
|
||||
|
||||
function reajusteVacances($timeVac){
|
||||
if (isset($this->file[0])) {
|
||||
$this->file[0] += time() - $timeVac;
|
||||
}
|
||||
|
||||
return serialize($this->file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajoute $nombre objets $objet dans la file $file
|
||||
* @param int $file Nom de la file d'attente
|
||||
|
|
@ -20,10 +34,13 @@ class File{
|
|||
*/
|
||||
function file_addObjet($file, $objet, $nombre = 1){
|
||||
$planete = $this;
|
||||
|
||||
if ($nombre > 99999) erreur('Dépacement de capacité !<br />Vous ne pouvez pas mettre autant d\'unités en file d\'attente en une seule fois.');
|
||||
|
||||
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 "technologies": $court = "tech"; $calc = "technolo"; $exist = $this->file_exist($objet, $nombre); 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;
|
||||
|
|
@ -67,44 +84,52 @@ class File{
|
|||
if ($exist) return 2;
|
||||
|
||||
//Vérification que le nombre ne soit pas négatif
|
||||
if ($nombre < 0) return 5;
|
||||
if ($nombre < 0 && ($file != "batiments" || $nombre < -1)) 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];
|
||||
if ($nombre > 0) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$a = ${$calc.'CALC'}[$objet][0];
|
||||
$b = ${$calc.'CALC'}[$objet][1];
|
||||
$c = ${$calc.'CALC'}[$objet][2];
|
||||
$a = 0;
|
||||
$b = 0;
|
||||
$c = 0;
|
||||
$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;
|
||||
|
|
@ -153,10 +178,10 @@ class File{
|
|||
|
||||
//On gère les files de type arbre
|
||||
if ($file == "technologies") {
|
||||
if (isset($this->{"file_".$court}[$objet])) {
|
||||
if (isset($this->{"file_".$court}[$objet+1])) {
|
||||
global ${$file.'CALC'};
|
||||
//On réinitialise le temps si c'est la première
|
||||
if ($objet == 1) $this->{"file_".$court}[0] = time();
|
||||
if ($objet == 0) $this->{"file_".$court}[0] = time();
|
||||
|
||||
$i = $objet;
|
||||
$filearbre = $this->{"file_".$court}[$objet+1][1];
|
||||
|
|
@ -190,37 +215,40 @@ class File{
|
|||
$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;
|
||||
}
|
||||
if ($nombre > 0) {
|
||||
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;
|
||||
}
|
||||
//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;
|
||||
//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;
|
||||
}
|
||||
|
|
@ -259,7 +287,6 @@ class File{
|
|||
* @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;
|
||||
|
|
@ -283,7 +310,7 @@ class File{
|
|||
if ($key == 0) continue;
|
||||
|
||||
//Récupération du temps de recherche
|
||||
$sec = $technologiesCALC[$bout[1]][$bout[0]][3] / (1 + $planete->batiments[6] * 0.005);
|
||||
$sec = $technologiesCALC[$bout[1]][$bout[0]][3] / (1 + $this->batiments[6] * 0.01);
|
||||
|
||||
//On applique les bonus politiques aux temps et coûts
|
||||
if (isset($this->politique) && $this->politique == 1 && ($file == "casernes" || $file == "terrestres" || $file == "vaisseaux")) {
|
||||
|
|
@ -296,9 +323,16 @@ class File{
|
|||
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 !
|
||||
$tps -= $sec;
|
||||
unset($this->{"file_".$court}[$key]);
|
||||
$this->{"file_".$court} = array_merge($this->{"file_".$court});
|
||||
|
||||
//La déouverte de technologie est bénéfique pour le moral de la population
|
||||
if ($this->moral) {
|
||||
if ($this->politique == 3) $this->setMoral(0.1); //Démocratie : Découvrir une nouvelle technologie a plus d'effet bénéfique sur le moral
|
||||
else $this->setMoral(0.05);
|
||||
}
|
||||
|
||||
if (!in_array($file, $this->modifUser)) $this->modifUser[] = $file;
|
||||
if (!in_array("file_".$court, $this->modif)) $this->modif[] = "file_".$court;
|
||||
}
|
||||
|
|
@ -320,7 +354,31 @@ class File{
|
|||
//Accélération du temps de construction
|
||||
$sec = floor($sec/VITESSE);
|
||||
|
||||
if ($sec * $bout[1] < $tps) {
|
||||
if ($bout[1] < 0) {
|
||||
$n--;
|
||||
eval(${$calc.'CALC'}[$bout[0]][3]);
|
||||
$sec = floor($sec*0.6/VITESSE);
|
||||
|
||||
if ($sec < $tps) {
|
||||
eval(${$calc.'CALC'}[$bout[0]][0]);
|
||||
eval(${$calc.'CALC'}[$bout[0]][1]);
|
||||
eval(${$calc.'CALC'}[$bout[0]][2]);
|
||||
|
||||
//On reçoit 70% des ressources en bonus
|
||||
$this->metal += $a * 0.7;
|
||||
$this->cristal += $b * 0.7;
|
||||
$this->hydrogene += $c * 0.7;
|
||||
|
||||
$this->{$file}[$bout[0]]--;
|
||||
$this->{"file_".$court}[0] += $bout[1] * $sec;
|
||||
$tps -= $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 * $bout[1] < $tps && $bout[1] > 0) {
|
||||
//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];
|
||||
|
|
@ -334,7 +392,7 @@ class File{
|
|||
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]) {
|
||||
elseif ($sec < time() - $this->{"file_".$court}[0] && $bout[1] > 0) {
|
||||
//TODO Trouver plus simple que la ligne en dessous
|
||||
for($j=0 ; $j * $sec < $tps ; $j++) {}
|
||||
$j--;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue