Jump to content

[KSP 1.10.1] Destruction Effects v1.12.0 (09/23/20)


jrodriguez

Recommended Posts

1 hour ago, gap said:

I have the same question.

@jrodriguez do you have an answer, please?

 

On 2/16/2019 at 5:28 PM, skygunner58203 said:

Is this working in 1.6.1?  Just wondering as playing with BDArmory is not nearly as much fun with smoke and boom

 

Yes, it works :) You should always try yourself before asking and then if it fails give me a heads up :)

I will do a new release for KSP 1.7 as soon as it is released.

Link to comment
Share on other sites

26 minutes ago, jrodriguez said:

 

Yes, it works :) You should always try yourself before asking and then if it fails give me a heads up :)

Okay, thank you for your quick reply and roger that :)

26 minutes ago, jrodriguez said:

 

Yes, it works :) You should always try yourself before asking and then if it fails give me a heads up :)

I will do a new release for KSP 1.7 as soon as it is released.

Cool, I just can't wait for the updates!

Link to comment
Share on other sites

  • 2 months later...

So, nothing too bad here, and I can live with it, but somehow when using this on my 1.6.1 install I use for my current YouTube series, I get the destruction effects showing up on launch. Presumably from detaching the launch clamps, but I can't really tell. Nothing actually breaks on any of the rockets though, so I'm a bit confused how those effects get triggered. Anybody else got that issue? Otherwise the mod works as intended with 1.6.1

Link to comment
Share on other sites

On 6/22/2019 at 8:07 AM, WWEdeadman said:

So, nothing too bad here, and I can live with it, but somehow when using this on my 1.6.1 install I use for my current YouTube series, I get the destruction effects showing up on launch. Presumably from detaching the launch clamps, but I can't really tell. Nothing actually breaks on any of the rockets though, so I'm a bit confused how those effects get triggered. Anybody else got that issue? Otherwise the mod works as intended with 1.6.1

I have the same issue in 1.6.1 or 1.7.1

It seems to be related to launch clamps as well as autostrutted parts. I've yet to find a fix for it

Link to comment
Share on other sites

  • 1 month later...

@jrodriguez

I have made several local changes to fix various null-refs.   I submitted a PR back in Jan 11, since then I've made some more fixes.

An issue with the PR is that it includes three files you may not want updated: 

  • Funding.yml, which I added to all my repos
  • DestructionEffects.sln
  • DestructionEffects.csproj

If necessary I can redo the repo without those files being changed.

 

Edited by linuxgurugamer
Link to comment
Share on other sites

On 8/26/2019 at 2:58 PM, linuxgurugamer said:

@jrodriguez

I have made several local changes to fix various null-refs.   I submitted a PR back in Jan 11, since then I've made some more fixes.

An issue with the PR is that it includes three files you may not want updated: 

  • Funding.yml, which I added to all my repos
  • DestructionEffects.sln
  • DestructionEffects.csproj

If necessary I can redo the repo without those files being changed.

 

Thanks @linuxgurugamer 

I have released a new version for KSP 1.7.3

https://github.com/jrodrigv/DestructionEffects/releases/tag/v1.10.0

Link to comment
Share on other sites

  • 3 weeks later...

@jrodriguez and @linuxgurugamer

First thanks for your update! For the real BDAc experience this mod is really essential for me and I had to delete it because it did not work properly.

When I tried the new version with BDAc I still got unwanted effects with autostruts however. Therefore I tried to modify the code.

I am no programmer and do not know how to do it properly in code but also with github checkin etc. and I am sure my programming changes look crude to you but it works locally for me and I thought it could be of interest for others.

Maybe you could integrate my suggestions or get inspiration for a proper fix that also solves the problem with BDAc installed?

There were 3 problems (for me) in the latest version:

1. Autostruts enable/disable cause massive inferno with BDAc (also any restrutting due to an explosion of a part)

--> As there is no indication in the partjoint if the joint is an autostrut (linuxgurugamer used the breakforce == 0 which does not work if the connection is dissolved by an exploding part) you basically have to check if the joint goes to a parent. However once the "Jointbreak" event occurs the connection is already dissolved. Therefore I added a function on the "onPartWillDie" during which the parent of the part going to die is still available and I put the info into a list. I then expanded the onJointbreak to check if the parts in the joint break are also in the list with dead parts and their parents.

2. If a middle part explodes there will be at least 2 joints that break. Once the "Host" of the joint break is destroyed and the target should get the flames (this is typically the main body) and once the target is destroyed and the host should get the flames (example would be the outer part of a wing that falls of when the middle part is destroyed). The second case could lead to an exception as it tries to attach flames to a part that is destroyed.

--> I added a check to see if the target of the joint break is in the list of destroyed parts and if it is attach flames to the host. Added benefit you get now a lot of burning parts if the ship is shot apart :cool:

