#!/usr/bin/python-gd # # File xswmap.py # Title XSW map generator # Version 0.4.2 # Authors # Sverre Stoltenberg # Stein Vråle # import xswob, gd, string, re ### Config # Paths base_dir = "/home/swserv/universe/" base_url = "/" db_path = "db/" www_path = "public_html/" cgi_path = "cgi-bin/" map_path = www_path + "map/" universe_id = "generic" universe_name = "terminus" #universe_id = "universe" universe_file = base_dir + db_path + universe_id + "_out.unv" largemap_file = base_dir + map_path + universe_id + ".png" minimap_file = base_dir + map_path + universe_id + "-mini.png" imagemap_file = base_dir + map_path + universe_id + "-map.html" object_url = "/cgi-bin/PlanetInfo.pl?"; # Universe x_sectors = 3 y_sectors = 3 x_pixels = 1024 y_pixels = 1024 # Options ### Get options def main(): ########### type = None x = None y = None tmpx = None tmpy = None size = None # print "Creating xswobjects from universe file" t = xswob.xswob(universe_file) # print "Now drawing the map..." imap = open(imagemap_file,'w') #print imap # HTML head imap.write("\n") imap.write("\n") imap.write("XSW Universe Map: %s \n" % universe_name) imap.write("\n") # imap.write("\n") imap.write("\n") imap.write("\n") imap.write("\n") imap.write("\n") scale_factor = 0.166; img = gd.image((x_pixels,y_pixels)) black = img.colorAllocate((0,0,0)) white = img.colorAllocate((255,255,255)) red = img.colorAllocate((255,0,0)) green = img.colorAllocate((0,255,0)) blue = img.colorAllocate((0,0,255)) yellow = img.colorAllocate((255,255,0)) cyan = img.colorAllocate((0,255,255)) purple = img.colorAllocate((255,0,255)) gray50 = img.colorAllocate((127,127,127)) x_size = x_pixels / x_sectors y_size = y_pixels / y_sectors # horisontal sector lines for x in [0,1,2]: img.line( (x * x_size , 0) , (x * x_size ,y_pixels), gray50) # vertical sector lines for y in [0,1,2]: img.line( (0 , y * y_size) , (x_pixels , y * y_size), gray50) color = white # FIXME: include a check on sectors. # Plot the universe for i in t.xswob: try: # Fixme: get rid of split... xsw_x = int(string.split(i['CoordX'], ".")[0]) xsw_y = int(string.split(i['CoordY'], ".")[0]) xsw_sect_x = int(string.split(i['SectX'], ".")[0]) xsw_sect_y = int(string.split(i['SectY'], ".")[0]) x = int((xsw_x + 1024 + (xsw_sect_x * 2048 )) * scale_factor) y = int((y_sectors * 2048 - (xsw_y + 1024 + (xsw_sect_y * 2048 ))) * scale_factor) #print "%s (%d, %d)" % (i['obid'], x, y) #print " (%s, %s)" % (i['CoordX'], i['CoordY']) type = int(i['Type']) if type == 11: # Nebula size = int ((int(i['Size']) / 1000) / 2); img.arc((x,y),(size, size), 0, 360 , purple) imap.write("\"%s\"\n" % (object_url,i['obid'],x-2,y-2,x+2,y+2,i['Name'])) elif type == 10: if i.has_key('Empire') == 1: if i['Empire'] == 'CMC': color = red elif i['Empire'] == 'TGI': color = green elif i['Empire'] == 'PKU': color = yellow elif i['Empire'] == 'WFG': color = blue elif i['Empire'] == 'BIT': color = gray50 elif i['Empire'] == 'KIL': color = gray50 elif i['Empire'] == 'MEG': color = gray50 elif i['Empire'] == 'GIG': color = gray50 else: color = gray50 else: color = gray50 if re.search("Star", i['Name']): img.rectangle((x-1,y-1),(x+1, y+1), color) img.fill((x,y), color) elif re.search('HomePlanet', i['Name']): img.arc((x,y),(5,5), 0, 360, color) img.fill((x,y), color) # img.arc((x,y),(250, 250), 0, 360 , color) elif re.search('Planet', i['Name']): img.arc((x,y), (3,3), 0, 360, color) img.fill((x,y), color) elif re.search('Astroid', i['Name']): img.arc((x,y), (3,3), 0, 360, color) img.fill((x,y), color) else: img.arc((x,y), (3,3), 0, 360, gray50) img.fill((x,y), color) # HTML image map imap.write("\"%s\"\n" % (object_url,i['obid'],x-2,y-2,x+2,y+2,i['Name'])) elif type == 3: if i.has_key('Empire') == 1: if i['Empire'] == 'CMC': color = red elif i['Empire'] == 'TGI': color = green elif i['Empire'] == 'PKU': color = yellow elif i['Empire'] == 'WFG': color = blue else: color = gray50 else: color = gray50 #if re.search("Station", i['Name']): #img.rectangle((x-3,y-3),(x+3, y+3), color) #img.fill((x,y), color) #img.arc((x,y),(50, 50), 0, 360 , color) # HTML image map # imap.write("\"%s\"\n" % (object_url,i['obid'],x-2,y-2,x+2,y+2,i['Name'])) #if re.search("HeadQuarter", i['Name']): #img.rectangle((x-3,y-3),(x+3, y+3), color) #img.fill((x,y), color) #img.arc((x,y),(100, 100), 0, 360 , color) # HTML image map #imap.write("\"%s\"\n" % (object_url,i['obid'],x-2,y-2,x+2,y+2,i['Name'])) #if re.search("Mine", i['Name']): #img.rectangle((x-1,y-1),(x+1, y+1), color) #img.fill((x,y), color) #img.arc((x,y),(10, 10), 0, 360 , color) # HTML image map #imap.write("\"%s\"\n" % (object_url,i['obid'],x-2,y-2,x+2,y+2,i['Name'])) elif type == 4: if i.has_key('Empire') == 1: if i['Empire'] == 'CMC': color = red elif i['Empire'] == 'TGI': color = green elif i['Empire'] == 'PKU': color = yellow elif i['Empire'] == 'WFG': color = blue else: color = gray50 elif type == 1: if re.search('System', i['Name']): img.arc((x,y), (5,5), 0, 360, white) img.fill((x,y), white) #img.arc((x,y), (25,25), 0, 360, white) else: # do nothing color = gray50 # elif type == 13: # #Wormhole # img.arc((x,y), (3,3), 0, 360, cyan) # img.fill((x,y), cyan) except: print "wrong key in object %s" % (i['obid']) # HTML end imap.write("\n") imap.write("\n") imap.write("\n") imap.close() smaller = gd.image(img, (1024, 1024)) gray50 = smaller.colorAllocate((127,127,127)) smaller.line((0,512), (1024,512), gray50) smaller.line((512,0), (512,1024), gray50) smaller.writePng(minimap_file) img.writePng(largemap_file) main() #pdb.run(main())