Esempio n. 1
0
        private void OnVesselRecovered(ProtoVessel v, bool quick)
        {
            // Don't check if we're not ready to complete
            if (!ReadyToComplete())
            {
                return;
            }

            // Special handling for null vessel cases
            if (v.vesselRef == null)
            {
                VesselParameterGroup vpg = GetParameterGroupHost();
                if (vpg == null)
                {
                    SetState(ParameterState.Complete);
                }
                else
                {
                }
            }

            recovered[v.vesselRef] = true;

            CheckVessel(v.vesselRef);
        }
        /// <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");
        }
        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);
                }
            }
        }
        protected Vessel CurrentVessel()
        {
            VesselParameterGroup vpg = GetParameterGroupHost();

            return(vpg == null ? null : vpg.TrackedVessel);
        }
Esempio n. 5
0
        protected override void OnUpdate()
        {
            base.OnUpdate();

            // Do a check to see if we need to play with the end time
            if (waitTime < Time.fixedTime)
            {
                waitTime = double.MaxValue;

                bool completed = triggered;
                if (startCriteria != StartCriteria.PARAMETER_COMPLETION && startCriteria != StartCriteria.PARAMETER_FAILURE)
                {
                    foreach (ContractParameter child in Parent.GetChildren())
                    {
                        if (child == this)
                        {
                            break;
                        }

                        if (child.State != ParameterState.Complete && !child.Optional)
                        {
                            completed = false;
                            break;
                        }
                    }
                }

                // Additional check when under a VesselParameterGroup
                VesselParameterGroup vpg = Parent as VesselParameterGroup;
                if (vpg != null && vpg.VesselList.Any())
                {
                    completed &= ContractVesselTracker.Instance.GetAssociatedKeys(FlightGlobals.ActiveVessel).
                                 Where(key => vpg.VesselList.Contains(key)).Any();
                }

                Vessel currentVessel = CurrentVessel();
                if (completed)
                {
                    if (currentVessel != null)
                    {
                        if (!endTimes.ContainsKey(currentVessel.id))
                        {
                            endTimes[currentVessel.id] = Planetarium.GetUniversalTime() + duration;
                        }
                    }
                    // Handle case for not under a VesselParameterGroup
                    else if (vpg == null)
                    {
                        if (endTime == 0.0)
                        {
                            endTime = Planetarium.GetUniversalTime() + duration;
                        }
                    }
                }
                else
                {
                    if (currentVessel != null && endTimes.ContainsKey(currentVessel.id))
                    {
                        endTimes.Remove(currentVessel.id);
                    }
                    else if (vpg == null)
                    {
                        endTime = 0.0;
                    }
                    resetClock = true;
                }
            }

            if (Planetarium.GetUniversalTime() - lastUpdate > 1.0f)
            {
                Vessel currentVessel = CurrentVessel();
                double time          = currentVessel != null && endTimes.ContainsKey(currentVessel.id) ? endTimes[currentVessel.id] : endTime;
                if (time != 0.0 || resetClock)
                {
                    lastUpdate = Planetarium.GetUniversalTime();
                    resetClock = false;

                    // Force a call to GetTitle to update the contracts app
                    GetTitle();

                    if (currentVessel != null)
                    {
                        CheckVessel(currentVessel);
                    }

                    // Special case for non-vessel parameter
                    if (endTime != 0.0 && Planetarium.GetUniversalTime() > endTime)
                    {
                        SetState(ParameterState.Complete);
                    }
                }
            }
        }