Пример #1
0
 public SData(int index, int seed, EStarType type, ESpectrType eSpectr)
 {
     this.seed       = seed;
     this.type       = type;
     this.spectrType = eSpectr;
     this.index      = index;
 }
Пример #2
0
 public void Import(BinaryReader r)
 {
     index      = r.ReadInt32();
     seed       = r.ReadInt32();
     type       = (EStarType)r.ReadInt32();
     spectrType = (ESpectrType)r.ReadInt32();
     other1     = r.ReadInt32();
     other2     = r.ReadInt32();
     other3     = r.ReadInt32();
 }
Пример #3
0
        //随机一个获取并更换一个星系
        IEnumerator RadomSun(StarData[] stars, int index, EStarType type, ESpectrType type1 = ESpectrType.O)
        {
            yield return(new WaitForFixedUpdate());//等待帧结束

            var star = stars[index];
            //暂存原始星系数据
            var oldstar = star;
            int seed    = random.Next();

            if (data.ContainsKey(index))
            {
                data[index].seed       = seed;
                data[index].type       = type;
                data[index].spectrType = type1;
                //生成新的星系
                stars[index] = StarGen.CreateStar(GameMain.galaxy, oldstar.position, index + 1, seed, type, type1);
                //还给一些原始数据
                SwapStar(oldstar, stars[index]);

                if (selectData != null)
                {
                    selectData = stars[index];
                }
            }
            else
            {
                data.Add(index, new SData(index, seed, type, type1));
                //生成新的星系
                stars[index] = StarGen.CreateStar(GameMain.galaxy, oldstar.position, index + 1, seed, type, type1);
                //还给一些原始数据
                SwapStar(oldstar, stars[index]);
                selectData = stars[index];
            }
            if (oldstar == GameMain.localStar)
            {
                Traverse.Create(GameMain.data).Field("<localStar>k__BackingField").SetValue(stars[index]);
            }
            SwapFinally();
        }
