Skip to content

Commit

Permalink
Merge pull request #262 from DiplomacyTeam/dev
Browse files Browse the repository at this point in the history
Release 1.2.11
  • Loading branch information
bennyz authored Feb 17, 2024
2 parents af6f279 + 6edfe7e commit db9d5af
Show file tree
Hide file tree
Showing 18 changed files with 258 additions and 101 deletions.
12 changes: 6 additions & 6 deletions build/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@

<!--Module Version-->
<PropertyGroup>
<Version>1.2.10</Version>
<Version>1.2.11</Version>
<GameVersion>1.0.0</GameVersion>
</PropertyGroup>

<!-- Versions of Major Dependencies (For Package References & SubModule.xml Substitution) -->
<PropertyGroup>
<!--BuildResources Version-->
<BuildResourcesVersion>1.1.0.102</BuildResourcesVersion>
<BuildResourcesVersion>1.1.0.104</BuildResourcesVersion>
<!--Harmony Version-->
<HarmonyVersion>2.2.2</HarmonyVersion>
<!--ButterLib Version-->
<ButterLibVersion>2.8.11</ButterLibVersion>
<ButterLibVersion>2.8.16</ButterLibVersion>
<!--MCM Version-->
<MCMVersion>5.9.1</MCMVersion>
<MCMVersion>5.9.2</MCMVersion>
<!--UIExtenderEx Version-->
<UIExtenderExVersion>2.8.0</UIExtenderExVersion>
<UIExtenderExVersion>2.11.0</UIExtenderExVersion>
<!--BUTRShared Version-->
<BUTRSharedVersion>3.0.0.137</BUTRSharedVersion>
<BUTRSharedVersion>3.0.0.138</BUTRSharedVersion>
<!--BUTRModuleManager Version-->
<BUTRModuleManagerVersion>5.0.209</BUTRModuleManagerVersion>
<!--ModuleLoader Version-->
Expand Down
7 changes: 7 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
---------------------------------------------------------------------------------------------------
Version: 1.2.11
Game Versions: v1.1.1,v1.1.2,v1.1.3,v1.1.4,v1.1.5,v1.1.6,v1.2.0,v1.2.1,v1.2.2,v1.2.3,v1.2.4,v1.2.5,v1.2.6,v1.2.7,v1.2.8,1.2.9
* Add support for v1.2.9
* UI fixes (Rogue-Demon-King)
* Alliance tendency bonus on leader clan marriages (eg3r)
* Relation based war declaration (eg3r)
---------------------------------------------------------------------------------------------------
Version: 1.2.10
Game Versions: v1.0.0,v1.0.1,v1.0.2,v1.0.3,v1.1.0,v1.1.1,v1.1.2,v1.1.3,v1.1.4,v1.1.5,v1.1.6,v1.2.0,v1.2.1,v1.2.2,v1.2.3,v1.2.4,v1.2.5,v1.2.6,v1.2.7,v1.2.8
* Add support for v1.2.6,v1.2.7,v1.2.8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal sealed class CivilWarBehavior : CampaignBehaviorBase
public override void RegisterEvents()
{
CampaignEvents.DailyTickClanEvent.AddNonSerializedListener(this, DailyTickClan);
#if v124 || v125 || v126 || v127 || v128
#if v124 || v125 || v126 || v127 || v128 || v129
CampaignEvents.OnClanChangedKingdomEvent.AddNonSerializedListener(this, (x, y, z, _, _) => RemoveClanFromRebelFaction(x, y, z));
#elif v100 || v101 || v102 || v103 || v110 || v111 || v112 || v113 || v114 || v115 || v116 || v120 || v121 || v122 || v123
CampaignEvents.ClanChangedKingdom.AddNonSerializedListener(this, (x, y, z, _, _) => RemoveClanFromRebelFaction(x, y, z));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public virtual ExplainedNumber GetScore(Kingdom ourKingdom, Kingdom otherKingdom
if (!ourKingdom.IsStrong())
explainedNum.Add(Scores.BelowMedianStrength, _TWeakKingdom);

// Marriage score

if (Settings.Instance!.LeaderClanMarriageAffectsAlliance && ourKingdom.RulingClan.HasMarriedClanLeaderRelation(otherKingdom.RulingClan))
explainedNum.Add(Scores.LeaderClanMarriage, CreateTextWithKingdom(SMarriageWithLeaderClan, otherKingdom));

// Common Enemies

var commonEnemies = FactionManager.GetEnemyKingdoms(ourKingdom).Intersect(FactionManager.GetEnemyKingdoms(otherKingdom));
Expand Down Expand Up @@ -129,6 +134,8 @@ public interface IDiplomacyScores
public int Relationship { get; }

public int Tendency { get; }

public int LeaderClanMarriage { get; }
}

private static readonly TextObject _TWeakKingdom = new("{=q5qphBwi}Weak Kingdom");
Expand All @@ -139,6 +146,7 @@ public interface IDiplomacyScores
private const string SWarWithKingdom = "{=RqQ4oqvl}War with {KINGDOM}";
private const string SAllianceWithKingdom = "{=cmOSpfyW}Alliance with {KINGDOM}";
private const string SPactWithKingdom = "{=t6YhBLj7}Non-Aggression Pact with {KINGDOM}";
private const string SMarriageWithLeaderClan = "{=BjkwaNot}Marriage with leading clan of {KINGDOM}";

private const string SCommonEnemy = SWarWithKingdom;
private const string SAlliedToEnemy = SAllianceWithKingdom;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ public class AllianceScores : IDiplomacyScores
public int Tendency => Settings.Instance!.AllianceTendency;

public int NonAggressionPactWithEnemy => -1000;

public int NonAggressionPactWithNeutral => -10;

public int LeaderClanMarriage => 50;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Diplomacy.Extensions;

using TaleWorlds.CampaignSystem;
using TaleWorlds.Localization;

namespace Diplomacy.DiplomaticAction.GenericConditions
{
internal sealed class BadRelationCondition : IDiplomacyCondition
{
public bool ApplyCondition(Kingdom kingdom,
Kingdom otherKingdom,
out TextObject? textObject,
bool forcePlayerCosts = false,
bool bypassCosts = false)
{
textObject = null;

// if kingdom leaders are friends, do not allow war
if (Settings.Instance!.NoWarBetweenFriends && kingdom.Leader.IsFriend(otherKingdom.Leader))
{
textObject = new TextObject("{=9aaZ8Ed4}Cannot declare war, kingdom leaders are friends.");
return false;
}

// if relations are above "good" do not start wars
if (Settings.Instance!.NoWarOnGoodRelations && kingdom.Leader.GetRelation(otherKingdom.Leader) >= Settings.Instance!.NoWarOnGoodRelationsThreshold)
{
textObject = new TextObject("{=Zimavbgw}Cannot declare war, kingdom leaders personal relations are excellent.");
return false;
}

// if leading clans have marriages between them => no wars
if (Settings.Instance!.NoWarWhenMarriedLeaderClans && kingdom.RulingClan.HasMarriedClanLeaderRelation(otherKingdom.RulingClan))
{
textObject = new TextObject("{=pXD8Uf2e}Cannot declare war, kingdom leader clans have close family marriages.");
return false;
}

return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class NonAggressionPactScores : IDiplomacyScores
public int Tendency => Settings.Instance!.NonAggressionPactTendency;
public int NonAggressionPactWithEnemy => -20;
public int NonAggressionPactWithNeutral => -10;
public int LeaderClanMarriage => 50;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ internal sealed class DeclareWarConditions : AbstractConditionEvaluator<DeclareW
new AtPeaceCondition(),
new HasEnoughTimeElapsedForWarCondition(),
new NotRebelKingdomCondition(),
new NotEliminatedCondition()
new NotEliminatedCondition(),
new BadRelationCondition()
};

public DeclareWarConditions() : base(Conditions) { }
Expand Down
7 changes: 7 additions & 0 deletions src/Bannerlord.Diplomacy/Extensions/ClanExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ public static IEnumerable<RebelFaction> GetRebelFactions(this Clan clan)
{
return default;
}
}

public static bool HasMarriedClanLeaderRelation(this Clan clan, Clan other)
{
// if any relatives are alive and married to other clan => "related by marriage"
return clan.Leader.Spouse?.AllRelatedHeroes().Any(ownSpouseFamMember => ownSpouseFamMember.Clan == other) ?? false
|| clan.Leader.AllRelatedHeroes().Any(famMember => famMember.IsAlive && (famMember.Spouse?.AllRelatedHeroes().Any(spouseFamMember => spouseFamMember.Clan == other) ?? false));
}
}
}
35 changes: 35 additions & 0 deletions src/Bannerlord.Diplomacy/Extensions/HeroExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;

