﻿#Events related to the Spouse Councillor's diplomacy task

namespace = councillor_spouse_martial


#Notifications:
# 0001: A county gains increased levies
# 0002: The realm gains increased levies
# 0003: Increased army morale
# 0004: Gain Prestige
# 0005: Reduced mercenary cost
# 0006: Health boost
# 0007: A wounded character gains a Health boost
# 0008: Gain Dread
# 0009: Increase a child's Prowess

#Events:
# 1001: Local Tourney
# 1002: Gain Prestige or Dread
# 1003: Stop a war between vassals
# 1004: Spouse raises troops
# 1005: A vassal is cowed

######################
# Notifications
#
######################

#A County gains a levy increase
# by Petter Vilberg
scripted_trigger councillor_spouse_martial_0001_county_trigger = {
	tier = tier_county
	NOT = {
		has_county_modifier = councillor_spouse_inspired_troops_county_modifier
	}
}

councillor_spouse_martial.0001 = {
	hidden = yes

	trigger = {
		valid_spouse_councillor_trigger = yes
		NOT = { has_character_flag = had_event_councillor_spouse_martial_0001 }
		any_held_title = {
			councillor_spouse_martial_0001_county_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = martial
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_1
		}
	}

	immediate = {
		cp:councillor_spouse = {
			save_scope_as = active_councillor
		}
		add_character_flag = {
			flag = had_event_councillor_spouse_martial_0001
			years = 5
		}
		random_held_title = {
			limit = {
				councillor_spouse_martial_0001_county_trigger = yes
			}
			save_scope_as = county
		}

		send_interface_message = {
			type = event_spouse_task_good
			title = councillor_spouse_martial.0001.message
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { martial < average_skill_level }
					}
					desc = task_martial_good_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { martial >= average_skill_level }
					}
					desc = task_martial_good_skilled_notification_tooltip
				}
			}
			
			right_icon = scope:councillor
			left_icon = scope:county

			scope:county = {
				add_county_modifier = {
					modifier = councillor_spouse_inspired_troops_county_modifier
					years = 10
				}
			}
		}
	}
}


#Council Owner gains a levy increase
# by Petter Vilberg
councillor_spouse_martial.0002 = {
	hidden = yes

	trigger = {
		valid_spouse_councillor_trigger = yes
		spouse_martial_tier_3_trigger = yes
		NOT = { has_character_flag = had_event_councillor_spouse_martial_0002 }
		NOT = {
			has_character_modifier = councillor_spouse_army_organization_modifier
		}
	}

	weight_multiplier = {
		base = 1
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = martial
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_3
		}
	}

	immediate = {
		cp:councillor_spouse = {
			save_scope_as = active_councillor
		}
		add_character_flag = {
			flag = had_event_councillor_spouse_martial_0002
			years = 10
		}

		send_interface_message = {
			type = event_spouse_task_good
			title = councillor_spouse_martial.0002.message
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { martial < average_skill_level }
					}
					desc = task_martial_good_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { martial >= average_skill_level }
					}
					desc = task_martial_good_skilled_notification_tooltip
				}
			}
			left_icon = scope:councillor

			add_character_modifier = {
				modifier = councillor_spouse_army_organization_modifier
				years = 10
			}
		}
	}
}


#Army Morale boost
# by Petter Vilberg
councillor_spouse_martial.0003 = {
	hidden = yes

	trigger = {
		valid_spouse_councillor_trigger = yes
		spouse_martial_tier_2_trigger = yes
		NOT = { has_character_flag = had_event_councillor_spouse_martial_0003 }
		NOT = {
			has_character_modifier = councillor_spouse_chivalric_boost_modifier
		}
	}

	weight_multiplier = {
		base = 1
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = martial
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_2
		}
	}

	immediate = {
		cp:councillor_spouse = {
			save_scope_as = active_councillor
		}
		add_character_flag = {
			flag = had_event_councillor_spouse_martial_0003
			years = 10
		}

		send_interface_message = {
			type = event_spouse_task_good
			title = councillor_spouse_martial.0003.message
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { martial < average_skill_level }
					}
					desc = task_martial_good_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { martial >= average_skill_level }
					}
					desc = task_martial_good_skilled_notification_tooltip
				}
			}
			
			left_icon = scope:councillor

			add_character_modifier = {
				modifier = councillor_spouse_chivalric_boost_modifier
				years = 10
			}
		}
	}
}


