public static bool GetModPlane(int index, ref PlanetRawData __instance, ref short __result)
        {
            Patch.Debug("scaleFactor " + __instance.GetFactoredScale(), LogLevel.Debug,
                        Patch.DebugGetModPlane);

            Patch.Debug("index " + index, LogLevel.Debug,
                        Patch.DebugGetModPlane);

            Patch.Debug("__instance.modData.Length " + __instance.modData.Length, LogLevel.Debug,
                        Patch.DebugGetModPlane);

            Patch.Debug(
                "test " + ((__instance.modData[index >> 1] >> (((index & 1) << 2) + 2)) & 3) * 133, LogLevel.Debug,
                Patch.DebugGetModPlane);

            float baseHeight = 20;

            baseHeight += __instance.GetFactoredScale() * 200 * 100;

            Patch.Debug("baseHeight " + baseHeight, LogLevel.Debug,
                        Patch.DebugGetModPlane);
            __result = (short)(((__instance.modData[index >> 1] >> (((index & 1) << 2) + 2)) & 3) * 133 +
                               baseHeight);

            Patch.Debug("GetModPlane __result " + __result, LogLevel.Debug,
                        Patch.DebugGetModPlane);

            return(false);
        }
        public static int GetModPlaneInt(this PlanetRawData planetRawData, int index)
        {
            float baseHeight = 20;

            baseHeight += planetRawData.GetFactoredScale() * 200 * 100;

            return((int)(((planetRawData.modData[index >> 1] >> (((index & 1) << 2) + 2)) & 3) * 133 + baseHeight));
        }
Beispiel #3
0
        public static int ComputeFlattenTerrainReform(PlanetFactory factory, List <Vector3> points, Vector3 center, float fade0 = 3f)
        {
            PlanetRawData data = factory.planet.data;

            tmpLevelChanges.Clear();

            float realRadius = factory.planet.realRadius;

            ushort[] heightData = data.heightData;

            float heightDiff = (heightData[data.QueryIndex(center)] - factory.planet.realRadius * 100f + 20f) * 0.01f * 2f;

            heightDiff = Mathf.Min(9f, Mathf.Abs(heightDiff));
            fade0     += heightDiff;
            float steps  = realRadius * 3.1415927f / (factory.planet.precision * 2f);
            int   extent = Mathf.CeilToInt(fade0 * 1.414f / steps * 1.5f + 0.5f);

            int cost = 0;

            foreach (Vector3 vpos in points)
            {
                float longitude     = BlueprintUtils.GetLongitudeRad(vpos.normalized);
                float longCount     = 2 * longitude / Mathf.PI;
                float angleDistance = Mathf.Abs(longCount - Mathf.Round(longCount));

                if (angleDistance <= 0.04)
                {
                    cost += ScanTerrainDetailed(data, realRadius, vpos, extent, fade0);
                }
                else
                {
                    cost += ScanTerrain(data, realRadius, vpos, extent, fade0);
                }
            }

            return(cost);
        }
 public static void AddFactoredRadius(this PlanetRawData planetRawData, PlanetData planet)
 {
     FactoredRadius[planetRawData] = planet.GetScaleFactored();
 }
 public static float GetFactoredScale(this PlanetRawData planetRawData)
 {
     return(FactoredRadius.TryGetValue(planetRawData, out var result) ? result : 1f);
 }
Beispiel #6
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();
			}
		}
