﻿namespace = NEOW_restoration

# Christian recovery of Britain, Nistrenian imperial conquests, and the five apostolic sees.
# Checked on the yearly playable-ruler pulse, as with the vanilla Roman restoration flavour.
# The global flags make each milestone occur once per campaign.

# Nistrenia: Moscow Reclaimed
NEOW_restoration.0001 = {
    type = character_event
    window = big_event_window
    title = NEOW_restoration.0001.t
    desc = NEOW_restoration.0001.desc
    theme = realm
    override_background = { reference = ep3_city_gate }
    override_effect_2d = { reference = legend_glow }
    left_portrait = {
        character = root
        animation = personality_honorable
    }

    trigger = {
        is_ai = no
        is_ruler = yes
        neow_restoration_nistrenian_ruler_trigger = yes
        NOT = { has_global_variable = flag_NEOW_restoration_0001 }
        NOT = { has_character_flag = flag_NEOW_restoration_cooldown }
        title:c_moskva.holder.top_liege = root
    }

    immediate = {
        play_music_cue = "mx_cue_epic_sacral_moment"
        set_global_variable = {
            name = flag_NEOW_restoration_0001
            value = root
        }
        add_character_flag = {
            flag = flag_NEOW_restoration_cooldown
            days = 60
        }
    }

    option = {
        name = NEOW_restoration.0001.a
        trigger_event = { id = NEOW_restoration.9000 days = 75 }
        add_prestige = major_prestige_gain
    }
}

# Nistrenia: The City on the Neva
NEOW_restoration.0002 = {
    type = character_event
    window = big_event_window
    title = NEOW_restoration.0002.t
    desc = NEOW_restoration.0002.desc
    theme = realm
    override_background = { reference = docks }
    override_effect_2d = { reference = legend_glow }
    left_portrait = {
        character = root
        animation = personality_honorable
    }

    trigger = {
        is_ai = no
        is_ruler = yes
        neow_restoration_nistrenian_ruler_trigger = yes
        NOT = { has_global_variable = flag_NEOW_restoration_0002 }
        NOT = { has_character_flag = flag_NEOW_restoration_cooldown }
        title:c_petrograd.holder.top_liege = root
    }

    immediate = {
        play_music_cue = "mx_cue_epic_sacral_moment"
        set_global_variable = {
            name = flag_NEOW_restoration_0002
            value = root
        }
        add_character_flag = {
            flag = flag_NEOW_restoration_cooldown
            days = 60
        }
    }

    option = {
        name = NEOW_restoration.0002.a
        trigger_event = { id = NEOW_restoration.9000 days = 75 }
        add_prestige = major_prestige_gain
    }
}

# Nistrenia: The Queen of Cities
NEOW_restoration.0003 = {
    type = character_event
    window = big_event_window
    title = NEOW_restoration.0003.t
    desc = NEOW_restoration.0003.desc
    theme = realm
    override_background = { reference = ep3_constantinople }
    override_effect_2d = { reference = legend_glow }
    left_portrait = {
        character = root
        animation = personality_honorable
    }

    trigger = {
        is_ai = no
        is_ruler = yes
        neow_restoration_nistrenian_ruler_trigger = yes
        NOT = { has_global_variable = flag_NEOW_restoration_0003 }
        NOT = { has_character_flag = flag_NEOW_restoration_cooldown }
        title:c_byzantion.holder.top_liege = root
    }

    immediate = {
        play_music_cue = "mx_cue_epic_sacral_moment"
        set_global_variable = {
            name = flag_NEOW_restoration_0003
            value = root
        }
        add_character_flag = {
            flag = flag_NEOW_restoration_cooldown
            days = 60
        }
    }

    option = {
        name = NEOW_restoration.0003.a
        trigger_event = { id = NEOW_restoration.9000 days = 75 }
        add_prestige = major_prestige_gain
    }
}

