﻿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
	window = big_event_window
	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
	window = big_event_window
	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
	window = big_event_window
	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
	window = big_event_window
	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
    }
}

# The Synod first disposes of the reigning Roman Pope, then enthrones the
# preserved body. Choices are local big-window events to avoid repeated effects.
NEOW_religious_decision.0240 = {
    type = character_event
    window = big_event_window
    title = NEOW_religious_decision.0240.t
    desc = NEOW_religious_decision.0240.desc
    theme = christian
    override_background = { reference = temple_church }
    left_portrait = { character = root animation = personality_rational }

    trigger = {
        has_character_flag = neow_cadaverist_enthronement_pending
        NOT = { has_global_variable = neow_cadaverist_enthronement_complete }
    }

    option = {
        name = NEOW_religious_decision.0240.a
        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 = { title:k_papal_state = { is_title_created = yes } }
            destroy_title = title:k_papal_state
        }
        faith:roman_catholic_faith = { remove_religious_head_title = yes }
        trigger_event = { id = NEOW_religious_decision.0241 days = 1 }
    }
}

NEOW_religious_decision.0241 = {
    type = character_event
    window = big_event_window
    title = NEOW_religious_decision.0241.t
    desc = NEOW_religious_decision.0241.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_cadaverist_ecclesiarch animation = wedding_priest }

    trigger = {
        has_character_flag = neow_cadaverist_enthronement_pending
        NOT = { has_global_variable = neow_cadaverist_enthronement_complete }
    }

    immediate = {
        # Reuse the current Ecclesiarch if the Cadaverist Synod already exists.
        if = {
            limit = {
                title:k_cadaverist_synod = { is_title_created = yes }
                exists = title:k_cadaverist_synod.holder
                title:k_cadaverist_synod.holder = { is_alive = yes }
            }
            title:k_cadaverist_synod.holder = {
                save_scope_as = neow_cadaverist_ecclesiarch
            }
        }
        else = {
            # In games without a Synod holder, elect an ordinary living
            # Cadaverist priest. John Paul II is never created as a character.
            create_character = {
                template = religious_leader_character
                random_traits = no
                culture = root.culture
                faith = faith:cadaverist_faith
                rite = cadaverist_rite
                save_scope_as = neow_cadaverist_ecclesiarch
            }
            scope:neow_cadaverist_ecclesiarch = {
                add_trait = education_learning_3
                add_trait = zealous
            }
        }
    }

    option = {
        name = NEOW_religious_decision.0241.a
        # John Paul II's remains sit on the ceremonial throne. The living
        # Ecclesiarch remains the Head of Faith through the Cadaverist Synod.
        create_title_and_vassal_change = {
            type = created
            save_scope_as = neow_cadaverist_title_change
            add_claim_on_loss = no
        }
        title:k_cadaverist_synod = {
            change_title_holder = {
                holder = scope:neow_cadaverist_ecclesiarch
                change = scope:neow_cadaverist_title_change
            }
            set_capital_county = title:c_roma
        }
        resolve_title_and_vassal_change = scope:neow_cadaverist_title_change

        faith:cadaverist_faith = {
            if = {
                limit = { has_doctrine = special_doctrine_not_allowed_to_hof }
                remove_doctrine = special_doctrine_not_allowed_to_hof
            }
            set_religious_head_title = title:k_cadaverist_synod
            change_fervor = {
                value = 25
                desc = NEOW_cadaverist_restoration_fervor_gain
            }
        }

        province:2577 = {
            if = {
                limit = { has_building = st_peters_basilica_01 }
                remove_building = st_peters_basilica_01
            }
            if = {
                limit = { NOT = { has_building = neow_vatican_bone_temple_01 } }
                add_special_building = neow_vatican_bone_temple_01
            }
        }
        title:b_vaticano = { set_title_name = neow_vatican_ossuary_title }
        add_piety = 1000
        add_prestige = 500
        set_global_variable = {
            name = neow_cadaverist_enthronement_complete
            value = yes
        }
        add_character_flag = neow_cadaverist_enthronement_complete
        remove_character_flag = neow_cadaverist_enthronement_pending
        # Only proclaim universal obedience after the Ecclesiarch is installed.
        neow_cadaverist_submit_catholic_world_effect = yes
    }
}