#Gain Prestige
# by Petter Vilberg
councillor_spouse_martial.0004 = {
	hidden = yes

	trigger = {
		valid_spouse_councillor_trigger = yes
		NOT = { has_character_flag = had_event_councillor_spouse_martial_0004 }
	}

	weight_multiplier = {
		base = 1
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = martial
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_1
		}
	}

	immediate = {
		cp:councillor_spouse = {
			save_scope_as = active_councillor
		}
		add_character_flag = {
			flag = had_event_councillor_spouse_martial_0004
			years = 10
		}

		hidden_effect = {
			scope:councillor = {
				if = {
					limit = {
						spouse_martial_tier_3_trigger = yes
					}
					add_prestige = major_prestige_gain
				}
				else_if = {
					limit = {
						spouse_martial_tier_2_trigger = yes
					}
					add_prestige = medium_prestige_gain
				}
				else = {
					add_prestige = minor_prestige_gain
				}
			}
		}

		send_interface_message = {
			type = event_spouse_task_good
			title = councillor_spouse_martial.0004.message
			left_icon = scope:councillor
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { martial < average_skill_level }
					}
					desc = task_martial_good_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { martial >= average_skill_level }
					}
					desc = task_martial_good_skilled_notification_tooltip
				}
			}
			
			if = {
				limit = {
					spouse_martial_tier_3_trigger = yes
				}
				add_prestige = major_prestige_gain
			}
			else_if = {
				limit = {
					spouse_martial_tier_2_trigger = yes
				}
				add_prestige = medium_prestige_gain
			}
			else = {
				add_prestige = minor_prestige_gain
			}
		}
	}
}


#Reduce the cost of Mercenaries
# by Petter Vilberg

councillor_spouse_martial.0005 = {
	hidden = yes

	trigger = {
		valid_spouse_councillor_trigger = yes
		spouse_martial_tier_2_trigger = yes
		NOT = { has_character_flag = had_event_councillor_spouse_martial_0005 }
		NOT = {
			has_character_modifier = councillor_spouse_mercenary_cost_modifier
		}
	}

	weight_multiplier = {
		base = 1
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = martial
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_2
		}
	}

	immediate = {
		cp:councillor_spouse = {
			save_scope_as = active_councillor
		}
		add_character_flag = {
			flag = had_event_councillor_spouse_martial_0005
			years = 10
		}

		send_interface_message = {
			type = event_spouse_task_good
			title = councillor_spouse_martial.0005.message
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { martial < average_skill_level }
					}
					desc = task_martial_good_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { martial >= average_skill_level }
					}
					desc = task_martial_good_skilled_notification_tooltip
				}
			}
			
			left_icon = scope:councillor

			add_character_modifier = {
				modifier = councillor_spouse_mercenary_cost_modifier
				years = 10
			}
		}
	}
}


#Health Boost
# by Petter Vilberg
councillor_spouse_martial.0006 = {
	hidden = yes

	trigger = {
		valid_spouse_councillor_trigger = yes
		NOT = { has_character_flag = had_event_councillor_spouse_martial_0006 }
		NOT = {
			has_character_modifier = councillor_spouse_health_modifier
		}
	}

	weight_multiplier = {
		base = 1
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = martial
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_1
		}
	}

	immediate = {
		cp:councillor_spouse = {
			save_scope_as = active_councillor
		}
		add_character_flag = {
			flag = had_event_councillor_spouse_martial_0006
			years = 10
		}

		send_interface_message = {
			type = event_spouse_task_good
			title = councillor_spouse_martial.0006.message
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { martial < average_skill_level }
					}
					desc = task_martial_good_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { martial >= average_skill_level }
					}
					desc = task_martial_good_skilled_notification_tooltip
				}
			}
			left_icon = scope:councillor

			add_character_modifier = {
				modifier = councillor_spouse_health_modifier
				years = 5
			}
		}
	}
}


