Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void CheckForCollisions(float moveSpeed)
{
if (Map.thingGrid.ThingAt(cell, ThingCategory.Pawn) is Pawn pawn and not VehiclePawn)
{
if (pawn.Faction.HostileTo(Faction) || Faction == null ||
if (TargetingHelper.IsHostileToVehicleOrFaction(this, pawn) || Faction == null ||
Rand.Chance(VehicleDamager.FriendlyFireChance(this, pawn)))
{
(float pawnDamage, float vehicleDamage) = CalculateImpactDamage(pawn, this, moveSpeed);
Expand Down
17 changes: 14 additions & 3 deletions Source/Vehicles/Utility/Helpers/TargetingHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public static bool TryGetTarget(this VehicleTurret turret, out LocalTargetInfo t
return false;
}

internal static bool IsHostileToVehicleOrFaction(VehiclePawn vehicle, Thing target)
{
return vehicle.HostileTo(target) || target.HostileTo(vehicle.Faction);
}

/// <summary>
/// Best attack target for VehicleTurret
/// </summary>
Expand Down Expand Up @@ -81,7 +86,7 @@ private static IAttackTarget BestAttackTarget(VehicleTurret turret, TargetScanFl
{
return false;
}
if (!searcherPawn.HostileTo(thing))
if (!IsHostileToVehicleOrFaction(searcherPawn, thing))
{
return false;
}
Expand Down Expand Up @@ -162,8 +167,14 @@ private static IAttackTarget BestAttackTarget(VehicleTurret turret, TargetScanFl
return true;
};

List<IAttackTarget> tmpTargets =
[.. searcherPawn.Map.attackTargetsCache.GetPotentialTargetsFor(searcherPawn)];
var attackTargetsCache = searcherPawn.Map.attackTargetsCache;
HashSet<IAttackTarget> targetSet = [.. attackTargetsCache.GetPotentialTargetsFor(searcherPawn)];
if (searcherPawn.Faction != null)
{
targetSet.UnionWith(attackTargetsCache.TargetsHostileToFaction(searcherPawn.Faction));
}
List<IAttackTarget> tmpTargets = [.. targetSet];

bool flag = false;
for (int i = 0; i < tmpTargets.Count; i++)
{
Expand Down