namespace = HFP

#Hansa
narrative_event = {
	id = HFP.40000
	desc = EVTDESC_HFP_40000
	title = TITLE_HFP_40000
	picture = GFX_evt_busy_trading_dock_republic
	is_triggered_only = yes

	option = {
		name = EVTOPTA_HFP_40000
		prestige = 500
	}
}

#Hansa Notification event
narrative_event = {
	id = HFP.40001
	desc = EVTDESC_HFP_40001
	title = TITLE_HFP_40001
	picture = GFX_evt_busy_trading_dock_republic
	is_triggered_only = yes

	trigger = {
		NOT = {
			has_landed_title = k_hansa
		}
	}

	option = {
		name = EVTOPTA_HFP_40001
	}
}

#Switzerland
narrative_event = {
	id = HFP.40010
	desc = EVTDESC_HFP_40010
	title = TITLE_HFP_40010
	picture = GFX_evt_council
	border = GFX_event_narrative_frame_diplomacy
	is_triggered_only = yes

	option = {
		name = EVTOPTA_HFP_40010
		prestige = 250
	}
}

#Swiss Notifications
narrative_event = {
	id = HFP.40012
	desc = EVTDESC_HFP_40012
	title = TITLE_HFP_40012
	picture = GFX_evt_throne_room
	border = GFX_event_narrative_frame_diplomacy
	is_triggered_only = yes

	trigger = {
		NOT = {
			has_landed_title = k_switzerland
		}
	}

	option = {
		name = EVTOPTA_HFP_40012
	}
}

#Antioch
narrative_event = {
    id = HFP.40013
    desc = EVTDESC_HFP_40013
    title = EVTTITLE_HFP_40013
    picture = GFX_evt_western_knights_byzantine
    is_triggered_only = yes

    option = {      
        name = EVTOPTA_HFP_40013

        prestige = 500
    }
}

#Cyprus
narrative_event = {
    id = HFP.40014
    desc = EVTDESC_HFP_40014
    title = EVTTITLE_HFP_40014
    picture = GFX_evt_western_knights_byzantine
    is_triggered_only = yes

    option = {      
        name = EVTOPTA_HFP_40014
		
		prestige = 500
    }
}

#Merchant Republic Kingdoms 
narrative_event = {
    id = HFP.40015
    desc = EVTDESC_HFP_40015
    title = EVTTITLE_HFP_40015
    picture = GFX_evt_busy_trading_dock_republic
    is_triggered_only = yes

    option = {      
        name = EVTOPTA_HFP_40015

       	prestige = 250
    }
}

# Archduke of Austria
narrative_event = {
    id = HFP.40022
    title = EVTTITLE_HFP_40022
    desc = {
        trigger = {
            e_hre = {
                OR = {
                    has_law = succ_feudal_elective
                    has_law = succ_hre_elective
                }
            }
        }
        text = EVTDESC_HFP_40022
    }
    desc = {
        trigger = {
            e_hre = {
                NOR = {
                    has_law = succ_feudal_elective
                    has_law = succ_hre_elective
                }
            }
        }
        text = EVTDESC_HFP_40022_2
    }
    picture = GFX_evt_book_carolingian_script
    is_triggered_only = yes

    option = {      
        name = EVTOPTA_HFP_40022
        trigger = {
        	has_landed_title = k_austria
        }

        prestige = 500
    }
    option = {      
        name = EVTOPTB_HFP_40022
        trigger = {
        	NOT = {
        		has_landed_title = k_austria
        	}
        }
    }
}

# Gather the Eastern Marches
narrative_event = {
    id = HFP.40023
    title = EVTTITLE_HFP_40023
    desc = EVTDESC_HFP_40023
    picture = GFX_evt_book_carolingian_script
    is_triggered_only = yes

    option = {      
        name = EVTOPTA_HFP_40023
        trigger = {
        	has_landed_title = k_eastern_marches
        }
        prestige = 1000
    }
    option = {      
        name = EVTOPTB_HFP_40023
        trigger = {
        	NOT = {
        		has_landed_title = k_eastern_marches
        	}
        }
    }
}