#Wounded character gains Health boost
# by Petter Vilberg
scripted_trigger councillor_spouse_martial_0007_wounded_character_trigger = {
	NOT = { this = scope:councillor }
	is_available_ai_adult = yes
	has_trait_rank = {
		trait = wounded
		rank >= 1
	}
	NOT = { has_character_modifier = councillor_spouse_health_modifier }
	#Spouse won't treat your Rival unless they are also your rival
	NOR = {
		has_relation_rival = scope:councillor
		AND = {
			has_relation_rival = root
			scope:councillor = {
				NOT = { has_relation_rival = root }
			}
		}
	}
}
councillor_spouse_martial.0007 = {
	hidden = yes

	trigger = {
		valid_spouse_councillor_trigger = yes

		NOT = { has_character_flag = had_event_councillor_spouse_martial_0007 }
		OR = {
			any_courtier = {
				councillor_spouse_martial_0007_wounded_character_trigger = yes
			}
			any_vassal = {
				can_be_commander_now_trigger = { ARMY_OWNER = root }
				councillor_spouse_martial_0007_wounded_character_trigger = yes
			}
		}
	}

	weight_multiplier = {
		base = 1
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = martial
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_1
		}
	}

	immediate = {
		cp:councillor_spouse = {
			save_scope_as = active_councillor
		}
		add_character_flag = {
			flag = had_event_councillor_spouse_martial_0007
			years = 5
		}

		every_courtier = {
			limit = {
				councillor_spouse_martial_0007_wounded_character_trigger = yes
			}
			add_to_list = wounded_characters
		}
		every_vassal = {
			limit = {
				can_be_commander_now_trigger = { ARMY_OWNER = root }
				councillor_spouse_martial_0007_wounded_character_trigger = yes
			}
			add_to_list = wounded_characters
		}

		random_in_list = {
			list = wounded_characters
			weight = {
				base = 1
				modifier = {
					add = 2
					is_of_major_interest_trigger = {
						CHARACTER = root
					}
				}
				modifier = {
					add = 1
					is_of_minor_interest_trigger = {
						CHARACTER = root
					}
				}
			}
			save_scope_as = wounded_character
			random_list = {
				100 = { }
				20 = {
					trigger = {
						mgr_can_seduce = yes
						possible_mutual_interest_trigger = {
							CHARACTER_1 = scope:councillor
							CHARACTER_2 = scope:wounded_character
						}
						can_set_relation_potential_lover_trigger = { CHARACTER = scope:councillor }
					}
					set_relation_potential_lover = scope:councillor
				}
				10 = {
					trigger = {
						mgr_can_seduce = yes
						possible_mutual_interest_trigger = {
							CHARACTER_1 = scope:councillor
							CHARACTER_2 = scope:wounded_character
						}
						can_set_relation_lover_trigger = { CHARACTER = scope:councillor }
					}
					set_relation_lover = scope:councillor
				}
				20 = {
					trigger = {
						OR = {
							can_set_relation_potential_friend_trigger = { CHARACTER = scope:councillor }
							can_set_relation_friend_trigger = { CHARACTER = scope:councillor }
						}
					}
					progress_towards_friend_effect = {
						CHARACTER = scope:councillor
						OPINION = no
					}
				}
				30 = {
					trigger = {
						NOT = {
							has_relation_friend = scope:councillor
						}
					}
					modifier = {
						add = 100
						has_relation_potential_friend = scope:councillor
					}
					set_relation_friend = scope:councillor
				}
			}
		}

		send_interface_message = {
			type = event_spouse_task_good
			title = councillor_spouse_martial.0007.message
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { martial < average_skill_level }
					}
					desc = task_martial_good_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { martial >= average_skill_level }
					}
					desc = task_martial_good_skilled_notification_tooltip
				}
			}
			
			right_icon = scope:councillor
			left_icon = scope:wounded_character

			scope:wounded_character = {
				add_character_modifier = {
					modifier = councillor_spouse_health_modifier
					years = 5
				}
			}
		}
	}
}


