namespace = mpo_contract_events

#############################
# Migration Contract Events 
#############################
### Disagreeable Herders
# Start
mpo_contract_events.0001 = {
	type = character_event
	hidden = yes
	
	trigger = {
		mpo_settlement_issue_trigger = { NUMBER = 1 }
	}

	immediate = {
		mpo_settlement_issue_own_lands_effect = { 
			NUMBER = 1 
			TIER = 1
		}
	}
}

# Reset
mpo_contract_events.0003 = {
	type = character_event
	hidden = yes
	
	immediate = {
		mpo_settlement_issue_reset_effect = {
			NUMBER = 1
			ID = 0001
		}
	}
}

# Event
mpo_contract_events.0005 = {
	type = character_event
	title = mpo_contract_events.0005.t
	desc = mpo_contract_events.0005.desc
    theme = nomads
	left_portrait = {
		character = root
		animation = disapproval
	}
	right_portrait = {
		character = scope:herder_character
		animation = debating
	}

	trigger = {
		any_character_active_contract = {
			has_task_contract_type = nomadic_migration_contract_1
		}
	}

	immediate = {
		scope:task_contract.task_contract_location = {
			save_scope_as = task_location
		}
		create_character = {
			template = herder_character
			faith = scope:task_contract.task_contract_location.faith
			culture = scope:task_contract.task_contract_location.culture
			location = scope:task_contract.task_contract_location
			save_scope_as = herder_character
			after_creation = {
				remove_character_flag = peasant_outfit
			}
		}
	}

	option = {
		name = mpo_contract_events.0005.a
		
		duel = {
			skills = { diplomacy martial }
			value = 15
			50 = {
				desc = mpo_contract_events.0005.a.impressed
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				send_interface_toast = {
					title = mpo_contract_events.0005.a.impressed
					domicile = {
						change_herd = minor_herd_value_static
					}
					scope:task_contract.task_contract_location.county = {
						change_county_control = 25
					}
				}
			}
			50 = {
				desc = mpo_contract_events.0005.a.unimpressed
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				send_interface_toast = {
					title = mpo_contract_events.0005.a.unimpressed
					scope:task_contract.task_contract_location.county = {
						change_county_fertility = tiny_county_fertility_level_loss
					}
				}
			}
		}

		ai_chance = {
			base = 0
		}
	}

	option = {
		name = mpo_contract_events.0005.b
		scope:task_contract.task_contract_location.county = {
			change_county_fertility = tiny_county_fertility_level_gain
		}
		scope:task_contract.task_contract_location.county = {
			change_county_control = 25
		}
		remove_short_term_gold = tiny_gold_value

		ai_chance = {
			base = 0
		}
	}

	option = {
		name = mpo_contract_events.0005.c
		scope:task_contract.task_contract_location.county = {
			change_county_control = 25
		}

		ai_chance = {
			base = 1
		}
	}

	after = {
		settlement_issue_after_completing_effect = yes
		scope:herder_character = {
			silent_disappearance_ai_effect = yes
		}
	}
}

### The Wild Herd
# Start
mpo_contract_events.0011 = {
	type = character_event
	hidden = yes
	
	trigger = {
		mpo_settlement_issue_trigger = { NUMBER = 2 }
	}

	immediate = {
		mpo_settlement_issue_own_lands_effect = { 
			NUMBER = 2
			TIER = 1
		}
	}
}

# Reset
mpo_contract_events.0013 = {
	type = character_event
	hidden = yes
	
	immediate = {
		mpo_settlement_issue_reset_effect = {
			NUMBER = 2
			ID = 0011
		}
	}
}

