function actividad() { do { $this->finCola = null; foreach ($this->planetas as $id => $planeta) { //Si el planeta no está ocupado, ejecutar. if ($this->planetas[$id]->finCola < time()) { $this->planetas[$id]->ciclo(); if ($this->planetas[$id]->error) { $this->error = true; break; } $this->finCola = min_not_null($this->finCola, $this->planetas[$id]->finCola); } } if (!$this->error) { $tiempo_espera = $this->finCola - time() + 1; if ($tiempo_espera > 0) { sleep($tiempo_espera); } } else { $this->logger->login(); $this->error = false; } } while (true); }
function cmp_min($a, $b) { return min_not_null($a) - min_not_null($b); }
function granjeo() { $this->finColas["granjeo"] = null; foreach ($this->granjas as $i => $granja) { if ($granja["estado"] == "libre") { //Si [estado]=libre, mandar flota a atacar. $flGranjeoB = new Flota($this->navesFlota); $flGranjeoB->addShips($GLOBALS["stringCazLig"], 3); $flGranjeoB->addShips($GLOBALS["stringPCarga"], 3); $datosFlota = $this->mandarFlota($flGranjeoB, $granja["coordenadas"], array("nombre_mision" => 'Atacar')); $this->granjas[$i]["estado"] = "ocupado"; $this->granjas[$i]["detalles"] = $datosFlota; $this->granjas[$i]["ultimo_granjeo"] = $datosFlota["llegada"]; $this->finColas["granjeo"] = min_not_null($this->finColas["granjeo"], $datosFlota["vuelta"]); } } }