|
| 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