# Nistrenia: The Eternal City
NEOW_restoration.0004 = {
    type = character_event
    window = big_event_window
    title = NEOW_restoration.0004.t
    desc = NEOW_restoration.0004.desc
    theme = realm
    override_background = { reference = pam_papal_throne_room_interior }
    override_effect_2d = { reference = legend_glow }
    left_portrait = {
        character = root
        animation = personality_honorable
    }

    trigger = {
        is_ai = no
        is_ruler = yes
        neow_restoration_nistrenian_ruler_trigger = yes
        NOT = { has_global_variable = flag_NEOW_restoration_0004 }
        NOT = { has_character_flag = flag_NEOW_restoration_cooldown }
        OR = {
            title:c_roma.holder.top_liege = root
            title:c_roma_urbs.holder.top_liege = root
        }
    }

    immediate = {
        play_music_cue = "mx_cue_epic_sacral_moment"
        set_global_variable = {
            name = flag_NEOW_restoration_0004
            value = root
        }
        add_character_flag = {
            flag = flag_NEOW_restoration_cooldown
            days = 60
        }
    }

    option = {
        name = NEOW_restoration.0004.a
        trigger_event = { id = NEOW_restoration.9000 days = 75 }
        add_prestige = major_prestige_gain
    }
}

# Nistrenia: The Ruins of Thessaloniki, former capital of Makedon
NEOW_restoration.0005 = {
    type = character_event
    window = big_event_window
    title = NEOW_restoration.0005.t
    desc = NEOW_restoration.0005.desc
    theme = realm
    override_background = { reference = burning_building }
    override_effect_2d = { reference = legend_glow }
    left_portrait = {
        character = root
        animation = personality_honorable
    }

    trigger = {
        is_ai = no
        is_ruler = yes
        neow_restoration_nistrenian_ruler_trigger = yes
        NOT = { has_global_variable = flag_NEOW_restoration_0005 }
        NOT = { has_character_flag = flag_NEOW_restoration_cooldown }
        title:c_thessalonika.holder.top_liege = root
    }

    immediate = {
        play_music_cue = "mx_cue_epic_sacral_moment"
        set_global_variable = {
            name = flag_NEOW_restoration_0005
            value = root
        }
        add_character_flag = {
            flag = flag_NEOW_restoration_cooldown
            days = 60
        }
    }

    option = {
        name = NEOW_restoration.0005.a
        trigger_event = { id = NEOW_restoration.9000 days = 75 }
        add_prestige = major_prestige_gain
    }
}

# Orthodox Pentarchy: The See of Antioch
NEOW_restoration.0101 = {
    type = character_event
    window = big_event_window
    title = NEOW_restoration.0101.t
    desc = NEOW_restoration.0101.desc
    theme = christian
    override_background = { reference = temple_church }
    override_effect_2d = { reference = legend_glow }
    left_portrait = {
        character = root
        animation = personality_zealous
    }

    trigger = {
        is_ai = no
        is_ruler = yes
        neow_restoration_nistrenian_ruler_trigger = yes
        religion = religion:eastern_orthodox_religion
        NOT = { has_global_variable = flag_NEOW_restoration_0101 }
        NOT = { has_character_flag = flag_NEOW_restoration_cooldown }
        title:c_antiocheia.holder.top_liege = root
    }

    immediate = {
        play_music_cue = "mx_cue_sacredrite"
        set_global_variable = {
            name = flag_NEOW_restoration_0101
            value = root
        }
        add_character_flag = {
            flag = flag_NEOW_restoration_cooldown
            days = 60
        }
    }

    option = {
        name = NEOW_restoration.0101.a
        trigger_event = { id = NEOW_restoration.9000 days = 75 }
        add_piety = major_piety_gain
    }
}

