Class DistanceMatrix
- Namespace
- Bannerlord.ButterLib.DistanceMatrix
- Assembly
- Bannerlord.ButterLib.dll
An abstract class used in a DistanceMatrix<T> derived class, that pairs given objects of type T and for each pair calculates the distance between the objects that formed it.
public abstract class DistanceMatrix
- Inheritance
-
DistanceMatrix
- Derived
- Inherited Members
Methods
CalculateDistanceBetweenClans(Clan, Clan, Dictionary<ulong, WeightedDistance>)
Calculates distance between two given Clan objects.
public static float? CalculateDistanceBetweenClans(Clan clan1, Clan clan2, Dictionary<ulong, WeightedDistance> settlementOwnersPairedList)
Parameters
clan1
ClanFirst of the clans to calculate distance between.
clan2
ClanSecond of the clans to calculate distance between.
settlementOwnersPairedList
Dictionary<ulong, WeightedDistance>List of the distances between pairs of settlements and of the weights of the paired settlements, except that the owner clan pairs are used instead of the settlements themselves to speed up the process.
Returns
- float?
A floating-point number representing the distance between two specified Clan objects or NaN if distance could not be calculated (usually when clan has no fiefs).
Remarks
Calculation is based on the average distance between clans fiefs weighted by the fief type.
CalculateDistanceBetweenHeroes(Hero, Hero)
Calculates distance between two given Hero objects.
public static float? CalculateDistanceBetweenHeroes(Hero hero1, Hero hero2)
Parameters
hero1
HeroThe first of the heroes to calculate distance between.
hero2
HeroThe second of the heroes to calculate distance between.
Returns
- float?
A floating-point number representing the distance between two specified Hero objects or NaN if distance could not be calculated.
CalculateDistanceBetweenKingdoms(Kingdom, Kingdom, DistanceMatrix<Clan>)
Calculates distance between two given Kingdom objects.
public static float? CalculateDistanceBetweenKingdoms(Kingdom kingdom1, Kingdom kingdom2, DistanceMatrix<Clan> clanDistanceMatrix)
Parameters
kingdom1
KingdomFirst of the kingdoms to calculate distance between.
kingdom2
KingdomSecond of the kingdoms to calculate distance between.
clanDistanceMatrix
DistanceMatrix<Clan>Settlement distance matrix .
Returns
- float?
A floating-point number representing the distance between two specified Kingdom objects or NaN if distance could not be calculated.
Remarks
Calculation is based on the average distance between kingdoms fiefs weighted by the fief type.
Create<T>()
Initializes a new instance of the DistanceMatrix<T> class as per actual implementation with the default EntityListGetter and DistanceCalculator methods.
public static DistanceMatrix<T>? Create<T>() where T : MBObjectBase
Returns
Type Parameters
T
Exceptions
Create<T>(Func<IEnumerable<T>>, Func<T, T, object[]?, float>, object[]?)
Initializes and returns a new instance of the DistanceMatrix<T> class as per actual implementation with custom methods that will be used to get the list of analyzed objects and calculate the distances between them.
public static DistanceMatrix<T>? Create<T>(Func<IEnumerable<T>> customListGetter, Func<T, T, object[]?, float> customDistanceCalculator, object[]? distanceCalculatorArgs) where T : MBObjectBase
Parameters
customListGetter
Func<IEnumerable<T>>A delegate to the method that will be used to get a list of objects of type
T
for calculating the distances between them.customDistanceCalculator
Func<T, T, object[], float>A delegate to the method that will be used to calculate the distance between two given type
T
objects.distanceCalculatorArgs
object[]Optional array of arguments that will be passed to the calculation method.
Returns
Type Parameters
T
Exceptions
GetSettlementOwnersPairedList(DistanceMatrix<Settlement>)
Transforms given Settlement distance matrix into list of the weighted distances between pairs of settlements, except that the owner clan pairs are used instead of the settlements themselves.
public static Dictionary<ulong, WeightedDistance>? GetSettlementOwnersPairedList(DistanceMatrix<Settlement> settlementDistanceMatrix)
Parameters
settlementDistanceMatrix
DistanceMatrix<Settlement>Settlement distance matrix to transform into list.
Returns
- Dictionary<ulong, WeightedDistance>
A list of tuples holding information about pair of initial settlements owners, distance between settlements and combined settlement weight.
Remarks
This method could be used to supply CalculateDistanceBetweenClans(Clan, Clan, Dictionary<ulong, WeightedDistance>) method with required list argument.
This page was last modified at 05/14/2024 18:40:00 +03:00 (UTC).
Commit Message
Author: Alexey Chernyshov
Commit: 2584f61cc2b0d2f623370f0fd8067fe0a1772be2
DistanceMatrix fixes and improvements