Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions BDArmory.Core/BDArmorySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ public class BDArmorySettings
public static string settingsConfigURL = "GameData/BDArmory/settings.cfg";

[BDAPersistantSettingsField] public static bool INSTAKILL = false;
[BDAPersistantSettingsField] public static bool BULLET_HITS = true;
[BDAPersistantSettingsField] public static bool PAINTBALL = false;
[BDAPersistantSettingsField] public static bool BATTLEDAMAGE = true;
[BDAPersistantSettingsField] public static bool BULLET_HITS = true;
[BDAPersistantSettingsField] public static bool BULLET_DECALS = true;
[BDAPersistantSettingsField] public static int MAX_NUM_BULLET_DECALS = 200;
[BDAPersistantSettingsField] public static bool SHOW_AMMO_GAUGES = false;
Expand All @@ -32,7 +34,8 @@ public class BDArmorySettings
[BDAPersistantSettingsField] public static float TARGET_WINDOW_SCALE_MIN = 0.50f;
[BDAPersistantSettingsField] public static float TARGET_WINDOW_SCALE = 1f;
[BDAPersistantSettingsField] public static float TARGET_WINDOW_SCALE_MAX = 2f;
[BDAPersistantSettingsField] public static float BDARMORY_UI_VOLUME = 0.35f;
[BDAPersistantSettingsField] public static bool STRICT_WINDOW_BOUNDARIES = false;
[BDAPersistantSettingsField] public static float BDARMORY_UI_VOLUME = 0.35f;
[BDAPersistantSettingsField] public static float BDARMORY_WEAPONS_VOLUME = 0.32f;
[BDAPersistantSettingsField] public static float MAX_GUARD_VISUAL_RANGE = 40000f;
[BDAPersistantSettingsField] public static float MAX_ACTIVE_RADAR_RANGE = 40000f; //NOTE: used ONLY for display range of radar windows! Actual radar range provided by part configs!
Expand All @@ -52,8 +55,9 @@ public class BDArmorySettings
[BDAPersistantSettingsField] public static float EXP_DMG_MOD_BALLISTIC;
[BDAPersistantSettingsField] public static float EXP_DMG_MOD_MISSILE;
[BDAPersistantSettingsField] public static float EXP_IMP_MOD;
[BDAPersistantSettingsField] public static bool FIRE_FX_IN_FLIGHT = false;
[BDAPersistantSettingsField] public static int MAX_FIRES_PER_VESSEL = 10; //controls fx for penetration only for landed or splashed
[BDAPersistantSettingsField] public static bool FIRE_FX_IN_FLIGHT = false;
[BDAPersistantSettingsField] public static bool SELFSEALING_TANKS = false;
[BDAPersistantSettingsField] public static int MAX_FIRES_PER_VESSEL = 10; //controls fx for penetration only for landed or splashed
[BDAPersistantSettingsField] public static float FIRELIFETIME_IN_SECONDS = 90f; //controls fx for penetration only for landed or splashed
[BDAPersistantSettingsField] public static bool PERFORMANCE_LOGGING = false;
[BDAPersistantSettingsField] public static bool AUTOCATEGORIZE_PARTS = true;
Expand Down
44 changes: 0 additions & 44 deletions BDArmory.Core/Extension/DamageFX.cs

This file was deleted.

160 changes: 131 additions & 29 deletions BDArmory.Core/Extension/PartExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,10 @@ public static void ApplyHitPoints(Part p, float damage_, float caliber, float ma
Debug.Log("[BDArmory]: mass: " + mass + " caliber: " + caliber + " multiplier: " + multiplier + " velocity: " + impactVelocity + " penetrationfactor: " + penetrationfactor);
Debug.Log("[BDArmory]: Ballistic Hitpoints Applied : " + Math.Round(damage_, 2));
}

//CheckDamageFX(p);
if (BDArmorySettings.BATTLEDAMAGE)
{
CheckDamageFX(p, caliber);
}
}

/// <summary>
Expand All @@ -149,7 +151,10 @@ public static void ApplyHitPoints(Part p, float damage)
if (BDArmorySettings.DRAW_DEBUG_LABELS)
Debug.Log("[BDArmory]: Explosive Hitpoints Applied to " + p.name + ": " + Math.Round(damage, 2));

//CheckDamageFX(p);
if (BDArmorySettings.BATTLEDAMAGE)
{
CheckDamageFX(p, 50);
}
}

