Beispiel #1
0
        public static List <ISpaceCraft> BuildSpaceCraft(IMassiveBody planet, double surfaceAngle, MissionConfig config, string craftDirectory)
        {
            if (string.IsNullOrEmpty(config.VehicleType))
            {
                throw new Exception("Must specify a vehicle type in the MissionConfig.xml!");
            }

            if (string.IsNullOrEmpty(config.ParentPlanet))
            {
                throw new Exception("Must specify a parent planet for the launch vehicle!");
            }

            var planetOffset = new DVector2(Math.Cos(surfaceAngle) * planet.SurfaceRadius,
                                            Math.Sin(surfaceAngle) * planet.SurfaceRadius);

            List <ISpaceCraft> spaceCrafts = GenerateSpaceCraft(planet, config, craftDirectory);

            foreach (ISpaceCraft craft in spaceCrafts)
            {
                craft.SkewEventTimes(config.TimeSkew);
            }

            if (spaceCrafts.Count == 0)
            {
                throw new Exception("No spacecrafts produced!");
            }

            ISpaceCraft primaryCraft = spaceCrafts[0];

            DVector2 distanceFromSurface = primaryCraft.Position - planet.Position;

            // If the ship is spawned on the planet update it's position to the correct surface angle
            if (distanceFromSurface.Length() * 0.999 < planet.SurfaceRadius)
            {
                primaryCraft.SetSurfacePosition(planet.Position + planetOffset, surfaceAngle);
            }
            else
            {
                primaryCraft.SetPitch(0);
            }

            return(spaceCrafts);
        }