Пример #4
0
		public virtual void GenerateVeins(bool sketchOnly)
		{
			lock (planet)
			{
				ThemeProto themeProto = LDB.themes.Select(planet.theme);
				if (themeProto == null)
				{
					return;
				}
				System.Random random = new System.Random(planet.seed);
				random.Next();
				random.Next();
				random.Next();
				random.Next();
				random.Next();
				int num = random.Next();
				System.Random random2 = new System.Random(num);
				PlanetRawData data = planet.data;
				float num2 = 2.1f / planet.radius;
				VeinProto[] veinProtos = PlanetModelingManager.veinProtos;
				int[] veinModelIndexs = PlanetModelingManager.veinModelIndexs;
				int[] veinModelCounts = PlanetModelingManager.veinModelCounts;
				int[] veinProducts = PlanetModelingManager.veinProducts;
				int[] veinSpotArr = new int[veinProtos.Length];
				float[] veinCountArr = new float[veinProtos.Length];
				float[] veinOpacityArr = new float[veinProtos.Length];
				if (themeProto.VeinSpot != null)
				{
					Array.Copy(themeProto.VeinSpot, 0, veinSpotArr, 1, Math.Min(themeProto.VeinSpot.Length, veinSpotArr.Length - 1));
				}
				if (themeProto.VeinCount != null)
				{
					Array.Copy(themeProto.VeinCount, 0, veinCountArr, 1, Math.Min(themeProto.VeinCount.Length, veinCountArr.Length - 1));
				}
				if (themeProto.VeinOpacity != null)
				{
					Array.Copy(themeProto.VeinOpacity, 0, veinOpacityArr, 1, Math.Min(themeProto.VeinOpacity.Length, veinOpacityArr.Length - 1));
				}
				float p = 1f;
				ESpectrType spectr = planet.star.spectr;
				switch (planet.star.type)
				{
					case EStarType.MainSeqStar:
						switch (spectr)
						{
							case ESpectrType.M:
								p = 2.5f;
								break;
							case ESpectrType.K:
								p = 1f;
								break;
							case ESpectrType.G:
								p = 0.7f;
								break;
							case ESpectrType.F:
								p = 0.6f;
								break;
							case ESpectrType.A:
								p = 1f;
								break;
							case ESpectrType.B:
								p = 0.4f;
								break;
							case ESpectrType.O:
								p = 1.6f;
								break;
						}
						break;
					case EStarType.GiantStar:
						p = 2.5f;
						break;
					case EStarType.WhiteDwarf:
						{
							p = 3.5f;
							veinSpotArr[9]++;
							veinSpotArr[9]++;
							for (int j = 1; j < 12; j++)
							{
								if (random.NextDouble() >= 0.44999998807907104)
								{
									break;
								}
								veinSpotArr[9]++;
							}
							veinCountArr[9] = 0.7f;
							veinOpacityArr[9] = 1f;
							veinSpotArr[10]++;
							veinSpotArr[10]++;
							for (int k = 1; k < 12; k++)
							{
								if (random.NextDouble() >= 0.44999998807907104)
								{
									break;
								}
								veinSpotArr[10]++;
							}
							veinCountArr[10] = 0.7f;
							veinOpacityArr[10] = 1f;
							veinSpotArr[12]++;
							for (int l = 1; l < 12; l++)
							{
								if (random.NextDouble() >= 0.5)
								{
									break;
								}
								veinSpotArr[12]++;
							}
							veinCountArr[12] = 0.7f;
							veinOpacityArr[12] = 0.3f;
							break;
						}
					case EStarType.NeutronStar:
						{
							p = 4.5f;
							veinSpotArr[14]++;
							for (int m = 1; m < 12; m++)
							{
								if (random.NextDouble() >= 0.64999997615814209)
								{
									break;
								}
								veinSpotArr[14]++;
							}
							veinCountArr[14] = 0.7f;
							veinOpacityArr[14] = 0.3f;
							break;
						}
					case EStarType.BlackHole:
						{
							p = 5f;
							veinSpotArr[14]++;
							for (int i = 1; i < 12; i++)
							{
								if (random.NextDouble() >= 0.64999997615814209)
								{
									break;
								}
								veinSpotArr[14]++;
							}
							veinCountArr[14] = 0.7f;
							veinOpacityArr[14] = 0.3f;
							break;
						}
				}
				for (int n = 0; n < themeProto.RareVeins.Length; n++)
				{
					int num3 = themeProto.RareVeins[n];
					float num4 = ((planet.star.index != 0) ? themeProto.RareSettings[n * 4 + 1] : themeProto.RareSettings[n * 4]);
					float num5 = themeProto.RareSettings[n * 4 + 2];
					float num6 = themeProto.RareSettings[n * 4 + 3];
					float num7 = num6;
					num4 = 1f - Mathf.Pow(1f - num4, p);
					num6 = 1f - Mathf.Pow(1f - num6, p);
					num7 = 1f - Mathf.Pow(1f - num7, p);
					if (!(random.NextDouble() < (double)num4))
					{
						continue;
					}
					veinSpotArr[num3]++;
					veinCountArr[num3] = num6;
					veinOpacityArr[num3] = num6;
					for (int num8 = 1; num8 < 12; num8++)
					{
						if (random.NextDouble() >= (double)num5)
						{
							break;
						}
						veinSpotArr[num3]++;
					}
				}
				float num9 = planet.star.resourceCoef;
				bool flag = DSPGame.GameDesc.resourceMultiplier >= 99.5f;
				if (planet.galaxy.birthPlanetId == planet.id)
				{
					num9 *= 2f / 3f;
				}
				float num10 = 1f;
				num10 *= 1.1f;
				Array.Clear(veinVectors, 0, veinVectors.Length);
				Array.Clear(veinVectorTypes, 0, veinVectorTypes.Length);
				veinVectorCount = 0;
				Vector3 vector = default(Vector3);
				if (planet.galaxy.birthPlanetId == planet.id)
				{
					Pose pose = planet.PredictPose(120.0);
					vector = Maths.QInvRotateLF(pose.rotation, planet.star.uPosition - (VectorLF3)pose.position * 40000.0);
					vector.Normalize();
					vector *= 0.75f;
				}
				else
				{
					vector.x = (float)random2.NextDouble() * 2f - 1f;
					vector.y = (float)random2.NextDouble() - 0.5f;
					vector.z = (float)random2.NextDouble() * 2f - 1f;
					vector.Normalize();
					vector *= (float)(random2.NextDouble() * 0.4 + 0.2);
				}
				planet.veinSpotsSketch = veinSpotArr;
				if (sketchOnly)
				{
					return;
				}
				for (int num11 = 1; num11 < 15; num11++)
				{
					if (veinVectorCount >= veinVectors.Length)
					{
						break;
					}
					EVeinType eVeinType = (EVeinType)num11;
					int num12 = veinSpotArr[num11];
					if (num12 > 1)
					{
						num12 += random2.Next(-1, 2);
					}
					for (int num13 = 0; num13 < num12; num13++)
					{
						int num14 = 0;
						Vector3 zero = Vector3.zero;
						bool flag2 = false;
						while (num14++ < 200)
						{
							zero.x = (float)random2.NextDouble() * 2f - 1f;
							zero.y = (float)random2.NextDouble() * 2f - 1f;
							zero.z = (float)random2.NextDouble() * 2f - 1f;
							if (eVeinType != EVeinType.Oil)
							{
								zero += vector;
							}
							zero.Normalize();
							float num15 = data.QueryHeight(zero);
							if (num15 < planet.radius || (eVeinType == EVeinType.Oil && num15 < planet.radius + 0.5f))
							{
								continue;
							}
							bool flag3 = false;
							float num16 = ((eVeinType != EVeinType.Oil) ? 196f : 100f);
							for (int num17 = 0; num17 < veinVectorCount; num17++)
							{
								if ((veinVectors[num17] - zero).sqrMagnitude < num2 * num2 * num16)
								{
									flag3 = true;
									break;
								}
							}
							if (flag3)
							{
								continue;
							}
							flag2 = true;
							break;
						}
						if (flag2)
						{
							veinVectors[veinVectorCount] = zero;
							veinVectorTypes[veinVectorCount] = eVeinType;
							veinVectorCount++;
							if (veinVectorCount == veinVectors.Length)
							{
								break;
							}
						}
					}
				}
				Array.Clear(planet.veinAmounts, 0, planet.veinAmounts.Length);
				data.veinCursor = 1;
				planet.veinGroups = new PlanetData.VeinGroup[veinVectorCount];
				tmp_vecs.Clear();
				VeinData vein = default(VeinData);
				for (int num18 = 0; num18 < veinVectorCount; num18++)
				{
					tmp_vecs.Clear();
					Vector3 normalized = veinVectors[num18].normalized;
					EVeinType eVeinType2 = veinVectorTypes[num18];
					int num19 = (int)eVeinType2;
					Quaternion quaternion = Quaternion.FromToRotation(Vector3.up, normalized);
					Vector3 vector2 = quaternion * Vector3.right;
					Vector3 vector3 = quaternion * Vector3.forward;
					planet.veinGroups[num18].type = eVeinType2;
					planet.veinGroups[num18].pos = normalized;
					planet.veinGroups[num18].count = 0;
					planet.veinGroups[num18].amount = 0L;
					tmp_vecs.Add(Vector2.zero);
					int num20 = Mathf.RoundToInt(veinCountArr[num19] * (float)random2.Next(20, 25));
					if (eVeinType2 == EVeinType.Oil)
					{
						num20 = 1;
					}
					int num21 = 0;
					while (num21++ < 20)
					{
						int count = tmp_vecs.Count;
						for (int num22 = 0; num22 < count; num22++)
						{
							if (tmp_vecs.Count >= num20)
							{
								break;
							}
							if (tmp_vecs[num22].sqrMagnitude > 36f)
							{
								continue;
							}
							double num23 = random2.NextDouble() * Math.PI * 2.0;
							Vector2 vector4 = new Vector2((float)Math.Cos(num23), (float)Math.Sin(num23));
							vector4 += tmp_vecs[num22] * 0.2f;
							vector4.Normalize();
							Vector2 vector5 = tmp_vecs[num22] + vector4;
							bool flag4 = false;
							for (int num24 = 0; num24 < tmp_vecs.Count; num24++)
							{
								if ((tmp_vecs[num24] - vector5).sqrMagnitude < 0.85f)
								{
									flag4 = true;
									break;
								}
							}
							if (!flag4)
							{
								tmp_vecs.Add(vector5);
							}
						}
						if (tmp_vecs.Count >= num20)
						{
							break;
						}
					}
					int num25 = Mathf.RoundToInt(veinOpacityArr[num19] * 100000f * num9);
					if (num25 < 20)
					{
						num25 = 20;
					}
					int num26 = ((num25 >= 16000) ? 15000 : Mathf.FloorToInt((float)num25 * 0.9375f));
					int minValue = num25 - num26;
					int maxValue = num25 + num26 + 1;
					for (int num27 = 0; num27 < tmp_vecs.Count; num27++)
					{
						Vector3 vector6 = (tmp_vecs[num27].x * vector2 + tmp_vecs[num27].y * vector3) * num2;
						vein.type = eVeinType2;
						vein.groupIndex = (short)num18;
						vein.modelIndex = (short)random2.Next(veinModelIndexs[num19], veinModelIndexs[num19] + veinModelCounts[num19]);
						vein.amount = Mathf.RoundToInt((float)random2.Next(minValue, maxValue) * num10);
						if (planet.veinGroups[num18].type != EVeinType.Oil)
						{
							vein.amount = Mathf.RoundToInt((float)vein.amount * DSPGame.GameDesc.resourceMultiplier);
						}
						if (vein.amount < 1)
						{
							vein.amount = 1;
						}
						if (flag && vein.type != EVeinType.Oil)
						{
							vein.amount = 1000000000;
						}
						vein.productId = veinProducts[num19];
						vein.pos = normalized + vector6;
						if (vein.type == EVeinType.Oil)
						{
							vein.pos = planet.aux.RawSnap(vein.pos);
						}
						vein.minerCount = 0;
						float num28 = data.QueryHeight(vein.pos);
						data.EraseVegetableAtPoint(vein.pos);
						vein.pos = vein.pos.normalized * num28;
						if (planet.waterItemId == 0 || !(num28 < planet.radius))
						{
							planet.veinAmounts[(uint)eVeinType2] += vein.amount;
							planet.veinGroups[num18].count++;
							planet.veinGroups[num18].amount += vein.amount;
							data.AddVeinData(vein);
						}
					}
				}
				tmp_vecs.Clear();
			}
		}