# Restore the Byzantine Empire
narrative_event = {
    id = HFP.40024
    title = EVTTITLE_HFP_40024
    desc = EVTDESC_HFP_40024
    picture = GFX_evt_victory_arch_byzantine
    is_triggered_only = yes
    trigger = {
    
    }

    immediate = {

    }

    # Rejoin the Empire (Byzantine Culture Group only)
    option = {      
        name = EVTOPTA_HFP_40024
        trigger = {
            culture_group = byzantine
            NOT = { 
                has_landed_title = e_byzantium
            }
            lower_tier_than = EMPEROR
            independent = yes
            controls_religion = no
        }
        set_defacto_liege = e_byzantium

        FROM = {
            letter_event = { id = HFP.40025 days = 1 }
        }

        ai_chance = {
            factor = 1 
            modifier = {
                factor = 2
                trait = content
            }
            modifier = {
                factor = 2
                FROM = {
                    trait = born_in_the_purple
                }
            }
            modifier = {
                factor = 2
                opinion = {
                    who = FROM
                    value = 30
                }
            }
            modifier = {
                factor = 0.5
                OR = {
                    trait = proud
                    trait = envious
                    trait = ambitious
                }
            }
            modifier = {
                factor = 0.5
                NOT = {
                    opinion = {
                        who = FROM
                        value = 10
                    }
                }
            }
            modifier = {
                factor = 0.5
                tier = KING
            }
            modifier = {
                factor = 2
                lower_tier_than = DUKE
            }
        }
    }  
    # Choose not to rejoin the Empire (Byzantine Culture Group only)
    option = {      
        name = EVTOPTB_HFP_40024
        trigger = {
            culture_group = byzantine
            NOT = {
                has_landed_title = e_byzantium
            }
        }

        ai_chance = {
            factor = 2
        }
    }
    # For others
    option = {
        name = EVTOPTC_HFP_40024
        trigger = {
            NOT = {
                culture_group = byzantine
            }
        }
    }
    # For the Emperor
    option = {
        name = EVTOPTD_HFP_40024
        trigger = {
            has_landed_title = e_byzantium
        }
    }
}

# Letter event Swearing Fealty to new Byzantine Emperor
letter_event = {
    id = HFP.40025
    desc = EVTDESC_HFP_40025
    picture = GFX_evt_throne_room
    is_triggered_only = yes

    option = {      
        name = EVTOPTA_HFP_40025
    }
}

