csproj changes for Visual Studio master
csproj changes for Visual Studio

file:b/.gitattributes (new)
  * text=auto
  * eol=lf
 
  # These files are text and should be normalized (convert crlf => lf)
  *.cs text diff=csharp
  *.cfg text
  *.csproj text eol=crlf
  *.sln text eol=crlf
 
  # Images should be treated as binary
  # (binary is a macro for -text -diff)
  *.png binary
  *.mbm binary
 
// QuantumStrutsContinued // QuantumStrutsContinued
// //
// Continued from QuantumStruts by BoJaN. Used by permission. // Continued from QuantumStruts by BoJaN. Used by permission.
// //
// ModuleManager patches © 2014 K3|Chris. Used by permission. // ModuleManager patches © 2014 K3|Chris. Used by permission.
// //
// Copyright © 2014, toadicus // Copyright © 2014, toadicus
// All rights reserved. // All rights reserved.
// //
// Redistribution and use in source and binary forms, with or without modification, // Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met: // are permitted provided that the following conditions are met:
// //
// 1. Redistributions of source code must retain the above copyright notice, // 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer. // this list of conditions and the following disclaimer.
// //
// 2. Redistributions in binary form must reproduce the above copyright notice, // 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation and/or other // this list of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution. // materials provided with the distribution.
// //
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ARISING IN ANY WAY OUT OF THE USE // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   
PART PART
{ {
// --- general parameters --- // --- general parameters ---
name = QuantumStrut name = QuantumStrut
module = Part module = Part
author = BoJaN author = BoJaN
   
// --- asset parameters --- // --- asset parameters ---
MODEL MODEL
{ {
model = Squad/Parts/Utility/linearRCS/model model = Squad/Parts/Utility/linearRCS/model
} }
rescaleFactor = 0.6 rescaleFactor = 0.6
   
// --- node definitions --- // --- node definitions ---
// definition format is Position X, Position Y, Position Z, Up X, Up Y, Up Z // definition format is Position X, Position Y, Position Z, Up X, Up Y, Up Z
node_attach = 0.0, 0.0 , 0.0, 0.0, -1.0, 0.0 node_attach = 0.0, 0.0 , 0.0, 0.0, -1.0, 0.0
   
// --- editor parameters --- // --- editor parameters ---
TechRequired = advScienceTech TechRequired = advScienceTech
cost = 1500 cost = 1500
category = Structural category = Structural
subcategory = 0 subcategory = 0
title = Quantum Strut title = Quantum Strut
manufacturer = Bojantek Corporation manufacturer = Bojantek Corporation
description = Highly experimental quantum struts harness a form of quantum locking to add support for docked vessels. description = Highly experimental quantum struts harness a form of quantum locking to add support for docked vessels.
   
// attachment rules: stack, srfAttach, allowStack, allowSrfAttach, allowCollision // attachment rules: stack, srfAttach, allowStack, allowSrfAttach, allowCollision
attachRules = 0,1,0,1,1 attachRules = 0,1,0,1,1
   
// --- standard part parameters --- // --- standard part parameters ---
mass = 0.05 mass = 0.05
dragModelType = default dragModelType = default
maximum_drag = 0.01 maximum_drag = 0.01
minimum_drag = 0.01 minimum_drag = 0.01
angularDrag = 0.1 angularDrag = 0.1
crashTolerance = 50 crashTolerance = 50
breakingForce = 50 breakingForce = 50
breakingTorque = 50 breakingTorque = 50
maxTemp = 3400 maxTemp = 3400
   
MODULE MODULE
{ {
name = QuantumStrut name = QuantumStrut
IsEnabled = true IsEnabled = true
PowerConsumption = 0.01 PowerConsumption = 0.01
   
Material = Particles/Additive Material = Particles/Additive
StartColor = 57, 146, 181 StartColor = 57, 146, 181
EndColor = 11, 29, 36 EndColor = 11, 29, 36
StartSize = 0.03 StartSize = 0.03
EndSize = 0.0025 EndSize = 0.015
   
Start = 0,0,0 Start = 0,0,0
Dir = 0,1,0 Dir = 0,1,0
} }
} }
   
// QuantumStrutsContinued // QuantumStrutsContinued
// //
// Continued from QuantumStruts by BoJaN. Used by permission. // Continued from QuantumStruts by BoJaN. Used by permission.
// //
// ModuleManager patches © 2014 K3|Chris. Used by permission. // ModuleManager patches © 2014 K3|Chris. Used by permission.
// //
// Copyright © 2014, toadicus // Copyright © 2014, toadicus
// All rights reserved. // All rights reserved.
// //
// Redistribution and use in source and binary forms, with or without modification, // Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met: // are permitted provided that the following conditions are met:
// //
// 1. Redistributions of source code must retain the above copyright notice, // 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer. // this list of conditions and the following disclaimer.
// //
// 2. Redistributions in binary form must reproduce the above copyright notice, // 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation and/or other // this list of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution. // materials provided with the distribution.
// //
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ARISING IN ANY WAY OUT OF THE USE // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   
PART PART
{ {
// --- general parameters --- // --- general parameters ---
name = StrutGun name = StrutGun
module = Part module = Part
author = BoJaN author = BoJaN
   
// --- asset parameters --- // --- asset parameters ---
MODEL MODEL
{ {
model = Squad/Parts/Utility/linearRCS/model model = Squad/Parts/Utility/linearRCS/model
} }
rescaleFactor = 0.6 rescaleFactor = 0.6
   
// --- node definitions --- // --- node definitions ---
// definition format is Position X, Position Y, Position Z, Up X, Up Y, Up Z // definition format is Position X, Position Y, Position Z, Up X, Up Y, Up Z
node_attach = 0.0, 0.0 , 0.0, 0.0, -1.0, 0.0 node_attach = 0.0, 0.0 , 0.0, 0.0, -1.0, 0.0
   
// --- editor parameters --- // --- editor parameters ---
TechRequired = advScienceTech TechRequired = advScienceTech
cost = 500 cost = 500
category = Structural category = Structural
subcategory = 0 subcategory = 0
title = Strut Gun title = Strut Gun
manufacturer = Bojantek Corporation manufacturer = Bojantek Corporation
description = A radial strut gun for attaching and detatching struts when needed description = A radial strut gun for attaching and detatching struts when needed
   
// attachment rules: stack, srfAttach, allowStack, allowSrfAttach, allowCollision // attachment rules: stack, srfAttach, allowStack, allowSrfAttach, allowCollision
attachRules = 0,1,0,1,1 attachRules = 0,1,0,1,1
   
// --- standard part parameters --- // --- standard part parameters ---
mass = 0.05 mass = 0.05
dragModelType = default dragModelType = default
maximum_drag = 0.01 maximum_drag = 0.01
minimum_drag = 0.01 minimum_drag = 0.01
angularDrag = 0.1 angularDrag = 0.1
crashTolerance = 50 crashTolerance = 50
breakingForce = 50 breakingForce = 50
breakingTorque = 50 breakingTorque = 50
maxTemp = 3400 maxTemp = 3400
   
MODULE MODULE
{ {
name = QuantumStrut name = QuantumStrut
IsEnabled = true IsEnabled = true
PowerConsumption = 0.01 PowerConsumption = 0.01
   
Material = KSP/Sprite Material = KSP/Sprite
StartColor = 50, 50, 50 StartColor = 50, 50, 50
EndColor = 50, 50, 50 EndColor = 50, 50, 50
StartSize = 0.03 StartSize = 0.03
EndSize = 0.03 EndSize = 0.03
   
Start = 0,0,0 Start = 0,0,0
Dir = 0,1,0 Dir = 0,1,0
} }
} }
   
