Example #1
0
 public static void _OnUpdate_Postfix()
 {
     if (Multiplayer.IsInMultiplayerMenu)
     {
         // as we need to load and generate planets for the detail view in the lobby, update the loading process here
         PlanetModelingManager.ModelingPlanetCoroutine();
         UIRoot.instance.uiGame.planetDetail._OnUpdate();
     }
 }
Example #2
0
        public override void ProcessPacket(PlanetDataRequest packet, NebulaConnection conn)
        {
            if (IsClient)
            {
                return;
            }

            Dictionary <int, byte[]> planetDataToReturn = new Dictionary <int, byte[]>();

            foreach (int planetId in packet.PlanetIDs)
            {
                PlanetData planet = GameMain.galaxy.PlanetById(planetId);
                Log.Info($"Returning terrain for {planet.name}");

                // NOTE: The following has been picked-n-mixed from "PlanetModelingManager.PlanetComputeThreadMain()"
                // This method is **costly** - do not run it more than is required!
                // It generates the planet on the host and then sends it to the client

                PlanetAlgorithm planetAlgorithm = PlanetModelingManager.Algorithm(planet);

                if (planet.data == null)
                {
                    planet.data    = new PlanetRawData(planet.precision);
                    planet.modData = planet.data.InitModData(planet.modData);
                    planet.data.CalcVerts();
                    planet.aux = new PlanetAuxData(planet);
                    planetAlgorithm.GenerateTerrain(planet.mod_x, planet.mod_y);
                    planetAlgorithm.CalcWaterPercent();

                    //Load planet meshes and register callback to unload unneccessary stuff
                    planet.wanted    = true;
                    planet.onLoaded += OnActivePlanetLoaded;
                    PlanetModelingManager.modPlanetReqList.Enqueue(planet);

                    if (planet.type != EPlanetType.Gas)
                    {
                        planetAlgorithm.GenerateVegetables();
                        planetAlgorithm.GenerateVeins(false);
                    }
                }

                using (BinaryUtils.Writer writer = new BinaryUtils.Writer())
                {
                    planet.ExportRuntime(writer.BinaryWriter);
                    planetDataToReturn.Add(planetId, writer.CloseAndGetBytes());
                }
            }

            conn.SendPacket(new PlanetDataResponse(planetDataToReturn));
        }
        private static byte[] PlanetCompute(int planetId) 
        {
            PlanetData planet = GameMain.galaxy.PlanetById(planetId);
            HighStopwatch highStopwatch = new HighStopwatch();
            highStopwatch.Begin();

            // NOTE: The following has been picked-n-mixed from "PlanetModelingManager.PlanetComputeThreadMain()"
            // This method is **costly** - do not run it more than is required!
            // It generates the planet on the host and then sends it to the client

            PlanetAlgorithm planetAlgorithm = PlanetModelingManager.Algorithm(planet);

            if (planet.data == null)
            {
                planet.data = new PlanetRawData(planet.precision);
                planet.modData = planet.data.InitModData(planet.modData);
                planet.data.CalcVerts();
                planet.aux = new PlanetAuxData(planet);
                planetAlgorithm.GenerateTerrain(planet.mod_x, planet.mod_y);
                planetAlgorithm.CalcWaterPercent();

                //Load planet meshes and register callback to unload unneccessary stuff
                planet.wanted = true;
                planet.onLoaded += OnActivePlanetLoaded;
                PlanetModelingManager.modPlanetReqList.Enqueue(planet);

                if (planet.type != EPlanetType.Gas)
                {
                    planetAlgorithm.GenerateVegetables();
                    planetAlgorithm.GenerateVeins(false);
                }
            }

            byte[] data;
            using (BinaryUtils.Writer writer = new BinaryUtils.Writer())
            {
                planet.ExportRuntime(writer.BinaryWriter);
                data = writer.CloseAndGetBytes();
            }
            Log.Info($"Returning terrain for {planet.name} (id:{planet.id} time:{highStopwatch.duration:F4}s)");
            return data;
        }