# Making a new Eastern Marches Kingdom
character_event = {
    id = HFP.40026
    desc = EVTDESC_HFP_40026
    picture = GFX_evt_throne_room
    is_triggered_only = yes
    trigger = {
    
    }

    immediate = {

    }
    # Austria
    option = {      
        name = EVTOPTA_HFP_40026
        if = {
            limit = {
                NOT = {
                    has_landed_title = c_osterreich
                }
            }
            grant_title_no_opinion = c_osterreich
        }
        if = {
            limit = {
                NOT = {
                    capital_scope = {
                        title = c_osterreich
                    }
                }
            }
            capital = c_osterreich
        }
    }
    # Styria
    option = {      
        name = EVTOPTB_HFP_40026
        hidden_tooltip = {
            k_eastern_marches = {
                set_name = "kingdom_of_styria_name"
                adjective = d_styria
                set_coa = d_styria   
            }
        }
        if = {
            limit = {
                NOT = {
                    has_landed_title = c_graz
                }
            }
            grant_title_no_opinion = c_graz
        }
        if = {
            limit = {
                NOT = {
                    capital_scope = {
                        title = c_graz
                    }
                }
            }
            capital = c_graz
        }
    }
    # Bavaria
    option = {
        name = EVTOPTC_HFP_40026
        hidden_tooltip = {
            k_eastern_marches = {
                set_name = "kingdom_of_bavaria_name"
                adjective = k_bavaria
                set_coa = k_bavaria
            }
        }
        if = {
            limit = {
                NOT = {
                    has_landed_title = c_regensburg 
                }
            }
            grant_title_no_opinion = c_regensburg
        }
        if = {
            limit = {
                NOT = {
                    capital_scope = {
                        title = c_regensburg
                    }
                }
            }
            capital = c_regensburg
        }

    }
    # Carinthia
    option = {
        name = EVTOPTD_HFP_40026
        hidden_tooltip = {
            k_eastern_marches = {
                set_name = "kingdom_of_carinthia_name"
                adjective = k_carinthia
                set_coa = k_carinthia
            }
        }
        if = {
            limit = {
                NOT = {
                    has_landed_title = c_karnten
                }
            }
            grant_title_no_opinion = c_karnten
        }
        if = {
            limit = {
                NOT = {
                    capital_scope = {
                        title = c_karnten
                    }
                }
            }
            capital = c_karnten
        }
    }

    after = {
        hidden_tooltip = {
            primary_title = {
                k_eastern_marches = {
                    copy_title_history = PREV
                    copy_title_laws = PREV
                }
            }
            grant_title_no_opinion = k_eastern_marches

            d_styria = {
                de_jure_liege = k_eastern_marches
            }
            d_osterreich = {
                de_jure_liege = k_eastern_marches
            }
            d_salzburg = {
                de_jure_liege = k_eastern_marches
            }
            d_bavaria = {
                de_jure_liege = k_eastern_marches
            }
            d_carinthia = {
                de_jure_liege = k_eastern_marches
            }
            d_friuli = {
                de_jure_liege = k_eastern_marches
            }
            d_carniola = {
                de_jure_liege = k_eastern_marches
            }
            d_tyrol = {
                de_jure_liege = k_eastern_marches
            }
            k_bavaria = {
                any_direct_de_jure_vassal_title = {
                    de_jure_liege = k_eastern_marches
                }
            }
            k_carinthia = {
                any_direct_de_jure_vassal_title = {
                    de_jure_liege = k_eastern_marches
                }
            }
            k_eastern_marches = {
                de_jure_liege = e_hre
                make_primary_title = yes
            }
            set_defacto_liege = e_hre

            destroy_landed_title = k_bavaria
            activate_title = { title = k_bavaria status = no }
            if = {
                limit = {
                    OR = {
                        has_landed_title = k_carinthia
                        k_carinthia = {
                            has_holder = no
                        }
                    }
                }
                destroy_landed_title = k_carinthia
                activate_title = { title = k_carinthia status = no }
            }

            ROOT = {
                narrative_event = { id = HFP.40023 }
            }
            any_playable_ruler = {
                limit = {
                    de_facto_liege_title = e_hre
                }
                narrative_event = { id = HFP.40023 }
            }
        }
    }
}

# Complete Catholic/Fraticelli victory
narrative_event = {
    id = HFP.40027
    title = EVTTITLE_HFP_40027
    desc = EVTDESC_HFP_40027
    picture = GFX_evt_crusaders
    border = GFX_event_narrative_frame_religion
    is_triggered_only = yes
    trigger = {
    
    }

    immediate = {

    }

    option = {      
        name = EVTOPTA_HFP_40027
        trigger = {
            religion_group = christian
        }
        if = {
            limit = {
                has_landed_title = e_outremer
            }
            prestige = 1000
            if = {
                limit = {
                    has_dlc = "Holy Fury"
                }
                if = {
                    limit = {
                        is_female = yes
                    }
                    create_bloodline = {
                        type = lord_of_outremer
                        inheritance = all_descendants
                    }
                }
                else = {
                    create_bloodline = {
                        type = lord_of_outremer
                    }
                }
                set_bloodline_founder_religion_flag_effect = yes
            }
        }
    }
    option = {      
        name = EVTOPTB_HFP_40027
        trigger = {
            NOT = {
                religion_group = christian
            }
        }

        ai_chance = {
            factor = 1
            trigger = {
                OR = {
                    NOT = {
                        any_liege = {
                            religion = FROM
                        }
                    }
                    ai = no
                }
            }
        }
    }
    option = {
        name = EVTOPTC_HFP_40027
        trigger = {
            religion_group = muslim
        }
        religion = FROM

        ai_chance = {
            trigger = {
                OR = {
                    trait = cynical
                    any_liege = {
                        religion = FROM
                    }
                }
            }
            factor = 1
        }
    }
}