Beispiel #7
0
 public static bool GenBirthPoints(PlanetRawData rawData, int _birthSeed)
 {
     return(true);
 }
        public static void FlattenTerrainReformALT(this PlanetFactory planetFactory, Vector3 center, float radius, int reformSize, bool veinBuried, float localRadius, float realRadius, float fade0 = 3f)
        {
            if (planetFactory.tmp_ids == null)
            {
                planetFactory.tmp_ids = new int[1024];
            }
            if (planetFactory.tmp_entity_ids == null)
            {
                planetFactory.tmp_entity_ids = new int[1024];
            }
            Array.Clear(planetFactory.tmp_ids, 0, planetFactory.tmp_ids.Length);
            Array.Clear(planetFactory.tmp_entity_ids, 0, planetFactory.tmp_entity_ids.Length);
            Vector3       zero = Vector3.zero;
            PlanetRawData data = planetFactory.planet.data;

            ushort[] heightData = data.heightData;
            float    f          = ((float)(int)heightData[data.QueryIndex(center)] - realRadius * 100f + 20f) * 0.01f * 2f;

            //f = Mathf.Min(9f, Mathf.Abs(f));
            f      = Mathf.Min(5f, Mathf.Abs(f));
            fade0 += f;
            float areaRadius = radius + fade0;
            short num        = (short)(realRadius * 100f + 20f);
            bool  levelized  = planetFactory.planet.levelized;
            int   num2       = Mathf.RoundToInt((center.magnitude - 0.2f - realRadius) / 1.33333325f);
            int   num3       = num2 * 133 + num - 60;
            float num4       = localRadius * 100f - 20f;

            foreach (KeyValuePair <int, int> tmp_levelChange in planetFactory.tmp_levelChanges)
            {
                /*
                 * if (tmp_levelChange.Value <= 0)
                 * {
                 *  continue;
                 * }
                 */
                ushort num5 = heightData[tmp_levelChange.Key];
                if (levelized)
                {
                    if (num5 >= num3)
                    {
                        if (data.GetModLevel(tmp_levelChange.Key) < 3)
                        {
                            data.SetModPlane(tmp_levelChange.Key, num2);
                        }
                        planetFactory.planet.AddHeightMapModLevel(tmp_levelChange.Key, tmp_levelChange.Value);
                    }
                }
                else
                {
                    Debug.Log("AddHeightMapModLevel: " + tmp_levelChange.Key + ", " + tmp_levelChange.Value);
                    planetFactory.planet.AddHeightMapModLevelALT(tmp_levelChange.Key, tmp_levelChange.Value);
                }
                if ((float)(int)num5 < num4)
                {
                    planetFactory.planet.landPercentDirty = true;
                }
            }
            if (planetFactory.planet.UpdateDirtyMeshes())
            {
                planetFactory.RenderLocalPlanetHeightmap();
            }
            radius -= (float)reformSize * 0.15f;
            NearColliderLogic nearColliderLogic = planetFactory.planet.physics.nearColliderLogic;
            int   vegetablesInAreaNonAlloc      = nearColliderLogic.GetVegetablesInAreaNonAlloc(center, areaRadius, planetFactory.tmp_ids);
            float num6 = radius * radius;

            for (int i = 0; i < vegetablesInAreaNonAlloc; i++)
            {
                int num7 = planetFactory.tmp_ids[i];
                zero  = planetFactory.vegePool[num7].pos;
                zero -= center;
                if (zero.x * zero.x + zero.y * zero.y + zero.z * zero.z <= num6 + 2.2f)
                {
                    planetFactory.RemoveVegeWithComponents(num7);
                    continue;
                }
                float num8 = data.QueryModifiedHeight(planetFactory.vegePool[num7].pos) - 0.03f;
                planetFactory.vegePool[num7].pos = planetFactory.vegePool[num7].pos.normalized * num8;
                GameMain.gpuiManager.AlterModel(planetFactory.vegePool[num7].modelIndex, planetFactory.vegePool[num7].modelId, num7, planetFactory.vegePool[num7].pos, planetFactory.vegePool[num7].rot, setBuffer: false);
            }
            float num9 = 50f;

            vegetablesInAreaNonAlloc = ((!veinBuried) ? nearColliderLogic.GetVeinsInOceanInAreaNonAlloc(center, areaRadius, planetFactory.tmp_ids) : nearColliderLogic.GetVeinsInAreaNonAlloc(center, areaRadius, planetFactory.tmp_ids));
            for (int j = 0; j < vegetablesInAreaNonAlloc; j++)
            {
                int num10 = planetFactory.tmp_ids[j];
                zero = planetFactory.veinPool[num10].pos;
                float   num11  = realRadius + 0.2f;
                Vector3 vector = zero.normalized * num11 - center;
                if (!(vector.x * vector.x + vector.y * vector.y + vector.z * vector.z <= num6 + 2f))
                {
                    continue;
                }
                PlanetPhysics physics      = planetFactory.planet.physics;
                int           colliderId   = planetFactory.veinPool[num10].colliderId;
                ColliderData  colliderData = physics.GetColliderData(colliderId);
                if (veinBuried)
                {
                    num11 -= num9;
                }
                else
                {
                    Vector3 center2 = zero.normalized * num11;
                    int     entitiesInAreaWhenReformNonAlloc = nearColliderLogic.GetEntitiesInAreaWhenReformNonAlloc(center2, colliderData.radius, planetFactory.tmp_entity_ids);
                    if (entitiesInAreaWhenReformNonAlloc > 0)
                    {
                        num11 = zero.magnitude;
                    }
                }
                Vector3 pos   = colliderData.pos.normalized * num11;
                int     num12 = colliderId >> 20;
                colliderId &= 0xFFFFF;
                physics.colChunks[num12].colliderPool[colliderId].pos = pos;
                planetFactory.veinPool[num10].pos = zero.normalized * num11;
                physics.RefreshColliders();
                GameMain.gpuiManager.AlterModel(planetFactory.veinPool[num10].modelIndex, planetFactory.veinPool[num10].modelId, num10, planetFactory.veinPool[num10].pos, setBuffer: false);
            }
            planetFactory.tmp_levelChanges.Clear();
            Array.Clear(planetFactory.tmp_ids, 0, planetFactory.tmp_ids.Length);
            Array.Clear(planetFactory.tmp_ids, 0, planetFactory.tmp_entity_ids.Length);
            GameMain.gpuiManager.SyncAllGPUBuffer();
        }
        public static int ComputeFlattenTerrainReformALT(this PlanetFactory planetFactory, Vector3[] points, Vector3 center, float radius, int pointsCount, float realRadius,
                                                         float fade0 = 3f, float fade1 = 1f)
        {
            PlanetRawData data = planetFactory.planet.data;

            if (planetFactory.tmp_levelChanges == null)
            {
                planetFactory.tmp_levelChanges = new Dictionary <int, int>();
            }
            planetFactory.tmp_levelChanges.Clear();
            Quaternion quaternion = Maths.SphericalRotation(center, 22.5f);

            //float realRadius = planetFactory.planet.realRadius;
            Vector3[] vertices   = data.vertices;
            ushort[]  heightData = data.heightData;

            float f = ((float)(int)heightData[data.QueryIndex(center)] - realRadius * 100f + 20f) * 0.01f * 2f;

            Debug.Log("ComputeFlattenTerrainReformALT.heightData(center): " + heightData[data.QueryIndex(center)] + " , f: " + f);
            //f = Mathf.Min(9f, Mathf.Abs(f));
            f      = Mathf.Min(5f, Mathf.Abs(f));
            fade0 += f;
            float radiusFade = radius + fade0;
            float levelArea  = radiusFade * radiusFade;

            Debug.Log("ComputeFlattenTerrainReformALT.levelArea: " + levelArea + " , radius: " + radius + " , fade0: " + fade0);
            //  realRadius * (float)Math.PI / (200 * 2f);
            float num3 = realRadius * (float)Math.PI / ((float)planetFactory.planet.precision * 2f);
            int   num4 = Mathf.CeilToInt(radiusFade * 1.414f / num3 + 0.5f);

            Vector3[] array = new Vector3[9]
            {
                center,
                center + quaternion * (new Vector3(0f, 0f, 1.414f) * radiusFade),
                center + quaternion * (new Vector3(0f, 0f, -1.414f) * radiusFade),
                center + quaternion * (new Vector3(1.414f, 0f, 0f) * radiusFade),
                center + quaternion * (new Vector3(-1.414f, 0f, 0f) * radiusFade),
                center + quaternion * (new Vector3(1f, 0f, 1f) * radiusFade),
                center + quaternion * (new Vector3(-1f, 0f, -1f) * radiusFade),
                center + quaternion * (new Vector3(1f, 0f, -1f) * radiusFade),
                center + quaternion * (new Vector3(-1f, 0f, 1f) * radiusFade)
            };

            int   stride     = data.stride;
            int   dataLength = data.dataLength;
            float minHeight  = 6f;
            int   num6       = 0;

            Vector3[] array2  = array;
            Vector3   vector  = default(Vector3);
            Vector3   vector2 = default(Vector3);

            foreach (Vector3 vpos in array2)
            {
                int num7 = data.QueryIndex(vpos);
                for (int j = -num4; j <= num4; j++)
                {
                    int num8 = num7 + j * stride;
                    if (num8 < 0 || num8 >= dataLength)
                    {
                        continue;
                    }
                    for (int k = -num4; k <= num4; k++)
                    {
                        int num9 = num8 + k;
                        if ((uint)num9 >= dataLength)
                        {
                            continue;
                        }
                        vector.x  = vertices[num9].x * realRadius;
                        vector.y  = vertices[num9].y * realRadius;
                        vector.z  = vertices[num9].z * realRadius;
                        vector2.x = vector.x - center.x;
                        vector2.y = vector.y - center.y;
                        vector2.z = vector.z - center.z;

                        float squareSum = vector2.x * vector2.x + vector2.y * vector2.y + vector2.z * vector2.z;

                        if (squareSum > levelArea /*|| */)
                        {
                            continue;
                        }

                        float num10 = float.PositiveInfinity;
                        for (int l = 0; l < pointsCount; l++)
                        {
                            float num11 = points[l].x - vector.x;
                            float num12 = points[l].y - vector.y;
                            float num13 = points[l].z - vector.z;
                            float num14 = num11 * num11 + num12 * num12 + num13 * num13;
                            num10 = ((!(num10 < num14)) ? num14 : num10);
                        }
                        int num15 = 0;
                        int num16 = 0;
                        int num17 = 0;
                        num16 = data.GetModLevel(num9);


                        if (num10 <= minHeight)
                        {
                            num15 = 3;
                        }
                        else
                        {
                            num10 -= minHeight;
                            if (num10 > fade0 * fade0)
                            {
                                continue;
                            }

                            float num18 = num10 / (fade0 * fade0);

                            if (num18 <= 0.1111111f)
                            {
                                num15 = 2;
                            }
                            else if (num18 <= 0.4444444f)
                            {
                                num15 = 1;
                            }
                            else
                            {
                                if (!(num18 < 1f))
                                {
                                    continue;
                                }
                                num15 = 0;
                            }
                        }
                        num17 = num15 - num16;

                        Debug.Log("CompALT.loop.jk\tnum9: " + num9 + "\t, squareSum: " + squareSum + "\t, contains: " + planetFactory.tmp_levelChanges.ContainsKey(num9)
                                  + "\t, modLevel: " + data.GetModLevel(num9) + "\t, num15: " + num15 + "\t, num16: " + num16 + "\t, num17: " + num17);
                        if (/*num15 >= num16 &&*/ num17 != 0)
                        {
                            planetFactory.tmp_levelChanges[num9] = num15;
                            float num19 = (float)(int)heightData[num9] * 0.01f;
                            float num20 = realRadius + 0.2f;
                            float num21 = num20 - num19;
                            if (num21 < 0f)
                            {
                                num21 *= 2f;
                            }
                            float f2 = 100f * (float)num17 * num21 * 0.3333333f;
                            num6 += Mathf.FloorToInt(f2);
                        }
                    }
                }
            }
            return(num6);
        }
        public static bool QueryModifiedHeight(ref PlanetRawData __instance,
                                               ref float __result, Vector3 vpos)
        {
            Patch.Debug("QueryModifiedHeight ", LogLevel.Debug,
                        Patch.DebugPlanetRawData);
            vpos.Normalize();
            var index1          = __instance.indexMap[__instance.PositionHash(vpos)];
            var radiusPrecision =
                (float)(3.14159274101257 / (__instance.precision * 2) * 1.20000004768372);

            Patch.Debug("radiusPrecision " + radiusPrecision, LogLevel.Debug,
                        Patch.DebugPlanetRawData);
            var radiusPrecisionSq = radiusPrecision * radiusPrecision;

            Patch.Debug("radiusPrecisionSq " + radiusPrecisionSq, LogLevel.Debug,
                        Patch.DebugPlanetRawData);
            var magnetudeOnPrecisionDummy = 0.0f;
            var HeightTimePrecision       = 0.0f;
            var stride = __instance.stride;

            for (var index2 = -1; index2 <= 3; ++index2)
            {
                for (var index3 = -1; index3 <= 3; ++index3)
                {
                    var index4 = index1 + index2 + index3 * stride;
                    if ((uint)index4 < __instance.dataLength)
                    {
                        var sqrMagnitude = (__instance.vertices[index4] - vpos).sqrMagnitude;

                        Patch.Debug("sqrMagnitude " + sqrMagnitude, LogLevel.Debug,
                                    Patch.DebugPlanetRawData);
                        if (sqrMagnitude <= (double)radiusPrecisionSq)
                        {
                            var magnetudeOnPrecision =
                                (float)(1.0 - Mathf.Sqrt(sqrMagnitude) / (double)radiusPrecision);

                            Patch.Debug("MagnetudeOnPrecision " + magnetudeOnPrecision, LogLevel.Debug,
                                        Patch.DebugPlanetRawData);
                            magnetudeOnPrecision *= __instance.GetFactoredScale();

                            Patch.Debug("MagnetudeOnPrecision Patched " + magnetudeOnPrecision,
                                        LogLevel.Debug,
                                        Patch.DebugPlanetRawData);
                            var   modLevel        = __instance.GetModLevel(index4);
                            float heightDataFinal = __instance.heightData[index4];

                            Patch.Debug("heightDataFinal First " + heightDataFinal, LogLevel.Debug,
                                        Patch.DebugPlanetRawData);
                            if (modLevel > 0)
                            {
                                // try patching here
                                var modPlane = __instance.GetModPlaneInt(index4);

                                Patch.Debug("modPlane " + modPlane, LogLevel.Debug,
                                            Patch.DebugPlanetRawData);
                                if (modLevel == 3)
                                {
                                    heightDataFinal = modPlane;

                                    Patch.Debug("heightDataFinal Second " + heightDataFinal, LogLevel.Debug,
                                                Patch.DebugPlanetRawData);
                                }
                                else
                                {
                                    var num7 = modLevel * 0.3333333f;
                                    heightDataFinal =
                                        (float)(__instance.heightData[index4] * (1.0 - num7) +
                                                modPlane * (double)num7);

                                    Patch.Debug("heightDataFinal Third " + heightDataFinal, LogLevel.Debug,
                                                Patch.DebugPlanetRawData);
                                }
                            }

                            Patch.Debug("__result num6 " + heightDataFinal, LogLevel.Debug,
                                        Patch.DebugPlanetRawData);

                            magnetudeOnPrecisionDummy += magnetudeOnPrecision;
                            HeightTimePrecision       += heightDataFinal * magnetudeOnPrecision;

                            Patch.Debug("heightDataFinal Third " + heightDataFinal, LogLevel.Debug,
                                        Patch.DebugPlanetRawData);
                        }
                    }
                }
            }

            if (magnetudeOnPrecisionDummy != 0.0)
            {
                __result = (float)(HeightTimePrecision / (double)magnetudeOnPrecisionDummy *
                                   0.00999999977648258);

                Patch.Debug("__result magnetudeOnPrecisionDummy" + __result, LogLevel.Debug,
                            Patch.DebugPlanetRawData);
                return(false);
            }

            Debug.LogWarning("bad query");
            __result = __instance.heightData[0] * 0.01f;

            Patch.Debug("__result bad query" + __result, LogLevel.Debug,
                        Patch.DebugPlanetRawData);

            return(false);
        }
