Skip to content

Commit

Permalink
Merge pull request #190 from DiplomacyTeam/dev
Browse files Browse the repository at this point in the history
v1.2.0 release
  • Loading branch information
artifixer authored Feb 3, 2023
2 parents 58da9ee + e77b4e4 commit 01e8008
Show file tree
Hide file tree
Showing 121 changed files with 4,255 additions and 1,175 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<p align="center">
<img src="https://tokei.rs/b1/github/DiplomacyTeam/Bannerlord.Diplomacy?category=code" alt="Lines of Code"/>
<a href="https://www.codefactor.io/repository/github/diplomacyteam/bannerlord.diplomacy"><img src="https://www.codefactor.io/repository/github/diplomacyteam/bannerlord.diplomacy/badge" alt="CodeFactor"/></a>
<a title="Crowdin" target="_blank" href="https://crowdin.com/project/bannerlorddiplomacy"><img src="https://badges.crowdin.net/bannerlorddiplomacy/localized.svg"></a>
</br>
<a href="https://www.nexusmods.com/mountandblade2bannerlord/mods/832" alt="NexusMods Bannerlord.Diplomacy">
<img src="https://img.shields.io/badge/NexusMods-Bannerlord.Diplomacy-yellow.svg" /></a>
Expand Down
16 changes: 8 additions & 8 deletions build/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@

<!--Module Version-->
<PropertyGroup>
<Version>1.1.19</Version>
<Version>1.2.0</Version>
<GameVersion>1.0.0</GameVersion>
</PropertyGroup>

