Skip to content

Commit

Permalink
Showing 2 changed files with 69 additions and 5 deletions.
Binary file modified GameData/RP-0/Plugins/RP0.dll
Binary file not shown.
74 changes: 69 additions & 5 deletions Source/ModuleAvionics.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KSP;
using System.Collections.Generic;
using System.Collections;
using UniLinq;
using UnityEngine;

namespace RP0
@@ -31,6 +29,10 @@ class ModuleAvionics : PartModule
[KSPField]
public string techRequired = "";

[KSPField(isPersistant = true, guiActive = false, guiActiveEditor = true, guiName = "Set to Debris"),
UI_Toggle(disabledText = "Never", enabledText = "On Stage", affectSymCounterparts = UI_Scene.Editor)]
public bool setToDebrisOnStage = false;

protected ModuleResource commandChargeResource = null;
protected bool wasWarping = false;
protected bool currentlyEnabled = true;
@@ -129,9 +131,66 @@ private void SetActionsAndGui()
Actions["ActivateAction"].active = !systemEnabled;
Actions["ShutdownAction"].active = systemEnabled;
}

protected void StageActivated(int stage)
{
if (setToDebrisOnStage)
StartCoroutine(CheckRenameDebris());
}

protected IEnumerator CheckRenameDebris()
{
bool rename = true;
yield return new WaitForSeconds(1f);
if (vessel != FlightGlobals.ActiveVessel)
{
Part p;
PartModule pm;
ModuleAvionics am;
for (int i = vessel.Parts.Count; i-- > 0;)
{
p = vessel.Parts[i];
if (p == part)
continue;

bool hasCommand = false;
bool allAvionicsDebris = true;
bool noAvionics = true;
for (int j = p.Modules.Count; j-- > 0;)
{
pm = p.Modules[j];
if (pm is ModuleCommand)
{
hasCommand = true;
}
else if (pm is ModuleAvionics)
{
noAvionics = false;
am = pm as ModuleAvionics;
if (!am.setToDebrisOnStage)
allAvionicsDebris = false;
}
}
if (hasCommand && (noAvionics || !allAvionicsDebris))
{
rename = false;
break;
}
}

if (rename)
vessel.vesselType = VesselType.Debris;
}
}
#endregion

#region Overrides
public override void OnAwake()
{
base.OnAwake();
GameEvents.onStageActivate.Add(StageActivated);
}

public void Start()
{
// check then bind to ModuleCommand
@@ -152,6 +211,11 @@ public void Start()
SetActionsAndGui();
}

protected void OnDestroy()
{
GameEvents.onStageActivate.Remove(StageActivated);
}

protected virtual string GetTonnageString()
{
string retStr = "This part allows control of vessels of ";

0 comments on commit d5c07d2

Please sign in to comment.