using TaleWorlds.CampaignSystem;
using TaleWorlds.CampaignSystem.CharacterDevelopment;
Expand All @@ -12,6 +13,40 @@ public static float GetNormalizedTraitValue(this Hero hero, TraitObject trait)
var zeroMinMaxTraitLevel = (float) Math.Abs(trait.MinValue) + trait.MaxValue;
var zeroMinTraitLevel = hero.GetTraitLevel(trait) + Math.Abs(trait.MinValue);
return zeroMinTraitLevel / zeroMinMaxTraitLevel;
}

public static IEnumerable<Hero> AllRelatedHeroes(this Hero inHero, bool includeExSpouses = false)
{
if (inHero.Father != null)
{
yield return inHero.Father;

// father side uncles/aunts are close family
foreach (Hero hero3 in inHero.Father.Siblings)
yield return hero3;
}

if (inHero.Mother != null)
{
yield return inHero.Mother;

// mother side uncles/aunts are close family
foreach (Hero hero4 in inHero.Mother.Siblings)
yield return hero4;
}

if (inHero.Spouse != null)
yield return inHero.Spouse;

foreach (Hero hero in inHero.Children)
yield return hero;

foreach (Hero hero2 in inHero.Siblings)
yield return hero2;

if (includeExSpouses)
foreach (Hero hero3 in inHero.ExSpouses)
yield return hero3;
}
}
}
20 changes: 20 additions & 0 deletions src/Bannerlord.Diplomacy/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ class Settings : AttributeGlobalSettings<Settings>
[SettingPropertyGroup(HeadingKingdomDiplomacy)]
public int MinimumAllianceDuration { get; set; } = 42;

