public static float GetAverageHeight(int X, int Z, int Width, int Height, ChunkGeneratorSettings Settings) { var avgHeight = 0; var numHeight = 0; for (var dx = 0; dx < Width; dx++) { for (var dz = 0; dz < Height; dz++) { var worldPos = new Vector3(X + dx, (Settings.WorldSizeInChunks.Y * VoxelConstants.ChunkSizeY) - 1, Z + dz); var baseVoxel = VoxelHelpers.FindFirstVoxelBelowIncludingWater(Settings.World.ChunkManager.CreateVoxelHandle(GlobalVoxelCoordinate.FromVector3(worldPos))); if (!baseVoxel.IsValid) { continue; } avgHeight += baseVoxel.Coordinate.Y + 1; numHeight += 1; } } if (numHeight == 0) { return(0); } return(avgHeight / numHeight); }
public Microsoft.Xna.Framework.Vector3 GetSpawnLocation(WorldManager world, EntitySpawnLocation SpawnLocation) { Microsoft.Xna.Framework.Vector3 location = location = VoxelHelpers.FindFirstVoxelBelowIncludingWater(new VoxelHandle(world.ChunkManager, GlobalVoxelCoordinate.FromVector3(MonsterSpawner.GetRandomWorldEdge(world)))).WorldPosition + Microsoft.Xna.Framework.Vector3.Up * 1.5f; switch (SpawnLocation) { case EntitySpawnLocation.BalloonPort: { var balloonport = world.EnumerateZones().OfType <BalloonPort>(); if (balloonport.Any()) { location = Datastructures.SelectRandom(balloonport).GetBoundingBox().Center() + Microsoft.Xna.Framework.Vector3.Up * 1.5f; } break; } case EntitySpawnLocation.RandomZone: { var zones = world.EnumerateZones(); if (zones.Any()) { location = Datastructures.SelectRandom(zones).GetBoundingBox().Center() + Microsoft.Xna.Framework.Vector3.Up * 1.5f; } break; } case EntitySpawnLocation.WorldEdge: { // already computed break; } } return(location); }