namespace = CleanerKarlings

# on_startup
character_event = {
    id = CleanerKarlings.1
    hide_window = yes

    is_triggered_only = yes

    # Trigger for the Pope
    only_playable = yes
    religion = catholic
    min_age = 16

    trigger = {
        controls_religion = yes

        year = 769
        NOT = { year = 867 }
        NOT = { has_global_flag = cleaner_karlings_init }
    }

    immediate = {

        set_global_flag = cleaner_karlings_init


        ################
        # Karl's realm #
        ################

        # "Aquitaine", south of the Loire
        # "West Francia"
        # "Frisia", east of the Rhine

        # Aquitaine: Gascogne, Aquitaine, +Poitou (large duchies)
        d_poitou =            { de_jure_liege = k_aquitaine }

        # West Francia: Anjou, Normandy, Picardie, Flanders(!), +Luxemborg, +Lower Lorraine, +Brabant
        d_luxembourg =        { de_jure_liege = k_france }
        d_lower_lorraine =    { de_jure_liege = k_france }
        d_brabant =           { de_jure_liege = k_france }

        # Frisia: Brabant, Holland, Gelre, +Koln, +Thuringia, +Franconia, +Hesse, +Rhine
        d_koln =              { de_jure_liege = k_frisia }
        d_thuringia =         { de_jure_liege = k_frisia }
        d_franconia =         { de_jure_liege = k_frisia }
        d_hesse =             { de_jure_liege = k_frisia }
        d_rhine =             { de_jure_liege = k_frisia }

        #k_frisia =           { set_name = "Rhine"  adjective = "Rhine" }
        k_frisia =            { de_jure_liege = e_germany }

        #####################
        # Carlomann's realm #
        #####################

        # "Burgundy", only slightly larger than in vanilla
        # "Middle Francia", eating Carlomann's side of vanilla's Aquitaine and vanilla's West Francia
        # "East Francia", eating bits of Middle Francia in order to balance things out

        # East Francia: +Champagne (contains capital!), Alemania, Baden, +Alsace, +Upper Lorraine, +Trier
        d_alsace =            { de_jure_liege = k_germany }
        d_upper_lorraine =    { de_jure_liege = k_germany }
        d_champagne =         { de_jure_liege = k_germany }
        d_trier =             { de_jure_liege = k_germany }

        # Middle Francia: ..., +Orleans, +Berry, +Bourbon, +Auvergne, +Toulouse, +Paris(Valois)
        d_orleans =           { de_jure_liege = k_lotharingia }
        d_berry =             { de_jure_liege = k_lotharingia }
        d_bourbon =           { de_jure_liege = k_lotharingia }
        d_auvergne =          { de_jure_liege = k_lotharingia }
        d_toulouse =          { de_jure_liege = k_lotharingia }
        d_valois =            { de_jure_liege = k_lotharingia }  # Paris

        # Burgundy: Provence, Dauphine, Savoy, Upper Burgundy, +Burgundy
        d_burgundy =         { de_jure_liege = k_burgundy }


        #################
        # Neither realm #
        #################

        # Umayadd
        d_barcelona =         { de_jure_liege = k_andalusia }


        ############################
        # Add titles for gavelkind #
        ############################

        k_france = {
            holder_scope = {
                k_frisia    = { grant_title = PREV }
                k_aquitaine = { grant_title = PREV }

                add_pressed_claim = k_burgundy
                add_pressed_claim = k_germany
            }
        }

        k_lotharingia = {
            holder_scope = {
                k_burgundy = { grant_title = PREV }
                k_germany  = { grant_title = PREV }

                add_pressed_claim = k_frisia
                add_pressed_claim = k_aquitaine
            }

            # I'd like to set East Francia as Karloman's primary, because:
            # * Moving the de facto capital duchy of Champaigne here makes the kingdoms more balanced and prettier
            # * "East Francia" makes more sense as a counterpart to "West Francia" as an initial realm title
            # * Two counties that are de jure Bavaria should stay with the primary title, vs one county that is now de jure Andalusia
            # Note: de jure capital of Middle Francia is Luxemborg and de jure capital of East Francia is Nassau.
            # Both of these de jure capitals are controlled by West Francia! Meanwhile, their capital is Paris, under our control!
            # BUT he just changes it back, probably because Nassau (which he doesn't even control) has German culture
            #k_germany = { make_primary_title = yes }
        }

        k_france = {
            any_claimant = {
                add_pressed_claim = k_aquitaine
                add_pressed_claim = k_france
                add_pressed_claim = k_frisia
                add_pressed_claim = k_burgundy
                add_pressed_claim = k_lotharingia
                add_pressed_claim = k_germany
            }
        }

        # Also claimants to e_francia ???

    }
}
