/// <summary>
 /// Adds an IFlightControlParameter to the reference dictionary, and throws an error if it already exists.
 /// </summary>
 /// <param name="name">the bound name of the parameter, this will be converted to lower case internally</param>
 /// <param name="parameter"></param>
 public void AddFlightControlParameter(string name, IFlightControlParameter parameter)
 {
     name = name.ToLower();
     if (flightControlParameters.ContainsKey(name))
     {
         throw new Exception("Flight parameter by the name " + name + " already exists.");
     }
     flightControlParameters[name] = parameter;
 }
예제 #2
0
 private void setValue(object val)
 {
     if (name == "steering")
     {
         IFlightControlParameter param = kOSVesselModule.GetInstance(shared.Vessel).GetFlightControlParameter("steering");
         if (param != null)
         {
             param.UpdateValue(val, shared);
         }
     }
     else
     {
         value = val;
     }
 }
예제 #3
0
        /// <summary>
        /// After a decouple or part explosion, it's possible for this vessel to
        /// still have an assigned flight control parameter that is coming from
        /// a kOS core that is no longer on this vessel but is instead on the newly
        /// branched vessel we left behind.  If so, that parameter needs to be
        /// removed from this vessel.  The new kOSVesselModule will take care of
        /// making a new parameter on the new vessel, but this kOSVesselModule needs
        /// to detach it from this one.
        /// </summary>
        private void ResetPhysicallyDetachedParameters()
        {
            List <string> removeKeys = new List <string>();

            foreach (string key in flightControlParameters.Keys)
            {
                IFlightControlParameter p = flightControlParameters[key];
                if (p.GetShared() != null && p.GetShared().Vessel != null && Vessel != null &&
                    p.GetShared().Vessel.id != Vessel.id)
                {
                    removeKeys.Add(key);
                }
            }
            foreach (string key in removeKeys)
            {
                SafeHouse.Logger.SuperVerbose(string.Format(
                                                  "kOSVesselModule: re-defaulting parameter \"{0}\" because it's on a detached part of the vessel.", key));
                RemoveFlightControlParameter(key);
                IFlightControlParameter p = null;
                if (key.Equals("steering"))
                {
                    p = new SteeringManager(Vessel);
                }
                else if (key.Equals("throttle"))
                {
                    p = new ThrottleManager(Vessel);
                }
                else if (key.Equals("wheelsteering"))
                {
                    p = new WheelSteeringManager(Vessel);
                }
                else if (key.Equals("wheelthrottle"))
                {
                    p = new WheelThrottleManager(Vessel);
                }
                else if (key.Equals("flightcontrol"))
                {
                    p = new FlightControl(Vessel);
                }

                if (p != null)
                {
                    AddFlightControlParameter(key, p);
                }
            }
            foundWrongVesselAutopilot = false;
        }
        /// <summary>
        /// Generates a list of all processorModules included on the parentVessel.
        /// </summary>
        private void HarvestParts()
        {
            var proccessorModules = parentVessel.FindPartModulesImplementing <kOSProcessor>();

            foreach (var proc in proccessorModules)
            {
                childParts.Add(proc.part.flightID);
                uint id = proc.part.flightID;
                if (partLookup.ContainsKey(id) && partLookup[id].ID != ID)
                {
                    // If the part is already known and not associated with this module, then
                    // it is appearing as a result of a staging or undocking event (or something
                    // similar).  As such, we need to copy the information from the flight parameters
                    // on the originating module.
                    foreach (string key in flightControlParameters.Keys)
                    {
                        if (partLookup[id].HasFlightControlParameter(key))
                        {
                            // Only copy the data if the previous vessel module still has the parameter.
                            IFlightControlParameter paramDestination = flightControlParameters[key];
                            IFlightControlParameter paramOrigin      = partLookup[id].GetFlightControlParameter(key);
                            // We only want to copy the parameters themselves once (because they are vessel dependent
                            // not part dependent) but we still need to iterate through each part since "control"
                            // itself is part dependent.
                            if (partLookup[id].ID != BaseId)
                            {
                                paramDestination.CopyFrom(paramOrigin);
                            }
                            if (paramOrigin.Enabled && paramOrigin.ControlPartId == id)
                            {
                                // If this parameter was previously controlled by this part, re-enable
                                // control, copy it's Value setpoint, and disable control on the old parameter.
                                SharedObjects shared = paramOrigin.GetShared();
                                paramDestination.EnableControl(shared);
                                paramDestination.UpdateValue(paramOrigin.GetValue(), shared);
                                paramOrigin.DisableControl();
                            }
                        }
                    }
                    baseId = partLookup[id].ID; // Keep track of which vessel the parameters are based on.
                }
                partLookup[id] = this;
            }
            partCount = parentVessel.Parts.Count;
        }
예제 #5
0
            private void SteerByWire(FlightCtrlState c)
            {
                IFlightControlParameter param = kOSVesselModule.GetInstance(shared.Vessel).GetFlightControlParameter("steering");

                if (Enabled)
                {
                    if (!param.Enabled)
                    {
                        param.EnableControl(shared);
                    }
                }
                else
                {
                    if (param.Enabled && param.ControlPartId == shared.KSPPart.flightID)
                    {
                        param.DisableControl(shared);
                    }
                }
            }
예제 #6
0
        void IFlightControlParameter.CopyFrom(IFlightControlParameter origin)
        {
            object val = origin.GetValue();

            Value = Convert.ToDouble(val);
        }
예제 #7
0
        void IFlightControlParameter.CopyFrom(IFlightControlParameter origin)
        {
            return;

            throw new NotImplementedException(); // TODO: implement copy
        }
예제 #8
0
 void IFlightControlParameter.CopyFrom(IFlightControlParameter origin)
 {
     SteeringManager smOrigin = origin as SteeringManager;
     if (smOrigin != null)
     {
         Copy(smOrigin, this);
     }
 }
예제 #9
0
 /// <summary>
 /// Adds an IFlightControlParameter to the reference dictionary, and throws an error if it already exists.
 /// </summary>
 /// <param name="name">the bound name of the parameter, this will be converted to lower case internally</param>
 /// <param name="parameter"></param>
 public void AddFlightControlParameter(string name, IFlightControlParameter parameter)
 {
     name = name.ToLower();
     if (flightControlParameters.ContainsKey(name))
         throw new Exception("Flight parameter by the name " + name + " already exists.");
     flightControlParameters[name] = parameter;
 }