namespace = subjects_expanded_brother_kingdom_events

country_event = {
	id = subjects_expanded_brother_kingdom_events.1
	title = subjects_expanded_brother_kingdom_events.EVTNAME1
	desc = subjects_expanded_brother_kingdom_events.EVTDESC1
	picture = BAD_WITH_MONARCH_eventPicture

	is_triggered_only = yes

	trigger = {
		NOT = { has_country_flag = handling_invalid_brother_kingdom }
		is_subject = no
		government = monarchy
		has_regency = no
		religion_group = christian
		has_subject_of_type = brother_kingdom
		any_subject_country = {
			is_subject_of_type = brother_kingdom
			NOT = { dynasty = ROOT }
			has_regency = no
		}
	}

	immediate = {
		hidden_effect = {
			set_country_flag = handling_invalid_brother_kingdom
			random_subject_country = {
				limit = {
					is_subject_of_type = brother_kingdom
					NOT = { dynasty = ROOT }
					has_regency = no
				}
				save_event_target_as = invalid_brother_kingdom
			}
		}
	}

	option = {
		name = subjects_expanded_brother_kingdom_events1.EVTOPT1

		ai_chance = { factor = 0.5 }

		event_target:invalid_brother_kingdom = {
			grant_independence = yes
			if = {
				limit = {
					government = monarchy
					NOT = { marriage_with = ROOT }
				}
				create_marriage = ROOT
			}
			create_alliance = ROOT
			add_ruler_modifier = {
				name = ruler_just_canceled_to_be_brother_kingdom
				duration = -1
				hidden = yes
			}
		}
	}

	option = {
		name = subjects_expanded_brother_kingdom_events1.EVTOPT2

		trigger = {
			religion_group = christian
			event_target:invalid_brother_kingdom = {
				religion_group = christian
			}
		}

		ai_chance = { factor = 0.5 }

		add_legitimacy = -25
		event_target:invalid_brother_kingdom = {
			add_liberty_desire = 100
			if = {
				limit = {
					OR = {
						NOT = { government = monarchy }
						has_government_attribute = has_ruler_election
					}
				}
				change_government = monarchy
				add_government_reform = feudalism_reform
			}
			if = {
				limit = {
					marriage_with = ROOT
				}
				break_marriage = ROOT
			}
			tooltip = {
				kill_ruler = yes
				if = {
					limit = {
						has_heir = yes
					}
					kill_heir = {}
				}
			}
			define_ruler = {
				claim = 10
				religion = ROOT
				culture = ROOT
				dynasty = ROOT
				male = yes
				max_random_adm = 2
				max_random_dip = 2
				max_random_mil = 2
				age = 20
			}
			hidden_effect = {
				if = {
					limit = {
						has_heir = yes
					}
					kill_heir = { allow_new_heir = no }
				}
			}
		}
	}

	after = {
		clr_country_flag = handling_invalid_brother_kingdom
	}
}

country_event = {
	id = subjects_expanded_brother_kingdom_events.2
	title = subjects_expanded_brother_kingdom_events.EVTNAME2
	desc = subjects_expanded_brother_kingdom_events.EVTDESC2
	picture = BATTLE_eventPicture

	major = yes
	is_triggered_only = yes

	option = {
		name = subjects_expanded_brother_kingdom_events2.EVTOPT1

		ai_chance = {
			factor = 0.5

			modifier = {
				factor = 3
				army_strength = { who = FROM value = 1.5 }
			}
			modifier = {
				factor = 10
				is_at_war = yes
				NOT = { war_score = 0 }
			}
			modifier = {
				factor = 2
				war_exhaustion = 5
			}
			modifier = {
				factor = 2
				war_exhaustion = 10
			}
		}

		add_prestige = -5
		FROM = {
			grant_independence = yes
		}
	}

	option = {
		name = subjects_expanded_brother_kingdom_events2.EVTOPT2

		ai_chance = {
			factor = 0.5

			modifier = {
				factor = 3
				army_strength = { who = FROM value = 1.5 }
			}
			modifier = {
				factor = 5
				army_strength = { who = FROM value = 3 }
			}
		}

		FROM = {
			hidden_effect = {
				add_casus_belli = {
					target = ROOT
					type = cb_independence_war
				}
			}
			declare_war_with_cb = {
				who = ROOT
				casus_belli = cb_independence_war
			}
		}
	}
}

