private void CheckSubject(Vessel vessel, string subjectID) { LoggingUtil.LogVerbose(this, "OnScienceReceived: " + subjectID + ", " + vessel.id); // Check the experiment type if (!string.IsNullOrEmpty(experiment) && !subjectID.StartsWith(experiment + "@")) { return; } // Temporarily set to test mode testMode = true; // Check whether we meet the conditions (with the exception of recovery) bool experimentPassed = ParameterDelegate <Vessel> .CheckChildConditions(this, vessel, true); // Reset test mode testMode = false; // Add the subject if it passed if (experimentPassed) { vesselData[vessel.id].subjects[subjectID] = true; } }
protected virtual void OnVesselWillDestroy(Vessel v) { LoggingUtil.LogVerbose(this, "OnVesselWillDestroy: " + v.id); foreach (string key in ContractVesselTracker.Instance.GetAssociatedKeys(v)) { LoggingUtil.LogVerbose(this, "adding to destroyedTargets: " + key); destroyedTargets.AddUnique(key); } bool success = ParameterDelegate <string> .CheckChildConditions(this, ""); if (ChildChanged || success) { ChildChanged = false; if (success) { SetState(ParameterState.Complete); } else { ContractConfigurator.OnParameterChange.Fire(Root, this); } } ContractConfigurator.OnParameterChange.Fire(Root, this); }
protected override IEnumerable <T> SetState(IEnumerable <T> values, ref bool conditionMet, bool checkOnly = false) { IEnumerable <T> newValues = ParameterDelegate <T> .CheckChildConditions(this, values, ref conditionMet, checkOnly); base.SetState(newValues, ref conditionMet, checkOnly); return(newValues); }
private void OnVesselRecovered(ProtoVessel v) { foreach (ProtoCrewMember crew in v.GetVesselCrew()) { if (recovered.ContainsKey(crew.name)) { recovered[crew.name] = true; } } // Retest the conditions bool success = ParameterDelegate <string> .CheckChildConditions(this, ""); if (ChildChanged || success) { ChildChanged = false; if (success) { SetState(ParameterState.Complete); } else { ContractConfigurator.OnParameterChange.Fire(Root, this); } } ContractConfigurator.OnParameterChange.Fire(Root, this); }
/// <summary> /// Whether this vessel meets the parameter condition. /// </summary> /// <param name="vessel">The vessel to check</param> /// <returns>Whether the vessel meets the condition</returns> protected override bool VesselMeetsCondition(Vessel vessel) { LoggingUtil.LogVerbose(this, "Checking VesselMeetsCondition: " + vessel.id); ParameterDelegate <Vessel> .CheckChildConditions(this, vessel); return(recoveryDone.Count == experiment.Count); }
protected override void SetState(IEnumerable <T> values, ref bool conditionMet, bool checkOnly = false) { BitArray current = ParameterDelegate <T> .CheckChildConditions(this, values, ref conditionMet, checkOnly); if (current != null) { src.And(current); } base.SetState(values, ref conditionMet, checkOnly); }
/// <summary> /// Whether this vessel meets the parameter condition. /// </summary> /// <param name="vessel">The vessel to check.</param> /// <returns>Whether the vessel meets the conditions.</returns> protected override bool VesselMeetsCondition(Vessel vessel) { LoggingUtil.LogVerbose(this, "Checking VesselMeetsCondition: " + vessel.id); // No passengers loaded if (passengers.Count == 0) { return(false); } return(ParameterDelegate <Vessel> .CheckChildConditions(this, vessel)); }
/// <summary> /// Whether this vessel meets the parameter condition. /// </summary> /// <param name="vessel">The vessel to check</param> /// <returns>Whether the vessel meets the condition</returns> protected override bool VesselMeetsCondition(Vessel vessel) { LoggingUtil.LogVerbose(this, "Checking VesselMeetsCondition: " + vessel.id); // If we're a VesselParameterGroup child, only do actual state change if we're the tracked vessel bool checkOnly = false; if (Parent is VesselParameterGroup) { checkOnly = ((VesselParameterGroup)Parent).TrackedVessel != vessel; } return(ParameterDelegate <ProtoCrewMember> .CheckChildConditions(this, GetVesselCrew(vessel, maxCrew == int.MaxValue), checkOnly)); }
/// <summary> /// Whether this vessel meets the parameter condition. /// </summary> /// <param name="vessel">The vessel to check</param> /// <returns>Whether the vessel meets the condition</returns> protected override bool VesselMeetsCondition(Vessel vessel) { LoggingUtil.LogVerbose(this, "Checking VesselMeetsCondition: {0}", vessel.id); // If we're a VesselParameterGroup child, only do actual state change if we're the tracked vessel bool checkOnly = false; if (Parent is VesselParameterGroup) { checkOnly = ((VesselParameterGroup)Parent).TrackedVessel != vessel; } return(ParameterDelegate <Part> .CheckChildConditions(this, vessel.parts, checkOnly)); }
protected virtual void CheckVessels() { bool success = ParameterDelegate <string> .CheckChildConditions(this, ""); if (ChildChanged || success) { ChildChanged = false; if (success) { SetState(ParameterState.Complete); } else { ContractConfigurator.OnParameterChange.Fire(Root, this); } } }
private void TestConditions() { // Retest the conditions bool success = ParameterDelegate <string> .CheckChildConditions(this, "") && ParameterCount > 0; if (ChildChanged || success) { ChildChanged = false; if (success) { SetState(ParameterState.Complete); } else { SetState(ParameterState.Incomplete); ContractConfigurator.OnParameterChange.Fire(Root, this); } } }
/// <summary> /// Checks the child parameters and updates state. /// </summary> /// <param name="vessel">The vessel to check the state for</param> public void UpdateState(Vessel vessel) { if (!enabled) { return; } LoggingUtil.LogVerbose(this, "-> UpdateState({0})", (vessel != null ? vessel.id.ToString() : "null")); // If this vessel doesn't match our list of valid vessels, ignore the update if (!VesselCanBeConsidered(vessel)) { LoggingUtil.LogVerbose(this, "<- UpdateState (vessel cannot be considered)"); // Set the tracked vessel in delegate parameters, if there is one (updates text) if (trackedVessel != null) { ParameterDelegate <Vessel> .CheckChildConditions(this, trackedVessel); } return; } // Reset the tracked vessel if it no longer exists if (trackedVesselGuid != Guid.Empty && !FlightGlobals.Vessels.Any(v => v.id == trackedVesselGuid)) { LoggingUtil.LogVerbose(this, "Tracked vessel no longer exists, resetting tracking."); waiting = false; trackedVessel = null; trackedVesselGuid = Guid.Empty; } // Ignore updates to non-tracked vessels if that vessel is already winning if (vessel != trackedVessel && (waiting || state == ParameterState.Complete)) { // Make sure that the state of our tracked vessel has not suddenly changed SetChildState(trackedVessel); if (AllChildParametersComplete()) { LoggingUtil.LogVerbose(this, "<- UpdateState (tracked vessel has already completed parameter)"); return; } } // Temporarily change the state SetChildState(vessel); // Check if this is a completion if (AllChildParametersComplete()) { trackedVessel = vessel; trackedVesselGuid = trackedVessel.id; } // Look at all other possible craft to see if we can find a winner else { trackedVessel = null; // Get a list of vessels to check Dictionary <Vessel, int> vessels = new Dictionary <Vessel, int>(); foreach (VesselParameter p in AllDescendents <VesselParameter>()) { foreach (Vessel v in p.GetCompletingVessels()) { if (v != vessel && VesselCanBeConsidered(v)) { vessels[v] = 0; } } } // Check the vessels foreach (Vessel v in vessels.Keys) { // Temporarily change the state SetChildState(v); // Do a check if (AllChildParametersComplete()) { trackedVessel = v; trackedVesselGuid = trackedVessel.id; break; } } // Still no winner if (trackedVessel == null) { // Use active if (FlightGlobals.ActiveVessel != null && VesselCanBeConsidered(FlightGlobals.ActiveVessel)) { SetChildState(FlightGlobals.ActiveVessel); trackedVessel = FlightGlobals.ActiveVessel; trackedVesselGuid = trackedVessel.id; } } } // Force a VesselMeetsCondition call to update ParameterDelegate objects if (oldTrackedVessel != trackedVessel && trackedVessel != null) { foreach (ContractParameter p in this.GetAllDescendents()) { if (p is VesselParameter) { ((VesselParameter)p).CheckVesselMeetsCondition(trackedVessel); } } oldTrackedVessel = trackedVessel; } if (trackedVessel != null) { // Set the tracked vessel in delegate parameters ParameterDelegate <Vessel> .CheckChildConditions(this, trackedVessel); } // Fire the parameter change event to account for all the changed child parameters. // We don't fire it for the child parameters, as any with a failed state will cause // the contract to fail, which we don't want. LoggingUtil.LogVerbose(this, "Firing OnParameterChange"); ContractConfigurator.OnParameterChange.Fire(this.Root, this); // Manually run the OnParameterStateChange OnParameterStateChange(this); LoggingUtil.LogVerbose(this, "<- UpdateState (state possibly changed)"); }
/// <summary> /// Whether this vessel meets the parameter condition. /// </summary> /// <param name="vessel">The vessel to check.</param> /// <returns>Whether the vessel meets the conditions.</returns> protected override bool VesselMeetsCondition(Vessel vessel) { LoggingUtil.LogVerbose(this, "Checking VesselMeetsCondition: " + vessel.id); return(ParameterDelegate <Vessel> .CheckChildConditions(this, vessel)); }