#Gain Dread
# by Petter Vilberg
councillor_spouse_martial.0008 = {
	hidden = yes

	trigger = {
		valid_spouse_councillor_trigger = yes
		spouse_martial_tier_2_trigger = yes
		NOT = { has_character_flag = had_event_councillor_spouse_martial_0008 }
		dread >= low_dread
	}

	weight_multiplier = {
		base = 1
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = martial
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_2
		}
	}

	immediate = {
		cp:councillor_spouse = {
			save_scope_as = active_councillor
		}
		add_character_flag = {
			flag = had_event_councillor_spouse_martial_0008
			years = 10
		}

		scope:councillor = {
			if = {
				limit = {
					spouse_martial_tier_3_trigger = yes
				}
				add_dread = major_dread_gain
			}
			else_if = {
				limit = {
					spouse_martial_tier_2_trigger = yes
				}
				add_dread = medium_dread_gain
			}
			else = {
				add_dread = minor_dread_gain
			}			
		}

		send_interface_message = {
			type = event_spouse_task_good
			title = councillor_spouse_martial.0008.message
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { martial < average_skill_level }
					}
					desc = task_martial_good_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { martial >= average_skill_level }
					}
					desc = task_martial_good_skilled_notification_tooltip
				}
			}
			left_icon = scope:councillor

			if = {
				limit = {
					spouse_martial_tier_3_trigger = yes
				}
				add_dread = major_dread_gain
			}
			else_if = {
				limit = {
					spouse_martial_tier_2_trigger = yes
				}
				add_dread = medium_dread_gain
			}
			else = {
				add_dread = minor_dread_gain
			}
		}
	}
}


#Increase a child's Prowess
# by Petter Vilberg
scripted_trigger councillor_spouse_martial_0009_child_trigger = {
	is_available_ai = yes
	is_healthy = yes
	age >= 7
	court_owner = root
	mother = scope:councillor	
}


councillor_spouse_martial.0009 = {
	hidden = yes

	trigger = {
		valid_spouse_councillor_trigger = yes
		NOT = { has_character_flag = had_event_councillor_spouse_martial_0009 }
		any_child = {
			councillor_spouse_martial_0009_child_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = martial
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_1
		}
	}

	immediate = {
		cp:councillor_spouse = {
			save_scope_as = active_councillor
		}
		add_character_flag = {
			flag = had_event_councillor_spouse_martial_0009
			years = 5
		}

		random_child = {
			limit = {
				councillor_spouse_martial_0009_child_trigger = yes
			}
			weight = {
				base = 1
				modifier = {
					add = 5
					can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
				}
				modifier = {
					add = 3
					this = root.player_heir
				}
				modifier = {
					add = 5
					has_trait_rank = {
						trait = education_martial
						rank >= 1
					}
				}
				modifier = {
					add = 5
					has_focus = education_martial
				}
			}
			save_scope_as = child
		}

		send_interface_message = {
			type = event_spouse_task_good
			title = councillor_spouse_martial.0009.message
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { martial < average_skill_level }
					}
					desc = task_martial_good_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { martial >= average_skill_level }
					}
					desc = task_martial_good_skilled_notification_tooltip
				}
			}
			right_icon = scope:councillor
			left_icon = scope:child

			scope:child = {
				if = {
					limit = {
						spouse_martial_tier_2_trigger = yes
					}
					add_prowess_skill = 2
				}
				else = {
					add_prowess_skill = 1
				}
			}
		}
	}
}




######################
#
#
######################


#Spouse holds a local tourney
# by Petter Vilberg

scripted_trigger councillor_spouse_martial_1001_eligible_child_trigger = {
	OR = {
		has_trait_rank = {
			trait = education_martial
			rank > 0
			rank < 4
		}
		has_focus = education_martial
	}
	age > 13
	age < 22
	can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root}
	number_of_commander_traits < commander_trait_limit
}

