Ejemplo n.º 1
0
        protected override void OnOffered()
        {
            System.Random random = new System.Random(contract.MissionSeed);

            int i = 0;

            foreach (WaypointData wpData in waypoints)
            {
                // Do type-specific waypoint handling
                if (wpData.type == "RANDOM_WAYPOINT")
                {
                    // Generate the position
                    WaypointManager.ChooseRandomPosition(out wpData.waypoint.latitude, out wpData.waypoint.longitude,
                                                         wpData.waypoint.celestialName, wpData.waterAllowed, wpData.forceEquatorial, random);
                }
                else if (wpData.type == "RANDOM_WAYPOINT_NEAR")
                {
                    Waypoint nearWaypoint = waypoints[wpData.nearIndex].waypoint;
                    WaypointManager.ChooseRandomPositionNear(out wpData.waypoint.latitude, out wpData.waypoint.longitude,
                                                             nearWaypoint.latitude, nearWaypoint.longitude, wpData.waypoint.celestialName,
                                                             wpData.nearDistance, wpData.waterAllowed, random);
                }

                // Set altitude
                if (wpData.randomAltitude)
                {
                    CelestialBody body = FlightGlobals.Bodies.Where <CelestialBody>(b => b.name == wpData.waypoint.celestialName).First();
                    if (body.atmosphere)
                    {
                        wpData.waypoint.altitude = random.NextDouble() * (body.maxAtmosphereAltitude);
                    }
                    else
                    {
                        wpData.waypoint.altitude = 0.0;
                    }
                }

                // Set name
                if (string.IsNullOrEmpty(wpData.waypoint.name))
                {
                    CelestialBody body = FlightGlobals.Bodies.Where <CelestialBody>(b => b.name == wpData.waypoint.celestialName).First();
                    wpData.waypoint.name = StringUtilities.GenerateSiteName(contract.MissionSeed + i++, body, !wpData.waterAllowed);
                }

                AddWayPoint(wpData.waypoint);
            }
        }
