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
11 changes: 5 additions & 6 deletions Source/CombatExtended/CombatExtended/CE_Math.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,10 @@ public static float CalculateHitPercent(float dist, float w, float h, float offs

float cos_theta = Mathf.Cos(shotAngle);

float sigma_gravity = (gravity * sigma_dist * sigma_dist) / (2 * shotSpeed * shotSpeed * cos_theta * cos_theta);
float sigma_vertical = Mathf.Sqrt(sigma_theta * sigma_theta + sigma_gravity);
float sigma_gravity = (gravity * dist * sigma_dist) / (2 * shotSpeed * shotSpeed * cos_theta * cos_theta);
float sigma_vertical = Mathf.Sqrt(sigma_y * sigma_y + sigma_gravity * sigma_gravity);

float half_w = w / 2;
float half_h = h / 2;
float p_horizontal = 1.0f;

if (sigma_horizontal > 0)
Expand All @@ -126,10 +125,10 @@ public static float CalculateHitPercent(float dist, float w, float h, float offs
{
// Becaue we might not be shooting at center of visible area, we have to calculate odds of missing high and the odds of missing low.
// The chance of hitting is the probability of the bullet passing between the upper and lower limit.
float upper = (offset + half_h) / sigma_vertical;
float lower = (offset - half_h) / sigma_vertical;
float higher = (h - offset) / sigma_vertical;
float lower = (-offset) / sigma_vertical;

p_vertical = normal_cdf(upper) - normal_cdf(lower);
p_vertical = normal_cdf(higher) - normal_cdf(lower);
}
return p_horizontal * p_vertical;
}
Expand Down
22 changes: 14 additions & 8 deletions Source/CombatExtended/CombatExtended/ShiftVecReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,24 @@ public string HitChance
var cv = new CollisionVertical(cover);
var cy_min = Mathf.Max(bounds.min.y, cv.Max);
var cy_max = bounds.max.y;
if (cy_max - cy_min < 0) // behind and shorter than cover
{
cy_max = cy_min;
}
bounds = new Bounds(new Vector3(bounds.center.x, cy_min + cy_max / 2, bounds.center.z),
new Vector3(bounds.size.x, (cy_max - cy_min), bounds.size.z));
}

var offset = bounds.size.y / 2;
float dist = shotDist;

// calculate uncertainty in xz position
float VS = Mathf.Sqrt(visibilityShift * visibilityShift
+ circularMissRadius * circularMissRadius
+ indirectFireShift * indirectFireShift
+ leadShift * leadShift);
float prob = CE_Math.CalculateHitPercent(dist, bounds, targetHeight, shotSpeed, shotAngle, swayDegrees, spreadDegrees, VS, CE_Utility.GravityConst);

float prob = CE_Math.CalculateHitPercent(dist, bounds, offset, shotSpeed, shotAngle, swayDegrees, spreadDegrees, VS, CE_Utility.GravityConst);

hitChance = GenText.ToStringByStyle(prob * 100, ToStringStyle.FloatTwo);
}
Expand Down Expand Up @@ -81,16 +87,16 @@ public float accuracyFactor
public float lightingShift = 0f;
public float weatherShift = 0f;

private float enviromentShiftInt = -1;
public float enviromentShift
private float environmentShiftInt = -1;
public float environmentShift
{
get
{
if (enviromentShiftInt < 0)
if (environmentShiftInt < 0)
{
enviromentShiftInt = ((blindFiring ? 1 : lightingShift) * 7f + weatherShift * 1.5f) * CE_Utility.LightingRangeMultiplier(shotDist) + smokeDensity;
environmentShiftInt = ((blindFiring ? 1 : lightingShift) * 7f + weatherShift * 1.5f) * CE_Utility.LightingRangeMultiplier(shotDist) + smokeDensity;
}
return enviromentShiftInt;
return environmentShiftInt;
}
}

Expand All @@ -107,7 +113,7 @@ public float visibilityShift
{
se = 0.02f;
}
visibilityShiftInt = enviromentShift * (shotDist / 50 / se) * (2 - aimingAccuracy);
visibilityShiftInt = environmentShift * (shotDist / 50 / se) * (2 - aimingAccuracy);
}
return visibilityShiftInt;
}
Expand Down Expand Up @@ -248,7 +254,7 @@ public string GetTextReadout()
{
stringBuilder.AppendLine(" " + $"DEBUG: visibilityShift\t\t{visibilityShift} ");
stringBuilder.AppendLine(" " + $"DEBUG: leadDist\t\t{leadDist} ");
stringBuilder.AppendLine(" " + $"DEBUG: enviromentShift\t{enviromentShift}");
stringBuilder.AppendLine(" " + $"DEBUG: environmentShift\t{environmentShift}");
stringBuilder.AppendLine(" " + $"DEBUG: accuracyFactor\t{accuracyFactor}");
stringBuilder.AppendLine(" " + $"DEBUG: circularMissRadius\t{circularMissRadius}");
stringBuilder.AppendLine(" " + $"DEBUG: sightsEfficiency\t{sightsEfficiency}");
Expand Down
Loading