BahamutoD / BDArmory

Gun turrets and other weapon systems for KSP
38 stars 112 forks source link

Allow explosions to apply temperature to physicsless parts (but still not apply force) #29

Open allmhuran opened 8 years ago

allmhuran commented 8 years ago

If I had an IDE here at home right now I'd try this myself, but in explosionFX.cs starting at line 128, we can see that physicsless parts are not subject to explosion force or explosion heat.

Maybe there is something about physicsless parts of which I am unaware, but they seem to behave normally with temperature (at least, they do now in 1.04/5, maybe they didn't before).

I'd suggest changing to the following, so that physicless parts are subject to explosion heat, but not subject to explosion force.

if(!ignoreParts.Contains(part) && (!sourceVessel || sourceVessel != missileSource)) // removed physicsless check from this line
{
    ignoreParts.Add(part);

    if (part.physicalSignificance == Part.PhysicalSignificance.FULL) { // added it back only for force application
        Rigidbody rb = part.GetComponent<Rigidbody>();
        if(rb)
        {
            rb.AddForceAtPosition(ray.direction * power * distanceFactor * ExplosionImpulseMultiplier, rayHit.point, ForceMode.Impulse);
        }
    }

    // but do apply heat even to physicsless parts
    if(heat < 0)
    {
        heat = power;
    }
    float heatDamage = (BDArmorySettings.DMG_MULTIPLIER/100) * ExplosionHeatMultiplier * heat * distanceFactor / part.crashTolerance;
    float excessHeat = Mathf.Max(0, (float)(part.temperature + heatDamage - part.maxTemp));
    part.temperature += heatDamage;
    if(BDArmorySettings.DRAW_DEBUG_LABELS) Debug.Log("====== Explosion ray hit part! Damage: " + heatDamage);
    if(excessHeat > 0 && part.parent)
    {
        part.parent.temperature += excessHeat;
    }
    return;