Ejemplo n.º 2
0
        protected override bool Generate()
        {
            if (AreWingsUnlocked() == false)
            {
                return(false);
            }

            int offeredContracts = 0;
            int activeContracts  = 0;

            foreach (AerialContract contract in ContractSystem.Instance.GetCurrentContracts <AerialContract>())
            {
                if (contract.ContractState == Contract.State.Offered)
                {
                    offeredContracts++;
                }
                else if (contract.ContractState == Contract.State.Active)
                {
                    activeContracts++;
                }
            }

            if (offeredContracts >= FPConfig.Aerial.MaximumAvailable || activeContracts >= FPConfig.Aerial.MaximumActive)
            {
                return(false);
            }

            double range = 10000.0;

            System.Random        generator           = new System.Random(this.MissionSeed);
            int                  additionalWaypoints = 0;
            List <CelestialBody> allBodies           = GetBodies_Reached(true, false);
            List <CelestialBody> atmosphereBodies    = new List <CelestialBody>();

            foreach (CelestialBody body in allBodies)
            {
                if (body.atmosphere)
                {
                    atmosphereBodies.Add(body);
                }
            }

            if (atmosphereBodies.Count == 0)
            {
                return(false);
            }

            targetBody = atmosphereBodies[generator.Next(0, atmosphereBodies.Count)];

            //TODO: Find some common ground to calculate these values automatically without specific names.
            switch (targetBody.GetName())
            {
            case "Jool":
                additionalWaypoints = 0;
                minAltitude         = 15000.0;
                maxAltitude         = 30000.0;
                break;

            case "Duna":
                additionalWaypoints = 1;
                minAltitude         = 8000.0;
                maxAltitude         = 16000.0;
                break;

            case "Laythe":
                additionalWaypoints = 1;
                minAltitude         = 15000.0;
                maxAltitude         = 30000.0;
                break;

            case "Eve":
                additionalWaypoints = 1;
                minAltitude         = 20000.0;
                maxAltitude         = 40000.0;
                break;

            case "Kerbin":
                additionalWaypoints = 2;
                minAltitude         = 12500.0;
                maxAltitude         = 25000.0;
                break;

            default:
                additionalWaypoints = 0;
                minAltitude         = 0.0;
                maxAltitude         = 10000.0;
                break;
            }

            int   waypointCount          = 0;
            float fundsMultiplier        = 1;
            float scienceMultiplier      = 1;
            float reputationMultiplier   = 1;
            float wpFundsMultiplier      = 1;
            float wpScienceMultiplier    = 1;
            float wpReputationMultiplier = 1;

            double altitudeHalfQuarterRange = Math.Abs(maxAltitude - minAltitude) * 0.125;
            double upperMidAltitude         = ((maxAltitude + minAltitude) / 2.0) + altitudeHalfQuarterRange;
            double lowerMidAltitude         = ((maxAltitude + minAltitude) / 2.0) - altitudeHalfQuarterRange;

            minAltitude = Math.Round((minAltitude + (generator.NextDouble() * (lowerMidAltitude - minAltitude))) / 100.0) * 100.0;
            maxAltitude = Math.Round((upperMidAltitude + (generator.NextDouble() * (maxAltitude - upperMidAltitude))) / 100.0) * 100.0;

            switch (this.prestige)
            {
            case ContractPrestige.Trivial:
                waypointCount  = FPConfig.Aerial.TrivialWaypoints;
                waypointCount += additionalWaypoints;
                range          = FPConfig.Aerial.TrivialRange;

                if (Util.IsGasGiant(targetBody))
                {
                    if (generator.Next(0, 100) < FPConfig.Aerial.ExceptionalLowAltitudeChance / 2)
                    {
                        minAltitude  *= FPConfig.Aerial.ExceptionalLowAltitudeMultiplier;
                        maxAltitude  *= FPConfig.Aerial.ExceptionalLowAltitudeMultiplier;
                        isLowAltitude = true;
                    }
                }
                else
                {
                    if (generator.Next(0, 100) < FPConfig.Aerial.TrivialLowAltitudeChance)
                    {
                        minAltitude  *= FPConfig.Aerial.TrivialLowAltitudeMultiplier;
                        maxAltitude  *= FPConfig.Aerial.TrivialLowAltitudeMultiplier;
                        isLowAltitude = true;
                    }
                }

                if (generator.Next(0, 100) < FPConfig.Aerial.TrivialHomeNearbyChance && targetBody == Planetarium.fetch.Home)
                {
                    WaypointManager.ChooseRandomPositionNear(out centerLatitude, out centerLongitude, SpaceCenter.Instance.Latitude, SpaceCenter.Instance.Longitude, targetBody.GetName(), FPConfig.Aerial.TrivialHomeNearbyRange, true);
                }
                else
                {
                    WaypointManager.ChooseRandomPosition(out centerLatitude, out centerLongitude, targetBody.GetName(), true, false);
                }

                break;

            case ContractPrestige.Significant:
                waypointCount          = FPConfig.Aerial.SignificantWaypoints;
                waypointCount         += additionalWaypoints;
                range                  = FPConfig.Aerial.SignificantRange;
                fundsMultiplier        = FPConfig.Aerial.Funds.SignificantMultiplier;
                scienceMultiplier      = FPConfig.Aerial.Science.SignificantMultiplier;
                reputationMultiplier   = FPConfig.Aerial.Reputation.SignificantMultiplier;
                wpFundsMultiplier      = FPConfig.Aerial.Funds.WaypointSignificantMultiplier;
                wpScienceMultiplier    = FPConfig.Aerial.Science.WaypointSignificantMultiplier;
                wpReputationMultiplier = FPConfig.Aerial.Reputation.WaypointSignificantMultiplier;

                if (Util.IsGasGiant(targetBody))
                {
                    if (generator.Next(0, 100) < FPConfig.Aerial.SignificantLowAltitudeChance / 2)
                    {
                        minAltitude  *= FPConfig.Aerial.SignificantLowAltitudeMultiplier;
                        maxAltitude  *= FPConfig.Aerial.SignificantLowAltitudeMultiplier;
                        isLowAltitude = true;
                    }
                }
                else
                {
                    if (generator.Next(0, 100) < FPConfig.Aerial.SignificantLowAltitudeChance)
                    {
                        minAltitude  *= FPConfig.Aerial.SignificantLowAltitudeMultiplier;
                        maxAltitude  *= FPConfig.Aerial.SignificantLowAltitudeMultiplier;
                        isLowAltitude = true;
                    }
                }

                if (generator.Next(0, 100) < FPConfig.Aerial.SignificantHomeNearbyChance && targetBody == Planetarium.fetch.Home)
                {
                    WaypointManager.ChooseRandomPositionNear(out centerLatitude, out centerLongitude, SpaceCenter.Instance.Latitude, SpaceCenter.Instance.Longitude, targetBody.GetName(), FPConfig.Aerial.SignificantHomeNearbyRange, true);
                }
                else
                {
                    WaypointManager.ChooseRandomPosition(out centerLatitude, out centerLongitude, targetBody.GetName(), true, false);
                }

                break;

            case ContractPrestige.Exceptional:
                waypointCount          = FPConfig.Aerial.ExceptionalWaypoints;
                waypointCount         += additionalWaypoints;
                range                  = FPConfig.Aerial.ExceptionalRange;
                fundsMultiplier        = FPConfig.Aerial.Funds.ExceptionalMultiplier;
                scienceMultiplier      = FPConfig.Aerial.Science.ExceptionalMultiplier;
                reputationMultiplier   = FPConfig.Aerial.Reputation.ExceptionalMultiplier;
                wpFundsMultiplier      = FPConfig.Aerial.Funds.WaypointExceptionalMultiplier;
                wpScienceMultiplier    = FPConfig.Aerial.Science.WaypointExceptionalMultiplier;
                wpReputationMultiplier = FPConfig.Aerial.Reputation.WaypointExceptionalMultiplier;

                if (Util.IsGasGiant(targetBody))
                {
                    if (generator.Next(0, 100) < FPConfig.Aerial.TrivialLowAltitudeChance / 2)
                    {
                        minAltitude  *= FPConfig.Aerial.TrivialLowAltitudeMultiplier;
                        maxAltitude  *= FPConfig.Aerial.TrivialLowAltitudeMultiplier;
                        isLowAltitude = true;
                    }
                }
                else
                {
                    if (generator.Next(0, 100) < FPConfig.Aerial.ExceptionalLowAltitudeChance)
                    {
                        minAltitude  *= FPConfig.Aerial.ExceptionalLowAltitudeMultiplier;
                        maxAltitude  *= FPConfig.Aerial.ExceptionalLowAltitudeMultiplier;
                        isLowAltitude = true;
                    }
                }

                if (generator.Next(0, 100) < FPConfig.Aerial.ExceptionalHomeNearbyChance && targetBody == Planetarium.fetch.Home)
                {
                    WaypointManager.ChooseRandomPositionNear(out centerLatitude, out centerLongitude, SpaceCenter.Instance.Latitude, SpaceCenter.Instance.Longitude, targetBody.GetName(), FPConfig.Aerial.ExceptionalHomeNearbyRange, true);
                }
                else
                {
                    WaypointManager.ChooseRandomPosition(out centerLatitude, out centerLongitude, targetBody.GetName(), true, false);
                }

                break;
            }

            for (int x = 0; x < waypointCount; x++)
            {
                ContractParameter newParameter;
                newParameter = this.AddParameter(new FlightWaypointParameter(x, targetBody, minAltitude, maxAltitude, centerLatitude, centerLongitude, range), null);
                newParameter.SetFunds(Mathf.Round(FPConfig.Aerial.Funds.WaypointBaseReward * wpFundsMultiplier), targetBody);
                newParameter.SetReputation(Mathf.Round(FPConfig.Aerial.Reputation.WaypointBaseReward * wpReputationMultiplier), targetBody);
                newParameter.SetScience(Mathf.Round(FPConfig.Aerial.Science.WaypointBaseReward * wpScienceMultiplier), targetBody);
            }

            base.AddKeywords(new string[] { "surveyflight" });
            base.SetExpiry(FPConfig.Aerial.Expire.MinimumExpireDays, FPConfig.Aerial.Expire.MaximumExpireDays);
            base.SetDeadlineDays(FPConfig.Aerial.Expire.DeadlineDays, targetBody);
            base.SetFunds(Mathf.Round(FPConfig.Aerial.Funds.BaseAdvance * fundsMultiplier), Mathf.Round(FPConfig.Aerial.Funds.BaseReward * fundsMultiplier), Mathf.Round(FPConfig.Aerial.Funds.BaseFailure * fundsMultiplier), targetBody);
            base.SetScience(Mathf.Round(FPConfig.Aerial.Science.BaseReward * scienceMultiplier), targetBody);
            base.SetReputation(Mathf.Round(FPConfig.Aerial.Reputation.BaseReward * reputationMultiplier), Mathf.Round(FPConfig.Aerial.Reputation.BaseFailure * reputationMultiplier), targetBody);
            return(true);
        }
