Advertisement
Guest User

Untitled

a guest
Oct 28th, 2013
537
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.02 KB | None | 0 0
  1. """
  2. Copyleft 2013  ISD LackOfFaith; Do whatever with this
  3. """
  4.  
  5. import sqlite3, sys
  6.  
  7. conn = sqlite3.connect(sys.argv[1])
  8. db = conn.cursor()
  9.  
  10. def distance(point1, point2):
  11.     return (
  12.         (point1[0]-point2[0])**2 +
  13.         (point1[1]-point2[1])**2 +
  14.         (point1[2]-point2[2])**2
  15.         )**0.5
  16.        
  17. def m_to_au(m):
  18.     return m/149597870700.
  19.  
  20. def gate_name(g_id):
  21.     Q_GATE_NAME = """
  22.        select mapsolarsystems.solarsystemname
  23.        from mapsolarsystems
  24.        inner join invitems, mapjumps on
  25.            invitems.locationid=mapsolarsystems.solarsystemid and
  26.            mapjumps.celestialid=invitems.itemid
  27.        where mapjumps.stargateid=?"""
  28.     results = db.execute(Q_GATE_NAME, [g_id])
  29.     if results:
  30.         return results.next()[0]
  31.     else:
  32.         return None
  33.  
  34. def system_name(s_id):
  35.     Q_SYSTEM_NAME = """
  36.        select mapsolarsystems.solarsystemname
  37.        from mapsolarsystems
  38.        where mapsolarsystems.solarsystemid=?"""
  39.     results = db.execute(Q_SYSTEM_NAME, [s_id])
  40.     if results:
  41.         return results.next()[0]
  42.     else:
  43.         return None
  44.  
  45.  
  46. Q_STARGATE = """
  47.        select invitems.itemid, invitems.locationid
  48.        from invitems
  49.        inner join invtypes, invgroups on
  50.              invitems.typeid=invtypes.typeid and
  51.              invtypes.groupid=invgroups.groupid
  52.        where invgroups.groupname="Stargate" """;
  53.  
  54.  
  55. system_gates = {}
  56.  
  57. for gate_id, system_id in db.execute(Q_STARGATE):
  58.     if system_id not in system_gates:
  59.         system_gates[system_id] = []
  60.     system_gates[system_id].append(gate_id)
  61.  
  62.  
  63. Q_GATE_LOCATION = """
  64.        select mapdenormalize.itemid, mapdenormalize.x, mapdenormalize.y, mapdenormalize.z
  65.        from mapdenormalize
  66.        inner join invitems on
  67.            invitems.itemid=mapdenormalize.itemid
  68.        where invitems.itemid=?
  69.        """
  70.  
  71. tmpgates = system_gates[system_gates.keys()[200]]
  72.  
  73. global_max = 0
  74. global_gate1 = None
  75. global_gate2 = None
  76. global_system = None
  77.  
  78. for system_id in system_gates:
  79.     gate_coords = {}
  80.    
  81.     for gate_id in system_gates[system_id]:
  82.         gate_coords[gate_id] = db.execute(Q_GATE_LOCATION, [gate_id]).next()
  83.    
  84.     max_dist = 0
  85.     max_gate1 = None
  86.     max_gate2 = None
  87.    
  88.     for gate1 in gate_coords:
  89.         for gate2 in gate_coords:
  90.             dist = distance(gate_coords[gate1], gate_coords[gate2])
  91.             if dist > max_dist:
  92.                 max_dist = dist
  93.                 max_gate1 = gate1
  94.                 max_gate2 = gate2
  95.  
  96.     if max_dist:
  97.         print system_id, m_to_au(max_dist), gate_name(max_gate1), gate_name(max_gate2)
  98.  
  99.     if max_dist > global_max:
  100.         global_max = max_dist
  101.         global_gate1 = max_gate1
  102.         global_gate2 = max_gate2
  103.         global_system = system_id
  104.  
  105. print "Maximum gate-gate warp was..."
  106. print "\tin system %s" % system_name(global_system)
  107. print "\ta distance of %.2f AU" % m_to_au(global_max)
  108. print "\tfrom Stargate (%s) to Stargate (%s)" % (gate_name(global_gate1), gate_name(global_gate2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement