establish_religious_march = {
	category = influence

	require_acceptance = no

	is_visible = {
		is_subject = no
		can_create_subject_type = {
			subject = FROM
			subject_type = religious_march
		}
	}

	is_allowed = {
		is_subject = no
		can_create_subject_type = {
			subject = FROM
			subject_type = religious_march
		}
		is_at_war = no
		FROM = { is_at_war = no }
	}

	on_accept = {
		if = {
			limit = {
				is_subject = no
				can_create_subject_type = {
					subject = FROM
					subject_type = religious_march
				}
				is_at_war = no
				FROM = { is_at_war = no }
			}
			create_subject = {
				subject = FROM
				subject_type = religious_march
				keep_liberty_desire = yes
			}
		}
	}

	ai_will_do = {
		NOT = { religion = confucianism }
		NOT = {
			can_create_subject_type = {
				subject = FROM
				subject_type = crusader_state_vassal
			}
		}
		NOT = {
			can_create_subject_type = {
				subject = FROM
				subject_type = iqta_vassal
			}
		}
		FROM = {
			NOT = { liberty_desire = 50 }
			NOT = { is_subject_of_type = exarchate_subject }
			NOT = { is_different_march_subject = yes }
			NOT = { development_of_overlord_fraction = 0.25 }
			any_neighbor_country = {
				OR = {
					is_rival = ROOT
					is_enemy = ROOT
				}
				NOT = { religion_group = ROOT }
			}
			NOT = { religious_unity = 0.7 }
			NOT = {
				num_of_owned_provinces_with = {
					value = 10
					is_permanent_claim = ROOT
				}
			}
		}
	}
}

