Пример #1
0
        /// <summary>
        /// Track the mission in the <see cref="PilotState"/> because some mission relevant details are only
        /// available in this journal entry.
        /// </summary>
        /// <param name="pilotState">
        /// A <see cref="PilotState"/> representing data associated with the pilot, such as the current station or system.
        /// </param>
        /// <param name="galaxyState">
        /// A <see cref="GalaxyState"/> reoresenting the Elite: Dangerous universe the pilot plays in.
        /// </param>
        /// <param name="supportedMinorFaction">
        /// The supported minor faction name. This must <b>exactly</b> match the name in the journal.
        /// </param>
        /// <param name="entry">
        /// A <see cref="JObject"/> representing the journal entry.
        /// </param>
        /// <returns>
        /// Will never return <see cref="SummaryEntry"/> objects.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// No argument can be null.
        /// </exception>
        public override IEnumerable <SummaryEntry> Process(PilotState pilotState, GalaxyState galaxyState, string supportedMinorFaction, JObject entry)
        {
            if (pilotState is null)
            {
                throw new ArgumentNullException(nameof(pilotState));
            }
            if (galaxyState is null)
            {
                throw new ArgumentNullException(nameof(galaxyState));
            }
            if (supportedMinorFaction is null)
            {
                throw new ArgumentNullException(nameof(supportedMinorFaction));
            }
            if (entry is null)
            {
                throw new ArgumentNullException(nameof(entry));
            }

            pilotState.Missions.Add(
                entry.Value <long>("MissionID"),
                new Mission(
                    entry.Value <long>("MissionID"),
                    entry.Value <string>("LocalisedName"),
                    entry.Value <string>("Influence"))
                );

            return(Enumerable.Empty <SummaryEntry>());
        }
        public void Constructor()
        {
            PilotState pilotState = new PilotState();

            Assert.That(pilotState.Missions, Is.Empty, "Missions is not empty");
            Assert.That(pilotState.LastDockedStation, Is.Null);
        }
Пример #3
0
        /// <summary>
        /// Track the mission in the <see cref="PilotState"/> because some mission relevant details are only
        /// available in this journal entry.
        /// </summary>
        /// <param name="pilotState">
        /// A <see cref="PilotState"/> representing data associated with the pilot, such as the current station or system.
        /// </param>
        /// <param name="galaxyState">
        /// A <see cref="GalaxyState"/> reoresenting the Elite: Dangerous universe the pilot plays in.
        /// </param>
        /// <param name="supportedMinorFaction">
        /// The supported minor faction name. This must <b>exactly</b> match the name in the journal.
        /// </param>
        /// <param name="entry">
        /// A <see cref="JObject"/> representing the journal entry.
        /// </param>
        /// <returns>
        /// Will never return <see cref="SummaryEntry"/> objects.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// No argument can be null.
        /// </exception>
        public override IEnumerable <SummaryEntry> Process(PilotState pilotState, GalaxyState galaxyState, string supportedMinorFaction, JObject entry)
        {
            if (pilotState is null)
            {
                throw new ArgumentNullException(nameof(pilotState));
            }
            if (galaxyState is null)
            {
                throw new ArgumentNullException(nameof(galaxyState));
            }
            if (supportedMinorFaction is null)
            {
                throw new ArgumentNullException(nameof(supportedMinorFaction));
            }
            if (entry is null)
            {
                throw new ArgumentNullException(nameof(entry));
            }

            // Create a new station instead of looking it up because the "Docked" event may be received before the "Location" event.
            pilotState.LastDockedStation = new Station(
                entry.Value <string>("StationName"),
                long.Parse(entry.Value <string>("SystemAddress")),
                entry["StationFaction"].Value <string>("Name")
                );

            return(Enumerable.Empty <SummaryEntry>());
        }
Пример #4
0
        public override IEnumerable <SummaryEntry> Process(PilotState pilotState, GalaxyState galaxyState, string supportedMinorFaction, JObject entry)
        {
            if (pilotState is null)
            {
                throw new ArgumentNullException(nameof(pilotState));
            }
            if (galaxyState is null)
            {
                throw new ArgumentNullException(nameof(galaxyState));
            }
            if (supportedMinorFaction is null)
            {
                throw new ArgumentNullException(nameof(supportedMinorFaction));
            }
            if (entry is null)
            {
                throw new ArgumentNullException(nameof(entry));
            }

            galaxyState.Systems[entry.Value <long>("SystemAddress")] = new StarSystem(
                entry.Value <long>("SystemAddress"),
                entry.Value <string>("StarSystem"),
                entry["Factions"]?.Select(o => o.Value <string>("Name")));

            return(Enumerable.Empty <SummaryEntry>());
        }