3. Many parts would not get flames attached because their names wer not included in the list or spelled with lower case. (e.g. "wing", "tail", cockpit", structural procedural, cone etc.)

--> I changed the function so that upper case lower case should not matter anymore and added some items

Below is my version of flamingjoints.cs (with some comments to show what and why I changed it, those can be deleted).

Edit: I updated the code so that also in case the root part is destroyed flames are attached to the break away parts (only if the root part is a part that otherwise should have gotten flames attached).

 

Spoiler

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<GameObject> FlameObjects = new List<GameObject>();             
        public List<Vessel> vesselsAllowed = new List<Vessel>();
        // added dictionary to remember the parents of parts that are destroyed
        public Dictionary<uint, uint> deadPartsParents = new Dictionary<uint, uint>();
        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))
            {
                deadPartsParents.Add(data.flightID, data.parent.flightID);
            }
            else
            {
                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<uint, uint>(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<FlamingJointScript>();

            foreach (var pe in flameObject.GetComponentsInChildren<KSPParticleEmitter>())
            {
                if (!pe.useWorldSpace) continue;

                var gpe = pe.gameObject.AddComponent<DeGaplessParticleEmitter>();
                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<ModuleDecouple>().Count > 0)
            {
                return false;
            }
            
            if (partJoint.Target.FindModulesImplementing<CModuleStrut>().Count > 0 ||
                partJoint.Host.FindModulesImplementing<CModuleStrut>().Count > 0 ||
                partJoint.Child.FindModulesImplementing<CModuleStrut>().Count > 0 ||
                partJoint.Parent?.FindModulesImplementing<CModuleStrut>().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<ModuleEngines>() != null ||
                part.FindModuleImplementing<ModuleEnginesFX>() != null)/*|| part.partInfo.title.Contains("Turret") */
            {
                return true;
            }

          
            return false;
        }

        private static bool IsPartHostTypeAJointBreakerTrigger(string hostPartName)
        {
            return _PartTypesTriggeringUnwantedJointBreakEvents.Any(hostPartName.Contains);
        }
    }
}

 

 

 

Edited by Alioth81
updated code to account for loading the same vessel
Link to comment
Share on other sites

  • 2 weeks later...
On 9/27/2019 at 7:35 PM, DownHereInChile said:

My aircraft are set afire every time I decouple (stock) drop tanks. Any way to fix this?

I think this was fixed before by adding decouplers, etc. to whitelists so the effect wouldn't fire on staging, etc. I remember this was happening to BD Armory missile firing, too. Not sure if this got spun off before those fixes, or if the parts themselves changed in the meantime.

Link to comment
Share on other sites

Well, I have not used DE for a while, but here is my settings file, it should eliminate most unwanted effects.

DESettings
{
    LegacyEffect = True
    PartIgnoreList = tube,mortar,hedg,rail,launcher,pylon,bahaAdjustableRail,missile,EnginePlate,clamp
}

Link to comment
Share on other sites

53 minutes ago, TheKurgan said:

Well, I have not used DE for a while, but here is my settings file, it should eliminate most unwanted effects.

DESettings
{
    LegacyEffect = True
    PartIgnoreList = tube,mortar,hedg,rail,launcher,pylon,bahaAdjustableRail,missile,EnginePlate,clamp
}

Ah! yes -- that's what I was recalling. TY

Link to comment
Share on other sites

4 hours ago, Beetlecat said:

I think this was fixed before by adding decouplers, etc. to whitelists so the effect wouldn't fire on staging, etc. I remember this was happening to BD Armory missile firing, too. Not sure if this got spun off before those fixes, or if the parts themselves changed in the meantime.

How do you whitelist parts? #halp

Link to comment
Share on other sites

@TheKurgan

How did your testing go?

I updated the code in my previous post so that also the breakaway parts get flames attached if the root part is destroyed which is quite a firework :cool:.

(Happens only if the root part would have gotten flames attached e.g. its a cockpit, has resources etc.).

Before I excluded the root part from the dead part list so its destruction was not triggering effects on the break away parts.

So please update as well

Edited by Alioth81
Link to comment
Share on other sites

I updated my version of flamingjoints.cs again (see some posts above)

 

This version clears the list of dead parts when a scene is loaded. Else it could lead to some unexpected burning parts when you reload a save game that contains a plane that was destroyed in a previous session.

Link to comment
Share on other sites

For those who cannot compile the code themselves I added this zip

https://github.com/Alioth81/DestructionEffects/releases/tag/1.10.1

I am a first time Github user and I do not claim this is a full release more a patch until it is fixed in the real destruction effects.

It works for me under 1.7.3 with modes to run the BAD-T challenge but I do not know how it interacts with other modes or KSP versions.

If I did something wrong please inform me and I delete it.

Link to comment
Share on other sites

  • 2 weeks later...

 

14 hours ago, Sidestrafe2462 said:

So does anyone know how to stop autostrut from flaming up the whole craft, or is that still unresolved?

I think it is resolved. Try this one here until a new release comes out

On 10/11/2019 at 12:32 PM, Alioth81 said:

For those who cannot compile the code themselves I added this zip

https://github.com/Alioth81/DestructionEffects/releases/tag/1.10.1

I am a first time Github user and I do not claim this is a full release more a patch until it is fixed in the real destruction effects.

It works for me under 1.7.3 with modes to run the BAD-T challenge but I do not know how it interacts with other modes or KSP versions.

If I did something wrong please inform me and I delete it.

 

Link to comment
Share on other sites

  • 5 months later...
This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...