Version 1.13a

This commit is contained in:
nemunaire 2020-11-15 16:12:30 +01:00
commit ba8f323879
1634 changed files with 10080 additions and 213021 deletions

View file

@ -15,9 +15,15 @@ class Asteroide extends Surface
$sante,
$nom_alliance,
$tag,
$wing,
$nom_asteroide,
$image_asteroide,
$credits_alliance;
$position = 5,
$cap = 123456789,
$credits_alliance,
$url_chat,
$url_forum,
$details = array();
/**
* Constructeur
@ -53,12 +59,20 @@ class Asteroide extends Surface
parent::User($SESS->values['id']); //On utilise le numéro d'utilisateur enregistré en session
$this->galaxie = $plan["galaxie"];
$this->ss = $plan["ss"];
$this->nom_asteroide = $plan["nom_asteroide"];
$this->image = $this->image_asteroide = $plan["image_asteroide"];
$this->debris_met = $plan["debris_met"];
$this->debris_cri = $plan["debris_cri"];
$this->metal = $plan["metal"];
$this->cristal = $plan["cristal"];
$this->hydrogene = $plan["hydrogene"];
$this->credits_alliance = $plan["credits_alliance"];
$this->fondateur = $plan["fondateur"];
$this->nom_alliance = $plan["nom_alliance"];
$this->wing = $plan["wing"];
$this->tag = $plan["tag"];
$this->url_forum = $plan["url_forum"];
$this->url_chat = $plan["url_chat"];
foreach($alli_batimentVAR as $bat)
$this->batiments[] = $plan[$bat];
@ -78,419 +92,107 @@ class Asteroide extends Surface
}
}
/**
* Actualise les ressources de la planète en fonction de la production et termine les files d'attentes.
*
* @return void
* @access public
*/
function loadDetails()
{
global $table_alliances;
$bdd = new bdd();
$this->details = $bdd->unique_query("SELECT presentation, message_inscription, texte_interne, port_chat, chan_chat, image, etat_inscription, defcon, defcon_txt FROM $table_alliances WHERE id = ".$this->id.";");
$bdd->deconnexion();
}
function actualiser($actuFile = true, $first = false)
{
//Actualisation des files d'attentes
if ($actuFile)
{
$this->file_ready("batiments");
$this->file_readyTechno("technologies");
$this->file_ready("casernes");
$this->file_ready("terrestres");
$this->file_ready("vaisseaux");
}
//Calcul de la capacité de stockage maximale
if (!empty($timestamp_lastSilo))
{
$this->cap = pow(2, $this->batiments[10]-1) * 100000;
$capnouv = pow(2, $this->batiments[10]) * 100000;
}
else
$this->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] < $this->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 = $this->cap;
}
}
if ($this->cristal + $ressources[1] < $this->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 = $this->cap;
}
}
if ($this->hydrogene + $ressources[2] < $this->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 = $this->cap;
}
}
//Vérification de la date pour faire les actions journalières
if (date('zya') != date('zya', $this->timestamp))
{
//On évalue le moral
$this->evalMoral($first);
//Si la population est à 0, on ajoute des habitants
if ($this->population <= 0)
$this->population = 1000;
$popPlus = $this->population * 0.0153^max(1, floor((time()-$this->timestamp)/86400));
if ($this->politique == 2)
$popPlus *= 1.1; //Communisme : 10 % de population qui arrive en plus.
elseif ($this->politique == 3)
$popPlus *= 1.05; //Démocratie : 5 % de population qui arrive en plus.
if ($this->technologies[2] & 4)
$popPlus *= 1.15;
elseif ($this->technologies[2] & 2)
$popPlus *= 1.10;
elseif ($this->technologies[2] & 1)
$popPlus *= 1.05;
$this->population += $popPlus;
$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)
$this->casesRest -= $bat;
}
function setMoral($difference)
{
$this->moral += $difference;
//Ajustement du moral
if ($this->moral > 1)
$this->moral = 1;
elseif ($this->moral < 0)
$this->moral = 0;
if (!in_array("moral", $this->modif))
$this->modif[] = "moral";
}
function evalMoral($first = false)
{
//Cas de sous-production
if (($this->coeff_bat[0] + $this->coeff_bat[1] + $this->coeff_bat[2])/3 < 0.9)
{
if ($this->politique == 2)
$this->moral -= 0.10; //Communisme : démoralise 2x plus
else
$this->moral -= 0.05;
if (!in_array('moral', $this->modif))
$this->modif[] = 'moral';
}
//Surpopulation
//Surlogement
//Ajustement du moral en fonction de la politique
if ($this->politique == 1 && $this->moral > 0.7)
$this->moral = 0.7;
//On vérifie qu'on ne dépasse pas le maximum
if ($this->moral > 1)
$this->moral = 1;
if ($this->moral < 0)
$this->moral = 0;
//Isolement si besoin
if ($this->moral < 0.1)
{
//On vérifie qu'il ne s'agit pas de la planète mère
global $bdd, $table_planete;
$bdd->connexion();
$res = $bdd->unique_query("SELECT id FROM $table_planete WHERE id_user = ".$this->id_user." ORDER BY id LIMIT 1;");
$bdd->deconnexion();
if ($res['id'] != $this->id)
{
if ($this->moral <= 0.01 || $this->moral <= 0.04)
{
if ($this->moral <= 0.01)
$rand = rand(0,4);
else
$rand = rand(0,20);
//Perte de la planète
if ($rand == 1)
{
$bdd->connexion();
$bdd->query("DELETE FROM $table_planete WHERE id = ".$this->id.";");
$bdd->deconnexion();
send_mp($this->id_user, 'Perte de contrôle de '.$this->nom_planete, "Suite à une démoralisation percistante de la population sur la planète ".$this->nom_planete." [".$this->galaxie.":".$this->ss.":".$this->position."], la population a renversé votre gouvernement en tuant tous vos gouverneurs. Vous perdez donc définitivement le contrôle de cette planète.");
if (!$first)
{
$SESS->values['idPlan'] = $res['id'];
erreur('La population de cette planète est tellement démoralisée qu\'elle s\'est révolté contre vous. Vous ne contrôlez plus cette planète.');
}
}
}
elseif ($this->moral <= 0.06 || $this->moral <= 0.1)
{
if ($this->moral <= 0.06)
$rand = rand(0,2);
else
$rand = rand(0,10);
//Perte de contrôle temporaire
if ($rand == 1)
{
$debut = time() - rand(0, 3600)*4;
$fin = $debut + 86400;
$this->isolement = array($debut, $fin);
if (!in_array('isolement', $this->modif)) $this->modif[] = 'isolement';
send_mp($this->id_user, 'Perte de contrôle temporaire de '.$this->nom_planete, "Suite à une démoralisation percistante de la population sur la planète ".$this->nom_planete." [".$this->galaxie.":".$this->ss.":".$this->position."], la population a pris le contrôle de votre planète. Vous perdez le contrôle de cette planète le temps que vos gouverneurs reprennent le pouvoir.");
if (!$first)
{
$SESS->values['idPlan'] = $res['id'];
erreur('La population de cette planète est tellement démoralisée qu\'elle s\'est révoltée contre vous. Vous perdez temporairement le contrôle de cette planète.');
}
}
}
}
$this->file_bat->batiment_ready($this);
$this->file_vais->vaisseaux_ready($this);
}
}
/**
* Vérifie si la planète est isolée ou non
*
* @return boolean
* @access public
*/
function isolement()
function checkAndRetireRessources($metal, $cristal, $hydrogene, $credits)
{
return false;
if ($this->metal >= $metal && $this->cristal >= $cristal && $this->hydrogene >= $hydrogene && $this->credits_alliance >= $credits)
{
$this->metal -= $metal;
$this->cristal -= $cristal;
$this->hydrogene -= $hydrogene;
$this->credits -= $credits;
$this->addModif("force");
$this->addModif("credits_alliance");
return true;
}
else
return false;
}
/**
* Calcul les ressources produites en fonction de $temps_ecoule
* @param int $temps_ecoule Temps écoulé depuis la dernière actualisation
*
* @return array
* @access public
*/
function production($temps_ecoule, $retarray = false)
function addRessources($metal, $cristal, $hydrogene, $credits)
{
//Accélération de la production
$temps_ecoule *= VITESSE;
$perte = 0;
//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;
if ($this->batiments[1] > 0)
$energie_c = ceil(exp(0.28*$this->batiments[1])*10);
else
$energie_c = 0;
if ($this->batiments[2] > 0)
$energie_h = ceil(exp(0.2849*$this->batiments[2])*13);
else
$energie_h = 0;
if ($this->batiments[3] > 0)
$energie_s = ceil(exp(0.28*$this->batiments[3])*22);
else
$energie_s = 0;
if ($this->batiments[4] > 0)
$energie_f = ceil(exp(0.297*$this->batiments[4])*25);
else
$energie_f = 0;
//Calcul de la consomation d'énergie
$this->energieConso = $energie_m * $this->coeff_bat[0] + $energie_c * $this->coeff_bat[1] + $energie_h * $this->coeff_bat[2];
$nrjmx = $energie_m + $energie_c + $energie_h;
//Calcul de la production d'énergie
$this->energie = $energie_s * $this->coeff_bat[3] + $energie_f * $this->coeff_bat[4];
if ($this->energieConso == 0)
$coeff = 0;
else
$coeff = $this->energie / $this->energieConso;
if ($coeff < 0)
$coeff = 0;
elseif ($coeff > 1)
$coeff = 1;
$Ncoeff = array();
for($i = 0; $i < 3; $i++)
$this->metal += $metal;
if ($this->metal > $this->cap)
{
$Ncoeff[$i] = $coeff * $this->coeff_bat[$i];
if ($Ncoeff[$i] > 1)
$Ncoeff[$i] = 1;
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';
}
$perte += $this->metal - $this->cap;
$this->metal = $this->cap;
}
//Calcul de la consomation d'hydrogène
if ($this->batiments[4] > 0)
$conso_h = ((ceil(pow(1.34,($this->batiments[4]-1))*9)/3600)*$temps_ecoule) * $this->coeff_bat[4];
else
$conso_h = 0;
//Calcul des production de ressources
if ($this->batiments[0] <= 0 || $this->batiments[3] <= 0)
$prod_met = 0.011 * $temps_ecoule;
else
$prod_met = ((ceil(pow(1.1, $this->batiments[0]) * 35 * $this->batiments[0]) / 3600) * $temps_ecoule) * $this->coeff_bat[0] * 1.5;
if ($this->batiments[1] <= 0 || $this->batiments[3] <= 0)
$prod_cri = 0.0055 * $temps_ecoule;
else
$prod_cri = ((ceil(pow(1.1, $this->batiments[1]) * 23 * $this->batiments[1]) / 3600) * $temps_ecoule) * $this->coeff_bat[1] * 1.5;
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;
//Augmentation de la production en fonction des technologies
if ($this->technologies[0] &4)
$this->cristal += $cristal;
if ($this->cristal > $this->cap)
{
$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;
$perte += $this->cristal - $this->cap;
$this->cristal = $this->cap;
}
//Augmentation de la production en fonction du moral
if ($this->moral > 0.9)
$this->hydrogene += $hydrogene;
if ($this->hydrogene > $this->cap)
{
$prod_met *= 1.05;
$prod_cri *= 1.05;
$prod_hy *= 1.05;
}
elseif ($this->moral > 0.75)
{
$prod_met *= 1.02;
$prod_cri *= 1.02;
$prod_hy *= 1.02;
}
elseif ($this->moral < 0.45)
{
$prod_met *= 0.97;
$prod_cri *= 0.97;
$prod_hy *= 0.97;
}
elseif ($this->moral < 0.25)
{
$prod_met *= 0.94;
$prod_cri *= 0.94;
$prod_hy *= 0.94;
$perte += $this->hydrogene - $this->cap;
$this->hydrogene = $this->cap;
}
//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;
}
$this->hydrogecredits_alliancene += $credits;
//On enlève la consomation d'hydrogène
$prod_hy -= $conso_h;
$this->addModif("force");
$this->addModif("credits_alliance");
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);
return $perte;
}
function creer($id_user)
function addCreditsAlliance($credits)
{
//Définition des paramètres de l'utilisateur pour la planète
$this->id_user = $id_user;
$this->credits_alliance += $credits;
$this->addModif("credits_alliance");
return 0;
}
function creer($fondateur, $mere = false)
{
global $VAR, $table_alliances_creation;
$bdd = new BDD();
$alliance = $bdd->unique_query("SELECT * FROM $table_alliances_creation WHERE fondateur = ".$fondateur->id_user." LIMIT 1;");
$bdd->deconnexion();
//On vérifie que l'alliance n'a pas déjà été créée
if (empty($alliance))
return 1;
//Définition des paramètres de l'utilisateur pour l'astéroide
$this->fondateur = $alliance["fondateur"];
$this->race = $fondateur->race;
//Génération du nombre de case et de l'image en fonction de la position dans le système
if ($this->position > MAX_PLANETE*0.75)
{
$this->cases = mt_rand(200,255);
$this->image = mt_rand(1,19);
}
elseif ($this->position > MAX_PLANETE/2)
{
$this->cases = mt_rand(250,300);
$this->image = mt_rand(1,19);
}
elseif ($this->position > MAX_PLANETE/4)
{
$this->cases = mt_rand(175,260);
$this->image = mt_rand(1,19);
}
else
{
$this->cases = mt_rand(150,220);
$this->image = mt_rand(1,19);
}
$this->sante = 1;
$this->nom_alliance = $alliance["nom_alliance"];
$this->tag = $alliance["tag"];
$this->nom_asteroide = $alliance["nom_alliance"];
$this->image_asteroide = mt_rand(1,3);
//Définition des principaux paramètres de la planète
$this->nom_planete = 'Planète colonisée';
$this->timestamp = time();
$this->metal = 1000;
$this->cristal = 700;
$this->hydrogene = 0;
$this->modif = array("id_user", "nom_planete", "galaxie", "ss", "position", "image", "cases", "timestamp", "metal", "cristal", "hydrogene");
$this->modif = array("fondateur", "race", "nom_alliance", "galaxie", "ss", "tag", "nom_asteroide", "image_asteroide");
}
/**
@ -501,12 +203,10 @@ class Asteroide extends Surface
*/
function __destruct()
{
if (empty($this->ss) || empty($this->id_user))
if (empty($this->ss) || empty($this->fondateur))
return;
if ($this->id_user == 1)
var_dump($this);
global $var___db, $config, $table_planete;
global $table_alliances;
if (empty($this->id))
{
$out1 = array(); $out2 = array();
@ -559,7 +259,7 @@ class Asteroide extends Surface
}
}
}
$bdd->query("INSERT INTO $table_planete (".implode(', ', $out1).", hash_planete) VALUES (".implode(', ', $out2).", SHA1(CONCAT('g',planete.galaxie,'s',planete.ss,'p',planete.position)))");
$bdd->query("INSERT INTO $table_alliances (".implode(', ', $out1).") VALUES (".implode(', ', $out2).")");
$bdd->deconnexion();
}
else
@ -570,7 +270,7 @@ class Asteroide extends Surface
for($i = 0; $i < $nb; $i++)
{
if ($this->modif[$i] == "force")
$out[] = "timestamp = timestamp";
$out[] = "metal = ".$this->metal.", cristal = ".$this->cristal.", hydrogene = ".$this->hydrogene;
elseif ($this->modif[$i] == 'technologies')
$this->modifUser[] = $this->modif[$i];
elseif (is_object($this->{$this->modif[$i]}))
@ -598,7 +298,7 @@ class Asteroide extends Surface
else
{
if ($this->modif[$i] == "batiments")
$calc = "batiment";
$calc = "alli_batiment";
elseif ($this->modif[$i] == "technologies")
$calc = "technolo";
elseif ($this->modif[$i] == "casernes")
@ -624,7 +324,7 @@ class Asteroide extends Surface
}
if (!empty($out))
{
$sql = "UPDATE $table_planete SET timestamp = ".time().", metal = ".$this->metal.", cristal = ".$this->cristal.", hydrogene = ".$this->hydrogene.", ".implode(', ', $out)." WHERE id = ".$this->id.";";
$sql = "UPDATE $table_alliances SET ".implode(', ', $out)." WHERE id = ".$this->id.";";
if (DEBUG) echo '<br /><br />'.$sql;
$bdd->query($sql);
}