# Orthodox Pentarchy: The See of Jerusalem
NEOW_restoration.0102 = {
    type = character_event
    window = big_event_window
    title = NEOW_restoration.0102.t
    desc = NEOW_restoration.0102.desc
    theme = christian
    override_background = { reference = NEOW_restoration_jerusalem }
    override_effect_2d = { reference = legend_glow }
    left_portrait = {
        character = root
        animation = personality_zealous
    }

    trigger = {
        is_ai = no
        is_ruler = yes
        neow_restoration_nistrenian_ruler_trigger = yes
        religion = religion:eastern_orthodox_religion
        NOT = { has_global_variable = flag_NEOW_restoration_0102 }
        NOT = { has_character_flag = flag_NEOW_restoration_cooldown }
        title:c_jerusalem.holder.top_liege = root
    }

    immediate = {
        play_music_cue = "mx_cue_sacredrite"
        set_global_variable = {
            name = flag_NEOW_restoration_0102
            value = root
        }
        add_character_flag = {
            flag = flag_NEOW_restoration_cooldown
            days = 60
        }
    }

    option = {
        name = NEOW_restoration.0102.a
        trigger_event = { id = NEOW_restoration.9000 days = 75 }
        add_piety = major_piety_gain
    }
}

# Orthodox Pentarchy: The See of Alexandria
NEOW_restoration.0103 = {
    type = character_event
    window = big_event_window
    title = NEOW_restoration.0103.t
    desc = NEOW_restoration.0103.desc
    theme = christian
    override_background = { reference = temple_church }
    override_effect_2d = { reference = legend_glow }
    left_portrait = {
        character = root
        animation = personality_zealous
    }

    trigger = {
        is_ai = no
        is_ruler = yes
        neow_restoration_nistrenian_ruler_trigger = yes
        religion = religion:eastern_orthodox_religion
        NOT = { has_global_variable = flag_NEOW_restoration_0103 }
        NOT = { has_character_flag = flag_NEOW_restoration_cooldown }
        title:c_alexandria.holder.top_liege = root
    }

    immediate = {
        play_music_cue = "mx_cue_sacredrite"
        set_global_variable = {
            name = flag_NEOW_restoration_0103
            value = root
        }
        add_character_flag = {
            flag = flag_NEOW_restoration_cooldown
            days = 60
        }
    }

    option = {
        name = NEOW_restoration.0103.a
        trigger_event = { id = NEOW_restoration.9000 days = 75 }
        add_piety = major_piety_gain
    }
}

# Orthodox Pentarchy: The See of Constantinople
NEOW_restoration.0104 = {
    type = character_event
    window = big_event_window
    title = NEOW_restoration.0104.t
    desc = NEOW_restoration.0104.desc
    theme = christian
    override_background = { reference = ep3_hagia_sophia }
    override_effect_2d = { reference = legend_glow }
    left_portrait = {
        character = root
        animation = personality_zealous
    }

    trigger = {
        is_ai = no
        is_ruler = yes
        neow_restoration_nistrenian_ruler_trigger = yes
        religion = religion:eastern_orthodox_religion
        NOT = { has_global_variable = flag_NEOW_restoration_0104 }
        NOT = { has_character_flag = flag_NEOW_restoration_cooldown }
        title:c_byzantion.holder.top_liege = root
    }

    immediate = {
        play_music_cue = "mx_cue_sacredrite"
        set_global_variable = {
            name = flag_NEOW_restoration_0104
            value = root
        }
        add_character_flag = {
            flag = flag_NEOW_restoration_cooldown
            days = 60
        }
    }

    option = {
        name = NEOW_restoration.0104.a
        trigger_event = { id = NEOW_restoration.9000 days = 75 }
        add_piety = major_piety_gain
    }
}

# Orthodox Pentarchy: The See of Rome
NEOW_restoration.0105 = {
    type = character_event
    window = big_event_window
    title = NEOW_restoration.0105.t
    desc = NEOW_restoration.0105.desc
    theme = christian
    override_background = { reference = pam_papal_throne_room_interior }
    override_effect_2d = { reference = legend_glow }
    left_portrait = {
        character = root
        animation = personality_zealous
    }

    trigger = {
        is_ai = no
        is_ruler = yes
        neow_restoration_nistrenian_ruler_trigger = yes
        religion = religion:eastern_orthodox_religion
        NOT = { has_global_variable = flag_NEOW_restoration_0105 }
        NOT = { has_character_flag = flag_NEOW_restoration_cooldown }
        title:c_roma.holder.top_liege = root
    }

    immediate = {
        play_music_cue = "mx_cue_sacredrite"
        set_global_variable = {
            name = flag_NEOW_restoration_0105
            value = root
        }
        add_character_flag = {
            flag = flag_NEOW_restoration_cooldown
            days = 60
        }
    }

    option = {
        name = NEOW_restoration.0105.a
        trigger_event = { id = NEOW_restoration.9000 days = 75 }
        add_piety = major_piety_gain
    }
}

