function scanrange_calculation() { $time = time(); $sth = mysql_query("select id from constellations"); if (!$sth) { echo "ERR::GET_CONST\n"; } // mop: da landen alle scanranges drinn $scanranges = array(); while (list($cid) = mysql_fetch_row($sth)) { // mop: alle planeten der constellation holen $sth1 = mysql_query("select p.id,s.id,p.uid from planets p, systems s where p.sid=s.id and s.cid={$cid} and uid!=0"); if (!$sth1) { echo "ERR::GET_PLANETS\n"; } while (list($pid, $sid, $uid) = mysql_fetch_row($sth1)) { // mop: für alle planeten die maximale scanrange raussuchen und schauen ob die grösser als die // bisherige scanrange pro system is $pid_scanrange = get_max_scan_range_by_pid($pid); if ($scanranges[$sid][$uid] < $pid_scanrange) { $scanranges[$sid][$uid] = $pid_scanrange; } } // mop: jetzt durchgehen und in db speichern foreach ($scanranges as $sid => $uid_scan) { foreach ($uid_scan as $uid => $range) { $sth1 = mysql_query("replace into __scanranges_" . $cid . " (sid,uid,type,range,last_update) values ('" . $sid . "','" . $uid . "','0','" . $range . "','" . $time . "')"); if (!$sth1) { echo "ERR::REPLACE SCANRANGES\n"; } } } // mop: scanranges resetten für fleets $scanranges = array(); $sth1 = mysql_query("select f.fid,f.sid,f.uid from fleet_info f,systems s where s.id=f.sid and s.cid=" . $cid); if (!$sth1) { echo "ERR::GET_FLEETS_SCAN"; } while (list($fid, $sid, $uid) = mysql_fetch_row($sth1)) { // mop: für alle planeten die maximale scanrange raussuchen und schauen ob die grösser als die // bisherige scanrange pro system is $fid_scanrange = get_max_scanrange_by_fid($fid); if ($scanranges[$sid][$uid] < $fid_scanrange) { $scanranges[$sid][$uid] = $fid_scanrange; } } // mop: jetzt durchgehen und in db speichern foreach ($scanranges as $sid => $uid_scan) { foreach ($uid_scan as $uid => $range) { $sth1 = mysql_query("replace into __scanranges_" . $cid . " (sid,uid,type,range,last_update) values ('" . $sid . "','" . $uid . "','1','" . $range . "','" . $time . "')"); if (!$sth1) { echo "ERR::REPLACE SCANRANGES\n"; } } } // mop: zum schluss alte einträge raushauen $sth1 = mysql_query("delete from __scanranges_" . $cid . " where last_update < {$time}"); } }
function get_minimap_values($colors = true, $scanrange = true, $fleets = true) { global $uid; $user_alliance = get_alliance($uid); if (!$colors) { $scanrange = false; } $sth = mysql_query("select id, uid from planets where sid=" . $this->id . " and uid != 0"); if (!$sth) { return 0; } while ($its_planets = mysql_fetch_array($sth)) { $its_uid = $its_planets["uid"]; $its_id = $its_planets["id"]; // minimap_colors if ($colors) { if ($its_uid == $uid) { $this->minimap_colors[] = "lime"; $this->scan = true; // scanrange if ($scanrange) { $its_scanradius = get_max_scan_range_by_pid($its_id); } } elseif (is_allied($its_uid, $uid)) { $this->minimap_colors[] = "yellow"; $this->scan = true; // scanrange if ($scanrange) { $its_scanradius = get_max_scan_range_by_pid($its_id); } } else { $planet_alliance = get_alliance($its_uid); if ($user_alliance && $planet_alliance && is_friendly($user_alliance, $planet_alliance)) { $this->minimap_colors[] = "orange"; } elseif ($user_alliance && $planet_alliance && is_enemy($user_alliance, $planet_alliance)) { $this->minimap_colors[] = "red"; } else { $this->minimap_colors[] = "blue"; } } } // max scanrange ermitteln if ($its_scanradius && $this->scanradius < $its_scanradius) { $this->scanradius = $its_scanradius; } } // minimap_fleets if ($fleets) { $sth = mysql_query("select distinct(uid) as unique_uid from fleet_info where sid=" . $this->id); if (!$sth || !mysql_num_rows($sth)) { return 0; } while ($its_fleets = mysql_fetch_array($sth)) { $its_uid = $its_fleets["unique_uid"]; if ($its_uid == $uid) { $this->minimap_fleets[] = "lime"; $this->scan = true; // scanrange der Flotten if ($scanrange) { $fleet_scanradius = get_max_fleet_scanrange_by_sid($this->id); } } elseif (is_allied($its_uid, $uid)) { $this->minimap_fleets[] = "yellow"; $this->scan = true; // scanrange der Flotten if ($scanrange) { $fleet_scanradius = get_max_fleet_scanrange_by_sid($this->id); } } else { $fleet_alliance = get_alliance($its_uid); if ($user_alliance && $fleet_alliance && is_friendly($user_alliance, $fleet_alliance)) { $this->minimap_fleets[] = "orange"; } elseif ($user_alliance && $fleet_alliance && is_enemy($user_alliance, $fleet_alliance)) { $this->minimap_fleets[] = "red"; } else { $this->minimap_fleets[] = "blue"; } } if ($fleet_scanradius && $this->scanradius < $fleet_scanradius) { $this->scanradius = $fleet_scanradius; } } // Scanrange if ($scanrange) { // Systeme in Scanrange $visible_systems = get_systems_in_scanrange($this->id, $this->scanradius); if (is_array($visible_systems)) { for ($j = 0; $j < sizeof($visible_systems); $j++) { $this->systems_in_scanrange[] = new MINIMAP_SYSTEM($visible_systems[$j]); } } for ($j = 0; $j < sizeof($this->systems_in_scanrange); $j++) { $this->systems_in_scanrange[$j]->get_minimap_values(true, false, true); $this->systems_in_scanrange[$j]->make_visible(); } } } // ende WHILE if (isset($this->minimap_colors[0])) { $this->minimap_colors = array_unique($this->minimap_colors); } if (isset($this->minimap_fleets[0])) { $this->minimap_fleets = array_unique($this->minimap_fleets); } }
function get_max_scanrange_by_sid($sid, $user_id = 0) { global $uid; if (!$user_id) { $user_id = $uid; } $sth = mysql_query("select id from planets where sid='{$sid}' and uid != 0"); if (!$sth || !mysql_num_rows($sth)) { return 0; } while ($its_planets = mysql_fetch_array($sth)) { $its_user = get_uid_by_pid($its_planets["id"]); if ($its_user == $user_id || is_allied($its_user, $user_id)) { $scanrange[] = get_max_scan_range_by_pid($its_planets["id"]); } } if (is_array($scanrange)) { rsort($scanrange); $max_scanrange = $scanrange[0]; } else { $max_scanrange = 0; } return $max_scanrange; }