forked from halo-battle/game
Version 1.12
This commit is contained in:
parent
2a066a7498
commit
de31cd3e9a
1373 changed files with 156282 additions and 45238 deletions
|
|
@ -8,7 +8,7 @@
|
|||
*
|
||||
*
|
||||
***************************************************************************/
|
||||
class Alliance extends File{
|
||||
class Alliance extends Surface{
|
||||
var $id,
|
||||
$race,
|
||||
$fondateur,
|
||||
|
|
@ -24,12 +24,7 @@ class Alliance extends File{
|
|||
$credits,
|
||||
$metal,
|
||||
$cristal,
|
||||
$hydrogene,
|
||||
$file_abat,
|
||||
$file_vais,
|
||||
$alli_batiments = array(),
|
||||
$vaisseaux = array(),
|
||||
$modif = array();
|
||||
$hydrogene;
|
||||
|
||||
/**
|
||||
* Constructeur
|
||||
|
|
@ -66,7 +61,7 @@ class Alliance extends File{
|
|||
$this->hydrogene = $alli["hydrogene"];
|
||||
|
||||
foreach($alli_batimentVAR as $bat){
|
||||
$this->alli_batiments[] = $alli[$bat];
|
||||
$this->batiments[] = $alli[$bat];
|
||||
}
|
||||
$this->file_bat = unserialize($alli["file_bat"]);
|
||||
|
||||
|
|
|
|||
691
game/Class/class.asteroide.php
Normal file
691
game/Class/class.asteroide.php
Normal file
|
|
@ -0,0 +1,691 @@
|
|||
<?php
|
||||
/***************************************************************************
|
||||
* class.asteroide.php
|
||||
* ---------------------
|
||||
* begin : Jeudi 25 décembre 2008
|
||||
* update : Dimanche 4 janvier 2008
|
||||
* email : nemunaire@gmail.com
|
||||
*
|
||||
*
|
||||
***************************************************************************/
|
||||
class Asteroide extends Surface
|
||||
{
|
||||
var $fondateur,
|
||||
$sante,
|
||||
$nom_alliance,
|
||||
$tag,
|
||||
$nom_asteroide,
|
||||
$image_asteroide,
|
||||
$credits_alliance,
|
||||
$alli_batiments;
|
||||
|
||||
/**
|
||||
* Constructeur
|
||||
* @param int $id id de la planète à importer
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function Asteroide($id = 0)
|
||||
{
|
||||
if (!empty($id)) {
|
||||
global $var___db, $config, $table_alliances, $sess;
|
||||
global $alli_batimentVAR, $nomvaisnVAR;
|
||||
$bdd = new bdd();
|
||||
|
||||
//On traite le cas où l'on envoie les coordonnées
|
||||
if (is_numeric($id))
|
||||
{
|
||||
$bdd->connexion();
|
||||
$plan = $bdd->unique_query("SELECT * FROM $table_alliances WHERE id = $id;");
|
||||
$bdd->deconnexion();
|
||||
}
|
||||
elseif (preg_match('#^\[?([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})\]?$#', $id, $position))
|
||||
{
|
||||
$bdd->connexion();
|
||||
$plan = $bdd->unique_query("SELECT * FROM $table_alliances WHERE galaxie = ".$position[1]." AND ss = ".$position[2].";");
|
||||
$bdd->deconnexion();
|
||||
}
|
||||
else
|
||||
die('Erreur #04 : Format de recherche d\'asteroide incorrect !');
|
||||
|
||||
if (!empty($plan))
|
||||
{
|
||||
$this->id = $plan["id"];
|
||||
parent::User($sess->values['id']); //On utilise le numéro d'utilisateur enregistré en session
|
||||
$this->galaxie = $plan["galaxie"];
|
||||
$this->ss = $plan["ss"];
|
||||
$this->image = $plan["image"];
|
||||
$this->debris_met = $plan["debris_met"];
|
||||
$this->debris_cri = $plan["debris_cri"];
|
||||
$this->metal = $plan["metal"];
|
||||
$this->cristal = $plan["cristal"];
|
||||
$this->hydrogene = $plan["hydrogene"];
|
||||
|
||||
foreach($alli_batimentVAR as $bat)
|
||||
$this->alli_batiments[] = $plan[$bat];
|
||||
if (!empty($plan["file_bat"]))
|
||||
$this->file_bat = unserialize($plan["file_bat"]);
|
||||
else
|
||||
$this->file_bat = array();
|
||||
|
||||
foreach($nomvaisnVAR as $vais)
|
||||
$this->vaisseaux[] = $plan[$vais];
|
||||
if (!empty($plan["file_vais"]))
|
||||
$this->file_vais = unserialize($plan["file_vais"]);
|
||||
else
|
||||
$this->file_vais = array();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Actualise les ressources de la planète en fonction de la production et termine les files d'attentes.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
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.');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifie si la planète est isolée ou non
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function isolement()
|
||||
{
|
||||
$return = false;
|
||||
|
||||
global $var___db, $config, $table_planete;
|
||||
$bdd = new BDD();
|
||||
$bdd->connexion();
|
||||
$plan = $bdd->query("SELECT id FROM $table_planete WHERE id_user = ".$this->id_user." ORDER BY id;");
|
||||
$bdd->deconnexion();
|
||||
|
||||
$numP = 0;
|
||||
foreach ($plan as $key => $p)
|
||||
{
|
||||
if ($p['id'] == $this->id)
|
||||
$numP = $key + 1;
|
||||
}
|
||||
|
||||
if ($numP >= 11)
|
||||
{
|
||||
if (!isset($this->isolement[0]) || (time() > $this->isolement[0] && (!isset($this->isolement[1]) || (time() > $this->isolement[1] && date('dmY') != date('dmY', $this->isolement[0])))))
|
||||
{
|
||||
switch($numP)
|
||||
{
|
||||
case 11:
|
||||
$tps = 2;
|
||||
break;
|
||||
case 12:
|
||||
$tps = 4;
|
||||
break;
|
||||
case 13:
|
||||
$tps = 6;
|
||||
break;
|
||||
case 14:
|
||||
$tps = 8;
|
||||
break;
|
||||
case 15:
|
||||
$tps = 12;
|
||||
break;
|
||||
case 16:
|
||||
$tps = 16;
|
||||
break;
|
||||
case 17:
|
||||
$tps = 20;
|
||||
break;
|
||||
default:
|
||||
$tps = 24;
|
||||
}
|
||||
$debut = mktime(rand(0, 24-$tps), 0, 0, date('n'), date('j'), date('Y'));
|
||||
$fin = $debut + $tps * 3600;
|
||||
|
||||
$this->isolement[0] = $debut;
|
||||
if (time() > $this->isolement[0])
|
||||
$this->isolement[1] = $fin;
|
||||
if (!in_array('isolement', $this->modif))
|
||||
$this->modif[] = 'isolement';
|
||||
}
|
||||
if (isset($this->isolement[1]) && time() < $this->isolement[1])
|
||||
$return = true;
|
||||
}
|
||||
elseif (!isset($this->isolement[0]))
|
||||
{
|
||||
$this->isolement = array(0,0);
|
||||
if (!in_array('isolement', $this->modif))
|
||||
$this->modif[] = 'isolement';
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
//Accélération de la production
|
||||
$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;
|
||||
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++)
|
||||
{
|
||||
$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';
|
||||
}
|
||||
}
|
||||
|
||||
//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)
|
||||
{
|
||||
$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 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;
|
||||
$prod_cri *= 1.10;
|
||||
$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);
|
||||
}
|
||||
|
||||
function creer($id_user)
|
||||
{
|
||||
//Définition des paramètres de l'utilisateur pour la planète
|
||||
$this->id_user = $id_user;
|
||||
|
||||
//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);
|
||||
}
|
||||
|
||||
//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");
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructeur
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function __destruct()
|
||||
{
|
||||
if (empty($this->ss) || empty($this->id_user))
|
||||
return;
|
||||
if ($this->id_user == 1)
|
||||
var_dump($this);
|
||||
|
||||
global $var___db, $config, $table_planete;
|
||||
if (empty($this->id))
|
||||
{
|
||||
$out1 = array(); $out2 = array();
|
||||
$bdd = new bdd();
|
||||
$bdd->connexion();
|
||||
foreach($this->modif as $modif)
|
||||
{
|
||||
if (!is_array($this->{$modif}))
|
||||
{
|
||||
$bdd->escape($this->{$modif});
|
||||
$out1[] = $modif;
|
||||
if (is_int($this->{$modif}) || is_float($this->{$modif}))
|
||||
$out2[] = $this->{$modif};
|
||||
else
|
||||
$out2[] = "'".$this->{$modif}."'";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (is_array($this->{$modif}) && $modif != "coeff_bat" && $modif != "vaisseaux" && $modif != "terrestres" && $modif != "casernes" && $modif != "technologies" && $modif != "batiments")
|
||||
{
|
||||
$prep = serialize($this->{$modif});
|
||||
$bdd->escape($prep);
|
||||
$out1[] = $modif;
|
||||
$out2[] = "'$prep'";
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($modif == "batiments")
|
||||
$calc = "batiment";
|
||||
elseif ($modif == "technologies")
|
||||
$calc = "technolo";
|
||||
elseif ($modif == "casernes")
|
||||
$calc = "casernen";
|
||||
elseif ($modif == "terrestres")
|
||||
$calc = "nomterrn";
|
||||
elseif ($modif == "vaisseaux")
|
||||
$calc = "nomvaisn";
|
||||
elseif ($modif == "coeff_bat")
|
||||
$calc = "coeff";
|
||||
|
||||
if (!isset(${$calc.'VAR'}))
|
||||
global ${$calc.'VAR'};
|
||||
|
||||
foreach($this->{$modif} as $j => $value)
|
||||
{
|
||||
$out1[] = ${$calc.'VAR'}[$j];
|
||||
$out2[] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$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->deconnexion();
|
||||
}
|
||||
else
|
||||
{
|
||||
$nb = count($this->modif);
|
||||
$out = array();
|
||||
$bdd = new bdd();
|
||||
$bdd->connexion();
|
||||
for($i = 0; $i < $nb; $i++)
|
||||
{
|
||||
if ($this->modif[$i] == 'technologies')
|
||||
$this->modifUser[] = $this->modif[$i];
|
||||
elseif (!is_array($this->{$this->modif[$i]}))
|
||||
{
|
||||
$bdd->escape($this->{$this->modif[$i]});
|
||||
if (is_int($this->{$this->modif[$i]}) || is_float($this->{$this->modif[$i]}))
|
||||
$out[] = $this->modif[$i]." = ".$this->{$this->modif[$i]};
|
||||
else
|
||||
$out[] = $this->modif[$i]." = '".$this->{$this->modif[$i]}."'";
|
||||
}
|
||||
else
|
||||
{
|
||||
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'";
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($this->modif[$i] == "batiments")
|
||||
$calc = "batiment";
|
||||
elseif ($this->modif[$i] == "technologies")
|
||||
$calc = "technolo";
|
||||
elseif ($this->modif[$i] == "casernes")
|
||||
$calc = "casernen";
|
||||
elseif ($this->modif[$i] == "terrestres")
|
||||
$calc = "nomterrn";
|
||||
elseif ($this->modif[$i] == "vaisseaux")
|
||||
$calc = "nomvaisn";
|
||||
elseif ($this->modif[$i] == "coeff_bat")
|
||||
$calc = "coeff";
|
||||
|
||||
if (!isset(${$calc.'VAR'}))
|
||||
global ${$calc.'VAR'};
|
||||
|
||||
$nombr = count(${$calc.'VAR'});
|
||||
for($j = 0; $j < $nombr; $j++)
|
||||
{
|
||||
$bdd->escape($this->{$this->modif[$i]}[$j]);
|
||||
$out[] = ${$calc.'VAR'}[$j]." = ".$this->{$this->modif[$i]}[$j]."";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($out))
|
||||
$plan = $bdd->query("UPDATE $table_planete SET ".implode(', ', $out)." WHERE id = ".$this->id.";");
|
||||
|
||||
$bdd->deconnexion();
|
||||
parent::__destruct();
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
include_once(_FCORE."../game/Class/class.rapport.php");
|
||||
/***************************************************************************
|
||||
* class.flotte.php
|
||||
* ------------------
|
||||
|
|
@ -8,284 +9,584 @@
|
|||
*
|
||||
*
|
||||
***************************************************************************/
|
||||
class Flotte{
|
||||
var $id_flotte = 0,
|
||||
$nom,
|
||||
$start_planete,
|
||||
$start_time,
|
||||
$end_planete,
|
||||
$end_time,
|
||||
$ret_planete,
|
||||
$ret_time,
|
||||
$nb_vais,
|
||||
$vaisseaux = array(),
|
||||
$tactique = 0,
|
||||
$mission,
|
||||
$vitesse,
|
||||
$statut = 0,
|
||||
$last,
|
||||
$contenu = array(0,0,0),
|
||||
$contenuMax = 0,
|
||||
$modifFlotte = array();
|
||||
class Flotte
|
||||
{
|
||||
var $id_flotte = 0,
|
||||
$nom,
|
||||
$start_planete,
|
||||
$start_time,
|
||||
$end_planete,
|
||||
$end_time,
|
||||
$ret_planete,
|
||||
$ret_time,
|
||||
$nb_vais,
|
||||
$vaisseaux = array(),
|
||||
$tactique = 0,
|
||||
$mission,
|
||||
$vitesse,
|
||||
$statut = 0,
|
||||
$last,
|
||||
$contenu = array(0,0,0),
|
||||
$contenuMax = 0,
|
||||
$modifFlotte = array();
|
||||
|
||||
/**
|
||||
* Constructeur
|
||||
* @param int $id id de la flotte à importer
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function Flotte($id = 0){
|
||||
if (!empty($id)) {
|
||||
global $var___db, $config, $table_flottes;
|
||||
global $nomvaisnVAR, $ressoVAR;
|
||||
$bdd = new bdd();
|
||||
$bdd->connexion();
|
||||
$bdd->escape($id);
|
||||
$flotte = $bdd->unique_query("SELECT * FROM $table_flottes WHERE id = $id;");
|
||||
$bdd->query("UPDATE $table_flottes SET last = ".time()." WHERE id = $id;"); //Obtention d'un vérrou de 10 seconde sur la flotte
|
||||
$bdd->deconnexion();
|
||||
if (!empty($flotte)) {
|
||||
$this->id_flotte = $flotte["id"];
|
||||
$this->nom = $flotte["nom"];
|
||||
$this->start_planete = $flotte["start_planete"];
|
||||
$this->start_time = $flotte["start_time"];
|
||||
$this->end_planete = $flotte["end_planete"];
|
||||
$this->end_time = $flotte["end_time"];
|
||||
$this->ret_planete = $flotte["ret_planete"];
|
||||
$this->ret_time = $flotte["ret_time"];
|
||||
$this->tactique = $flotte["tactique"];
|
||||
$this->mission = $flotte["mission"];
|
||||
$this->statut = $flotte["statut"];
|
||||
$this->last = $flotte["last"];
|
||||
$this->nb_vais = $flotte["nb_vais"];
|
||||
/**
|
||||
* Constructeur
|
||||
* @param int $id id de la flotte à importer
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function Flotte($id = 0)
|
||||
{
|
||||
if (!empty($id))
|
||||
{
|
||||
global $var___db, $config, $table_flottes;
|
||||
global $nomvaisnVAR, $ressoVAR;
|
||||
$bdd = new bdd();
|
||||
$bdd->connexion();
|
||||
$bdd->escape($id);
|
||||
$flotte = $bdd->unique_query("SELECT * FROM $table_flottes WHERE id = $id;");
|
||||
$bdd->query("UPDATE $table_flottes SET last = ".time()." WHERE id = $id;"); //Obtention d'un vérrou de 10 seconde sur la flotte
|
||||
$bdd->deconnexion();
|
||||
if (!empty($flotte))
|
||||
{
|
||||
$this->id_flotte = $flotte["id"];
|
||||
$this->nom = $flotte["nom"];
|
||||
$this->start_planete = $flotte["start_planete"];
|
||||
$this->start_time = $flotte["start_time"];
|
||||
$this->end_planete = $flotte["end_planete"];
|
||||
$this->end_time = $flotte["end_time"];
|
||||
$this->ret_planete = $flotte["ret_planete"];
|
||||
$this->ret_time = $flotte["ret_time"];
|
||||
$this->tactique = $flotte["tactique"];
|
||||
$this->mission = $flotte["mission"];
|
||||
$this->vitesse = $flotte["vitesse"];
|
||||
$this->statut = $flotte["statut"];
|
||||
$this->last = $flotte["last"];
|
||||
$this->nb_vais = $flotte["nb_vais"];
|
||||
|
||||
foreach($nomvaisnVAR as $vais){
|
||||
$this->vaisseaux[] = $flotte[$vais];
|
||||
}
|
||||
foreach($nomvaisnVAR as $vais)
|
||||
$this->vaisseaux[] = $flotte[$vais];
|
||||
|
||||
$this->contenu = array($flotte["contenu_metal"], $flotte["contenu_cristal"], $flotte["contenu_hydrogene"]);
|
||||
$this->contenu = array($flotte["contenu_metal"], $flotte["contenu_cristal"], $flotte["contenu_hydrogene"]);
|
||||
|
||||
$this->calculer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function calculer(){
|
||||
global $nomvais_rs;
|
||||
|
||||
$this->nb_vais = 0;
|
||||
|
||||
//Calcul de la capacité maximale d'embarquement de la flotte
|
||||
foreach($this->vaisseaux as $key => $vais){
|
||||
$this->nb_vais += $vais;
|
||||
$this->contenuMax += $nomvais_rs[$key] * $vais;
|
||||
}
|
||||
}
|
||||
|
||||
function load_planete(){
|
||||
if (is_numeric($this->start_planete) && !empty($this->start_planete)) {
|
||||
$this->start_planete = new Planete($this->start_planete);
|
||||
}
|
||||
if (is_numeric($this->end_planete) && !empty($this->end_planete)) {
|
||||
$this->end_planete = new Planete($this->end_planete);
|
||||
}
|
||||
if (is_numeric($this->ret_planete) && !empty($this->ret_planete)) {
|
||||
$this->ret_planete = new Planete($this->ret_planete);
|
||||
}
|
||||
}
|
||||
|
||||
function calc_deplacement($start_galaxie, $start_systeme, $start_position, $end_galaxie, $end_systeme, $end_position, $vitesse, $returnArray = false, $returnConso = false){
|
||||
//Si la planète de départ n'est pas chargée, on charge les planètes
|
||||
if (is_numeric($this->start_planete)) $this->load_planete();
|
||||
global $config, $nomvais_vitesseP, $nomvais_vitesseS, $nomvais_vitesseG, $nomvais_rs;
|
||||
$this->vitesse = $vitesse;
|
||||
|
||||
//Calcul de la longueur du déplacement
|
||||
$diff_galaxie = abs($start_galaxie - $end_galaxie);
|
||||
$diff_systeme = abs($start_systeme - $end_systeme);
|
||||
$diff_position = abs($start_position - $end_position);
|
||||
|
||||
$diff_centre_position_start = abs(ceil($config['nb_amas']/2) - $start_position);
|
||||
$diff_centre_systeme_start = abs(ceil($config['nb_systeme']/2) - $start_systeme);
|
||||
|
||||
$diff_centre_position_end = abs(ceil($config['nb_amas']/2) - $end_position);
|
||||
$diff_centre_systeme_end = abs(ceil($config['nb_systeme']/2) - $end_systeme);
|
||||
|
||||
//Calcul du temps de déplacement pour chaque vaisseau
|
||||
$temps = array(); $conso = array(0, 0, 0);
|
||||
foreach($this->vaisseaux as $key => $vais){
|
||||
//S'il n'y a pas de vaisseaux de ce type, on ne calcul pas leur vitesse
|
||||
if ($vais == 0) continue;
|
||||
|
||||
//Calcul du temps de déplacement entre planètes
|
||||
if ($start_systeme == $end_systeme && $start_galaxie == $end_galaxie) {
|
||||
$temps[0][$key] = (10/$nomvais_vitesseP[$key]) * (1 + 0.1 * $diff_position);
|
||||
$temps[1][$key] = $temps[2][$key] = 0;
|
||||
}
|
||||
//Calcul du temps de déplacement entre système
|
||||
elseif ($start_galaxie == $end_galaxie) {
|
||||
$temps[0][$key] = (10/$nomvais_vitesseP[$key]) * (1 + 0.1 * ($diff_centre_position_start + $diff_centre_position_end));
|
||||
$temps[1][$key] = (20/$nomvais_vitesseS[$key]) * (2 + 1 * $diff_systeme);
|
||||
$temps[2][$key] = 0;
|
||||
}
|
||||
//Calcul du temps de déplacement entre galaxies
|
||||
else {
|
||||
$temps[0][$key] = (10/$nomvais_vitesseP[$key]) * (1 + 0.1 * ($diff_centre_position_start + $diff_centre_position_end));
|
||||
$temps[1][$key] = (20/$nomvais_vitesseS[$key]) * (2 + 1 * ($diff_centre_systeme_start + $diff_centre_systeme_end));
|
||||
$temps[2][$key] = (50/$nomvais_vitesseG[$key]) * (2 + 1.5 * $diff_galaxie);
|
||||
}
|
||||
|
||||
//Calcul du bonus pour le réacteur à combustion
|
||||
$techR = $this->start_planete->technologies[1];
|
||||
if ($techR & 56) $bonus = 0.7;
|
||||
elseif ($techR & 24) $bonus = 0.8;
|
||||
elseif ($techR & 8) $bonus = 0.9;
|
||||
else $bonus = 1;
|
||||
$temps[0][$key] *= $bonus * 1/$vitesse;
|
||||
$conso[0] += $vais * $temps[0][$key] * $bonus / exp($vitesse/5);
|
||||
|
||||
//Calcul du bonus pour le réacteur à fusion
|
||||
$techR = $this->start_planete->technologies[1];
|
||||
if ($techR & 448) $bonus = 0.7;
|
||||
elseif ($techR & 192) $bonus = 0.8;
|
||||
elseif ($techR & 64) $bonus = 0.9;
|
||||
else $bonus = 1;
|
||||
$temps[1][$key] *= $bonus * 1/$vitesse;
|
||||
$conso[1] += $vais * $temps[1][$key] * $bonus / exp($vitesse/7.5);
|
||||
|
||||
//Calcul du bonus pour le réacteur à fusion de type II
|
||||
$techR = $this->start_planete->technologies[1];
|
||||
if ($techR & 3584) $bonus = 0.7;
|
||||
elseif ($techR & 1536) $bonus = 0.8;
|
||||
elseif ($techR & 512) $bonus = 0.9;
|
||||
else $bonus = 1;
|
||||
$temps[2][$key] *= $bonus * 1/$vitesse;
|
||||
$conso[2] += $vais * $temps[2][$key] * $bonus / exp($vitesse/10);
|
||||
}
|
||||
|
||||
if (!isset($this->vaisseaux[4])) $this->vaisseaux[4] = 0;
|
||||
if (!isset($this->vaisseaux[5])) $this->vaisseaux[5] = 0;
|
||||
|
||||
//Si les chasseurs peuvent rentrer dans les cales des vaisseaux, on les enlèves
|
||||
if ($this->contenuMax - ($this->contenu[0] + $this->contenu[1] + $this->contenu[2]) - ($this->vaisseaux[4] * $nomvais_rs[4] + $this->vaisseaux[5] * $nomvais_rs[5]) >= ($this->vaisseaux[4] + $this->vaisseaux[5]) * 200) {
|
||||
$temps[2][4] = $temps[2][5] = $temps[1][4] = $temps[1][5] = $temps[0][4] = $temps[0][5] = 0;
|
||||
}
|
||||
|
||||
//On calcul le temps de déplacement maximal
|
||||
if ($returnArray) return $temps;
|
||||
elseif ($returnConso) return array(max($temps[0]) + max($temps[1]) + max($temps[2]), ceil($conso[0]+$conso[1]+$conso[2]));
|
||||
else return (max($temps[0]) + max($temps[1]) + max($temps[2]));
|
||||
}
|
||||
|
||||
function check_mission(){
|
||||
//On vérifie qu'un calcul ne soit pas déjà en cours
|
||||
if ($this->last >= time() - 10) return false;
|
||||
elseif ($this->start_time + $this->end_time < time()) return false;
|
||||
elseif ($this->statut == 1 && ($this->ret_time > time() || $this->start_time + $this->end_time * 2 >= time())) return $this->retourner();
|
||||
|
||||
switch($this->mission){
|
||||
case 0:
|
||||
case 5:
|
||||
return $this->stationner();
|
||||
break;
|
||||
case 1:
|
||||
return $this->transporter();
|
||||
break;
|
||||
case 2:
|
||||
return $this->coloniser();
|
||||
break;
|
||||
case 3:
|
||||
return $this->espionner();
|
||||
break;
|
||||
case 4:
|
||||
return $this->attaquer();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function rappeler(){
|
||||
if ($this->start_time + $this->end_time >= time()) return false;
|
||||
else {
|
||||
$this->end_time = time() - $this->start_time + 10;
|
||||
$this->mission = 5;
|
||||
if (!in_array('mission', $this->modifFlotte)) $this->modifFlotte[] = 'mission';
|
||||
if (!in_array('end_time', $this->modifFlotte)) $this->modifFlotte[] = 'end_time';
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function retourner(){
|
||||
//Si la planète de départ n'est pas chargée, on charge les planètes
|
||||
if (is_numeric($this->start_planete)) $this->load_planete();
|
||||
|
||||
//Si on a demandé une planète particulière au retour
|
||||
if (!empty($this->ret_time) && !empty($this->ret_planete) && !is_numeric($this->ret_planete)) {
|
||||
foreach($this->vaisseaux as $key => $vais){
|
||||
$this->ret_planete->vaisseaux[$key] += $vais;
|
||||
}
|
||||
}
|
||||
//Si le retour se fait sur la planète source
|
||||
else {
|
||||
foreach($this->vaisseaux as $key => $vais){
|
||||
$this->start_planete->vaisseaux[$key] += $vais;
|
||||
}
|
||||
}
|
||||
$this->modifFlotte = "DELETE";
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructeur
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function __destruct(){
|
||||
global $var___db, $config, $table_flottes;
|
||||
$nb = count($this->modifFlotte);
|
||||
$out = array();
|
||||
$bdd = new bdd();
|
||||
$bdd->connexion();
|
||||
if ($this->modifFlotte === "DELETE") $bdd->query("DELETE FROM $table_flottes WHERE id = ".$this->id_flotte.";");
|
||||
else {
|
||||
if (empty($this->id_flotte)) {
|
||||
if ($this->modifFlotte === "INSERT") {
|
||||
$out1 = ''; $out2 = '';
|
||||
global $nomvaisnVAR;
|
||||
foreach ($this->vaisseaux as $key => $vais){
|
||||
$out1 .= ', '.$nomvaisnVAR[$key];
|
||||
$out2 .= ', '.$vais;
|
||||
$this->calculer();
|
||||
}
|
||||
}
|
||||
$sql = "INSERT INTO $table_flottes (id_user, mission, start_time, start_planete, end_time, end_planete, vitesse, contenu_metal, contenu_cristal, contenu_hydrogene, tactique, nom, nbvais$out1) VALUES ('".$this->start_planete->id_user."', '".$this->mission."', '".$this->start_time."', '".$this->start_planete->id."', '".$this->end_time."', '".$this->end_planete."', '".$this->vitesse."', '".$this->contenu[0]."', '".$this->contenu[1]."', '".$this->contenu[2]."', '".$this->tactique."', '".$this->nom.", ".$nb_vais."'$out2);";
|
||||
//var_dump($sql);
|
||||
$bdd->query($sql);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for($i = 0; $i < $nb; $i++){
|
||||
if (!is_array($this->{$this->modifFlotte[$i]})) {
|
||||
$bdd->escape($this->{$this->modifFlotte[$i]});
|
||||
if (is_int($this->{$this->modifFlotte[$i]}) || is_float($this->{$this->modifFlotte[$i]})) $out[] .= $this->modifFlotte[$i]." = ".$this->{$this->modifFlotte[$i]};
|
||||
else $out[] .= $this->modifFlotte[$i]." = '".$this->{$this->modifFlotte[$i]}."'";
|
||||
}
|
||||
else {
|
||||
if ($this->modifFlotte[$i] == "contenu") $calc = "resso";
|
||||
elseif ($this->modifFlotte[$i] == "vaisseaux") $calc = "nomvaisn";
|
||||
|
||||
if (!isset(${$calc.'VAR'})) global ${$calc.'VAR'};
|
||||
|
||||
$nombr = count(${$calc.'VAR'});
|
||||
for($j = 0; $j < $nombr; $j++){
|
||||
$bdd->escape($this->{$this->modifFlotte[$i]}[$j]);
|
||||
$out[] = ${$calc.'VAR'}[$j]." = ".$this->{$this->modifFlotte[$i]}[$j];
|
||||
}
|
||||
function calculer()
|
||||
{
|
||||
global $nomvais_rs;
|
||||
|
||||
$this->nb_vais = 0;
|
||||
|
||||
//Calcul de la capacité maximale d'embarquement de la flotte
|
||||
foreach($this->vaisseaux as $key => $vais)
|
||||
{
|
||||
$this->nb_vais += $vais;
|
||||
$this->contenuMax += $nomvais_rs[$key] * $vais;
|
||||
}
|
||||
}
|
||||
if (!empty($out)) $bdd->query("UPDATE $table_flottes SET ".implode(', ', $out).", last = 0 WHERE id = ".$this->id_flotte.";");
|
||||
else $bdd->query("UPDATE $table_flottes SET last = 0 WHERE id = ".$this->id_flotte.";");
|
||||
}
|
||||
}
|
||||
$bdd->deconnexion();
|
||||
|
||||
|
||||
function load_planete()
|
||||
{
|
||||
if (is_numeric($this->start_planete) && !empty($this->start_planete))
|
||||
{
|
||||
global $planete;
|
||||
//Si la planète est la même que celle du joueur actuel, on l'utilise, sinon, on la crée
|
||||
if ($planete->id == $this->start_planete)
|
||||
$this->start_planete = $planete;
|
||||
else
|
||||
$this->start_planete = new Planete($this->start_planete);
|
||||
}
|
||||
if (is_numeric($this->end_planete) && !empty($this->end_planete))
|
||||
{
|
||||
global $planete;
|
||||
//Si la planète est la même que celle du joueur actuel, on l'utilise, sinon, on la crée
|
||||
if ($planete->id == $this->end_planete)
|
||||
$this->end_planete = $planete;
|
||||
else
|
||||
$this->end_planete = new Planete($this->end_planete);
|
||||
}
|
||||
if (is_numeric($this->ret_planete) && !empty($this->ret_planete))
|
||||
{
|
||||
global $planete;
|
||||
//Si la planète est la même que celle du joueur actuel, on l'utilise, sinon, on la crée
|
||||
if ($planete->id == $this->ret_planete)
|
||||
$this->ret_planete = $planete;
|
||||
else
|
||||
$this->ret_planete = new Planete($this->ret_planete);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function calc_deplacement($start_galaxie, $start_systeme, $start_position, $end_galaxie, $end_systeme, $end_position, $vitesse, $returnArray = false, $returnConso = false)
|
||||
{
|
||||
//Si la planète de départ n'est pas chargée, on charge les planètes
|
||||
if (is_numeric($this->start_planete))
|
||||
$this->load_planete();
|
||||
global $config, $nomvais_vitesseP, $nomvais_vitesseS, $nomvais_vitesseG, $nomvais_rs;
|
||||
$this->vitesse = $vitesse;
|
||||
|
||||
//Calcul de la longueur du déplacement
|
||||
$diff_galaxie = abs($start_galaxie - $end_galaxie);
|
||||
$diff_systeme = abs($start_systeme - $end_systeme);
|
||||
$diff_position = abs($start_position - $end_position);
|
||||
|
||||
$diff_centre_position_start = abs(ceil($config['nb_amas']/2) - $start_position);
|
||||
$diff_centre_systeme_start = abs(ceil($config['nb_systeme']/2) - $start_systeme);
|
||||
|
||||
$diff_centre_position_end = abs(ceil($config['nb_amas']/2) - $end_position);
|
||||
$diff_centre_systeme_end = abs(ceil($config['nb_systeme']/2) - $end_systeme);
|
||||
|
||||
//Calcul du temps de déplacement pour chaque vaisseau
|
||||
$temps = array(); $conso = array(0, 0, 0);
|
||||
foreach($this->vaisseaux as $key => $vais)
|
||||
{
|
||||
//S'il n'y a pas de vaisseaux de ce type, on ne calcul pas leur vitesse
|
||||
if ($vais == 0)
|
||||
continue;
|
||||
|
||||
//Calcul du temps de déplacement entre planètes
|
||||
if ($start_systeme == $end_systeme && $start_galaxie == $end_galaxie)
|
||||
{
|
||||
$temps[0][$key] = (10/$nomvais_vitesseP[$key]) * (1 + 0.1 * $diff_position);
|
||||
$temps[1][$key] = $temps[2][$key] = 0;
|
||||
}
|
||||
//Calcul du temps de déplacement entre système
|
||||
elseif ($start_galaxie == $end_galaxie)
|
||||
{
|
||||
$temps[0][$key] = (10/$nomvais_vitesseP[$key]) * (1 + 0.1 * ($diff_centre_position_start + $diff_centre_position_end));
|
||||
$temps[1][$key] = (20/$nomvais_vitesseS[$key]) * (2 + 1 * $diff_systeme);
|
||||
$temps[2][$key] = 0;
|
||||
}
|
||||
//Calcul du temps de déplacement entre galaxies
|
||||
else
|
||||
{
|
||||
$temps[0][$key] = (10/$nomvais_vitesseP[$key]) * (1 + 0.1 * ($diff_centre_position_start + $diff_centre_position_end));
|
||||
$temps[1][$key] = (20/$nomvais_vitesseS[$key]) * (2 + 1 * ($diff_centre_systeme_start + $diff_centre_systeme_end));
|
||||
$temps[2][$key] = (50/$nomvais_vitesseG[$key]) * (2 + 1.5 * $diff_galaxie);
|
||||
}
|
||||
|
||||
//Calcul du bonus pour le réacteur à combustion
|
||||
$techR = $this->start_planete->technologies[1];
|
||||
if ($techR & 56)
|
||||
$bonus = 0.7;
|
||||
elseif ($techR & 24)
|
||||
$bonus = 0.8;
|
||||
elseif ($techR & 8)
|
||||
$bonus = 0.9;
|
||||
else
|
||||
$bonus = 1;
|
||||
$temps[0][$key] *= $bonus * 1/$vitesse;
|
||||
$conso[0] += $vais * $temps[0][$key] * $bonus / exp($vitesse/5);
|
||||
|
||||
//Calcul du bonus pour le réacteur à fusion
|
||||
$techR = $this->start_planete->technologies[1];
|
||||
if ($techR &448)
|
||||
$bonus = 0.7;
|
||||
elseif ($techR &192)
|
||||
$bonus = 0.8;
|
||||
elseif ($techR &64)
|
||||
$bonus = 0.9;
|
||||
else
|
||||
$bonus = 1;
|
||||
$temps[1][$key] *= $bonus * 1/$vitesse;
|
||||
$conso[1] += $vais * $temps[1][$key] * $bonus / exp($vitesse/7.5);
|
||||
|
||||
//Calcul du bonus pour le réacteur à fusion de type II
|
||||
$techR = $this->start_planete->technologies[1];
|
||||
if ($techR &3584)
|
||||
$bonus = 0.7;
|
||||
elseif ($techR &1536)
|
||||
$bonus = 0.8;
|
||||
elseif ($techR &512)
|
||||
$bonus = 0.9;
|
||||
else
|
||||
$bonus = 1;
|
||||
$temps[2][$key] *= $bonus * 1/$vitesse;
|
||||
$conso[2] += $vais * $temps[2][$key] * $bonus / exp($vitesse/10);
|
||||
}
|
||||
|
||||
if (!isset($this->vaisseaux[4]))
|
||||
$this->vaisseaux[4] = 0;
|
||||
if (!isset($this->vaisseaux[5]))
|
||||
$this->vaisseaux[5] = 0;
|
||||
|
||||
//Si les chasseurs peuvent rentrer dans les cales des vaisseaux, on les enlèves
|
||||
if ($this->contenuMax - ($this->contenu[0] + $this->contenu[1] + $this->contenu[2]) - ($this->vaisseaux[4] * $nomvais_rs[4] + $this->vaisseaux[5] * $nomvais_rs[5]) >= ($this->vaisseaux[4] + $this->vaisseaux[5]) * 200)
|
||||
$temps[2][4] = $temps[2][5] = $temps[1][4] = $temps[1][5] = $temps[0][4] = $temps[0][5] = 0;
|
||||
|
||||
//On calcul le temps de déplacement maximal
|
||||
if ($returnArray)
|
||||
return $temps;
|
||||
elseif ($returnConso)
|
||||
return array(max($temps[0]) + max($temps[1]) + max($temps[2]), ceil($conso[0]+$conso[1]+$conso[2]));
|
||||
else
|
||||
return (max($temps[0]) + max($temps[1]) + max($temps[2]));
|
||||
}
|
||||
|
||||
|
||||
function check_mission()
|
||||
{
|
||||
//On vérifie qu'un calcul ne soit pas déjà en cours
|
||||
if ($this->last >= time() - 10)
|
||||
return false;
|
||||
elseif ($this->start_time + $this->end_time > time())
|
||||
return false;
|
||||
|
||||
if ($this->statut == 0)
|
||||
{
|
||||
switch($this->mission)
|
||||
{
|
||||
case 0:
|
||||
return $this->stationner();
|
||||
break;
|
||||
case 1:
|
||||
return $this->transporter();
|
||||
break;
|
||||
case 2:
|
||||
return $this->coloniser();
|
||||
break;
|
||||
case 3:
|
||||
return $this->attaquer();
|
||||
break;
|
||||
case 4:
|
||||
return $this->recycler();
|
||||
break;
|
||||
case 5:
|
||||
return $this->espionner();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->statut == 1 && ($this->ret_time > time() || $this->start_time + $this->end_time * 2 <= time()))
|
||||
return $this->retourner();
|
||||
}
|
||||
|
||||
|
||||
function stationner()
|
||||
{
|
||||
//On décharge les ressources éventuellement contenue
|
||||
$this->decharger();
|
||||
|
||||
//On fait atterir les vaisseaux
|
||||
foreach ($this->vaisseaux as $key => $vais)
|
||||
$this->end_planete->vaisseaux[$key] += $vais;
|
||||
|
||||
if (!in_array("vaisseaux", $this->end_planete->modif))
|
||||
$this->end_planete->modif[] = "vaisseaux";
|
||||
$this->modifFlotte = "DELETE";
|
||||
}
|
||||
|
||||
|
||||
function transporter()
|
||||
{
|
||||
$max = $this->decharger();
|
||||
|
||||
//Envoie du MP de confirmation au joueur
|
||||
$send = new Rapport(2, $this->start_planete->id_user, $this->end_planete->id_user, $this->start_time + $this->end_time);
|
||||
$send->addInfo(array($this->end_planete->nom_planete, $this->end_planete->galaxie, $this->end_planete->ss, $this->end_planete->position), 0);
|
||||
$send->addInfo($max, 1);
|
||||
|
||||
$this->statut = 1;
|
||||
if (!in_array('statut', $this->modifFlotte))
|
||||
$this->modifFlotte[] = 'statut';
|
||||
}
|
||||
|
||||
|
||||
function coloniser()
|
||||
{
|
||||
//On vérifie que les coordonnées de la planètes sont bien enregistrée
|
||||
if (empty($this->end_planete) || is_object($this->end_planete) || !preg_match('#^\[?([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})\]?$#', $this->end_planete))
|
||||
{
|
||||
$this->load_planete();
|
||||
file_log("Erreur de colonisation de la planète : ".$this->end_planete." pour le joueur : ".$this->start_planete->id_user, 2);
|
||||
send_mp($this->start_planete->id_user, "Erreur de colonisation [F#01]", "Une erreur s'est produite lors de la tentative de colonisation de votre flotte, elle a fait demi-tour.");
|
||||
$this->rappeler();
|
||||
}
|
||||
|
||||
//On vérifie que la planète ne soit pas déjà colonisée
|
||||
global $var___db, $config, $table_planete;
|
||||
$bdd = new bdd();
|
||||
preg_match('#^\[?([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})\]?$#', $this->end_planete, $position);
|
||||
$bdd->connexion();
|
||||
$p = $bdd->query("SELECT * FROM $table_planete WHERE galaxie = ".$position[1]." AND ss = ".$position[2]." AND position = ".$position[3].";");
|
||||
$bdd->deconnexion();
|
||||
|
||||
if ($p)
|
||||
{
|
||||
$this->load_planete();
|
||||
|
||||
$rapport = new Rapport(2, $this->start_planete->id_user, 0, $this->start_time + $this->end_time);
|
||||
$rapport->addInfo(array($position[1], $position[2], $position[3]), 0);
|
||||
$rapport->addInfo(false, 1);
|
||||
$rapport->send();
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->load_planete();
|
||||
|
||||
//On crée la planète
|
||||
$this->end_planete = new Planete();
|
||||
$this->end_planete->galaxie = $position[1];
|
||||
$this->end_planete->ss = $position[2];
|
||||
$this->end_planete->position = $position[3];
|
||||
$this->end_planete->creer($this->start_planete->id_user);
|
||||
|
||||
//Rembousement du carburant non utilisé (la colonisation prévois au départ un allé/retour)
|
||||
$conso = $this->calc_deplacement($this->start_planete->galaxie, $this->start_planete->ss, $this->start_planete->position, $position[1], $position[2], $position[3], $this->vitesse, false, true);
|
||||
$this->end_planete->hydrogene += $conso[1];
|
||||
|
||||
//On définit la limite de ressources pour permettre le déchargement de celles contenues dans les vaisseaux
|
||||
$this->end_planete->cap = 100000;
|
||||
|
||||
//On enlève un vaisseau de colonisation de la liste
|
||||
$this->vaisseaux[2]--;
|
||||
|
||||
//On fait atterir les vaisseaux et décharger les ressources
|
||||
$this->decharger();
|
||||
$this->atterir();
|
||||
|
||||
//On envoie un rapport
|
||||
$rapport = new Rapport(2, $this->start_planete->id_user, 0, $this->start_time + $this->end_time);
|
||||
$rapport->addInfo(array($position[1], $position[2], $position[3]), 0);
|
||||
$rapport->addInfo(true, 1);
|
||||
$rapport->send();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function recycler()
|
||||
{
|
||||
//Si la planète d'arrivé n'est pas chargée, on charge les planètes
|
||||
if (is_numeric($this->end_planete))
|
||||
$this->load_planete();
|
||||
|
||||
$coeff = ($this->contenuMax - $this->contenu[0] - $this->contenu[1] - $this->contenu[2])/($this->end_planete->debris_met + $this->end_planete->debris_cri);
|
||||
if ($coeff > 1)
|
||||
$coeff = 1;
|
||||
|
||||
$a = floor($this->end_planete->debris_met * $coeff);
|
||||
$b = floor($this->end_planete->debris_cri * $coeff);
|
||||
|
||||
$this->contenu[0] += $a;
|
||||
$this->contenu[1] += $b;
|
||||
if (!in_array('contenu', $this->modifFlotte))
|
||||
$this->modifFlotte[] = 'contenu';
|
||||
|
||||
$this->end_planete->debris_met -= $a;
|
||||
$this->end_planete->debris_cri -= $b;
|
||||
if (!in_array('debris_met', $this->end_planete->modif))
|
||||
$this->end_planete->modif[] = 'debris_met';
|
||||
if (!in_array('debris_cri', $this->end_planete->modif))
|
||||
$this->end_planete->modif[] = 'debris_cri';
|
||||
|
||||
//Send link
|
||||
$rapport = new Rapport(4, $this->start_planete->id_user, 0, $this->start_time + $this->end_time);
|
||||
$rapport->addInfo($this->end_planete, 0);
|
||||
$rapport->addInfo(array($a, $b), 1);
|
||||
$rapport->send();
|
||||
|
||||
$this->statut = 1;
|
||||
if (!in_array('statut', $this->modifFlotte))
|
||||
$this->modifFlotte[] = 'statut';
|
||||
}
|
||||
|
||||
|
||||
function espionnage()
|
||||
{
|
||||
//Si la planète d'arrivé n'est pas chargée, on charge les planètes
|
||||
if (is_numeric($this->end_planete))
|
||||
$this->load_planete();
|
||||
|
||||
|
||||
|
||||
$this->statut = 1;
|
||||
if (!in_array('statut', $this->modifFlotte))
|
||||
$this->modifFlotte[] = 'statut';
|
||||
}
|
||||
|
||||
|
||||
function decharger()
|
||||
{
|
||||
//Si la planète d'arrivé n'est pas chargée, on charge les planètes
|
||||
if (is_numeric($this->end_planete))
|
||||
$this->load_planete();
|
||||
$max = array(0, 0, 0);
|
||||
|
||||
//Si on dépasse les capacités, on laisse les ressources en trop dans le cargo
|
||||
if ($this->end_planete->metal + $this->contenu[0] > $this->end_planete->cap)
|
||||
{
|
||||
$max[0] = $this->end_planete->cap - $this->end_planete->metal;
|
||||
if ($max[0] < 0) $max[0] = 0;
|
||||
}
|
||||
else
|
||||
$max[0] = $this->contenu[0];
|
||||
$this->end_planete->metal += $max[0];
|
||||
$this->contenu[0] -= $max[0];
|
||||
|
||||
if ($this->end_planete->cristal + $this->contenu[1] > $this->end_planete->cap)
|
||||
{
|
||||
$max[1] = $this->end_planete->cap - $this->end_planete->cristal;
|
||||
if ($max[1] < 0) $max[1] = 0;
|
||||
}
|
||||
else
|
||||
$max[1] = $this->contenu[1];
|
||||
$this->end_planete->cristal += $max[1];
|
||||
$this->contenu[1] -= $max[1];
|
||||
|
||||
if ($this->end_planete->hydrogene + $this->contenu[2] > $this->end_planete->cap)
|
||||
{
|
||||
$max[2] = $this->end_planete->cap - $this->end_planete->hydrogene;
|
||||
if ($max[2] < 0) $max[2] = 0;
|
||||
}
|
||||
else
|
||||
$max[2] = $this->contenu[2];
|
||||
$this->end_planete->hydrogene += $max[2];
|
||||
$this->contenu[2] -= $max[2];
|
||||
|
||||
if (!in_array('contenu', $this->modifFlotte))
|
||||
$this->modifFlotte[] = 'contenu';
|
||||
return $max;
|
||||
}
|
||||
|
||||
|
||||
function atterir($planete = "end_planete")
|
||||
{
|
||||
//Si la planète d'arrivé n'est pas chargée, on charge les planètes
|
||||
if (is_numeric($this->$planete))
|
||||
$this->load_planete();
|
||||
|
||||
if (isset($this->$planete->vaisseaux[0]))
|
||||
{
|
||||
foreach ($this->vaisseaux as $key => $vais)
|
||||
$this->$planete->vaisseaux[$key] += $vais;
|
||||
}
|
||||
else
|
||||
$this->$planete->vaisseaux = $this->vaisseaux;
|
||||
|
||||
if (!in_array("vaisseaux", $this->$planete->modif))
|
||||
$this->$planete->modif[] = "vaisseaux";
|
||||
|
||||
$this->modifFlotte = "DELETE";
|
||||
}
|
||||
|
||||
|
||||
function rappeler()
|
||||
{
|
||||
if ($this->start_time + $this->end_time >= time())
|
||||
return false;
|
||||
else
|
||||
{
|
||||
$this->end_time = time() - $this->start_time + 10;
|
||||
$this->mission = 5;
|
||||
if (!in_array('mission', $this->modifFlotte))
|
||||
$this->modifFlotte[] = 'mission';
|
||||
if (!in_array('end_time', $this->modifFlotte))
|
||||
$this->modifFlotte[] = 'end_time';
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function retourner()
|
||||
{
|
||||
//Si la planète de départ n'est pas chargée, on charge les planètes
|
||||
if (is_numeric($this->start_planete))
|
||||
$this->load_planete();
|
||||
|
||||
//Si on a demandé une planète particulière au retour
|
||||
if (!empty($this->ret_time) && !empty($this->ret_planete) && !is_numeric($this->ret_planete))
|
||||
{
|
||||
foreach($this->vaisseaux as $key => $vais)
|
||||
$this->ret_planete->vaisseaux[$key] += $vais;
|
||||
}
|
||||
//Si le retour se fait sur la planète source
|
||||
else
|
||||
{
|
||||
foreach($this->vaisseaux as $key => $vais)
|
||||
$this->start_planete->vaisseaux[$key] += $vais;
|
||||
}
|
||||
|
||||
if (!in_array("vaisseaux", $this->start_planete->modif))
|
||||
$this->start_planete->modif[] = "vaisseaux";
|
||||
$this->modifFlotte = "DELETE";
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructeur
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function __destruct()
|
||||
{
|
||||
global $var___db, $config, $table_flottes;
|
||||
$nb = count($this->modifFlotte);
|
||||
$out = array();
|
||||
$bdd = new bdd();
|
||||
$bdd->connexion();
|
||||
if ($this->modifFlotte === "DELETE")
|
||||
$bdd->query("DELETE FROM $table_flottes WHERE id = ".$this->id_flotte.";");
|
||||
else
|
||||
{
|
||||
if (empty($this->id_flotte))
|
||||
{
|
||||
if ($this->modifFlotte == "INSERT")
|
||||
{
|
||||
$out1 = ''; $out2 = '';
|
||||
global $nomvaisnVAR;
|
||||
foreach ($this->vaisseaux as $key => $vais)
|
||||
{
|
||||
$out1 .= ', '.$nomvaisnVAR[$key];
|
||||
$out2 .= ', '.$vais;
|
||||
}
|
||||
$sql = "INSERT INTO $table_flottes (id_user, mission, start_time, start_planete, end_time, end_planete, vitesse, contenu_metal, contenu_cristal, contenu_hydrogene, tactique, nom, nb_vais$out1) VALUES ('".$this->start_planete->id_user."', '".$this->mission."', '".$this->start_time."', '".$this->start_planete->id."', '".$this->end_time."', '".$this->end_planete."', '".$this->vitesse."', '".$this->contenu[0]."', '".$this->contenu[1]."', '".$this->contenu[2]."', '".$this->tactique."', '".$this->nom."', ".$this->nb_vais."$out2);";
|
||||
//var_dump($sql);
|
||||
$bdd->query($sql);
|
||||
}
|
||||
}
|
||||
elseif(isset($this->modifFlotte[0]))
|
||||
{
|
||||
for($i = 0; $i < $nb; $i++)
|
||||
{
|
||||
if (!is_array($this->{$this->modifFlotte[$i]}))
|
||||
{
|
||||
$bdd->escape($this->{$this->modifFlotte[$i]});
|
||||
if (is_int($this->{$this->modifFlotte[$i]}) || is_float($this->{$this->modifFlotte[$i]}))
|
||||
$out[] .= $this->modifFlotte[$i]." = ".$this->{$this->modifFlotte[$i]};
|
||||
else
|
||||
$out[] .= $this->modifFlotte[$i]." = '".$this->{$this->modifFlotte[$i]}."'";
|
||||
}
|
||||
else {
|
||||
if ($this->modifFlotte[$i] == "contenu")
|
||||
$calc = "resso";
|
||||
elseif ($this->modifFlotte[$i] == "vaisseaux")
|
||||
$calc = "nomvaisn";
|
||||
|
||||
if (!isset(${$calc.'VAR'}))
|
||||
global ${$calc.'VAR'};
|
||||
|
||||
$nombr = count(${$calc.'VAR'});
|
||||
for($j = 0; $j < $nombr; $j++)
|
||||
{
|
||||
$bdd->escape($this->{$this->modifFlotte[$i]}[$j]);
|
||||
$out[] = ${$calc.'VAR'}[$j]." = ".$this->{$this->modifFlotte[$i]}[$j];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($out))
|
||||
$bdd->query("UPDATE $table_flottes SET ".implode(', ', $out).", last = 0 WHERE id = ".$this->id_flotte.";");
|
||||
else
|
||||
$bdd->query("UPDATE $table_flottes SET last = 0 WHERE id = ".$this->id_flotte.";");
|
||||
}
|
||||
}
|
||||
$bdd->deconnexion();
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -34,9 +34,9 @@ class Rapport{
|
|||
}
|
||||
|
||||
function send(){
|
||||
if ($this->type == '1') $this->sendCombat();
|
||||
elseif ($this->type == '2') $this->sendTransport();
|
||||
elseif ($this->type == '3') $this->sendColonisation();
|
||||
if ($this->type == '3') $this->sendCombat();
|
||||
elseif ($this->type == '1') $this->sendTransport();
|
||||
elseif ($this->type == '2') $this->sendColonisation();
|
||||
elseif ($this->type == '4') $this->sendRecyclage();
|
||||
elseif ($this->type == '5') $this->sendEspionnage();
|
||||
elseif ($this->type == '6') $this->sendAlliance();
|
||||
|
|
@ -112,15 +112,15 @@ class Rapport{
|
|||
function sendTransport(){
|
||||
global $config;
|
||||
include_once(_FCORE."../game/function.php");
|
||||
$titre = 'Transport vers '.$this->var[0]['nom_planete'].' ['.$this->var[0]['galaxie'].':'.$this->var[0]['ss'].':'.$this->var[0]['position'].']';
|
||||
$titre = 'Transport vers '.$this->var[0][0].' ['.$this->var[0][1].':'.$this->var[0][2].':'.$this->var[0][3].']';
|
||||
|
||||
$race = trouvInfo($this->utilA, 'race');
|
||||
$race = trouvInfo($this->utilA, 'race'); //TODO A optimiser
|
||||
include(_FCORE."../game/noms.php");
|
||||
$rapportA = 'Vos vaisseaux ont déposé '.$this->var[1][0].' de '.$ressourc[0].', '.$this->var[1][1].' de '.$ressourc[1].' et '.$this->var[1][2].' d\''.$ressourc[2].' sur '.$this->var[0]['nom_planete'].'['.$this->var[0]['galaxie'].':'.$this->var[0]['ss'].':'.$this->var[0]['position'].']</b><br /><br />';
|
||||
$rapportA = 'Vos vaisseaux ont déposé '.$this->var[1][0].' de '.$ressourc[0].', '.$this->var[1][1].' de '.$ressourc[1].' et '.$this->var[1][2].' d\''.$ressourc[2].' sur '.$this->var[0][0].'['.$this->var[0][1].':'.$this->var[0][2].':'.$this->var[0][3].']</b><br /><br />';
|
||||
|
||||
$race = trouvInfo($this->utilB, 'race');
|
||||
$race = trouvInfo($this->utilB, 'race'); //TODO A optimiser
|
||||
include(_FCORE."../game/noms.php");
|
||||
$rapportB = 'Les vaisseaux de '.trouvNom($this->utilA).' ont déposé '.$this->var[1][0].' de '.$ressourc[0].', '.$this->var[1][1].' de '.$ressourc[1].' et '.$this->var[1][2].' d\''.$ressourc[2].' sur '.$this->var[0]['nom_planete'].'['.$this->var[0]['galaxie'].':'.$this->var[0]['ss'].':'.$this->var[0]['position'].']</b><br /><br />';
|
||||
$rapportB = 'Les vaisseaux de '.trouvNom($this->utilA).' ont déposé '.$this->var[1][0].' de '.$ressourc[0].', '.$this->var[1][1].' de '.$ressourc[1].' et '.$this->var[1][2].' d\''.$ressourc[2].' sur '.$this->var[0][0].'['.$this->var[0][1].':'.$this->var[0][2].':'.$this->var[0][3].']</b><br /><br />';
|
||||
|
||||
$temps = $this->timestamp;
|
||||
$db = new bdd();
|
||||
|
|
@ -129,8 +129,8 @@ class Rapport{
|
|||
$db->escape($rapportA);
|
||||
$db->escape($rapportB);
|
||||
|
||||
$db->query("INSERT INTO ".$this->table." (destinataire, sujet, contenu, temps) VALUES(".$this->utilA.", '$titre', '$rapportA', '$temps')");
|
||||
if ($this->utilA != $this->utilB) $db->query("INSERT INTO ".$this->table." (destinataire, sujet, contenu, temps) VALUES(".$this->utilB.", '$titre', '$rapportB', '$temps')");
|
||||
$db->query("INSERT INTO ".$this->table." (destinataire, sujet, contenu, temps) VALUES(".$this->utilA.", '$titre', '$rapportA', '$temps');");
|
||||
if ($this->utilA != $this->utilB) $db->query("INSERT INTO ".$this->table." (destinataire, sujet, contenu, temps) VALUES(".$this->utilB.", '$titre', '$rapportB', '$temps');");
|
||||
$db->deconnexion();
|
||||
}
|
||||
|
||||
|
|
@ -150,9 +150,10 @@ class Rapport{
|
|||
}
|
||||
|
||||
function sendRecyclage(){
|
||||
include_once(_FCORE."../game/function.php");
|
||||
$titre = 'Recyclage de '.$this->var[0]['nom_planete'].' ['.$this->var[0]['galaxie'].':'.$this->var[0]['ss'].':'.$this->var[0]['position'].']';
|
||||
$rapport = 'Vos vaisseaux récoltent '.$this->var[1][0].' de '.$ressourc[0].' et '.$this->var[1][1].' de '.$ressourc[1].' sur '.$this->var[0]['nom_planete'].'['.$this->var[0]['galaxie'].':'.$this->var[0]['ss'].':'.$this->var[0]['position'].']</b><br /><br />';
|
||||
global $ressourc;
|
||||
|
||||
$titre = 'Recyclage de '.$this->var[0]->nom_planete.' ['.$this->var[0]->galaxie.':'.$this->var[0]->ss.':'.$this->var[0]->position.']';
|
||||
$rapport = 'Vos vaisseaux récoltent '.$this->var[1][0].' de '.$ressourc[0].' et '.$this->var[1][1].' de '.$ressourc[1].' sur '.$this->var[0]->nom_planete.'['.$this->var[0]->galaxie.':'.$this->var[0]->ss.':'.$this->var[0]->position.']</b><br /><br />';
|
||||
|
||||
$temps = $this->timestamp;
|
||||
|
||||
|
|
|
|||
30
game/Class/class.surface.php
Normal file
30
game/Class/class.surface.php
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
/***************************************************************************
|
||||
* class.surface.php
|
||||
* -------------------
|
||||
* begin : Jeudi 21 août 2008
|
||||
* update : Dimanche 4 janvier 2009
|
||||
* email : nemunaire@gmail.com
|
||||
*
|
||||
*
|
||||
***************************************************************************/
|
||||
class Surface extends User
|
||||
{
|
||||
var $id = 0,
|
||||
$galaxie,
|
||||
$ss,
|
||||
$image,
|
||||
$debris_met,
|
||||
$debris_cri,
|
||||
$metal,
|
||||
$cristal,
|
||||
$hydrogene,
|
||||
$alert_ressources = array(false, false, false),
|
||||
$timestamp,
|
||||
$file_bat,
|
||||
$file_vais,
|
||||
$batiments = array(),
|
||||
$vaisseaux = array(),
|
||||
$modif = array();
|
||||
}
|
||||
?>
|
||||
47
game/Class/class.tinyplanete.php
Normal file
47
game/Class/class.tinyplanete.php
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
class TinyPlanete{
|
||||
var $id = 0,
|
||||
$galaxie,
|
||||
$ss,
|
||||
$position,
|
||||
$nom_planete;
|
||||
|
||||
/**
|
||||
* Constructeur
|
||||
* @param int $id id de la planète à importer
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function TinyPlanete($id = 0){
|
||||
if (!empty($id)) {
|
||||
global $securePlanete;
|
||||
global $var___db, $config, $table_planete;
|
||||
global $batimentVAR, $casernenVAR, $nomterrnVAR, $nomvaisnVAR;
|
||||
$actuFile = true;
|
||||
$bdd = new bdd();
|
||||
|
||||
//On traite le cas où l'on envoie les coordonnées
|
||||
if (is_numeric($id)) {
|
||||
$bdd->connexion();
|
||||
$plan = $bdd->unique_query("SELECT * FROM $table_planete WHERE id = $id;");
|
||||
$bdd->deconnexion();
|
||||
}
|
||||
elseif (preg_match('#^\[?([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})\]?$#', $id, $position)) {
|
||||
$bdd->connexion();
|
||||
$plan = $bdd->unique_query("SELECT * FROM $table_planete WHERE galaxie = ".$position[1]." AND ss = ".$position[2]." AND position = ".$position[3].";");
|
||||
$bdd->deconnexion();
|
||||
}
|
||||
else die('Erreur #04 : Format de recherche de planete incorrect !');
|
||||
|
||||
if (!empty($plan)) {
|
||||
$this->id = $plan["id"];
|
||||
$this->galaxie = $plan["galaxie"];
|
||||
$this->ss = $plan["ss"];
|
||||
$this->position = $plan["position"];
|
||||
$this->nom_planete = $plan["nom_planete"];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -86,40 +86,51 @@ class User extends File{
|
|||
*/
|
||||
function __destruct(){
|
||||
global $var___db, $config, $table_user;
|
||||
$nb = count($this->modifUser);
|
||||
$out = array();
|
||||
$bdd = new bdd();
|
||||
$bdd->connexion();
|
||||
for($i = 0; $i < $nb; $i++){
|
||||
if (!is_array($this->{$this->modifUser[$i]})) {
|
||||
$bdd->escape($this->{$this->modifUser[$i]});
|
||||
if (is_int($this->{$this->modifUser[$i]}) || is_float($this->{$this->modifUser[$i]})) $out[] .= $this->modifUser[$i]." = ".$this->{$this->modifUser[$i]};
|
||||
else $out[] .= $this->modifUser[$i]." = '".$this->{$this->modifUser[$i]}."'";
|
||||
}
|
||||
else {
|
||||
if (ereg('file', $this->modifUser[$i])) {
|
||||
$prep = implode(';', $this->{$this->modifUser[$i]});
|
||||
$bdd->escape($prep);
|
||||
$out[] .= $this->modifUser[$i]." = '$prep'";
|
||||
}
|
||||
else {
|
||||
if ($this->modifUser[$i] == "batiments") $calc = "batiment";
|
||||
elseif ($this->modifUser[$i] == "technologies") $calc = "technologies";
|
||||
elseif ($this->modifUser[$i] == "casernes")$calc = "casernen";
|
||||
elseif ($this->modifUser[$i] == "terrestres") $calc = "nomterrn";
|
||||
elseif ($this->modifUser[$i] == "vaisseaux") $calc = "nomvaisn";
|
||||
|
||||
if (!isset(${$calc.'VAR'})) global ${$calc.'VAR'};
|
||||
|
||||
$nombr = count(${$calc.'VAR'});
|
||||
for($j = 0; $j < $nombr; $j++){
|
||||
$bdd->escape($this->{$this->modifUser[$i]}[$j]);
|
||||
$out[] .= ${$calc.'VAR'}[$j]." = ".$this->{$this->modifUser[$i]}[$j];
|
||||
foreach($this->modifUser as $key => $modif)
|
||||
{
|
||||
if (!is_array($this->{$modif}))
|
||||
{
|
||||
$bdd->escape($this->{$modif});
|
||||
if (is_int($this->{$modif}) || is_float($this->{$modif})) $out[] .= $modif." = ".$this->{$modif};
|
||||
else $out[] .= $modif." = '".$this->{$modif}."'";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ereg('file', $modif))
|
||||
{
|
||||
$prep = implode(';', $this->{$modif});
|
||||
$bdd->escape($prep);
|
||||
$out[] .= $modif." = '$prep'";
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($modif == "batiments")
|
||||
$calc = "batiment";
|
||||
elseif ($modif == "technologies")
|
||||
$calc = "technologies";
|
||||
elseif ($modif == "casernes")
|
||||
$calc = "casernen";
|
||||
elseif ($modif == "terrestres")
|
||||
$calc = "nomterrn";
|
||||
elseif ($modif == "vaisseaux")
|
||||
$calc = "nomvaisn";
|
||||
|
||||
if (!isset(${$calc.'VAR'}))
|
||||
global ${$calc.'VAR'};
|
||||
|
||||
$nombr = count(${$calc.'VAR'});
|
||||
for($j = 0; $j < $nombr; $j++){
|
||||
$bdd->escape($this->{$modif}[$j]);
|
||||
$out[] .= ${$calc.'VAR'}[$j]." = ".$this->{$modif}[$j];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($out)) $plan = $bdd->query("UPDATE $table_user SET ".implode(', ', $out)." WHERE id = ".$this->id_user.";");
|
||||
if (!empty($out))
|
||||
$plan = $bdd->query("UPDATE $table_user SET ".implode(', ', $out)." WHERE id = ".$this->id_user.";");
|
||||
$bdd->deconnexion();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue