forked from halo-battle/game
Version 0.9a
This commit is contained in:
parent
d5c122a2c5
commit
59fbc7104e
141 changed files with 8686 additions and 1156 deletions
246
Class/flotte.php
Normal file
246
Class/flotte.php
Normal file
|
|
@ -0,0 +1,246 @@
|
|||
<?php
|
||||
/***************************************************************************
|
||||
* flottes.php
|
||||
* ----------------
|
||||
* begin : Samedi 8 décembre 2007
|
||||
* copyright : (C) 2007 Halo-Battle
|
||||
* email : nemunaire@gmail.com
|
||||
*
|
||||
* $Id: gererFile.php,v 1.0 08/12/2007 19:16:21 $
|
||||
*
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/**
|
||||
* Classe flotte. Par Némunaire de Halo-Battle
|
||||
*
|
||||
* Classe permettant la gestion simple d'une flotte
|
||||
*
|
||||
*/
|
||||
class flotte {
|
||||
var $vaisseaux = array(0,0,0,0,0,0,0,0,0,0,0,0); //Tableau contenant le nombre de vaisseaux par type
|
||||
var $vaisseaux_fret = array(0,0,0); //Tableau contenant le nombre de ressources transporté par tous les vaisseaux, classé par type
|
||||
var $fret_max = 0;
|
||||
|
||||
var $ressources_max = array(); //Tableau contenant le nombre de ressources maximal de ressoources que peut transporter un vaisseau particulier
|
||||
var $vitesses_cd = array(); //Tableau des vitesses de courtes distances
|
||||
var $vitesses_ld = array(); //Tableau des vitesses de longues distances
|
||||
var $preparation_cd = array(); //Tableau des temps de préparation pour un déplacement courte distance
|
||||
var $preparation_ld = array(); //Tableau des temps de préparation pour un déplacement longue distance
|
||||
// var $chauffe_cd = array(); //Tableau des temps de chauffe pour un déplacement courte distance
|
||||
var $chauffe_ld = array(); //Tableau des temps de chauffe pour un déplacement longue distance
|
||||
var $vitesse_coefficient = 1;
|
||||
|
||||
var $vaisseaux_nombre = 0;
|
||||
|
||||
var $position_galaxie = 0;
|
||||
var $position_systeme = 0;
|
||||
var $position_planete = 0;
|
||||
var $position_temps = 0;
|
||||
var $destination_galaxie = 0;
|
||||
var $destination_systeme = 0;
|
||||
var $destination_planete = 0;
|
||||
var $destination_temps = 0;
|
||||
|
||||
/**
|
||||
* Constructeur. Définition du nombre de vaisseaux au départ
|
||||
*
|
||||
*/
|
||||
function flotte($Tressources_max, $Tvitesses_cd, $Tvitesses_ld, $Tpreparation_cd, $Tpreparation_ld, $Tchauffe_ld, $vaisseau_1 = 0, $vaisseau_2 = 0, $vaisseau_3 = 0, $vaisseau_4 = 0, $vaisseau_5 = 0, $vaisseau_6 = 0, $vaisseau_7 = 0, $vaisseau_8 = 0, $vaisseau_9 = 0, $vaisseau_10 = 0, $vaisseau_11 = 0, $vaisseau_12 = 0) {
|
||||
$this->vaisseaux[0] = $vaisseau_1; $this->vaisseaux[1] = $vaisseau_2; $this->vaisseaux[2] = $vaisseau_3; $this->vaisseaux[3] = $vaisseau_4; $this->vaisseaux[4] = $vaisseau_5; $this->vaisseaux[5] = $vaisseau_6; $this->vaisseaux[6] = $vaisseau_7; $this->vaisseaux[7] = $vaisseau_8; $this->vaisseaux[8] = $vaisseau_9; $this->vaisseaux[9] = $vaisseau_10; $this->vaisseaux[10] = $vaisseau_11; $this->vaisseaux[11] = $vaisseau_12;
|
||||
$this->ressources_max = $Tressources_max;
|
||||
$this->vitesses_cd = $Tvitesses_cd;
|
||||
$this->vitesses_ld = $Tvitesses_ld;
|
||||
$this->preparation_cd = $Tpreparation_cd;
|
||||
$this->preparation_ld = $Tpreparation_ld;
|
||||
$this->chauffe_ld = $Tchauffe_ld;
|
||||
$this->calcFret();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajouter $nombre vaisseaux de type $type
|
||||
*
|
||||
*/
|
||||
function addVaisseaux($type, $nombre) {
|
||||
$type--;
|
||||
$this->vaisseaux[$type] += $nombre;
|
||||
|
||||
$this->calcFret();
|
||||
}
|
||||
|
||||
/**
|
||||
* Supprime $nombre vaisseaux de type $type
|
||||
*
|
||||
*/
|
||||
function delVaisseaux($type, $nombre) {
|
||||
$type--;
|
||||
$this->vaisseaux[$type] -= $nombre;
|
||||
if ($this->vaisseaux[$type] < 0) $this->vaisseaux[$type] = 0;
|
||||
|
||||
$this->calcFret();
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifie qu'il reste assez de place dans les vaisseaux pour transporter $nombre de ressources du type $type
|
||||
*
|
||||
*/
|
||||
function verifRessources($type, $nombre) {
|
||||
$type--;
|
||||
if ($type == 0) {
|
||||
if ($this->vaisseaux_fret[$type]+$nombre+$this->vaisseaux_fret[$type+1]+$this->vaisseaux_fret[$type+2] > $this->fret_max) return false; // Retourne false si la quantité à ajouter est trop importante
|
||||
else return true;
|
||||
}
|
||||
elseif ($type == 1) {
|
||||
if ($this->vaisseaux_fret[$type]+$nombre+$this->vaisseaux_fret[$type+1]+$this->vaisseaux_fret[$type-1] > $this->fret_max) return false; // Retourne false si la quantité à ajouter est trop importante
|
||||
else return true;
|
||||
}
|
||||
elseif ($type == 2) {
|
||||
if ($this->vaisseaux_fret[$type]+$nombre+$this->vaisseaux_fret[$type-1]+$this->vaisseaux_fret[$type-2] > $this->fret_max) return false; // Retourne false si la quantité à ajouter est trop importante
|
||||
else return true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajouter $nombre ressources de type $type
|
||||
*
|
||||
*/
|
||||
function addRessources($type, $nombre) {
|
||||
if ($this->verifRessources($type, $nombre) == true) {
|
||||
$type--;
|
||||
$this->vaisseaux_fret[$type] += $nombre;
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enlève $nombre ressources de type $type
|
||||
*
|
||||
*/
|
||||
function delRessources($type, $nombre) {
|
||||
$type--;
|
||||
$this->vaisseaux_fret[$type] -= $nombre;
|
||||
if ($this->vaisseaux_fret[$type] < 0) $this->vaisseaux_fret[$type] = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enlève toutes les ressources de type $type
|
||||
* Si $type = 0, enlève toutes les ressources
|
||||
*
|
||||
*/
|
||||
function razRessources($type = 0) {
|
||||
$type--;
|
||||
if ($type == -1) $this->vaisseaux_fret = array(0,0,0);
|
||||
else $this->vaisseaux_fret[$type] = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recalcul le nombre maximum de ressource que peuvent transporter tous les vaisseaux
|
||||
*
|
||||
*/
|
||||
function calcFret() {
|
||||
$cnt = count($this->vaisseaux);
|
||||
for ($i=0 ; $i<$cnt ; $i++) {
|
||||
$this->fret_max += $this->vaisseaux[$i] * $this->ressources_max[$i];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixer position de départ
|
||||
*
|
||||
*/
|
||||
function fixePosition($galaxie, $systeme, $planete, $time = 0) {
|
||||
if ($time == 0) $time = time();
|
||||
|
||||
$this->position_galaxie = $galaxie;
|
||||
$this->position_systeme = $systeme;
|
||||
$this->position_planete = $planete;
|
||||
$this->position_temps = $time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Déplacer la flotte vers une destination et calcul du temps de déplacement
|
||||
*
|
||||
*/
|
||||
function deplacerFlotte($galaxie, $systeme, $planete, $coefficient = 1) {
|
||||
$this->destination_galaxie = $galaxie;
|
||||
$this->destination_systeme = $systeme;
|
||||
$this->destination_planete = $planete;
|
||||
$this->vitesse_coefficient = $coefficient;
|
||||
|
||||
$this->calcTemps();
|
||||
}
|
||||
|
||||
/**
|
||||
* Recalcul le temps de déplacement
|
||||
*
|
||||
*/
|
||||
function calcTemps() {
|
||||
$start_galaxie = $this->position_galaxie;
|
||||
$start_ss = $this->position_systeme;
|
||||
$start_position = $this->position_planete;
|
||||
$end_galaxie = $this->destination_galaxie;
|
||||
$end_ss = $this->destination_systeme;
|
||||
$end_position = $this->destination_planete;
|
||||
|
||||
$AvaisType = ''; $AvaisVitesseC = ''; $AvaisVitesseL = ''; $AvaisPrepC = ''; $AvaisChauffe = ''; $AvaisContenu = 0;
|
||||
for ($i=0 ; $i<=12 ; $i++) {
|
||||
for ($j = 1; $j <= $this->vaisseaux[$i]; $j++) {
|
||||
$AvaisType .= ($i).' ';
|
||||
$AvaisVitesseC .= $this->vitesses_cd[$i].' ';
|
||||
$AvaisVitesseL .= $this->vitesses_ld[$i].' ';
|
||||
$AvaisPrepC .= $this->preparation_cd[$i].' ';
|
||||
$AvaisPrepL .= $this->preparation_ld[$i].' ';
|
||||
$AvaisChauffe .= $this->chauffe_ld[$i].' ';
|
||||
}
|
||||
}
|
||||
$AvaisType = split(' ', trim($AvaisType)); $AvaisVitesseC = split(' ', trim($AvaisVitesseC)); $AvaisVitesseL = split(' ', trim($AvaisVitesseL)); $AvaisContenu = split(' ', trim($AvaisContenu)); $AvaisPrepC = split(' ', trim($AvaisPrepC)); $AvaisPrepL = split(' ', trim($AvaisPrepL)); $AvaisChauffe = split(' ', trim($AvaisChauffe));
|
||||
|
||||
if(min($AvaisVitesseL) != 0) {
|
||||
$vitesse = min($AvaisVitesseL);
|
||||
$preparation = max($AvaisPrepL);
|
||||
$chauffe = max($AvaisChauffe);
|
||||
}
|
||||
else {
|
||||
$vitesse = min($AvaisVitesseC);
|
||||
$preparation = max($AvaisPrepC);
|
||||
$chauffe = 0;
|
||||
}
|
||||
|
||||
$this->vaisseaux_nombre = count($AvaisType);
|
||||
$coefvitesse = $this->vitesse_coefficient;
|
||||
|
||||
if ($end_galaxie-$start_galaxie == 0 && $end_ss-$start_ss == 0 && $end_position-$start_position == 0) $temps = 0;
|
||||
elseif ($end_galaxie-$start_galaxie == 0 && $end_ss-$start_ss == 0 && $chauffe == 0) $temps = $preparation+abs($end_position-$start_position)*$vitesse/12;
|
||||
elseif ($end_galaxie-$start_galaxie == 0 && $chauffe == 0) $temps = $preparation+abs($end_ss-$start_ss)*$vitesse;
|
||||
elseif ($chauffe == 0) $temps = $preparation+abs($end_galaxie-$start_galaxie)*$vitesse*300;
|
||||
elseif ($end_galaxie-$start_galaxie == 0 && $end_ss-$start_ss == 0) $temps = $preparation+abs($end_position-$start_position)*($vitesse*2)/12+$preparation;
|
||||
/*elseif ($end_galaxie-$start_galaxie == 0 && $end_ss-$start_ss <= $chauffe) $temps = abs($end_ss-$start_ss)*(($vitesse/$chauffe)*($chauffe-abs($end_ss-$start_ss))+$vitesse)+$preparation;
|
||||
elseif ($end_galaxie-$start_galaxie == 0) $temps = $vitesse*abs($end_ss-$start_ss)+$vitesse*10+$preparation;*/
|
||||
elseif ($end_galaxie-$start_galaxie == 0) $temps = (abs($end_ss-$start_ss)*(($vitesse/$chauffe)*((abs($chauffe-abs($end_ss-$start_ss))+($chauffe-abs($end_ss-$start_ss)))/2)+$vitesse))+(20-(abs($chauffe-abs($end_ss-$start_ss))+($chauffe-abs($end_ss-$start_ss)))/2)*54+$preparation;
|
||||
else $temps = (($vitesse/$chauffe)*($chauffe-abs($end_galaxie-$start_galaxie))+$vitesse)*300+108+$preparation;
|
||||
|
||||
$this->destination_temps = $temps/$coefvitesse;
|
||||
return $temps/$coefvitesse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calcul la consomation de la flotte
|
||||
*
|
||||
*/
|
||||
function calcConso() {
|
||||
return intval($this->destination_temps*$this->vaisseaux_nombre/20);
|
||||
}
|
||||
}
|
||||
|
||||
$race = 'humain';
|
||||
$auth_level = 7;
|
||||
include('../languages/fr_FR/noms.php');
|
||||
|
||||
$flotte = new flotte($nomvais_rs,$nomvais_dc,$nomvais_lc,$nomvais_pdc,$nomvais_pdl,$nomvais_cdl,0,0,0,4);
|
||||
$flotte->addRessources(1,11);
|
||||
$flotte->deplacerFlotte(1,1,1);
|
||||
$flotte->calcTemps();
|
||||
print_r ($flotte->calcConso());
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue