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

Intersection improvment #2856

Merged
merged 8 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion Source/CombatExtended/CombatExtended/CE_Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ public static bool IntersectionPoint(Vector3 p1, Vector3 p2, Vector3 center, flo
Vector3 lp2 = p2 - center;

// If we obviously don't cross, early out.
if (lp1.sqrMagnitude < radSq && lp2.sqrMagnitude < radSq)
if (lp1.sqrMagnitude > radSq && lp2.sqrMagnitude > radSq)
perkinslr marked this conversation as resolved.
Show resolved Hide resolved
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,10 @@ private bool CheckCellForCollision(IntVec3 cell)
// Check for collision
if (thing == intendedTargetThing || def.projectile.alwaysFreeIntercept || thing.Position.DistanceTo(OriginIV3) >= minCollisionDistance)
{
if (!CanCollideWith(thing, out _))
{
continue;
}
if (BlockerRegistry.CheckForCollisionBetweenCallback(this, LastPos, thing.TrueCenter()))
{
return true;
Expand All @@ -894,10 +898,6 @@ private bool CheckCellForCollision(IntVec3 cell)
var newPosIV3 = thing.TrueCenter().ToIntVec3();
// Iterate through all cells between the last and the THING
// INCLUDING[!!!] THE LAST AND NEW POSITIONS!
if (!CanCollideWith(thing, out _))
{
continue;
}
var cells = GenSight.PointsOnLineOfSight(lastPosIV3, newPosIV3).Union(new[] { lastPosIV3, newPosIV3 }).Distinct().OrderBy(x => (x.ToVector3Shifted() - LastPos).MagnitudeHorizontalSquared());
foreach (var _cell in cells)
{
Expand Down