Пример #5
0
 private bool OncePerJump(PilotState flag)
 {
     if (!state.HasFlag(flag))
     {
         state |= flag;
         return(true);
     }
     return(false);
 }
Пример #6
0
 public void SwitchModeTo(PilotState newPilotMode)
 {
     if (newPilotMode == PilotState.NoPilot)
     {
         if (this.pilotMode == PilotState.Pilot)
         {
             this.YawAndPitchInput  = null;
             this.orbitPlanet       = null;
             this.orbitalPlanetDist = 0f;
             this.pilotMode         = newPilotMode;
         }
     }
     else if (newPilotMode == PilotState.Pilot)
     {
         this.YawAndPitchInput  = this.YawAndPitchPlayerInput;
         this.orbitPlanet       = null;
         this.orbitalPlanetDist = 0f;
         this.pilotMode         = newPilotMode;
     }
     else if (newPilotMode == PilotState.AutoPilot)
     {
         this.YawAndPitchInput  = this.YawAndPitchAutoPilotInput;
         this.orbitPlanet       = null;
         this.orbitalPlanetDist = 0f;
         this.pilotMode         = newPilotMode;
     }
     else if (newPilotMode == PilotState.OrbitAutoPilot)
     {
         if (this.pilotMode == PilotState.AutoPilot)
         {
             if (this.CanEnterOrbitalAutoPilotMode())
             {
                 this.YawAndPitchInput  = this.YawAndPitchOrbitAutoPilotInput;
                 this.orbitPlanet       = null;
                 this.orbitalPlanetDist = 0f;
                 this.pilotMode         = newPilotMode;
             }
         }
     }
     else if (newPilotMode == PilotState.Orbit)
     {
         if (this.pilotMode == PilotState.OrbitAutoPilot)
         {
             if (this.CanEnterOrbitalMode())
             {
                 this.orbitPlanet       = this.SelectedPlanet;
                 this.orbitalPlanetDist = this.SelectedPlanetDist;
                 this.targetSpeed       = Mathf.Sqrt(this.SelectedPlanet.Grav.mass / this.SelectedPlanetDist) / 10f;
                 this.YawAndPitchInput  = this.YawAndPitchOrbitInput;
                 this.pilotMode         = newPilotMode;
             }
         }
     }
 }