Example #4
0
        public static void _OnOpen_Postfix(UIGalaxySelect __instance)
        {
            if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsClient)
            {
                RectTransform galaxySelectRect = __instance.gameObject.GetComponent <RectTransform>();

                galaxySelectRect.Find("star-count").gameObject.SetActive(false);
                galaxySelectRect.Find("resource-multiplier").gameObject.SetActive(false);
                galaxySelectRect.Find("galaxy-seed").GetComponentInChildren <InputField>().enabled = false;
                galaxySelectRect.Find("random-button").gameObject.SetActive(false);
                galaxySelectRect.Find("property-multiplier").gameObject.SetActive(false);
                galaxySelectRect.Find("seed-key").gameObject.SetActive(false);
            }
            if (Multiplayer.IsActive)
            {
                // show lobby hints if needed
                if (Config.Options.ShowLobbyHints)
                {
                    InGamePopup.ShowInfo("The Lobby",
                                         "We changed the start of a new multiplayer game a bit and want to give you a quick overview of the new feature.\n\n" +
                                         "Clients can now join while the host is in the galaxy selection screen, and they will also land there if it is their first time connecting to the currently hosted save.\n\n" +
                                         "You can now click on any star to bring up the solar system preview. From there you can click on any planet to bring up its details.\n" +
                                         "Note that when using GalacticScale 2 this process can take a bit longer.\n\n" +
                                         "By clicking a planet while having its detail panel open you will set it as your birth planet.\n\n" +
                                         "By clicking into outer space you will go one detail level up.\n\n" +
                                         "We hope you enjoy this new feature!",
                                         "Okay, cool :)",
                                         CloseLobbyInfo);
                }
                // prepare PlanetModelingManager for the use of its compute thread as we need that for the planet details view in the lobby
                PlanetModelingManager.PrepareWorks();
                // store current star id because entering the solar system details view messes up the main menu background system.
                if (MainMenuStarID == -1)
                {
                    MainMenuStarID = GameMain.localStar.id;
                }
                Button button = GameObject.Find("UI Root/Overlay Canvas/Galaxy Select/start-button").GetComponent <Button>();
                button.interactable = true;
            }
        }
