Skip to content

Commit

Permalink
Clamp UntrackedObjectClass for 1.8 (not clear this is needed, but eh)
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanKell committed Jul 29, 2022
1 parent aed6b9b commit 68509b1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Contract Configurator 2.1.2
- Fix compatibility with 1.8.1/1.9

Contract Configurator 2.1.1
- Fix tag handling

Expand Down
12 changes: 8 additions & 4 deletions source/ContractConfigurator/Behaviour/SpawnVessel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ public static SpawnVessel Create(ConfigNode configNode, SpawnVesselFactory facto

return valid ? spawnVessel : null;
}

// For 1.8/1.9 compat
protected static int UntrackedObjectEnumCount = System.Enum.GetValues(typeof(UntrackedObjectClass)).Length;
protected static UntrackedObjectClass GetObjectSize(int size) => (UntrackedObjectClass)(Math.Min(UntrackedObjectEnumCount - 1, size));

protected bool CreateVessels()
{
Expand Down Expand Up @@ -379,19 +383,19 @@ protected bool CreateVessels()
// Only for KSP 1.10+
else if (size < 52.125f)
{
sizeClass = UntrackedObjectClass.F;
sizeClass = GetObjectSize(5);
}
else if (size < 86.875f)
{
sizeClass = UntrackedObjectClass.G;
sizeClass = GetObjectSize(6);
}
else if (size < 144.75f)
{
sizeClass = UntrackedObjectClass.H;
sizeClass = GetObjectSize(7);
}
else
{
sizeClass = UntrackedObjectClass.I;
sizeClass = GetObjectSize(8);
}

foreach (CrewData cd in vesselData.crew)
Expand Down

0 comments on commit 68509b1

Please sign in to comment.