Skip to content

Commit 7fccb4a

Browse files
Conversion of Imperator Defensive Leagues + compatches for TFE and RoA (#2631)
### CHANGES - Finished game_start effect that sets up converted Imperator Defensive Leagues. (Closes #2591) - I decided to not add the Confederation/Defensive League split stuff directly into the converter because it ended up requiring quite a bit of changes that could be annoying to update whenever something needs to be added or changed. Because it is something that can be used without the converter too, I kept it as a separate mod that I uploaded to the Steam Workshop called "Confederations & Leagues". - I modified the welcome event that gets triggered at game start for players (that normally notifies them of the game rules added by the converter), and added a section to explain any/all mods that end up being designed to work alongside the converter, so players can know that the mod exists, and what it does. - I setup the game_start effect so that if it detects that the "Confederations & Leagues" mod is loaded (through a global variable), it will properly setup the converted Defensive Leagues according to how the mod allows them to be setup. If it detects that you are playing without the mod, then it will only setup the converted Defensive Leagues that can properly be setup in base game CK3 (meaning only Tribes/Nomads below kingdom-tier can get in). - Made a global variable (`irtock3_enabled`) get set at game start that indicates that the converter was used (and you are currently using a converted save game), so that if any mod in the future wants/needs to consider whether you are playing a converted Imperator game, they can easily check that variable. - Updated the files for the new TFE update (didn't add anything new aside from just making sure there were no replaceable/removable code errors) (Closes #2639) ### UPDATE (June 20) - Updated for RoA Version 4.0.0 (mainly just made sure there were no big errors when converting, haven't added much of their new content yet) - RoA changed how it handles the CCU parameter to be similar to how WtWSMS handles it, so the relevant code files were modified to account for that change. - Converter heritage and language files were modified to account for RoA CCU change, as well as change some of the parameters given to some of the heritages/languages by the mods so they make a little more sense. - Merged the Venetic heritage and language file into the main IRToCK3_heritage/language files to simplify things. - Made Basque have Equal Inheritance instead of Visigothic Codes in vanilla CK3 and RoA (TFE and WtWSMS make their own edits) - Renamed zzz_IRToCK3_tfe_override_l_english.yml.liquid to zzz_IRToCK3_mod_override_l_english.yml.liquid and added a section for ROA. - Made Talaiotic map to Nuragic, since they were expected to be closer to them than the Basque. - Added a mapping to ROA's new Nenets culture in the proper out-of-scope region of CK3 - Added a mapping for the romano_hellenic and helleno_roman cultures from the Imperator "Terra Europea - Terra Indomita Sub-Mod" to greek since they represent a kind of Roman-Hellenic hybrid culture in Imperator - Redid the province mappings for RoA since they changed their map a bit. Might need to be reworked later, but should be fine for now. (Since the converter can now convert wasteland provinces to whoever owns most of the land surrounding them, I left quite a bit of the wasteland province mappings the provinceMapper made) - Redid the imperator_invictus mappings, removing the mapped provinces from Subsaharan Africa so they don't all end up Berber/Megalithic. ### UPDATE (June 21) - Moved 00_mongol_invasion_effects.txt edit from the TFE versions of replaceable/removable_file_blocks to vanilla version of files. - Modified become_chakravarti_decision and unite_india_decision_effect so that they can only be taken if e_india has no holder or de jure land, and instead of requiring the three normal Indian Empire titles, it instead requires you to control the entire world_india region (pretty much the same thing as what it required before), and it de jure drifts the kingdoms of all empires that are 80% inside that india region. (Closes #2596) - Changed title mappings so that BHA maps to e_india instead of MRY. e_india and BHA both represent a united India title/tag in their respective games, so it makes more sense to have those mapped together. - Made HIB map to k_ireland instead of IVE since HIB actually represents a united Ireland. - Updated some of the replaceable/removable_file_blocks for ROA and TFE. --------- Co-authored-by: iht <[email protected]>
1 parent b08187a commit 7fccb4a

37 files changed

+6365
-8572
lines changed

ImperatorToCK3.UnitTests/Imperator/Diplomacy/DiplomacyDBTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,21 @@ public void DependencyCanBeLoaded() {
9999
Assert.Equal(new Date("1.1.1", AUC: true), diplomacy.Dependencies[0].StartDate);
100100
Assert.Equal("tributary", diplomacy.Dependencies[0].SubjectType);
101101
}
102+
103+
[Fact]
104+
public void DefensiveLeagueCanBeLoaded() {
105+
var reader = new BufferedReader(
106+
"""
107+
defensive_league={
108+
member=7
109+
member=552
110+
}
111+
""");
112+
var diplomacy = new ImperatorToCK3.Imperator.Diplomacy.DiplomacyDB(reader);
113+
114+
Assert.Single(diplomacy.DefensiveLeagues);
115+
Assert.Equal(2, diplomacy.DefensiveLeagues[0].Count);
116+
Assert.Equal((ulong)7, diplomacy.DefensiveLeagues[0][0]);
117+
Assert.Equal((ulong)552, diplomacy.DefensiveLeagues[0][1]);
118+
}
102119
}

