Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for leaning pawns along shotLine for friendly fire avoidance. #2948

Draft
wants to merge 6 commits into
base: Development
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -1291,8 +1291,45 @@ private bool CanHitCellFromCellIgnoringRange(Vector3 shotSource, IntVec3 targetL
{
targetPos = targetLoc.ToVector3Shifted();
}

Ray shotLine = new Ray(shotSource, (targetPos - shotSource));

foreach (Pawn pawn in shotSource.ToIntVec3().PawnsNearSegment(targetLoc, caster.Map, 1, behind: false, infront: true))
{
Log.Message($"Pawn: {pawn} may be in the way");
if (pawn.Faction != null && ShooterPawn != null && !ShooterPawn.HostileTo(pawn))
{
if (pawn == ShooterPawn || pawn.Downed)
{
continue;
}
var bounds = CE_Utility.GetBoundsFor(pawn);
if (bounds.IntersectRay(shotLine, out var dist))
{
Log.Message($"intersects? {dist}");
return false;
}
}
}

foreach (Pawn pawn in shotSource.ToIntVec3().PawnsNearSegment(targetLoc, caster.Map, 2, behind: false, infront: true))
{
Log.Message($"Pawn: {pawn} may be in the way (2)");
if (pawn.Faction != null && ShooterPawn != null && !ShooterPawn.HostileTo(pawn))
{
if (pawn == ShooterPawn || pawn.Downed)
{
continue;
}
var bounds = CE_Utility.GetBoundsFor(pawn);
if (bounds.IntersectRay(shotLine, out var dist))
{
Log.Message($"intersects? {dist}");
return false;
}
}
}

// Create validator to check for intersection with partial cover
var aimMode = CompFireModes?.CurrentAimMode;

Expand Down
Loading