#Written by Dub
#(Almost) every single one of these missions that deals with multiple provinces uses custom triggers for designating provinces, because I keep repeating the same code every time. As such it's simpler to refer to them there instead.
#If you want to check them out, go to byz_mission_triggers.txt

tre_reclaim_anatolia = {
	slot = 1
	generic = no
	ai = yes
	potential = {
		tag = TRE
		NOT = { has_dlc = "Winds of Change" }
	}
	has_country_shield = yes
	
	#Idea: Reclaim Pontus, then reclaim Paphlagonia, then Anatolian Coast, then take rest of Anatolia.
	tre_reclaim_pontus = {
		icon = mission_unite_home_region
		position = 1 #1-1
		required_missions = {  }
		
		provinces_to_highlight = {
			province_group = tre_reclaim_pontus_provinces
			NOT = { country_or_non_sovereign_subject_holds = ROOT }
		}
		
		trigger = {
			has_fulfiled_province_requirement_for_mission_trigger = {
				tooltip=country_holds_or_non_sovereign_subject_holds_highlighted 
				provinces=tre_reclaim_pontus_provinces
				owner_type=country_or_non_sovereign_subject_holds
			}
		}
		
		effect = {
			add_country_modifier = {
				name = "trebizond_resurgent"
				duration = 5475
			}
			
			#Claims
			give_permaclaims_for_mission = { mission=tre_expand_pontus }
		}
	
		ai_weight = {
			factor = 500	#AI gogo!
		}
	}
	
	tre_expand_pontus = {
		icon = mission_pf_soldier
		position = 3 #1-3
		required_missions = { tre_reclaim_pontus }
		
		provinces_to_highlight = {
			province_group = tre_expand_pontus_provinces
			NOT = { country_or_non_sovereign_subject_holds = ROOT }
		}
		
		trigger = {
			has_fulfiled_province_requirement_for_mission_trigger = {
				tooltip=country_holds_or_non_sovereign_subject_holds_highlighted 
				provinces=tre_expand_pontus_provinces
				owner_type=country_or_non_sovereign_subject_holds
			}
		}
		
		effect = {			
			#Religion
			if = {
				limit = {
					religion = orthodox
				}
				add_country_modifier = {
					name = "growth_of_the_orthodox_church"
					duration = 7300
				}
				add_estate_loyalty = {
					estate = estate_church
					loyalty = 10
				}
			}
			increase_religious_currency_effect = yes
			
			#Claims
			give_permaclaims_for_mission = { mission=tre_reconquer_west_anatolia }
			
			#Misc.
			if = { #If Genoa/Vassal controls Amastris & has capital in Italy still (Genoa)
				limit = {
					exists = GEN
					GEN = { 
						capital_scope = {
							region = italy_region
						}
						owns_or_non_sovereign_subject_of = 2299 #Amastris
					}
				}
				country_event = { id = resurgent_BYZ.23 }
			}
			else = {
				add_permanent_claim = 2299
			}
		}
		
		ai_weight = {
			factor = 500	#AI gogo!
		}
	}
	#The following two missions are basically carbon-cut copies of Byz missions.
	tre_reconquer_west_anatolia = {
		icon = mission_unite_home_region
		position = 5 #1-5
		required_missions = { tre_expand_pontus }
		
		provinces_to_highlight = {
			province_group = tre_reconquer_west_anatolia_provinces
			NOT = { country_or_non_sovereign_subject_holds = ROOT }
		}
		
		trigger = {
			has_fulfiled_province_requirement_for_mission_trigger = {
				tooltip=country_holds_or_non_sovereign_subject_holds_highlighted 
				provinces=tre_reconquer_west_anatolia_provinces
				owner_type=country_or_non_sovereign_subject_holds
			}
		}
		
		effect = {
			add_country_modifier = {
				name = "trebizond_resurgent"
				duration = 5475
			}
			
			#Dev bonuses
			316 = { #Nicomedia
				add_base_tax = 3
				add_base_manpower = 3
				if = {
					limit = {
						has_global_flag = byz_byzantine_silk_restored
					}
					change_trade_goods = silk
				}
			}
			5157 = { #Nicaea
				add_base_tax = 3
				add_base_production = 3
				if = {
					limit = {
						has_global_flag = byz_favored_glassmakers
					}
					add_base_production = 2
					add_or_spawn_center_of_trade = { level = 2 }
				}
			}
			random_owned_province = { #RandProv 1
				limit = {
					province_group = tre_reconquer_west_anatolia_provinces
					NOT = { #To prevent picking Nicaea/Nicomedia
						province_id = 316
						province_id = 5157
					}
				}
				add_base_tax = 1
				add_base_manpower = 1
				set_province_flag = byz_prov_1_to_dev #To prevent same province picked twice in practice
			}
			random_owned_province = { #RandProv 2
				limit = {
					province_group = tre_reconquer_west_anatolia_provinces
					NOT = { #To prevent picking Nicaea/Nicomedia
						province_id = 316
						province_id = 5157
						has_province_flag = byz_prov_1_to_dev #To prevent same province picked twice in practice
					}
				}
				add_base_tax = 1
				add_base_manpower = 1
			}
			hidden_effect = { #Clearing the flag above.
				every_owned_province = {
					limit = {
						has_province_flag = byz_prov_1_to_dev
					}
					clr_province_flag = byz_prov_1_to_dev 
				}
			}
			#Claims
			give_permaclaims_for_mission = { mission=tre_reclaim_anatolia }
			give_permaclaims_for_mission = { mission=tre_conquer_lesser_armenia }
			
			#CB
			if = { #Epirus
				limit = {
					does_tag_exist_and_have_less_than_provided_dev_trigger = {
						tag=EPI
						dev=200
					}
				}
				add_casus_belli = {
					type = cb_vassalize_mission
					months = 300 #25 years. I'm not sure if you can actually make it infinite.
					target = EPI
				}
			}
			if = { #Cappadocia
				limit = {
					does_tag_exist_and_have_less_than_provided_dev_trigger = {
						tag=CAP
						dev=200
					}
				}
				add_casus_belli = {
					type = cb_vassalize_mission
					months = 300 #25 years. I'm not sure if you can actually make it infinite.
					target = CAP
				}
			}
		}		
	
		ai_weight = {
			factor = 500	#AI gogo!
		}
	}
	
	tre_reclaim_anatolia = {
		icon = mission_empire
		position = 6 #1-6
		required_missions = { tre_reconquer_west_anatolia }
		
		provinces_to_highlight = {
			province_group = tre_reclaim_anatolia_provinces
			NOT = { country_or_non_sovereign_subject_holds = ROOT }
		}
		
		trigger = {
			has_fulfiled_province_requirement_for_mission_trigger = {
				tooltip=country_holds_or_non_sovereign_subject_holds_highlighted 
				provinces=tre_reclaim_anatolia_provinces
				owner_type=country_or_non_sovereign_subject_holds
			}
		}
		
		effect = {
			#Religion
			if = {
				limit = {
					religion = orthodox
				}
				add_country_modifier = {
					name = "growth_of_the_orthodox_church"
					duration = 7300
				}
				add_estate_loyalty = {
					estate = estate_church
					loyalty = 10
				}
			}
			increase_religious_currency_effect = yes
			
			#Dev bonuses
			326 = { #Ancyra
				add_base_tax = 3
				add_base_manpower = 3
			}
			151 = { #Constantinople
				add_base_tax = 3
				add_base_production = 3
			}
			random_owned_province = { #RandProv 1
				limit = {
					province_group = tre_reclaim_anatolia_provinces
					NOT = { #To prevent picking Nicaea/Nicomedia
						province_id = 326
					}
				}
				add_base_tax = 1
				add_base_manpower = 1
				set_province_flag = byz_prov_1_to_dev #To prevent same province picked twice in practice
			}
			random_owned_province = { #RandProv 2
				limit = {
					province_group = tre_reclaim_anatolia_provinces
					NOT = { #To prevent picking Nicaea/Nicomedia
						province_id = 326
						has_province_flag = byz_prov_1_to_dev #To prevent same province picked twice in practice
					}
				}
				add_base_tax = 1
				add_base_manpower = 1
				set_province_flag = byz_prov_2_to_dev #To prevent same province picked twice in practice
			}
			random_owned_province = { #RandProv 3
				limit = {
					province_group = tre_reclaim_anatolia_provinces
					NOT = { #To prevent picking Nicaea/Nicomedia
						province_id = 326
						has_province_flag = byz_prov_1_to_dev #To prevent same province picked twice in practice
						has_province_flag = byz_prov_2_to_dev #To prevent same province picked twice in practice
					}
				}
				add_base_tax = 1
				add_base_manpower = 1
				set_province_flag = byz_prov_3_to_dev #To prevent same province picked twice in practice
			}
			random_owned_province = { #RandProv 4
				limit = {
					province_group = tre_reclaim_anatolia_provinces
					NOT = { #To prevent picking Nicaea/Nicomedia
						province_id = 326
						has_province_flag = byz_prov_1_to_dev #To prevent same province picked twice in practice
						has_province_flag = byz_prov_2_to_dev #To prevent same province picked twice in practice
						has_province_flag = byz_prov_3_to_dev #To prevent same province picked twice in practice
					}
				}
				add_base_tax = 1
				add_base_manpower = 1
				set_province_flag = byz_prov_4_to_dev #To prevent same province picked twice in practice
			}
			random_owned_province = { #RandProv 5
				limit = {
					province_group = tre_reclaim_anatolia_provinces
					NOT = { #To prevent picking Nicaea/Nicomedia
						province_id = 326
						has_province_flag = byz_prov_1_to_dev #To prevent same province picked twice in practice
						has_province_flag = byz_prov_2_to_dev #To prevent same province picked twice in practice
						has_province_flag = byz_prov_3_to_dev #To prevent same province picked twice in practice
						has_province_flag = byz_prov_4_to_dev #To prevent same province picked twice in practice
					}
				}
				add_base_tax = 1
				add_base_manpower = 1
			}
			hidden_effect = { #Clearing the flags above.
				every_owned_province = {
					limit = {
						has_province_flag = byz_prov_1_to_dev
					}
					clr_province_flag = byz_prov_1_to_dev 
				}
				every_owned_province = {
					limit = {
						has_province_flag = byz_prov_2_to_dev
					}
					clr_province_flag = byz_prov_1_to_dev 
				}
				every_owned_province = {
					limit = {
						has_province_flag = byz_prov_3_to_dev
					}
					clr_province_flag = byz_prov_1_to_dev 
				}
				every_owned_province = {
					limit = {
						has_province_flag = byz_prov_4_to_dev
					}
					clr_province_flag = byz_prov_1_to_dev 
				}
			}
			
			custom_tooltip = reclaim_anatolia_tooltip
			hidden_effect = {
				tre_reconquer_west_anatolia_provinces = {
					add_province_modifier = {
						name = "byz_resettlement_act"
						duration = 18250
					}
				}
			}
		}	
	
		ai_weight = {
			factor = 500	#AI gogo!
		}
	}
}