[SettingPropertyBool("{=xXKKRp99}Leader Clan Family Marriage Affects Alliance", Order = 33, RequireRestart = false, HintText = "{=BGS6mUID}If active, will grant a bonus to alliance tendency when leader clans have a family marriage between them. Default value is active.")]
[SettingPropertyGroup(HeadingKingdomDiplomacy)]
public bool LeaderClanMarriageAffectsAlliance { get; set; } = true;

[SettingPropertyInteger("{=V35hUfcc}Non-Aggression Pact Duration in Days", 0, 1000, Order = 50, RequireRestart = false, HintText = "{=KXLGZEPh}The duration (in days) that a non-aggression pact will last. Default value is 84 (one standard game year).")]
[SettingPropertyGroup(HeadingKingdomDiplomacy)]
public int NonAggressionPactDuration { get; set; } = 84;
Expand All @@ -80,6 +84,22 @@ class Settings : AttributeGlobalSettings<Settings>
[SettingPropertyGroup(HeadingKingdomDiplomacy)]
public bool PlayerDiplomacyControl { get; set; } = false;

[SettingPropertyBool(displayName: "{=dRyU9E7Z}No Wars Between Friends", Order = 1001, RequireRestart = false, HintText = "{=XyXJSTKr}If active, kingdom leaders that are friends will not start wars with each other. Default value is enabled.")]
[SettingPropertyGroup(HeadingKingdomDiplomacy)]
public bool NoWarBetweenFriends { get; set; } = true;

[SettingPropertyBool(displayName: "{=pWoKQ6HO}No Wars If Good Relations", Order = 1002, RequireRestart = false, HintText = "{=bOuGhbPt}If active, wars between leaders of kingdoms will not be allowed if relations are above war start relations. Default value is enabled.")]
[SettingPropertyGroup(HeadingKingdomDiplomacy)]
public bool NoWarOnGoodRelations { get; set; } = true;

[SettingPropertyInteger("{=x0Aoiomr}No Wars Good Relations Threshold", 0, 100, Order = 1003, RequireRestart = false, HintText = "{=aH6rpjt6}The relation value of kingdom leaders after which kingdoms will not start wars with each other. Default value is 30.")]
[SettingPropertyGroup(HeadingKingdomDiplomacy)]
public int NoWarOnGoodRelationsThreshold { get; set; } = 30;

[SettingPropertyInteger("{=jwNKk8P7}No Wars When Married", 0, 100, Order = 1004, RequireRestart = false, HintText = "{=xcMzKH48}If active, kingdom leader clans that have a marriage between each other will not start wars. Default value is active.")]
[SettingPropertyGroup(HeadingKingdomDiplomacy)]
public bool NoWarWhenMarriedLeaderClans { get; set; } = true;

// Messengers

[SettingPropertyBool("{=nwTyegdV}Enable Messengers Accidents", Order = 0, RequireRestart = false, HintText = "{=T7yybpw3}If enabled, adds a small chance of failure for messengers. The longer the journey, the higher the chance of an accident on the road. Default value is enabled.")]
Expand Down
4 changes: 4 additions & 0 deletions src/Bannerlord.Diplomacy/SubModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ protected override void OnSubModuleLoad()
base.OnSubModuleLoad();
Instance = this;