councillor_spouse_martial.1001 = {
	type = character_event
	title = councillor_spouse_martial.1001.t
	desc = councillor_spouse_martial.1001.desc
	theme = martial
	left_portrait = {
		character = scope:councillor
		animation = personality_honorable
	}
	right_portrait = {
		character = scope:child
		animation = personality_bold
	}

	trigger = {
		NOT = { has_character_flag = had_event_councillor_spouse_martial_1001 }
		valid_spouse_councillor_trigger = yes
		scope:councillor = {
			is_ai = yes
		}
		number_of_knights > 1
	}

	weight_multiplier = {
		base = 1
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = martial
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_1
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_event_councillor_spouse_martial_1001
			years = 5
		}
		every_knight = {
			add_to_list = list_of_all_knights
		}
		random_child = {
			limit = {
				councillor_spouse_martial_1001_eligible_child_trigger = yes
			}
			weight = {
				base = 1
				modifier = {
					add = 5
					this = root.player_heir
				}
			}
			save_scope_as = child
		}
	}

	option = {
		name = councillor_spouse_martial.1001.a
		every_in_list = {
			list = list_of_all_knights
			custom = councillor_spouse_martial.1001.commanders
			if = {
				limit = {
					spouse_martial_tier_3_trigger = yes
				}
				add_opinion = {
					target = root
					modifier = spouse_held_local_tourney_opinion
					years = 12
				}
			}
			else_if = {
				limit = {
					spouse_martial_tier_2_trigger = yes
				}
				add_opinion = {
					target = root
					modifier = spouse_held_local_tourney_opinion
					years = 10
				}
			}
			else = {
				add_opinion = {
					target = root
					modifier = spouse_held_local_tourney_opinion
					years = 8
				}
			}
		}
	}

	option = {
		name = councillor_spouse_martial.1001.b
		trigger = {
			exists = scope:child
			martial > scope:child.martial
		}
		scope:child = {
			if = {
				limit = {
					has_focus = education_martial
				}
				hidden_effect = {
					education_point_acquisition_effect = yes
					education_point_acquisition_effect = yes
				}
				custom_tooltip = councillor_spouse_martial.1001.b.education_tt
			}
			else_if = {
				limit = {
					has_trait = education_martial
					has_trait_rank = {
						trait = education_martial
						rank < 4
					}
				}
				change_trait_rank = {
					trait = education_martial
					rank = 1
				}
				give_random_commander_trait_effect = yes
			}
			else_if = {
				limit = {
					is_adult = yes
				}
				give_random_commander_trait_effect = yes
			}
			else = {
				add_prestige = minor_prestige_gain
			}
		}
	}
	
	option = {
		name = councillor_spouse_martial.1001.c
		if = {
			limit = {
				spouse_martial_tier_3_trigger = yes
			}
			add_prestige = major_prestige_gain
		}
		else_if = {
			limit = {
				spouse_martial_tier_1_trigger = yes
			}
			add_prestige = medium_prestige_gain
		}
		else = {
			add_prestige = minor_prestige_gain
		}
	}
}


#Should your Spouse emphasise your Prestige or Dreadfulness
# by Petter Vilberg
councillor_spouse_martial.1002 = {
	type = character_event
	title = councillor_spouse_martial.1002.t
	desc = councillor_spouse_martial.1002.desc
	theme = martial
	left_portrait = {
		character = scope:councillor
		animation = scheme
	}
	
	trigger = {
		valid_spouse_councillor_trigger = yes
		NOT = { has_character_flag = had_event_councillor_spouse_martial_1002 }
	}

	weight_multiplier = {
		base = 1
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = martial
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_1
		}
		modifier = {
			factor = 0.1
			dread < low_dread
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_event_councillor_spouse_martial_1002
			years = 10
		}
		hidden_effect = {
			scope:councillor = {
				add_dread = minor_dread_gain
				add_prestige = minor_prestige_gain
			}
		}
	}

	option = {
		name = councillor_spouse_martial.1002.a
		add_prestige = {
			value = medium_prestige_gain
			multiply = {
				value = 1
				if = {
					limit = {
						spouse_martial_tier_2_trigger = yes
					}
					add = 1
				}
				if = {
					limit = {
						spouse_martial_tier_3_trigger = yes
					}
					add = 1
				}
			}
		}
	}

	option = {
		name = councillor_spouse_martial.1002.b
		add_dread = {
			value = minor_dread_gain
			multiply = {
				value = 1
				if = {
					limit = {
						spouse_martial_tier_2_trigger = yes
					}
					add = 1
				}
				if = {
					limit = {
						spouse_martial_tier_3_trigger = yes
					}
					add = 1
				}
			}
		}
	}
	
	option = {
		name = councillor_spouse_martial.1002.c
		trigger = {
			has_trait = sadistic
		}
		trait = sadistic
		add_prestige = {
			value = medium_prestige_gain
			multiply = {
				value = 1
				if = {
					limit = {
						spouse_martial_tier_2_trigger = yes
					}
					add = 1
				}
				if = {
					limit = {
						spouse_martial_tier_3_trigger = yes
					}
					add = 1
				}
			}
		}
		add_dread = {
			value = minor_dread_gain
			multiply = {
				value = 1
				if = {
					limit = {
						spouse_martial_tier_2_trigger = yes
					}
					add = 1
				}
				if = {
					limit = {
						spouse_martial_tier_3_trigger = yes
					}
					add = 1
				}
			}
		}
		scope:councillor = {
			add_stress = medium_stress_gain
			add_opinion = {
				target = root
				modifier = cruelty_opinion
				opinion = -20
			}
		}
	}
}