Пример #7
0
        public void ProcessSingleEntry(string journalEntry, string minorFaction, Mission mission, StarSystem system, IEnumerable <MissionSummaryEntry> expectedSummaryEntries)
        {
            MissionCompletedEntryProcessor missionCompletedEventProcessor = new MissionCompletedEntryProcessor();
            PilotState pilotState = new PilotState();
            // pilotState.Missions.Add(mission.Id, mission);
            GalaxyState galaxyState = new GalaxyState();
            // galaxyState.Systems.Add(system.SystemAdddress, system);

            JObject entry = new JournalEntryParser().Parse(journalEntry);

            IEnumerable <SummaryEntry> entries = missionCompletedEventProcessor.Process(pilotState, galaxyState, minorFaction, entry);

            Assert.That(entries, Is.Empty);
        }
        public void ProcessSingleEntry(string journalEntry, string supportedMinorFaction, IEnumerable <RedeemVoucherSummaryEntry> expectedSummaryEntries)
        {
            RedeemVoucherEntryProcessor dockedEventProcessor = new RedeemVoucherEntryProcessor();
            PilotState pilotState = new PilotState();

            pilotState.LastDockedStation = new Station("Quetelet Dock", 1, "The Sovereign Justice Collective");
            GalaxyState galaxyState = new GalaxyState();

            galaxyState.Systems[1] = new StarSystem(1, "Afli", new string[] { "The Sovereign Justice Collective", "Afli Silver Universal Exchange" });

            JObject entry = new JournalEntryParser().Parse(journalEntry);

            Assert.That(
                dockedEventProcessor.Process(pilotState, galaxyState, supportedMinorFaction, entry).Cast <RedeemVoucherSummaryEntry>(),
                Is.EquivalentTo(expectedSummaryEntries));
        }
        /// <summary>
        /// Add the bounty if it is relevant to the minor faction.
        /// </summary>
        /// <param name="pilotState">
        /// A <see cref="PilotState"/> representing data associated with the pilot, such as the current station or system.
        /// </param>
        /// <param name="galaxyState">
        /// A <see cref="GalaxyState"/> reoresenting the Elite: Dangerous universe the pilot plays in.
        /// </param>
        /// <param name="supportedMinorFaction">
        /// The supported minor faction name. This must <b>exactly</b> match the name in the journal.
        /// </param>
        /// <param name="entry">
        /// A <see cref="JObject"/> representing the journal entry.
        /// </param>
        /// <returns>
        /// Will never return <see cref="SummaryEntry"/> objects.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// No argument can be null.
        /// </exception>
        public override IEnumerable <SummaryEntry> Process(PilotState pilotState, GalaxyState galaxyState, string supportedMinorFaction, JObject entry)
        {
            if (supportedMinorFaction is null)
            {
                throw new ArgumentNullException(nameof(supportedMinorFaction));
            }
            if (entry is null)
            {
                throw new ArgumentNullException(nameof(entry));
            }
            if (pilotState.LastDockedStation == null)
            {
                throw new InvalidOperationException("Has not docked at a station");
            }
            if (!galaxyState.Systems.ContainsKey(pilotState.LastDockedStation.SystemAddress))
            {
                throw new InvalidOperationException($"System address { pilotState.LastDockedStation.SystemAddress } not found");
            }

            string  systemName = galaxyState.GetSystemName(pilotState.LastDockedStation.SystemAddress);
            Station station    = pilotState.LastDockedStation;

            List <SummaryEntry> result = new List <SummaryEntry>();

            if (entry.Value <string>(TypePropertyName) == BountyValue)
            {
                var categorizedEntries = entry.Value <JArray>(FactionsPropertyName)
                                         .Select(e => (JObject)e)
                                         .Select(e => new { Entry = e, FactionInfluence = GetFactionInfluence(supportedMinorFaction, e.Value <string>(FactionPropertyName), station.ControllingMinorFaction, galaxyState.Systems[pilotState.LastDockedStation.SystemAddress].MinorFactions) });
                result.AddRange(categorizedEntries
                                .Where(e => e.FactionInfluence == FactionInfluence.Increase)
                                .Select(e => new RedeemVoucherSummaryEntry(GetTimeStamp(entry), systemName, true, entry.Value <string>(TypePropertyName), e.Entry.Value <int>(AmountPropertyName))));
                result.AddRange(categorizedEntries
                                .Where(e => e.FactionInfluence == FactionInfluence.Decrease)
                                .Select(e => new RedeemVoucherSummaryEntry(GetTimeStamp(entry), systemName, false, entry.Value <string>(TypePropertyName), e.Entry.Value <int>(AmountPropertyName))));
            }
            else
            {
                FactionInfluence factionInfluence = GetFactionInfluence(supportedMinorFaction, entry.Value <string>(FactionPropertyName), station.ControllingMinorFaction, galaxyState.Systems[pilotState.LastDockedStation.SystemAddress].MinorFactions);
                if (factionInfluence != FactionInfluence.None)
                {
                    result.Add(new RedeemVoucherSummaryEntry(GetTimeStamp(entry), systemName, factionInfluence == FactionInfluence.Increase, entry.Value <string>(TypePropertyName), entry.Value <int>(AmountPropertyName)));
                }
            }

            return(result);
        }
        public void ProcessSingleEntry(string journalEntry, string minorFaction, string expectedStationName, long expectedSystemAddress, string expectedControllingMinorFaction)
        {
            DockedEntryProcessor dockedEventProcessor = new DockedEntryProcessor();
            PilotState           pilotState           = new PilotState();
            GalaxyState          galaxyState          = new GalaxyState();
            Station station = new Station(expectedStationName, expectedSystemAddress, expectedControllingMinorFaction);

            galaxyState.AddOrUpdateStation(station);

            JObject entry = new JournalEntryParser().Parse(journalEntry);

            IEnumerable <SummaryEntry> entries = dockedEventProcessor.Process(pilotState, galaxyState, minorFaction, entry);

            Assert.That(entries, Is.Empty);
            Assert.That(pilotState.Missions, Is.Empty);
            Assert.That(pilotState.LastDockedStation, Is.EqualTo(station));
        }
Пример #11
0
        public void Reset(bool soft)
        {
            // soft reset (after every jump)
            last_faceplant_time       = DateTime.UtcNow.AddHours(-1);
            SecondsUntilScoopComplete = 0.0;
            state &= PilotState.Enabled | PilotState.SysMap | PilotState.Cruise | PilotState.Honk | PilotState.Scoop; // clear per-jump flags
            if (soft)
            {
                return;
            }

            // hard reset (when user activates autopilot)
            state         |= PilotState.firstjump;
            state         |= PilotState.Faceplant; // no need to dodge the star until we have initiated a jump -- stops cruising from trying to dodge a star
            alignFrames    = 0;
            last_jump_time = DateTime.UtcNow.AddHours(-1);
        }
