/// Fetches the latest price guides for a given game from MKM and stores it as a CSV file. /// Does NOT re-load the internal database manager structures - loadPriceGuidesDatabase has to be called once all games are up to date. /// <param name="game">The game for which to load the database.</param> /// <returns><c>Null</c> in case the update failed either due to bad response from MKM or IO problems, /// otherwise the table with the guides.</returns> private DataTable updatePriceGuidesFiles(GameDesc game) { if (MainView.Instance.Config.Games.Count == 0) { LogError("updating price guides database", "No games specified in config.xml.", true); return(null); } try { MainView.Instance.LogMainWindow("Updating MKM price guides database..."); // build expansions var guidesFile = MKMInteract.RequestHelper.GetPriceGuideFile(game.GameID); if (guidesFile == null || guidesFile.Length == 0) { return(null); } var gameGuides = ConvertCSVtoDataTable(guidesFile); if (!Directory.Exists(@".\\PriceGuideDatabase)")) { Directory.CreateDirectory(@".\\PriceGuideDatabase"); } WriteTableAsCSV(@".\\PriceGuideDatabase\\priceguides_" + game.GameID + ".csv", gameGuides); return(gameGuides); } catch (Exception eError) { LogError("downloading MKM price guides", eError.Message, true); } return(null); }
/// Fetches the latest expansions database for a given game from MKM and stores it as a CSV file. /// Does NOT re-load the internal database manager structures - loadExpansionDatabase has to be called once all games are up to date. /// <param name="game">The game for which to load the database.</param> /// <returns><c>False</c> in case the update failed either due to bad response from MKM or IO problems.</returns> private bool updateExpansionsDatabaseFiles(GameDesc game) { if (MainView.Instance.Config.Games.Count == 0) { LogError("updating expansion database", "No games specified in config.xml.", true); return(false); } try { MainView.Instance.LogMainWindow("Updating MKM expansions database..."); // build expansions var doc = MKMInteract.RequestHelper.GetExpansions(game.GameID); var node = doc.GetElementsByTagName("expansion"); using (StreamWriter exp = new StreamWriter(@".\\ExpansionsDatabase\\mkmexpansions_" + game.GameID + ".csv")) { exp.WriteLine(string.Format("\"{0}\",\"{1}\",\"{2}\",\"{3}\"", ExpansionsFields.ExpansionID, ExpansionsFields.Abbreviation, ExpansionsFields.Name, ExpansionsFields.ReleaseDate)); foreach (XmlNode nExpansion in node) { exp.WriteLine("\"" + nExpansion[ExpansionsFields.ExpansionID].InnerText + "\",\"" // put commas around each, in case wizards ever decide to do set with a comma in the name + nExpansion[ExpansionsFields.Abbreviation].InnerText + "\",\"" + nExpansion[ExpansionsFields.Name].InnerText + "\",\"" + nExpansion[ExpansionsFields.ReleaseDate].InnerText + "\""); } } MainView.Instance.LogMainWindow("MKM expansions database for game " + game.GameID + " updated."); } catch (Exception eError) { LogError("downloading MKM expansions", eError.Message, true); return(false); } return(true); }
public static bool EnterGame_Prefix(UIGalaxySelect __instance) { if (Multiplayer.IsInMultiplayerMenu) { Multiplayer.Session.IsInLobby = false; if (UIVirtualStarmap_Transpiler.customBirthPlanet != -1) { Log.Debug((GameMain.data.galaxy.PlanetById(UIVirtualStarmap_Transpiler.customBirthPlanet) == null) ? "null" : "not null"); GameMain.data.galaxy.PlanetById(UIVirtualStarmap_Transpiler.customBirthPlanet)?.UnloadFactory(); } if (((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { UIRoot.instance.uiGame.planetDetail.gameObject.SetActive(false); GameDesc gameDesc = __instance.gameDesc; DSPGame.StartGameSkipPrologue(gameDesc); } else { Multiplayer.Session.Network.SendPacket(new StartGameMessage()); } return(false); } return(true); }
private static void OnJoinGameButtonClick() { string[] parts = hostIPAdressInput.text.Split(':'); string ip = parts[0]; int port; if (parts.Length == 1) { // Use default port port = 8469; } else if (!int.TryParse(parts[1], out port)) { Log.Info($"Port must be a valid number above 1024"); return; } Log.Info($"Connecting to server... {ip}:{port}"); Object.FindObjectOfType <MultiplayerSession>().Connect(ip, port); // TODO: Should display a loader during the connection and only open the game once the player as connected to the server. // TODO: We should also wait to receive the actual game seed to make sure that we can load the same map and wait for the InitialGameState packet to update the game world properly. multiplayerMenu.gameObject.SetActive(false); GameDesc gameDesc = new GameDesc(); gameDesc.SetForNewGame(UniverseGen.algoVersion, 1, 64, 1, 1f); DSPGame.StartGameSkipPrologue(gameDesc); }
public static void GenerateAllPlanets(GalaxyData galaxy, StarData star, GameDesc gameDesc, List <PlanetForGenerator> planetsToGenerate) { Patch.Debug("Recap of what have to be generated : \n", LogLevel.Debug, Patch.DebugStarGen); var finalIndex = 0; foreach (var planet in planetsToGenerate) { var debugLine = "A "; planet.planetIndex = finalIndex; foreach (var planetForGenerator in planet.moons) { planetForGenerator.orbitAround = finalIndex + 1; } if (planet.isGasGiant) { debugLine += " Gas Giant :" + planet.planetIndex + "with values : \n"; } else { debugLine += " Telluric Planet :" + planet.planetIndex + "with values : \n"; } //planet.ToString(); //planet.GenerateThePlanet(ref galaxy,ref star,ref gameDesc); // Debug.Log(); PlanetGen.CreatePlanet(galaxy, star, gameDesc, planet.planetIndex, planet.orbitAround, planet.orbitIndex, planet.number, planet.isGasGiant, planet.infoSeed, planet.genSeed); star.planets[finalIndex].name = star.name + " - " + RomanNumbers.roman[planet.number]; planet.name = star.planets[finalIndex].name; if (planet.moons.Count >= 2) { star.planets[finalIndex].HasMultipleSatellites(); } Patch.Debug(star.planets[finalIndex].name, LogLevel.Debug, Patch.DebugStarNamingGen); finalIndex++; //debugLine += planet.ToString() + "\n\n"; if (planet.moons.Count != 0) { debugLine += "with " + planet.moons.Count + " Moons : \n\n"; foreach (var moon in planet.moons) { moon.planetIndex = finalIndex; debugLine += " Moon : " + moon.planetIndex + "\n"; PlanetGen.CreatePlanet(galaxy, star, gameDesc, moon.planetIndex, moon.orbitAround, moon.orbitIndex, moon.number, moon.isGasGiant, moon.infoSeed, moon.genSeed); star.planets[moon.planetIndex].name = planet.name + " - " + RomanNumbers.roman[moon.number]; Patch.Debug(star.planets[moon.planetIndex].name, LogLevel.Debug, Patch.DebugStarNamingGen); finalIndex++; } } Patch.Debug(debugLine, LogLevel.Debug, Patch.DebugStarGen); } }
private static void OnJoinGameButtonClick() { string[] parts = hostIPAdressInput.text.Split(':'); string ip = parts[0]; int port; if (parts.Length == 1) { // Use default port port = 8469; } else if (!int.TryParse(parts[1], out port)) { Log.Info($"Port must be a valid number above 1024"); return; } Log.Info($"Connecting to server... {ip}:{port}"); Object.FindObjectOfType <MultiplayerSession>().Connect(ip, port); // TODO: Should display a loader during the connection and only open the game once the player is connected to the server. multiplayerMenu.gameObject.SetActive(false); // TODO: For now I'm only starting the same world on all clients by using the same seed. But we will need to change this // code to instead share the save game to all clients that join the game to make sure that everyone has the same initial state. GameDesc gameDesc = new GameDesc(); gameDesc.SetForNewGame(UniverseGen.algoVersion, 1, 64, 1, 1f); DSPGame.StartGameSkipPrologue(gameDesc); }
public override void ProcessPacket(LobbyResponse packet, NebulaConnection conn) { using (BinaryUtils.Reader p = new BinaryUtils.Reader(packet.ModsSettings)) { for (int i = 0; i < packet.ModsSettingsCount; i++) { string guid = p.BinaryReader.ReadString(); PluginInfo info = Chainloader.PluginInfos[guid]; if (info.Instance is IMultiplayerModWithSettings mod) { mod.Import(p.BinaryReader); } } } ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost = false; Multiplayer.Session.NumPlayers = packet.NumPlayers; Multiplayer.Session.IsInLobby = true; DiscordManager.UpdateRichPresence(partyId: packet.DiscordPartyId); UIRoot.instance.galaxySelect._Open(); UIRoot.instance.uiMainMenu._Close(); GameDesc gameDesc = new GameDesc(); gameDesc.SetForNewGame(packet.GalaxyAlgo, packet.GalaxySeed, packet.StarCount, 1, packet.ResourceMultiplier); gameDesc.savedThemeIds = packet.SavedThemeIds; UIRoot.instance.galaxySelect.gameDesc = gameDesc; UIRoot.instance.galaxySelect.SetStarmapGalaxy(); }
public override void ProcessPacket(HandshakeResponse packet, NebulaConnection conn) { using (BinaryUtils.Reader p = new BinaryUtils.Reader(packet.ModsSettings)) { for (int i = 0; i < packet.ModsSettingsCount; i++) { string guid = p.BinaryReader.ReadString(); PluginInfo info = Chainloader.PluginInfos[guid]; if (info.Instance is IMultiplayerModWithSettings mod) { mod.Import(p.BinaryReader); } } } // overwrite local setting with host setting, but dont save it as its a temp setting for this session Config.Options.SyncSoil = packet.SyncSoil; ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost = false; ((LocalPlayer)Multiplayer.Session.LocalPlayer).SetPlayerData(packet.LocalPlayerData, packet.IsNewPlayer); Multiplayer.Session.IsInLobby = false; Multiplayer.ShouldReturnToJoinMenu = false; GameDesc gameDesc = new GameDesc(); gameDesc.SetForNewGame(packet.AlgoVersion, packet.GalaxySeed, packet.StarCount, 1, packet.ResourceMultiplier); DSPGame.StartGameSkipPrologue(gameDesc); InGamePopup.ShowInfo("Loading", "Loading state from server, please wait", null); }
// TODO: Remove all this once we change the way we deal with hosting a game. // We could it should probably be done from the in game Esc Menu. private static void OnHostGameButtonClick() { string[] parts = hostIPAdressInput.text.Split(':'); int port; if (parts.Length == 1) { port = Config.DefaultPort; } else if (!int.TryParse(parts[1], out port)) { Log.Info($"Port must be a valid number above 1024"); return; } multiplayerMenu.gameObject.SetActive(false); Log.Info($"Listening server on port {port}"); var session = NebulaBootstrapper.Instance.CreateMultiplayerHostSession(); session.StartServer(port); GameDesc gameDesc = new GameDesc(); gameDesc.SetForNewGame(UniverseGen.algoVersion, 1, 64, 1, 1f); DSPGame.StartGameSkipPrologue(gameDesc); }
//GalaxySeed = 14171500; //StarSeed = 1826783713 static void Main() { DateTime StartTime = DateTime.Now; GameDesc gameDesc = new GameDesc { starCount = 64 }; ThemeProtoSet themes = ThemeWorks.GetThemes(); int length = themes.dataArray.Length; gameDesc.themeIds = new int[length]; ParallelOptions options = new ParallelOptions(); options.MaxDegreeOfParallelism = 50; for (int index = 0; index < length; ++index) { gameDesc.themeIds[index] = themes.dataArray[index].ID; } int StartSeed = 73295657; int EndSeed = 73295657; Parallel.For( StartSeed, EndSeed + 1, options, (i, loopState) => { System.Console.WriteLine("StartLoop " + i.ToString("D8")); gameDesc.galaxySeed = i; MUniverseGen MUniverseGen = new MUniverseGen(); GalaxyData galaxyData = MUniverseGen.CreateGalaxy(gameDesc); System.Console.WriteLine("Seed: " + galaxyData.seed.ToString("D8") + " BirthStar: " + galaxyData.stars[0].displayName); } ); //for (int i = StartSeed; i < EndSeed+1; i++) //{ // gameDesc.galaxySeed = i; // GalaxyData galaxyData = MUniverseGen.CreateGalaxy(gameDesc); // System.Console.WriteLine("Seed: " + galaxyData.seed.ToString("D8") + " BirthStar: "+galaxyData.stars[0].displayName); // //System.Console.WriteLine("START: " + galaxyData.stars[0].displayName); // //System.Console.WriteLine("BH: " + galaxyData.stars[63].displayName); // //System.Console.WriteLine("BH: " + galaxyData.stars[63].position.magnitude); //} DateTime EndTime = DateTime.Now; System.Console.WriteLine("Finished"); Console.WriteLine("Time Used: " + EndTime.Subtract(StartTime).TotalSeconds + "Seconds"); Console.WriteLine("Seed Calculated: " + (EndSeed - StartSeed + 1)); System.Console.ReadLine(); }
public static void CreateGalaxy_Postfix(GameDesc gameDesc, GalaxyData __result) { if (Multiplayer.IsActive && UIVirtualStarmap_Transpiler.customBirthStar != -1) { Debug.Log("Overwriting with " + __result.PlanetById(UIVirtualStarmap_Transpiler.customBirthPlanet) + " and " + __result.StarById(UIVirtualStarmap_Transpiler.customBirthStar)); __result.birthPlanetId = UIVirtualStarmap_Transpiler.customBirthPlanet; __result.birthStarId = UIVirtualStarmap_Transpiler.customBirthStar; } }
static bool SeedRadom(UIGalaxySelect __instance) { GameDesc gameDesc = Traverse.Create(__instance).Field("gameDesc").GetValue <GameDesc>(); System.Random random = Traverse.Create(__instance).Field("random").GetValue <System.Random>(); gameDesc.galaxySeed = random.Next(int.MaxValue); __instance.SetStarmapGalaxy(); return(false); }
static void SetPlanetTheme(ref PlanetData planet, ref StarData star, ref GameDesc game_desc) { // Trick the game to spawn a barren planet as the other planets if (planet.star.index == 0 && planet.type != EPlanetType.Ocean && planet.type != EPlanetType.Gas) { Debug.Log($"alternatestart -- Forcing planet {planet.star.id}.{planet.id} to desert"); planet.type = EPlanetType.Desert; } }
public bool IsDifferentGame() { if (DSPGame.GameDesc != lastGameDesc) { lastGameDesc = DSPGame.GameDesc; return(true); } return(false); }
public static bool CreateStarPlanets(GalaxyData galaxy, StarData star, GameDesc gameDesc) { if (Patch.EnableCustomStarAlgorithm.Value) { // InnerCount for the System ReworkStarGen.CreateStarPlanetsRework(galaxy, star, gameDesc, new PlanetGeneratorSettings()); return(false); } return(true); }
// Print all planet themes public static void PrintAllThemes(GameDesc game_desc) { int[] themeIds = game_desc.themeIds; int num = themeIds.Length; Debug.Log("Printing themes:"); for (int i = 0; i < num; i++) { Debug.Log(game_desc.themeIds[i]); } }
public void ProcessPacket(HandshakeResponse packet, NebulaConnection conn) { GameDesc gameDesc = new GameDesc(); gameDesc.SetForNewGame(packet.AlgoVersion, packet.GalaxySeed, packet.StarCount, 1, packet.ResourceMultiplier); DSPGame.StartGameSkipPrologue(gameDesc); LocalPlayer.IsMasterClient = false; LocalPlayer.SetPlayerData(packet.LocalPlayerData); InGamePopup.ShowInfo("Loading", "Loading state from server, please wait", null); }
public static bool OnStarCountSliderValueChange(UIGalaxySelect __instance, ref Slider ___starCountSlider, ref GameDesc ___gameDesc, float val) { var num = (int)(___starCountSlider.value + 0.100000001490116); if (num == ___gameDesc.starCount) { return(false); } ___gameDesc.starCount = num; __instance.SetStarmapGalaxy(); return(false); }
public override void ProcessPacket(LobbyUpdateValues packet, NebulaConnection conn) { if (IsHost) { return; } GameDesc gameDesc = new GameDesc(); gameDesc.SetForNewGame(packet.GalaxyAlgo, packet.GalaxySeed, packet.StarCount, 1, packet.ResourceMultiplier); UIRoot.instance.galaxySelect.gameDesc = gameDesc; UIRoot.instance.galaxySelect.SetStarmapGalaxy(); }
public static bool EnterGame_Prefix(UIGalaxySelect __instance) { if (MainMenuManager.IsInMultiplayerMenu) { Log.Info($"Listening server on port {Config.DefaultPort}"); var session = NebulaBootstrapper.Instance.CreateMultiplayerHostSession(); session.StartServer(Config.DefaultPort); GameDesc gameDesc = AccessTools.Field(__instance.GetType(), "gameDesc").GetValue(__instance) as GameDesc; DSPGame.StartGameSkipPrologue(gameDesc); return(false); } return(true); }
private void InitializeGameDescription(GameDesc desc) { GameName = desc.Name; State = desc.State; StateColor = desc.StateFieldColor; WhitePlayerName = desc.WhiteUsername; BlackPlayerName = desc.BlackUsername; WhitePlayerRating = desc.WhiteRating; BlackPlayerRating = desc.BlackRating; WhitePlayerRatingForWin = desc.WhiteRatingForWin; BlackPlayerRatingForWin = desc.BlackRatingForWin; WhitePlayerRatingForLose = desc.WhiteRatingForLose; BlackPlayerRatingForLose = desc.BlackRatingForLose; WhitePlayerRatingForDraw = desc.WhiteRatingForDraw; BlackPlayerRatingForDraw = desc.BlackRatingForDraw; }
private void InitializeBoard(GameDesc desc) { _state = desc.State; ChessDotNet.Player side = TcpChessClient.getInstance().Username == desc.WhiteUsername ? ChessDotNet.Player.White : ChessDotNet.Player.Black; Board = new Board(side); Cells = Board.Cells; HorizontalIndexes = Board.HorizontalIndexes; VerticalIndexes = Board.VerticalIndexes; MoveCommand = new DelegateCommand <string>((move) => { if (_state == "Playing") { Board.MakeMove(move); } }); }
public static bool CreatePlanet( GalaxyData galaxy, StarData star, GameDesc gameDesc, int index, int orbitAround, int orbitIndex, int number, bool gasGiant, int info_seed, int gen_seed, ref PlanetData __result) { //Debug.Log("CreatePlanet -----"); __result = ReworkPlanetGen.ReworkCreatePlanet(ref galaxy, ref star, ref gameDesc, index, orbitAround, orbitIndex, number, gasGiant, info_seed, gen_seed); //Debug.Log("__result.index" + __result.id); return(false); }
static bool BigSeed(UIGalaxySelect __instance) { var _this = __instance; long num1 = -1; InputField seedInput = Traverse.Create(__instance).Field("seedInput").GetValue <InputField>(); GameDesc gameDesc = Traverse.Create(__instance).Field("gameDesc").GetValue <GameDesc>(); if (long.TryParse(seedInput.text, out num1)) { num1 = Math.Abs(num1); if (num1 > int.MaxValue) { num1 = int.MaxValue; } gameDesc.galaxySeed = (int)num1; } _this.SetStarmapGalaxy(); return(false); }
static bool SetPlanetTheme( ref PlanetData planet, ref StarData star, ref GameDesc game_desc, ref int set_theme, ref int set_algo, ref double rand1, ref double rand2, ref double rand3, ref double rand4, ref int theme_seed) { // Change the theme algorithm for the starting star system if (star.id == 1) { if (planet.type == EPlanetType.Ocean) { int newType; // 35% chance for a oceanic jungle if (rand1 > 0.65d) { newType = 8; } // 35% chance for a red stone else if (rand1 > 0.30d) { newType = 14; } // 20% chance for a prarie else if (rand1 > 0.10d) { newType = 15; } // 10% chance for a terran else { newType = 1; } ChangePlanetTheme(ref planet, newType, rand2, rand3, rand4); return(false); } else if (planet.type == EPlanetType.Gas) { } else { } } return(true); }
public static bool SetPlanetTheme( ref List <int> ___tmp_theme, PlanetData planet, StarData star, GameDesc game_desc, int set_theme, int set_algo, double rand1, double rand2, double rand3, double rand4, int theme_seed) { if (planet.type == EPlanetType.Gas) { ReworkSetPlanetTheme.SetPlanetTheme(ref planet, ref star, theme_seed); return(false); } return(true); }
public void ProcessPacket(HandshakeResponse packet, NebulaConnection conn) { if (LocalPlayer.GS2_GSSettings != null && packet.CompressedGS2Settings.Length > 1) // if host does not use GS2 we send a null byte { LocalPlayer.GS2ApplySettings(packet.CompressedGS2Settings); } else if (LocalPlayer.GS2_GSSettings != null && packet.CompressedGS2Settings.Length == 1) { InGamePopup.ShowWarning("Galactic Scale - Server not supported", "The server does not seem to use Galactic Scale. Make sure that your mod configuration matches.", "Close"); return; } GameDesc gameDesc = new GameDesc(); gameDesc.SetForNewGame(packet.AlgoVersion, packet.GalaxySeed, packet.StarCount, 1, packet.ResourceMultiplier); DSPGame.StartGameSkipPrologue(gameDesc); LocalPlayer.IsMasterClient = false; LocalPlayer.SetPlayerData(packet.LocalPlayerData); InGamePopup.ShowInfo("Loading", "Loading state from server, please wait", null); }
public static PlanetData ReworkCreatePlanet( ref GalaxyData galaxy, ref StarData star, ref GameDesc gameDesc, int index, int orbitAround, int orbitIndex, int number, bool gasGiant, int info_seed, int gen_seed) { Patch.Debug("ReworkCreatePlanet", LogLevel.Debug, Patch.DebugReworkPlanetGen); var planetData = new PlanetData(); var mainSeed = new Random(info_seed); //Base data of the planet : planetData.index = index; planetData.galaxy = star.galaxy; planetData.star = star; planetData.seed = gen_seed; // Index of the thing it's orbiting around , 0 for star , anything else mean it's a moon planetData.orbitAround = orbitAround; // Current orbit Index around the planet planetData.orbitIndex = orbitIndex; // index of the planet in the system ? planetData.number = number; // Global Id of the entity planetData.id = star.id * 100 + planetData.index + 1; var stars = galaxy.stars; Patch.Debug("Basic Information Setup", LogLevel.Debug, Patch.DebugReworkPlanetGen); var randomNumber1 = mainSeed.NextDouble(); var randomNumber2 = mainSeed.NextDouble(); var randomNumber3 = mainSeed.NextDouble(); var randomNumber4 = mainSeed.NextDouble(); var randomNumber5 = mainSeed.NextDouble(); var randomNumber6 = mainSeed.NextDouble(); var randomNumber7 = mainSeed.NextDouble(); var randomNumber8 = mainSeed.NextDouble(); var randomNumber9 = mainSeed.NextDouble(); var randomNumber10 = mainSeed.NextDouble(); var randomNumber11 = mainSeed.NextDouble(); var randomNumber12 = mainSeed.NextDouble(); var randomNumber13 = mainSeed.NextDouble(); var randomNumber14 = mainSeed.NextDouble(); // Orbit definition Patch.Debug("Orbit definition", LogLevel.Debug, Patch.DebugReworkPlanetGen); var baselineOrbitVariation = Mathf.Pow(1.2f, (float)(randomNumber1 * (randomNumber2 - 0.5) * 0.5)); var orbitInclination = UnityRandom.Range(0, Patch.MaxOrbitInclination.Value) * MathUtils.RangePlusMinusOne(mainSeed); Patch.Debug("Rotation definition", LogLevel.Debug, Patch.DebugReworkPlanetGen); // rotation period planetData.rotationPeriod = randomNumber8 * randomNumber9 * Patch.RotationPeriodVariabilityFactor.Value + Patch.RotationPeriodBaseTime.Value; // Planet Patch.Debug("Body Stuff", LogLevel.Debug, Patch.DebugReworkPlanetGen); //orbit longitude planetData.orbitLongitude = (float)(randomNumber4 * 360.0); //runtimeOrbitRotation planetData.runtimeOrbitRotation = Quaternion.AngleAxis(planetData.orbitLongitude, Vector3.up) * Quaternion.AngleAxis(orbitInclination, Vector3.forward); planetData.runtimeSystemRotation = planetData.runtimeOrbitRotation * Quaternion.AngleAxis(planetData.obliquity, Vector3.forward); if (planetData.IsNotAMoon()) { Patch.Debug("Planets Stuff", LogLevel.Debug, Patch.DebugReworkPlanetGen); //orbit var baselineOrbitSize = Patch.OrbitRadiusPlanetArray[orbitIndex] * star.orbitScaler; var orbitSize = (float)((baselineOrbitVariation - 1.0) / Mathf.Max(1f, baselineOrbitSize) + 1.0); planetData.orbitRadius = baselineOrbitSize * orbitSize; // orbit Inclination + periods planetData.orbitInclination = orbitInclination; planetData.orbitalPeriod = Math.Sqrt(pi2Rad * planetData.orbitRadius * planetData.orbitRadius * planetData.orbitRadius / (1.35385519905204E-06 * star.mass)); //rotation period if (planetData.IsGasGiant() || planetData.star.type == EStarType.NeutronStar) { planetData.rotationPeriod *= 0.200000002980232; } else if (planetData.star.type == EStarType.BlackHole) { planetData.rotationPeriod *= 0.150000005960464; } planetData.sunDistance = planetData.orbitRadius; // rotation period planetData.rotationPeriod = 1.0 / (1.0 / planetData.orbitalPeriod * 2); //Tidal Lock Management if (randomNumber13 < Patch.ChanceTidalLock.Value) { if (randomNumber13 < Patch.ChanceTidalLock1.Value) { planetData.obliquity *= 0.01f; planetData.rotationPeriod = planetData.orbitalPeriod; planetData.IsTidallyLocked(TidalLevel.TidalLocked); } else if (randomNumber13 < Patch.ChanceTidalLock2.Value) { planetData.obliquity *= 0.1f; planetData.rotationPeriod = planetData.orbitalPeriod * 0.5; planetData.IsTidallyLocked(TidalLevel.TidalLocked2); } else { planetData.obliquity *= 0.2f; planetData.rotationPeriod = planetData.orbitalPeriod * 0.25; planetData.IsTidallyLocked(TidalLevel.TidalLocked4); } } Patch.Debug("Planets Stuff Done", LogLevel.Debug, Patch.DebugReworkPlanetGen); } // Moon else { // the previous algo is using the number of the planet it's orbiting around, not the actual index --> so minus 1 orbitAround -= 1; Patch.Debug("Moon Stuff", LogLevel.Debug, Patch.DebugReworkPlanetGen); //affect the data of the planet of the moon Patch.Debug("orbitAround " + orbitAround, LogLevel.Debug, Patch.DebugReworkPlanetGen); planetData.orbitAroundPlanet = star.planets[orbitAround]; Patch.Debug("orbitAround id : " + star.planets[orbitAround].index, LogLevel.Debug, Patch.DebugReworkPlanetGen); var orbitRadiusScaled = Patch.OrbitRadiusArrayMoons[orbitIndex] * star.orbitScaler * Mathf.Lerp(baselineOrbitVariation, 1f, 0.5f) * planetData.orbitAroundPlanet.GetGasGiantOrbitScaler(); //orbit planetData.orbitRadius = orbitRadiusScaled; Patch.Debug("orbitRadius " + planetData.orbitRadius, LogLevel.Debug, Patch.DebugReworkPlanetGen); // orbit Inclination + periods planetData.orbitInclination = orbitInclination * Patch.MoonOrbitInclinationFactor.Value; Patch.Debug("orbitInclination " + planetData.orbitInclination, LogLevel.Debug, Patch.DebugReworkPlanetGen); planetData.orbitalPeriod = Math.Sqrt(pi2Rad * planetData.orbitRadius * planetData.orbitRadius * planetData.orbitRadius / 1.08308421068537E-08); Patch.Debug("orbitalPeriod " + planetData.orbitalPeriod, LogLevel.Debug, Patch.DebugReworkPlanetGen); planetData.rotationPeriod *= Mathf.Pow(planetData.orbitRadius, 0.25f); Patch.Debug("rotationPeriod " + planetData.rotationPeriod, LogLevel.Debug, Patch.DebugReworkPlanetGen); // distance = planet of the moon planetData.sunDistance = planetData.orbitAroundPlanet.orbitRadius; Patch.Debug("sunDistance " + planetData.sunDistance, LogLevel.Debug, Patch.DebugReworkPlanetGen); // rotation period planetData.rotationPeriod = 1.0 / (1.0 / planetData.orbitAroundPlanet.orbitalPeriod + 1.0 / planetData.rotationPeriod); Patch.Debug("rotationPeriod - 2 " + planetData.rotationPeriod, LogLevel.Debug, Patch.DebugReworkPlanetGen); Patch.Debug("Tidal Lock " + planetData.rotationPeriod, LogLevel.Debug, Patch.DebugReworkPlanetGen); //Tidal Lock Management if (randomNumber13 < Patch.ChanceTidalLock.Value) { if (randomNumber13 < Patch.ChanceTidalLock1.Value) { planetData.obliquity *= 0.01f; planetData.rotationPeriod = planetData.orbitAroundPlanet.orbitalPeriod; planetData.IsTidallyLocked(TidalLevel.TidalLocked); } else if (randomNumber13 < Patch.ChanceTidalLock2.Value) { planetData.obliquity *= 0.1f; planetData.rotationPeriod = planetData.orbitAroundPlanet.orbitalPeriod * 0.5; planetData.IsTidallyLocked(TidalLevel.TidalLocked2); } else { planetData.obliquity *= 0.2f; planetData.rotationPeriod = planetData.orbitAroundPlanet.orbitalPeriod * 0.25; planetData.IsTidallyLocked(TidalLevel.TidalLocked4); } } Patch.Debug("End Tidal Lock " + planetData.rotationPeriod, LogLevel.Debug, Patch.DebugReworkPlanetGen); //runtimeOrbitRotation planetData.runtimeOrbitRotation = planetData.orbitAroundPlanet.runtimeOrbitRotation * planetData.runtimeOrbitRotation; Patch.Debug("runtimeOrbitRotation " + planetData.runtimeOrbitRotation, LogLevel.Debug, Patch.DebugReworkPlanetGen); Patch.Debug("Moon Stuff Done", LogLevel.Debug, Patch.DebugReworkPlanetGen); } Patch.Debug("Body orbit Phase", LogLevel.Debug, Patch.DebugReworkPlanetGen); // orbit phase planetData.orbitPhase = (float)(randomNumber5 * 360.0); Patch.Debug("Body Rotation Phase", LogLevel.Debug, Patch.DebugReworkPlanetGen); //rotation phase planetData.rotationPhase = (float)(randomNumber10 * 360.0); Patch.Debug("Body Orbit Obliquity", LogLevel.Debug, Patch.DebugReworkPlanetGen); // orbit obliquity Patch.Debug("Body Obliquity Modification", LogLevel.Debug, Patch.DebugReworkPlanetGen); if (randomNumber13 < Patch.ChancePlanetLaySide.Value) { planetData.obliquity = (float)randomNumber6 * MathUtils.RangePlusMinusOne(mainSeed) * Patch.LaySideBaseAngle.Value; planetData.obliquity += Patch.LaySideAddingAngle.Value * MathUtils.RangePlusMinusOne(mainSeed); planetData.HasLayingObliquity(); } else if (randomNumber13 < Patch.ChanceBigObliquity.Value) { planetData.obliquity = (float)randomNumber6 * MathUtils.RangePlusMinusOne(mainSeed) * Patch.BigObliquityBaseAngle.Value; planetData.obliquity += Patch.BigObliquityAddingAngle.Value * MathUtils.RangePlusMinusOne(mainSeed); } else { planetData.obliquity = (float)randomNumber6 * MathUtils.RangePlusMinusOne(mainSeed) * Patch.StandardObliquityAngle.Value; } Patch.Debug("Body runtimeSystemRotation", LogLevel.Debug, Patch.DebugReworkPlanetGen); //runtimeOrbitRotation obliquity adjustment planetData.runtimeSystemRotation = planetData.runtimeOrbitRotation * Quaternion.AngleAxis(planetData.obliquity, Vector3.forward); Patch.Debug("Body Retrograde", LogLevel.Debug, Patch.DebugReworkPlanetGen); //Define if the orbit is retrograde if (randomNumber14 < Patch.ChanceRetrogradeOrbit.Value) { planetData.HasRetrogradeOrbit(); } Patch.Debug("Body Neutron Star", LogLevel.Debug, Patch.DebugReworkPlanetGen); // Anomaly around neutron stars if (planetData.star.type == EStarType.NeutronStar) { planetData.OrbitAroundNeutronStar(); } Patch.Debug("Body Type Definition", LogLevel.Debug, Patch.DebugReworkPlanetGen); // type of the planet : if (gasGiant) { Patch.Debug("Body is Gas Giant", LogLevel.Debug, Patch.DebugReworkPlanetGen); planetData.type = EPlanetType.Gas; planetData.habitableBias = 100f; } else { Patch.Debug("Body TypeDefinition ( planet / Moon )", LogLevel.Debug, Patch.DebugReworkPlanetGen); var sunDistance = planetData.sunDistance; var ratioHabitableDistance = Patch.HabitabilityBaseConstant.Value; Patch.Debug("Body Habitability", LogLevel.Debug, Patch.DebugReworkPlanetGen); if (star.habitableRadius > 0.0 && sunDistance > 0.0) { ratioHabitableDistance = sunDistance / star.habitableRadius; } Patch.Debug("Star Habitability radius ", LogLevel.Debug, Patch.DebugReworkPlanetGen); var minRadiusHabitable = star.habitableRadius - Patch.HabitableRadiusAreaBaseline.Value; var maxRadiusHabitable = star.habitableRadius + Patch.HabitableRadiusAreaBaseline.Value; if (planetData.sunDistance < maxRadiusHabitable && planetData.sunDistance > minRadiusHabitable) { planetData.habitableBias = Patch.ChanceBeingHabitable.Value; } Patch.Debug("Body Temperature ( planet / Moon )", LogLevel.Debug, Patch.DebugReworkPlanetGen); planetData.temperatureBias = (float)(1.20000004768372 / (ratioHabitableDistance + 0.200000002980232) - 1.0); if (randomNumber11 < planetData.habitableBias) { Patch.Debug("Body Type Ocean ( planet / Moon )", LogLevel.Debug, Patch.DebugReworkPlanetGen); planetData.type = EPlanetType.Ocean; ++star.galaxy.habitableCount; } else if (ratioHabitableDistance < Patch.VolcanoPlanetDistanceRatio.Value) { Patch.Debug("Body Type Volcano ( planet / Moon )", LogLevel.Debug, Patch.DebugReworkPlanetGen); planetData.type = EPlanetType.Vocano; } else if (ratioHabitableDistance > Patch.IcePlanetDistanceRatio.Value) { Patch.Debug("Body Type Ice ( planet / Moon )", LogLevel.Debug, Patch.DebugReworkPlanetGen); planetData.type = EPlanetType.Ice; } else { Patch.Debug("Body Type Desert ( planet / Moon )", LogLevel.Debug, Patch.DebugReworkPlanetGen); planetData.type = EPlanetType.Desert; } Patch.Debug("Body Type Defined ( planet / Moon )", LogLevel.Debug, Patch.DebugReworkPlanetGen); } Patch.Debug("Body Luminosity( planet / Moon )", LogLevel.Debug, Patch.DebugReworkPlanetGen); //Luminosity planetData.luminosity = Mathf.Pow(planetData.star.lightBalanceRadius / (planetData.sunDistance + 0.01f), 0.6f); if (planetData.luminosity > 1.0) { planetData.luminosity = Mathf.Log(planetData.luminosity) + 1f; planetData.luminosity = Mathf.Log(planetData.luminosity) + 1f; planetData.luminosity = Mathf.Log(planetData.luminosity) + 1f; } planetData.luminosity = Mathf.Round(planetData.luminosity * 100f) / 100f; Patch.Debug("Body Size Def ( planet / Moon )", LogLevel.Debug, Patch.DebugReworkPlanetGen); //Size related stuff : if (planetData.type == EPlanetType.Gas) { var radiusGasGiantWanted = PatchSize.VanillaGasGiantSize; if (PatchSize.EnableResizingFeature.Value) { //Default : 0.25 var minScalingGasGiantRatio = (PatchSize.BaseGasGiantSize.Value - PatchSize.BaseGasGiantSizeVariationFactor.Value) / (PatchSize.BaseGasGiantSize.Value + PatchSize.BaseGasGiantSizeVariationFactor.Value); radiusGasGiantWanted = PatchSize.BaseGasGiantSize.Value + MathUtils.RangePlusMinusOne(mainSeed) * PatchSize.BaseGasGiantSizeVariationFactor.Value; radiusGasGiantWanted -= radiusGasGiantWanted % 10; } planetData.scale = PatchSize.VanillaGasGiantScale; planetData.radius = radiusGasGiantWanted / planetData.scale; planetData.precision = 64; planetData.segment = 2; } else if (planetData.type != EPlanetType.None) { if (PatchSize.EnableResizingFeature.Value) { var radiusTelluricWanted = PatchSize.VanillaTelluricSize; if (planetData.IsNotAMoon()) { radiusTelluricWanted = PatchSize.BaseTelluricSize.Value + MathUtils.RangePlusMinusOne(mainSeed) * PatchSize.BaseTelluricSizeVariationFactor.Value; } else { //A moon can only be smaller than it's host if (planetData.orbitAroundPlanet.type != EPlanetType.Gas) { radiusTelluricWanted = planetData.orbitAroundPlanet.radius - (float)mainSeed.NextDouble() * PatchSize.BaseTelluricSizeVariationFactor.Value; // clamp to avoid weird sizes radiusTelluricWanted = Mathf.Clamp(radiusTelluricWanted, PatchSize.MinTelluricSize.Value, planetData.orbitAroundPlanet.radius); } else { radiusTelluricWanted = PatchSize.BaseTelluricSize.Value + MathUtils.RangePlusMinusOne(mainSeed) * PatchSize.BaseTelluricSizeVariationFactor.Value; } } radiusTelluricWanted -= radiusTelluricWanted % 10; planetData.radius = Mathf.RoundToInt(radiusTelluricWanted); Patch.Debug(" planetData.radius" + planetData.radius, LogLevel.Debug, Patch.DebugReworkPlanetGenDeep); planetData.scale = planetData.GetScaleFactored(); Patch.Debug(" planetData.scale" + planetData.scale, LogLevel.Debug, Patch.DebugReworkPlanetGenDeep); planetData.precision = planetData.GetPrecisionFactored(); Patch.Debug(" planetData.precision" + planetData.precision, LogLevel.Debug, Patch.DebugReworkPlanetGenDeep); } else { planetData.radius = PatchSize.VanillaTelluricSize; planetData.scale = PatchSize.VanillaTelluricScale; planetData.precision = PatchSize.VanillaTelluricPrecision; } planetData.segment = 5; } else { planetData.radius = PatchSize.VanillaTelluricSize; planetData.precision = 64; planetData.segment = 2; } star.planets[planetData.index] = planetData; planetData.star = star; Patch.Debug("Body Theme Def ( planet / Moon )", LogLevel.Debug, Patch.DebugReworkPlanetGen); Patch.Debug("planetData \n" + "planetData.star.index " + planetData.star.index + "\n" + "planetData.index " + planetData.index + "\n" + "planetData.temperatureBias " + planetData.temperatureBias + "\n" + "planetData.planets " + planetData.star.planets + "\n" + "planetData.planets index : " + planetData.star.planets[planetData.index].type + "\n" + "planetData.planets Lenght " + planetData.star.planets.Length + "\n" + "planetData.type " + planetData.type + "\n" + "planetData.mod_x " + planetData.mod_x + "\n" + "planetData.mod_y " + planetData.mod_y + "\n" + "planetData.algoId " + planetData.algoId + "\n" , LogLevel.Debug, Patch.DebugReworkPlanetGen); star.galaxy.astroPoses[planetData.id].uRadius = planetData.realRadius; Patch.Debug("ReworkCreatePlanet Done !", LogLevel.Debug, Patch.DebugReworkPlanetGen); return(planetData); }
public void GenerateThePlanet(ref GalaxyData galaxy, ref StarData star, ref GameDesc gameDesc) { PlanetGen.CreatePlanet(galaxy, star, gameDesc, planetIndex, orbitAround, orbitIndex, number, isGasGiant, infoSeed, genSeed); }
//private int[] tmp_state; public GalaxyData CreateGalaxy(GameDesc gameDesc) { int galaxySeed = gameDesc.galaxySeed; int starCount = gameDesc.starCount; StarGen StarGen = new StarGen(); Random random = new Random(galaxySeed); int tempPoses = this.GenerateTempPoses(random.Next(), starCount, 4, 2.0, 2.3, 3.5, 0.18); GalaxyData galaxy = new GalaxyData(); galaxy.seed = galaxySeed; galaxy.starCount = tempPoses; galaxy.stars = new StarData[tempPoses]; //Assert.Positive(tempPoses); if (tempPoses <= 0) { return(galaxy); } float num1 = (float)random.NextDouble(); float num2 = (float)random.NextDouble(); float num3 = (float)random.NextDouble(); float num4 = (float)random.NextDouble(); int num5 = Mathf.CeilToInt((float)(0.00999999977648258 * (double)tempPoses + (double)num1 * 0.300000011920929)); int num6 = Mathf.CeilToInt((float)(0.00999999977648258 * (double)tempPoses + (double)num2 * 0.300000011920929)); int num7 = Mathf.CeilToInt((float)(0.0160000007599592 * (double)tempPoses + (double)num3 * 0.400000005960464)); int num8 = Mathf.CeilToInt((float)(0.0130000002682209 * (double)tempPoses + (double)num4 * 1.39999997615814)); int num9 = tempPoses - num5; int num10 = num9 - num6; int num11 = num10 - num7; int num12 = (num11 - 1) / num8; int num13 = num12 / 2; for (int index = 0; index < tempPoses; ++index) { int seed = random.Next(); if (index == 0) { //生成母星系 galaxy.stars[index] = StarGen.CreateBirthStar(galaxy, seed); } else { ESpectrType needSpectr = ESpectrType.X; if (index == 3) { needSpectr = ESpectrType.M; } else if (index == num11 - 1) { needSpectr = ESpectrType.O; } EStarType needtype = EStarType.MainSeqStar; if (index % num12 == num13) { needtype = EStarType.GiantStar; } if (index >= num9) { needtype = EStarType.BlackHole; } else if (index >= num10) { needtype = EStarType.NeutronStar; } else if (index >= num11) { needtype = EStarType.WhiteDwarf; } galaxy.stars[index] = StarGen.CreateStar(galaxy, this.tmp_poses[index], index + 1, seed, needtype, needSpectr); } } //AstroPose[] astroPoses = galaxy.astroPoses; StarData[] stars = galaxy.stars; //for (int index = 0; index < galaxy.astroPoses.Length; ++index) //{ // astroPoses[index].uRot.w = 1f; // astroPoses[index].uRotNext.w = 1f; //} for (int index = 0; index < tempPoses; ++index) { StarGen.CreateStarPlanets(galaxy, stars[index], gameDesc); //astroPoses[stars[index].id * 100].uPos = astroPoses[stars[index].id * 100].uPosNext = stars[index].uPosition; //astroPoses[stars[index].id * 100].uRot = astroPoses[stars[index].id * 100].uRotNext = Quaternion.identity; //astroPoses[stars[index].id * 100].uRadius = stars[index].physicsRadius; } //galaxy.UpdatePoses(0.0); galaxy.birthPlanetId = 0; if (tempPoses > 0) { StarData starData = stars[0]; for (int index = 0; index < starData.planetCount; ++index) { PlanetData planet = starData.planets[index]; ThemeProtoSet themes = ThemeWorks.GetThemes(); var themeProto = themes.dataArray[planet.theme - 1]; if (themeProto != null && themeProto.Distribute == EThemeDistribute.Birth) { galaxy.birthPlanetId = planet.id; galaxy.birthStarId = starData.id; break; } } } //Assert.Positive(galaxy.birthPlanetId); for (int index1 = 0; index1 < tempPoses; ++index1) { StarData star = galaxy.stars[index1]; for (int index2 = 0; index2 < star.planetCount; ++index2) { PlanetModelingManager.Algorithm(star.planets[index2]).GenerateVeins(true); } } //MUniverseGen.CreateGalaxyStarGraph(galaxy); return(galaxy); }