Example #5
0
    //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);
    }
        private static void ShowSolarSystem(UIVirtualStarmap starmap, int starIndex)
        {
            // start planet compute thread if not done already
            PlanetModelingManager.StartPlanetComputeThread();

            // add star
            StarData starData = starmap._galaxyData.StarById(starIndex + 1); // because StarById() decrements by 1

            AddStarToStarmap(starmap, starData);

            starmap.clickText = starData.id.ToString();
            Debug.Log("Setting it to " + starmap.clickText + " " + starData.id);

            for (int i = 0; i < starData.planetCount; i++)
            {
                // add planets
                PlanetData pData       = starData.planets[i];
                Color      color       = starmap.neutronStarColor;
                float      scaleFactor = 0.6f;
                bool       isMoon      = false;

                VectorLF3 pPos = GetRelativeRotatedPlanetPos(starData, pData, ref isMoon);

                // request generation of planet surface data to display its details when clicked and if not already loaded
                if (!pData.loaded)
                {
                    PlanetModelingManager.RequestLoadPlanet(pData);
                }

                // create fake StarData to pass _OnLateUpdate()
                StarData dummyStarData = new StarData
                {
                    position = pPos,
                    color    = starData.color,
                    id       = pData.id
                };

                Vector3 scale = (pData.realRadius / 100) * scaleFactor * Vector3.one;
                if (scale.x > 3 || scale.y > 3 || scale.z > 3)
                {
                    scale = new Vector3(3, 3, 3);
                }

                starmap.starPool[i + 1].active   = true;
                starmap.starPool[i + 1].starData = dummyStarData;
                starmap.starPool[i + 1].pointRenderer.material.SetColor("_TintColor", color);
                starmap.starPool[i + 1].pointRenderer.transform.localPosition = pPos;
                starmap.starPool[i + 1].pointRenderer.transform.localScale    = scale;
                starmap.starPool[i + 1].pointRenderer.gameObject.SetActive(true);
                starmap.starPool[i + 1].nameText.text  = pData.displayName + " (" + pData.typeString + ")";
                starmap.starPool[i + 1].nameText.color = Color.Lerp(color, Color.white, 0.5f);
                starmap.starPool[i + 1].nameText.rectTransform.sizeDelta        = new Vector2(starmap.starPool[i + 1].nameText.preferredWidth, starmap.starPool[i + 1].nameText.preferredHeight);
                starmap.starPool[i + 1].nameText.rectTransform.anchoredPosition = new Vector2(-2000f, -2000f);
                starmap.starPool[i + 1].textContent = pData.displayName + " (" + pData.typeString + ")";

                starmap.starPool[i + 1].nameText.gameObject.SetActive(true);

                // add orbit renderer
                starmap.connPool[i].active = true;
                starmap.connPool[i].lineRenderer.material.SetColor("_LineColorA", Color.Lerp(color, Color.white, 0.65f));

                if (starmap.connPool[i].lineRenderer.positionCount != 61)
                {
                    starmap.connPool[i].lineRenderer.positionCount = 61;
                }
                for (int j = 0; j < 61; j++)
                {
                    float   f    = (float)j * 0.017453292f * 6f; // ty dsp devs :D
                    Vector3 cPos = GetCenterOfOrbit(starData, pData, ref isMoon);
                    Vector3 position;
                    if (isMoon)
                    {
                        position = new Vector3(Mathf.Cos(f) * pData.orbitRadius * orbitScaler * 8 + (float)cPos.x, cPos.y, Mathf.Sin(f) * pData.orbitRadius * orbitScaler * 8 + (float)cPos.z);
                    }
                    else
                    {
                        position = new Vector3(Mathf.Cos(f) * pData.orbitRadius * orbitScaler + (float)cPos.x, cPos.y, Mathf.Sin(f) * pData.orbitRadius * orbitScaler + (float)cPos.z);
                    }

                    // rotate position around center by orbit angle
                    Quaternion quaternion = Quaternion.Euler(pData.orbitInclination, pData.orbitInclination, pData.orbitInclination);
                    Vector3    dir        = quaternion * (position - cPos);
                    position = dir + cPos;

                    starmap.connPool[i].lineRenderer.SetPosition(j, position);
                }
                starmap.connPool[i].lineRenderer.gameObject.SetActive(true);
            }
        }