tre_reclaim_anatolia_2 = {
	slot = 2
	generic = no
	ai = yes
	potential = {
		tag = TRE
		NOT = { has_dlc = "Winds of Change" }
	}
	has_country_shield = yes
	
	tre_conquer_lesser_armenia = {
		icon = mission_mesopotamia
		position = 6 #2-6
		required_missions = { tre_reconquer_west_anatolia }
		
		provinces_to_highlight = {
			province_group = tre_conquer_lesser_armenia_provinces
			NOT = { country_or_non_sovereign_subject_holds = ROOT }
		}
		
		trigger = {
			has_fulfiled_province_requirement_for_mission_trigger = {
				tooltip=country_holds_or_non_sovereign_subject_holds_highlighted 
				provinces=tre_conquer_lesser_armenia_provinces
				owner_type=country_or_non_sovereign_subject_holds
			}
		}
		
		effect = {
			add_country_modifier = {
				name = byz_armenian_ambition
				duration = 5475
			}
			
			#Misc
			add_accepted_culture = cilician
		}
	
		ai_weight = {
			factor = 500	#AI gogo!
		}
	}
}

tre_reclaim_chersonesus = {
	slot = 3
	generic = no
	ai = yes
	potential = {
		tag = TRE
		NOT = { has_dlc = "Winds of Change" }
	}
	has_country_shield = yes
	
	#Idea: Integrate Theodoro, then claim Cherson.
	tre_integrate_theodoro = {
		icon = mission_have_two_subjects
		position = 1 #3-1
		required_missions = { }
		
		provinces_to_highlight = {
			province_id = 2410
			NOT = { owned_by = ROOT }
		}
		
		trigger = {
			owns = 2410
			NOT = { exists = FEO }
		}
		
		effect = {
			#Claims
			give_permaclaims_for_mission = { mission=tre_reclaim_chersonese }
		}
	
		ai_weight = {
			factor = 500	#AI gogo!
		}
	}
	
	tre_reclaim_chersonese = {
		icon = mission_invade_island
		position = 3 #3-3
		required_missions = { tre_integrate_theodoro }
		
		provinces_to_highlight = {
			province_group = tre_reclaim_chersonese_provinces
			NOT = { country_or_non_sovereign_subject_holds = ROOT }
		}
		
		trigger = {
			has_fulfiled_province_requirement_for_mission_trigger = {
				tooltip=country_holds_or_non_sovereign_subject_holds_highlighted 
				provinces=tre_reclaim_chersonese_provinces
				owner_type=country_or_non_sovereign_subject_holds
			}
		}
		
		effect = {
			2447 = {
				add_permanent_claim = ROOT
			}
			286 = {
				add_claim = ROOT
			}
			2410 = {
				add_base_tax = 2
				add_base_manpower = 2
			}
			7190 = {
				add_base_tax = 3
				add_base_manpower = 3
			}
		}
	
		ai_weight = {
			factor = 500	#AI gogo!
		}
	}
	
	tre_northern_allies = {
		icon = mission_cossack_cavalry
		position = 5 #3-5
		required_missions = { tre_reclaim_chersonese }
		
		provinces_to_highlight = {
			#None
		}
		
		trigger = {
			any_country = {
				culture_group = east_slavic
				OR = {
					alliance_with = ROOT
					is_subject_of = ROOT
				}
			}
		}
		
		effect = {
			add_dip_power = 50
		}
	
		ai_weight = {
			factor = 500	#AI gogo!
		}
	}
}