Ejemplo n.º 3
0
        public void Initialize()
        {
            if (!initialized)
            {
                LoggingUtil.LogVerbose(this, "Initializing waypoint generator.");
                foreach (WaypointData wpData in waypoints)
                {
                    CelestialBody body = FlightGlobals.Bodies.Where <CelestialBody>(b => b.name == wpData.waypoint.celestialName).FirstOrDefault();
                    if (body == null)
                    {
                        continue;
                    }

                    // Do type-specific waypoint handling
                    if (wpData.type == "RANDOM_WAYPOINT")
                    {
                        LoggingUtil.LogVerbose(this, "   Generating a random waypoint...");

                        while (true)
                        {
                            // Generate the position
                            WaypointManager.ChooseRandomPosition(out wpData.waypoint.latitude, out wpData.waypoint.longitude,
                                                                 wpData.waypoint.celestialName, wpData.waterAllowed, wpData.forceEquatorial, random);

                            // Force a water waypoint
                            if (wpData.underwater)
                            {
                                Vector3d radialVector = QuaternionD.AngleAxis(wpData.waypoint.longitude, Vector3d.down) *
                                                        QuaternionD.AngleAxis(wpData.waypoint.latitude, Vector3d.forward) * Vector3d.right;
                                if (body.pqsController.GetSurfaceHeight(radialVector) - body.pqsController.radius >= 0.0)
                                {
                                    continue;
                                }
                            }
                            break;
                        }
                    }
                    else if (wpData.type == "RANDOM_WAYPOINT_NEAR")
                    {
                        Waypoint nearWaypoint = waypoints[wpData.nearIndex].waypoint;

                        LoggingUtil.LogVerbose(this, "   Generating a random waypoint near waypoint {0}...", nearWaypoint.name);

                        if (!nearWaypoint.celestialBody.hasSolidSurface)
                        {
                            wpData.waterAllowed = true;
                        }


                        // Convert input to radians
                        double rlat1 = nearWaypoint.latitude * Math.PI / 180.0;
                        double rlon1 = nearWaypoint.longitude * Math.PI / 180.0;

                        for (int i = 0; i < 10000; i++)
                        {
                            // Sliding window
                            double window = (i < 100 ? 1 : (1.01 * (i - 100 + 1)));
                            double max    = wpData.maxDistance * window;
                            double min    = wpData.minDistance / window;

                            // Distance between our point and the random waypoint
                            double d = min + random.NextDouble() * (max - min);

                            // Random bearing
                            double brg = random.NextDouble() * 2.0 * Math.PI;

                            // Angle between our point and the random waypoint
                            double a = d / nearWaypoint.celestialBody.Radius;

                            // Calculate the coordinates
                            double rlat2 = Math.Asin(Math.Sin(rlat1) * Math.Cos(a) + Math.Cos(rlat1) * Math.Sin(a) * Math.Cos(brg));
                            double rlon2;

                            // Check for pole
                            if (Math.Abs(Math.Cos(rlat1)) < 0.0001)
                            {
                                rlon2 = rlon1;
                            }
                            else
                            {
                                rlon2 = ((rlon1 - Math.Asin(Math.Sin(brg) * Math.Sin(a) / Math.Cos(rlat2)) + Math.PI) % (2.0 * Math.PI)) - Math.PI;
                            }

                            wpData.waypoint.latitude  = rlat2 * 180.0 / Math.PI;
                            wpData.waypoint.longitude = rlon2 * 180.0 / Math.PI;

                            // Calculate the waypoint altitude
                            Vector3d radialVector = QuaternionD.AngleAxis(wpData.waypoint.longitude, Vector3d.down) *
                                                    QuaternionD.AngleAxis(wpData.waypoint.latitude, Vector3d.forward) * Vector3d.right;
                            double altitude = body.pqsController.GetSurfaceHeight(radialVector) - body.pqsController.radius;

                            // Check water conditions if required
                            if (!nearWaypoint.celestialBody.hasSolidSurface || !nearWaypoint.celestialBody.ocean || (wpData.waterAllowed && !wpData.underwater) || (wpData.underwater && altitude < 0) || (!wpData.underwater && altitude > 0))
                            {
                                break;
                            }
                        }
                    }
                    else if (wpData.type == "PQS_CITY")
                    {
                        GeneratePQSCityCoordinates(wpData, body);
                    }
                    else if (wpData.type == "LAUNCH_SITE")
                    {
                        GenerateLaunchSiteCoordinates(wpData, body);
                    }

                    // Set altitude
                    SetAltitude(wpData, body);

                    LoggingUtil.LogVerbose(this, "   Generated waypoint {0} at {1}, {2}.", wpData.waypoint.name, wpData.waypoint.latitude, wpData.waypoint.longitude);
                }

                initialized = true;
                LoggingUtil.LogVerbose(this, "Waypoint generator initialized.");
            }
        }
        public void Initialize()
        {
            if (!initialized)
            {
                LoggingUtil.LogVerbose(this, "Initializing waypoint generator.");
                foreach (WaypointData wpData in waypoints)
                {
                    CelestialBody body = FlightGlobals.Bodies.Where <CelestialBody>(b => b.name == wpData.waypoint.celestialName).FirstOrDefault();
                    if (body == null)
                    {
                        continue;
                    }

                    // Do type-specific waypoint handling
                    if (wpData.type == "RANDOM_WAYPOINT")
                    {
                        LoggingUtil.LogVerbose(this, "   Generating a random waypoint...");

                        while (true)
                        {
                            // Generate the position
                            WaypointManager.ChooseRandomPosition(out wpData.waypoint.latitude, out wpData.waypoint.longitude,
                                                                 wpData.waypoint.celestialName, wpData.waterAllowed, wpData.forceEquatorial, random);

                            // Force a water waypoint
                            if (wpData.underwater)
                            {
                                Vector3d radialVector = QuaternionD.AngleAxis(wpData.waypoint.longitude, Vector3d.down) *
                                                        QuaternionD.AngleAxis(wpData.waypoint.latitude, Vector3d.forward) * Vector3d.right;
                                if (body.pqsController.GetSurfaceHeight(radialVector) - body.pqsController.radius >= 0.0)
                                {
                                    continue;
                                }
                            }
                            break;
                        }
                    }
                    else if (wpData.type == "RANDOM_WAYPOINT_NEAR")
                    {
                        Waypoint nearWaypoint = waypoints[wpData.nearIndex].waypoint;

                        LoggingUtil.LogVerbose(this, "   Generating a random waypoint near waypoint " + nearWaypoint.name + "...");

                        // TODO - this is really bad, we need to implement this method ourselves...
                        do
                        {
                            WaypointManager.ChooseRandomPositionNear(out wpData.waypoint.latitude, out wpData.waypoint.longitude,
                                                                     nearWaypoint.latitude, nearWaypoint.longitude, wpData.waypoint.celestialName,
                                                                     wpData.maxDistance, wpData.waterAllowed, random);

                            // Force a water waypoint
                            if (wpData.underwater)
                            {
                                Vector3d radialVector = QuaternionD.AngleAxis(wpData.waypoint.longitude, Vector3d.down) *
                                                        QuaternionD.AngleAxis(wpData.waypoint.latitude, Vector3d.forward) * Vector3d.right;
                                if (body.pqsController.GetSurfaceHeight(radialVector) - body.pqsController.radius >= 0.0)
                                {
                                    continue;
                                }
                            }
                        } while (WaypointUtil.GetDistance(wpData.waypoint.latitude, wpData.waypoint.longitude, nearWaypoint.latitude, nearWaypoint.longitude,
                                                          body.Radius) < wpData.minDistance);
                    }
                    else if (wpData.type == "PQS_CITY")
                    {
                        GeneratePQSCityCoordinates(wpData, body);
                    }

                    // Set altitude
                    SetAltitude(wpData, body);

                    LoggingUtil.LogVerbose(this, "   Generated waypoint " + wpData.waypoint.name + " at " +
                                           wpData.waypoint.latitude + ", " + wpData.waypoint.longitude + ".");
                }

                initialized = true;
                LoggingUtil.LogVerbose(this, "Waypoint generator initialized.");
            }
        }