# Christian Britain: Babylon Is Fallen
NEOW_restoration.1001 = {
    type = character_event
    window = big_event_window
    title = NEOW_restoration.1001.t
    desc = NEOW_restoration.1001.desc
    theme = christian
    override_background = { reference = market_crowd }
    override_effect_2d = { reference = legend_glow }
    left_portrait = {
        character = root
        animation = personality_zealous
    }

    trigger = {
        is_ai = no
        is_ruler = yes
        neow_restoration_christian_ruler_trigger = yes
        NOT = { has_global_variable = flag_NEOW_restoration_1001 }
        NOT = { has_character_flag = flag_NEOW_restoration_cooldown }
        title:c_london.holder.top_liege = root
    }

    immediate = {
        play_music_cue = "mx_cue_epic_sacral_moment"
        set_global_variable = {
            name = flag_NEOW_restoration_1001
            value = root
        }
        add_character_flag = {
            flag = flag_NEOW_restoration_cooldown
            days = 60
        }
    }

    option = {
        name = NEOW_restoration.1001.a
        trigger_event = { id = NEOW_restoration.9000 days = 75 }
        add_prestige = major_prestige_gain
    }
}

# Christian Britain: Babylon Is Fallen
NEOW_restoration.1002 = {
    type = character_event
    window = big_event_window
    title = NEOW_restoration.1002.t
    desc = NEOW_restoration.1002.desc
    theme = christian
    override_background = { reference = pam_romanesque_church_exterior }
    override_effect_2d = { reference = legend_glow }
    left_portrait = {
        character = root
        animation = personality_zealous
    }

    trigger = {
        is_ai = no
        is_ruler = yes
        neow_restoration_christian_ruler_trigger = yes
        NOT = { has_global_variable = flag_NEOW_restoration_1002 }
        NOT = { has_character_flag = flag_NEOW_restoration_cooldown }
        neow_restoration_full_britain_trigger = yes
    }

    immediate = {
        play_music_cue = "mx_cue_epic_sacral_moment"
        set_global_variable = {
            name = flag_NEOW_restoration_1002
            value = root
        }
        add_character_flag = {
            flag = flag_NEOW_restoration_cooldown
            days = 60
        }
    }

    option = {
        name = NEOW_restoration.1002.a
        trigger_event = { id = NEOW_restoration.9000 days = 75 }
        add_prestige = major_prestige_gain
        hidden_effect = {
            # The religious revival reaches most of Great Britain, but not every county.
            # England, Wales and Scotland only; Ireland remains unaffected.
            title:k_england = {
                every_de_jure_county = {
                    limit = {
                        holder.top_liege = root
                        OR = {
                            NOT = { faith = root.faith }
                            NOT = { rite = root.rite }
                        }
                    }
                    random = {
                        chance = 45
                        set_county_faith = root.faith
                        set_county_rite = root.rite
                    }
                }
            }
            title:k_northumberland = {
                every_de_jure_county = {
                    limit = {
                        holder.top_liege = root
                        OR = {
                            NOT = { faith = root.faith }
                            NOT = { rite = root.rite }
                        }
                    }
                    random = {
                        chance = 45
                        set_county_faith = root.faith
                        set_county_rite = root.rite
                    }
                }
            }
            title:k_wales = {
                every_de_jure_county = {
                    limit = {
                        holder.top_liege = root
                        OR = {
                            NOT = { faith = root.faith }
                            NOT = { rite = root.rite }
                        }
                    }
                    random = {
                        chance = 45
                        set_county_faith = root.faith
                        set_county_rite = root.rite
                    }
                }
            }
            title:k_scotland = {
                every_de_jure_county = {
                    limit = {
                        holder.top_liege = root
                        OR = {
                            NOT = { faith = root.faith }
                            NOT = { rite = root.rite }
                        }
                    }
                    random = {
                        chance = 45
                        set_county_faith = root.faith
                        set_county_rite = root.rite
                    }
                }
            }
            title:k_mann = {
                every_de_jure_county = {
                    limit = {
                        holder.top_liege = root
                        OR = {
                            NOT = { faith = root.faith }
                            NOT = { rite = root.rite }
                        }
                    }
                    random = {
                        chance = 45
                        set_county_faith = root.faith
                        set_county_rite = root.rite
                    }
                }
            }
        }
    }
}