ImperatorToCK3/CK3/Cultures/PillarCollection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ private void LoadPillar(string pillarId, BufferedReader pillarReader, OrderedDic
9393
Logger.Warn($"Language {pillarId} is missing required language_family parameter!");
9494
}
9595
}
96-
if (ck3ModFlags["wtwsms"]) {
96+
if (ck3ModFlags["wtwsms"] || ck3ModFlags["roa"]) {
9797
if (!pillar.Parameters.AsValueEnumerable().Any(p => p.Key.StartsWith("language_branch_"))) {
9898
Logger.Warn($"Language {pillarId} is missing required language_branch parameter!");
9999
}
100100
}
101-
if (ck3ModFlags["tfe"] || ck3ModFlags["roa"]) {
101+
if (ck3ModFlags["tfe"]) {
102102
if (!pillar.Parameters.AsValueEnumerable().Any(p => p.Key.StartsWith("language_group_"))) {
103103
Logger.Warn($"Language {pillarId} is missing required language_group parameter!");
104104
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using commonItems;
2+
using ImperatorToCK3.CK3.Titles;
3+
using ImperatorToCK3.Imperator.Countries;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
7+
namespace ImperatorToCK3.CK3.Diplomacy;
8+
9+
internal class DiplomacyDB {
10+
public List<List<Title>> Leagues { get; } = [];
11+
12+
public void ImportImperatorLeagues(IReadOnlyCollection<List<ulong>> irLeagues, CountryCollection countries) {
13+
Logger.Info("Importing Imperator defensive leagues...");
14+
15+
foreach (var irLeague in irLeagues) {
16+
List<Title> ck3LeagueMembers = [];
17+
foreach (var irMemberId in irLeague) {
18+
if (!countries.TryGetValue(irMemberId, out var country)) {
19+
Logger.Warn($"Member {irMemberId} of defensive league not found in countries!");
20+
continue;
21+
}
22+
23+
var ck3Title = country.CK3Title;
24+
if (ck3Title is not null) {
25+
ck3LeagueMembers.Add(ck3Title);
26+
}
27+
}
28+
29+
if (ck3LeagueMembers.Count < 2) {
30+
Logger.Notice("Not enough members in league to import it, skipping: " +
31+
$"{string.Join(", ", ck3LeagueMembers.Select(t => t.Id))}");
32+
continue;
33+
}
34+
Leagues.Add(ck3LeagueMembers);
35+
}
36+
}
37+
}

ImperatorToCK3/CK3/World.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using ImperatorToCK3.CK3.Armies;
66
using ImperatorToCK3.CK3.Characters;
77
using ImperatorToCK3.CK3.Cultures;
8+
using ImperatorToCK3.CK3.Diplomacy;
89
using ImperatorToCK3.CK3.Dynasties;
910
using ImperatorToCK3.CK3.Legends;
1011
using ImperatorToCK3.CK3.Provinces;
@@ -38,6 +39,7 @@
3839
using System.Threading;
3940
using System.Threading.Tasks;
4041
using Open.Collections;
42+
using DiplomacyDB = ImperatorToCK3.CK3.Diplomacy.DiplomacyDB;
4143
using System.Collections.Frozen;
4244

4345
namespace ImperatorToCK3.CK3;
@@ -60,6 +62,7 @@ internal sealed class World {
6062
public MapData MapData { get; private set; } = null!;
6163
public List<Wars.War> Wars { get; } = [];
6264
public LegendSeedCollection LegendSeeds { get; } = [];
65+
public DiplomacyDB Diplomacy { get; } = new();
6366
internal CoaMapper CK3CoaMapper { get; private set; } = null!;
6467
private readonly List<string> enabledDlcFlags = [];
6568

@@ -408,6 +411,10 @@ public World(Imperator.World impWorld, Configuration config, Thread? irCoaExtrac
408411
() => {
409412
LegendSeeds.LoadSeeds(ModFS);
410413
LegendSeeds.RemoveAnachronisticSeeds("configurables/legend_seeds_to_remove.txt");
414+
},
415+
416+
() => {
417+
Diplomacy.ImportImperatorLeagues(impWorld.DefensiveLeagues, impWorld.Countries);
411418
}
412419
);
413420
}

ImperatorToCK3/Data_Files/blankMod/output/common/on_action/IRToCK3_titles_game_start.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ on_game_start = {
33
on_actions = {
44
IRToCK3_create_admin_noble_families
55
IRToCK3_fix_roman_empire_name
6+
IRToCK3_initial_variables
67
}
78
}
89

@@ -723,4 +724,11 @@ IRToCK3_gamestart_events = {
723724
trigger_event = welcome.1 # This event so far just notifies the players of the game rules added by the converter
724725
}
725726
}
727+
}
728+
729+
# This just sets up a global variable that could be checked by any theoretical mod that wants to consider whether the converter was used
730+
IRToCK3_initial_variables = {
731+
effect = {
732+
set_global_variable = irtock3_enabled
733+
}
726734
}
Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
## This handles setting up the defensive leagues converted from Imperator
2+
# Inputs:
3+
# list = irtock3_confederation_members - A list containing all of the members of the specific Imperator Defensive League
4+
irtock3_confederation_setup_effect = {
5+
if = { # Check if the Confederations & Leagues mod is loaded, allowing more than Nomads/Tribes into confederations
6+
limit = { has_global_variable = confed_league_enabled }
7+
8+
if = {
9+
limit = { # Need to make sure that there are enough members in the Imperator Defensive League of appropriate rank. Confederations & Leagues might be modified to allow smaller kingdoms into Confederations/Leagues (likely as a game rule), so when that is done, this will likely get modified to account for that.
10+
any_in_list = {
11+
list = irtock3_confederation_members
12+
count > 1
13+
CL_has_appropriate_title_tier = yes
14+
}
15+
}
16+
17+
# Remove rulers who can't be in a confederation/league because of title rank or government, so they aren't added later or considered for anything else later on
18+
every_in_list = {
19+
limit = {
20+
OR = {
21+
CL_has_appropriate_title_tier = no
22+
AND = {
23+
CL_uses_confederations = no
24+
CL_uses_leagues = no
25+
}
26+
}
27+
}
28+
list = irtock3_confederation_members
29+
remove_from_list = irtock3_confederation_members
30+
}
31+
32+
## Need to determine whether this specific Imperator Defensive League will convert to a Confederation or a League, so check the government of every member, and count how many should be in confederations and how many should be in leagues
33+
set_global_variable = {
34+
name = confed_num
35+
value = 0
36+
}
37+
set_global_variable = {
38+
name = league_num
39+
value = 0
40+
}
41+
every_in_list = {
42+
list = irtock3_confederation_members
43+
44+
if = {
45+
limit = { CL_uses_confederations = yes }
46+
change_global_variable = {
47+
name = confed_num
48+
add = 1
49+
}
50+
}
51+
else_if = {
52+
limit = { CL_uses_leagues = yes }
53+
change_global_variable = {
54+
name = league_num
55+
add = 1
56+
}
57+
}
58+
}
59+
60+
# Now need to get relevant rulers to be used to determine the name of the confederation/league. For now, will just take the two with the largest military strength
61+
if = {
62+
limit = { global_var:league_num >= global_var:confed_num } # This should imply they should be in a Defensive League
63+
64+
# Get first member, for the 'actor' scope
65+
ordered_in_list = {
66+
limit = { CL_uses_leagues = yes }
67+
alternative_limit = { always = yes } # Incase somehow this was chosen and no one is actually capable of using leagues, need to make sure someone is chosen
68+
list = irtock3_confederation_members
69+
order_by = max_military_strength
70+
save_scope_as = actor
71+
save_scope_as = confederation_offerer
72+
}
73+
# Get second member, for the 'recipient' scope
74+
ordered_in_list = {
75+
limit = {
76+
CL_uses_leagues = yes
77+
NOT = { this = scope:actor }
78+
}
79+
alternative_limit = { # Incase somehow this was chosen and no one is actually capable of using leagues, need to make sure someone is chosen
80+
NOT = { this = scope:actor }
81+
}
82+
list = irtock3_confederation_members
83+
order_by = max_military_strength
84+
save_scope_as = recipient
85+
save_scope_as = confederation_accepter
86+
}
87+
88+
# When an Imperator Defensive League is converted, its members will always be allowed into the confederation/league, regardless of government, so need to give them a variable that signifies they should be allowed in
89+
every_in_list = {
90+
limit = { CL_uses_leagues = no }
91+
list = irtock3_confederation_members
92+
set_variable = allowed_in_leagues
93+
}
94+
}
95+
else = { # Otherwise, they will be put into a confederation
96+
# Get first member, for the 'actor' scope
97+
ordered_in_list = {
98+
limit = { CL_uses_confederations = yes }
99+
alternative_limit = { always = yes } # Incase somehow this was chosen an no one is actually capable of using confederations, need to make sure someone is chosen
100+
list = irtock3_confederation_members
101+
order_by = max_military_strength
102+
save_scope_as = actor
103+
save_scope_as = confederation_offerer
104+
}
105+
# Get second member, for the 'recipient' scope
106+
ordered_in_list = {
107+
limit = {
108+
CL_uses_confederations = yes
109+
NOT = { this = scope:actor }
110+
}
111+
alternative_limit = { # Incase somehow this was chosen an no one is actually capable of using confederations, need to make sure someone is chosen
112+
NOT = { this = scope:actor }
113+
}
114+
list = irtock3_confederation_members
115+
order_by = max_military_strength
116+
save_scope_as = recipient
117+
save_scope_as = confederation_accepter
118+
}
119+
120+
# When an Imperator Defensive League is converted, its members will always be allowed into the confederation/league, regardless of government (as long as they meet the rank requirements), so need to give them a variable that signifies they should be allowed in
121+
every_in_list = {
122+
limit = { CL_uses_confederations = no }
123+
list = irtock3_confederation_members
124+
set_variable = allowed_in_confederations
125+
}
126+
}
127+
128+
# Trigger the event that will create the confederation/league and have both scope:actor and scope:recipient added to it
129+
scope:actor = {
130+
#Event distributor event
131+
trigger_event = mpo_interactions_events.0001
132+
}
133+
134+
# Add other Defensive League members
135+
every_in_list = {
136+
limit = { is_confederation_member = no }
137+
list = irtock3_confederation_members
138+
save_scope_as = new_member
139+
scope:actor.confederation = { add_confederation_member = scope:new_member }
140+
clear_saved_scope = new_member
141+
}
142+
143+
# Cleanup so it doesn't cause any issues when converting multiple Defensive Leagues from Imperator
144+
remove_global_variable = league_num
145+
remove_global_variable = confed_num
146+
clear_saved_scope = actor
147+
clear_saved_scope = confederation_offerer
148+
clear_saved_scope = recipient
149+
clear_saved_scope = confederation_accepter
150+
clear_saved_scope = new_confederation
151+
}
152+
}
153+
# Otherwise, assume just using base game confederations, meaning only Nomads/Tribes should be allowed in
154+
else = {
155+
if = {
156+
limit = { # Need to make sure that there are enough members in the Imperator Defensive League of appropriate rank and government for base game confederations
157+
any_in_list = {
158+
list = irtock3_confederation_members
159+
count > 1
160+
AND = {
161+
highest_held_title_tier < tier_kingdom
162+
OR = {
163+
has_government = nomad_government
164+
has_government = tribal_government
165+
}
166+
}
167+
}
168+
}
169+
170+
# Remove rulers who can't be in a confederation because of title rank or government, so they aren't added later on
171+
every_in_list = {
172+
limit = {
173+
OR = {
174+
highest_held_title_tier >= tier_kingdom
175+
NOR = {
176+
has_government = nomad_government
177+
has_government = tribal_government
178+
}
179+
}
180+
}
181+
list = irtock3_confederation_members
182+
remove_from_list = irtock3_confederation_members
183+
}
184+
185+
## Now need to get relevant rulers to be used to determine the name of the confederation. For now, will just take the two with the largest military strength
186+
# Get first member, for the 'actor' scope
187+
ordered_in_list = {
188+
list = irtock3_confederation_members
189+
order_by = max_military_strength
190+
save_scope_as = actor
191+
save_scope_as = confederation_offerer
192+
}
193+
# Get second member, for the 'recipient' scope
194+
ordered_in_list = {
195+
limit = {
196+
NOT = { this = scope:actor }
197+
}
198+
list = irtock3_confederation_members
199+
order_by = max_military_strength
200+
save_scope_as = recipient
201+
save_scope_as = confederation_accepter
202+
}
203+
204+
# Trigger the event that will create the confederation and have both scope:actor and scope:recipient added to it
205+
scope:actor = {
206+
#Event distributor event
207+
trigger_event = mpo_interactions_events.0001
208+
}
209+
210+
# Add other Defensive League members
211+
every_in_list = {
212+
limit = { is_confederation_member = no }
213+
list = irtock3_confederation_members
214+
save_scope_as = new_member
215+
scope:actor.confederation = { add_confederation_member = scope:new_member }
216+
clear_saved_scope = new_member
217+
}
218+
219+
# Cleanup so it doesn't cause any issues when converting multiple Defensive Leagues from Imperator
220+
clear_saved_scope = actor
221+
clear_saved_scope = confederation_offerer
222+
clear_saved_scope = recipient
223+
clear_saved_scope = confederation_accepter
224+
clear_saved_scope = new_confederation
225+
}
226+
}
227+
228+
# Empty the list of members so there are no conflicts when converting multiple Imperator Defensive Leagues
229+
every_in_list = {
230+
list = irtock3_confederation_members
231+
remove_from_list = irtock3_confederation_members
232+
}
233+
}

0 commit comments

Comments
 (0)