Ejemplo n.º 5
0
        protected override bool Generate()
        {
            if (AreWingsUnlocked() == false)
            {
                return(false);
            }

            //Allow four contracts in pocket but only two on the board at a time.
            int offeredContracts = 0;
            int activeContracts  = 0;

            foreach (AerialContract contract in ContractSystem.Instance.GetCurrentContracts <AerialContract>())
            {
                if (contract.ContractState == Contract.State.Offered)
                {
                    offeredContracts++;
                }
                else if (contract.ContractState == Contract.State.Active)
                {
                    activeContracts++;
                }
            }

            if (offeredContracts >= 2 || activeContracts >= 4)
            {
                return(false);
            }

            double range = 10000.0;

            System.Random        generator           = new System.Random(this.MissionSeed);
            int                  additionalWaypoints = 0;
            List <CelestialBody> allBodies           = GetBodies_Reached(true, false);
            List <CelestialBody> atmosphereBodies    = new List <CelestialBody>();

            foreach (CelestialBody body in allBodies)
            {
                if (body.atmosphere)
                {
                    atmosphereBodies.Add(body);
                }
            }

            if (atmosphereBodies.Count == 0)
            {
                return(false);
            }

            targetBody = atmosphereBodies[UnityEngine.Random.Range(0, atmosphereBodies.Count)];

            switch (targetBody.GetName())
            {
            case "Jool":
                additionalWaypoints = 0;
                minAltitude         = 15000.0;
                maxAltitude         = 30000.0;
                break;

            case "Duna":
                additionalWaypoints = 1;
                minAltitude         = 8000.0;
                maxAltitude         = 16000.0;
                break;

            case "Laythe":
                additionalWaypoints = 1;
                minAltitude         = 15000.0;
                maxAltitude         = 30000.0;
                break;

            case "Eve":
                additionalWaypoints = 1;
                minAltitude         = 20000.0;
                maxAltitude         = 40000.0;
                break;

            case "Kerbin":
                additionalWaypoints = 2;
                minAltitude         = 12500.0;
                maxAltitude         = 25000.0;
                break;

            default:
                additionalWaypoints = 0;
                minAltitude         = 0.0;
                maxAltitude         = 10000.0;
                break;
            }

            int    waypointCount            = 0;
            double altitudeHalfQuarterRange = Math.Abs(maxAltitude - minAltitude) * 0.125;
            double upperMidAltitude         = ((maxAltitude + minAltitude) / 2.0) + altitudeHalfQuarterRange;
            double lowerMidAltitude         = ((maxAltitude + minAltitude) / 2.0) - altitudeHalfQuarterRange;

            minAltitude = Math.Round((minAltitude + (generator.NextDouble() * (lowerMidAltitude - minAltitude))) / 100.0) * 100.0;
            maxAltitude = Math.Round((upperMidAltitude + (generator.NextDouble() * (maxAltitude - upperMidAltitude))) / 100.0) * 100.0;

            if (this.prestige == Contract.ContractPrestige.Trivial)
            {
                waypointCount  = 1;
                waypointCount += additionalWaypoints;
                range          = 100000.0;
            }
            else if (this.prestige == Contract.ContractPrestige.Significant)
            {
                waypointCount  = 2;
                waypointCount += additionalWaypoints;
                range          = 200000.0;
            }
            else if (this.prestige == Contract.ContractPrestige.Exceptional)
            {
                waypointCount  = 3;
                waypointCount += additionalWaypoints;
                range          = 300000.0;
            }

            WaypointManager.ChooseRandomPosition(out centerLatitude, out centerLongitude, targetBody.GetName(), true);

            for (int x = 0; x < waypointCount; x++)
            {
                ContractParameter newParameter;
                newParameter = this.AddParameter(new FlightWaypointParameter(x, targetBody, minAltitude, maxAltitude, centerLatitude, centerLongitude, range), null);
                newParameter.SetFunds(3750.0f, targetBody);
                newParameter.SetReputation(7.5f, targetBody);
                newParameter.SetScience(7.5f, targetBody);
            }

            base.AddKeywords(new string[] { "surveyflight" });
            base.SetExpiry();
            base.SetDeadlineYears(5.0f, targetBody);
            base.SetFunds(4000.0f, 17500.0f, targetBody);
            base.SetReputation(50.0f, 25.0f, targetBody);
            return(true);
        }
