public void SpawnInitial(SpawnPopulation population, SpawnDistribution distribution) { int targetCount = this.GetTargetCount(population, distribution); int currentCount = targetCount - this.GetCurrentCount(population, distribution); this.Spawn(population, distribution, targetCount, currentCount, currentCount * population.SpawnAttemptsInitial); }
private void EnforceLimits(SpawnPopulation population, SpawnDistribution distribution) { int targetCount = this.GetTargetCount(population, distribution); Spawnable[] all = this.FindAll(population); if (all.Length <= targetCount) { return; } Debug.Log((object)(population.ToString() + " has " + (object)all.Length + " objects, but max allowed is " + (object)targetCount)); int count = all.Length - targetCount; Debug.Log((object)(" - deleting " + (object)count + " objects")); foreach (Spawnable spawnable in ((IEnumerable <Spawnable>)all).Take <Spawnable>(count)) { BaseEntity baseEntity = ((Component)spawnable).get_gameObject().ToBaseEntity(); if (baseEntity.IsValid()) { baseEntity.Kill(BaseNetworkable.DestroyMode.None); } else { GameManager.Destroy(((Component)spawnable).get_gameObject(), 0.0f); } } }
private void EnforceLimits(SpawnPopulation population, SpawnDistribution distribution) { int targetCount = this.GetTargetCount(population, distribution); Spawnable[] spawnableArray = this.FindAll(population); if ((int)spawnableArray.Length <= targetCount) { return; } UnityEngine.Debug.Log(string.Concat(new object[] { population, " has ", (int)spawnableArray.Length, " objects, but max allowed is ", targetCount })); int length = (int)spawnableArray.Length - targetCount; UnityEngine.Debug.Log(string.Concat(" - deleting ", length, " objects")); foreach (Spawnable spawnable in spawnableArray.Take <Spawnable>(length)) { BaseEntity baseEntity = spawnable.gameObject.ToBaseEntity(); if (!baseEntity.IsValid()) { GameManager.Destroy(spawnable.gameObject, 0f); } else { baseEntity.Kill(BaseNetworkable.DestroyMode.None); } } }
private IEnumerator SpawnTick() { label_1: do { yield return((object)CoroutineEx.waitForEndOfFrame); }while (!this.spawnTick || !Spawn.respawn_populations); yield return((object)CoroutineEx.waitForSeconds(Spawn.tick_populations)); for (int i = 0; i < this.AllSpawnPopulations.Length; ++i) { SpawnPopulation allSpawnPopulation = this.AllSpawnPopulations[i]; if (!((BaseScriptableObject)allSpawnPopulation == (BaseScriptableObject)null)) { SpawnDistribution spawnDistribution = this.SpawnDistributions[i]; if (spawnDistribution != null) { try { if (this.SpawnDistributions != null) { this.SpawnRepeating(allSpawnPopulation, spawnDistribution); } } catch (Exception ex) { Debug.LogError((object)ex); } yield return((object)CoroutineEx.waitForEndOfFrame); } } } goto label_1; }
//GameBuilder constructor public GameBuilder1(Initializer init, SpawnM1 spawner, SpawnPopulation spawner2) { this.calendar = new List <Day> (); this.calendar.Add(initDay(init)); spawner.onStart(init, this); spawner2.onStart(init, this); rander = new Randomize((int)init.getParam("variance")); }
internal void Load(BaseNetworkable.LoadInfo info) { if (info.msg.spawnable != null) { this.Population = FileSystem.Load <SpawnPopulation>(StringPool.Get((uint)((Spawnable)info.msg.spawnable).population), true); } this.Add(); }
public void SpawnRepeating(SpawnPopulation population, SpawnDistribution distribution) { int targetCount = this.GetTargetCount(population, distribution); int currentCount = this.GetCurrentCount(population, distribution); int num = Mathf.RoundToInt((float)(targetCount - currentCount) * population.GetCurrentSpawnRate()); int numToFill = Random.Range(Mathf.Min(num, this.MinSpawnsPerTick), Mathf.Min(num, this.MaxSpawnsPerTick)); this.Spawn(population, distribution, targetCount, numToFill, numToFill * population.SpawnAttemptsRepeating); }
public void SpawnRepeating(SpawnPopulation population, SpawnDistribution distribution) { int targetCount = this.GetTargetCount(population, distribution); int currentCount = targetCount - this.GetCurrentCount(population, distribution); currentCount = Mathf.RoundToInt((float)currentCount * population.GetCurrentSpawnRate()); currentCount = UnityEngine.Random.Range(Mathf.Min(currentCount, this.MinSpawnsPerTick), Mathf.Min(currentCount, this.MaxSpawnsPerTick)); this.Spawn(population, distribution, targetCount, currentCount, currentCount * population.SpawnAttemptsRepeating); }
public Spawnable[] FindAll(SpawnPopulation population) { return(UnityEngine.Object.FindObjectsOfType <Spawnable>().Where <Spawnable>((Spawnable x) => { if (!x.gameObject.activeInHierarchy) { return false; } return x.Population == population; }).ToArray <Spawnable>()); }
private GameObject Spawn(SpawnPopulation population, Vector3 pos, Quaternion rot) { Prefab <Spawnable> randomPrefab = population.GetRandomPrefab(); if (randomPrefab == null) { return(null); } if (randomPrefab.Component == null) { UnityEngine.Debug.LogError(string.Concat("[Spawn] Missing component 'Spawnable' on ", randomPrefab.Name)); return(null); } Vector3 vector3 = Vector3.one; DecorComponent[] decorComponentArray = PrefabAttribute.server.FindAll <DecorComponent>(randomPrefab.ID); randomPrefab.Object.transform.ApplyDecorComponents(decorComponentArray, ref pos, ref rot, ref vector3); if (!randomPrefab.ApplyTerrainAnchors(ref pos, rot, vector3, TerrainAnchorMode.MinimizeMovement, population.Filter)) { return(null); } if (!randomPrefab.ApplyTerrainChecks(pos, rot, vector3, population.Filter)) { return(null); } if (!randomPrefab.ApplyTerrainFilters(pos, rot, vector3, null)) { return(null); } if (!randomPrefab.ApplyWaterChecks(pos, rot, vector3)) { return(null); } if (!this.CheckBounds(randomPrefab, pos, rot, vector3)) { return(null); } if (randomPrefab.Component.Population != population) { randomPrefab.Component.Population = population; } if (Global.developer > 1) { UnityEngine.Debug.Log(string.Concat("[Spawn] Spawning ", randomPrefab.Name)); } BaseEntity baseEntity = randomPrefab.SpawnEntity(pos, rot); if (baseEntity != null) { baseEntity.Spawn(); return(baseEntity.gameObject); } UnityEngine.Debug.LogWarning(string.Concat("[Spawn] Couldn't create prefab as entity - ", randomPrefab.Name)); return(null); }
private GameObject Spawn(SpawnPopulation population, Vector3 pos, Quaternion rot) { Prefab <Spawnable> randomPrefab = population.GetRandomPrefab(); if (randomPrefab == null) { return((GameObject)null); } if (Object.op_Equality((Object)randomPrefab.Component, (Object)null)) { Debug.LogError((object)("[Spawn] Missing component 'Spawnable' on " + randomPrefab.Name)); return((GameObject)null); } Vector3 one = Vector3.get_one(); DecorComponent[] all = PrefabAttribute.server.FindAll <DecorComponent>(randomPrefab.ID); randomPrefab.Object.get_transform().ApplyDecorComponents(all, ref pos, ref rot, ref one); if (!randomPrefab.ApplyTerrainAnchors(ref pos, rot, one, TerrainAnchorMode.MinimizeMovement, population.Filter)) { return((GameObject)null); } if (!randomPrefab.ApplyTerrainChecks(pos, rot, one, population.Filter)) { return((GameObject)null); } if (!randomPrefab.ApplyTerrainFilters(pos, rot, one, (SpawnFilter)null)) { return((GameObject)null); } if (!randomPrefab.ApplyWaterChecks(pos, rot, one)) { return((GameObject)null); } if (!this.CheckBounds(randomPrefab, pos, rot, one)) { return((GameObject)null); } if ((BaseScriptableObject)randomPrefab.Component.Population != (BaseScriptableObject)population) { randomPrefab.Component.Population = population; } if (Global.developer > 1) { Debug.Log((object)("[Spawn] Spawning " + randomPrefab.Name)); } BaseEntity baseEntity = randomPrefab.SpawnEntity(pos, rot); if (Object.op_Equality((Object)baseEntity, (Object)null)) { Debug.LogWarning((object)("[Spawn] Couldn't create prefab as entity - " + randomPrefab.Name)); return((GameObject)null); } baseEntity.Spawn(); return(((Component)baseEntity).get_gameObject()); }
public Spawnable[] FindAll(SpawnPopulation population) { return(((IEnumerable <Spawnable>)Object.FindObjectsOfType <Spawnable>()).Where <Spawnable>((Func <Spawnable, bool>)(x => { if (((Component)x).get_gameObject().get_activeInHierarchy()) { return (BaseScriptableObject)x.Population == (BaseScriptableObject)population; } return false; })).ToArray <Spawnable>()); }
public int GetTargetCount(SpawnPopulation population, SpawnDistribution distribution) { float size = TerrainMeta.Size.x * TerrainMeta.Size.z; float currentSpawnDensity = population.GetCurrentSpawnDensity(); if (population.ScaleWithSpawnFilter) { currentSpawnDensity *= distribution.Density; } return(Mathf.RoundToInt(size * currentSpawnDensity)); }
public void UpdateDistributions() { if (World.Size == 0) { return; } this.SpawnDistributions = new SpawnDistribution[(int)this.AllSpawnPopulations.Length]; this.population2distribution = new Dictionary <SpawnPopulation, SpawnDistribution>(); Vector3 size = TerrainMeta.Size; Vector3 position = TerrainMeta.Position; int num = Mathf.NextPowerOfTwo((int)((float)((float)World.Size) * 0.25f)); for (int i1 = 0; i1 < (int)this.AllSpawnPopulations.Length; i1++) { SpawnPopulation allSpawnPopulations = this.AllSpawnPopulations[i1]; if (allSpawnPopulations != null) { byte[] factor = new byte[num * num]; SpawnFilter filter = allSpawnPopulations.Filter; Parallel.For(0, num, (int z) => { for (int i = 0; i < num; i++) { float popRes = ((float)i + 0.5f) / (float)num; float single = ((float)z + 0.5f) / (float)num; factor[z * num + i] = (byte)(255f * filter.GetFactor(popRes, single)); } }); SpawnDistribution[] spawnDistributions = this.SpawnDistributions; SpawnDistribution spawnDistribution = new SpawnDistribution(this, factor, position, size); SpawnDistribution spawnDistribution1 = spawnDistribution; spawnDistributions[i1] = spawnDistribution; this.population2distribution.Add(allSpawnPopulations, spawnDistribution1); } else { UnityEngine.Debug.LogError("Spawn handler contains null spawn population."); } } int num1 = Mathf.NextPowerOfTwo((int)((float)((float)World.Size) * 0.5f)); byte[] numArray = new byte[num1 * num1]; SpawnFilter characterSpawn = this.CharacterSpawn; Parallel.For(0, num1, (int z) => { for (int i = 0; i < num1; i++) { float charRes = ((float)i + 0.5f) / (float)num1; float single = ((float)z + 0.5f) / (float)num1; numArray[z * num1 + i] = (byte)(255f * characterSpawn.GetFactor(charRes, single)); } }); this.CharDistribution = new SpawnDistribution(this, numArray, position, size); }
public void UpdateDistributions() { if (World.Size == 0U) { return; } this.SpawnDistributions = new SpawnDistribution[this.AllSpawnPopulations.Length]; this.population2distribution = new Dictionary <SpawnPopulation, SpawnDistribution>(); Vector3 size = TerrainMeta.Size; Vector3 position = TerrainMeta.Position; int pop_res = Mathf.NextPowerOfTwo((int)((double)World.Size * 0.25)); for (int index1 = 0; index1 < this.AllSpawnPopulations.Length; ++index1) { SpawnPopulation allSpawnPopulation = this.AllSpawnPopulations[index1]; if ((BaseScriptableObject)allSpawnPopulation == (BaseScriptableObject)null) { Debug.LogError((object)"Spawn handler contains null spawn population."); } else { byte[] map = new byte[pop_res * pop_res]; SpawnFilter filter = allSpawnPopulation.Filter; Parallel.For(0, pop_res, (Action <int>)(z => { for (int index = 0; index < pop_res; ++index) { float normX = ((float)index + 0.5f) / (float)pop_res; float normZ = ((float)z + 0.5f) / (float)pop_res; map[z * pop_res + index] = (byte)((double)byte.MaxValue * (double)filter.GetFactor(normX, normZ)); } })); SpawnDistribution spawnDistribution = this.SpawnDistributions[index1] = new SpawnDistribution(this, map, position, size); this.population2distribution.Add(allSpawnPopulation, spawnDistribution); } } int char_res = Mathf.NextPowerOfTwo((int)((double)World.Size * 0.5)); byte[] map1 = new byte[char_res * char_res]; SpawnFilter filter1 = this.CharacterSpawn; Parallel.For(0, char_res, (Action <int>)(z => { for (int index = 0; index < char_res; ++index) { float normX = ((float)index + 0.5f) / (float)char_res; float normZ = ((float)z + 0.5f) / (float)char_res; map1[z * char_res + index] = (byte)((double)byte.MaxValue * (double)filter1.GetFactor(normX, normZ)); } })); this.CharDistribution = new SpawnDistribution(this, map1, position, size); }
public int GetTargetCount(SpawnPopulation population, SpawnDistribution distribution) { // ISSUE: variable of the null type __Null local = TerrainMeta.Size.x * TerrainMeta.Size.z; float currentSpawnDensity = population.GetCurrentSpawnDensity(); if (population.ScaleWithSpawnFilter) { currentSpawnDensity *= distribution.Density; } double num = (double)currentSpawnDensity; return(Mathf.RoundToInt((float)(local * num))); }
public void EnforceLimits(bool forceAll = false) { if (this.SpawnDistributions == null) { return; } for (int i = 0; i < (int)this.AllSpawnPopulations.Length; i++) { if (this.AllSpawnPopulations[i] != null) { SpawnPopulation allSpawnPopulations = this.AllSpawnPopulations[i]; SpawnDistribution spawnDistributions = this.SpawnDistributions[i]; if (forceAll || allSpawnPopulations.EnforcePopulationLimits) { this.EnforceLimits(allSpawnPopulations, spawnDistributions); } } } }
public void EnforceLimits(bool forceAll = false) { if (this.SpawnDistributions == null) { return; } for (int index = 0; index < this.AllSpawnPopulations.Length; ++index) { if (!((BaseScriptableObject)this.AllSpawnPopulations[index] == (BaseScriptableObject)null)) { SpawnPopulation allSpawnPopulation = this.AllSpawnPopulations[index]; SpawnDistribution spawnDistribution = this.SpawnDistributions[index]; if (forceAll || allSpawnPopulation.EnforcePopulationLimits) { this.EnforceLimits(allSpawnPopulation, spawnDistribution); } } } }
private void Spawn( SpawnPopulation population, SpawnDistribution distribution, int targetCount, int numToFill, int numToTry) { if (targetCount == 0) { return; } if (!population.Initialize()) { Debug.LogError((object)("[Spawn] No prefabs to spawn in " + population.ResourceFolder), (Object)population); } else { if (Global.developer > 1) { Debug.Log((object)("[Spawn] Population " + population.ResourceFolder + " needs to spawn " + (object)numToFill)); } float num1 = Mathf.Max((float)population.ClusterSizeMax, distribution.GetGridCellArea() * population.GetMaximumSpawnDensity()); population.UpdateWeights(distribution, targetCount); while (numToFill >= population.ClusterSizeMin && numToTry > 0) { ByteQuadtree.Element node = distribution.SampleNode(); int num2 = Random.Range(population.ClusterSizeMin, population.ClusterSizeMax + 1); int num3 = Mathx.Min(numToTry, numToFill, num2); for (int index = 0; index < num3; ++index) { Vector3 spawnPos; Quaternion spawnRot; if (distribution.Sample(out spawnPos, out spawnRot, node, population.AlignToNormal, (float)population.ClusterDithering) && (double)population.Filter.GetFactor(spawnPos) > 0.0 && (double)distribution.GetCount(spawnPos) < (double)num1) { this.Spawn(population, spawnPos, spawnRot); --numToFill; } --numToTry; } } } }
private IEnumerator SpawnTick() { SpawnHandler spawnHandler = null; while (true) { yield return(CoroutineEx.waitForEndOfFrame); if (spawnHandler.spawnTick && Spawn.respawn_populations) { yield return(CoroutineEx.waitForSeconds(Spawn.tick_populations)); for (int i = 0; i < (int)spawnHandler.AllSpawnPopulations.Length; i++) { SpawnPopulation allSpawnPopulations = spawnHandler.AllSpawnPopulations[i]; if (allSpawnPopulations != null) { SpawnDistribution spawnDistributions = spawnHandler.SpawnDistributions[i]; if (spawnDistributions != null) { try { if (spawnHandler.SpawnDistributions != null) { spawnHandler.SpawnRepeating(allSpawnPopulations, spawnDistributions); } } catch (Exception exception) { UnityEngine.Debug.LogError(exception); } yield return(CoroutineEx.waitForEndOfFrame); } } } } } }
private void Spawn(SpawnPopulation population, SpawnDistribution distribution, int targetCount, int numToFill, int numToTry) { Vector3 vector3; Quaternion quaternion; if (targetCount == 0) { return; } if (!population.Initialize()) { UnityEngine.Debug.LogError(string.Concat("[Spawn] No prefabs to spawn in ", population.ResourceFolder), population); return; } if (Global.developer > 1) { UnityEngine.Debug.Log(string.Concat(new object[] { "[Spawn] Population ", population.ResourceFolder, " needs to spawn ", numToFill })); } float single = Mathf.Max((float)population.ClusterSizeMax, distribution.GetGridCellArea() * population.GetMaximumSpawnDensity()); population.UpdateWeights(distribution, targetCount); while (numToFill >= population.ClusterSizeMin && numToTry > 0) { ByteQuadtree.Element element = distribution.SampleNode(); int num = UnityEngine.Random.Range(population.ClusterSizeMin, population.ClusterSizeMax + 1); num = Mathx.Min(numToTry, numToFill, num); for (int i = 0; i < num; i++) { if (distribution.Sample(out vector3, out quaternion, element, population.AlignToNormal, (float)population.ClusterDithering) && population.Filter.GetFactor(vector3) > 0f && (float)distribution.GetCount(vector3) < single) { this.Spawn(population, vector3, quaternion); numToFill--; } numToTry--; } } }
protected void OnValidate() { this.Population = null; }
public string GetReport(bool detailed = true) { StringBuilder stringBuilder = new StringBuilder(); if (this.AllSpawnPopulations == null) { stringBuilder.AppendLine("Spawn population array is null."); } if (this.SpawnDistributions == null) { stringBuilder.AppendLine("Spawn distribution array is null."); } if (this.AllSpawnPopulations != null && this.SpawnDistributions != null) { for (int index = 0; index < this.AllSpawnPopulations.Length; ++index) { if (!((BaseScriptableObject)this.AllSpawnPopulations[index] == (BaseScriptableObject)null)) { SpawnPopulation allSpawnPopulation = this.AllSpawnPopulations[index]; SpawnDistribution spawnDistribution = this.SpawnDistributions[index]; if ((BaseScriptableObject)allSpawnPopulation != (BaseScriptableObject)null) { if (!string.IsNullOrEmpty(allSpawnPopulation.ResourceFolder)) { stringBuilder.AppendLine(((Object)allSpawnPopulation).get_name() + " (autospawn/" + allSpawnPopulation.ResourceFolder + ")"); } else { stringBuilder.AppendLine(((Object)allSpawnPopulation).get_name()); } if (detailed) { stringBuilder.AppendLine("\tPrefabs:"); if (allSpawnPopulation.Prefabs != null) { foreach (Prefab <Spawnable> prefab in allSpawnPopulation.Prefabs) { stringBuilder.AppendLine("\t\t" + prefab.Name + " - " + (object)prefab.Object); } } else { stringBuilder.AppendLine("\t\tN/A"); } } if (spawnDistribution != null) { int currentCount = this.GetCurrentCount(allSpawnPopulation, spawnDistribution); int targetCount = this.GetTargetCount(allSpawnPopulation, spawnDistribution); stringBuilder.AppendLine("\tPopulation: " + (object)currentCount + "/" + (object)targetCount); } else { stringBuilder.AppendLine("\tDistribution #" + (object)index + " is not set."); } } else { stringBuilder.AppendLine("Population #" + (object)index + " is not set."); } stringBuilder.AppendLine(); } } } return(stringBuilder.ToString()); }
public int GetCurrentCount(SpawnPopulation population, SpawnDistribution distribution) { return(distribution.Count); }
protected void OnValidate() { this.Population = (SpawnPopulation)null; }
/// <summary> /// Method to generate an initial conway's game of life table. /// </summary> /// <param name="population"> Initial living cells. </param> /// <param name="length"> Length of the table.</param> /// <param name="width"> Width of the table. </param> /// <returns> An 2D int array with randomly generated population of living cells. </returns> public int[,] GenrateTableWithPopulation(int population, int length, int width) { return(SpawnPopulation.GeneratePopulationOnTable(population, length, width)); }
public string GetReport(bool detailed = true) { StringBuilder stringBuilder = new StringBuilder(); if (this.AllSpawnPopulations == null) { stringBuilder.AppendLine("Spawn population array is null."); } if (this.SpawnDistributions == null) { stringBuilder.AppendLine("Spawn distribution array is null."); } if (this.AllSpawnPopulations != null && this.SpawnDistributions != null) { for (int i = 0; i < (int)this.AllSpawnPopulations.Length; i++) { if (this.AllSpawnPopulations[i] != null) { SpawnPopulation allSpawnPopulations = this.AllSpawnPopulations[i]; SpawnDistribution spawnDistributions = this.SpawnDistributions[i]; if (allSpawnPopulations == null) { stringBuilder.AppendLine(string.Concat("Population #", i, " is not set.")); } else { if (string.IsNullOrEmpty(allSpawnPopulations.ResourceFolder)) { stringBuilder.AppendLine(allSpawnPopulations.name); } else { stringBuilder.AppendLine(string.Concat(allSpawnPopulations.name, " (autospawn/", allSpawnPopulations.ResourceFolder, ")")); } if (detailed) { stringBuilder.AppendLine("\tPrefabs:"); if (allSpawnPopulations.Prefabs == null) { stringBuilder.AppendLine("\t\tN/A"); } else { Prefab <Spawnable>[] prefabs = allSpawnPopulations.Prefabs; for (int j = 0; j < (int)prefabs.Length; j++) { Prefab <Spawnable> prefab = prefabs[j]; stringBuilder.AppendLine(string.Concat(new object[] { "\t\t", prefab.Name, " - ", prefab.Object })); } } } if (spawnDistributions == null) { stringBuilder.AppendLine(string.Concat("\tDistribution #", i, " is not set.")); } else { int currentCount = this.GetCurrentCount(allSpawnPopulations, spawnDistributions); int targetCount = this.GetTargetCount(allSpawnPopulations, spawnDistributions); stringBuilder.AppendLine(string.Concat(new object[] { "\tPopulation: ", currentCount, "/", targetCount })); } } stringBuilder.AppendLine(); } } } return(stringBuilder.ToString()); }