// QuantumStrutsContinued // QuantumStrutsContinued
// //
// AssemblyInfo.cs // AssemblyInfo.cs
// //
// Continued from QuantumStruts by BoJaN. Used by permission. // Continued from QuantumStruts by BoJaN. Used by permission.
// //
// ModuleManager patches © 2014 K3|Chris. Used by permission. // ModuleManager patches © 2014 K3|Chris. Used by permission.
// //
// Copyright © 2014, toadicus // Copyright © 2014, toadicus
// All rights reserved. // All rights reserved.
// //
// Redistribution and use in source and binary forms, with or without modification, // Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met: // are permitted provided that the following conditions are met:
// //
// 1. Redistributions of source code must retain the above copyright notice, // 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer. // this list of conditions and the following disclaimer.
// //
// 2. Redistributions in binary form must reproduce the above copyright notice, // 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation and/or other // this list of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution. // materials provided with the distribution.
// //
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
   
// General Information about an assembly is controlled through the following // General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information // set of attributes. Change these attribute values to modify the information
// associated with an assembly. // associated with an assembly.
[assembly: AssemblyTitle("QuantumStrutsContinued")] [assembly: AssemblyTitle("QuantumStrutsContinued")]
[assembly: AssemblyDescription("A KSP part mod that provides magical struts for rigidifying vessels constructed outside the VAB.")] [assembly: AssemblyDescription("A KSP part mod that provides magical struts for rigidifying vessels constructed outside the VAB.")]
[assembly: AssemblyProduct("QuantumStrutsContinued")] [assembly: AssemblyProduct("QuantumStrutsContinued")]
[assembly: AssemblyCopyright("Copyright © 2014 toadicus")] [assembly: AssemblyCopyright("Copyright © 2014 toadicus")]
   
// Setting ComVisible to false makes the types in this assembly not visible // Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from // to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type. // COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)] [assembly: ComVisible(false)]
   
// The following GUID is for the ID of the typelib if this project is exposed to COM // The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("57e209db-4b94-46b4-be0e-bd6e830d4eb5")] [assembly: Guid("57e209db-4b94-46b4-be0e-bd6e830d4eb5")]
   
// Version information for an assembly consists of the following four values: // Version information for an assembly consists of the following four values:
// //
// Major Version // Major Version
// Minor Version // Minor Version
// Build Number // Build Number
// Revision // Revision
// //
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.4.*")] [assembly: AssemblyVersion("1.6.*")]
   
// QuantumStrutsContinued // QuantumStrutsContinued
// //
// QuantumStrut.cs // QuantumStrut.cs
// //
// Continued from QuantumStruts by BoJaN. Used by permission. // Continued from QuantumStruts by BoJaN. Used by permission.
// //
// ModuleManager patches © 2014 K3|Chris. Used by permission. // ModuleManager patches © 2014 K3|Chris. Used by permission.
// //
// Copyright © 2014, toadicus // Copyright © 2014, toadicus
// All rights reserved. // All rights reserved.
// //
// Redistribution and use in source and binary forms, with or without modification, // Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met: // are permitted provided that the following conditions are met:
// //
// 1. Redistributions of source code must retain the above copyright notice, // 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer. // this list of conditions and the following disclaimer.
// //
// 2. Redistributions in binary form must reproduce the above copyright notice, // 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation and/or other // this list of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution. // materials provided with the distribution.
// //
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   
#define DEBUG  
   
using KSP; using KSP;
using System; using System;
using ToadicusTools; using ToadicusTools;
using UnityEngine; using UnityEngine;
   
