def GetShipList(dir = None): import nt import strop if (not dir is None): loaddir = dir else: loaddir = "scripts\Custom" ships = [] f = nt.open(loaddir + "\ships.txt", nt.O_RDONLY) l = nt.lseek((f, 0, 2)) nt.lseek((f, 0, 0)) s = nt.read((f, l)) list = strop.split(s) nt.close(f) for ship in list: s = strop.split(ship, '.') if (len(s)>1) and ((s[-1] == 'pyc') or (s[-1] == 'py')): shipname = s[0] pModule = __import__('ships.'+shipname) if (hasattr(pModule, 'GetShipStats')): stats = pModule.GetShipStats() if (shipname != '__init__') and (ships.count([shipname, stats["Name"]]) == 0): ships.append([shipname, stats["Name"]]) ships.sort() return ships
def RebuildLoadMenu(): import nt import strop # load both directorys, where we can find Missions here. list = nt.listdir('scripts\Custom\QuickBattleGame') + nt.listdir('scripts\Custom\QuickBattleGame\Missions') files = [] for file in list: s = strop.split(file, '.') if (len(s)>1) and ((s[-1] == 'pyc') or (s[-1] == 'py')): filename = s[0] try: pModule = __import__('Custom.QuickBattleGame.Missions.'+filename) except: pModule = __import__('Custom.QuickBattleGame.'+filename) if (hasattr(pModule, 'gVersion')): if (files.count(filename)==0): files.append(filename) pSet = App.g_kSetManager.GetSet('bridge') pSaffi = App.CharacterClass_GetObject(pSet, 'XO') g_pLoadMenu.KillChildren() for file in files: button = CreateBridgeMenuButton(App.TGString(file), Lib.Ambiguity.getEvent("ET_SELECT_FILE"), file, pSaffi) button.SetUseUIHeight(0) g_pLoadMenu.AddChild(button) g_pLoadMenu.ResizeToContents() g_pLoadWindow.Layout()
def _import_hook(self, fqname, globals=None, locals=None, fromlist=None): """Python calls this hook to locate and import a module.""" parts = strop.split(fqname, '.') # determine the context of this import parent = self._determine_import_context(globals) # if there is a parent, then its importer should manage this import if parent: module = parent.__importer__._do_import(parent, parts, fromlist) if module: return module # has the top module already been imported? try: top_module = sys.modules[parts[0]] except KeyError: # look for the topmost module top_module = self._import_top_module(parts[0]) if not top_module: # the topmost module wasn't found at all. raise ImportError, 'No module named ' + fqname # fast-path simple imports if len(parts) == 1: if not fromlist: return top_module if not top_module.__dict__.get('__ispkg__'): # __ispkg__ isn't defined (the module was not imported by us), # or it is zero. # # In the former case, there is no way that we could import # sub-modules that occur in the fromlist (but we can't raise an # error because it may just be names) because we don't know how # to deal with packages that were imported by other systems. # # In the latter case (__ispkg__ == 0), there can't be any sub- # modules present, so we can just return. # # In both cases, since len(parts) == 1, the top_module is also # the "bottom" which is the defined return when a fromlist # exists. return top_module importer = top_module.__dict__.get('__importer__') if importer: return importer._finish_import(top_module, parts[1:], fromlist) # If the importer does not exist, then we have to bail. A missing # importer means that something else imported the module, and we have # no knowledge of how to get sub-modules out of the thing. raise ImportError, 'No module named ' + fqname
def GetSystemList(dir = None): import nt import strop if (not dir is None): loaddir = dir else: loaddir = "scripts\Custom" systems = [] f = nt.open(loaddir + "\systems.txt", nt.O_RDONLY) l = nt.lseek((f, 0, 2)) nt.lseek((f, 0, 0)) s = nt.read((f, l)) list = strop.split(s) nt.close(f) for system in list: s = strop.split(system, '.') if (len(s)==1): systemname = s[0] if (systemname == "Starbase12"): continue # Starbase12 will only crash us pModule = __import__('Systems.Starbase12.Starbase') elif (systemname == "DryDock"): pModule = __import__('Systems.DryDock.DryDockSystem') elif (systemname == "QuickBattle"): pModule = __import__('Systems.QuickBattle.QuickBattleSystem') else: pModule = __import__('Systems.'+systemname+'.'+systemname) if (hasattr(pModule, 'CreateMenus')): systems.append(systemname) systems.sort() return systems
def _setup(out_file, args): import strop in_file = args[0] # open file as specified in uu file and # assign out_file for later use i = in_file.readline() i = strop.strip(i) if 'begin' != i[:5]: raise IOError, 'input file not in UUencoded format' [dummy, mode, filename] = strop.split(i) mode = strop.atoi(mode, 8) out_file = open(filename,'w',mode) _out_file_orig = 0 return (out_file,_out_file_orig)
def RebuildShipSystemMenu(): pSet = App.g_kSetManager.GetSet('bridge') pSaffi = App.CharacterClass_GetObject(pSet, 'XO') g_pShipSystemMenu.KillChildren() for system in QBFile.g_pRegionListData: import strop s = strop.split(system, '.') button = CreateBridgeMenuButton(App.TGString(s[-1]), Lib.Ambiguity.getEvent("ET_SELECT_SHIPSYSTEM"), system, pSaffi) button.SetChoosable(1) if (system == g_pSelShipSystem): button.SetChosen(1) g_pShipSystemMenu.AddChild(button)
def _setup(out_file, args): import strop in_file = args[0] # open file as specified in uu file and # assign out_file for later use i = in_file.readline() i = strop.strip(i) if 'begin' != i[:5]: raise IOError, 'input file not in UUencoded format' [dummy, mode, filename] = strop.split(i) mode = strop.atoi(mode, 8) out_file = open(filename, 'w', mode) _out_file_orig = 0 return (out_file, _out_file_orig)
def SelectShipSystem(pObject, pEvent): if (not pEvent is None): selsystem = (App.TGStringEvent_Cast(pEvent)).GetCString() global g_pSelShipSystem g_pSelShipSystem = selsystem for system in QBFile.g_pRegionListData: import strop s = strop.split(system, '.') button = g_pShipSystemMenu.GetButtonW(App.TGString(s[-1])) if (not button is None): if (system == g_pSelShipSystem): button.SetChosen(1) else: button.SetChosen(0)
def RebuildRegionList(): pSet = App.g_kSetManager.GetSet('bridge') pSaffi = App.CharacterClass_GetObject(pSet, 'XO') g_pRegionList.KillChildren() QBFile.g_pRegionListData.sort() for region in QBFile.g_pRegionListData: import strop s = strop.split(region, '.') button = CreateBridgeMenuButton(App.TGString(s[-1]), Lib.Ambiguity.getEvent("ET_SELECT_REGIONLIST"), region, pSaffi) button.SetUseUIHeight(0) g_pRegionList.AddChild(button) g_pRegionList.ResizeToContents() g_pRegionListWindow.Layout()
def WriteSetup(filename): gBridge = g_sBridge gSystem = [] gShips = [] for system in g_pRegionListData: import strop s = strop.split(system, '.') gSystem.append([s[0], s[1], '']) keys = g_pShipListData.keys() for key in keys: gShips.append(g_pShipListData[key]) import nt try: if (filename == "QBSetup"): nt.remove("scripts\Custom\QuickBattleGame\\" + filename + ".py") else: nt.remove("scripts\Custom\QuickBattleGame\Missions\\" + filename + ".py") except OSError: pass import QuickBattle try: if (filename == "QBSetup"): # We have to save the mainsetup in the main directory file = nt.open('scripts\Custom\QuickBattleGame\\' + filename + '.py', nt.O_CREAT | nt.O_RDWR) else: # rest here. file = nt.open('scripts\Custom\QuickBattleGame\Missions\\' + filename + '.py', nt.O_CREAT | nt.O_RDWR) nt.write(file, "gVersion=" + repr(QuickBattle.g_version) + "\n") nt.write(file, "gSystem=" + repr(gSystem) + "\n") nt.write(file, "gBridge=" + repr(gBridge) + "\n") nt.write(file, "gShips=" + repr(gShips) + "\n") import plugin nt.write(file, "gPluginData=" + repr(plugin.gPluginData) + "\n") nt.close(file) except: return 0 return -1
def ChangeGlobals(): debug(__name__ + ", ChangeGlobals") global gBridge gBridge = QBGUI.g_Bridge global gSystem gSystem = [] for system in QBFile.g_pRegionListData: import strop s = strop.split(system, '.') gSystem.append([s[0], s[1], '']) global gShips gShips = [] keys = QBFile.g_pShipListData.keys() for key in keys: ship = QBFile.g_pShipListData[key] gShips.append(ship)
def UpdateShipList(pObject, pEvent): if (not g_pSelectedShip is None): ship = QBFile.g_pShipListData[g_pSelectedShip] ship['name'] = g_pEdName.GetCString() del QBFile.g_pShipListData[g_pSelectedShip] global g_pSelectedShip g_pSelectedShip = ship['name'] QBFile.g_pShipListData[g_pSelectedShip] = ship QBFile.g_pShipListData[g_pSelectedShip] ship['ailevel'] = g_iSelectedAILevel if (g_iSelectedGroup == 0.0): ship['group'] = 'neutral' elif (g_iSelectedGroup == 1.0): ship['group'] = 'friend' elif (g_iSelectedGroup == 2.0): ship['group'] = 'enemy' elif (g_iSelectedGroup == 3.0): ship['group'] = 'player' # The Player ship has to be named 'player' for some reason. # It's probably related to the AI. ship['name'] = 'player' elif (g_iSelectedGroup == 4.0): ship['group'] = 'neutral2' if (not g_pSelShipSystem is None): import strop s = strop.split(g_pSelShipSystem, '.') ship['system'] = s[-1] try: x = float(g_pEdX.GetCString()) ship['pos'][0] = x except ValueError: print "'" + g_pEdX.GetCString() + "' is no float value" try: y = float(g_pEdY.GetCString()) ship['pos'][1] = y except ValueError: print "'" + g_pEdY.GetCString() + "' is no float value" try: z = float(g_pEdZ.GetCString()) ship['pos'][2] = z except ValueError: print "'" + g_pEdZ.GetCString() + "' is no float value" try: mindamage = (100-float(g_pEdMinDamage.GetCString())) / 100 ship['mindamage'] = mindamage except ValueError: print "'" + g_pEdMinDamage.GetCString() + "' is no float value" try: maxdamage = (100-float(g_pEdMaxDamage.GetCString())) / 100 ship['maxdamage'] = maxdamage except ValueError: print "'" + g_pEdMaxDamage.GetCString() + "' is no float value" minETA = g_pEdMinETA.GetCString() ship['minETA'] = minETA maxETA = g_pEdMaxETA.GetCString() ship['maxETA'] = maxETA import string ship['ai'] = string.strip(g_pEdAI.GetCString()) ship['starbase'] = g_pStarbaseButton.IsChosen() ship['warp'] = g_pWarpButton.IsChosen() ship['missioncritical'] = g_pCriticalButton.IsChosen() RebuildShipList() if (pObject): pObject.CallNextHandler(pEvent)
def SelectShipList(pObject, pEvent): key = (App.TGStringEvent_Cast(pEvent)).GetCString() ship = QBFile.g_pShipListData[key] global g_pSelectedShip g_pSelectedShip = key ChangeIcon(key) # Name g_pEdName.SetString(ship['name']) # X g_pEdX.SetString(repr(ship['pos'][0])) # Y g_pEdY.SetString(repr(ship['pos'][1])) # Z g_pEdZ.SetString(repr(ship['pos'][2])) # AI file if (ship['ai'] != ''): g_pEdAI.SetString(ship['ai']) else: g_pEdAI.SetString(' ') g_pEdMinDamage.SetString(repr(100-ship['mindamage']*100)) g_pEdMaxDamage.SetString(repr(100-ship['maxdamage']*100)) if ship.has_key('minETA'): g_pEdMinETA.SetString(str(ship['minETA'])) g_pEdMaxETA.SetString(str(ship['maxETA'])) else: g_pEdMinETA.SetString("0") g_pEdMaxETA.SetString("0") SetAI(ship['ailevel']) if (ship['group']=='neutral'): SetGroup(0.0) elif (ship['group']=='friend'): SetGroup(1.0) elif (ship['group']=='enemy'): SetGroup(2.0) elif (ship['group']=='player'): SetGroup(3.0) elif (ship['group']=='neutral2'): SetGroup(4.0) global g_pSelShipSystem g_pSelShipSystem = None for system in QBFile.g_pRegionListData: import strop s = strop.split(system, '.') if (s[-1] == ship['system']): g_pSelShipSystem = system SelectShipSystem(None, None) g_pStarbaseButton.SetChosen(ship['starbase']) g_pWarpButton.SetChosen(ship['warp']) g_pCriticalButton.SetChosen(ship['missioncritical']) if (pObject): pObject.CallNextHandler(pEvent)