namespace = ancrel

##############################################
#
# Ancient Religions Reborn
# - Lets. Get. PAGAN! Events
#
# Event Ids: ancrel.9001 - 9100 reserved
##############################################

# the pope pagans up the world
character_event = {
	id = ancrel.9001
	desc = ancrel.9001.desc
	picture = GFX_evt_Pagan_dolmen
	is_triggered_only = yes

	trigger = {
		NOT = { has_global_flag = acr_paganify }
	}

	immediate = {
		set_global_flag = acr_paganify
		if = {
			limit = { controls_religion = yes }
			character_event = { id = ancrel.9014 days = 1 }
		}
		#character_event = { id = ancrel.9014 days = 1 }
	}

	option = {
		name = ancrel.9001.a
		any_independent_ruler = {
			any_realm_character = {
				if = { # Celtic
					limit = {
						NOT = { religion_group = pagan_group }
						OR = {
							culture_group = celtic
							culture_group = iberian
							culture_group = west_germanic
							culture = occitan
							culture = french
							culture = norman
						}
					}
					character_event = { id = ancrel.9002 }
				}
				if = { # Hellenic
					limit = {
						NOT = { religion_group = pagan_group }					
						NOT = { culture = coptic }
						OR = {
							culture_group = byzantine
							culture = italian
							culture = sardinian
							culture = dalmatian
						}

					}
					character_event = { id = ancrel.9003 }
				}
				if = { # Titan
					limit = {
						culture = alan
					}
					character_event = { id = ancrel.9012 }
				}
				if = { # Kemetic
					limit = {
						NOT = { religion_group = pagan_group }					
						OR = {
							culture = bedouin_arabic
							culture = levantine_arabic
							culture = egyptian_arabic
							culture_group = east_african
							culture = coptic
						}
					}
					character_event = { id = ancrel.9004 }
				}
				if = { # West African
					limit = {
						NOT = { religion_group = pagan_group }					
						OR = {
							culture = maghreb_arabic
							culture = andalusian_arabic
							culture_group = west_african
							culture_group = central_african
						}
					}
					character_event = { id = ancrel.9005 }
				}
				if = { # Slavic
					limit = {
						NOT = { religion_group = pagan_group }					
						OR = {
							culture_group = west_slavic
							culture_group = east_slavic
							culture_group = south_slavic
						}
					}
					character_event = { id = ancrel.9006 }
				}
				if = { # Norse
					limit = {
						NOT = { religion_group = pagan_group }					
						OR = {
							culture_group = north_germanic
							culture_group = central_germanic
						}
					}
					character_event = { id = ancrel.9007 }					
				}
				if = { # Zoroastrian
					limit = {
						NOT = { religion_group = pagan_group }
						NOT = { culture = afghan }
						culture_group = iranian
					}
					character_event = { id = ancrel.9008 }
				}
				if = { # Tengri
					limit = {
						NOT = { religion_group = pagan_group }
						OR = {
							culture_group = altaic
							culture_group = magyar
						}
					}
					character_event = { id = ancrel.9009 }
				}
				if = { # Bon
					limit = {
						NOT = { religion_group = pagan_group }
						culture_group = tibetan_group
					}
					character_event = { id = ancrel.9011 }
				}
				if = { # Zun 1
					limit = {
						NOT = { religion_group = pagan_group }
						culture = afghan
					}
					character_event = { id = ancrel.9013 }
				}
				if = { # Zun 2
					limit = {
						NOR = {
							religion_group = pagan_group
							religion_group = indian_group
						}
						OR = {
							culture_group = indo_aryan_group
							culture_group = dravidian_group
						}
					}
					character_event = { id = ancrel.9013 }
				}
				if = { # Religious heads (not the pope)
					limit = {
						controls_religion = yes
					}
					character_event = { id = ancrel.9014 }
				}
			}
		}
	}
}

# Celtic
character_event = {
	id = ancrel.9002
	desc = ancrel.9002.desc
	picture = GFX_evt_Pagan_dolmen
	is_triggered_only = yes
	hide_from = yes
	
	option = {
		name = OK
		if = {
			limit = { is_ruler = yes }
			set_secret_religion = celtic_pagan
			set_character_flag = convert_secret
			convert_religion_failsafe_effect = yes
		}
		else = { religion = celtic_pagan }
		any_demesne_title = {
			limit = { tier = count }
			location = { religion = celtic_pagan }
		}
	}
}