tre_komnenoi_restoration = {
	slot = 5
	generic = no
	ai = yes
	potential = {
		tag = TRE
		NOT = { has_dlc = "Winds of Change" }
	}
	has_country_shield = yes
	
	#Idea: Royally marry into Byzantium (Or be their rival if they rivalled you), then get PU mission to take restore Komnenoi rule, then restore Byzantine Empire.
	tre_marry_into_palaiologos = {
		icon = mission_alliances
		position = 1 #5-1
		required_missions = { }
		
		provinces_to_highlight = {
			#None
		}
		
		trigger = {
			OR = {
				if = {
					limit = {
						NOT = { BYZ = { is_rival = ROOT } } #If Byzantium has not rivalled Trebizond
					}
					marriage_with = BYZ
				}
				else = {
					is_rival = BYZ
				}
				NOT = { exists = BYZ }
			}
			BYZ = {
				is_subject = no
			}
		}
		
		effect = {
			#Copied from Austria's missions, adjusted to become a vassalization.
			if = { 
				limit = {
					valid_for_personal_unions_trigger = yes
					BYZ = {
						valid_for_personal_unions_trigger = yes
					}
				}
				add_casus_belli = {
					type = cb_restore_personal_union
					months = 300
					target = BYZ
				}
			}
			else = {
				151 = { add_permanent_claim = ROOT }
			}
			
		}
	
		ai_weight = {
			factor = 500	#AI gogo!
		}
	}
	
	tre_reclaim_byzantine_throne = {
		icon = mission_pf_map_table
		position = 3 #5-3
		required_missions = { tre_marry_into_palaiologos }
		
		provinces_to_highlight = {
			province_id = 151
			NOT = { country_or_non_sovereign_subject_holds = ROOT }
		}
		
		trigger = {
			owns_or_non_sovereign_subject_of = 151
		}
		
		effect = {
			add_adm_power = 100
			add_dip_power = 100
			add_mil_power = 100
			
			#Claims
			give_permaclaims_for_mission = { mission=tre_restore_byzantine_empire }
		}
	
		ai_weight = {
			factor = 500	#AI gogo!
		}
	}
	
	tre_restore_byzantine_empire = {
		icon = mission_empire
		position = 5 #5-5
		required_missions = { tre_reclaim_byzantine_throne }
		
		provinces_to_highlight = {
			province_group = tre_restore_byzantine_empire_provinces
			NOT = { country_or_non_sovereign_subject_holds = ROOT }
		}
		
		trigger = {
			has_fulfiled_province_requirement_for_mission_trigger = {
				tooltip=country_holds_or_non_sovereign_subject_holds_highlighted 
				provinces=tre_restore_byzantine_empire_provinces
				owner_type=country_or_non_sovereign_subject_holds
			}
		}
		
		effect = {
			if = {
				limit = {
					BYZ = {
						is_subject_of = ROOT
					}
				}
				inherit = BYZ
			}
			else = {
				151 = { #Constantinople
					add_base_tax = 5
					add_base_production = 5
					add_base_manpower = 2
				}
			}
			148 = { #Thessalonica, from Reclaim Aegean Islands mission.
				add_base_tax = 4
				add_base_production = 4
				add_base_manpower = 2
			}
		}
	
		ai_weight = {
			factor = 500	#AI gogo!
		}
	}
}