Beispiel #11
0
        public static void FlattenTerrainReform(PlanetFactory factory, List <Vector3> points, Vector3 center)
        {
            if (factory.tmp_ids == null)
            {
                factory.tmp_ids = new int[1024];
            }

            if (factory.tmp_entity_ids == null)
            {
                factory.tmp_entity_ids = new int[1024];
            }

            Array.Clear(factory.tmp_ids, 0, factory.tmp_ids.Length);
            Array.Clear(factory.tmp_entity_ids, 0, factory.tmp_entity_ids.Length);

            PlanetRawData data = factory.planet.data;

            ushort[] heightData = data.heightData;
            short    h          = (short)(factory.planet.realRadius * 100f + 20f);
            bool     levelized  = factory.planet.levelized;
            int      step       = Mathf.RoundToInt((center.magnitude - 0.2f - factory.planet.realRadius) / 1.3333333f);
            int      heightT    = step * 133 + h - 60;
            float    heightT2   = factory.planet.radius * 100f - 20f;

            foreach (KeyValuePair <int, int> keyValuePair in tmpLevelChanges)
            {
                if (keyValuePair.Value > 0)
                {
                    ushort height = heightData[keyValuePair.Key];
                    if (levelized)
                    {
                        if (height >= heightT)
                        {
                            if (data.GetModLevel(keyValuePair.Key) < 3)
                            {
                                data.SetModPlane(keyValuePair.Key, step);
                            }

                            factory.planet.AddHeightMapModLevel(keyValuePair.Key, keyValuePair.Value);
                        }
                    }
                    else
                    {
                        factory.planet.AddHeightMapModLevel(keyValuePair.Key, keyValuePair.Value);
                    }

                    if (height < heightT2)
                    {
                        factory.planet.landPercentDirty = true;
                    }
                }
            }

            if (factory.planet.UpdateDirtyMeshes())
            {
                factory.RenderLocalPlanetHeightmap();
            }

            foreach (Vector3 point in points)
            {
                NearColliderLogic nearColliderLogic = factory.planet.physics.nearColliderLogic;
                int num7 = nearColliderLogic.GetVegetablesInAreaNonAlloc(point, 1, factory.tmp_ids);
                for (int i = 0; i < num7; i++)
                {
                    int     id       = factory.tmp_ids[i];
                    Vector3 position = factory.vegePool[id].pos;
                    position -= point;
                    if (position.sqrMagnitude <= 9f)
                    {
                        factory.RemoveVegeWithComponents(id);
                    }
                    else
                    {
                        float d = data.QueryModifiedHeight(factory.vegePool[id].pos) - 0.03f;
                        factory.vegePool[id].pos = factory.vegePool[id].pos.normalized * d;
                        GameMain.gpuiManager.AlterModel(factory.vegePool[id].modelIndex, factory.vegePool[id].modelId, id,
                                                        factory.vegePool[id].pos, factory.vegePool[id].rot, false);
                    }
                }
            }


            tmpLevelChanges.Clear();
            Array.Clear(factory.tmp_ids, 0, factory.tmp_ids.Length);
            Array.Clear(factory.tmp_ids, 0, factory.tmp_entity_ids.Length);
            GameMain.gpuiManager.SyncAllGPUBuffer();
        }