# Hellenic
character_event = {
	id = ancrel.9003
	desc = ancrel.9003.desc
	picture = GFX_evt_roman_temple
	is_triggered_only = yes
	hide_from = yes

	option = {
		name = OK
		if = {
			limit = { is_ruler = yes }
			set_secret_religion = hellenic_pagan
			set_character_flag = convert_secret
			convert_religion_failsafe_effect = yes
		}
		else = { religion = hellenic_pagan }
		if = {
			limit = {
				d_galilee = {
					holder_scope = {
						character = ROOT
					}
				}
			}
			remove_trait = eunuch
		}
		any_demesne_title = {
			limit = { tier = count }
			location = { religion = hellenic_pagan }
		}
	}
}

# Kemetic
character_event = {
	id = ancrel.9004
	desc = ancrel.9004.desc
	picture = GFX_evt_temple_egyptian_pagan
	is_triggered_only = yes
	hide_from = yes

	option = {
		name = OK
		if = {
			limit = { is_ruler = yes }
			set_secret_religion = egyptian_pagan
			set_character_flag = convert_secret
			convert_religion_failsafe_effect = yes
		}
		else = { religion = egyptian_pagan }
		any_demesne_title = {
			limit = { tier = count }
			location = { religion = egyptian_pagan }
		}
	}
}

# West African
character_event = {
	id = ancrel.9005
	desc = ancrel.9005.desc
	picture = GFX_evt_desert
	is_triggered_only = yes
	hide_from = yes

	option = {
		name = OK
		if = {
			limit = { is_ruler = yes }
			set_secret_religion = west_african_pagan
			set_character_flag = convert_secret
			convert_religion_failsafe_effect = yes
		}
		else = { religion = west_african_pagan }
		any_demesne_title = {
			limit = { tier = count }
			location = { religion = west_african_pagan }
		}
	}
}

# Slavic
character_event = {
	id = ancrel.9006
	desc = ancrel.9006.desc
	picture = GFX_evt_cathedral_norse_pagan
	is_triggered_only = yes
	hide_from = yes

	option = {
		name = OK
		if = {
			limit = { is_ruler = yes }
			set_secret_religion = slavic_pagan
			set_character_flag = convert_secret
			convert_religion_failsafe_effect = yes
		}
		else = { religion = slavic_pagan }
		any_demesne_title = {
			limit = { tier = count }
			location = { religion = slavic_pagan }
		}
	}
}

# Norse
character_event = {
	id = ancrel.9007
	desc = ancrel.9007.desc
	picture = GFX_evt_cathedral_norse_pagan
	is_triggered_only = yes
	hide_from = yes

	option = {
		name = OK
		if = {
			limit = { is_ruler = yes }
			set_secret_religion = norse_pagan
			set_character_flag = convert_secret
			convert_religion_failsafe_effect = yes
		}
		else = { religion = norse_pagan }
		any_demesne_title = {
			limit = { tier = count }
			location = { religion = norse_pagan }
		}
	}
}

# Zoroastrian
character_event = {
	id = ancrel.9008
	desc = ancrel.9008.desc
	picture = GFX_evt_marriage_zoroastrian_group
	is_triggered_only = yes
	hide_from = yes

	option = {
		name = OK
		if = {
			limit = { is_ruler = yes }
			set_secret_religion = zoroastrian
			set_character_flag = convert_secret
			convert_religion_failsafe_effect = yes
		}
		else = { religion = zoroastrian }
		any_demesne_title = {
			limit = { tier = count }
			location = { religion = zoroastrian }
		}
	}
}

# Tengri
character_event = {
	id = ancrel.9009
	desc = ancrel.9009.desc
	picture = "GFX_evt_mongols"
	border = "GFX_event_normal_frame_war"

	is_triggered_only = yes
	hide_from = yes

	option = {
		name = OK
		if = {
			limit = { is_ruler = yes }
			set_secret_religion = tengri_pagan
			set_character_flag = convert_secret
			convert_religion_failsafe_effect = yes
		}
		else = { religion = tengri_pagan }
		any_demesne_title = {
			limit = { tier = count }
			location = { religion = tengri_pagan }
		}
	}
}