# Removes the prince / princess titles from the children of the Prince of Antioch
character_event = {
    id = HFP.40028
    hide_window = yes
    is_triggered_only = yes
    trigger = {
        has_landed_title = k_antioch
    }

    immediate = {
        if = {
            limit = {
                primary_title = {
                    title = k_antioch
                }
            }
            any_child = {
                if = {
                    limit = {
                        has_minor_title = title_prince
                    }
                    remove_title = title_prince
                }
            }
        }
    }
}

# The Order of Calatrava has been formed
narrative_event = {
    id = HFP.40029
    desc = EVTDESC_HFP_40029
    title = EVTTITLE_HFP_40029
    picture = GFX_evt_melee
    border = GFX_event_narrative_frame_religion
    portrait = event_target:portrait_target
    is_triggered_only = yes

    immediate = {
        if = {
            limit = {
                NOT = {
                    character = FROM
                }
            }
            d_knights_calatrava = {
                holder_scope = {
                    save_event_target_as = portrait_target
                }
            }
        }
        else = {
            save_event_target_as = portrait_target
        }
    }

    option = {
        name = EVTOPTA_HFP_40029
        trigger = {
            religion_group = FROM
        }
    }
    option = {
        name = EVTOPTB_HFP_40029
        trigger = {
            NOT = {
                religion_group = FROM
            }
        }
    }
}

# The Order of Santiago has been formed
narrative_event = {
    id = HFP.40030
    desc = EVTDESC_HFP_40030
    title = EVTTITLE_HFP_40030
    picture = GFX_evt_magnificent_castle
    border = GFX_event_narrative_frame_religion
    portrait = event_target:portrait_target
    is_triggered_only = yes

    immediate = {
        if = {
            limit = {
                NOT = {
                    character = FROM
                }
            }
            d_knights_santiago = {
                holder_scope = {
                    save_event_target_as = portrait_target
                }
            }
        }
        else = {
            save_event_target_as = portrait_target
        }
    }

    option = {
        name = EVTOPTA_HFP_40030
        trigger = {
            religion_group = FROM
        }
    }

    option = {
        name = EVTOPTB_HFP_40030
        trigger = {
            NOT = {
                religion_group = FROM
            }
        }
    }
}

# The Teutonic Order has been formed
narrative_event = {
    id = HFP.40031
    desc = EVTDESC_HFP_40031
    title = EVTTITLE_HFP_40031
    picture = GFX_evt_crusaders
    border = GFX_event_narrative_frame_religion
    portrait = event_target:portrait_target
    is_triggered_only = yes

    immediate = {
        if = {
            limit = {
                NOT = {
                    character = FROM
                }
            }
            d_teutonic_order = {
                holder_scope = {
                    save_event_target_as = portrait_target
                }
            }
        }
        else = {
            save_event_target_as = portrait_target
        }
    }

    option = {
        name = EVTOPTA_HFP_40031
        trigger = {
            religion_group = FROM
        }
    }

    option = {
        name = EVTOPTB_HFP_40031
        trigger = {
            NOT = {
                religion_group = FROM
            }
        }
    }
}

# The Holy Sepulchre has been formed
narrative_event = {
    id = HFP.40032
    desc = EVTDESC_SOA_1609
    title = EVTTITLE_SOA_1609
    picture = GFX_evt_western_knights_byzantine
    border = GFX_event_narrative_frame_religion
    portrait = event_target:portrait_target
    is_triggered_only = yes

    immediate = {
        if = {
            limit = {
                NOT = {
                    character = FROM
                }
            }
            d_holy_sepulchre = {
                holder_scope = {
                    save_event_target_as = portrait_target
                }
            }
        }
        else = {
            save_event_target_as = portrait_target
        }
    }

    option = {
        name = EVTOPTA_SOA_1609
        trigger = {
            religion = FROM
        }
    }

    option = {
        name = EVTOPTB_SOA_1609
        trigger = {
            NOT = {
                religion = FROM
            }
        }
    }
}

