Пример #1
0
 /**
  * Combat constructor.
  * @param Hexa $hexa
  */
 public function __construct(Hexa $hexa)
 {
     $this->hexa = $hexa;
     $this->attaquants = new QgVirtuel();
     $this->defenseurs = new QgVirtuel();
     $this->spectateurs = new QgCollection();
     Log::getInstance()->debug(array('msg' => 'combat construct', 'hexa' => $hexa->getId()));
 }
Пример #2
0
 /**
  * Renvoie l'altitude moyenne des voisins, sans les hexas de la couronne et sans les hexas d'altitude 0
  * @param Hexa $hexa
  * @param HexaCollection $couronne
  * @return float
  */
 public function altitudeMoyenneSansCouronne(Hexa $hexa, HexaCollection $couronne)
 {
     $altitudes = array();
     for ($angle = 0; $angle <= 5; $angle++) {
         $voisin = $hexa->getVoisin($angle);
         if (!is_null($voisin) && !$couronne->exists($voisin) && $voisin->getAltitude() > 0) {
             $altitudes[] = $voisin->getAltitude();
         }
     }
     if (count($altitudes) == 0) {
         return 0;
     }
     return array_sum($altitudes) / count($altitudes);
 }
Пример #3
0
 /**
  * @param Hexa $hexa1
  * @param Hexa $hexa2
  * @return Riviere
  */
 public static function getByHexas(Hexa $hexa1, Hexa $hexa2)
 {
     $index = min($hexa1->getId(), $hexa2->getId()) . '_' . max($hexa1->getId(), $hexa2->getId());
     if (isset(self::$indexByHexas[$index])) {
         return self::$indexByHexas[$index];
     } else {
         $riviere = RiviereBusiness::getEntre2Hexas($hexa1, $hexa2);
         if (is_null($riviere)) {
             self::$indexByHexas[$index] = null;
         } else {
             self::store($riviere);
         }
         return $riviere;
     }
 }
Пример #4
0
 /**
  * Renvoie la quantité de nourriture disponible sur la case
  * @param Hexa $hexa
  * @return int
  */
 public static function getNourriture(Hexa $hexa)
 {
     if (isset(self::$nourriture[$hexa->getTemperature() . '_' . $hexa->getAltitude() . '_' . $hexa->getVegetation()])) {
         return self::$nourriture[$hexa->getTemperature() . '_' . $hexa->getAltitude() . '_' . $hexa->getVegetation()];
     } else {
         return null;
     }
 }
Пример #5
0
 /**
  * Renvoie le coin supérieur gauche de la carte
  * @return Hexa
  */
 public function coinSupGauche()
 {
     if (is_null($this->coinSupGauche)) {
         // Recalage en Y du centre pour les bords
         while ($this->centre->getY() < floor($this->hauteur / 2)) {
             if (fmod($this->centre->getY(), 2) == 1) {
                 // Y impair
                 $this->centre = $this->centre->getVoisin(5);
             } else {
                 // Y pair
                 $this->centre = $this->centre->getVoisin(4);
             }
         }
         while ($this->partie->getHauteur() - 1 - floor($this->hauteur / 2) < $this->centre->getY()) {
             if (fmod($this->centre->getY(), 2) == 1) {
                 // Y impair
                 $this->centre = $this->centre->getVoisin(1);
             } else {
                 // Y pair
                 $this->centre = $this->centre->getVoisin(2);
             }
         }
         // Recherche Y du coin
         $coin = $this->centre;
         while ($coin->getY() > $this->centre->getY() - ($this->hauteur / 2 - (1 - fmod($this->hauteur, 2) / 2))) {
             if (fmod($coin->getY(), 2) == 1) {
                 // Y impair
                 $coin = $coin->getVoisin(1);
             } else {
                 // Y pair
                 $coin = $coin->getVoisin(2);
             }
         }
         // Recherche du X du coin
         for ($i = 1; $i <= $this->largeur / 2 - (1 - fmod($this->largeur, 2) / 2); $i++) {
             $coin = $coin->getVoisin(3);
         }
         $this->coinSupGauche = $coin;
     }
     return $this->coinSupGauche;
 }
Пример #6
0
 /**
  * Renvoie les Productions liés au Hexa fourni
  * @var Hexa $hexa
  * @return ProductionCollection
  */
 public static function getByHexa(Hexa $hexa)
 {
     $req = "SELECT * from production WHERE idBatiment IN (SELECT batiment.idBatiment FROM batiment WHERE batiment.idHexa = " . $hexa->getIdHexa() . ")";
     return DbHandler::collFromQuery($req, 'Production', 'ProductionCollection');
 }
Пример #7
0
 /**
  * @param Hexa $hexa
  * @return BatimentCollection
  */
 public static function getConstruitsByHexa(Hexa $hexa)
 {
     $req = "SELECT * FROM batiment WHERE idHexa = '" . $hexa->getIdHexa() . "' AND enConstruction IN (0, -1); ";
     return DbHandler::collFromQuery($req, 'Batiment', 'BatimentCollection');
 }
