Skip to content

Commit

Permalink
Check for game mode before checking science results; null checks
Browse files Browse the repository at this point in the history
  • Loading branch information
DMagic1 committed Aug 21, 2019
1 parent 42eb790 commit 47e931b
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions SCANsat/SCAN_Data/SCANdata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ public SCANanomaly[] Anomalies

public List<SCANROC> ROCS(bool refresh)
{
if (ROCManager.Instance == null)
return null;

if (!ROCManager.Instance.RocsEnabledInCurrentGame)
return null;

Expand All @@ -215,15 +218,21 @@ public List<SCANROC> ROCS(bool refresh)

rocs.Clear();

if (body == null)
return null;

PQS controller = body.pqsController;

if (controller == null)
if (controller == null || controller.transform == null)
return null;

for (int i = controller.transform.childCount - 1; i >= 0; i--)
{
Transform child = controller.transform.GetChild(i);

if (child == null)
continue;

if (child.name.StartsWith("ROC"))
{
int index = child.name.IndexOf(' ');
Expand All @@ -232,23 +241,36 @@ public List<SCANROC> ROCS(bool refresh)
{
string id = child.name.Substring(index + 1);

List<ScienceSubject> subjects = ResearchAndDevelopment.GetSubjects();

bool scanned = false;

for (int k = subjects.Count - 1; k >= 0; k--)
if (HighLogic.CurrentGame.Mode == Game.Modes.SANDBOX || HighLogic.CurrentGame.Mode == Game.Modes.MISSION)
{
scanned = true;
}
else
{
if (subjects[k].id.Contains(id))
List<ScienceSubject> subjects = ResearchAndDevelopment.GetSubjects();

if (subjects != null)
{
scanned = true;
break;
for (int k = subjects.Count - 1; k >= 0; k--)
{
if (subjects[k].id.Contains(id))
{
scanned = true;
break;
}
}
}
}

for (int j = child.childCount - 1; j >= 0; j--)
{
Transform cache = child.GetChild(j);

if (cache == null)
continue;

if (cache.name != ("Unassigned"))
{
ROC roc = cache.GetComponentInChildren<ROC>();
Expand Down

0 comments on commit 47e931b

Please sign in to comment.