From 951cc989904a2e361efa9cde1d4c7aba10df0ebe Mon Sep 17 00:00:00 2001 From: NathanKell Date: Fri, 8 Sep 2023 23:49:46 -0700 Subject: [PATCH] add crewOnly support to HasCrew rather than forcing it to be based off maxCrew being defined --- .../Parameter/VesselParameter/HasCrew.cs | 8 ++++++-- .../ParameterFactory/HasCrewFactory.cs | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/source/ContractConfigurator/Parameter/VesselParameter/HasCrew.cs b/source/ContractConfigurator/Parameter/VesselParameter/HasCrew.cs index 83ddf7b67..6d344645c 100644 --- a/source/ContractConfigurator/Parameter/VesselParameter/HasCrew.cs +++ b/source/ContractConfigurator/Parameter/VesselParameter/HasCrew.cs @@ -21,6 +21,7 @@ public class HasCrew : VesselParameter, IKerbalNameStorage protected int maxCrew { get; set; } protected int minExperience { get; set; } protected int maxExperience { get; set; } + protected bool crewOnly { get; set; } protected List kerbals = new List(); protected List excludeKerbals = new List(); @@ -29,7 +30,7 @@ public HasCrew() { } - public HasCrew(string title, IEnumerable kerbals, IEnumerable excludeKerbals, string trait, int minCrew = 1, int maxCrew = int.MaxValue, int minExperience = 0, int maxExperience = 5) + public HasCrew(string title, IEnumerable kerbals, IEnumerable excludeKerbals, string trait, int minCrew = 1, int maxCrew = int.MaxValue, int minExperience = 0, int maxExperience = 5, bool crewOnly = false) : base(title) { if (minCrew > maxCrew) @@ -44,6 +45,7 @@ public HasCrew(string title, IEnumerable kerbals, IEnumerable ex this.trait = trait; this.kerbals = kerbals == null ? new List() : kerbals.ToList(); this.excludeKerbals = excludeKerbals == null ? new List() : excludeKerbals.ToList(); + this.crewOnly = crewOnly; CreateDelegates(); } @@ -253,6 +255,7 @@ protected override void OnParameterSave(ConfigNode node) node.AddValue("maxCrew", maxCrew); node.AddValue("minExperience", minExperience); node.AddValue("maxExperience", maxExperience); + node.AddValue("crewOnly", crewOnly); foreach (Kerbal kerbal in kerbals) { ConfigNode kerbalNode = new ConfigNode("KERBAL"); @@ -279,6 +282,7 @@ protected override void OnParameterLoad(ConfigNode node) maxExperience = Convert.ToInt32(node.GetValue("maxExperience")); minCrew = Convert.ToInt32(node.GetValue("minCrew")); maxCrew = Convert.ToInt32(node.GetValue("maxCrew")); + crewOnly = ConfigNodeUtil.ParseValue(node, "crewOnly", false); foreach (ConfigNode kerbalNode in node.GetNodes("KERBAL")) { @@ -368,7 +372,7 @@ protected override bool VesselMeetsCondition(Vessel vessel) checkOnly = ((VesselParameterGroup)Parent).TrackedVessel != vessel; } - return ParameterDelegate.CheckChildConditions(this, GetVesselCrew(vessel, maxCrew == int.MaxValue), checkOnly); + return ParameterDelegate.CheckChildConditions(this, GetVesselCrew(vessel, !crewOnly && maxCrew == int.MaxValue), checkOnly); } /// diff --git a/source/ContractConfigurator/ParameterFactory/HasCrewFactory.cs b/source/ContractConfigurator/ParameterFactory/HasCrewFactory.cs index 850588ace..d7b5abb0a 100644 --- a/source/ContractConfigurator/ParameterFactory/HasCrewFactory.cs +++ b/source/ContractConfigurator/ParameterFactory/HasCrewFactory.cs @@ -20,6 +20,7 @@ public class HasCrewFactory : ParameterFactory protected int maxExperience; protected int minCrew; protected int maxCrew; + protected bool crewOnly; protected List kerbal; protected List excludeKerbal; @@ -34,6 +35,7 @@ public override bool Load(ConfigNode configNode) valid &= ConfigNodeUtil.ParseValue(configNode, "maxExperience", x => maxExperience = x, this, 5, x => Validation.Between(x, 0, 5)); valid &= ConfigNodeUtil.ParseValue(configNode, "minCrew", x => minCrew = x, this, 1, x => Validation.GE(x, 0)); valid &= ConfigNodeUtil.ParseValue(configNode, "maxCrew", x => maxCrew = x, this, int.MaxValue, x => Validation.GE(x, minCrew)); + valid &= ConfigNodeUtil.ParseValue(configNode, "crewOnly", x => crewOnly = x, this, false); valid &= ConfigNodeUtil.ParseValue>(configNode, "kerbal", x => kerbal = x, this, new List()); valid &= ConfigNodeUtil.ParseValue>(configNode, "excludeKerbal", x => excludeKerbal = x, this, new List()); @@ -53,7 +55,7 @@ public override ContractParameter Generate(Contract contract) minCrew = 0; } - return new HasCrew(title, kerbal, excludeKerbal, trait, minCrew, maxCrew, minExperience, maxExperience); + return new HasCrew(title, kerbal, excludeKerbal, trait, minCrew, maxCrew, minExperience, maxExperience, crewOnly); } } }