# Romagna / Papal States usurpation event
character_event = {
    id = HFP.40033
    hide_window = yes
    is_triggered_only = yes
    trigger = {
        FROM = {
            title = k_papacy
        }
    }

    immediate = {
        if = {
            limit = {
                NOT = {
                    has_landed_title = k_papal_state
                }
            }
            grant_title_no_opinion = k_romagna
            destroy_landed_title = k_papacy
            k_papacy = {
                any_direct_de_jure_vassal_title = {
                    de_jure_liege = k_romagna
                }
                dejure_liege_title = {
                    k_romagna = {
                        de_jure_liege = PREV
                    }
                }
            }
            ROOT = {
                character_event = { id = HFP.40036 }
            }
            any_playable_ruler = {
                limit = {
                    any_demesne_province = {
                        region = world_europe_south_italy
                    }
                }
                character_event = { id = HFP.40036 }
            }
        }
    }
}

# Papal States becomes Romagna when the Pope holds no lands in Italy
character_event = {
    id = HFP.40034
    hide_window = yes
    is_triggered_only = yes
    trigger = {
        has_landed_title = k_papal_state
    }

    immediate = {
        destroy_landed_title = k_papacy
        k_papacy = {
            any_direct_de_jure_vassal_title = {
                de_jure_liege = k_romagna
            }
        }
        any_playable_ruler = {
            limit = {
                any_demesne_province = {
                    region = world_europe_south_italy
                }
            }
            character_event = { id = HFP.40037 }
        }
    }
}

# Clean up Papal Guards 
character_event = {
    id = HFP.40035
    hide_window = yes
    is_triggered_only = yes
    trigger = {
    
    }

    immediate = {
        activate_title = {
            title = d_papal_guards
            status = no
        }
    }
}

# Narrative Event - Papal States usurped -
narrative_event = {
    id = HFP.40036
    desc = EVTDESC_HFP_40036
    title = EVTTITLE_HFP_40036
    picture = GFX_evt_magnificent_castle
    is_triggered_only = yes

    option = {      
        name = EVTOPTA_HFP_40036
        trigger = {
            NOT = {
                character = FROM
            }
        }
    }
    option = {
        name = EVTOPTB_HFP_40036
        trigger = {
            character = FROM
        }
    }
}

# Narrative Event - Papacy has lost all their land, and thus any claim to the land in central Italy -
narrative_event = {
    id = HFP.40037
    desc = EVTDESC_HFP_40037
    title = EVTTITLE_HFP_40037
    picture = GFX_evt_magnificent_castle
    is_triggered_only = yes

    option = {      
        name = EVTOPTA_HFP_40037
    }
}

# Narrative Event - Grand Stem Duchies in the HRE
narrative_event = {
    id = HFP.40038
    desc = EVTDESC_HFP_40038
    title = EVTTITLE_HFP_40038
    picture = GFX_evt_magnificent_castle
    is_triggered_only = yes

    option = {
        name = EVTOPTA_HFP_40038
        trigger = {
            NOT = {
                FROM = {
                    character = ROOT
                }
            }
        }
    }
    option = {
        name = EVTOPTB_HFP_40038
        trigger = {
            FROM = {
                character = ROOT
            }
        }
        prestige = 500
    }
}

# The Slavic Union is formed
narrative_event = {
    id = HFP.99999
    title = EVTTITLE_HFP_99999
    desc = EVTDESC_HFP_99999
    picture = GFX_evt_pagan_reformation
    border = GFX_event_narrative_frame_diplomacy
    is_triggered_only = yes

    option = {      
        name = EVTOPTA_HFP_99999
    }
}

######
#Princely Elective Dynamic Elector titles.

#On regular start.
character_event = {
	id = HFP.24120
	hide_window = yes
	
	only_rulers = yes
	trigger = {
		has_landed_title = e_hre #Only if the original exists.
		NOT = {
			e_hre = {
				persistent_event_target:hre_title_1_per = { always = yes } #If one exists already, all do.
			}
		}
	}

	is_triggered_only = yes

	immediate = {
		princely_elective_german_elector_setup_effect = yes #Regular German setup.
	}
}