#if v129
var extender = UIExtender.Create(Name);
#else
var extender = new UIExtender(Name);

Check warning on line 53 in src/Bannerlord.Diplomacy/SubModule.cs

View workflow job for this annotation

GitHub Actions / Build Module

'UIExtender.UIExtender(string)' is obsolete: 'Use UIExtender.Create(moduleName) if backwards compatibility is not a concern.'

Check warning on line 53 in src/Bannerlord.Diplomacy/SubModule.cs

View workflow job for this annotation

GitHub Actions / Build Module

'UIExtender.UIExtender(string)' is obsolete: 'Use UIExtender.Create(moduleName) if backwards compatibility is not a concern.'

Check warning on line 53 in src/Bannerlord.Diplomacy/SubModule.cs

View workflow job for this annotation

GitHub Actions / Build Module

'UIExtender.UIExtender(string)' is obsolete: 'Use UIExtender.Create(moduleName) if backwards compatibility is not a concern.'

Check warning on line 53 in src/Bannerlord.Diplomacy/SubModule.cs

View workflow job for this annotation

GitHub Actions / Build Module

'UIExtender.UIExtender(string)' is obsolete: 'Use UIExtender.Create(moduleName) if backwards compatibility is not a concern.'

Check warning on line 53 in src/Bannerlord.Diplomacy/SubModule.cs

View workflow job for this annotation

GitHub Actions / Build Module

'UIExtender.UIExtender(string)' is obsolete: 'Use UIExtender.Create(moduleName) if backwards compatibility is not a concern.'

Check warning on line 53 in src/Bannerlord.Diplomacy/SubModule.cs

View workflow job for this annotation

GitHub Actions / Build Module

'UIExtender.UIExtender(string)' is obsolete: 'Use UIExtender.Create(moduleName) if backwards compatibility is not a concern.'

Check warning on line 53 in src/Bannerlord.Diplomacy/SubModule.cs

View workflow job for this annotation

GitHub Actions / Build Module

'UIExtender.UIExtender(string)' is obsolete: 'Use UIExtender.Create(moduleName) if backwards compatibility is not a concern.'

Check warning on line 53 in src/Bannerlord.Diplomacy/SubModule.cs

View workflow job for this annotation

GitHub Actions / Build Module

'UIExtender.UIExtender(string)' is obsolete: 'Use UIExtender.Create(moduleName) if backwards compatibility is not a concern.'

Check warning on line 53 in src/Bannerlord.Diplomacy/SubModule.cs

View workflow job for this annotation

GitHub Actions / Build Module

'UIExtender.UIExtender(string)' is obsolete: 'Use UIExtender.Create(moduleName) if backwards compatibility is not a concern.'

Check warning on line 53 in src/Bannerlord.Diplomacy/SubModule.cs

View workflow job for this annotation

GitHub Actions / Build Module

'UIExtender.UIExtender(string)' is obsolete: 'Use UIExtender.Create(moduleName) if backwards compatibility is not a concern.'
#endif
extender.Register(typeof(SubModule).Assembly);
extender.Enable();