Example #7
0
        public static void GameMain_End_Prefix()
        {
            spreadsheetGenRequestFlag = false;
            planetResourceData.Clear();

            /******************************************************************/
            /* The code below fixes a bug in the original game which this mod */
            /* just makes appear more easily.  The original game doesn't      */
            /* properly handle PlanetModelingManager resetting when a game    */
            /* ends.  Such resetting is only needed when a planet/factory is  */
            /* being loaded, a rare occurance if it weren't for this mod.     */
            /******************************************************************/

            if (PlanetModelingManager.genPlanetReqList.Count == 0 &&
                PlanetModelingManager.fctPlanetReqList.Count == 0 &&
                PlanetModelingManager.modPlanetReqList.Count == 0)
            {
                Logger.LogInfo("Planet modeling reset is not needed.");
                return;
            }

            Logger.LogInfo("Stopping planet modeling thread.");
            PlanetModelingManager.EndPlanetComputeThread();
            Thread.Sleep(100);

            uint sleepIterationCount = 1;

            while (PlanetModelingManager.planetComputeThreadFlag == PlanetModelingManager.ThreadFlag.Ending &&
                   ++sleepIterationCount < 100) // Don't wait more than 10 seconds.  (It shouldn't even enter this loop.)
            {
                Thread.Sleep(100);
            }

            Logger.LogInfo("Clearing planet modeling queues.");
            PlanetModelingManager.genPlanetReqList.Clear();  // RequestLoadStar or RequestLoadPlanet -> PlanetComputeThreadMain
            PlanetModelingManager.fctPlanetReqList.Clear();  // RequestLoadPlanetFactory -> LoadingPlanetFactoryCoroutine
            PlanetModelingManager.modPlanetReqList.Clear();  // ModelingPlanetCoroutine -> ModelingPlanetMain

            if (PlanetModelingManager.currentModelingPlanet != null)
            {
                Logger.LogInfo("Cancelling planet modeling for " + PlanetModelingManager.currentModelingPlanet.name);
                PlanetModelingManager.currentModelingPlanet.Unload();
                PlanetModelingManager.currentModelingPlanet.factoryLoaded = false;
                PlanetModelingManager.currentModelingPlanet     = null;
                PlanetModelingManager.currentModelingStage      = 0;
                PlanetModelingManager.currentModelingSeamNormal = 0;
            }

            if (PlanetModelingManager.currentFactingPlanet != null)
            {
                Logger.LogInfo("Cancelling planet factory modeling for " + PlanetModelingManager.currentFactingPlanet.name);
                PlanetModelingManager.currentFactingPlanet.UnloadFactory();
                PlanetModelingManager.currentFactingPlanet.factoryLoaded = false;
                PlanetModelingManager.currentFactingPlanet = null;
                PlanetModelingManager.currentFactingStage  = 0;
            }

            Logger.LogInfo("Resetting planet modeling manager so we don't get a magenta planet when a new game begins.");
            for (int num57 = 0; num57 < PlanetModelingManager.tmpMeshList.Count; num57++)
            {
                UnityEngine.Object.Destroy(PlanetModelingManager.tmpMeshList[num57]);
            }
            UnityEngine.Object.Destroy(PlanetModelingManager.tmpPlanetGameObject);
            PlanetModelingManager.tmpPlanetGameObject       = null;
            PlanetModelingManager.tmpPlanetBodyGameObject   = null;
            PlanetModelingManager.tmpPlanetReformGameObject = null;
            PlanetModelingManager.tmpPlanetReformRenderer   = null;
            PlanetModelingManager.tmpMeshList.Clear();
            PlanetModelingManager.tmpTris.Clear();
            PlanetModelingManager.tmpVerts.Clear();
            PlanetModelingManager.tmpNorms.Clear();
            PlanetModelingManager.tmpTgnts.Clear();
            PlanetModelingManager.tmpUvs.Clear();
            PlanetModelingManager.tmpUv2s.Clear();
            PlanetModelingManager.currentModelingPlanet     = null;
            PlanetModelingManager.currentModelingStage      = 0;
            PlanetModelingManager.currentModelingSeamNormal = 0;

            Logger.LogInfo("Restarting planet modeling thread.");
            PlanetModelingManager.StartPlanetComputeThread();
        }