Ejemplo n.º 6
0
        protected override void OnOffered()
        {
            System.Random random = new System.Random(contract.MissionSeed);

            int index = 0;

            foreach (WaypointData wpData in waypoints)
            {
                // Do type-specific waypoint handling
                if (wpData.type == "RANDOM_WAYPOINT")
                {
                    // Generate the position
                    WaypointManager.ChooseRandomPosition(out wpData.waypoint.latitude, out wpData.waypoint.longitude,
                                                         wpData.waypoint.celestialName, wpData.waterAllowed, wpData.forceEquatorial, random);
                }
                else if (wpData.type == "RANDOM_WAYPOINT_NEAR")
                {
                    CelestialBody body         = FlightGlobals.Bodies.Where(b => b.name == wpData.waypoint.celestialName).First();
                    Waypoint      nearWaypoint = waypoints[wpData.nearIndex].waypoint;
                    // TODO - this is really bad, we need to implement this method ourselves...
                    do
                    {
                        WaypointManager.ChooseRandomPositionNear(out wpData.waypoint.latitude, out wpData.waypoint.longitude,
                                                                 nearWaypoint.latitude, nearWaypoint.longitude, wpData.waypoint.celestialName,
                                                                 wpData.maxDistance, wpData.waterAllowed, random);
                    } while (WaypointUtil.GetDistance(wpData.waypoint.latitude, wpData.waypoint.longitude, nearWaypoint.latitude, nearWaypoint.longitude,
                                                      body.Radius) < wpData.minDistance);
                }
                else if (wpData.type == "PQS_CITY")
                {
                    CelestialBody body     = FlightGlobals.Bodies.Where(b => b.name == wpData.waypoint.celestialName).First();
                    Vector3d      position = wpData.pqsCity.transform.position;

                    // Translate by the PQS offset (inverse transform of coordinate system)
                    Vector3d v         = wpData.pqsOffset;
                    Vector3d i         = wpData.pqsCity.transform.right;
                    Vector3d j         = wpData.pqsCity.transform.forward;
                    Vector3d k         = wpData.pqsCity.transform.up;
                    Vector3d offsetPos = new Vector3d(
                        (j.y * k.z - j.z * k.y) * v.x + (i.z * k.y - i.y * k.z) * v.y + (i.y * j.z - i.z * j.y) * v.z,
                        (j.z * k.x - j.x * k.z) * v.x + (i.x * k.z - i.z * k.x) * v.y + (i.z * j.x - i.x * j.z) * v.z,
                        (j.x * k.y - j.y * k.x) * v.x + (i.y * k.x - i.x * k.y) * v.y + (i.x * j.y - i.y * j.x) * v.z
                        );
                    offsetPos *= (i.x * j.y * k.z) + (i.y * j.z * k.x) + (i.z * j.x * k.y) - (i.z * j.y * k.x) - (i.y * j.x * k.z) - (i.x * j.z * k.y);
                    wpData.waypoint.latitude  = body.GetLatitude(position + offsetPos);
                    wpData.waypoint.longitude = body.GetLongitude(position + offsetPos);
                }

                // Set altitude
                if (wpData.randomAltitude)
                {
                    CelestialBody body = FlightGlobals.Bodies.Where <CelestialBody>(b => b.name == wpData.waypoint.celestialName).First();
                    if (body.atmosphere)
                    {
                        wpData.waypoint.altitude = random.NextDouble() * (body.atmosphereDepth);
                    }
                    else
                    {
                        wpData.waypoint.altitude = 0.0;
                    }
                }

                // Set name
                if (string.IsNullOrEmpty(wpData.waypoint.name))
                {
                    CelestialBody body = FlightGlobals.Bodies.Where <CelestialBody>(b => b.name == wpData.waypoint.celestialName).First();
                    wpData.waypoint.name = StringUtilities.GenerateSiteName(contract.MissionSeed + index++, body, !wpData.waterAllowed);
                }

                if (!wpData.hidden && (string.IsNullOrEmpty(wpData.parameter) || contract.AllParameters.
                                       Where(p => p.ID == wpData.parameter && p.State == ParameterState.Complete).Any()))
                {
                    AddWayPoint(wpData.waypoint);
                }
            }
        }
