public static ChunkSpawner MakeChunkSpawner(ChunkConfiguration chunkType, CompoundCloudSystem cloudSystem) { foreach (var mesh in chunkType.Meshes) { if (mesh.LoadedScene == null) { throw new ArgumentException("configured chunk spawner has a mesh that has no scene loaded"); } } return(new ChunkSpawner(chunkType, cloudSystem)); }
/// <summary> /// Must be called when spawned to provide access to the needed systems /// </summary> public void Init(CompoundCloudSystem cloudSystem, GameProperties currentGame, bool isPlayer) { this.cloudSystem = cloudSystem; CurrentGame = currentGame; IsPlayerMicrobe = isPlayer; if (!isPlayer) { ai = new MicrobeAI(this); } // Needed for immediately applying the species _Ready(); }
public PatchManager(SpawnSystem spawnSystem, ProcessSystem processSystem, CompoundCloudSystem compoundCloudSystem, TimedLifeSystem timedLife, DirectionalLight worldLight, GameProperties currentGame) { this.spawnSystem = spawnSystem; this.processSystem = processSystem; this.compoundCloudSystem = compoundCloudSystem; this.timedLife = timedLife; this.worldLight = worldLight; CloudSpawner = new CompoundCloudSpawner(compoundCloudSystem); ChunkSpawner = new ChunkSpawner(compoundCloudSystem); MicrobeSpawner = new MicrobeSpawner(compoundCloudSystem, currentGame); }
/// <summary> /// Grabs data from the type to initialize this /// </summary> /// <remarks> /// <para> /// Doesn't initialize the graphics scene which needs to be set separately /// </para> /// </remarks> public void Init(ChunkConfiguration chunkType, CompoundCloudSystem compoundClouds, string modelPath) { this.compoundClouds = compoundClouds; // Grab data VentPerSecond = chunkType.VentAmount; Dissolves = chunkType.Dissolves; Size = chunkType.Size; Damages = chunkType.Damages; DeleteOnTouch = chunkType.DeleteOnTouch; Mass = chunkType.Mass; // These are stored for saves to work Radius = chunkType.Radius; ChunkScale = chunkType.ChunkScale; ModelNodePath = modelPath; // Apply physics shape var shape = GetNode <CollisionShape>("CollisionShape"); // This only works as long as the sphere shape type is not changed in the editor ((SphereShape)shape.Shape).Radius = chunkType.Radius; // Copy compounds to vent if (chunkType.Compounds != null && chunkType.Compounds.Count > 0) { // Capacity is set to 0 so that no compounds can be added // the normal way to the chunk ContainedCompounds = new CompoundBag(0); foreach (var entry in chunkType.Compounds) { ContainedCompounds.Compounds.Add(entry.Key, entry.Value.Amount); } } // Needs physics callback when this is engulfable or damaging if (Damages > 0 || DeleteOnTouch || Size > 0) { ContactsReported = Constants.DEFAULT_STORE_CONTACTS_COUNT; Connect("body_shape_entered", this, "OnContactBegin"); Connect("body_shape_exited", this, "OnContactEnd"); } }
public void ApplyPropertiesFromSave(CompoundCloudSystem compoundCloudSystem) { cloudGridCenter = compoundCloudSystem.cloudGridCenter; elapsed = compoundCloudSystem.elapsed; // Copy concentrations (and as well as the other cloud parameters that need to be set) // TODO: allow saves to work if new compounds are added if (clouds.Count != compoundCloudSystem.clouds.Count) { throw new Exception("Loading a save that has different compound cloud types doesn't currently work"); } for (int i = 0; i < clouds.Count; ++i) { // TODO: it's not very nice to pass null as the context here clouds[i].ApplySave(compoundCloudSystem.clouds[i], null); } }
public static FloatingChunk SpawnChunk(ChunkConfiguration chunkType, Vector3 location, Node worldNode, PackedScene chunkScene, CompoundCloudSystem cloudSystem, Random random) { var chunk = (FloatingChunk)chunkScene.Instance(); // Settings need to be applied before adding it to the scene var selectedMesh = chunkType.Meshes.Random(random); chunk.GraphicsScene = selectedMesh.LoadedScene ?? throw new Exception("Chunk scene has not been loaded even though it should be loaded here"); chunk.ConvexPhysicsMesh = selectedMesh.LoadedConvexShape; if (chunk.GraphicsScene == null) { throw new ArgumentException("couldn't find a graphics scene for a chunk"); } // Pass on the chunk data chunk.Init(chunkType, cloudSystem, selectedMesh.SceneModelPath); chunk.UsesDespawnTimer = !chunkType.Dissolves; worldNode.AddChild(chunk); // Chunk is spawned with random rotation chunk.Transform = new Transform(new Quat( new Vector3(0, 1, 1).Normalized(), 2 * Mathf.Pi * (float)random.NextDouble()), location); chunk.GetNode <Spatial>("NodeToScale").Scale = new Vector3(chunkType.ChunkScale, chunkType.ChunkScale, chunkType.ChunkScale); chunk.AddToGroup(Constants.FLUID_EFFECT_GROUP); chunk.AddToGroup(Constants.AI_TAG_CHUNK); return(chunk); }
public ChunkSpawner(ChunkConfiguration chunkType, CompoundCloudSystem cloudSystem) { this.chunkType = chunkType; this.cloudSystem = cloudSystem; chunkScene = SpawnHelpers.LoadChunkScene(); }
public CompoundCloudSpawner(Compound compound, CompoundCloudSystem clouds, float amount) { this.compound = compound ?? throw new ArgumentException("compound is null"); this.clouds = clouds ?? throw new ArgumentException("clouds is null"); this.amount = amount; }
public static CompoundCloudSpawner MakeCompoundSpawner(Compound compound, CompoundCloudSystem clouds, float amount) { return(new CompoundCloudSpawner(compound, clouds, amount)); }
public static MicrobeSpawner MakeMicrobeSpawner(Species species, CompoundCloudSystem cloudSystem, GameProperties currentGame) { return(new MicrobeSpawner(species, cloudSystem, currentGame)); }
public void Init(MicrobeCamera camera, CompoundCloudSystem cloudSystem) { this.camera = camera; this.cloudSystem = cloudSystem; cloudCompounds = SimulationParameters.Instance.GetCloudCompounds(); }
public ChunkSpawner(CompoundCloudSystem cloudSystem) { this.cloudSystem = cloudSystem; chunkScene = LoadChunkScene(); }
public static IEnumerable <Microbe> SpawnBacteriaColony(Species species, Vector3 location, Node worldRoot, PackedScene microbeScene, CompoundCloudSystem cloudSystem, GameProperties currentGame, Random random) { var curSpawn = new Vector3(random.Next(1, 8), 0, random.Next(1, 8)); // Three kinds of colonies are supported, line colonies and clump colonies and Networks if (random.Next(0, 5) < 2) { // Clump for (int i = 0; i < random.Next(Constants.MIN_BACTERIAL_COLONY_SIZE, Constants.MAX_BACTERIAL_COLONY_SIZE + 1); i++) { // Dont spawn them on top of each other because it // causes them to bounce around and lag yield return(Spawn(species, location + curSpawn, worldRoot, microbeScene, true, cloudSystem, currentGame)); curSpawn = curSpawn + new Vector3(random.Next(-7, 8), 0, random.Next(-7, 8)); } } else if (random.Next(0, 31) > 2) { // Line // Allow for many types of line // (I combined the lineX and lineZ here because they have the same values) var line = random.Next(-5, 6) + random.Next(-5, 6); for (int i = 0; i < random.Next(Constants.MIN_BACTERIAL_LINE_SIZE, Constants.MAX_BACTERIAL_LINE_SIZE + 1); i++) { // Dont spawn them on top of each other because it // Causes them to bounce around and lag yield return(Spawn(species, location + curSpawn, worldRoot, microbeScene, true, cloudSystem, currentGame)); curSpawn = curSpawn + new Vector3(line + random.Next(-2, 3), 0, line + random.Next(-2, 3)); } } else { // Network // Allows for "jungles of cyanobacteria" // Network is extremely rare // To prevent bacteria being spawned on top of each other var vertical = false; var colony = new ColonySpawnInfo { Horizontal = false, Random = random, Species = species, CloudSystem = cloudSystem, CurrentGame = currentGame, CurSpawn = curSpawn, MicrobeScene = microbeScene, WorldRoot = worldRoot, }; for (int i = 0; i < random.Next(Constants.MIN_BACTERIAL_COLONY_SIZE, Constants.MAX_BACTERIAL_COLONY_SIZE + 1); i++) { if (random.Next(0, 5) < 2 && !colony.Horizontal) { colony.Horizontal = true; vertical = false; foreach (var microbe in MicrobeColonySpawnHelper(colony, location)) { yield return(microbe); } } else if (random.Next(0, 5) < 2 && !vertical) { colony.Horizontal = false; vertical = true; foreach (var microbe in MicrobeColonySpawnHelper(colony, location)) { yield return(microbe); } } else if (random.Next(0, 5) < 2 && !colony.Horizontal) { colony.Horizontal = true; vertical = false; foreach (var microbe in MicrobeColonySpawnHelper(colony, location)) { yield return(microbe); } } else if (random.Next(0, 5) < 2 && !vertical) { colony.Horizontal = false; vertical = true; foreach (var microbe in MicrobeColonySpawnHelper(colony, location)) { yield return(microbe); } } else { // Diagonal colony.Horizontal = false; vertical = false; foreach (var microbe in MicrobeColonySpawnHelper(colony, location)) { yield return(microbe); } } } } }
public MicrobeSpawner(CompoundCloudSystem cloudSystem, GameProperties currentGame) { this.cloudSystem = cloudSystem; microbeScene = LoadMicrobeScene(); CurrentGame = currentGame; }
// TODO: this is likely a huge cause of lag. Would be nice to be able // to spawn these so that only one per tick is spawned. public static IEnumerable <Microbe> SpawnBacteriaColony(Species species, Vector3 location, Node worldRoot, PackedScene microbeScene, CompoundCloudSystem cloudSystem, GameProperties currentGame, Random random) { var curSpawn = new Vector3(random.Next(1, 8), 0, random.Next(1, 8)); // Three kinds of colonies are supported, line colonies and clump colonies and Networks if (random.Next(0, 5) < 2) { // Clump for (int i = 0; i < random.Next(Constants.MIN_BACTERIAL_COLONY_SIZE, Constants.MAX_BACTERIAL_COLONY_SIZE + 1); i++) { // Dont spawn them on top of each other because it // causes them to bounce around and lag yield return(SpawnMicrobe(species, location + curSpawn, worldRoot, microbeScene, true, cloudSystem, currentGame)); curSpawn = curSpawn + new Vector3(random.Next(-7, 8), 0, random.Next(-7, 8)); } } else if (random.Next(0, 31) > 2) { // Line // Allow for many types of line // (I combined the lineX and lineZ here because they have the same values) var line = random.Next(-5, 6) + random.Next(-5, 6); for (int i = 0; i < random.Next(Constants.MIN_BACTERIAL_LINE_SIZE, Constants.MAX_BACTERIAL_LINE_SIZE + 1); i++) { // Dont spawn them on top of each other because it // Causes them to bounce around and lag yield return(SpawnMicrobe(species, location + curSpawn, worldRoot, microbeScene, true, cloudSystem, currentGame)); curSpawn = curSpawn + new Vector3(line + random.Next(-2, 3), 0, line + random.Next(-2, 3)); } } else { // Network // Allows for "jungles of cyanobacteria" // Network is extremely rare // To prevent bacteria being spawned on top of each other var horizontal = false; var vertical = false; for (int i = 0; i < random.Next(Constants.MIN_BACTERIAL_COLONY_SIZE, Constants.MAX_BACTERIAL_COLONY_SIZE + 1); i++) { if (random.Next(0, 5) < 2 && !horizontal) { horizontal = true; vertical = false; for (int c = 0; c < random.Next(Constants.MIN_BACTERIAL_LINE_SIZE, Constants.MAX_BACTERIAL_LINE_SIZE + 1); c++) { // Dont spawn them on top of each other because // It causes them to bounce around and lag curSpawn.x += random.Next(5, 8); // Add a litlle organicness to the look curSpawn.z += random.Next(-2, 3); yield return(SpawnMicrobe(species, location + curSpawn, worldRoot, microbeScene, true, cloudSystem, currentGame)); } } else if (random.Next(0, 5) < 2 && !vertical) { horizontal = false; vertical = true; for (int c = 0; c < random.Next(Constants.MIN_BACTERIAL_LINE_SIZE, Constants.MAX_BACTERIAL_LINE_SIZE + 1); c++) { // Dont spawn them on top of each other because it // Causes them to bounce around and lag curSpawn.z += random.Next(5, 8); // Add a litlle organicness to the look curSpawn.x += random.Next(-2, 3); yield return(SpawnMicrobe(species, location + curSpawn, worldRoot, microbeScene, true, cloudSystem, currentGame)); } } else if (random.Next(0, 5) < 2 && !horizontal) { horizontal = true; vertical = false; for (int c = 0; c < random.Next(Constants.MIN_BACTERIAL_LINE_SIZE, Constants.MAX_BACTERIAL_LINE_SIZE + 1); c++) { // Dont spawn them on top of each other because // It causes them to bounce around and lag curSpawn.x -= random.Next(5, 8); // Add a little organicness to the look curSpawn.z -= random.Next(-2, 3); yield return(SpawnMicrobe(species, location + curSpawn, worldRoot, microbeScene, true, cloudSystem, currentGame)); } } else if (random.Next(0, 5) < 2 && !vertical) { horizontal = false; vertical = true; for (int c = 0; c < random.Next(Constants.MIN_BACTERIAL_LINE_SIZE, Constants.MAX_BACTERIAL_LINE_SIZE + 1); c++) { // Dont spawn them on top of each other because it // causes them to bounce around and lag curSpawn.z -= random.Next(5, 8); // Add a little organicness to the look curSpawn.x -= random.Next(-2, 3); yield return(SpawnMicrobe(species, location + curSpawn, worldRoot, microbeScene, true, cloudSystem, currentGame)); } } else { // Diagonal horizontal = false; vertical = false; for (int c = 0; c < random.Next(Constants.MIN_BACTERIAL_LINE_SIZE, Constants.MAX_BACTERIAL_LINE_SIZE + 1); c++) { // Dont spawn them on top of each other because it // Causes them to bounce around and lag curSpawn.z += random.Next(5, 8); curSpawn.x += random.Next(5, 8); yield return(SpawnMicrobe(species, location + curSpawn, worldRoot, microbeScene, true, cloudSystem, currentGame)); } } } } }
public static ChunkSpawner MakeChunkSpawner(Biome.ChunkConfiguration chunkType, CompoundCloudSystem cloudSystem) { return(new ChunkSpawner(chunkType, cloudSystem)); }
public CompoundCloudSpawner(CompoundCloudSystem clouds) { this.clouds = clouds ?? throw new ArgumentException("clouds is null"); }