Пример #12
0
        /// <summary>
        /// This handles cruising behaviour. The main function is already keeping us aligned;
        /// we just need to drop to 75% speed.
        /// This function could also do the final part:
        ///  1. press G when the "SAFE DISENGAGE" graphic is detected
        ///  2. Wait 5 seconds
        ///  3. Press Tab, X, 1,E,E,Space,S,Space to boost, cut throttle, and request docking (so the docking computer takes over).
        /// </summary>
        private void Cruise()
        {
            if (SecondsSinceFaceplant > 20 && OncePerJump(PilotState.cruiseStart))
            {
                Sounds.Play("cruise mode engaged.mp3");
                keyboard.Tap(keyThrottle100);      // full throttle
                keyboard.Tap(keyThrottleReduce25); // drop 25% throttle, to 75%
            }

            if (!state.HasFlag(PilotState.CruiseEnd) && cruiseSensor.MatchSafDisengag())
            {
                keyboard.Tap(keyHyperspace); // "Safe Disengage"
                state |= PilotState.DisengageStarted;
                return;
            }

            // disengage can take a while so wait for it to finish before continuing
            if (!state.HasFlag(PilotState.CruiseEnd) &&
                state.HasFlag(PilotState.DisengageStarted) &&
                !cruiseSensor.MatchSafDisengag())
            {
                state |= PilotState.CruiseEnd;
                state &= ~PilotState.Enabled;                                   // disable! we've arrived!
                // these commands will initiate docking if we have a computer
                Task.Delay(1000).ContinueWith(t => keyboard.Tap(keyBoost));     // boost
                Task.Delay(5000).ContinueWith(t => keyboard.Tap(keyThrottle0)); // cut throttle
                Task.Delay(8000).ContinueWith(t =>                              // request docking
                {
                    if (!state.HasFlag(PilotState.Cruise))
                    {
                        return; // abort docking request if cruise gets turned off
                    }
                    Sounds.PlayOneOf("time to dock.mp3", "its dock oclock.mp3", "autopilot disengaged.mp3");
                    keyboard.TapWait(keyNavMenu);      // nav menu
                    keyboard.TapWait(keyMenuTabRight); // tab right
                    keyboard.Tap(keyMenuTabRight);     // tab right
                    keyboard.Tap(keySelect);           // select first contact (the station)
                    keyboard.Tap(keyDown);             // down to the second option (request docking)
                    keyboard.Tap(keySelect);           // select request docking
                    keyboard.Tap(keyNavMenu);          // close nav menu

                    state &= ~PilotState.Cruise;       // disable! we've arrived!
                });
            }
        }
Пример #13
0
        public void Test(string journal, SummaryEntry[] expectedSummaryEntries)
        {
            PilotState  pilotState            = new PilotState();
            GalaxyState galaxyState           = new GalaxyState();
            string      supportedMinorFaction = "EDA Kunti League";

            Assert.That(
                new StringJournalSource(journal).Entries
                .Select(new JournalEntryParser().Parse)
                .SelectMany(entry => new Summarizer(
                                Assembly.GetAssembly(typeof(JournalEntryProcessor))
                                .GetTypes()
                                .Where(t => t != typeof(JournalEntryProcessor) && t.IsAssignableFrom(typeof(JournalEntryProcessor)))
                                .Select(t => t.GetConstructor(new Type[0]).Invoke(new object[0]))
                                .Cast <JournalEntryProcessor>())
                            .Convert(pilotState, galaxyState, supportedMinorFaction, entry)),
                Is.EquivalentTo(expectedSummaryEntries));
        }
Пример #14
0
            //--------------- Pilot management ---------------

            public bool onUpdate()
            {
                if (remotePilot.IsAutoPilotEnabled)
                {
                    if (state == PilotState.DISABLED)
                    {
                        state = PilotState.DRIVING;
                    }
                    this.Objective = getCurrentObjective();
                    if (this.Objective != null)
                    {
                        double destination = Move();

                        if (destination < precisionFactor)
                        {// target reached
                            if (state == PilotState.AVOID)
                            {
                                state = PilotState.DRIVING;
                            }
                            bool hasAny = RemoveReachedObjective();
                            if (!hasAny)
                            {
                                uIManager.printOnScreens("service", "[SYS] AP destination reached");
                                remotePilot.HandBrake = true;
                                wheelController.ReleaseWheels();
                            }
                        }
                    }
                    else
                    {
                        // No waypoints in list
                        remotePilot.SetAutoPilotEnabled(false);
                        return(false);
                    }
                }
                else
                {
                    wheelController.ReleaseWheels();
                    state = PilotState.DISABLED;
                }
                return(true);
            }
