コード例 #1
0
        private void OnExecClick()
        {
            if (mFlightComputer.Vessel.patchedConicSolver == null || mFlightComputer.Vessel.patchedConicSolver.maneuverNodes.Count == 0)
            {
                return;
            }
            var cmd = ManeuverCommand.WithNode(0, mFlightComputer);

            if (cmd.TimeStamp < RTUtil.GameTime + mFlightComputer.Delay)
            {
                RTUtil.ScreenMessage(Localizer.Format("#RT_FC_msg5"));//"[Flight Computer]: Signal delay is too high to execute this maneuver at the proper time."
            }
            else
            {
                mFlightComputer.Enqueue(cmd, false, false, true);

                //check for subsequent nodes
                int numSubsequentNodes = mFlightComputer.Vessel.patchedConicSolver.maneuverNodes.Count - 1;
                if (numSubsequentNodes >= 1)
                {
                    for (int nodeIndex = 1; nodeIndex <= numSubsequentNodes; nodeIndex++)
                    {
                        mFlightComputer.Enqueue(ManeuverCommand.WithNode(nodeIndex, mFlightComputer), false, false, true);
                    }
                }
            }
        }
コード例 #2
0
        public override bool Pop(FlightComputer f)
        {
            var burn = f.ActiveCommands.FirstOrDefault(c => c is BurnCommand);

            if (burn != null)
            {
                f.Remove(burn);
            }

            OriginalDelta        = Node.DeltaV.magnitude;
            RemainingDelta       = this.getRemainingDeltaV(f);
            this.EngineActivated = true;

            double thrustToMass = FlightCore.GetTotalThrust(f.Vessel) / f.Vessel.GetTotalMass();

            if (thrustToMass == 0.0)
            {
                this.EngineActivated = false;
                RTUtil.ScreenMessage("[Flight Computer]: No engine to carry out the maneuver.");
            }
            else
            {
                RemainingTime = RemainingDelta / thrustToMass;
            }

            return(true);
        }
コード例 #3
0
ファイル: ManeuverCommand.cs プロジェクト: ozraven/RemoteTech
 /// <summary>
 ///
 /// </summary>
 /// <param name="computer">FlightComputer instance of the computer of the vessel.</param>
 private void AbortManeuver(FlightComputer computer)
 {
     RTUtil.ScreenMessage("[Flight Computer]: Maneuver removed");
     if (computer.Vessel.patchedConicSolver != null)
     {
         Node.RemoveSelf();
     }
     // enqueue kill rot
     computer.Enqueue(AttitudeCommand.KillRot(), true, true, true);
 }
コード例 #4
0
ファイル: AttitudeFragment.cs プロジェクト: zmpeg/RemoteTech
        private void OnExecClick()
        {
            if (mFlightComputer.Vessel.patchedConicSolver == null || mFlightComputer.Vessel.patchedConicSolver.maneuverNodes.Count == 0)
            {
                return;
            }
            var cmd = ManeuverCommand.WithNode(0, mFlightComputer);

            if (cmd.TimeStamp < RTUtil.GameTime + mFlightComputer.Delay)
            {
                RTUtil.ScreenMessage("[Flight Computer]: Signal delay is too high to execute this maneuver at the proper time.");
            }
            else
            {
                mFlightComputer.Enqueue(cmd, false, false, true);
            }
        }
コード例 #5
0
        public override bool Pop(FlightComputer f)
        {
            if (f.Vessel.patchedConicSolver == null)
            {
                f.Vessel.AttachPatchedConicsSolver();
                f.Vessel.patchedConicSolver.Update();
            }

            if (this.Node.solver == null)                                // need to repair (due to the scenario of 2 vessels within phyical range)
            {
                if (f.Vessel.patchedConicSolver.maneuverNodes.Count < 1) // no nodes
                {
                    RTUtil.ScreenMessage("[Flight Computer]: No maneuver node to execute.");
                    return(false);
                }

                this.Node = f.Vessel.patchedConicSolver.maneuverNodes.Find(x => x.UT == this.Node.UT);
            }

            var burn = f.ActiveCommands.FirstOrDefault(c => c is BurnCommand);

            if (burn != null)
            {
                f.Remove(burn);
            }

            OriginalDelta        = Node.DeltaV.magnitude;
            RemainingDelta       = this.getRemainingDeltaV(f);
            this.EngineActivated = true;

            double thrustToMass = FlightCore.GetTotalThrust(f.Vessel) / f.Vessel.GetTotalMass();

            if (thrustToMass == 0.0)
            {
                this.EngineActivated = false;
                RTUtil.ScreenMessage("[Flight Computer]: No engine to carry out the maneuver.");
            }
            else
            {
                RemainingTime = RemainingDelta / thrustToMass;
            }

            f.PIDController.setPIDParameters(FlightComputer.PIDKp, FlightComputer.PIDKi, FlightComputer.PIDKd);

            return(true);
        }
