﻿namespace = NEOW_religious_decision

NEOW_religious_decision.0001 = { #custom patron gods for Leviathan
	type = character_event
	title = NEOW_religious_decision.0001.t
	desc = NEOW_religious_decision.0001.desc
	theme = faith
	left_portrait = {
		character = root
		animation = personality_rational
	}

	option = {
		name = NEOW_religious_decision.0001.nationalisators
		trigger = {
			NOT = { has_character_modifier = bhakti_leviathan_nationalisators }
		}
		NEOW_set_bhakti_effect = { BHAKTI = bhakti_leviathan_nationalisators }
	}

	option = {
		name = NEOW_religious_decision.0001.technosaurs
		trigger = {
			NOT = { has_character_modifier = bhakti_leviathan_technosaurs }
		}
		NEOW_set_bhakti_effect = { BHAKTI = bhakti_leviathan_technosaurs }
	}

	option = {
		name = NEOW_religious_decision.0001.mechasaurs
		trigger = {
			NOT = { has_character_modifier = bhakti_leviathan_mechasaurs }
		}
		NEOW_set_bhakti_effect = { BHAKTI = bhakti_leviathan_mechasaurs }
	}

	option = {
		name = NEOW_religious_decision.0001.petrosaurs
		trigger = {
			NOT = { has_character_modifier = bhakti_leviathan_petrosaurs }
		}
		NEOW_set_bhakti_effect = { BHAKTI = bhakti_leviathan_petrosaurs }
	}

	option = {
		name = NEOW_religious_decision.0001.metallurgicals
		trigger = {
			NOT = { has_character_modifier = bhakti_leviathan_metallurgicals }
		}
		NEOW_set_bhakti_effect = { BHAKTI = bhakti_leviathan_metallurgicals }
	}
	
	option = {
		name = NEOW_religious_decision.0001.nautiluses
		trigger = {
			NOT = { has_character_modifier = bhakti_leviathan_nautiluses }
		}
		NEOW_set_bhakti_effect = { BHAKTI = bhakti_leviathan_nautiluses }
	}

	option = {
		name = NEOW_religious_decision.0001.aerosaurs
		trigger = {
			NOT = { has_character_modifier = bhakti_leviathan_aerosaurs }
		}
		NEOW_set_bhakti_effect = { BHAKTI = bhakti_leviathan_aerosaurs }
	}

	# Opt-Out
	option = {
		name = NEOW_religious_decision.0001.optout
		flavor = NEOW_religious_decision.0001.flavor

		ai_chance = {
			base = 0
		}
	}
}

NEOW_religious_decision.0103 = { #custom patron gods for Leviathan
	type = character_event
	title = NEOW_religious_decision.0103.t
	desc = NEOW_religious_decision.0103.desc
	theme = faith
	left_portrait = {
		character = root
		animation = personality_rational
	}

	option = {
		name = NEOW_religious_decision.0103.jesus
		trigger = {
			NOT = { has_character_modifier = bhakti_folketero_jesus }
		}
		NEOW_set_bhakti_effect = { BHAKTI = bhakti_folketero_jesus }
	}

	option = {
		name = NEOW_religious_decision.0103.per
		trigger = {
			NOT = { has_character_modifier = bhakti_folketero_per }
		}
		NEOW_set_bhakti_effect = { BHAKTI = bhakti_folketero_per }
	}

	option = {
		name = NEOW_religious_decision.0103.lucia
		trigger = {
			NOT = { has_character_modifier = bhakti_folketero_lucia }
		}
		NEOW_set_bhakti_effect = { BHAKTI = bhakti_folketero_lucia }
	}

	option = {
		name = NEOW_religious_decision.0103.olaf
		trigger = {
			NOT = { has_character_modifier = bhakti_folketero_olaf }
		}
		NEOW_set_bhakti_effect = { BHAKTI = bhakti_folketero_olaf }
	}

	# Opt-Out
	option = {
		name = NEOW_religious_decision.0001.optout
		flavor = NEOW_religious_decision.0001.flavor

		ai_chance = {
			base = 0
		}
	}
}

