diff --git a/.gitattributes b/.gitattributes old mode 100644 new mode 100755 diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..6764825 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,8 @@ +# These are supported funding model platforms + +github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +patreon: linuxgurugamer +open_collective: # Replace with a single Open Collective username +ko_fi: # Replace with a single Ko-fi username +tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +custom: # Replace with a single custom sponsorship URL diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 index 2c5c832..8af9a47 --- a/.gitignore +++ b/.gitignore @@ -228,3 +228,8 @@ $RECYCLE.BIN/ *.msi *.msm *.msp +/.vs/config +/.vs/DestructionEffects/v15/sqlite3 +/.vs/DestructionEffects/v15/Server/sqlite3 +/BuildRelease +/.vs diff --git a/@ b/@ new file mode 100644 index 0000000..6600463 --- /dev/null +++ b/@ @@ -0,0 +1,27 @@ + +# Please enter the commit message for your changes. Lines starting +# with '#' will be ignored, and an empty message aborts the commit. +# +# On branch master +# Your branch is up to date with 'origin/master'. +# +# Changes to be committed: +# new file: BDAcheck.cs +# new file: FlamingJoints.cs +# +# Changes not staged for commit: +# deleted: ../DEGaplessParticleEmitter.cs +# deleted: ../DESettings.cs +# modified: ../DestructionEffects.csproj +# modified: ../DestructionEffects.sln +# deleted: ../FlamingJointScript.cs +# deleted: ../FlamingJoints.cs +# deleted: ../Properties/AssemblyInfo.cs +# +# Untracked files: +# DEGaplessParticleEmitter.cs +# DESettings.cs +# DestructionEffects.csproj +# FlamingJointScript.cs +# Properties/ +# diff --git a/BDAcheck.cs b/BDAcheck.cs new file mode 100644 index 0000000..74ff725 --- /dev/null +++ b/BDAcheck.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.NetworkInformation; +using CompoundParts; +using UnityEngine; + +namespace DestructionEffects +{ + [KSPAddon(KSPAddon.Startup.MainMenu, false)] + public class BDACheck : MonoBehaviour + { + public static bool bdaAvailable = false; + void Start() + { + bdaAvailable = AssemblyLoader.loadedAssemblies.Any(a => a.assembly.GetName().Name == "BDArmory"); + } + } +} \ No newline at end of file diff --git a/DEGaplessParticleEmitter.cs b/DEGaplessParticleEmitter.cs deleted file mode 100644 index 2479ef7..0000000 --- a/DEGaplessParticleEmitter.cs +++ /dev/null @@ -1,78 +0,0 @@ -using System; -using UnityEngine; - -namespace DestructionEffects -{ - public class DEGaplessParticleEmitter : MonoBehaviour - { - public KSPParticleEmitter pEmitter; - - public float maxDistance = 1.1f; - - public bool emit = false; - - public Part part = null; - - public Rigidbody rb; - - - - void Start() - { - pEmitter = gameObject.GetComponent(); - pEmitter.emit = false; - - - if(part!=null) - { - Debug.Log ("Part "+part.partName+"'s explosionPotential: "+ part.explosionPotential); - } - - maxDistance = pEmitter.minSize/3; - - - } - - void FixedUpdate() - { - if(emit) - { - Vector3 velocity = (part == null) ? rb.velocity : part.rigidbody.velocity; - Vector3 originalLocalPosition = gameObject.transform.localPosition; - Vector3 originalPosition = gameObject.transform.position; - Vector3 startPosition = gameObject.transform.position + (velocity * Time.fixedDeltaTime); - float originalGapDistance = Vector3.Distance(originalPosition, startPosition); - float intermediateSteps = originalGapDistance/maxDistance; - - pEmitter.EmitParticle(); - gameObject.transform.position = Vector3.MoveTowards(gameObject.transform.position, startPosition, maxDistance); - for(int i = 1; i < intermediateSteps; i++) - { - pEmitter.EmitParticle(); - gameObject.transform.position = Vector3.MoveTowards(gameObject.transform.position, startPosition, maxDistance); - } - gameObject.transform.localPosition = originalLocalPosition; - } - - } - - public void EmitParticles() - { - Vector3 velocity = (part == null) ? rb.velocity : part.rigidbody.velocity; - Vector3 originalLocalPosition = gameObject.transform.localPosition; - Vector3 originalPosition = gameObject.transform.position; - Vector3 startPosition = gameObject.transform.position + (velocity * Time.fixedDeltaTime); - float originalGapDistance = Vector3.Distance(originalPosition, startPosition); - float intermediateSteps = originalGapDistance/maxDistance; - - //gameObject.transform.position = startPosition; - for(int i = 0; i < intermediateSteps; i++) - { - pEmitter.EmitParticle(); - gameObject.transform.position = Vector3.MoveTowards(gameObject.transform.position, startPosition, maxDistance); - } - gameObject.transform.localPosition = originalLocalPosition; - } - } -} - diff --git a/DestructionEffects.csproj b/DestructionEffects.csproj old mode 100644 new mode 100755 index c240674..f190633 --- a/DestructionEffects.csproj +++ b/DestructionEffects.csproj @@ -1,5 +1,6 @@ - - + + + Debug x86 @@ -9,7 +10,9 @@ Library DestructionEffects DestructionEffects - v3.5 + v4.7.2 + + true @@ -21,6 +24,7 @@ 4 x86 false + false none @@ -30,19 +34,142 @@ 4 x86 false + false + + + true + bin\Debug\ + DEBUG; + full + AnyCPU + prompt + MinimumRecommendedRules.ruleset + false + + + bin\Release\ + AnyCPU + prompt + MinimumRecommendedRules.ruleset + true + false - ..\..\..\Games\KSP\KSP 0.90 - Mod Dev\KSP_Data\Managed\Assembly-CSharp.dll + ..\_LocalDev\KSPRefs\Assembly-CSharp.dll + False + + + ..\_LocalDev\KSPRefs\KSPAssets.dll + False + + + + + + + - ..\..\..\Games\KSP\KSP 0.90 - Mod Dev\KSP_Data\Managed\UnityEngine.dll + ..\_LocalDev\KSPRefs\UnityEngine.dll + False + + + ..\_LocalDev\KSPRefs\UnityEngine.CoreModule.dll + False + + + ..\_LocalDev\KSPRefs\UnityEngine.ParticleSystemModule.dll + + + ..\_LocalDev\KSPRefs\UnityEngine.PhysicsModule.dll + False - - - + + + + + + + + + False + .NET Framework 3.5 SP1 + true + + + + + + + + + + + + + + + + + + + + + + + + + @echo $(Targetname) +SET ModName=DestructionEffects +@echo ... +@echo set lpath vars from LocalDev storage... +set /p KSP_DIR=<"$(ProjectDir)LocalDev\ksp_dir.txt" +set /p PDB2MDB_EXE=<"$(ProjectDir)LocalDev\pdb2mdb_exe.txt" +set /p ZA_DIR=<"$(ProjectDir)LocalDev\7za_dir.txt" +set /p DIST_DIR=<"$(ProjectDir)LocalDev\dist_dir.txt" + +@echo distributing $(Targetname) files... +copy /Y "$(TargetPath)" "$(ProjectDir)Distribution\GameData\%25ModName%25\Plugins\" +copy /Y "$(TargetPath)" "C:\Users\dlane\Dropbox\Kerbal\ModDevelopment\Release" +copy /Y "$(TargetPath)" "$(ProjectDir)Distribution\GameData\DestructionEffects\Plugins\" + +if $(ConfigurationName) == Debug ( +@echo building $(Targetname).dll.mdb file... +cd "$(TargetDir)" +copy /Y "$(TargetDir)$(Targetname).pdb" "%25KSP_DIR%25\GameData\%25ModName%25\Plugins\" +) + +@echo deleting previous build ... +if exist "%25DIST_DIR%25\%25ModName%25*.zip" del "%25DIST_DIR%25\%25ModName%25*.zip" +@echo packaging new build... +call "%25ZA_DIR%25\7za.exe" a -tzip -r "%25DIST_DIR%25\%25ModName%25.@(VersionNumber)_%25DATE:~4,2%25%25DATE:~7,2%25%25DATE:~10,4%25.zip" "$(ProjectDir)Distribution\*.*" +copy /Y "$(TargetDir)$(Targetname).dll.mdb" "%25KSP_DIR%25\GameData\DestructionEffects\Plugins\" +) + +@echo packaging files... +if exist "%25DIST_DIR%25\DestructionEffects*.zip" del "%25DIST_DIR%25\DestructionEffects*.zip" +call "%25ZA_DIR%25\7za.exe" a -tzip -r "%25DIST_DIR%25\DestructionEffects.@(VersionNumber)_%25DATE:~4,2%25%25DATE:~7,2%25%25DATE:~10,4%25.zip" "$(ProjectDir)Distribution\*.*" + +@echo Deploy $(Targetname) Distribution files to test env: %25KSP_DIR%25\GameData... +@echo copying:"$(SolutionDir)Distribution\GameData" to "%25KSP_DIR%25\GameData" +xcopy /E /Y "$(SolutionDir)Distribution\GameData" "%25KSP_DIR%25\GameData" + +if $(ConfigurationName) == Debug ( +copy /Y "$(TargetDir)$(Targetname).pdb" "%25KSP_DIR%25\GameData\%25ModName%25\Plugins\" +copy /Y "$(TargetDir)$(Targetname).pdb" "%25KSP_DIR%25\GameData\DestructionEffects\Plugins\" +) + +@echo Build/deploy complete! + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + \ No newline at end of file diff --git a/DestructionEffects.sln b/DestructionEffects.sln new file mode 100755 index 0000000..9bebf4f --- /dev/null +++ b/DestructionEffects.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.27428.2005 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DestructionEffects", "DestructionEffects.csproj", "{7BBA3030-1674-4759-8DEA-2012D86512BC}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7BBA3030-1674-4759-8DEA-2012D86512BC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7BBA3030-1674-4759-8DEA-2012D86512BC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7BBA3030-1674-4759-8DEA-2012D86512BC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7BBA3030-1674-4759-8DEA-2012D86512BC}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A1256FAF-2BDB-4301-A668-46EE1D7A261F} + EndGlobalSection +EndGlobal diff --git a/DestructionEffects/BDAcheck.cs b/DestructionEffects/BDAcheck.cs new file mode 100644 index 0000000..74ff725 --- /dev/null +++ b/DestructionEffects/BDAcheck.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.NetworkInformation; +using CompoundParts; +using UnityEngine; + +namespace DestructionEffects +{ + [KSPAddon(KSPAddon.Startup.MainMenu, false)] + public class BDACheck : MonoBehaviour + { + public static bool bdaAvailable = false; + void Start() + { + bdaAvailable = AssemblyLoader.loadedAssemblies.Any(a => a.assembly.GetName().Name == "BDArmory"); + } + } +} \ No newline at end of file diff --git a/DestructionEffects/DEGaplessParticleEmitter.cs b/DestructionEffects/DEGaplessParticleEmitter.cs new file mode 100644 index 0000000..67850da --- /dev/null +++ b/DestructionEffects/DEGaplessParticleEmitter.cs @@ -0,0 +1,79 @@ +//1.2pre +using UnityEngine; + +namespace DestructionEffects +{ + public class DeGaplessParticleEmitter : MonoBehaviour + { + public bool Emit; + + public float MaxDistance = 1.1f; + + public Part Part; + + public KSPParticleEmitter PEmitter; + + public Rigidbody Rb; + + private void Start() + { + PEmitter = gameObject.GetComponent(); + PEmitter.emit = false; + + if (Part != null) + { + Debug.Log("Part " + Part.partName + "'s explosionPotential: " + Part.explosionPotential); + } + + MaxDistance = PEmitter.minSize / 3; + } + + private void FixedUpdate() + { + if (!Emit) return; + + var velocity = Part?.GetComponent().velocity ?? Rb.velocity; + var originalLocalPosition = gameObject.transform.localPosition; + var originalPosition = gameObject.transform.position; + var startPosition = gameObject.transform.position + velocity * Time.fixedDeltaTime; + var originalGapDistance = Vector3.Distance(originalPosition, startPosition); + var intermediateSteps = originalGapDistance / MaxDistance; + + PEmitter.EmitParticle(); + gameObject.transform.position = Vector3.MoveTowards( + gameObject.transform.position, + startPosition, + MaxDistance); + for (var i = 1; i < intermediateSteps; i++) + { + PEmitter.EmitParticle(); + gameObject.transform.position = Vector3.MoveTowards( + gameObject.transform.position, + startPosition, + MaxDistance); + } + gameObject.transform.localPosition = originalLocalPosition; + } + + public void EmitParticles() + { + var velocity = Part?.GetComponent().velocity ?? Rb.velocity; + var originalLocalPosition = gameObject.transform.localPosition; + var originalPosition = gameObject.transform.position; + var startPosition = gameObject.transform.position + velocity * Time.fixedDeltaTime; + var originalGapDistance = Vector3.Distance(originalPosition, startPosition); + var intermediateSteps = originalGapDistance / MaxDistance; + + //gameObject.transform.position = startPosition; + for (var i = 0; i < intermediateSteps; i++) + { + PEmitter.EmitParticle(); + gameObject.transform.position = Vector3.MoveTowards( + gameObject.transform.position, + startPosition, + MaxDistance); + } + gameObject.transform.localPosition = originalLocalPosition; + } + } +} \ No newline at end of file diff --git a/DestructionEffects/DESettings.cs b/DestructionEffects/DESettings.cs new file mode 100644 index 0000000..fcc2f7b --- /dev/null +++ b/DestructionEffects/DESettings.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using UnityEngine; + +namespace DestructionEffects +{ + [KSPAddon(KSPAddon.Startup.EveryScene, false)] + public class DESettings : MonoBehaviour + { + public static string settingsConfigURL = "GameData/DestructionEffects/settings.cfg"; + //=======configurable settings + + public static bool LegacyEffect = false; + public static string[] PartIgnoreList; + + void Start() + { + LoadConfig(); + } + + public static void LoadConfig() + { + try + { + Debug.Log("== DestructionEffects: Loading settings.cfg =="); + + ConfigNode fileNode = ConfigNode.Load(settingsConfigURL); + if (!fileNode.HasNode("DESettings")) return; + + ConfigNode settings = fileNode.GetNode("DESettings"); + + LegacyEffect = bool.Parse(settings.GetValue("LegacyEffect")); + PartIgnoreList = settings.GetValues("PartIgnoreList"); + } + catch (NullReferenceException) + { + Debug.Log("== DestructionEffects : Failed to load settings config=="); + } + } + } +} diff --git a/DestructionEffects/DestructionEffects.csproj b/DestructionEffects/DestructionEffects.csproj new file mode 100644 index 0000000..91c39fe --- /dev/null +++ b/DestructionEffects/DestructionEffects.csproj @@ -0,0 +1,64 @@ + + + + + Debug + AnyCPU + {95AE4D2E-FE17-4B78-A17F-A63F6249B14D} + Library + Properties + DestructionEffects + DestructionEffects + v3.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + R:\KSP_1.7.2_dev\KSP_x64_Data\Managed\Assembly-CSharp.dll + + + R:\KSP_1.7.2_dev\KSP_x64_Data\Managed\Assembly-CSharp-firstpass.dll + + + R:\KSP_1.7.2_dev\KSP_x64_Data\Managed\KSPAssets.dll + + + + + + + + + R:\KSP_1.7.2_dev\KSP_x64_Data\Managed\UnityEngine.dll + + + R:\KSP_1.7.2_dev\KSP_x64_Data\Managed\UnityEngine.UI.dll + + + + + + + + + + + + \ No newline at end of file diff --git a/DestructionEffects/FlamingJointScript.cs b/DestructionEffects/FlamingJointScript.cs new file mode 100644 index 0000000..f405a14 --- /dev/null +++ b/DestructionEffects/FlamingJointScript.cs @@ -0,0 +1,84 @@ +//1.2 +using UnityEngine; + +namespace DestructionEffects +{ + public class FlamingJointScript : MonoBehaviour + { + private readonly float _maxCombineDistance = 0.6f; + + private readonly float _shrinkRateFlame = 0.25f; // from 0.35f //from 0.75f //from 1.75f + + private readonly float _shrinkRateSmoke = 0.07f; //from 1f//from 2f// + private GameObject _destroyer; + + private float _destroyTimerStart; + + private float _highestEnergy; + + public void Start() + { + foreach (var otherFlame in FlamingJoints.FlameObjects) + { + if ( + !((gameObject.transform.position - otherFlame.transform.position).sqrMagnitude + < _maxCombineDistance * _maxCombineDistance)) continue; + Debug.Log("== Flame combined =="); + Destroy(gameObject); + return; + } + + foreach (var pe in gameObject.GetComponentsInChildren()) + { + var color = pe.material.color; + color.a = color.a / 2; + pe.material.SetColor("_TintColor", color); + pe.force = -FlightGlobals.getGeeForceAtPosition(transform.position) / 3; + if (!(pe.maxEnergy > _highestEnergy)) continue; + _destroyer = pe.gameObject; + _highestEnergy = pe.maxEnergy; + EffectBehaviour.AddParticleEmitter(pe); + } + FlamingJoints.FlameObjects.Add(gameObject); + } + + public void FixedUpdate()//pe is particle emitter + { + foreach (var pe in gameObject.GetComponentsInChildren()) + { + var shrinkRate = pe.gameObject.name.Contains("smoke") ? _shrinkRateSmoke : _shrinkRateFlame; + pe.maxSize = Mathf.MoveTowards(pe.maxSize, 0, shrinkRate * Time.fixedDeltaTime); + pe.minSize = Mathf.MoveTowards(pe.minSize, 0, shrinkRate * Time.fixedDeltaTime); + if (pe.maxSize < 0.1f && pe.gameObject == _destroyer && _destroyTimerStart == 0) + { + _destroyTimerStart = Time.time; + } + + var lightComponent = pe.gameObject.GetComponent(); + + if (lightComponent != null) + { + lightComponent.intensity = Random.Range(0f, pe.maxSize / 6); + } + } + + if (_destroyTimerStart != 0 && Time.time - _destroyTimerStart > _highestEnergy) + { + Destroy(gameObject); + } + } + + private void OnDestroy() + { + foreach (var pe in gameObject.GetComponentsInChildren()) + { + EffectBehaviour.RemoveParticleEmitter(pe); + } + + if (FlamingJoints.FlameObjects.Contains(gameObject)) + { + FlamingJoints.FlameObjects.Remove(gameObject); + } + } + } +} \ No newline at end of file diff --git a/DestructionEffects/FlamingJoints.cs b/DestructionEffects/FlamingJoints.cs new file mode 100644 index 0000000..636b498 --- /dev/null +++ b/DestructionEffects/FlamingJoints.cs @@ -0,0 +1,266 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.NetworkInformation; +using CompoundParts; +using UnityEngine; + +namespace DestructionEffects +{ + [KSPAddon(KSPAddon.Startup.Flight, false)] + public class FlamingJoints : MonoBehaviour + { + private const string NewFlameModelPath = "DestructionEffects/Models/FlameEffect2/model"; + private const string LegacyFlameModelPath = "DestructionEffects/Models/FlameEffect_Legacy/model"; + //private float timeNoFlames; + //private Vessel LastVesselLoaded = null; + public static List FlameObjects = new List(); + public List vesselsAllowed = new List(); + // added dictionary to remember the parents of parts that are destroyed + public Dictionary deadPartsParents = new Dictionary(); + private static readonly string[] PartTypesTriggeringUnwantedJointBreakEvents = new string[] + { + "decoupler", + "separator", + "docking", + "grappling", + "landingleg", + "clamp", + "gear", + "wheel", + "mast", + "heatshield", + "turret", + "missilelauncher", + "moudleturret", + "missileturret", + "missilefire", + "kas.", + "kis.", + "cport,", + "torpedo", + "slw", + "mortar", + "hedg" + }; + + private static readonly string[] _PartTypesTriggeringUnwantedJointBreakEvents = new string[DESettings.PartIgnoreList.Length + PartTypesTriggeringUnwantedJointBreakEvents.Length]; + + //1553 void OnPartJointBreak(PartJoint j, float breakForce) + public void Start() + { + GameEvents.onPhysicsEaseStop.Add(OnPhysicsEaseStop); + GameEvents.onPartJointBreak.Add(OnPartJointBreak); + GameEvents.onPartWillDie.Add(OnPartWillDie); + GameEvents.onLevelWasLoadedGUIReady.Add(OnLevelLoaded); + PartTypesTriggeringUnwantedJointBreakEvents.CopyTo(_PartTypesTriggeringUnwantedJointBreakEvents,0); + DESettings.PartIgnoreList.CopyTo(_PartTypesTriggeringUnwantedJointBreakEvents, PartTypesTriggeringUnwantedJointBreakEvents.Length); + } + + // this function was added as during this event the joints are still intact and we can remember the parent of the part that is going to die + public void OnPartWillDie(Part data) + { + if (!(data.localRoot == data)) + { + if (!deadPartsParents.ContainsKey(data.flightID)) + { + deadPartsParents.Add(data.flightID, data.parent.flightID); + } + + } + else + { + if (!deadPartsParents.ContainsKey(data.flightID)) + { + deadPartsParents.Add(data.flightID, data.flightID); + } + } + } + + // this function was added to clear the list of dead parts when a scene is loaded + public void OnLevelLoaded(GameScenes data) + { + deadPartsParents.Clear(); + } + + public void OnPhysicsEaseStop(Vessel data) + { + vesselsAllowed.Add(data); + } + + public void OnPartJointBreak(PartJoint partJoint, float breakForce) + { + if (HighLogic.LoadedScene == GameScenes.EDITOR) + { + return; + } + if (partJoint.Target == null) + { + return; + } + if (partJoint.Target.PhysicsSignificance == 1) + { + return; + } + + if (vesselsAllowed.Count == 0) + { + return; + } + if (!vesselsAllowed.Contains(partJoint.Target.vessel)) + { + return; + } + if (!ShouldFlamesBeAttached(partJoint)) + { + return; + } + + if (breakForce == 0) + { + // probably the BDa check is not required as I think the fix should work also in other situations + if (!BDACheck.bdaAvailable) + return; + + // this checks if the joint connects a parent and a child (other cases are autostruts that we do not want) + if (!(deadPartsParents.Contains(new KeyValuePair(partJoint.Host.flightID, partJoint.Target.flightID)) || deadPartsParents.ContainsKey(partJoint.Target.flightID))) + { + return; + } + } + + // added this check because if a part dies that has a still intact child there will be 2 partjoint breaks one where the target that is destroyed and one where the host is destroyed + // also expanded attach flames with this new parameter (basically we avoid attaching flames to a destroyed object that could lead to exceptions + bool attachToHost = false; + + if (deadPartsParents.ContainsKey(partJoint.Target.flightID)) + { + attachToHost = true; + } + + AttachFlames(partJoint, attachToHost); + } + + private static void AttachFlames(PartJoint partJoint, bool attachToHost) + { + var modelUrl = DESettings.LegacyEffect ? LegacyFlameModelPath : NewFlameModelPath; + + // adjusted the function with this new varaible that is either the hos or the target part depending on parameters (done to avoid attaching flames to a destroyed part) + Part flamingpart = partJoint.Target; + + if (attachToHost) + { + flamingpart = partJoint.Host; + } + + var flameObject = + (GameObject) + Instantiate( + GameDatabase.Instance.GetModel(modelUrl), + partJoint.transform.position, + Quaternion.identity); + + flameObject.SetActive(true); + flameObject.transform.parent = flamingpart.transform; + flameObject.AddComponent(); + + foreach (var pe in flameObject.GetComponentsInChildren()) + { + if (!pe.useWorldSpace) continue; + + var gpe = pe.gameObject.AddComponent(); + gpe.Part = flamingpart; + gpe.Emit = true; + } + } + + private static bool ShouldFlamesBeAttached(PartJoint partJoint) + { + if (partJoint == null) return false; + if (partJoint.Host == null) return false; + if (!partJoint.Host) return false; + if (partJoint.Host.Modules == null)return false; + + if (partJoint.Target == null) return false; + if (partJoint.Target.Modules == null) return false; + if (!partJoint.Target) return false; + + if (partJoint.Child == null) return false; + if (partJoint.Child.Modules == null) return false; + if (!partJoint.Child) return false; + + + if (partJoint.joints.All(x => x == null)) return false; + + + if (partJoint.Parent != null && partJoint.Parent.vessel != null) + { + if (partJoint.Parent.vessel.atmDensity <= 0.1) + { + return false; + } + } + + var part = partJoint.Target;//SM edit for DE on ships and ship parts, adding bow, hull, stern, superstructure + + if (partJoint.Target.FindModulesImplementing().Count > 0) + { + return false; + } + + if (partJoint.Target.FindModulesImplementing().Count > 0 || + partJoint.Host.FindModulesImplementing().Count > 0 || + partJoint.Child.FindModulesImplementing().Count > 0 || + partJoint.Parent?.FindModulesImplementing().Count > 0) + { + return false; + } + + if (partJoint.Target.Modules.Contains("ModuleTurret")) + { + return false; + } +; + if (IsPartHostTypeAJointBreakerTrigger(partJoint.Host.name.ToLower())) + { + return false; + } + + if (part.Resources + .Any(resource => resource.resourceName.Contains("Fuel") || + resource.resourceName.Contains("Ox") || + resource.resourceName.Contains("Elec") || + resource.resourceName.Contains("Amm") || + resource.resourceName.Contains("Cann"))) + { + return true; + } + + //added to lower case as in some parts the description is not uppercase in addition added some more parts that are like fuseslage (procedural structural, engine, cone, tail, cockpit) + if (part.partInfo.title.ToLower().Contains("wing") || + part.partInfo.title.ToLower().Contains("fuselage") || + part.partInfo.title.ToLower().Contains("bow") || + part.partInfo.title.ToLower().Contains("stern") || + part.partInfo.title.ToLower().Contains("hull") || + part.partInfo.title.ToLower().Contains("superstructure") || + part.partInfo.title.ToLower().Contains("structural") || + part.partInfo.title.ToLower().Contains("engine") || + part.partInfo.title.ToLower().Contains("cone") || + part.partInfo.title.ToLower().Contains("tail") || + part.partInfo.title.ToLower().Contains("cockpit") || + part.FindModuleImplementing() != null || + part.FindModuleImplementing() != null)/*|| part.partInfo.title.Contains("Turret") */ + { + return true; + } + + + return false; + } + + private static bool IsPartHostTypeAJointBreakerTrigger(string hostPartName) + { + return _PartTypesTriggeringUnwantedJointBreakEvents.Any(hostPartName.Contains); + } + } +} diff --git a/DestructionEffects/Properties/AssemblyInfo.cs b/DestructionEffects/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..95db3d4 --- /dev/null +++ b/DestructionEffects/Properties/AssemblyInfo.cs @@ -0,0 +1,33 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("DestructionEffects")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("Paolo Encarnacion")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 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 +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("8714d31a-d1ef-47f2-aaea-f7bce82f9f9e")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +[assembly: AssemblyVersion("1.12")] +[assembly: AssemblyFileVersion("1.12.0.0")] diff --git a/Distribution/GameData/DestructionEffects/ChangeLog.txt b/Distribution/GameData/DestructionEffects/ChangeLog.txt new file mode 100644 index 0000000..139136e --- /dev/null +++ b/Distribution/GameData/DestructionEffects/ChangeLog.txt @@ -0,0 +1,50 @@ +v1.12 +- Compiled for KSP 1.10.1 + +v1.11 +- Compiled for KSP 1.8 +- Fixes for autostrut thanks to Alioth81 + +v1.10 +- Compiled for KSP 1.7.3 +- Fixes for non-breaking joints thanks to LGG + +v1.9 +- Compiled for KSP 1.5.1 + +v1.8 +- Compiled for KSP 1.4.2 + +v1.7 +- Fixes break joints events during physics ease + +v1.6 +- Fixes Autostrut issue. Issue #12 and #16 + +v1.5 +- Compiled for KSP 1.3. +- Fixed unwanted fx effects. Issue #6 + +v1.4 +- Compiled for KSP 1.2.9. +- Final fix for particle system +- Fixing some exceptions. + +v1.3 +- Compiled for KSP 1.2.2. +- Fixing some exceptions. + +v1.2 +- Compiled for KSP 1.2.1 +- Add settings file to enable legacy effects (default value is disabled) + +v1.1.0 +- Avoid heat-shield and mast part to trigger effects. +- Add parts effects for Bow, Stern, Hull and Superstructures. +- Add part effects for resources : electric, ammo and cannon. +- No destruction effects if atmosphere density is below 1%. +- Duration time for effects increased (2x). + +v1.0-beta +- Fix for destruction effects wrong triggered when a part is decoupled. +- Other code improvements. \ No newline at end of file diff --git a/Distribution/GameData/DestructionEffects/DestructionEffects.version b/Distribution/GameData/DestructionEffects/DestructionEffects.version new file mode 100644 index 0000000..15b8357 --- /dev/null +++ b/Distribution/GameData/DestructionEffects/DestructionEffects.version @@ -0,0 +1,31 @@ +{ + "NAME": "DestructionEffects", + "URL": "https://raw.githubusercontent.com/jrodrigv/DestructionEffects/master/Distribution/GameData/DestructionEffects/DestructionEffects.version", + "DOWNLOAD": "https://github.com/jrodrigv/DestructionEffects/releases/tag/v1.12.0", + "GITHUB": { + "USERNAME": "jrodrigv", + "REPOSITORY": "DestructionEffects", + "ALLOW_PRE_RELEASE": false + }, + "VERSION": { + "MAJOR": 1, + "MINOR": 12, + "PATCH": 0, + "BUILD": 0 + }, + "KSP_VERSION": { + "MAJOR": 1, + "MINOR": 10, + "PATCH": 1 + }, + "KSP_VERSION_MIN": { + "MAJOR": 1, + "MINOR": 10, + "PATCH": 1 + }, + "KSP_VERSION_MAX": { + "MAJOR": 1, + "MINOR": 10, + "PATCH": 99 + } +} \ No newline at end of file diff --git a/Distribution/GameData/DestructionEffects/License.txt b/Distribution/GameData/DestructionEffects/License.txt new file mode 100755 index 0000000..4e92f51 --- /dev/null +++ b/Distribution/GameData/DestructionEffects/License.txt @@ -0,0 +1,8 @@ +This mod is released under the Creative Commons 0 license. + +"The person who associated a work with this deed has dedicated the work to the public domain by waiving all of his or her rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. + +You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission. " + +CC0 1.0 Universal +https://creativecommons.org/publicdomain/zero/1.0/ \ No newline at end of file diff --git a/Distribution/GameData/DestructionEffects/Models/FlameEffect2/Torchanimation_135.png b/Distribution/GameData/DestructionEffects/Models/FlameEffect2/Torchanimation_135.png new file mode 100755 index 0000000..441f876 Binary files /dev/null and b/Distribution/GameData/DestructionEffects/Models/FlameEffect2/Torchanimation_135.png differ diff --git a/Distribution/GameData/DestructionEffects/Models/FlameEffect2/flameA.png b/Distribution/GameData/DestructionEffects/Models/FlameEffect2/flameA.png new file mode 100755 index 0000000..8337f5e Binary files /dev/null and b/Distribution/GameData/DestructionEffects/Models/FlameEffect2/flameA.png differ diff --git a/Distribution/GameData/DestructionEffects/Models/FlameEffect2/flameD.png b/Distribution/GameData/DestructionEffects/Models/FlameEffect2/flameD.png new file mode 100755 index 0000000..1e6cb21 Binary files /dev/null and b/Distribution/GameData/DestructionEffects/Models/FlameEffect2/flameD.png differ diff --git a/Distribution/GameData/DestructionEffects/Models/FlameEffect2/model.mu b/Distribution/GameData/DestructionEffects/Models/FlameEffect2/model.mu new file mode 100755 index 0000000..3b3e751 Binary files /dev/null and b/Distribution/GameData/DestructionEffects/Models/FlameEffect2/model.mu differ diff --git a/Distribution/GameData/DestructionEffects/Models/FlameEffect2/muzzleSmoke.png b/Distribution/GameData/DestructionEffects/Models/FlameEffect2/muzzleSmoke.png new file mode 100755 index 0000000..25b51fa Binary files /dev/null and b/Distribution/GameData/DestructionEffects/Models/FlameEffect2/muzzleSmoke.png differ diff --git a/Distribution/GameData/DestructionEffects/Models/FlameEffect_Legacy/ExpTex2.png b/Distribution/GameData/DestructionEffects/Models/FlameEffect_Legacy/ExpTex2.png new file mode 100755 index 0000000..4e99ffe Binary files /dev/null and b/Distribution/GameData/DestructionEffects/Models/FlameEffect_Legacy/ExpTex2.png differ diff --git a/Distribution/GameData/DestructionEffects/Models/FlameEffect_Legacy/model.mu b/Distribution/GameData/DestructionEffects/Models/FlameEffect_Legacy/model.mu new file mode 100755 index 0000000..5df3df2 Binary files /dev/null and b/Distribution/GameData/DestructionEffects/Models/FlameEffect_Legacy/model.mu differ diff --git a/Distribution/GameData/DestructionEffects/Models/FlameEffect_Legacy/smoke.png b/Distribution/GameData/DestructionEffects/Models/FlameEffect_Legacy/smoke.png new file mode 100755 index 0000000..affebd7 Binary files /dev/null and b/Distribution/GameData/DestructionEffects/Models/FlameEffect_Legacy/smoke.png differ diff --git a/Distribution/GameData/DestructionEffects/Plugins/DestructionEffects.dll b/Distribution/GameData/DestructionEffects/Plugins/DestructionEffects.dll new file mode 100644 index 0000000..fbf9b8d Binary files /dev/null and b/Distribution/GameData/DestructionEffects/Plugins/DestructionEffects.dll differ diff --git a/Distribution/GameData/DestructionEffects/settings.cfg b/Distribution/GameData/DestructionEffects/settings.cfg new file mode 100755 index 0000000..9981213 --- /dev/null +++ b/Distribution/GameData/DestructionEffects/settings.cfg @@ -0,0 +1,5 @@ +DESettings +{ + LegacyEffect = True + PartIgnoreList = tube,mortar,hedg +} diff --git a/FlamingJointScript.cs b/FlamingJointScript.cs deleted file mode 100644 index 145f360..0000000 --- a/FlamingJointScript.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System; -using UnityEngine; - -namespace DestructionEffects -{ - public class FlamingJointScript : MonoBehaviour - { - float maxCombineDistance = 0.6f; - - float shrinkRateSmoke = 1f; - float shrinkRateFlame = 0.35f; - - float highestEnergy = 0; - float destroyTimerStart = 0; - GameObject destroyer; - - public void Start() - { - foreach(GameObject otherFlame in FlamingJoints.flameObjects) - { - if((gameObject.transform.position-otherFlame.transform.position).sqrMagnitude < (maxCombineDistance * maxCombineDistance)) - { - Debug.Log ("== Flame combined =="); - Destroy(gameObject); - return; - } - } - - foreach(var pe in gameObject.GetComponentsInChildren()) - { - Color color = pe.material.color; - color.a = color.a/2; - pe.material.SetColor("_TintColor", color); - pe.force = -FlightGlobals.getGeeForceAtPosition(transform.position)/3; - if(pe.maxEnergy > highestEnergy) - { - destroyer = pe.gameObject; - highestEnergy = pe.maxEnergy; - } - } - FlamingJoints.flameObjects.Add(gameObject); - - } - - public void FixedUpdate() - { - foreach(var pe in gameObject.GetComponentsInChildren()) - { - float shrinkRate = pe.gameObject.name.Contains("smoke") ? shrinkRateSmoke : shrinkRateFlame; - pe.maxSize = Mathf.MoveTowards(pe.maxSize, 0, shrinkRate * Time.fixedDeltaTime); - pe.minSize = Mathf.MoveTowards(pe.minSize, 0, shrinkRate * Time.fixedDeltaTime); - if(pe.maxSize < 0.1f && pe.gameObject == destroyer && destroyTimerStart == 0) - { - destroyTimerStart = Time.time; - } - - if(pe.gameObject.GetComponent()) - { - pe.gameObject.GetComponent().intensity = UnityEngine.Random.Range(0f, pe.maxSize/6); - } - } - - - - if(destroyTimerStart != 0 && Time.time-destroyTimerStart > highestEnergy) - { - GameObject.Destroy(gameObject); - } - } - - void OnDestroy() - { - if(FlamingJoints.flameObjects.Contains(gameObject)) - { - FlamingJoints.flameObjects.Remove(gameObject); - } - } - } -} - diff --git a/FlamingJoints.cs b/FlamingJoints.cs deleted file mode 100644 index bb9e528..0000000 --- a/FlamingJoints.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System; -using UnityEngine; -using System.Collections.Generic; - -namespace DestructionEffects -{ - [KSPAddon(KSPAddon.Startup.Flight, false)] - public class FlamingJoints : MonoBehaviour - { - - public static List flameObjects = new List(); - - public void Start() - { - GameEvents.onPartJointBreak.Add(onPartJointBreak); - - } - - public void onPartJointBreak(PartJoint partJoint) - { - - if(partJoint.Target!=null && partJoint.Target.PhysicsSignificance != 1) - { - Part part = partJoint.Target; - bool attachFlames = false; - - if(part.partInfo.title.Contains("Wing") - || part.partInfo.title.Contains("Fuselage") - || part.FindModuleImplementing() - || part.FindModuleImplementing() - ) - { - attachFlames = true; - } - else - { - foreach(PartResource resource in part.Resources) - { - if(resource.resourceName.Contains("Fuel") || resource.resourceName.Contains("Ox")) - { - attachFlames = true; - } - } - } - if(attachFlames) - { - GameObject flameObject2 = (GameObject) GameObject.Instantiate(GameDatabase.Instance.GetModel("DestructionEffects/Models/FlameEffect/model"), partJoint.transform.position, Quaternion.identity); - flameObject2.SetActive(true); - flameObject2.transform.parent = partJoint.Target.transform; - flameObject2.AddComponent(); - foreach(var pe in flameObject2.GetComponentsInChildren()) - { - if(pe.useWorldSpace) - { - DEGaplessParticleEmitter gpe = pe.gameObject.AddComponent(); - gpe.part = partJoint.Target; - gpe.emit = true; - - } - } - } - } - - - } - - - } -} - diff --git a/GameData/DestructionEffects/Plugins/DestructionEffects.dll b/GameData/DestructionEffects/Plugins/DestructionEffects.dll new file mode 100755 index 0000000..822772e Binary files /dev/null and b/GameData/DestructionEffects/Plugins/DestructionEffects.dll differ diff --git a/LocalDev/7za_dir.txt b/LocalDev/7za_dir.txt new file mode 100644 index 0000000..20f215f --- /dev/null +++ b/LocalDev/7za_dir.txt @@ -0,0 +1 @@ +D:\PROGRAMS\7za\x64 \ No newline at end of file diff --git a/LocalDev/dist_dir.txt b/LocalDev/dist_dir.txt new file mode 100644 index 0000000..3fddb8b --- /dev/null +++ b/LocalDev/dist_dir.txt @@ -0,0 +1 @@ +E:\PROGRAMACION\KSP_Development \ No newline at end of file diff --git a/LocalDev/ksp_dir.txt b/LocalDev/ksp_dir.txt new file mode 100644 index 0000000..7c0ac5b --- /dev/null +++ b/LocalDev/ksp_dir.txt @@ -0,0 +1 @@ +D:\GAMES\KERBAL\Kerbal Space Program_110_DEV \ No newline at end of file diff --git a/LocalDev/ksp_dir2.txt b/LocalDev/ksp_dir2.txt new file mode 100644 index 0000000..2a99837 --- /dev/null +++ b/LocalDev/ksp_dir2.txt @@ -0,0 +1 @@ +G:\GAMES\KERBAL\Kerbal Space Program_191_DEVM2 \ No newline at end of file diff --git a/LocalDev/mono_exe.txt b/LocalDev/mono_exe.txt new file mode 100644 index 0000000..6dc18e1 --- /dev/null +++ b/LocalDev/mono_exe.txt @@ -0,0 +1 @@ +D:\PROGRAMS\Unity\Editor\Data\MonoBleedingEdge\bin \ No newline at end of file diff --git a/LocalDev/pdb2mdb_exe.txt b/LocalDev/pdb2mdb_exe.txt new file mode 100644 index 0000000..734d54f --- /dev/null +++ b/LocalDev/pdb2mdb_exe.txt @@ -0,0 +1 @@ +G:\pdb2mdb\pdb2mdb.exe \ No newline at end of file diff --git a/README.md b/README.md new file mode 100755 index 0000000..f0b9f20 --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# DestructionEffects +Adds flames and smoke to joint-breaks of certain parts in ksp. + +Joint breaks and flames are associated with the following parts: + +decoupler, +seperator, +grappling, +landingleg, +clamp, +gear , +wheel, +fuselage, +wing, + + ship parts hull, stern, superstructure and bow + +and any part containing the following resources; + +Fuel, +Oxidizer, +Ammo, +CannonShells, +Electric charge, diff --git a/packages.config b/packages.config new file mode 100755 index 0000000..2ca092b --- /dev/null +++ b/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file