Пример #8
0
 /**
  * Renvoie les Qgs dont this est dans la ZDC
  * @param Hexa $hexa
  * @return QgCollection
  * @throws \Exception
  */
 public function inZdcDe(Hexa $hexa)
 {
     $ret = new QgCollection();
     if (is_null($this->getIdJoueur())) {
         throw new \Exception("Qg " . $this->getId() . " has no Joueur");
     }
     $qgs = $hexa->getCouronnePleine(Missions::getMaxTailleZdc())->getQgs();
     foreach ($qgs as $qg) {
         if (is_null($qg->getIdJoueur())) {
             throw new \Exception("Qg " . $qg->getId() . " has no Joueur");
         }
         if ($qg->getJoueur()->isEnnemi($this->getJoueur()) && $qg->getIdTypeMission() != Missions::RETRANCHEMENT && ($qg->getIdTypeQg() == $this->getIdTypeQg() || $this->getIdTypeQg() == Unites::TYPE_AMPHIBIE && ($qg->getIdTypeQg() == Unites::TYPE_TERRESTRE || $qg->getIdTypeQg() == Unites::TYPE_NAVAL)) && $qg->getHexa()->getCouronnePleine(Missions::$types[$qg->getIdTypeMission()]['tailleZone'])->exists($hexa)) {
             $ret->ajout($qg);
         }
     }
     return $ret;
 }
Пример #9
0
 /**
  * @param Hexa $hexa
  * @return bool
  */
 public static function hexaAutoriseDemarrage(Hexa $hexa)
 {
     return !in_array($hexa->getTypeTerrain(), self::$typesInterditsDemarrage);
 }
Пример #10
0
 /**
  * Crée un Hexa lié à ce Joueur
  * @return Hexa
  */
 public function createHexa()
 {
     $hexa = new Hexa();
     $hexa->setIdTerritoire($this->getIdJoueur());
     return $hexa;
 }
Пример #11
0
 function jsonSerialize()
 {
     return array('noPassageDebordement' => $this->noPassageDebordement, 'hexa' => is_null($this->hexa) ? 0 : $this->hexa->getId(), 'provenance' => is_null($this->provenance) ? 0 : $this->provenance->getId());
 }
Пример #12
0
 /**
  * Renvoie les Qg liées à un Hexa
  * @param Hexa $hexa
  * @return QgCollection
  */
 public static function getByHexa(Hexa $hexa)
 {
     $req = "SELECT * FROM qg WHERE idHexa = '" . $hexa->getIdHexa() . "';";
     return DbHandler::collFromQuery($req, 'Qg', 'QgCollection');
 }
Пример #13
0
 /**
  * @param Hexa $hexa1
  * @param Hexa $hexa2
  * @return string
  */
 public static function getIndexCouple(Hexa $hexa1, Hexa $hexa2)
 {
     return min($hexa1->getId(), $hexa2->getId()) . '_' . max($hexa1->getId(), $hexa2->getId());
 }
Пример #14
0
 /**
  * Dit quel est l'angle de voisinage de la case demandée
  * @param Hexa $hexa
  * @return int ou null si la case n'est pas voisine de this
  */
 public function quelVoisin(Hexa $hexa)
 {
     $voisins = array();
     for ($angle = 0; $angle <= 5; $angle++) {
         $coords = self::getCoordsVoisins($this->getX(), $this->getY(), $angle);
         $coords = $this->getPartie()->coordsCorrigees($coords[0], $coords[1]);
         if (!is_null($coords)) {
             $voisins[$coords[0] . '_' . $coords[1]] = $angle;
         }
     }
     if (isset($voisins[$hexa->getX() . '_' . $hexa->getY()])) {
         return $voisins[$hexa->getX() . '_' . $hexa->getY()];
     }
     return null;
 }
Пример #15
0
 /**
  * Renvoie les Competences liés au Hexa fourni
  * @var Hexa $hexa
  * @return CompetenceCollection
  */
 public static function getByHexa(Hexa $hexa)
 {
     $req = "SELECT * from competence WHERE idQg IN (SELECT qg.idQg FROM qg WHERE qg.idHexa = " . $hexa->getIdHexa() . ")";
     return DbHandler::collFromQuery($req, 'Competence', 'CompetenceCollection');
 }
Пример #16
0
 /**
  * Dit si un hexa est repésenté dans les visibles de la collection
  * @param Hexa $hexa
  * @return bool
  */
 public function hexaExists(Hexa $hexa)
 {
     return isset($this->indexParHexa[$hexa->getId()]);
 }