# A human Catholic ruler receives a personal, non-broadcast choice when the
# Tribunal claims communion across the Catholic world.
NEOW_religious_decision.0250 = {
    type = character_event
    window = big_event_window
    title = NEOW_religious_decision.0250.t
    desc = NEOW_religious_decision.0250.desc
    theme = christian
    override_background = { reference = temple_church }
    left_portrait = { character = root animation = prayer }

    trigger = {
        is_ai = no
        faith = { religion = religion:catholic_religion }
        OR = {
            faith != faith:catholic_tribunal_faith
            rite != rite:catholic_tribunal_rite
        }
    }

    option = {
        name = NEOW_religious_decision.0250.a
        faith:catholic_tribunal_faith = { save_scope_as = neow_united_papacy_faith }
        rite:catholic_tribunal_rite = { save_scope_as = neow_united_papacy_rite }
        neow_restored_papacy_convert_catholic_ruler_effect = yes
        neow_restored_papacy_convert_held_catholic_counties_effect = yes
    }
    option = {
        name = NEOW_religious_decision.0250.b
    }
}

# The Cadaverist Synod invites the same submission after its own enthronement.
NEOW_religious_decision.0251 = {
    type = character_event
    window = big_event_window
    title = NEOW_religious_decision.0251.t
    desc = NEOW_religious_decision.0251.desc
    theme = christian
    override_background = { reference = temple_church }
    left_portrait = { character = root animation = prayer }

    trigger = {
        is_ai = no
        faith = { religion = religion:catholic_religion }
        OR = {
            faith != faith:cadaverist_faith
            rite != rite:cadaverist_rite
        }
    }

    option = {
        name = NEOW_religious_decision.0251.a
        faith:cadaverist_faith = { save_scope_as = neow_united_papacy_faith }
        rite:cadaverist_rite = { save_scope_as = neow_united_papacy_rite }
        neow_restored_papacy_convert_catholic_ruler_effect = yes
        neow_restored_papacy_convert_held_catholic_counties_effect = yes
    }
    option = {
        name = NEOW_religious_decision.0251.b
    }
}


NEOW_religious_decision.0260 = {
    type = character_event
    window = big_event_window
    title = NEOW_religious_decision.0260.t
    desc = NEOW_religious_decision.0260.desc
    theme = faith
    override_background = { reference = temple_church }
    override_effect_2d = { reference = legend_glow }
    left_portrait = { character = root animation = prayer }

    trigger = {
        faith = faith:orthodox
        has_global_variable = neow_western_orthodox_rite_established
    }

    option = {
        name = NEOW_religious_decision.0260.a
        trigger_event = NEOW_religious_decision.0262
    }
}

NEOW_religious_decision.0261 = {
    type = character_event
    window = big_event_window
    title = NEOW_religious_decision.0261.t
    desc = NEOW_religious_decision.0261.desc
    theme = christian
    override_background = { reference = temple_church }
    left_portrait = { character = root animation = prayer }

    trigger = {
        is_ai = no
        faith = { religion = religion:catholic_religion }
        NOT = { any_held_title = { is_head_of_faith = yes } }
    }

    option = {
        name = NEOW_religious_decision.0261.a
        neow_western_orthodox_convert_catholic_ruler_effect = yes
    }
    option = {
        name = NEOW_religious_decision.0261.b
    }
}

NEOW_religious_decision.0262 = {
    type = character_event
    window = big_event_window
    title = NEOW_religious_decision.0262.t
    desc = NEOW_religious_decision.0262.desc
    theme = faith
    override_background = { reference = temple_church }
    left_portrait = { character = root animation = prayer }

    trigger = {
        faith = faith:orthodox
        has_global_variable = neow_western_orthodox_rite_established
    }

    option = {
        name = NEOW_religious_decision.0262.a
        ai_chance = { base = 50 }
        set_character_rite = rite:western_orthodox_rite
        remove_variable = neow_rome_founder_original_rite
    }
    option = {
        name = NEOW_religious_decision.0262.b
        ai_chance = { base = 50 }
        # Refusal is an explicit restoration, not a no-op. This protects
        # against implicit conversion while the rite was being established.
        if = {
            limit = { has_variable = neow_rome_founder_original_rite }
            set_character_rite = var:neow_rome_founder_original_rite
        }
        remove_variable = neow_rome_founder_original_rite
    }
}