#[on_startup] maintenance event
character_event = {
	id = ancrel.9010
	hide_window = yes

	is_triggered_only = yes

	religion = catholic
	
	trigger = {
		controls_religion = yes # Let it happen for the Pope. He's always around.
		NOT = { has_global_flag = ancrel }
	}

	immediate = {
		set_global_flag = ancrel
		if = {
			limit = {
				OR = {
					has_game_rule = {
						name = acr_pagan_papal
						value = cardinals
					}
					has_game_rule = {
						name = acr_pagan_papal
						value = both
					}
				}
			}
			set_global_flag = acr_pagan_papal
		}
		if = {
			limit = {
				OR = {
					has_game_rule = {
						name = acr_pagan_papal
						value = antipopes
					}
					has_game_rule = {
						name = acr_pagan_papal
						value = both
					}
				}
			}
			set_global_flag = acr_pagan_antipopes
		}
		if = {
			limit = {
				has_game_rule = {
					name = acr_holy_order_cardinals
					value = on
				}
			}
			set_global_flag = acr_holy_order_cardinals
		}
		if = {
			limit = {
				has_game_rule = {
					name = acr_mpb
					value = on
				}
			}
			set_global_flag = acr_mpb
		}
	}
}

# Bon
character_event = {
	id = ancrel.9011
	desc = ancrel.9011.desc
	picture = GFX_evt_meditating_in_temple

	is_triggered_only = yes
	hide_from = yes

	option = {
		name = OK
		if = {
			limit = { is_ruler = yes }
			set_secret_religion = bon_pagan
			set_character_flag = convert_secret
			convert_religion_failsafe_effect = yes
		}
		else = { religion = bon_pagan }
		any_demesne_title = {
			limit = { tier = count }
			location = { religion = bon_pagan }
		}
	}
}

# Titan
character_event = {
	id = ancrel.9012
	desc = ancrel.9012.desc
	picture = GFX_evt_cathedral_norse_pagan
	hide_from = yes

	is_triggered_only = yes

	option = {
		name = OK
		if = {
			limit = { is_ruler = yes }
			set_secret_religion = titan_pagan
			set_character_flag = convert_secret
			convert_religion_failsafe_effect = yes
		}
		else = { religion = titan_pagan }
		any_demesne_title = {
			limit = { tier = count }
			location = { religion = titan_pagan }
		}
	}
}

# Zun
character_event = {
	id = ancrel.9013
	desc = ancrel.9013.desc
	picture = GFX_evt_temple_egyptian_pagan
	is_triggered_only = yes
	hide_from = yes

	option = {
		name = OK
		if = {
			limit = { is_ruler = yes }
			set_secret_religion = zun_pagan
			set_character_flag = convert_secret
			convert_religion_failsafe_effect = yes
		}
		else = { religion = zun_pagan }
		any_demesne_title = {
			limit = { tier = count }
			location = { religion = zun_pagan }
		}
	}
}

# free a religious head's vassals count and above
character_event = {
	id = ancrel.9014
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		any_vassal = {
			limit = {
				primary_title = {
					higher_tier_than = BARON
				}
			}
			set_defacto_liege = THIS
		}
	}
}

##############################################
#
# Ancient Religions Reborn
# - Debugging Events
#
# Event Ids: ancrel.9001 - 9100 reserved
##############################################

# set the ancrel_debug global flag for testing
# some events and decisions may check this flag
# and alter their behavior to make testing easier
character_event = {
	id = ancrel.9015
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		set_global_flag = ancrel_debug
	}
}

# debugging event to end all wars
character_event = {
	id = ancrel.9016
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		any_war = {
			end_war = whitepeace
		}
	}
}

