Ajout d'une étape de linting dans DroneCi (#3)
All checks were successful
continuous-integration/drone/push Build is passing

Corrige un doublons laissé par le rebase semi-manuel

Ajout d'une étape de linting dans DroneCi

Fix linting

Co-authored-by: Nigel Sheldon <nigelsheldon@live.fr>
Reviewed-on: https://gitea.nemunai.re/halo-battle/game/pulls/3
This commit is contained in:
Nigel 2020-11-21 18:54:32 +00:00
commit dd61d3b66b
263 changed files with 45327 additions and 42695 deletions

View file

@ -3,208 +3,198 @@ require_once("Class/Donnees/interface.php");
class dAlliancesBatiments implements Donnees
{
public static function metal($id, $niveau, surface $planete)
{
switch($id)
{
case 0:
$metal = ceil(pow(1.5, $niveau)*68);
break;
case 1:
$metal = ceil(pow(1.6, $niveau)*53);
break;
case 2:
$metal = ceil(pow(1.5, $niveau)*242);
break;
case 3:
$metal = ceil(pow(1.5, $niveau)*92);
break;
case 4:
$metal = ceil(pow(1.73, $niveau)*800);
break;
case 5:
$metal = ceil(pow(2, $niveau)*750);
break;
default:
trigger_error("Batiment d'alliance ".$id." introuvable dans les données", E_USER_ERROR);
}
public static function metal($id, $niveau, surface $planete)
{
switch ($id) {
case 0:
$metal = ceil(pow(1.5, $niveau)*68);
break;
case 1:
$metal = ceil(pow(1.6, $niveau)*53);
break;
case 2:
$metal = ceil(pow(1.5, $niveau)*242);
break;
case 3:
$metal = ceil(pow(1.5, $niveau)*92);
break;
case 4:
$metal = ceil(pow(1.73, $niveau)*800);
break;
case 5:
$metal = ceil(pow(2, $niveau)*750);
break;
default:
trigger_error("Batiment d'alliance ".$id." introuvable dans les données", E_USER_ERROR);
}
return $metal;
}
return $metal;
}
public static function cristal($id, $niveau, surface $planete)
{
switch($id)
{
case 0:
$cristal = ceil(pow(1.5, $niveau)*17);
break;
case 1:
$cristal = ceil(pow(1.6, $niveau)*27);
break;
case 2:
$cristal = ceil(pow(1.5, $niveau)*72);
break;
case 3:
$cristal = ceil(pow(1.5, $niveau)*37);
break;
case 4:
$cristal = ceil(pow(1.73, $niveau)*420);
break;
case 5:
$cristal = ceil(pow(2, $niveau)*500);
break;
default:
trigger_error("Batiment d'alliance ".$id." introuvable dans les données", E_USER_ERROR);
}
public static function cristal($id, $niveau, surface $planete)
{
switch ($id) {
case 0:
$cristal = ceil(pow(1.5, $niveau)*17);
break;
case 1:
$cristal = ceil(pow(1.6, $niveau)*27);
break;
case 2:
$cristal = ceil(pow(1.5, $niveau)*72);
break;
case 3:
$cristal = ceil(pow(1.5, $niveau)*37);
break;
case 4:
$cristal = ceil(pow(1.73, $niveau)*420);
break;
case 5:
$cristal = ceil(pow(2, $niveau)*500);
break;
default:
trigger_error("Batiment d'alliance ".$id." introuvable dans les données", E_USER_ERROR);
}
return $cristal;
}
return $cristal;
}
public static function hydrogene($id, $niveau, surface $planete)
{
switch($id)
{
case 0:
$hydrogene = 0;
break;
case 1:
$hydrogene = 0;
break;
case 2:
$hydrogene = 0;
break;
case 3:
$hydrogene = 0;
break;
case 4:
$hydrogene = ceil(pow(1.68, $niveau)*285);
break;
case 5:
$hydrogene = 0;
break;
default:
trigger_error("Batiment d'alliance ".$id." introuvable dans les données", E_USER_ERROR);
}
public static function hydrogene($id, $niveau, surface $planete)
{
switch ($id) {
case 0:
$hydrogene = 0;
break;
case 1:
$hydrogene = 0;
break;
case 2:
$hydrogene = 0;
break;
case 3:
$hydrogene = 0;
break;
case 4:
$hydrogene = ceil(pow(1.68, $niveau)*285);
break;
case 5:
$hydrogene = 0;
break;
default:
trigger_error("Batiment d'alliance ".$id." introuvable dans les données", E_USER_ERROR);
}
return $hydrogene;
}
return $hydrogene;
}
public static function credits($id, $niveau, surface $planete)
{
switch($id)
{
case 0:
$credits = ceil(pow(1.68, $niveau)*25);
break;
case 1:
$credits = ceil(pow(1.68, $niveau)*85);
break;
case 2:
$credits = ceil(pow(1.68, $niveau)*185);
break;
case 3:
$credits = ceil(pow(1.68, $niveau)*285);
break;
case 4:
$credits = ceil(pow(1.68, $niveau)*385);
break;
case 5:
$credits = ceil(pow(1.68, $niveau)*485);
break;
default:
trigger_error("Batiment d'alliance ".$id." introuvable dans les données", E_USER_ERROR);
}
public static function credits($id, $niveau, surface $planete)
{
switch ($id) {
case 0:
$credits = ceil(pow(1.68, $niveau)*25);
break;
case 1:
$credits = ceil(pow(1.68, $niveau)*85);
break;
case 2:
$credits = ceil(pow(1.68, $niveau)*185);
break;
case 3:
$credits = ceil(pow(1.68, $niveau)*285);
break;
case 4:
$credits = ceil(pow(1.68, $niveau)*385);
break;
case 5:
$credits = ceil(pow(1.68, $niveau)*485);
break;
default:
trigger_error("Batiment d'alliance ".$id." introuvable dans les données", E_USER_ERROR);
}
return $credits;
}
return $credits;
}
public static function temps($id, $niveau, surface $planete)
{
switch($id)
{
case 0:
$sec = pow(1.5, $niveau)*6;
break;
case 1:
$sec = pow(1.55, $niveau)*6;
break;
case 2:
$sec = pow(1.624, $niveau)*6;
break;
case 3:
$sec = pow(1.597, $niveau)*6;
break;
case 4:
$sec = pow(1.7, $niveau)*6;
break;
case 5:
$sec = ceil(pow(2, $niveau)*720);
break;
default:
trigger_error("Batiment d'alliance ".$id." introuvable dans les données", E_USER_ERROR);
}
public static function temps($id, $niveau, surface $planete)
{
switch ($id) {
case 0:
$sec = pow(1.5, $niveau)*6;
break;
case 1:
$sec = pow(1.55, $niveau)*6;
break;
case 2:
$sec = pow(1.624, $niveau)*6;
break;
case 3:
$sec = pow(1.597, $niveau)*6;
break;
case 4:
$sec = pow(1.7, $niveau)*6;
break;
case 5:
$sec = ceil(pow(2, $niveau)*720);
break;
default:
trigger_error("Batiment d'alliance ".$id." introuvable dans les données", E_USER_ERROR);
}
//Accélération du temps de construction
$sec /= VITESSE;
//Accélération du temps de construction
$sec /= VITESSE;
return $sec;
}
return $sec;
}
public static function image($id, surface $planete)
{
if ($planete->race == "covenant")
{
switch($id)
{
case 0:
//return "batimentcovieux4.jpg";
break;
}
return Donnees::image_covenant_default;
}
elseif ($planete->race == "humain")
{
switch($id)
{
case 0:
//return "batimentcovieux4.jpg";
break;
}
return Donnees::image_humain_default;
}
else
trigger_error("Impossible de trouver la race pour ".$planete->race, E_USER_ERROR);
}
public static function image($id, surface $planete)
{
if ($planete->race == "covenant") {
switch ($id) {
case 0:
//return "batimentcovieux4.jpg";
break;
}
return Donnees::image_covenant_default;
} elseif ($planete->race == "humain") {
switch ($id) {
case 0:
//return "batimentcovieux4.jpg";
break;
}
return Donnees::image_humain_default;
} else {
trigger_error("Impossible de trouver la race pour ".$planete->race, E_USER_ERROR);
}
}
public static function needed($id, surface $planete, $print = false)
{
$neededAlliancesBatiments =
array(
0,
array(
array('batiments', 0, 1)
),
array(
array('batiments', 0, 3)
),
array(
array('batiments', 0, 5)
),
array(
array('batiments', 0, 4)
),
array(
array('batiments', 0, 2)
)
);
public static function needed($id, surface $planete, $print = false)
{
$neededAlliancesBatiments =
array(
0,
array(
array('batiments', 0, 1)
),
array(
array('batiments', 0, 3)
),
array(
array('batiments', 0, 5)
),
array(
array('batiments', 0, 4)
),
array(
array('batiments', 0, 2)
)
);
if ($print)
return dDonnees::print_neededCheck($neededAlliancesBatiments[$id], $planete);
else
return dDonnees::neededCheck($neededAlliancesBatiments[$id], $planete);
}
if ($print) {
return dDonnees::print_neededCheck($neededAlliancesBatiments[$id], $planete);
} else {
return dDonnees::neededCheck($neededAlliancesBatiments[$id], $planete);
}
}
}
?>

View file

@ -3,515 +3,489 @@ require_once("Class/Donnees/interface.php");
class dBatiments implements Donnees
{
public static function metal($id, $niveau, surface $planete)
{
switch($id)
{
case 0:
$metal = ceil(pow(1.5, $niveau)*68);
break;
case 1:
$metal = ceil(pow(1.6, $niveau)*53);
break;
case 2:
$metal = ceil(pow(1.5, $niveau)*242);
break;
case 3:
$metal = ceil(pow(1.5, $niveau)*92);
break;
case 4:
//$metal = ceil(pow(1.73, $niveau)*800);
$metal = ceil(pow(3, $niveau)*5000);
break;
case 5:
$metal = ceil(pow(2, $niveau)*750);
break;
case 6:
$metal = ceil(pow(2, $niveau)*200);
break;
case 7:
$metal = ceil(pow(2, $niveau)*520);
break;
case 8:
$metal = ceil(pow(2, $niveau)*600);
break;
case 9:
$metal = ceil(pow(2, $niveau)*200);
break;
case 10:
$metal = ceil(pow(2, $niveau)*400);
break;
case 11:
$metal = ceil(pow(1.7, $niveau)*600);
break;
public static function metal($id, $niveau, surface $planete)
{
switch ($id) {
case 0:
$metal = ceil(pow(1.5, $niveau)*68);
break;
case 1:
$metal = ceil(pow(1.6, $niveau)*53);
break;
case 2:
$metal = ceil(pow(1.5, $niveau)*242);
break;
case 3:
$metal = ceil(pow(1.5, $niveau)*92);
break;
case 4:
//$metal = ceil(pow(1.73, $niveau)*800);
$metal = ceil(pow(3, $niveau)*5000);
break;
case 5:
$metal = ceil(pow(2, $niveau)*750);
break;
case 6:
$metal = ceil(pow(2, $niveau)*200);
break;
case 7:
$metal = ceil(pow(2, $niveau)*520);
break;
case 8:
$metal = ceil(pow(2, $niveau)*600);
break;
case 9:
$metal = ceil(pow(2, $niveau)*200);
break;
case 10:
$metal = ceil(pow(2, $niveau)*400);
break;
case 11:
$metal = ceil(pow(1.7, $niveau)*600);
break;
case 12:
$metal = ceil(pow($niveau, 2.075)*1000+1500);
break;
case 13:
$metal = ceil(pow($niveau,2.8)*1000+299000);
break;
case 14:
$metal = ceil(pow($niveau, 2)*1200+140000);
break;
case 15:
$metal = ceil(pow($niveau, 2)*1000+80000);
break;
case 16:
$metal = ceil(pow($niveau, 2)*850+60000);
break;
case 17:
$metal = ceil(pow($niveau, 2.5)*500 -300);
break;
default:
trigger_error("Batiment ".$id." introuvable dans les données", E_USER_ERROR);
}
case 12:
$metal = ceil(pow($niveau, 2.075)*1000+1500);
break;
case 13:
$metal = ceil(pow($niveau, 2.8)*1000+299000);
break;
case 14:
$metal = ceil(pow($niveau, 2)*1200+140000);
break;
case 15:
$metal = ceil(pow($niveau, 2)*1000+80000);
break;
case 16:
$metal = ceil(pow($niveau, 2)*850+60000);
break;
case 17:
$metal = ceil(pow($niveau, 2.5)*500 -300);
break;
default:
trigger_error("Batiment ".$id." introuvable dans les données", E_USER_ERROR);
}
//On tient compte des bonus
//Bonus technologique pour les mines
if ($id <= 3)
{
if ($planete->technologies[0] &262144)
{
$metal *= 0.85;
}
elseif ($planete->technologies[0] &131072)
{
$metal *= 0.9;
}
elseif ($planete->technologies[0] &65536)
{
$metal *= 0.95;
}
}
//On tient compte des bonus
//Bonus technologique pour les mines
if ($id <= 3) {
if ($planete->technologies[0] &262144) {
$metal *= 0.85;
} elseif ($planete->technologies[0] &131072) {
$metal *= 0.9;
} elseif ($planete->technologies[0] &65536) {
$metal *= 0.95;
}
}
return $metal;
}
return $metal;
}
public static function cristal($id, $niveau, surface $planete)
{
switch($id)
{
case 0:
$cristal = ceil(pow(1.5, $niveau)*17);
break;
case 1:
$cristal = ceil(pow(1.6, $niveau)*27);
break;
case 2:
$cristal = ceil(pow(1.5, $niveau)*72);
break;
case 3:
$cristal = ceil(pow(1.5, $niveau)*37);
break;
case 4:
//$cristal = ceil(pow(1.73, $niveau)*420);
$cristal = ceil(pow(3, $niveau)*3000);
break;
case 5:
$cristal = ceil(pow(2, $niveau)*500);
break;
case 6:
$cristal = ceil(pow(2, $niveau)*150);
break;
case 7:
$cristal = ceil(pow(2, $niveau)*380);
break;
case 8:
$cristal = ceil(pow(2, $niveau)*450);
break;
case 9:
$cristal = ceil(pow(2, $niveau)*100);
break;
case 10:
$cristal = ceil(pow(2, $niveau)*260);
break;
case 11:
$cristal = ceil(pow(1.7, $niveau)*420);
break;
public static function cristal($id, $niveau, surface $planete)
{
switch ($id) {
case 0:
$cristal = ceil(pow(1.5, $niveau)*17);
break;
case 1:
$cristal = ceil(pow(1.6, $niveau)*27);
break;
case 2:
$cristal = ceil(pow(1.5, $niveau)*72);
break;
case 3:
$cristal = ceil(pow(1.5, $niveau)*37);
break;
case 4:
//$cristal = ceil(pow(1.73, $niveau)*420);
$cristal = ceil(pow(3, $niveau)*3000);
break;
case 5:
$cristal = ceil(pow(2, $niveau)*500);
break;
case 6:
$cristal = ceil(pow(2, $niveau)*150);
break;
case 7:
$cristal = ceil(pow(2, $niveau)*380);
break;
case 8:
$cristal = ceil(pow(2, $niveau)*450);
break;
case 9:
$cristal = ceil(pow(2, $niveau)*100);
break;
case 10:
$cristal = ceil(pow(2, $niveau)*260);
break;
case 11:
$cristal = ceil(pow(1.7, $niveau)*420);
break;
case 12:
$cristal = ceil(pow($niveau, 1.8)*1000+1000);
break;
case 13:
$cristal = ceil(pow($niveau,2.5)*1000+149000);
break;
case 14:
$cristal = ceil(pow($niveau, 2)*900+99000);
break;
case 15:
$cristal = ceil(pow($niveau, 2)*750+65000);
break;
case 16:
$cristal = ceil(pow($niveau, 2)*650+50000);
break;
case 17:
$cristal = ceil(pow($niveau, 2.4)*400-250);
break;
default:
trigger_error("Batiment ".$id." introuvable dans les données", E_USER_ERROR);
}
case 12:
$cristal = ceil(pow($niveau, 1.8)*1000+1000);
break;
case 13:
$cristal = ceil(pow($niveau, 2.5)*1000+149000);
break;
case 14:
$cristal = ceil(pow($niveau, 2)*900+99000);
break;
case 15:
$cristal = ceil(pow($niveau, 2)*750+65000);
break;
case 16:
$cristal = ceil(pow($niveau, 2)*650+50000);
break;
case 17:
$cristal = ceil(pow($niveau, 2.4)*400-250);
break;
default:
trigger_error("Batiment ".$id." introuvable dans les données", E_USER_ERROR);
}
//On tient compte des bonus
//Bonus technologique pour les mines
if ($id <= 3)
{
if ($planete->technologies[0] &262144)
{
$cristal *= 0.85;
}
elseif ($planete->technologies[0] &131072)
{
$cristal *= 0.9;
}
elseif ($planete->technologies[0] &65536)
{
$cristal *= 0.95;
}
}
//On tient compte des bonus
//Bonus technologique pour les mines
if ($id <= 3) {
if ($planete->technologies[0] &262144) {
$cristal *= 0.85;
} elseif ($planete->technologies[0] &131072) {
$cristal *= 0.9;
} elseif ($planete->technologies[0] &65536) {
$cristal *= 0.95;
}
}
return $cristal;
}
return $cristal;
}
public static function hydrogene($id, $niveau, surface $planete)
{
switch($id)
{
case 0:
$hydrogene = 0;
break;
case 1:
$hydrogene = 0;
break;
case 2:
$hydrogene = 0;
break;
case 3:
$hydrogene = 0;
break;
case 4:
//$hydrogene = ceil(pow(1.68, $niveau)*285);
$hydrogene = 0;
break;
case 5:
$hydrogene = 0;
break;
case 6:
$hydrogene = 0;
break;
case 7:
$hydrogene = 0;
break;
case 8:
$hydrogene = 0;
break;
case 9:
$hydrogene = 0;
break;
case 10:
$hydrogene = 0;
break;
case 11:
$hydrogene = ceil(pow(1.7, $niveau)*100);
break;
public static function hydrogene($id, $niveau, surface $planete)
{
switch ($id) {
case 0:
$hydrogene = 0;
break;
case 1:
$hydrogene = 0;
break;
case 2:
$hydrogene = 0;
break;
case 3:
$hydrogene = 0;
break;
case 4:
//$hydrogene = ceil(pow(1.68, $niveau)*285);
$hydrogene = 0;
break;
case 5:
$hydrogene = 0;
break;
case 6:
$hydrogene = 0;
break;
case 7:
$hydrogene = 0;
break;
case 8:
$hydrogene = 0;
break;
case 9:
$hydrogene = 0;
break;
case 10:
$hydrogene = 0;
break;
case 11:
$hydrogene = ceil(pow(1.7, $niveau)*100);
break;
case 12:
$hydrogene = 0;
break;
case 13:
$hydrogene = 0;
break;
case 14:
$hydrogene = ceil(pow($niveau, 2)*500+30000);
break;
case 15:
$hydrogene = 0;
break;
case 16:
$hydrogene = 0;
break;
case 17:
$hydrogene = 0;
break;
default:
trigger_error("Batiment ".$id." introuvable dans les données", E_USER_ERROR);
}
case 12:
$hydrogene = 0;
break;
case 13:
$hydrogene = 0;
break;
case 14:
$hydrogene = ceil(pow($niveau, 2)*500+30000);
break;
case 15:
$hydrogene = 0;
break;
case 16:
$hydrogene = 0;
break;
case 17:
$hydrogene = 0;
break;
default:
trigger_error("Batiment ".$id." introuvable dans les données", E_USER_ERROR);
}
//On tient compte des bonus
//Bonus technologique pour les mines
if ($id <= 3)
{
if ($planete->technologies[0] &262144)
{
$hydrogene *= 0.85;
}
elseif ($planete->technologies[0] &131072)
{
$hydrogene *= 0.9;
}
elseif ($planete->technologies[0] &65536)
{
$hydrogene *= 0.95;
}
}
//On tient compte des bonus
//Bonus technologique pour les mines
if ($id <= 3) {
if ($planete->technologies[0] &262144) {
$hydrogene *= 0.85;
} elseif ($planete->technologies[0] &131072) {
$hydrogene *= 0.9;
} elseif ($planete->technologies[0] &65536) {
$hydrogene *= 0.95;
}
}
return $hydrogene;
}
return $hydrogene;
}
public static function credits($id, $niveau, surface $planete)
{
return 0;
}
public static function credits($id, $niveau, surface $planete)
{
return 0;
}
public static function temps($id, $niveau, surface $planete, $demolition = false)
{
switch($id)
{
case 0:
$sec = pow(1.5, $niveau)*6;
break;
case 1:
$sec = pow(1.55, $niveau)*6;
break;
case 2:
$sec = pow(1.624, $niveau)*6;
break;
case 3:
$sec = pow(1.597, $niveau)*6;
break;
case 4:
$sec = pow(1.7, $niveau)*6;
break;
case 5:
$sec = ceil(pow(2, $niveau)*720);
break;
case 6:
$sec = ceil(pow(2, $niveau)*720);
break;
case 7:
$sec = ceil(pow(2, $niveau)*420);
break;
case 8:
$sec = ceil(pow(2, $niveau)*600);
break;
case 9:
$sec = ceil(pow(2, $niveau)*300);
break;
case 10:
$sec = ceil(pow(2, $niveau)*1200);
break;
case 11:
$sec = ceil((pow(1.9, $niveau)*800));
break;
public static function temps($id, $niveau, surface $planete, $demolition = false)
{
switch ($id) {
case 0:
$sec = pow(1.5, $niveau)*6;
break;
case 1:
$sec = pow(1.55, $niveau)*6;
break;
case 2:
$sec = pow(1.624, $niveau)*6;
break;
case 3:
$sec = pow(1.597, $niveau)*6;
break;
case 4:
$sec = pow(1.7, $niveau)*6;
break;
case 5:
$sec = ceil(pow(2, $niveau)*720);
break;
case 6:
$sec = ceil(pow(2, $niveau)*720);
break;
case 7:
$sec = ceil(pow(2, $niveau)*420);
break;
case 8:
$sec = ceil(pow(2, $niveau)*600);
break;
case 9:
$sec = ceil(pow(2, $niveau)*300);
break;
case 10:
$sec = ceil(pow(2, $niveau)*1200);
break;
case 11:
$sec = ceil((pow(1.9, $niveau)*800));
break;
case 12:
$sec = ceil(pow($niveau, 2.5)*60+4)*60;
break;
case 13:
$sec = ceil(pow($niveau, 1.6)*60+60)*60;
break;
case 14:
$sec = ceil(pow($niveau, 2)*5+3)*60;
break;
case 15:
$sec = pow($niveau, 2)*240;
break;
case 16:
$sec = pow($niveau, 2)*180;
break;
case 17:
$sec = pow($niveau, 1.65)*3600;
break;
default:
trigger_error("Batiment ".$id." introuvable dans les données", E_USER_ERROR);
}
case 12:
$sec = ceil(pow($niveau, 2.5)*60+4)*60;
break;
case 13:
$sec = ceil(pow($niveau, 1.6)*60+60)*60;
break;
case 14:
$sec = ceil(pow($niveau, 2)*5+3)*60;
break;
case 15:
$sec = pow($niveau, 2)*240;
break;
case 16:
$sec = pow($niveau, 2)*180;
break;
case 17:
$sec = pow($niveau, 1.65)*3600;
break;
default:
trigger_error("Batiment ".$id." introuvable dans les données", E_USER_ERROR);
}
//On applique le bonus de temps des ingénieurs et des centrales informatiques
if ($id == 11 && $planete->casernes[7])
$sec /= (1.0025 * $planete->casernes[7]);
elseif ($id != 11 && ($planete->casernes[7] || $planete->batiments[11]))
$sec /= (pow(1.23, $planete->batiments[11]) + 1.0025 * $planete->casernes[7]);
//On applique le bonus de temps des ingénieurs et des centrales informatiques
if ($id == 11 && $planete->casernes[7]) {
$sec /= (1.0025 * $planete->casernes[7]);
} elseif ($id != 11 && ($planete->casernes[7] || $planete->batiments[11])) {
$sec /= (pow(1.23, $planete->batiments[11]) + 1.0025 * $planete->casernes[7]);
}
//Accélération du temps de construction
$sec /= VITESSE;
//Accélération du temps de construction
$sec /= VITESSE;
if ($demolition)
return $sec * Donnees::coeff_demolition;
else
return $sec;
}
if ($demolition) {
return $sec * Donnees::coeff_demolition;
} else {
return $sec;
}
}
public static function type($id)
{
switch($id)
{
case 0:
case 1:
case 2:
case 3:
case 4:
return 1;
case 6:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
case 16:
case 17:
case 18:
return 2;
case 5:
case 7:
case 8:
case 9:
return 4;
return 6;
default:
trigger_error("Bâtiment ".$id." introuvable dans les données", E_USER_ERROR);
}
}
public static function type($id)
{
switch ($id) {
case 0:
case 1:
case 2:
case 3:
case 4:
return 1;
case 6:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
case 16:
case 17:
case 18:
return 2;
case 5:
case 7:
case 8:
case 9:
return 4;
return 6;
default:
trigger_error("Bâtiment ".$id." introuvable dans les données", E_USER_ERROR);
}
}
public static function image($id, surface $planete)
{
if ($planete->race == "covenant")
{
switch($id)
{
case 0:
return "batimentcovieux4.jpg";
break;
case 1:
return "cristaloo3.png";
break;
case 2:
return "powersupplycoviejq1.jpg";
break;
case 3:
return "solaire.jpg";
break;
case 4:
return "sanstitrevi7.jpg";
break;
case 5:
return "oeilduprophetewj6.jpg";
break;
case 6:
return "covielabocn5.jpg";
break;
case 7:
return "chantierterrestrehg1.jpg";
break;
case 8:
return "sanstitretruecolor09zn6.jpg";
break;
case 9:
return "caserncov0ry.jpg";
break;
case 10:
return "stockagebasement1cs10bl.jpg";
break;
case 11:
return "ordianteur_hologramme.jpg";
break;
}
return Donnees::image_covenant_default;
}
elseif ($planete->race == "humain")
{
switch($id)
{
case 0:
return "mine_m.jpg";
break;
case 1:
return "mine_c.png";
break;
case 2:
return "synchroniseur.jpg";
break;
case 3:
return "centrale solaire.jpg";
break;
case 4:
return "centrale electrique.jpg";
break;
case 5:
return "baseradardl3.jpg";
break;
case 6:
return "recherches.jpg";
break;
case 7:
return "chantierterrestrecopybj8.jpg";
break;
case 8:
return "chantier spatial.jpg";
break;
case 9:
return "ecole militaire.jpg";
break;
case 10:
return "stockage.jpg";
break;
case 11:
return "search0yp.jpg";
break;
}
return Donnees::image_humain_default;
}
else
trigger_error("Impossible de trouver la race pour ".$planete->race, E_USER_ERROR);
}
public static function image($id, surface $planete)
{
if ($planete->race == "covenant") {
switch ($id) {
case 0:
return "batimentcovieux4.jpg";
break;
case 1:
return "cristaloo3.png";
break;
case 2:
return "powersupplycoviejq1.jpg";
break;
case 3:
return "solaire.jpg";
break;
case 4:
return "sanstitrevi7.jpg";
break;
case 5:
return "oeilduprophetewj6.jpg";
break;
case 6:
return "covielabocn5.jpg";
break;
case 7:
return "chantierterrestrehg1.jpg";
break;
case 8:
return "sanstitretruecolor09zn6.jpg";
break;
case 9:
return "caserncov0ry.jpg";
break;
case 10:
return "stockagebasement1cs10bl.jpg";
break;
case 11:
return "ordianteur_hologramme.jpg";
break;
}
return Donnees::image_covenant_default;
} elseif ($planete->race == "humain") {
switch ($id) {
case 0:
return "mine_m.jpg";
break;
case 1:
return "mine_c.png";
break;
case 2:
return "synchroniseur.jpg";
break;
case 3:
return "centrale solaire.jpg";
break;
case 4:
return "centrale electrique.jpg";
break;
case 5:
return "baseradardl3.jpg";
break;
case 6:
return "recherches.jpg";
break;
case 7:
return "chantierterrestrecopybj8.jpg";
break;
case 8:
return "chantier spatial.jpg";
break;
case 9:
return "ecole militaire.jpg";
break;
case 10:
return "stockage.jpg";
break;
case 11:
return "search0yp.jpg";
break;
}
return Donnees::image_humain_default;
} else {
trigger_error("Impossible de trouver la race pour ".$planete->race, E_USER_ERROR);
}
}
public static function needed($id, surface $planete, $print = false)
{
$neededBatiments =
array (
0,
0,
0,
0,
array(
array("batiments", 3, 12),
array("batiments_max", 4, 4)
),
0,
0,
array(
array("technologies", 2,3)
),
array(
array("technologies", 2,4)
),
0,
0,
array(
array("technologies", 1,12)
),
0,
array(
array("technologies", 3,8)
),
array(
array("technologies", 7,12)
),
array(
array("technologies", 3,6)
),
array(
array("technologies", 3,7)
),
0
);
public static function needed($id, surface $planete, $print = false)
{
$neededBatiments =
array(
0,
0,
0,
0,
array(
array("batiments", 3, 12),
array("batiments_max", 4, 4)
),
0,
0,
array(
array("technologies", 2,3)
),
array(
array("technologies", 2,4)
),
0,
0,
array(
array("technologies", 1,12)
),
0,
array(
array("technologies", 3,8)
),
array(
array("technologies", 7,12)
),
array(
array("technologies", 3,6)
),
array(
array("technologies", 3,7)
),
0
);
if ($print)
return dDonnees::print_neededCheck($neededBatiments[$id], $planete);
else
return dDonnees::neededCheck($neededBatiments[$id], $planete);
}
if ($print) {
return dDonnees::print_neededCheck($neededBatiments[$id], $planete);
} else {
return dDonnees::neededCheck($neededBatiments[$id], $planete);
}
}
}
?>

View file

@ -3,299 +3,293 @@ require_once("Class/Donnees/interface.php");
class dCaserne implements Donnees
{
public static function metal($id, $nombre, surface $planete)
{
switch($id)
{
case 0:
$metal = 80;
break;
case 1:
$metal = 110;
break;
case 2:
$metal = 150;
break;
case 3:
$metal = 220;
break;
case 4:
$metal = 180;
break;
case 5:
$metal = 25000;
break;
case 6:
$metal = 100;
break;
case 7:
$metal = 90;
break;
case 8:
$metal = 300;
break;
default:
trigger_error("Unité ".$id." introuvable dans les données", E_USER_ERROR);
}
public static function metal($id, $nombre, surface $planete)
{
switch ($id) {
case 0:
$metal = 80;
break;
case 1:
$metal = 110;
break;
case 2:
$metal = 150;
break;
case 3:
$metal = 220;
break;
case 4:
$metal = 180;
break;
case 5:
$metal = 25000;
break;
case 6:
$metal = 100;
break;
case 7:
$metal = 90;
break;
case 8:
$metal = 300;
break;
default:
trigger_error("Unité ".$id." introuvable dans les données", E_USER_ERROR);
}
//On tient compte des bonus
if (isset($planete->politique) && $planete->politique == 1)
$metal *= 0.9;
//On tient compte des bonus
if (isset($planete->politique) && $planete->politique == 1) {
$metal *= 0.9;
}
return $metal * $nombre;
}
return $metal * $nombre;
}
public static function cristal($id, $nombre, surface $planete)
{
switch($id)
{
case 0:
$cristal = 45;
break;
case 1:
$cristal = 90;
break;
case 2:
$cristal = 105;
break;
case 3:
$cristal = 150;
break;
case 4:
$cristal = 100;
break;
case 5:
$cristal = 10000;
break;
case 6:
$cristal = 100;
break;
case 7:
$cristal = 105;
break;
case 8:
$cristal = 250;
break;
default:
trigger_error("Unité ".$id." introuvable dans les données", E_USER_ERROR);
}
public static function cristal($id, $nombre, surface $planete)
{
switch ($id) {
case 0:
$cristal = 45;
break;
case 1:
$cristal = 90;
break;
case 2:
$cristal = 105;
break;
case 3:
$cristal = 150;
break;
case 4:
$cristal = 100;
break;
case 5:
$cristal = 10000;
break;
case 6:
$cristal = 100;
break;
case 7:
$cristal = 105;
break;
case 8:
$cristal = 250;
break;
default:
trigger_error("Unité ".$id." introuvable dans les données", E_USER_ERROR);
}
//On tient compte des bonus
if (isset($planete->politique) && $planete->politique == 1)
$cristal *= 0.9;
//On tient compte des bonus
if (isset($planete->politique) && $planete->politique == 1) {
$cristal *= 0.9;
}
return $cristal * $nombre;
}
return $cristal * $nombre;
}
public static function hydrogene($id, $nombre, surface $planete)
{
switch($id)
{
case 0:
$hydrogene = 0;
break;
case 1:
$hydrogene = 0;
break;
case 2:
$hydrogene = 20;
break;
case 3:
$hydrogene = 0;
break;
case 4:
$hydrogene = 0;
break;
case 5:
$hydrogene = 0;
break;
case 6:
$hydrogene = 0;
break;
case 7:
$hydrogene = 0;
break;
case 8:
$hydrogene = 0;
break;
default:
trigger_error("Unité ".$id." introuvable dans les données", E_USER_ERROR);
}
public static function hydrogene($id, $nombre, surface $planete)
{
switch ($id) {
case 0:
$hydrogene = 0;
break;
case 1:
$hydrogene = 0;
break;
case 2:
$hydrogene = 20;
break;
case 3:
$hydrogene = 0;
break;
case 4:
$hydrogene = 0;
break;
case 5:
$hydrogene = 0;
break;
case 6:
$hydrogene = 0;
break;
case 7:
$hydrogene = 0;
break;
case 8:
$hydrogene = 0;
break;
default:
trigger_error("Unité ".$id." introuvable dans les données", E_USER_ERROR);
}
//On tient compte des bonus
if (isset($planete->politique) && $planete->politique == 1)
$hydrogene *= 0.9;
//On tient compte des bonus
if (isset($planete->politique) && $planete->politique == 1) {
$hydrogene *= 0.9;
}
return $hydrogene * $nombre;
}
return $hydrogene * $nombre;
}
public static function credits($id, $nombre, surface $planete)
{
return 0;
}
public static function credits($id, $nombre, surface $planete)
{
return 0;
}
public static function temps($id, $nombre, surface $planete)
{
switch($id)
{
case 0:
$temps = 60;
$moins = 1;
break;
case 1:
$temps = 240;
$moins = 2;
break;
case 2:
$temps = 240;
$moins = 3;
break;
case 3:
$temps = 720;
$moins = 5;
break;
case 4:
$temps = 300;
$moins = 3;
break;
case 5:
$temps = 29700;
$moins = 10;
break;
case 6:
$temps = 90;
$moins = 2;
break;
case 7:
$temps = 90;
$moins = 2;
break;
case 8:
$temps = 900;
$moins = 5;
break;
default:
trigger_error("Unité ".$id." introuvable dans les données", E_USER_ERROR);
}
public static function temps($id, $nombre, surface $planete)
{
switch ($id) {
case 0:
$temps = 60;
$moins = 1;
break;
case 1:
$temps = 240;
$moins = 2;
break;
case 2:
$temps = 240;
$moins = 3;
break;
case 3:
$temps = 720;
$moins = 5;
break;
case 4:
$temps = 300;
$moins = 3;
break;
case 5:
$temps = 29700;
$moins = 10;
break;
case 6:
$temps = 90;
$moins = 2;
break;
case 7:
$temps = 90;
$moins = 2;
break;
case 8:
$temps = 900;
$moins = 5;
break;
default:
trigger_error("Unité ".$id." introuvable dans les données", E_USER_ERROR);
}
//On tient compte de la vitesse
$temps /= VITESSE;
//On tient compte de la vitesse
$temps /= VITESSE;
//On tient compte des bonus
return ceil($temps/pow(1.25, ($planete->batiments[9] - $moins))) * $nombre;
}
//On tient compte des bonus
return ceil($temps/pow(1.25, ($planete->batiments[9] - $moins))) * $nombre;
}
public static function image($id, surface $planete)
{
if ($planete->race == "covenant")
{
array('','','','','','','','','');
switch($id)
{
case 0:
return "grunt1.jpg";
break;
case 1:
return "jackal.jpg";
break;
case 2:
return "94990342wb4.jpg";
break;
case 3:
return "98004530fx3.jpg";
break;
case 4:
return "88091275ja8.jpg";
break;
case 5:
return "hunter1.jpg";
break;
case 6:
return "81770345oo4.jpg";
break;
case 7:
return "88218731ts1.jpg";
break;
case 8:
return "72188202fg9.jpg";
break;
}
return Donnees::image_covenant_default;
}
elseif ($planete->race == "humain")
{
switch($id)
{
case 0:
return "marines.jpg";
break;
case 1:
return "marinehf0.jpg";
break;
case 2:
return "grenadier.jpg";
break;
case 3:
return "TCAO2.jpg";
break;
case 4:
return "sniper.jpg";
break;
case 5:
return "spartan.jpg";
break;
case 6:
return "ingenieurs.jpg";
break;
case 7:
return "exosquelettehbpb2.jpg";
break;
}
return Donnees::image_humain_default;
}
else
trigger_error("Impossible de trouver la race pour ".$planete->race, E_USER_ERROR);
}
public static function image($id, surface $planete)
{
if ($planete->race == "covenant") {
array('','','','','','','','','');
switch ($id) {
case 0:
return "grunt1.jpg";
break;
case 1:
return "jackal.jpg";
break;
case 2:
return "94990342wb4.jpg";
break;
case 3:
return "98004530fx3.jpg";
break;
case 4:
return "88091275ja8.jpg";
break;
case 5:
return "hunter1.jpg";
break;
case 6:
return "81770345oo4.jpg";
break;
case 7:
return "88218731ts1.jpg";
break;
case 8:
return "72188202fg9.jpg";
break;
}
return Donnees::image_covenant_default;
} elseif ($planete->race == "humain") {
switch ($id) {
case 0:
return "marines.jpg";
break;
case 1:
return "marinehf0.jpg";
break;
case 2:
return "grenadier.jpg";
break;
case 3:
return "TCAO2.jpg";
break;
case 4:
return "sniper.jpg";
break;
case 5:
return "spartan.jpg";
break;
case 6:
return "ingenieurs.jpg";
break;
case 7:
return "exosquelettehbpb2.jpg";
break;
}
return Donnees::image_humain_default;
} else {
trigger_error("Impossible de trouver la race pour ".$planete->race, E_USER_ERROR);
}
}
public static function needed($id, surface $planete, $print = false)
{
$neededCaserne =
array(
array(
array('batiments', 9, 1)
),
array(
array('batiments', 9, 2)
),
array(
array('batiments', 9, 3)
),
array(
array('batiments', 9, 5)
),
array(
array('batiments', 9, 3)
),
array(
array('batiments', 9, 10)
),
array(
array('batiments', 9, 2)
),
array(
array('batiments', 9, 2)
),
array(
array('batiments', 9, 5)
)
);
public static function needed($id, surface $planete, $print = false)
{
$neededCaserne =
array(
array(
array('batiments', 9, 1)
),
array(
array('batiments', 9, 2)
),
array(
array('batiments', 9, 3)
),
array(
array('batiments', 9, 5)
),
array(
array('batiments', 9, 3)
),
array(
array('batiments', 9, 10)
),
array(
array('batiments', 9, 2)
),
array(
array('batiments', 9, 2)
),
array(
array('batiments', 9, 5)
)
);
if ($print)
return dDonnees::print_neededCheck($neededCaserne[$id], $planete);
else
return dDonnees::neededCheck($neededCaserne[$id], $planete);
}
if ($print) {
return dDonnees::print_neededCheck($neededCaserne[$id], $planete);
} else {
return dDonnees::neededCheck($neededCaserne[$id], $planete);
}
}
}
?>

View file

@ -1,202 +1,217 @@
<?php
if(!defined('ONYX')) exit;
if (!defined('ONYX')) {
exit;
}
interface Donnees
{
const image_covenant_default = "../covenant_na.jpg";
const image_humain_default = "../humain_na.jpg";
const image_covenant_default = "../covenant_na.jpg";
const image_humain_default = "../humain_na.jpg";
const coeff_demolition = 0.6;
const coeff_demolition = 0.6;
public static function metal($id, $niveau, surface $planete);
public static function cristal($id, $niveau, surface $planete);
public static function hydrogene($id, $niveau, surface $planete);
public static function credits($id, $niveau, surface $planete);
public static function temps($id, $niveau, surface $planete);
public static function metal($id, $niveau, surface $planete);
public static function cristal($id, $niveau, surface $planete);
public static function hydrogene($id, $niveau, surface $planete);
public static function credits($id, $niveau, surface $planete);
public static function temps($id, $niveau, surface $planete);
public static function image($id, surface $planete);
public static function image($id, surface $planete);
public static function needed($id, surface $planete, $print = false);
public static function needed($id, surface $planete, $print = false);
}
class dDonnees{
static function tailleFile(surface $planete)
{
//On calcul la taille maximale de la file d'attente
if (!empty($planete->technologies[1]))
{
if (($planete->technologies[1] &131072) == 131072) return 5;
elseif (($planete->technologies[1] &65536) == 65536) return 4;
elseif (($planete->technologies[1] &32768) == 32768) return 3;
else return 2;
}
else return 3; //Au cas où il n'y ait pas de technologie sur le lieu, on fixe la taille de la file d'attente
}
class dDonnees
{
public static function tailleFile(surface $planete)
{
//On calcul la taille maximale de la file d'attente
if (!empty($planete->technologies[1])) {
if (($planete->technologies[1] &131072) == 131072) {
return 5;
} elseif (($planete->technologies[1] &65536) == 65536) {
return 4;
} elseif (($planete->technologies[1] &32768) == 32768) {
return 3;
} else {
return 2;
}
} else {
return 3;
} //Au cas où il n'y ait pas de technologie sur le lieu, on fixe la taille de la file d'attente
}
static function neededCheck($tableau, surface $planete)
{
if (!is_array($tableau)) return true;
else
{
foreach ($tableau as $need)
{
switch($need[0])
{
case 'batiments':
if (get_class($planete) == "Planete" && $planete->batiments[$need[1]] < $need[2])
return false;
break;
case 'batiments_max':
if (get_class($planete) == "Planete" && $planete->batiments[$need[1]] > $need[2])
return false;
break;
case 'technologies':
if (((int)$planete->technologies[$need[1]]& dTechnologies::idToBit($need[2])) == 0)
return false;
break;
case 'casernes':
if ($planete->casernes[$need[1]] < $need[2])
return false;
break;
case 'terrestres':
if ($planete->terrestres[$need[1]] < $need[2])
return false;
break;
case 'vaisseaux':
if ($planete->vaisseaux[$need[1]] < $need[2])
return false;
break;
default:
return false;
}
}
return true;
}
}
public static function neededCheck($tableau, surface $planete)
{
if (!is_array($tableau)) {
return true;
} else {
foreach ($tableau as $need) {
switch ($need[0]) {
case 'batiments':
if (get_class($planete) == "Planete" && $planete->batiments[$need[1]] < $need[2]) {
return false;
}
break;
case 'batiments_max':
if (get_class($planete) == "Planete" && $planete->batiments[$need[1]] > $need[2]) {
return false;
}
break;
case 'technologies':
if (((int)$planete->technologies[$need[1]]& dTechnologies::idToBit($need[2])) == 0) {
return false;
}
break;
case 'casernes':
if ($planete->casernes[$need[1]] < $need[2]) {
return false;
}
break;
case 'terrestres':
if ($planete->terrestres[$need[1]] < $need[2]) {
return false;
}
break;
case 'vaisseaux':
if ($planete->vaisseaux[$need[1]] < $need[2]) {
return false;
}
break;
default:
return false;
}
}
return true;
}
}
static function print_neededCheck($tableau, surface $planete)
{
global $LANG;
$race = $planete->race;
if (!is_array($tableau)) return 'Débloqué';
else
{
$return = '';
foreach ($tableau as $need)
{
switch($need[0])
{
case 'batiments':
if ($planete->batiments[$need[1]] < $need[2])
$return .= '<span class="lack">'.ucfirst($LANG[$race]["batiments"]["noms_sing"][$need[1]]).' niveau '.$need[2].' (batiment)</span><br />';
else
$return .= ucfirst($LANG[$race]["batiments"]["noms_sing"][$need[1]]).' niveau '.$need[2].' (batiment)<br />';
break;
case 'batiments_max':
if ($planete->batiments[$need[1]] > $need[2])
$return .= '<span class="lack">'.ucfirst($LANG[$race]["batiments"]["noms_sing"][$need[1]]).' < niveau '.($need[2]+1).' (batiment)</span><br />';
else
$return .= ucfirst($LANG[$race]["batiments"]["noms_sing"][$need[1]]).' < niveau '.($need[2]+1).' (batiment)<br />';
break;
case 'technologies':
if (((int)$planete->technologies[$need[1]]& dTechnologies::idToBit($need[2])) == 0)
$return .= '<span class="lack">'.$LANG[$race]["technologies"]["noms_sing"][$need[1]][$need[2]].' (technologie)</span><br />';
else
$return .= $LANG[$race]["technologies"]["noms_sing"][$need[1]][$need[2]].' (technologie)<br />';
break;
case 'casernes':
if ($planete->casernes[$need[1]] < $need[2])
$return .= '<span class="lack">'.$need[2].' '.$LANG[$race]["caserne"]["noms_pluriel"][$need[1]].' (unité de la caserne)</span><br />';
else
$return .= $need[2].' '.$LANG[$race]["caserne"]["noms_pluriel"][$need[1]].' (unité de la caserne)<br />';
break;
case 'terrestres':
if ($planete->terrestres[$need[1]] < $need[2])
$return .= '<span class="lack">'.$need[2].' '.$LANG[$race]["terrestre"]["noms_pluriel"][$need[1]].' (unité du chantier terrestre)</span><br />';
else
$return .= $need[2].' '.$LANG[$race]["terrestre"]["noms_pluriel"][$need[1]].' (unité du chantier terrestre)<br />';
break;
case 'vaisseaux':
if ($planete->vaisseaux[$need[1]] < $need[2])
$return .= '<span class="lack">'.$need[2].' '.$LANG[$race]["vaisseaux"]["noms_pluriel"][$need[1]].' (unité du chantier spatial)</span><br />';
else
$return .= $need[2].' '.$LANG[$race]["vaisseaux"]["noms_pluriel"][$need[1]].' (unité du chantier spatial)<br />';
break;
}
}
return $return;
}
}
public static function print_neededCheck($tableau, surface $planete)
{
global $LANG;
$race = $planete->race;
if (!is_array($tableau)) {
return 'Débloqué';
} else {
$return = '';
foreach ($tableau as $need) {
switch ($need[0]) {
case 'batiments':
if ($planete->batiments[$need[1]] < $need[2]) {
$return .= '<span class="lack">'.ucfirst($LANG[$race]["batiments"]["noms_sing"][$need[1]]).' niveau '.$need[2].' (batiment)</span><br />';
} else {
$return .= ucfirst($LANG[$race]["batiments"]["noms_sing"][$need[1]]).' niveau '.$need[2].' (batiment)<br />';
}
break;
case 'batiments_max':
if ($planete->batiments[$need[1]] > $need[2]) {
$return .= '<span class="lack">'.ucfirst($LANG[$race]["batiments"]["noms_sing"][$need[1]]).' < niveau '.($need[2]+1).' (batiment)</span><br />';
} else {
$return .= ucfirst($LANG[$race]["batiments"]["noms_sing"][$need[1]]).' < niveau '.($need[2]+1).' (batiment)<br />';
}
break;
case 'technologies':
if (((int)$planete->technologies[$need[1]]& dTechnologies::idToBit($need[2])) == 0) {
$return .= '<span class="lack">'.$LANG[$race]["technologies"]["noms_sing"][$need[1]][$need[2]].' (technologie)</span><br />';
} else {
$return .= $LANG[$race]["technologies"]["noms_sing"][$need[1]][$need[2]].' (technologie)<br />';
}
break;
case 'casernes':
if ($planete->casernes[$need[1]] < $need[2]) {
$return .= '<span class="lack">'.$need[2].' '.$LANG[$race]["caserne"]["noms_pluriel"][$need[1]].' (unité de la caserne)</span><br />';
} else {
$return .= $need[2].' '.$LANG[$race]["caserne"]["noms_pluriel"][$need[1]].' (unité de la caserne)<br />';
}
break;
case 'terrestres':
if ($planete->terrestres[$need[1]] < $need[2]) {
$return .= '<span class="lack">'.$need[2].' '.$LANG[$race]["terrestre"]["noms_pluriel"][$need[1]].' (unité du chantier terrestre)</span><br />';
} else {
$return .= $need[2].' '.$LANG[$race]["terrestre"]["noms_pluriel"][$need[1]].' (unité du chantier terrestre)<br />';
}
break;
case 'vaisseaux':
if ($planete->vaisseaux[$need[1]] < $need[2]) {
$return .= '<span class="lack">'.$need[2].' '.$LANG[$race]["vaisseaux"]["noms_pluriel"][$need[1]].' (unité du chantier spatial)</span><br />';
} else {
$return .= $need[2].' '.$LANG[$race]["vaisseaux"]["noms_pluriel"][$need[1]].' (unité du chantier spatial)<br />';
}
break;
}
}
return $return;
}
}
static function nameVAR($name)
{
if ($name == "alli_batiments")
return "alli_batiments";
elseif ($name == "batiments")
return "batiments";
elseif ($name == "technologies")
return "technologies";
elseif ($name == "casernes")
return "caserne";
elseif ($name == "terrestres")
return "terrestre";
elseif ($name == "vaisseaux")
return "spatial";
elseif ($name == "coeff_bat")
return "coeff";
}
public static function nameVAR($name)
{
if ($name == "alli_batiments") {
return "alli_batiments";
} elseif ($name == "batiments") {
return "batiments";
} elseif ($name == "technologies") {
return "technologies";
} elseif ($name == "casernes") {
return "caserne";
} elseif ($name == "terrestres") {
return "terrestre";
} elseif ($name == "vaisseaux") {
return "spatial";
} elseif ($name == "coeff_bat") {
return "coeff";
}
}
static function capaciteVilles(surface $planete)
{
return $planete->cases * pow($planete->batiments[17], -3) + 10;
}
public static function capaciteVilles(surface $planete)
{
return $planete->cases * pow($planete->batiments[17], -3) + 10;
}
static function nameVilles($level)
{
switch ($level)
{
case 0:
case 1:
case 2:
return "Poste d'observation taille ".($level+1);
break;
case 3:
case 4:
case 5:
return "Poste avancé taille ".($level-2);
break;
case 6:
case 7:
case 8:
return "Colonie taille ".($level-5);
break;
case 9:
case 10:
case 11:
case 12:
return "Ville taille ".($level-8);
break;
case 13:
case 14:
case 15:
return "Cité taille ".($level-12);
break;
case 16:
case 17:
case 18:
return "Grande cité taille ".($level-15);
break;
case 19:
return "Mégapole";
break;
case 20:
return "Mégalopole";
break;
default:
trigger_error("Taille de ville incorrect !");
}
}
public static function nameVilles($level)
{
switch ($level) {
case 0:
case 1:
case 2:
return "Poste d'observation taille ".($level+1);
break;
case 3:
case 4:
case 5:
return "Poste avancé taille ".($level-2);
break;
case 6:
case 7:
case 8:
return "Colonie taille ".($level-5);
break;
case 9:
case 10:
case 11:
case 12:
return "Ville taille ".($level-8);
break;
case 13:
case 14:
case 15:
return "Cité taille ".($level-12);
break;
case 16:
case 17:
case 18:
return "Grande cité taille ".($level-15);
break;
case 19:
return "Mégapole";
break;
case 20:
return "Mégalopole";
break;
default:
trigger_error("Taille de ville incorrect !");
}
}
}
?>

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -3,475 +3,468 @@ require_once("Class/Donnees/interface.php");
class dTerrestre implements Donnees
{
public static function metal($id, $nombre, surface $planete)
{
switch($id)
{
case 0:
$cristal = 300;
break;
case 1:
$cristal = 420;
break;
case 2:
$cristal = 600;
break;
case 3:
$cristal = 950;
break;
case 4:
$cristal = 240;
break;
case 5:
$cristal = 260;
break;
case 6:
$cristal = 420;
break;
case 7:
$cristal = 500;
break;
case 8:
$cristal = 230;
break;
case 9:
$cristal = 650;
break;
case 10:
$cristal = 1750;
break;
case 11:
$cristal = 3750;
break;
case 12:
$cristal = 9500;
break;
case 13:
$cristal = 9500;
break;
case 14:
$cristal = 9500;
break;
case 15:
$cristal = 9500;
break;
default:
trigger_error("Unité ".$unite." introuvable dans les données", E_USER_ERROR);
}
public static function metal($id, $nombre, surface $planete)
{
switch ($id) {
case 0:
$cristal = 300;
break;
case 1:
$cristal = 420;
break;
case 2:
$cristal = 600;
break;
case 3:
$cristal = 950;
break;
case 4:
$cristal = 240;
break;
case 5:
$cristal = 260;
break;
case 6:
$cristal = 420;
break;
case 7:
$cristal = 500;
break;
case 8:
$cristal = 230;
break;
case 9:
$cristal = 650;
break;
case 10:
$cristal = 1750;
break;
case 11:
$cristal = 3750;
break;
case 12:
$cristal = 9500;
break;
case 13:
$cristal = 9500;
break;
case 14:
$cristal = 9500;
break;
case 15:
$cristal = 9500;
break;
default:
trigger_error("Unité ".$unite." introuvable dans les données", E_USER_ERROR);
}
//On tient compte des bonus
if (isset($planete->politique) && $planete->politique == 1)
$cristal *= 0.9;
//On tient compte des bonus
if (isset($planete->politique) && $planete->politique == 1) {
$cristal *= 0.9;
}
return $cristal * $nombre;
}
return $cristal * $nombre;
}
public static function cristal($id, $nombre, surface $planete)
{
switch($id)
{
case 0:
$cristal = 300;
break;
case 1:
$cristal = 420;
break;
case 2:
$cristal = 600;
break;
case 3:
$cristal = 950;
break;
case 4:
$cristal = 240;
break;
case 5:
$cristal = 260;
break;
case 6:
$cristal = 420;
break;
case 7:
$cristal = 500;
break;
case 8:
$cristal = 230;
break;
case 9:
$cristal = 650;
break;
case 10:
$cristal = 1750;
break;
case 11:
$cristal = 3750;
break;
case 12:
$cristal = 9500;
break;
case 13:
$cristal = 9500;
break;
case 14:
$cristal = 9500;
break;
case 15:
$cristal = 9500;
break;
default:
trigger_error("Unité ".$id." introuvable dans les données", E_USER_ERROR);
}
public static function cristal($id, $nombre, surface $planete)
{
switch ($id) {
case 0:
$cristal = 300;
break;
case 1:
$cristal = 420;
break;
case 2:
$cristal = 600;
break;
case 3:
$cristal = 950;
break;
case 4:
$cristal = 240;
break;
case 5:
$cristal = 260;
break;
case 6:
$cristal = 420;
break;
case 7:
$cristal = 500;
break;
case 8:
$cristal = 230;
break;
case 9:
$cristal = 650;
break;
case 10:
$cristal = 1750;
break;
case 11:
$cristal = 3750;
break;
case 12:
$cristal = 9500;
break;
case 13:
$cristal = 9500;
break;
case 14:
$cristal = 9500;
break;
case 15:
$cristal = 9500;
break;
default:
trigger_error("Unité ".$id." introuvable dans les données", E_USER_ERROR);
}
//On tient compte des bonus
if (isset($planete->politique) && $planete->politique == 1)
$cristal *= 0.9;
//On tient compte des bonus
if (isset($planete->politique) && $planete->politique == 1) {
$cristal *= 0.9;
}
return $cristal * $nombre;
}
return $cristal * $nombre;
}
public static function hydrogene($id, $nombre, surface $planete)
{
switch($id)
{
case 0:
$hydrogene = 0;
break;
case 1:
$hydrogene = 0;
break;
case 2:
$hydrogene = 0;
break;
case 3:
$hydrogene = 0;
break;
case 4:
$hydrogene = 0;
break;
case 5:
$hydrogene = 0;
break;
case 6:
$hydrogene = 0;
break;
case 7:
$hydrogene = 0;
break;
case 8:
$hydrogene = 0;
break;
case 9:
$hydrogene = 80;
break;
case 10:
$hydrogene = 100;
break;
case 11:
$hydrogene = 120;
break;
case 12:
$hydrogene = 1500;
break;
case 13:
$hydrogene = 1500;
break;
case 14:
$hydrogene = 1500;
break;
case 15:
$hydrogene = 1500;
break;
default:
trigger_error("Unité ".$id." introuvable dans les données", E_USER_ERROR);
}
public static function hydrogene($id, $nombre, surface $planete)
{
switch ($id) {
case 0:
$hydrogene = 0;
break;
case 1:
$hydrogene = 0;
break;
case 2:
$hydrogene = 0;
break;
case 3:
$hydrogene = 0;
break;
case 4:
$hydrogene = 0;
break;
case 5:
$hydrogene = 0;
break;
case 6:
$hydrogene = 0;
break;
case 7:
$hydrogene = 0;
break;
case 8:
$hydrogene = 0;
break;
case 9:
$hydrogene = 80;
break;
case 10:
$hydrogene = 100;
break;
case 11:
$hydrogene = 120;
break;
case 12:
$hydrogene = 1500;
break;
case 13:
$hydrogene = 1500;
break;
case 14:
$hydrogene = 1500;
break;
case 15:
$hydrogene = 1500;
break;
default:
trigger_error("Unité ".$id." introuvable dans les données", E_USER_ERROR);
}
//On tient compte des bonus
if (isset($planete->politique) && $planete->politique == 1)
$hydrogene *= 0.9;
//On tient compte des bonus
if (isset($planete->politique) && $planete->politique == 1) {
$hydrogene *= 0.9;
}
return $hydrogene * $nombre;
}
return $hydrogene * $nombre;
}
public static function credits($id, $nombre, surface $planete)
{
return 0;
}
public static function credits($id, $nombre, surface $planete)
{
return 0;
}
public static function temps($id, $nombre, surface $planete)
{
switch($id)
{
case 0:
$temps = 720;
$moins = 1;
break;
case 1:
$temps = 2040;
$moins = 3;
break;
case 2:
$temps = 7200;
$moins = 4;
break;
case 3:
$temps = 3960;
$moins = 6;
break;
case 4:
$temps = 600;
$moins = 1;
break;
case 5:
$temps = 1080;
$moins = 2;
break;
case 6:
$temps = 2160;
$moins = 3;
break;
case 7:
$temps = 4680;
$moins = 5;
break;
case 8:
$temps = 1080;
$moins = 1;
break;
case 9:
$temps = 2040;
$moins = 3;
break;
case 10:
$temps = 7200;
$moins = 4;
break;
case 11:
$temps = 3960;
$moins = 7;
break;
case 12:
$temps = 3960;
$moins = 9;
break;
case 13:
$temps = 3960;
$moins = 9;
break;
case 14:
$temps = 3960;
$moins = 9;
break;
case 15:
$temps = 3960;
$moins = 9;
break;
default:
trigger_error("Unité ".$id." introuvable dans les données", E_USER_ERROR);
}
public static function temps($id, $nombre, surface $planete)
{
switch ($id) {
case 0:
$temps = 720;
$moins = 1;
break;
case 1:
$temps = 2040;
$moins = 3;
break;
case 2:
$temps = 7200;
$moins = 4;
break;
case 3:
$temps = 3960;
$moins = 6;
break;
case 4:
$temps = 600;
$moins = 1;
break;
case 5:
$temps = 1080;
$moins = 2;
break;
case 6:
$temps = 2160;
$moins = 3;
break;
case 7:
$temps = 4680;
$moins = 5;
break;
case 8:
$temps = 1080;
$moins = 1;
break;
case 9:
$temps = 2040;
$moins = 3;
break;
case 10:
$temps = 7200;
$moins = 4;
break;
case 11:
$temps = 3960;
$moins = 7;
break;
case 12:
$temps = 3960;
$moins = 9;
break;
case 13:
$temps = 3960;
$moins = 9;
break;
case 14:
$temps = 3960;
$moins = 9;
break;
case 15:
$temps = 3960;
$moins = 9;
break;
default:
trigger_error("Unité ".$id." introuvable dans les données", E_USER_ERROR);
}
//On tient compte de la vitesse
$temps /= VITESSE;
//On tient compte de la vitesse
$temps /= VITESSE;
//On tient compte des bonus
return ceil($temps/pow(1.25, ($planete->batiments[7] - $moins))) * $nombre;
}
//On tient compte des bonus
return ceil($temps/pow(1.25, ($planete->batiments[7] - $moins))) * $nombre;
}
public static function type($id)
{
switch($id)
{
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
return true;
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
return false;
default:
trigger_error("Unité ".$id." introuvable dans les données", E_USER_ERROR);
}
}
public static function type($id)
{
switch ($id) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
return true;
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
return false;
default:
trigger_error("Unité ".$id." introuvable dans les données", E_USER_ERROR);
}
}
public static function image($id, surface $planete)
{
if ($planete->race == "covenant")
{
switch($id)
{
//Unités terrestres
case 0:
return "bansheeqp0.jpg";
break;
case 1:
return "spirit1.jpg";
break;
case 2:
return "phantomfu2.jpg";
break;
case 3:
return "boardingcraft.jpg";
break;
case 4:
return "ghostic1.jpg";
break;
case 5:
return "shadow.jpg";
break;
case 6:
return "spectre.jpg";
break;
case 7:
return "wraith.jpg";
break;
public static function image($id, surface $planete)
{
if ($planete->race == "covenant") {
switch ($id) {
//Unités terrestres
case 0:
return "bansheeqp0.jpg";
break;
case 1:
return "spirit1.jpg";
break;
case 2:
return "phantomfu2.jpg";
break;
case 3:
return "boardingcraft.jpg";
break;
case 4:
return "ghostic1.jpg";
break;
case 5:
return "shadow.jpg";
break;
case 6:
return "spectre.jpg";
break;
case 7:
return "wraith.jpg";
break;
//Défenses
case 8:
return "shade.jpg";
break;
case 9:
return "defcovie.jpg";
break;
case 10:
return "tourellebarreau.jpg";
break;
case 11:
return "tourelle.jpg";
break;
case 12:
return "lanceur_torpilles.jpg";
break;
}
return Donnees::image_covenant_default;
}
elseif ($planete->race == "humain")
{
switch($id)
{
//Unités terrestres
case 0:
return "csnusparrowhawkkp4.jpg";
break;
case 1:
return "pelican.jpg";
break;
case 2:
return "csnushortswordad3.jpg";
break;
case 3:
return "albatross.jpg";
break;
case 4:
return "warthog-vrl.jpg";
break;
case 5:
return "M12G1_LAAV_Warthog.jpg";
break;
case 6:
return "M12A1_LAAV_Warthog.jpg";
break;
case 7:
return "scorpionN.jpg";
break;
//Défenses
case 8:
return "shade.jpg";
break;
case 9:
return "defcovie.jpg";
break;
case 10:
return "tourellebarreau.jpg";
break;
case 11:
return "tourelle.jpg";
break;
case 12:
return "lanceur_torpilles.jpg";
break;
}
return Donnees::image_covenant_default;
} elseif ($planete->race == "humain") {
switch ($id) {
//Unités terrestres
case 0:
return "csnusparrowhawkkp4.jpg";
break;
case 1:
return "pelican.jpg";
break;
case 2:
return "csnushortswordad3.jpg";
break;
case 3:
return "albatross.jpg";
break;
case 4:
return "warthog-vrl.jpg";
break;
case 5:
return "M12G1_LAAV_Warthog.jpg";
break;
case 6:
return "M12A1_LAAV_Warthog.jpg";
break;
case 7:
return "scorpionN.jpg";
break;
//Défenses
case 8:
//return "";
break;
case 9:
//return "";
break;
case 10:
//return "";
break;
case 11:
//return "";
break;
}
return Donnees::image_humain_default;
}
else
trigger_error("Impossible de trouver la race pour ".$planete->race, E_USER_ERROR);
}
//Défenses
case 8:
//return "";
break;
case 9:
//return "";
break;
case 10:
//return "";
break;
case 11:
//return "";
break;
}
return Donnees::image_humain_default;
} else {
trigger_error("Impossible de trouver la race pour ".$planete->race, E_USER_ERROR);
}
}
public static function needed($id, surface $planete, $print = false)
{
$neededTerrestre = array(
array(
array('batiments', 7, 1)
),
array(
array('batiments', 7, 3)
),
array(
array('batiments', 7, 4)
),
array(
array('batiments', 7, 6)
),
array(
array('batiments', 7, 1)
),
array(
array('batiments', 7, 2)
),
array(
array('batiments', 7, 3)
),
array(
array('batiments', 7, 5)
),
//Défenses
array(
array('batiments', 7, 1),
array('technologies', 6, 0)
),
array(
array('batiments', 7, 3),
array('technologies', 6, 3)
),
array(
array('batiments', 7, 4),
array('technologies', 6, 1)
),
array(
array('batiments', 7, 4),
array('technologies', 6, 4)
),
array(
array('batiments', 7, 8),
array('technologies', 6, 2)
),
array(
array('batiments', 7, 8),
array('technologies', 6, 5)
),
array(
array('batiments', 7, 8),
array('technologies', 6, 6)
),
array(
array('batiments', 7, 10),
array('technologies', 7, 11)
)
);
public static function needed($id, surface $planete, $print = false)
{
$neededTerrestre = array(
array(
array('batiments', 7, 1)
),
array(
array('batiments', 7, 3)
),
array(
array('batiments', 7, 4)
),
array(
array('batiments', 7, 6)
),
array(
array('batiments', 7, 1)
),
array(
array('batiments', 7, 2)
),
array(
array('batiments', 7, 3)
),
array(
array('batiments', 7, 5)
),
//Défenses
array(
array('batiments', 7, 1),
array('technologies', 6, 0)
),
array(
array('batiments', 7, 3),
array('technologies', 6, 3)
),
array(
array('batiments', 7, 4),
array('technologies', 6, 1)
),
array(
array('batiments', 7, 4),
array('technologies', 6, 4)
),
array(
array('batiments', 7, 8),
array('technologies', 6, 2)
),
array(
array('batiments', 7, 8),
array('technologies', 6, 5)
),
array(
array('batiments', 7, 8),
array('technologies', 6, 6)
),
array(
array('batiments', 7, 10),
array('technologies', 7, 11)
)
);
if ($print)
return dDonnees::print_neededCheck($neededTerrestre[$id], $planete);
else
return dDonnees::neededCheck($neededTerrestre[$id], $planete);
}
if ($print) {
return dDonnees::print_neededCheck($neededTerrestre[$id], $planete);
} else {
return dDonnees::neededCheck($neededTerrestre[$id], $planete);
}
}
}
?>

View file

@ -3,255 +3,249 @@ require_once("Class/File/interface.php");
class FileAlliancesBatiments extends FileCommun implements File
{
public function objectInFile($object)
{
foreach($this->files as $keyF => $file)
{
foreach($file as $keyE => $element)
{
if ($element[0] == $object)
return array($keyF, $keyE);
}
}
return false;
}
public function objectInFile($object)
{
foreach ($this->files as $keyF => $file) {
foreach ($file as $keyE => $element) {
if ($element[0] == $object) {
return array($keyF, $keyE);
}
}
}
return false;
}
public function nbObjectInFile($object, $type = null)
{
$c = 0;
if (isset($type))
{
if (!isset($type) || $type)
{
foreach($this->files as $file)
{
$c += count(array_keys($file, array($object, true)));
}
}
if (!isset($type) || !$type)
{
foreach($this->files as $file)
{
$c += count(array_keys($file, array($object, false)));
}
}
}
return $c;
}
public function nbObjectInFile($object, $type = null)
{
$c = 0;
if (isset($type)) {
if (!isset($type) || $type) {
foreach ($this->files as $file) {
$c += count(array_keys($file, array($object, true)));
}
}
if (!isset($type) || !$type) {
foreach ($this->files as $file) {
$c += count(array_keys($file, array($object, false)));
}
}
}
return $c;
}
public function addObjet($object, $nombre, surface $planete)
{
//On vérifie que l'on ne dépasse pas la taille maximale de la file
if (!$this->checkMaxSize($planete))
throw new ExceptionHB(1, 1);
public function addObjet($object, $nombre, surface $planete)
{
//On vérifie que l'on ne dépasse pas la taille maximale de la file
if (!$this->checkMaxSize($planete)) {
throw new ExceptionHB(1, 1);
}
//Validation des conditions de construction
if (!dAlliancesBatiments::needed($object, $planete))
throw new ExceptionHB(1, 2);
//Validation des conditions de construction
if (!dAlliancesBatiments::needed($object, $planete)) {
throw new ExceptionHB(1, 2);
}
//On vérifie qu'il n'y ait pas une demande de démolition du même bâtiment
if ($this->nbObjectInFile($object, true) >= 1)
throw new ExceptionHB(1, 7);
//On vérifie qu'il n'y ait pas une demande de démolition du même bâtiment
if ($this->nbObjectInFile($object, true) >= 1) {
throw new ExceptionHB(1, 7);
}
//Calcul du prochain niveau du batiment
$nextLvl = $planete->batiments[$object] + $this->nbObjectInFile($object, false) + 1;
//Calcul du prochain niveau du batiment
$nextLvl = $planete->batiments[$object] + $this->nbObjectInFile($object, false) + 1;
//On recherche le lieu ayant le moins de construction en cours
$lieu = $this->findShorter();
//On recherche le lieu ayant le moins de construction en cours
$lieu = $this->findShorter();
//On rafraîchit le temps de la file si aucun objet n'est en file d'attente
$this->refreshTime($lieu);
//On rafraîchit le temps de la file si aucun objet n'est en file d'attente
$this->refreshTime($lieu);
//On vérifie qu'il y ait assez de ressources sur la planète
if ($planete->checkAndRetireRessources(dAlliancesBatiments::metal($object, $nextLvl, $planete), dAlliancesBatiments::cristal($object, $nextLvl, $planete), dAlliancesBatiments::hydrogene($object, $nextLvl, $planete), dAlliancesBatiments::credits($object, $nextLvl, $planete)))
{
$this->files[$lieu][] = array($object, false);
$planete->addModif("file_bat");
return true;
}
else
throw new ExceptionHB(1, 4);
}
//On vérifie qu'il y ait assez de ressources sur la planète
if ($planete->checkAndRetireRessources(dAlliancesBatiments::metal($object, $nextLvl, $planete), dAlliancesBatiments::cristal($object, $nextLvl, $planete), dAlliancesBatiments::hydrogene($object, $nextLvl, $planete), dAlliancesBatiments::credits($object, $nextLvl, $planete))) {
$this->files[$lieu][] = array($object, false);
$planete->addModif("file_bat");
return true;
} else {
throw new ExceptionHB(1, 4);
}
}
public function addDemolition($object, $nombre, surface $planete)
{
//On vérifie que l'on ne dépasse pas la taille maximale de la file
if (!$this->checkMaxSize($planete))
throw new ExceptionHB(1, 1);
public function addDemolition($object, $nombre, surface $planete)
{
//On vérifie que l'on ne dépasse pas la taille maximale de la file
if (!$this->checkMaxSize($planete)) {
throw new ExceptionHB(1, 1);
}
//On vérifie que le niveau actuel du batiment ne soit non nul
if ($planete->batiments[$object] <= $this->nbObjectInFile($object, false))
throw new ExceptionHB(1, 6);
//On vérifie que le niveau actuel du batiment ne soit non nul
if ($planete->batiments[$object] <= $this->nbObjectInFile($object, false)) {
throw new ExceptionHB(1, 6);
}
//On vérifie qu'il n'y ait pas une demande de construction du même bâtiment
if ($this->nbObjectInFile($object, false) >= 1)
throw new ExceptionHB(1, 7);
//On vérifie qu'il n'y ait pas une demande de construction du même bâtiment
if ($this->nbObjectInFile($object, false) >= 1) {
throw new ExceptionHB(1, 7);
}
//On recherche le lieu ayant le moins de construction en cours
$lieu = $this->findShorter();
//On recherche le lieu ayant le moins de construction en cours
$lieu = $this->findShorter();
//On rafraîchit le temps de la file si aucun objet n'est en file d'attente
$this->refreshTime($lieu);
//On rafraîchit le temps de la file si aucun objet n'est en file d'attente
$this->refreshTime($lieu);
$this->files[$lieu][] = array($object, true);
$this->files[$lieu][] = array($object, true);
$planete->addModif("file_bat");
$planete->addModif("file_bat");
return true;
}
return true;
}
public function delObjet($id, $nombre, $lieu, surface $planete)
{
//Vérification de l'existance de l'objet en file d'attente
if (empty($this->files[$lieu][$id]))
throw new ExceptionHB(1, 5);
public function delObjet($id, $nombre, $lieu, surface $planete)
{
//Vérification de l'existance de l'objet en file d'attente
if (empty($this->files[$lieu][$id])) {
throw new ExceptionHB(1, 5);
}
//On récupère le type de batiment
$object = $this->files[$lieu][$id][0];
//On récupère le type de batiment
$object = $this->files[$lieu][$id][0];
//On gère les démolition
//@todo -cFileBatiments Est-ce vraiment utile de calculer le niveau du batiment en cas de démolition ?
if ($this->files[$lieu][$id][1])
$lvlAnnule = $planete->batiments[$object] - $this->nbObjectInFile($object, true) + 1;
else
$lvlAnnule = $planete->batiments[$object] + $this->nbObjectInFile($object, false);
//On gère les démolition
//@todo -cFileBatiments Est-ce vraiment utile de calculer le niveau du batiment en cas de démolition ?
if ($this->files[$lieu][$id][1]) {
$lvlAnnule = $planete->batiments[$object] - $this->nbObjectInFile($object, true) + 1;
} else {
$lvlAnnule = $planete->batiments[$object] + $this->nbObjectInFile($object, false);
}
//On met à jour le temps si on vient d'annuler le premier batiment en lice
if ($id == $this->findFirstKey($lieu))
$this->times[$lieu] = time();
//On met à jour le temps si on vient d'annuler le premier batiment en lice
if ($id == $this->findFirstKey($lieu)) {
$this->times[$lieu] = time();
}
$planete->addModif("file_bat");
$planete->addModif("file_bat");
if (!$this->files[$lieu][$id][1])
{
//On redonne 60% des ressources au joueur si c'est la première construction dans la file d'attente
if ($id == 0)
$planete->addRessources(dAlliancesBatiments::metal($object, $lvlAnnule, $planete)*0.6, dAlliancesBatiments::cristal($object, $lvlAnnule, $planete)*0.6, dAlliancesBatiments::hydrogene($object, $lvlAnnule, $planete)*0.6, dAlliancesBatiments::credits($object, $lvlAnnule, $planete)*0.6);
else
$planete->addRessources(dAlliancesBatiments::metal($object, $lvlAnnule, $planete), dAlliancesBatiments::cristal($object, $lvlAnnule, $planete), dAlliancesBatiments::hydrogene($object, $lvlAnnule, $planete), dAlliancesBatiments::credits($object, $lvlAnnule, $planete));
}
if (!$this->files[$lieu][$id][1]) {
//On redonne 60% des ressources au joueur si c'est la première construction dans la file d'attente
if ($id == 0) {
$planete->addRessources(dAlliancesBatiments::metal($object, $lvlAnnule, $planete)*0.6, dAlliancesBatiments::cristal($object, $lvlAnnule, $planete)*0.6, dAlliancesBatiments::hydrogene($object, $lvlAnnule, $planete)*0.6, dAlliancesBatiments::credits($object, $lvlAnnule, $planete)*0.6);
} else {
$planete->addRessources(dAlliancesBatiments::metal($object, $lvlAnnule, $planete), dAlliancesBatiments::cristal($object, $lvlAnnule, $planete), dAlliancesBatiments::hydrogene($object, $lvlAnnule, $planete), dAlliancesBatiments::credits($object, $lvlAnnule, $planete));
}
}
//Effacement de la file
unset($this->files[$lieu][$id]);
//Effacement de la file
unset($this->files[$lieu][$id]);
return true;
}
return true;
}
public function ready(SURFACE $planete)
{
//On parcourt la liste des lieux de construction
foreach($this->files as $keyF => $file)
{
//On vérifie qu'il y a bien des éléments dans cette file d'attente
if (count($file) == 0)
continue;
public function ready(SURFACE $planete)
{
//On parcourt la liste des lieux de construction
foreach ($this->files as $keyF => $file) {
//On vérifie qu'il y a bien des éléments dans cette file d'attente
if (count($file) == 0) {
continue;
}
//On parcourt la file
foreach ($file as $keyE => $element)
{
$tempsEcoule = time() - $this->times[$keyF];
//On parcourt la file
foreach ($file as $keyE => $element) {
$tempsEcoule = time() - $this->times[$keyF];
//On gère les démolitions
if ($element[1])
{
//On récupère le niveau actuel du batiment
$lvl = $planete->batiments[$element[0]];
//On gère les démolitions
if ($element[1]) {
//On récupère le niveau actuel du batiment
$lvl = $planete->batiments[$element[0]];
//On calcul le temps de démolition nécessaire (60% du niveau actuel)
$tempsNecessaire = dAlliancesBatiments::temps($element[0], $lvl, $planete, true);
//On calcul le temps de démolition nécessaire (60% du niveau actuel)
$tempsNecessaire = dAlliancesBatiments::temps($element[0], $lvl, $planete, true);
if ($tempsEcoule >= $tempsNecessaire)
{
$metal = dAlliancesBatiments::metal($element[0], $lvl, $planete);
$cristal = dAlliancesBatiments::cristal($element[0], $lvl, $planete);
$hydrogene = dAlliancesBatiments::hydrogene($element[0], $lvl, $planete);
if ($tempsEcoule >= $tempsNecessaire) {
$metal = dAlliancesBatiments::metal($element[0], $lvl, $planete);
$cristal = dAlliancesBatiments::cristal($element[0], $lvl, $planete);
$hydrogene = dAlliancesBatiments::hydrogene($element[0], $lvl, $planete);
//On redonne 70% des ressources du batiment au joueur
$planete->addRessources($metal*0.7, $cristal*0.7, $hydrogene*0.7);
//On redonne 70% des ressources du batiment au joueur
$planete->addRessources($metal*0.7, $cristal*0.7, $hydrogene*0.7);
//On retire un niveau au batiment
$planete->batiments[$element[0]]--;
//On retire un niveau au batiment
$planete->batiments[$element[0]]--;
//On efface l'entrée de la file et on met à jour le temps de la file
unset($this->files[$keyF][$keyE]);
$this->times[$keyF] += $tempsNecessaire;
//On efface l'entrée de la file et on met à jour le temps de la file
unset($this->files[$keyF][$keyE]);
$this->times[$keyF] += $tempsNecessaire;
//On demande la mise à jour des champs modifiés
$planete->addModif(array("batiments", $element[0]));
$planete->addModif("file_bat");
//On demande la mise à jour des champs modifiés
$planete->addModif(array("batiments", $element[0]));
$planete->addModif("file_bat");
//On retire les points
$planete->addPoints($metal, $cristal, $hydrogene, 0, true);
//On retire les points
$planete->addPoints($metal, $cristal, $hydrogene, 0, true);
unset($metal, $cristal, $hydrogene);
}
//Si le temps écoulé n'est pas suffisant pour ce batiment, on annule tous les suivants
else
break;
}
else //Cas de la construction
{
//Récupération du niveau du batiment
$lvl = $planete->batiments[$element[0]] + 1;
unset($metal, $cristal, $hydrogene);
}
//Si le temps écoulé n'est pas suffisant pour ce batiment, on annule tous les suivants
else {
break;
}
} else { //Cas de la construction
//Récupération du niveau du batiment
$lvl = $planete->batiments[$element[0]] + 1;
$tempsNecessaire = dAlliancesBatiments::temps($element[0], $lvl, $planete);
$tempsNecessaire = dAlliancesBatiments::temps($element[0], $lvl, $planete);
//Si le temps écoulé est suffisant
if ($tempsEcoule >= $tempsNecessaire)
{
//On ajoute un niveau au batiment
$planete->batiments[$element[0]]++;
//Si le temps écoulé est suffisant
if ($tempsEcoule >= $tempsNecessaire) {
//On ajoute un niveau au batiment
$planete->batiments[$element[0]]++;
//On efface l'entrée de la file et on met à jour le temps de la file
unset($this->files[$keyF][$keyE]);
$this->times[$keyF] += $tempsNecessaire;
//On efface l'entrée de la file et on met à jour le temps de la file
unset($this->files[$keyF][$keyE]);
$this->times[$keyF] += $tempsNecessaire;
//On demande la mise à jour des champs modifiés
$planete->addModif(array("batiments", $element[0]));
$planete->addModif("file_bat");
//On demande la mise à jour des champs modifiés
$planete->addModif(array("batiments", $element[0]));
$planete->addModif("file_bat");
//On ajoute les points
$planete->addPoints(dAlliancesBatiments::metal($element[0], $planete->batiments[$element[0]], $planete), dAlliancesBatiments::cristal($element[0], $planete->batiments[$element[0]], $planete), dAlliancesBatiments::hydrogene($element[0], $planete->batiments[$element[0]], $planete));
}
//Si le temps écoulé n'est pas suffisant pour ce batiment, on annule tous les suivants
else
break;
}
}
}
}
//On ajoute les points
$planete->addPoints(dAlliancesBatiments::metal($element[0], $planete->batiments[$element[0]], $planete), dAlliancesBatiments::cristal($element[0], $planete->batiments[$element[0]], $planete), dAlliancesBatiments::hydrogene($element[0], $planete->batiments[$element[0]], $planete));
}
//Si le temps écoulé n'est pas suffisant pour ce batiment, on annule tous les suivants
else {
break;
}
}
}
}
}
public function printFile(SURFACE $planete, $lieu = NULL)
{
$out = array();
foreach ($this->files as $keyF => $file)
{
if (isset($lieu) && $lieu != $keyF)
continue;
public function printFile(SURFACE $planete, $lieu = null)
{
$out = array();
foreach ($this->files as $keyF => $file) {
if (isset($lieu) && $lieu != $keyF) {
continue;
}
$prems = true;
foreach ($file as $keyE => $element)
{
if ($element[1]) //Cas d'une démolition
{
$temps = dAlliancesBatiments::temps($element[0], $planete->batiments[$element[0]], $planete, true);
if ($prems)
$temps -= time() - $this->times[$keyF];
$out[$keyF][$keyE] = array($element[0], $element[1], ceil($temps), $prems);
}
else //Cas d'une construction
{
$temps = dAlliancesBatiments::temps($element[0], $planete->batiments[$element[0]]+1, $planete);
if ($prems)
$temps -= time() - $this->times[$keyF];
$out[$keyF][$keyE] = array($element[0], $element[1], ceil($temps), $prems);
}
$prems = false;
}
}
return $out;
}
$prems = true;
foreach ($file as $keyE => $element) {
if ($element[1]) { //Cas d'une démolition
$temps = dAlliancesBatiments::temps($element[0], $planete->batiments[$element[0]], $planete, true);
if ($prems) {
$temps -= time() - $this->times[$keyF];
}
$out[$keyF][$keyE] = array($element[0], $element[1], ceil($temps), $prems);
} else { //Cas d'une construction
$temps = dAlliancesBatiments::temps($element[0], $planete->batiments[$element[0]]+1, $planete);
if ($prems) {
$temps -= time() - $this->times[$keyF];
}
$out[$keyF][$keyE] = array($element[0], $element[1], ceil($temps), $prems);
}
$prems = false;
}
}
return $out;
}
}
?>

View file

@ -3,266 +3,258 @@ require_once("Class/File/interface.php");
class FileBatiments extends FileCommun implements File
{
public function objectInFile($object)
{
foreach($this->files as $keyF => $file)
{
foreach($file as $keyE => $element)
{
if ($element[0] == $object)
return array($keyF, $keyE);
}
}
return false;
}
public function objectInFile($object)
{
foreach ($this->files as $keyF => $file) {
foreach ($file as $keyE => $element) {
if ($element[0] == $object) {
return array($keyF, $keyE);
}
}
}
return false;
}
public function nbObjectInFile($object, $type = null)
{
$c = 0;
if (!isset($object))
{
foreach($this->files as $file)
{
$c += count($file);
}
}
else
{
if (!isset($type) || $type)
{
foreach($this->files as $file)
{
$c += count(array_keys($file, array($object, true)));
}
}
if (!isset($type) || !$type)
{
foreach($this->files as $file)
{
$c += count(array_keys($file, array($object, false)));
}
}
}
return $c;
}
public function nbObjectInFile($object, $type = null)
{
$c = 0;
if (!isset($object)) {
foreach ($this->files as $file) {
$c += count($file);
}
} else {
if (!isset($type) || $type) {
foreach ($this->files as $file) {
$c += count(array_keys($file, array($object, true)));
}
}
if (!isset($type) || !$type) {
foreach ($this->files as $file) {
$c += count(array_keys($file, array($object, false)));
}
}
}
return $c;
}
public function addObjet($object, $nombre, surface $planete)
{
//On vérifie que l'on ne dépasse pas la taille maximale de la file
if (!$this->checkMaxSize($planete))
throw new ExceptionHB(1, 1);
public function addObjet($object, $nombre, surface $planete)
{
//On vérifie que l'on ne dépasse pas la taille maximale de la file
if (!$this->checkMaxSize($planete)) {
throw new ExceptionHB(1, 1);
}
//Validation des conditions de construction
if (!dBatiments::needed($object, $planete))
throw new ExceptionHB(1, 2);
//Validation des conditions de construction
if (!dBatiments::needed($object, $planete)) {
throw new ExceptionHB(1, 2);
}
//On vérifie qu'il n'y ait pas une demande de démolition du même bâtiment
if ($this->nbObjectInFile($object, true) >= 1)
throw new ExceptionHB(1, 7);
//On vérifie qu'il n'y ait pas une demande de démolition du même bâtiment
if ($this->nbObjectInFile($object, true) >= 1) {
throw new ExceptionHB(1, 7);
}
//On vérifie qu'il reste suffisamment de place sur la planète
if ($planete->casesRest <= 0 || $planete->casesRest <= $this->nbObjectInFile(null))
throw new ExceptionHB(1, 0);
//On vérifie qu'il reste suffisamment de place sur la planète
if ($planete->casesRest <= 0 || $planete->casesRest <= $this->nbObjectInFile(null)) {
throw new ExceptionHB(1, 0);
}
//Calcul du prochain niveau du batiment
$nextLvl = $planete->batiments[$object] + $this->nbObjectInFile($object, false) + 1;
//Calcul du prochain niveau du batiment
$nextLvl = $planete->batiments[$object] + $this->nbObjectInFile($object, false) + 1;
//On recherche le lieu ayant le moins de construction en cours
$lieu = $this->findShorter();
//On recherche le lieu ayant le moins de construction en cours
$lieu = $this->findShorter();
//On rafraîchit le temps de la file si aucun objet n'est en file d'attente
$this->refreshTime($lieu);
//On rafraîchit le temps de la file si aucun objet n'est en file d'attente
$this->refreshTime($lieu);
//On vérifie qu'il y ait assez de ressources sur la planète
if ($planete->checkAndRetireRessources(dBatiments::metal($object, $nextLvl, $planete), dBatiments::cristal($object, $nextLvl, $planete), dBatiments::hydrogene($object, $nextLvl, $planete), dBatiments::credits($object, $nextLvl, $planete)))
{
$this->files[$lieu][] = array($object, false);
$planete->addModif("file_bat");
return true;
}
else
throw new ExceptionHB(1, 4);
}
//On vérifie qu'il y ait assez de ressources sur la planète
if ($planete->checkAndRetireRessources(dBatiments::metal($object, $nextLvl, $planete), dBatiments::cristal($object, $nextLvl, $planete), dBatiments::hydrogene($object, $nextLvl, $planete), dBatiments::credits($object, $nextLvl, $planete))) {
$this->files[$lieu][] = array($object, false);
$planete->addModif("file_bat");
return true;
} else {
throw new ExceptionHB(1, 4);
}
}
public function addDemolition($object, $nombre, surface $planete)
{
//On vérifie que l'on ne dépasse pas la taille maximale de la file
if (!$this->checkMaxSize($planete))
throw new ExceptionHB(1, 1);
public function addDemolition($object, $nombre, surface $planete)
{
//On vérifie que l'on ne dépasse pas la taille maximale de la file
if (!$this->checkMaxSize($planete)) {
throw new ExceptionHB(1, 1);
}
//On vérifie que le niveau actuel du batiment ne soit non nul
if ($planete->batiments[$object] <= $this->nbObjectInFile($object, false))
throw new ExceptionHB(1, 6);
//On vérifie que le niveau actuel du batiment ne soit non nul
if ($planete->batiments[$object] <= $this->nbObjectInFile($object, false)) {
throw new ExceptionHB(1, 6);
}
//On vérifie qu'il n'y ait pas une demande de construction du même bâtiment
if ($this->nbObjectInFile($object, false) >= 1)
throw new ExceptionHB(1, 7);
//On vérifie qu'il n'y ait pas une demande de construction du même bâtiment
if ($this->nbObjectInFile($object, false) >= 1) {
throw new ExceptionHB(1, 7);
}
//On recherche le lieu ayant le moins de construction en cours
$lieu = $this->findShorter();
//On recherche le lieu ayant le moins de construction en cours
$lieu = $this->findShorter();
//On rafraîchit le temps de la file si aucun objet n'est en file d'attente
$this->refreshTime($lieu);
//On rafraîchit le temps de la file si aucun objet n'est en file d'attente
$this->refreshTime($lieu);
$this->files[$lieu][] = array($object, true);
$this->files[$lieu][] = array($object, true);
$planete->addModif("file_bat");
$planete->addModif("file_bat");
return true;
}
return true;
}
public function delObjet($id, $nombre, $lieu, surface $planete)
{
//Vérification de l'existance de l'objet en file d'attente
if (empty($this->files[$lieu][$id]))
throw new ExceptionHB(1, 5);
public function delObjet($id, $nombre, $lieu, surface $planete)
{
//Vérification de l'existance de l'objet en file d'attente
if (empty($this->files[$lieu][$id])) {
throw new ExceptionHB(1, 5);
}
//On récupère le type de batiment
$object = $this->files[$lieu][$id][0];
//On récupère le type de batiment
$object = $this->files[$lieu][$id][0];
//On gère les démolition
//@todo -cFileBatiments Est-ce vraiment utile de calculer le niveau du batiment en cas de démolition ?
if ($this->files[$lieu][$id][1])
$lvlAnnule = $planete->batiments[$object] - $this->nbObjectInFile($object, true) + 1;
else
$lvlAnnule = $planete->batiments[$object] + $this->nbObjectInFile($object, false);
//On gère les démolition
//@todo -cFileBatiments Est-ce vraiment utile de calculer le niveau du batiment en cas de démolition ?
if ($this->files[$lieu][$id][1]) {
$lvlAnnule = $planete->batiments[$object] - $this->nbObjectInFile($object, true) + 1;
} else {
$lvlAnnule = $planete->batiments[$object] + $this->nbObjectInFile($object, false);
}
//On met à jour le temps si on vient d'annuler le premier batiment en lice
if ($id == $this->findFirstKey($lieu))
$this->times[$lieu] = time();
//On met à jour le temps si on vient d'annuler le premier batiment en lice
if ($id == $this->findFirstKey($lieu)) {
$this->times[$lieu] = time();
}
$planete->addModif("file_bat");
$planete->addModif("file_bat");
if (!$this->files[$lieu][$id][1])
{
//On redonne 60% des ressources au joueur si c'est la première construction dans la file d'attente
if ($id == 0)
$planete->addRessources(dBatiments::metal($object, $lvlAnnule, $planete)*0.6, dBatiments::cristal($object, $lvlAnnule, $planete)*0.6, dBatiments::hydrogene($object, $lvlAnnule, $planete)*0.6, dBatiments::credits($object, $lvlAnnule, $planete)*0.6);
else
$planete->addRessources(dBatiments::metal($object, $lvlAnnule, $planete), dBatiments::cristal($object, $lvlAnnule, $planete), dBatiments::hydrogene($object, $lvlAnnule, $planete), dBatiments::credits($object, $lvlAnnule, $planete));
}
if (!$this->files[$lieu][$id][1]) {
//On redonne 60% des ressources au joueur si c'est la première construction dans la file d'attente
if ($id == 0) {
$planete->addRessources(dBatiments::metal($object, $lvlAnnule, $planete)*0.6, dBatiments::cristal($object, $lvlAnnule, $planete)*0.6, dBatiments::hydrogene($object, $lvlAnnule, $planete)*0.6, dBatiments::credits($object, $lvlAnnule, $planete)*0.6);
} else {
$planete->addRessources(dBatiments::metal($object, $lvlAnnule, $planete), dBatiments::cristal($object, $lvlAnnule, $planete), dBatiments::hydrogene($object, $lvlAnnule, $planete), dBatiments::credits($object, $lvlAnnule, $planete));
}
}
//Effacement de la file
unset($this->files[$lieu][$id]);
//Effacement de la file
unset($this->files[$lieu][$id]);
return true;
}
return true;
}
public function ready(SURFACE $planete)
{
//On parcourt la liste des lieux de construction
foreach($this->files as $keyF => $file)
{
//On vérifie qu'il y a bien des éléments dans cette file d'attente
if (count($file) == 0)
continue;
public function ready(SURFACE $planete)
{
//On parcourt la liste des lieux de construction
foreach ($this->files as $keyF => $file) {
//On vérifie qu'il y a bien des éléments dans cette file d'attente
if (count($file) == 0) {
continue;
}
//On parcourt la file
foreach ($file as $keyE => $element)
{
$tempsEcoule = time() - $this->times[$keyF];
//On parcourt la file
foreach ($file as $keyE => $element) {
$tempsEcoule = time() - $this->times[$keyF];
//On gère les démolitions
if ($element[1])
{
//On récupère le niveau actuel du batiment
$lvl = $planete->batiments[$element[0]];
//On gère les démolitions
if ($element[1]) {
//On récupère le niveau actuel du batiment
$lvl = $planete->batiments[$element[0]];
//On calcul le temps de démolition nécessaire (60% du niveau actuel)
$tempsNecessaire = dBatiments::temps($element[0], $lvl, $planete, true);
//On calcul le temps de démolition nécessaire (60% du niveau actuel)
$tempsNecessaire = dBatiments::temps($element[0], $lvl, $planete, true);
if ($tempsEcoule >= $tempsNecessaire)
{
$metal = dBatiments::metal($element[0], $lvl, $planete);
$cristal = dBatiments::cristal($element[0], $lvl, $planete);
$hydrogene = dBatiments::hydrogene($element[0], $lvl, $planete);
if ($tempsEcoule >= $tempsNecessaire) {
$metal = dBatiments::metal($element[0], $lvl, $planete);
$cristal = dBatiments::cristal($element[0], $lvl, $planete);
$hydrogene = dBatiments::hydrogene($element[0], $lvl, $planete);
//On redonne 70% des ressources du batiment au joueur
$planete->addRessources($metal*0.7, $cristal*0.7, $hydrogene*0.7);
//On redonne 70% des ressources du batiment au joueur
$planete->addRessources($metal*0.7, $cristal*0.7, $hydrogene*0.7);
//On retire un niveau au batiment
$planete->batiments[$element[0]]--;
//On retire un niveau au batiment
$planete->batiments[$element[0]]--;
//On efface l'entrée de la file et on met à jour le temps de la file
unset($this->files[$keyF][$keyE]);
$this->times[$keyF] += $tempsNecessaire;
//On efface l'entrée de la file et on met à jour le temps de la file
unset($this->files[$keyF][$keyE]);
$this->times[$keyF] += $tempsNecessaire;
//On demande la mise à jour des champs modifiés
$planete->addModif(array("batiments", $element[0]));
$planete->addModif("file_bat");
//On demande la mise à jour des champs modifiés
$planete->addModif(array("batiments", $element[0]));
$planete->addModif("file_bat");
//On retire les points
$planete->addPoints($metal, $cristal, $hydrogene, 0, true);
//On retire les points
$planete->addPoints($metal, $cristal, $hydrogene, 0, true);
unset($metal, $cristal, $hydrogene);
}
//Si le temps écoulé n'est pas suffisant pour ce batiment, on annule tous les suivants
else
break;
}
else //Cas de la construction
{
//Récupération du niveau du batiment
$lvl = $planete->batiments[$element[0]] + 1;
unset($metal, $cristal, $hydrogene);
}
//Si le temps écoulé n'est pas suffisant pour ce batiment, on annule tous les suivants
else {
break;
}
} else { //Cas de la construction
//Récupération du niveau du batiment
$lvl = $planete->batiments[$element[0]] + 1;
$tempsNecessaire = dBatiments::temps($element[0], $lvl, $planete);
$tempsNecessaire = dBatiments::temps($element[0], $lvl, $planete);
//Si le temps écoulé est suffisant
if ($tempsEcoule >= $tempsNecessaire)
{
//On ajoute un niveau au batiment
$planete->batiments[$element[0]]++;
//Si le temps écoulé est suffisant
if ($tempsEcoule >= $tempsNecessaire) {
//On ajoute un niveau au batiment
$planete->batiments[$element[0]]++;
//On efface l'entrée de la file et on met à jour le temps de la file
unset($this->files[$keyF][$keyE]);
$this->times[$keyF] += $tempsNecessaire;
//On efface l'entrée de la file et on met à jour le temps de la file
unset($this->files[$keyF][$keyE]);
$this->times[$keyF] += $tempsNecessaire;
//On demande la mise à jour des champs modifiés
$planete->addModif(array("batiments", $element[0]));
$planete->addModif("file_bat");
//On demande la mise à jour des champs modifiés
$planete->addModif(array("batiments", $element[0]));
$planete->addModif("file_bat");
//On ajoute les points
$planete->addPoints(dBatiments::metal($element[0], $planete->batiments[$element[0]], $planete), dBatiments::cristal($element[0], $planete->batiments[$element[0]], $planete), dBatiments::hydrogene($element[0], $planete->batiments[$element[0]], $planete));
}
//Si le temps écoulé n'est pas suffisant pour ce batiment, on annule tous les suivants
else
break;
}
}
}
}
//On ajoute les points
$planete->addPoints(dBatiments::metal($element[0], $planete->batiments[$element[0]], $planete), dBatiments::cristal($element[0], $planete->batiments[$element[0]], $planete), dBatiments::hydrogene($element[0], $planete->batiments[$element[0]], $planete));
}
//Si le temps écoulé n'est pas suffisant pour ce batiment, on annule tous les suivants
else {
break;
}
}
}
}
}
public function printFile(SURFACE $planete, $lieu = null)
{
$out = array();
foreach ($this->files as $keyF => $file)
{
if (isset($lieu) && $lieu != $keyF)
continue;
public function printFile(SURFACE $planete, $lieu = null)
{
$out = array();
foreach ($this->files as $keyF => $file) {
if (isset($lieu) && $lieu != $keyF) {
continue;
}
$prems = true;
foreach ($file as $keyE => $element)
{
if ($element[1]) //Cas d'une démolition
{
$temps = dBatiments::temps($element[0], $planete->batiments[$element[0]], $planete, true);
if ($prems)
$temps -= time() - $this->times[$keyF];
$out[$keyF][$keyE] = array($element[0], $element[1], ceil($temps), $prems);
}
else //Cas d'une construction
{
$temps = dBatiments::temps($element[0], $planete->batiments[$element[0]]+1, $planete);
if ($prems)
$temps -= time() - $this->times[$keyF];
$out[$keyF][$keyE] = array($element[0], $element[1], ceil($temps), $prems);
}
$prems = false;
}
}
return $out;
}
$prems = true;
foreach ($file as $keyE => $element) {
if ($element[1]) { //Cas d'une démolition
$temps = dBatiments::temps($element[0], $planete->batiments[$element[0]], $planete, true);
if ($prems) {
$temps -= time() - $this->times[$keyF];
}
$out[$keyF][$keyE] = array($element[0], $element[1], ceil($temps), $prems);
} else { //Cas d'une construction
$temps = dBatiments::temps($element[0], $planete->batiments[$element[0]]+1, $planete);
if ($prems) {
$temps -= time() - $this->times[$keyF];
}
$out[$keyF][$keyE] = array($element[0], $element[1], ceil($temps), $prems);
}
$prems = false;
}
}
return $out;
}
}
?>

View file

@ -3,307 +3,304 @@ require_once("Class/File/interface.php");
class FileCaserne extends FileCommun implements File
{
public function objectInFile($object, $lieu = null)
{
if (isset($lieu))
{
if (!empty($this->files[$lieu]))
{
foreach($this->files[$lieu] as $keyE => $element)
{
if ($element[0] == $object)
return array($lieu, $keyE);
}
}
}
else
{
foreach($this->files as $keyF => $file)
{
foreach($file as $keyE => $element)
{
if ($element[0] == $object)
return array($keyF, $keyE);
}
}
}
public function objectInFile($object, $lieu = null)
{
if (isset($lieu)) {
if (!empty($this->files[$lieu])) {
foreach ($this->files[$lieu] as $keyE => $element) {
if ($element[0] == $object) {
return array($lieu, $keyE);
}
}
}
} else {
foreach ($this->files as $keyF => $file) {
foreach ($file as $keyE => $element) {
if ($element[0] == $object) {
return array($keyF, $keyE);
}
}
}
}
return false;
}
return false;
}
public function nbObjectInFile($object)
{
$c = 0;
foreach($this->files as $key => $file)
{
foreach($file as $element)
{
if ($element[0] == $object)
$c += $element[1];
}
}
return $c;
}
public function nbObjectInFile($object)
{
$c = 0;
foreach ($this->files as $key => $file) {
foreach ($file as $element) {
if ($element[0] == $object) {
$c += $element[1];
}
}
}
return $c;
}
public function addObjet($object, $nombre, surface $planete, $lieu = null)
{
//Vérification du nombre passé en entrée
if (!is_numeric($nombre) || $nombre < 0 || $nombre > 99999)
throw new ExceptionHB(3, 8);
public function addObjet($object, $nombre, surface $planete, $lieu = null)
{
//Vérification du nombre passé en entrée
if (!is_numeric($nombre) || $nombre < 0 || $nombre > 99999) {
throw new ExceptionHB(3, 8);
}
//Validation des conditions de construction
if (!dCaserne::needed($object, $planete))
throw new ExceptionHB(3, 2);
//Validation des conditions de construction
if (!dCaserne::needed($object, $planete)) {
throw new ExceptionHB(3, 2);
}
//On vérifie que l'on ne dépasse pas la taille maximale de la file
if (!($sauvLastKey = $this->objectInFile($object, $lieu)) && !$this->checkMaxSize($planete, $lieu))
throw new ExceptionHB(3, 1);
//On vérifie que l'on ne dépasse pas la taille maximale de la file
if (!($sauvLastKey = $this->objectInFile($object, $lieu)) && !$this->checkMaxSize($planete, $lieu)) {
throw new ExceptionHB(3, 1);
}
//On tronque au maximum d'unités constructible sur la planète
if (($metal = dCaserne::metal($object, 1, $planete)) > 0)
$metal = $planete->metal/$metal;
else
$metal = $nombre;
if (($cristal = dCaserne::cristal($object, 1, $planete)) > 0)
$cristal = $planete->cristal/$cristal;
else
$cristal = $nombre;
if (($hydrogene = dCaserne::hydrogene($object, 1, $planete)) > 0)
$hydrogene = $planete->hydrogene/$hydrogene;
else
$hydrogene = $nombre;
//On tronque au maximum d'unités constructible sur la planète
if (($metal = dCaserne::metal($object, 1, $planete)) > 0) {
$metal = $planete->metal/$metal;
} else {
$metal = $nombre;
}
if (($cristal = dCaserne::cristal($object, 1, $planete)) > 0) {
$cristal = $planete->cristal/$cristal;
} else {
$cristal = $nombre;
}
if (($hydrogene = dCaserne::hydrogene($object, 1, $planete)) > 0) {
$hydrogene = $planete->hydrogene/$hydrogene;
} else {
$hydrogene = $nombre;
}
$nombre = floor(min($nombre, $metal, $cristal, $hydrogene));
$nombre = floor(min($nombre, $metal, $cristal, $hydrogene));
//On vérifie qu'il y ait assez de ressources sur la planète
if ($planete->checkAndRetireRessources(dCaserne::metal($object, $nombre, $planete), dCaserne::cristal($object, $nombre, $planete), dCaserne::hydrogene($object, $nombre, $planete), dCaserne::credits($object, $nombre, $planete)))
{
//Si il existe déjà l'objet en file d'attente, on l'ajoute
if(isset($sauvLastKey) && isset($this->files[$sauvLastKey[0]][$sauvLastKey[1]]))
{
//On rafraîchit le temps de la file si aucun objet n'est en file d'attente
$this->refreshTime($sauvLastKey[0]);
//On vérifie qu'il y ait assez de ressources sur la planète
if ($planete->checkAndRetireRessources(dCaserne::metal($object, $nombre, $planete), dCaserne::cristal($object, $nombre, $planete), dCaserne::hydrogene($object, $nombre, $planete), dCaserne::credits($object, $nombre, $planete))) {
//Si il existe déjà l'objet en file d'attente, on l'ajoute
if (isset($sauvLastKey) && isset($this->files[$sauvLastKey[0]][$sauvLastKey[1]])) {
//On rafraîchit le temps de la file si aucun objet n'est en file d'attente
$this->refreshTime($sauvLastKey[0]);
$this->files[$sauvLastKey[0]][$sauvLastKey[1]][1] += $nombre;
}
else
{
if (!isset($lieu))
{
//On recherche le lieu ayant le moins de construction en cours
$lieu = $this->findShorter();
}
$this->files[$sauvLastKey[0]][$sauvLastKey[1]][1] += $nombre;
} else {
if (!isset($lieu)) {
//On recherche le lieu ayant le moins de construction en cours
$lieu = $this->findShorter();
}
//On rafraîchit le temps de la file si aucun objet n'est en file d'attente
$this->refreshTime($lieu);
//On rafraîchit le temps de la file si aucun objet n'est en file d'attente
$this->refreshTime($lieu);
$this->files[$lieu][] = array($object, $nombre, false);
}
$this->files[$lieu][] = array($object, $nombre, false);
}
$planete->addModif("file_cas");
return true;
}
else
throw new ExceptionHB(3, 4);
}
$planete->addModif("file_cas");
return true;
} else {
throw new ExceptionHB(3, 4);
}
}
public function addDemolition($object, $nombre, surface $planete, $lieu = null)
{
//On vérifie que l'on ne dépasse pas la taille maximale de la file
if (!$this->checkMaxSize($planete, $lieu) && !($sauvLastKey = $this->objectInFile($object, $lieu)))
throw new ExceptionHB(3, 1);
public function addDemolition($object, $nombre, surface $planete, $lieu = null)
{
//On vérifie que l'on ne dépasse pas la taille maximale de la file
if (!$this->checkMaxSize($planete, $lieu) && !($sauvLastKey = $this->objectInFile($object, $lieu))) {
throw new ExceptionHB(3, 1);
}
//Vérification du nombre passé en entrée
if (!is_numeric($nombre) || $nombre < 0 || $nombre > 99999)
throw new ExceptionHB(3, 8);
//Vérification du nombre passé en entrée
if (!is_numeric($nombre) || $nombre < 0 || $nombre > 99999) {
throw new ExceptionHB(3, 8);
}
//On vérifie que le nombre d'unité actuel soit non nul
if ($planete->casernes[$object] < $nombre)
throw new ExceptionHB(3, 6);
//On vérifie que le nombre d'unité actuel soit non nul
if ($planete->casernes[$object] < $nombre) {
throw new ExceptionHB(3, 6);
}
if (!isset($lieu))
{
//On recherche le lieu ayant le moins de construction en cours
$lieu = $this->findShorter();
}
if (!isset($lieu)) {
//On recherche le lieu ayant le moins de construction en cours
$lieu = $this->findShorter();
}
//On rafraîchit le temps de la file si aucun objet n'est en file d'attente
$this->refreshTime($lieu);
//On rafraîchit le temps de la file si aucun objet n'est en file d'attente
$this->refreshTime($lieu);
//Si il existe déjà l'objet en file d'attente, on l'ajoute
if(isset($sauvLastKey))
$this->files[$sauvLastKey[0]][$sauvLastKey[1]][1] += $nombre;
else
$this->files[$lieu][] = array($object, $nombre, false);
//Si il existe déjà l'objet en file d'attente, on l'ajoute
if (isset($sauvLastKey)) {
$this->files[$sauvLastKey[0]][$sauvLastKey[1]][1] += $nombre;
} else {
$this->files[$lieu][] = array($object, $nombre, false);
}
$planete->addModif("file_cas");
$planete->addModif("file_cas");
return true;
}
return true;
}
public function delObjet($id, $nombre, $lieu, surface $planete)
{
//Vérification de l'existance de l'objet en file d'attente
if (empty($this->files[$lieu][$id]))
throw new ExceptionHB(1, 5);
public function delObjet($id, $nombre, $lieu, surface $planete)
{
//Vérification de l'existance de l'objet en file d'attente
if (empty($this->files[$lieu][$id])) {
throw new ExceptionHB(1, 5);
}
//Si $nombre est supérieur au nombre présent dans la file, on le réduit
if ($this->files[$lieu][$id][1] < $nombre)
$nombre = $this->files[$lieu][$id][1];
//Si $nombre est supérieur au nombre présent dans la file, on le réduit
if ($this->files[$lieu][$id][1] < $nombre) {
$nombre = $this->files[$lieu][$id][1];
}
//On récupère les informations disponibles
$objet = $this->files[$lieu][$id][0];
$nombreMax = $this->files[$lieu][$id][1];
//On récupère les informations disponibles
$objet = $this->files[$lieu][$id][0];
$nombreMax = $this->files[$lieu][$id][1];
//On met à jour le temps si on vient d'annuler le premier groupe d'unités en lice
if ($id == $this->findFirstKey($lieu) && $nombreMax == $nombre)
$this->times[$lieu] = time();
//On met à jour le temps si on vient d'annuler le premier groupe d'unités en lice
if ($id == $this->findFirstKey($lieu) && $nombreMax == $nombre) {
$this->times[$lieu] = time();
}
$planete->addModif("file_cas");
$planete->addModif("file_cas");
if (!$this->files[$lieu][$id][2])
$planete->addRessources(dCaserne::metal($objet, $nombre, $planete), dCaserne::cristal($objet, $nombre, $planete), dCaserne::hydrogene($objet, $nombre, $planete), dCaserne::credits($objet, $nombre, $planete));
if (!$this->files[$lieu][$id][2]) {
$planete->addRessources(dCaserne::metal($objet, $nombre, $planete), dCaserne::cristal($objet, $nombre, $planete), dCaserne::hydrogene($objet, $nombre, $planete), dCaserne::credits($objet, $nombre, $planete));
}
//Effacement de la file
if ($nombre >= $nombreMax)
unset($this->files[$lieu][$id]);
else
$this->files[$lieu][$id][1] -= $nombre;
$planete->addModif("file_cas");
//Effacement de la file
if ($nombre >= $nombreMax) {
unset($this->files[$lieu][$id]);
} else {
$this->files[$lieu][$id][1] -= $nombre;
}
$planete->addModif("file_cas");
return true;
}
return true;
}
public function ready(SURFACE $planete)
{
//On parcourt la liste des lieux de construction
foreach($this->files as $keyF => $file)
{
//On vérifie qu'il y a bien des éléments dans cette file d'attente
if (count($file) == 0)
continue;
public function ready(SURFACE $planete)
{
//On parcourt la liste des lieux de construction
foreach ($this->files as $keyF => $file) {
//On vérifie qu'il y a bien des éléments dans cette file d'attente
if (count($file) == 0) {
continue;
}
//On parcourt la liste à la recherche des unités terminées dans l'ordre
foreach($file as $keyE => $element)
{
//Calcul du temps écoulé depuis le dernier entraînement
$tempsEcoule = time() - $this->times[$keyF];
//On parcourt la liste à la recherche des unités terminées dans l'ordre
foreach ($file as $keyE => $element) {
//Calcul du temps écoulé depuis le dernier entraînement
$tempsEcoule = time() - $this->times[$keyF];
//On gére les licenciments !
if ($element[2])
{
//On vérifie qu'il reste des unités du type sur la planète
if ($planete->casernes[$element[0]] <= 0)
{
unset($this->files[$keyF][$keyE]);
$planete->addModif("file_cas");
}
else
{
//Récupération de 60% du temps nécessaire
$tempsNecessaire = dCaserne::temps($element[0], 1, $planete) * 0.6;
//On gére les licenciments !
if ($element[2]) {
//On vérifie qu'il reste des unités du type sur la planète
if ($planete->casernes[$element[0]] <= 0) {
unset($this->files[$keyF][$keyE]);
$planete->addModif("file_cas");
} else {
//Récupération de 60% du temps nécessaire
$tempsNecessaire = dCaserne::temps($element[0], 1, $planete) * 0.6;
//Calcul du nombre d'unités maximum
$nbUnitee = min(floor($tempsEcoule/$tempsNecessaire), $element[1], $planete->casernes[$element[0]]);
//Calcul du nombre d'unités maximum
$nbUnitee = min(floor($tempsEcoule/$tempsNecessaire), $element[1], $planete->casernes[$element[0]]);
//Si le temps écoulé est suffisant
if ($nbUnitee > 0)
{
//On redonne 70% des ressources de l'unité au joueur
$planete->addRessources(dCaserne::metal($element[0], $nbUnitee, $planete)*0.7, dCaserne::cristal($element[0], $nbUnitee, $planete)*0.7, dCaserne::hydrogene($element[0], $nbUnitee, $planete)*0.7, dCaserne::credits($element[0], $nbUnitee, $planete)*0.7);
//Si le temps écoulé est suffisant
if ($nbUnitee > 0) {
//On redonne 70% des ressources de l'unité au joueur
$planete->addRessources(dCaserne::metal($element[0], $nbUnitee, $planete)*0.7, dCaserne::cristal($element[0], $nbUnitee, $planete)*0.7, dCaserne::hydrogene($element[0], $nbUnitee, $planete)*0.7, dCaserne::credits($element[0], $nbUnitee, $planete)*0.7);
//On retire les unités
$planete->casernes[$element[0]] -= $nbUnitee;
//On retire les unités
$planete->casernes[$element[0]] -= $nbUnitee;
//On efface l'entrée de la file et on met à jour le temps de la file
if ($nbUnitee >= $element[1])
unset($this->filefiles[$keyF][$keyE]);
else
$this->file[$key][1] -= $nbUnitee;
$this->timefiles[$keyF] += $tempsNecessaire*$nbUnitee;
//On efface l'entrée de la file et on met à jour le temps de la file
if ($nbUnitee >= $element[1]) {
unset($this->filefiles[$keyF][$keyE]);
} else {
$this->file[$key][1] -= $nbUnitee;
}
$this->timefiles[$keyF] += $tempsNecessaire*$nbUnitee;
//On demande la mise à jour des champs modifiés
$planete->addModif(array("casernes", $element[0]));
$planete->addModif("file_cas");
//On demande la mise à jour des champs modifiés
$planete->addModif(array("casernes", $element[0]));
$planete->addModif("file_cas");
if ($nbUnitee < $element[1])
return false;
}
//Si le temps écoulé n'est pas suffisant pour cette unité, on annule toutes les suivantes
else
break;
}
}
else //Cas de la construction
{
//Récupération du temps nécessaire
$tempsNecessaire = dCaserne::temps($element[0], 1, $planete);
if ($nbUnitee < $element[1]) {
return false;
}
}
//Si le temps écoulé n'est pas suffisant pour cette unité, on annule toutes les suivantes
else {
break;
}
}
} else { //Cas de la construction
//Récupération du temps nécessaire
$tempsNecessaire = dCaserne::temps($element[0], 1, $planete);
//Calcul du nombre d'unités maximum
$nbUnitee = min(floor($tempsEcoule/$tempsNecessaire), $element[1]);
//Calcul du nombre d'unités maximum
$nbUnitee = min(floor($tempsEcoule/$tempsNecessaire), $element[1]);
//Si le temps écoulé est suffisant
if ($nbUnitee > 0)
{
//On ajoute le nombre d'unités
$planete->casernes[$element[0]] += $nbUnitee;
//Si le temps écoulé est suffisant
if ($nbUnitee > 0) {
//On ajoute le nombre d'unités
$planete->casernes[$element[0]] += $nbUnitee;
//On efface l'entrée de la file et on met à jour le temps de la file
if ($nbUnitee >= $element[1])
unset($this->files[$keyF][$keyE]);
else
$this->files[$keyF][$keyE][1] -= $nbUnitee;
$this->times[$keyF] += $tempsNecessaire * $nbUnitee;
//On efface l'entrée de la file et on met à jour le temps de la file
if ($nbUnitee >= $element[1]) {
unset($this->files[$keyF][$keyE]);
} else {
$this->files[$keyF][$keyE][1] -= $nbUnitee;
}
$this->times[$keyF] += $tempsNecessaire * $nbUnitee;
//On demande la mise à jour des champs modifiés
$planete->addModif(array("casernes", $element[0]));
$planete->addModif("file_cas");
//On demande la mise à jour des champs modifiés
$planete->addModif(array("casernes", $element[0]));
$planete->addModif("file_cas");
if ($nbUnitee < $element[1])
break;
}
//Si le temps écoulé n'est pas suffisant pour ce batiment, on annule tous les suivants
else
break;
}
}
}
}
if ($nbUnitee < $element[1]) {
break;
}
}
//Si le temps écoulé n'est pas suffisant pour ce batiment, on annule tous les suivants
else {
break;
}
}
}
}
}
function printFile(SURFACE $planete, $lieu = NULL)
{
$out = array();
foreach ($this->files as $keyF => $file)
{
if (isset($lieu) && $lieu != $keyF)
continue;
public function printFile(SURFACE $planete, $lieu = null)
{
$out = array();
foreach ($this->files as $keyF => $file) {
if (isset($lieu) && $lieu != $keyF) {
continue;
}
$prems = true;
foreach ($file as $keyE => $element)
{
if ($element[2])
{
$temps = dCaserne::temps($element[0], 1, $planete) * 0.6;
if ($prems)
$temps_moins = time() - $this->times[$keyF];
else
$temps_moins = 0;
$out[$keyF][$keyE] = array($element[0], $element[1], $element[2], ceil($temps * $element[1] - $temps_moins), ceil($temps - $temps_moins), $prems);
}
else
{
$temps = dCaserne::temps($element[0], 1, $planete);
if ($prems)
$temps_moins = time() - $this->times[$keyF];
else
$temps_moins = 0;
$out[$keyF][$keyE] = array($element[0], $element[1], $element[2], ceil($temps * $element[1] - $temps_moins), ceil($temps - $temps_moins), $prems);
}
$prems = false;
}
}
return $out;
}
$prems = true;
foreach ($file as $keyE => $element) {
if ($element[2]) {
$temps = dCaserne::temps($element[0], 1, $planete) * 0.6;
if ($prems) {
$temps_moins = time() - $this->times[$keyF];
} else {
$temps_moins = 0;
}
$out[$keyF][$keyE] = array($element[0], $element[1], $element[2], ceil($temps * $element[1] - $temps_moins), ceil($temps - $temps_moins), $prems);
} else {
$temps = dCaserne::temps($element[0], 1, $planete);
if ($prems) {
$temps_moins = time() - $this->times[$keyF];
} else {
$temps_moins = 0;
}
$out[$keyF][$keyE] = array($element[0], $element[1], $element[2], ceil($temps * $element[1] - $temps_moins), ceil($temps - $temps_moins), $prems);
}
$prems = false;
}
}
return $out;
}
}
?>

View file

@ -1,113 +1,113 @@
<?php
if(!defined('ONYX')) exit;
if (!defined('ONYX')) {
exit;
}
interface File
{
public function objectInFile($object);
public function nbObjectInFile($object);
public function addObjet($object, $nombre, surface $planete);
public function addDemolition($object, $nombre, surface $planete);
public function delObjet($id, $nombre, $lieu, surface $planete);
public function ready(surface $planete);
public function objectInFile($object);
public function nbObjectInFile($object);
public function addObjet($object, $nombre, surface $planete);
public function addDemolition($object, $nombre, surface $planete);
public function delObjet($id, $nombre, $lieu, surface $planete);
public function ready(surface $planete);
public function printFile(surface $planete, $lieu = NULL);
public function printFile(surface $planete, $lieu = null);
}
class FileCommun
{
protected $files = array();
protected $times = array();
protected $simultane;
protected $files = array();
protected $times = array();
protected $simultane;
function __construct()
{
$this->times[] = time();
$this->simultane = 1;
}
public function __construct()
{
$this->times[] = time();
$this->simultane = 1;
}
function refreshTime($lieu)
{
if (empty($this->files[$lieu]) || count($this->files[$lieu]) < 1)
$this->times[$lieu] = time();
}
public function refreshTime($lieu)
{
if (empty($this->files[$lieu]) || count($this->files[$lieu]) < 1) {
$this->times[$lieu] = time();
}
}
function reajusteVacances($timelost)
{
foreach($this->times as $key => $time)
$this->times[$key] += $timelost;
public function reajusteVacances($timelost)
{
foreach ($this->times as $key => $time) {
$this->times[$key] += $timelost;
}
return serialize($this);
}
return serialize($this);
}
function hasObject()
{
foreach($this->files as $file)
{
if (count($file) > 0)
return true;
}
public function hasObject()
{
foreach ($this->files as $file) {
if (count($file) > 0) {
return true;
}
}
return false;
}
return false;
}
function checkMaxSize(surface $planete, $lieu = null)
{
$nombre = 0;
if (isset($lieu))
{
if (!empty($this->files[$lieu]))
$nombre = count($this->files[$lieu]);
}
else
{
foreach($this->files as $file)
{
$nombre += count($file);
}
}
public function checkMaxSize(surface $planete, $lieu = null)
{
$nombre = 0;
if (isset($lieu)) {
if (!empty($this->files[$lieu])) {
$nombre = count($this->files[$lieu]);
}
} else {
foreach ($this->files as $file) {
$nombre += count($file);
}
}
return ($nombre < dDonnees::tailleFile($planete));
}
return ($nombre < dDonnees::tailleFile($planete));
}
function findShorter()
{
$short = 0;
$value = 99;
foreach($this->files as $key => $file)
{
if ($key >= $this->simultane)
break;
public function findShorter()
{
$short = 0;
$value = 99;
foreach ($this->files as $key => $file) {
if ($key >= $this->simultane) {
break;
}
$count = count($file);
if ($value > $count)
{
$value = $count;
$short = $key;
}
}
$count = count($file);
if ($value > $count) {
$value = $count;
$short = $key;
}
}
return $short;
}
return $short;
}
function findFirstKey($lieu)
{
foreach($this->files[$lieu] as $key => $file)
return $key;
}
public function findFirstKey($lieu)
{
foreach ($this->files[$lieu] as $key => $file) {
return $key;
}
}
function DEBUG__print()
{
var_dump($this);
var_dump($this->files);
}
public function DEBUG__print()
{
var_dump($this);
var_dump($this->files);
}
function DEBUG__setTime($lieu, $moins)
{
$this->times[$lieu] -= $moins;
public function DEBUG__setTime($lieu, $moins)
{
$this->times[$lieu] -= $moins;
return $this->times[$lieu];
}
return $this->times[$lieu];
}
}
?>

View file

@ -3,307 +3,304 @@ require_once("Class/File/interface.php");
class FileSpatial extends FileCommun implements File
{
public function objectInFile($object, $lieu = null)
{
if (isset($lieu))
{
if (!empty($this->files[$lieu]))
{
foreach($this->files[$lieu] as $keyE => $element)
{
if ($element[0] == $object)
return array($lieu, $keyE);
}
}
}
else
{
foreach($this->files as $keyF => $file)
{
foreach($file as $keyE => $element)
{
if ($element[0] == $object)
return array($keyF, $keyE);
}
}
}
public function objectInFile($object, $lieu = null)
{
if (isset($lieu)) {
if (!empty($this->files[$lieu])) {
foreach ($this->files[$lieu] as $keyE => $element) {
if ($element[0] == $object) {
return array($lieu, $keyE);
}
}
}
} else {
foreach ($this->files as $keyF => $file) {
foreach ($file as $keyE => $element) {
if ($element[0] == $object) {
return array($keyF, $keyE);
}
}
}
}
return false;
}
return false;
}
public function nbObjectInFile($object)
{
$c = 0;
foreach($this->files as $key => $file)
{
foreach($file as $element)
{
if ($element[0] == $object)
$c += $element[1];
}
}
return $c;
}
public function nbObjectInFile($object)
{
$c = 0;
foreach ($this->files as $key => $file) {
foreach ($file as $element) {
if ($element[0] == $object) {
$c += $element[1];
}
}
}
return $c;
}
public function addObjet($object, $nombre, surface $planete, $lieu = null)
{
//Vérification du nombre passé en entrée
if (!is_numeric($nombre) || $nombre < 0 || $nombre > 99999)
throw new ExceptionHB(3, 8);
public function addObjet($object, $nombre, surface $planete, $lieu = null)
{
//Vérification du nombre passé en entrée
if (!is_numeric($nombre) || $nombre < 0 || $nombre > 99999) {
throw new ExceptionHB(3, 8);
}
//Validation des conditions de construction
if (!dSpatial::needed($object, $planete))
throw new ExceptionHB(3, 2);
//Validation des conditions de construction
if (!dSpatial::needed($object, $planete)) {
throw new ExceptionHB(3, 2);
}
//On vérifie que l'on ne dépasse pas la taille maximale de la file
if (!($sauvLastKey = $this->objectInFile($object, $lieu)) && !$this->checkMaxSize($planete, $lieu))
throw new ExceptionHB(3, 1);
//On vérifie que l'on ne dépasse pas la taille maximale de la file
if (!($sauvLastKey = $this->objectInFile($object, $lieu)) && !$this->checkMaxSize($planete, $lieu)) {
throw new ExceptionHB(3, 1);
}
//On tronque au maximum d'unités constructible sur la planète
if (($metal = dSpatial::metal($object, 1, $planete)) > 0)
$metal = $planete->metal/$metal;
else
$metal = $nombre;
if (($cristal = dSpatial::cristal($object, 1, $planete)) > 0)
$cristal = $planete->cristal/$cristal;
else
$cristal = $nombre;
if (($hydrogene = dSpatial::hydrogene($object, 1, $planete)) > 0)
$hydrogene = $planete->hydrogene/$hydrogene;
else
$hydrogene = $nombre;
//On tronque au maximum d'unités constructible sur la planète
if (($metal = dSpatial::metal($object, 1, $planete)) > 0) {
$metal = $planete->metal/$metal;
} else {
$metal = $nombre;
}
if (($cristal = dSpatial::cristal($object, 1, $planete)) > 0) {
$cristal = $planete->cristal/$cristal;
} else {
$cristal = $nombre;
}
if (($hydrogene = dSpatial::hydrogene($object, 1, $planete)) > 0) {
$hydrogene = $planete->hydrogene/$hydrogene;
} else {
$hydrogene = $nombre;
}
$nombre = floor(min($nombre, $metal, $cristal, $hydrogene));
$nombre = floor(min($nombre, $metal, $cristal, $hydrogene));
//On vérifie qu'il y ait assez de ressources sur la planète
if ($planete->checkAndRetireRessources(dSpatial::metal($object, $nombre, $planete), dSpatial::cristal($object, $nombre, $planete), dSpatial::hydrogene($object, $nombre, $planete), dSpatial::credits($object, $nombre, $planete)))
{
//Si il existe déjà l'objet en file d'attente, on l'ajoute
if(isset($sauvLastKey) && isset($this->files[$sauvLastKey[0]][$sauvLastKey[1]]))
{
//On rafraîchit le temps de la file si aucun objet n'est en file d'attente
$this->refreshTime($sauvLastKey[0]);
//On vérifie qu'il y ait assez de ressources sur la planète
if ($planete->checkAndRetireRessources(dSpatial::metal($object, $nombre, $planete), dSpatial::cristal($object, $nombre, $planete), dSpatial::hydrogene($object, $nombre, $planete), dSpatial::credits($object, $nombre, $planete))) {
//Si il existe déjà l'objet en file d'attente, on l'ajoute
if (isset($sauvLastKey) && isset($this->files[$sauvLastKey[0]][$sauvLastKey[1]])) {
//On rafraîchit le temps de la file si aucun objet n'est en file d'attente
$this->refreshTime($sauvLastKey[0]);
$this->files[$sauvLastKey[0]][$sauvLastKey[1]][1] += $nombre;
}
else
{
if (!isset($lieu))
{
//On recherche le lieu ayant le moins de construction en cours
$lieu = $this->findShorter();
}
$this->files[$sauvLastKey[0]][$sauvLastKey[1]][1] += $nombre;
} else {
if (!isset($lieu)) {
//On recherche le lieu ayant le moins de construction en cours
$lieu = $this->findShorter();
}
//On rafraîchit le temps de la file si aucun objet n'est en file d'attente
$this->refreshTime($lieu);
//On rafraîchit le temps de la file si aucun objet n'est en file d'attente
$this->refreshTime($lieu);
$this->files[$lieu][] = array($object, $nombre, false);
}
$this->files[$lieu][] = array($object, $nombre, false);
}
$planete->addModif("file_vais");
return true;
}
else
throw new ExceptionHB(3, 4);
}
$planete->addModif("file_vais");
return true;
} else {
throw new ExceptionHB(3, 4);
}
}
public function addDemolition($object, $nombre, surface $planete, $lieu = null)
{
//On vérifie que l'on ne dépasse pas la taille maximale de la file
if (!$this->checkMaxSize($planete, $lieu) && !($sauvLastKey = $this->objectInFile($object, $lieu)))
throw new ExceptionHB(3, 1);
public function addDemolition($object, $nombre, surface $planete, $lieu = null)
{
//On vérifie que l'on ne dépasse pas la taille maximale de la file
if (!$this->checkMaxSize($planete, $lieu) && !($sauvLastKey = $this->objectInFile($object, $lieu))) {
throw new ExceptionHB(3, 1);
}
//Vérification du nombre passé en entrée
if (!is_numeric($nombre) || $nombre < 0 || $nombre > 99999)
throw new ExceptionHB(3, 8);
//Vérification du nombre passé en entrée
if (!is_numeric($nombre) || $nombre < 0 || $nombre > 99999) {
throw new ExceptionHB(3, 8);
}
//On vérifie que le nombre d'unité actuel soit non nul
if ($planete->vaisseaux[$object] < $nombre)
throw new ExceptionHB(3, 6);
//On vérifie que le nombre d'unité actuel soit non nul
if ($planete->vaisseaux[$object] < $nombre) {
throw new ExceptionHB(3, 6);
}
if (!isset($lieu))
{
//On recherche le lieu ayant le moins de construction en cours
$lieu = $this->findShorter();
}
if (!isset($lieu)) {
//On recherche le lieu ayant le moins de construction en cours
$lieu = $this->findShorter();
}
//On rafraîchit le temps de la file si aucun objet n'est en file d'attente
$this->refreshTime($lieu);
//On rafraîchit le temps de la file si aucun objet n'est en file d'attente
$this->refreshTime($lieu);
//Si il existe déjà l'objet en file d'attente, on l'ajoute
if(isset($sauvLastKey))
$this->files[$sauvLastKey[0]][$sauvLastKey[1]][1] += $nombre;
else
$this->files[$lieu][] = array($object, $nombre, false);
//Si il existe déjà l'objet en file d'attente, on l'ajoute
if (isset($sauvLastKey)) {
$this->files[$sauvLastKey[0]][$sauvLastKey[1]][1] += $nombre;
} else {
$this->files[$lieu][] = array($object, $nombre, false);
}
$planete->addModif("file_vais");
$planete->addModif("file_vais");
return true;
}
return true;
}
public function delObjet($id, $nombre, $lieu, surface $planete)
{
//Vérification de l'existance de l'objet en file d'attente
if (empty($this->files[$lieu][$id]))
throw new ExceptionHB(1, 5);
public function delObjet($id, $nombre, $lieu, surface $planete)
{
//Vérification de l'existance de l'objet en file d'attente
if (empty($this->files[$lieu][$id])) {
throw new ExceptionHB(1, 5);
}
//Si $nombre est supérieur au nombre présent dans la file, on le réduit
if ($this->files[$lieu][$id][1] < $nombre)
$nombre = $this->files[$lieu][$id][1];
//Si $nombre est supérieur au nombre présent dans la file, on le réduit
if ($this->files[$lieu][$id][1] < $nombre) {
$nombre = $this->files[$lieu][$id][1];
}
//On récupère les informations disponibles
$objet = $this->files[$lieu][$id][0];
$nombreMax = $this->files[$lieu][$id][1];
//On récupère les informations disponibles
$objet = $this->files[$lieu][$id][0];
$nombreMax = $this->files[$lieu][$id][1];
//On met à jour le temps si on vient d'annuler le premier groupe d'unités en lice
if ($id == $this->findFirstKey($lieu) && $nombreMax == $nombre)
$this->times[$lieu] = time();
//On met à jour le temps si on vient d'annuler le premier groupe d'unités en lice
if ($id == $this->findFirstKey($lieu) && $nombreMax == $nombre) {
$this->times[$lieu] = time();
}
$planete->addModif("file_vais");
$planete->addModif("file_vais");
if (!$this->files[$lieu][$id][2])
$planete->addRessources(dSpatial::metal($objet, $nombre, $planete), dSpatial::cristal($objet, $nombre, $planete), dSpatial::hydrogene($objet, $nombre, $planete), dSpatial::credits($objet, $nombre, $planete));
if (!$this->files[$lieu][$id][2]) {
$planete->addRessources(dSpatial::metal($objet, $nombre, $planete), dSpatial::cristal($objet, $nombre, $planete), dSpatial::hydrogene($objet, $nombre, $planete), dSpatial::credits($objet, $nombre, $planete));
}
//Effacement de la file
if ($nombre >= $nombreMax)
unset($this->files[$lieu][$id]);
else
$this->files[$lieu][$id][1] -= $nombre;
$planete->addModif("file_vais");
//Effacement de la file
if ($nombre >= $nombreMax) {
unset($this->files[$lieu][$id]);
} else {
$this->files[$lieu][$id][1] -= $nombre;
}
$planete->addModif("file_vais");
return true;
}
return true;
}
public function ready(SURFACE $planete)
{
//On parcourt la liste des lieux de construction
foreach($this->files as $keyF => $file)
{
//On vérifie qu'il y a bien des éléments dans cette file d'attente
if (count($file) == 0)
continue;
public function ready(SURFACE $planete)
{
//On parcourt la liste des lieux de construction
foreach ($this->files as $keyF => $file) {
//On vérifie qu'il y a bien des éléments dans cette file d'attente
if (count($file) == 0) {
continue;
}
//On parcourt la liste à la recherche des unités terminées dans l'ordre
foreach($file as $keyE => $element)
{
//Calcul du temps écoulé depuis le dernier entraînement
$tempsEcoule = time() - $this->times[$keyF];
//On parcourt la liste à la recherche des unités terminées dans l'ordre
foreach ($file as $keyE => $element) {
//Calcul du temps écoulé depuis le dernier entraînement
$tempsEcoule = time() - $this->times[$keyF];
//On gére les licenciments !
if ($element[2])
{
//On vérifie qu'il reste des unités du type sur la planète
if ($planete->vaisseaux[$element[0]] <= 0)
{
unset($this->files[$keyF][$keyE]);
$planete->addModif("file_vais");
}
else
{
//Récupération de 60% du temps nécessaire
$tempsNecessaire = dSpatial::temps($element[0], 1, $planete) * 0.6;
//On gére les licenciments !
if ($element[2]) {
//On vérifie qu'il reste des unités du type sur la planète
if ($planete->vaisseaux[$element[0]] <= 0) {
unset($this->files[$keyF][$keyE]);
$planete->addModif("file_vais");
} else {
//Récupération de 60% du temps nécessaire
$tempsNecessaire = dSpatial::temps($element[0], 1, $planete) * 0.6;
//Calcul du nombre d'unités maximum
$nbUnitee = min(floor($tempsEcoule/$tempsNecessaire), $element[1], $planete->vaisseaux[$element[0]]);
//Calcul du nombre d'unités maximum
$nbUnitee = min(floor($tempsEcoule/$tempsNecessaire), $element[1], $planete->vaisseaux[$element[0]]);
//Si le temps écoulé est suffisant
if ($nbUnitee > 0)
{
//On redonne 70% des ressources de l'unité au joueur
$planete->addRessources(dSpatial::metal($element[0], $nbUnitee, $planete)*0.7, dSpatial::cristal($element[0], $nbUnitee, $planete)*0.7, dSpatial::hydrogene($element[0], $nbUnitee, $planete)*0.7, dSpatial::credits($element[0], $nbUnitee, $planete)*0.7);
//Si le temps écoulé est suffisant
if ($nbUnitee > 0) {
//On redonne 70% des ressources de l'unité au joueur
$planete->addRessources(dSpatial::metal($element[0], $nbUnitee, $planete)*0.7, dSpatial::cristal($element[0], $nbUnitee, $planete)*0.7, dSpatial::hydrogene($element[0], $nbUnitee, $planete)*0.7, dSpatial::credits($element[0], $nbUnitee, $planete)*0.7);
//On retire les unités
$planete->vaisseaux[$element[0]] -= $nbUnitee;
//On retire les unités
$planete->vaisseaux[$element[0]] -= $nbUnitee;
//On efface l'entrée de la file et on met à jour le temps de la file
if ($nbUnitee >= $element[1])
unset($this->filefiles[$keyF][$keyE]);
else
$this->file[$key][1] -= $nbUnitee;
$this->timefiles[$keyF] += $tempsNecessaire*$nbUnitee;
//On efface l'entrée de la file et on met à jour le temps de la file
if ($nbUnitee >= $element[1]) {
unset($this->filefiles[$keyF][$keyE]);
} else {
$this->file[$key][1] -= $nbUnitee;
}
$this->timefiles[$keyF] += $tempsNecessaire*$nbUnitee;
//On demande la mise à jour des champs modifiés
$planete->addModif(array("vaisseaux", $element[0]));
$planete->addModif("file_vais");
//On demande la mise à jour des champs modifiés
$planete->addModif(array("vaisseaux", $element[0]));
$planete->addModif("file_vais");
if ($nbUnitee < $element[1])
return false;
}
//Si le temps écoulé n'est pas suffisant pour cette unité, on annule toutes les suivantes
else
break;
}
}
else //Cas de la construction
{
//Récupération du temps nécessaire
$tempsNecessaire = dSpatial::temps($element[0], 1, $planete);
if ($nbUnitee < $element[1]) {
return false;
}
}
//Si le temps écoulé n'est pas suffisant pour cette unité, on annule toutes les suivantes
else {
break;
}
}
} else { //Cas de la construction
//Récupération du temps nécessaire
$tempsNecessaire = dSpatial::temps($element[0], 1, $planete);
//Calcul du nombre d'unités maximum
$nbUnitee = min(floor($tempsEcoule/$tempsNecessaire), $element[1]);
//Calcul du nombre d'unités maximum
$nbUnitee = min(floor($tempsEcoule/$tempsNecessaire), $element[1]);
//Si le temps écoulé est suffisant
if ($nbUnitee > 0)
{
//On ajoute le nombre d'unités
$planete->vaisseaux[$element[0]] += $nbUnitee;
//Si le temps écoulé est suffisant
if ($nbUnitee > 0) {
//On ajoute le nombre d'unités
$planete->vaisseaux[$element[0]] += $nbUnitee;
//On efface l'entrée de la file et on met à jour le temps de la file
if ($nbUnitee >= $element[1])
unset($this->files[$keyF][$keyE]);
else
$this->files[$keyF][$keyE][1] -= $nbUnitee;
$this->times[$keyF] += $tempsNecessaire * $nbUnitee;
//On efface l'entrée de la file et on met à jour le temps de la file
if ($nbUnitee >= $element[1]) {
unset($this->files[$keyF][$keyE]);
} else {
$this->files[$keyF][$keyE][1] -= $nbUnitee;
}
$this->times[$keyF] += $tempsNecessaire * $nbUnitee;
//On demande la mise à jour des champs modifiés
$planete->addModif(array("vaisseaux", $element[0]));
$planete->addModif("file_vais");
//On demande la mise à jour des champs modifiés
$planete->addModif(array("vaisseaux", $element[0]));
$planete->addModif("file_vais");
if ($nbUnitee < $element[1])
break;
}
//Si le temps écoulé n'est pas suffisant pour ce batiment, on annule tous les suivants
else
break;
}
}
}
}
if ($nbUnitee < $element[1]) {
break;
}
}
//Si le temps écoulé n'est pas suffisant pour ce batiment, on annule tous les suivants
else {
break;
}
}
}
}
}
function printFile(SURFACE $planete, $lieu = NULL)
{
$out = array();
foreach ($this->files as $keyF => $file)
{
if (isset($lieu) && $lieu != $keyF)
continue;
public function printFile(SURFACE $planete, $lieu = null)
{
$out = array();
foreach ($this->files as $keyF => $file) {
if (isset($lieu) && $lieu != $keyF) {
continue;
}
$prems = true;
foreach ($file as $keyE => $element)
{
if ($element[2])
{
$temps = dSpatial::temps($element[0], 1, $planete) * 0.6;
if ($prems)
$temps_moins = time() - $this->times[$keyF];
else
$temps_moins = 0;
$out[$keyF][$keyE] = array($element[0], $element[1], $element[2], ceil($temps * $element[1] - $temps_moins), ceil($temps - $temps_moins), $prems);
}
else
{
$temps = dSpatial::temps($element[0], 1, $planete);
if ($prems)
$temps_moins = time() - $this->times[$keyF];
else
$temps_moins = 0;
$out[$keyF][$keyE] = array($element[0], $element[1], $element[2], ceil($temps * $element[1] - $temps_moins), ceil($temps - $temps_moins), $prems);
}
$prems = false;
}
}
return $out;
}
$prems = true;
foreach ($file as $keyE => $element) {
if ($element[2]) {
$temps = dSpatial::temps($element[0], 1, $planete) * 0.6;
if ($prems) {
$temps_moins = time() - $this->times[$keyF];
} else {
$temps_moins = 0;
}
$out[$keyF][$keyE] = array($element[0], $element[1], $element[2], ceil($temps * $element[1] - $temps_moins), ceil($temps - $temps_moins), $prems);
} else {
$temps = dSpatial::temps($element[0], 1, $planete);
if ($prems) {
$temps_moins = time() - $this->times[$keyF];
} else {
$temps_moins = 0;
}
$out[$keyF][$keyE] = array($element[0], $element[1], $element[2], ceil($temps * $element[1] - $temps_moins), ceil($temps - $temps_moins), $prems);
}
$prems = false;
}
}
return $out;
}
}
?>

View file

@ -5,159 +5,160 @@ require_once("Class/File/interface.php");
class FileTechnologies extends FileCommun implements File
{
public function objectInFile($object)
{
foreach($this->files as $keyF => $file)
{
foreach($file as $keyE => $element)
{
if ($element[0] == $object)
return array($keyF, $keyE);
}
}
return false;
}
public function objectInFile($object)
{
foreach ($this->files as $keyF => $file) {
foreach ($file as $keyE => $element) {
if ($element[0] == $object) {
return array($keyF, $keyE);
}
}
}
return false;
}
public function nbObjectInFile($branche, $tech = null)
{
$c = 0;
foreach($this->files as $file)
{
$c += count(array_keys($file, array($branche, $tech)));
}
return $c;
}
public function nbObjectInFile($branche, $tech = null)
{
$c = 0;
foreach ($this->files as $file) {
$c += count(array_keys($file, array($branche, $tech)));
}
return $c;
}
public function addObjet($branche, $tech, surface $planete)
{
//On vérifie que l'on ne dépasse pas la taille maximale de la file
if (!$this->checkMaxSize($planete))
throw new ExceptionHB(4, 1);
public function addObjet($branche, $tech, surface $planete)
{
//On vérifie que l'on ne dépasse pas la taille maximale de la file
if (!$this->checkMaxSize($planete)) {
throw new ExceptionHB(4, 1);
}
//On vérifie qu'il n'y ait pas une recherche de la même technologie
if ($this->nbObjectInFile($branche, $tech) >= 1)
throw new ExceptionHB(4, 7);
//On vérifie qu'il n'y ait pas une recherche de la même technologie
if ($this->nbObjectInFile($branche, $tech) >= 1) {
throw new ExceptionHB(4, 7);
}
//On vérifie que la technologie ne soit pas déjà développée
if (dTechnologies::idToBit($tech) & $planete->technologies[$branche])
throw new ExceptionHB(4, 7);
//On vérifie que la technologie ne soit pas déjà développée
if (dTechnologies::idToBit($tech) & $planete->technologies[$branche]) {
throw new ExceptionHB(4, 7);
}
//Validation des conditions de construction
if (!dTechnologies::needed(array($branche, $tech), $planete))
throw new ExceptionHB(4, 2);
//Validation des conditions de construction
if (!dTechnologies::needed(array($branche, $tech), $planete)) {
throw new ExceptionHB(4, 2);
}
//On recherche le lieu ayant le moins de construction en cours
$lieu = $this->findShorter();
//On recherche le lieu ayant le moins de construction en cours
$lieu = $this->findShorter();
//On rafraîchit le temps de la file si aucun objet n'est en file d'attente
$this->refreshTime($lieu);
//On rafraîchit le temps de la file si aucun objet n'est en file d'attente
$this->refreshTime($lieu);
//On vérifie qu'il y ait assez de ressources sur la planète
if ($planete->checkAndRetireRessources(dTechnologies::metal($branche, $tech, $planete), dTechnologies::cristal($branche, $tech, $planete), dTechnologies::hydrogene($branche, $tech, $planete), dTechnologies::credits($branche, $tech, $planete)))
{
$this->files[$lieu][] = array($branche, $tech);
$planete->addModif("file_tech");
return true;
}
else
throw new ExceptionHB(4, 4);
}
//On vérifie qu'il y ait assez de ressources sur la planète
if ($planete->checkAndRetireRessources(dTechnologies::metal($branche, $tech, $planete), dTechnologies::cristal($branche, $tech, $planete), dTechnologies::hydrogene($branche, $tech, $planete), dTechnologies::credits($branche, $tech, $planete))) {
$this->files[$lieu][] = array($branche, $tech);
$planete->addModif("file_tech");
return true;
} else {
throw new ExceptionHB(4, 4);
}
}
public function addDemolition($object, $nombre = 1, surface $planete)
{
trigger_error("Pas de démolition possible pour les technologies");
}
public function addDemolition($object, $nombre = 1, surface $planete)
{
trigger_error("Pas de démolition possible pour les technologies");
}
public function delObjet($id, $nombre = 1, $lieu, surface $planete)
{
//Vérification de l'existance de l'objet en file d'attente
if (empty($this->files[$lieu][$id]))
throw new ExceptionHB(4, 5);
public function delObjet($id, $nombre = 1, $lieu, surface $planete)
{
//Vérification de l'existance de l'objet en file d'attente
if (empty($this->files[$lieu][$id])) {
throw new ExceptionHB(4, 5);
}
//On récupère la branche et l'id de la technologie
$branche = $this->files[$lieu][$id][0];
$tech = $this->files[$lieu][$id][1];
//On récupère la branche et l'id de la technologie
$branche = $this->files[$lieu][$id][0];
$tech = $this->files[$lieu][$id][1];
//On met à jour le temps si on vient d'annuler la première recherche en lice
if ($tech == $this->findFirstKey($lieu))
$this->times[$lieu] = time();
//On met à jour le temps si on vient d'annuler la première recherche en lice
if ($tech == $this->findFirstKey($lieu)) {
$this->times[$lieu] = time();
}
$planete->addModif("file_tech");
$planete->addModif("file_tech");
//On redonne 70% des ressources au joueur si c'est la première construction dans la file d'attente
if ($id == 0)
$planete->addRessources(dTechnologies::metal($branche, $tech, $planete)*0.7, dTechnologies::cristal($branche, $tech, $planete)*0.7, dTechnologies::hydrogene($branche, $tech, $planete)*0.7, dTechnologies::credits($branche, $tech, $planete)*0.7);
else
$planete->addRessources(dTechnologies::metal($branche, $tech, $planete), dTechnologies::cristal($branche, $tech, $planete), dTechnologies::hydrogene($branche, $tech, $planete), dTechnologies::credits($branche, $tech, $planete));
//On redonne 70% des ressources au joueur si c'est la première construction dans la file d'attente
if ($id == 0) {
$planete->addRessources(dTechnologies::metal($branche, $tech, $planete)*0.7, dTechnologies::cristal($branche, $tech, $planete)*0.7, dTechnologies::hydrogene($branche, $tech, $planete)*0.7, dTechnologies::credits($branche, $tech, $planete)*0.7);
} else {
$planete->addRessources(dTechnologies::metal($branche, $tech, $planete), dTechnologies::cristal($branche, $tech, $planete), dTechnologies::hydrogene($branche, $tech, $planete), dTechnologies::credits($branche, $tech, $planete));
}
//Effacement de la file
unset($this->files[$lieu][$id]);
//Effacement de la file
unset($this->files[$lieu][$id]);
return true;
}
return true;
}
public function ready(surface $planete)
{
//On parcourt la liste des lieux de recherche
foreach($this->files as $keyF => $file)
{
//On vérifie qu'il y a bien des éléments dans cette file d'attente
if (count($file) == 0)
continue;
public function ready(surface $planete)
{
//On parcourt la liste des lieux de recherche
foreach ($this->files as $keyF => $file) {
//On vérifie qu'il y a bien des éléments dans cette file d'attente
if (count($file) == 0) {
continue;
}
//On parcourt la file
foreach ($file as $keyE => $element)
{
$tempsEcoule = time() - $this->times[$keyF];
//On parcourt la file
foreach ($file as $keyE => $element) {
$tempsEcoule = time() - $this->times[$keyF];
$tempsNecessaire = dTechnologies::temps($element[0], $element[1], $planete);
$tempsNecessaire = dTechnologies::temps($element[0], $element[1], $planete);
//Si le temps écoulé est suffisant
if ($tempsEcoule >= $tempsNecessaire)
{
//On ajoute un niveau au batiment
$planete->technologies[$element[0]] = $planete->technologies[$element[0]] | dTechnologies::idToBit($element[1]);
//Si le temps écoulé est suffisant
if ($tempsEcoule >= $tempsNecessaire) {
//On ajoute un niveau au batiment
$planete->technologies[$element[0]] = $planete->technologies[$element[0]] | dTechnologies::idToBit($element[1]);
//On efface l'entrée de la file et on met à jour le temps de la file
unset($this->files[$keyF][$keyE]);
$this->times[$keyF] += $tempsNecessaire;
//On efface l'entrée de la file et on met à jour le temps de la file
unset($this->files[$keyF][$keyE]);
$this->times[$keyF] += $tempsNecessaire;
//On demande la mise à jour des champs modifiés
$planete->addModifUser(array("technologies", $element[0]));
$planete->addModif("file_tech");
//On demande la mise à jour des champs modifiés
$planete->addModifUser(array("technologies", $element[0]));
$planete->addModif("file_tech");
//On ajoute les points
$planete->addPoints(dTechnologies::metal($element[0], $element[0], $planete), dTechnologies::cristal($element[0], $element[1], $planete), dTechnologies::hydrogene($element[0], $element[1], $planete), dTechnologies::credits($element[0], $element[1], $planete));
}
//Si le temps écoulé n'est pas suffisant pour ce batiment, on annule tous les suivants
else
break;
}
}
}
//On ajoute les points
$planete->addPoints(dTechnologies::metal($element[0], $element[0], $planete), dTechnologies::cristal($element[0], $element[1], $planete), dTechnologies::hydrogene($element[0], $element[1], $planete), dTechnologies::credits($element[0], $element[1], $planete));
}
//Si le temps écoulé n'est pas suffisant pour ce batiment, on annule tous les suivants
else {
break;
}
}
}
}
public function printFile(surface $planete, $lieu = null)
{
$out = array();
foreach ($this->files as $keyF => $file)
{
if (isset($lieu) && $lieu != $keyF)
continue;
public function printFile(surface $planete, $lieu = null)
{
$out = array();
foreach ($this->files as $keyF => $file) {
if (isset($lieu) && $lieu != $keyF) {
continue;
}
$prems = true;
foreach ($file as $keyE => $element)
{
$temps = dTechnologies::temps($element[0], $element[1], $planete);
if ($prems)
$temps -= time() - $this->times[$keyF];
$out[$keyF][$keyE] = array($element[0], $element[1], ceil($temps), $prems);
$prems = true;
foreach ($file as $keyE => $element) {
$temps = dTechnologies::temps($element[0], $element[1], $planete);
if ($prems) {
$temps -= time() - $this->times[$keyF];
}
$out[$keyF][$keyE] = array($element[0], $element[1], ceil($temps), $prems);
$prems = false;
}
}
return $out;
}
$prems = false;
}
}
return $out;
}
}
?>

View file

@ -3,307 +3,304 @@ require_once("Class/File/interface.php");
class FileTerrestre extends FileCommun implements File
{
public function objectInFile($object, $lieu = null)
{
if (isset($lieu))
{
if (!empty($this->files[$lieu]))
{
foreach($this->files[$lieu] as $keyE => $element)
{
if ($element[0] == $object)
return array($lieu, $keyE);
}
}
}
else
{
foreach($this->files as $keyF => $file)
{
foreach($file as $keyE => $element)
{
if ($element[0] == $object)
return array($keyF, $keyE);
}
}
}
public function objectInFile($object, $lieu = null)
{
if (isset($lieu)) {
if (!empty($this->files[$lieu])) {
foreach ($this->files[$lieu] as $keyE => $element) {
if ($element[0] == $object) {
return array($lieu, $keyE);
}
}
}
} else {
foreach ($this->files as $keyF => $file) {
foreach ($file as $keyE => $element) {
if ($element[0] == $object) {
return array($keyF, $keyE);
}
}
}
}
return false;
}
return false;
}
public function nbObjectInFile($object)
{
$c = 0;
foreach($this->files as $key => $file)
{
foreach($file as $element)
{
if ($element[0] == $object)
$c += $element[1];
}
}
return $c;
}
public function nbObjectInFile($object)
{
$c = 0;
foreach ($this->files as $key => $file) {
foreach ($file as $element) {
if ($element[0] == $object) {
$c += $element[1];
}
}
}
return $c;
}
public function addObjet($object, $nombre, surface $planete, $lieu = null)
{
//Vérification du nombre passé en entrée
if (!is_numeric($nombre) || $nombre < 0 || $nombre > 99999)
throw new ExceptionHB(3, 8);
public function addObjet($object, $nombre, surface $planete, $lieu = null)
{
//Vérification du nombre passé en entrée
if (!is_numeric($nombre) || $nombre < 0 || $nombre > 99999) {
throw new ExceptionHB(3, 8);
}
//Validation des conditions de construction
if (!dTerrestre::needed($object, $planete))
throw new ExceptionHB(3, 2);
//Validation des conditions de construction
if (!dTerrestre::needed($object, $planete)) {
throw new ExceptionHB(3, 2);
}
//On vérifie que l'on ne dépasse pas la taille maximale de la file
if (!($sauvLastKey = $this->objectInFile($object, $lieu)) && !$this->checkMaxSize($planete, $lieu))
throw new ExceptionHB(3, 1);
//On vérifie que l'on ne dépasse pas la taille maximale de la file
if (!($sauvLastKey = $this->objectInFile($object, $lieu)) && !$this->checkMaxSize($planete, $lieu)) {
throw new ExceptionHB(3, 1);
}
//On tronque au maximum d'unités constructible sur la planète
if (($metal = dTerrestre::metal($object, 1, $planete)) > 0)
$metal = $planete->metal/$metal;
else
$metal = $nombre;
if (($cristal = dTerrestre::cristal($object, 1, $planete)) > 0)
$cristal = $planete->cristal/$cristal;
else
$cristal = $nombre;
if (($hydrogene = dTerrestre::hydrogene($object, 1, $planete)) > 0)
$hydrogene = $planete->hydrogene/$hydrogene;
else
$hydrogene = $nombre;
//On tronque au maximum d'unités constructible sur la planète
if (($metal = dTerrestre::metal($object, 1, $planete)) > 0) {
$metal = $planete->metal/$metal;
} else {
$metal = $nombre;
}
if (($cristal = dTerrestre::cristal($object, 1, $planete)) > 0) {
$cristal = $planete->cristal/$cristal;
} else {
$cristal = $nombre;
}
if (($hydrogene = dTerrestre::hydrogene($object, 1, $planete)) > 0) {
$hydrogene = $planete->hydrogene/$hydrogene;
} else {
$hydrogene = $nombre;
}
$nombre = floor(min($nombre, $metal, $cristal, $hydrogene));
$nombre = floor(min($nombre, $metal, $cristal, $hydrogene));
//On vérifie qu'il y ait assez de ressources sur la planète
if ($planete->checkAndRetireRessources(dTerrestre::metal($object, $nombre, $planete), dTerrestre::cristal($object, $nombre, $planete), dTerrestre::hydrogene($object, $nombre, $planete), dTerrestre::credits($object, $nombre, $planete)))
{
//Si il existe déjà l'objet en file d'attente, on l'ajoute
if(isset($sauvLastKey) && isset($this->files[$sauvLastKey[0]][$sauvLastKey[1]]))
{
//On rafraîchit le temps de la file si aucun objet n'est en file d'attente
$this->refreshTime($sauvLastKey[0]);
//On vérifie qu'il y ait assez de ressources sur la planète
if ($planete->checkAndRetireRessources(dTerrestre::metal($object, $nombre, $planete), dTerrestre::cristal($object, $nombre, $planete), dTerrestre::hydrogene($object, $nombre, $planete), dTerrestre::credits($object, $nombre, $planete))) {
//Si il existe déjà l'objet en file d'attente, on l'ajoute
if (isset($sauvLastKey) && isset($this->files[$sauvLastKey[0]][$sauvLastKey[1]])) {
//On rafraîchit le temps de la file si aucun objet n'est en file d'attente
$this->refreshTime($sauvLastKey[0]);
$this->files[$sauvLastKey[0]][$sauvLastKey[1]][1] += $nombre;
}
else
{
if (!isset($lieu))
{
//On recherche le lieu ayant le moins de construction en cours
$lieu = $this->findShorter();
}
$this->files[$sauvLastKey[0]][$sauvLastKey[1]][1] += $nombre;
} else {
if (!isset($lieu)) {
//On recherche le lieu ayant le moins de construction en cours
$lieu = $this->findShorter();
}
//On rafraîchit le temps de la file si aucun objet n'est en file d'attente
$this->refreshTime($lieu);
//On rafraîchit le temps de la file si aucun objet n'est en file d'attente
$this->refreshTime($lieu);
$this->files[$lieu][] = array($object, $nombre, false);
}
$this->files[$lieu][] = array($object, $nombre, false);
}
$planete->addModif("file_ter");
return true;
}
else
throw new ExceptionHB(3, 4);
}
$planete->addModif("file_ter");
return true;
} else {
throw new ExceptionHB(3, 4);
}
}
public function addDemolition($object, $nombre, surface $planete, $lieu = null)
{
//On vérifie que l'on ne dépasse pas la taille maximale de la file
if (!$this->checkMaxSize($planete, $lieu) && !($sauvLastKey = $this->objectInFile($object, $lieu)))
throw new ExceptionHB(3, 1);
public function addDemolition($object, $nombre, surface $planete, $lieu = null)
{
//On vérifie que l'on ne dépasse pas la taille maximale de la file
if (!$this->checkMaxSize($planete, $lieu) && !($sauvLastKey = $this->objectInFile($object, $lieu))) {
throw new ExceptionHB(3, 1);
}
//Vérification du nombre passé en entrée
if (!is_numeric($nombre) || $nombre < 0 || $nombre > 99999)
throw new ExceptionHB(3, 8);
//Vérification du nombre passé en entrée
if (!is_numeric($nombre) || $nombre < 0 || $nombre > 99999) {
throw new ExceptionHB(3, 8);
}
//On vérifie que le nombre d'unité actuel soit non nul
if ($planete->terrestres[$object] < $nombre)
throw new ExceptionHB(3, 6);
//On vérifie que le nombre d'unité actuel soit non nul
if ($planete->terrestres[$object] < $nombre) {
throw new ExceptionHB(3, 6);
}
if (!isset($lieu))
{
//On recherche le lieu ayant le moins de construction en cours
$lieu = $this->findShorter();
}
if (!isset($lieu)) {
//On recherche le lieu ayant le moins de construction en cours
$lieu = $this->findShorter();
}
//On rafraîchit le temps de la file si aucun objet n'est en file d'attente
$this->refreshTime($lieu);
//On rafraîchit le temps de la file si aucun objet n'est en file d'attente
$this->refreshTime($lieu);
//Si il existe déjà l'objet en file d'attente, on l'ajoute
if(isset($sauvLastKey))
$this->files[$sauvLastKey[0]][$sauvLastKey[1]][1] += $nombre;
else
$this->files[$lieu][] = array($object, $nombre, false);
//Si il existe déjà l'objet en file d'attente, on l'ajoute
if (isset($sauvLastKey)) {
$this->files[$sauvLastKey[0]][$sauvLastKey[1]][1] += $nombre;
} else {
$this->files[$lieu][] = array($object, $nombre, false);
}
$planete->addModif("file_ter");
$planete->addModif("file_ter");
return true;
}
return true;
}
public function delObjet($id, $nombre, $lieu, surface $planete)
{
//Vérification de l'existance de l'objet en file d'attente
if (empty($this->files[$lieu][$id]))
throw new ExceptionHB(1, 5);
public function delObjet($id, $nombre, $lieu, surface $planete)
{
//Vérification de l'existance de l'objet en file d'attente
if (empty($this->files[$lieu][$id])) {
throw new ExceptionHB(1, 5);
}
//Si $nombre est supérieur au nombre présent dans la file, on le réduit
if ($this->files[$lieu][$id][1] < $nombre)
$nombre = $this->files[$lieu][$id][1];
//Si $nombre est supérieur au nombre présent dans la file, on le réduit
if ($this->files[$lieu][$id][1] < $nombre) {
$nombre = $this->files[$lieu][$id][1];
}
//On récupère les informations disponibles
$objet = $this->files[$lieu][$id][0];
$nombreMax = $this->files[$lieu][$id][1];
//On récupère les informations disponibles
$objet = $this->files[$lieu][$id][0];
$nombreMax = $this->files[$lieu][$id][1];
//On met à jour le temps si on vient d'annuler le premier groupe d'unités en lice
if ($id == $this->findFirstKey($lieu) && $nombreMax == $nombre)
$this->times[$lieu] = time();
//On met à jour le temps si on vient d'annuler le premier groupe d'unités en lice
if ($id == $this->findFirstKey($lieu) && $nombreMax == $nombre) {
$this->times[$lieu] = time();
}
$planete->addModif("file_ter");
$planete->addModif("file_ter");
if (!$this->files[$lieu][$id][2])
$planete->addRessources(dTerrestre::metal($objet, $nombre, $planete), dTerrestre::cristal($objet, $nombre, $planete), dTerrestre::hydrogene($objet, $nombre, $planete), dTerrestre::credits($objet, $nombre, $planete));
if (!$this->files[$lieu][$id][2]) {
$planete->addRessources(dTerrestre::metal($objet, $nombre, $planete), dTerrestre::cristal($objet, $nombre, $planete), dTerrestre::hydrogene($objet, $nombre, $planete), dTerrestre::credits($objet, $nombre, $planete));
}
//Effacement de la file
if ($nombre >= $nombreMax)
unset($this->files[$lieu][$id]);
else
$this->files[$lieu][$id][1] -= $nombre;
$planete->addModif("file_ter");
//Effacement de la file
if ($nombre >= $nombreMax) {
unset($this->files[$lieu][$id]);
} else {
$this->files[$lieu][$id][1] -= $nombre;
}
$planete->addModif("file_ter");
return true;
}
return true;
}
public function ready(SURFACE $planete)
{
//On parcourt la liste des lieux de construction
foreach($this->files as $keyF => $file)
{
//On vérifie qu'il y a bien des éléments dans cette file d'attente
if (count($file) == 0)
continue;
public function ready(SURFACE $planete)
{
//On parcourt la liste des lieux de construction
foreach ($this->files as $keyF => $file) {
//On vérifie qu'il y a bien des éléments dans cette file d'attente
if (count($file) == 0) {
continue;
}
//On parcourt la liste à la recherche des unités terminées dans l'ordre
foreach($file as $keyE => $element)
{
//Calcul du temps écoulé depuis le dernier entraînement
$tempsEcoule = time() - $this->times[$keyF];
//On parcourt la liste à la recherche des unités terminées dans l'ordre
foreach ($file as $keyE => $element) {
//Calcul du temps écoulé depuis le dernier entraînement
$tempsEcoule = time() - $this->times[$keyF];
//On gére les licenciments !
if ($element[2])
{
//On vérifie qu'il reste des unités du type sur la planète
if ($planete->terrestres[$element[0]] <= 0)
{
unset($this->files[$keyF][$keyE]);
$planete->addModif("file_ter");
}
else
{
//Récupération de 60% du temps nécessaire
$tempsNecessaire = dTerrestre::temps($element[0], 1, $planete) * 0.6;
//On gére les licenciments !
if ($element[2]) {
//On vérifie qu'il reste des unités du type sur la planète
if ($planete->terrestres[$element[0]] <= 0) {
unset($this->files[$keyF][$keyE]);
$planete->addModif("file_ter");
} else {
//Récupération de 60% du temps nécessaire
$tempsNecessaire = dTerrestre::temps($element[0], 1, $planete) * 0.6;
//Calcul du nombre d'unités maximum
$nbUnitee = min(floor($tempsEcoule/$tempsNecessaire), $element[1], $planete->terrestres[$element[0]]);
//Calcul du nombre d'unités maximum
$nbUnitee = min(floor($tempsEcoule/$tempsNecessaire), $element[1], $planete->terrestres[$element[0]]);
//Si le temps écoulé est suffisant
if ($nbUnitee > 0)
{
//On redonne 70% des ressources de l'unité au joueur
$planete->addRessources(dTerrestre::metal($element[0], $nbUnitee, $planete)*0.7, dTerrestre::cristal($element[0], $nbUnitee, $planete)*0.7, dTerrestre::hydrogene($element[0], $nbUnitee, $planete)*0.7, dTerrestre::credits($element[0], $nbUnitee, $planete)*0.7);
//Si le temps écoulé est suffisant
if ($nbUnitee > 0) {
//On redonne 70% des ressources de l'unité au joueur
$planete->addRessources(dTerrestre::metal($element[0], $nbUnitee, $planete)*0.7, dTerrestre::cristal($element[0], $nbUnitee, $planete)*0.7, dTerrestre::hydrogene($element[0], $nbUnitee, $planete)*0.7, dTerrestre::credits($element[0], $nbUnitee, $planete)*0.7);
//On retire les unités
$planete->terrestres[$element[0]] -= $nbUnitee;
//On retire les unités
$planete->terrestres[$element[0]] -= $nbUnitee;
//On efface l'entrée de la file et on met à jour le temps de la file
if ($nbUnitee >= $element[1])
unset($this->filefiles[$keyF][$keyE]);
else
$this->file[$key][1] -= $nbUnitee;
$this->timefiles[$keyF] += $tempsNecessaire*$nbUnitee;
//On efface l'entrée de la file et on met à jour le temps de la file
if ($nbUnitee >= $element[1]) {
unset($this->filefiles[$keyF][$keyE]);
} else {
$this->file[$key][1] -= $nbUnitee;
}
$this->timefiles[$keyF] += $tempsNecessaire*$nbUnitee;
//On demande la mise à jour des champs modifiés
$planete->addModif(array("terrestres", $element[0]));
$planete->addModif("file_ter");
//On demande la mise à jour des champs modifiés
$planete->addModif(array("terrestres", $element[0]));
$planete->addModif("file_ter");
if ($nbUnitee < $element[1])
return false;
}
//Si le temps écoulé n'est pas suffisant pour cette unité, on annule toutes les suivantes
else
break;
}
}
else //Cas de la construction
{
//Récupération du temps nécessaire
$tempsNecessaire = dTerrestre::temps($element[0], 1, $planete);
if ($nbUnitee < $element[1]) {
return false;
}
}
//Si le temps écoulé n'est pas suffisant pour cette unité, on annule toutes les suivantes
else {
break;
}
}
} else { //Cas de la construction
//Récupération du temps nécessaire
$tempsNecessaire = dTerrestre::temps($element[0], 1, $planete);
//Calcul du nombre d'unités maximum
$nbUnitee = min(floor($tempsEcoule/$tempsNecessaire), $element[1]);
//Calcul du nombre d'unités maximum
$nbUnitee = min(floor($tempsEcoule/$tempsNecessaire), $element[1]);
//Si le temps écoulé est suffisant
if ($nbUnitee > 0)
{
//On ajoute le nombre d'unités
$planete->terrestres[$element[0]] += $nbUnitee;
//Si le temps écoulé est suffisant
if ($nbUnitee > 0) {
//On ajoute le nombre d'unités
$planete->terrestres[$element[0]] += $nbUnitee;
//On efface l'entrée de la file et on met à jour le temps de la file
if ($nbUnitee >= $element[1])
unset($this->files[$keyF][$keyE]);
else
$this->files[$keyF][$keyE][1] -= $nbUnitee;
$this->times[$keyF] += $tempsNecessaire * $nbUnitee;
//On efface l'entrée de la file et on met à jour le temps de la file
if ($nbUnitee >= $element[1]) {
unset($this->files[$keyF][$keyE]);
} else {
$this->files[$keyF][$keyE][1] -= $nbUnitee;
}
$this->times[$keyF] += $tempsNecessaire * $nbUnitee;
//On demande la mise à jour des champs modifiés
$planete->addModif(array("terrestres", $element[0]));
$planete->addModif("file_ter");
//On demande la mise à jour des champs modifiés
$planete->addModif(array("terrestres", $element[0]));
$planete->addModif("file_ter");
if ($nbUnitee < $element[1])
break;
}
//Si le temps écoulé n'est pas suffisant pour ce batiment, on annule tous les suivants
else
break;
}
}
}
}
if ($nbUnitee < $element[1]) {
break;
}
}
//Si le temps écoulé n'est pas suffisant pour ce batiment, on annule tous les suivants
else {
break;
}
}
}
}
}
function printFile(SURFACE $planete, $lieux = NULL)
{
$out = array();
foreach ($this->files as $keyF => $file)
{
if (isset($lieu) && $lieu != $keyF)
continue;
public function printFile(SURFACE $planete, $lieux = null)
{
$out = array();
foreach ($this->files as $keyF => $file) {
if (isset($lieu) && $lieu != $keyF) {
continue;
}
$prems = true;
foreach ($file as $keyE => $element)
{
if ($element[2])
{
$temps = dTerrestre::temps($element[0], 1, $planete) * 0.6;
if ($prems)
$temps_moins = time() - $this->times[$keyF];
else
$temps_moins = 0;
$out[$keyF][$keyE] = array($element[0], $element[1], $element[2], ceil($temps * $element[1] - $temps_moins), ceil($temps - $temps_moins), $prems, dTerrestre::type($element[0]));
}
else
{
$temps = dTerrestre::temps($element[0], 1, $planete);
if ($prems)
$temps_moins = time() - $this->times[$keyF];
else
$temps_moins = 0;
$out[$keyF][$keyE] = array($element[0], $element[1], $element[2], ceil($temps * $element[1] - $temps_moins), ceil($temps - $temps_moins), $prems, dTerrestre::type($element[0]));
}
$prems = false;
}
}
return $out;
}
$prems = true;
foreach ($file as $keyE => $element) {
if ($element[2]) {
$temps = dTerrestre::temps($element[0], 1, $planete) * 0.6;
if ($prems) {
$temps_moins = time() - $this->times[$keyF];
} else {
$temps_moins = 0;
}
$out[$keyF][$keyE] = array($element[0], $element[1], $element[2], ceil($temps * $element[1] - $temps_moins), ceil($temps - $temps_moins), $prems, dTerrestre::type($element[0]));
} else {
$temps = dTerrestre::temps($element[0], 1, $planete);
if ($prems) {
$temps_moins = time() - $this->times[$keyF];
} else {
$temps_moins = 0;
}
$out[$keyF][$keyE] = array($element[0], $element[1], $element[2], ceil($temps * $element[1] - $temps_moins), ceil($temps - $temps_moins), $prems, dTerrestre::type($element[0]));
}
$prems = false;
}
}
return $out;
}
}
?>

View file

@ -59,22 +59,22 @@
/**
* Marker constant for Services_JSON::decode(), used to flag stack state
*/
define('SERVICES_JSON_SLICE', 1);
define('SERVICES_JSON_SLICE', 1);
/**
* Marker constant for Services_JSON::decode(), used to flag stack state
*/
define('SERVICES_JSON_IN_STR', 2);
define('SERVICES_JSON_IN_STR', 2);
/**
* Marker constant for Services_JSON::decode(), used to flag stack state
*/
define('SERVICES_JSON_IN_ARR', 3);
define('SERVICES_JSON_IN_ARR', 3);
/**
* Marker constant for Services_JSON::decode(), used to flag stack state
*/
define('SERVICES_JSON_IN_OBJ', 4);
define('SERVICES_JSON_IN_OBJ', 4);
/**
* Marker constant for Services_JSON::decode(), used to flag stack state
@ -114,48 +114,48 @@ define('SERVICES_JSON_SUPPRESS_ERRORS', 32);
*/
class Services_JSON
{
/**
* constructs a new JSON instance
*
* @param int $use object behavior flags; combine with boolean-OR
*
* possible values:
* - SERVICES_JSON_LOOSE_TYPE: loose typing.
* "{...}" syntax creates associative arrays
* instead of objects in decode().
* - SERVICES_JSON_SUPPRESS_ERRORS: error suppression.
* Values which can't be encoded (e.g. resources)
* appear as NULL instead of throwing errors.
* By default, a deeply-nested resource will
* bubble up with an error, so all return values
* from encode() should be checked with isError()
*/
function Services_JSON($use = 0)
/**
* constructs a new JSON instance
*
* @param int $use object behavior flags; combine with boolean-OR
*
* possible values:
* - SERVICES_JSON_LOOSE_TYPE: loose typing.
* "{...}" syntax creates associative arrays
* instead of objects in decode().
* - SERVICES_JSON_SUPPRESS_ERRORS: error suppression.
* Values which can't be encoded (e.g. resources)
* appear as NULL instead of throwing errors.
* By default, a deeply-nested resource will
* bubble up with an error, so all return values
* from encode() should be checked with isError()
*/
public function Services_JSON($use = 0)
{
$this->use = $use;
}
/**
* convert a string from one UTF-16 char to one UTF-8 char
*
* Normally should be handled by mb_convert_encoding, but
* provides a slower PHP-only method for installations
* that lack the multibye string extension.
*
* @param string $utf16 UTF-16 character
* @return string UTF-8 character
* @access private
*/
function utf162utf8($utf16)
/**
* convert a string from one UTF-16 char to one UTF-8 char
*
* Normally should be handled by mb_convert_encoding, but
* provides a slower PHP-only method for installations
* that lack the multibye string extension.
*
* @param string $utf16 UTF-16 character
* @return string UTF-8 character
* @access private
*/
public function utf162utf8($utf16)
{
// oh please oh please oh please oh please oh please
if(function_exists('mb_convert_encoding')) {
if (function_exists('mb_convert_encoding')) {
return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16');
}
$bytes = (ord($utf16{0}) << 8) | ord($utf16{1});
switch(true) {
switch (true) {
case ((0x7F & $bytes) == $bytes):
// this case should never be reached, because we are in ASCII range
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
@ -179,25 +179,25 @@ class Services_JSON
return '';
}
/**
* convert a string from one UTF-8 char to one UTF-16 char
*
* Normally should be handled by mb_convert_encoding, but
* provides a slower PHP-only method for installations
* that lack the multibye string extension.
*
* @param string $utf8 UTF-8 character
* @return string UTF-16 character
* @access private
*/
function utf82utf16($utf8)
/**
* convert a string from one UTF-8 char to one UTF-16 char
*
* Normally should be handled by mb_convert_encoding, but
* provides a slower PHP-only method for installations
* that lack the multibye string extension.
*
* @param string $utf8 UTF-8 character
* @return string UTF-16 character
* @access private
*/
public function utf82utf16($utf8)
{
// oh please oh please oh please oh please oh please
if(function_exists('mb_convert_encoding')) {
if (function_exists('mb_convert_encoding')) {
return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8');
}
switch(strlen($utf8)) {
switch (strlen($utf8)) {
case 1:
// this case should never be reached, because we are in ASCII range
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
@ -223,18 +223,18 @@ class Services_JSON
return '';
}
/**
* encodes an arbitrary variable into JSON format
*
* @param mixed $var any number, boolean, string, array, or object to be encoded.
* see argument 1 to Services_JSON() above for array-parsing behavior.
* if var is a strng, note that encode() always expects it
* to be in ASCII or UTF-8 format!
*
* @return mixed JSON string representation of input var or an error if a problem occurs
* @access public
*/
function encode($var)
/**
* encodes an arbitrary variable into JSON format
*
* @param mixed $var any number, boolean, string, array, or object to be encoded.
* see argument 1 to Services_JSON() above for array-parsing behavior.
* if var is a strng, note that encode() always expects it
* to be in ASCII or UTF-8 format!
*
* @return mixed JSON string representation of input var or an error if a problem occurs
* @access public
*/
public function encode($var)
{
switch (gettype($var)) {
case 'boolean':
@ -260,7 +260,6 @@ class Services_JSON
* escaping with a slash or encoding to UTF-8 where necessary
*/
for ($c = 0; $c < $strlen_var; ++$c) {
$ord_var_c = ord($var{$c});
switch (true) {
@ -304,9 +303,12 @@ class Services_JSON
case (($ord_var_c & 0xF0) == 0xE0):
// characters U-00000800 - U-0000FFFF, mask 1110XXXX
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$char = pack('C*', $ord_var_c,
ord($var{$c + 1}),
ord($var{$c + 2}));
$char = pack(
'C*',
$ord_var_c,
ord($var{$c + 1}),
ord($var{$c + 2})
);
$c += 2;
$utf16 = $this->utf82utf16($char);
$ascii .= sprintf('\u%04s', bin2hex($utf16));
@ -315,10 +317,13 @@ class Services_JSON
case (($ord_var_c & 0xF8) == 0xF0):
// characters U-00010000 - U-001FFFFF, mask 11110XXX
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$char = pack('C*', $ord_var_c,
ord($var{$c + 1}),
ord($var{$c + 2}),
ord($var{$c + 3}));
$char = pack(
'C*',
$ord_var_c,
ord($var{$c + 1}),
ord($var{$c + 2}),
ord($var{$c + 3})
);
$c += 3;
$utf16 = $this->utf82utf16($char);
$ascii .= sprintf('\u%04s', bin2hex($utf16));
@ -327,11 +332,14 @@ class Services_JSON
case (($ord_var_c & 0xFC) == 0xF8):
// characters U-00200000 - U-03FFFFFF, mask 111110XX
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$char = pack('C*', $ord_var_c,
ord($var{$c + 1}),
ord($var{$c + 2}),
ord($var{$c + 3}),
ord($var{$c + 4}));
$char = pack(
'C*',
$ord_var_c,
ord($var{$c + 1}),
ord($var{$c + 2}),
ord($var{$c + 3}),
ord($var{$c + 4})
);
$c += 4;
$utf16 = $this->utf82utf16($char);
$ascii .= sprintf('\u%04s', bin2hex($utf16));
@ -340,12 +348,15 @@ class Services_JSON
case (($ord_var_c & 0xFE) == 0xFC):
// characters U-04000000 - U-7FFFFFFF, mask 1111110X
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$char = pack('C*', $ord_var_c,
ord($var{$c + 1}),
ord($var{$c + 2}),
ord($var{$c + 3}),
ord($var{$c + 4}),
ord($var{$c + 5}));
$char = pack(
'C*',
$ord_var_c,
ord($var{$c + 1}),
ord($var{$c + 2}),
ord($var{$c + 3}),
ord($var{$c + 4}),
ord($var{$c + 5})
);
$c += 5;
$utf16 = $this->utf82utf16($char);
$ascii .= sprintf('\u%04s', bin2hex($utf16));
@ -376,12 +387,14 @@ class Services_JSON
// treat as a JSON object
if (is_array($var) && count($var) && (array_keys($var) !== range(0, sizeof($var) - 1))) {
$properties = array_map(array($this, 'name_value'),
array_keys($var),
array_values($var));
$properties = array_map(
array($this, 'name_value'),
array_keys($var),
array_values($var)
);
foreach($properties as $property) {
if(Services_JSON::isError($property)) {
foreach ($properties as $property) {
if (Services_JSON::isError($property)) {
return $property;
}
}
@ -392,8 +405,8 @@ class Services_JSON
// treat it like a regular array
$elements = array_map(array($this, 'encode'), $var);
foreach($elements as $element) {
if(Services_JSON::isError($element)) {
foreach ($elements as $element) {
if (Services_JSON::isError($element)) {
return $element;
}
}
@ -403,12 +416,14 @@ class Services_JSON
case 'object':
$vars = get_object_vars($var);
$properties = array_map(array($this, 'name_value'),
array_keys($vars),
array_values($vars));
$properties = array_map(
array($this, 'name_value'),
array_keys($vars),
array_values($vars)
);
foreach($properties as $property) {
if(Services_JSON::isError($property)) {
foreach ($properties as $property) {
if (Services_JSON::isError($property)) {
return $property;
}
}
@ -422,35 +437,35 @@ class Services_JSON
}
}
/**
* array-walking function for use in generating JSON-formatted name-value pairs
*
* @param string $name name of key to use
* @param mixed $value reference to an array element to be encoded
*
* @return string JSON-formatted name-value pair, like '"name":value'
* @access private
*/
function name_value($name, $value)
/**
* array-walking function for use in generating JSON-formatted name-value pairs
*
* @param string $name name of key to use
* @param mixed $value reference to an array element to be encoded
*
* @return string JSON-formatted name-value pair, like '"name":value'
* @access private
*/
public function name_value($name, $value)
{
$encoded_value = $this->encode($value);
if(Services_JSON::isError($encoded_value)) {
if (Services_JSON::isError($encoded_value)) {
return $encoded_value;
}
return $this->encode(strval($name)) . ':' . $encoded_value;
}
/**
* reduce a string by removing leading and trailing comments and whitespace
*
* @param $str string string value to strip of comments and whitespace
*
* @return string string value stripped of comments and whitespace
* @access private
*/
function reduce_string($str)
/**
* reduce a string by removing leading and trailing comments and whitespace
*
* @param $str string string value to strip of comments and whitespace
*
* @return string string value stripped of comments and whitespace
* @access private
*/
public function reduce_string($str)
{
$str = preg_replace(array(
@ -469,19 +484,19 @@ class Services_JSON
return trim($str);
}
/**
* decodes a JSON string into appropriate variable
*
* @param string $str JSON-formatted string
*
* @return mixed number, boolean, string, array, or object
* corresponding to given JSON input string.
* See argument 1 to Services_JSON() above for object-output behavior.
* Note that decode() always returns strings
* in ASCII or UTF-8 format!
* @access public
*/
function decode($str)
/**
* decodes a JSON string into appropriate variable
*
* @param string $str JSON-formatted string
*
* @return mixed number, boolean, string, array, or object
* corresponding to given JSON input string.
* See argument 1 to Services_JSON() above for object-output behavior.
* Note that decode() always returns strings
* in ASCII or UTF-8 format!
* @access public
*/
public function decode($str)
{
$str = $this->reduce_string($str);
@ -509,7 +524,6 @@ class Services_JSON
return ((float)$str == (integer)$str)
? (integer)$str
: (float)$str;
} elseif (preg_match('/^("|\').*(\1)$/s', $str, $m) && $m[1] == $m[2]) {
// STRINGS RETURNED IN UTF-8 FORMAT
$delim = substr($str, 0, 1);
@ -518,7 +532,6 @@ class Services_JSON
$strlen_chrs = strlen($chrs);
for ($c = 0; $c < $strlen_chrs; ++$c) {
$substr_chrs_c_2 = substr($chrs, $c, 2);
$ord_chrs_c = ord($chrs{$c});
@ -602,11 +615,9 @@ class Services_JSON
break;
}
}
return $utf8;
} elseif (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) {
// array, or object notation
@ -633,10 +644,8 @@ class Services_JSON
if ($chrs == '') {
if (reset($stk) == SERVICES_JSON_IN_ARR) {
return $arr;
} else {
return $obj;
}
}
@ -645,7 +654,6 @@ class Services_JSON
$strlen_chrs = strlen($chrs);
for ($c = 0; $c <= $strlen_chrs; ++$c) {
$top = end($stk);
$substr_chrs_c_2 = substr($chrs, $c, 2);
@ -659,7 +667,6 @@ class Services_JSON
if (reset($stk) == SERVICES_JSON_IN_ARR) {
// we are in an array, so just push an element onto the stack
array_push($arr, $this->decode($slice));
} elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
// we are in an object, so figure
// out the property name and set an
@ -688,14 +695,11 @@ class Services_JSON
$obj->$key = $val;
}
}
}
} elseif ((($chrs{$c} == '"') || ($chrs{$c} == "'")) && ($top['what'] != SERVICES_JSON_IN_STR)) {
// found a quote, and we are not inside a string
array_push($stk, array('what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs{$c}));
//print("Found start of string at {$c}\n");
//print("Found start of string at {$c}\n");
} elseif (($chrs{$c} == $top['delim']) &&
($top['what'] == SERVICES_JSON_IN_STR) &&
((strlen(substr($chrs, 0, $c)) - strlen(rtrim(substr($chrs, 0, $c), '\\'))) % 2 != 1)) {
@ -703,59 +707,49 @@ class Services_JSON
// we know that it's not escaped becase there is _not_ an
// odd number of backslashes at the end of the string so far
array_pop($stk);
//print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n");
//print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n");
} elseif (($chrs{$c} == '[') &&
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
// found a left-bracket, and we are in an array, object, or slice
array_push($stk, array('what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false));
//print("Found start of array at {$c}\n");
//print("Found start of array at {$c}\n");
} elseif (($chrs{$c} == ']') && ($top['what'] == SERVICES_JSON_IN_ARR)) {
// found a right-bracket, and we're in an array
array_pop($stk);
//print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
//print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
} elseif (($chrs{$c} == '{') &&
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
// found a left-brace, and we are in an array, object, or slice
array_push($stk, array('what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false));
//print("Found start of object at {$c}\n");
//print("Found start of object at {$c}\n");
} elseif (($chrs{$c} == '}') && ($top['what'] == SERVICES_JSON_IN_OBJ)) {
// found a right-brace, and we're in an object
array_pop($stk);
//print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
//print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
} elseif (($substr_chrs_c_2 == '/*') &&
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
// found a comment start, and we are in an array, object, or slice
array_push($stk, array('what' => SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false));
$c++;
//print("Found start of comment at {$c}\n");
//print("Found start of comment at {$c}\n");
} elseif (($substr_chrs_c_2 == '*/') && ($top['what'] == SERVICES_JSON_IN_CMT)) {
// found a comment end, and we're in one now
array_pop($stk);
$c++;
for ($i = $top['where']; $i <= $c; ++$i)
for ($i = $top['where']; $i <= $c; ++$i) {
$chrs = substr_replace($chrs, ' ', $i, 1);
}
//print("Found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
}
}
if (reset($stk) == SERVICES_JSON_IN_ARR) {
return $arr;
} elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
return $obj;
}
}
}
}
@ -763,7 +757,7 @@ class Services_JSON
/**
* @todo Ultimately, this should just call PEAR::isError()
*/
function isError($data, $code = null)
public function isError($data, $code = null)
{
if (class_exists('pear')) {
return PEAR::isError($data, $code);
@ -777,16 +771,18 @@ class Services_JSON
}
if (class_exists('PEAR_Error')) {
class Services_JSON_Error extends PEAR_Error
{
function Services_JSON_Error($message = 'unknown error', $code = null,
$mode = null, $options = null, $userinfo = null)
{
public function Services_JSON_Error(
$message = 'unknown error',
$code = null,
$mode = null,
$options = null,
$userinfo = null
) {
parent::PEAR_Error($message, $code, $mode, $options, $userinfo);
}
}
} else {
/**
@ -794,13 +790,13 @@ if (class_exists('PEAR_Error')) {
*/
class Services_JSON_Error
{
function Services_JSON_Error($message = 'unknown error', $code = null,
$mode = null, $options = null, $userinfo = null)
{
public function Services_JSON_Error(
$message = 'unknown error',
$code = null,
$mode = null,
$options = null,
$userinfo = null
) {
}
}
}
?>

View file

@ -8,133 +8,149 @@
*
*
***************************************************************************/
class Alliance extends SURFACE{
var $id,
$race,
$fondateur,
$sante,
$nom,
$tag,
$galaxie,
$ss,
$nom_asteroide,
$image_asteroide,
$debris_met,
$debris_cri,
$credits,
$metal,
$cristal,
$hydrogene;
class Alliance extends SURFACE
{
public $id;
public $race;
public $fondateur;
public $sante;
public $nom;
public $tag;
public $galaxie;
public $ss;
public $nom_asteroide;
public $image_asteroide;
public $debris_met;
public $debris_cri;
public $credits;
public $metal;
public $cristal;
public $hydrogene;
/**
* Constructeur
* @param int $id id de l'alliance à importer
*
* @return void
* @access public
*/
function Alliance($id = 0){
if (!empty($id)) {
global $var___db, $config, $table_alliances;
global $alli_batimentVAR, $spatialVAR;
$bdd = new bdd();
$bdd->connexion();
$bdd->escape($id);
$alli = $bdd->unique_query("SELECT * FROM $table_alliances WHERE id = $id;");
$bdd->deconnexion();
if (!empty($alli)) {
$this->id = $alli["id"];
$this->race = $alli["race"];
$this->fondateur = $alli["fondateur"];
$this->sante = $alli["sante"];
$this->nom = $alli["nom"];
$this->tag = $alli["tag"];
$this->galaxie = $alli["galaxie"];
$this->ss = $alli["ss"];
$this->position = $alli["wing"];
$this->nom_asteroide = $alli["nom_asteroide"];
$this->image_asteroide = $alli["image_asteroide"];
$this->debris_met = $alli["debris_met"];
$this->debris_cri = $alli["debris_cri"];
$this->credits = $alli["credits"];
$this->metal = $alli["metal"];
$this->cristal = $alli["cristal"];
$this->hydrogene = $alli["hydrogene"];
/**
* Constructeur
* @param int $id id de l'alliance à importer
*
* @return void
* @access public
*/
public function Alliance($id = 0)
{
if (!empty($id)) {
global $var___db, $config, $table_alliances;
global $alli_batimentVAR, $spatialVAR;
$bdd = new bdd();
$bdd->connexion();
$bdd->escape($id);
$alli = $bdd->unique_query("SELECT * FROM $table_alliances WHERE id = $id;");
$bdd->deconnexion();
if (!empty($alli)) {
$this->id = $alli["id"];
$this->race = $alli["race"];
$this->fondateur = $alli["fondateur"];
$this->sante = $alli["sante"];
$this->nom = $alli["nom"];
$this->tag = $alli["tag"];
$this->galaxie = $alli["galaxie"];
$this->ss = $alli["ss"];
$this->position = $alli["wing"];
$this->nom_asteroide = $alli["nom_asteroide"];
$this->image_asteroide = $alli["image_asteroide"];
$this->debris_met = $alli["debris_met"];
$this->debris_cri = $alli["debris_cri"];
$this->credits = $alli["credits"];
$this->metal = $alli["metal"];
$this->cristal = $alli["cristal"];
$this->hydrogene = $alli["hydrogene"];
foreach($alli_batimentVAR as $bat){
$this->batiments[] = $alli[$bat];
}
$this->file_bat = unserialize($alli["file_bat"]);
foreach ($alli_batimentVAR as $bat) {
$this->batiments[] = $alli[$bat];
}
$this->file_bat = unserialize($alli["file_bat"]);
foreach($spatialVAR as $vais){
$this->vaisseaux[] = $plan[$vais];
}
$this->file_vais = unserialize($alli["file_vais"]);
foreach ($spatialVAR as $vais) {
$this->vaisseaux[] = $plan[$vais];
}
$this->file_vais = unserialize($alli["file_vais"]);
$this->actualiser();
}
}
}
$this->actualiser();
}
}
}
/**
* 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){
//Actualisation des files d'attentes
if ($actuFile) {
$this->file_pret("alli_batiments");
$this->file_pret("vaisseaux");
}
}
/**
* Actualise les ressources de la planète en fonction de la production et termine les files d'attentes.
*
* @return void
* @access public
*/
public function actualiser($actuFile = true)
{
//Actualisation des files d'attentes
if ($actuFile) {
$this->file_pret("alli_batiments");
$this->file_pret("vaisseaux");
}
}
/**
* Destructeur
*
* @return void
* @access public
*/
function __destruct(){
global $var___db, $config, $table_alliances;
$nb = count($this->modif);
$out = array();
$bdd = new bdd();
$bdd->connexion();
for($i = 0; $i < $nb; $i++){
if (!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 (preg_match('#file#', $this->modif[$i])) {
$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] == "alli_batiments") $calc = "alli_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";
/**
* Destructeur
*
* @return void
* @access public
*/
public function __destruct()
{
global $var___db, $config, $table_alliances;
$nb = count($this->modif);
$out = array();
$bdd = new bdd();
$bdd->connexion();
for ($i = 0; $i < $nb; $i++) {
if (!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 (preg_match('#file#', $this->modif[$i])) {
$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] == "alli_batiments") {
$calc = "alli_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'};
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->unique_query("UPDATE $table_alliances SET ".implode(', ', $out)." WHERE id = ".$this->id.";");
$bdd->deconnexion();
}
$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->unique_query("UPDATE $table_alliances SET ".implode(', ', $out)." WHERE id = ".$this->id.";");
}
$bdd->deconnexion();
}
}
?>

View file

@ -11,375 +11,359 @@ include_once("Class/surface.php");
***************************************************************************/
class Asteroide extends Surface
{
var $fondateur,
$sante,
$nom_alliance,
$tag,
$wing,
$nom_asteroide,
$image_asteroide,
$position = 5,
$cap = 123456789,
$credits_alliance,
$points_alliance,
$url_chat,
$url_forum,
$details = array();
public $fondateur;
public $sante;
public $nom_alliance;
public $tag;
public $wing;
public $nom_asteroide;
public $image_asteroide;
public $position = 5;
public $cap = 123456789;
public $credits_alliance;
public $points_alliance;
public $url_chat;
public $url_forum;
public $details = array();
/**
* Constructeur
* @param int $id id de la planète à importer
*
* @return void
* @access public
*/
function __construct($id = 0)
{
if (!empty($id)) {
global $table_alliances, $SESS;
global $alli_batimentsVAR, $spatialVAR;
$bdd = new BDD();
/**
* Constructeur
* @param int $id id de la planète à importer
*
* @return void
* @access public
*/
public function __construct($id = 0)
{
if (!empty($id)) {
global $table_alliances, $SESS;
global $alli_batimentsVAR, $spatialVAR;
$bdd = new BDD();
//On traite le cas où l'on envoie les coordonnées
if (is_numeric($id))
{
$plan = $bdd->unique_query("SELECT * FROM $table_alliances WHERE id = $id;");
$bdd->deconnexion();
}
elseif (preg_match('#^\[?([0-9]{1,2}):([0-9]{1,2}):?[Aa]?\]?$#', $id, $position))
{
$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 !');
//On traite le cas où l'on envoie les coordonnées
if (is_numeric($id)) {
$plan = $bdd->unique_query("SELECT * FROM $table_alliances WHERE id = $id;");
$bdd->deconnexion();
} elseif (preg_match('#^\[?([0-9]{1,2}):([0-9]{1,2}):?[Aa]?\]?$#', $id, $position)) {
$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->points_alliance = @$plan["points_alliance"];
$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"];
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->points_alliance = @$plan["points_alliance"];
$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_batimentsVAR as $bat)
$this->batiments[] = $plan[$bat];
if (!empty($plan["file_bat"]))
$this->file_bat = unserialize($plan["file_bat"]);
else
$this->file_bat = new FileAlliancesBatiments();
foreach ($alli_batimentsVAR as $bat) {
$this->batiments[] = $plan[$bat];
}
if (!empty($plan["file_bat"])) {
$this->file_bat = unserialize($plan["file_bat"]);
} else {
$this->file_bat = new FileAlliancesBatiments();
}
foreach($spatialVAR as $vais)
$this->vaisseaux[] = $plan[$vais];
if (!empty($plan["file_vais"]))
$this->file_vais = unserialize($plan["file_vais"]);
else
$this->file_vais = new FileSpatial('vaisseaux');
foreach ($spatialVAR as $vais) {
$this->vaisseaux[] = $plan[$vais];
}
if (!empty($plan["file_vais"])) {
$this->file_vais = unserialize($plan["file_vais"]);
} else {
$this->file_vais = new FileSpatial('vaisseaux');
}
}
}
}
}
}
}
public function loadDetails()
{
global $table_alliances, $table_user;
$bdd = new bdd();
$this->details = array_merge($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->unique_query("SELECT COUNT(id) AS nb_membres FROM $table_user WHERE id_alliance = ".$this->id.";"));
$bdd->deconnexion();
}
function loadDetails()
{
global $table_alliances, $table_user;
$bdd = new bdd();
$this->details = array_merge($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->unique_query("SELECT COUNT(id) AS nb_membres FROM $table_user WHERE id_alliance = ".$this->id.";"));
$bdd->deconnexion();
}
public function actualiser($actuFile = true, $first = false)
{
//Actualisation des files d'attentes
if ($actuFile) {
$this->file_bat->ready($this);
$this->file_vais->ready($this);
}
}
function actualiser($actuFile = true, $first = false)
{
//Actualisation des files d'attentes
if ($actuFile)
{
$this->file_bat->ready($this);
$this->file_vais->ready($this);
}
}
public function checkAndRetireRessources($metal, $cristal, $hydrogene, $credits)
{
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;
function checkAndRetireRessources($metal, $cristal, $hydrogene, $credits)
{
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");
$this->addModif("force");
$this->addModif("credits_alliance");
return true;
} else {
return false;
}
}
return true;
}
else
return false;
}
public function addRessources($metal, $cristal, $hydrogene, $credits)
{
$perte = 0;
function addRessources($metal, $cristal, $hydrogene, $credits)
{
$perte = 0;
$this->metal += $metal;
if ($this->metal > $this->cap) {
$perte += $this->metal - $this->cap;
$this->metal = $this->cap;
}
$this->metal += $metal;
if ($this->metal > $this->cap)
{
$perte += $this->metal - $this->cap;
$this->metal = $this->cap;
}
$this->cristal += $cristal;
if ($this->cristal > $this->cap) {
$perte += $this->cristal - $this->cap;
$this->cristal = $this->cap;
}
$this->cristal += $cristal;
if ($this->cristal > $this->cap)
{
$perte += $this->cristal - $this->cap;
$this->cristal = $this->cap;
}
$this->hydrogene += $hydrogene;
if ($this->hydrogene > $this->cap) {
$perte += $this->hydrogene - $this->cap;
$this->hydrogene = $this->cap;
}
$this->hydrogene += $hydrogene;
if ($this->hydrogene > $this->cap)
{
$perte += $this->hydrogene - $this->cap;
$this->hydrogene = $this->cap;
}
$this->hydrogecredits_alliancene += $credits;
$this->hydrogecredits_alliancene += $credits;
$this->addModif("force");
$this->addModif("credits_alliance");
$this->addModif("force");
$this->addModif("credits_alliance");
return $perte;
}
return $perte;
}
public function addCreditsAlliance($credits)
{
$this->credits_alliance += $credits;
$this->addModif("credits_alliance");
function addCreditsAlliance($credits)
{
$this->credits_alliance += $credits;
$this->addModif("credits_alliance");
return 0;
}
return 0;
}
public function addPoints($metal, $cristal, $hydrogene, $credits = 0, $demolition = false)
{
global $table_bourse_ressources;
//On charge les 3 valeurs boursières
$bdd = new BDD();
$bourse = $bdd->query("SELECT dispo FROM $table_bourse_ressources;");
$bdd->deconnexion();
function addPoints($metal, $cristal, $hydrogene, $credits = 0, $demolition = false)
{
global $table_bourse_ressources;
//On charge les 3 valeurs boursières
$bdd = new BDD();
$bourse = $bdd->query("SELECT dispo FROM $table_bourse_ressources;");
$bdd->deconnexion();
if (!empty($credits)) {
//TODO Equivalence non prouvée entre $credits/bourse_calcPrixBase($bourse[0]["dispo"], 0.7); et $credits/bourse_calcPrixBase($bourse[0]["dispo"], 1) * 0.7; dans le but de ne donner que 70% des points
$metal += $credits/bourse_calcPrixBase($bourse[0]["dispo"], 0.7);
$cristal += $credits/bourse_calcPrixBase($bourse[1]["dispo"], 0.7);
$hydrogene += $credits/bourse_calcPrixBase($bourse[2]["dispo"], 0.7);
}
if (!empty($credits))
{
//TODO Equivalence non prouvée entre $credits/bourse_calcPrixBase($bourse[0]["dispo"], 0.7); et $credits/bourse_calcPrixBase($bourse[0]["dispo"], 1) * 0.7; dans le but de ne donner que 70% des points
$metal += $credits/bourse_calcPrixBase($bourse[0]["dispo"], 0.7);
$cristal += $credits/bourse_calcPrixBase($bourse[1]["dispo"], 0.7);
$hydrogene += $credits/bourse_calcPrixBase($bourse[2]["dispo"], 0.7);
}
$points = bourse_calcPrixBase($bourse[0]["dispo"], $metal);
$points += bourse_calcPrixBase($bourse[1]["dispo"], $cristal);
$points += bourse_calcPrixBase($bourse[2]["dispo"], $hydrogene);
$points = bourse_calcPrixBase($bourse[0]["dispo"], $metal);
$points += bourse_calcPrixBase($bourse[1]["dispo"], $cristal);
$points += bourse_calcPrixBase($bourse[2]["dispo"], $hydrogene);
if ($demolition) {
$this->points_alliance -= intval($points);
} else {
$this->points_alliance += intval($points);
}
if ($demolition)
$this->points_alliance -= intval($points);
else
$this->points_alliance += intval($points);
$this->addModif("points_alliance");
}
$this->addModif("points_alliance");
}
public function creer($fondateur, $mere = false)
{
global $VAR, $table_alliances_creation;
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();
$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;
}
//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;
//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
$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);
//Génération du nombre de case et de l'image en fonction de la position dans le système
$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);
$this->modif = array("fondateur", "race", "nom_alliance", "galaxie", "ss", "tag", "nom_asteroide", "image_asteroide");
}
$this->modif = array("fondateur", "race", "nom_alliance", "galaxie", "ss", "tag", "nom_asteroide", "image_asteroide");
}
/**
* Destructeur
*
* @return void
* @access public
*/
public function __destruct()
{
if (empty($this->ss) || empty($this->fondateur)) {
return;
}
if (DEBUG) {
var_dump($this);
}
/**
* Destructeur
*
* @return void
* @access public
*/
function __destruct()
{
if (empty($this->ss) || empty($this->fondateur))
return;
if (DEBUG)
var_dump($this);
global $table_alliances;
if (empty($this->id)) {
$outNomChamps = array();
$outValeurs = array();
$bdd = new BDD();
foreach ($this->modif as $modif) {
//On gère les champs variables tableaux
if (is_array($modif)) {
if ($modif[0] == "batiments") {
$calc = dDonnees::nameVAR("alli_batiments");
} else {
$calc = dDonnees::nameVAR($modif[0]);
}
global $table_alliances;
if (empty($this->id))
{
$outNomChamps = array(); $outValeurs = array();
$bdd = new BDD();
foreach($this->modif as $modif)
{
//On gère les champs variables tableaux
if (is_array($modif))
{
if ($modif[0] == "batiments")
$calc = dDonnees::nameVAR("alli_batiments");
else
$calc = dDonnees::nameVAR($modif[0]);
if (!isset(${$calc.'VAR'})) {
global ${$calc.'VAR'};
}
if (!isset(${$calc.'VAR'}))
global ${$calc.'VAR'};
$outNomChamps[] = ${$calc.'VAR'}[$modif[1]];
$outValeurs[] = $this->{$modif[0]}[$modif[1]];
} elseif ($modif == "force") {
$outNomChamps[] = "metal";
$outNomChamps[] = "cristal";
$outNomChamps[] = "hydrogene";
$outNomChamps[] = ${$calc.'VAR'}[$modif[1]];
$outValeurs[] = $this->{$modif[0]}[$modif[1]];
}
elseif ($modif == "force")
{
$outNomChamps[] = "metal";
$outNomChamps[] = "cristal";
$outNomChamps[] = "hydrogene";
$outValeurs[] = $this->metal;
$outValeurs[] = $this->cristal;
$outValeurs[] = $this->hydrogene;
} elseif (!is_array($this->{$modif})) {
$bdd->escape($this->{$modif});
$outNomChamps[] = $modif;
if (is_int($this->{$modif}) || is_float($this->{$modif})) {
$outValeurs[] = $this->{$modif};
} else {
$outValeurs[] = "'".$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);
$outNomChamps[] = $modif;
$outValeurs[] = "'$prep'";
} else {
$calc = dDonnees::nameVAR($modif);
$outValeurs[] = $this->metal;
$outValeurs[] = $this->cristal;
$outValeurs[] = $this->hydrogene;
}
elseif (!is_array($this->{$modif}))
{
$bdd->escape($this->{$modif});
$outNomChamps[] = $modif;
if (is_int($this->{$modif}) || is_float($this->{$modif}))
$outValeurs[] = $this->{$modif};
else
$outValeurs[] = "'".$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);
$outNomChamps[] = $modif;
$outValeurs[] = "'$prep'";
}
else
{
$calc = dDonnees::nameVAR($modif);
if (!isset(${$calc.'VAR'})) {
global ${$calc.'VAR'};
}
if (!isset(${$calc.'VAR'}))
global ${$calc.'VAR'};
foreach ($this->{$modif} as $j => $value) {
$outNomChamps[] = ${$calc.'VAR'}[$j];
$outValeurs[] = $value;
}
}
}
}
//On supprime le lien de construction de l'alliance
$bdd->query("DELETE FROM $table_alliances_creation WHERE fondateur = ".$this->fondateur.";");
if ($bdd->affected() != 1) {
elog($bdd->affected()." champ(s) affecté(s) par la requête du fichier ".__FILE__." à la ligne ".__LINE__.", données : fondateur = ".$this->fondateur, 2);
}
//On ajout l'astéroide
$bdd->query("INSERT INTO $table_alliances (".implode(', ', $outNomChamps).") VALUES (".implode(', ', $outValeurs).");");
if ($bdd->affected() != 1) {
elog($bdd->affected()." champ(s) affecté(s) par la requête du fichier ".__FILE__." à la ligne ".__LINE__.", données : outNomChamps = ".serialize($outNomChamps)." ; outValeurs = ".serialize($outValeurs), 2);
}
$bdd->deconnexion();
} else {
$out = array();
$bdd = new BDD();
foreach ($this->modif as $modif) {
//On gère les champs variables tableaux
if (is_array($modif)) {
if ($modif[0] == "batiments") {
$calc = dDonnees::nameVAR("alli_batiments");
} else {
$calc = dDonnees::nameVAR($modif[0]);
}
foreach($this->{$modif} as $j => $value)
{
$outNomChamps[] = ${$calc.'VAR'}[$j];
$outValeurs[] = $value;
}
}
}
}
//On supprime le lien de construction de l'alliance
$bdd->query("DELETE FROM $table_alliances_creation WHERE fondateur = ".$this->fondateur.";");
if ($bdd->affected() != 1)
elog($bdd->affected()." champ(s) affecté(s) par la requête du fichier ".__FILE__." à la ligne ".__LINE__.", données : fondateur = ".$this->fondateur, 2);
//On ajout l'astéroide
$bdd->query("INSERT INTO $table_alliances (".implode(', ', $outNomChamps).") VALUES (".implode(', ', $outValeurs).");");
if ($bdd->affected() != 1)
elog($bdd->affected()." champ(s) affecté(s) par la requête du fichier ".__FILE__." à la ligne ".__LINE__.", données : outNomChamps = ".serialize($outNomChamps)." ; outValeurs = ".serialize($outValeurs), 2);
$bdd->deconnexion();
}
else
{
$out = array();
$bdd = new BDD();
foreach($this->modif as $modif)
{
//On gère les champs variables tableaux
if (is_array($modif))
{
if ($modif[0] == "batiments")
$calc = dDonnees::nameVAR("alli_batiments");
else
$calc = dDonnees::nameVAR($modif[0]);
if (!isset(${$calc.'VAR'})) {
global ${$calc.'VAR'};
}
if (empty(${$calc.'VAR'})) {
trigger_error('Impossible de trouver les données pour '.$modif[0], E_USER_ERROR);
}
if (!isset(${$calc.'VAR'}))
global ${$calc.'VAR'};
if (empty(${$calc.'VAR'}))
trigger_error('Impossible de trouver les données pour '.$modif[0], E_USER_ERROR);
$out[] = ${$calc.'VAR'}[$modif[1]]." = ".$this->{$modif[0]}[$modif[1]];
} elseif ($modif == "force") {
$out[] = "metal = ".$this->metal;
$out[] = "cristal = ".$this->cristal;
$out[] = "hydrogene = ".$this->hydrogene;
} elseif (!is_array($this->{$modif}) && !is_object($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 ($modif != "coeff_bat" && $modif != "vaisseaux" && $modif != "terrestres" && $modif != "casernes" && $modif != "technologies" && $modif != "batiments") {
$prep = serialize($this->{$modif});
$bdd->escape($prep);
$out[] = $modif." = '$prep'";
} else {
$calc = dDonnees::nameVAR($modif);
$out[] = ${$calc.'VAR'}[$modif[1]]." = ".$this->{$modif[0]}[$modif[1]];
}
elseif ($modif == "force")
{
$out[] = "metal = ".$this->metal;
$out[] = "cristal = ".$this->cristal;
$out[] = "hydrogene = ".$this->hydrogene;
}
elseif (!is_array($this->{$modif}) && !is_object($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 ($modif != "coeff_bat" && $modif != "vaisseaux" && $modif != "terrestres" && $modif != "casernes" && $modif != "technologies" && $modif != "batiments")
{
$prep = serialize($this->{$modif});
$bdd->escape($prep);
$out[] = $modif." = '$prep'";
}
else
{
$calc = dDonnees::nameVAR($modif);
if (!isset(${$calc.'VAR'})) {
global ${$calc.'VAR'};
}
if (!isset(${$calc.'VAR'}))
global ${$calc.'VAR'};
foreach ($this->{$modif} as $j => $value) {
$out[] = ${$calc.'VAR'}[$j]." = ".$value;
}
}
}
}
if (!empty($out)) {
$sql = "UPDATE $table_alliances SET ".implode(', ', $out)." WHERE id = ".$this->id.";";
if (DEBUG) {
echo '<br /><br />'.$sql;
}
$bdd->query($sql);
if ($bdd->affected() != 1) {
elog($bdd->affected()." champ(s) affecté(s) par la requête du fichier ".__FILE__." à la ligne ".__LINE__.", données : out = ".serialize($out), 2);
}
}
foreach($this->{$modif} as $j => $value)
$out[] = ${$calc.'VAR'}[$j]." = ".$value;
}
}
}
if (!empty($out))
{
$sql = "UPDATE $table_alliances SET ".implode(', ', $out)." WHERE id = ".$this->id.";";
if (DEBUG)
echo '<br /><br />'.$sql;
$bdd->query($sql);
if ($bdd->affected() != 1)
elog($bdd->affected()." champ(s) affecté(s) par la requête du fichier ".__FILE__." à la ligne ".__LINE__.", données : out = ".serialize($out), 2);
}
$bdd->deconnexion();
parent::__destruct();
}
}
$bdd->deconnexion();
parent::__destruct();
}
}
}
?>

View file

@ -6,37 +6,36 @@
*/
class Attaques
{
var $groupes = array();
public $groupes = array();
/**
* Constructor
*/
function __construct()
{
/**
* Constructor
*/
public function __construct()
{
}
}
public function addGroupe($groupe)
{
$this->groupes[] = $groupe;
}
function addGroupe($groupe)
{
$this->groupes[] = $groupe;
}
public function checkAllGroupes()
{
foreach ($groupes as $key => $groupe) {
$this->checkGroupe($key);
}
}
function checkAllGroupes()
{
foreach ($groupes as $key => $groupe)
$this->checkGroupe($key);
}
function checkGroupe($id)
{
if (is_a($this->groupes[$id], "Groupe"))
{
if ($this->groupes[$id]->)
{
}
}
$groupes[$id]->
}
public function checkGroupe($id)
{
// if (is_a($this->groupes[$id], "Groupe"))
// {
// if ($this->groupes[$id]->)
// {
//
// }
// }
// $groupes[$id]->
}
}
?>

View file

@ -4,187 +4,224 @@
* Dernière édition le 21 Juillet 2008
* Copyright Halo-Battle Tous droits réservés
*/
class Bourse{
var $bd;
class Bourse
{
public $bd;
var $id;
var $nom;
var $taxeA = 1.1;
var $taxeV = 1.5;
var $metal;
var $cristal;
var $actionsUser;
var $user;
public $id;
public $nom;
public $taxeA = 1.1;
public $taxeV = 1.5;
public $metal;
public $cristal;
public $actionsUser;
public $user;
/**
* Constructor
*
* @param String $nom Nom de l'action
* @param int $user ID du joueur à charger automatiquement
*
* @access protected
*/
function Bourse($nom = "", $user = 0){
global $var___db, $config;
$db = new bdd();
$db->connexion();
$this->bd = $db;
/**
* Constructor
*
* @param String $nom Nom de l'action
* @param int $user ID du joueur à charger automatiquement
*
* @access protected
*/
public function Bourse($nom = "", $user = 0)
{
global $var___db, $config;
$db = new bdd();
$db->connexion();
$this->bd = $db;
if (!empty($nom)) {
$this->loadAction($nom, "id");
if (!empty($user)) $this->loadUser($user);
}
}
if (!empty($nom)) {
$this->loadAction($nom, "id");
if (!empty($user)) {
$this->loadUser($user);
}
}
}
function __destruct(){
$this->bd->deconnexion();
}
public function __destruct()
{
$this->bd->deconnexion();
}
function loadAction($nom, $type = "nom"){
global $table_bourse;
$this->bd->escape($nom);
$act = $this->bd->unique_query("SELECT * FROM $table_bourse WHERE $type = '$nom';");
if ($act) {
$this->id = $act['id'];
$this->nom = $act['nom'];
$this->metal = $act['metal'];
$this->cristal = $act['cristal'];
}
else erreur('Impossible de trouver cette action !', "red", '?p=bourse');
}
public function loadAction($nom, $type = "nom")
{
global $table_bourse;
$this->bd->escape($nom);
$act = $this->bd->unique_query("SELECT * FROM $table_bourse WHERE $type = '$nom';");
if ($act) {
$this->id = $act['id'];
$this->nom = $act['nom'];
$this->metal = $act['metal'];
$this->cristal = $act['cristal'];
} else {
erreur('Impossible de trouver cette action !', "red", '?p=bourse');
}
}
function loadUser($user, $type = "id"){
global $table_user;
$this->bd->escape($user);
$act = $this->bd->unique_query("SELECT id, bourse FROM $table_user WHERE $type = '$user';");
$this->user = $act['id'];
$this->traitUser($act['bourse']);
}
public function loadUser($user, $type = "id")
{
global $table_user;
$this->bd->escape($user);
$act = $this->bd->unique_query("SELECT id, bourse FROM $table_user WHERE $type = '$user';");
$this->user = $act['id'];
$this->traitUser($act['bourse']);
}
function traitUser($start){
$end = array();
$start = explode(';', $start);
$cnt = count($start);
for($i = 0; $i < $cnt; $i++){
$tmp = explode(':', $start[$i]);
if (!empty($tmp[1])) $end[$tmp[0]] = explode(',', $tmp[1]);
else $end[$tmp[0]] = array();
}
$this->actionsUser = $end;
}
public function traitUser($start)
{
$end = array();
$start = explode(';', $start);
$cnt = count($start);
for ($i = 0; $i < $cnt; $i++) {
$tmp = explode(':', $start[$i]);
if (!empty($tmp[1])) {
$end[$tmp[0]] = explode(',', $tmp[1]);
} else {
$end[$tmp[0]] = array();
}
}
$this->actionsUser = $end;
}
function prixAchat($nb){
return array(floor($this->metal * $nb * $this->taxeA), floor($this->cristal * $nb * $this->taxeA));
}
public function prixAchat($nb)
{
return array(floor($this->metal * $nb * $this->taxeA), floor($this->cristal * $nb * $this->taxeA));
}
function prixVente($nb){
if ($this->action() < $nb) $nb = $this->action();
public function prixVente($nb)
{
if ($this->action() < $nb) {
$nb = $this->action();
}
return array(floor($this->metal * $nb / $this->taxeV), floor($this->cristal * $nb / $this->taxeV));
}
return array(floor($this->metal * $nb / $this->taxeV), floor($this->cristal * $nb / $this->taxeV));
}
function addAction($nb){
$ret = array(floor($this->metal * $nb * $this->taxeA), floor($this->cristal * $nb * $this->taxeA));
public function addAction($nb)
{
$ret = array(floor($this->metal * $nb * $this->taxeA), floor($this->cristal * $nb * $this->taxeA));
$this->metal *= pow(1.1, $nb);
$this->cristal *= pow(1.1, $nb);
$this->metal *= pow(1.1, $nb);
$this->cristal *= pow(1.1, $nb);
for($i = 0; $i < $nb; $i++){
$this->actionsUser[$this->id][] = time();
}
for ($i = 0; $i < $nb; $i++) {
$this->actionsUser[$this->id][] = time();
}
$this->maj();
return $ret;
}
$this->maj();
return $ret;
}
function delAction($nb){
if ($this->action() < $nb) $nb = $this->action();
public function delAction($nb)
{
if ($this->action() < $nb) {
$nb = $this->action();
}
$ret = array(floor($this->metal * $nb / $this->taxeV), floor($this->cristal * $nb / $this->taxeV));
$ret = array(floor($this->metal * $nb / $this->taxeV), floor($this->cristal * $nb / $this->taxeV));
$this->metal /= pow(1.1, $nb);
$this->cristal /= pow(1.1, $nb);
$this->metal /= pow(1.1, $nb);
$this->cristal /= pow(1.1, $nb);
for($i = 0; $i < $nb; $i++){
unset($this->actionsUser[$this->id][$i]);
}
for ($i = 0; $i < $nb; $i++) {
unset($this->actionsUser[$this->id][$i]);
}
$this->maj();
return $ret;
}
$this->maj();
return $ret;
}
function actionIn24Hours(){
$nb = 0;
if (isset($this->actionsUser[$this->id])) {
$cnt = count($this->actionsUser[$this->id]);
for($i = 0; $i < $cnt; $i++){
if ($this->actionsUser[$this->id][$i] > time() - 86400) $nb++;
}
}
return $nb;
}
public function actionIn24Hours()
{
$nb = 0;
if (isset($this->actionsUser[$this->id])) {
$cnt = count($this->actionsUser[$this->id]);
for ($i = 0; $i < $cnt; $i++) {
if ($this->actionsUser[$this->id][$i] > time() - 86400) {
$nb++;
}
}
}
return $nb;
}
function action(){
if (isset($this->actionsUser[$this->id])) return count($this->actionsUser[$this->id]);
else return 0;
public function action()
{
if (isset($this->actionsUser[$this->id])) {
return count($this->actionsUser[$this->id]);
} else {
return 0;
}
}
}
public function maj()
{
$this->majBourse();
$this->majUser();
$this->fileSave();
}
function maj(){
$this->majBourse();
$this->majUser();
$this->fileSave();
}
public function majBourse()
{
global $table_bourse;
function majBourse(){
global $table_bourse;
$this->bd->query("UPDATE $table_bourse SET nom = '".$this->nom."', metal = '".$this->metal."', cristal = '".$this->cristal."' WHERE id = ".$this->id.";");
}
$this->bd->query("UPDATE $table_bourse SET nom = '".$this->nom."', metal = '".$this->metal."', cristal = '".$this->cristal."' WHERE id = ".$this->id.";");
}
public function majUser()
{
global $table_user;
function majUser(){
global $table_user;
$champ = '';
foreach ($this->actionsUser as $key => $cell) {
if (count($cell) > 0) {
if (empty($champ)) {
$champ .= $key.':'.implode(',', $cell);
} else {
$champ .= ';'.$key.':'.implode(',', $cell);
}
}
}
$champ = '';
foreach($this->actionsUser as $key => $cell) {
if (count($cell) > 0) {
if (empty($champ)) $champ .= $key.':'.implode(',', $cell);
else $champ .= ';'.$key.':'.implode(',', $cell);
}
}
$this->bd->query("UPDATE $table_user SET bourse = '$champ' WHERE id = ".$this->user.";");
}
$this->bd->query("UPDATE $table_user SET bourse = '$champ' WHERE id = ".$this->user.";");
}
public function delUser($id = "")
{
if (!empty($id)) {
$this->loadUser($id);
}
function delUser($id = ""){
if (!empty($id)) $this->loadUser($id);
$champ = '';
foreach($this->actionsUser as $key => $cell) {
$cnt = count($cell);
if ($cnt > 0) {
$this->loadAction($key, "id");
$this->delAction($cnt);
}
}
}
$champ = '';
foreach ($this->actionsUser as $key => $cell) {
$cnt = count($cell);
if ($cnt > 0) {
$this->loadAction($key, "id");
$this->delAction($cnt);
}
}
}
function fileSave(){
$fichier = fopen(_FCORE."../game/cache/bourse/".$this->id.".".strftime('%Y%m%d').".bourse",'a+');
fwrite($fichier, time().';'.$this->metal.';'.$this->cristal."\n");
fclose($fichier);
}
public function fileSave()
{
$fichier = fopen(_FCORE."../game/cache/bourse/".$this->id.".".strftime('%Y%m%d').".bourse", 'a+');
fwrite($fichier, time().';'.$this->metal.';'.$this->cristal."\n");
fclose($fichier);
}
function newGroupe($nom, $metal, $cristal, $description = ""){
global $table_bourse;
public function newGroupe($nom, $metal, $cristal, $description = "")
{
global $table_bourse;
$this->bd->query("INSERT INTO $table_bourse (nom, metal, cristal, description) VALUES('$nom', '$metal', '$cristal', '$description');");
}
$this->bd->query("INSERT INTO $table_bourse (nom, metal, cristal, description) VALUES('$nom', '$metal', '$cristal', '$description');");
}
function editGroupe($description){
//TODO toute cette fonction !!
}
public function editGroupe($description)
{
//TODO toute cette fonction !!
}
}
?>

View file

@ -9,254 +9,262 @@
*
***************************************************************************/
class Donnee
{
public static function donneeTechnologie($branche, $idTechnologie, $retour, Planete $planete)
{
static function donneeTechnologie($branche, $idTechnologie, $retour, Planete $planete)
{
//TODO : Faire un switch pour ne renvoyer le tableau que de la branche plutôt que ce tableau avec l'intégralité des branches.
$technologies_donnees = array(
//Industrie
array(
array(1, 0, 1000, 54000),
array(2, 1, 2000, 90000),
array(4, 3, 4000, 126000),
array(8, 1, 4000, 126000),
array(16, 1, 2000, 72000),
array(32, 17, 4000, 108000),
array(64, 49, 8000, 144000),
array(128, 1, 2000, 72000),
array(256, 129, 4000, 108000),
array(512, 385, 8000, 144000),
array(1024, 1, 2000, 72000),
array(2048, 1025, 4000, 108000),
array(4096, 3073, 8000, 144000),
array(8192, 9, 3000, 126000),
array(16384, 8201, 6000, 162000),
array(32768, 24585, 12000, 198000),
array(65536, 1169, 3000, 126000),
array(131072, 66705, 6000, 162000),
array(262144, 197777, 12000, 198000)
),
//Ingénieurie
array(
array(1, 0, 1000, 54000),
array(2, 1, 2000, 90000),
array(4, 3, 4000, 126000),
array(8, 1, 2000, 90000),
array(16, 9, 4000, 126000),
array(32, 25, 8000, 162000),
array(64, 9, 3000, 126000),
array(128, 73, 6000, 162000),
array(256, 201, 12000, 198000),
array(512, 73, 4000, 162000),
array(1024, 585, 8000, 198000),
array(2048, 1609, 16000, 234000),
array(4096, 0, 1000, 54000),
array(8192, 4096, 2000, 90000),
array(16384, 12288, 4000, 126000),
array(32768, 4096, 2000, 54000),
array(65536, 36864, 4000, 90000),
array(131072, 102400, 8000, 126000),
array(262144, 12288, 2000, 72000),
array(524288, 274432, 4000, 108000),
array(1048576, 798720, 8000, 144000),
array(2097152, 274432, 2000, 54000),
array(4194304, 2371584, 4000, 90000),
array(8388608, 6565888, 8000, 126000),
array(16777216, 28672, 2000, 54000),
array(33554432, 16805888, 4000, 90000),
array(67108864, 50360320, 8000, 126000),
array(134217728, 28672, 3000, 90000),
array(268435456, 134246400, 6000, 126000),
array(536870912, 402681856, 12000, 162000)
),
//Ingénieurie 2
array(
array(1, 0, 1000, 36000),
array(2, 1, 2000, 72000),
array(4, 3, 4000, 108000),
array(8, 1, 4000, 126000),
array(16, 1, 4000, 126000),
array(32, 25, 4000, 126000),
array(64, 57, 8000, 162000),
array(128, 121, 16000, 198000)
),
//Politique
array(
array(1, 0, 1000, 36000),
array(2, 1, 2000, 72000),
array(4, 3, 4000, 108000),
array(8, 1, 2000, 72000),
array(16, 9, 4000, 108000),
array(32, 25, 8000, 144000),
array(64, 9, 4000, 126000),
array(128, 8, 6000, 162000),
array(256, 9, 6000, 162000),
array(512, 0, 1000, 90000),
array(1024, 512, 2000, 90000),
array(2048, 1536, 4000, 90000),
array(4096, 512, 2000, 72000),
array(8192, 4608, 4000, 108000),
array(16384, 12800, 8000, 144000)
),
//TODO : Faire un switch pour ne renvoyer le tableau que de la branche plutôt que ce tableau avec l'intégralité des branches.
$technologies_donnees = array(
//Industrie
array(
array(1, 0, 1000, 54000),
array(2, 1, 2000, 90000),
array(4, 3, 4000, 126000),
array(8, 1, 4000, 126000),
array(16, 1, 2000, 72000),
array(32, 17, 4000, 108000),
array(64, 49, 8000, 144000),
array(128, 1, 2000, 72000),
array(256, 129, 4000, 108000),
array(512, 385, 8000, 144000),
array(1024, 1, 2000, 72000),
array(2048, 1025, 4000, 108000),
array(4096, 3073, 8000, 144000),
array(8192, 9, 3000, 126000),
array(16384, 8201, 6000, 162000),
array(32768, 24585, 12000, 198000),
array(65536, 1169, 3000, 126000),
array(131072, 66705, 6000, 162000),
array(262144, 197777, 12000, 198000)
),
//Ingénieurie
array(
array(1, 0, 1000, 54000),
array(2, 1, 2000, 90000),
array(4, 3, 4000, 126000),
array(8, 1, 2000, 90000),
array(16, 9, 4000, 126000),
array(32, 25, 8000, 162000),
array(64, 9, 3000, 126000),
array(128, 73, 6000, 162000),
array(256, 201, 12000, 198000),
array(512, 73, 4000, 162000),
array(1024, 585, 8000, 198000),
array(2048, 1609, 16000, 234000),
array(4096, 0, 1000, 54000),
array(8192, 4096, 2000, 90000),
array(16384, 12288, 4000, 126000),
array(32768, 4096, 2000, 54000),
array(65536, 36864, 4000, 90000),
array(131072, 102400, 8000, 126000),
array(262144, 12288, 2000, 72000),
array(524288, 274432, 4000, 108000),
array(1048576, 798720, 8000, 144000),
array(2097152, 274432, 2000, 54000),
array(4194304, 2371584, 4000, 90000),
array(8388608, 6565888, 8000, 126000),
array(16777216, 28672, 2000, 54000),
array(33554432, 16805888, 4000, 90000),
array(67108864, 50360320, 8000, 126000),
array(134217728, 28672, 3000, 90000),
array(268435456, 134246400, 6000, 126000),
array(536870912, 402681856, 12000, 162000)
),
//Ingénieurie 2
array(
array(1, 0, 1000, 36000),
array(2, 1, 2000, 72000),
array(4, 3, 4000, 108000),
array(8, 1, 4000, 126000),
array(16, 1, 4000, 126000),
array(32, 25, 4000, 126000),
array(64, 57, 8000, 162000),
array(128, 121, 16000, 198000)
),
//Politique
array(
array(1, 0, 1000, 36000),
array(2, 1, 2000, 72000),
array(4, 3, 4000, 108000),
array(8, 1, 2000, 72000),
array(16, 9, 4000, 108000),
array(32, 25, 8000, 144000),
array(64, 9, 4000, 126000),
array(128, 8, 6000, 162000),
array(256, 9, 6000, 162000),
array(512, 0, 1000, 90000),
array(1024, 512, 2000, 90000),
array(2048, 1536, 4000, 90000),
array(4096, 512, 2000, 72000),
array(8192, 4608, 4000, 108000),
array(16384, 12800, 8000, 144000)
),
//Armement
array(
array(1, 0, 1000, 36000),
array(2, 1, 2000, 72000),
array(4, 3, 4000, 108000),
array(8, 1, 1000, 54000),
array(16, 9, 2000, 90000),
array(32, 25, 4000, 126000),
array(64, 9, 2000, 72000),
array(128, 73, 4000, 108000),
array(256, 201, 8000, 144000),
array(512, 73, 2000, 90000),
array(1024, 585, 4000, 126000),
array(2048, 1609, 8000, 162000),
array(4096, 1, 3000, 108000),
array(8192, 4097, 6000, 144000),
array(16384, 12289, 12000, 180000),
array(32768, 4097, 3000, 126000),
array(65536, 36865, 6000, 162000),
array(131072, 102401, 12000, 198000)
),
//Défense
array(
array(1, 0, 1000, 36000),
array(2, 1, 2000, 72000),
array(4, 3, 4000, 108000),
array(8, 1, 2000, 72000),
array(16, 9, 4000, 108000),
array(32, 25, 8000, 144000),
array(64, 9, 3000, 108000),
array(128, 73, 6000, 144000),
array(256, 201, 12000, 180000),
array(512, 0, 1000, 36000),
array(1024, 512, 2000, 72000),
array(2048, 1536, 4000, 108000),
array(4096, 512, 2000, 72000),
array(8192, 4608, 4000, 108000),
array(16384, 12800, 8000, 144000),
array(32768, 4608, 3000, 108000),
array(65536, 37376, 6000, 144000),
array(131072, 102912, 12000, 180000),
array(262144, 512, 1000, 54000),
array(524288, 262656, 2000, 90000),
array(1048576, 786944, 4000, 126000),
array(2097152, 262656, 2000, 90000),
array(4194304, 2359808, 4000, 126000),
array(8388608, 6554112, 8000, 162000),
array(16777216, 2359808, 3000, 126000),
array(33554432, 19137024, 6000, 162000),
array(67108864, 52691456, 12000, 198000)
),
//Défense 2
array(
array(1, 0, 2000, 72000),
array(2, 1, 4000, 144000),
array(4, 3, 6000, 216000),
array(8, 0, 2000, 72000),
array(16, 8, 4000, 144000),
array(32, 24, 6000, 216000),
array(64, 27, 8000, 288000)
),
//Projets expérimentaux
array(
array(1, 0, 2000, 36000),
array(2, 1, 4000, 72000),
array(4, 2, 4000, 108000),
array(8, 4, 6000, 144000),
array(16, 8, 6000, 144000),
array(32, 8, 8000, 180000),
array(64, 32, 10000, 216000),
array(128, 64, 10000, 234000),
array(256, 128, 12000, 288000),
array(512, 256, 14000, 324000),
array(1024, 64, 14000, 342000),
array(2048, 256, 16000, 360000),
array(4096, 576, 18000, 396000),
array(8192, 4096, 20000, 432000),
array(16384, 8192, 22000, 504000)
),
//Technologie expansion
array(
array(1, 0, 4000, 54000),
array(2, 1, 6000, 72000),
array(4, 3, 8000, 90000),
array(8, 7, 10000, 108000),
array(16, 15, 12000, 126000),
array(32, 31, 14000, 144000),
array(64, 63, 16000, 162000),
array(128, 127, 18000, 180000),
array(256, 255, 20000, 198000),
array(512, 511, 22000, 216000),
array(1024, 1023, 24000, 234000),
array(2048, 2047, 26000, 252000),
array(4096, 4095, 28000, 270000),
array(8192, 8191, 30000, 288000),
array(16384, 16383, 32000, 306000),
array(32768, 32767, 34000, 324000),
array(65536, 65535, 36000, 342000),
array(131072, 131071, 38000, 360000)
)
);
//Armement
array(
array(1, 0, 1000, 36000),
array(2, 1, 2000, 72000),
array(4, 3, 4000, 108000),
array(8, 1, 1000, 54000),
array(16, 9, 2000, 90000),
array(32, 25, 4000, 126000),
array(64, 9, 2000, 72000),
array(128, 73, 4000, 108000),
array(256, 201, 8000, 144000),
array(512, 73, 2000, 90000),
array(1024, 585, 4000, 126000),
array(2048, 1609, 8000, 162000),
array(4096, 1, 3000, 108000),
array(8192, 4097, 6000, 144000),
array(16384, 12289, 12000, 180000),
array(32768, 4097, 3000, 126000),
array(65536, 36865, 6000, 162000),
array(131072, 102401, 12000, 198000)
),
//Défense
array(
array(1, 0, 1000, 36000),
array(2, 1, 2000, 72000),
array(4, 3, 4000, 108000),
array(8, 1, 2000, 72000),
array(16, 9, 4000, 108000),
array(32, 25, 8000, 144000),
array(64, 9, 3000, 108000),
array(128, 73, 6000, 144000),
array(256, 201, 12000, 180000),
array(512, 0, 1000, 36000),
array(1024, 512, 2000, 72000),
array(2048, 1536, 4000, 108000),
array(4096, 512, 2000, 72000),
array(8192, 4608, 4000, 108000),
array(16384, 12800, 8000, 144000),
array(32768, 4608, 3000, 108000),
array(65536, 37376, 6000, 144000),
array(131072, 102912, 12000, 180000),
array(262144, 512, 1000, 54000),
array(524288, 262656, 2000, 90000),
array(1048576, 786944, 4000, 126000),
array(2097152, 262656, 2000, 90000),
array(4194304, 2359808, 4000, 126000),
array(8388608, 6554112, 8000, 162000),
array(16777216, 2359808, 3000, 126000),
array(33554432, 19137024, 6000, 162000),
array(67108864, 52691456, 12000, 198000)
),
//Défense 2
array(
array(1, 0, 2000, 72000),
array(2, 1, 4000, 144000),
array(4, 3, 6000, 216000),
array(8, 0, 2000, 72000),
array(16, 8, 4000, 144000),
array(32, 24, 6000, 216000),
array(64, 27, 8000, 288000)
),
//Projets expérimentaux
array(
array(1, 0, 2000, 36000),
array(2, 1, 4000, 72000),
array(4, 2, 4000, 108000),
array(8, 4, 6000, 144000),
array(16, 8, 6000, 144000),
array(32, 8, 8000, 180000),
array(64, 32, 10000, 216000),
array(128, 64, 10000, 234000),
array(256, 128, 12000, 288000),
array(512, 256, 14000, 324000),
array(1024, 64, 14000, 342000),
array(2048, 256, 16000, 360000),
array(4096, 576, 18000, 396000),
array(8192, 4096, 20000, 432000),
array(16384, 8192, 22000, 504000)
),
//Technologie expansion
array(
array(1, 0, 4000, 54000),
array(2, 1, 6000, 72000),
array(4, 3, 8000, 90000),
array(8, 7, 10000, 108000),
array(16, 15, 12000, 126000),
array(32, 31, 14000, 144000),
array(64, 63, 16000, 162000),
array(128, 127, 18000, 180000),
array(256, 255, 20000, 198000),
array(512, 511, 22000, 216000),
array(1024, 1023, 24000, 234000),
array(2048, 2047, 26000, 252000),
array(4096, 4095, 28000, 270000),
array(8192, 8191, 30000, 288000),
array(16384, 16383, 32000, 306000),
array(32768, 32767, 34000, 324000),
array(65536, 65535, 36000, 342000),
array(131072, 131071, 38000, 360000)
)
);
if ($retour == "metal") return 0;
elseif ($retour == "cristal") return 0;
elseif ($retour == "hydrogene") return 0;
elseif ($retour == "credits") return $technologies_donnees[$branche][$idTechnologie][2];
elseif ($retour == "temps") return $technologies_donnees[$branche][$idTechnologie][3]/VITESSE;
elseif ($retour == "needed") return $technologies_donnees[$branche][$idTechnologie][1];
elseif ($retour == "id") return $technologies_donnees[$branche][$idTechnologie][0];
elseif ($retour == "array") return array(0, 0, 0, $technologies_donnees[$branche][$idTechnologie][2], $technologies_donnees[$branche][$idTechnologie][3]/VITESSE);
}
static function metalTechnologie($branche, $idTechnologie, Planete $planete)
{
return Donnee::donneeTechnologie($branche, $idTechnologie, "metal", $planete);
}
static function cristalTechnologie($branche, $idTechnologie, Planete $planete)
{
return Donnee::donneeTechnologie($branche, $idTechnologie, "cristal", $planete);
}
static function hydrogeneTechnologie($branche, $idTechnologie, Planete $planete)
{
return Donnee::donneeTechnologie($branche, $idTechnologie, "hydrogene", $planete);
}
static function creditsTechnologie($branche, $idTechnologie, Planete $planete)
{
return Donnee::donneeTechnologie($branche, $idTechnologie, "credits", $planete);
}
static function tempsTechnologie($branche, $idTechnologie, Planete $planete)
{
return Donnee::donneeTechnologie($branche, $idTechnologie, "temps", $planete);
}
static function idTechnologie($branche, $idTechnologie, Planete $planete)
{
return Donnee::donneeTechnologie($branche, $idTechnologie, "id", $planete);
}
static function neededTechnologie($branche, $idTechnologie, Planete $planete)
{
$neededTechnologies = Donnee::donneeTechnologie($branche, $idTechnologie, "needed", $planete);
if (empty($neededTechnologies)) return true;
if (is_array($neededTechnologies))
{
//TODO prévoir le besoin de plus d'une technologie pour la validation, dans une autre branche, batiment (?) ...
die('TODO '.__LINE__.' in '.__FILE__);
}
else
{
if (((int)$planete->technologies[$branche]& $neededTechnologies) == $neededTechnologies)
return true;
else
return false;
}
}
if ($retour == "metal") {
return 0;
} elseif ($retour == "cristal") {
return 0;
} elseif ($retour == "hydrogene") {
return 0;
} elseif ($retour == "credits") {
return $technologies_donnees[$branche][$idTechnologie][2];
} elseif ($retour == "temps") {
return $technologies_donnees[$branche][$idTechnologie][3]/VITESSE;
} elseif ($retour == "needed") {
return $technologies_donnees[$branche][$idTechnologie][1];
} elseif ($retour == "id") {
return $technologies_donnees[$branche][$idTechnologie][0];
} elseif ($retour == "array") {
return array(0, 0, 0, $technologies_donnees[$branche][$idTechnologie][2], $technologies_donnees[$branche][$idTechnologie][3]/VITESSE);
}
}
?>
public static function metalTechnologie($branche, $idTechnologie, Planete $planete)
{
return Donnee::donneeTechnologie($branche, $idTechnologie, "metal", $planete);
}
public static function cristalTechnologie($branche, $idTechnologie, Planete $planete)
{
return Donnee::donneeTechnologie($branche, $idTechnologie, "cristal", $planete);
}
public static function hydrogeneTechnologie($branche, $idTechnologie, Planete $planete)
{
return Donnee::donneeTechnologie($branche, $idTechnologie, "hydrogene", $planete);
}
public static function creditsTechnologie($branche, $idTechnologie, Planete $planete)
{
return Donnee::donneeTechnologie($branche, $idTechnologie, "credits", $planete);
}
public static function tempsTechnologie($branche, $idTechnologie, Planete $planete)
{
return Donnee::donneeTechnologie($branche, $idTechnologie, "temps", $planete);
}
public static function idTechnologie($branche, $idTechnologie, Planete $planete)
{
return Donnee::donneeTechnologie($branche, $idTechnologie, "id", $planete);
}
public static function neededTechnologie($branche, $idTechnologie, Planete $planete)
{
$neededTechnologies = Donnee::donneeTechnologie($branche, $idTechnologie, "needed", $planete);
if (empty($neededTechnologies)) {
return true;
}
if (is_array($neededTechnologies)) {
//TODO prévoir le besoin de plus d'une technologie pour la validation, dans une autre branche, batiment (?) ...
die('TODO '.__LINE__.' in '.__FILE__);
} else {
if (((int)$planete->technologies[$branche]& $neededTechnologies) == $neededTechnologies) {
return true;
} else {
return false;
}
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -9,178 +9,166 @@
*
***************************************************************************/
class FlotteGroupee
{
var $id_flotte = 0,
$nom,
$end_planete,
$time_end,
$end_type,
$ret_planete,
$flottes = array(),
$mission,
$modifFlotte = array();
{
public $id_flotte = 0;
public $nom;
public $end_planete;
public $time_end;
public $end_type;
public $ret_planete;
public $flottes = array();
public $mission;
public $modifFlotte = array();
/**
* Constructeur
* @param int $id id de la flotte à importer
* @param bool $verrou Booléen disant si la classe doit obtenir préalablement un verrou pour la flotte.
*
* @return void
* @access public
*/
function __construct($id = 0, $verrou = true)
{
if (!empty($id))
{
global $table_flottes_preparation;
global $spatialVAR, $ressoVAR;
/**
* Constructeur
* @param int $id id de la flotte à importer
* @param bool $verrou Booléen disant si la classe doit obtenir préalablement un verrou pour la flotte.
*
* @return void
* @access public
*/
public function __construct($id = 0, $verrou = true)
{
if (!empty($id)) {
global $table_flottes_preparation;
global $spatialVAR, $ressoVAR;
$id = intval($id);
$bdd = new BDD();
$flotte = $bdd->unique_query("SELECT * FROM $table_flottes_preparation WHERE id = $id;");
$bdd->deconnexion();
$id = intval($id);
$bdd = new BDD();
$flotte = $bdd->unique_query("SELECT * FROM $table_flottes_preparation WHERE id = $id;");
$bdd->deconnexion();
if (!empty($flotte))
{
$this->id_flotte = $flotte["id"];
$this->nom = $flotte["nom"];
$this->end_planete = $flotte["end_planete"];
$this->end_type = $flotte["end_type"];
$this->time_end = $flotte["time_end"];
$this->mission = $flotte["mission"];
if (!empty($flotte)) {
$this->id_flotte = $flotte["id"];
$this->nom = $flotte["nom"];
$this->end_planete = $flotte["end_planete"];
$this->end_type = $flotte["end_type"];
$this->time_end = $flotte["time_end"];
$this->mission = $flotte["mission"];
if (empty($this->flottes)
$this->flottes = array();
else
$this->flottes = unserialize($flotte["flottes"]);
}
}
}
if (empty($this->flottes)) {
$this->flottes = array();
} else {
$this->flottes = unserialize($flotte["flottes"]);
}
}
}
}
function load_planete()
{
if (is_numeric($this->end_planete) && !empty($this->end_planete))
{
//On traite l'importation en fonction des types fornis
if ($this->end_type == 0 || $this->end_type == 1)
{
global $planete;
//Si la planète est la même que celle du joueur actuel, on l'utilise, sinon, on la crée
if (SURFACE == "planete" && $planete->id == $this->end_planete)
$this->end_planete = $planete;
else
$this->end_planete = new Planete($this->end_planete);
}
else
{
global $planete;
//Si la planète est la même que celle du joueur actuel, on l'utilise, sinon, on la crée
if (SURFACE == "asteroide" && $planete->id == $this->end_planete)
$this->end_planete = $planete;
else
$this->end_planete = new Asteroide($this->end_planete);
}
}
}
public function load_planete()
{
if (is_numeric($this->end_planete) && !empty($this->end_planete)) {
//On traite l'importation en fonction des types fornis
if ($this->end_type == 0 || $this->end_type == 1) {
global $planete;
//Si la planète est la même que celle du joueur actuel, on l'utilise, sinon, on la crée
if (SURFACE == "planete" && $planete->id == $this->end_planete) {
$this->end_planete = $planete;
} else {
$this->end_planete = new Planete($this->end_planete);
}
} else {
global $planete;
//Si la planète est la même que celle du joueur actuel, on l'utilise, sinon, on la crée
if (SURFACE == "asteroide" && $planete->id == $this->end_planete) {
$this->end_planete = $planete;
} else {
$this->end_planete = new Asteroide($this->end_planete);
}
}
}
}
function addFlotte($start_planete, $vitesse, $vaisseaux, $contenu_metal, $contenu_cristal, $contenu_hydrogene)
{
$this->flottes[] = array($start_planete->id_user, $start_planete->id, $vitesse, $vaisseaux, $contenu_metal, $contenu_cristal, $contenu_hydrogene);
addModifFlotte("flottes");
}
public function addFlotte($start_planete, $vitesse, $vaisseaux, $contenu_metal, $contenu_cristal, $contenu_hydrogene)
{
$this->flottes[] = array($start_planete->id_user, $start_planete->id, $vitesse, $vaisseaux, $contenu_metal, $contenu_cristal, $contenu_hydrogene);
addModifFlotte("flottes");
}
function lancer()
{
public function lancer()
{
}
}
public function addModifFlotte($modif)
{
if (!in_array($modif, $this->modifFlotte)) {
$this->modifFlotte[] = $modif;
}
}
function addModifFlotte($modif)
{
if (!in_array($modif, $this->modifFlotte))
$this->modifFlotte[] = $modif;
}
/**
* Destructeur
*
* @return void
* @access public
*/
public function __destruct()
{
global $table_flottes;
/**
* Destructeur
*
* @return void
* @access public
*/
function __destruct()
{
global $table_flottes;
if ($this->modifFlotte === "DELETE") {
$bdd = new BDD();
$bdd->query("DELETE FROM $table_flottes WHERE id = ".$this->id_flotte.";");
$bdd->deconnexion();
} else {
if (empty($this->id_flotte)) {
if ($this->modifFlotte == "INSERT") {
$out1 = '';
$out2 = '';
global $spatialVAR;
foreach ($this->vaisseaux as $key => $vais) {
$out1 .= ', '.$spatialVAR[$key];
$out2 .= ', '.$vais;
}
$sql = "INSERT INTO $table_flottes (id_user, mission, start_time, start_type, start_planete, end_time, end_type, 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_type."', '".$this->start_planete->id."', '".$this->end_time."', '".$this->end_type."', '".$this->end_planete."', '".$this->vitesse."', '".$this->contenu[0]."', '".$this->contenu[1]."', '".$this->contenu[2]."', '".$this->tactique."', '".$this->nom."', ".$this->nb_vais."$out2);";
if (DEBUG) {
echo $sql;
}
$bdd = new BDD();
$bdd->query($sql);
$bdd->deconnexion();
}
} elseif (isset($this->modifFlotte[0])) {
$out = array();
$bdd = new BDD();
foreach ($this->modifFlotte as $modif) {
if (!is_array($this->{$modif})) {
if (is_int($this->{$modif}) || is_float($this->{$modif})) {
$out[] .= $modif." = ".$this->{$modif};
} else {
$bdd->escape($this->{$modif});
$out[] .= $modif." = '".$this->{$modif}."'";
}
} else {
if ($modif == "contenu") {
$calc = "resso";
} elseif ($modif == "vaisseaux") {
$calc = "nomvaisn";
}
if ($this->modifFlotte === "DELETE")
{
$bdd = new BDD();
$bdd->query("DELETE FROM $table_flottes WHERE id = ".$this->id_flotte.";");
$bdd->deconnexion();
}
else
{
if (empty($this->id_flotte))
{
if ($this->modifFlotte == "INSERT")
{
$out1 = ''; $out2 = '';
global $spatialVAR;
foreach ($this->vaisseaux as $key => $vais)
{
$out1 .= ', '.$spatialVAR[$key];
$out2 .= ', '.$vais;
}
$sql = "INSERT INTO $table_flottes (id_user, mission, start_time, start_type, start_planete, end_time, end_type, 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_type."', '".$this->start_planete->id."', '".$this->end_time."', '".$this->end_type."', '".$this->end_planete."', '".$this->vitesse."', '".$this->contenu[0]."', '".$this->contenu[1]."', '".$this->contenu[2]."', '".$this->tactique."', '".$this->nom."', ".$this->nb_vais."$out2);";
if (DEBUG) echo $sql;
$bdd = new BDD();
$bdd->query($sql);
$bdd->deconnexion();
}
}
elseif(isset($this->modifFlotte[0]))
{
$out = array();
$bdd = new BDD();
foreach($this->modifFlotte as $modif)
{
if (!is_array($this->{$modif}))
{
if (is_int($this->{$modif}) || is_float($this->{$modif}))
$out[] .= $modif." = ".$this->{$modif};
else
{
$bdd->escape($this->{$modif});
$out[] .= $modif." = '".$this->{$modif}."'";
}
}
else
{
if ($modif == "contenu")
$calc = "resso";
elseif ($modif == "vaisseaux")
$calc = "nomvaisn";
if (!isset(${$calc.'VAR'})) {
global ${$calc.'VAR'};
}
if (!isset(${$calc.'VAR'}))
global ${$calc.'VAR'};
foreach (${$calc.'VAR'} as $key => $var) {
$bdd->escape($this->{$modif}[$key]);
$out[] = ${$calc.'VAR'}[$key]." = ".$this->{$modif}[$key];
}
}
}
foreach(${$calc.'VAR'} as $key => $var)
{
$bdd->escape($this->{$modif}[$key]);
$out[] = ${$calc.'VAR'}[$key]." = ".$this->{$modif}[$key];
}
}
}
if (!empty($out)) {
$sql = "UPDATE $table_flottes SET ".implode(', ', $out).", last = 0 WHERE id = ".$this->id_flotte.";";
if (DEBUG) {
var_dump($sql);
}
$bdd->query($sql);
}
if (!empty($out))
{
$sql = "UPDATE $table_flottes SET ".implode(', ', $out).", last = 0 WHERE id = ".$this->id_flotte.";";
if (DEBUG) var_dump($sql);
$bdd->query($sql);
}
$bdd->deconnexion();
}
}
}
}
?>
$bdd->deconnexion();
}
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -9,145 +9,140 @@
*
***************************************************************************/
class ExceptionHB extends Exception {
class ExceptionHB extends Exception
{
public function __construct($branche, $code = 0, $debug = true, $gerer = false)
{
if ($gerer) {
parent::__construct($branche, $code);
} else {
if (is_numeric($branche)) {
switch ($branche) {
case 1:
switch ($code) {
case 0:
$message = "La planète est pleine, vous ne pouvez plus construire de batiment dessus !";
break;
case 1:
$message = "La file d'attente est pleine, vous ne pouvez pas rajouter plus de batiments.";
break;
case 2:
$message = "Vous n'avez pas les bâtiments et/ou technologies nécessaires pour construire ce bâtiment.";
break;
case 3:
$message = "Le bâtiment dont vous demandez la construction est actuellement en démolition. Annulez la démolition pour lui ajouter l'aggrandir.";
break;
case 4:
$message = "Vous n'avez pas les ressources nécessaire pour construire ce bâtiment !";
break;
public function __construct($branche, $code = 0, $debug = true, $gerer = false) {
if ($gerer)
parent::__construct($branche, $code);
else
{
if (is_numeric($branche))
{
switch($branche)
{
case 1:
switch($code)
{
case 0:
$message = "La planète est pleine, vous ne pouvez plus construire de batiment dessus !";
break;
case 1:
$message = "La file d'attente est pleine, vous ne pouvez pas rajouter plus de batiments.";
break;
case 2:
$message = "Vous n'avez pas les bâtiments et/ou technologies nécessaires pour construire ce bâtiment.";
break;
case 3:
$message = "Le bâtiment dont vous demandez la construction est actuellement en démolition. Annulez la démolition pour lui ajouter l'aggrandir.";
break;
case 4:
$message = "Vous n'avez pas les ressources nécessaire pour construire ce bâtiment !";
break;
case 5:
$message = "Impossible d'annuler la construction de ce bâtiment, il n'a pas été trouvé dans la file !";
break;
case 5:
$message = "Impossible d'annuler la construction de ce bâtiment, il n'a pas été trouvé dans la file !";
break;
case 6:
$message = "Vous ne pouvez pas démolir ce batiment, il n'est pas encore construit !";
break;
case 7:
$message = "Le bâtiment dont vous demandez la démolition est actuellement en travaux. Annulez les travaux en cours pour pouvoir le démolir.";
break;
}
break;
case 2:
switch ($code) {
case 0:
$message = "Cette technologie est déjà en file d'attente, soyez patient !";
break;
case 1:
$message = "La file d'attente est pleine, vous ne pouvez pas rajouter plus de technologies.";
break;
case 2:
$message = "Vous n'avez pas les bâtiments et/ou technologies nécessaires pour rechercher cette technologie.";
break;
case 3:
$message = "Vous possédez déjà cette technologie !";
break;
case 4:
$message = "Vous n'avez pas les crédits ou ressources nécessaires pour rechercher cette technologie !";
break;
case 6:
$message = "Vous ne pouvez pas démolir ce batiment, il n'est pas encore construit !";
break;
case 7:
$message = "Le bâtiment dont vous demandez la démolition est actuellement en travaux. Annulez les travaux en cours pour pouvoir le démolir.";
break;
}
break;
case 2:
switch($code)
{
case 0:
$message = "Cette technologie est déjà en file d'attente, soyez patient !";
break;
case 1:
$message = "La file d'attente est pleine, vous ne pouvez pas rajouter plus de technologies.";
break;
case 2:
$message = "Vous n'avez pas les bâtiments et/ou technologies nécessaires pour rechercher cette technologie.";
break;
case 3:
$message = "Vous possédez déjà cette technologie !";
break;
case 4:
$message = "Vous n'avez pas les crédits ou ressources nécessaires pour rechercher cette technologie !";
break;
case 5:
$message = "Impossible d'annuler la recherche de cette technologie, elle n'a pas été trouvée dans la file !";
break;
}
break;
case 3:
switch ($code) {
case 1:
$message = "La file d'attente est pleine, vous ne pouvez pas rajouter plus d'unités.";
break;
case 2:
$message = "Vous n'avez pas les bâtiments et/ou technologies nécessaires pour entraîner ces unités.";
break;
case 3:
$message = "L'unité dont vous demandez l'entraînement est actuellement en démentellement. Annulez le démentellement pour l'entraîner de nouveau.";
break;
case 4:
$message = "Vous n'avez pas les ressources nécessaire pour entraîner cette unité !";
break;
case 5:
$message = "Impossible d'annuler la recherche de cette technologie, elle n'a pas été trouvée dans la file !";
break;
}
break;
case 3:
switch($code)
{
case 1:
$message = "La file d'attente est pleine, vous ne pouvez pas rajouter plus d'unités.";
break;
case 2:
$message = "Vous n'avez pas les bâtiments et/ou technologies nécessaires pour entraîner ces unités.";
break;
case 3:
$message = "L'unité dont vous demandez l'entraînement est actuellement en démentellement. Annulez le démentellement pour l'entraîner de nouveau.";
break;
case 4:
$message = "Vous n'avez pas les ressources nécessaire pour entraîner cette unité !";
break;
case 5:
$message = "Impossible d'annuler l'entraînement de cette unité, elle n'a pas été trouvé dans la file !";
break;
case 5:
$message = "Impossible d'annuler l'entraînement de cette unité, elle n'a pas été trouvé dans la file !";
break;
case 6:
$message = "Vous ne pouvez pas démenteler autant d'unités !";
break;
case 7:
$message = "L'unité dont vous demandez le démentellement est actuellement en entraînement. Annulez l'entraînement en cours pour pouvoir la démenteller.";
break;
case 6:
$message = "Vous ne pouvez pas démenteler autant d'unités !";
break;
case 7:
$message = "L'unité dont vous demandez le démentellement est actuellement en entraînement. Annulez l'entraînement en cours pour pouvoir la démenteller.";
break;
case 8:
$message = "Dépassement de capacité.<br />Vous ne pouvez pas demander la construction d'autant d'unités en même temps.";
break;
}
break;
case 4:
switch ($code) {
case 1:
$message = "La file d'attente est pleine, vous ne pouvez pas rajouter plus de recherches.";
break;
case 2:
$message = "Vous n'avez pas les bâtiments et/ou technologies nécessaires pour rechercher cette technologie.";
break;
case 4:
$message = "Vous n'avez pas les ressources nécessaire pour rechercher cette technologie !";
break;
case 8:
$message = "Dépassement de capacité.<br />Vous ne pouvez pas demander la construction d'autant d'unités en même temps.";
break;
}
break;
case 4:
switch($code)
{
case 1:
$message = "La file d'attente est pleine, vous ne pouvez pas rajouter plus de recherches.";
break;
case 2:
$message = "Vous n'avez pas les bâtiments et/ou technologies nécessaires pour rechercher cette technologie.";
break;
case 4:
$message = "Vous n'avez pas les ressources nécessaire pour rechercher cette technologie !";
break;
case 5:
$message = "Impossible d'annuler la recherche de cette technologie, elle n'a pas été trouvé dans la file !";
break;
case 5:
$message = "Impossible d'annuler la recherche de cette technologie, elle n'a pas été trouvé dans la file !";
break;
case 6:
$message = "Il n'est pas possible d'annuler une technologie connue";
break;
case 7:
$message = "Vous recherchez déjà cette technologie !";
break;
}
break;
}
} else {
$message = $branche;
}
case 6:
$message = "Il n'est pas possible d'annuler une technologie connue";
break;
case 7:
$message = "Vous recherchez déjà cette technologie !";
break;
}
break;
}
}
else
$message = $branche;
if ($debug || empty($message)) {
$message = "Erreur #".intval($branche)."/".$code." :<br />".$message;
}
if ($debug || empty($message))
$message = "Erreur #".intval($branche)."/".$code." :<br />".$message;
global $template, $page;
if (!empty($page))
$template->assign('page', $page);
$template->assign('message', $message);
$template->assign('couleur', 'red');
$template->display('game/erreur.tpl');
exit;
}
}
global $template, $page;
if (!empty($page)) {
$template->assign('page', $page);
}
$template->assign('message', $message);
$template->assign('couleur', 'red');
$template->display('game/erreur.tpl');
exit;
}
}
}
?>

File diff suppressed because it is too large Load diff

View file

@ -5,32 +5,30 @@
*/
class Groupe
{
var $contenu = array(); //Tableau contenant les vaisseaux de l'utilisateur
var $caracteristiques = array();
var $example = array(
array("somme boucliers", "somme pv", "nbVaisseauxInitiaux")
);
var $user; //Classe donnant des informations sur l'utilisateur de la flotte ou l'ID de l'utilisateur
var $camp = 0; //Camp du groupe
var $timestamp = 0; //TImestamp de la dernière attaque
var $actions = array(); //Tableau des actions faite ou à faire
var $action_encours = 0;
public $contenu = array(); //Tableau contenant les vaisseaux de l'utilisateur
public $caracteristiques = array();
public $example = array(
array("somme boucliers", "somme pv", "nbVaisseauxInitiaux")
);
public $user; //Classe donnant des informations sur l'utilisateur de la flotte ou l'ID de l'utilisateur
public $camp = 0; //Camp du groupe
public $timestamp = 0; //TImestamp de la dernière attaque
public $actions = array(); //Tableau des actions faite ou à faire
public $action_encours = 0;
/**
* Constructor
*/
function __construct()
{
/**
* Constructor
*/
public function __construct()
{
}
}
function regenereBoucliers()
{
foreach ($this->caracteristiques as $caracteristique)
{
if ($this->actions[$action_encours][0] == 2)
$
}
}
public function regenereBoucliers()
{
// foreach ($this->caracteristiques as $caracteristique)
// {
// if ($this->actions[$action_encours][0] == 2)
// $
// }
}
}
?>

View file

@ -20,4 +20,3 @@ $PHPMAILER_LANG["connect_host"] = 'Erreur SMTP: Impossible de se connecter au se
$PHPMAILER_LANG["file_access"] = 'Accès au fichier impossible: ';
$PHPMAILER_LANG["file_open"] = 'File Error: Ne peut ouvrir le fichier: ';
$PHPMAILER_LANG["encoding"] = 'Type d\'encodage inconnu : ';
?>

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -7,397 +7,387 @@
*/
class Rapport
{
var $type = 0;
var $var = array();
var $utilA = 0;
var $utilB = 0;
var $timestamp = 0;
public $type = 0;
public $var = array();
public $utilA = 0;
public $utilB = 0;
public $timestamp = 0;
var $titreA = "";
var $titreB = "";
var $rapportA = "";
var $rapportB = "";
public $titreA = "";
public $titreB = "";
public $rapportA = "";
public $rapportB = "";
/**
* Constructor
* @access protected
*/
function Rapport($type, $utilA, $utilB, $time)
{
$this->type = $type;
$this->utilA = $utilA;
$this->utilB = $utilB;
$this->timestamp = $time;
}
/**
* Constructor
* @access protected
*/
public function Rapport($type, $utilA, $utilB, $time)
{
$this->type = $type;
$this->utilA = $utilA;
$this->utilB = $utilB;
$this->timestamp = $time;
}
function addInfo($info, $id)
{
$this->var[$id] = $info;
}
public function addInfo($info, $id)
{
$this->var[$id] = $info;
}
function sendRapport()
{
if (!empty($this->utilA) && !empty($this->rapportA))
send_mp($this->utilA->id_user, $this->titreA, $this->rapportA, $this->timestamp);
if (!empty($this->utilB) && !empty($this->rapportB))
send_mp($this->utilB->id_user, $this->titreB, $this->rapportB, $this->timestamp);
}
public function sendRapport()
{
if (!empty($this->utilA) && !empty($this->rapportA)) {
send_mp($this->utilA->id_user, $this->titreA, $this->rapportA, $this->timestamp);
}
if (!empty($this->utilB) && !empty($this->rapportB)) {
send_mp($this->utilB->id_user, $this->titreB, $this->rapportB, $this->timestamp);
}
}
function send()
{
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();
elseif ($this->type == '7')
$this->sendAlliance2();
}
public function send()
{
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();
} elseif ($this->type == '7') {
$this->sendAlliance2();
}
}
function sendEspionnage()
{
global $LANG;
public function sendEspionnage()
{
global $LANG;
//Différentiation entre les planètes et les astéroides
if (!isset($this->var[0]->nom_planete))
{
$this->titreA = "Rapport d'espionnage de ".$this->var[0]->nom_asteroide." [".$this->var[0]->galaxie.":".$this->var[0]->ss.":A".$this->var[0]->position."]";
$this->rapportA = "<strong>Espionnage de ".$this->var[0]->pseudo." sur ".$this->var[0]->nom_asteroide."[".$this->var[0]->galaxie.":".$this->var[0]->ss.":A".$this->var[0]->position."]</strong><br /><br />";
}
else
{
$this->titreA = "Rapport d'espionnage de ".$this->var[0]->nom_planete." [".$this->var[0]->galaxie.":".$this->var[0]->ss.":".$this->var[0]->position."]";
$this->rapportA = "<strong>Espionnage de ".$this->var[0]->pseudo." sur ".$this->var[0]->nom_planete."[".$this->var[0]->galaxie.":".$this->var[0]->ss.":".$this->var[0]->position."]</strong><br /><br />";
}
//Différentiation entre les planètes et les astéroides
if (!isset($this->var[0]->nom_planete)) {
$this->titreA = "Rapport d'espionnage de ".$this->var[0]->nom_asteroide." [".$this->var[0]->galaxie.":".$this->var[0]->ss.":A".$this->var[0]->position."]";
$this->rapportA = "<strong>Espionnage de ".$this->var[0]->pseudo." sur ".$this->var[0]->nom_asteroide."[".$this->var[0]->galaxie.":".$this->var[0]->ss.":A".$this->var[0]->position."]</strong><br /><br />";
} else {
$this->titreA = "Rapport d'espionnage de ".$this->var[0]->nom_planete." [".$this->var[0]->galaxie.":".$this->var[0]->ss.":".$this->var[0]->position."]";
$this->rapportA = "<strong>Espionnage de ".$this->var[0]->pseudo." sur ".$this->var[0]->nom_planete."[".$this->var[0]->galaxie.":".$this->var[0]->ss.":".$this->var[0]->position."]</strong><br /><br />";
}
if ($this->var[2] < 1)
$this->rapportA .= "<em>Nos sondes n'ont pas pu récolter d'informations sur cette planète.</em>";
else {
//Ressources
if ($this->var[2] > 1)
$this->rapportA .= "<table style=\"margin: auto;\"><tr><th colspan=\"2\">Ressources sur la planète :</th></tr><tr><td>".$LANG[$this->var[0]->race]["ressources"]["noms"]["metal"]." :</td><td>".$this->var[0]->metal."</td></tr><tr><td>".$LANG[$this->var[0]->race]["ressources"]["noms"]["cristal"]." :</td><td>".$this->var[0]->cristal."</td></tr><tr><td>".$LANG[$this->var[0]->race]["ressources"]["noms"]["hydrogene"]." :</td><td>".$this->var[0]->hydrogene."</td></tr></table><br />";
if ($this->var[2] < 1) {
$this->rapportA .= "<em>Nos sondes n'ont pas pu récolter d'informations sur cette planète.</em>";
} else {
//Ressources
if ($this->var[2] > 1) {
$this->rapportA .= "<table style=\"margin: auto;\"><tr><th colspan=\"2\">Ressources sur la planète :</th></tr><tr><td>".$LANG[$this->var[0]->race]["ressources"]["noms"]["metal"]." :</td><td>".$this->var[0]->metal."</td></tr><tr><td>".$LANG[$this->var[0]->race]["ressources"]["noms"]["cristal"]." :</td><td>".$this->var[0]->cristal."</td></tr><tr><td>".$LANG[$this->var[0]->race]["ressources"]["noms"]["hydrogene"]." :</td><td>".$this->var[0]->hydrogene."</td></tr></table><br />";
}
//Bâtiments
if ($this->var[2] > 2)
{
$this->rapportA .= "<table style=\"margin: auto;\"><tr><th>Niveau</th><th>B&acirc;timent</th></tr>";
foreach ($this->var[0]->batiments as $key => $batiment)
{
$this->rapportA .= "<tr><td>".rand($batiment * (1 - $this->var[1]), $batiment * (1 + $this->var[1]))."</td><td>".$LANG[$this->var[0]->race]["batiments"]["noms_sing"][$key]."</td></tr>";
}
$this->rapportA .= "</table><br />";
}
//Bâtiments
if ($this->var[2] > 2) {
$this->rapportA .= "<table style=\"margin: auto;\"><tr><th>Niveau</th><th>B&acirc;timent</th></tr>";
foreach ($this->var[0]->batiments as $key => $batiment) {
$this->rapportA .= "<tr><td>".rand($batiment * (1 - $this->var[1]), $batiment * (1 + $this->var[1]))."</td><td>".$LANG[$this->var[0]->race]["batiments"]["noms_sing"][$key]."</td></tr>";
}
$this->rapportA .= "</table><br />";
}
//Flottes en orbite
if ($this->var[2] > 3)
{
//Flottes en orbite
if ($this->var[2] > 3) {
}
}
//Flottes au sol
if ($this->var[2] > 5) {
$this->rapportA .= "<table style=\"margin: auto;\"><tr><th>Nombre</th><th>Vaisseaux</th></tr>";
foreach ($this->var[0]->vaisseaux as $key => $vaisseau) {
$this->rapportA .= "<tr><td>".rand($vaisseau * (1 - $this->var[1]), $vaisseau * (1 + $this->var[1]))."</td><td>".$LANG[$this->var[0]->race]["vaisseaux"]["noms_sing"][$key]."</td></tr>";
}
$this->rapportA .= "</table><br />";
}
//Flottes au sol
if ($this->var[2] > 5)
{
$this->rapportA .= "<table style=\"margin: auto;\"><tr><th>Nombre</th><th>Vaisseaux</th></tr>";
foreach ($this->var[0]->vaisseaux as $key => $vaisseau)
{
$this->rapportA .= "<tr><td>".rand($vaisseau * (1 - $this->var[1]), $vaisseau * (1 + $this->var[1]))."</td><td>".$LANG[$this->var[0]->race]["vaisseaux"]["noms_sing"][$key]."</td></tr>";
}
$this->rapportA .= "</table><br />";
}
//Défenses
if ($this->var[2] > 4) {
$this->rapportA .= "<table style=\"margin: auto;\"><tr><th>Nombre</th><th>Défenses</th></tr>";
foreach ($this->var[0]->terrestres as $key => $unite) {
if (!dTerrestre::type($key)) {
$this->rapportA .= "<tr><td>".rand($unite * (1 - $this->var[1]), $unite * (1 + $this->var[1]))."</td><td>".$LANG[$this->var[0]->race]["terrestre"]["noms_sing"][$key]."</td></tr>";
}
}
$this->rapportA .= "</table><br />";
}
}
//Défenses
if ($this->var[2] > 4)
{
$this->rapportA .= "<table style=\"margin: auto;\"><tr><th>Nombre</th><th>Défenses</th></tr>";
foreach ($this->var[0]->terrestres as $key => $unite)
{
if (!dTerrestre::type($key)) $this->rapportA .= "<tr><td>".rand($unite * (1 - $this->var[1]), $unite * (1 + $this->var[1]))."</td><td>".$LANG[$this->var[0]->race]["terrestre"]["noms_sing"][$key]."</td></tr>";
}
$this->rapportA .= "</table><br />";
}
}
if ($this->var[3] >= 1) {
$this->titreB = "Rapport de contre-espionnage";
if (!isset($this->var[0]->nom_planete)) {
$this->rapportB = "Nous venons d'apprendre que notre planète : ".$this->var[0]->nom_asteroide."[".$this->var[0]->galaxie.":".$this->var[0]->ss.":A] a été la cible d'un espionnage de la part de ".$this->utilA->pseudo;
} else {
$this->rapportB = "Nous venons d'apprendre que notre planète : ".$this->var[0]->nom_planete."[".$this->var[0]->galaxie.":".$this->var[0]->ss.":".$this->var[0]->position."] a été la cible d'un espionnage de la part de ".$this->utilA->pseudo;
}
}
$this->rapportA = $this->rapportA;
}
if ($this->var[3] >= 1)
{
$this->titreB = "Rapport de contre-espionnage";
if (!isset($this->var[0]->nom_planete))
$this->rapportB = "Nous venons d'apprendre que notre planète : ".$this->var[0]->nom_asteroide."[".$this->var[0]->galaxie.":".$this->var[0]->ss.":A] a été la cible d'un espionnage de la part de ".$this->utilA->pseudo;
else
$this->rapportB = "Nous venons d'apprendre que notre planète : ".$this->var[0]->nom_planete."[".$this->var[0]->galaxie.":".$this->var[0]->ss.":".$this->var[0]->position."] a été la cible d'un espionnage de la part de ".$this->utilA->pseudo;
}
$this->rapportA = $this->rapportA;
}
public function sendTransport()
{
global $LANG;
if (!isset($this->var[0]->nom_planete)) {
$titre = 'Transport vers '.$this->var[0]->nom_asteroide.' ['.$this->var[0]->galaxie.':'.$this->var[0]->ss.':A]';
$this->rapportA = 'Vos vaisseaux ont déposé '.$this->var[1][0].' de '.$LANG[$this->utilA->race]["ressources"]["noms"]["metal"].', '.$this->var[1][1].' de '.$LANG[$this->utilA->race]["ressources"]["noms"]["cristal"].' et '.$this->var[1][2].' d\''.$LANG[$this->utilA->race]["ressources"]["noms"]["hydrogene"].' sur '.$this->var[0]->nom_asteroide.'['.$this->var[0]->galaxie.':'.$this->var[0]->ss.':A]</b><br /><br />';
$this->rapportB = 'Les vaisseaux de '.$this->utilA->pseudo.' ont déposé '.$this->var[1][0].' de '.$LANG[$this->utilB->race]["ressources"]["noms"]["metal"].', '.$this->var[1][1].' de '.$LANG[$this->utilB->race]["ressources"]["noms"]["cristal"].' et '.$this->var[1][2].' d\''.$LANG[$this->utilB->race]["ressources"]["noms"]["hydrogene"].' sur '.$this->var[0]->nom_asteroide.'['.$this->var[0]->galaxie.':'.$this->var[0]->ss.':A]</b><br /><br />';
} else {
$titre = 'Transport vers '.$this->var[0]->nom_planete.' ['.$this->var[0]->galaxie.':'.$this->var[0]->ss.':'.$this->var[0]->position.']';
$this->rapportA = 'Vos vaisseaux ont déposé '.$this->var[1][0].' de '.$LANG[$this->utilA->race]["ressources"]["noms"]["metal"].', '.$this->var[1][1].' de '.$LANG[$this->utilA->race]["ressources"]["noms"]["cristal"].' et '.$this->var[1][2].' d\''.$LANG[$this->utilA->race]["ressources"]["noms"]["hydrogene"].' sur '.$this->var[0]->nom_planete.'['.$this->var[0]->galaxie.':'.$this->var[0]->ss.':'.$this->var[0]->position.']</b><br /><br />';
$this->rapportB = 'Les vaisseaux de '.$this->utilA->pseudo.' ont déposé '.$this->var[1][0].' de '.$LANG[$this->utilB->race]["ressources"]["noms"]["metal"].', '.$this->var[1][1].' de '.$LANG[$this->utilB->race]["ressources"]["noms"]["cristal"].' et '.$this->var[1][2].' d\''.$LANG[$this->utilB->race]["ressources"]["noms"]["hydrogene"].' sur '.$this->var[0]->nom_planete.'['.$this->var[0]->galaxie.':'.$this->var[0]->ss.':'.$this->var[0]->position.']</b><br /><br />';
}
function sendTransport()
{
global $LANG;
if (!isset($this->var[0]->nom_planete))
{
$titre = 'Transport vers '.$this->var[0]->nom_asteroide.' ['.$this->var[0]->galaxie.':'.$this->var[0]->ss.':A]';
$this->rapportA = 'Vos vaisseaux ont déposé '.$this->var[1][0].' de '.$LANG[$this->utilA->race]["ressources"]["noms"]["metal"].', '.$this->var[1][1].' de '.$LANG[$this->utilA->race]["ressources"]["noms"]["cristal"].' et '.$this->var[1][2].' d\''.$LANG[$this->utilA->race]["ressources"]["noms"]["hydrogene"].' sur '.$this->var[0]->nom_asteroide.'['.$this->var[0]->galaxie.':'.$this->var[0]->ss.':A]</b><br /><br />';
$this->rapportB = 'Les vaisseaux de '.$this->utilA->pseudo.' ont déposé '.$this->var[1][0].' de '.$LANG[$this->utilB->race]["ressources"]["noms"]["metal"].', '.$this->var[1][1].' de '.$LANG[$this->utilB->race]["ressources"]["noms"]["cristal"].' et '.$this->var[1][2].' d\''.$LANG[$this->utilB->race]["ressources"]["noms"]["hydrogene"].' sur '.$this->var[0]->nom_asteroide.'['.$this->var[0]->galaxie.':'.$this->var[0]->ss.':A]</b><br /><br />';
}
else
{
$titre = 'Transport vers '.$this->var[0]->nom_planete.' ['.$this->var[0]->galaxie.':'.$this->var[0]->ss.':'.$this->var[0]->position.']';
$this->rapportA = 'Vos vaisseaux ont déposé '.$this->var[1][0].' de '.$LANG[$this->utilA->race]["ressources"]["noms"]["metal"].', '.$this->var[1][1].' de '.$LANG[$this->utilA->race]["ressources"]["noms"]["cristal"].' et '.$this->var[1][2].' d\''.$LANG[$this->utilA->race]["ressources"]["noms"]["hydrogene"].' sur '.$this->var[0]->nom_planete.'['.$this->var[0]->galaxie.':'.$this->var[0]->ss.':'.$this->var[0]->position.']</b><br /><br />';
$this->rapportB = 'Les vaisseaux de '.$this->utilA->pseudo.' ont déposé '.$this->var[1][0].' de '.$LANG[$this->utilB->race]["ressources"]["noms"]["metal"].', '.$this->var[1][1].' de '.$LANG[$this->utilB->race]["ressources"]["noms"]["cristal"].' et '.$this->var[1][2].' d\''.$LANG[$this->utilB->race]["ressources"]["noms"]["hydrogene"].' sur '.$this->var[0]->nom_planete.'['.$this->var[0]->galaxie.':'.$this->var[0]->ss.':'.$this->var[0]->position.']</b><br /><br />';
$temps = $this->timestamp;
$db = new BDD();
$db->escape($titre);
$db->escape($this->rapportA);
$db->escape($this->rapportB);
}
$db->query("INSERT INTO ".$this->table." (destinataire, sujet, contenu, temps) VALUES(".$this->utilA->id_user.", '$titre', '$this->rapportA', '$temps');");
if ($this->utilA->id_user != $this->utilB->id_user) {
$db->query("INSERT INTO ".$this->table." (destinataire, sujet, contenu, temps) VALUES(".$this->utilB->id_user.", '$titre', '$this->rapportB', '$temps');");
}
$db->deconnexion();
}
$temps = $this->timestamp;
$db = new BDD();
$db->escape($titre);
$db->escape($this->rapportA);
$db->escape($this->rapportB);
public function sendColonisation()
{
$titre = 'Colonisation de ['.$this->var[0][0].':'.$this->var[0][1].':'.$this->var[0][2].']';
if (is_numeric($this->var[0][2])) {
if ($this->var[1]) {
$rapport = 'Votre vaisseau a atteint la planète ['.$this->var[0][0].':'.$this->var[0][1].':'.$this->var[0][2].'] et commence la colonisation.';
} else {
$rapport = 'Nous n\'avons pas pu coloniser la planète ['.$this->var[0][0].':'.$this->var[0][1].':'.$this->var[0][2].'] car lorsque nous sommes arrivé sur place, elle était déjà colonisée.';
}
} else {
if ($this->var[1]) {
$rapport = 'Votre vaisseau a atteint l\'astéroide ['.$this->var[0][0].':'.$this->var[0][1].':'.$this->var[0][2].'] et commence la colonisation.';
} else {
$rapport = 'Nous n\'avons pas pu coloniser la planète ['.$this->var[0][0].':'.$this->var[0][1].':'.$this->var[0][2].'] car lorsque nous sommes arrivé sur place, elle était déjà colonisée.';
}
}
$db->query("INSERT INTO ".$this->table." (destinataire, sujet, contenu, temps) VALUES(".$this->utilA->id_user.", '$titre', '$this->rapportA', '$temps');");
if ($this->utilA->id_user != $this->utilB->id_user) $db->query("INSERT INTO ".$this->table." (destinataire, sujet, contenu, temps) VALUES(".$this->utilB->id_user.", '$titre', '$this->rapportB', '$temps');");
$db->deconnexion();
}
$temps = $this->timestamp;
$db = new BDD();
$db->escape($titre);
$db->escape($rapport);
$db->query("INSERT INTO ".$this->table." (destinataire, sujet, contenu, temps) VALUES(".$this->utilA->id_user.", '$titre', '$rapport', '$temps');");
$db->deconnexion();
}
function sendColonisation()
{
$titre = 'Colonisation de ['.$this->var[0][0].':'.$this->var[0][1].':'.$this->var[0][2].']';
if (is_numeric($this->var[0][2]))
{
if ($this->var[1])
$rapport = 'Votre vaisseau a atteint la planète ['.$this->var[0][0].':'.$this->var[0][1].':'.$this->var[0][2].'] et commence la colonisation.';
else
$rapport = 'Nous n\'avons pas pu coloniser la planète ['.$this->var[0][0].':'.$this->var[0][1].':'.$this->var[0][2].'] car lorsque nous sommes arrivé sur place, elle était déjà colonisée.';
}
else
{
if ($this->var[1])
$rapport = 'Votre vaisseau a atteint l\'astéroide ['.$this->var[0][0].':'.$this->var[0][1].':'.$this->var[0][2].'] et commence la colonisation.';
else
$rapport = 'Nous n\'avons pas pu coloniser la planète ['.$this->var[0][0].':'.$this->var[0][1].':'.$this->var[0][2].'] car lorsque nous sommes arrivé sur place, elle était déjà colonisée.';
}
public function sendRecyclage()
{
global $LANG;
if (!isset($this->var[0]->nom_planete)) {
$titre = 'Recyclage de '.$this->var[0]->nom_asteroide.' ['.$this->var[0]->galaxie.':'.$this->var[0]->ss.':A]';
$rapport = 'Vos vaisseaux récoltent '.$this->var[1][0].' de '.$LANG[$this->utilA->race]["ressources"]["noms"]["metal"].' et '.$this->var[1][1].' de '.$LANG[$this->utilA->race]["ressources"]["noms"]["cristal"].' sur '.$this->var[0]->nom_asteroide.'['.$this->var[0]->galaxie.':'.$this->var[0]->ss.':A]</b><br /><br />';
} else {
$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 '.$LANG[$this->utilA->race]["ressources"]["noms"]["metal"].' et '.$this->var[1][1].' de '.$LANG[$this->utilA->race]["ressources"]["noms"]["cristal"].' sur '.$this->var[0]->nom_planete.'['.$this->var[0]->galaxie.':'.$this->var[0]->ss.':'.$this->var[0]->position.']</b><br /><br />';
}
$temps = $this->timestamp;
$db = new BDD();
$db->escape($titre);
$db->escape($rapport);
$db->query("INSERT INTO ".$this->table." (destinataire, sujet, contenu, temps) VALUES(".$this->utilA->id_user.", '$titre', '$rapport', '$temps');");
$db->deconnexion();
}
$temps = $this->timestamp;
function sendRecyclage()
{
global $LANG;
if (!isset($this->var[0]->nom_planete))
{
$titre = 'Recyclage de '.$this->var[0]->nom_asteroide.' ['.$this->var[0]->galaxie.':'.$this->var[0]->ss.':A]';
$rapport = 'Vos vaisseaux récoltent '.$this->var[1][0].' de '.$LANG[$this->utilA->race]["ressources"]["noms"]["metal"].' et '.$this->var[1][1].' de '.$LANG[$this->utilA->race]["ressources"]["noms"]["cristal"].' sur '.$this->var[0]->nom_asteroide.'['.$this->var[0]->galaxie.':'.$this->var[0]->ss.':A]</b><br /><br />';
}
else
{
$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 '.$LANG[$this->utilA->race]["ressources"]["noms"]["metal"].' et '.$this->var[1][1].' de '.$LANG[$this->utilA->race]["ressources"]["noms"]["cristal"].' sur '.$this->var[0]->nom_planete.'['.$this->var[0]->galaxie.':'.$this->var[0]->ss.':'.$this->var[0]->position.']</b><br /><br />';
}
$db = new BDD();
$db->escape($titre);
$db->escape($rapport);
$db->query("INSERT INTO ".$this->table." (destinataire, sujet, contenu, temps) VALUES(".$this->utilA->id_user.", '$titre', '$rapport', '$temps');");
$db->deconnexion();
}
$temps = $this->timestamp;
public function sendCombat()
{
include(_FCORE."../game/vars.php");
include_once(_FCORE."../game/function.php");
require_once(SMARTY_DIR."Smarty.class.php");
$db = new BDD();
$db->escape($titre);
$db->escape($rapport);
$db->query("INSERT INTO ".$this->table." (destinataire, sujet, contenu, temps) VALUES(".$this->utilA->id_user.", '$titre', '$rapport', '$temps');");
$db->deconnexion();
}
$this->rapportA = new Smarty();
$this->rapportB = new Smarty();
function sendCombat(){
include(_FCORE."../game/vars.php");
include_once(_FCORE."../game/function.php");
require_once(SMARTY_DIR."Smarty.class.php");
$this->rapportA->template_dir = _FCORE.'templates/templates/';
$this->rapportA->compile_dir = _FCORE.'templates/templates_c/';
$this->rapportA->config_dir = _FCORE.'templates/configs/';
$this->rapportA->cache_dir = _FCORE.'templates/cache/';
$this->rapportA = new Smarty();
$this->rapportB = new Smarty();
$this->rapportB->template_dir = _FCORE.'templates/templates/';
$this->rapportB->compile_dir = _FCORE.'templates/templates_c/';
$this->rapportB->config_dir = _FCORE.'templates/configs/';
$this->rapportB->cache_dir = _FCORE.'templates/cache/';
$this->rapportA->template_dir = _FCORE.'templates/templates/';
$this->rapportA->compile_dir = _FCORE.'templates/templates_c/';
$this->rapportA->config_dir = _FCORE.'templates/configs/';
$this->rapportA->cache_dir = _FCORE.'templates/cache/';
$this->var[4]['pseudo'] = trouvNom($this->var[4]['id_user']);
$this->var[5]['pseudo'] = trouvNom($this->var[5]['id_user']);
$this->rapportB->template_dir = _FCORE.'templates/templates/';
$this->rapportB->compile_dir = _FCORE.'templates/templates_c/';
$this->rapportB->config_dir = _FCORE.'templates/configs/';
$this->rapportB->cache_dir = _FCORE.'templates/cache/';
$this->rapportA->assign('tour', $this->var[3]);
$this->rapportA->assign('EN', $this->var[4]);
$this->rapportA->assign('flotte', $this->var[5]);
$this->rapportA->assign('vaisseaux1', $this->var[0]);
$this->rapportA->assign('vaisseaux2', $this->var[1]);
$this->rapportA->assign('defenses1', $this->var[2]);
$this->rapportA->assign('vaisseaux3', $this->var[7]);
$this->rapportA->assign('vaisseaux4', $this->var[8]);
$this->rapportA->assign('defenses2', $this->var[9]);
$this->var[4]['pseudo'] = trouvNom($this->var[4]['id_user']);
$this->var[5]['pseudo'] = trouvNom($this->var[5]['id_user']);
$this->rapportA->assign('termine', $this->var[6][0]);
$this->rapportA->assign('attaquantG', $this->var[6][1]);
$this->rapportA->assign('pillage', $this->var[11]);
$this->rapportA->assign('tour', $this->var[3]);
$this->rapportA->assign('EN', $this->var[4]);
$this->rapportA->assign('flotte', $this->var[5]);
$this->rapportA->assign('vaisseaux1', $this->var[0]);
$this->rapportA->assign('vaisseaux2', $this->var[1]);
$this->rapportA->assign('defenses1', $this->var[2]);
$this->rapportA->assign('vaisseaux3', $this->var[7]);
$this->rapportA->assign('vaisseaux4', $this->var[8]);
$this->rapportA->assign('defenses2', $this->var[9]);
$this->rapportA->assign('vaisBC', $nomvais_bc);
$this->rapportA->assign('vaisPV', $nomvais_pv);
$this->rapportA->assign('defBC', $defense_bc);
$this->rapportA->assign('defPV', $defense_pv);
$this->rapportA->assign('nextTour', $this->var[10]);
$this->rapportA->assign('termine', $this->var[6][0]);
$this->rapportA->assign('attaquantG', $this->var[6][1]);
$this->rapportA->assign('pillage', $this->var[11]);
$race = trouvInfo($this->utilA, 'race');
include(_FCORE."../game/noms.php");
$this->rapportA->assign('ressources', $ressourc);
$this->rapportA->assign('nomvaisAT', $nomvaisa);
$this->rapportA->assign('vaisBC', $nomvais_bc);
$this->rapportA->assign('vaisPV', $nomvais_pv);
$this->rapportA->assign('defBC', $defense_bc);
$this->rapportA->assign('defPV', $defense_pv);
$this->rapportA->assign('nextTour', $this->var[10]);
$race = trouvInfo($this->var[4]['id_user'], 'race');
include(_FCORE."../game/noms.php");
$this->rapportA->assign('nomvaisEN', $nomvaisa);
array_splice($nomterra, 0, 8);
$this->rapportA->assign('nomdefEN', $nomterra);
$race = trouvInfo($this->utilA, 'race');
include(_FCORE."../game/noms.php");
$this->rapportA->assign('ressources', $ressourc);
$this->rapportA->assign('nomvaisAT', $nomvaisa);
$race = trouvInfo($this->var[4]['id_user'], 'race');
include(_FCORE."../game/noms.php");
$this->rapportA->assign('nomvaisEN', $nomvaisa);
array_splice($nomterra, 0, 8);
$this->rapportA->assign('nomdefEN', $nomterra);
$this->rapportA = $this->rapportA->fetch('game/ATrapport_combat.tpl');
$this->rapportA = $this->rapportA->fetch('game/ATrapport_combat.tpl');
$this->rapportB->assign('tour', $this->var[3]);
$this->rapportB->assign('EN', $this->var[4]);
$this->rapportB->assign('flotte', $this->var[5]);
$this->rapportB->assign('vaisseaux1', $this->var[0]);
$this->rapportB->assign('vaisseaux2', $this->var[1]);
$this->rapportB->assign('defenses1', $this->var[2]);
$this->rapportB->assign('vaisseaux3', $this->var[7]);
$this->rapportB->assign('vaisseaux4', $this->var[8]);
$this->rapportB->assign('defenses2', $this->var[9]);
$this->rapportB->assign('tour', $this->var[3]);
$this->rapportB->assign('EN', $this->var[4]);
$this->rapportB->assign('flotte', $this->var[5]);
$this->rapportB->assign('vaisseaux1', $this->var[0]);
$this->rapportB->assign('vaisseaux2', $this->var[1]);
$this->rapportB->assign('defenses1', $this->var[2]);
$this->rapportB->assign('vaisseaux3', $this->var[7]);
$this->rapportB->assign('vaisseaux4', $this->var[8]);
$this->rapportB->assign('defenses2', $this->var[9]);
$this->rapportB->assign('termine', $this->var[6][0]);
$this->rapportB->assign('attaquantG', $this->var[6][1]);
$this->rapportB->assign('matchnul', $this->var[6][2]);
$this->rapportB->assign('pillage', $this->var[11]);
$this->rapportB->assign('termine', $this->var[6][0]);
$this->rapportB->assign('attaquantG', $this->var[6][1]);
$this->rapportB->assign('matchnul', $this->var[6][2]);
$this->rapportB->assign('pillage', $this->var[11]);
$this->rapportB->assign('vaisBC', $nomvais_bc);
$this->rapportB->assign('vaisPV', $nomvais_pv);
$this->rapportB->assign('defBC', $defense_bc);
$this->rapportB->assign('defPV', $defense_pv);
$this->rapportB->assign('nextTour', $this->var[10]);
$this->rapportB->assign('vaisBC', $nomvais_bc);
$this->rapportB->assign('vaisPV', $nomvais_pv);
$this->rapportB->assign('defBC', $defense_bc);
$this->rapportB->assign('defPV', $defense_pv);
$this->rapportB->assign('nextTour', $this->var[10]);
$race = trouvInfo($this->utilA, 'race');
include(_FCORE."../game/noms.php");
$this->rapportB->assign('ressources', $ressourc);
$this->rapportB->assign('nomvaisAT', $nomvaisa);
$race = trouvInfo($this->utilA, 'race');
include(_FCORE."../game/noms.php");
$this->rapportB->assign('ressources', $ressourc);
$this->rapportB->assign('nomvaisAT', $nomvaisa);
$race = trouvInfo($this->var[4]['id_user'], 'race');
include(_FCORE."../game/noms.php");
$this->rapportB->assign('nomvaisEN', $nomvaisa);
array_splice($nomterra, 0, 8);
$this->rapportB->assign('nomdefEN', $nomterra);
$race = trouvInfo($this->var[4]['id_user'], 'race');
include(_FCORE."../game/noms.php");
$this->rapportB->assign('nomvaisEN', $nomvaisa);
array_splice($nomterra, 0, 8);
$this->rapportB->assign('nomdefEN', $nomterra);
$this->rapportB = $this->rapportB->fetch('game/ENrapport_combat.tpl');
$this->rapportB = $this->rapportB->fetch('game/ENrapport_combat.tpl');
$this->titreA = 'Combat contre '.$this->var[4]['pseudo'];
$this->titreB = 'Combat contre '.$this->var[5]['pseudo'];
$temps = $this->timestamp;
$db = new bdd();
$db->connexion();
$db->escape($this->titreA);
$db->escape($this->titreB);
$db->escape($this->rapportA);
$db->escape($this->rapportB);
$db->query("INSERT INTO ".$this->table." (destinataire, sujet, contenu, temps) VALUES(".$this->utilA->id_user.", '$this->titreA', '$this->rapportA', '$temps')");
$db->query("INSERT INTO ".$this->table." (destinataire, sujet, contenu, temps) VALUES(".$this->utilB->id_user."', '$this->titreB', '$this->rapportB', '$temps')");
$db->deconnexion();
}
$this->titreA = 'Combat contre '.$this->var[4]['pseudo'];
$this->titreB = 'Combat contre '.$this->var[5]['pseudo'];
$temps = $this->timestamp;
$db = new bdd();
$db->connexion();
$db->escape($this->titreA);
$db->escape($this->titreB);
$db->escape($this->rapportA);
$db->escape($this->rapportB);
$db->query("INSERT INTO ".$this->table." (destinataire, sujet, contenu, temps) VALUES(".$this->utilA->id_user.", '$this->titreA', '$this->rapportA', '$temps')");
$db->query("INSERT INTO ".$this->table." (destinataire, sujet, contenu, temps) VALUES(".$this->utilB->id_user."', '$this->titreB', '$this->rapportB', '$temps')");
$db->deconnexion();
}
function show(){
include(_FCORE."../game/vars.php");
include_once(_FCORE."../game/function.php");
require_once(SMARTY_DIR."Smarty.class.php");
public function show()
{
include(_FCORE."../game/vars.php");
include_once(_FCORE."../game/function.php");
require_once(SMARTY_DIR."Smarty.class.php");
$this->rapportA = new Smarty();
$this->rapportA = new Smarty();
$this->rapportA->template_dir = _FCORE.'templates/templates/';
$this->rapportA->compile_dir = _FCORE.'templates/templates_c/';
$this->rapportA->config_dir = _FCORE.'templates/configs/';
$this->rapportA->cache_dir = _FCORE.'templates/cache/';
$this->rapportA->template_dir = _FCORE.'templates/templates/';
$this->rapportA->compile_dir = _FCORE.'templates/templates_c/';
$this->rapportA->config_dir = _FCORE.'templates/configs/';
$this->rapportA->cache_dir = _FCORE.'templates/cache/';
$this->rapportA->assign('tour', $this->var[3]);
$this->rapportA->assign('EN', $this->var[4]);
$this->rapportA->assign('flotte', $this->var[5]);
$this->rapportA->assign('vaisseaux1', $this->var[0]);
$this->rapportA->assign('vaisseaux2', $this->var[1]);
$this->rapportA->assign('defenses1', $this->var[2]);
$this->rapportA->assign('vaisseaux3', $this->var[7]);
$this->rapportA->assign('vaisseaux4', $this->var[8]);
$this->rapportA->assign('defenses2', $this->var[9]);
$this->rapportA->assign('tour', $this->var[3]);
$this->rapportA->assign('EN', $this->var[4]);
$this->rapportA->assign('flotte', $this->var[5]);
$this->rapportA->assign('vaisseaux1', $this->var[0]);
$this->rapportA->assign('vaisseaux2', $this->var[1]);
$this->rapportA->assign('defenses1', $this->var[2]);
$this->rapportA->assign('vaisseaux3', $this->var[7]);
$this->rapportA->assign('vaisseaux4', $this->var[8]);
$this->rapportA->assign('defenses2', $this->var[9]);
$this->rapportA->assign('termine', $this->var[6][0]);
$this->rapportA->assign('attaquantG', $this->var[6][1]);
$this->rapportA->assign('pillage', $this->var[11]);
$this->rapportA->assign('debris', $this->var[12]);
$this->rapportA->assign('infoPLUS', $this->var[14]);
//$this->rapportA->assign('infoPLUS2', $this->var[15]);
$this->rapportA->assign('termine', $this->var[6][0]);
$this->rapportA->assign('attaquantG', $this->var[6][1]);
$this->rapportA->assign('pillage', $this->var[11]);
$this->rapportA->assign('debris', $this->var[12]);
$this->rapportA->assign('infoPLUS', $this->var[14]);
//$this->rapportA->assign('infoPLUS2', $this->var[15]);
$this->rapportA->assign('page', 'simulation');
$this->rapportA->assign('enligne', $this->var[13][0]);
$this->rapportA->assign('infos', $this->var[13][1]);
$this->rapportA->assign('nbinfos', $this->var[13][2]);
$this->rapportA->assign('count', $this->var[13][3]);
$this->rapportA->assign('version', $this->var[13][4]);
$this->rapportA->assign('tpsdejeu', $this->var[13][5]);
$this->rapportA->assign('page', 'simulation');
$this->rapportA->assign('enligne', $this->var[13][0]);
$this->rapportA->assign('infos', $this->var[13][1]);
$this->rapportA->assign('nbinfos', $this->var[13][2]);
$this->rapportA->assign('count', $this->var[13][3]);
$this->rapportA->assign('version', $this->var[13][4]);
$this->rapportA->assign('tpsdejeu', $this->var[13][5]);
$this->rapportA->assign('vaisBC', $nomvais_bc);
$this->rapportA->assign('vaisPV', $nomvais_pv);
$this->rapportA->assign('defBC', $defense_bc);
$this->rapportA->assign('defPV', $defense_pv);
$this->rapportA->assign('nextTour', $this->var[10]);
$this->rapportA->assign('vaisBC', $nomvais_bc);
$this->rapportA->assign('vaisPV', $nomvais_pv);
$this->rapportA->assign('defBC', $defense_bc);
$this->rapportA->assign('defPV', $defense_pv);
$this->rapportA->assign('nextTour', $this->var[10]);
$race = trouvInfo($this->utilA, 'race');
include(_FCORE."../game/noms.php");
$this->rapportA->assign('ressources', $ressourc);
$this->rapportA->assign('nomvaisAT', $nomvaisa);
$this->rapportA->assign('nomvaisEN', $nomvaisa);
array_splice($nomterra, 0, 8);
$this->rapportA->assign('nomdefEN', $nomterra);
$this->rapportA->assign('race', $race);
$race = trouvInfo($this->utilA, 'race');
include(_FCORE."../game/noms.php");
$this->rapportA->assign('ressources', $ressourc);
$this->rapportA->assign('nomvaisAT', $nomvaisa);
$this->rapportA->assign('nomvaisEN', $nomvaisa);
array_splice($nomterra, 0, 8);
$this->rapportA->assign('nomdefEN', $nomterra);
$this->rapportA->assign('race', $race);
return $this->rapportA->fetch('game/SIMrapport_combat.tpl');
return $this->rapportA;
}
return $this->rapportA->fetch('game/SIMrapport_combat.tpl');
return $this->rapportA;
}
function sendAlliance()
{
$this->titreA = 'Déclaration officielle de votre alliance !';
$this->rapportA = 'Félicitations, votre alliance a recueilli suffisament de signature, sa déclaration est maintenant officielle !<br /><br />Vous pouvez dès maintenant administrer votre alliance en vous rendant sur la page Alliance.';
public function sendAlliance()
{
$this->titreA = 'Déclaration officielle de votre alliance !';
$this->rapportA = 'Félicitations, votre alliance a recueilli suffisament de signature, sa déclaration est maintenant officielle !<br /><br />Vous pouvez dès maintenant administrer votre alliance en vous rendant sur la page Alliance.';
$temps = $this->timestamp;
$temps = $this->timestamp;
$db = new BDD();
$db->escape($this->titreA);
$db->escape($this->rapportA);
$db->query("INSERT INTO ".$this->table." (destinataire, sujet, contenu, temps) VALUES(".$this->utilA->id_user.", '$this->titreA', '$this->rapportA', '$temps')");
$db->deconnexion();
}
$db = new BDD();
$db->escape($this->titreA);
$db->escape($this->rapportA);
$db->query("INSERT INTO ".$this->table." (destinataire, sujet, contenu, temps) VALUES(".$this->utilA->id_user.", '$this->titreA', '$this->rapportA', '$temps')");
$db->deconnexion();
}
function sendAlliance2()
{
$this->titreA = 'Fondation de votre alliance !';
$this->rapportA = 'Pour terminer la création de votre alliance, trouvez 4 joueurs de cette galaxie sans alliance pour leur faire signer votre traité de fondation d\'alliance.<br /><br />Lien de signature : <a href="?p=alliances&amp;q=signer&amp;i='.$this->var[0].'">http://'.$_SERVER['HTTP_HOST'].'/?p=alliances&amp;q=signer&amp;i='.$this->var[0].'</a>';
public function sendAlliance2()
{
$this->titreA = 'Fondation de votre alliance !';
$this->rapportA = 'Pour terminer la création de votre alliance, trouvez 4 joueurs de cette galaxie sans alliance pour leur faire signer votre traité de fondation d\'alliance.<br /><br />Lien de signature : <a href="?p=alliances&amp;q=signer&amp;i='.$this->var[0].'">http://'.$_SERVER['HTTP_HOST'].'/?p=alliances&amp;q=signer&amp;i='.$this->var[0].'</a>';
$temps = $this->timestamp;
$temps = $this->timestamp;
$db = new BDD();
$db->escape($this->titreA);
$db->escape($this->rapportA);
$db->query("INSERT INTO ".$this->table." (destinataire, sujet, contenu, temps) VALUES(".$this->utilA->id_user.", '$this->titreA', '$this->rapportA', '$temps')");
$db->deconnexion();
}
$db = new BDD();
$db->escape($this->titreA);
$db->escape($this->rapportA);
$db->query("INSERT INTO ".$this->table." (destinataire, sujet, contenu, temps) VALUES(".$this->utilA->id_user.", '$this->titreA', '$this->rapportA', '$temps')");
$db->deconnexion();
}
}
?>

View file

@ -27,26 +27,26 @@ class SMTP
* SMTP server port
* @var int
*/
var $SMTP_PORT = 25;
public $SMTP_PORT = 25;
/**
* SMTP reply line ending
* @var string
*/
var $CRLF = "\r\n";
public $CRLF = "\r\n";
/**
* Sets whether debugging is turned on
* @var bool
*/
var $do_debug; # the level of debug to perform
public $do_debug; # the level of debug to perform
/**#@+
* @access private
*/
var $smtp_conn; # the socket to the server
var $error; # error if any on the last call
var $helo_rply; # the reply the server sent to us for HELO
public $smtp_conn; # the socket to the server
public $error; # error if any on the last call
public $helo_rply; # the reply the server sent to us for HELO
/**#@-*/
/**
@ -54,7 +54,8 @@ class SMTP
* @access public
* @return void
*/
function SMTP() {
public function SMTP()
{
$this->smtp_conn = 0;
$this->error = null;
$this->helo_rply = null;
@ -79,12 +80,13 @@ class SMTP
* @access public
* @return bool
*/
function Connect($host,$port=0,$tval=30) {
public function Connect($host, $port=0, $tval=30)
{
# set the error val to null so there is no confusion
$this->error = null;
# make sure we are __not__ connected
if($this->connected()) {
if ($this->connected()) {
# ok we are connected! what should we do?
# for now we will just give an error saying we
# are already connected
@ -93,7 +95,7 @@ class SMTP
return false;
}
if(empty($port)) {
if (empty($port)) {
$port = $this->SMTP_PORT;
}
@ -104,11 +106,11 @@ class SMTP
$errstr, # error message if any
$tval); # give up after ? secs
# verify we connected properly
if(empty($this->smtp_conn)) {
if (empty($this->smtp_conn)) {
$this->error = array("error" => "Failed to connect to server",
"errno" => $errno,
"errstr" => $errstr);
if($this->do_debug >= 1) {
if ($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] .
": $errstr ($errno)" . $this->CRLF;
}
@ -118,8 +120,9 @@ class SMTP
# sometimes the SMTP server takes a little longer to respond
# so we will give it a longer timeout for the first read
// Windows still does not have support for this timeout function
if(substr(PHP_OS, 0, 3) != "WIN")
socket_set_timeout($this->smtp_conn, $tval, 0);
if (substr(PHP_OS, 0, 3) != "WIN") {
socket_set_timeout($this->smtp_conn, $tval, 0);
}
# get any announcement stuff
$announce = $this->get_lines();
@ -128,7 +131,7 @@ class SMTP
//if(function_exists("socket_set_timeout"))
// socket_set_timeout($this->smtp_conn, 0, 100000);
if($this->do_debug >= 2) {
if ($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $this->CRLF . $announce;
}
@ -141,19 +144,20 @@ class SMTP
* @access public
* @return bool
*/
function Authenticate($username, $password) {
public function Authenticate($username, $password)
{
// Start authentication
fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF);
fputs($this->smtp_conn, "AUTH LOGIN" . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
$code = substr($rply, 0, 3);
if($code != 334) {
if ($code != 334) {
$this->error =
array("error" => "AUTH not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
"smtp_msg" => substr($rply, 4));
if ($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] .
": " . $rply . $this->CRLF;
}
@ -164,14 +168,14 @@ class SMTP
fputs($this->smtp_conn, base64_encode($username) . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
$code = substr($rply, 0, 3);
if($code != 334) {
if ($code != 334) {
$this->error =
array("error" => "Username not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
"smtp_msg" => substr($rply, 4));
if ($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] .
": " . $rply . $this->CRLF;
}
@ -182,14 +186,14 @@ class SMTP
fputs($this->smtp_conn, base64_encode($password) . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
$code = substr($rply, 0, 3);
if($code != 235) {
if ($code != 235) {
$this->error =
array("error" => "Password not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
"smtp_msg" => substr($rply, 4));
if ($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] .
": " . $rply . $this->CRLF;
}
@ -204,13 +208,14 @@ class SMTP
* @access private
* @return bool
*/
function Connected() {
if(!empty($this->smtp_conn)) {
public function Connected()
{
if (!empty($this->smtp_conn)) {
$sock_status = socket_get_status($this->smtp_conn);
if($sock_status["eof"]) {
if ($sock_status["eof"]) {
# hmm this is an odd situation... the socket is
# valid but we aren't connected anymore
if($this->do_debug >= 1) {
if ($this->do_debug >= 1) {
echo "SMTP -> NOTICE:" . $this->CRLF .
"EOF caught while checking if connected";
}
@ -229,10 +234,11 @@ class SMTP
* @access public
* @return void
*/
function Close() {
public function Close()
{
$this->error = null; # so there is no confusion
$this->helo_rply = null;
if(!empty($this->smtp_conn)) {
if (!empty($this->smtp_conn)) {
# close the connection and cleanup
fclose($this->smtp_conn);
$this->smtp_conn = 0;
@ -263,30 +269,31 @@ class SMTP
* @access public
* @return bool
*/
function Data($msg_data) {
public function Data($msg_data)
{
$this->error = null; # so no confusion is caused
if(!$this->connected()) {
if (!$this->connected()) {
$this->error = array(
"error" => "Called Data() without being connected");
return false;
}
fputs($this->smtp_conn,"DATA" . $this->CRLF);
fputs($this->smtp_conn, "DATA" . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
$code = substr($rply, 0, 3);
if($this->do_debug >= 2) {
if ($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
}
if($code != 354) {
if ($code != 354) {
$this->error =
array("error" => "DATA command not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
"smtp_msg" => substr($rply, 4));
if ($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] .
": " . $rply . $this->CRLF;
}
@ -304,9 +311,9 @@ class SMTP
# line. NOTE: this does not count towards are limit.
# normalize the line breaks so we know the explode works
$msg_data = str_replace("\r\n","\n",$msg_data);
$msg_data = str_replace("\r","\n",$msg_data);
$lines = explode("\n",$msg_data);
$msg_data = str_replace("\r\n", "\n", $msg_data);
$msg_data = str_replace("\r", "\n", $msg_data);
$lines = explode("\n", $msg_data);
# we need to find a good way to determine is headers are
# in the msg_data or if it is a straight msg body
@ -315,43 +322,42 @@ class SMTP
# does not contain a space then it _should_ be a header
# and we can process all lines before a blank "" line as
# headers.
$field = substr($lines[0],0,strpos($lines[0],":"));
$field = substr($lines[0], 0, strpos($lines[0], ":"));
$in_headers = false;
if(!empty($field) && !strstr($field," ")) {
if (!empty($field) && !strstr($field, " ")) {
$in_headers = true;
}
$max_line_length = 998; # used below; set here for ease in change
while(list(,$line) = @each($lines)) {
while (list(, $line) = @each($lines)) {
$lines_out = null;
if($line == "" && $in_headers) {
if ($line == "" && $in_headers) {
$in_headers = false;
}
# ok we need to break this line up into several
# smaller lines
while(strlen($line) > $max_line_length) {
$pos = strrpos(substr($line,0,$max_line_length)," ");
$lines_out[] = substr($line,0,$pos);
$line = substr($line,$pos + 1);
while (strlen($line) > $max_line_length) {
$pos = strrpos(substr($line, 0, $max_line_length), " ");
$lines_out[] = substr($line, 0, $pos);
$line = substr($line, $pos + 1);
# if we are processing headers we need to
# add a LWSP-char to the front of the new line
# rfc 822 on long msg headers
if($in_headers) {
if ($in_headers) {
$line = "\t" . $line;
}
}
$lines_out[] = $line;
# now send the lines to the server
while(list(,$line_out) = @each($lines_out)) {
if(strlen($line_out) > 0)
{
if(substr($line_out, 0, 1) == ".") {
while (list(, $line_out) = @each($lines_out)) {
if (strlen($line_out) > 0) {
if (substr($line_out, 0, 1) == ".") {
$line_out = "." . $line_out;
}
}
fputs($this->smtp_conn,$line_out . $this->CRLF);
fputs($this->smtp_conn, $line_out . $this->CRLF);
}
}
@ -360,18 +366,18 @@ class SMTP
fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
$code = substr($rply, 0, 3);
if($this->do_debug >= 2) {
if ($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
}
if($code != 250) {
if ($code != 250) {
$this->error =
array("error" => "DATA not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
"smtp_msg" => substr($rply, 4));
if ($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] .
": " . $rply . $this->CRLF;
}
@ -396,30 +402,31 @@ class SMTP
* @access public
* @return string array
*/
function Expand($name) {
public function Expand($name)
{
$this->error = null; # so no confusion is caused
if(!$this->connected()) {
if (!$this->connected()) {
$this->error = array(
"error" => "Called Expand() without being connected");
return false;
}
fputs($this->smtp_conn,"EXPN " . $name . $this->CRLF);
fputs($this->smtp_conn, "EXPN " . $name . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
$code = substr($rply, 0, 3);
if($this->do_debug >= 2) {
if ($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
}
if($code != 250) {
if ($code != 250) {
$this->error =
array("error" => "EXPN not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
"smtp_msg" => substr($rply, 4));
if ($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] .
": " . $rply . $this->CRLF;
}
@ -427,9 +434,9 @@ class SMTP
}
# parse the reply and place in our array to return to user
$entries = explode($this->CRLF,$rply);
while(list(,$l) = @each($entries)) {
$list[] = substr($l,4);
$entries = explode($this->CRLF, $rply);
while (list(, $l) = @each($entries)) {
$list[] = substr($l, 4);
}
return $list;
@ -447,10 +454,11 @@ class SMTP
* @access public
* @return bool
*/
function Hello($host="") {
public function Hello($host="")
{
$this->error = null; # so no confusion is caused
if(!$this->connected()) {
if (!$this->connected()) {
$this->error = array(
"error" => "Called Hello() without being connected");
return false;
@ -458,17 +466,17 @@ class SMTP
# if a hostname for the HELO wasn't specified determine
# a suitable one to send
if(empty($host)) {
if (empty($host)) {
# we need to determine some sort of appopiate default
# to send to the server
$host = "localhost";
}
// Send extended hello first (RFC 2821)
if(!$this->SendHello("EHLO", $host))
{
if(!$this->SendHello("HELO", $host))
if (!$this->SendHello("EHLO", $host)) {
if (!$this->SendHello("HELO", $host)) {
return false;
}
}
return true;
@ -479,22 +487,23 @@ class SMTP
* @access private
* @return bool
*/
function SendHello($hello, $host) {
public function SendHello($hello, $host)
{
fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
$code = substr($rply, 0, 3);
if($this->do_debug >= 2) {
if ($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER: " . $this->CRLF . $rply;
}
if($code != 250) {
if ($code != 250) {
$this->error =
array("error" => $hello . " not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
"smtp_msg" => substr($rply, 4));
if ($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] .
": " . $rply . $this->CRLF;
}
@ -521,35 +530,36 @@ class SMTP
* @access public
* @return string
*/
function Help($keyword="") {
public function Help($keyword="")
{
$this->error = null; # to avoid confusion
if(!$this->connected()) {
if (!$this->connected()) {
$this->error = array(
"error" => "Called Help() without being connected");
return false;
}
$extra = "";
if(!empty($keyword)) {
if (!empty($keyword)) {
$extra = " " . $keyword;
}
fputs($this->smtp_conn,"HELP" . $extra . $this->CRLF);
fputs($this->smtp_conn, "HELP" . $extra . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
$code = substr($rply, 0, 3);
if($this->do_debug >= 2) {
if ($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
}
if($code != 211 && $code != 214) {
if ($code != 211 && $code != 214) {
$this->error =
array("error" => "HELP not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
"smtp_msg" => substr($rply, 4));
if ($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] .
": " . $rply . $this->CRLF;
}
@ -573,30 +583,31 @@ class SMTP
* @access public
* @return bool
*/
function Mail($from) {
public function Mail($from)
{
$this->error = null; # so no confusion is caused
if(!$this->connected()) {
if (!$this->connected()) {
$this->error = array(
"error" => "Called Mail() without being connected");
return false;
}
fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $this->CRLF);
fputs($this->smtp_conn, "MAIL FROM:<" . $from . ">" . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
$code = substr($rply, 0, 3);
if($this->do_debug >= 2) {
if ($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
}
if($code != 250) {
if ($code != 250) {
$this->error =
array("error" => "MAIL not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
"smtp_msg" => substr($rply, 4));
if ($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] .
": " . $rply . $this->CRLF;
}
@ -615,30 +626,31 @@ class SMTP
* @access public
* @return bool
*/
function Noop() {
public function Noop()
{
$this->error = null; # so no confusion is caused
if(!$this->connected()) {
if (!$this->connected()) {
$this->error = array(
"error" => "Called Noop() without being connected");
return false;
}
fputs($this->smtp_conn,"NOOP" . $this->CRLF);
fputs($this->smtp_conn, "NOOP" . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
$code = substr($rply, 0, 3);
if($this->do_debug >= 2) {
if ($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
}
if($code != 250) {
if ($code != 250) {
$this->error =
array("error" => "NOOP not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
"smtp_msg" => substr($rply, 4));
if ($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] .
": " . $rply . $this->CRLF;
}
@ -658,42 +670,43 @@ class SMTP
* @access public
* @return bool
*/
function Quit($close_on_error=true) {
public function Quit($close_on_error=true)
{
$this->error = null; # so there is no confusion
if(!$this->connected()) {
if (!$this->connected()) {
$this->error = array(
"error" => "Called Quit() without being connected");
return false;
}
# send the quit command to the server
fputs($this->smtp_conn,"quit" . $this->CRLF);
fputs($this->smtp_conn, "quit" . $this->CRLF);
# get any good-bye messages
$byemsg = $this->get_lines();
if($this->do_debug >= 2) {
if ($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $this->CRLF . $byemsg;
}
$rval = true;
$e = null;
$code = substr($byemsg,0,3);
if($code != 221) {
$code = substr($byemsg, 0, 3);
if ($code != 221) {
# use e as a tmp var cause Close will overwrite $this->error
$e = array("error" => "SMTP server rejected quit command",
"smtp_code" => $code,
"smtp_rply" => substr($byemsg,4));
"smtp_rply" => substr($byemsg, 4));
$rval = false;
if($this->do_debug >= 1) {
if ($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $e["error"] . ": " .
$byemsg . $this->CRLF;
}
}
if(empty($e) || $close_on_error) {
if (empty($e) || $close_on_error) {
$this->Close();
}
@ -712,30 +725,31 @@ class SMTP
* @access public
* @return bool
*/
function Recipient($to) {
public function Recipient($to)
{
$this->error = null; # so no confusion is caused
if(!$this->connected()) {
if (!$this->connected()) {
$this->error = array(
"error" => "Called Recipient() without being connected");
return false;
}
fputs($this->smtp_conn,"RCPT TO:<" . $to . ">" . $this->CRLF);
fputs($this->smtp_conn, "RCPT TO:<" . $to . ">" . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
$code = substr($rply, 0, 3);
if($this->do_debug >= 2) {
if ($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
}
if($code != 250 && $code != 251) {
if ($code != 250 && $code != 251) {
$this->error =
array("error" => "RCPT not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
"smtp_msg" => substr($rply, 4));
if ($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] .
": " . $rply . $this->CRLF;
}
@ -756,30 +770,31 @@ class SMTP
* @access public
* @return bool
*/
function Reset() {
public function Reset()
{
$this->error = null; # so no confusion is caused
if(!$this->connected()) {
if (!$this->connected()) {
$this->error = array(
"error" => "Called Reset() without being connected");
return false;
}
fputs($this->smtp_conn,"RSET" . $this->CRLF);
fputs($this->smtp_conn, "RSET" . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
$code = substr($rply, 0, 3);
if($this->do_debug >= 2) {
if ($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
}
if($code != 250) {
if ($code != 250) {
$this->error =
array("error" => "RSET failed",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
"smtp_msg" => substr($rply, 4));
if ($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] .
": " . $rply . $this->CRLF;
}
@ -805,30 +820,31 @@ class SMTP
* @access public
* @return bool
*/
function Send($from) {
public function Send($from)
{
$this->error = null; # so no confusion is caused
if(!$this->connected()) {
if (!$this->connected()) {
$this->error = array(
"error" => "Called Send() without being connected");
return false;
}
fputs($this->smtp_conn,"SEND FROM:" . $from . $this->CRLF);
fputs($this->smtp_conn, "SEND FROM:" . $from . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
$code = substr($rply, 0, 3);
if($this->do_debug >= 2) {
if ($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
}
if($code != 250) {
if ($code != 250) {
$this->error =
array("error" => "SEND not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
"smtp_msg" => substr($rply, 4));
if ($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] .
": " . $rply . $this->CRLF;
}
@ -853,30 +869,31 @@ class SMTP
* @access public
* @return bool
*/
function SendAndMail($from) {
public function SendAndMail($from)
{
$this->error = null; # so no confusion is caused
if(!$this->connected()) {
if (!$this->connected()) {
$this->error = array(
"error" => "Called SendAndMail() without being connected");
return false;
}
fputs($this->smtp_conn,"SAML FROM:" . $from . $this->CRLF);
fputs($this->smtp_conn, "SAML FROM:" . $from . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
$code = substr($rply, 0, 3);
if($this->do_debug >= 2) {
if ($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
}
if($code != 250) {
if ($code != 250) {
$this->error =
array("error" => "SAML not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
"smtp_msg" => substr($rply, 4));
if ($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] .
": " . $rply . $this->CRLF;
}
@ -901,30 +918,31 @@ class SMTP
* @access public
* @return bool
*/
function SendOrMail($from) {
public function SendOrMail($from)
{
$this->error = null; # so no confusion is caused
if(!$this->connected()) {
if (!$this->connected()) {
$this->error = array(
"error" => "Called SendOrMail() without being connected");
return false;
}
fputs($this->smtp_conn,"SOML FROM:" . $from . $this->CRLF);
fputs($this->smtp_conn, "SOML FROM:" . $from . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
$code = substr($rply, 0, 3);
if($this->do_debug >= 2) {
if ($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
}
if($code != 250) {
if ($code != 250) {
$this->error =
array("error" => "SOML not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
"smtp_msg" => substr($rply, 4));
if ($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] .
": " . $rply . $this->CRLF;
}
@ -946,10 +964,11 @@ class SMTP
* @access public
* @return bool
*/
function Turn() {
public function Turn()
{
$this->error = array("error" => "This method, TURN, of the SMTP ".
"is not implemented");
if($this->do_debug >= 1) {
if ($this->do_debug >= 1) {
echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF;
}
return false;
@ -968,30 +987,31 @@ class SMTP
* @access public
* @return int
*/
function Verify($name) {
public function Verify($name)
{
$this->error = null; # so no confusion is caused
if(!$this->connected()) {
if (!$this->connected()) {
$this->error = array(
"error" => "Called Verify() without being connected");
return false;
}
fputs($this->smtp_conn,"VRFY " . $name . $this->CRLF);
fputs($this->smtp_conn, "VRFY " . $name . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
$code = substr($rply, 0, 3);
if($this->do_debug >= 2) {
if ($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
}
if($code != 250 && $code != 251) {
if ($code != 250 && $code != 251) {
$this->error =
array("error" => "VRFY failed on name '$name'",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
"smtp_msg" => substr($rply, 4));
if ($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] .
": " . $rply . $this->CRLF;
}
@ -1013,27 +1033,26 @@ class SMTP
* @access private
* @return string
*/
function get_lines() {
public function get_lines()
{
$data = "";
while($str = fgets($this->smtp_conn,515)) {
if($this->do_debug >= 4) {
while ($str = fgets($this->smtp_conn, 515)) {
if ($this->do_debug >= 4) {
echo "SMTP -> get_lines(): \$data was \"$data\"" .
$this->CRLF;
echo "SMTP -> get_lines(): \$str is \"$str\"" .
$this->CRLF;
}
$data .= $str;
if($this->do_debug >= 4) {
if ($this->do_debug >= 4) {
echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF;
}
# if the 4th character is a space then we are done reading
# so just break the loop
if(substr($str,3,1) == " ") { break; }
if (substr($str, 3, 1) == " ") {
break;
}
}
return $data;
}
}
?>

View file

@ -11,33 +11,33 @@ include_once("Class/user.php");
***************************************************************************/
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,
$isolement = false,
$batiments = array(),
$vaisseaux = array(),
$modif = array();
public $id = 0;
public $galaxie;
public $ss;
public $image;
public $debris_met;
public $debris_cri;
public $metal;
public $cristal;
public $hydrogene;
public $alert_ressources = array(false, false, false);
public $timestamp;
public $file_bat;
public $file_vais;
public $isolement = false;
public $batiments = array();
public $vaisseaux = array();
public $modif = array();
function isolement()
{
return false;
}
public function isolement()
{
return false;
}
function addModif($modif)
{
if (!in_array($modif, $this->modif))
$this->modif[] = $modif;
}
public function addModif($modif)
{
if (!in_array($modif, $this->modif)) {
$this->modif[] = $modif;
}
}
}
?>

View file

@ -1,46 +1,41 @@
<?php
class TinyAsteroide
{
var $id = 0,
$galaxie,
$ss,
$nom_asteroide;
{
public $id = 0;
public $galaxie;
public $ss;
public $nom_asteroide;
/**
* Constructeur
* @param int $id id de la planète à importer
*
* @return void
* @access public
*/
function __construct($id)
{
//Récupération du nom des tables utilisées et connexion à la base de données
global $table_alliances;
$bdd = new BDD();
/**
* Constructeur
* @param int $id id de la planète à importer
*
* @return void
* @access public
*/
public function __construct($id)
{
//Récupération du nom des tables utilisées et connexion à la base de données
global $table_alliances;
$bdd = new BDD();
//On traite le cas où l'on recoit l'ID ou les coordonnées de l'asteroide
if (is_numeric($id))
{
$aste = $bdd->unique_query("SELECT id, galaxie, ss, nom_asteroide FROM $table_alliances WHERE id = $id;");
$bdd->deconnexion();
}
elseif (preg_match('#^\[?([0-9]{1,2}):([0-9]{1,2}):?[Aa]?\]?$#', $id, $position))
{
$aste = $bdd->unique_query("SELECT id, galaxie, ss, nom_asteroide FROM $table_alliances WHERE galaxie = ".$position[1]." AND ss = ".$position[2].";");
$bdd->deconnexion();
}
else
trigger_error('Erreur #04 : Format de recherche d\'astéroide incorrect !', E_USER_ERROR);
//On traite le cas où l'on recoit l'ID ou les coordonnées de l'asteroide
if (is_numeric($id)) {
$aste = $bdd->unique_query("SELECT id, galaxie, ss, nom_asteroide FROM $table_alliances WHERE id = $id;");
$bdd->deconnexion();
} elseif (preg_match('#^\[?([0-9]{1,2}):([0-9]{1,2}):?[Aa]?\]?$#', $id, $position)) {
$aste = $bdd->unique_query("SELECT id, galaxie, ss, nom_asteroide FROM $table_alliances WHERE galaxie = ".$position[1]." AND ss = ".$position[2].";");
$bdd->deconnexion();
} else {
trigger_error('Erreur #04 : Format de recherche d\'astéroide incorrect !', E_USER_ERROR);
}
if (!empty($aste))
{
//Chargement des données depuis le résultat de la base de données
$this->id = $aste["id"];
$this->galaxie = $aste["galaxie"];
$this->ss = $aste["ss"];
$this->nom_asteroide = $aste["nom_asteroide"];
}
}
}
?>
if (!empty($aste)) {
//Chargement des données depuis le résultat de la base de données
$this->id = $aste["id"];
$this->galaxie = $aste["galaxie"];
$this->ss = $aste["ss"];
$this->nom_asteroide = $aste["nom_asteroide"];
}
}
}

View file

@ -1,47 +1,43 @@
<?php
class TinyPlanete{
var $id = 0,
$galaxie,
$ss,
$position,
$nom_planete;
<?php
class TinyPlanete
{
public $id = 0;
public $galaxie;
public $ss;
public $position;
public $nom_planete;
/**
* Constructeur
* @param int $id id de la planète à importer
*
* @return void
* @access public
*/
function __construct($id)
{
//Récupération du nom des tables utilisées et connexion à la base de données
global $table_planete;
$bdd = new bdd();
/**
* Constructeur
* @param int $id id de la planète à importer
*
* @return void
* @access public
*/
public function __construct($id)
{
//Récupération du nom des tables utilisées et connexion à la base de données
global $table_planete;
$bdd = new bdd();
//On traite le cas où l'on recoit l'ID ou les coordonnées de la planète
if (is_numeric($id))
{
$plan = $bdd->unique_query("SELECT id, galaxie, ss, position, nom_planete 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))
{
$plan = $bdd->unique_query("SELECT id, galaxie, ss, position, nom_planete FROM $table_planete WHERE galaxie = ".$position[1]." AND ss = ".$position[2]." AND position = ".$position[3].";");
$bdd->deconnexion();
}
else
trigger_error('Erreur #04 : Format de recherche de planete incorrect !', E_USER_ERROR);
//On traite le cas où l'on recoit l'ID ou les coordonnées de la planète
if (is_numeric($id)) {
$plan = $bdd->unique_query("SELECT id, galaxie, ss, position, nom_planete 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)) {
$plan = $bdd->unique_query("SELECT id, galaxie, ss, position, nom_planete FROM $table_planete WHERE galaxie = ".$position[1]." AND ss = ".$position[2]." AND position = ".$position[3].";");
$bdd->deconnexion();
} else {
trigger_error('Erreur #04 : Format de recherche de planete incorrect !', E_USER_ERROR);
}
if (!empty($plan))
{
//Chargement des données depuis le résultat de la base de données
$this->id = $plan["id"];
$this->galaxie = $plan["galaxie"];
$this->ss = $plan["ss"];
$this->position = $plan["position"];
$this->nom_planete = $plan["nom_planete"];
}
}
if (!empty($plan)) {
//Chargement des données depuis le résultat de la base de données
$this->id = $plan["id"];
$this->galaxie = $plan["galaxie"];
$this->ss = $plan["ss"];
$this->position = $plan["position"];
$this->nom_planete = $plan["nom_planete"];
}
}
}
?>

View file

@ -11,201 +11,210 @@ include_once("Class/tinyasteroide.php");
*
*
***************************************************************************/
class User{
var $id_user,
$pseudo,
$auth_level,
$options,
$race,
$alliance,
$id_alliance,
$id_grade_alliance,
$permissions_alliance,
$mv,
$mail,
$envoyerMail,
$last_visite,
$points,
$place_points,
$technologies = array(),
$credits,
$politique,
$politique_lastchange,
$destinationsFavoris,
$amis = array(),
$combatAT_tactique,
$combatDE_tactique,
$modifUser = array();
class User
{
public $id_user;
public $pseudo;
public $auth_level;
public $options;
public $race;
public $alliance;
public $id_alliance;
public $id_grade_alliance;
public $permissions_alliance;
public $mv;
public $mail;
public $envoyerMail;
public $last_visite;
public $points;
public $place_points;
public $technologies = array();
public $credits;
public $politique;
public $politique_lastchange;
public $destinationsFavoris;
public $amis = array();
public $combatAT_tactique;
public $combatDE_tactique;
public $modifUser = array();
/**
* Constructeur
* @param int $id id de la planète à importer
*
* @return void
* @access public
*/
function User($id = 0){
if (!empty($id)) {
global $technologiesVAR, $table_user;
$bdd = new bdd();
$bdd->escape($id);
$user = $bdd->unique_query("SELECT * FROM $table_user WHERE id = $id;");
$bdd->deconnexion();
if (!empty($user)) {
$this->id_user = $user["id"];
$this->pseudo = $user["pseudo"];
$this->auth_level = $user["auth_level"];
$this->race = $user["race"];
$this->options = @intval($user["options"]);
$this->mv = $user["mv"];
$this->id_alliance = $user["id_alliance"];
$this->id_grade_alliance = $user["id_grade_alliance"];
$this->mail = $user["mail"];
$this->envoyerMail = $user["envoyerMail"];
$this->last_visite = $user["last_visite"];
$this->points = $user["points"];
$this->place_points = $user["place_points"];
$this->credits = $user["credits"];
$this->politique = $user["politique"];
$this->politique_lastchange = $user["politique_lastchange"];
if (!empty($user["amis"])) $this->amis = unserialize($user["amis"]);
else $this->amis = array();
if (!empty($user["destinationsFavoris"])) $this->destinationsFavoris = unserialize($user["destinationsFavoris"]);
else $this->destinationsFavoris = array();
$this->combatAT_tactique = $user["combatAT_tactique"];
$this->combatDE_tactique = $user["combatDE_tactique"];
/**
* Constructeur
* @param int $id id de la planète à importer
*
* @return void
* @access public
*/
public function User($id = 0)
{
if (!empty($id)) {
global $technologiesVAR, $table_user;
$bdd = new bdd();
$bdd->escape($id);
$user = $bdd->unique_query("SELECT * FROM $table_user WHERE id = $id;");
$bdd->deconnexion();
if (!empty($user)) {
$this->id_user = $user["id"];
$this->pseudo = $user["pseudo"];
$this->auth_level = $user["auth_level"];
$this->race = $user["race"];
$this->options = @intval($user["options"]);
$this->mv = $user["mv"];
$this->id_alliance = $user["id_alliance"];
$this->id_grade_alliance = $user["id_grade_alliance"];
$this->mail = $user["mail"];
$this->envoyerMail = $user["envoyerMail"];
$this->last_visite = $user["last_visite"];
$this->points = $user["points"];
$this->place_points = $user["place_points"];
$this->credits = $user["credits"];
$this->politique = $user["politique"];
$this->politique_lastchange = $user["politique_lastchange"];
if (!empty($user["amis"])) {
$this->amis = unserialize($user["amis"]);
} else {
$this->amis = array();
}
if (!empty($user["destinationsFavoris"])) {
$this->destinationsFavoris = unserialize($user["destinationsFavoris"]);
} else {
$this->destinationsFavoris = array();
}
$this->combatAT_tactique = $user["combatAT_tactique"];
$this->combatDE_tactique = $user["combatDE_tactique"];
foreach($technologiesVAR as $tech){
$this->technologies[] = intval($user[$tech]);
}
foreach ($technologiesVAR as $tech) {
$this->technologies[] = intval($user[$tech]);
}
//Si l'ID d'alliance est défini, on charge l'alliance
if (!empty($this->id_alliance))
$this->alliance = new TinyAsteroide($this->id_alliance);
}
else die('Erreur #01 : Utilisateur recherché introuvable dans la base de données. Contactez le support technique ('.$config['mail_support'].') au plus vite en précisant le code d\'erreur.');
}
}
//Si l'ID d'alliance est défini, on charge l'alliance
if (!empty($this->id_alliance)) {
$this->alliance = new TinyAsteroide($this->id_alliance);
}
} else {
die('Erreur #01 : Utilisateur recherché introuvable dans la base de données. Contactez le support technique ('.$config['mail_support'].') au plus vite en précisant le code d\'erreur.');
}
}
}
function loadPermissions($fondateur = 0)
{
if ($fondateur == $this->id_user)
$this->permissions_alliance = 1023;
else
{
global $table_alliances_grade;
$bdd = new BDD();
$grade = $bdd->unique_query("SELECT * FROM $table_alliances_grade WHERE id = ".$this->id_grade_alliance.";");
$bdd->deconnexion();
public function loadPermissions($fondateur = 0)
{
if ($fondateur == $this->id_user) {
$this->permissions_alliance = 1023;
} else {
global $table_alliances_grade;
$bdd = new BDD();
$grade = $bdd->unique_query("SELECT * FROM $table_alliances_grade WHERE id = ".$this->id_grade_alliance.";");
$bdd->deconnexion();
$this->permissions_alliance = intval($grade['auth']);
}
}
$this->permissions_alliance = intval($grade['auth']);
}
}
function addPoints($metal, $cristal, $hydrogene, $credits = 0, $demolition = false)
{
global $table_bourse_ressources;
//On charge les 3 valeurs boursières
$bdd = new BDD();
$bourse = $bdd->query("SELECT dispo FROM $table_bourse_ressources;");
$bdd->deconnexion();
public function addPoints($metal, $cristal, $hydrogene, $credits = 0, $demolition = false)
{
global $table_bourse_ressources;
//On charge les 3 valeurs boursières
$bdd = new BDD();
$bourse = $bdd->query("SELECT dispo FROM $table_bourse_ressources;");
$bdd->deconnexion();
if (!empty($credits))
{
//TODO Equivalence non prouvée entre $credits/bourse_calcPrixBase($bourse[0]["dispo"], 0.7); et $credits/bourse_calcPrixBase($bourse[0]["dispo"], 1) * 0.7; dans le but de ne donner que 70% des points
$metal += $credits/bourse_calcPrixBase($bourse[0]["dispo"], 0.7);
$cristal += $credits/bourse_calcPrixBase($bourse[1]["dispo"], 0.7);
$hydrogene += $credits/bourse_calcPrixBase($bourse[2]["dispo"], 0.7);
}
if (!empty($credits)) {
//TODO Equivalence non prouvée entre $credits/bourse_calcPrixBase($bourse[0]["dispo"], 0.7); et $credits/bourse_calcPrixBase($bourse[0]["dispo"], 1) * 0.7; dans le but de ne donner que 70% des points
$metal += $credits/bourse_calcPrixBase($bourse[0]["dispo"], 0.7);
$cristal += $credits/bourse_calcPrixBase($bourse[1]["dispo"], 0.7);
$hydrogene += $credits/bourse_calcPrixBase($bourse[2]["dispo"], 0.7);
}
$points = bourse_calcPrixBase($bourse[0]["dispo"], $metal);
$points += bourse_calcPrixBase($bourse[1]["dispo"], $cristal);
$points += bourse_calcPrixBase($bourse[2]["dispo"], $hydrogene);
$points = bourse_calcPrixBase($bourse[0]["dispo"], $metal);
$points += bourse_calcPrixBase($bourse[1]["dispo"], $cristal);
$points += bourse_calcPrixBase($bourse[2]["dispo"], $hydrogene);
if ($demolition)
$this->points -= intval($points);
else
$this->points += intval($points);
if ($demolition) {
$this->points -= intval($points);
} else {
$this->points += intval($points);
}
$this->addModifUser("points");
}
$this->addModifUser("points");
}
function addCredits($credits)
{
$this->credits += $credits;
$this->addModifUser("credits");
public function addCredits($credits)
{
$this->credits += $credits;
$this->addModifUser("credits");
return 0;
}
return 0;
}
function addModifUser($modif)
{
if (!in_array($modif, $this->modifUser))
$this->modifUser[] = $modif;
}
public function addModifUser($modif)
{
if (!in_array($modif, $this->modifUser)) {
$this->modifUser[] = $modif;
}
}
/**
* Destructeur
*
* @return void
* @access public
*/
function __destruct(){
global $table_user;
$out = array();
$bdd = new BDD();
foreach($this->modifUser as $key => $modif)
{
//On gère les champs variables tableaux
if (is_array($modif))
{
$calc = dDonnees::nameVAR($modif[0]);
/**
* Destructeur
*
* @return void
* @access public
*/
public function __destruct()
{
global $table_user;
$out = array();
$bdd = new BDD();
foreach ($this->modifUser as $key => $modif) {
//On gère les champs variables tableaux
if (is_array($modif)) {
$calc = dDonnees::nameVAR($modif[0]);
if (!isset(${$calc.'VAR'}))
global ${$calc.'VAR'};
if (empty(${$calc.'VAR'}))
trigger_error('Impossible de trouver les données pour '.$modif[0], E_USER_ERROR);
if (!isset(${$calc.'VAR'})) {
global ${$calc.'VAR'};
}
if (empty(${$calc.'VAR'})) {
trigger_error('Impossible de trouver les données pour '.$modif[0], E_USER_ERROR);
}
$out[] = ${$calc.'VAR'}[$modif[1]]." = ".$this->{$modif[0]}[$modif[1]];
}
elseif ($modif == "force")
$out[] = " ";
elseif (!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 ($modif != "coeff_bat" && $modif != "vaisseaux" && $modif != "terrestres" && $modif != "casernes" && $modif != "technologies" && $modif != "batiments")
{
$prep = serialize($this->{$modif});
$bdd->escape($prep);
$out[] = $modif." = '$prep'";
}
else
{
$calc = dDonnees::nameVAR($modif);
$out[] = ${$calc.'VAR'}[$modif[1]]." = ".$this->{$modif[0]}[$modif[1]];
} elseif ($modif == "force") {
$out[] = " ";
} elseif (!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 ($modif != "coeff_bat" && $modif != "vaisseaux" && $modif != "terrestres" && $modif != "casernes" && $modif != "technologies" && $modif != "batiments") {
$prep = serialize($this->{$modif});
$bdd->escape($prep);
$out[] = $modif." = '$prep'";
} else {
$calc = dDonnees::nameVAR($modif);
if (!isset(${$calc.'VAR'}))
global ${$calc.'VAR'};
if (!isset(${$calc.'VAR'})) {
global ${$calc.'VAR'};
}
foreach($this->{$modif} as $j => $value)
$out[] = ${$calc.'VAR'}[$j]." = ".$value;
}
}
}
if (!empty($out))
{
$sql = "UPDATE $table_user SET ".implode(', ', $out)." WHERE id = ".$this->id_user.";";
if (DEBUG)
echo '<br /><br />'.$sql;
$bdd->query($sql);
if ($bdd->affected() != 1)
elog($bdd->affected()." champ(s) affecté(s) par la requête du fichier ".__FILE__." à la ligne ".__LINE__.", données : out = ".serialize($out)." avec l'ID ".$this->id_user, 2);
}
$bdd->deconnexion();
}
foreach ($this->{$modif} as $j => $value) {
$out[] = ${$calc.'VAR'}[$j]." = ".$value;
}
}
}
}
if (!empty($out)) {
$sql = "UPDATE $table_user SET ".implode(', ', $out)." WHERE id = ".$this->id_user.";";
if (DEBUG) {
echo '<br /><br />'.$sql;
}
$bdd->query($sql);
if ($bdd->affected() != 1) {
elog($bdd->affected()." champ(s) affecté(s) par la requête du fichier ".__FILE__." à la ligne ".__LINE__.", données : out = ".serialize($out)." avec l'ID ".$this->id_user, 2);
}
}
$bdd->deconnexion();
}
}
?>