Skip to content

Commit

Permalink
Merge pull request #12 from yalov/Dev-KaboomSuperglue
Browse files Browse the repository at this point in the history
# fix kabooming by kerbal
 * Invoke() with delay instead of OnUpdate(). 
      * scale delay on timewarp. Parts are able to kaboom while timewarp
 * fix decoupling of decouplers on glued kaboom
 * fix missing title and fields for kabooming by kerbal within range
      *  increase range to 10, same as EVA Construction Mode range

![](https://i.imgur.com/gFaxXfN.jpeg)
  • Loading branch information
zer0Kerbal authored Sep 20, 2021
2 parents 6e3f398 + 682d527 commit 6852faa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 41 deletions.
66 changes: 25 additions & 41 deletions source/Kaboom.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using KSP.Localization;
using UnityEngine;

namespace Kaboom
{
Expand All @@ -7,24 +8,18 @@ namespace Kaboom
/// </summary>
public class ModuleKaboom : PartModule
{
[KSPField(isPersistant = true, guiActiveEditor = true, guiActive = true, guiName = "Kaboom delay",
groupName = "Kaboom", groupStartCollapsed = true,
guiUnits = " Seconds"),
[KSPField(isPersistant = true,
guiName = "Kaboom delay", groupName = "Kaboom", groupStartCollapsed = true, guiUnits = " Seconds",
guiActive = true, guiActiveUnfocused = true, unfocusedRange = 10f, guiActiveEditor = true),
UI_FloatRange(minValue = 0f, maxValue = 30f, stepIncrement = 1f)]

public float delay = 0;

[KSPField(isPersistant = true)]
public bool timerActive = false;

[KSPField(isPersistant = true)]
public double kaboomTime;

[KSPField(isPersistant = true)]
public bool isGlued = false;

[KSPEvent(groupName = "Kaboom",
guiActive = true, guiActiveEditor = true, active = true, guiActiveUncommand = true)]
guiActive = true, guiActiveUnfocused = true, unfocusedRange = 10f, guiActiveEditor = true,
active = true, guiActiveUncommand = true)]
public void GluedEvent()
{
isGlued = !isGlued;
Expand All @@ -40,14 +35,16 @@ private void GUITextUpdate()
}

[KSPEvent(guiName = "Kaboom!", groupName = "Kaboom",
guiActive = true, guiActiveUnfocused = true, unfocusedRange = 5f, active = true, guiActiveUncommand = true)]
guiActive = true, guiActiveUnfocused = true, unfocusedRange = 10f,
active = true, guiActiveUncommand = true)]
public void KaboomEvent()
{
KaboomIt();
}

[KSPEvent(guiName = "Cancel Kaboom!", groupName = "Kaboom",
guiActive = true, guiActiveUnfocused = true, unfocusedRange = 5f, active = false, guiActiveUncommand = true)]
guiActive = true, guiActiveUnfocused = true, unfocusedRange = 10f,
active = false, guiActiveUncommand = true)]
public void CancelKaboomEvent()
{
CancelKaboomIt();
Expand All @@ -66,66 +63,53 @@ public override void OnStart(StartState state)
Fields["delay"].group.displayName = "Kaboom Safety Cover";

GUITextUpdate();

}

private void KaboomIt()
{
Events["CancelKaboomEvent"].active = true;
Events["KaboomEvent"].active = false;
part.force_activate();

if (delay == 0)
{
bool success = Proceed();
if (!success)
CancelKaboomIt();
Proceed();
}
else
{
float delay_scaled = delay;

if (TimeWarp.WarpMode == TimeWarp.Modes.HIGH)
delay_scaled /= TimeWarp.CurrentRate;

Invoke("Proceed", delay_scaled);
ScreenMessages.PostScreenMessage("Kaboom set for " + delay + " seconds.", 5.0f, ScreenMessageStyle.UPPER_CENTER);
kaboomTime = Planetarium.GetUniversalTime() + delay;
timerActive = true;
}
}

private bool Proceed()
private void Proceed()
{
bool success;
if (isGlued)
{
var k = new Welding(vessel, part);
bool success = k.MergeParts(true);
return success;
success = k.MergeParts(true);
}
else
{
part.force_activate();
WeldingUtilities.Explode(part);
return true;
success = true;
}

if (!success)
CancelKaboomIt();
}

private void CancelKaboomIt()
{
Events["CancelKaboomEvent"].active = false;
Events["KaboomEvent"].active = true;
ScreenMessages.PostScreenMessage("Kaboom canceled.", 5.0f, ScreenMessageStyle.UPPER_CENTER);
timerActive = false;
}

public override void OnUpdate()
{
base.OnUpdate();
if (timerActive)
{
if (Planetarium.GetUniversalTime() >= kaboomTime)
{
timerActive = false;
bool success = Proceed();
if (!success)
CancelKaboomIt();
}
}
//base.OnUpdate();
}
}
}
4 changes: 4 additions & 0 deletions source/Repo-Kaboom112.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
<DesignTime>True</DesignTime>
<DependentUpon>Version.tt</DependentUpon>
</Compile>
<Compile Include="Support\Settings.cs" />
<Compile Include="Welding\Welding.cs" />
<Compile Include="Welding\WeldingData.cs" />
<Compile Include="Welding\WeldingUtilities.cs" />
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Service References\" />
Expand Down

0 comments on commit 6852faa

Please sign in to comment.