# Event
mpo_contract_events.0015 = {
	type = character_event
	title = mpo_contract_events.0015.t
	desc = mpo_contract_events.0015.desc
    theme = nomads
    override_background = { reference = wilderness }
	left_portrait = {
		character = root
		animation = survey
	}

	trigger = {
		any_character_active_contract = {
			has_task_contract_type = nomadic_migration_contract_2
		}
	}

	option = {
		name = mpo_contract_events.0015.a
		duel = {
			skill = martial
			value = 15
			50 = {
				desc = mpo_contract_events.0015.a.successful
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				send_interface_toast = {
					title = mpo_contract_events.0015.a.successful
					domicile = {
						change_herd = minor_herd_value_static
					}
				}
			}
			50 = {
				desc = mpo_contract_events.0015.a.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				send_interface_toast = {
					title = mpo_contract_events.0015.a.failure
					domicile = {
						change_herd = miniscule_herd_value_static
					}
				}
			}
		}

		ai_chance = {
			base = 0
		}
	}

	option = {
		name = mpo_contract_events.0015.b
		add_character_modifier = {
			modifier = mpo_si_slaughtered_for_a_feast
			years = 3
		}

		ai_chance = {
			base = 0
		}
	}

	option = {
		name = mpo_contract_events.0015.c
		add_gold = minor_gold_value

		ai_chance = {
			base = 1
		}
	}

	after = { 
		settlement_issue_after_completing_effect = yes 
		scope:task_contract.task_contract_location.county = {
			change_county_control = 25
		}
	}
}

### Contentious Grazelands
# Start
mpo_contract_events.0021 = {
	type = character_event
	hidden = yes
	
	trigger = {
		any_knight = {
			count >= 2
			is_landed = no
		}
		any_held_county = {
			is_landless_type_title = no
			exists = title_province
			county_control < 90
			NOT = { has_county_modifier = ongoing_settlement_contract }
		}
		NOT = {
			any_task_contract = {
				has_task_contract_type = nomadic_migration_contract_3
			}
		}
	}

	immediate = {
		mpo_settlement_issue_own_lands_effect = { 
			NUMBER = 3
			TIER = 1
		}
	}
}

# Reset
mpo_contract_events.0023 = {
	type = character_event
	hidden = yes
	
	immediate = {
		mpo_settlement_issue_reset_effect = {
			NUMBER = 3
			ID = 0021
		}
	}
}

# Event
mpo_contract_events.0025 = {
	type = character_event
	title = mpo_contract_events.0025.t
	desc = mpo_contract_events.0025.desc
    theme = nomads
	left_portrait = {
		character = root
		animation = boredom
	}

	right_portrait = {
		character = scope:task_contract.task_contract_employer
		animation = debating
	}

	lower_left_portrait = scope:knight_2

	trigger = {
		any_character_active_contract = {
			has_task_contract_type = nomadic_migration_contract_3
		}
	}

	immediate = {
		random_knight = {
			limit = {
				NOT = { this = scope:task_contract.task_contract_employer }
				is_landed = no
				is_ai = yes
			}
			save_scope_as = knight_2
		}
	}

	option = {
		name = mpo_contract_events.0025.a
		scope:task_contract.task_contract_location.county = { change_county_control = 25 }
		scope:task_contract.task_contract_employer = {
			add_opinion = {
				opinion = 15
				modifier = friendliness_opinion
				target = root
			}
		}
		scope:knight_2 = {
			add_opinion = {
				opinion = -15
				modifier = disappointed_opinion
				target = root
			}
		}

		ai_chance = {
			base = 1
		}
	}

	option = {
		name = mpo_contract_events.0025.b
		scope:task_contract.task_contract_location.county = { change_county_control = 25 }
		scope:knight_2 = {
			add_opinion = {
				opinion = 15
				modifier = friendliness_opinion
				target = root
			}
		}
		scope:task_contract.task_contract_employer = {
			add_opinion = {
				opinion = -15
				modifier = disappointed_opinion
				target = root
			}
		}

		ai_chance = {
			base = 0
		}
	}

	option = {
		name = mpo_contract_events.0025.c
		domicile = { change_herd = settlement_issue_herd_reward }

		ai_chance = {
			base = 0
		}
	}

	after = { settlement_issue_after_completing_effect = yes }
}

