Skip to content

Commit

Permalink
add crewOnly support to HasCrew rather than forcing it to be based of…
Browse files Browse the repository at this point in the history
…f maxCrew being defined
  • Loading branch information
NathanKell authored Sep 9, 2023
1 parent 5371d12 commit 951cc98
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Kerbal> kerbals = new List<Kerbal>();
protected List<Kerbal> excludeKerbals = new List<Kerbal>();

Expand All @@ -29,7 +30,7 @@ public HasCrew()
{
}

public HasCrew(string title, IEnumerable<Kerbal> kerbals, IEnumerable<Kerbal> excludeKerbals, string trait, int minCrew = 1, int maxCrew = int.MaxValue, int minExperience = 0, int maxExperience = 5)
public HasCrew(string title, IEnumerable<Kerbal> kerbals, IEnumerable<Kerbal> excludeKerbals, string trait, int minCrew = 1, int maxCrew = int.MaxValue, int minExperience = 0, int maxExperience = 5, bool crewOnly = false)
: base(title)
{
if (minCrew > maxCrew)
Expand All @@ -44,6 +45,7 @@ public HasCrew(string title, IEnumerable<Kerbal> kerbals, IEnumerable<Kerbal> ex
this.trait = trait;
this.kerbals = kerbals == null ? new List<Kerbal>() : kerbals.ToList();
this.excludeKerbals = excludeKerbals == null ? new List<Kerbal>() : excludeKerbals.ToList();
this.crewOnly = crewOnly;

CreateDelegates();
}
Expand Down Expand Up @@ -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");
Expand All @@ -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<bool>(node, "crewOnly", false);

foreach (ConfigNode kerbalNode in node.GetNodes("KERBAL"))
{
Expand Down Expand Up @@ -368,7 +372,7 @@ protected override bool VesselMeetsCondition(Vessel vessel)
checkOnly = ((VesselParameterGroup)Parent).TrackedVessel != vessel;
}

return ParameterDelegate<ProtoCrewMember>.CheckChildConditions(this, GetVesselCrew(vessel, maxCrew == int.MaxValue), checkOnly);
return ParameterDelegate<ProtoCrewMember>.CheckChildConditions(this, GetVesselCrew(vessel, !crewOnly && maxCrew == int.MaxValue), checkOnly);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class HasCrewFactory : ParameterFactory
protected int maxExperience;
protected int minCrew;
protected int maxCrew;
protected bool crewOnly;

protected List<Kerbal> kerbal;
protected List<Kerbal> excludeKerbal;
Expand All @@ -34,6 +35,7 @@ public override bool Load(ConfigNode configNode)
valid &= ConfigNodeUtil.ParseValue<int>(configNode, "maxExperience", x => maxExperience = x, this, 5, x => Validation.Between(x, 0, 5));
valid &= ConfigNodeUtil.ParseValue<int>(configNode, "minCrew", x => minCrew = x, this, 1, x => Validation.GE(x, 0));
valid &= ConfigNodeUtil.ParseValue<int>(configNode, "maxCrew", x => maxCrew = x, this, int.MaxValue, x => Validation.GE(x, minCrew));
valid &= ConfigNodeUtil.ParseValue<bool>(configNode, "crewOnly", x => crewOnly = x, this, false);

valid &= ConfigNodeUtil.ParseValue<List<Kerbal>>(configNode, "kerbal", x => kerbal = x, this, new List<Kerbal>());
valid &= ConfigNodeUtil.ParseValue<List<Kerbal>>(configNode, "excludeKerbal", x => excludeKerbal = x, this, new List<Kerbal>());
Expand All @@ -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);
}
}
}

0 comments on commit 951cc98

Please sign in to comment.