コード例 #6
0
        public override bool Pop(FlightComputer f)
        {
            if (f.Vessel.patchedConicSolver == null)
            {
                f.Vessel.AttachPatchedConicsSolver();
                f.Vessel.patchedConicSolver.Update();
            }

            // check if the stored node is still valid
            if (f.Vessel.patchedConicSolver.maneuverNodes.FindIndex(x => x.UT == this.Node.UT && x.DeltaV == this.Node.DeltaV) < 0)//IndexOf() is bad comparer
            {
                RTUtil.ScreenMessage("[Flight Computer]: No maneuver node found.");
                return(false);
            }

            if (this.Node.solver == null) // need to repair (due to the scenario of 2 vessels within phyical range)
            {
                this.Node = f.Vessel.patchedConicSolver.maneuverNodes.Find(x => x.UT == this.Node.UT && x.DeltaV == this.Node.DeltaV);
            }

            var burn = f.ActiveCommands.FirstOrDefault(c => c is BurnCommand);

            if (burn != null)
            {
                f.Remove(burn);
            }

            OriginalDelta        = Node.DeltaV.magnitude;
            RemainingDelta       = this.getRemainingDeltaV(f);
            this.EngineActivated = true;

            double thrustToMass = FlightCore.GetTotalThrust(f.Vessel) / f.Vessel.GetTotalMass();

            if (thrustToMass == 0.0)
            {
                this.EngineActivated = false;
                RTUtil.ScreenMessage("[Flight Computer]: No engine to carry out the maneuver.");
            }
            else
            {
                RemainingTime = RemainingDelta / thrustToMass;
            }

            return(true);
        }
コード例 #7
0
ファイル: ManeuverCommand.cs プロジェクト: zmpeg/RemoteTech
        /// <summary>
        ///
        /// </summary>
        /// <param name="computer">FlightComputer instance of the computer of the vessel.</param>
        private void AbortManeuver(FlightComputer computer)
        {
            RTUtil.ScreenMessage("[Flight Computer]: Maneuver removed");
            if (computer.Vessel.patchedConicSolver != null)
            {
                Node.RemoveSelf();
            }

            // Flight Computer mode after execution based on settings
            if (RTSettings.Instance.FCOffAfterExecute)
            {
                computer.Enqueue(AttitudeCommand.Off(), true, true, true);
            }
            if (!RTSettings.Instance.FCOffAfterExecute)
            {
                computer.Enqueue(AttitudeCommand.KillRot(), true, true, true);
            }
        }
コード例 #8
0
 /// <summary>
 /// Loads the ExternalAPICommand from the persistent file. If the loading
 /// can't find the <see cref="ReflectionType"/> we'll notify a ScreenMessage
 /// and remove the command.
 /// </summary>
 /// <param name="node">Node with the command infos to load</param>
 /// <param name="computer">Current flightcomputer</param>
 /// <returns>true - loaded successfull</returns>
 public override bool Load(ConfigNode node, FlightComputer computer)
 {
     try
     {
         if (base.Load(node, computer))
         {
             if (node.HasNode("ExternalData"))
             {
                 this.ConfigNodeToObject(this, node.GetNode("ExternalData"));
                 // try loading the reflectionType
                 this.getReflectionType(this.ReflectionType);
                 return(true);
             }
         }
     }
     catch (Exception)
     {
         RTUtil.ScreenMessage(string.Format("Mod '{0}' not found. Queued command '{1}' will be removed.", this.Executor, this.ShortName));
     }
     return(false);
 }
コード例 #9
0
        /// <summary>
        /// Restores the flightcomputer from the persistant
        /// </summary>
        /// <param name="n">Node with the informations for the flightcomputer</param>
        public void load(ConfigNode n)
        {
            RTLog.Notify("Loading Flightcomputer from persistent!");

            if (!n.HasNode("FlightComputer"))
            {
                return;
            }

            // Wait while we are packed and store the current configNode
            if (Vessel.packed)
            {
                RTLog.Notify("Save flightconfig after unpacking");
                fcLoadedConfigs = n;
                return;
            }

            // Load the current vessel from signalprocessor if we've no on the flightcomputer
            if (Vessel == null)
            {
                Vessel = SignalProcessor.Vessel;
                mRoverComputer.SetVessel(Vessel);
            }

            // Read Flightcomputer informations
            ConfigNode FlightNode = n.GetNode("FlightComputer");

            TotalDelay = double.Parse(FlightNode.GetValue("TotalDelay"));
            ConfigNode ActiveCommands = FlightNode.GetNode("ActiveCommands");
            ConfigNode Commands       = FlightNode.GetNode("Commands");

            // Read active commands
            if (ActiveCommands.HasNode())
            {
                if (mActiveCommands.Count > 0)
                {
                    mActiveCommands.Clear();
                }
                foreach (ConfigNode cmdNode in ActiveCommands.nodes)
                {
                    ICommand cmd = AbstractCommand.LoadCommand(cmdNode, this);

                    if (cmd != null)
                    {
                        mActiveCommands[cmd.Priority] = cmd;
                        cmd.Pop(this);
                    }
                }
            }

            // Read queued commands
            if (Commands.HasNode())
            {
                int qCounter = 0;

                // clear the current list
                if (mCommandQueue.Count > 0)
                {
                    mCommandQueue.Clear();
                }

                RTLog.Notify("Loading queued commands from persistent ...");
                foreach (ConfigNode cmdNode in Commands.nodes)
                {
                    ICommand cmd = AbstractCommand.LoadCommand(cmdNode, this);

                    if (cmd != null)
                    {
                        // if delay = 0 we're ready for the extraDelay
                        if (cmd.Delay == 0)
                        {
                            if (cmd is ManeuverCommand)
                            {
                                // TODO: Need better text
                                RTUtil.ScreenMessage("You missed the maneuver burn!");
                                continue;
                            }

                            // if extraDelay is set, we've to calculate the elapsed time
                            // and set the new extradelay based on the current time
                            if (cmd.ExtraDelay > 0)
                            {
                                cmd.ExtraDelay = cmd.TimeStamp + cmd.ExtraDelay - RTUtil.GameTime;

                                // Are we ready to handle the command ?
                                if (cmd.ExtraDelay <= 0)
                                {
                                    if (cmd is BurnCommand)
                                    {
                                        // TODO: Need better text
                                        RTUtil.ScreenMessage("You missed the burn command!");
                                        continue;
                                    }
                                    else
                                    {
                                        // change the extra delay to x/100
                                        cmd.ExtraDelay = (qCounter) / 100;
                                    }
                                }
                            }
                        }
                        mCommandQueue.Add(cmd);
                    }
                }
            }
        }