Пример #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);
    }
Пример #6
0
    //public abstract void GenerateTerrain(double modX, double modY);

    //public abstract void GenerateVegetables();

    //public virtual void CalcWaterPercent()
    //{
    //    if (this.planet.type == EPlanetType.Gas)
    //        this.planet.windStrength = 0.0f;
    //    PlanetAlgorithm.CalcLandPercent(this.planet);
    //}

    public virtual void GenerateVeins(bool sketchOnly)
    {
        //lock ((object)this.planet)
        //{
        ThemeProtoSet themes     = ThemeWorks.GetThemes();
        var           themeProto = themes.dataArray[this.planet.theme - 1];

        if (themeProto == null)
        {
            return;
        }
        Random random1 = new Random(this.planet.seed);

        random1.Next();
        random1.Next();
        random1.Next();
        random1.Next();
        int    _birthSeed = random1.Next();
        Random random2    = new Random(random1.Next());
        //PlanetRawData data = this.planet.data;
        float num1      = 2.1f / this.planet.radius;
        int   VeinCount = 15;

        //VeinProto[] veinProtos = PlanetModelingManager.veinProtos;
        //int[] veinModelIndexs = PlanetModelingManager.veinModelIndexs;
        //int[] veinModelCounts = PlanetModelingManager.veinModelCounts;
        //int[] veinProducts = PlanetModelingManager.veinProducts;
        int[]   numArray1 = new int[VeinCount];
        float[] numArray2 = new float[VeinCount];
        float[] numArray3 = new float[VeinCount];
        if (themeProto.VeinSpot != null)
        {
            Array.Copy((Array)themeProto.VeinSpot, 0, (Array)numArray1, 1, Math.Min(themeProto.VeinSpot.Length, numArray1.Length - 1));
        }
        if (themeProto.VeinCount != null)
        {
            Array.Copy((Array)themeProto.VeinCount, 0, (Array)numArray2, 1, Math.Min(themeProto.VeinCount.Length, numArray2.Length - 1));
        }
        if (themeProto.VeinOpacity != null)
        {
            Array.Copy((Array)themeProto.VeinOpacity, 0, (Array)numArray3, 1, Math.Min(themeProto.VeinOpacity.Length, numArray3.Length - 1));
        }
        float       p      = 1f;
        ESpectrType spectr = this.planet.star.spectr;

        switch (this.planet.star.type)
        {
        case EStarType.MainSeqStar:
            switch (spectr)
            {
            case ESpectrType.M:
                p = 2.5f;
                break;

            case ESpectrType.K:
                p = 1f;
                break;

            case ESpectrType.G:
                p = 0.7f;
                break;

            case ESpectrType.F:
                p = 0.6f;
                break;

            case ESpectrType.A:
                p = 1f;
                break;

            case ESpectrType.B:
                p = 0.4f;
                break;

            case ESpectrType.O:
                p = 1.6f;
                break;
            }
            break;

        case EStarType.GiantStar:
            p = 2.5f;
            break;

        case EStarType.WhiteDwarf:
            p = 3.5f;
            ++numArray1[9];
            ++numArray1[9];
            for (int index = 1; index < 12 && random1.NextDouble() < 0.449999988079071; ++index)
            {
                ++numArray1[9];
            }
            numArray2[9] = 0.7f;
            numArray3[9] = 1f;
            ++numArray1[10];
            ++numArray1[10];
            for (int index = 1; index < 12 && random1.NextDouble() < 0.449999988079071; ++index)
            {
                ++numArray1[10];
            }
            numArray2[10] = 0.7f;
            numArray3[10] = 1f;
            ++numArray1[12];
            for (int index = 1; index < 12 && random1.NextDouble() < 0.5; ++index)
            {
                ++numArray1[12];
            }
            numArray2[12] = 0.7f;
            numArray3[12] = 0.3f;
            break;

        case EStarType.NeutronStar:
            p = 4.5f;
            ++numArray1[14];
            for (int index = 1; index < 12 && random1.NextDouble() < 0.649999976158142; ++index)
            {
                ++numArray1[14];
            }
            numArray2[14] = 0.7f;
            numArray3[14] = 0.3f;
            break;

        case EStarType.BlackHole:
            p = 5f;
            ++numArray1[14];
            for (int index = 1; index < 12 && random1.NextDouble() < 0.649999976158142; ++index)
            {
                ++numArray1[14];
            }
            numArray2[14] = 0.7f;
            numArray3[14] = 0.3f;
            break;
        }
        for (int index1 = 0; index1 < themeProto.RareVeins.Length; ++index1)
        {
            int   rareVein     = themeProto.RareVeins[index1];
            float num2         = this.planet.star.index != 0 ? themeProto.RareSettings[index1 * 4 + 1] : themeProto.RareSettings[index1 * 4];
            float rareSetting1 = themeProto.RareSettings[index1 * 4 + 2];
            float rareSetting2 = themeProto.RareSettings[index1 * 4 + 3];
            float num3         = rareSetting2;
            float num4         = 1f - Mathf.Pow(1f - num2, p);
            float num5         = 1f - Mathf.Pow(1f - rareSetting2, p);
            float num6         = 1f - Mathf.Pow(1f - num3, p);
            if (random1.NextDouble() < (double)num4)
            {
                ++numArray1[rareVein];
                numArray2[rareVein] = num5;
                numArray3[rareVein] = num5;
                for (int index2 = 1; index2 < 12 && random1.NextDouble() < (double)rareSetting1; ++index2)
                {
                    ++numArray1[rareVein];
                }
            }
        }
        bool flag1 = this.planet.galaxy.birthPlanetId == this.planet.id;
        //if (flag1 && !sketchOnly)
        //    this.planet.GenBirthPoints(data, _birthSeed);
        float resourceCoef = this.planet.star.resourceCoef;

        //
        //bool flag2 = (double)DSPGame.GameDesc.resourceMultiplier >= 99.5;
        if (flag1)
        {
            resourceCoef *= 0.6666667f;
        }
        //float num7 = 1f * 1.1f;
        Array.Clear((Array)this.veinVectors, 0, this.veinVectors.Length);
        Array.Clear((Array)this.veinVectorTypes, 0, this.veinVectorTypes.Length);
        //this.veinVectorCount = 0;
        Vector3 vector3_1;

        if (flag1)
        {
            vector3_1 = this.planet.birthPoint;
            vector3_1.Normalize();
            vector3_1 *= 0.75f;
        }
        else
        {
            Vector3 vector3_2;
            vector3_2.x = (float)(random2.NextDouble() * 2.0 - 1.0);
            vector3_2.y = (float)random2.NextDouble() - 0.5f;
            vector3_2.z = (float)(random2.NextDouble() * 2.0 - 1.0);
            vector3_2.Normalize();
            vector3_1 = vector3_2 * (float)(random2.NextDouble() * 0.4 + 0.2);
        }
        this.planet.veinSpotsSketch = numArray1;
        if (sketchOnly)
        {
            return;
        }



        //if (flag1)
        //{
        //    this.veinVectorTypes[0] = EVeinType.Iron;
        //    this.veinVectors[0] = this.planet.birthResourcePoint0;
        //    this.veinVectorTypes[1] = EVeinType.Copper;
        //    this.veinVectors[1] = this.planet.birthResourcePoint1;
        //    this.veinVectorCount = 2;
        //}
        //for (int index1 = 1; index1 < 15 && this.veinVectorCount < this.veinVectors.Length; ++index1)
        //{
        //    EVeinType eveinType = (EVeinType)index1;
        //    int num2 = numArray1[index1];
        //    if (num2 > 1)
        //        num2 += random2.Next(-1, 2);
        //    for (int index2 = 0; index2 < num2; ++index2)
        //    {
        //        int num3 = 0;
        //        Vector3 zero = Vector3.zero;
        //        bool flag3 = false;
        //        while (num3++ < 200)
        //        {
        //            zero.x = (float)(random2.NextDouble() * 2.0 - 1.0);
        //            zero.y = (float)(random2.NextDouble() * 2.0 - 1.0);
        //            zero.z = (float)(random2.NextDouble() * 2.0 - 1.0);
        //            if (eveinType != EVeinType.Oil)
        //                zero += vector3_1;
        //            zero.Normalize();
        //            float num4 = data.QueryHeight(zero);
        //            if ((double)num4 >= (double)this.planet.radius && (eveinType != EVeinType.Oil || (double)num4 >= (double)this.planet.radius + 0.5))
        //            {
        //                bool flag4 = false;
        //                float num5 = eveinType != EVeinType.Oil ? 196f : 100f;
        //                for (int index3 = 0; index3 < this.veinVectorCount; ++index3)
        //                {
        //                    if ((double)(this.veinVectors[index3] - zero).sqrMagnitude < (double)num1 * (double)num1 * (double)num5)
        //                    {
        //                        flag4 = true;
        //                        break;
        //                    }
        //                }
        //                if (!flag4)
        //                {
        //                    flag3 = true;
        //                    break;
        //                }
        //            }
        //        }
        //        if (flag3)
        //        {
        //            this.veinVectors[this.veinVectorCount] = zero;
        //            this.veinVectorTypes[this.veinVectorCount] = eveinType;
        //            ++this.veinVectorCount;
        //            if (this.veinVectorCount == this.veinVectors.Length)
        //                break;
        //        }
        //    }
        //}
        //Array.Clear((Array)this.planet.veinAmounts, 0, this.planet.veinAmounts.Length);
        //data.veinCursor = 1;
        //this.planet.veinGroups = new PlanetData.VeinGroup[this.veinVectorCount];
        //this.tmp_vecs.Clear();
        //VeinData vein = new VeinData();
        //for (int index1 = 0; index1 < this.veinVectorCount; ++index1)
        //{
        //    this.tmp_vecs.Clear();
        //    Vector3 normalized = this.veinVectors[index1].normalized;
        //    EVeinType veinVectorType = this.veinVectorTypes[index1];
        //    int index2 = (int)veinVectorType;
        //    Quaternion rotation = Quaternion.FromToRotation(Vector3.up, normalized);
        //    Vector3 vector3_2 = rotation * Vector3.right;
        //    Vector3 vector3_3 = rotation * Vector3.forward;
        //    this.planet.veinGroups[index1].type = veinVectorType;
        //    this.planet.veinGroups[index1].pos = normalized;
        //    this.planet.veinGroups[index1].count = 0;
        //    this.planet.veinGroups[index1].amount = 0L;
        //    this.tmp_vecs.Add(Vector2.zero);
        //    int num2 = Mathf.RoundToInt(numArray2[index2] * (float)random2.Next(20, 25));
        //    if (veinVectorType == EVeinType.Oil)
        //        num2 = 1;
        //    float num3 = numArray3[index2];
        //    if (flag1 && index1 < 2)
        //    {
        //        num2 = 6;
        //        num3 = 0.2f;
        //    }
        //    int num4 = 0;
        //    while (num4++ < 20)
        //    {
        //        int count = this.tmp_vecs.Count;
        //        for (int index3 = 0; index3 < count && this.tmp_vecs.Count < num2; ++index3)
        //        {
        //            if ((double)this.tmp_vecs[index3].sqrMagnitude <= 36.0)
        //            {
        //                double num5 = random2.NextDouble() * Math.PI * 2.0;
        //                Vector2 vector2_1 = new Vector2((float)Math.Cos(num5), (float)Math.Sin(num5));
        //                vector2_1 += this.tmp_vecs[index3] * 0.2f;
        //                vector2_1.Normalize();
        //                Vector2 vector2_2 = this.tmp_vecs[index3] + vector2_1;
        //                bool flag3 = false;
        //                for (int index4 = 0; index4 < this.tmp_vecs.Count; ++index4)
        //                {
        //                    if ((double)(this.tmp_vecs[index4] - vector2_2).sqrMagnitude < 0.850000023841858)
        //                    {
        //                        flag3 = true;
        //                        break;
        //                    }
        //                }
        //                if (!flag3)
        //                    this.tmp_vecs.Add(vector2_2);
        //            }
        //        }
        //        if (this.tmp_vecs.Count >= num2)
        //            break;
        //    }
        //    int num6 = Mathf.RoundToInt(num3 * 100000f * resourceCoef);
        //    if (num6 < 20)
        //        num6 = 20;
        //    int num8 = num6 >= 16000 ? 15000 : Mathf.FloorToInt((float)num6 * (15f / 16f));
        //    int minValue = num6 - num8;
        //    int maxValue = num6 + num8 + 1;
        //    for (int index3 = 0; index3 < this.tmp_vecs.Count; ++index3)
        //    {
        //        Vector3 vector3_4 = (this.tmp_vecs[index3].x * vector3_2 + this.tmp_vecs[index3].y * vector3_3) * num1;
        //        vein.type = veinVectorType;
        //        vein.groupIndex = (short)index1;
        //        vein.modelIndex = (short)random2.Next(veinModelIndexs[index2], veinModelIndexs[index2] + veinModelCounts[index2]);
        //        vein.amount = Mathf.RoundToInt((float)random2.Next(minValue, maxValue) * num7);
        //        if (this.planet.veinGroups[index1].type != EVeinType.Oil)
        //            vein.amount = Mathf.RoundToInt((float)vein.amount * DSPGame.GameDesc.resourceMultiplier);
        //        if (vein.amount < 1)
        //            vein.amount = 1;
        //        if (flag2 && vein.type != EVeinType.Oil)
        //            vein.amount = 1000000000;
        //        vein.productId = veinProducts[index2];
        //        vein.pos = normalized + vector3_4;
        //        if (vein.type == EVeinType.Oil)
        //            vein.pos = this.planet.aux.RawSnap(vein.pos);
        //        vein.minerCount = 0;
        //        float num5 = data.QueryHeight(vein.pos);
        //        data.EraseVegetableAtPoint(vein.pos);
        //        vein.pos = vein.pos.normalized * num5;
        //        if (this.planet.waterItemId == 0 || (double)num5 >= (double)this.planet.radius)
        //        {
        //            this.planet.veinAmounts[(int)veinVectorType] += (long)vein.amount;
        //            ++this.planet.veinGroups[index1].count;
        //            this.planet.veinGroups[index1].amount += (long)vein.amount;
        //            data.AddVeinData(vein);
        //        }
        //    }
        //}
        this.tmp_vecs.Clear();
        //}
    }
 public static void CreateStar(ref GalaxyData galaxy, ref VectorLF3 pos, ref int id, int seed, ref EStarType needtype, ref ESpectrType needSpectr, ref StarData __result)
 {
     //Console.WriteLine($"CreateStar() id: {__result.id}\r\n\tage: {__result.age}\r\n\tclassFactor: {__result.classFactor}\r\n\tcolor: {__result.color}\r\n\tluminosity: {__result.luminosity}\r\n\tradius: {__result.radius}\r\n\ttemperature: {__result.temperature}\r\n\tspectr: {__result.spectr}\r\n\tlifetime: {__result.lifetime}\r\n\tlightBalanceRaddius: {__result.lightBalanceRadius}\r\n\ttype: {__result.type}");
 }
