Version 1.10c

This commit is contained in:
nemunaire 2008-11-19 12:00:00 +01:00
commit 2a066a7498
148 changed files with 2174 additions and 134960 deletions

View file

@ -24,6 +24,7 @@ class Planete extends User{
$cristal,
$hydrogene,
$population,
$moral,
$alert_ressources = array(false, false, false),
$timestamp,
$timestamp_lastSilo,
@ -51,7 +52,7 @@ class Planete extends User{
* @return void
* @access public
*/
function Planete($id = 0){
function Planete($id = 0, $first = false){
if (!empty($id)) {
global $var___db, $config, $table_planete;
global $batimentVAR, $casernenVAR, $nomterrnVAR, $nomvaisnVAR;
@ -77,6 +78,7 @@ class Planete extends User{
$this->cristal = $plan["cristal"];
$this->hydrogene = $plan["hydrogene"];
$this->population = $plan["population"];
$this->moral = $plan["moral"];
$this->timestamp = $plan["timestamp"];
foreach($batimentVAR as $bat){
@ -109,7 +111,7 @@ class Planete extends User{
if (!empty($plan["file_vais"])) $this->file_vais = unserialize($plan["file_vais"]);
else $this->file_vais = array();
$this->actualiser();
$this->actualiser(true, $first);
}
}
}
@ -120,7 +122,7 @@ class Planete extends User{
* @return void
* @access public
*/
function actualiser($actuFile = true){
function actualiser($actuFile = true, $first = false){
//Actualisation des files d'attentes
if ($actuFile) {
$this->file_pret("batiments");
@ -177,11 +179,24 @@ class Planete extends User{
}
}
//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;
$this->population = $this->population * 1.0153^max(1, floor((time()-$this->timestamp)/86400));
$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';
}
@ -196,6 +211,75 @@ class Planete extends User{
}
}
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;
//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.');
}
}
}
}
}
}
/**
* Vérifie si la planète est isolée ou non
*
@ -205,8 +289,8 @@ class Planete extends User{
function isolement(){
$return = false;
if (time() > $isolement[0]) {
if (!isset($isolement[1]) || (time() > $isolement[1] && date('dmY') != date('dmY', $isolement[0]))) {
if (time() > $this->isolement[0]) {
if (!isset($this->isolement[1]) || (time() > $this->isolement[1] && date('dmY') != date('dmY', $this->isolement[0]))) {
$nbPlan = count($queryPlanetes);
$numP = 0;
for ($i=0 ; $i<$nbPlan ; $i++) {
@ -226,25 +310,17 @@ class Planete extends User{
$debut = mktime(rand(0, 24-$tps), 0, 0, date('n'), date('j'), date('Y'));
$fin = $debut + $tps * 3600;
$bdd->connexion();
$bdd->query("UPDATE $table_planete SET isolement = '$debut $fin' WHERE id = '$idPlan';");
$bdd->deconnexion();
$isolement[0] = $debut;
if (time() > $isolement[0]) $isolement[1] = $fin;
$this->isolement[0] = $debut;
if (time() > $this->isolement[0]) $this->isolement[1] = $fin;
if (!in_array('isolement', $this->modif)) $this->modif[] = 'isolement';
}
}
$p = gpc('p');
if (isset($isolement[1]) && time() < $isolement[1]) {
if (isset($this->isolement[1]) && time() < $this->isolement[1]) {
$return = true;
}
}
//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;
}
@ -301,7 +377,7 @@ class Planete extends User{
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 - $conso_h;
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) {
@ -320,6 +396,28 @@ class Planete extends User{
$prod_hy *= 1.05;
}
//Augmentation de la production en fonction du moral
if ($this->moral > 0.9) {
$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;
}
//Augmentation de la production en fonction de la politique
if ($this->politique == 2) {
$prod_met *= 1.10;
@ -327,6 +425,9 @@ class Planete extends User{
$prod_hy *= 1.10;
}
//On enlève la consomation d'hydrogène
$prod_hy -= $conso_h;
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);
}