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_max_fleet_scanrange_by_sid($sid, $user_id = 0) { global $uid; if (!$user_id) { $user_id = $uid; } $sth = mysql_query("select fid from fleet_info where sid=" . $sid); if (!$sth || !mysql_num_rows($sth)) { return 0; } while ($its_fleets = mysql_fetch_array($sth)) { $its_user = get_uid_by_fid($its_fleets["fid"]); if ($its_user == $user_id || is_allied($its_user, $user_id)) { $scanrange[] = get_max_scanrange_by_fid($its_fleets["fid"]); } } if (is_array($scanrange)) { rsort($scanrange); $max_scanrange = $scanrange[0]; } else { $max_scanrange = 0; } return $max_scanrange; }