/// <summary>
Expand Down Expand Up @@ -294,11 +299,6 @@ public static Vector3 GetSize(this Part part)
{
var size = part.GetComponentInChildren<MeshFilter>().mesh.bounds.size;

if (part.name.Contains("B9.Aero.Wing.Procedural"))
{
size = size * 0.1f;
}

float scaleMultiplier = 1f;
if (part.Modules.Contains("TweakScale"))
{
Expand All @@ -310,13 +310,22 @@ public static Vector3 GetSize(this Part part)
return size * scaleMultiplier;
}

public static bool IsAero(this Part part)
{
return part.Modules.Contains("ModuleControlSurface") ||
part.Modules.Contains("ModuleLiftingSurface");
}

public static string GetExplodeMode(this Part part)
public static bool IsAero(this Part part)
{
return part.Modules.Contains("ModuleLiftingSurface") ||
part.Modules.Contains("FARWingAerodynamicModel");
}
public static bool IsCtrlSrf(this Part part)
{
return part.Modules.Contains("ModuleControlSurface") ||
part.Modules.Contains("FARControllableSurface");
}
public static bool IsProcpart(this Part part)
{
return part.Modules.Contains("ProceduralPart");
}

public static string GetExplodeMode(this Part part)
{
return Dependencies.Get<DamageService>().GetExplodeMode_svc(part);
}
Expand Down Expand Up @@ -409,21 +418,114 @@ public static float DamageReduction(float armor, float damage, bool isMissile, f
return damage;
}

public static void CheckDamageFX(Part part)
{
if (part.GetComponent<ModuleEngines>() != null && part.GetDamagePercentatge() <= 0.35f)
{
part.gameObject.AddOrGetComponent<DamageFX>();
DamageFX.engineDamaged = true;
}

if (part.GetComponent<ModuleLiftingSurface>() != null && part.GetDamagePercentatge() <= 0.35f)
public static void CheckDamageFX(Part part, float caliber)
{
//what can get damaged? engines, wings, SAS, cockpits (past a certain dmg%, kill kerbals?), weapons(would be far easier to just have these have low hp), radars

if (part.GetComponent<ModuleEngines>() != null && part.GetDamagePercentatge() < 0.95f)
{
ModuleEngines engine;
engine = part.GetComponent<ModuleEngines>();
if (part.GetDamagePercentatge() >= 0.50f)
{
if (engine.thrustPercentage > 0)
{
//engine.maxThrust -= ((engine.maxThrust * 0.125f) / 100); // doesn't seem to adjust thrust; investigate
engine.thrustPercentage -= ((engine.maxThrust * 0.125f) / 100);
Mathf.Clamp(engine.thrustPercentage, 0, 1);
}
}
if (part.GetDamagePercentatge() < 0.50f)
{
if (engine.EngineIgnited)
{
engine.PlayFlameoutFX(true);
engine.Shutdown();
engine.allowRestart = false;
}
}
}
if (part.GetComponent<ModuleEnginesFX>() != null && part.GetDamagePercentatge() < 0.95f)
{
ModuleEnginesFX engine;
engine = part.GetComponent<ModuleEnginesFX>();
if (part.GetDamagePercentatge() >= 0.50f)
{
if (engine.thrustPercentage > 0)
{
//engine.maxThrust -= ((engine.maxThrust * 0.125f) / 100); // doesn't seem to adjust thrust; investigate
engine.thrustPercentage -= ((engine.maxThrust * 0.125f) / 100);
Mathf.Clamp(engine.thrustPercentage, 0, 1);
}
}
if (part.GetDamagePercentatge() < 0.50f)
{
if (engine.EngineIgnited)
{
engine.PlayFlameoutFX(true);
engine.Shutdown();
engine.allowRestart = false;
}
}
}
if (part.GetComponent<ModuleLiftingSurface>() != null && part.GetDamagePercentatge() > 0.125f)
{
ModuleLiftingSurface wing;
wing = part.GetComponent<ModuleLiftingSurface>();
if (wing.deflectionLiftCoeff > (caliber * caliber / 40000))
{
wing.deflectionLiftCoeff -= (caliber * caliber / 40000);
}
}
if (part.GetComponent<ModuleControlSurface>() != null && part.GetDamagePercentatge() > 0.125f)
{
ModuleControlSurface aileron;
aileron = part.GetComponent<ModuleControlSurface>();
aileron.deflectionLiftCoeff -= (caliber * caliber / 40000);
if (part.GetDamagePercentatge() < 0.75f)
{
if (aileron.ctrlSurfaceRange >= 0.5)
{
aileron.ctrlSurfaceRange -= 0.5f;
}
}
}
if (part.GetComponent<ModuleReactionWheel>() != null && part.GetDamagePercentatge() < 0.75f)
{
//part.gameObject.AddOrGetComponent<DamageFX>();
}
}

public static Vector3 GetBoundsSize(Part part)
ModuleReactionWheel SAS;
SAS = part.GetComponent<ModuleReactionWheel>();
if (SAS.PitchTorque > 1)
{
SAS.PitchTorque -= (1 - part.GetDamagePercentatge());
}
if (SAS.YawTorque > 1)
{
SAS.YawTorque -= (1 - part.GetDamagePercentatge());
}
if (SAS.RollTorque > 1)
{
SAS.RollTorque -= (1 - part.GetDamagePercentatge());
}
}
if (part.protoModuleCrew.Count > 0 && part.GetDamagePercentatge() < 0.50f)
{
ProtoCrewMember crewMember = part.protoModuleCrew.FirstOrDefault(x => x != null);
if (crewMember != null)
{
crewMember.UnregisterExperienceTraits(part);
crewMember.Die();
part.RemoveCrewmember(crewMember);
//Vessel.CrewWasModified(part.vessel);
Debug.Log(crewMember.name + " was killed by damage to cabin!");
if (HighLogic.CurrentGame.Parameters.Difficulty.MissingCrewsRespawn)
{
crewMember.StartRespawnPeriod();
}
//ScreenMessages.PostScreenMessage(crewMember.name + " killed by damage to " + part.vessel.name + part.partName + ".", 5.0f, ScreenMessageStyle.UPPER_LEFT);
}
}
}
public static Vector3 GetBoundsSize(Part part)
{
return PartGeometryUtil.MergeBounds(part.GetRendererBounds(), part.transform).size;
}
Expand Down
85 changes: 51 additions & 34 deletions BDArmory.Core/Module/HitpointTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class HitpointTracker : PartModule
private float previousHitpoints;
private bool _updateHitpoints = false;
private bool _forceUpdateHitpointsUI = false;
private const int HpRounding = 100;
private const int HpRounding = 25;

