private IEnumerable <Entity> SpawnEntitiesStaticly(EntitySpawnPoint entitySpawnPoint, DeterministicBatchGenerator deterministicBatchGenerator, Entity parentEntity = null) { Optional <UweWorldEntity> uweWorldEntity = worldEntityFactory.From(entitySpawnPoint.ClassId); if (uweWorldEntity.HasValue) { IEnumerable <Entity> entities = CreateEntityWithChildren(entitySpawnPoint, entitySpawnPoint.Scale, uweWorldEntity.Value.TechType, uweWorldEntity.Value.CellLevel, entitySpawnPoint.ClassId, deterministicBatchGenerator, parentEntity); foreach (Entity entity in entities) { yield return(entity); } } }
private List <UwePrefab> FilterAllowedPrefabs(List <UwePrefab> prefabs, EntitySpawnPoint entitySpawnPoint) { List <UwePrefab> allowedPrefabs = new List <UwePrefab>(); foreach (UwePrefab prefab in prefabs) { if (prefab.ClassId != "None") { Optional <UweWorldEntity> uweWorldEntity = worldEntityFactory.From(prefab.ClassId); if (uweWorldEntity.HasValue && entitySpawnPoint.AllowedTypes.Contains(uweWorldEntity.Value.SlotType)) { allowedPrefabs.Add(prefab); } } } return(allowedPrefabs); }
private List <PrefabData> filterAllowedPrefabs(List <PrefabData> prefabs, EntitySpawnPoint entitySpawnPoint) { List <PrefabData> allowedPrefabs = new List <PrefabData>(); foreach (PrefabData prefab in prefabs) { if (prefab.classId != "None") { WorldEntityInfo worldEntityInfo; if (worldEntitiesByClassId.TryGetValue(prefab.classId, out worldEntityInfo) && entitySpawnPoint.AllowedTypes.Contains(worldEntityInfo.slotType)) { allowedPrefabs.Add(prefab); } } } return(allowedPrefabs); }
private IEnumerable <Entity> CreateEntityWithChildren(EntitySpawnPoint entitySpawnPoint, TechType techType, LargeWorldEntity.CellLevel cellLevel, string classId) { Entity spawnedEntity = new Entity(entitySpawnPoint.Position, entitySpawnPoint.Rotation, techType, (int)cellLevel, classId); yield return(spawnedEntity); IEntityBootstrapper bootstrapper; if (customBootstrappersByTechType.TryGetValue(spawnedEntity.TechType, out bootstrapper)) { bootstrapper.Prepare(spawnedEntity); foreach (Entity childEntity in spawnedEntity.ChildEntities) { yield return(childEntity); } } }
private IEnumerable <Entity> CreateEntityWithChildren(EntitySpawnPoint entitySpawnPoint, NitroxVector3 scale, NitroxTechType techType, int cellLevel, string classId, DeterministicBatchGenerator deterministicBatchGenerator, Entity parentEntity = null) { Entity spawnedEntity = new Entity(entitySpawnPoint.LocalPosition, entitySpawnPoint.LocalRotation, scale, techType, cellLevel, classId, true, deterministicBatchGenerator.NextId(), null, parentEntity); spawnedEntity.ChildEntities = SpawnEntities(entitySpawnPoint.Children, deterministicBatchGenerator, spawnedEntity); CreatePrefabPlaceholdersWithChildren(spawnedEntity, classId, deterministicBatchGenerator); IEntityBootstrapper bootstrapper; if (customBootstrappersByTechType.TryGetValue(techType, out bootstrapper)) { bootstrapper.Prepare(spawnedEntity, parentEntity, deterministicBatchGenerator); } yield return(spawnedEntity); if (parentEntity == null) // Ensures children are only returned at the top level { // Children are yielded as well so they can be indexed at the top level (for use by simulation // ownership and various other consumers). The parent should always be yielded before the children foreach (Entity childEntity in AllChildren(spawnedEntity)) { yield return(childEntity); } } }
private IEnumerable <Entity> SpawnEntitiesUsingRandomDistribution(EntitySpawnPoint entitySpawnPoint, List <UwePrefab> prefabs, DeterministicBatchGenerator deterministicBatchGenerator, Entity parentEntity = null) { List <UwePrefab> allowedPrefabs = FilterAllowedPrefabs(prefabs, entitySpawnPoint); float rollingProbabilityDensity = allowedPrefabs.Sum(prefab => prefab.Probability / entitySpawnPoint.Density); if (rollingProbabilityDensity <= 0) { yield break; } double randomNumber = deterministicBatchGenerator.NextDouble(); if (rollingProbabilityDensity > 1f) { randomNumber *= rollingProbabilityDensity; } double rollingProbability = 0; UwePrefab selectedPrefab = allowedPrefabs.FirstOrDefault(prefab => { if (Math.Abs(prefab.Probability) < 0.0001) { return(false); } float probabilityDensity = prefab.Probability / entitySpawnPoint.Density; rollingProbability += probabilityDensity; return(rollingProbability >= randomNumber); }); if (selectedPrefab == null) { yield break; } Optional <UweWorldEntity> opWorldEntity = worldEntityFactory.From(selectedPrefab.ClassId); if (opWorldEntity.HasValue) { UweWorldEntity uweWorldEntity = opWorldEntity.Value; for (int i = 0; i < selectedPrefab.Count; i++) { IEnumerable <Entity> entities = CreateEntityWithChildren(entitySpawnPoint, uweWorldEntity.Scale, uweWorldEntity.TechType, uweWorldEntity.CellLevel, selectedPrefab.ClassId, deterministicBatchGenerator, parentEntity); foreach (Entity entity in entities) { yield return(entity); } } } }