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()); ?>