country_event = {
	id = subjects_expanded_brother_kingdom_events.3
	title = subjects_expanded_brother_kingdom_events.EVTNAME3
	desc = subjects_expanded_brother_kingdom_events.EVTDESC3
	picture = BATTLE_eventPicture

	hidden = yes
	is_triggered_only = yes

	trigger = {
		can_be_overlord = brother_kingdom
		war_with = FROM
		FROM = {
			is_subject = no
		}
	}

	immediate = {
		hidden_effect = {
			add_casus_belli = {
				target = FROM
				type = cb_disloyal_brother_kingdom
			}
		}
	}

	option = {
		name = subjects_expanded_brother_kingdom_events3.EVTOPT1

		ai_chance = { factor = 100 }
	}
}

country_event = {
	id = subjects_expanded_brother_kingdom_events.4
	title = subjects_expanded_brother_kingdom_events.EVTNAME4
	desc = subjects_expanded_brother_kingdom_events.EVTDESC4
	picture = BAD_WITH_MONARCH_eventPicture

	is_triggered_only = yes

	trigger = {
		NOT = { has_country_flag = handling_invalid_brother_kingdom_possible_war }
		num_of_subjects = 1
		OR = {
			AND = {
				OR = {
					is_subject = yes
					NOT = { government = monarchy }
					NOT = { religion_group = christian }
				}
				has_subject_of_type = brother_kingdom
			}
			any_subject_country = {
				is_subject_of_type = brother_kingdom
				NOT = { government = monarchy }
			}
		}
	}

	immediate = {
		hidden_effect = {
			set_country_flag = handling_invalid_brother_kingdom_possible_war
			if = {
				limit = {
					any_subject_country = {
						is_subject_of_type = brother_kingdom
						NOT = { government = monarchy }
					}
				}
				random_subject_country = {
					limit = {
						is_subject_of_type = brother_kingdom
						NOT = { government = monarchy }
					}
					save_event_target_as = invalid_brother_kingdom
				}
			}
			else = {
				random_subject_country = {
					limit = {
						is_subject_of_type = brother_kingdom
					}
					save_event_target_as = invalid_brother_kingdom
				}
			}
		}
	}

	option = {
		name = subjects_expanded_brother_kingdom_events4.EVTOPT1

		ai_chance = { factor = 0.9 }

		event_target:invalid_brother_kingdom = {
			grant_independence = yes
			if = {
				limit = {
					government = monarchy
					NOT = { marriage_with = ROOT }
				}
				create_marriage = ROOT
			}
			create_alliance = ROOT
			add_ruler_modifier = {
				name = ruler_just_canceled_to_be_brother_kingdom
				duration = -1
				hidden = yes
			}
		}
	}

	option = {
		name = subjects_expanded_brother_kingdom_events4.EVTOPT2

		ai_chance = {
			factor = 0.1
			modifier = {
				factor = 0
				is_at_war = yes
			}
			modifier = {
				factor = 0
				any_country = {
					is_supporting_independence_of = event_target:invalid_brother_kingdom
				}
			}
		}

		event_target:invalid_brother_kingdom = {
			hidden_effect = {
				if = {
					limit = {
						marriage_with = ROOT
					}
					break_marriage = ROOT
				}
				grant_independence = yes
				ROOT = { vassalize = PREV }
				add_liberty_desire = 100
				add_casus_belli = {
					target = ROOT
					type = cb_independence_war
				}
			}
			tooltip = {
				ROOT = { vassalize = PREV }
			}
			declare_war_with_cb = {
				who = ROOT
				casus_belli = cb_independence_war
			}
		}
	}

	after = {
		clr_country_flag = handling_invalid_brother_kingdom_possible_war
	}
}