###########################################
#
# Religious Decisions for Sons of Abraham
#
###########################################
# Written by Henrik Fhraeus
###########################################

decisions = {
	
	create_fraticelli_papacy = {
		
		is_high_prio = yes
	
		potential = {
			religion = fraticelli
			NOT = { is_title_active = d_fraticelli }
			has_dlc = "Sons of Abraham"
		}
		
		allow = {
			piety = 1000
			OR = {
				owns = 333 # Rome
				any_realm_lord = {
					owns = 333
				}
			}
		}
		
		effect = {
			activate_title = { title = d_fraticelli status = yes }
			hidden_tooltip = {
				create_random_priest = {
					dynasty = none
					random_traits = yes
				}
				new_character = {
					d_fraticelli = {
						grant_title = PREV
					}
					wealth = 500
					opinion = {
						who = ROOT
						modifier = opinion_creator_of_rel_heal
					}
				}
				
				religion_authority = {
					modifier = papacy_instituted
					years = 20
				}
			}
			piety = 1000
		}
		
		revoke_allowed = {
			always = no
		}
		
		ai_will_do = {
			factor = 1
		}
	}
	
	create_iconoclast_patriarchy = {
		
		is_high_prio = yes
	
		potential = {
			religion = iconoclast
			NOT = { is_title_active = d_iconoclast }
			has_dlc = "Sons of Abraham"
		}
		
		allow = {
			piety = 1000
			OR = {
				owns = 496 # Constantinople
				any_realm_lord = {
					owns = 496
				}
			}
		}
		
		effect = {
			activate_title = { title = d_iconoclast status = yes }
			hidden_tooltip = {
				create_random_priest = {
					dynasty = none
					random_traits = yes
				}
				new_character = {
					d_iconoclast = {
						grant_title = PREV
					}
					wealth = 500
					opinion = {
						who = ROOT
						modifier = opinion_creator_of_rel_heal
					}
				}
				
				religion_authority = {
					modifier = patriarchy_instituted
					years = 20
				}
			}
			piety = 1000
		}
		
		revoke_allowed = {
			always = no
		}
		
		ai_will_do = {
			factor = 1
		}
	}
	
	restore_pope_in_rome = {
		is_high_prio = yes
	
		potential = {
			is_playable = yes
			independent = yes
			has_dlc = "Sons of Abraham"
			
			OR = {
				religion = catholic
				AND = {
					religion = fraticelli
					is_title_active = d_fraticelli
				}
			}
			
			controls_religion = no
			
			c_roma = {
				holder_scope = {
					OR = {
						character = ROOT
						is_liege_or_above = ROOT
					}
					OR = {
						AND = {
							ROOT = { religion = catholic }
							k_papal_state = {
								holder_scope = {
									NOT = { character = PREVPREV }
									NOT = { is_vassal_or_below = PREVPREV }
								}
							}
						}
						AND = {
							ROOT = { religion = fraticelli }
							d_fraticelli = {
								holder_scope = {
									NOT = { character = PREVPREV }
									NOT = { is_vassal_or_below = PREVPREV }
								}
							}
						}
					}
				}
			}
		}
		
		effect = {		
			if = {
				limit = {
					religion = catholic
				}
				k_papal_state = {
					holder_scope = {
						c_roma = {
							grant_title = PREV
							any_de_jure_vassal_title = {
								limit = {
									holder_scope = { 
										OR = {
											character = ROOT
											is_liege_or_above = ROOT
										}
									}
								}
								grant_title = PREVPREV
							}
						}
					}
				}
			}
			if = {
				limit = {
					AND = {
						religion = catholic
						NOT = { has_character_flag = restored_catholic_pope_in_rome }
					}
				}
				k_papal_state = {
					holder_scope = {
						opinion = {
							who = ROOT
							modifier = opinion_restored_to_rome
						}
					}
				}
				piety = 1000
				set_character_flag = restored_catholic_pope_in_rome
			}
			
			if = {
				limit = {
					religion = fraticelli
				}
				d_fraticelli = {
					holder_scope = {
						c_roma = {
							grant_title = PREV
							any_de_jure_vassal_title = {
								limit = {
									holder_scope = { 
										OR = {
											character = ROOT
											is_liege_or_above = ROOT
										}
									}
								}
								grant_title = PREVPREV
							}
						}
					}
				}
			}
			if = {
				limit = {
					AND = {
						religion = fraticelli
						 NOT = { has_character_flag = restored_fraticelli_pope_in_rome }
					}
				}
				piety = 1000
				set_character_flag = restored_fraticelli_pope_in_rome
			}
		}
		
		revoke_allowed = {
			always = no
		}
		
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				NOT = {
					any_demesne_province = {
						NOT = { province_id = 333 }
					}
				}
			}
			modifier = {
				factor = 0
				c_roma = {
					holder_scope = {
						OR = {
							ai = no
							any_liege = { ai = no }  # AI will never take Rome province away from a player
						}
					}
				}
			}
		}
	}
	
	restore_ecumenical_patriarchate = {
		is_high_prio = yes
		potential = {
			has_dlc = "Sons of Abraham"
			religion = orthodox
			has_landed_title = c_byzantion
			is_playable = yes
			independent = yes
			k_orthodox = {
				NOT = {
					holder_scope = {
						religion = orthodox
					}
				}
			}
		}
		allow = {
			piety = 1000
			OR = {
				owns = 496 # Constantinople
				any_realm_lord = {
					owns = 496
				}
			}
		}
		effect = {
			piety = -1000
			hidden_tooltip = {
				if = {
					limit = {
						NOT = { is_title_active = k_orthodox }
					}
					activate_title = { title = k_orthodox status = yes }
				}
				create_random_priest = {
					random_traits = yes
					religion = ROOT
					dynasty = none
				}
				new_character = {
					k_orthodox = {
						grant_title = PREV
					}
					b_hagiasophia = {
						grant_title = PREV
					}
					c_byzantion = {
						grant_title = PREV
					}
					wealth = 500
				}
			}
		}
	}	
}