NEOW_religious_decision.0104 = { #custom icons for orthodoxy
	type = character_event
	title = NEOW_religious_decision.0104.t
	desc = NEOW_religious_decision.0104.desc
	theme = faith
	left_portrait = {
		character = root
		animation = personality_rational
	}

	option = {
		name = NEOW_religious_decision.0104.paisos
		trigger = {
			NOT = { has_character_modifier = bhakti_orthodox_paisos }
		}
		NEOW_set_bhakti_effect = { BHAKTI = bhakti_orthodox_paisos}
	}

	option = {
		name = NEOW_religious_decision.0104.gabriel
		trigger = {
			NOT = { has_character_modifier = bhakti_orthodox_gabriel }
		}
		NEOW_set_bhakti_effect = { BHAKTI = bhakti_orthodox_gabriel }
	}

	option = {
		trigger = { is_vaguely_nistrenian_bhakti_trigger = yes }	
		name = NEOW_religious_decision.0104.adriana
		trigger = {
			NOT = { has_character_modifier = bhakti_orthodox_adriana }
		}
		NEOW_set_bhakti_effect = { BHAKTI = bhakti_orthodox_adriana }
	}

	option = {
		trigger = { is_vaguely_nistrenian_bhakti_trigger = no }	
		name = NEOW_religious_decision.0104.olga
		trigger = {
			NOT = { has_character_modifier = bhakti_orthodox_olga }
		}
		NEOW_set_bhakti_effect = { BHAKTI = bhakti_orthodox_olga }
	}

	option = {
		name = NEOW_religious_decision.0104.palamas
		trigger = {
			NOT = { has_character_modifier = bhakti_orthodox_palamas }
		}
		NEOW_set_bhakti_effect = { BHAKTI = bhakti_orthodox_palamas }
	}
	option = {
		name = NEOW_religious_decision.0104.surgeon
		trigger = {
			NOT = { has_character_modifier = bhakti_orthodox_surgeon }
		}
		NEOW_set_bhakti_effect = { BHAKTI = bhakti_orthodox_surgeon }
	}

	option = {
		name = NEOW_religious_decision.0104.lazar
		trigger = {
			NOT = { has_character_modifier = bhakti_orthodox_lazar }
		}
		NEOW_set_bhakti_effect = { BHAKTI = bhakti_orthodox_lazar }
	}

	option = {
		name = NEOW_religious_decision.0104.theotokos
		trigger = {
			NOT = { has_character_modifier = bhakti_orthodox_theotokos }
		}
		NEOW_set_bhakti_effect = { BHAKTI = bhakti_orthodox_theotokos }
	}
	# Opt-Out
	option = {
		name = NEOW_religious_decision.0001.optout
		flavor = NEOW_religious_decision.0001.flavor

		ai_chance = {
			base = 0
		}
	}
}

NEOW_religious_decision.0200 = { #restoring the patriarch
	type = character_event
	title = NEOW_religious_decision.0200.t
	desc = NEOW_religious_decision.0200.desc
	theme = faith
	override_background = { reference = ep3_hagia_sophia }
	override_effect_2d = {
		reference = legend_glow
	}
	left_portrait = {
		character = root
		animation = prayer
	}
	right_portrait = {
		character = scope:new_patriarch
		animation = wedding_priest
	}

	option = {
		name = NEOW_religious_decision.0200.a
	}
}
NEOW_religious_decision.0201 = { # Restoring the Patriarch
	type = character_event
	title = NEOW_religious_decision.0201.t
	desc = NEOW_religious_decision.0201.desc
	theme = faith

	override_background = {
		reference = ep3_hagia_sophia
	}

	override_effect_2d = {
		reference = legend_glow
	}

	left_portrait = {
		character = root
		animation = prayer
	}

	right_portrait = {
		character = scope:new_patriarch
		animation = wedding_priest
	}

	immediate = {
		# Give Russian Orthodoxy the doctrine that enables GHWs
		faith:russian_orthodox = {
			remove_doctrine = special_doctrine_not_allowed_to_hof

			# Unlock the GHW system for this faith's religion
			religion = {
				set_variable = {
					name = variable_ghw_unlocked
					value = yes
				}
			}
		}
	}

	option = {
		name = NEOW_religious_decision.0201.a
	}
}