Пример #15
0
            // Constructor
            public AutoPilotManager(IMyGridTerminalSystem myGridTerminalSystem, UIManager uIManager, float powerFactor, int precisionFactor, int scanDistance)
            {
                List <IMyRemoteControl> controllers = new List <IMyRemoteControl>();

                myGridTerminalSystem.GetBlocksOfType(controllers);

                foreach (IMyRemoteControl c in controllers)
                {
                    remotePilot      = c;
                    controlReference = remotePilot;
                }
                wheelController      = new WheelController(myGridTerminalSystem, controlReference);
                this.powerFactor     = powerFactor;
                this.precisionFactor = precisionFactor;
                maxScanDistance      = scanDistance;
                state               = PilotState.DRIVING;
                this.uIManager      = uIManager;
                collisionController = new CollisionController(myGridTerminalSystem, remotePilot.GetValueBool("CollisionAvoidance"));
                uIManager.printOnScreens("service", $"Found {collisionController.cameras.Count} cameras for collision detection.");
            }
        public void ProcessSingleEntry(string journalEntry, string minorFaction, long expectedMissionID, string expectedName, string expectedSourceMinorFactionName, string expectedTargetMinorFactionName, string expectedDestinationSystem)
        {
            MissionAcceptedEntryProcessor missionAcceptedEventProcessor = new MissionAcceptedEntryProcessor();
            PilotState  pilotState  = new PilotState();
            GalaxyState galaxyState = new GalaxyState();

            JObject entry = new JournalEntryParser().Parse(journalEntry);

            IEnumerable <SummaryEntry> entries = missionAcceptedEventProcessor.Process(pilotState, galaxyState, minorFaction, entry);

            Assert.That(entries, Is.Empty);
            Assert.That(pilotState.LastDockedStation, Is.Null);
            Assert.That(pilotState.Missions, Has.Count.EqualTo(1));
            Assert.That(pilotState.Missions.ContainsKey(expectedMissionID), Is.True);
            Assert.That(pilotState.Missions[expectedMissionID], Has.Property("Id").EqualTo(expectedMissionID));
            Assert.That(pilotState.Missions[expectedMissionID], Has.Property("Name").EqualTo(expectedName));
            // TODO: Fix
            // Assert.That(pilotState.Missions[expectedMissionID], Has.Property("Influence").EqualTo(expectedInfluence));

            //Assert.That(pilotState.Missions[expectedMissionID], Has.Property("SourceMinorFactionName").EqualTo(expectedSourceMinorFactionName));
            //Assert.That(pilotState.Missions[expectedMissionID], Has.Property("TargetMinorFactionName").EqualTo(expectedTargetMinorFactionName));
            //Assert.That(pilotState.Missions[expectedMissionID], Has.Property("DestinationSystem").EqualTo(expectedDestinationSystem));
        }
Пример #17
0
        public void ProcessSingleEntry(string journalEntry, string minorFaction, string expectedStationName, long expectedSystemAddress, string expectedSystemName, string expectedStationControllingMinorFaction, string[] expectedMinorFactions, string expectedSystemMinorFaction)
        {
            LocationEntryProcessor locationEntryProcessor = new LocationEntryProcessor();
            PilotState             pilotState             = new PilotState();
            GalaxyState            galaxyState            = new GalaxyState();

            JObject entry = new JournalEntryParser().Parse(journalEntry);

            IEnumerable <SummaryEntry> entries = locationEntryProcessor.Process(pilotState, galaxyState, minorFaction, entry);

            Assert.That(entries, Is.Empty);
            Assert.That(pilotState.Missions, Is.Empty);
            Assert.That(pilotState.LastDockedStation, Is.Not.Null);
            Assert.That(pilotState.LastDockedStation.Name, Is.EqualTo(expectedStationName));
            Assert.That(pilotState.LastDockedStation.SystemAddress, Is.EqualTo(expectedSystemAddress));
            Assert.That(pilotState.LastDockedStation.ControllingMinorFaction, Is.EqualTo(expectedStationControllingMinorFaction));

            Assert.That(galaxyState.Systems, Has.Count.EqualTo(1));
            Assert.That(galaxyState.Systems[expectedSystemAddress], Is.EqualTo(new StarSystem(expectedSystemAddress, expectedSystemName, expectedMinorFactions)));

            Assert.That(galaxyState.Stations, Has.Count.EqualTo(1));
            Assert.That(galaxyState.Stations, Is.EquivalentTo(new[] { new Station(expectedStationName, expectedSystemAddress, expectedStationControllingMinorFaction) }));
        }