Ejemplo n.º 7
0
        protected override bool Generate()
        {
            if (AreWheelsUnlocked() == false)
            {
                return(false);
            }

            //Allow four contracts in pocket but only two on the board at a time.
            int offeredContracts = 0;
            int activeContracts  = 0;

            foreach (RoverContract contract in ContractSystem.Instance.GetCurrentContracts <RoverContract>())
            {
                if (contract.ContractState == Contract.State.Offered)
                {
                    offeredContracts++;
                }
                else if (contract.ContractState == Contract.State.Active)
                {
                    activeContracts++;
                }
            }

            if (offeredContracts >= FPConfig.Rover.MaximumAvailable || activeContracts >= FPConfig.Rover.MaximumActive)
            {
                return(false);
            }

            System.Random        generator = new System.Random(this.MissionSeed);
            double               range     = 10000.0;
            List <CelestialBody> bodies    = GetBodies_Reached(true, false);

            if (bodies.Count == 0)
            {
                return(false);
            }

            targetBody = bodies[generator.Next(0, bodies.Count)];

            if (Util.IsGasGiant(targetBody))
            {
                targetBody = Util.RandomNeighbor(MissionSeed, targetBody, false);

                if (Util.IsGasGiant(targetBody) || targetBody == null)
                {
                    return(false);
                }
            }

            int   waypointCount          = 0;
            float fundsMultiplier        = 1;
            float scienceMultiplier      = 1;
            float reputationMultiplier   = 1;
            float wpFundsMultiplier      = 1;
            float wpScienceMultiplier    = 1;
            float wpReputationMultiplier = 1;

            switch (this.prestige)
            {
            case ContractPrestige.Trivial:
                waypointCount = FPConfig.Rover.TrivialWaypoints;
                range         = FPConfig.Rover.TrivialRange;

                range /= 2;
                range  = range + range * targetBody.GeeASL;

                if (generator.Next(0, 100) < FPConfig.Rover.TrivialHomeNearbyChance && targetBody == Planetarium.fetch.Home)
                {
                    WaypointManager.ChooseRandomPositionNear(out centerLatitude, out centerLongitude, SpaceCenter.Instance.Latitude, SpaceCenter.Instance.Longitude, targetBody.GetName(), FPConfig.Rover.TrivialHomeNearbyRange, false);
                }
                else
                {
                    WaypointManager.ChooseRandomPosition(out centerLatitude, out centerLongitude, targetBody.GetName(), false, false);
                }

                break;

            case ContractPrestige.Significant:
                waypointCount          = FPConfig.Rover.SignificantWaypoints;
                range                  = FPConfig.Rover.SignificantRange;
                fundsMultiplier        = FPConfig.Rover.Funds.SignificantMultiplier;
                scienceMultiplier      = FPConfig.Rover.Science.SignificantMultiplier;
                reputationMultiplier   = FPConfig.Rover.Reputation.SignificantMultiplier;
                wpFundsMultiplier      = FPConfig.Rover.Funds.WaypointSignificantMultiplier;
                wpScienceMultiplier    = FPConfig.Rover.Science.WaypointSignificantMultiplier;
                wpReputationMultiplier = FPConfig.Rover.Reputation.WaypointSignificantMultiplier;

                range /= 2;
                range  = range + range * targetBody.GeeASL;

                if (generator.Next(0, 100) < FPConfig.Rover.SignificantHomeNearbyChance && targetBody == Planetarium.fetch.Home)
                {
                    WaypointManager.ChooseRandomPositionNear(out centerLatitude, out centerLongitude, SpaceCenter.Instance.Latitude, SpaceCenter.Instance.Longitude, targetBody.GetName(), FPConfig.Rover.SignificantHomeNearbyRange, false);
                }
                else
                {
                    WaypointManager.ChooseRandomPosition(out centerLatitude, out centerLongitude, targetBody.GetName(), false, false);
                }

                break;

            case ContractPrestige.Exceptional:
                waypointCount          = FPConfig.Rover.ExceptionalWaypoints;
                range                  = FPConfig.Rover.ExceptionalRange;
                fundsMultiplier        = FPConfig.Rover.Funds.ExceptionalMultiplier;
                scienceMultiplier      = FPConfig.Rover.Science.ExceptionalMultiplier;
                reputationMultiplier   = FPConfig.Rover.Reputation.ExceptionalMultiplier;
                wpFundsMultiplier      = FPConfig.Rover.Funds.WaypointExceptionalMultiplier;
                wpScienceMultiplier    = FPConfig.Rover.Science.WaypointExceptionalMultiplier;
                wpReputationMultiplier = FPConfig.Rover.Reputation.WaypointExceptionalMultiplier;

                range /= 2;
                range  = range + range * targetBody.GeeASL;

                if (generator.Next(0, 100) < FPConfig.Rover.ExceptionalHomeNearbyChance && targetBody == Planetarium.fetch.Home)
                {
                    WaypointManager.ChooseRandomPositionNear(out centerLatitude, out centerLongitude, SpaceCenter.Instance.Latitude, SpaceCenter.Instance.Longitude, targetBody.GetName(), FPConfig.Rover.ExceptionalHomeNearbyRange, false);
                }
                else
                {
                    WaypointManager.ChooseRandomPosition(out centerLatitude, out centerLongitude, targetBody.GetName(), false, false);
                }

                break;
            }

            int secret = generator.Next(0, waypointCount);

            for (int x = 0; x < waypointCount; x++)
            {
                ContractParameter newParameter;

                if (x == secret)
                {
                    newParameter = this.AddParameter(new RoverWaypointParameter(x, targetBody, centerLatitude, centerLongitude, range, true), null);
                }
                else
                {
                    newParameter = this.AddParameter(new RoverWaypointParameter(x, targetBody, centerLatitude, centerLongitude, range, false), null);
                }

                newParameter.SetFunds(Mathf.Round(FPConfig.Rover.Funds.WaypointBaseReward * wpFundsMultiplier), targetBody);
                newParameter.SetScience(Mathf.Round(FPConfig.Rover.Science.WaypointBaseReward * wpScienceMultiplier), targetBody);
                newParameter.SetReputation(Mathf.Round(FPConfig.Rover.Reputation.WaypointBaseReward * wpReputationMultiplier), targetBody);
            }

            base.AddKeywords(new string[] { "roversearch" });
            base.SetExpiry(FPConfig.Rover.Expire.MinimumExpireDays, FPConfig.Rover.Expire.MaximumExpireDays);
            base.SetDeadlineDays(FPConfig.Rover.Expire.DeadlineDays, targetBody);
            base.SetFunds(Mathf.Round(FPConfig.Rover.Funds.BaseAdvance * fundsMultiplier), Mathf.Round(FPConfig.Rover.Funds.BaseReward * fundsMultiplier), Mathf.Round(FPConfig.Rover.Funds.BaseFailure * fundsMultiplier), targetBody);
            base.SetScience(Mathf.Round(FPConfig.Rover.Science.BaseReward * scienceMultiplier), targetBody);
            base.SetReputation(Mathf.Round(FPConfig.Rover.Reputation.BaseReward * reputationMultiplier), Mathf.Round(FPConfig.Rover.Reputation.BaseFailure * reputationMultiplier), targetBody);
            return(true);
        }