コード例 #10
0
        /// <summary>Restores the flight computer from the persistent save.</summary>
        /// <param name="configNode">Node with the informations for the flight computer</param>
        public void Load(ConfigNode configNode)
        {
            RTLog.Notify("Loading Flightcomputer from persistent!");

            if (!configNode.HasNode("FlightComputer"))
            {
                return;
            }

            // Wait while we are packed and store the current configNode
            if (Vessel.packed)
            {
                RTLog.Notify("Save Flightconfig after unpacking");
                _fcLoadedConfigs = configNode.CreateCopy();
                //Apparently, _fcLoadedConfigs (resided at memory pointer of configNode) is changed at 1 point before loading into FC. CreateCopy() duplicates the content to a separate memory space.
                return;
            }

            // Load the current vessel from signal processor if we haven't one the flight computer
            if (Vessel == null)
            {
                Vessel = SignalProcessor.Vessel;
                RoverComputer.SetVessel(Vessel);
                PIDController.SetVessel(Vessel);
            }

            // Read Flight computer informations
            var flightNode = configNode.GetNode("FlightComputer");

            TotalDelay = double.Parse(flightNode.GetValue("TotalDelay"));
            var activeCommands = flightNode.GetNode("ActiveCommands");
            var commands       = flightNode.GetNode("Commands");

            // Read active commands
            if (activeCommands.HasNode())
            {
                if (_activeCommands.Count > 0)
                {
                    _activeCommands.Clear();
                }

                foreach (ConfigNode cmdNode in activeCommands.nodes)
                {
                    var cmd = AbstractCommand.LoadCommand(cmdNode, this);
                    if (cmd == null)
                    {
                        continue;
                    }

                    _activeCommands[cmd.Priority] = cmd;
                    cmd.Pop(this);
                }
            }

            // Read queued commands
            if (commands.HasNode())
            {
                // clear the current list
                if (_commandQueue.Count > 0)
                {
                    _commandQueue.Clear();
                }

                RTLog.Notify("Loading queued commands from persistent ...");
                foreach (ConfigNode cmdNode in commands.nodes)
                {
                    var cmd = AbstractCommand.LoadCommand(cmdNode, this);
                    if (cmd == null)
                    {
                        continue;
                    }

                    // if delay = 0 we're ready for the extraDelay
                    if (cmd.Delay == 0)
                    {
                        if (cmd is ManeuverCommand)
                        {
                            RTUtil.ScreenMessage(Localizer.Format("#RT_FC_msg3"));//"A maneuver burn is required"
                            continue;
                        }

                        // if extraDelay is set, we've to calculate the elapsed time
                        // and set the new extra delay based on the current time
                        if (cmd.ExtraDelay > 0)
                        {
                            cmd.ExtraDelay = cmd.TimeStamp + cmd.ExtraDelay - RTUtil.GameTime;

                            // Are we ready to handle the command ?
                            if (cmd.ExtraDelay <= 0)
                            {
                                if (cmd is BurnCommand)
                                {
                                    RTUtil.ScreenMessage(Localizer.Format("#RT_FC_msg4"));//"A burn command is required"
                                    continue;
                                }

                                // change the extra delay to x/100
                                cmd.ExtraDelay = Math.Abs(cmd.ExtraDelay) / 100;
                            }
                        }
                    }
                    // add command to queue
                    _commandQueue.Add(cmd);
                }
            }

            UpdateLastTarget();
        }