/* * Method for generating ContractParameter objects. This will call the Generate() method * on the sub-class, load all common parameters and load child parameters. */ public virtual ContractParameter Generate(Contract contract, IContractParameterHost contractParamHost) { // Generate a parameter using the sub-class logic ContractParameter parameter = Generate(contract); if (parameter == null) { throw new Exception(GetType().FullName + ".Generate() returned a null ContractParameter!"); } // Add ContractParameter to the host contractParamHost.AddParameter(parameter); // Set the funds/science/reputation parameters parameter.SetFunds(rewardFunds, failureFunds, targetBody); parameter.SetReputation(rewardReputation, failureReputation, targetBody); parameter.SetScience(rewardScience, targetBody); // Set other flags parameter.Optional = optional; if (disableOnStateChange != null) { parameter.DisableOnStateChange = (bool)disableOnStateChange; } return(parameter); }
/// <summary> /// Gets all the parameter's descendents /// </summary> /// <param name="p">Contract parameter</param> /// <returns>Enumerator of descendents</returns> public static IEnumerable <ContractParameter> GetChildren(this IContractParameterHost p) { for (int i = 0; i < p.ParameterCount; i++) { yield return(p.GetParameter(i)); } }
public void OnParameterChange(Contract c, ContractParameter p) { if (c != Root) { return; } // Hide the waypoint if we are done with it if (hideOnCompletion && waypoint != null && waypoint.visible) { for (IContractParameterHost paramHost = this; paramHost != Root; paramHost = paramHost.Parent) { if (state == ParameterState.Complete) { ContractParameter param = paramHost as ContractParameter; if (param != null && !param.Enabled) { waypoint.visible = false; NavWaypoint navPoint = NavWaypoint.fetch; if (navPoint != null && NavWaypoint.fetch.IsActive && navPoint.Latitude == waypoint.latitude && navPoint.Longitude == waypoint.longitude) { NavWaypoint.fetch.Clear(); NavWaypoint.fetch.Deactivate(); } break; } } else { break; } } } }
/// <summary> /// Generates all the ContractParameter objects required for the array of ConfigNodes, and /// adds them to the host object. /// </summary> /// <param name="contract">Contract to generate for</param> /// <param name="contractParamHost">The object to use as a parent for ContractParameters</param> /// <param name="paramFactories">The ParameterFactory objects to use to generate parameters.</param> /// <returns>Whether the generation was successful.</returns> public static bool GenerateParameters(ConfiguredContract contract, IContractParameterHost contractParamHost, List <ParameterFactory> paramFactories) { foreach (ParameterFactory paramFactory in paramFactories) { if (paramFactory.enabled) { ContractParameter parameter = paramFactory.Generate(contract, contractParamHost); // Get the child parameters if (parameter != null) { if (!GenerateParameters(contract, parameter, paramFactory.childNodes)) { return(false); } } ContractConfiguratorParameter ccParam = parameter as ContractConfiguratorParameter; if (ccParam != null && ccParam.hideChildren) { foreach (ContractParameter child in ccParam.GetChildren()) { ContractConfiguratorParameter ccChild = child as ContractConfiguratorParameter; if (ccChild != null) { ccChild.Hide(); } } } } } return(true); }
/// <summary> /// Generates all the ContractParameter objects required for the array of ConfigNodes, and /// adds them to the host object. /// </summary> /// <param name="contract">Contract to generate for</param> /// <param name="contractParamHost">The object to use as a parent for ContractParameters</param> /// <param name="paramFactories">The ParameterFactory objects to use to generate parameters.</param> /// <returns>Whether the generation was successful.</returns> public static bool GenerateParameters(ConfiguredContract contract, IContractParameterHost contractParamHost, List <ParameterFactory> paramFactories) { foreach (ParameterFactory paramFactory in paramFactories) { if (paramFactory.enabled) { // Set up the iterator int count = 1; int current = 0; if (paramFactory.iteratorType != null) { count = (int)paramFactory.dataNode["iteratorCount"]; } // Loop through the iterator, or do a single parameter for non-iterated parameters while (current++ < count) { // Refresh the deterministic values int oldValue = DataNode.IteratorCurrentIndex; if (paramFactory.iteratorType != null) { DataNode.IteratorCurrentIndex = current - 1; ConfigNodeUtil.UpdateNonDeterministicValues(paramFactory.dataNode, paramFactory.dataNode); } ContractParameter parameter = paramFactory.Generate(contract, contractParamHost); // Get the child parameters if (parameter != null) { if (!GenerateParameters(contract, parameter, paramFactory.childNodes)) { return(false); } } ContractConfiguratorParameter ccParam = parameter as ContractConfiguratorParameter; if (ccParam != null && ccParam.hideChildren) { foreach (ContractParameter child in ccParam.GetChildren()) { ContractConfiguratorParameter ccChild = child as ContractConfiguratorParameter; if (ccChild != null) { ccChild.Hide(); } } } // Restore the old value for the iterator list (for recursive iterations) DataNode.IteratorCurrentIndex = oldValue; } } } return(true); }
/* * Generates all the ContractParameter objects required for the array of ConfigNodes, and * adds them to the host object. */ public static void GenerateParameters(ConfiguredContract contract, IContractParameterHost contractParamHost, List <ParameterFactory> paramFactories) { foreach (ParameterFactory paramFactory in paramFactories) { ContractParameter parameter = paramFactory.Generate(contract, contractParamHost); // Get the child parameters GenerateParameters(contract, parameter, paramFactory.childNodes); } }
/* * Follows the given path to get the parameter. */ protected ContractParameter GetParamFromPath(string path) { IContractParameterHost h = Root; foreach (int i in path.Split(new char[] { ',' }).Select <string, int>(s => Convert.ToInt32(s))) { h = h.GetParameter(i); } return(h as ContractParameter); }
/// <summary> /// Gets all the parameter's descendents /// </summary> /// <param name="p">Contract parameter</param> /// <returns>Enumerator of descendents</returns> public static IEnumerable <ContractParameter> GetAllDescendents(this IContractParameterHost p) { for (int i = 0; i < p.ParameterCount; i++) { ContractParameter child = p.GetParameter(i); yield return(child); foreach (ContractParameter descendent in child.GetAllDescendents()) { yield return(descendent); } } }
private VesselParameterGroup GetParameterGroupHost() { IContractParameterHost host = Parent; while (host != Root && !(host is VesselParameterGroup)) { host = host.Parent; } if (host is VesselParameterGroup) { return((VesselParameterGroup)host); } return(null); }
/// <summary> /// Method for generating ContractParameter objects. This will call the Generate() method /// on the sub-class, load all common parameters and load child parameters. /// </summary> /// <param name="contract">Contract to generate for</param> /// <param name="contractParamHost">Parent object for the ContractParameter</param> /// <returns>Generated ContractParameter</returns> public virtual ContractParameter Generate(ConfiguredContract contract, IContractParameterHost contractParamHost) { // First check any requirements if (!ContractRequirement.RequirementsMet(contract, contract.contractType, requirements)) { LoggingUtil.LogVerbose(typeof(ParameterFactory), "Returning null for " + contract.contractType.name + "." + name + ": requirements not met."); return(null); } // Generate a parameter using the sub-class logic ContractParameter parameter = Generate(contract); if (parameter == null) { LoggingUtil.LogWarning(this, GetType().FullName + ".Generate() returned a null ContractParameter!"); return(null); } // Add ContractParameter to the host contractParamHost.AddParameter(parameter); // Set the funds/science/reputation parameters parameter.SetFunds(rewardFunds, failureFunds, targetBody); parameter.SetReputation(rewardReputation, failureReputation, targetBody); parameter.SetScience(rewardScience, targetBody); // Set other flags parameter.Optional = optional; if (disableOnStateChange != null) { parameter.DisableOnStateChange = (bool)disableOnStateChange; } parameter.ID = name; // Special stuff for contract configurator parameters ContractConfiguratorParameter ccParam = parameter as ContractConfiguratorParameter; if (ccParam != null) { ccParam.completeInSequence = completeInSequence; ccParam.notes = notes; ccParam.completedMessage = completedMessage; ccParam.hidden = hidden; ccParam.hideChildren = hideChildren; } return(parameter); }
protected new void SetState(ParameterState newState) { if (state != newState) { state = newState; IContractParameterHost current = this; ParameterDelegateContainer container = null; while (container == null) { current = current.Parent; container = current as ParameterDelegateContainer; } container.ChildChanged = true; } }
protected new void SetState(ParameterState newState) { if (state != newState) { LoggingUtil.LogVerbose(this, "Setting state for '" + title + "', state = " + newState); state = newState; IContractParameterHost current = this; ParameterDelegateContainer container = null; while (container == null) { current = current.Parent; container = current as ParameterDelegateContainer; } container.ChildChanged = true; } }
protected void CheckVesselParameters(IContractParameterHost host) { // Check if any VesselParameter parameters that are not part of a VPG are reset for (int i = host.ParameterCount - 1; i >= 0; i--) { ContractParameter param = host[i]; if (!(param is VesselParameterGroup)) { VesselParameter vp = param as VesselParameter; if (vp != null && vp.Enabled && vp.State == ParameterState.Complete) { vp.SetState(ParameterState.Incomplete); } CheckVesselParameters(param); } } }
/* * Gets the "path" to the given contract parameter from the root. */ protected static IEnumerable <int> GetPathFromParam(ContractParameter p) { IContractParameterHost h = p; while (h != p.Root) { for (int i = 0; i < h.Parent.ParameterCount; i++) { if (h.Parent.GetParameter(i) == h) { yield return(i); break; } } h = h.Parent; } yield break; }
public ContractPredicate(IContractParameterHost parent);
/// <summary> /// Generates all the ContractParameter objects required for the array of ConfigNodes, and /// adds them to the host object. /// </summary> /// <param name="contract">Contract to generate for</param> /// <param name="contractParamHost">The object to use as a parent for ContractParameters</param> /// <param name="paramFactories">The ParameterFactory objects to use to generate parameters.</param> /// <returns>Whether the generation was successful.</returns> public static bool GenerateParameters(ConfiguredContract contract, IContractParameterHost contractParamHost, List<ParameterFactory> paramFactories) { foreach (ParameterFactory paramFactory in paramFactories) { if (paramFactory.enabled) { // Set up the iterator int count = 1; int current = 0; if (paramFactory.iteratorType != null) { count = (int)paramFactory.dataNode["iteratorCount"]; } // Loop through the iterator, or do a single parameter for non-iterated parameters while (current++ < count) { // Refresh the deterministic values int oldValue = DataNode.IteratorCurrentIndex; if (paramFactory.iteratorType != null) { DataNode.IteratorCurrentIndex = current-1; ConfigNodeUtil.UpdateNonDeterministicValues(paramFactory.dataNode, paramFactory.dataNode); } ContractParameter parameter = paramFactory.Generate(contract, contractParamHost); // Get the child parameters if (parameter != null) { if (!GenerateParameters(contract, parameter, paramFactory.childNodes)) { return false; } } ContractConfiguratorParameter ccParam = parameter as ContractConfiguratorParameter; if (ccParam != null && ccParam.hideChildren) { foreach (ContractParameter child in ccParam.GetChildren()) { ContractConfiguratorParameter ccChild = child as ContractConfiguratorParameter; if (ccChild != null) { ccChild.Hide(); } } } // Restore the old value for the iterator list (for recursive iterations) DataNode.IteratorCurrentIndex = oldValue; } } } return true; }
public void NestToParent(IContractParameterHost parent);
/// <summary> /// Method for generating ContractParameter objects. This will call the Generate() method /// on the sub-class, load all common parameters and load child parameters. /// </summary> /// <param name="contract">Contract to generate for</param> /// <param name="contractParamHost">Parent object for the ContractParameter</param> /// <returns>Generated ContractParameter</returns> public virtual ContractParameter Generate(ConfiguredContract contract, IContractParameterHost contractParamHost) { // First check any requirements if (!ContractRequirement.RequirementsMet(contract, contract.contractType, requirements)) { LoggingUtil.LogVerbose(typeof(ParameterFactory), "Returning null for " + contract.contractType.name + "." + name + ": requirements not met."); return null; } // Generate a parameter using the sub-class logic ContractParameter parameter = Generate(contract); if (parameter == null) { LoggingUtil.LogWarning(this, GetType().FullName + ".Generate() returned a null ContractParameter!"); return null; } // Add ContractParameter to the host contractParamHost.AddParameter(parameter); // Set the funds/science/reputation parameters parameter.SetFunds(rewardFunds, failureFunds, targetBody); parameter.SetReputation(rewardReputation, failureReputation, targetBody); parameter.SetScience(rewardScience, targetBody); // Set other flags parameter.Optional = optional; if (disableOnStateChange != null) { parameter.DisableOnStateChange = (bool)disableOnStateChange; } parameter.ID = name; // Special stuff for contract configurator parameters ContractConfiguratorParameter ccParam = parameter as ContractConfiguratorParameter; if (ccParam != null) { ccParam.completeInSequence = completeInSequence; ccParam.notes = notes; ccParam.completedMessage = completedMessage; ccParam.hideChildren = hideChildren; } return parameter; }
/// <summary> /// Generates all the ContractParameter objects required for the array of ConfigNodes, and /// adds them to the host object. /// </summary> /// <param name="contract">Contract to generate for</param> /// <param name="contractParamHost">The object to use as a parent for ContractParameters</param> /// <param name="paramFactories">The ParameterFactory objects to use to generate parameters.</param> /// <returns>Whether the generation was successful.</returns> public static bool GenerateParameters(ConfiguredContract contract, IContractParameterHost contractParamHost, List<ParameterFactory> paramFactories) { foreach (ParameterFactory paramFactory in paramFactories) { if (paramFactory.enabled) { ContractParameter parameter = paramFactory.Generate(contract, contractParamHost); // Get the child parameters if (parameter != null) { if (!GenerateParameters(contract, parameter, paramFactory.childNodes)) { return false; } } ContractConfiguratorParameter ccParam = parameter as ContractConfiguratorParameter; if (ccParam != null && ccParam.hideChildren) { foreach (ContractParameter child in ccParam.GetChildren()) { ContractConfiguratorParameter ccChild = child as ContractConfiguratorParameter; if (ccChild != null) { ccChild.Hide(); } } } } } return true; }