Пример #8
0
        // Move planets at runtime. This is the safest way (for your save files) to modify the planets, but also the buggiest.
        static void CreateGalaxy(ref GameDesc gameDesc, ref GalaxyData __result)
        {
            GalaxyDataHelper.RepairBirthIds(ref __result);

            // Seed rng from galaxy seed for deterministic randomness
            int seed = gameDesc.galaxySeed;

            seededRandom      = new Random(gameDesc.galaxySeed);
            arrangementString = null;

            GalaxyData        galaxy       = __result;
            List <PlanetData> gasPlanets   = new List <PlanetData>();
            List <PlanetData> otherPlanets = new List <PlanetData>();
            List <PlanetData> moons        = new List <PlanetData>();
            List <PlanetData> newMoons     = new List <PlanetData>();
            PlanetData        birthPlanet  = null;
            int  birthPlanetId             = __result.birthPlanetId;
            bool tooManyPlanets            = false;
            bool peacockSystem             = false;

            // Find starting system
            for (int i = 0; i < __result.stars.Length; i++)
            {
                StarData star = __result.stars[i];
                // If starting star
                if (star.index == 0)
                {
                    GSCompatPatch(ref star);

                    if (AlternativeStartPlugin.zDebuggingMode)
                    {
                        StarDataHelper.LogStarPlanetInfo(star);
                    }
                    // Edit the starting star
                    float       newLevel   = seededRandom.Next(15, 500) / 1000f;
                    EStarType   needtype   = EStarType.MainSeqStar;
                    ESpectrType needSpectr = ESpectrType.G;
                    if (gameDesc.galaxySeed == 16161616)
                    {
                        Debug.LogWarning($"Using anomaly seed {gameDesc.galaxySeed}");
                        newLevel   = 1f;
                        needtype   = EStarType.BlackHole;
                        needSpectr = ESpectrType.X;
                    }
                    else if (gameDesc.galaxySeed == 00000000)
                    {
                        Debug.LogWarning($"Using anomaly seed {gameDesc.galaxySeed}");
                        needSpectr = ESpectrType.O;
                    }
                    else if (newLevel < 0.03f)
                    {
                        needtype   = EStarType.GiantStar;
                        needSpectr = ESpectrType.M;
                    }
                    ModifyStar(ref star, newLevel, needtype, needSpectr);
                    arrangementString += $"{(int)star.type}{star.spectr.ToString()[0]}";
                    StartModification(ref star);
                    FinalizeModification(ref star);
                    // Log new system configuration
                    if (AlternativeStartPlugin.zDebuggingMode)
                    {
                        StarDataHelper.LogStarPlanetInfo(star);
                    }
                }
            }

            void GSCompatPatch(ref StarData star)
            {
                int oceans = 0;

                for (int i = 0; i < star.planets.Length; i++)
                {
                    PlanetData planet = star.planets[i];
                    if (planet.type == EPlanetType.Ocean)
                    {
                        oceans++;
                    }
                }
                if (oceans < 1)
                {
                    Debug.LogWarning($"Invalid starting system detected. Attempting to correct...");

                    // Look for a gas giant moon to turn into an ocean
                    for (int i = 0; i < star.planets.Length; i++)
                    {
                        PlanetData planet = star.planets[i];
                        if (planet.orbitAroundPlanet != null && planet.orbitAroundPlanet.type == EPlanetType.Gas)
                        {
                            Random seededRandom2 = new Random(seed);
                            PatchPlanetGen.ChangePlanetTheme(ref planet, 8, seededRandom2.NextDouble(), seededRandom2.NextDouble(), seededRandom2.NextDouble());
                            Debug.LogWarning($"Invalid starting system corrected.");
                            return;
                        }
                    }

                    // Turn any non-gas planet into an ocean
                    for (int i = star.planets.Length; i > 0; i--)
                    {
                        PlanetData planet = star.planets[i];
                        if (planet.type != EPlanetType.Gas)
                        {
                            Random seededRandom2 = new Random(seed);
                            PatchPlanetGen.ChangePlanetTheme(ref planet, 8, seededRandom2.NextDouble(), seededRandom2.NextDouble(), seededRandom2.NextDouble());
                            Debug.LogWarning($"Invalid starting system corrected.");
                            return;
                        }
                    }

                    Debug.LogError($"Failed to correct invalid starting system.");
                }
            }

            void ModifyStar(ref StarData star, float newLevel, EStarType needtype, ESpectrType needSpectr)
            {
                Debug.Log($"Started modifying birth star to level {newLevel}f");

                // Possibly allow starting systems to be a giant M-class?

                star.spectr = needSpectr;

                double num3 = seededRandom.NextDouble();
                double num4 = seededRandom.NextDouble();
                double numStarAgeRandomizer = seededRandom.NextDouble();
                double num6 = (seededRandom.NextDouble() - 0.5) * 0.2;
                double num7 = seededRandom.NextDouble() * 0.2 + 0.9;
                double num8 = seededRandom.NextDouble() * 0.4 - 0.2;
                double num9 = Math.Pow(2.0, num8);
                // modification to allow better class stars
                float num10 = Mathf.Lerp(-0.98f, 0.88f, newLevel);

                num10 = ((!(num10 < 0f)) ? (num10 + 0.65f) : (num10 - 0.65f));
                float standardDeviation = 0.33f;
                float num11             = StarGen.RandNormal(num10, standardDeviation, num3, num4);

                switch (needSpectr)
                {
                case ESpectrType.M:
                    num11 = -3f;
                    break;

                case ESpectrType.O:
                    num11 = 3f;
                    break;
                }

                num11 = ((!(num11 > 0f)) ? (num11 * 1f) : (num11 * 2f));
                num11 = Mathf.Clamp(num11, -2.4f, 4.65f) + (float)num6 + 1f;

                star.mass = Mathf.Pow(2f, num11);

                double d = 5.0;

                if (star.mass < 2f)
                {
                    d = 2.0 + 0.4 * (1.0 - (double)star.mass);
                }
                star.lifetime = (float)(10000.0 * Math.Pow(0.1, Math.Log10((double)star.mass * 0.5) / Math.Log10(d) + 1.0) * num7);


                switch (needtype)
                {
                case EStarType.BlackHole:
                    star.mass = 18f + (float)(num3 * num4) * 30f;
                    break;

                case EStarType.GiantStar:
                    star.lifetime = (float)(10000.0 * Math.Pow(0.1, Math.Log10((double)star.mass * 0.58) / Math.Log10(d) + 1.0) * num7);
                    star.age      = (float)numStarAgeRandomizer * 0.04f + 0.96f;
                    break;

                default:
                    if ((double)star.mass < 0.5)
                    {
                        star.age = (float)numStarAgeRandomizer * 0.12f + 0.02f;
                    }
                    else if ((double)star.mass < 0.8)
                    {
                        star.age = (float)numStarAgeRandomizer * 0.4f + 0.1f;
                    }
                    else
                    {
                        star.age = (float)numStarAgeRandomizer * 0.7f + 0.2f;
                    }
                    break;
                }

                if (needtype == EStarType.BlackHole)
                {
                    star.age = (float)numStarAgeRandomizer * 0.4f + 1f;
                }

                float num12 = star.lifetime * star.age;

                if (num12 > 5000f)
                {
                    num12 = (Mathf.Log(num12 / 5000f) + 1f) * 5000f;
                }
                if (num12 > 8000f)
                {
                    float f = num12 / 8000f;
                    f     = Mathf.Log(f) + 1f;
                    f     = Mathf.Log(f) + 1f;
                    f     = Mathf.Log(f) + 1f;
                    num12 = f * 8000f;
                }
                star.lifetime = num12 / star.age;
                float num13 = (1f - Mathf.Pow(Mathf.Clamp01(star.age), 20f) * 0.5f) * star.mass;

                star.temperature = (float)(Math.Pow(num13, 0.56 + 0.14 / (Math.Log10(num13 + 4f) / Math.Log10(5.0))) * 4450.0 + 1300.0);
                double num14 = Math.Log10(((double)star.temperature - 1300.0) / 4500.0) / Math.Log10(2.6) - 0.5;

                if (num14 < 0.0)
                {
                    num14 *= 4.0;
                }
                if (num14 > 2.0)
                {
                    num14 = 2.0;
                }
                else if (num14 < -4.0)
                {
                    num14 = -4.0;
                }
                star.spectr       = (ESpectrType)Mathf.RoundToInt((float)num14 + 4f);
                star.color        = Mathf.Clamp01(((float)num14 + 3.5f) * 0.2f);
                star.classFactor  = (float)num14;
                star.luminosity   = Mathf.Pow(num13, 0.7f);
                star.radius       = (float)(Math.Pow(star.mass, 0.4) * num9);
                star.acdiskRadius = 0f;
                float p = (float)num14 + 2f;

                star.habitableRadius    = Mathf.Pow(1.7f, p) + 0.25f * Mathf.Min(1f, star.orbitScaler);
                star.lightBalanceRadius = Mathf.Pow(1.7f, p);
                star.orbitScaler        = Mathf.Pow(1.35f, p);
                if (star.orbitScaler < 1f)
                {
                    star.orbitScaler = Mathf.Lerp(star.orbitScaler, 1f, 0.6f);
                }

                double rn = seededRandom.NextDouble();
                double rt = seededRandom.NextDouble();

                StarGen.SetStarAge(star, star.age, rn, rt);

                star.dysonRadius = star.orbitScaler * 0.28f;
                if ((double)star.dysonRadius * 40000.0 < (double)(star.physicsRadius * 1.5f))
                {
                    star.dysonRadius = (float)((double)(star.physicsRadius * 1.5f) / 40000.0);
                }
                star.uPosition = star.position * 2400000.0;

                Debug.Log($"Finished modifying birth star. Now a {star.spectr} class {star.type}...");
            }

            void StartModification(ref StarData star)
            {
                for (int j = 0; j < star.planets.Length; j++)
                {
                    PlanetData planet = star.planets[j];
                    // Sort planets into lists
                    if (birthPlanetId == planet.id)
                    {
                        birthPlanet = planet;
                        continue;
                    }
                    else if (planet.type == EPlanetType.Gas)
                    {
                        gasPlanets.Add(planet);
                        continue;
                    }
                    else if (planet.orbitAroundPlanet != null)
                    {
                        moons.Add(planet);
                        continue;
                    }
                    else
                    {
                        otherPlanets.Add(planet);
                    }
                }


                // Additional checks for modded games, and extremly rare starting system configurations.
                if (birthPlanet == null)
                {
                    Debug.LogError("alternatestart -- Failed to find birth planet");
                    return;
                }
                if (otherPlanets.Count() + moons.Count() > 2)
                {
                    tooManyPlanets = true;
                    Debug.LogWarning("alternatestart -- Modded starting system detected");
                }
                if (otherPlanets.Count() == 0 && moons.Count() == 0)
                {
                    Debug.LogWarning("alternatestart -- Not enough planets to change starting system");
                    return;
                }
                if (otherPlanets.Count() == 0 && moons.Count() > 0)
                {
                    peacockSystem = true;
                    Debug.LogWarning("alternatestart -- Peacock system detected");
                    if (tooManyPlanets)
                    {
                        Debug.LogWarning("alternatestart -- System is very strange");
                        if (gasPlanets.Count() == 0)
                        {
                            Debug.LogError("alternatestart -- Not possible to modify starting system. No other planets except birth planet.");
                            return;
                        }

                        return;
                    }
                }

                // Prior run detection;
                if (birthPlanet.orbitAroundPlanet == null)
                {
                    Debug.LogWarning("alternatestart -- System was already modified?");
                    return;
                }

                Debug.Log("alternatestart -- Started system modification");
                if (peacockSystem)
                {
                    MoveSystemPeacock();
                }
                else
                {
                    MoveSystemNormal();
                }
            }

            void FinalizeModification(ref StarData star)
            {
                for (int i = 0; i < gasPlanets.Count(); i++)
                {
                    PlanetData gasPlanet = gasPlanets[i];
                    RevokeSingularities(ref gasPlanet);
                }
                if (newMoons.Count > 1)
                {
                    // The starting planet having multiple moons and horizontal rotation is rare and might be cool.

                    //birthPlanet.singularity = EPlanetSingularity.MultipleSatellites;
                    //Debug.Log($"alternatestart -- Added plural satellites singularity to planet {birthPlanet.id}");
                }

                int skip = 1;
                int step = 1;

                switch (star.type)
                {
                case EStarType.GiantStar:
                    skip += 7;
                    break;

                default:
                    switch (star.spectr)
                    {
                    case ESpectrType.M:
                    case ESpectrType.K:
                        break;

                    case ESpectrType.G:
                    case ESpectrType.F:
                        skip = 2;
                        break;

                    case ESpectrType.A:
                        skip = 2;
                        step = 2;
                        break;

                    case ESpectrType.B:
                        skip = 3;
                        step = 2;
                        break;

                    case ESpectrType.O:
                        skip = 8;
                        break;

                    case ESpectrType.X:
                        skip = 4;
                        step = 2;
                        break;
                    }
                    break;
                }


                PlanetDataHelper.ReIndexPlanets(ref star, skip, step);
                PlanetDataHelper.ReOrbitPlanets(ref star, seededRandom);

                if (star.type == EStarType.BlackHole)
                {
                    star.planets.Select(x => x.luminosity *= 0.66f);
                }
            }

            void MoveSystemPeacock()
            {
                birthPlanet.orbitRadius       = 0.6f;
                birthPlanet.orbitInclination *= 1.2f;
                birthPlanet.orbitAroundPlanet = null;
                birthPlanet.orbitAround       = 0;
                birthPlanet.orbitIndex        = 1;

                for (int i = 0; i < moons.Count(); i++)
                {
                    PlanetData moon = moons[i];
                    PlanetDataHelper.StealMoon(ref birthPlanet, ref moon);
                    newMoons.Add(moon);
                    if (newMoons.Count() >= 2)
                    {
                        Debug.Log("alternatestart -- Birth planet has maximum allowed moons");
                        break;
                    }
                }

                Debug.LogWarning($"alternatestart -- New System arrangement is peacock");
            }

            void MoveSystemNormal()
            {
                double     num     = seededRandom.NextDouble();
                double     num2    = seededRandom.NextDouble();
                double     num3    = seededRandom.NextDouble();
                PlanetData lowest  = otherPlanets.OrderBy(x => x.orbitRadius).First();
                PlanetData highest = otherPlanets.OrderBy(x => x.orbitRadius).Last();

                // How should the system be arranged?
                if (num > 0.8f)
                {
                    arrangementString += 'C';
                    PlanetDataHelper.SwapPlanets(ref highest, ref birthPlanet);
                }
                else if (num > 0.6f)
                {
                    arrangementString += 'B';
                    PlanetDataHelper.SwapPlanets(ref lowest, ref birthPlanet);
                }
                else
                {
                    if (gasPlanets.Count() > 0)
                    {
                        arrangementString += 'A';
                        PlanetData gasPlanet = gasPlanets[0];
                        PlanetDataHelper.SwapPlanets(ref lowest, ref birthPlanet);
                        PlanetDataHelper.SwapPlanets(ref gasPlanet, ref birthPlanet);
                    }
                    else
                    {
                        PlanetDataHelper.SwapPlanets(ref lowest, ref birthPlanet);
                        arrangementString += 'D';
                    }
                }
                if (num2 > 0.30d)
                {
                    arrangementString += 'A';
                    PlanetDataHelper.StealMoon(ref birthPlanet, ref lowest);
                    newMoons.Add(lowest);
                    for (int i = 0; i < moons.Count(); i++)
                    {
                        PlanetData moon = moons[i];
                        if (moon.orbitAround != birthPlanet.id && !newMoons.Contains(moon))
                        {
                            PlanetDataHelper.StealMoon(ref birthPlanet, ref moon);
                            newMoons.Add(moon);
                            if (newMoons.Count() >= 2)
                            {
                                Debug.Log("alternatestart -- Birth planet has maximum allowed moons");
                                break;
                            }
                        }
                    }
                }
                else
                {
                    arrangementString += 'B';
                }

                // Orphan a gas giant moon?
                if (num3 > 0.6d)
                {
                    bool demooned = false;
                    for (int i = 0; i < birthPlanet.star.planets.Length; i++)
                    {
                        PlanetData moon = birthPlanet.star.planets[i];
                        if (moon.orbitAround != 0 && moon.orbitalPeriod != birthPlanet.id)
                        {
                            moon.orbitRadius       = moon.orbitAroundPlanet.orbitRadius * 1.2f;
                            moon.orbitAroundPlanet = null;
                            moon.orbitAround       = 0;
                            demooned           = true;
                            arrangementString += 'A';
                            break;
                        }
                    }
                    if (!demooned)
                    {
                        arrangementString += 'B';
                    }
                }
                else
                {
                    arrangementString += 'B';
                }

                Debug.LogWarning($"alternatestart -- New System arrangement is {arrangementString}");
            }

            // Remove any dangling multiple moon singularities from gas giants that no longer deserve them
            void RevokeSingularities(ref PlanetData targetPlanet)
            {
                int moonCount = 0;

                for (int i = 0; i < targetPlanet.star.planets.Count(); i++)
                {
                    PlanetData planet = targetPlanet.star.planets[i];
                    if (planet.orbitAround == targetPlanet.id)
                    {
                        if (moonCount++ > 1)
                        {
                            return;
                        }
                    }
                }
                if (targetPlanet.singularity == EPlanetSingularity.MultipleSatellites)
                {
                    Debug.Log($"alternatestart -- Removed plural satellites singularity from planet {targetPlanet.id}");
                    targetPlanet.singularity = EPlanetSingularity.None;
                }
            }
        }
        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);
        }
Пример #10
0
    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);
    }