def GetRandomNameFor(sShipType): debug(__name__ + ", GetRandomNameFor") FdtnShip = Foundation.shipList[sShipType] if FdtnShip.GetRace() and Races.has_key(FdtnShip.GetRace().name): ShipRace = FdtnShip.GetRace().name return Races[ShipRace].GetRandomName() else: return None
def CreateRacesSelect(pTopicMenu): pLibraryWindow = GetLibraryWindow() pRaceDatabase = App.g_kLocalizationManager.Load("data/TGL/Races.tgl") i = 0 for race in Races.keys(): if race != "GodShips": if pRaceDatabase and pRaceDatabase.HasString(race): RaceTGS = pRaceDatabase.GetString(race) else: RaceTGS = App.TGString(race) # Setup the event for when this button is clicked pEvent = App.TGIntEvent_Create() pEvent.SetEventType(ET_TOPIC) pEvent.SetInt(i) # store the index so we know which button was clicked. pEvent.SetDestination(pLibraryWindow) pButton = App.STRoundedButton_CreateW(RaceTGS, pEvent, 0.20, 0.02) pButton.SetActivationEvent(pEvent) pTopicMenu.AddChild(pButton) pEvent.SetSource(pButton) i = i + 1 # Other ships pEvent = App.TGIntEvent_Create() pEvent.SetEventType(ET_TOPIC) pEvent.SetInt(99) pEvent.SetDestination(pLibraryWindow) pButton = App.STRoundedButton_CreateW(App.TGString("Minor Races"), pEvent, 0.20, 0.02) pButton.SetActivationEvent(pEvent) pTopicMenu.AddChild(pButton) pEvent.SetSource(pButton) App.g_kLocalizationManager.Unload(pRaceDatabase)
def SelectTopic(pObject, pEvent): SHIP_IMAGE_WIDTH = 0.2515625 SHIP_IMAGE_HEIGHT = 0.2458333 SelectedTopic = pEvent.GetInt() if SelectedTopic: pLibraryWindow = GetLibraryWindow() pLibraryWindow.ScrollToTop() pBodyMenu.KillChildren() if SelectedCategory == 1: FdtnShips = Foundation.shipList myship = FdtnShips[SelectedTopic] g_pShipsDatabase = App.g_kLocalizationManager.Load("data/TGL/Ships.tgl") pShipsHeader = App.TGParagraph_Create("", 0.1, None, "", 0.1, App.TGParagraph.TGPF_WORD_WRAP | App.TGParagraph.TGPF_READ_ONLY) pShipsHeader.SetStringW(g_pShipsDatabase.GetString(myship.GetShipFile())) pBodyMenu.AddChild(pShipsHeader) pIcon = App.TGIcon_Create("ShipIcons", App.SPECIES_UNKNOWN) pIcon.Resize(SHIP_IMAGE_WIDTH, SHIP_IMAGE_HEIGHT) iIconNumber = myship.GetIconNum() pIcon.SetVisible() pIcon.SetIconNum(iIconNumber) pIcon.SizeToArtwork() pBodyMenu.AddChild(pIcon) pShipsText = App.TGParagraph_Create("", 0.3, None, "", 1.0, App.TGParagraph.TGPF_WORD_WRAP | App.TGParagraph.TGPF_READ_ONLY) pShipsText.SetStringW(g_pShipsDatabase.GetString(myship.GetShipFile() + " Description")) pBodyMenu.AddChild(pShipsText) App.g_kLocalizationManager.Unload(g_pShipsDatabase) elif SelectedCategory == 2: FdtnSystems = Foundation.systemList mySystem = FdtnSystems[SelectedTopic] pSystemsDatabase = App.g_kLocalizationManager.Load("data/TGL/Systems.tgl") pSystemsHeader = App.TGParagraph_Create("", 0.1, None, "", 0.1, App.TGParagraph.TGPF_WORD_WRAP | App.TGParagraph.TGPF_READ_ONLY) pSystemsHeader.SetStringW(pSystemsDatabase.GetString(mySystem.name)) pBodyMenu.AddChild(pSystemsHeader) pGraphicsMode = App.GraphicsModeInfo_GetCurrentMode() pcLCARS = pGraphicsMode.GetLcarsString() pIcon = App.TGIcon_Create(pcLCARS, 800) pIcon.Resize(SHIP_IMAGE_WIDTH, SHIP_IMAGE_HEIGHT) pIcon.SetVisible() pIcon.SizeToArtwork() pBodyMenu.AddChild(pIcon) pSystemsText = App.TGParagraph_Create("", 0.3, None, "", 1.0, App.TGParagraph.TGPF_WORD_WRAP | App.TGParagraph.TGPF_READ_ONLY) pSystemsText.SetStringW(pSystemsDatabase.GetString(mySystem.name + " Description")) pBodyMenu.AddChild(pSystemsText) App.g_kLocalizationManager.Unload(pSystemsDatabase) elif SelectedCategory == 3: pRaceDatabase = App.g_kLocalizationManager.Load("data/TGL/Races.tgl") i = 0 iIconNumber = 0 myRace = None for race in Races.keys(): print i, race if race != "GodShips": if SelectedTopic == i: myRace = race iIconNumber = i break elif SelectedTopic == 99: myRace = "Other" iIconNumber = 99 break i = i + 1 pRacesHeader = App.TGParagraph_Create("", 0.1, None, "", 0.1, App.TGParagraph.TGPF_WORD_WRAP | App.TGParagraph.TGPF_READ_ONLY) if pRaceDatabase and pRaceDatabase.HasString(myRace): pRacesHeader.SetStringW(pRaceDatabase.GetString(myRace)) else: pRacesHeader.SetStringW(App.TGString(myRace)) pBodyMenu.AddChild(pRacesHeader) pIcon = App.TGIcon_Create("RacesIcons", App.SPECIES_UNKNOWN) pIcon.Resize(SHIP_IMAGE_WIDTH, SHIP_IMAGE_HEIGHT) pIcon.SetVisible() pIcon.SetIconNum(iIconNumber) pIcon.SizeToArtwork() pBodyMenu.AddChild(pIcon) if pRaceDatabase and pRaceDatabase.HasString(myRace + " Description"): pRacesText = App.TGParagraph_Create("", 0.3, None, "", 1.0, App.TGParagraph.TGPF_WORD_WRAP | App.TGParagraph.TGPF_READ_ONLY) pRacesText.SetStringW(pRaceDatabase.GetString(myRace + " Description")) pBodyMenu.AddChild(pRacesText) App.g_kLocalizationManager.Unload(pRaceDatabase)
def AddShipTimer(ShipRace, ToAdd, pSet = None): debug(__name__ + ", AddShipTimer") global dict_Timer, ShipInd, ET_ADD, ET_NOTIFY, dict_Notify, min_time, max_time, incoming_mult NotifyTime = 0 AddShipRace = None EscortShips = None pPlayer = MissionLib.GetPlayer() if pPlayer and not pSet: pSet = pPlayer.GetContainingSet() # ok, thats what we have to do here: # 1. Get our enemys and friendlys if not Races.has_key(ShipRace): print("Error: No race info for", ShipRace) return # 2. Find out what to do: if (ToAdd == "friendly"): # Get a random shiptype: if (len(Races[ShipRace].GetShips()) == 0): print("Error: No Ships for Race", ShipRace) return RandTypeNum = App.g_kSystemWrapper.GetRandomNumber(len(Races[ShipRace].GetShips())) ShipType = Races[ShipRace].GetShips()[RandTypeNum] if getMVAMShip(ShipType): ShipType = getMVAMShip(ShipType) if IsGodShip(ShipType): return Position = "friendly" RealShipName = Races[ShipRace].GetRandomName() if not RealShipName: RealShipName = GetFreeName(ShipType) NotifyTime = 1 AddShipRace = Races[ShipRace] elif (ToAdd == "friendlyRace"): # Get a random friendly ShipRace if (len(Races[ShipRace].GetFriendlys()) == 0): print("ERROR: No friendly Race for", ShipRace) return RandRaceNum = App.g_kSystemWrapper.GetRandomNumber(len(Races[ShipRace].GetFriendlys())) friendRace = Races[ShipRace].GetFriendlys()[RandRaceNum] if not Races.has_key(friendRace): print("Error: No race info for", friendRace) return if (len(Races[friendRace].GetShips()) == 0): print("Error: No Ships for Race", friendRace) return RandTypeNum = App.g_kSystemWrapper.GetRandomNumber(len(Races[friendRace].GetShips())) ShipType = Races[friendRace].GetShips()[RandTypeNum] if getMVAMShip(ShipType): ShipType = getMVAMShip(ShipType) if IsGodShip(ShipType) or IsGodRace(friendRace): return Position = "friendly" RealShipName = Races[friendRace].GetRandomName() if not RealShipName: RealShipName = GetFreeName(ShipType) NotifyTime = 1 AddShipRace = Races[friendRace] elif (ToAdd == "enemy"): # Get a random enemy ShipRace if (len(Races[ShipRace].GetEnemys()) == 0): print("ERROR: No enemy Race for", ShipRace) return RandRaceNum = App.g_kSystemWrapper.GetRandomNumber(len(Races[ShipRace].GetEnemys())) enemyRace = Races[ShipRace].GetEnemys()[RandRaceNum] if not Races.has_key(enemyRace): print("Error: No race info for", enemyRace) return if (len(Races[enemyRace].GetShips()) == 0): print("Error: No Ships for Race", enemyRace) return RandTypeNum = App.g_kSystemWrapper.GetRandomNumber(len(Races[enemyRace].GetShips())) ShipType = Races[enemyRace].GetShips()[RandTypeNum] if getMVAMShip(ShipType): ShipType = getMVAMShip(ShipType) if IsGodShip(ShipType) or IsGodRace(enemyRace): return Position = "enemy" RealShipName = Races[enemyRace].GetRandomName() if not RealShipName: RealShipName = GetFreeName(ShipType) AddShipRace = Races[enemyRace] elif (ToAdd == "ferengi"): ShipType = "Marauder" Position = "neutral" RealShipName = "Ferengi" else: print("Error: Nothing todo") return # Preload try: loadspacehelper.PreloadShip(ShipType, 1) except: print("Error: Cannot preload", ShipType) return ShipName = RealShipName + "-" + str(ShipInd) ShipInd = ShipInd + 1 # Create an event - it's a thing that will call this function pTimerEvent = App.TGEvent_Create() pTimerEvent.SetEventType(ET_ADD) pTimerEvent.SetDestination(App.TopWindow_GetTopWindow()) # Add in 30 seconds up to 5 minutes RealAddTime = 0 if max_time > 0: RealAddTime = App.g_kSystemWrapper.GetRandomNumber(max_time) + min_time AddTime = App.g_kUtopiaModule.GetGameTime() + RealAddTime # Create a timer - it's a thing that will wait for a given time,then do something pTimer = App.TGTimer_Create() pTimer.SetTimerStart(AddTime) pTimer.SetDelay(0) pTimer.SetDuration(0) pTimer.SetEvent(pTimerEvent) App.g_kTimerManager.AddTimer(pTimer) print("Get: ", ShipType, ShipName, "as", Position, "in", RealAddTime) # or any other Idea how to get Informations together with a Timer? dict_Timer[str(pTimerEvent)] = ShipType, ShipName, Position, pSet # does this ship get an escort? if AddShipRace: EscortShips = AddShipRace.GetEscort(ShipType) if EscortShips: for EscortShip in EscortShips: EscortName = AddShipRace.GetRandomName() if not EscortName: EscortName = GetFreeName(EscortShip) # Preload try: loadspacehelper.PreloadShip(ShipType, 1) except: print("Error: Cannot preload", ShipType) return # Create an event - it's a thing that will call this function pTimerEvent = App.TGEvent_Create() pTimerEvent.SetEventType(ET_ADD) pTimerEvent.SetDestination(App.TopWindow_GetTopWindow()) # Create a timer - it's a thing that will wait for a given time,then do something pTimer = App.TGTimer_Create() pTimer.SetTimerStart(AddTime) pTimer.SetDelay(0) pTimer.SetDuration(0) pTimer.SetEvent(pTimerEvent) App.g_kTimerManager.AddTimer(pTimer) dict_Timer[str(pTimerEvent)] = EscortShip, EscortName, Position, pSet # if we add a friendly, we also Notify the Player if (NotifyTime == 1): RealNotifyTime = 0 if incoming_mult > 0: RealNotifyTime = RealAddTime / (App.g_kSystemWrapper.GetRandomNumber(incoming_mult) + 2) NotifyTime = App.g_kUtopiaModule.GetGameTime() + RealNotifyTime pTimer2Event = App.TGEvent_Create() pTimer2Event.SetEventType(ET_NOTIFY) pTimer2Event.SetDestination(App.TopWindow_GetTopWindow()) pTimer2 = App.TGTimer_Create() pTimer2.SetTimerStart(NotifyTime) pTimer2.SetDelay(0) pTimer2.SetDuration(0) pTimer2.SetEvent(pTimer2Event) App.g_kTimerManager.AddTimer(pTimer2) # variant the arrive time about +/-10 seconds varTime = math.pow(-1, App.g_kSystemWrapper.GetRandomNumber(3)) * App.g_kSystemWrapper.GetRandomNumber(10) approxTime = RealAddTime - RealNotifyTime + varTime dict_Notify[str(pTimer2Event)] = RealShipName, approxTime