Пример #18
0
            private double Move()
            {
                double destination = UpdatePosition();

                remotePilot.HandBrake = false;
                double tillCollision = -1;

                if (remotePilot.GetValueBool("CollisionAvoidance") && state == PilotState.DRIVING)
                {
                    double scanDistance = Math.Min(destination, maxScanDistance);
                    tillCollision = collisionController.checkForCollisions(scanDistance);
                }
                if (tillCollision != -1)
                {// collision detected, reduce speed and steer right
                    state = PilotState.AVOID;

                    Vector3D targetPosition = Vector3D.Transform(new Vector3D(10, 0, 10), controlReference.WorldMatrix);
                    addObjectiveFirst(targetPosition);
                    uIManager.printOnScreens("service", "[SYS] Avoiding collision");
                    return(destination);
                }
                Cruise(destination, remotePilot.SpeedLimit, RelativeTarget); // Apply Power
                return(destination);
            }
Пример #19
0
 /// <summary>
 /// Process the journal entry.
 /// </summary>
 /// <param name="pilotState">
 /// A <see cref="PilotState"/> representing data associated with the pilot, such as the current station or system.
 /// </param>
 /// <param name="galaxyState">
 /// A <see cref="GalaxyState"/> reoresenting the Elite: Dangerous universe the pilot plays in.
 /// </param>
 /// <param name="supportedMinorFaction">
 /// The supported minor faction name. This must <b>exactly</b> match the name in the journal.
 /// </param>
 /// <param name="entry">
 /// A <see cref="JObject"/> representing the journal entry.
 /// </param>
 /// <returns>
 /// Zero or more <see cref="SummaryEntry"/> objects representing actions that impact the supported minor faction.
 /// </returns>
 /// <exception cref="ArgumentNullException">
 /// No argument can be null.
 /// </exception>
 public abstract IEnumerable <SummaryEntry> Process(PilotState pilotState, GalaxyState galaxyState, string supportedMinorFaction, JObject entry);
        public override IEnumerable <SummaryEntry> Process(PilotState pilotState, GalaxyState galaxyState, string supportedMinorFaction, JObject entry)
        {
            if (pilotState is null)
            {
                throw new ArgumentNullException(nameof(pilotState));
            }
            if (galaxyState is null)
            {
                throw new ArgumentNullException(nameof(galaxyState));
            }
            if (supportedMinorFaction is null)
            {
                throw new ArgumentNullException(nameof(supportedMinorFaction));
            }
            if (entry is null)
            {
                throw new ArgumentNullException(nameof(entry));
            }

            List <SummaryEntry> result = new List <SummaryEntry>();
            string missionName         = pilotState.Missions.TryGetValue(entry.Value <long>("MissionID"), out Mission mission) ? mission.Name : entry.Value <string>("Name");

            foreach (JObject influenceObject in entry.Value <JArray>(FactionEffectsSectionName)
                     .SelectMany(e => e.Value <JArray>("Influence").Children <JObject>()))
            {
                string influenceFaction   = influenceObject.Parent.Parent.Parent.Value <string>("Faction");
                string entryFaction       = entry.Value <string>("Faction");
                string faction            = string.IsNullOrWhiteSpace(influenceFaction) ? entryFaction : influenceFaction;
                string entryTargetFaction = entry.Value <string>("TargetFaction");

                if (influenceObject.HasValues)
                {
                    string   systemName        = galaxyState.Systems.TryGetValue(influenceObject.Value <long>("SystemAddress"), out StarSystem system) ? system.Name : influenceObject.Value <string>("SystemAddress");
                    string   influence         = influenceObject.Value <string>("Influence");
                    bool     influenceIncrease = influenceObject.Value <string>("Trend") == "UpGood";
                    DateTime timeStamp         = GetTimeStamp(entry);

                    if (faction == supportedMinorFaction)
                    {
                        result.Add(new MissionSummaryEntry(
                                       timeStamp,
                                       missionName,
                                       systemName,
                                       influenceIncrease,
                                       influence));
                    }
                    else if (system != null &&
                             system.MinorFactions.Contains(supportedMinorFaction))
                    {
                        // && influenceIncrease
                        // Note that inclureases and decreases to minor faction influence other than the supported faction are harder to quantify.

                        result.Add(new MissionSummaryEntry(
                                       timeStamp,
                                       missionName,
                                       systemName,
                                       !influenceIncrease,
                                       influence));
                    }
                }
            }

            return(result);
        }