Expand Down
2 changes: 1 addition & 1 deletion src/Bannerlord.Diplomacy/ViewModel/RebelFactionsVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public void OnCreateFaction()
inquiryElements,
true,
1,
#if v120 || v121 || v122 || v123 || v124 || v125 || v126 || v127 || v128
#if v120 || v121 || v122 || v123 || v124 || v125 || v126 || v127 || v128 || v129
1,
#endif
GameTexts.FindText("str_ok").ToString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public WarExhaustionMapIndicatorVM()
_kingdomsAtWar = new MBBindingList<WarExhaustionMapIndicatorItemVM>();
RefreshValues();
DiplomacyEvents.WarExhaustionInitialized.AddNonSerializedListener(this, HandleStanceChange);
#if v124 || v125 || v126 || v127 || v128
#if v124 || v125 || v126 || v127 || v128 || v129
CampaignEvents.OnClanChangedKingdomEvent.AddNonSerializedListener(this, (x, _, _, _, _) => HandleClanChangedKingdom(x));
#elif v100 || v101 || v102 || v103 || v110 || v111 || v112 || v113 || v114 || v115 || v116 || v120 || v121 || v122 || v123
CampaignEvents.ClanChangedKingdom.AddNonSerializedListener(this, (x, _, _, _, _) => HandleClanChangedKingdom(x));
Expand Down Expand Up @@ -51,7 +51,7 @@ public override void OnFinalize()
{
base.OnFinalize();

#if v124 || v125 || v126 || v127 || v128
#if v124 || v125 || v126 || v127 || v128 || v129
CampaignEvents.OnClanChangedKingdomEvent.ClearListeners(this);
#elif v100 || v101 || v102 || v103 || v110 || v111 || v112 || v113 || v114 || v115 || v116 || v120 || v121 || v122 || v123
CampaignEvents.ClanChangedKingdom.ClearListeners(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
<TextWidget DataSource="{CurrentSelectedClan}" WidthSizePolicy="CoverChildren" HeightSizePolicy="CoverChildren" HorizontalAlignment="Center" Brush="Kingdom.ParagraphSmall.Text" Text="@TierText" ClipContents="false"/>

<!--Banner-->
<MaskedTextureWidget DataSource="{CurrentSelectedClan\Banner_9}" WidthSizePolicy="Fixed" HeightSizePolicy="Fixed" SuggestedWidth="107" SuggestedHeight="128" MarginTop="5" HorizontalAlignment="Center" VerticalAlignment="Top" Brush="Kingdom.TornBanner.Big" AdditionalArgs="@AdditionalArgs" ImageId="@Id" ImageTypeCode="@ImageTypeCode" OverlayTextureScale="1.6" />
<MaskedTextureWidget DataSource="{CurrentSelectedClan\Banner_9}" WidthSizePolicy="Fixed" HeightSizePolicy="Fixed" SuggestedWidth="107" SuggestedHeight="128" MarginTop="5" HorizontalAlignment="Center" VerticalAlignment="Top" Brush="Kingdom.TornBanner.Big" AdditionalArgs="@AdditionalArgs" ImageId="@Id" ImageTypeCode="@ImageTypeCode" />

<ListPanel UpdateChildrenStates="true" WidthSizePolicy="StretchToParent" HeightSizePolicy="CoverChildren" StackLayout.LayoutMethod="HorizontalLeftToRight" >
<Children>
Expand Down Expand Up @@ -187,7 +187,7 @@
<Widget WidthSizePolicy="Fixed" HeightSizePolicy="Fixed" SuggestedWidth="55" SuggestedHeight="55" HorizontalAlignment="Center" VerticalAlignment="Center" Sprite="frame_small_9" />
</Children>
</ImageIdentifierWidget>-->
<MaskedTextureWidget DataSource="{ClanBanner_9}" WidthSizePolicy="Fixed" HeightSizePolicy="Fixed" SuggestedWidth="!Banner.Width.Scaled" SuggestedHeight="!Banner.Height.Scaled" HorizontalAlignment="Right" VerticalAlignment="Top" Brush="Flat.Tuple.Banner.Small.Hero" AdditionalArgs="@AdditionalArgs" ImageId="@Id" ImageTypeCode="@ImageTypeCode" IsDisabled="true" OverlayTextureScale="2.2" />
<MaskedTextureWidget DataSource="{ClanBanner_9}" WidthSizePolicy="Fixed" HeightSizePolicy="Fixed" SuggestedWidth="!Banner.Width.Scaled" SuggestedHeight="!Banner.Height.Scaled" HorizontalAlignment="Right" VerticalAlignment="Top" Brush="Flat.Tuple.Banner.Small.Hero" AdditionalArgs="@AdditionalArgs" ImageId="@Id" ImageTypeCode="@ImageTypeCode" IsDisabled="true" />
<ImageIdentifierWidget DataSource="{ImageIdentifier}" WidthSizePolicy="Fixed" HeightSizePolicy="Fixed" SuggestedWidth="85" SuggestedHeight="61" PositionYOffset="-1" HorizontalAlignment="Center" VerticalAlignment="Center" AdditionalArgs="@AdditionalArgs" ImageId="@Id" ImageTypeCode="@ImageTypeCode" IsEnabled="false" />
<HintWidget WidthSizePolicy="StretchToParent" HeightSizePolicy="StretchToParent" Command.HoverBegin="ExecuteBeginHint" Command.HoverEnd="ExecuteEndHint" IsEnabled="false" />
<RichTextWidget WidthSizePolicy = "StretchToParent" HeightSizePolicy = "CoverChildren" HorizontalAlignment="Center" VerticalAlignment="Top" Brush="Kingdom.ParagraphSmall.Text" Brush.FontSize="16" PositionYOffset="65" Text="@NameText" ClipContents="false"/>
Expand Down Expand Up @@ -395,4 +395,4 @@
</Children>
</Widget>
</Window>
</Prefab>
</Prefab>
Loading

0 comments on commit db9d5af

Please sign in to comment.