### A Lack of Tools
# Start
mpo_contract_events.0031 = {
	type = character_event
	hidden = yes
	
	trigger = {
		mpo_settlement_issue_trigger = { NUMBER = 4 }
	}

	immediate = {
		mpo_settlement_issue_own_lands_effect = { 
			NUMBER = 4
			TIER = 1
		}
	}
}

# Reset
mpo_contract_events.0033 = {
	type = character_event
	hidden = yes
	
	immediate = {
		mpo_settlement_issue_reset_effect = {
			NUMBER = 4
			ID = 0031
		}
	}
}

scripted_effect mpo_contract_event_35_remove_modifier_effect = {
	if = {
		limit = {
			has_character_modifier = mpo_si_lacking_tools_3
		}
		remove_character_modifier = mpo_si_lacking_tools_3
	}
	else_if = {
		limit = {
			has_character_modifier = mpo_si_lacking_tools_2
		}
		remove_character_modifier = mpo_si_lacking_tools_2
	}
	else_if = {
		limit = {
			has_character_modifier = mpo_si_lacking_tools
		}
		remove_character_modifier = mpo_si_lacking_tools
	}
}

# Event
mpo_contract_events.0035 = {
	type = character_event
	title = mpo_contract_events.0035.t
	desc = mpo_contract_events.0035.desc
    theme = nomads
	left_portrait = {
		character = root
		animation = thinking
	}

	trigger = {
		any_character_active_contract = {
			has_task_contract_type = nomadic_migration_contract_4
		}
	}

	option = {
		name = mpo_contract_events.0035.a
		trigger = {
			domicile ?= {
				has_domicile_building_or_higher = trade_yurt_01
			}
		}
		reason = trade_yurt

		add_prestige = minor_prestige_gain
		scope:task_contract.task_contract_location.county = {
			change_county_control = 25
		}

		mpo_contract_event_35_remove_modifier_effect = yes

		ai_chance = {
			base = 5
		}
	}

	option = {
		name = mpo_contract_events.0035.b
		trigger = {
			domicile ?= {
				NOT = { has_domicile_building_or_higher = trade_yurt_01 }
			}
		}
		show_as_unavailable = {
			always = yes
		}

		remove_short_term_gold = minor_gold_value

		scope:task_contract.task_contract_location.county = {
			change_county_control = 25
		}

		mpo_contract_event_35_remove_modifier_effect = yes

		ai_chance = {
			base = 0
		}
	}

	option = {
		name = mpo_contract_events.0035.c
		trigger = {
			domicile ?= {
				NOT = { has_domicile_building_or_higher = trade_yurt_01 }
			}
		}
		show_as_unavailable = {
			always = yes
		}

		add_prestige = medium_prestige_loss
		scope:task_contract.task_contract_location.county = {
			change_county_control = 25
		}

		mpo_contract_event_35_remove_modifier_effect = yes

		ai_chance = {
			base = 1
		}
	}

	option = {
		name = mpo_contract_events.0035.d
		trigger = {
			domicile ?= {
				NOT = { has_domicile_building_or_higher = trade_yurt_01 }
			}
		}
		show_as_unavailable = {
			always = yes
		}

		if = {
			limit = {
				has_character_modifier = mpo_si_lacking_tools_3
			}
			add_character_modifier = {
				modifier = mpo_si_lacking_tools_3
				years = 30
			}
			add_prestige = minor_prestige_loss
		}
		else_if = {
			limit = {
				has_character_modifier = mpo_si_lacking_tools_2
			}
			hidden_effect = { remove_character_modifier = mpo_si_lacking_tools_2 }
			add_character_modifier = {
				modifier = mpo_si_lacking_tools_3
				years = 20
			}
		}
		else_if = {
			limit = {
				has_character_modifier = mpo_si_lacking_tools
			}
			hidden_effect = { remove_character_modifier = mpo_si_lacking_tools }
			add_character_modifier = {
				modifier = mpo_si_lacking_tools_2
				years = 20
			}
		}
		else = {
			add_character_modifier = {
				modifier = mpo_si_lacking_tools
				years = 20
			}
		}
	}

	after = { 
		settlement_issue_after_completing_effect = yes 
	}
}