Пример #21
0
 public void SwitchModeTo(PilotState newPilotMode)
 {
     if (newPilotMode == PilotState.NoPilot) {
         if (this.pilotMode == PilotState.Pilot) {
             this.YawAndPitchInput = null;
             this.orbitPlanet = null;
             this.orbitalPlanetDist = 0f;
             this.pilotMode = newPilotMode;
         }
     }
     else if (newPilotMode == PilotState.Pilot) {
         this.YawAndPitchInput = this.YawAndPitchPlayerInput;
         this.orbitPlanet = null;
         this.orbitalPlanetDist = 0f;
         this.pilotMode = newPilotMode;
     }
     else if (newPilotMode == PilotState.AutoPilot) {
         this.YawAndPitchInput = this.YawAndPitchAutoPilotInput;
         this.orbitPlanet = null;
         this.orbitalPlanetDist = 0f;
         this.pilotMode = newPilotMode;
     }
     else if (newPilotMode == PilotState.OrbitAutoPilot) {
         if (this.pilotMode == PilotState.AutoPilot) {
             if (this.CanEnterOrbitalAutoPilotMode ()) {
                 this.YawAndPitchInput = this.YawAndPitchOrbitAutoPilotInput;
                 this.orbitPlanet = null;
                 this.orbitalPlanetDist = 0f;
                 this.pilotMode = newPilotMode;
             }
         }
     }
     else if (newPilotMode == PilotState.Orbit) {
         if (this.pilotMode == PilotState.OrbitAutoPilot) {
             if (this.CanEnterOrbitalMode ()) {
                 this.orbitPlanet = this.SelectedPlanet;
                 this.orbitalPlanetDist = this.SelectedPlanetDist;
                 this.targetSpeed = Mathf.Sqrt (this.SelectedPlanet.Grav.mass / this.SelectedPlanetDist) / 10f;
                 this.YawAndPitchInput = this.YawAndPitchOrbitInput;
                 this.pilotMode = newPilotMode;
             }
         }
     }
 }
Пример #22
0
 public PilotJumper()
 {
     state = PilotState.Scoop | PilotState.Honk | PilotState.Cruise; // these modes are enabled by default, but user can disable
 }
Пример #23
0
        /// <summary>
        /// Fly close past the star
        /// </summary>
        private void Scoop()
        {
            int scoopWaitSeconds   = Properties.Settings.Default.scoopWaitSeconds;
            int scoopFinishSeconds = Properties.Settings.Default.scoopFinishSeconds;

            //RIP-- WIP, I guess
            if (cruiseSensor.EmergencyDrop())
            {
                keyboard.Tap(keyThrottle0);
                state &= ~PilotState.Enabled; // disable! we're f****d!
                Sounds.Play("oh f**k.mp3");
                return;
            }

            // if we try to select the star earlier than this, sometimes it selects the wrong thing
            if (SecondsSinceFaceplant < 2)
            {
                return;
            }

            // roll so that the star is below (makes pitch up quicker -- less likely to collide in slow ships)
            if (OncePerJump(PilotState.SelectStar))
            {
                if (!SelectStar())
                {
                    keyboard.TapWait(keyThrottle0);
                    state &= ~PilotState.Enabled; // disable! we're f****d!
                    keyboard.TapWait(keySuperCruise);
                    Sounds.Play("oh f**k.mp3");
                    return;
                }
            }
            AlignCompass(bPitchYaw: false);

            //Set a value to confirm that we've actually started scooping
            if (OncePerJump(PilotState.ScoopStart))
            {
                keyboard.Tap(keyThrottle50); // 50% throttle
            }
            // (barely) avoid crashing into the star
            bool collisionImminent = cruiseSensor.MatchImpact() || compassRecognizer.MatchFaceplant();

            keyboard.SetKeyState(keyPitchUp, collisionImminent);

            // start speeding up towards the end so we don't crash/overheat
            // Keep the scoopwaitseconds as a "general idea" of when to start pulling up, at least until maybe a check for "full tank"
            if (SecondsSinceFaceplant > scoopWaitSeconds && OncePerJump(PilotState.ScoopMiddle))
            {
                keyboard.Tap(keyThrottle100);
            }

            //If the fueling is complete, we probably want to GTFO
            if (cruiseSensor.FuelComplete())
            {
                if (OncePerJump(PilotState.ScoopMiddle))
                {
                    keyboard.Tap(keyThrottle100);
                }
            }


            //If we've passed the expected wait point and the Scoop Active display is gone, flag appropriately and wait for scoopFinishSeconds to pass
            if (state.HasFlag(PilotState.ScoopMiddle) && !state.HasFlag(PilotState.ScoopDeactive) && !cruiseSensor.MatchScooping())
            {
                SecondsUntilScoopComplete = SecondsSinceFaceplant + scoopFinishSeconds;
                Console.WriteLine(string.Format("Match scooping is not true at {0}", SecondsSinceFaceplant));
                OncePerJump(PilotState.ScoopDeactive);
                status += string.Format("Finalizing scoop + {0:0.0}\n", SecondsSinceFaceplant);


                //We're far enough away from the scoop range for heat to be a non-issue
            }
            else if (state.HasFlag(PilotState.ScoopDeactive) && SecondsSinceFaceplant > SecondsUntilScoopComplete)
            {
                state  |= PilotState.scoopComplete;
                status += string.Format("Finalizing scoop + {0:0.0}\n", SecondsSinceFaceplant);
            }
            else
            {
                status += string.Format("Scoop wait + {0:0.0}\n", SecondsSinceFaceplant);
            }
        }
