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 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