public override void OnLoad(ConfigNode node)
{
Expand Down Expand Up @@ -150,39 +150,56 @@ private void RefreshHitPoints()
}
}

#region Hitpoints Functions

public float CalculateTotalHitpoints()
{
float hitpoints;

if (!part.IsMissile())
{
var averageSize = part.GetAverageBoundSize();
var sphereRadius = averageSize * 0.5f;
var sphereSurface = 4 * Mathf.PI * sphereRadius * sphereRadius;
var structuralVolume = sphereSurface * 0.1f;

var density = (part.mass * 1000f) / structuralVolume;
density = Mathf.Clamp(density, 1000, 10000);
//Debug.Log("[BDArmory]: Hitpoint Calc" + part.name + " | structuralVolume : " + structuralVolume);
//Debug.Log("[BDArmory]: Hitpoint Calc"+part.name+" | Density : " + density);

var structuralMass = density * structuralVolume;
//Debug.Log("[BDArmory]: Hitpoint Calc" + part.name + " | structuralMass : " + structuralMass);
//3. final calculations
hitpoints = structuralMass * hitpointMultiplier * 0.33f;

if (hitpoints > 10 * part.mass * 1000f || hitpoints < 0.1f * part.mass * 1000f)
{
Debug.Log($"[BDArmory]: HitpointTracker::Clamping hitpoints for part {part.name}");
hitpoints = hitpointMultiplier * part.mass * 333f;
}

hitpoints = Mathf.Round(hitpoints / HpRounding) * HpRounding;
if (hitpoints <= 0) hitpoints = HpRounding;
}
else
#region Hitpoints Functions

public float CalculateTotalHitpoints()
{
float hitpoints;

if (!part.IsMissile())
{
var averageSize = part.GetAverageBoundSize();
var sphereRadius = averageSize * 0.5f;
var sphereSurface = 4 * Mathf.PI * sphereRadius * sphereRadius;
var structuralVolume = sphereSurface * 0.1f;

var density = (part.mass * 1000f) / structuralVolume;
density = Mathf.Clamp(density, 1000, 10000);
//Debug.Log("[BDArmory]: Hitpoint Calc" + part.name + " | structuralVolume : " + structuralVolume);
//Debug.Log("[BDArmory]: Hitpoint Calc"+part.name+" | Density : " + density);

var structuralMass = density * structuralVolume;
//Debug.Log("[BDArmory]: Hitpoint Calc" + part.name + " | structuralMass : " + structuralMass);
//3. final calculations
hitpoints = structuralMass * hitpointMultiplier * 0.33f;

if (hitpoints > 10 * part.mass * 1000f || hitpoints < 0.1f * part.mass * 1000f)
{
Debug.Log($"[BDArmory]: HitpointTracker::Clamping hitpoints for part {part.name}");
hitpoints = hitpointMultiplier * part.mass * 333f;
}

if (part.name.Contains("B9.Aero.Wing.Procedural")) // the above works for basic cylindrical-esque parts, but not wings, esp. not proc wings
{
hitpoints = (part.mass * 1000f) * 3.5f; // since wings are basically a 2d object, lets have mass be our scalar - afterall, 2x the mass will ~= 2x the surfce area
}
if (part.IsAero())
{
hitpoints = (part.mass * 1000f) * 7f; // stock wings are half the mass of proc wings, at least in FAR. Will need to check stock aero wing masses.
}
if (part.IsCtrlSrf())
{
hitpoints = 100f + (part.mass * 1000f) * 5f; // Crtl surfaces will have actuators of some flavor, are going to be more vulnerable to damage. +100 for guaranteed min health
}
if (part.IsProcpart())
{
hitpoints = (part.mass * 1000f) * 10f; // a 10x mult gives them about the same HP as similar size stock tanks and cones
}
hitpoints = Mathf.Round(hitpoints / HpRounding) * HpRounding;
if (hitpoints <= 0) hitpoints = HpRounding;
if (hitpoints < 100) hitpoints = 100;
}
else
{
hitpoints = 5;
Armor = 2;
Expand Down
Loading