Пример #24
0
        /// <summary>
        /// Handle an input frame by setting which keys are pressed.
        /// </summary>
        public void Act()
        {
            status = "";

            if (!state.HasFlag(PilotState.Enabled))
            {
                Idle();
                return;
            }

            // perform the first alignment/jump immediately
            if (state.HasFlag(PilotState.firstjump) && jumps_remaining > 0)
            {
                StartJump();
                if (AlignTarget())
                {
                    Jump();
                }
                return;
            }

            // charging frendship drive (15s) / countdown (5s) / loading screen (~14-16s)
            if (SecondsSinceLastJump < 30)
            {
                status = string.Format("Waiting for jump, {0:0.0}", SecondsSinceLastJump);
                return;
            }

            // just in case, we should make sure no keys have been forgotten about
            if (OncePerJump(PilotState.clearedJump))
            {
                keyboard.Tap(keyThrottle0); // cut throttle
                keyboard.Clear();
            }

            // wait until we hit the star at the end of the loading screen (up to 100 seconds)
            if (!state.HasFlag(PilotState.Faceplant))
            {
                bool stationaryCompass = compassRecognizer.DetectStationaryCompass();
                if (stationaryCompass || compassRecognizer.MatchFaceplant() || SecondsSinceLastJump > 100)
                {
                    state |= PilotState.Faceplant;
                    last_faceplant_time = DateTime.UtcNow;
                    if (stationaryCompass)
                    {
                        // if the jump ended without detecting a star, it's probably a neutron star or black hole, so skip fuel scooping.
                        state |= PilotState.SkipThisScoop;
                    }
                }
                else
                {
                    status = string.Format("Waiting for jump end, {0:0.0}", SecondsSinceLastJump);
                    return; // keep waiting
                }
            }

            // don't do anything for a second after faceplant detection because the game sometimes doesn't register inputs
            if (SecondsSinceFaceplant < 1)
            {
                return;
            }


            // If we've finished jumping and are not cruising, just stop and point at the star (scan and makes scooping easier).
            if (jumps_remaining < 1 && !state.HasFlag(PilotState.Cruise))
            {
                if (OncePerJump(PilotState.swoopEnd))
                {
                    keyboard.Tap(keyThrottle0); // cut throttle
                }
                if (OncePerJump(PilotState.SelectStar))
                {
                    SelectStar();
                }

                AlignTarget();
                return;
            }

            if (!state.HasFlag(PilotState.scoopComplete))
            {
                if (state.HasFlag(PilotState.Scoop) &&
                    !state.HasFlag(PilotState.SkipThisScoop) &&
                    jumps_remaining > 0)
                {
                    Scoop();
                    return;
                }
                else
                {
                    // swoop a bit more if last jump because slow ship kept hitting star
                    if (SecondsSinceFaceplant < 30)
                    {
                        Swoop();
                        return;
                    }
                }
            }

            if (state.HasFlag(PilotState.Honk) && OncePerJump(PilotState.HonkComplete))
            {
                keyboard.Keydown(keyFire1);                                    // hooooooooooooonk
                Task.Delay(10000).ContinueWith(t => keyboard.Keyup(keyFire1)); // stop honking after ten seconds
                return;
            }

            // make sure we are travelling away from the star so that even if our next jump is directly behind it our turn will parallax it out of the way.
            // don't do it for the supcruz at the end because we can't reselect the in-system destination with the "N" key.
            if (!state.HasFlag(PilotState.AwayFromStar) && jumps_remaining > 0)
            {
                if (OncePerJump(PilotState.SelectStar))
                {
                    SelectStar();
                }

                // 10 because we want to make sure the honk finishes before opening the system map
                if (AntiAlign() && SecondsSinceFaceplant > 10)
                {
                    state |= PilotState.AwayFromStar;
                    keyboard.Tap(keyNextDestination);
                    keyboard.Tap(keyThrottle100);
                }

                return;
            }

            // okay, by this point we are cruising away from the star and are ready to align and jump. We can't start
            // charging to jump until 10 seconds after witchspace ends, but we can start aligning.

            if (jumps_remaining < 1 && state.HasFlag(PilotState.Cruise))
            {
                AlignTarget();
                Cruise();
            }
            else if (jumps_remaining > 0)
            {
                // start charging before we are aligned (saves time)
                if (!state.HasFlag(PilotState.SysMap))
                {
                    StartJump();
                }

                if (AlignTarget())
                {
                    Jump(); // do everything else
                }
            }
        }