Пример #17
0
 /**
  * Cherche la trajectoire la plus courte
  * @return void
  */
 public function make()
 {
     $noeud = new Noeud($this->getOrigine());
     $noeud->setNoPassageDebordement(0);
     $this->noeuds[] = $noeud;
     $pas = 0;
     /*
      * Trouvage chemin le plus court
      */
     while (!$this->termine) {
         if ($this->getOrigine()->getId() == 904) {
             Debug::w(array('pas' => $pas));
         }
         $auMoinsUnNoeud = false;
         foreach ($this->noeuds as $noeud) {
             Debug::w(__LINE__);
             foreach ($noeud->getHexa()->voisins() as $voisin) {
                 /** @var Hexa $voisin */
                 $canPass = $this->fakeQg->canPass($noeud->getHexa(), $voisin, true);
                 $coutDep = $this->fakeQg->getCoutDeplacement($noeud->getHexa(), $voisin);
                 if ($canPass && (!is_null($voisin->getNoeud()) && $coutDep + $noeud->getNoPassageDebordement() < $voisin->getNoeud()->getNoPassageDebordement() || is_null($voisin->getNoeud()))) {
                     $auMoinsUnNoeud = true;
                     if (is_null($voisin->getNoeud())) {
                         $noeudCible = new Noeud($voisin);
                     } else {
                         $noeudCible = $voisin->getNoeud();
                     }
                     $noeudCible->setNoPassageDebordement($coutDep + $noeud->getNoPassageDebordement());
                     $noeudCible->setProvenance($noeud->getHexa());
                     $this->noeuds[] = $noeudCible;
                     if ($this->objectifAtteint($voisin->getNoeud())) {
                         $this->termine = true;
                         $this->possible = true;
                         $this->destination = $voisin;
                         break 3;
                     }
                 }
             }
         }
         if (!$auMoinsUnNoeud) {
             $this->termine = true;
             $this->possible = false;
         }
         $pas++;
     }
     /*
      * Traçage du chemin
      */
     if ($this->possible) {
         $enCours = true;
         $this->hexas->ajout($this->destination);
         $noeud = $this->destination->getNoeud();
         while ($enCours) {
             if (!is_null($noeud->getProvenance())) {
                 $this->hexas->ajout($noeud->getProvenance());
                 $noeud = $noeud->getProvenance()->getNoeud();
             } else {
                 $enCours = false;
             }
         }
         $this->hexas->reverse();
     }
     /*
      * Vidage des noeuds des hexas
      */
     foreach ($this->noeuds as $noeud) {
         $noeud->getHexa()->setNoeud(null);
     }
 }
Пример #18
0
 /**
  * Donne qui a la priorité entre 2 hexas pour le choix du recul forcé. Priorités :
  * - Non-présence ennemi
  * - Non-présence ami
  * - Rand
  * @param Hexa $hexa1
  * @param Hexa $hexa2
  * @return int
  */
 public static function choixReculForce(Hexa $hexa1, Hexa $hexa2)
 {
     if ($hexa1->hasQg(true) && !$hexa2->hasQg(true)) {
         return 1;
     } elseif (!$hexa1->hasQg(true) && $hexa2->hasQg(true)) {
         return -1;
     } else {
         if ($hexa1->hasQg() && !$hexa2->hasQg()) {
             return 1;
         } elseif (!$hexa1->hasQg() && $hexa2->hasQg()) {
             return -1;
         } else {
             return rand(0, 1) * 2 - 1;
         }
     }
 }
Пример #19
0
 /**
  * @param Hexa $hexa
  * @param int $enConstruction
  * @return BaseCollection
  */
 public static function getByHexaDOrigine(Hexa $hexa, $enConstruction = null)
 {
     $req = "SELECT * FROM unite WHERE idHexaConstruit = " . $hexa->getId() . " ";
     if (!is_null($enConstruction)) {
         $req .= " AND enConstruction = " . $enConstruction . " ";
     }
     $req .= ";";
     return DbHandler::collFromQuery($req, 'Unite', 'UniteCollection');
 }
 /**
  * Renvoie le pont entre 2 hexas ou null si aucun n'est trouvé
  * @param Hexa $hexa1
  * @param Hexa $hexa2
  * @return Infrastructure De type pont
  */
 public static function getPontEntre2Hexas(Hexa $hexa1, Hexa $hexa2)
 {
     $req = "SELECT * FROM infrastructure WHERE (idHexa='" . $hexa1->getId() . "' AND idHexa2='" . $hexa2->getId() . "') OR (idHexa2='" . $hexa1->getId() . "' AND idHexa='" . $hexa2->getId() . "') AND idType=" . Infrastructures::PONT . ";";
     return DbHandler::objFromQuery($req, 'Infrastructure');
 }
Пример #21
0
 /**
  * Dit si une infra est storée pour les 2 hexas fournis
  * @param Hexa $hexa1
  * @param Hexa $hexa2
  * @return bool
  */
 public static function existsByHexas(Hexa $hexa1, Hexa $hexa2)
 {
     $index = min($hexa1->getId(), $hexa2->getId()) . '_' . max($hexa1->getId(), $hexa2->getId());
     return isset(self::$indexByHexas[$index]);
 }