#Spouse stops a war between vassals
# by Petter Vilberg

scripted_trigger councillor_spouse_martial_1003_defender_vassal = {
	is_ai = yes
	is_at_war_as_defender = yes
	save_temporary_scope_as = defender_vassal
	NOT = {
		this = root.cp:councillor_chancellor
	}
}

scripted_trigger councillor_spouse_martial_1003_attacker_vassal = {	
	is_ai = yes
	is_at_war_as_attacker = yes
	is_at_war_with = scope:defender_vassal
	NOT = {
		this = root.cp:councillor_chancellor
	}
}

councillor_spouse_martial.1003 = {
	type = character_event
	title = councillor_spouse_martial.1003.t
	desc = councillor_spouse_martial.1003.desc
	theme = martial
	left_portrait = {
		character = scope:councillor
		animation = disapproval
	}
	right_portrait = {
		character = scope:attacker_vassal
		animation = anger
	}
	lower_right_portrait = scope:defender_vassal
	
	trigger = {
		valid_spouse_councillor_trigger = yes
		spouse_martial_tier_2_trigger = yes
		is_at_war = no
		any_vassal = {
			councillor_spouse_martial_1003_defender_vassal = yes
		}
		any_vassal = {
			councillor_spouse_martial_1003_attacker_vassal = yes
		}
		
		scope:councillor = {
			diplomacy > mediocre_skill_rating
		}
	}

	weight_multiplier = {
		base = 1
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = martial
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_2
		}
	}

	immediate = {
		random_vassal = {
			limit = {
				councillor_spouse_martial_1003_defender_vassal = yes
				root = {
					any_vassal = {
						councillor_spouse_martial_1003_attacker_vassal = yes
					}
				}
			}
			save_scope_as = defender_vassal
		}
		random_vassal = {
			limit = {
				councillor_spouse_martial_1003_attacker_vassal = yes
			}
			save_scope_as = attacker_vassal
			random_character_war = {
				limit = {
					primary_defender = scope:defender_vassal
				}
				save_scope_as = war
			}
		}
		scope:councillor = {
			assign_quirk_effect = yes
		}
	}

	option = {
		name = councillor_spouse_martial.1003.a
		remove_short_term_gold = medium_gold_value
		scope:war = {
			end_war = white_peace
		}
		if = {
			limit = {
				scope:attacker_vassal = {
					has_relation_rival = scope:defender_vassal
				}
			}
			random = {
				chance = {
					value = scope:councillor.diplomacy
					multiply = 5
					max = 80
				}
				scope:attacker_vassal = {
					remove_relation_rival = scope:defender_vassal
				}
			}
		}
		else_if = {
			limit = {
				scope:attacker_vassal = {
					can_set_relation_friend_trigger = { CHARACTER = scope:defender_vassal }
				}
			}
			random = {
				chance = {
					value = scope:councillor.diplomacy
					multiply = 5
					max = 80
				}
				scope:attacker_vassal = {
					set_relation_friend = scope:defender_vassal
				}
			}
		}
		ai_chance = {
			base = 100
		}
	}

	option = {
		name = councillor_spouse_martial.1003.b
		custom_tooltip = councillor_spouse_martial.1003.b.tt
		ai_chance = {
			base = 10
		}
	}

	option = {
		name = councillor_spouse_martial.1003.c
		trigger = {
			spouse_martial_tier_3_trigger = yes
			always = no
		}
		exclusive = yes
		custom_tooltip = councillor_spouse_martial.1003.c.unlock_tt
		scope:war = {
			end_war = white_peace
		}
		if = {
			limit = {
				scope:attacker_vassal = {
					has_relation_rival = scope:defender_vassal
				}
			}
			random = {
				chance = {
					value = scope:councillor.diplomacy
					multiply = 5
					max = 80
				}
				scope:attacker_vassal = {
					remove_relation_rival = scope:defender_vassal
				}
			}
		}
		else_if = {
			limit = {
				scope:attacker_vassal = {
					NOT = { has_relation_friend = scope:defender_vassal }
				}
			}
			random = {
				chance = {
					value = scope:councillor.diplomacy
					multiply = 5
					max = 80
				}
				scope:attacker_vassal = {
					set_relation_friend = scope:defender_vassal
				}
			}
		}
		ai_chance = {
			base = 100
		}
	}

	option = {
		name = councillor_spouse_martial.1003.b
		custom_tooltip = councillor_spouse_martial.1003.b.tt
		ai_chance = {
			base = 10
		}
	}
}