### Fragmentation of the Tribe
# Start
mpo_contract_events.0041 = {
	type = character_event
	hidden = yes
	
	trigger = {
		domain_size > 1
		any_knight = {
			count >= 1
		}
		any_held_county = {
			is_landless_type_title = no
			exists = title_province
			county_control < 90
			NOR = { 
				this.title_province = root.capital_province
				has_county_modifier = ongoing_settlement_contract 
			}
		}
		NOT = {
			any_task_contract = {
				has_task_contract_type = nomadic_migration_contract_5
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			factor = 5
			domain_limit_available < 0
		}
	}

	immediate = {
		if = {
			limit = {
				NOT = { exists = scope:contract_province }
			}
			random_held_county = {
				limit = {
				is_landless_type_title = no
				exists = title_province
					county_control < 90
					NOR = { 
						this.title_province = root.capital_province
						has_county_modifier = ongoing_settlement_contract 
					}
				}
				title_province = { save_scope_as = contract_province }
			}
		}

		if = {
			limit = {
				NOT = { exists = scope:new_employer }
			}
			random_knight = {
				limit = { 
					is_landed = no 
					is_ai = yes
				}
				alternative_limit = { is_ai = yes }
				save_scope_as = new_employer
			}
		}

		create_task_contract = {
			task_contract_type = nomadic_migration_contract_5
			task_contract_tier = 1
			location = scope:contract_province
			task_contract_employer = scope:new_employer
		}
	}
}

# Reset
mpo_contract_events.0043 = {
	type = character_event
	hidden = yes
	
	immediate = {
		mpo_settlement_issue_reset_effect = {
			NUMBER = 5
			ID = 0041
		}
	}
}

# Event
mpo_contract_events.0045 = {
	type = character_event
	title = mpo_contract_events.0045.t
	desc = mpo_contract_events.0045.desc
    theme = nomads
	left_portrait = {
		character = root
		animation = thinking
	}

	right_portrait = {
		character = scope:new_chieftain
		animation = debating
	}

	trigger = {
		any_character_active_contract = {
			has_task_contract_type = nomadic_migration_contract_5
		}
	}

	immediate = {
		create_character = {
			template = nomadic_chieftain_character
			gender_female_chance = root_soldier_female_chance
			employer = root
			save_scope_as = new_chieftain
		}
	}

	option = {
		name = mpo_contract_events.0045.a

		duel = {
			skill = diplomacy
			target = scope:new_chieftain
			50 = {
				desc = mpo_contract_events.0045.a.successful
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				send_interface_toast = {
					title = mpo_contract_events.0045.a.successful
					add_prestige = medium_prestige_gain
					scope:task_contract.task_contract_location.county = {
						change_county_control = 25
					}
				}
			}
			50 = {
				desc = mpo_contract_events.0045.a.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				send_interface_toast = {
					title = mpo_contract_events.0045.a.failure
					scope:task_contract.task_contract_location.county = {
						change_county_control = -25
					}
				}
			}
		}

		ai_chance = {
			base = 1
		}
	}

	option = {
		name = mpo_contract_events.0045.b

		create_title_and_vassal_change = {
			type = granted
			save_scope_as = change
			add_claim_on_loss = no
		}
		scope:task_contract.task_contract_location.county = {
			change_title_holder = {
				holder = scope:new_chieftain
				change = scope:change
			}
		}

		resolve_title_and_vassal_change = scope:change

		scope:new_chieftain = {
			add_opinion = {
				modifier = obedience_opinion
				target = root
				years = 15
			}
		}

		scope:task_contract.task_contract_location.county = {
			change_county_control = 100
			hidden_effect = { set_county_culture = scope:new_chieftain.culture }
		}

		domicile = {
			change_herd = minor_herd_value_static
		}

		add_character_modifier = {
			modifier = mpo_si_accepting_cultures
			years = 10
		}

		custom_tooltip = mpo_contract_events.0045.b.tt
		hidden_effect = {
			if = {
				limit = {
					scope:new_chieftain = {
						is_landed = yes
						can_diverge_excluding_cost = yes
					}
				}
				scope:new_chieftain = {
					create_divergent_culture_with_side_effects_excluding_cost = yes
				}
				scope:task_contract.task_contract_location.county = { 
					set_county_culture = scope:new_chieftain.culture 
				}
			}
		}

		ai_chance = {
			base = 0 # Too many irritating small divergences
		}
	}

	option = {
		name = mpo_contract_events.0045.c

		remove_short_term_gold = minor_gold_value
		scope:task_contract.task_contract_location.county = {
			change_county_control = 25
		}

		ai_chance = {
			base = 1
		}
	}

	option = {
		name = mpo_contract_events.0045.d

		scope:task_contract.task_contract_location.county = {
			change_county_control = -10
		}

		ai_chance = {
			base = 0
		}
	}

	after = { 
		settlement_issue_after_completing_effect = yes
		scope:new_chieftain = {
			if = {
				limit = {
					is_ruler = no
				}
				silent_disappearance_ai_effect = yes
			}
		}
	}
}

### Poisonous Lands
# Start
mpo_contract_events.0051 = {
	type = character_event
	hidden = yes
	
	trigger = {
		mpo_settlement_issue_trigger = { NUMBER = 6 }
	}

	immediate = {
		mpo_settlement_issue_own_lands_effect = {
			NUMBER = 6
			TIER = 1
		}
	}
}

# Reset
mpo_contract_events.0053 = {
	type = character_event
	hidden = yes
	
	immediate = {
		mpo_settlement_issue_reset_effect = {
			NUMBER = 6
			ID = 0051
		}
	}
}

# Event
mpo_contract_events.0055 = {
	type = character_event
	title = mpo_contract_events.0055.t
	desc = mpo_contract_events.0055.desc
    theme = nomads
    override_background = { reference = wilderness }
    left_portrait = {
    	character = root
    	animation = survey
    }

	trigger = {
		any_character_active_contract = {
			has_task_contract_type = nomadic_migration_contract_6
		}
	}

	option = {
		name = mpo_contract_events.0055.a

		duel = {
			skill = learning
			value = 8
			50 = {
				desc = mpo_contract_events.0055.a.successful
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2.5
					min = -49
				}
				send_interface_toast = {
					title = mpo_contract_events.0055.a.successful
					add_prestige = minor_prestige_gain
					scope:task_contract.task_contract_location.county = {
						change_county_control = 25
					}
				}
			}
			50 = {
				desc = mpo_contract_events.0055.a.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -2.5
					min = -49
				}
				send_interface_toast = {
					title = mpo_contract_events.0055.a.failure
					domicile ?= {
						change_herd = {
							subtract = medium_herd_value_static
						}
					}
				}
			}
		}

		ai_chance = {
			base = 0
		}
	}

	option = {
		name = mpo_contract_events.0055.b

		remove_short_term_gold = minor_gold_value

		scope:task_contract.task_contract_location.county = {
			change_county_control = 25
		}

		ai_chance = {
			base = 0
		}
	}

	option = {
		name = mpo_contract_events.0055.c

		domicile ?= {
			change_herd = {
				subtract = minor_herd_value_static
			}
		}

		scope:task_contract.task_contract_location.county = {
			change_county_control = 25
		}

		add_character_modifier = {
			modifier = mpo_si_slaughtered_animals
		}

		ai_chance = {
			base = 1
		}
	}

	after = { 
		settlement_issue_after_completing_effect = yes
	}
}