<!-- Versions of Major Dependencies (For Package References & SubModule.xml Substitution) -->
<PropertyGroup>
<!--BuildResources Version-->
<BuildResourcesVersion>1.0.1.86</BuildResourcesVersion>
<BuildResourcesVersion>1.0.1.89</BuildResourcesVersion>
<!--Harmony Version-->
<HarmonyVersion>2.2.2</HarmonyVersion>
<!--ButterLib Version-->
<ButterLibVersion>2.6.1</ButterLibVersion>
<ButterLibVersion>2.6.3</ButterLibVersion>
<!--MCM Version-->
<MCMVersion>5.4.5</MCMVersion>
<MCMVersion>5.5.5</MCMVersion>
<!--UIExtenderEx Version-->
<UIExtenderExVersion>2.4.0</UIExtenderExVersion>
<UIExtenderExVersion>2.6.0</UIExtenderExVersion>
<!--BUTRShared Version-->
<BUTRSharedVersion>3.0.0.124</BUTRSharedVersion>
<BUTRSharedVersion>3.0.0.130</BUTRSharedVersion>
<!--BUTRModuleManager Version-->
<BUTRModuleManagerVersion>4.1.154</BUTRModuleManagerVersion>
<BUTRModuleManagerVersion>5.0.198</BUTRModuleManagerVersion>
<!--ModuleLoader Version-->
<BUTRModuleLoaderVersion>1.0.1.44</BUTRModuleLoaderVersion>
<!--Harmony Extensions Version-->
<HarmonyExtensionsVersion>3.2.0.72</HarmonyExtensionsVersion>
<HarmonyExtensionsVersion>3.2.0.73</HarmonyExtensionsVersion>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
Expand Down
50 changes: 49 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,55 @@
---------------------------------------------------------------------------------------------------
Version: 1.2.0
Game Versions: v1.0.0,v1.0.1,v1.0.2,v1.0.3,v1.1.0
* Adapted for v1.1.0
* Diplomacy events should now be ready to be a part of the public API, if we ever have one.
* Changed some setting hints to make them clearer.
* Fixed excessive UI overlap when repeatedly pressing the Factions button in the Encyclopedia.
* Better compatibility with other Encyclopedia mods for Faction page.
* Diplomacy console commands should no longer cause crashes when executed from the main menu.
* Added diplomacy.form_non_aggression_pact console command.
* Added diplomacy.break_non_aggression_pact console command.
* Added diplomacy.legitimize_rebel_kingdom console command to help fix broken civil wars.
* Fixed diplomacy.set_war_exhaustion console command.
* Fixed some cost calculations using wrong settings.
* Added Kingdom Wallet costs. They are used to pay war reparations and other interstate payments.
* Diplomatic actions now include up to 3 different costs: a gold cost (usually representing organizational expenses and benefiting no one), an influence cost, and a kingdom wallet cost (used for interstate payments when required).
* Added settings for proper calculating of gold and kingdom wallet costs.
* Adjusted kingdom scaling factor calculation for kingdoms with mercenary clans.
* Adjusted kingdom scaling factor calculation to be more notable for larger kingdoms.
* Donating gold to a clan now affects character traits.
* Fixed a bug preventing faction to consolidate when its demands are fulfilled.
* Fixed a bug where eliminated clans were not removed from factions.
* Fixed several crashes related to factions and Civil Wars.
* Made some overall stability improvements.
* Added a checkup on game load to fix the most common issues with current factions and civil wars from older saves.
* Fixed a bug due to which messengers did not move if the game was not saved and reloaded after sending the messenger.
* Resticted sending messengers only to the people you personally met or at least likely to know of, in order to keep intended game pace.
* Added a chance of messengers not reaching their target (road accidents).
* Added new mod settings to regulate new changes to messengers.
* Making peace without an election, whether it be from Kingdom Management or due to War Exhaustion, now imposes a tribute as usual.
* Making peace while on Critical War Exhaustion may result in war reparations being paid, if the other side is winning the War Exhaustion race.
* Losing a war due to War Exhaustion may result in some or even all of the territories captured by the defeated side being returned to the victor.
* A faction without fiefs is now destroyed if it loses the last ongoing war due to War Exhaustion.
* Fixed an issue where War Exhaustion report showed incorrect breakdown numbers if Exhaustion gain settings were changed during the war.
* Added War Exhaustion numbers to the campaign map indicator.
* Optimized the performance of the War Exhaustion map indicator.
* Added UI notification and explanation when War Exhaustion is critical.
* Critical War Exhaustion now affects Kingdom Management.
* Added UI notification when War Exhaustion can not be fully applied due to a campaign questline.
* Active questline now prevents War Exhaustion raising above the critical threshold, rather than capping it at 100%.
* Losing all fiefs no longer instantly raises War Exhaustion to its cap, but moderately increases it and effectively puts a fiefless faction on a timer, greatly increasing its daily Exhaustion gain.
* Some War Exhaustion events now can optionally be accounted for with diminishing returns, preventing rapid and meaningless Exhaustion accumulation when, for example, a single settlement is repeatedly recaptured by the belligerents.
* Added a setting allowing for War Exhaustion multipliers to be set differently for every side of the conflict, depending on the factions individual power scores.
* Added new War Exhaustion entries: heroes imprisoned and heroes perished. Both take into account hero significance for the faction.
* Added new War Exhaustion entry: caravans raided.
* Successful castle sieges now add half as much War Exhaustion as towns.
* Added detailed tooltips to War Exhaustion breakdown numbers in the report.
* War Exhaustion for all ongoing conflicts will be recalculated on first save load according to current mod settings.
---------------------------------------------------------------------------------------------------
Version: 1.1.19
Game Versions: v1.0.0,v1.0.1,v1.0.2
* Fiexed a crash that occured for some users on mod loading.
* Fixed a crash that occurred for some users on mod loading.
* Fixed a crash that occurred when pressing the "Grant fief" button multiple times in a row in Encyclopedia.
* Granting a fief to a clan would no longer worsen relations with mercenary clans or clans that own considerably more land.
* Granting fief interface now includes the name of the clan you are granting a fief to.
Expand Down
7 changes: 7 additions & 0 deletions crowdin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
files:
- source: /src/Bannerlord.Diplomacy/_Module/ModuleData/Languages/*.xml
translation: /src/Bannerlord.Diplomacy/_Module/ModuleData/Languages/%two_letters_code%/%original_file_name%
content_segmentation: 0
translatable_elements:
- '/base/tags/tag[@language],/base/strings/string[@text]'
- '/LanguageData[@id],/LanguageData[@name],/LanguageData[@subtitle_extension],/LanguageData[@supported_iso],/LanguageData/LanguageFile[@xml_path]'
34 changes: 34 additions & 0 deletions src/Bannerlord.Diplomacy/Actions/DestroyKingdomSoftlyAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Linq;

using TaleWorlds.CampaignSystem;
using TaleWorlds.CampaignSystem.Actions;

namespace Diplomacy.Actions
{
public static class DestroyKingdomSoftlyAction
{
public static void Apply(Kingdom kingdomToDestroy)
{
//Cold be already eliminated via CW or other mods
if (kingdomToDestroy.IsEliminated)
return;

foreach (Clan clan in kingdomToDestroy.Clans.ToList())
{
if (!clan.IsEliminated)
{
if (clan.IsUnderMercenaryService)
{
ChangeKingdomAction.ApplyByLeaveKingdomAsMercenary(clan);
}
else
{
ChangeKingdomAction.ApplyByLeaveKingdom(clan);
}
}
}
//Check again!
if (!kingdomToDestroy.IsEliminated) DestroyKingdomAction.Apply(kingdomToDestroy);
}
}
}
11 changes: 8 additions & 3 deletions src/Bannerlord.Diplomacy/Actions/GiveGoldToClanAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,25 @@ private static void ApplyInternal(Hero? giverHero, Clan? clan, int goldAmount)

private static void GiveGoldToClan(int gold, Clan clan)
{
foreach (var valueTuple in MBMath.DistributeShares(gold, clan.Lords, CalculateShare))
foreach ((var recipientHero, var amount) in MBMath.DistributeShares(gold, clan.Lords, CalculateShare))
{
GiveGoldAction.ApplyBetweenCharacters(null, valueTuple.Item1, valueTuple.Item2);
GiveGoldAction.ApplyBetweenCharacters(null, recipientHero, amount);
}
}

private static int CalculateShare(Hero member)
{
return HeroHelper.CalculateTotalStrength(member) + 10;
return HeroHelper.CalculateTotalStrength(member) + (member == member.Clan?.Leader ? 100 : 10);
}

public static void ApplyFromHeroToClan(Hero giverHero, Clan clan, int amount)
{
ApplyInternal(giverHero, clan, amount);
}

public static void ApplyToClan(Clan clan, int amount)
{
ApplyInternal(null, clan, amount);
}
}
}
93 changes: 93 additions & 0 deletions src/Bannerlord.Diplomacy/Actions/GiveGoldToKingdomAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using TaleWorlds.CampaignSystem;
using TaleWorlds.CampaignSystem.Actions;
using TaleWorlds.Library;

namespace Diplomacy.Actions
{
public static class GiveGoldToKingdomAction
{
private static void ApplyInternal(Kingdom? giverKingdom, Kingdom? receiverKingdom, int amount, WalletType giverWallet, WalletType receiverWallet)
{
if (amount == 0)
return;

if (giverKingdom != null)
{
switch (giverWallet)
{
case WalletType.TributeWallet:
giverKingdom.TributeWallet -= amount;
break;
case WalletType.BudgetWallet:
//Leaders should benefit from those payments too
var leaderAmount = amount < 0 ? amount / 3 : 0;
if (leaderAmount > 0) GiveGoldAction.ApplyBetweenCharacters(null, giverKingdom.Leader, leaderAmount);
giverKingdom.KingdomBudgetWallet -= (amount - leaderAmount);
break;
default:
break;
}
}
if (receiverKingdom != null)
{
switch (receiverWallet)
{
case WalletType.TributeWallet:
receiverKingdom.TributeWallet += amount;
break;
case WalletType.BudgetWallet:
//Leaders should benefit from those payments too
var leaderAmount = amount > 0 ? amount / 3 : 0;
if (leaderAmount > 0) GiveGoldAction.ApplyBetweenCharacters(null, receiverKingdom.Leader, leaderAmount);
receiverKingdom.KingdomBudgetWallet += (amount - leaderAmount);
break;
default:
break;
}
}
}

private static void ApplyInternal(Hero? giverHero, Kingdom? kingdom, int goldAmount)
{
if (giverHero != null)
{
GiveGoldAction.ApplyBetweenCharacters(giverHero, null, goldAmount, true);
}
if (kingdom != null)
{
GiveGoldToKingdom(goldAmount, kingdom);
}
}

private static void GiveGoldToKingdom(int gold, Kingdom kingdom)
{
foreach ((var recipientClan, var amount) in MBMath.DistributeShares(gold, kingdom.Clans, CalculateShare))
{
GiveGoldToClanAction.ApplyToClan(recipientClan, amount);
}
}

private static int CalculateShare(Clan clan)
{
return (int) clan.TotalStrength + (clan == clan.Kingdom?.Leader?.Clan ? 1000 : 10);
}

public static void ApplyFromHeroToKingdom(Hero giverHero, Kingdom kingdom, int amount)
{
ApplyInternal(giverHero, kingdom, amount);
}

public static void ApplyFromWalletToWallet(Kingdom? giverKingdom, Kingdom? receiverKingdom, int amount, WalletType giverWallet = WalletType.TributeWallet, WalletType receiverWallet = WalletType.BudgetWallet)
{
ApplyInternal(giverKingdom, receiverKingdom, amount, giverWallet, receiverWallet);
}

public enum WalletType : byte
{
None = 0,
MercenaryWallet = 1,
TributeWallet = 2,
BudgetWallet = 3,
}
}
}
4 changes: 2 additions & 2 deletions src/Bannerlord.Diplomacy/Actions/GrantFiefAction.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Diplomacy.Character;
using Diplomacy.Event;
using Diplomacy.Events;
using Diplomacy.Extensions;

using System;
Expand Down Expand Up @@ -37,7 +37,7 @@ public static void Apply(Settlement settlement, Clan grantedClan)
// gain generosity when granting fief
PlayerCharacterTraitEventExperience.FiefGranted.Apply();

Events.Instance.OnFiefGranted(settlement.Town);
DiplomacyEvents.Instance.OnFiefGranted(settlement.Town);
}

private static bool ShouldNegativeRelationBeApplied(Clan clan, Clan grantedClan, int grantedClanFiefCount, float grantedClanProsperity)
Expand Down
10 changes: 5 additions & 5 deletions src/Bannerlord.Diplomacy/Bannerlord.Diplomacy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<!-- STABLE, BETA, and e.g., e157 / e158 Constants Defined in Code -->
<PropertyGroup>
<GameVersionFlat>$([System.String]::Copy('$(GameVersion)').Replace('.',''))</GameVersionFlat>
<GameVersionConstant>e$(GameVersionFlat)</GameVersionConstant>
<GameVersionConstant>v$(GameVersionFlat)</GameVersionConstant>
<DefineConstants>$(DefineConstants);$(GameVersionConstant)</DefineConstants>
</PropertyGroup>

Expand Down Expand Up @@ -48,10 +48,10 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<!-- ReferenceAssemblies -->
<PackageReference Include="Bannerlord.ReferenceAssemblies.Core" Version="$(GameVersion).*" PrivateAssets="All" />
<PackageReference Include="Bannerlord.ReferenceAssemblies.Native" Version="$(GameVersion).*" PrivateAssets="All" />
<PackageReference Include="Bannerlord.ReferenceAssemblies.StoryMode" Version="$(GameVersion).*" PrivateAssets="All" />
<PackageReference Include="Bannerlord.ReferenceAssemblies.Sandbox" Version="$(GameVersion).*" PrivateAssets="All" />
<PackageReference Include="Bannerlord.ReferenceAssemblies.Core" Version="$(GameVersion).*-*" PrivateAssets="All" />
<PackageReference Include="Bannerlord.ReferenceAssemblies.Native" Version="$(GameVersion).*-*" PrivateAssets="All" />
<PackageReference Include="Bannerlord.ReferenceAssemblies.StoryMode" Version="$(GameVersion).*-*" PrivateAssets="All" />
<PackageReference Include="Bannerlord.ReferenceAssemblies.Sandbox" Version="$(GameVersion).*-*" PrivateAssets="All" />
</ItemGroup>

<!-- Extra Substitution Variables to Use in SubModule.xml -->
Expand Down
27 changes: 23 additions & 4 deletions src/Bannerlord.Diplomacy/CampaignBehaviors/AllianceBehavior.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Diplomacy.DiplomaticAction.Alliance;
using Diplomacy.DiplomaticAction.WarPeace;
using Diplomacy.Event;
using Diplomacy.Events;
using Diplomacy.Extensions;

using System.Linq;
Expand All @@ -18,8 +18,12 @@ internal sealed class AllianceBehavior : CampaignBehaviorBase
public override void RegisterEvents()
{
CampaignEvents.DailyTickClanEvent.AddNonSerializedListener(this, DailyTickClan);
Events.WarDeclared.AddNonSerializedListener(this, WarDeclared);
Events.AllianceFormed.AddNonSerializedListener(this, AllianceFormed);
#if v100 || v101 || v102 || v103
DiplomacyEvents.WarDeclared.AddNonSerializedListener(this, WarDeclared);
#else
CampaignEvents.WarDeclared.AddNonSerializedListener(this, WarDeclared);
#endif
DiplomacyEvents.AllianceFormed.AddNonSerializedListener(this, AllianceFormed);
}

public override void SyncData(IDataStore dataStore) { }
Expand Down Expand Up @@ -48,6 +52,7 @@ private void AllianceFormed(AllianceEvent allianceFormedEvent)
InformationManager.DisplayMessage(new InformationMessage(txtRendered, SubModule.StdTextColor));
}

#if v100 || v101 || v102 || v103
private void WarDeclared(WarDeclaredEvent warDeclaredEvent)
{
if (!warDeclaredEvent.IsProvoked
Expand All @@ -57,7 +62,17 @@ private void WarDeclared(WarDeclaredEvent warDeclaredEvent)
SupportAlliedKingdom(defender, attacker);
}
}

#else
private void WarDeclared(IFaction faction1, IFaction faction2, DeclareWarAction.DeclareWarDetail declareWarDetail)
{
if (declareWarDetail != DeclareWarAction.DeclareWarDetail.CausedByPlayerHostility
&& faction1 is Kingdom attacker
&& faction2 is Kingdom defender)
{
SupportAlliedKingdom(defender, attacker);
}
}
#endif
private void SupportAlliedKingdom(Kingdom kingdom, Kingdom kingdomToDeclareWarOn)
{
var allies = KingdomExtensions.AllActiveKingdoms.Where(k => kingdom != k && FactionManager.IsAlliedWithFaction(kingdom, k));
Expand All @@ -67,7 +82,11 @@ private void SupportAlliedKingdom(Kingdom kingdom, Kingdom kingdomToDeclareWarOn
if (!DeclareWarConditions.Instance.CanApply(ally, kingdomToDeclareWarOn, bypassCosts: true))
continue;

#if v100 || v101 || v102 || v103
DeclareWarAction.ApplyDeclareWarOverProvocation(ally, kingdomToDeclareWarOn);
#else
DeclareWarAction.ApplyByKingdomDecision(ally, kingdomToDeclareWarOn);
#endif
var txt = new TextObject("{=UDC8eW7s}{ALLIED_KINGDOM} is joining their ally, {KINGDOM}, in the war against {ENEMY_KINGDOM}.");
txt.SetTextVariable("ALLIED_KINGDOM", ally.Name);
txt.SetTextVariable("KINGDOM", kingdom.Name);
Expand Down
Loading

0 comments on commit 01e8008

Please sign in to comment.