diff --git a/docs/articles/DistanceMatrix/Overview.md b/docs/articles/DistanceMatrix/Overview.md index d9652e91..b59a4913 100644 --- a/docs/articles/DistanceMatrix/Overview.md +++ b/docs/articles/DistanceMatrix/Overview.md @@ -3,7 +3,7 @@ Distance Matrix is a subsystem that provides a means for handling distances betw Additionally, there are built-in implementations for `Settlement`, `Clan`, and `Kingdom` types, along with a behavior to keep the distances updated. ## Usage -Use [``DistanceMatrix``](xref:Bannerlord.ButterLib.DistanceMatrix.DistanceMatrix) class to work with your custom distance matrix. +Use [``DistanceMatrix``](xref:Bannerlord.ButterLib.DistanceMatrix.DistanceMatrix-1) class to work with your custom distance matrix. Use [``CampaignExtensions``](xref:Bannerlord.ButterLib.Common.Extensions.CampaignExtensions) to access the built-in implementations. If you plan to use built-in implementations and behavior, don't forget to enable the SubSystem in your `SubModule` class: @@ -20,11 +20,11 @@ Example usage of built-in `DistanceMatrix` for `Clan` type: var clanDistanceMatrix = Campaign.Current.GetDefaultClanDistanceMatrix(); var playerClan = Clan.PlayerClan; -var playerNeighbors = clanDistanceMatrix.GetNearestNeighbors(playerClan, 10); +var playerNeighbours = clanDistanceMatrix.GetNearestNeighbours(playerClan, 10); Clan inquiredClan = Clan.All.FirstOrDefault(clan => clan.Fiefs.Count > 0 && Clan.All.Any(x => x.Fiefs.Count > 0 && clan.MapFaction.IsAtWarWith(x.MapFaction))); -var unfriendlyNeighbors = clanDistanceMatrix.GetNearestNeighbors(inquiredObject: inquiredClan, 20, x => !float.IsNaN(x.Distance) && x.OtherObject != inquiredClan && x.OtherObject.MapFaction.IsAtWarWith(inquiredClan.MapFaction)).ToList(); -var unfriendlyNeighborsN = clanDistanceMatrix.GetNearestNeighborsNormalized(inquiredObject: inquiredClan, 20, x => !float.IsNaN(x.Distance) && x.OtherObject != inquiredClan && x.OtherObject.MapFaction.IsAtWarWith(inquiredClan.MapFaction)).ToList(); +var unfriendlyNeighbours = clanDistanceMatrix.GetNearestNeighbours(inquiredObject: inquiredClan, 20, x => !float.IsNaN(x.Distance) && x.OtherObject != inquiredClan && x.OtherObject.MapFaction.IsAtWarWith(inquiredClan.MapFaction)).ToList(); +var unfriendlyNeighboursN = clanDistanceMatrix.GetNearestNeighboursNormalized(inquiredObject: inquiredClan, 20, x => !float.IsNaN(x.Distance) && x.OtherObject != inquiredClan && x.OtherObject.MapFaction.IsAtWarWith(inquiredClan.MapFaction)).ToList(); ``` Example usage of Distance Matrix with custom selector and distance calculator: diff --git a/src/Bannerlord.ButterLib.Implementation/DistanceMatrix/DistanceMatrixImplementation.cs b/src/Bannerlord.ButterLib.Implementation/DistanceMatrix/DistanceMatrixImplementation.cs index 34474ad8..d86a8903 100644 --- a/src/Bannerlord.ButterLib.Implementation/DistanceMatrix/DistanceMatrixImplementation.cs +++ b/src/Bannerlord.ButterLib.Implementation/DistanceMatrix/DistanceMatrixImplementation.cs @@ -76,18 +76,18 @@ public override void SetDistance(T object1, T object2, float distance) } /// - public override IEnumerable<(T OtherObject, float Distance)> GetNearestNeighbors(T inquiredObject, int count) => GetNearestNeighbors(inquiredObject, count, IsNotNaN()); + public override IEnumerable<(T OtherObject, float Distance)> GetNearestNeighbours(T inquiredObject, int count) => GetNearestNeighbours(inquiredObject, count, IsNotNaN()); /// - public override IEnumerable<(T OtherObject, float Distance)> GetNearestNeighbors(T inquiredObject, int count, Func<(T OtherObject, float Distance), bool> searchPredicate) => + public override IEnumerable<(T OtherObject, float Distance)> GetNearestNeighbours(T inquiredObject, int count, Func<(T OtherObject, float Distance), bool> searchPredicate) => _flatenedDictionary.TryGetValue(inquiredObject, out var nearestNeighbors) ? nearestNeighbors.Where(searchPredicate).Take(count) : []; /// - public override IEnumerable<(T OtherObject, float Distance)> GetNearestNeighborsNormalized(T inquiredObject, int count, float scaleMin = 0f, float scaleMax = 100f) => - GetNearestNeighborsNormalized(inquiredObject, count, IsNotNaN(), scaleMin, scaleMax); + public override IEnumerable<(T OtherObject, float Distance)> GetNearestNeighboursNormalized(T inquiredObject, int count, float scaleMin = 0f, float scaleMax = 100f) => + GetNearestNeighboursNormalized(inquiredObject, count, IsNotNaN(), scaleMin, scaleMax); /// - public override IEnumerable<(T OtherObject, float Distance)> GetNearestNeighborsNormalized(T inquiredObject, int count, Func<(T OtherObject, float Distance), bool> searchPredicate, float scaleMin = 0f, float scaleMax = 100f) + public override IEnumerable<(T OtherObject, float Distance)> GetNearestNeighboursNormalized(T inquiredObject, int count, Func<(T OtherObject, float Distance), bool> searchPredicate, float scaleMin = 0f, float scaleMax = 100f) { if (_flatenedDictionary.TryGetValue(inquiredObject, out var nearestNeighbors)) { diff --git a/src/Bannerlord.ButterLib/DistanceMatrix/DistanceMatrixT.cs b/src/Bannerlord.ButterLib/DistanceMatrix/DistanceMatrixT.cs index f902a420..8a6e92b6 100644 --- a/src/Bannerlord.ButterLib/DistanceMatrix/DistanceMatrixT.cs +++ b/src/Bannerlord.ButterLib/DistanceMatrix/DistanceMatrixT.cs @@ -108,7 +108,7 @@ protected DistanceMatrix(Func> customListGetter, FuncObject to search nearest neighbours for. /// Number of neighbours to be returned. /// - public abstract IEnumerable<(T OtherObject, float Distance)> GetNearestNeighbors(T inquiredObject, int count); + public abstract IEnumerable<(T OtherObject, float Distance)> GetNearestNeighbours(T inquiredObject, int count); /// /// Search for nearest neighbours of the specified type object @@ -119,7 +119,7 @@ protected DistanceMatrix(Func> customListGetter, FuncNumber of neighbours to be returned. /// A search predicate to filter through neighbours before returning nearest ones that qualify. /// - public abstract IEnumerable<(T OtherObject, float Distance)> GetNearestNeighbors(T inquiredObject, int count, Func<(T OtherObject, float Distance), bool> searchPredicate); + public abstract IEnumerable<(T OtherObject, float Distance)> GetNearestNeighbours(T inquiredObject, int count, Func<(T OtherObject, float Distance), bool> searchPredicate); /// /// Search for nearest neighbours of the specified type object @@ -132,7 +132,7 @@ protected DistanceMatrix(Func> customListGetter, FuncMinimum normalized value. /// Maximum normalized value. /// - public abstract IEnumerable<(T OtherObject, float Distance)> GetNearestNeighborsNormalized(T inquiredObject, int count, float scaleMin = 0f, float scaleMax = 100f); + public abstract IEnumerable<(T OtherObject, float Distance)> GetNearestNeighboursNormalized(T inquiredObject, int count, float scaleMin = 0f, float scaleMax = 100f); /// /// Search for nearest neighbours of the specified type object @@ -146,5 +146,5 @@ protected DistanceMatrix(Func> customListGetter, FuncMinimum normalized value. /// Maximum normalized value. /// - public abstract IEnumerable<(T OtherObject, float Distance)> GetNearestNeighborsNormalized(T inquiredObject, int count, Func<(T OtherObject, float Distance), bool> searchPredicate, float scaleMin = 0f, float scaleMax = 100f); + public abstract IEnumerable<(T OtherObject, float Distance)> GetNearestNeighboursNormalized(T inquiredObject, int count, Func<(T OtherObject, float Distance), bool> searchPredicate, float scaleMin = 0f, float scaleMax = 100f); } \ No newline at end of file