-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #395 from BUTR/dev
v2.9.8
- Loading branch information
Showing
27 changed files
with
324 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,13 @@ | ||
# Common Extension Methods | ||
Below are the common extensions provided by the ButterLib. | ||
|
||
### [``ApplicationVersionExtensions``](xref:Bannerlord.ButterLib.Common.Extensions.ApplicationVersionExtensions) | ||
|
||
|
||
### [``CampaignExtensions``](xref:Bannerlord.ButterLib.Common.Extensions.CampaignExtensions) | ||
|
||
|
||
### [``DependencyInjectionExtensions``](xref:Bannerlord.ButterLib.Common.Extensions.DependencyInjectionExtensions) | ||
|
||
### [``CampaignExtensions``](xref:Bannerlord.ButterLib.Common.Extensions.CampaignExtensions) | ||
|
||
### [``ICampaignExtensions``](xref:Bannerlord.ButterLib.Common.Extensions.ICampaignExtensions) | ||
|
||
|
||
### [``IInputContextExtensions``](xref:Bannerlord.ButterLib.Common.Extensions.IInputContextExtensions) | ||
### [``DependencyInjectionExtensions``](xref:Bannerlord.ButterLib.Common.Extensions.DependencyInjectionExtensions) | ||
|
||
|
||
### [``MbEventExtensions``](xref:Bannerlord.ButterLib.Common.Extensions.MbEventExtensions) | ||
### [``MbEventExtensions``](xref:Bannerlord.ButterLib.Common.Extensions.MbEventExtensions) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
# Common Helper Methods | ||
Below are the common helpers provided by the ButterLib. | ||
|
||
### [``ApplicationVersionComparer``](xref:Bannerlord.ButterLib.Common.Helpers.ApplicationVersionComparer) | ||
|
||
|
||
### [``ElegantPairHelper``](xref:Bannerlord.ButterLib.Common.Helpers.ElegantPairHelper) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Distance Matrix | ||
Distance Matrix is a subsystem that provides a means for handling distances between various ``MBObjectBase`` objects in the game. You can use it to create your own implementations for the types you need. | ||
Additionally, there are built-in implementations for ``Settlement``, ``Clan``, and ``Kingdom`` types, along with a behavior to keep the distances updated. | ||
|
||
## Usage | ||
Use [``DistanceMatrix<T>``](https://butterlib.butr.link/api/Bannerlord.ButterLib.DistanceMatrix.DistanceMatrix-1.html) 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: | ||
```csharp | ||
if (this.GetServiceProvider() is { } serviceProvider) | ||
{ | ||
var distanceMatrixSubSystem = serviceProvider.GetSubSystem("Distance Matrix"); | ||
distanceMatrixSubSystem?.Enable(); | ||
} | ||
``` | ||
|
||
Example usage of built-in `DistanceMatrix` for `Clan` type: | ||
```csharp | ||
var clanDistanceMatrix = Campaign.Current.GetDefaultClanDistanceMatrix(); | ||
|
||
var playerClan = Clan.PlayerClan; | ||
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 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: | ||
```csharp | ||
//Gives same result as Campaign.Current.GetDefaultClanDistanceMatrix(); | ||
//...or Campaign.Current.GetCampaignBehavior<GeopoliticsBehavior>().ClanDistanceMatrix; | ||
var settlementDistanceMatrix = Campaign.Current.GetCampaignBehavior<GeopoliticsBehavior>().SettlementDistanceMatrix ?? new DistanceMatrixImplementation<Settlement>(); | ||
var clanDistanceMatrix = DistanceMatrix<Clan>.Create(() => Clan.All.Where(x => !x.IsEliminated && !x.IsBanditFaction), (clan, otherClan, args) => | ||
{ | ||
if (args != null && args.Length == 1 && args[0] is Dictionary<ulong, WeightedDistance> lst) | ||
{ | ||
return ButterLib.DistanceMatrix.DistanceMatrix.CalculateDistanceBetweenClans(clan, otherClan, lst).GetValueOrDefault(); | ||
} | ||
return float.NaN; | ||
}, [ButterLib.DistanceMatrix.DistanceMatrix.GetSettlementOwnersPairedList(settlementDistanceMatrix!)!]); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.