Beispiel #12
0
        private static int ScanTerrain(PlanetRawData data, float realRadius, Vector3 vpos, int extent, float fade0)
        {
            int         stride     = data.stride;
            int         dataLength = data.dataLength;
            const float minimum    = 8f;

            Vector3[] vertices   = data.vertices;
            ushort[]  heightData = data.heightData;

            int start = data.QueryIndex(vpos);

            int cost = 0;

            for (int i = -extent; i <= extent; i++)
            {
                int index = start + i * stride;
                if (index < 0 || index >= dataLength)
                {
                    continue;
                }


                for (int j = -extent; j <= extent; j++)
                {
                    int finalIndex = index + j;
                    if ((ulong)finalIndex >= (ulong)dataLength)
                    {
                        continue;
                    }

                    Vector3 groundPos = vertices[finalIndex] * realRadius;

                    float closestDist = (vpos - groundPos).sqrMagnitude;

                    int currentLevel = data.GetModLevel(finalIndex);

                    if (tmpLevelChanges.ContainsKey(finalIndex))
                    {
                        currentLevel = tmpLevelChanges[finalIndex];
                        if (currentLevel == 3)
                        {
                            continue;
                        }
                    }

                    int fillLevel;
                    if (closestDist <= minimum)
                    {
                        fillLevel = 3;
                    }
                    else
                    {
                        closestDist -= minimum;
                        if (closestDist > fade0 * fade0)
                        {
                            continue;
                        }

                        float dist = closestDist / (fade0 * fade0);
                        if (dist <= 0.1111111f)
                        {
                            fillLevel = 2;
                        }
                        else if (dist <= 0.4444444f)
                        {
                            fillLevel = 1;
                        }
                        else
                        {
                            if (dist >= 1f)
                            {
                                continue;
                            }

                            fillLevel = 0;
                        }
                    }

                    int fillDiff = fillLevel - currentLevel;
                    if (fillLevel >= currentLevel && fillDiff != 0)
                    {
                        tmpLevelChanges[finalIndex] = fillLevel;
                        float height     = heightData[finalIndex] * 0.01f;
                        float fillHeight = realRadius + 0.2f - height;
                        if (fillHeight < 0f)
                        {
                            fillHeight *= 2f;
                        }

                        float tileCost = 100f * fillDiff * fillHeight * 0.3333333f;
                        cost += Mathf.FloorToInt(tileCost);
                    }
                }
            }

            return(cost);
        }