Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 49 additions & 34 deletions MechJeb2/ComputerModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public class ComputerModule : IComparable<ComputerModule>
public readonly MechJebCore Core;

//conveniences:
public Vessel Vessel => Part.vessel;
public CelestialBody MainBody => Part.vessel.mainBody;
public VesselState VesselState => Core.VesselState;
public Vessel Vessel => Part.vessel;
public CelestialBody MainBody => Part.vessel.mainBody;
public VesselState VesselState => Core.VesselState;

[UsedImplicitly]
public Part Part => Core.part;
Expand All @@ -29,11 +29,11 @@ public class ComputerModule : IComparable<ComputerModule>

[UsedImplicitly]
[Persistent(pass = (int)Pass.LOCAL)]
public readonly string UnlockParts = "";
public string unlockParts = "";

[UsedImplicitly]
[Persistent(pass = (int)Pass.LOCAL)]
public readonly string UnlockTechs = "";
public string unlockTechs = "";

public bool UnlockChecked;

Expand All @@ -48,7 +48,7 @@ public bool Enabled
{
if (value == _enabled) return;

Dirty = true;
Dirty = true;
_enabled = value;

if (_enabled)
Expand Down Expand Up @@ -79,7 +79,7 @@ public bool Enabled

protected ComputerModule(MechJebCore core)
{
Core = core;
Core = core;
ProfilerName = GetType().Name;

Users = new UserPool(this);
Expand Down Expand Up @@ -190,50 +190,65 @@ public virtual void UnlockCheck()
{
if (UnlockChecked) return;

// Bypass check for Sandbox mode
if (HighLogic.CurrentGame != null && HighLogic.CurrentGame.Mode == Game.Modes.SANDBOX)
{
UnlockChecked = true;
return;
}

if (ResearchAndDevelopment.Instance == null) return;

bool unlock = true;

if (ResearchAndDevelopment.Instance != null)
string[] parts = unlockParts.Split(new[] { ' ', ',', ';', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
if (parts.Length > 0)
{
string[] parts = UnlockParts.Split(new[] { ' ', ',', ';', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
if (parts.Length > 0)
unlock = false;
foreach (string p in parts)
{
unlock = false;
foreach (string p in parts)
if (PartLoader.LoadedPartsList.Count(a => a.name == p) > 0 &&
ResearchAndDevelopment.PartModelPurchased(PartLoader.LoadedPartsList.First(a => a.name == p)))
{
if (PartLoader.LoadedPartsList.Count(a => a.name == p) > 0 &&
ResearchAndDevelopment.PartModelPurchased(PartLoader.LoadedPartsList.First(a => a.name == p)))
{
unlock = true;
break;
}
unlock = true;
break;
}
}
}

string[] techs = UnlockTechs.Split(new[] { ' ', ',', ';', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
if (techs.Length > 0)
string[] techs = unlockTechs.Split(new[] { ' ', ',', ';', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
if (techs.Length > 0)
{
if (parts.Length == 0)
{
if (parts.Length == 0)
{
unlock = false;
}
unlock = false;
}

foreach (string t in techs)
foreach (string t in techs)
{
if (ResearchAndDevelopment.GetTechnologyState(t) == RDTech.State.Available)
{
if (ResearchAndDevelopment.GetTechnologyState(t) == RDTech.State.Available)
{
unlock = true;
break;
}
unlock = true;
break;
}
}
}

unlock = unlock && IsSpaceCenterUpgradeUnlocked();

// Debug start

Debug.Log($"[MechJeb2] UnlockCheck {GetType().Name}: unlock={unlock}, " +
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you've at least got one stray Debug.Log left in here, and this PR would be better without all the whitespace changes.

$"mode={HighLogic.CurrentGame?.Mode}, " +
$"RnD={(ResearchAndDevelopment.Instance != null)}, " +
$"unlockTechs='{unlockTechs}', unlockParts='{unlockParts}'");

// End of debug
UnlockChecked = true;

if (!unlock)
{
Enabled = false;
Enabled = false;
Core.someModuleAreLocked = true;
}
}
Expand All @@ -252,16 +267,16 @@ public virtual void UnlockCheck()
[Flags]
public enum Pass
{
LOCAL = 1,
TYPE = 2,
LOCAL = 1,
TYPE = 2,
GLOBAL = 4
}

public class ModuleEvent
{
public delegate void OnEvent();

private readonly List<OnEvent> _events = new List<OnEvent>();
private readonly List<OnEvent> _events = new List<OnEvent>();
private readonly Dictionary<OnEvent, int> _eventIndex = new Dictionary<OnEvent, int>();

public void Add(OnEvent evt)
Expand Down
2 changes: 1 addition & 1 deletion MechJeb2/DisplayModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public override void UnlockCheck()
bool prevEn = Enabled;
Enabled = true;
base.UnlockCheck();
if (UnlockParts.Trim().Length > 0 || UnlockTechs.Trim().Length > 0 || !IsSpaceCenterUpgradeUnlocked())
if (unlockParts.Trim().Length > 0 || unlockTechs.Trim().Length > 0 || !IsSpaceCenterUpgradeUnlocked())
{
Hidden = !Enabled;
if (Hidden)
Expand Down
Loading