function scan_area($sector, $range) { $result = sql_query("SELECT * FROM s_sectors WHERE id={$sector}"); $sector = sql_fetchrow($result); echo "<table align=center border=1>\n"; echo " <tr><th colspan=4>Scanning from origin " . $sector['name'] . " ( " . $sector['distance'] . " / " . $sector['angle'] . " ) @ " . $range . " lightyears</th></tr>\n"; echo " <tr><td>Name</td><td>Race</td><td>D / A</td><td>Range</td></tr>\n"; $result = sql_query("SELECT * FROM g_vessels ORDER BY user_id"); while ($vessel = sql_fetchrow($result)) { $result2 = sql_query("SELECT * FROM s_species WHERE user_id = " . $vessel['user_id']); $race = sql_fetchrow($result2); if ($vessel['sector_id'] == 0) { $distance = calc_distance($sector['distance'], $sector['angle'], $vessel['distance'], $vessel['angle']); if ($distance <= $range) { echo "<tr><td>" . $vessel['name'] . " (" . $vessel['sector_id'] . ")</td><td>" . $race['name'] . "</td><td>" . $vessel['distance'] . " / " . $vessel['angle'] . "</td><td>" . $distance . "</td></tr>\n"; } } else { $result2 = sql_query("SELECT * FROM s_sectors WHERE id=" . $vessel['sector_id']); $vessel_sector = sql_fetchrow($result2); $distance = calc_distance($sector['distance'], $sector['angle'], $vessel_sector['distance'], $vessel_sector['angle']); if ($distance <= $range) { echo "<tr><td>" . $vessel['name'] . " (" . $vessel['sector_id'] . ")</td><td>" . $race['name'] . "</td><td>SECTOR: " . $vessel_sector['distance'] . " / " . $vessel_sector['angle'] . "</td><td>" . $distance . "</td></tr>\n"; } } } print "</table>"; print "<br><br>"; return; }
function rasterUTM_Map($UTMzoneUpLeft, $UTMlatZoneUpLeft, $MAP_TOP, $MAP_LEFT, $UTMzoneBottomRight, $UTMlatZoneBottomRight, $MAP_BOTTOM, $MAP_RIGHT, $rasterFilename, $pixelWidth = 0, $pixelHeight = 0) { global $moduleRelPath, $mapsPath; $this->MAP_TOP = $MAP_TOP; $this->MAP_LEFT = $MAP_LEFT; $this->MAP_BOTTOM = $MAP_BOTTOM; $this->MAP_RIGHT = $MAP_RIGHT; $this->UTMzoneUpLeft = $UTMzoneUpLeft; $this->UTMzoneBottomRight = $UTMzoneBottomRight; $this->UTMlatZoneUpLeft = $UTMlatZoneUpLeft; $this->UTMlatZoneBottomRight = $UTMlatZoneBottomRight; DEBUG("MAP", 1, "new rasterUTM_Map(): (right, left) :" . $MAP_RIGHT . " [" . $UTMzoneBottomRight . "] ," . $MAP_LEFT . "[" . $UTMzoneUpLeft . "]#<BR>"); if ($this->UTMzoneUpLeft == $this->UTMzoneBottomRight) { // one UTM zone -> simple $this->mapWidthMeters = $this->MAP_RIGHT - $this->MAP_LEFT; } else { // transform to latlon list($max_lon, $max_lat) = iutm($MAP_LEFT, $MAP_TOP, $UTMzoneUpLeft, $UTMlatZoneUpLeft); list($min_lon, $min_lat) = iutm($MAP_RIGHT, $MAP_BOTTOM, $UTMzoneBottomRight, $UTMlatZoneBottomRight); // TEST MANOLIS $this->min_lat = $min_lat; $BottomRight_zoneWidth = getUTMZoneWidth($min_lat); $this->MAP_RIGHT = $this->MAP_RIGHT + $BottomRight_zoneWidth; $this->UTMzoneBottomRight = $this->UTMzoneUpLeft; DEBUG("MAP", 1, "rasterUTM_Map: flight spans to multiple UTM zones<BR>"); DEBUG("MAP", 1, "rasterUTM_Map: min_lat:{$min_lat}, min_lon:{$min_lon}, max_lat:{$max_lat}, max_lon:{$max_lon} <BR>"); DEBUG("MAP", 1, "rasterUTM_Map: MAP (right, left) :" . $this->MAP_RIGHT . " [" . $this->UTMzoneBottomRight . "] ," . $MAP_LEFT . "[" . $UTMzoneUpLeft . "]#<BR>"); $totalWidth1 = calc_distance($min_lat, $min_lon, $min_lat, $max_lon); $totalWidth2 = calc_distance($max_lat, $min_lon, $max_lat, $max_lon); $totalWidth = max($totalWidth1, $totalWidth2); $this->mapWidthMeters = $totalWidth; } $this->mapHeightMeters = $this->MAP_TOP - $this->MAP_BOTTOM; if ($rasterFilename == "") { $this->pixelWidth = $pixelWidth; $this->pixelHeight = $pixelHeight; } else { $this->rasterFilename = $mapsPath . "/" . $rasterFilename; $this->img = 0; $this->img = @imagecreatefromjpeg($this->rasterFilename); if (!$this->img) { // failed to open jpeg $this->pixelWidth = 0; $this->pixelHeight = 0; // DEBUG("MAP",1,"jpg not found: ".$this->rasterFilename); } else { $this->pixelWidth = imagesx($this->img); $this->pixelHeight = imagesy($this->img); } } if ($this->pixelWidth > 0) { $this->metersPerPixel = $this->mapWidthMeters / $this->pixelWidth; } else { $this->metersPerPixel = 0; } // echo "metersPerPixel : ".$this->metersPerPixel."<BR>"; }
function sector_show_all_sectors($user_id) { assert(isset($user_id)); global $_RUN; $homesector = sector_get_sector(user_get_home_sector($user_id)); // Get all anomaly counts from the sectors the user has discovered. We DONT want to count // the anomalies that the user did not already discovered. Hence the big SQL statement :) $result = sql_query("SELECT a.sector_id, COUNT(*) AS qty FROM s_anomalies AS a, g_anomalies AS g WHERE g.user_id = " . $user_id . " AND ( FIND_IN_SET( a.id, g.csl_discovered_id ) OR FIND_IN_SET( a.id, g.csl_undiscovered_id) ) GROUP BY a.sector_id"); while ($count = sql_fetchrow($result)) { $anomaly_count[$count['sector_id']] = $count['qty']; } $result = sql_query("SELECT s.* FROM s_sectors AS s, g_sectors AS g WHERE g.user_id = " . $user_id . " AND FIND_IN_SET(s.id, g.csl_sector_id)"); while ($sector = sql_fetchrow($result)) { $distance = calc_distance($homesector['distance'], $homesector['angle'], $sector['distance'], $sector['angle']); if ($sector['user_id'] == 0) { $owner = '<font color=red>unclaimed</font>'; } else { $tmp = user_get_user($sector['user_id']); $owner = $tmp['race']; } $tmp = array(); $tmp['href'] = "sector.php?cmd=" . encrypt_get_vars("show") . "&sid=" . encrypt_get_vars($sector['id']); $tmp['id'] = $sector['sector']; $tmp['name'] = $sector['name']; $tmp['qty'] = $anomaly_count[$sector['id']]; $tmp['owner'] = $owner; $tmp['coordinate'] = $sector['distance'] . " / " . $sector['angle']; $tmp['distance'] = round($distance); $tmp['unround_distance'] = $distance; $sector_rows[] = $tmp; } uasort($sector_rows, "show_all_sectors_cmp"); print_subtitle("All known sectors and their planets"); foreach ($sector_rows as $sector) { $tmp = array(); $tmp['id'] = $sector['id']; $tmp['name'] = $sector['name']; $tmp['qty'] = $sector['qty']; $tmp['owner'] = $sector['owner']; $tmp['coordinate'] = $sector['coordinate']; $tmp['distance'] = $sector['distance']; $tmp['href'] = $sector['href']; $tmpvar[] = $tmp; } $template = new Smarty(); $template->debugging = true; help_set_template_vars($template); $template->assign("sectors", $tmpvar); if (isset($_REQUEST['pager_pos'])) { $template->assign("pager_pos", $_REQUEST['pager_pos']); } else { $template->assign("pager_pos", 0); } $template->assign("theme_path", $_RUN['theme_path']); $template->display($_RUN['theme_path'] . "/sectors-all.tpl"); }
function calc_sector_ticks($src_d, $src_a, $dst_d, $dst_a, $warp) { assert($src_d >= 0); assert($src_a >= 0 && $src_a <= 360000); assert($dst_d >= 0); assert($dst_a >= 0 && $dst_a <= 360000); assert($warp >= 0 && $warp <= 100); global $_CONFIG; if ($warp == 0) { return 0; } $ticks = calc_distance($src_d, $src_a, $dst_d, $dst_a); $ticks = $ticks * (100 / ($warp / 10) / 10); $ticks = round($ticks / $_CONFIG['warp_dividor']); return $ticks; }
function auto_defence_oasis($home_x, $home_y, $defence_unit, $defence_unit_speed) { global $server; $url = "http://{$server}/build.php?gid=16"; $ch = my_curl_init(); curl_setopt($ch, CURLOPT_URL, $url); $result = curl_exec($ch); curl_close($ch); $res = get_defence_oasis($result); print_r($res); if (empty($res)) { return false; } foreach ($res as &$a) { $x = $a[0]; $y = $a[1]; $remain = $a[2]; $arrive = $a[3]; $distance = calc_distance($home_x, $home_y, $x, $y); $need_time = 3600 * $distance / $defence_unit_speed; $wait_time = $remain - $need_time; array_push($a, $wait_time); } usort($res, "cmp"); print_r($res); $last_wait_time = 0; foreach ($res as $b) { $x = $b[0]; $y = $b[1]; $arrive = $b[3]; $wait_time = $b[4]; //print_r($a); // too late if ($wait_time < 0) { echo "wait time < 0\n"; continue; } // 20 minutes if ($wait_time - $last_wait_time > 1200) { echo "wait time - last wait time > 1200\n"; break; } $arrive2 = minus_time_str($arrive, 30); echo "raid {$x}, {$y} {$arrive2}\n"; raid($x, $y, array($defence_unit => 2), $arrive2); $last_wait_time = $wait_time; } }
function getUTMZoneWidth($lat) { // central meridian of zone ? $central = 0; $zone_distance = calc_distance($lat, $central, $lat, $central + 6); DEBUG("UTM", 64, "Zone_distance at lat: {$lat} = {$zone_distance}<br>"); return $zone_distance; }
function getMapFromServer($num = 0) { global $moduleRelPath, $mapServerActive; if (!$mapServerActive) { return; } require_once dirname(__FILE__) . "/CL_map.php"; $filename = $this->getIGCFilename(1); $lines = @file($filename); if (!$lines) { return; } $i = 0; $min_lat = 1000; $max_lat = -1000; $min_lon = 1000; $max_lon = -1000; foreach ($lines as $line) { $line = trim($line); if (strlen($line) == 0) { continue; } if ($line[0] == 'B') { $thisPoint = new gpsPoint($line, $this->timezone); if ($thisPoint->lat > $max_lat) { $max_lat = $thisPoint->lat; } if ($thisPoint->lat < $min_lat) { $min_lat = $thisPoint->lat; } if ($thisPoint->lon > $max_lon) { $max_lon = $thisPoint->lon; } if ($thisPoint->lon < $min_lon) { $min_lon = $thisPoint->lon; } $i++; } } if ($i == 0) { return; } // no B records found $lat_diff = $max_lat - $min_lat; $lon_diff = $max_lon - $min_lon; DEBUG("MAP", 1, "MAP min_lat: {$min_lat}, min_lon: {$min_lon}, max_lat: {$max_lat}, max_lon: {$max_lon} <BR>"); if ($lat_diff > 20 || $lon_diff > 20) { return; } // too much list($MAP_LEFT, $MAP_TOP, $UTMzone, $UTMlatZone) = utm(-$max_lon, $max_lat); list($MAP_RIGHT, $MAP_BOTTOM, $UTMzone2, $UTMlatZone2) = utm(-$min_lon, $min_lat); $totalWidth1 = calc_distance($min_lat, $min_lon, $min_lat, $max_lon); $totalWidth2 = calc_distance($max_lat, $min_lon, $max_lat, $max_lon); $totalWidth = max($totalWidth1, $totalWidth2); $totalWidth_initial = $totalWidth; $totalHeight = $MAP_TOP - $MAP_BOTTOM; DEBUG("MAP", 1, "MAP (right, left) :" . $MAP_RIGHT . " [" . $UTMzone2 . "] ," . $MAP_LEFT . "[" . $UTMzone . "]<BR>"); DEBUG("MAP", 1, "MAP (top, bottom) :" . $MAP_TOP . " ," . $MAP_BOTTOM . "<BR>"); DEBUG("MAP", 1, "MAP (witdh,height) :" . $totalWidth . "," . $totalHeight . "<BR>"); if ($totalWidth > $totalHeight) { // Landscape style DEBUG("MAP", 1, "Landscape style <BR>"); DEBUG("MAP", 1, "totalWidth: {$totalWidth}, totalHeight: {$totalHeight}, totalHeight/totalWidth: " . $totalHeight / $totalWidth . "<br>"); if ($totalHeight / $totalWidth < 3 / 4) { $totalHeight = 3 / 4 * $totalWidth; } } else { // portait style DEBUG("MAP", 1, "Portait style <BR>"); DEBUG("MAP", 1, "totalWidth: {$totalWidth}, totalHeight: {$totalHeight}, totalWidth/totalHeight: " . $totalWidth / $totalHeight . "<br>"); if ($totalWidth / $totalHeight < 3 / 4) { $totalWidth = 3 / 4 * $totalHeight; } } $marginHor = 2000 + floor($totalWidth / 20000) * 1000 + ($totalWidth - $totalWidth_initial) / 2; //in meters $marginVert = 2000 + floor($totalHeight / 20000) * 1000 + ($totalHeight - ($MAP_TOP - $MAP_BOTTOM)) / 2; //in meters if ($marginHor > $marginVert) { // landscape style ... if ($marginVert / $marginHor < 3 / 4) { $marginVert = 3 / 4 * $marginHor; } } else { // portait style if ($marginHor / $marginVert < 3 / 4) { $marginHor = 3 / 4 * $marginVert; } } DEBUG("MAP", 1, "marginHor: {$marginHor}, marginVert:{$marginVert} <br>"); $flMap = new flightMap($UTMzone, $UTMlatZone, $MAP_TOP + $marginVert, $MAP_LEFT - $marginHor, $UTMzone2, $UTMlatZone2, $MAP_BOTTOM - $marginVert, $MAP_RIGHT + $marginHor, 600, 800, $this->getIGCFilename(1), $this->getMapFilename(0), $this->is3D()); DEBUG("MAP", 1, "MAP Required m/pixel = " . $flMap->metersPerPixel . "<br>"); $flMap->drawFlightMap(); }
function scan_anomalies($vessel_id, $range, $scans, $i) { list($src_distance, $src_angle) = get_correct_da($vessel_id); // Scan for sectors $result = sql_query("SELECT * FROM s_sectors ORDER BY name"); while ($sector = sql_fetchrow($result)) { $distance = calc_distance($src_distance, $src_angle, $sector['distance'], $sector['angle']); if ($distance <= $range and $distance != 0) { $scans[$i]['str'] = "<tr class=bl><td> Sector </td><td> " . $sector['name'] . " </td><td> " . $sector['distance'] . " / " . $sector['angle'] . " </td><td> " . $distance . " </td></tr>\n"; $scans[$i]['range'] = $distance; $i++; } } // Scan for wormhole endpoints $result = sql_query("SELECT * FROM w_wormhole"); while ($worm = sql_fetchrow($result)) { $tmp = anomaly_get_anomaly($worm['id']); $distance = calc_distance($src_distance, $src_angle, $worm['distance'], $worm['angle']); if ($distance <= $range and $distance != 0) { $scans[$i]['str'] = "<tr class=bl><td> Wormhole </td><td> " . $tmp['name'] . " </td><td> " . $worm['distance'] . " / " . $worm['angle'] . " </td><td> " . $distance . " </td></tr>\n"; $scans[$i]['range'] = $distance; $i++; } } return array($scans, $i); }
require_once dirname(__FILE__) . "/CL_map.php"; $min_lat = $_GET[min_lat] + 0; $max_lat = $_GET[max_lat] + 0; $min_lon = $_GET[min_lon] + 0; $max_lon = $_GET[max_lon] + 0; $lat_diff = $max_lat - $min_lat; $lon_diff = $max_lon - $min_lon; DEBUG("MAP", 1, "MAP min_lat: {$min_lat}, min_lon: {$min_lon}, max_lat: {$max_lat}, max_lon: {$max_lon} <BR>"); if ($lat_diff > 20 || $lon_diff > 20) { return; } // too much list($MAP_LEFT, $MAP_TOP, $UTMzone, $UTMlatZone) = utm(-$max_lon, $max_lat); list($MAP_RIGHT, $MAP_BOTTOM, $UTMzone2, $UTMlatZone2) = utm(-$min_lon, $min_lat); $totalWidth1 = calc_distance($min_lat, $min_lon, $min_lat, $max_lon); $totalWidth2 = calc_distance($max_lat, $min_lon, $max_lat, $max_lon); $totalWidth = max($totalWidth1, $totalWidth2); $totalWidth_initial = $totalWidth; $totalHeight = $MAP_TOP - $MAP_BOTTOM; DEBUG("MAP", 1, "MAP (right, left) :" . $MAP_RIGHT . " [" . $UTMzone2 . "] ," . $MAP_LEFT . "[" . $UTMzone . "]<BR>"); DEBUG("MAP", 1, "MAP (top, bottom) :" . $MAP_TOP . " ," . $MAP_BOTTOM . "<BR>"); DEBUG("MAP", 1, "MAP (witdh,height) :" . $totalWidth . "," . $totalHeight . "<BR>"); if ($totalWidth > $totalHeight) { // Landscape style DEBUG("MAP", 1, "Landscape style <BR>"); DEBUG("MAP", 1, "totalWidth: {$totalWidth}, totalHeight: {$totalHeight}, totalHeight/totalWidth: " . $totalHeight / $totalWidth . "<br>"); if ($totalHeight / $totalWidth < 3 / 4) { $totalHeight = 3 / 4 * $totalWidth; } } else { // portait style
function get_nearest_airport($data) { $x = $data['user']['x']; $y = $data['user']['y']; $closeness = 1.0; $nearest = NULL; $nearest_dist = 0; $others = array(); //TODO: Sanitize this! Toss geolookups into Db. $lower_x = (double) $x - $closeness; $lower_y = (double) $y - $closeness; $upper_x = (double) $x + $closeness; $upper_y = (double) $y + $closeness; $query = "select * from airports where x >= {$lower_x} and x <= {$upper_x} and y >= {$lower_y} and y <= {$upper_y}"; $db = new Db(); $sites = $db->performQuery($query)['data']; if (empty($sites)) { throw new Exception("You don't appear to be at an airport. Or near one. Or even within 70 miles of a far one. Awkward :/"); } foreach ($sites as $site) { $dist = calc_distance(array('x' => $x, 'y' => $y), array('x' => $site['x'], 'y' => $site['y'])); $site['dist'] = $dist; if (empty($nearest) || $dist < $nearest_dist) { if (!empty($nearest)) { $others[] = $nearest; } $nearest = $site; $nearest_dist = $dist; continue; } else { $others[] = $site; } } $data['nearest'] = $nearest; $data['others'] = $others; return $data; }
function calc_all_distance($res) { $user_id = get_sess_userid(); $user_lat = get_session("position_y"); $user_long = get_session("position_x"); $deal = false; $isNull = empty($user_lat) || empty($user_long); if (is_array($res)) { if (array_key_exists("user_id", $res)) { if ($res["user_id"] == $user_id) { $res["distance_to_me"] = 0; $deal = true; } } if (!$deal && array_key_exists("position_x", $res) && array_key_exists("position_y", $res)) { $x = $res["position_x"]; $y = $res["position_y"]; if ($isNull || empty($x) || empty($y)) { $res["distance_to_me"] = rand(1000, 100000); $deal = true; } else { $res["distance_to_me"] = calc_distance($y, $x, $user_lat, $user_long); $deal = true; } } if (!$deal) { foreach ($res as $key => $value) { $isSameUser = false; if (array_key_exists("user_id", $value)) { if ($value["user_id"] == $user_id) { $res[$key]["distance_to_me"] = 0; $isSameUser = true; } } if (!$isSameUser && array_key_exists("position_x", $value) && array_key_exists("position_y", $value)) { $x = $value["position_x"]; $y = $value["position_y"]; if ($isNull || empty($x) || empty($y)) { $res[$key]["distance_to_me"] = rand(1000, 100000); } else { $res[$key]["distance_to_me"] = calc_distance($y, $x, $user_id, $user_long); } } } } } return $res; }