ask_to_become_religious_march = {
	category = influence

	alert_index = 6
	alert_tooltip = ask_to_become_religious_march_alert_tooltip

	require_acceptance = yes

	is_visible = {
		FROM = {
			is_subject = no
			can_create_subject_type = {
				subject = ROOT
				subject_type = religious_march
			}
		}
	}

	is_allowed = {
		FROM = {
			is_subject = no
			can_create_subject_type = {
				subject = ROOT
				subject_type = religious_march
			}
		}
		is_at_war = no
		FROM = { is_at_war = no }
	}

	on_accept = {
		if = {
			limit = {
				FROM = {
					is_subject = no
					can_create_subject_type = {
						subject = ROOT
						subject_type = religious_march
					}
				}
				is_at_war = no
				FROM = { is_at_war = no }
			}
			FROM = {
				create_subject = {
					subject = ROOT
					subject_type = religious_march
					keep_liberty_desire = yes
				}
			}
		}
	}

	on_decline = {
		if = {
			limit = {
				FROM = {
					is_subject = no
					can_create_subject_type = {
						subject = ROOT
						subject_type = religious_march
					}
				}
				is_at_war = no
				FROM = { is_at_war = no }
			}
			FROM = {
				clr_country_flag = declined_become_religious_march_@ROOT
				set_country_flag = declined_become_religious_march_@ROOT
			}
			add_opinion = {
				who = FROM
				modifier = declined_ask_to_become_religious_march
			}
		}
	}

	ai_acceptance = {
		add_entry = {
			name = OPINION
			export_to_variable = {
				which = ai_value
				value = opinion
				who = FROM
				with = ROOT
			}
			divide_variable = { which = ai_value value = 4 }
		}
		add_entry = {
			name = MODIFIER_DIPLO_SKILL
			export_to_variable = {
				which = ai_value
				value = modifier:diplomatic_reputation
			}
			multiply_variable = { which = ai_value value = 5 }
		}
		add_entry = {
			name = ROOT_IS_VASSAL_FOR_AT_LEAST_10_YEARS
			limit = {
				years_in_vassalage_under = {
					who = FROM
					years = 10
					all_subject_country = yes
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_IS_NOT_A_NEIGHBOR_OF_FROMS_RIVALS
			limit = {
				NOT = {
					any_neighbor_country = {
						OR = {
							is_rival = FROM
							is_enemy = FROM
						}
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_HAS_MORE_THAN_25_PERCENT_OF_OVERLORD_DEVELOPMENT
			limit = {
				development_of_overlord_fraction = 0.25
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_HAS_TOO_FEW_PRODUCTION_INCOME
			limit = {
				OR = {
					NOT = { monthly_income = 20 }
					NOT = { production_income_percentage = 0.35 }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_HAS_TOO_HIGH_RELIGIOUS_UNITY
			limit = {
				religious_unity = 0.75
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
	}

	ai_will_do = {
		NOT = { religion = confucianism }
		NOT = { liberty_desire = 50 }
		NOT = { is_subject_of_type = exarchate_subject }
		NOT = { is_different_march_subject = yes }
		NOT = { religious_unity = 0.6 }
		any_neighbor_country = {
			OR = {
				is_rival = FROM
				is_enemy = FROM
			}
			NOT = { religion_group = FROM }
		}
		FROM = {
			NOT = {
				can_create_subject_type = {
					subject = ROOT
					subject_type = crusader_state_vassal
				}
			}
			NOT = {
				can_create_subject_type = {
					subject = ROOT
					subject_type = iqta_vassal
				}
			}
			OR = {
				NOT = { has_country_flag = declined_become_religious_march_@ROOT }
				had_country_flag = { flag = declined_become_religious_march_@ROOT days = 1825 }
			}
		}
		NOT = {
			num_of_owned_provinces_with = {
				value = 10
				is_permanent_claim = FROM
			}
		}
	}
}

religious_march_enable_increased_conversion_efforts = {
	category = subject_interactions

	require_acceptance = no

	is_visible = {
		FROM = {
			is_subject_of = ROOT
			is_subject_of_type = religious_march
			NOT = { has_country_flag = religious_march_increased_conversion_efforts }
		}
	}

	is_allowed = {
		hidden_trigger = {
			FROM = {
				is_subject_of = ROOT
				is_subject_of_type = religious_march
				NOT = { has_country_flag = religious_march_increased_conversion_efforts }
			}
		}
		NOT = { truce_with = FROM }
		is_at_war = no
		FROM = { is_at_war = no }
		FROM = { NOT = { liberty_desire = 50 } }
		FROM = {
			any_owned_province = {
				has_owner_religion = no
			}
		}
	}

	on_accept = {
		if = {
			limit = {
				FROM = {
					is_subject_of = ROOT
					is_subject_of_type = religious_march
					NOT = { has_country_flag = religious_march_increased_conversion_efforts }
				}
				NOT = { truce_with = FROM }
				is_at_war = no
				FROM = { is_at_war = no }
				FROM = { NOT = { liberty_desire = 50 } }
				FROM = {
					any_owned_province = {
						has_owner_religion = no
					}
				}
			}
			FROM = {
				set_country_flag = religious_march_increased_conversion_efforts
			}
		}
	}

	ai_will_do = {
		FROM = {
			is_at_war = no
			NOT = { liberty_desire = 35 }
			NOT = { religious_unity = 0.5 }
		}
	}
}

religious_march_disable_increased_conversion_efforts = {
	category = subject_interactions

	require_acceptance = no

	is_visible = {
		FROM = {
			is_subject_of = ROOT
			is_subject_of_type = religious_march
			has_country_flag = religious_march_increased_conversion_efforts
		}
	}

	is_allowed = {
		hidden_trigger = {
			FROM = {
				is_subject_of = ROOT
				is_subject_of_type = religious_march
				has_country_flag = religious_march_increased_conversion_efforts
			}
		}
		is_at_war = no
		FROM = { is_at_war = no }
		prestige = 0
	}

	on_accept = {
		if = {
			limit = {
				FROM = {
					is_subject_of = ROOT
					is_subject_of_type = religious_march
					has_country_flag = religious_march_increased_conversion_efforts
				}
				is_at_war = no
				FROM = { is_at_war = no }
			}
			add_prestige = -10
			FROM = {
				clr_country_flag = religious_march_increased_conversion_efforts
			}
		}
	}

	ai_will_do = {
		FROM = {
			OR = {
				is_at_war = yes
				liberty_desire = 55
				religious_unity = 0.8
			}
		}
	}
}