Ejemplo n.º 8
0
        protected override bool Generate()
        {
            if (AreWheelsUnlocked() == false)
            {
                return(false);
            }

            //Allow four contracts in pocket but only two on the board at a time.
            int offeredContracts = 0;
            int activeContracts  = 0;

            foreach (RoverContract contract in ContractSystem.Instance.GetCurrentContracts <RoverContract>())
            {
                if (contract.ContractState == Contract.State.Offered)
                {
                    offeredContracts++;
                }
                else if (contract.ContractState == Contract.State.Active)
                {
                    activeContracts++;
                }
            }

            if (offeredContracts >= 2 || activeContracts >= 4)
            {
                return(false);
            }

            System.Random        generator = new System.Random(this.MissionSeed);
            double               range     = 10000.0;
            List <CelestialBody> bodies    = GetBodies_Reached(true, false);

            if (bodies.Count == 0)
            {
                return(false);
            }

            targetBody = bodies[generator.Next(0, bodies.Count)];

            if (targetBody.GetName() == "Jool")
            {
                targetBody = Util.RandomJoolianMoon();

                if (targetBody.GetName() == "Jool" || targetBody == null)
                {
                    return(false);
                }
            }

            int waypointCount = 0;

            if (this.prestige == Contract.ContractPrestige.Trivial)
            {
                waypointCount = 3;
                range         = 1000 + 1000 * targetBody.GeeASL;
            }
            else if (this.prestige == Contract.ContractPrestige.Significant)
            {
                waypointCount = 5;
                range         = 2000 + 2000 * targetBody.GeeASL;
            }
            else if (this.prestige == Contract.ContractPrestige.Exceptional)
            {
                waypointCount = 7;
                range         = 3000 + 3000 * targetBody.GeeASL;
            }

            WaypointManager.ChooseRandomPosition(out centerLatitude, out centerLongitude, targetBody.GetName(), false);
            int secret = UnityEngine.Random.Range(0, waypointCount);

            for (int x = 0; x < waypointCount; x++)
            {
                ContractParameter newParameter;

                if (x == secret)
                {
                    newParameter = this.AddParameter(new RoverWaypointParameter(x, targetBody, centerLatitude, centerLongitude, range, true), null);
                }
                else
                {
                    newParameter = this.AddParameter(new RoverWaypointParameter(x, targetBody, centerLatitude, centerLongitude, range, false), null);
                }

                newParameter.SetFunds(5000.0f, targetBody);
                newParameter.SetReputation(10.0f, targetBody);
                newParameter.SetScience(10.0f, targetBody);
            }

            base.AddKeywords(new string[] { "roversearch" });
            base.SetExpiry();
            base.SetDeadlineYears(5.0f, targetBody);
            base.SetFunds(4000.0f, 17500.0f, targetBody);
            base.SetReputation(50.0f, 25.0f, targetBody);
            return(true);
        }