Example #8
0
            private static void exportStar(PlanetData planet)
            {
                UnityEngine.Debug.Log("-- planet: " + planet.id);
                PlanetAlgorithm planetAlgorithm = PlanetModelingManager.Algorithm(planet);

                planet.data    = new PlanetRawData(planet.precision);
                planet.modData = planet.data.InitModData(planet.modData);
                planet.data.CalcVerts();
                planet.aux = new PlanetAuxData(planet);
                planetAlgorithm.GenerateTerrain(planet.mod_x, planet.mod_y);
                planetAlgorithm.CalcWaterPercent();
                if (planet.type != EPlanetType.Gas)
                {
                    planetAlgorithm.GenerateVegetables();
                }
                if (planet.type != EPlanetType.Gas)
                {
                    planetAlgorithm.GenerateVeins(false);
                }
                Monitor.Enter(streamWriter);
                try
                {
                    if (!firstPlanet)
                    {
                        streamWriter.Write(",");
                    }
                    else
                    {
                        firstPlanet = false;
                    }
                    streamWriter.Write("\"" + planet.name + "\":{" +
                                       "\"seed\":" + planet.seed +
                                       ",\"index\":" + planet.index +
                                       ",\"id\":" + planet.id +
                                       ",\"orbitAround\":" + planet.orbitAround +
                                       ",\"number\":" + planet.number +
                                       ",\"orbitIndex\":" + planet.orbitIndex +
                                       ",\"name\":\"" + planet.name + "\"" +
                                       ",\"orbitRadius\":" + planet.orbitRadius +
                                       ",\"orbitInclination\":" + planet.orbitInclination +
                                       ",\"orbitLongitude\":" + planet.orbitLongitude +
                                       ",\"orbitalPeriod\":" + planet.orbitalPeriod +
                                       ",\"orbitPhase\":" + planet.orbitPhase +
                                       ",\"obliquity\":" + planet.obliquity +
                                       ",\"rotationPeriod\":" + planet.rotationPeriod +
                                       ",\"rotationPhase\":" + planet.rotationPhase +
                                       ",\"radius\":" + planet.radius +
                                       ",\"scale\":" + planet.scale +
                                       ",\"sunDistance\":" + planet.sunDistance +
                                       ",\"habitableBias\":" + planet.habitableBias +
                                       ",\"temperatureBias\":" + planet.temperatureBias +
                                       ",\"ionHeight\":" + planet.ionHeight +
                                       ",\"windStrength\":" + planet.windStrength +
                                       ",\"luminosity\":" + planet.luminosity +
                                       ",\"landPercent\":" + planet.landPercent +
                                       ",\"mod_x\":" + planet.mod_x +
                                       ",\"mod_y\":" + planet.mod_y +
                                       ",\"type\":" + (int)planet.type +
                                       ",\"singularity\":" + (int)planet.singularity +
                                       ",\"theme\":" + planet.theme +
                                       ",\"algoId\":" + planet.algoId +
                                       ",\"waterHeight\":" + planet.waterHeight);
                    if (planet.waterItemId > 0)
                    {
                        ItemProto water = LDB.items.Select(planet.waterItemId);
                        streamWriter.Write(
                            ",\"waterItem\":\"" + water.name + "\""
                            );
                    }
                    if (planet.type == EPlanetType.Gas)
                    {
                        streamWriter.Write(",\"gasTotalHeat\":" + planet.gasTotalHeat);
                        streamWriter.Write(",\"gas\":{"); // open gas[]
                        bool firstvein = true;
                        for (int k = 0; k < planet.gasItems.Length; k++)
                        {
                            ItemProto gas = LDB.items.Select(planet.gasItems[k]);
                            if (firstvein == false)
                            {
                                streamWriter.Write(",");
                            }
                            else
                            {
                                firstvein = false;
                            }
                            streamWriter.Write("\"" + gas.name + "\":{" +
                                               "\"gasName\":\"" + gas.name + "\"" +
                                               ",\"gasItem\":" + planet.gasItems[k] +
                                               ",\"gasSpeed\":\"" + planet.gasSpeeds[k] + "\"" +
                                               ",\"gasHeatValue\":\"" + planet.gasHeatValues[k] + "\"}");
                        }
                        streamWriter.Write("}"); // close gas[]
                    }
                    else
                    {
                        streamWriter.Write(",\"vein\":{"); // open vein[]
                        bool firstvein = true;
                        for (int k = 0; k < planet.veinAmounts.Length; k++)
                        {
                            if (planet.veinAmounts[k] == 0)
                            {
                                continue;
                            }
                            if (firstvein == false)
                            {
                                streamWriter.Write(",");
                            }
                            else
                            {
                                firstvein = false;
                            }
                            streamWriter.Write("\"" + (EVeinType)k + "\":" + planet.veinAmounts[k]);
                        }
                        streamWriter.Write("}");                                                                                                                // close vein[]
                    }
                    streamWriter.Write(",\"uPosition\":{\"x\":" + planet.uPosition.x + ",\"y\":" + planet.uPosition.y + ",\"z\":" + planet.uPosition.z + "}}"); // close planet
                }
                finally { Monitor.Exit(streamWriter); }
                planet.Unload();
            }
        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);
        }