void Update() { if (spawnTimer.HasPassed(1.0f / spawnRate)) { spawnTimer.Reset(); Vector3 offset = box.size; offset.x *= Random.Range(-0.5f, 0.5f); offset.y *= Random.Range(-0.5f, 0.5f); Vector3 pos = transform.position + offset; var star = GameObject.Instantiate(starPrefab, pos, Quaternion.identity) as GameObject; SpawnFolder.SetParent(star, "Stars"); var size = Random.Range(minSpawnSize, 1.0f); star.transform.localScale *= size; var data = new StarData(); data.star = star; data.size = size; spawnedStars.Add(data); } for (int i = spawnedStars.Count - 1; i >= 0; i--) { var star = spawnedStars[i]; star.star.transform.position += Vector3.down * star.size * baseMoveSpeed * Time.deltaTime; if (star.star.transform.position.y < -transform.position.y) { spawnedStars.RemoveAt(i); GameObject.Destroy(star.star); } } }
public static StarData CreateSystemPlanets(StarData curSys) { PlanetGenerationData pgList = new PlanetGenerationData(); SpotPlanetGenerationTable pgTable = new SpotPlanetGenerationTable(); bool planetFound = false; try { pgList = planetGenerationDataList.Find(p => p.starType == curSys.SpectralClass); } catch (Exception ex) { Debug.LogError("Could not lookup " + curSys.SpectralClass.ToString() + " table for system " + curSys.Name + "! Error:" + ex.ToString()); return null; // try again with the next star } for (int x = 0; x < MaxPlanetsPerSystem; x++) // 6 spots to generate { pgTable = pgList.planetGenerationTable[x]; planetFound = false; // reset planet flag int generationChance = 0; int planetTypeChance = 0; // Step 1: check to see if there is a chance of a planet generationChance = UnityEngine.Random.Range(0, 100); if (generationChance <= pgTable.baseChance + (curSys.pMaterial * pgTable.materialMultiplier) - ((int)curSys.starMultipleType * pgTable.companionModifier)) // Step 2: look up the planet generation tables for this type of star and determine which planet type is generated { planetTypeChance = UnityEngine.Random.Range(0, 100); for (int y = 0; y < pgTable.chanceData.Count; y++) // look up planet data on each table { if (!planetFound) { int curChance = pgTable.chanceData[y]; if (planetTypeChance <= curChance) { PlanetData curPlanetData = new PlanetData(); curPlanetData = GeneratePlanet((PlanetData.ePlanetType)pgTable.typeData[y],curSys,x+1); curPlanetData.SystemID = curSys.ID; galaxyDataRef.AddPlanetDataToList(curPlanetData); //curSys.PlanetList.Add(curPlanetData); // a planet is born! Generate it now curSys.PlanetSpots[x] = curPlanetData; // stick it in the correct 'spot' (probably will rewrite) planetFound = true; } } } } } return curSys; }
private static void GenerateStar(StarData stData) { // Step 1: Pick name for star if (DataManager.systemNameList.Count > 0) { var nameIndex = UnityEngine.Random.Range(0, DataManager.systemNameList.Count); stData.Name = DataManager.systemNameList[nameIndex]; DataManager.systemNameList.RemoveAt(nameIndex); DataManager.systemNameList.TrimExcess(); } else { stData.Name = "GenericName"; } // Step 2/3: Determine spectral class/adjust // generate age int specAge = 0; specAge = UnityEngine.Random.Range(1, 11); stData.Age = specAge; // assign age // assign classes DetermineSpectralClasses(stData, "S"); // Step 3b: Adjust size for secondary spectral class stData.Size -= stData.SecondarySpectralClass; // Step 4: Now check for the possibility of multiple star systems (binary, trinary systems) int binChance = UnityEngine.Random.Range(1, 11); // check 1D10 for -nary system if (binChance <= 4) { if (binChance > 2 && binChance < 5) { stData.starMultipleType = StarData.eStarMultiple.Binary; // binary system DetermineSpectralClasses(stData, "B"); } else { stData.starMultipleType = StarData.eStarMultiple.Trinary; // trinary system DetermineSpectralClasses(stData, "B"); // determine binary class DetermineSpectralClasses(stData, "T"); // and then trinary } } // Step 5: Generate specials for each star (not all stars may have a special!) - TBD // Step 6: Determine metallicity stData.Metallicity = UnityEngine.Random.Range(1, 11); // Step 7: Generate stellar planetary material (automatically calculated in the class; derived when needed // Step 8: Generate star ID stData.ID = "STAR" + stData.Name.Substring(0, 2).ToUpper() + UnityEngine.Random.Range(0, 10000); // 2 parts: first 4 letters of name and 5 digit # creates unique ID // Step 9: Reset Intel level to 0 (determine from empire settings) stData.IntelValue = 0; }
private static void DetermineSpectralClasses(StarData stData, string stType) { int specClass = 0; int secSpecClass = 0; // rolls for spectral classes specClass = UnityEngine.Random.Range(1, 101); secSpecClass = UnityEngine.Random.Range(1, 11); if (specClass < 3) { if (stType == "S") { stData.SpectralClass = StarData.eSpectralClass.O_B; stData.Size = 90; } else if (stType == "B") { stData.compSpectralClass = StarData.eSpectralClass.O_B; stData.Size = 90; } else { stData.terniaryCompSpectralClass = StarData.eSpectralClass.O_B; stData.Size = 90; } } else if (specClass < 8) { if (stType == "S") { stData.SpectralClass = StarData.eSpectralClass.A; stData.Size = 70; } else if (stType == "B") { stData.compSpectralClass = StarData.eSpectralClass.A; stData.Size = 70; } else { stData.terniaryCompSpectralClass = StarData.eSpectralClass.A; stData.Size = 70; } } else if (specClass < 21) { stData.Size = 60; if (stType == "S") stData.SpectralClass = StarData.eSpectralClass.F; else if (stType == "B") stData.compSpectralClass = StarData.eSpectralClass.F; else stData.terniaryCompSpectralClass = StarData.eSpectralClass.F; } else if (specClass < 38) { stData.Size = 50; if (stType == "S") stData.SpectralClass = StarData.eSpectralClass.G; else if (stType == "B") stData.compSpectralClass = StarData.eSpectralClass.G; else stData.terniaryCompSpectralClass = StarData.eSpectralClass.G; } else if (specClass < 59) { stData.Size = 40; if (stType == "S") { stData.SpectralClass = StarData.eSpectralClass.K; stData.Size = 40; } else if (stType == "B") stData.compSpectralClass = StarData.eSpectralClass.K; else stData.terniaryCompSpectralClass = StarData.eSpectralClass.K; } else if (specClass < 77) { stData.Size = 20; if (stType == "S") { stData.SpectralClass = StarData.eSpectralClass.M; stData.Size = 20; } else if (stType == "B") stData.compSpectralClass = StarData.eSpectralClass.M; else stData.terniaryCompSpectralClass = StarData.eSpectralClass.M; } else if (specClass < 84) { stData.Size = 17; if (stType == "S") { stData.SpectralClass = StarData.eSpectralClass.L; stData.Size = 17; } else if (stType == "B") stData.compSpectralClass = StarData.eSpectralClass.L; else stData.terniaryCompSpectralClass = StarData.eSpectralClass.L; } else if (specClass < 90) { stData.Size = 15; if (stType == "S") { stData.SpectralClass = StarData.eSpectralClass.T; } else if (stType == "B") stData.compSpectralClass = StarData.eSpectralClass.T; else stData.terniaryCompSpectralClass = StarData.eSpectralClass.T; } else if (specClass < 93) { stData.Size = 20; if (stType == "S") { stData.SpectralClass = StarData.eSpectralClass.D; } else if (stType == "B") stData.compSpectralClass = StarData.eSpectralClass.D; else stData.terniaryCompSpectralClass = StarData.eSpectralClass.D; } else if (specClass < 97) { stData.Size = 50; if (stType == "S") { stData.SpectralClass = StarData.eSpectralClass.BH; } else if (stType == "B") stData.compSpectralClass = StarData.eSpectralClass.BH; else stData.terniaryCompSpectralClass = StarData.eSpectralClass.BH; } else { stData.SpectralClass = StarData.eSpectralClass.NoStar; } stData.SecondarySpectralClass = secSpecClass; // assign secondary class // Step 3: Now compare age and adjust the spectral class if needed due to age //giant stars if (stType == "S") { if (stData.Age == 10 && stData.SpectralClass < (StarData.eSpectralClass)3) { stData.SpectralClass = StarData.eSpectralClass.BH; //black hole stData.Size = 50; } if (stData.Age == 9 && stData.SpectralClass < (StarData.eSpectralClass)3) { stData.SpectralClass = StarData.eSpectralClass.Neutron; //neutron star stData.Size = 15; } if (stData.Age == 8 && stData.SpectralClass < (StarData.eSpectralClass)3) { stData.SpectralClass = StarData.eSpectralClass.RG; //sub-giant stData.Size = 120; } //main sequence stars if (stData.Age == 10 && (int)stData.SpectralClass < 6 && (int)stData.SpectralClass > 1) { stData.SpectralClass = StarData.eSpectralClass.D; //degenerate/white dwarf stData.Size = 20; } if (stData.Age == 9 && (int)stData.SpectralClass < 6 && (int)stData.SpectralClass > 2) { stData.SpectralClass = StarData.eSpectralClass.Neutron; //neutron star stData.Size = 20; } if (stData.Age == 8 && (int)stData.SpectralClass < 6 && (int)stData.SpectralClass > 2) { stData.SpectralClass = StarData.eSpectralClass.SG; //red giant stData.Size = 120; } } else // binary star adjustments { StarData.eSpectralClass tempClass = StarData.eSpectralClass.NoStar; bool changeOfClass = false; if ((int)stData.SpectralClass == 11) { tempClass = StarData.eSpectralClass.WR; changeOfClass = true; } if ((int)stData.SpectralClass > 1 && (int)stData.SpectralClass < 6) { int compChangeChange = UnityEngine.Random.Range(0, 101); // 33% chance of a white dwarf binary companion if SC is low if (compChangeChange < 34) { tempClass = StarData.eSpectralClass.D; changeOfClass = true; } } if ((int)stData.SpectralClass > 10 && (int)stData.SpectralClass <15) { int compChangeChange = UnityEngine.Random.Range(0, 101); // 80% chance of a white dwarf binary companion if spectral class is high if (compChangeChange < 81) { tempClass = StarData.eSpectralClass.D; changeOfClass = true; } } if (changeOfClass) { if (stType == "B") stData.compSpectralClass = tempClass; else stData.terniaryCompSpectralClass = tempClass; } } }
public void ResetInfo(StarProperties starProperties, StarData starData) { m_PlanetAmount.text = starData.PlanetAmount.ToString(); m_StarName.text = "Star No." + starProperties.Index.ToString(); m_StarInfo.text = "Mass: \t" + starProperties.Mass.ToString() + "\nProportion: \t" + starProperties.Proportion.ToString(); }
public void InitialApply(StaticsDB statics, StarData star, IEnumerable <Planet> planets) { //no operation }
public MoveMission(StarData destination, Wormhole usedWormhole) { this.Destination = destination; this.UsedWormhole = usedWormhole; }
void Start() { EnitColorGradient(); string[] data = cataloque.text.Split(new char[] { '\n' }); //Note: First row is data labels, so skip that one for (int i = 1; i < data.Length; i++) { StarData sd = new StarData(); var style = NumberStyles.Float; var culture = CultureInfo.InvariantCulture; string[] row = data[i].Split(new char[] { ',' }); int.TryParse(row[0], style, culture, out sd.StarID); int.TryParse(row[1], out sd.HIP); int.TryParse(row[2], out sd.HD); int.TryParse(row[3], out sd.HR); sd.Gliese = row[4]; sd.BayerFlamsteed = row[5]; sd.ProperName = row[6]; float.TryParse(row[7], out sd.RA); float.TryParse(row[8], out sd.Dec); float.TryParse(row[9], out sd.Distance); //Don't bother with PMRA, PMDec and RV float.TryParse(row[13], style, culture, out sd.Mag); float.TryParse(row[14], style, culture, out sd.AbsMag); sd.Spectrum = row[15]; float.TryParse(row[16], style, culture, out sd.ColorIndex); float.TryParse(row[17], style, culture, out sd.X); float.TryParse(row[18], style, culture, out sd.Y); float.TryParse(row[19], style, culture, out sd.Z); float.TryParse(row[20], style, culture, out sd.VX); float.TryParse(row[21], style, culture, out sd.VY); float.TryParse(row[22], style, culture, out sd.VZ); StarDataList.Add(sd); } for (int i = 0; i < StarDataList.Count; i++) { Vector3 pos = new Vector3(StarDataList[i].X, StarDataList[i].Y, StarDataList[i].Z) / 1f; Color32 color = GetBVColor(StarDataList[i].ColorIndex); float size = ExtensionMethods.Remap(StarDataList[i].AbsMag, 17f, -10f, 0.1f, 1f); if (string.IsNullOrEmpty(StarDataList[i].ProperName)) { var emitParams = new ParticleSystem.EmitParams(); emitParams.position = pos; emitParams.startColor = color; emitParams.startSize = size; particleSystem.Emit(emitParams, 1); } else { NamedStar star = Instantiate(namedStarPrefab, pos, Quaternion.identity, center); star.Init(size, color, StarDataList[i].ProperName); } } }
public static void GenerateAllPlanets(GalaxyData galaxy, StarData star, GameDesc gameDesc, List <PlanetForGenerator> planetsToGenerate) { bool isDebugOn = star.IsStartingStar(); Patch.Debug("Recap of what have to be generated : \n", LogLevel.Debug, Patch.DebugStarGen && isDebugOn); 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 && isDebugOn); } }
public static void PreGenerateAllBodies(StarData star, List <PlanetForGenerator> planetsToGenerate, Random annexSeed, PlanetGeneratorSettings genSettings, PatchForStarSystemGeneration.StarSystemSetting currentSettings) { bool isDebugOn = star.IsStartingStar(); // //preparation of the planet creation : Patch.Debug("Define the belts for whatever they are for :", LogLevel.Debug, Patch.DebugStarGenDeep); //Define where the 2 asteroids belts are ( maybe not implemented ) var asterBelt1OrbitIndex = UnityRandom.Range(1, genSettings.nbOfPlanets - 1); var asterBelt2OrbitIndex = UnityRandom.Range(asterBelt1OrbitIndex + 1, genSettings.nbOfPlanets); Patch.Debug("asterBelt1OrbitIndex :" + asterBelt1OrbitIndex, LogLevel.Debug, Patch.DebugStarGenDeep); Patch.Debug("asterBelt2OrbitIndex :" + asterBelt2OrbitIndex, LogLevel.Debug, Patch.DebugStarGenDeep); //Attach the information to the star star.asterBelt1OrbitIndex = asterBelt1OrbitIndex; star.asterBelt2OrbitIndex = asterBelt2OrbitIndex; star.asterBelt1Radius = Patch.OrbitRadiusPlanetArray[asterBelt1OrbitIndex]; star.asterBelt2Radius = Patch.OrbitRadiusPlanetArray[asterBelt2OrbitIndex]; int infoSeed; int genSeed; // planets pre-generation var nbOfBodiesPreGenerated = 0; var nbOfPlanetsPreGenerated = 0; var planetsPreGeneratedNumber = 1; var nbOfMoonsPreGenerated = 0; var currentOrbitPlanetIndex = 1; var previousOrbitPlanetIndex = 0; int currentOrbitMoonIndex; var beltGenerated = 0; int jumpOrbitMargin; for (var i = 0; i < genSettings.nbOfStellarBodies; i++) { infoSeed = annexSeed.Next(); genSeed = annexSeed.Next(); var planetInfoSeed = 0 + infoSeed; var planetGenSeed = 0 + genSeed; Patch.Debug("bodies generated !" + nbOfBodiesPreGenerated, LogLevel.Debug, Patch.DebugStarGenDeep); Patch.Debug("genSettings.nbOfPlanets + genSettings.nbOfMoons !" + (genSettings.nbOfPlanets + genSettings.nbOfMoons), LogLevel.Debug, Patch.DebugStarGenDeep); bool isGasGiant; var orbitAround = 0; if (asterBelt1OrbitIndex == currentOrbitPlanetIndex) { Patch.Debug("Jump Belt 1 Orbit :", LogLevel.Debug, Patch.DebugStarGenDeep); currentOrbitPlanetIndex++; nbOfBodiesPreGenerated++; beltGenerated++; } if (asterBelt2OrbitIndex == currentOrbitPlanetIndex) { Patch.Debug("Jump Belt 2 Orbit :", LogLevel.Debug, Patch.DebugStarGenDeep); currentOrbitPlanetIndex++; nbOfBodiesPreGenerated++; beltGenerated++; } Patch.Debug("nbOfPlanetsPreGenerated : " + nbOfPlanetsPreGenerated, LogLevel.Debug, Patch.DebugStarGenDeep); Patch.Debug("nbOfPlanets : " + genSettings.nbOfPlanets, LogLevel.Debug, Patch.DebugStarGenDeep); if (nbOfPlanetsPreGenerated < genSettings.nbOfPlanets) { //planets // jumporbit planet jumpOrbitMargin = Patch.OrbitRadiusArrayPlanetNb.Value - (genSettings.nbOfPlanets - nbOfPlanetsPreGenerated); if (currentOrbitPlanetIndex < jumpOrbitMargin && jumpOrbitMargin < currentSettings.JumpOrbitPlanetMax) { if (annexSeed.NextDouble() < currentSettings.ChanceJumpOrbitPlanets)// can jump orbit up to JumpOrbitPlanetIndex { currentOrbitPlanetIndex = UnityRandom.Range(currentOrbitPlanetIndex, currentOrbitPlanetIndex + currentSettings.JumpOrbitPlanetMax); } } previousOrbitPlanetIndex = currentOrbitPlanetIndex; orbitAround = 0; if (nbOfBodiesPreGenerated < genSettings.nbOfTelluricPlanets + beltGenerated)//telluric { isGasGiant = false; } else//gasgiant { isGasGiant = true; } planetsToGenerate.Add(new PlanetForGenerator(nbOfBodiesPreGenerated - beltGenerated, orbitAround, currentOrbitPlanetIndex, planetsPreGeneratedNumber, isGasGiant, planetInfoSeed, planetGenSeed, null)); Patch.Debug("planetsToGenerate --> \n" + planetsToGenerate[nbOfPlanetsPreGenerated].ToStringDebug(), LogLevel.Debug, Patch.DebugStarGen && isDebugOn); nbOfPlanetsPreGenerated++; planetsPreGeneratedNumber++; currentOrbitPlanetIndex++; if (isGasGiant) { Patch.Debug("gas Giant generated !", LogLevel.Debug, Patch.DebugStarGen && isDebugOn); } else { Patch.Debug("planet generated !", LogLevel.Debug, Patch.DebugStarGen && isDebugOn); } } else if (nbOfBodiesPreGenerated < genSettings.nbOfPlanets + genSettings.nbOfMoons + beltGenerated) { Patch.Debug("Moon in generation!", LogLevel.Debug, Patch.DebugStarGen && isDebugOn); isGasGiant = false; if (genSettings.nbOfTelluricPlanets != 0 && nbOfBodiesPreGenerated < genSettings.nbOfPlanets + genSettings.nbOfMoonsTelluric + beltGenerated) { // telluric moon orbitAround = UnityRandom.Range(1, genSettings.nbOfTelluricPlanets); Patch.Debug("telluric moon! orbit around : " + orbitAround, LogLevel.Debug, Patch.DebugStarGenDeep); } else { if (genSettings.nbOfGasGiantPlanets != 0) { //gasgiant moon orbitAround = UnityRandom.Range(genSettings.nbOfTelluricPlanets + 1, genSettings.nbOfTelluricPlanets + genSettings.nbOfGasGiantPlanets); Patch.Debug("gas moon! orbit around : " + orbitAround, LogLevel.Debug, Patch.DebugStarGenDeep); } } if (orbitAround <= 0) { Patch.Debug("Issue in moon generation : " + orbitAround, LogLevel.Debug, Patch.DebugStarGen && isDebugOn); } jumpOrbitMargin = Patch.OrbitRadiusArrayMoonsNb.Value - (genSettings.nbOfMoons - nbOfMoonsPreGenerated); Patch.Debug("orbitAround - 1 : " + (orbitAround - 1), LogLevel.Debug, Patch.DebugStarGenDeep); Patch.Debug("planetsToGenerate.Count :" + planetsToGenerate.Count, LogLevel.Debug, Patch.DebugStarGenDeep); Patch.Debug("planetsToGenerate[orbitAround - 1] :" + planetsToGenerate[orbitAround - 1].orbitIndex, LogLevel.Debug, Patch.DebugStarGenDeep); int currentPlanetMoonsNb; var currentPlanet = planetsToGenerate[orbitAround - 1]; Patch.Debug("planetsToGenerate nb :" + planetsToGenerate.Count, LogLevel.Debug, Patch.DebugStarGenDeep); currentPlanetMoonsNb = currentPlanet.moons.Count; Patch.Debug("currentPlanetMoonsNb :" + currentPlanetMoonsNb, LogLevel.Debug, Patch.DebugStarGenDeep); if (currentPlanetMoonsNb != 0) { currentOrbitMoonIndex = currentPlanet.moons[currentPlanetMoonsNb - 1].orbitIndex + 1; } else { currentOrbitMoonIndex = 0; } Patch.Debug("currentOrbitMoonIndex : " + currentOrbitMoonIndex, LogLevel.Debug, Patch.DebugStarGenDeep); if (currentOrbitMoonIndex < jumpOrbitMargin && jumpOrbitMargin < currentSettings.JumpOrbitMoonMax) { if (annexSeed.NextDouble() < currentSettings.ChanceJumpOrbitMoons) { // can jump orbit up to JumpOrbitPlanetIndex var oldOrbitIndex = currentOrbitMoonIndex; currentOrbitMoonIndex += UnityRandom.Range(currentOrbitMoonIndex, currentOrbitMoonIndex + currentSettings.JumpOrbitMoonMax); } } currentPlanet.AddMoonInOrbit(nbOfBodiesPreGenerated, currentOrbitMoonIndex, planetGenSeed, planetInfoSeed); nbOfMoonsPreGenerated++; Patch.Debug("moonToGenerate --> +" + genSettings.nbOfMoons + " --> nbOfMoonsPreGenerated : " + nbOfMoonsPreGenerated, LogLevel.Debug, Patch.DebugStarGenDeep); } nbOfBodiesPreGenerated++; } }
public override void ProcessPacket(DysonSphereData packet, NebulaConnection conn) { if (IsHost) { return; } switch (packet.Event) { case DysonSphereRespondEvent.List: //Overwrite content assigned by UIDETopFunction.SetDysonComboBox() UIComboBox dysonBox = UIRoot.instance.uiGame.dysonEditor.controlPanel.topFunction.dysonBox; using (BinaryReader br = new BinaryUtils.Reader(packet.BinaryData).BinaryReader) { dysonBox.Items = new List <string>(); dysonBox.ItemsData = new List <int>(); int count = br.ReadInt32(); for (int i = 0; i < count; i++) { int starIndex = br.ReadInt32(); dysonBox.Items.Add(GameMain.galaxy.stars[starIndex].displayName); dysonBox.ItemsData.Add(starIndex); } } int index = dysonBox.ItemsData.FindIndex(x => x == UIRoot.instance.uiGame.dysonEditor.selection.viewStar?.index); dysonBox.itemIndex = index >= 0 ? index : 0; break; case DysonSphereRespondEvent.Load: //Failsafe, if client does not have instantiated sphere for the star, it will create dummy one that will be replaced during import GameMain.data.dysonSpheres[packet.StarIndex] = new DysonSphere(); GameMain.data.statistics.production.Init(GameMain.data); //Another failsafe, DysonSphere import requires initialized factory statistics if (GameMain.data.statistics.production.factoryStatPool[0] == null) { GameMain.data.statistics.production.factoryStatPool[0] = new FactoryProductionStat(); GameMain.data.statistics.production.factoryStatPool[0].Init(); } GameMain.data.dysonSpheres[packet.StarIndex].Init(GameMain.data, GameMain.data.galaxy.stars[packet.StarIndex]); StarData star = GameMain.galaxy.stars[packet.StarIndex]; Log.Info($"Parsing {packet.BinaryData.Length} bytes of data for DysonSphere {star.name} (INDEX: {star.id})"); using (BinaryUtils.Reader reader = new BinaryUtils.Reader(packet.BinaryData)) { GameMain.data.dysonSpheres[packet.StarIndex].Import(reader.BinaryReader); } if (UIRoot.instance.uiGame.dysonEditor.active) { UIRoot.instance.uiGame.dysonEditor.selection.SetViewStar(GameMain.galaxy.stars[packet.StarIndex]); UIComboBox dysonBox2 = UIRoot.instance.uiGame.dysonEditor.controlPanel.topFunction.dysonBox; int index2 = dysonBox2.ItemsData.FindIndex(x => x == UIRoot.instance.uiGame.dysonEditor.selection.viewStar?.index); dysonBox2.itemIndex = index2 >= 0 ? index2 : 0; } if (Multiplayer.Session.IsGameLoaded) { // Don't fade out when client is still joining InGamePopup.FadeOut(); } Multiplayer.Session.DysonSpheres.RequestingIndex = -1; Multiplayer.Session.DysonSpheres.IsNormal = true; break; case DysonSphereRespondEvent.Desync: Multiplayer.Session.DysonSpheres.HandleDesync(packet.StarIndex, conn); break; } }
public void SetStarAge(StarData star, float age, double rn, double rt) { float num1 = (float)(rn * 0.1 + 0.95); float num2 = (float)(rt * 0.4 + 0.8); float num3 = (float)(rt * 9.0 + 1.0); star.age = age; if ((double)age >= 1.0) { if ((double)star.mass >= 18.0) { star.type = EStarType.BlackHole; star.spectr = ESpectrType.X; star.mass *= 2.5f * num2; star.radius *= 1f; star.acdiskRadius = star.radius * 5f; star.temperature = 0.0f; star.luminosity *= 1f / 1000f * num1; star.habitableRadius = 0.0f; star.lightBalanceRadius *= 0.4f * num1; } else if ((double)star.mass >= 7.0) { star.type = EStarType.NeutronStar; star.spectr = ESpectrType.X; star.mass *= 0.2f * num1; star.radius *= 0.15f; star.acdiskRadius = star.radius * 9f; star.temperature = num3 * 1E+07f; star.luminosity *= 0.1f * num1; star.habitableRadius = 0.0f; star.lightBalanceRadius *= 3f * num1; star.orbitScaler *= 1.5f * num1; } else { star.type = EStarType.WhiteDwarf; star.spectr = ESpectrType.X; star.mass *= 0.2f * num1; star.radius *= 0.2f; star.acdiskRadius = 0.0f; star.temperature = num2 * 150000f; star.luminosity *= 0.04f * num2; star.habitableRadius *= 0.15f * num2; star.lightBalanceRadius *= 0.2f * num1; } } else { if ((double)age < 0.959999978542328) { return; } float num4 = (float)(Math.Pow(5.0, Math.Abs(Math.Log10((double)star.mass) - 0.7)) * 5.0); if ((double)num4 > 10.0) { num4 = (float)(((double)Mathf.Log(num4 * 0.1f) + 1.0) * 10.0); } float num5 = (float)(1.0 - (double)Mathf.Pow(star.age, 30f) * 0.5); star.type = EStarType.GiantStar; star.mass = num5 * star.mass; star.radius = num4 * num2; star.acdiskRadius = 0.0f; star.temperature = num5 * star.temperature; star.luminosity = 1.6f * star.luminosity; star.habitableRadius = 9f * star.habitableRadius; star.lightBalanceRadius = 3f * star.habitableRadius; star.orbitScaler = 3.3f * star.orbitScaler; } }
public StarData CreateStar( GalaxyData galaxy, VectorLF3 pos, int id, int seed, EStarType needtype, ESpectrType needSpectr = ESpectrType.X) { StarData starData = new StarData() { galaxy = galaxy, index = id - 1 }; starData.level = galaxy.starCount <= 1 ? 0.0f : (float)starData.index / (float)(galaxy.starCount - 1); starData.id = id; starData.seed = seed; Random random1 = new Random(seed); int seed1 = random1.Next(); int Seed = random1.Next(); starData.position = pos; float num1 = (float)pos.magnitude / 32f; if ((double)num1 > 1.0) { num1 = Mathf.Log(Mathf.Log(Mathf.Log(Mathf.Log(Mathf.Log(num1) + 1f) + 1f) + 1f) + 1f) + 1f; } starData.resourceCoef = Mathf.Pow(7f, num1) * 0.6f; Random random2 = new Random(Seed); double r1 = random2.NextDouble(); double r2 = random2.NextDouble(); double num2 = random2.NextDouble(); double rn = random2.NextDouble(); double rt = random2.NextDouble(); double num3 = (random2.NextDouble() - 0.5) * 0.2; double num4 = random2.NextDouble() * 0.2 + 0.9; double y = random2.NextDouble() * 0.4 - 0.2; double num5 = Math.Pow(2.0, y); float num6 = Mathf.Lerp(-0.98f, 0.88f, starData.level); float averageValue = (double)num6 >= 0.0 ? num6 + 0.65f : num6 - 0.65f; float standardDeviation = 0.33f; if (needtype == EStarType.GiantStar) { averageValue = y <= -0.08 ? 1.6f : -1.5f; standardDeviation = 0.3f; } float num7 = this.RandNormal(averageValue, standardDeviation, r1, r2); switch (needSpectr) { case ESpectrType.M: num7 = -3f; break; case ESpectrType.O: num7 = 3f; break; } float p1 = (float)((double)Mathf.Clamp((double)num7 <= 0.0 ? num7 * 1f : num7 * 2f, -2.4f, 4.65f) + num3 + 1.0); switch (needtype) { case EStarType.WhiteDwarf: starData.mass = (float)(1.0 + r2 * 5.0); break; case EStarType.NeutronStar: starData.mass = (float)(7.0 + r1 * 11.0); break; case EStarType.BlackHole: starData.mass = (float)(18.0 + r1 * r2 * 30.0); break; default: starData.mass = Mathf.Pow(2f, p1); break; } double d = 5.0; if ((double)starData.mass < 2.0) { d = 2.0 + 0.4 * (1.0 - (double)starData.mass); } starData.lifetime = (float)(10000.0 * Math.Pow(0.1, Math.Log10((double)starData.mass * 0.5) / Math.Log10(d) + 1.0) * num4); switch (needtype) { case EStarType.GiantStar: starData.lifetime = (float)(10000.0 * Math.Pow(0.1, Math.Log10((double)starData.mass * 0.58) / Math.Log10(d) + 1.0) * num4); starData.age = (float)(num2 * 0.0399999991059303 + 0.959999978542328); break; case EStarType.WhiteDwarf: case EStarType.NeutronStar: case EStarType.BlackHole: starData.age = (float)(num2 * 0.400000005960464 + 1.0); if (needtype == EStarType.WhiteDwarf) { starData.lifetime += 10000f; break; } if (needtype == EStarType.NeutronStar) { starData.lifetime += 1000f; break; } break; default: starData.age = (double)starData.mass >= 0.5 ? ((double)starData.mass >= 0.8 ? (float)(num2 * 0.699999988079071 + 0.200000002980232) : (float)(num2 * 0.400000005960464 + 0.100000001490116)) : (float)(num2 * 0.119999997317791 + 0.0199999995529652); break; } float num8 = starData.lifetime * starData.age; if ((double)num8 > 5000.0) { num8 = (float)(((double)Mathf.Log(num8 / 5000f) + 1.0) * 5000.0); } if ((double)num8 > 8000.0) { num8 = (Mathf.Log(Mathf.Log(Mathf.Log(num8 / 8000f) + 1f) + 1f) + 1f) * 8000f; } starData.lifetime = num8 / starData.age; float f = (float)(1.0 - (double)Mathf.Pow(Mathf.Clamp01(starData.age), 20f) * 0.5) * starData.mass; starData.temperature = (float)(Math.Pow((double)f, 0.56 + 0.14 / (Math.Log10((double)f + 4.0) / Math.Log10(5.0))) * 4450.0 + 1300.0); double num9 = Math.Log10(((double)starData.temperature - 1300.0) / 4500.0) / Math.Log10(2.6) - 0.5; if (num9 < 0.0) { num9 *= 4.0; } if (num9 > 2.0) { num9 = 2.0; } else if (num9 < -4.0) { num9 = -4.0; } starData.spectr = (ESpectrType)Mathf.RoundToInt((float)num9 + 4f); starData.color = Mathf.Clamp01((float)((num9 + 3.5) * 0.200000002980232)); starData.classFactor = (float)num9; starData.luminosity = Mathf.Pow(f, 0.7f); starData.radius = (float)(Math.Pow((double)starData.mass, 0.4) * num5); starData.acdiskRadius = 0.0f; float p2 = (float)num9 + 2f; starData.habitableRadius = Mathf.Pow(1.7f, p2) + 0.25f * Mathf.Min(1f, starData.orbitScaler); starData.lightBalanceRadius = Mathf.Pow(1.7f, p2); starData.orbitScaler = Mathf.Pow(1.35f, p2); if ((double)starData.orbitScaler < 1.0) { starData.orbitScaler = Mathf.Lerp(starData.orbitScaler, 1f, 0.6f); } this.SetStarAge(starData, starData.age, rn, rt); starData.dysonRadius = starData.orbitScaler * 0.28f; if ((double)starData.dysonRadius * 40000.0 < (double)starData.physicsRadius * 1.5) { starData.dysonRadius = (float)((double)starData.physicsRadius * 1.5 / 40000.0); } starData.uPosition = starData.position * 2400000.0; starData.name = NameGen.RandomStarName(seed1, starData, galaxy); starData.overrideName = string.Empty; return(starData); }
public void CreateStarPlanets(GalaxyData galaxy, StarData star, GameDesc gameDesc) { MPlanetGen MPlanetGen = new MPlanetGen(); Random random1 = new Random(star.seed); random1.Next(); random1.Next(); random1.Next(); Random random2 = new Random(random1.Next()); double num1 = random2.NextDouble(); double num2 = random2.NextDouble(); double num3 = random2.NextDouble(); double num4 = random2.NextDouble(); double num5 = random2.NextDouble(); double num6 = random2.NextDouble() * 0.2 + 0.9; double num7 = random2.NextDouble() * 0.2 + 0.9; if (star.type == EStarType.BlackHole) { star.planetCount = 1; star.planets = new PlanetData[star.planetCount]; int info_seed = random2.Next(); int gen_seed = random2.Next(); star.planets[0] = MPlanetGen.CreatePlanet(galaxy, star, gameDesc, 0, 0, 3, 1, false, info_seed, gen_seed); } else if (star.type == EStarType.NeutronStar) { star.planetCount = 1; star.planets = new PlanetData[star.planetCount]; int info_seed = random2.Next(); int gen_seed = random2.Next(); star.planets[0] = MPlanetGen.CreatePlanet(galaxy, star, gameDesc, 0, 0, 3, 1, false, info_seed, gen_seed); } else if (star.type == EStarType.WhiteDwarf) { if (num1 < 0.699999988079071) { star.planetCount = 1; star.planets = new PlanetData[star.planetCount]; int info_seed = random2.Next(); int gen_seed = random2.Next(); star.planets[0] = MPlanetGen.CreatePlanet(galaxy, star, gameDesc, 0, 0, 3, 1, false, info_seed, gen_seed); } else { star.planetCount = 2; star.planets = new PlanetData[star.planetCount]; if (num2 < 0.300000011920929) { int info_seed1 = random2.Next(); int gen_seed1 = random2.Next(); star.planets[0] = MPlanetGen.CreatePlanet(galaxy, star, gameDesc, 0, 0, 3, 1, false, info_seed1, gen_seed1); int info_seed2 = random2.Next(); int gen_seed2 = random2.Next(); star.planets[1] = MPlanetGen.CreatePlanet(galaxy, star, gameDesc, 1, 0, 4, 2, false, info_seed2, gen_seed2); } else { int info_seed1 = random2.Next(); int gen_seed1 = random2.Next(); star.planets[0] = MPlanetGen.CreatePlanet(galaxy, star, gameDesc, 0, 0, 4, 1, true, info_seed1, gen_seed1); int info_seed2 = random2.Next(); int gen_seed2 = random2.Next(); star.planets[1] = MPlanetGen.CreatePlanet(galaxy, star, gameDesc, 1, 1, 1, 1, false, info_seed2, gen_seed2); } } } else if (star.type == EStarType.GiantStar) { if (num1 < 0.300000011920929) { star.planetCount = 1; star.planets = new PlanetData[star.planetCount]; int info_seed = random2.Next(); int gen_seed = random2.Next(); star.planets[0] = MPlanetGen.CreatePlanet(galaxy, star, gameDesc, 0, 0, num3 <= 0.5 ? 2 : 3, 1, false, info_seed, gen_seed); } else if (num1 < 0.800000011920929) { star.planetCount = 2; star.planets = new PlanetData[star.planetCount]; if (num2 < 0.25) { int info_seed1 = random2.Next(); int gen_seed1 = random2.Next(); star.planets[0] = MPlanetGen.CreatePlanet(galaxy, star, gameDesc, 0, 0, num3 <= 0.5 ? 2 : 3, 1, false, info_seed1, gen_seed1); int info_seed2 = random2.Next(); int gen_seed2 = random2.Next(); star.planets[1] = MPlanetGen.CreatePlanet(galaxy, star, gameDesc, 1, 0, num3 <= 0.5 ? 3 : 4, 2, false, info_seed2, gen_seed2); } else { int info_seed1 = random2.Next(); int gen_seed1 = random2.Next(); star.planets[0] = MPlanetGen.CreatePlanet(galaxy, star, gameDesc, 0, 0, 3, 1, true, info_seed1, gen_seed1); int info_seed2 = random2.Next(); int gen_seed2 = random2.Next(); star.planets[1] = MPlanetGen.CreatePlanet(galaxy, star, gameDesc, 1, 1, 1, 1, false, info_seed2, gen_seed2); } } else { star.planetCount = 3; star.planets = new PlanetData[star.planetCount]; if (num2 < 0.150000005960464) { int info_seed1 = random2.Next(); int gen_seed1 = random2.Next(); star.planets[0] = MPlanetGen.CreatePlanet(galaxy, star, gameDesc, 0, 0, num3 <= 0.5 ? 2 : 3, 1, false, info_seed1, gen_seed1); int info_seed2 = random2.Next(); int gen_seed2 = random2.Next(); star.planets[1] = MPlanetGen.CreatePlanet(galaxy, star, gameDesc, 1, 0, num3 <= 0.5 ? 3 : 4, 2, false, info_seed2, gen_seed2); int info_seed3 = random2.Next(); int gen_seed3 = random2.Next(); star.planets[2] = MPlanetGen.CreatePlanet(galaxy, star, gameDesc, 2, 0, num3 <= 0.5 ? 4 : 5, 3, false, info_seed3, gen_seed3); } else if (num2 < 0.75) { int info_seed1 = random2.Next(); int gen_seed1 = random2.Next(); star.planets[0] = MPlanetGen.CreatePlanet(galaxy, star, gameDesc, 0, 0, num3 <= 0.5 ? 2 : 3, 1, false, info_seed1, gen_seed1); int info_seed2 = random2.Next(); int gen_seed2 = random2.Next(); star.planets[1] = MPlanetGen.CreatePlanet(galaxy, star, gameDesc, 1, 0, 4, 2, true, info_seed2, gen_seed2); int info_seed3 = random2.Next(); int gen_seed3 = random2.Next(); star.planets[2] = MPlanetGen.CreatePlanet(galaxy, star, gameDesc, 2, 2, 1, 1, false, info_seed3, gen_seed3); } else { int info_seed1 = random2.Next(); int gen_seed1 = random2.Next(); star.planets[0] = MPlanetGen.CreatePlanet(galaxy, star, gameDesc, 0, 0, num3 <= 0.5 ? 3 : 4, 1, true, info_seed1, gen_seed1); int info_seed2 = random2.Next(); int gen_seed2 = random2.Next(); star.planets[1] = MPlanetGen.CreatePlanet(galaxy, star, gameDesc, 1, 1, 1, 1, false, info_seed2, gen_seed2); int info_seed3 = random2.Next(); int gen_seed3 = random2.Next(); star.planets[2] = MPlanetGen.CreatePlanet(galaxy, star, gameDesc, 2, 1, 2, 2, false, info_seed3, gen_seed3); } } } else { Array.Clear((Array)this.pGas, 0, this.pGas.Length); if (star.index == 0) { star.planetCount = 4; this.pGas[0] = 0.0; this.pGas[1] = 0.0; this.pGas[2] = 0.0; } else if (star.spectr == ESpectrType.M) { star.planetCount = num1 >= 0.1 ? (num1 >= 0.3 ? (num1 >= 0.8 ? 4 : 3) : 2) : 1; if (star.planetCount <= 3) { this.pGas[0] = 0.2; this.pGas[1] = 0.2; } else { this.pGas[0] = 0.0; this.pGas[1] = 0.2; this.pGas[2] = 0.3; } } else if (star.spectr == ESpectrType.K) { star.planetCount = num1 >= 0.1 ? (num1 >= 0.2 ? (num1 >= 0.7 ? (num1 >= 0.95 ? 5 : 4) : 3) : 2) : 1; if (star.planetCount <= 3) { this.pGas[0] = 0.18; this.pGas[1] = 0.18; } else { this.pGas[0] = 0.0; this.pGas[1] = 0.18; this.pGas[2] = 0.28; this.pGas[3] = 0.28; } } else if (star.spectr == ESpectrType.G) { star.planetCount = num1 >= 0.4 ? (num1 >= 0.9 ? 5 : 4) : 3; if (star.planetCount <= 3) { this.pGas[0] = 0.18; this.pGas[1] = 0.18; } else { this.pGas[0] = 0.0; this.pGas[1] = 0.2; this.pGas[2] = 0.3; this.pGas[3] = 0.3; } } else if (star.spectr == ESpectrType.F) { star.planetCount = num1 >= 0.35 ? (num1 >= 0.8 ? 5 : 4) : 3; if (star.planetCount <= 3) { this.pGas[0] = 0.2; this.pGas[1] = 0.2; } else { this.pGas[0] = 0.0; this.pGas[1] = 0.22; this.pGas[2] = 0.31; this.pGas[3] = 0.31; } } else if (star.spectr == ESpectrType.A) { star.planetCount = num1 >= 0.3 ? (num1 >= 0.75 ? 5 : 4) : 3; if (star.planetCount <= 3) { this.pGas[0] = 0.2; this.pGas[1] = 0.2; } else { this.pGas[0] = 0.1; this.pGas[1] = 0.28; this.pGas[2] = 0.3; this.pGas[3] = 0.35; } } else if (star.spectr == ESpectrType.B) { star.planetCount = num1 >= 0.3 ? (num1 >= 0.75 ? 6 : 5) : 4; if (star.planetCount <= 3) { this.pGas[0] = 0.2; this.pGas[1] = 0.2; } else { this.pGas[0] = 0.1; this.pGas[1] = 0.22; this.pGas[2] = 0.28; this.pGas[3] = 0.35; this.pGas[4] = 0.35; } } else if (star.spectr == ESpectrType.O) { star.planetCount = num1 >= 0.5 ? 6 : 5; this.pGas[0] = 0.1; this.pGas[1] = 0.2; this.pGas[2] = 0.25; this.pGas[3] = 0.3; this.pGas[4] = 0.32; this.pGas[5] = 0.35; } else { star.planetCount = 1; } star.planets = new PlanetData[star.planetCount]; int num8 = 0; int num9 = 0; int orbitAround = 0; int num10 = 1; for (int index = 0; index < star.planetCount; ++index) { int info_seed = random2.Next(); int gen_seed = random2.Next(); double num11 = random2.NextDouble(); double num12 = random2.NextDouble(); bool gasGiant = false; if (orbitAround == 0) { ++num8; if (index < star.planetCount - 1 && num11 < this.pGas[index]) { gasGiant = true; if (num10 < 3) { num10 = 3; } } for (; star.index != 0 || num10 != 3; ++num10) { int num13 = star.planetCount - index; int num14 = 9 - num10; if (num14 > num13) { float a = (float)num13 / (float)num14; float num15 = num10 <= 3 ? Mathf.Lerp(a, 1f, 0.15f) + 0.01f : Mathf.Lerp(a, 1f, 0.45f) + 0.01f; if (random2.NextDouble() < (double)num15) { goto label_63; } } else { goto label_63; } } gasGiant = true; } else { ++num9; gasGiant = false; } label_63: star.planets[index] = MPlanetGen.CreatePlanet(galaxy, star, gameDesc, index, orbitAround, orbitAround != 0 ? num9 : num10, orbitAround != 0 ? num9 : num8, gasGiant, info_seed, gen_seed); ++num10; if (gasGiant) { orbitAround = num8; num9 = 0; } if (num9 >= 1 && num12 < 0.8) { orbitAround = 0; num9 = 0; } } } int num16 = 0; int num17 = 0; int index1 = 0; for (int index2 = 0; index2 < star.planetCount; ++index2) { if (star.planets[index2].type == EPlanetType.Gas) { num16 = star.planets[index2].orbitIndex; break; } } for (int index2 = 0; index2 < star.planetCount; ++index2) { if (star.planets[index2].orbitAround == 0) { num17 = star.planets[index2].orbitIndex; } } if (num16 > 0) { int num8 = num16 - 1; bool flag = true; for (int index2 = 0; index2 < star.planetCount; ++index2) { if (star.planets[index2].orbitAround == 0 && star.planets[index2].orbitIndex == num16 - 1) { flag = false; break; } } if (flag && num4 < 0.2 + (double)num8 * 0.2) { index1 = num8; } } int index3 = num5 >= 0.2 ? (num5 >= 0.4 ? (num5 >= 0.8 ? 0 : num17 + 1) : num17 + 2) : num17 + 3; if (index3 != 0 && index3 < 5) { index3 = 5; } star.asterBelt1OrbitIndex = (float)index1; star.asterBelt2OrbitIndex = (float)index3; if (index1 > 0) { star.asterBelt1Radius = this.orbitRadius[index1] * (float)num6 * star.orbitScaler; } if (index3 <= 0) { return; } star.asterBelt2Radius = this.orbitRadius[index3] * (float)num7 * star.orbitScaler; }
public StarData CreateBirthStar(GalaxyData galaxy, int seed) { StarData starData = new StarData(); starData.galaxy = galaxy; starData.index = 0; starData.level = 0.0f; starData.id = 1; starData.seed = seed; starData.resourceCoef = 0.6f; Random random1 = new Random(seed); int seed1 = random1.Next(); int Seed = random1.Next(); starData.name = NameGen.RandomName(seed1); starData.overrideName = string.Empty; starData.position = VectorLF3.zero; Random random2 = new Random(Seed); double r1 = random2.NextDouble(); double r2 = random2.NextDouble(); double num1 = random2.NextDouble(); double rn = random2.NextDouble(); double rt = random2.NextDouble(); double num2 = random2.NextDouble() * 0.2 + 0.9; double num3 = Math.Pow(2.0, random2.NextDouble() * 0.4 - 0.2); float p1 = Mathf.Clamp(this.RandNormal(0.0f, 0.08f, r1, r2), -0.2f, 0.2f); starData.mass = Mathf.Pow(2f, p1); if ((double)this.specifyBirthStarMass > 0.100000001490116) { starData.mass = this.specifyBirthStarMass; } if ((double)this.specifyBirthStarAge > 9.99999974737875E-06) { starData.age = this.specifyBirthStarAge; } double d = 2.0 + 0.4 * (1.0 - (double)starData.mass); starData.lifetime = (float)(10000.0 * Math.Pow(0.1, Math.Log10((double)starData.mass * 0.5) / Math.Log10(d) + 1.0) * num2); starData.age = (float)(num1 * 0.4 + 0.3); if ((double)this.specifyBirthStarAge > 9.99999974737875E-06) { starData.age = this.specifyBirthStarAge; } float f = (float)(1.0 - (double)Mathf.Pow(Mathf.Clamp01(starData.age), 20f) * 0.5) * starData.mass; starData.temperature = (float)(Math.Pow((double)f, 0.56 + 0.14 / (Math.Log10((double)f + 4.0) / Math.Log10(5.0))) * 4450.0 + 1300.0); double num4 = Math.Log10(((double)starData.temperature - 1300.0) / 4500.0) / Math.Log10(2.6) - 0.5; if (num4 < 0.0) { num4 *= 4.0; } if (num4 > 2.0) { num4 = 2.0; } else if (num4 < -4.0) { num4 = -4.0; } starData.spectr = (ESpectrType)Mathf.RoundToInt((float)num4 + 4f); starData.color = Mathf.Clamp01((float)((num4 + 3.5) * 0.200000002980232)); starData.classFactor = (float)num4; starData.luminosity = Mathf.Pow(f, 0.7f); starData.radius = (float)(Math.Pow((double)starData.mass, 0.4) * num3); starData.acdiskRadius = 0.0f; float p2 = (float)num4 + 2f; starData.habitableRadius = Mathf.Pow(1.7f, p2) + 0.2f * Mathf.Min(1f, starData.orbitScaler); starData.lightBalanceRadius = Mathf.Pow(1.7f, p2); starData.orbitScaler = Mathf.Pow(1.35f, p2); if ((double)starData.orbitScaler < 1.0) { starData.orbitScaler = Mathf.Lerp(starData.orbitScaler, 1f, 0.6f); } this.SetStarAge(starData, starData.age, rn, rt); starData.dysonRadius = starData.orbitScaler * 0.28f; if ((double)starData.dysonRadius * 40000.0 < (double)starData.physicsRadius * 1.5) { starData.dysonRadius = (float)((double)starData.physicsRadius * 1.5 / 40000.0); } starData.uPosition = VectorLF3.zero; starData.name = NameGen.RandomStarName(seed1, starData, galaxy); starData.overrideName = string.Empty; return(starData); }
private bool OnStarPressed(StarObject star) { if ( star.cell.adjacentStars.Count() != 1 || star.cell.name == MapGenerator.SUN_NAME || _submittedStars.Contains(star.cell.name) || solved ) { Audio.PlaySoundAtTransform("NotOutskirts", star.transform); return(true); } Debug.LogFormat("[Space Traders #{0}] Pressed star: {1}", _moduleId, star.cell.name); Debug.LogFormat("[Space Traders #{0}] Current time: {1}", _moduleId, BombInfo.GetFormattedTime()); Debug.LogFormat("[Space Traders #{0}] Path: {1}", _moduleId, star.cell.path.Select((c) => c.name).Join(",")); IEnumerable <MapGenerator.CellStar> starsWithTax = star.cell.path.Where((s) => StarData.HasTaxAt(s, this)); Debug.LogFormat("[Space Traders #{0}] Stars with tax: {1}", _moduleId, starsWithTax.Select((c) => c.name).Join(",")); int tax = starsWithTax.Select((s) => s.tax).Sum(); Debug.LogFormat("[Space Traders #{0}] Required tax: {1}", _moduleId, tax); if (tax > maxTax) { Debug.LogFormat("[Space Traders #{0}] Required tax greater than maximum allowed", _moduleId); BombModule.HandleStrike(); Debug.LogFormat("[Space Traders #{0}] Reseting module", _moduleId); ResetModule(true); return(false); } Audio.PlaySoundAtTransform("StarSubmitted", star.transform); if (soldProductsCount + 1 == productsCountToBeSold) { _forceSolved = false; } soldProductsCount += 1; Debug.LogFormat("[Space Traders #{0}] Sold products count: {1}/{2}", _moduleId, soldProductsCount, productsCountToBeSold); _submittedStars.Add(star.cell.name); foreach (StarObject pathStar in star.cell.path.Select((pathCell) => starByName[pathCell.name])) { pathStar.HypercorridorToSun.GetComponent <Renderer>().material = UsedHypercorridorMaterial; } return(true); }
public bool AdvisePointIfOcclusion(PlayerMove_Sail __instance, ref VectorLF3 advisePoint, double radiusOffest) { bool navPlanet = false; bool navStar = false; StarData localStar = GameMain.localStar; VectorLF3 srcPoint = __instance.player.uPosition; VectorLF3 dstPoint = VectorLF3.zero; if (IsCurNavStar()) { navStar = true; dstPoint = target.TargetStar.uPosition; } else if (IsCurNavPlanet()) { navPlanet = true; dstPoint = target.TargetPlanet.uPosition; } else { ModDebug.Error("AdvisePointIfOcclusion When No Navigate!!!"); return(false); } bool hit = false; Math.Line3D hitPlaneVertical = new Math.Line3D(); double uncoverRadius = 0; Math.Line3D line = new Math.Line3D(srcPoint, dstPoint); Math.Plane3D plane = new Math.Plane3D(); plane.normal = line.dir; if (localStar != null) { //Planet occlusion for (int index = 0; index < localStar.planetCount; ++index) { PlanetData planet = localStar.planets[index]; plane.ponit = planet.uPosition; if (plane.IsParallel(line) == false) { //Target planet if (navPlanet && planet.id == target.TargetPlanet.id) { continue; } VectorLF3 intersection = plane.GetIntersection(line); double minHitRange = planet.realRadius + radiusOffest; if (intersection.Distance(planet.uPosition) < minHitRange && intersection.Distance(srcPoint) + intersection.Distance(dstPoint) <= (dstPoint.Distance(srcPoint) + 0.1)) { hit = true; //Maximum radius plane if (minHitRange > uncoverRadius) { uncoverRadius = minHitRange; hitPlaneVertical.src = planet.uPosition; if (planet.uPosition != intersection) { hitPlaneVertical.dst = intersection; } //Rare case else { hitPlaneVertical.dst = plane.GetAnyPoint(); } } } } } ///Star occlusion StarData star = localStar; plane.ponit = star.uPosition; //Target star if (navStar && star.id == target.TargetStar.id) { } else { if (plane.IsParallel(line) == false) { VectorLF3 intersection = plane.GetIntersection(line); double minHitRange = star.physicsRadius + radiusOffest; if (intersection.Distance(star.uPosition) < minHitRange) { hit = true; //Maximum radius plane if (minHitRange > uncoverRadius) { uncoverRadius = minHitRange; hitPlaneVertical.src = star.uPosition; if (star.uPosition != intersection) { hitPlaneVertical.dst = intersection; } //Rare case else { hitPlaneVertical.dst = plane.GetAnyPoint(); } } } } } } if (hit) { #if DEBUG ModDebug.Log("AdvisePointIfOcclusion Hit"); #endif VectorLF3 uncoverOrbitPoint = hitPlaneVertical.src + (hitPlaneVertical.dir * (uncoverRadius + 10)); Math.Line3D uncoverLine = new Math.Line3D(dstPoint, uncoverOrbitPoint); plane.normal = uncoverLine.dir; plane.ponit = srcPoint; advisePoint = plane.GetIntersection(uncoverLine); } return(hit); }
public static void CreateStarPlanetsRework(GalaxyData galaxy, StarData star, GameDesc gameDesc, PlanetGeneratorSettings genSettings) { bool isDebugOn = star.IsStartingStar(); star.name = SystemsNames.systems[star.index]; Patch.Debug("System " + star.name + " - " + star.type + " - " + star.spectr, LogLevel.Debug, Patch.DebugStarGen && isDebugOn); // Random Generators Inits UnityRandom.InitState(star.seed); var mainSeed = new Random(star.seed); var annexSeed = new Random(mainSeed.Next()); // InnerCount for the System var planetsToGenerate = new List <PlanetForGenerator>(); // settings from the config PatchForStarSystemGeneration.StarSystemSetting currentSettings; if (star.type == EStarType.BlackHole || star.type == EStarType.GiantStar || star.type == EStarType.NeutronStar || star.type == EStarType.WhiteDwarf) { currentSettings = Patch.GeneratorSpecialsSystemConfig[star.type]; } else { currentSettings = Patch.GeneratorMainSystemConfig[star.spectr]; } //Debugging configs Patch.Debug("*************************** : \n" + "ChanceMoonGasGiant : " + currentSettings.ChanceGasGiantMoon + "\n" + "ChanceMoonTelluric : " + currentSettings.ChanceMoonTelluric + "\n" + "ChancePlanetTelluric : " + currentSettings.ChanceTelluricPlanet + "\n" + "ChancePlanetGasGiant : " + currentSettings.ChanceGasGiant + "\n" + "MaxMoonTelluricNb : " + currentSettings.MaxMoonTelluricNb + "\n" + "MaxMoonGasGiantNb : " + currentSettings.MaxMoonGasGiantNb + "\n" + "MaxTelluricNb : " + currentSettings.MaxTelluricNb + "\n" + "MaxGasGiantNb : " + currentSettings.MaxGasGiantNb + "\n" + "ChanceJumpOrbitMoons : " + currentSettings.ChanceJumpOrbitMoons + "\n" + "ChanceJumpOrbitPlanets : " + currentSettings.ChanceJumpOrbitPlanets + "\n" + "*************************** ", LogLevel.Debug, Patch.DebugStarGenDeep); Patch.Debug("Definition of Nb of planets In the system :", LogLevel.Debug, Patch.DebugStarGenDeep); DefineNumberOfBodies(currentSettings, annexSeed, genSettings); if (star.IsStartingStar()) { // check if minimum number of planet is met genSettings.nbOfTelluricPlanets = genSettings.nbOfTelluricPlanets < Patch.StartingSystemMinPlanetTelluricNb.Value ? Patch.StartingSystemMinPlanetTelluricNb.Value : genSettings.nbOfTelluricPlanets; genSettings.nbOfMoonsTelluric = genSettings.nbOfMoonsTelluric < Patch.StartingSystemMinTelluricMoonNb.Value ? Patch.StartingSystemMinTelluricMoonNb.Value : genSettings.nbOfMoonsTelluric; genSettings.nbOfGasGiantPlanets = genSettings.nbOfGasGiantPlanets < Patch.StartingSystemMinGasGiantNb.Value ? Patch.StartingSystemMinGasGiantNb.Value : genSettings.nbOfGasGiantPlanets; genSettings.nbOfMoonsGasGiant = genSettings.nbOfMoonsGasGiant < Patch.StartingSystemMinGasGiantMoonNb.Value ? Patch.StartingSystemMinGasGiantMoonNb.Value : genSettings.nbOfMoonsGasGiant; genSettings.nbOfMoons = genSettings.nbOfMoonsTelluric + genSettings.nbOfMoonsGasGiant; genSettings.nbOfPlanets = genSettings.nbOfTelluricPlanets + genSettings.nbOfGasGiantPlanets; genSettings.nbOfStellarBodies = genSettings.nbOfPlanets + genSettings.nbOfMoons; } star.planets = new PlanetData[genSettings.nbOfStellarBodies]; Patch.Debug("*************************** :", LogLevel.Debug, Patch.DebugStarGen && isDebugOn); Patch.Debug("\nSystem Presets : ", LogLevel.Debug, Patch.DebugStarGen && isDebugOn); var preset = "nbOfPlanets : " + genSettings.nbOfPlanets + "\n" + "nbOfTelluricPlanets : " + genSettings.nbOfTelluricPlanets + "\n" + "nbOfGasGiantPlanets : " + genSettings.nbOfGasGiantPlanets + "\n" + "nbOfMoons : " + genSettings.nbOfMoons + "\n" + "nbOfMoonsTelluric : " + genSettings.nbOfMoonsTelluric + "\n" + "nbOfMoonsGasGiant : " + genSettings.nbOfMoonsGasGiant + "\n\n"; Patch.Debug(preset, LogLevel.Debug, Patch.DebugStarGen && isDebugOn); PreGenerateAllBodies(star, planetsToGenerate, annexSeed, genSettings, currentSettings); GenerateAllPlanets(galaxy, star, gameDesc, planetsToGenerate); if (star.IsStartingStar()) { Patch.Debug(star.name + " --recap-- : ", LogLevel.Debug, Patch.DebugStarGen && isDebugOn); var nbOfHabitablePlanets = 0; foreach (var planet in star.planets) { if (planet.orbitAround != 0) { Patch.Debug("moon type : " + planet.type, LogLevel.Debug, Patch.DebugStarGen && isDebugOn); } else { Patch.Debug("planet type : " + planet.type, LogLevel.Debug, Patch.DebugStarGen && isDebugOn); } if (planet.type == EPlanetType.Ocean) { nbOfHabitablePlanets++; } } if (nbOfHabitablePlanets == 0) { Patch.Debug("Nb of habitable == 0 --> Override one planet ", LogLevel.Debug, Patch.DebugStarGen && isDebugOn); var @override = true; while (@override) { var indexStartingPlanet = UnityRandom.Range(0, star.planets.Length - 1); if (star.planets[indexStartingPlanet].type != EPlanetType.Gas) { star.planets[indexStartingPlanet].ShouldBeHabitable(); galaxy.birthPlanetId = star.planets[indexStartingPlanet].id; @override = false; } } Patch.Debug(" galaxy.birthPlanetId --> " + galaxy.birthPlanetId, LogLevel.Debug, Patch.DebugStarGen && isDebugOn); } } // Apply themes foreach (var planet in star.planets) { PlanetGen.SetPlanetTheme(planet, star, gameDesc, 0, 0, mainSeed.NextDouble(), mainSeed.NextDouble(), mainSeed.NextDouble(), mainSeed.NextDouble(), mainSeed.Next()); if (star.IsStartingStar()) { Patch.Debug("planet.name --> " + planet.name, LogLevel.Debug, Patch.DebugStarGen && isDebugOn); Patch.Debug("planet.algoId --> " + planet.algoId, LogLevel.Debug, Patch.DebugStarGen && isDebugOn); Patch.Debug("planet.type --> " + planet.type, LogLevel.Debug, Patch.DebugStarGen && isDebugOn); } } star.planetCount = star.planets.Length; }
private void SpawnNamedStar(StarData sd) { }
public static bool CreateStarPlanetsPatch(GalaxyData galaxy, StarData star, GameDesc gameDesc) { CreateStarPlanets(galaxy, star, gameDesc); return(false); }
void mywindowfunction(int windowid) { if (GUI.Button(new Rect(0, 0, 20, 20), "X")) { isShow = !isShow; if (isShow) { rect = temp; } else { rect.width = 30; rect.height = 20; temp.x = rect.x; temp.y = rect.y; } } GUI.Label(new Rect(10, 20, 300, 300), ST.Tip); fingStarNameAll = GUI.TextField(new Rect(10, 40, 100, 20), fingStarNameAll, 20); if (GUI.Button(new Rect(110, 40, 40, 20), ST.查找)) { var galaxyData = GameMain.data.galaxy; if (galaxyData != null) { findStar(galaxyData, fingStarNameAll); } } if (selectData != null) { GUI.Label(new Rect(10, 60, 100, 20), selectData.name); } if (GUI.Button(new Rect(110, 60, 40, 20), ST.更换)) { if (selectData != null) { StartCoroutine(RadomSun(GameMain.data.galaxy.stars, selectData.id - 1, (EStarType)type1, (ESpectrType)type2)); } } input1 = GUI.TextField(new Rect(160, 40, 40, 20), type1.ToString(), 1); GUI.Label(new Rect(160, 60, 60, 100), "0-母星\n1-巨星\n2-白矮\n3-中子\n4-黑洞"); input2 = GUI.TextField(new Rect(210, 40, 30, 20), type2.ToString(), 1); GUI.Label(new Rect(210, 60, 30, 140), "0-M\n1-K\n2-G\n3-F\n4-A\n5-B\n6-O\n7-X"); if (int.TryParse(input1, out type1)) { if (type1 < 0 || type1 > 4) { type1 = 0; } } if (int.TryParse(input2, out type2)) { if (type2 < 0 || type2 > 7) { type2 = 0; } } int i = 0; foreach (var d in resDate) { if (GUI.Button(new Rect(10, 80 + 22 * i, 100, 20), d.Key)) { selectData = d.Value; } i++; } GUI.DragWindow(new Rect(0, 0, 10000, 10000)); }
public static void CreateStarPlanets(GalaxyData galaxy, StarData star, GameDesc gameDesc) { Traverse.Create(typeof(StarGen)).Field("pGas").SetValue(new double[100]); System.Random random = new System.Random(star.seed); random.Next(); random.Next(); random.Next(); int seed = random.Next(); System.Random random2 = new System.Random(seed); double num = random2.NextDouble(); double num2 = random2.NextDouble(); double num3 = random2.NextDouble(); double num4 = random2.NextDouble(); double num5 = random2.NextDouble(); double num6 = random2.NextDouble() * 0.2 + 0.9; double num7 = random2.NextDouble() * 0.2 + 0.9; if (star.type == EStarType.BlackHole) { star.planetCount = 1; star.planets = new PlanetData[star.planetCount]; int info_seed = random2.Next(); int gen_seed = random2.Next(); star.planets[0] = PlanetGen.CreatePlanet(galaxy, star, gameDesc, 0, 0, 3, 1, false, info_seed, gen_seed); } else if (star.type == EStarType.NeutronStar) { star.planetCount = 1; star.planets = new PlanetData[star.planetCount]; int info_seed2 = random2.Next(); int gen_seed2 = random2.Next(); star.planets[0] = PlanetGen.CreatePlanet(galaxy, star, gameDesc, 0, 0, 3, 1, false, info_seed2, gen_seed2); } else if (star.type == EStarType.WhiteDwarf) { if (num < 0.699999988079071) { star.planetCount = 1; star.planets = new PlanetData[star.planetCount]; int info_seed3 = random2.Next(); int gen_seed3 = random2.Next(); star.planets[0] = PlanetGen.CreatePlanet(galaxy, star, gameDesc, 0, 0, 3, 1, false, info_seed3, gen_seed3); } else { star.planetCount = 2; star.planets = new PlanetData[star.planetCount]; if (num2 < 0.30000001192092896) { int info_seed4 = random2.Next(); int gen_seed4 = random2.Next(); star.planets[0] = PlanetGen.CreatePlanet(galaxy, star, gameDesc, 0, 0, 3, 1, false, info_seed4, gen_seed4); info_seed4 = random2.Next(); gen_seed4 = random2.Next(); star.planets[1] = PlanetGen.CreatePlanet(galaxy, star, gameDesc, 1, 0, 4, 2, false, info_seed4, gen_seed4); } else { int info_seed4 = random2.Next(); int gen_seed4 = random2.Next(); star.planets[0] = PlanetGen.CreatePlanet(galaxy, star, gameDesc, 0, 0, 4, 1, true, info_seed4, gen_seed4); info_seed4 = random2.Next(); gen_seed4 = random2.Next(); star.planets[1] = PlanetGen.CreatePlanet(galaxy, star, gameDesc, 1, 1, 1, 1, false, info_seed4, gen_seed4); } } } else if (star.type == EStarType.GiantStar) { if (num < 0.30000001192092896) { star.planetCount = 1; star.planets = new PlanetData[star.planetCount]; int info_seed5 = random2.Next(); int gen_seed5 = random2.Next(); star.planets[0] = PlanetGen.CreatePlanet(galaxy, star, gameDesc, 0, 0, (num3 <= 0.5) ? 2 : 3, 1, false, info_seed5, gen_seed5); } else if (num < 0.800000011920929) { star.planetCount = 2; star.planets = new PlanetData[star.planetCount]; if (num2 < 0.25) { int info_seed6 = random2.Next(); int gen_seed6 = random2.Next(); star.planets[0] = PlanetGen.CreatePlanet(galaxy, star, gameDesc, 0, 0, (num3 <= 0.5) ? 2 : 3, 1, false, info_seed6, gen_seed6); info_seed6 = random2.Next(); gen_seed6 = random2.Next(); star.planets[1] = PlanetGen.CreatePlanet(galaxy, star, gameDesc, 1, 0, (num3 <= 0.5) ? 3 : 4, 2, false, info_seed6, gen_seed6); } else { int info_seed6 = random2.Next(); int gen_seed6 = random2.Next(); star.planets[0] = PlanetGen.CreatePlanet(galaxy, star, gameDesc, 0, 0, 3, 1, true, info_seed6, gen_seed6); info_seed6 = random2.Next(); gen_seed6 = random2.Next(); star.planets[1] = PlanetGen.CreatePlanet(galaxy, star, gameDesc, 1, 1, 1, 1, false, info_seed6, gen_seed6); } } else { star.planetCount = 3; star.planets = new PlanetData[star.planetCount]; if (num2 < 0.15000000596046448) { int info_seed7 = random2.Next(); int gen_seed7 = random2.Next(); star.planets[0] = PlanetGen.CreatePlanet(galaxy, star, gameDesc, 0, 0, (num3 <= 0.5) ? 2 : 3, 1, false, info_seed7, gen_seed7); info_seed7 = random2.Next(); gen_seed7 = random2.Next(); star.planets[1] = PlanetGen.CreatePlanet(galaxy, star, gameDesc, 1, 0, (num3 <= 0.5) ? 3 : 4, 2, false, info_seed7, gen_seed7); info_seed7 = random2.Next(); gen_seed7 = random2.Next(); star.planets[2] = PlanetGen.CreatePlanet(galaxy, star, gameDesc, 2, 0, (num3 <= 0.5) ? 4 : 5, 3, false, info_seed7, gen_seed7); } else if (num2 < 0.75) { int info_seed7 = random2.Next(); int gen_seed7 = random2.Next(); star.planets[0] = PlanetGen.CreatePlanet(galaxy, star, gameDesc, 0, 0, (num3 <= 0.5) ? 2 : 3, 1, false, info_seed7, gen_seed7); info_seed7 = random2.Next(); gen_seed7 = random2.Next(); star.planets[1] = PlanetGen.CreatePlanet(galaxy, star, gameDesc, 1, 0, 4, 2, true, info_seed7, gen_seed7); info_seed7 = random2.Next(); gen_seed7 = random2.Next(); star.planets[2] = PlanetGen.CreatePlanet(galaxy, star, gameDesc, 2, 2, 1, 1, false, info_seed7, gen_seed7); } else { int info_seed7 = random2.Next(); int gen_seed7 = random2.Next(); star.planets[0] = PlanetGen.CreatePlanet(galaxy, star, gameDesc, 0, 0, (num3 <= 0.5) ? 3 : 4, 1, true, info_seed7, gen_seed7); info_seed7 = random2.Next(); gen_seed7 = random2.Next(); star.planets[1] = PlanetGen.CreatePlanet(galaxy, star, gameDesc, 1, 1, 1, 1, false, info_seed7, gen_seed7); info_seed7 = random2.Next(); gen_seed7 = random2.Next(); star.planets[2] = PlanetGen.CreatePlanet(galaxy, star, gameDesc, 2, 1, 2, 2, false, info_seed7, gen_seed7); } } } else { if (star.index == 0) { star.planetCount = StarCount; for (int i = 0; i < star.planetCount; i++) { SetPGas(i, random.NextDouble() % 0.9); } } else if (star.spectr == ESpectrType.M) { if (num < 0.1) { star.planetCount = 1; } else if (num < 0.3) { star.planetCount = 2; } else if (num < 0.8) { star.planetCount = 3; } else { star.planetCount = 4; } if (star.planetCount <= 3) { SetPGas(0, 0.2); SetPGas(1, 0.2); } else { SetPGas(0, 0); SetPGas(1, 0.2); SetPGas(2, 0.3); } } else if (star.spectr == ESpectrType.K) { if (num < 0.1) { star.planetCount = 1; } else if (num < 0.2) { star.planetCount = 2; } else if (num < 0.7) { star.planetCount = 3; } else if (num < 0.95) { star.planetCount = 4; } else { star.planetCount = 5; } if (star.planetCount <= 3) { SetPGas(0, 0.18); SetPGas(1, 0.18); } else { SetPGas(0, 0); SetPGas(1, 0.18); SetPGas(2, 0.28); SetPGas(3, 0.28); } } else if (star.spectr == ESpectrType.G) { if (num < 0.4) { star.planetCount = 3; } else if (num < 0.9) { star.planetCount = 4; } else { star.planetCount = 5; } if (star.planetCount <= 3) { SetPGas(0, 0.18); SetPGas(1, 0.18); } else { SetPGas(0, 0); SetPGas(1, 0.2); SetPGas(2, 0.3); SetPGas(3, 0.3); } } else if (star.spectr == ESpectrType.F) { if (num < 0.35) { star.planetCount = 3; } else if (num < 0.8) { star.planetCount = 4; } else { star.planetCount = 5; } if (star.planetCount <= 3) { SetPGas(0, 0.2); SetPGas(1, 0.2); } else { SetPGas(0, 0); SetPGas(1, 0.22); SetPGas(2, 0.31); SetPGas(3, 0.31); } } else if (star.spectr == ESpectrType.A) { if (num < 0.3) { star.planetCount = 3; } else if (num < 0.75) { star.planetCount = 4; } else { star.planetCount = 5; } if (star.planetCount <= 3) { SetPGas(0, 0.2); SetPGas(1, 0.2); } else { SetPGas(0, 0.1); SetPGas(1, 0.28); SetPGas(2, 0.3); SetPGas(3, 0.35); } } else if (star.spectr == ESpectrType.B) { if (num < 0.3) { star.planetCount = 4; } else if (num < 0.75) { star.planetCount = 5; } else { star.planetCount = 6; } if (star.planetCount <= 3) { SetPGas(0, 0.2); SetPGas(0, 0.2); } else { SetPGas(0, 0.1); SetPGas(1, 0.22); SetPGas(2, 0.28); SetPGas(3, 0.35); SetPGas(4, 0.35); } } else if (star.spectr == ESpectrType.O) { if (num < 0.5) { star.planetCount = 5; } else { star.planetCount = 6; } SetPGas(0, 0.1); SetPGas(1, 0.2); SetPGas(2, 0.25); SetPGas(3, 0.3); SetPGas(4, 0.32); SetPGas(5, 0.35); } else { star.planetCount = 1; } star.planets = new PlanetData[star.planetCount]; int num8 = 0; int num9 = 0; int num10 = 0; int num11 = 1; for (int i = 0; i < star.planetCount; i++) { int info_seed8 = random2.Next(); int gen_seed8 = random2.Next(); double num12 = random2.NextDouble(); double num13 = random2.NextDouble(); bool flag = false; if (num10 == 0) { num8++; if (i < star.planetCount - 1 && num12 < Traverse.Create(typeof(StarGen)).Field("pGas").GetValue <double[]>()[i]) { flag = true; if (num11 < 3) { num11 = 3; } } while (star.index != 0 || num11 != 3) { int num14 = star.planetCount - i; int num15 = 9 - num11; if (num15 > num14) { float num16 = (float)num14 / (float)num15; if (num11 > 3) { num16 = Mathf.Lerp(num16, 1f, 0.45f) + 0.01f; } else { num16 = Mathf.Lerp(num16, 1f, 0.15f) + 0.01f; } double num17 = random2.NextDouble(); if (num17 >= (double)num16) { num11++; continue; } } goto IL_D1A; } flag = true; } else { num9++; flag = false; } IL_D1A: star.planets[i] = PlanetGen.CreatePlanet(galaxy, star, gameDesc, i, num10, (num10 != 0) ? num9 : num11, (num10 != 0) ? num9 : num8, flag, info_seed8, gen_seed8); num11++; if (flag) { num10 = num8; num9 = 0; } if (num9 >= 1 && num13 < 0.8) { num10 = 0; num9 = 0; } } } int num18 = 0; int num19 = 0; int num20 = 0; for (int j = 0; j < star.planetCount; j++) { if (star.planets[j].type == EPlanetType.Gas) { num18 = star.planets[j].orbitIndex; break; } } for (int k = 0; k < star.planetCount; k++) { if (star.planets[k].orbitAround == 0) { num19 = star.planets[k].orbitIndex; } } if (num18 > 0) { int num21 = num18 - 1; bool flag2 = true; for (int l = 0; l < star.planetCount; l++) { if (star.planets[l].orbitAround == 0 && star.planets[l].orbitIndex == num18 - 1) { flag2 = false; break; } } if (flag2 && num4 < 0.2 + (double)num21 * 0.2) { num20 = num21; } } int num22; if (num5 < 0.2) { num22 = num19 + 3; } else if (num5 < 0.4) { num22 = num19 + 2; } else if (num5 < 0.8) { num22 = num19 + 1; } else { num22 = 0; } if (num22 != 0 && num22 < 5) { num22 = 5; } star.asterBelt1OrbitIndex = (float)num20; star.asterBelt2OrbitIndex = (float)num22; if (num20 > 0) { star.asterBelt1Radius = StarGen.orbitRadius[num20] * (float)num6 * star.orbitScaler; } if (num22 > 0) { star.asterBelt2Radius = StarGen.orbitRadius[num22] * (float)num7 * star.orbitScaler; } }
public static GalaxyData CreateGalaxy(GameDesc gameDesc) { int galaxyAlgo = gameDesc.galaxyAlgo; int galaxySeed = gameDesc.galaxySeed; int num = gameDesc.starCount; if (galaxyAlgo < 20200101 || galaxyAlgo > 20591231) { throw new Exception("Wrong version of unigen algorithm!"); } System.Random random = new System.Random(galaxySeed); int seed = random.Next(); num = Traverse.Create(typeof(UniverseGen)).Method("GenerateTempPoses", seed, num, 4, 2.0, 2.3, 3.5, 0.18).GetValue <int>(); GalaxyData galaxyData = new GalaxyData(); galaxyData.seed = galaxySeed; galaxyData.starCount = num; galaxyData.stars = new StarData[num]; Assert.Positive(num); if (num <= 0) { return(galaxyData); } float num2 = (float)random.NextDouble(); float num3 = (float)random.NextDouble(); float num4 = (float)random.NextDouble(); float num5 = (float)random.NextDouble(); int num6 = Mathf.CeilToInt(0.01f * (float)num + num2 * 0.3f); int num7 = Mathf.CeilToInt(0.01f * (float)num + num3 * 0.3f); int num8 = Mathf.CeilToInt(0.016f * (float)num + num4 * 0.4f); int num9 = Mathf.CeilToInt(0.013f * (float)num + num5 * 1.4f); int num10 = num - num6; int num11 = num10 - num7; int num12 = num11 - num8; int num13 = (num12 - 1) / num9; int num14 = num13 / 2; for (int i = 0; i < num; i++) { int seed2 = random.Next(); ESpectrType needSpectr = ESpectrType.X; if (i == 3) { needSpectr = ESpectrType.M; } else if (i == num12 - 1) { needSpectr = ESpectrType.O; } EStarType needtype = EStarType.MainSeqStar; if (i % num13 == num14) { needtype = EStarType.GiantStar; } if (i >= num10) { needtype = EStarType.BlackHole; } else if (i >= num11) { needtype = EStarType.NeutronStar; } else if (i >= num12) { needtype = EStarType.WhiteDwarf; } galaxyData.stars[i] = StarGen.CreateStar(galaxyData, Traverse.Create(typeof(UniverseGen)).Field("tmp_poses").GetValue <List <VectorLF3> >()[i], i + 1, seed2, needtype, needSpectr); } AstroPose[] astroPoses = galaxyData.astroPoses; StarData[] stars = galaxyData.stars; for (int j = 0; j < galaxyData.astroPoses.Length; j++) { astroPoses[j].uRot.w = 1f; astroPoses[j].uRotNext.w = 1f; } for (int k = 0; k < num; k++) { StarGen.CreateStarPlanets(galaxyData, stars[k], gameDesc); astroPoses[stars[k].id * 100].uPos = (astroPoses[stars[k].id * 100].uPosNext = stars[k].uPosition); astroPoses[stars[k].id * 100].uRot = (astroPoses[stars[k].id * 100].uRotNext = Quaternion.identity); astroPoses[stars[k].id * 100].uRadius = stars[k].physicsRadius; } galaxyData.UpdatePoses(0.0); galaxyData.birthPlanetId = 0; if (num > 0) { StarData starData = stars[0]; for (int l = 0; l < starData.planetCount; l++) { PlanetData planetData = starData.planets[l]; ThemeProto themeProto = LDB.themes.Select(planetData.theme); if (themeProto != null && themeProto.Distribute == EThemeDistribute.Birth) { galaxyData.birthPlanetId = planetData.id; galaxyData.birthStarId = starData.id; CustomBirthPlanet(planetData); break; } } } Assert.Positive(galaxyData.birthPlanetId); for (int m = 0; m < num; m++) { StarData starData2 = galaxyData.stars[m]; for (int n = 0; n < starData2.planetCount; n++) { PlanetData planet = starData2.planets[n]; PlanetAlgorithm planetAlgorithm = PlanetModelingManager.Algorithm(planet); planetAlgorithm.GenerateVeins(true); } } UniverseGen.CreateGalaxyStarGraph(galaxyData); return(galaxyData); }
public Wormhole VisibleWormholeAt(StarData starA, StarData starB, MainGame game) { var wormhole = game.States.Wormholes.At.GetOrDefault(starA, starB); return(wormhole != null && this.Player.Intelligence.IsKnown(wormhole) ? wormhole : null); }
internal StarInfo(StarData data) { this.Data = data; }
private static List <SpaceObjectData> GeneratePlanetsSystem(StarData starData) { Single deltaMass = Random.Range(0.004f, 0.04f) * Constants.SolMass; Single metallicity = Random.Range(0.5f, 0.9f); //Масса тяжелых элементов (тяжелее гелия) в % от общей массы var planets = new List <PlanetData>(); //Это начальный вариант системы, много планет будет удалено в ходе эволюции var asteroidFields = new List <AsteroidFieldData>(); for (Int32 i = 0; i < MaxPlanetCount && deltaMass > 0; i++) { planets.Add(GeneratePlanet(starData, metallicity, i)); } for (Int32 iterator = 0; iterator < EvolutionIterationsCount; iterator++) //Эволюция в три приема { for (Int32 i = 0; i < planets.Count - 1; i++) //Идем парами по орбитам { if (i < 0) { continue; } //Т.к. мы работаем со списком, то можем удалять элементы, но не забываем уменьшать значение итератора var planet1 = planets[i]; var planet2 = planets[i + 1]; if (!(Mathf.Abs(planet1.OrbitRadius - planet2.OrbitRadius) < EvolutionRange)) { continue; } Single ratio = planet1.Mass / planet2.Mass; if (ratio < 0.1f) { if (Random.Range(0, 2) == 1) { planet2.Mass += planet1.Mass * Random.Range(0f, 1f); //Вторая ест первую planet2.RingsMass = 0.01f * planet1.Mass; //Будем подбирать } planets.Remove(planet1); i--; } if (ratio <= 10f && ratio >= 0.1f) //Взаимно поделились на ноль { if (Random.Range(0, 2) == 1 && planet1.Type != PlanetType.Gas && planet2.Type != PlanetType.Gas) { var asteroidField = new AsteroidFieldData { LocationID = starData.LocationID, ParentStarID = starData.ID, Mass = planet1.Mass + planet2.Mass, Radius = (planet1.OrbitRadius + planet2.OrbitRadius) / 2, Name = "AstFieldFrom(" + planet1.Name + ")(" + planet2.Name + ")" }; asteroidFields.Add(asteroidField); } planets.Remove(planet1); planets.Remove(planet2); i -= 2; } if (ratio > 10) { if (Random.Range(0, 2) == 1) { planet1.Mass += planet2.Mass * Random.Range(0f, 1f); //Первая ест вторую planet1.RingsMass = 0.01f * planet2.Mass; } planets.Remove(planet2); i--; } } } for (Int32 i = 0; i < asteroidFields.Count - 1; i++) { if (Mathf.Abs(asteroidFields[i].Radius - asteroidFields[i + 1].Radius) > AsteroidBeltMergeRange) { continue; } asteroidFields[i].Radius = (asteroidFields[i].Radius + asteroidFields[i + 1].Radius) / 2; asteroidFields[i].Mass += asteroidFields[i + 1].Mass; var removingAsteroidField = asteroidFields[i + 1]; asteroidFields.Remove(removingAsteroidField); i--; } var resultList = new List <SpaceObjectData>(); resultList.AddRange(planets.ConvertAll(p => (SpaceObjectData)p)); resultList.AddRange(asteroidFields.ConvertAll(a => (SpaceObjectData)a)); return(resultList); }
private static PlanetData GeneratePlanet(PlanetData.ePlanetType planetType, StarData curSys, int systemSpot) { PlanetData cPlan = new PlanetData(); PlanetAttributeTable pTable = new PlanetAttributeTable(); PlanetAttributeData pData = new PlanetAttributeData(); // assign the attribute table for the planet type try { pData = DataManager.planetAttributeDataList.Find(p => p.planetType == planetType); pTable = pData.planetTraitsTable; } catch (Exception ex) { Debug.LogError("Could not lookup " + planetType.ToString() + " table for planet type " + planetType.ToString() + "! Error:" + ex.ToString()); return null; // try again with the next planet } // Step 0: Log spot of planet in system cPlan.PlanetSpot = systemSpot; // Step 1: Determine type of planet cPlan.Type = (StellarObjects.PlanetData.ePlanetType)planetType; // assign the planet type // Step 2: Pick name for planet and assign ID(will change to generic star name) systemSpot = curSys.PlanetList.Count + 1; if (cPlan.Type == PlanetData.ePlanetType.AsteroidBelt) cPlan.Name = curSys.Name + " AB-" + HelperFunctions.StringConversions.ConvertToRomanNumeral(systemSpot); else if (cPlan.Type == PlanetData.ePlanetType.IceBelt) cPlan.Name = curSys.Name + " IB-" + HelperFunctions.StringConversions.ConvertToRomanNumeral(systemSpot); else if (cPlan.Type == PlanetData.ePlanetType.DustRing) cPlan.Name = curSys.Name + " DR-" + HelperFunctions.StringConversions.ConvertToRomanNumeral(systemSpot); else cPlan.Name = curSys.Name + " " + HelperFunctions.StringConversions.ConvertToRomanNumeral(systemSpot); // convert to planet and spot cPlan.ID = curSys.Name.Substring(0,2) + UnityEngine.Random.Range(0,9999); // set ID // Step 3: Determine size/axial tilt of planet try { int sizeVar = UnityEngine.Random.Range(0, pTable.sizeVar); int sizeResult = pTable.size + sizeVar; cPlan.Size = sizeResult; // sizeMod; } catch(Exception ex) { Debug.LogError("Could not calcuate. Error: " + ex.ToString()); } cPlan.AxialTilt = UnityEngine.Random.Range(0f, 70f); // tilt between 0-70 // Step 4: Determine habitibility of planet try { int habVar = UnityEngine.Random.Range(0, pTable.habVar); float habResult = pTable.habitability + habVar; float spotVar = 0f; switch (cPlan.PlanetSpot) { case 1: if ((int)curSys.SpectralClass < 5) { spotVar = .6f; break; } else { spotVar = .9f; break; } case 2: spotVar = .9f; break; case 3: spotVar = 1f; break; case 4: spotVar = 1f; break; case 5: spotVar = .9f; break; case 6: spotVar = .7f; break; default: spotVar = 1f; break; } cPlan.Bio = (int)(habResult * spotVar); } catch (Exception ex) { Debug.LogError("Could not calcuate. Error: " + ex.ToString()); } // Step 5: Determine industrial modifier of planet cPlan.IndustrialMultiplier = (pTable.indMult / 100); // Step 6: Determine if planet has any rings if (UnityEngine.Random.Range(0, 100) <= pTable.ringChance) cPlan.Rings = true; else cPlan.Rings = false; // Step 7: Determine how many moons the planet has if (UnityEngine.Random.Range(0, 100) <= pTable.moonChance) cPlan.Moons = UnityEngine.Random.Range(1,pTable.maxMoons); // change later to expand on moons // Step 7b: Adjust habitability based on moons if (cPlan.Moons > 0) if (((int)cPlan.Type == 7) || ((int)cPlan.Type == 8)) { cPlan.Bio += (cPlan.Moons * 2); } if (((int)cPlan.Type == 10) || ((int)cPlan.Type == 3) || ((int)cPlan.Type == 2) || ((int)cPlan.Type == 13)) { cPlan.Bio += (cPlan.Moons * 5); } // Step 8: Determine rating of alpha materials try { int alphaVar = UnityEngine.Random.Range(0, pTable.alpVar); cPlan.BasicMaterials = pTable.alpMaterial + alphaVar; } catch (Exception ex) { Debug.LogError("Could not calcuate. Error: " + ex.ToString()); } // Step 9: Determine rating of heavy materials try { int heavyVar = UnityEngine.Random.Range(0, pTable.heavVar); cPlan.HeavyMaterials = (int)(pTable.heavyMaterial * (1 + (curSys.pMaterial / 20))); cPlan.HeavyMaterials = cPlan.HeavyMaterials * (1 + ((5 - systemSpot) / 10)); cPlan.HeavyMaterials += heavyVar; } catch (Exception ex) { Debug.LogError("Could not calcuate. Error: " + ex.ToString()); } // Step 10: Determine rating of rare materials try { int rareMod = UnityEngine.Random.Range(0, pTable.rareVar); cPlan.RareMaterials = (int)(pTable.rareMaterial * (1 + (curSys.pMaterial / 12))); cPlan.RareMaterials = cPlan.RareMaterials * (1 + ((5 - systemSpot) / 8)); cPlan.RareMaterials += rareMod; } catch (Exception ex) { Debug.LogError("Could not calcuate. Error: " + ex.ToString()); } // Step 11: Determine energy rating try { cPlan.Energy = (int)(pTable.energy * (1 + (curSys.pMaterial / 12))); cPlan.Energy = cPlan.Energy * (1 + ((5 - systemSpot) / 10)); cPlan.Energy += UnityEngine.Random.Range(0, 30); } catch (Exception ex) { Debug.LogError("Could not calcuate. Error: " + ex.ToString()); } // Step 12: Generate sprite number (to show type of planet) if ((cPlan.Type != PlanetData.ePlanetType.DustRing) && (cPlan.Type != PlanetData.ePlanetType.IceBelt) && (cPlan.Type != PlanetData.ePlanetType.AsteroidBelt)) cPlan.PlanetSpriteNumber = UnityEngine.Random.Range(0, SpritesPerPlanetType - 1); else cPlan.PlanetSpriteNumber = UnityEngine.Random.Range(0, SpritesPerBeltType - 1); // Step 13: Generate ring sprite number if applicable cPlan.PlanetRingSpriteNumber = UnityEngine.Random.Range(0, SpritesPerRingType - 1); cPlan.PlanetRingTilt = UnityEngine.Random.Range(-10, 10); // Step 13: Determine planetary traits DeterminePlanetTraits(cPlan); // Step 14: Determine total and habitable tiles based on bio level cPlan.MaxTiles = (cPlan.Size / 3); for (int x = 0; x < cPlan.MaxTiles; x++) { if (UnityEngine.Random.Range(0, 100) < cPlan.AdjustedBio) { cPlan.MaxHabitableTiles += 1; } } // Step 15: Create and assign tiles to the planet GeneratePlanetRegions(cPlan); // Step 16: Send the planet data back! return cPlan; }
public void Reset() { planetData = null; starData = null; }
// create a new star system and return it to the GalaxyCreator public static StarData CreateNewStar() { StarData stData = new StarData(); GenerateStar(stData); return stData; }
public void SetTarget(StarData star) { Reset(); starData = star; }
public void AddStarDataToList(StarData sData) { GalaxyStarDataList.Add(sData); }
public IEnumerator ProcessTwitchCommand(string command) { if (!activated) { yield return("sendtochat {0}, !{1} not activated"); yield break; } command = command.Trim().ToLower(); if (command == "outskirts") { IEnumerable <StarObject> stars = starByName.Values.Where(s => s.cell.adjacentStars.Count == 1 && s.cell.name != MapGenerator.SUN_NAME); yield return(null); if (stars.Count() > 3) { yield return("waiting music"); } foreach (StarObject star in stars) { star.GetComponent <KMSelectable>().Highlight.transform.GetChild(0).gameObject.SetActive(true); star.Highlight(); yield return(new WaitForSeconds(5f)); star.GetComponent <KMSelectable>().Highlight.transform.GetChild(0).gameObject.SetActive(false); star.RemoveHighlight(); yield return(null); if (TwitchShouldCancelCommand) { yield return("cancelled"); yield break; } } yield break; } if (command.StartsWith("trace ")) { string starName = command.Skip(6).Join("").Trim(); if (starName == MapGenerator.SUN_NAME) { yield break; } if ( !StarData.HasLowerCasedStarName(starName) || !starByName.ContainsKey(StarData.LowerCasedStarNameToActual(starName)) ) { yield return("sendtochat {0}, !{1} " + string.Format("Star \"{0}\" not found", starName)); yield break; } StarObject target = starByName[StarData.LowerCasedStarNameToActual(starName)]; yield return(null); if (target.cell.path.Count > 3) { yield return("waiting music"); } foreach (MapGenerator.CellStar cell in target.cell.path) { StarObject star = starByName[cell.name]; star.GetComponent <KMSelectable>().Highlight.transform.GetChild(0).gameObject.SetActive(true); star.Highlight(); yield return(new WaitForSeconds(5f)); star.GetComponent <KMSelectable>().Highlight.transform.GetChild(0).gameObject.SetActive(false); star.RemoveHighlight(); yield return(null); if (TwitchShouldCancelCommand) { yield return("cancelled"); yield break; } } yield break; } if (command.StartsWith("send ")) { string[] starsName = command.Split(' ').Skip(1).Where((n) => n.Length > 0).ToArray(); string[] unknownStars = starsName.Where((s) => ( !StarData.HasLowerCasedStarName(s) || !starByName.ContainsKey(StarData.LowerCasedStarNameToActual(s)) )).ToArray(); if (unknownStars.Length > 0) { yield return("sendtochat {0}, !{1} " + string.Format( "Stars {0} not found", unknownStars.Select((s) => string.Format("\"{0}\"", s)).Join(", ") )); yield break; } foreach (StarObject star in starsName.Select((s) => starByName[StarData.LowerCasedStarNameToActual(s)])) { bool success = OnStarPressed(star); if (!success) { break; } } yield return(new KMSelectable[] { }); yield break; } if (command.StartsWith("look ")) { string[] starsName = command.Split(' ').Skip(1).Where((n) => n.Length > 0).ToArray(); string[] unknownStars = starsName.Where((s) => ( !StarData.HasLowerCasedStarName(s) || !starByName.ContainsKey(StarData.LowerCasedStarNameToActual(s)) )).ToArray(); if (unknownStars.Length > 0) { yield return("sendtochat {0}, !{1} " + string.Format( "Stars {0} not found", unknownStars.Select((s) => string.Format("\"{0}\"", s)).Join(", ") )); yield break; } yield return(null); if (starsName.Count() > 3) { yield return("waiting music"); } foreach (string starName in starsName) { StarObject star = starByName[StarData.LowerCasedStarNameToActual(starName)]; star.GetComponent <KMSelectable>().Highlight.transform.GetChild(0).gameObject.SetActive(true); star.Highlight(); yield return(new WaitForSeconds(5f)); star.GetComponent <KMSelectable>().Highlight.transform.GetChild(0).gameObject.SetActive(false); star.RemoveHighlight(); yield return(null); if (TwitchShouldCancelCommand) { yield return("cancelled"); yield break; } } yield break; } yield return(null); }