NEOW_religious_decision.0202 = { # An ecclesiarch restores the See of Saint Andrew
	type = character_event
	title = NEOW_religious_decision.0202.t
	desc = NEOW_religious_decision.0202.desc
	theme = faith
	override_background = { reference = ep3_hagia_sophia }
	override_effect_2d = { reference = legend_glow }
	left_portrait = {
		character = root
		animation = prayer
	}

	option = {
		name = NEOW_religious_decision.0202.a
	}
}

NEOW_religious_decision.0203 = { # Proclamation of the Athonite Empire
	type = character_event
	title = NEOW_religious_decision.0203.t
	desc = NEOW_religious_decision.0203.desc
	theme = faith
	override_effect_2d = { reference = legend_glow }
	left_portrait = {
		character = root
		animation = prayer
	}

	option = {
		name = NEOW_religious_decision.0203.a
	}
}

NEOW_religious_decision.0210 = {
	type = character_event
	title = NEOW_religious_decision.0210.t
	desc = NEOW_religious_decision.0210.desc
	theme = faith

	left_portrait = {
		character = root
		animation = personality_rational
	}

	option = {
		name = NEOW_religious_decision.0210.a

		# Enter communion with the victorious Patriarchate.
		set_character_faith_with_conversion = scope:reunited_orthodox_faith

		# The base-game schism reunion also brings the ruler's own counties
		# into the communion whose hierarchy the ruler has recognised.
		every_held_title = {
			limit = { title_tier = county }
			set_county_faith = scope:reunited_orthodox_faith
		}

		ai_chance = {
			base = 75

			modifier = {
				add = 25
				has_trait = zealous
			}

			modifier = {
				add = -50
				has_trait = stubborn
			}

			modifier = {
				add = -75
				has_trait = cynical
			}
		}
	}

	option = {
		name = NEOW_religious_decision.0210.b

		ai_chance = {
			base = 25
		}
	}
}
NEOW_religious_decision.0211 = {
	type = character_event
	title = NEOW_religious_decision.0211.t
	desc = NEOW_religious_decision.0211.desc
	theme = faith

	override_background = {
		reference = ep3_hagia_sophia
	}

	override_effect_2d = {
		reference = legend_glow
	}

	left_portrait = {
		character = root
		animation = prayer
	}

	option = {
		name = NEOW_religious_decision.0211.a
	}
}

# The Tribunal's two stages are private big-window events.  Major events broadcast
# to multiple characters and must not be used for choices that alter world state.
NEOW_religious_decision.0230 = {
    type = character_event
    window = big_event_window
    title = NEOW_religious_decision.0230.t
    desc = NEOW_religious_decision.0230.desc
    theme = christian
    override_background = { reference = council_chamber }
    override_effect_2d = { reference = legend_glow }
    left_portrait = { character = root animation = personality_rational }

    trigger = {
        has_character_flag = neow_tribunal_trial_pending
        NOT = { has_character_flag = neow_tribunal_verdict_reached }
    }

    option = {
        name = NEOW_religious_decision.0230.a
        ai_chance = { base = 50 }
        # Apply the sentence to the CURRENT holders before their titles are
        # destroyed. Do not rely on saved portrait/event scopes here.
        if = {
            limit = {
                exists = title:k_papal_state.holder
                title:k_papal_state.holder = { is_alive = yes }
            }
            title:k_papal_state.holder = {
                death = { death_reason = death_execution killer = root }
            }
        }
        if = {
            limit = {
                exists = title:k_compostelan_papacy.holder
                title:k_compostelan_papacy.holder = { is_alive = yes }
            }
            title:k_compostelan_papacy.holder = {
                death = { death_reason = death_execution killer = root }
            }
        }
        neow_tribunal_abolish_rival_papacies_effect = yes
        add_character_flag = neow_tribunal_executed_false_popes
        add_character_flag = neow_tribunal_verdict_reached
        trigger_event = { id = NEOW_religious_decision.0231 days = 1 }
    }

    option = {
        name = NEOW_religious_decision.0230.b
        ai_chance = { base = 50 }
        neow_tribunal_abolish_rival_papacies_effect = yes
        add_character_flag = neow_tribunal_deposed_false_popes
        add_character_flag = neow_tribunal_verdict_reached
        trigger_event = { id = NEOW_religious_decision.0231 days = 1 }
    }
}

