コード例 #1
0
        /// <summary>
        /// Checks whether the given vessel meets the condition, and completes the contract parameter as necessary.
        /// </summary>
        /// <param name="vessel">The vessel to check.</param>
        protected virtual void CheckVessel(Vessel vessel, bool forceStateChange = false)
        {
            // No vessel to check.
            if (vessel == null)
            {
                return;
            }

            LoggingUtil.LogVerbose(this, "-> CheckVessel(" + vessel.id + ")");
            if (IsIgnoredVesselType(vessel.vesselType))
            {
                LoggingUtil.LogVerbose(this, "<- CheckVessel");
                return;
            }

            VesselParameterGroup vpg = GetParameterGroupHost();

            if (CanCheckVesselMeetsCondition(vessel))
            {
                // Using VesselParameterGroup logic
                if (vpg != null)
                {
                    // Set the craft specific state
                    bool stateChanged = SetState(vessel, VesselMeetsCondition(vessel) ?
                                                 Contracts.ParameterState.Complete : Contracts.ParameterState.Incomplete) || forceStateChange;

                    // Update the group
                    if (stateChanged)
                    {
                        vpg.UpdateState(vessel);
                    }
                }
                // Logic applies only to active vessel
                else if (vessel.isActiveVessel)
                {
                    if (VesselMeetsCondition(vessel))
                    {
                        SetState(ParameterState.Complete);
                        if (!allowStateReset)
                        {
                            Disable();
                        }
                    }
                    else
                    {
                        SetState(ParameterState.Incomplete);
                    }
                }

                // Special handling for parameter delegates
                if (ChildChanged)
                {
                    LoggingUtil.LogVerbose(this, "Firing onParameterChange due to ChildChanged = true");
                    ContractConfigurator.OnParameterChange.Fire(this.Root, this);
                    ChildChanged = false;
                }
            }
            LoggingUtil.LogVerbose(this, "<- CheckVessel");
        }
コード例 #2
0
        protected virtual void OnFlightReady()
        {
            CheckVessel(FlightGlobals.ActiveVessel);

            // Set parameters properly on first load
            if (FlightGlobals.ActiveVessel != null)
            {
                VesselParameterGroup vpg = GetParameterGroupHost();
                if (vpg != null)
                {
                    vpg.UpdateState(FlightGlobals.ActiveVessel);
                }
            }
        }