namespace QuantumStrut namespace QuantumStrut
{ {
public class QuantumStrut : PartModule public class QuantumStrut : PartModule
{ {
public static Material LaserMaterial; public static Material LaserMaterial;
Strut strut = null; Strut strut = null;
GameObject lineObj; GameObject lineObj;
LineRenderer lr; LineRenderer lr;
bool Editor = false;  
int I = 0; int I = 0;
   
#region Fields #region Fields
   
[KSPField(isPersistant = true)] [KSPField(isPersistant = true)]
public bool IsEnabled = true; public bool IsEnabled = true;
[KSPField(isPersistant = false)] [KSPField(isPersistant = false)]
public float PowerConsumption = 0; public float PowerConsumption = 0;
[KSPField(isPersistant = false)] [KSPField(isPersistant = false)]
public string TransformName = ""; public string TransformName = "";
[KSPField(isPersistant = false)] [KSPField(isPersistant = false)]
public Vector3 Start = new Vector3(0, 0, 0); public Vector3 Start = new Vector3(0, 0, 0);
[KSPField(isPersistant = false)] [KSPField(isPersistant = false)]
public Vector3 Dir = new Vector3(0, 1, 0); public Vector3 Dir = new Vector3(0, 1, 0);
[KSPField(isPersistant = false)] [KSPField(isPersistant = false)]
public string Material = "Particles/Additive"; public string Material = "Particles/Additive";
[KSPField(isPersistant = false)] [KSPField(isPersistant = false)]
public Vector3 StartColor = Vector3.zero; public Vector3 StartColor = Vector3.zero;
[KSPField(isPersistant = false)] [KSPField(isPersistant = false)]
public Vector3 EndColor = Vector3.zero; public Vector3 EndColor = Vector3.zero;
[KSPField(isPersistant = false)] [KSPField(isPersistant = false)]
public float StartSize = 0.03f; public float StartSize = 0.03f;
[KSPField(isPersistant = false)] [KSPField(isPersistant = false)]
public float EndSize = 0.0075f; public float EndSize = 0.015f;
   
  [KSPField(
  isPersistant = false, guiActiveEditor = true,
  guiName = "Max. Strut Length", guiUnits = "m", guiFormat = "F0"
  )]
  [UI_FloatRange(minValue = 2f, maxValue = 50f, stepIncrement = 2f)]
  public float MaxStrutLength = 10f;
   
#endregion #endregion
   
#region Actions #region Actions
   
[KSPAction("Toggle")] [KSPAction("Toggle")]
public void ToggleStrut(KSPActionParam param) public void ToggleStrut(KSPActionParam param)
{ {
IsEnabled = !IsEnabled; IsEnabled = !IsEnabled;
CheckHit(); CheckHit();
} }
   
[KSPAction("Activate")] [KSPAction("Activate")]
public void ActivateStrut(KSPActionParam param) public void ActivateStrut(KSPActionParam param)
{ {
this.ActivateStrut(); this.ActivateStrut();
} }
   
[KSPAction("Deactivate")] [KSPAction("Deactivate")]
public void DeactivateStrut(KSPActionParam param) public void DeactivateStrut(KSPActionParam param)
{ {
this.DeactivateStrut(); this.DeactivateStrut();
} }
   
#endregion #endregion
   
#region Events #region Events
   
[KSPEvent(guiActive = true, guiName = "Activate", active = true, guiActiveUnfocused = true, unfocusedRange = 2f)] [KSPEvent(guiActive = true, guiName = "Activate", active = true, guiActiveUnfocused = true, unfocusedRange = 2f)]
public void ActivateStrut() public void ActivateStrut()
{ {
IsEnabled = true; IsEnabled = true;
CheckHit(); CheckHit();
this.Events["ActivateStrut"].guiActiveEditor = false; this.Events["ActivateStrut"].guiActiveEditor = false;
this.Events["DeactivateStrut"].guiActiveEditor = true; this.Events["DeactivateStrut"].guiActiveEditor = true;
} }
   
[KSPEvent(guiActive = true, guiName = "Deactivate", active = false, guiActiveUnfocused = true, unfocusedRange = 2f)] [KSPEvent(guiActive = true, guiName = "Deactivate", active = false, guiActiveUnfocused = true, unfocusedRange = 2f)]
public void DeactivateStrut() public void DeactivateStrut()
{ {
IsEnabled = false; IsEnabled = false;
CheckHit(); CheckHit();
this.Events["ActivateStrut"].guiActiveEditor = true; this.Events["ActivateStrut"].guiActiveEditor = true;
this.Events["DeactivateStrut"].guiActiveEditor = false; this.Events["DeactivateStrut"].guiActiveEditor = false;
} }
   
#endregion #endregion
   
public Material material = null; public Material material = null;
public Color startColor = Color.white; public Color startColor = Color.white;
public Color endColor = Color.white; public Color endColor = Color.white;
   
public Color Vector3toColor(Vector3 vec) public Color Vector3toColor(Vector3 vec)
{ {
return new Color(vec.x / 255, vec.y / 255, vec.z / 255); return new Color(vec.x / 255, vec.y / 255, vec.z / 255);
} }
   
Transform getTransform() Transform getTransform()
{ {
if (TransformName == "") if (TransformName == "")
return part.transform; return part.transform;
else else
return part.FindModelTransform(TransformName); return part.FindModelTransform(TransformName);
} }
   
public void print(object body, params object[] args) public void print(object body, params object[] args)
{ {
string final = body.ToString(); string final = body.ToString();
for (int I = 0; I < args.Length; I++) for (int I = 0; I < args.Length; I++)
{ {
final = final.Replace("{" + I + "}", args[I].ToString()); final = final.Replace("{" + I + "}", args[I].ToString());
} }
MonoBehaviour.print("[AutoStrut] " + final); MonoBehaviour.print("[AutoStrut] " + final);
} }
   
public override void OnLoad(ConfigNode node) public override void OnLoad(ConfigNode node)
{ {
base.OnLoad(node); base.OnLoad(node);
} }
   
public override void OnActive() public override void OnActive()
{ {
InitLaser(); InitLaser();
   
base.OnActive(); base.OnActive();
} }
   
public override void OnInactive() public override void OnInactive()
{ {
DestroyLaser(); DestroyLaser();
   
base.OnInactive(); base.OnInactive();
} }
   
public override string GetInfo() public override string GetInfo()
{ {
return "Requires:\n- ElectricCharge (" + PowerConsumption + "/s.)\n\n Costs 5 to create strut."; return "Requires:\n- ElectricCharge (" + PowerConsumption + "/s.)\n\n Costs 5 to create strut.";
} }
   
public override void OnStart(PartModule.StartState state) public override void OnStart(PartModule.StartState state)
{ {
try try
{ {
print("Material: {0}", Material); print("Material: {0}", Material);
material = new Material(Shader.Find(Material.Trim())); material = new Material(Shader.Find(Material.Trim()));
} }
catch catch
{ {
material = null; material = null;
} }
   
base.stagingEnabled = false; base.stagingEnabled = false;
   
startColor = Vector3toColor(StartColor); startColor = Vector3toColor(StartColor);
endColor = Vector3toColor(EndColor); endColor = Vector3toColor(EndColor);
   
if (!Util.isValid(LaserMaterial)) if (!Util.isValid(LaserMaterial))
LaserMaterial = new Material(Shader.Find("Particles/Additive")); LaserMaterial = new Material(Shader.Find("Particles/Additive"));
   
if (state == StartState.Docked) switch (state)
CheckHit(); {
  case StartState.Editor:
if (state == StartState.Editor) InitLaser();
{ break;
Editor = true; case StartState.Docked:
RenderingManager.AddToPostDrawQueue(0, DrawBuildOverlay); CheckHit();
InitLaser(); DestroyLaser();
} break;
else default:
{ DestroyLaser();
Editor = false; break;
RenderingManager.RemoveFromPostDrawQueue(0, DrawBuildOverlay);  
DestroyLaser();  
} }
   
base.OnStart(state); base.OnStart(state);
} }
   
public override bool IsStageable() public override bool IsStageable()
{ {
return false; return false;
  }
   
  public void Update()
  {
  if (strut != null && !strut.isDestroyed)
  {
  if (PowerConsumption == 0 || (Util.GetEnergy(part.vessel) > PowerConsumption * TimeWarp.fixedDeltaTime && part.RequestResource(
  "ElectricCharge",
  PowerConsumption * TimeWarp.fixedDeltaTime
  ) > 0))
  {
  strut.Update();
  }
  else
  {
  strut.Destroy();
  }
  }
} }
   
public void FixedUpdate() public void FixedUpdate()
{ {
Events["ActivateStrut"].guiActiveEditor = Events["ActivateStrut"].active = !IsEnabled; Events["ActivateStrut"].guiActiveEditor = Events["ActivateStrut"].active = !IsEnabled;
Events["DeactivateStrut"].guiActiveEditor = Events["DeactivateStrut"].active = IsEnabled; Events["DeactivateStrut"].guiActiveEditor = Events["DeactivateStrut"].active = IsEnabled;
   
if (IsEnabled) if (IsEnabled)
{ {
I = I + 1 % 255; I = I + 1 % 255;
   
if (strut != null && !strut.isDestroyed) if (strut == null || strut.isDestroyed)
{  
if (PowerConsumption == 0 || (Util.GetEnergy(part.vessel) > PowerConsumption * TimeWarp.fixedDeltaTime && part.RequestResource(  
"ElectricCharge",  
PowerConsumption * TimeWarp.fixedDeltaTime  
) > 0))  
strut.Update();  
else  
strut.Destroy();  
}  
else  
{ {
if ((I % 10) == 0) if ((I % 10) == 0)
{ {
CheckHit(); CheckHit();
} }
} }
} }
else else
{ {
if (strut != null) if (strut != null)
{ {
strut.Destroy(); strut.Destroy();
strut = null; strut = null;
} }
} }
   
base.OnUpdate(); base.OnUpdate();
} }
   
  public void OnGUI()
  {
  if (HighLogic.LoadedSceneIsEditor && Util.isValid(part))
  {
  this.DrawBuildOverlay();
  }
  else
  {
  DestroyLaser();
  }
  }
   
  public void OnDestroy()
  {
  DestroyLaser();
  }
   
void CheckHit() void CheckHit()
{ {
if (HighLogic.LoadedSceneIsEditor) if (HighLogic.LoadedSceneIsEditor)
{ {
Logging.PostDebugMessage(this, "Checking bailing out: in the editor!"); Logging.PostDebugMessage(this, "Checking bailing out: in the editor!");
return; return;
} }
   
if (!isEnabled) if (!isEnabled)
{ {
Logging.PostDebugMessage(this, "Destroying strut."); Logging.PostDebugMessage(this, "Destroying strut.");
   
strut.Destroy(); strut.Destroy();
strut = null; strut = null;
return; return;
} }
   
Logging.PostDebugMessage(this, "Checking for ray hit."); Logging.PostDebugMessage(this, "Checking for ray hit.");
   
Logging.PostDebugMessage(this, "Enabled, continuing."); Logging.PostDebugMessage(this, "Enabled, continuing.");
   
if (strut == null || strut.isDestroyed) if (strut == null || strut.isDestroyed)
{ {
Logging.PostDebugMessage(this, "strut is {0}", strut == null ? "null" : strut.isDestroyed.ToString()); Logging.PostDebugMessage(this, "strut is {0}", strut == null ? "null" : strut.isDestroyed.ToString());
   
Vector3 dir = getTransform().TransformDirection(Dir); Vector3 dir = getTransform().TransformDirection(Dir);
Vector3 start = getTransform().TransformPoint(Start); Vector3 start = getTransform().TransformPoint(Start);
   
Logging.PostDebugMessage(this, "Got transforms. Checking for raycast hit."); Logging.PostDebugMessage(this, "Got transforms. Checking for raycast hit.");
   
UnityEngine.RaycastHit info = new RaycastHit(); UnityEngine.RaycastHit info = new RaycastHit();
bool hit = Physics.Raycast(new UnityEngine.Ray(start + (dir * 0.05f), dir), out info, 10); bool hit = Physics.Raycast(new UnityEngine.Ray(start + (dir * 0.05f), dir), out info, MaxStrutLength);
   
if (hit) if (hit)
{ {
Logging.PostDebugMessage(this, "Found raycast hit. Fetching target part."); Logging.PostDebugMessage(this, "Found raycast hit. Fetching target part.");
   
Part targetPart = Util.partFromRaycast(info); Part targetPart = Util.partFromRaycast(info);
   
Logging.PostDebugMessage(this, Logging.PostDebugMessage(this,
"Found target part {0} on {1}.", "Found target part {0} on {1}.",
targetPart.partName, targetPart.partName,
targetPart.vessel == null ? "null vessel" : targetPart.vessel.vesselName targetPart.vessel == null ? "null vessel" : targetPart.vessel.vesselName
); );
   
if ( if (
targetPart && vessel.parts.Contains(targetPart) && targetPart && vessel.parts.Contains(targetPart) &&
Util.GetEnergy(part.vessel) > 5 * TimeWarp.fixedDeltaTime Util.GetEnergy(part.vessel) > 5 * TimeWarp.fixedDeltaTime
) )
{ {
Logging.PostDebugMessage(this, "Target part is in our vessel and we have the energy to continue."); Logging.PostDebugMessage(this, "Target part is in our vessel and we have the energy to continue.");
   
strut = new Strut( strut = new Strut(
part, part,
targetPart, targetPart,
targetPart.transform.InverseTransformPoint(info.point), targetPart.transform.InverseTransformPoint(info.point),
getTransform() getTransform()
); );
   
Logging.PostDebugMessage(this, "Built a new strut, setting material, colors, and sizes."); Logging.PostDebugMessage(this, "Built a new strut, setting material, colors, and sizes.");
   
strut.Material = material; strut.Material = material;
strut.StartColor = startColor; strut.StartColor = startColor;
strut.EndColor = endColor; strut.EndColor = endColor;
strut.StartSize = StartSize; strut.StartSize = StartSize;
strut.EndSize = EndSize; strut.EndSize = EndSize;
   
Logging.PostDebugMessage(this, "Strut all done!"); Logging.PostDebugMessage(this, "Strut all done!");
} }
} }
} }
} }
   
void InitLaser() void InitLaser()
{ {
if (!Util.isValid(lr)) if (!Util.isValid(lr))
{ {
lineObj = new GameObject(); lineObj = new GameObject();
   
lr = lineObj.AddComponent<LineRenderer>(); lr = lineObj.AddComponent<LineRenderer>();
lr.useWorldSpace = true; lr.useWorldSpace = false;
   
lr.material = material; lr.material = material;
lr.SetColors(startColor, endColor); lr.SetColors(startColor, endColor);
lr.SetWidth(StartSize, EndSize); lr.SetWidth(StartSize, EndSize);
   
lr.SetVertexCount(2); lr.SetVertexCount(2);
lr.SetPosition(0, Vector3.zero); lr.SetPosition(0, Vector3.zero);
lr.SetPosition(1, Vector3.zero); lr.SetPosition(1, Vector3.zero);
lr.castShadows = false; lr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
lr.receiveShadows = true; lr.receiveShadows = true;
} }
} }
   
void DestroyLaser() void DestroyLaser()
{ {
if (Util.isValid(lr)) if (Util.isValid(lr))
LineRenderer.DestroyImmediate(lr); LineRenderer.DestroyImmediate(lr);
   
if (Util.isValid(lineObj)) if (Util.isValid(lineObj))
GameObject.DestroyImmediate(lineObj); GameObject.DestroyImmediate(lineObj);
} }
   
public void DrawBuildOverlay() public void DrawBuildOverlay()
{ {
if (Util.isValid(part)) if (Util.isValid(lr))
{ {
if (!Editor) Vector3 dir = getTransform().TransformDirection(Dir);
return; Vector3 start = getTransform().TransformPoint(Start);
   
if (Util.isValid(lr)) UnityEngine.RaycastHit info = new RaycastHit();
{ bool hit = Physics.Raycast(new UnityEngine.Ray(start + (dir * 0.05f), dir), out info, MaxStrutLength);
Vector3 dir = getTransform().TransformDirection(Dir); if (hit && IsEnabled)
Vector3 start = getTransform().TransformPoint(Start); {
  if (Util.isValid(material))
UnityEngine.RaycastHit info = new RaycastHit(); lr.material = material;
bool hit = Physics.Raycast(new UnityEngine.Ray(start + (dir * 0.05f), dir), out info, 10);  
if (hit && IsEnabled) lr.SetColors(startColor, endColor);
{ lr.SetWidth(StartSize, EndSize);
if (Util.isValid(material))  
lr.material = material; lr.SetPosition(0, start);
  lr.SetPosition(1, info.point);
lr.SetColors(startColor, endColor); }
lr.SetWidth(StartSize, EndSize); else
  {
lr.SetPosition(0, start); lr.material = LaserMaterial;
lr.SetPosition(1, info.point); lr.SetColors(Color.red, Color.red);
} lr.SetWidth(0.01f, 0.01f);
else  
{ lr.SetPosition(0, start);
lr.material = LaserMaterial; lr.SetPosition(1, start + (dir * MaxStrutLength));
lr.SetColors(Color.red, Color.red); }
lr.SetWidth(0.01f, 0.01f);  
   
lr.SetPosition(0, start);  
lr.SetPosition(1, start + (dir * 10));  
}  
}  
}  
else  
{  
DestroyLaser();  
RenderingManager.RemoveFromPostDrawQueue(0, DrawBuildOverlay);  
} }
} }
} }
} }
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug_win</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug_win</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion> <ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion> <SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{D6EC2150-27A5-4CB2-ACF9-C53FF7754A77}</ProjectGuid> <ProjectGuid>{D6EC2150-27A5-4CB2-ACF9-C53FF7754A77}</ProjectGuid>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<RootNamespace>QuantumStrutsContinued</RootNamespace> <RootNamespace>QuantumStrutsContinued</RootNamespace>
<AssemblyName>QuantumStrutsContinued</AssemblyName> <AssemblyName>QuantumStrutsContinued</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion> <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<UseMSBuildEngine>False</UseMSBuildEngine> <UseMSBuildEngine>False</UseMSBuildEngine>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug_win|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug_win|AnyCPU' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath> <OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants> <DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget> <PlatformTarget>x86</PlatformTarget>
<ConsolePause>false</ConsolePause> <ConsolePause>false</ConsolePause>
<CustomCommands> <CustomCommands>
<CustomCommands> <CustomCommands>
<Command type="AfterBuild" command="xcopy /Y ${TargetFile} ${ProjectDir}\GameData\QuantumStrutsContinued\Plugins\" /> <Command type="AfterBuild" command="xcopy /Y ${TargetFile} ${ProjectDir}\GameData\QuantumStrutsContinued\Plugins\" />
</CustomCommands> </CustomCommands>
</CustomCommands> </CustomCommands>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release_win|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release_win|AnyCPU' ">
<Optimize>true</Optimize> <Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath> <OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget> <PlatformTarget>x86</PlatformTarget>
<ConsolePause>false</ConsolePause> <ConsolePause>false</ConsolePause>
<CustomCommands> <CustomCommands>
<CustomCommands> <CustomCommands>
<Command type="AfterBuild" command="xcopy /Y ${TargetFile} ${ProjectDir}\GameData\QuantumStrutsContinued\Plugins\" /> <Command type="AfterBuild" command="xcopy /Y ${TargetFile} ${ProjectDir}\GameData\QuantumStrutsContinued\Plugins\" />
</CustomCommands> </CustomCommands>
</CustomCommands> </CustomCommands>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug_linux|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug_linux|AnyCPU' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath> <OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants> <DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause> <ConsolePause>false</ConsolePause>
<PlatformTarget>x86</PlatformTarget> <PlatformTarget>x86</PlatformTarget>
<CustomCommands> <CustomCommands>
<CustomCommands> <CustomCommands>
<Command type="AfterBuild" command="cp -af ${TargetFile} ${ProjectDir}/GameData/QuantumStrutsContinued/Plugins/" /> <Command type="AfterBuild" command="cp -af ${TargetFile} ${ProjectDir}/GameData/QuantumStrutsContinued/Plugins/" />
</CustomCommands> </CustomCommands>
</CustomCommands> </CustomCommands>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release_linux|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release_linux|AnyCPU' ">
<Optimize>true</Optimize> <Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath> <OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<CustomCommands> <CustomCommands>
<CustomCommands> <CustomCommands>
<Command type="AfterBuild" command="cp -af ${TargetFile} ${ProjectDir}/GameData/QuantumStrutsContinued/Plugins/" /> <Command type="AfterBuild" command="cp -af ${TargetFile} ${ProjectDir}/GameData/QuantumStrutsContinued/Plugins/" />
</CustomCommands> </CustomCommands>
</CustomCommands> </CustomCommands>
<ConsolePause>false</ConsolePause> <ConsolePause>false</ConsolePause>
<PlatformTarget>x86</PlatformTarget> <PlatformTarget>x86</PlatformTarget>
</PropertyGroup> </PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup> <ItemGroup>
<Compile Include="QuantumStrut.cs" /> <Compile Include="QuantumStrut.cs" />
<Compile Include="Strut.cs" /> <Compile Include="Strut.cs" />
<Compile Include="Util.cs" /> <Compile Include="Util.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="..\ToadicusTools\Extensions\ComponentExtensions.cs"> <Compile Include="..\ToadicusTools\Extensions\ComponentExtensions.cs">
<Link>ToadicusTools\ComponentExtensions.cs</Link> <Link>ToadicusTools\ComponentExtensions.cs</Link>
</Compile> </Compile>
<Compile Include="..\ToadicusTools\Text\Extensions.cs"> <Compile Include="..\ToadicusTools\Text\Extensions.cs">
<Link>ToadicusTools\Extensions.cs</Link> <Link>ToadicusTools\Extensions.cs</Link>
</Compile> </Compile>
<Compile Include="..\ToadicusTools\Logging.cs"> <Compile Include="..\ToadicusTools\Logging.cs">
<Link>ToadicusTools\Logging.cs</Link> <Link>ToadicusTools\Logging.cs</Link>
</Compile> </Compile>
<Compile Include="..\ToadicusTools\MathTools.cs"> <Compile Include="..\ToadicusTools\MathTools.cs">
<Link>ToadicusTools\MathTools.cs</Link> <Link>ToadicusTools\MathTools.cs</Link>
</Compile> </Compile>
<Compile Include="..\ToadicusTools\MuMechTools\MuMech_Tools.cs"> <Compile Include="..\ToadicusTools\MuMechTools\MuMech_Tools.cs">
<Link>ToadicusTools\MuMech_Tools.cs</Link> <Link>ToadicusTools\MuMech_Tools.cs</Link>
</Compile> </Compile>
<Compile Include="..\ToadicusTools\Extensions\PartExtensions.cs"> <Compile Include="..\ToadicusTools\Extensions\PartExtensions.cs">
<Link>ToadicusTools\PartExtensions.cs</Link> <Link>ToadicusTools\PartExtensions.cs</Link>
</Compile> </Compile>
<Compile Include="..\ToadicusTools\Debug\PooledDebugLogger.cs"> <Compile Include="..\ToadicusTools\Debug\PooledDebugLogger.cs">
<Link>ToadicusTools\PooledDebugLogger.cs</Link> <Link>ToadicusTools\PooledDebugLogger.cs</Link>
</Compile> </Compile>
<Compile Include="..\ToadicusTools\APIHelpers\PooledObject.cs"> <Compile Include="..\ToadicusTools\APIHelpers\PooledObject.cs">
<Link>ToadicusTools\PooledObject.cs</Link> <Link>ToadicusTools\PooledObject.cs</Link>
</Compile> </Compile>
<Compile Include="..\ToadicusTools\Text\PooledStringBuilder.cs"> <Compile Include="..\ToadicusTools\Text\PooledStringBuilder.cs">
<Link>ToadicusTools\PooledStringBuilder.cs</Link> <Link>ToadicusTools\PooledStringBuilder.cs</Link>
</Compile> </Compile>
<Compile Include="..\ToadicusTools\Text\SIFormatProvider.cs"> <Compile Include="..\ToadicusTools\Text\SIFormatProvider.cs">
<Link>ToadicusTools\SIFormatProvider.cs</Link> <Link>ToadicusTools\SIFormatProvider.cs</Link>
</Compile> </Compile>
<Compile Include="..\ToadicusTools\Text\TextTools.cs"> <Compile Include="..\ToadicusTools\Text\TextTools.cs">
<Link>ToadicusTools\TextTools.cs</Link> <Link>ToadicusTools\TextTools.cs</Link>
</Compile> </Compile>
<Compile Include="..\ToadicusTools\Enums.cs"> <Compile Include="..\ToadicusTools\Enums.cs">
<Link>ToadicusTools\Enums.cs</Link> <Link>ToadicusTools\Enums.cs</Link>
</Compile> </Compile>
</ItemGroup> </ItemGroup>
<ProjectExtensions> <ProjectExtensions>
<MonoDevelop> <MonoDevelop>
<Properties> <Properties>
<Policies> <Policies>
<StandardHeader Text="${ProjectName}&#xD;&#xA;&#xD;&#xA;${FileName}&#xD;&#xA;&#xD;&#xA;Copyright © ${Year}, ${AuthorName}&#xD;&#xA;All rights reserved.&#xD;&#xA;&#xD;&#xA;Redistribution and use in source and binary forms, with or without modification,&#xD;&#xA;are permitted provided that the following conditions are met:&#xD;&#xA;&#xD;&#xA;1. Redistributions of source code must retain the above copyright notice,&#xD;&#xA; this list of conditions and the following disclaimer.&#xD;&#xA;&#xD;&#xA;2. Redistributions in binary form must reproduce the above copyright notice,&#xD;&#xA; this list of conditions and the following disclaimer in the documentation and/or other&#xD;&#xA; materials provided with the distribution.&#xD;&#xA;&#xD;&#xA;THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES,&#xD;&#xA;INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE&#xD;&#xA;DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,&#xD;&#xA;SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR&#xD;&#xA;SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,&#xD;&#xA;WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE&#xD;&#xA;OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." IncludeInNewFiles="True" /> <StandardHeader Text="${ProjectName}&#xD;&#xA;&#xD;&#xA;${FileName}&#xD;&#xA;&#xD;&#xA;Copyright © ${Year}, ${AuthorName}&#xD;&#xA;All rights reserved.&#xD;&#xA;&#xD;&#xA;Redistribution and use in source and binary forms, with or without modification,&#xD;&#xA;are permitted provided that the following conditions are met:&#xD;&#xA;&#xD;&#xA;1. Redistributions of source code must retain the above copyright notice,&#xD;&#xA; this list of conditions and the following disclaimer.&#xD;&#xA;&#xD;&#xA;2. Redistributions in binary form must reproduce the above copyright notice,&#xD;&#xA; this list of conditions and the following disclaimer in the documentation and/or other&#xD;&#xA; materials provided with the distribution.&#xD;&#xA;&#xD;&#xA;THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES,&#xD;&#xA;INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE&#xD;&#xA;DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,&#xD;&#xA;SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR&#xD;&#xA;SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,&#xD;&#xA;WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE&#xD;&#xA;OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." IncludeInNewFiles="True" />
</Policies> </Policies>
</Properties> </Properties>
</MonoDevelop> </MonoDevelop>
</ProjectExtensions> </ProjectExtensions>
<ItemGroup> <ItemGroup>
<Reference Include="Assembly-CSharp"> <Reference Include="Assembly-CSharp">
<HintPath>..\_KSPAssemblies\Assembly-CSharp.dll</HintPath> <HintPath>..\_KSPAssemblies\Assembly-CSharp.dll</HintPath>
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="System"> <Reference Include="System">
<HintPath>..\_KSPAssemblies\System.dll</HintPath> <HintPath>..\_KSPAssemblies\System.dll</HintPath>
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="UnityEngine"> <Reference Include="UnityEngine">
<HintPath>..\_KSPAssemblies\UnityEngine.dll</HintPath> <HintPath>..\_KSPAssemblies\UnityEngine.dll</HintPath>
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
  <Reference Include="KSPUtil">
  <HintPath>..\_KSPAssemblies\KSPUtil.dll</HintPath>
  </Reference>
  <Reference Include="UnityEngine.UI">
  <HintPath>..\_KSPAssemblies\UnityEngine.UI.dll</HintPath>
  </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="GameData\QuantumStrutsContinued\Parts\QuantumStruts\quantumStrut\part.cfg" /> <None Include="GameData\QuantumStrutsContinued\Parts\QuantumStruts\quantumStrut\part.cfg" />
