* Galaxy map * * @author Mauri Kujala <*****@*****.**> * @copyright Copyright (C) 2016, Mauri Kujala * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 */ //http://ed-board.net/3Dgalnet/ $pagetitle = "Galaxy Map & Neighborhood Map"; require_once "" . $_SERVER["DOCUMENT_ROOT"] . "/style/header.php"; if (valid_coordinates($curSys["x"], $curSys["y"], $curSys["z"])) { $ucoordx = $curSys["x"]; $ucoordy = $curSys["y"]; $ucoordz = -$curSys["z"]; } else { // get last known coordinates $last_coords = last_known_system(); $ucoordx = $last_coords["x"]; $ucoordy = $last_coords["y"]; $ucoordz = -$last_coords["z"]; $is_unknown = " *"; } ?> <div style="display:none" id="curx"><?php echo $ucoordx; ?> </div> <div style="display:none" id="cury"><?php echo $ucoordy; ?> </div> <div style="display:none" id="curz"><?php
/** * Return usable coordinates * * @return array of floats x, y, z and bool current * @author Mauri Kujala <*****@*****.**> */ function usable_coords() { global $curSys; $usable = []; if (valid_coordinates($curSys["x"], $curSys["y"], $curSys["z"])) { $usable["x"] = $curSys["x"]; $usable["y"] = $curSys["y"]; $usable["z"] = $curSys["z"]; $usable["current"] = true; } else { $last_coords = last_known_system(); $usable["x"] = $last_coords["x"]; $usable["y"] = $last_coords["y"]; $usable["z"] = $last_coords["z"]; $usable["current"] = false; } if (!valid_coordinates($usable["x"], $usable["y"], $usable["z"])) { $usable["x"] = "0"; $usable["y"] = "0"; $usable["z"] = "0"; $usable["current"] = false; } return $usable; }
/** * Define accuracy of current position * * Count how many jumps user has made since last known * coordinates and return a "fuzziness" factor * * @return array $value range in ly to use for reference systems * @throws \Exception * @author Mauri Kujala <*****@*****.**> */ private function fuzziness() { /** * if user wants the standard references, we don't need any of this */ if ($this->standard !== true) { $query = " SELECT system_name\n FROM user_visited_systems\n ORDER BY visit DESC\n LIMIT 30"; $result = $this->mysqli->query($query) or write_log($this->mysqli->error, __FILE__, __LINE__); $count = $result->num_rows; if ($count > 0) { /** * fetch user's last known system */ $last_known = last_known_system(true); /** @var string $last_known user's last known system */ $last_known_name = $last_known["name"]; if (!empty($last_known_name)) { $num = 0; $value = []; /** * loop for as long as it takes to find the last visited system with known cooords */ while ($obj = $result->fetch_object()) { $visited_system_name = $obj->system_name; if ($visited_system_name == $last_known_name) { break; } else { $num++; } } $num = $num == 0 ? 1 : $num; $fuzziness = $num * 40 + 20; // assuming a max range of 40 ly per jump (+ 20 ly just to be on the safe side) $value["fuzziness"] = $fuzziness; $value["system_name"] = $last_known_name; $value["x"] = $last_known["x"]; $value["y"] = $last_known["y"]; $value["z"] = $last_known["z"]; $result->close(); return $value; } else { throw new \Exception('Cannot calculate fuzziness factor: no last known system'); } } else { throw new \Exception('Cannot calculate fuzziness factor: no visited systems'); } } else { throw new \Exception('Cannot calculate fuzziness factor: standard = true'); } }
/** * NearestSystems constructor. */ public function __construct() { global $server, $user, $pwd, $db; /** * connect to database */ $this->mysqli = new mysqli($server, $user, $pwd, $db); if ($this->mysqli->connect_errno) { echo "Failed to connect to MySQL: " . $this->mysqli->connect_error; } /** * determine what coordinates to use */ $this->system = isset($_GET["system"]) ? $_GET["system"] + 0 : ""; if (!empty($this->system)) { $query = " SELECT name, id, x, y, z\n FROM edtb_systems\n WHERE id = '{$this->system}'\n LIMIT 1"; $result = $this->mysqli->query($query) or write_log($this->mysqli->error, __FILE__, __LINE__); $sys_obj = $result->fetch_object(); $sys_name = $sys_obj->name; $sys_id = $sys_obj->id; $this->usex = $sys_obj->x; $this->usey = $sys_obj->y; $this->usez = $sys_obj->z; $result->close(); $this->text .= ' (to <a href="/System?system_id=' . $sys_id . '">' . $sys_name . '</a>) '; $this->power_params .= "&system=" . $this->system; $this->allegiance_params .= "&system=" . $this->system; $this->hidden_inputs .= '<input type="hidden" name="system" value="' . $sys_id . '" />'; } elseif (valid_coordinates($curSys["x"], $curSys["y"], $curSys["z"]) && empty($this->system)) { $this->usex = $curSys["x"]; $this->usey = $curSys["y"]; $this->usez = $curSys["z"]; } else { // get last known coordinates $last_coords = last_known_system(); $this->usex = $last_coords["x"]; $this->usey = $last_coords["y"]; $this->usez = $last_coords["z"]; $this->is_unknown = " *"; } /** * If we still don't have valid coordinates, center on Sol */ if (!valid_coordinates($this->usex, $this->usey, $this->usez)) { $this->usex = "0"; $this->usey = "0"; $this->usez = "0"; $this->is_unknown = " *"; } }
/** * Count how many jumps user has made since last known * coordinates and return a "fuzziness" factor * * @return array|bool $value range in ly to use for reference systems * @author Mauri Kujala <*****@*****.**> */ function fuzziness() { $res = mysqli_query($GLOBALS["___mysqli_ston"], "\tSELECT system_name\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM user_visited_systems\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tORDER BY visit DESC\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tLIMIT 30") or write_log(mysqli_error($GLOBALS["___mysqli_ston"]), __FILE__, __LINE__); $count = mysqli_num_rows($res); if ($count > 0) { $last_known = last_known_system(true); $last_known_name = $last_known["name"]; if (!empty($last_known_name)) { $num = 0; $value = array(); while ($arr = mysqli_fetch_assoc($res)) { $visited_system_name = $arr["system_name"]; if ($visited_system_name == $last_known_name) { break; } else { $num++; } } $num = $num == 0 ? 1 : $num; $fuzziness = $num * 40 + 20; // assuming a range of 40 ly per jump (+ 20 ly just to be on the safe side) $value["fuzziness"] = $fuzziness; $value["system_name"] = $last_known_name; $value["x"] = $last_known["x"]; $value["y"] = $last_known["y"]; $value["z"] = $last_known["z"]; return $value; } else { return false; } } else { return false; } }