private static IEnumerable <Microbe> MicrobeColonySpawnHelper(ColonySpawnInfo colony, Vector3 location) { for (int c = 0; c < colony.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 // And add a little organicness to the look if (colony.Horizontal) { colony.CurSpawn.x += colony.Random.Next(5, 8); colony.CurSpawn.z += colony.Random.Next(-2, 3); } else { colony.CurSpawn.z += colony.Random.Next(5, 8); colony.CurSpawn.x += colony.Random.Next(-2, 3); } yield return(SpawnMicrobe(colony.Species, location + colony.CurSpawn, colony.WorldRoot, colony.MicrobeScene, true, colony.CloudSystem, colony.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 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); } } } } }