### Troublesome Neighbors
# Start
mpo_contract_events.0061 = {
	type = character_event
	hidden = yes
	
	trigger = {
		any_knight = {
			count >= 1
		}
		any_held_county = {
			is_landless_type_title = no
			exists = title_province
			county_control < 90
			NOT = { has_county_modifier = ongoing_settlement_contract }
			any_neighboring_county = {
				NOT = { holder.top_liege ?= root.top_liege }
			}
		}
		NOT = {
			any_task_contract = {
				has_task_contract_type = nomadic_migration_contract_7
			}
		}
	}

	immediate = {
		mpo_settlement_issue_own_lands_effect = {
			NUMBER = 7
			TIER = 1
		}
	}
}

# Reset
mpo_contract_events.0063 = {
	type = character_event
	hidden = yes
	
	immediate = {
		mpo_settlement_issue_reset_effect = {
			NUMBER = 7
			ID = 0061
		}
	}
}

# Event
mpo_contract_events.0065 = {
	type = character_event
	title = mpo_contract_events.0065.t
	desc = mpo_contract_events.0065.desc
    theme = nomads
    override_background = { reference = wilderness }
	left_portrait = {
		character = root
		animation = disapproval
	}
	right_portrait = {
		character = scope:neighbor_leader
		animation = anger
	}

	trigger = {
		any_character_active_contract = {
			has_task_contract_type = nomadic_migration_contract_7
		}
	}

	immediate = {
		scope:task_contract.task_contract_location.county = {
			random_neighboring_county = {
				limit = {
					NOT = { holder.top_liege = root.top_liege }				
				}
				holder = { save_scope_as = neighbor_leader }
			}
		}
	}

	option = {
		name = mpo_contract_events.0065.a

		duel = {
			skills = { diplomacy martial }
			target = scope:neighbor_leader
			50 = {
				desc = mpo_contract_events.0065.a.successful
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				send_interface_toast = {
					title = mpo_contract_events.0065.a.successful
					domicile ?= {
						change_herd = minor_herd_value_static
					}
				}
			}
			50 = {
				desc = mpo_contract_events.0065.a.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				send_interface_toast = {
					title = mpo_contract_events.0065.a.failure
					scope:neighbor_leader = {
						add_opinion = {
							opinion = -15
							modifier = disgusted_opinion
							target = root
						}
					}
				}
			}
		}

		ai_chance = {
			base = 0
		}
	}

	option = {
		name = mpo_contract_events.0065.b

		domicile ?= {
			change_herd = {
				integer_range = {
					min = minor_herd_value_static
					max = medium_herd_value_static
				}
			}
		}

		scope:neighbor_leader = {
			add_opinion = {
				modifier = upset_opinion
				target = root
				opinion = -20
			}
		}

		ai_chance = {
			base = 0
		}
	}

	option = {
		name = mpo_contract_events.0065.c

		ai_chance = {
			base = 1
		}
	}

	after = { 
		settlement_issue_after_completing_effect = yes
		scope:task_contract.task_contract_location.county = {
			change_county_control = 25
		}
	}
}