# Arriving for the great holy war - Non-Hellenic Ancient Religions
character_event = {
	id = ancrel.9017
	desc = EVTDESC8300
	picture = GFX_evt_battle
	border = GFX_event_normal_frame_war
	
	min_age = 16
	capable_only = yes
	prisoner = no
	
	trigger = {
		has_crusade_trait_trigger = no
		in_command = yes
		is_ancient_religion_trigger = yes
		religion_openly_hellenic_or_reformed_trigger = no # vanilla event covers hellenic
		OR = {
			AND = {
				any_war = {
					using_cb = crusade
				}
				crusade_target = {
					is_located_in = ROOT
				}
			}
			any_liege = {
				religion = ROOT
				any_war = {
					using_cb = crusade
				}
				crusade_target = {
					is_located_in = ROOT
				}
			}
		}
	}

	mean_time_to_happen = {
		days = 1
	}
	
	option = {
		name = 8469.a
		trigger = {
			religion_openly_in_celtic_subgroup_trigger = yes
		}
		add_trait = lughs_own
	}

	option = {
		name = 8469.a
		trigger = {
			religion = egyptian_pagan
		}
		add_trait = montu
	}

	option = {
		name = 8469.a
		trigger = {
			religion = aten_pagan
		}
		add_trait = atens_chosen
	}

	option = {
		name = 8469.a
		trigger = {
			NOR = {
				religion_openly_in_celtic_subgroup_trigger = yes
				religion = aten_pagan
				religion = egyptian_pagan
			}
		}
	}
}

# debug to grant all provinces in your dejure kingdom to you, including the king title
character_event = {
	id = ancrel.9020
	hide_window = yes
	
	is_triggered_only = yes
	
	has_global_flag = ancrel_debug

	immediate = {
		capital_scope = {
			kingdom = {
				save_event_target_as = ancrel_title_grant
				ROOT = { 
					grant_title_no_opinion = PREV
				}
			}
		}
	}
	
	after = {
		any_character = {
			limit = {
				NOT = { character = ROOT }
				is_landed = yes
				primary_title = { higher_real_tier_than = BARON }
				de_jure_liege_or_above = event_target:ancrel_title_grant
			}
			any_realm_province = {
				county = {
					ROOT = { 
						grant_title_no_opinion = PREV
					}
				}
			}
		}
	}
}

# debug to grant you the de jure empire of your capital and vassalize de jure vassals
character_event = {
	id = ancrel.9021
	hide_window = yes

	is_triggered_only = yes
	
	has_global_flag = ancrel_debug

	immediate = {
		capital_scope = {
			empire = {
				save_event_target_as = ancrel_title_grant
				grant_title_no_opinion = ROOT
				#ROOT = { 
				#	grant_title_no_opinion = PREV
				#}
			}
		}
	}
	
	after = {
		any_independent_ruler = {
			limit = {
				de_jure_liege_or_above = event_target:ancrel_title_grant
			}
			set_defacto_liege = ROOT
		}
	}
}

# debug to convert all characters and provinces in your realm to your religion and culture
character_event = {
	id = ancrel.9022
	hide_window = yes

	is_triggered_only = yes

	
	has_global_flag = ancrel_debug

	immediate = {
		any_realm_character = {
			#religion = ROOT
			if = {
				limit = { is_ruler = yes }
				set_secret_religion = ROOT
				set_character_flag = convert_secret
				convert_religion_failsafe_effect = yes
			}
			else = { religion = ROOT }
			culture = ROOT
		}

		any_realm_province = {
			religion = ROOT
			culture = ROOT
		}
	}
}

# migration event, fired [on_start], smooths over issues with save files between versions
character_event = {
	id = ancrel.9023
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		NOT = { has_global_flag = ancrel_sequana }
	}

	immediate = {
		set_global_flag = ancrel_sequana
		if = {
			limit = {
				has_global_flag = celtic_reformation
			}

			any_mercenary_band = {
				limit = {
					holy_order = yes
					holder_scope = { religion = celtic_pagan }
				}

				religion = celtic_pagan_reformed
			}
		}
		if = {
			limit = {
				has_global_flag = egyptian_reformation
			}

			any_mercenary_band = {
				limit = {
					holy_order = yes
					holder_scope = { religion = egyptian_pagan }
				}

				religion = egyptian_pagan_reformed
			}
		}
		if = {
			limit = {
				has_global_flag = hellenic_reformation
			}

			any_mercenary_band = {
				limit = {
					holy_order = yes
					holder_scope = { religion = hellenic_pagan }
				}

				religion = hellenic_pagan_reformed
			}
		}
	}
}