<None Include="GameData\QuantumStrutsContinued\Parts\QuantumStruts\strutGun\part.cfg" /> <None Include="GameData\QuantumStrutsContinued\Parts\QuantumStruts\strutGun\part.cfg" />
<None Include="GameData\QuantumStrutsContinued\LICENSE" /> <None Include="GameData\QuantumStrutsContinued\LICENSE" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup />
<Folder Include="ToadicusTools\" /> <PropertyGroup>
</ItemGroup> <PostBuildEvent>xcopy /Y $(TargetPath) $(ProjectDir)GameData\$(ProjectName)</PostBuildEvent>
  </PropertyGroup>
</Project> </Project>
file:a/Strut.cs -> file:b/Strut.cs
// QuantumStrutsContinued // QuantumStrutsContinued
// //
// Strut.cs // Strut.cs
// //
// Continued from QuantumStruts by BoJaN. Used by permission. // Continued from QuantumStruts by BoJaN. Used by permission.
// //
// ModuleManager patches © 2014 K3|Chris. Used by permission. // ModuleManager patches © 2014 K3|Chris. Used by permission.
// //
// Copyright © 2014, toadicus // Copyright © 2014, toadicus
// All rights reserved. // All rights reserved.
// //
// Redistribution and use in source and binary forms, with or without modification, // Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met: // are permitted provided that the following conditions are met:
// //
// 1. Redistributions of source code must retain the above copyright notice, // 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer. // this list of conditions and the following disclaimer.
// //
// 2. Redistributions in binary form must reproduce the above copyright notice, // 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation and/or other // this list of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution. // materials provided with the distribution.
// //
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   
using KSP; using KSP;
using System; using System;
using UnityEngine; using UnityEngine;
   