# Hidden one-off check, called after gaining a title, yearly for existing saves,
# and after resolving a prior event. All outcome events retain their own triggers.
NEOW_restoration.9000 = {
    type = character_event
    hidden = yes
    immediate = {
        if = {
            limit = {
                is_ai = no
                is_ruler = yes
                NOT = { has_character_flag = flag_NEOW_restoration_event_pending }
                NOT = { has_character_flag = flag_NEOW_restoration_cooldown }
            }
            if = {
                limit = {
                    is_ai = no
                    is_ruler = yes
                    neow_restoration_nistrenian_ruler_trigger = yes
                    NOT = { has_global_variable = flag_NEOW_restoration_0001 }
                    NOT = { has_character_flag = flag_NEOW_restoration_cooldown }
                    title:c_moskva.holder.top_liege = root
                }
                add_character_flag = { flag = flag_NEOW_restoration_event_pending days = 7 }
                trigger_event = { id = NEOW_restoration.0001 days = 1 }
            }
            else_if = {
                limit = {
                    is_ai = no
                    is_ruler = yes
                    neow_restoration_nistrenian_ruler_trigger = yes
                    NOT = { has_global_variable = flag_NEOW_restoration_0002 }
                    NOT = { has_character_flag = flag_NEOW_restoration_cooldown }
                    title:c_petrograd.holder.top_liege = root
                }
                add_character_flag = { flag = flag_NEOW_restoration_event_pending days = 7 }
                trigger_event = { id = NEOW_restoration.0002 days = 1 }
            }
            else_if = {
                limit = {
                    is_ai = no
                    is_ruler = yes
                    neow_restoration_nistrenian_ruler_trigger = yes
                    NOT = { has_global_variable = flag_NEOW_restoration_0003 }
                    NOT = { has_character_flag = flag_NEOW_restoration_cooldown }
                    title:c_byzantion.holder.top_liege = root
                }
                add_character_flag = { flag = flag_NEOW_restoration_event_pending days = 7 }
                trigger_event = { id = NEOW_restoration.0003 days = 1 }
            }
            else_if = {
                limit = {
                    is_ai = no
                    is_ruler = yes
                    neow_restoration_nistrenian_ruler_trigger = yes
                    NOT = { has_global_variable = flag_NEOW_restoration_0004 }
                    NOT = { has_character_flag = flag_NEOW_restoration_cooldown }
                    OR = {
            title:c_roma.holder.top_liege = root
            title:c_roma_urbs.holder.top_liege = root
        }
                }
                add_character_flag = { flag = flag_NEOW_restoration_event_pending days = 7 }
                trigger_event = { id = NEOW_restoration.0004 days = 1 }
            }
            else_if = {
                limit = {
                    is_ai = no
                    is_ruler = yes
                    neow_restoration_nistrenian_ruler_trigger = yes
                    NOT = { has_global_variable = flag_NEOW_restoration_0005 }
                    NOT = { has_character_flag = flag_NEOW_restoration_cooldown }
                    title:c_thessalonika.holder.top_liege = root
                }
                add_character_flag = { flag = flag_NEOW_restoration_event_pending days = 7 }
                trigger_event = { id = NEOW_restoration.0005 days = 1 }
            }
            else_if = {
                limit = {
                    is_ai = no
                    is_ruler = yes
                    neow_restoration_nistrenian_ruler_trigger = yes
                    religion = religion:eastern_orthodox_religion
                    NOT = { has_global_variable = flag_NEOW_restoration_0101 }
                    NOT = { has_character_flag = flag_NEOW_restoration_cooldown }
                    title:c_antiocheia.holder.top_liege = root
                }
                add_character_flag = { flag = flag_NEOW_restoration_event_pending days = 7 }
                trigger_event = { id = NEOW_restoration.0101 days = 1 }
            }
            else_if = {
                limit = {
                    is_ai = no
                    is_ruler = yes
                    neow_restoration_nistrenian_ruler_trigger = yes
                    religion = religion:eastern_orthodox_religion
                    NOT = { has_global_variable = flag_NEOW_restoration_0102 }
                    NOT = { has_character_flag = flag_NEOW_restoration_cooldown }
                    title:c_jerusalem.holder.top_liege = root
                }
                add_character_flag = { flag = flag_NEOW_restoration_event_pending days = 7 }
                trigger_event = { id = NEOW_restoration.0102 days = 1 }
            }
            else_if = {
                limit = {
                    is_ai = no
                    is_ruler = yes
                    neow_restoration_nistrenian_ruler_trigger = yes
                    religion = religion:eastern_orthodox_religion
                    NOT = { has_global_variable = flag_NEOW_restoration_0103 }
                    NOT = { has_character_flag = flag_NEOW_restoration_cooldown }
                    title:c_alexandria.holder.top_liege = root
                }
                add_character_flag = { flag = flag_NEOW_restoration_event_pending days = 7 }
                trigger_event = { id = NEOW_restoration.0103 days = 1 }
            }
            else_if = {
                limit = {
                    is_ai = no
                    is_ruler = yes
                    neow_restoration_nistrenian_ruler_trigger = yes
                    religion = religion:eastern_orthodox_religion
                    NOT = { has_global_variable = flag_NEOW_restoration_0104 }
                    NOT = { has_character_flag = flag_NEOW_restoration_cooldown }
                    title:c_byzantion.holder.top_liege = root
                }
                add_character_flag = { flag = flag_NEOW_restoration_event_pending days = 7 }
                trigger_event = { id = NEOW_restoration.0104 days = 1 }
            }
            else_if = {
                limit = {
                    is_ai = no
                    is_ruler = yes
                    neow_restoration_nistrenian_ruler_trigger = yes
                    religion = religion:eastern_orthodox_religion
                    NOT = { has_global_variable = flag_NEOW_restoration_0105 }
                    NOT = { has_character_flag = flag_NEOW_restoration_cooldown }
                    title:c_roma.holder.top_liege = root
                }
                add_character_flag = { flag = flag_NEOW_restoration_event_pending days = 7 }
                trigger_event = { id = NEOW_restoration.0105 days = 1 }
            }
            else_if = {
                limit = {
                    is_ai = no
                    is_ruler = yes
                    neow_restoration_christian_ruler_trigger = yes
                    NOT = { has_global_variable = flag_NEOW_restoration_1001 }
                    NOT = { has_character_flag = flag_NEOW_restoration_cooldown }
                    title:c_london.holder.top_liege = root
                }
                add_character_flag = { flag = flag_NEOW_restoration_event_pending days = 7 }
                trigger_event = { id = NEOW_restoration.1001 days = 1 }
            }
            else_if = {
                limit = {
                    is_ai = no
                    is_ruler = yes
                    neow_restoration_christian_ruler_trigger = yes
                    NOT = { has_global_variable = flag_NEOW_restoration_1002 }
                    NOT = { has_character_flag = flag_NEOW_restoration_cooldown }
                    neow_restoration_full_britain_trigger = yes
                }
                add_character_flag = { flag = flag_NEOW_restoration_event_pending days = 7 }
                trigger_event = { id = NEOW_restoration.1002 days = 1 }
            }
        }
    }
}