### The Leftovers
# Start
mpo_contract_events.0071 = {
	type = character_event
	hidden = yes
	
	trigger = {
		mpo_settlement_issue_trigger = { NUMBER = 8 }
	}

	immediate = {
		mpo_settlement_issue_own_lands_effect = {
			NUMBER = 8
			TIER = 1
		}
	}
}

# Reset
mpo_contract_events.0073 = {
	type = character_event
	hidden = yes
	
	immediate = {
		mpo_settlement_issue_reset_effect = {
			NUMBER = 8
			ID = 0071
		}
	}
}

# Event
mpo_contract_events.0075 = {
	type = character_event
	title = mpo_contract_events.0075.t
	desc = mpo_contract_events.0075.desc
	override_background = { reference = wilderness }
    theme = nomads
    left_portrait = {
    	character = root
    	animation = horse_surveying
  		camera = camera_event_horse_right_forward
    }

	trigger = {
		any_character_active_contract = {
			has_task_contract_type = nomadic_migration_contract_8
		}
	}

	immediate = {
		random_realm_province = {
			limit = {
				county = scope:task_contract.task_contract_location.county	
			}
			save_scope_as = barony_location
		}
	}

	option = {
		name = mpo_contract_events.0075.a

		domicile ?= {
			change_herd = minor_herd_value_static
		}

		ai_chance = {
			base = 1
		}
	}

	option = {
		name = mpo_contract_events.0075.b

		scope:task_contract.task_contract_location.county = {
			change_county_fertility = tiny_county_fertility_level_gain
		}

		ai_chance = {
			base = 0
		}
	}

	option = {
		name = mpo_contract_events.0075.c

		add_gold = minor_gold_value

		ai_chance = {
			base = 0
		}
	}

	after = { 
		settlement_issue_after_completing_effect = yes
		scope:task_contract.task_contract_location.county = {
			change_county_control = 25
		}
	}
}