#Spouse raises troops
# by Petter Vilberg
councillor_spouse_martial.1004 = {
	type = character_event
	title = councillor_spouse_martial.1004.t
	desc = councillor_spouse_martial.1004.desc	
	theme = martial
	override_background = {
		event_background = courtyard
	}
	left_portrait = {
		character = scope:councillor
		animation = personality_honorable
	}
	
	trigger = {
		valid_spouse_councillor_trigger = yes
		spouse_martial_tier_2_trigger = yes
		NOT = { has_character_flag = had_event_councillor_spouse_martial_1004 }
		NOT = {
			has_character_modifier = spouse_martial_personal_guard_modifier
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 0.5
			is_at_war = yes
		}
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = martial
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_2
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_event_councillor_spouse_martial_1004
			years = 10
		}
		hidden_effect = {
			scope:councillor = {
				add_prowess_skill = 1
			}
		}
	}

	#Event troops
	option = {
		name = councillor_spouse_martial.1004.a
		if = {
			limit = {
				is_at_war = yes
			}
			spawn_army = {
				name = event_troop_default_name
				levies = scope:councillor.spouse_martial_event_troop_size
				location = capital_province
			}
		}
		else = {
			add_character_modifier = {
				modifier = spouse_martial_increased_levy_modifier
				years = 10
			}
		}
	}

	#Gain Prowess
	option = {
		name = councillor_spouse_martial.1004.b
		add_character_modifier = {
			modifier = spouse_martial_personal_guard_modifier
			years = spouse_martial_personal_guard_duration
		}
	}
}



#Spouse Cows a vassal
# by Petter Vilberg

scripted_trigger councillor_spouse_martial_1005_vassal_trigger = {
	is_available_ai_adult = yes
	has_dread_level_towards = {
		target = root
		level = 0
	}
	NOR = {
		this = scope:councillor
		has_relation_friend = scope:councillor
		has_relation_lover = scope:councillor
		has_relation_lover = root
		has_relation_friend = root
	}
	NOT = {
		has_opinion_modifier = {
			target = root
			modifier = spouse_martial_display_of_force_opinion
		}
	}
}

councillor_spouse_martial.1005 = {
	type = character_event
	title = councillor_spouse_martial.1005.t
	desc = councillor_spouse_martial.1005.desc
	theme = martial
	left_portrait = {
		character = scope:councillor
		animation = scheme
	}
	right_portrait = {
		character = scope:vassal
		animation = shock
	}
	
	trigger = {
		valid_spouse_councillor_trigger = yes
		spouse_martial_tier_2_trigger = yes
		NOT = { has_character_flag = had_event_councillor_spouse_martial_1005 }
		any_vassal = {
			councillor_spouse_martial_1005_vassal_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = martial
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_2
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_event_councillor_spouse_martial_1005
			years = 10
		}
		random_vassal = {
			limit = {
				councillor_spouse_martial_1005_vassal_trigger = yes
			}
			save_scope_as = vassal
		}
		capital_province = {
			barony = {
				save_scope_as = capital
			}
		}
	}

	option = {
		name = councillor_spouse_martial.1005.a
		scope:vassal = {
			add_opinion = {
				target = root
				modifier = spouse_martial_display_of_force_opinion
				years = councillor_spouse_martial_1005_a_value
			}
			add_character_modifier = {
				modifier = spouse_martial_cowed_vassal_modifier
				years = 10
			}
		}
		custom_tooltip = councillor_spouse_martial.1005.a.tt
	}

	option = {
		name = councillor_spouse_martial.1005.b
		add_prestige = medium_prestige_gain
	}
}