Ejemplo n.º 9
0
        protected override bool Generate()
        {
            if (AreSatellitesUnlocked() == false)
            {
                return(false);
            }

            //Allow four contracts in pocket but only two on the board at a time.
            int offeredContracts = 0;
            int activeContracts  = 0;

            foreach (SatelliteContract contract in ContractSystem.Instance.GetCurrentContracts <SatelliteContract>())
            {
                if (contract.ContractState == Contract.State.Offered)
                {
                    offeredContracts++;
                }
                else if (contract.ContractState == Contract.State.Active)
                {
                    activeContracts++;
                }
            }

            if (offeredContracts >= FPConfig.Satellite.MaximumAvailable || activeContracts >= FPConfig.Satellite.MaximumActive)
            {
                return(false);
            }

            generator = new System.Random(this.MissionSeed);
            float rewardMultiplier = 1.0f;
            float partChance       = 10;

            if (this.prestige == Contract.ContractPrestige.Trivial)
            {
                List <CelestialBody> bodies = GetBodies_Reached(true, false);

                if (bodies.Count == 0)
                {
                    return(false);
                }

                targetBody = bodies[generator.Next(0, bodies.Count)];

                if (generator.Next(0, 100) < FPConfig.Satellite.TrivialSolarChance && FPConfig.Satellite.AllowSolar)
                {
                    targetBody = Planetarium.fetch.Sun;
                }

                //Prefer Kerbin
                if (generator.Next(0, 100) < FPConfig.Satellite.TrivialHomeOverrideChance && FPConfig.Satellite.PreferHome)
                {
                    targetBody = Planetarium.fetch.Home;
                }

                deviation        = FPConfig.Satellite.TrivialDeviation;
                difficultyFactor = FPConfig.Satellite.TrivialDifficulty;
                pickEasy();
                rewardMultiplier = 2.0f;
                partChance       = FPConfig.Satellite.TrivialPartChance;
            }
            else if (this.prestige == Contract.ContractPrestige.Significant)
            {
                List <CelestialBody> bodies = GetBodies_Reached(true, false);

                if (bodies.Count == 0)
                {
                    return(false);
                }

                targetBody = bodies[generator.Next(0, bodies.Count)];

                if (generator.Next(0, 100) < FPConfig.Satellite.SignificantSolarChance && FPConfig.Satellite.AllowSolar)
                {
                    targetBody = Planetarium.fetch.Sun;
                }

                //Prefer Kerbin
                if (generator.Next(0, 100) < FPConfig.Satellite.SignificantHomeOverrideChance && FPConfig.Satellite.PreferHome)
                {
                    targetBody = Planetarium.fetch.Home;
                }

                deviation        = FPConfig.Satellite.SignificantDeviation;
                difficultyFactor = FPConfig.Satellite.SignificantDifficulty;
                pickMedium();
                rewardMultiplier     = 2.5f;
                partChance           = FPConfig.Satellite.SignificantPartChance;
                fundsMultiplier      = FPConfig.Satellite.Funds.SignificantMultiplier;
                scienceMultiplier    = FPConfig.Satellite.Science.SignificantMultiplier;
                reputationMultiplier = FPConfig.Satellite.Reputation.SignificantMultiplier;
            }
            else if (this.prestige == Contract.ContractPrestige.Exceptional)
            {
                targetBody = GetNextUnreachedTarget(1, true, true);

                if (targetBody == null)
                {
                    List <CelestialBody> bodies = GetBodies_Reached(true, false);

                    if (bodies.Count == 0)
                    {
                        return(false);
                    }

                    targetBody = bodies[generator.Next(0, bodies.Count)];
                }

                if (generator.Next(0, 100) < FPConfig.Satellite.ExceptionalSolarChance && FPConfig.Satellite.AllowSolar)
                {
                    targetBody = Planetarium.fetch.Sun;
                }

                //Prefer Kerbin
                if (generator.Next(0, 100) < FPConfig.Satellite.ExceptionalHomeOverrideChance && FPConfig.Satellite.PreferHome)
                {
                    targetBody = Planetarium.fetch.Home;
                }

                deviation        = FPConfig.Satellite.ExceptionalDeviation;
                difficultyFactor = FPConfig.Satellite.ExceptionalDifficulty;
                pickHard();
                rewardMultiplier     = 3.0f;
                partChance           = FPConfig.Satellite.ExceptionalPartChance;
                fundsMultiplier      = FPConfig.Satellite.Funds.ExceptionalMultiplier;
                scienceMultiplier    = FPConfig.Satellite.Science.ExceptionalMultiplier;
                reputationMultiplier = FPConfig.Satellite.Reputation.ExceptionalMultiplier;
            }

            if (targetBody == null)
            {
                targetBody = Planetarium.fetch.Home;
            }

            if (orbitType == OrbitType.POLAR)
            {
                rewardMultiplier += 0.25f;
            }

            if (orbitType == OrbitType.STATIONARY || orbitType == OrbitType.SYNCHRONOUS)
            {
                rewardMultiplier += 0.5f;
            }

            if (orbitType == OrbitType.KOLNIYA || orbitType == OrbitType.TUNDRA)
            {
                rewardMultiplier += 1.0f;
            }

            this.AddParameter(new ProbeSystemsParameter(), null);

            double e = 0.0;

            if (orbitType == OrbitType.SYNCHRONOUS)
            {
                e = generator.NextDouble() * (difficultyFactor / 2);
            }
            Orbit o = Util.GenerateOrbit(orbitType, MissionSeed, targetBody, difficultyFactor, e);

            Util.PostProcessOrbit(ref o);

            this.AddParameter(new SpecificOrbitParameter(orbitType, o.inclination, o.eccentricity, o.semiMajorAxis, o.LAN, o.argumentOfPeriapsis, o.meanAnomalyAtEpoch, o.epoch, targetBody, difficultyFactor, deviation), null);

            if (orbitType == OrbitType.STATIONARY)
            {
                double latitude  = 0.0;
                double longitude = 0.0;
                WaypointManager.ChooseRandomPosition(out latitude, out longitude, targetBody.GetName(), false, true);
                this.AddParameter(new StationaryPointParameter(targetBody, longitude), null);
            }

            List <string> partList = FPConfig.Satellite.PartRequests.Replace(" ", "").Split(',').ToList();

            while (partList.Count > 0 && generator.Next(0, 101) <= partChance)
            {
                int    element = generator.Next(partList.Count);
                string part    = partList[element];
                partList.RemoveAt(element);

                if (Util.haveTechnology(part))
                {
                    AvailablePart ap = PartLoader.getPartInfoByName(part);
                    this.AddParameter(new PartNameParameter("Have a " + ap.title + " on the satellite", part));
                    fundsMultiplier      *= FPConfig.Satellite.Funds.PartMultiplier;
                    scienceMultiplier    *= FPConfig.Satellite.Science.PartMultiplier;
                    reputationMultiplier *= FPConfig.Satellite.Reputation.PartMultiplier;
                }
            }

            this.AddParameter(new KillControlsParameter(), null);

            switch (orbitType)
            {
            case OrbitType.POLAR:
                fundsMultiplier      *= FPConfig.Satellite.Funds.PolarMultiplier;
                scienceMultiplier    *= FPConfig.Satellite.Science.PolarMultiplier;
                reputationMultiplier *= FPConfig.Satellite.Reputation.PolarMultiplier;
                break;

            case OrbitType.SYNCHRONOUS:
                fundsMultiplier      *= FPConfig.Satellite.Funds.SynchronousMultiplier;
                scienceMultiplier    *= FPConfig.Satellite.Science.SynchronousMultiplier;
                reputationMultiplier *= FPConfig.Satellite.Reputation.SynchronousMultiplier;
                break;

            case OrbitType.STATIONARY:
                fundsMultiplier      *= FPConfig.Satellite.Funds.StationaryMultiplier;
                scienceMultiplier    *= FPConfig.Satellite.Science.StationaryMultiplier;
                reputationMultiplier *= FPConfig.Satellite.Reputation.StationaryMultiplier;
                break;

            case OrbitType.KOLNIYA:
                fundsMultiplier      *= FPConfig.Satellite.Funds.KolniyaMultiplier;
                scienceMultiplier    *= FPConfig.Satellite.Science.KolniyaMultiplier;
                reputationMultiplier *= FPConfig.Satellite.Reputation.KolniyaMultiplier;
                break;

            case OrbitType.TUNDRA:
                fundsMultiplier      *= FPConfig.Satellite.Funds.TundraMultiplier;
                scienceMultiplier    *= FPConfig.Satellite.Science.TundraMultiplier;
                reputationMultiplier *= FPConfig.Satellite.Reputation.TundraMultiplier;
                break;
            }

            if (targetBody == Planetarium.fetch.Home)
            {
                fundsMultiplier      *= FPConfig.Satellite.Funds.HomeMultiplier;
                scienceMultiplier    *= FPConfig.Satellite.Science.HomeMultiplier;
                reputationMultiplier *= FPConfig.Satellite.Reputation.HomeMultiplier;
            }

            base.AddKeywords(new string[] { "deploysatellite" });
            base.SetExpiry(FPConfig.Satellite.Expire.MinimumExpireDays, FPConfig.Satellite.Expire.MaximumExpireDays);
            base.SetDeadlineDays(FPConfig.Satellite.Expire.DeadlineDays, targetBody);
            base.SetFunds(Mathf.Round(FPConfig.Satellite.Funds.BaseAdvance * fundsMultiplier), Mathf.Round(FPConfig.Satellite.Funds.BaseReward * fundsMultiplier), Mathf.Round(FPConfig.Satellite.Funds.BaseFailure * fundsMultiplier), this.targetBody);
            base.SetScience(Mathf.Round(FPConfig.Satellite.Science.BaseReward * scienceMultiplier), this.targetBody);
            base.SetReputation(Mathf.Round(FPConfig.Satellite.Reputation.BaseReward * reputationMultiplier), Mathf.Round(FPConfig.Satellite.Reputation.BaseFailure * reputationMultiplier), targetBody);
            return(true);
        }