Skip to content

Commit

Permalink
Merge pull request #22 from noreenko/optimize-AreAllies
Browse files Browse the repository at this point in the history
optimize AreAllies
  • Loading branch information
jecrell authored Oct 21, 2022
2 parents d16dbab + 00b7f7d commit a636a8c
Showing 1 changed file with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,25 +93,23 @@ public static IEnumerable<Pawn> GetPawnsInsideRadius(LocalTargetInfo center, Map
}

/// <summary>
/// Convenience function for checking whether the pawns are allies.
/// Convenience function for checking whether the pawns are allies. Handles null Factions.
/// </summary>
/// <param name="first">Initiator pawn that is checking.</param>
/// <param name="second">Second pawn to check with.</param>
/// <returns>True if they are allies. False if not.</returns>
public static bool AreAllies(Thing first, Thing second)
{
//If you are yourself, then you are definitely allies.
if (first == second)
//You are allies with yourself and others in your factions. Treat null as a faction
if (first.Faction == second.Faction)
return true;

//Null factions are allies.
if (first.Faction == null && second.Faction == null)
return true;
//Otherwise, null Factions are not allies with non-null Factions
if (first.Faction == null || second.Faction == null)
return false;

//Be allies if in the same Faction or if the goodwill with the other Faction is abouve 50%.
if (second.Faction == null)
return first.Faction == second.Faction;
return first.Faction == second.Faction || first.Faction.GoodwillWith(second.Faction) >= 0.5f;
//Be allies if the goodwill with the other Faction is above 50%.
return first.Faction.GoodwillWith(second.Faction) >= 0.5f;
}

/// <summary>
Expand Down

0 comments on commit a636a8c

Please sign in to comment.