namespace QuantumStrut namespace QuantumStrut
{ {
class Strut class Strut
{ {
public bool isDestroyed = false; public bool isDestroyed = false;
Material _material = null; Material _material = null;
   
public Material Material public Material Material
{ {
set set
{ {
_material = value; _material = value;
if (Material != null) if (Material != null)
lr.material = Material; lr.material = Material;
} }
get get
{ {
return _material; return _material;
} }
} }
   
Color _startColor = Color.white; Color _startColor = Color.white;
   
public Color StartColor public Color StartColor
{ {
set set
{ {
_startColor = value; _startColor = value;
lr.SetColors(StartColor, EndColor); lr.SetColors(StartColor, EndColor);
} }
get get
{ {
return _startColor; return _startColor;
} }
} }
   
Color _endColor = Color.white; Color _endColor = Color.white;
   
public Color EndColor public Color EndColor
{ {
set set
{ {
_endColor = value; _endColor = value;
lr.SetColors(StartColor, EndColor); lr.SetColors(StartColor, EndColor);
} }
get get
{ {
return _endColor; return _endColor;
} }
} }
   
float _startSize = 0; float _startSize = 0;
   
public float StartSize public float StartSize
{ {
set set
{ {
_startSize = value; _startSize = value;
lr.SetWidth(StartSize, EndSize); lr.SetWidth(StartSize, EndSize);
} }
get get
{ {
return _startSize; return _startSize;
} }
} }
   
float _endSize = 0; float _endSize = 0;
   
public float EndSize public float EndSize
{ {
set set
{ {
_endSize = value; _endSize = value;
lr.SetWidth(StartSize, EndSize); lr.SetWidth(StartSize, EndSize);
} }
get get
{ {
return _endSize; return _endSize;
} }
} }
   
ConfigurableJoint joint; ConfigurableJoint joint;
Transform parentTransform = null; Transform parentTransform = null;
Part parent = null; Part parent = null;
Part target = null; Part target = null;
Vector3 targetOffset = Vector3.zero; Vector3 targetOffset = Vector3.zero;
GameObject LineObj = null; GameObject LineObj = null;
LineRenderer lr = null; LineRenderer lr = null;
   
public void print(object body, params object[] args) public void print(object body, params object[] args)
{ {
string final = body.ToString(); string final = body.ToString();
for (int I = 0; I < args.Length; I++) for (int I = 0; I < args.Length; I++)
{ {
final = final.Replace("{" + I + "}", args[I].ToString()); final = final.Replace("{" + I + "}", args[I].ToString());
} }
MonoBehaviour.print("[AutoStrut] " + final); MonoBehaviour.print("[AutoStrut] " + final);
} }
   
void DrawLine(Vector3 origin, Vector3 end) void DrawLine(Vector3 origin, Vector3 end)
{ {
if (Util.isValid(lr)) if (Util.isValid(lr))
{ {
lr.SetPosition(0, origin); lr.SetPosition(0, origin);
lr.SetPosition(1, end); lr.SetPosition(1, end);
} }
} }
   
public Strut(Part parent, Part target, Vector3 targetOffset, Transform parentTransform) public Strut(Part parent, Part target, Vector3 targetOffset, Transform parentTransform)
{ {
this.parent = parent; this.parent = parent;
this.target = target; this.target = target;
this.targetOffset = targetOffset; this.targetOffset = targetOffset;
this.parentTransform = parentTransform; this.parentTransform = parentTransform;
   
if (parent.vessel.parts.Contains(target)) if (parent.vessel.parts.Contains(target))
{ {
joint = parent.parent.gameObject.AddComponent<ConfigurableJoint>(); joint = parent.parent.gameObject.AddComponent<ConfigurableJoint>();
joint.connectedBody = target.rigidbody; joint.connectedBody = target.Rigidbody;
   
joint.anchor = new Vector3( joint.anchor = new Vector3(
0, 0,
0, 0,
Vector3.Distance( Vector3.Distance(
parentTransform.position, parentTransform.position,
target.transform.TransformPoint(targetOffset) target.transform.TransformPoint(targetOffset)
) / 2 ) / 2
); );
joint.axis = new Vector3(0, 0, 1); joint.axis = new Vector3(0, 0, 1);
joint.xMotion = ConfigurableJointMotion.Locked; joint.xMotion = ConfigurableJointMotion.Locked;
joint.yMotion = ConfigurableJointMotion.Locked; joint.yMotion = ConfigurableJointMotion.Locked;
joint.zMotion = ConfigurableJointMotion.Locked; joint.zMotion = ConfigurableJointMotion.Locked;
joint.angularXMotion = ConfigurableJointMotion.Locked; joint.angularXMotion = ConfigurableJointMotion.Locked;
joint.angularYMotion = ConfigurableJointMotion.Locked; joint.angularYMotion = ConfigurableJointMotion.Locked;
joint.angularZMotion = ConfigurableJointMotion.Locked; joint.angularZMotion = ConfigurableJointMotion.Locked;
   
LineObj = new GameObject(); LineObj = new GameObject();
LineObj.name = "quantumstrut"; LineObj.name = "quantumstrut";
   
lr = LineObj.AddComponent<LineRenderer>(); lr = LineObj.AddComponent<LineRenderer>();
lr.useWorldSpace = true; lr.useWorldSpace = false;
   
Material = QuantumStrut.LaserMaterial; Material = QuantumStrut.LaserMaterial;
StartColor = Color.white; StartColor = Color.white;
EndColor = Color.white; EndColor = Color.white;
StartSize = 0.03f; StartSize = 0.03f;
EndSize = 0.0075f; EndSize = 0.0075f;
   
lr.SetVertexCount(2); lr.SetVertexCount(2);
lr.SetPosition(0, Vector3.zero); lr.SetPosition(0, Vector3.zero);
lr.SetPosition(1, Vector3.zero); lr.SetPosition(1, Vector3.zero);
} }
else else
{ {
Destroy(); Destroy();
} }
} }
   
public void Update() public void Update()
{ {
if (Util.isValid(parent) && Util.isValid(target) && Util.isValid(parent.vessel) && parent.vessel.parts.Contains(target)) if (Util.isValid(parent) && Util.isValid(target) && Util.isValid(parent.vessel) && parent.vessel.parts.Contains(target))
{ {
Vector3 start = parentTransform.position; Vector3 start = parentTransform.position;
Vector3 end = target.transform.TransformPoint(targetOffset); Vector3 end = target.transform.TransformPoint(targetOffset);
DrawLine(start, end); DrawLine(start, end);
} }
else else
{ {
DrawLine(Vector3.zero, Vector3.zero); DrawLine(Vector3.zero, Vector3.zero);
Destroy(); Destroy();
} }
} }
   
public void Destroy() public void Destroy()
{ {
DrawLine(Vector3.zero, Vector3.zero); DrawLine(Vector3.zero, Vector3.zero);
if (Util.isValid(joint)) if (Util.isValid(joint))
GameObject.DestroyImmediate(joint); GameObject.DestroyImmediate(joint);
   
if (Util.isValid(lr)) if (Util.isValid(lr))
GameObject.DestroyImmediate(lr); GameObject.DestroyImmediate(lr);
   
if (Util.isValid(LineObj)) if (Util.isValid(LineObj))
GameObject.DestroyImmediate(LineObj); GameObject.DestroyImmediate(LineObj);
   
joint = null; joint = null;
LineObj = null; LineObj = null;
lr = null; lr = null;
   
parentTransform = null; parentTransform = null;
parent = null; parent = null;
target = null; target = null;
targetOffset = Vector3.zero; targetOffset = Vector3.zero;
isDestroyed = true; isDestroyed = true;
} }
} }
} }
file:a/Util.cs -> file:b/Util.cs
// QuantumStrutsContinued // QuantumStrutsContinued
// //
// Util.cs // Util.cs
// //
// Continued from QuantumStruts by BoJaN. Used by permission. // Continued from QuantumStruts by BoJaN. Used by permission.
// //
// ModuleManager patches © 2014 K3|Chris. Used by permission. // ModuleManager patches © 2014 K3|Chris. Used by permission.
// //
// Copyright © 2014, toadicus // Copyright © 2014, toadicus
// All rights reserved. // All rights reserved.
// //
// Redistribution and use in source and binary forms, with or without modification, // Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met: // are permitted provided that the following conditions are met:
// //
// 1. Redistributions of source code must retain the above copyright notice, // 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer. // this list of conditions and the following disclaimer.
// //
// 2. Redistributions in binary form must reproduce the above copyright notice, // 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation and/or other // this list of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution. // materials provided with the distribution.
// //
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   
using KSP.IO; using KSP.IO;
using System; using System;
using System.ComponentModel; using System.ComponentModel;
using UnityEngine; using UnityEngine;
   
