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 1 commit
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,25 @@ 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))
{
if (pawn.Faction == ShooterPawn?.Faction)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should use if (pawn.Faction != null && !ShooterPawn.HostileTo(pawn)) to avoid friendly fire with ally (wandering wild men/animals will be ignored)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

{
if (pawn == ShooterPawn || pawn.Downed)
{
continue;
}
var bounds = CE_Utility.GetBoundsFor(pawn);
if (bounds.IntersectRay(shotLine, out var dist))
{
return false;
}
}
}

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

Expand Down
Loading