### Drawing Lines
# Start
mpo_contract_events.0081 = {
	type = character_event
	hidden = yes
	
	trigger = {
		any_knight = {
			count >= 1
		}
		any_held_county = {
			is_landless_type_title = no
			exists = title_province
			county_control < 90
			NOT = { has_county_modifier = ongoing_settlement_contract }
			any_neighboring_county = {
				holder = root
			}
		}
		NOT = {
			any_task_contract = {
				has_task_contract_type = nomadic_migration_contract_9
			}
		}
	}

	immediate = {
		mpo_settlement_issue_own_lands_effect = {
			NUMBER = 9
			TIER = 1
		}
	}
}

# Reset
mpo_contract_events.0083 = {
	type = character_event
	hidden = yes
	
	immediate = {
		mpo_settlement_issue_reset_effect = {
			NUMBER = 9
			ID = 0081
		}
	}
}

# Event
mpo_contract_events.0085 = {
	type = character_event
	title = mpo_contract_events.0085.t
	desc = mpo_contract_events.0085.desc
    theme = nomads
    left_portrait = {
    	character = root
    	animation = thinking
    }
    right_portrait = {
    	character = scope:task_contract.task_contract_employer
    	animation = debating
    }

	trigger = {
		any_character_active_contract = {
			has_task_contract_type = nomadic_migration_contract_9
		}
	}

	immediate = {
		scope:task_contract.task_contract_location.county = {
			random_neighboring_county = {
				limit = {
					holder = root
				}
				save_scope_as = other_county
			}
		}
	}

	option = {
		name = mpo_contract_events.0085.a

		scope:task_contract.task_contract_location.county = {
			change_county_fertility = tiny_county_fertility_level_gain
			change_county_control = 25
		}
		scope:other_county = {
			add_county_modifier = {
				modifier = mpo_si_spurned_tribe
				years = 10
			}
		}

		ai_chance = {
			base = 1
		}
	}

	option = {
		name = mpo_contract_events.0085.b

		scope:other_county = {
			change_county_fertility = tiny_county_fertility_level_gain
			change_county_control = 25
		}
		scope:task_contract.task_contract_location.county = {
			add_county_modifier = {
				modifier = mpo_si_spurned_tribe
				years = 10
			}
		}

		ai_chance = {
			base = 0
		}
	}

	after = { 
		settlement_issue_after_completing_effect = yes
	}
}