# Only the ruler who convened the Tribunal chooses the new papal seat. A flag
# set on delivery prevents multiple queued copies in existing saved games.
NEOW_religious_decision.0231 = {
    type = character_event
    window = big_event_window
    title = NEOW_religious_decision.0231.t
    desc = NEOW_religious_decision.0231.desc
    theme = christian
    override_background = { reference = temple_church }
    override_effect_2d = { reference = legend_glow }
    left_portrait = { character = root animation = prayer }
    right_portrait = {
        character = scope:neow_tribunal_new_pope
        animation = wedding_priest
    }

    trigger = {
        has_character_flag = neow_tribunal_verdict_reached
        NOT = { has_character_flag = neow_tribunal_papal_seat_event_opened }
        NOT = { has_character_flag = neow_tribunal_papacy_restored }
        title:k_catholic_tribunal = { is_title_created = no }
    }

    immediate = {
        add_character_flag = neow_tribunal_papal_seat_event_opened
        if = {
            limit = {
                exists = global_var:neow_catholic_tribunal_jozef
                global_var:neow_catholic_tribunal_jozef = {
                    is_alive = yes
                    faith = faith:catholic_tribunal_faith
                }
            }
            global_var:neow_catholic_tribunal_jozef = {
                save_scope_as = neow_tribunal_new_pope
            }
        }
        else = {
            create_character = {
                template = religious_leader_character
                random_traits = no
                faith = faith:catholic_tribunal_faith
                culture = culture:bavarian
                save_scope_as = neow_tribunal_new_pope
            }
            scope:neow_tribunal_new_pope = {
                add_trait = education_learning_3
                add_trait = zealous
            }
        }
    }

    option = {
        name = NEOW_religious_decision.0231.a
        ai_chance = { base = 60 }
        neow_tribunal_install_restored_pope_effect = yes
        title:k_catholic_tribunal = {
            set_capital_county = title:c_roma
            set_title_name = neow_tribunal_papacy_rome
            set_variable = { name = neow_tribunal_papal_seat_rome value = yes }
        }
        add_character_flag = neow_tribunal_papacy_restored
        remove_character_flag = neow_tribunal_trial_pending
    }
    option = {
        name = NEOW_religious_decision.0231.b
        ai_chance = { base = 38 }
        neow_tribunal_install_restored_pope_effect = yes
        # San Diego is absent from the supplied county map; use a named see.
        title:k_catholic_tribunal = {
            set_title_name = neow_tribunal_papacy_san_diego
            set_variable = { name = neow_tribunal_papal_seat_san_diego value = yes }
        }
        add_character_flag = neow_tribunal_papacy_restored
        remove_character_flag = neow_tribunal_trial_pending
    }
    option = {
        name = NEOW_religious_decision.0231.c
        ai_chance = { base = 2 }
        neow_tribunal_install_restored_pope_effect = yes
        title:k_catholic_tribunal = {
            set_capital_county = title:c_vaucluse
            set_title_name = neow_tribunal_papacy_avignon
            set_variable = { name = neow_tribunal_papal_seat_avignon value = yes }
        }
        add_character_flag = neow_tribunal_papacy_restored
        remove_character_flag = neow_tribunal_trial_pending
    }
}
