﻿mz_fix_religions_effect = {
	if = {
		limit = { # Double-check to make certain this has not already happened
			NOT = { exists = global_var:mz_flag_fix_religion_decision }	
		}
		set_global_variable = { # Add global variable to prevent this from happening more than once
			name = mz_flag_fix_religion_decision
			value = yes
		}
		# Begin process of replacing doctrines and tenets
		every_religion_global = {
			every_faith = {
				## Add Holy Matrimony to all valid faiths
				if = {
					limit = { 
						NOR = { 
							has_doctrine = doctrine_mz_monogamy
							has_doctrine = tenet_polyamory
						} 
					}
					if = {
						limit = { 
							has_doctrine_parameter = adultery_male_accepted
							has_doctrine_parameter = adultery_female_accepted
						}
						add_doctrine = tenet_polyamory
					}
					else = {
						add_doctrine = doctrine_mz_monogamy
					}
				}
	
				## Syncretism Fix
				# Add True Faith
				if = {
					limit = { 
						NOR = { 
							has_doctrine = tenet_sinitic_syncretism
							has_doctrine = tenet_eastern_syncretism
							has_doctrine = tenet_unreformed_syncretism
							has_doctrine = tenet_christian_syncretism
							has_doctrine = tenet_islamic_syncretism
							has_doctrine = tenet_jewish_syncretism
							has_doctrine = doctrine_mz_no_syncretism
						} 
					}
					add_doctrine = doctrine_mz_no_syncretism
				}
	
				# Add adaptive to all syncretist faiths that are pluralistic
				if = {
					limit = { 
						OR = { 
							has_doctrine = tenet_sinitic_syncretism
							has_doctrine = tenet_eastern_syncretism
							has_doctrine = tenet_unreformed_syncretism
							has_doctrine = tenet_christian_syncretism
							has_doctrine = tenet_islamic_syncretism
							has_doctrine = tenet_jewish_syncretism
						}
						has_doctrine = doctrine_pluralism_pluralistic
						NOT = { has_doctrine = tenet_adaptive }
					}
					add_doctrine = tenet_adaptive
				}
	
				# Nudity doctrines fix
				if = { # Faiths that have natural primitivism have Full Nudity doctrine
					limit = { 
						has_doctrine = tenet_natural_primitivism
						NOT = { has_doctrine = doctrine_mz_full_nudity }
					}
					if = {
						limit = { has_doctrine = special_doctrine_naked_priests }
						remove_doctrine = special_doctrine_naked_priests
					}
					if = {
						limit = { has_doctrine = doctrine_mz_no_nudity }
						remove_doctrine = doctrine_mz_no_nudity
					}
					add_doctrine = doctrine_mz_full_nudity
				}
				if = { # All other faiths that lack Full Nudity or Naked Priests have No Nudity doctrine
					limit = { 
						NOR = { 
							has_doctrine = doctrine_mz_no_nudity
							has_doctrine = doctrine_mz_full_nudity
							has_doctrine = special_doctrine_naked_priests
						}
					}
					add_doctrine = doctrine_mz_no_nudity
				}
			}	
		}
		### Fixing individual Faiths
		## For Divine Marriage
		# Messalian
		faith:messalian = {
				if = { 
					limit = { has_doctrine = doctrine_consanguinity_unrestricted }
					remove_doctrine = doctrine_consanguinity_unrestricted
				}
				if = { 
					limit = { 
						NOT = { has_doctrine = tenet_divine_marriage }
					}
					add_doctrine = tenet_divine_marriage
				}
				if = { 
					limit = { 
						NOT = { has_doctrine = tenet_asceticism }
					}
					add_doctrine = tenet_asceticism
				}
		}	
		# Zoroastrianism
		faith:mazdayasna = {
			if = { 
				limit = { has_doctrine = doctrine_consanguinity_unrestricted }
				remove_doctrine = doctrine_consanguinity_unrestricted
			}
			if = { 
				limit = { 
					NOT = { has_doctrine = tenet_divine_marriage }
				}
				add_doctrine = tenet_divine_marriage
			}
			if = { 
				limit = { 
					NOT = { has_doctrine = tenet_communal_identity }
				}
				add_doctrine = tenet_communal_identity
			}
			if = {
				limit = {
					NOT = { has_doctrine = tenet_sanctity_of_nature }				
				}
				add_doctrine = tenet_sanctity_of_nature
			}
		}	
		faith:zurvanism = { # Actually Behafaridism
			if = { 
				limit = { 
					NOT = { has_doctrine = tenet_communal_identity }
				}
				add_doctrine = tenet_communal_identity
			}
			if = { 
				limit = { 
					NOT = { has_doctrine = tenet_vows_of_poverty }
				}
				add_doctrine = tenet_vows_of_poverty
			}
		}
		## Sycnretism Edge Cases
		# Yazidi
		faith:yazidi = {
			if = { 
				limit = { 
					NOT = { has_doctrine = tenet_ritual_celebrations }
				}
				add_doctrine = tenet_ritual_celebrations
			}
		}
		faith:meshefaresism = {
			if = { 
				limit = { 
					NOT = { has_doctrine = tenet_literalism }
				}
				add_doctrine = tenet_literalism
			}
		}
		faith:kitebacilweism = {
			if = { 
				limit = { 
					NOT = { has_doctrine = tenet_communal_identity }
				}
				add_doctrine = tenet_communal_identity
			}
		}
		# Dualism
		faith:mandeaism = {
			if = {
				limit = { 
					NOT = { has_doctrine = tenet_communal_identity }
				}
				add_doctrine = tenet_communal_identity				
			}
		}
		# Mingism (Make it close to Manichaeism)
		faith:mingism = {
			if = {
				limit = { 
					NOT = { has_doctrine = tenet_mendicant_preachers }
				}
				add_doctrine = tenet_mendicant_preachers				
			}			
		}
	}
}