namespace QuantumStrut namespace QuantumStrut
{ {
public static class Util public static class Util
{ {
static System.Random r = new System.Random(); static System.Random r = new System.Random();
   
public static float Random(float min, float max) public static float Random(float min, float max)
{ {
return (float)((r.NextDouble() * (max - min)) + min); return (float)((r.NextDouble() * (max - min)) + min);
} }
   
public static float Random() public static float Random()
{ {
return (float)r.NextDouble(); return (float)r.NextDouble();
} }
   
public static Part getTank(Part parent) public static Part getTank(Part parent)
{ {
if (parent.Resources.Count != 0) if (parent.Resources.Count != 0)
return parent; return parent;
   
if (isValid(parent.parent) && parent.fuelCrossFeed) if (isValid(parent.parent) && parent.fuelCrossFeed)
return getTank(parent.parent); return getTank(parent.parent);
   
return null; return null;
} }
   
public static Vessel Kerbal public static Vessel Kerbal
{ {
get get
{ {
if (isValid(FlightGlobals.fetch.activeVessel) && FlightGlobals.fetch.activeVessel.isEVA) if (isValid(FlightGlobals.fetch.activeVessel) && FlightGlobals.fetch.activeVessel.isEVA)
return FlightGlobals.fetch.activeVessel; return FlightGlobals.fetch.activeVessel;
return null; return null;
} }
} }
   
public static bool isValid(UnityEngine.Object obj) public static bool isValid(UnityEngine.Object obj)
{ {
return (obj && obj != null); return (obj && obj != null);
} }
   
public static void printObj(object obj) public static void printObj(object obj)
{ {
using (KSP.IO.TextWriter writer = TextWriter.CreateForType<string>("obj.cs")) using (KSP.IO.TextWriter writer = TextWriter.CreateForType<string>("obj.cs"))
{ {
string str = printProperties(obj, TypeDescriptor.GetProperties(obj), 0); string str = printProperties(obj, TypeDescriptor.GetProperties(obj), 0);
writer.Write(str); writer.Write(str);
MonoBehaviour.print(str); MonoBehaviour.print(str);
} }
} }
   
static string printProperties(object obj, PropertyDescriptorCollection collection, int I) static string printProperties(object obj, PropertyDescriptorCollection collection, int I)
{ {
if (I > 2) if (I > 2)
return ""; return "";
   
string prefix = ""; string prefix = "";
string str = ""; string str = "";
for (int T = 0; T < I; T++) for (int T = 0; T < I; T++)
{ {
prefix += " "; prefix += " ";
} }
   
PropertyDescriptor d; PropertyDescriptor d;
for (int i = 0; i < collection.Count; i++) for (int i = 0; i < collection.Count; i++)
{ {
d = collection[i]; d = collection[i];
   
str += "\n" + prefix + d.Name + " = " + d.GetValue(obj); str += "\n" + prefix + d.Name + " = " + d.GetValue(obj);
} }
return str; return str;
} }
   
public static Part partFromGameObject(GameObject ob) public static Part partFromGameObject(GameObject ob)
{ {
GameObject o = ob; GameObject o = ob;
   
while (o) while (o)
{ {
Part p = Part.FromGO(o); Part p = Part.FromGO(o);
if (p && p != null) if (p && p != null)
{ {
return p; return p;
} }
   
if (o.transform.parent) if (o.transform.parent)
o = o.transform.parent.gameObject; o = o.transform.parent.gameObject;
else else
return null; return null;
} }
return null; return null;
} }
   
public static Part partFromRaycast(RaycastHit hit) public static Part partFromRaycast(RaycastHit hit)
{ {
return partFromGameObject(hit.collider.gameObject); return partFromGameObject(hit.collider.gameObject);
} }
   
public static float GetEnergy(Vessel vessel) public static float GetEnergy(Vessel vessel)
{ {
double energy = 0; double energy = 0;
Part p; Part p;
for (int pIdx = 0; pIdx < vessel.parts.Count; pIdx++) for (int pIdx = 0; pIdx < vessel.parts.Count; pIdx++)
{ {
p = vessel.parts[pIdx]; p = vessel.parts[pIdx];
   
PartResource r; PartResource r;
for (int rIdx = 0; rIdx < p.Resources.Count; rIdx++) for (int rIdx = 0; rIdx < p.Resources.Count; rIdx++)
{ {
r = p.Resources[rIdx]; r = p.Resources[rIdx];
   
if (r.resourceName == "ElectricCharge") if (r.resourceName == "ElectricCharge")
energy += r.amount; energy += r.amount;
} }
} }
return (float)energy; return (float)energy;
} }
} }
} }