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

decisions = {
	
	create_fraticelli_papacy = {
		only_playable = yes
		
		is_high_prio = yes
		ai_check_interval = 36
	
		potential = {
			is_playable = yes
			religion = fraticelli
			NOT = { is_title_active = d_fraticelli }
			has_dlc = "Sons of Abraham"
			NOT = {
				has_alternate_start_parameter = { key = religion_names value = random }
			}
		}
		
		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
				}
			}
			hidden_effect = {
				character_event = { id = 39703 }
			}
			piety = 1000
		}
		
		revoke_allowed = {
			always = no
		}
		
		ai_will_do = {
			factor = 1
		}
	}
	
	create_iconoclast_patriarchy = {
		only_playable = yes
		
		is_high_prio = yes
		ai_check_interval = 36
	
		potential = {
			is_playable = yes
			religion = iconoclast
			NOT = { is_title_active = d_iconoclast }
			has_dlc = "Sons of Abraham"
			NOT = {
				has_alternate_start_parameter = { key = religion_names value = random }
			}
		}
		
		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
				}
			}
			hidden_effect = {
				long_character_event = { id = 39704 }
			}
			piety = 1000
		}
		
		revoke_allowed = {
			always = no
		}
		
		ai_will_do = {
			factor = 1
		}
	}
	
	restore_pope_in_rome = {
		only_independent = yes
		is_high_prio = yes
		ai_check_interval = 36
	
		potential = {
			is_playable = yes
			independent = yes
			has_dlc = "Sons of Abraham"
			NOT = {
				has_alternate_start_parameter = { key = religion_names value = random }
			}
			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
							}
						}
						save_event_target_as = restored_pope
					}
				}
			}
			if = {
				limit = {
					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
							}
						}
						save_event_target_as = restored_pope
					}
				}
			}
			if = {
				limit = {
					religion = fraticelli
					NOT = { has_character_flag = restored_fraticelli_pope_in_rome }
				}
				piety = 1000
				set_character_flag = restored_fraticelli_pope_in_rome
			}
			hidden_effect = {
				character_event = { id = 39705 }
				set_character_flag = testflagrome
			}
		}
		
		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 = {
		only_independent = yes
		is_high_prio = yes
		ai_check_interval = 36
		
		potential = {
			is_playable = yes
			has_dlc = "Sons of Abraham"
			religion = orthodox
			has_landed_title = c_byzantion
			independent = yes
			k_orthodox = {
				NOT = {
					holder_scope = {
						religion = orthodox
					}
				}
			}
			NOT = {
				has_alternate_start_parameter = { key = religion_names value = random }
			}
		}
		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
					female = no
					dynasty = none
				}
				new_character = {
					k_orthodox = {
						grant_title = PREV
					}
					b_hagiasophia = {
						grant_title = PREV
					}
					wealth = 500
				}
			}
			hidden_effect = {
				long_character_event = { id = 39706 }
			}
		}
	}
	african_tolerate_abrahamics = {
		only_playable = yes
		ai_check_interval = 36

		potential = {
            OR = {
                religion = west_african_pagan # Only unreformed. Reformers can pick the Syncretism Doctrine to sympathize with everyone they wish.
                religion = bori
                religion = a_tag_roog
                religion = amazigh
            }
			NOR = {
				trait = sympathy_christendom
				trait = sympathy_islam
				trait = sympathy_judaism
				has_character_flag = flag_picking_sympathy
			}
			NOT = {
				has_alternate_start_parameter = { key = religion_names value = random }
			}
		}
		allow = {
			NOT = {
				trait = zealous
			}
			custom_tooltip = {
				text = african_sympathy_abrahamic
				hidden_tooltip = {
					OR = {
						any_neighbor_independent_ruler = {
							OR = {
								religion_group = christian
								religion_group = muslim
								religion_group = jewish_group
							}
						}
						any_liege = {
							OR = {
								religion_group = christian
								religion_group = muslim
								religion_group = jewish_group
							}
						}
					}
				}
			}
			piety = 50
		}
		effect = {
			custom_tooltip = { text = tooltip_african_picking_syncretism }
			hidden_tooltip = { character_event = { id = HFP.23027 } }
			piety = -50
		}
		ai_will_do = {
			factor = 1
		}
	}
}
