/// <summary> /// Creates a flat, wooden balloon port for the balloon to land on, and Dwarves to sit on. /// </summary> /// <param name="roomDes">The player's BuildRoom designator (so that we can create a balloon port)</param> /// <param name="chunkManager">The terrain handler</param> /// <param name="x">The position of the center of the balloon port</param> /// <param name="z">The position of the center of the balloon port</param> /// <param name="size">The size of the (square) balloon port in voxels on a side</param> public void GenerateInitialBalloonPort(RoomBuilder roomDes, ChunkManager chunkManager, float x, float z, int size) { Vector3 pos = new Vector3(x, ChunkHeight - 1, z); // First, compute the maximum height of the terrain in a square window. int averageHeight = 0; int count = 0; for(int dx = -size; dx <= size; dx++) { for(int dz = -size; dz <= size; dz++) { Vector3 worldPos = new Vector3(pos.X + dx, pos.Y, pos.Z + dz); VoxelChunk chunk = chunkManager.ChunkData.GetVoxelChunkAtWorldLocation(worldPos); if(chunk == null) { continue; } Vector3 gridPos = chunk.WorldToGrid(worldPos); int h = chunk.GetFilledHeightOrWaterAt((int) gridPos.X + dx, (int) gridPos.Y, (int) gridPos.Z + dz); if (h > 0) { averageHeight += h; count++; } } } averageHeight = (int) Math.Round(((float) averageHeight/(float) count)); // Next, create the balloon port by deciding which voxels to fill. List<Voxel> designations = new List<Voxel>(); for(int dx = -size; dx <= size; dx++) { for(int dz = -size; dz <= size; dz++) { Vector3 worldPos = new Vector3(pos.X + dx, pos.Y, pos.Z + dz); VoxelChunk chunk = chunkManager.ChunkData.GetVoxelChunkAtWorldLocation(worldPos); if (chunk == null) { continue; } Vector3 gridPos = chunk.WorldToGrid(worldPos); int h = chunk.GetFilledVoxelGridHeightAt((int) gridPos.X, (int) gridPos.Y, (int) gridPos.Z); if(h == -1) { continue; } for (int y = averageHeight; y < h; y++) { Voxel v = chunk.MakeVoxel((int)gridPos.X, y, (int)gridPos.Z); v.Type = VoxelLibrary.GetVoxelType(0); chunk.Data.Water[v.Index].WaterLevel = 0; } if (averageHeight < h) { h = averageHeight; } // Fill from the top height down to the bottom. for (int y = h - 1; y < averageHeight; y++) { Voxel v = chunk.MakeVoxel((int) gridPos.X, y, (int) gridPos.Z); v.Type = VoxelLibrary.GetVoxelType("Scaffold"); chunk.Data.Water[v.Index].WaterLevel = 0; v.Chunk = chunk; v.Chunk.NotifyTotalRebuild(!v.IsInterior); if (y == averageHeight - 1) { designations.Add(v); } } } } // Actually create the BuildRoom. BalloonPort toBuild = new BalloonPort(designations, chunkManager); BuildRoomOrder buildDes = new BuildRoomOrder(toBuild, roomDes.Faction); buildDes.Build(); roomDes.DesignatedRooms.Add(toBuild); }
public async Task InsertAirportAsync(FAADataParser.NASR.Apt.Airport airport) { var dbAirport = new Airport { FAAComputerIdentifier = airport.FAAComputerIdentifier, LandingFacilityType = airport.LandingFacilityType, LocationIdentifier = airport.LocationIdentifier, InformationEffectiveDate = airport.InformationEffectiveDate, FacilityName = airport.FacilityName, AirportOwnershipType = airport.AirportOwnershipType, FacilityUse = airport.FacilityUse, Latitude = airport.Latitude, Longitude = airport.Longitude, Elevation = airport.Elevation, MagneticVariation = airport.MagneticVariation, MagneticVariationEpochYear = airport.MagneticVariationEpochYear, TPA = airport.TPA, }; _ = await _database.InsertAsync(dbAirport); foreach (FAADataParser.NASR.Apt.ILandingStructure landingStructure in airport.LandingStructures) { if (landingStructure.GetType() == typeof(FAADataParser.NASR.Apt.Runway)) { var rwy = (FAADataParser.NASR.Apt.Runway)landingStructure; var dbRwy = new Runway { AirportPrimaryKey = dbAirport.FAAComputerIdentifier, Identification = rwy.Identification, LengthInFeet = rwy.LengthInFeet, WidthInFeet = rwy.WidthInFeet, BaseEndIdentifier = rwy.BaseEndIdentifier, BaseEndTrueAlignment = rwy.BaseEndTrueAlignment, BaseEndRightTraffic = rwy.BaseEndRightTraffic, BaseEndLatitude = rwy.BaseEndLatitude, BaseEndLongitude = rwy.BaseEndLongitude, BaseEndElevation = rwy.BaseEndElevation, BaseEndDisplacedThresholdLatitude = rwy.BaseEndDisplacedThresholdLatitude, BaseEndDisplacedThresholdLongitude = rwy.BaseEndDisplacedThresholdLongitude, BaseEndDisplacedThresholdElevation = rwy.BaseEndDisplacedThresholdElevation, BaseEndTouchdownZoneElevation = rwy.BaseEndTouchdownZoneElevation, ReciprocalEndIdentifier = rwy.ReciprocalEndIdentifier, ReciprocalEndTrueAlignment = rwy.ReciprocalEndTrueAlignment, ReciprocalEndRightTraffic = rwy.ReciprocalEndRightTraffic, ReciprocalEndLatitude = rwy.ReciprocalEndLatitude, ReciprocalEndLongitude = rwy.ReciprocalEndLongitude, ReciprocalEndElevation = rwy.ReciprocalEndElevation, ReciprocalEndDisplacedThresholdLatitude = rwy.ReciprocalEndDisplacedThresholdLatitude, ReciprocalEndDisplacedThresholdLongitude = rwy.ReciprocalEndDisplacedThresholdLongitude, ReciprocalEndDisplacedThresholdElevation = rwy.ReciprocalEndDisplacedThresholdElevation, ReciprocalEndTouchdownZoneElevation = rwy.ReciprocalEndTouchdownZoneElevation, }; _ = await _database.InsertAsync(dbRwy); } else if (landingStructure.GetType() == typeof(FAADataParser.NASR.Apt.Helipad)) { var helipad = (FAADataParser.NASR.Apt.Helipad)landingStructure; var dbHelipad = new Helipad { AirportPrimaryKey = dbAirport.FAAComputerIdentifier, Identification = helipad.Identification, Latitude = helipad.Latitude, Longitude = helipad.Longitude, Elevation = helipad.Elevation, }; _ = await _database.InsertAsync(dbHelipad); } else if (landingStructure.GetType() == typeof(FAADataParser.NASR.Apt.BalloonPort)) { var balloonport = (FAADataParser.NASR.Apt.BalloonPort)landingStructure; var dbBalloonPort = new BalloonPort { AirportPrimaryKey = dbAirport.FAAComputerIdentifier, Identification = balloonport.Identification, Latitude = balloonport.Latitude, Longitude = balloonport.Longitude, Elevation = balloonport.Elevation, }; _ = await _database.InsertAsync(dbBalloonPort); } else { throw new ApplicationException("Unknown landing structure type"); } } }