### The Old Tribe
# Start
mpo_contract_events.0091 = {
	type = character_event
	hidden = yes
	
	trigger = {
		any_knight = {
			count >= 1
		}
		any_held_county = {
			is_landless_type_title = no
			exists = title_province
			county_control < 90
			has_variable = migration_previous_culture
			NOR = { 
				var:migration_previous_culture ?= root.culture
				has_county_modifier = ongoing_settlement_contract 
			}
			var:migration_previous_culture = {
				any_tradition = {
					save_temporary_scope_as = culture_trigger_scope
					OR = {
						NOT = { has_tradition_category = regional }
						NOT = {
							root.culture = {
								any_tradition = {
									this = scope:culture_trigger_scope
								}
							}
						}
					}
				}
			}
		}
		NOT = {
			any_task_contract = {
				has_task_contract_type = nomadic_migration_contract_10
			}
		}
	}

	immediate = {
		if = {
			limit = {
				NOT = { exists = scope:contract_province }
			}
			random_held_county = {
				limit = {
					is_landless_type_title = no
					exists = title_province
					county_control < 90
					has_variable = migration_previous_culture
					NOT = { has_county_modifier = ongoing_settlement_contract }
				}
				title_province = { save_scope_as = contract_province }
			}
		}

		if = {
			limit = {
				NOT = { exists = scope:new_employer }
			}
			random_knight = {
				limit = { 
					is_landed = no 
					is_ai = yes
				}
				alternative_limit = { is_ai = yes }
				save_scope_as = new_employer
			}
		}

		create_task_contract = {
			task_contract_type = nomadic_migration_contract_10
			task_contract_tier = 1
			location = scope:contract_province
			task_contract_employer = scope:new_employer
		}
	}
}

# Reset
mpo_contract_events.0093 = {
	type = character_event
	hidden = yes
	
	immediate = {
		mpo_settlement_issue_reset_effect = {
			NUMBER = 10
			ID = 0091
		}
	}
}

# Event
mpo_contract_events.0095 = {
	type = character_event
	title = mpo_contract_events.0095.t
	desc = mpo_contract_events.0095.desc
    theme = nomads
    left_portrait = {
    	character = root
    	animation = thinking
    }
    right_portrait = {
    	character = scope:new_chieftain
    	animation = debating
    }

	trigger = {
		any_character_active_contract = {
			has_task_contract_type = nomadic_migration_contract_10
		}
	}

	immediate = {
		scope:task_contract.task_contract_location.county.var:migration_previous_culture = {
			save_scope_as = previous_culture
		}
		create_character = {
			template = nomadic_chieftain_character
			gender_female_chance = root_soldier_female_chance
			location = scope:task_contract.task_contract_location
			culture = scope:previous_culture
			save_scope_as = new_chieftain
		}
	}

	option = {
		name = mpo_contract_events.0095.a

		scope:previous_culture = {
			change_cultural_acceptance = {
				target = root.culture
				value = 5
				desc = cultural_acceptance_gain_event
			}
			every_tradition = {
				limit = {
					save_temporary_scope_as = culture_trigger_scope
					root = { can_embrace_tradition = prev }
					NOT = { 
						root.culture = {
							any_tradition = {
								this = scope:culture_trigger_scope
							}
						}
					}
				}
				inspired_by_tradition_effect = { CHARACTER = root }
			}
		}

		scope:task_contract.task_contract_location.county = {
			add_county_modifier = {
				modifier = mpo_si_old_tribe
				years = 10
			}
		}

		add_courtier = scope:new_chieftain
		scope:new_chieftain = {
			add_opinion = {
				modifier = obedience_opinion
				target = root
				years = 10
			}
		}

		ai_chance = {
			base = 0
		}
	}

	option = {
		name = mpo_contract_events.0095.b

		add_dread = minor_dread_gain

		ai_chance = {
			base = 1
		}
	}

	after = { 
		settlement_issue_after_completing_effect = yes
		scope:task_contract.task_contract_location.county = {
			change_county_control = 25
		}
		domicile ?= { 
			change_herd = {
				value = minor_herd_value_static 
				divide = 2
			}
		}
		scope:new_chieftain = {
			silent_disappearance_ai_effect = yes
		}
	}
}
