• We have updated our Community Code of Conduct. Please read through the new rules for the forum that are an integral part of Paradox Interactive’s User Agreement.
Hi All

Really newbie question,

I try to scope my steward and get his name for event portrait and description.

I try search wiki in scope page and i cannot see anything about steward.

on wiki example also give Random_vassal scope that i assume it is a saved scope

is there file that listed available saved scope in game file?

Thanks

For the steward it is:
left_portrait = { character = cp:councillor_steward }

Or you could scope him inside the immediate-block and then refer to him by your custom name:

root.cp:councillor_steward = {save_scope_as = my_dyscalculic_steward}

left_portrait = { character = scope:my_dyscalculic_steward }
 
  • 1Like
Reactions:
Is there a forum thread or discord for getting help with translation of mods for other localizations? I can use google translate for quick and dirty translations but I want it to be at least a bit understandable for those who want to use my mod in their preferred language.
 
  • 1Like
Reactions:
Hi All

Is there way to create timed chain event

event.001 (end)
Wait for 7days
enent.002(start with condition event001)

Kind Regards
In event.001 you can call the 2nd event using trigger_event. This can be done like:
trigger_event = event.002

This would immediately trigger it. You can however also specify a delay, like:
trigger_event = {
id = event.002
days = 7
}


To add a bit of randomnees you might want:
trigger_event = {
id = event.002
days = { 5 10 }
}

This would do it between 5 and 10 days later.
 
  • 1Like
Reactions:
In event.001 you can call the 2nd event using trigger_event. This can be done like:
trigger_event = event.002

This would immediately trigger it. You can however also specify a delay, like:
trigger_event = {
id = event.002
days = 7
}


To add a bit of randomnees you might want:
trigger_event = {
id = event.002
days = { 5 10 }
}

This would do it between 5 and 10 days later.
Thanks heaps
 
Got a problem with localization. The english localization works as intended but the german localization is not. The game is acting as if there are no files for the german but they are all there with the same file format UTF-8 .yml extension with the same name except german instead of english in the name and at the top of the file. I am missing something here but not sure what. Can someone who has made multi localization mods give me a proven process for getting them to work?
 
Got a problem with localization. The english localization works as intended but the german localization is not. The game is acting as if there are no files for the german but they are all there with the same file format UTF-8 .yml extension with the same name except german instead of english in the name and at the top of the file. I am missing something here but not sure what. Can someone who has made multi localization mods give me a proven process for getting them to work?
Have you tried just copying your original English files into the German folder, then just renaming them and pasting the German translations into them? I think I had the same problem once where I wasn't able to find a mistake and that helped.
 
Got a problem with localization. The english localization works as intended but the german localization is not. The game is acting as if there are no files for the german but they are all there with the same file format UTF-8 .yml extension with the same name except german instead of english in the name and at the top of the file. I am missing something here but not sure what. Can someone who has made multi localization mods give me a proven process for getting them to work?

The correct encoding isn't UTF-8, but UTF-8 with BOM.

Double check that l_german: is spelled with a lowercase L, and not a capital i or a 1, which is a surprisingly common mistake.

Also, just in case because you didn't say they were: german files need to be in the \german\ folder
 
I am looking for the file that includes character claims on titles. Where can I find this file in the Crusader Kings 3 directory?

I don't think there's one.

The fact that children get implicit claim on their parent's title, and inherit claims when they die, is handled in code I think, not in script.

Other than that, there are effects to give or take away claims. In console, use the command script_docs, this will create an effects.log file in your log folder. Search for "claims" in there and you should find them.
 
Does anyone know if designate_heir_interaction and set_designated_heir are used by the ai, or is it only the player that uses this code?

If they have an ai_frequency and ai_will_do block, they are (assuming the triggers in ai_will_do enables the AI to use them).

If not, it's handled in code, but changing the trigger block of the interaction might still affect the AI. It does for the declare_war interaction - the AI doesn't really use the interaction as is, but you can still change the rules of when the AI is allowed to declare war.
 
  • 1
Reactions:
I'd like to keep characters with certain traits in their physical twenties for their entire lifespan, WITHOUT making them immortal. Any ideas how to accomplish this?

Increasing life_expectancy sort of does that, if you set GRACEFUL_AGING_END in the defines to something high. But that just delays them growing old visually, it doesn't prevent it altogether.
 
The correct encoding isn't UTF-8, but UTF-8 with BOM.

Double check that l_german: is spelled with a lowercase L, and not a capital i or a 1, which is a surprisingly common mistake.

Also, just in case because you didn't say they were: german files need to be in the \german\ folder
The files were made by copying the English files (which work perfectly) to the german folder and then changing english to german in the files names and the top of the file and of course changing the text to a german translation. The format of the files are UTF-8 with BOM, I didn't realize there were different versions with same names and was using short hand before.
 
The files were made by copying the English files (which work perfectly) to the german folder and then changing english to german in the files names and the top of the file and of course changing the text to a german translation. The format of the files are UTF-8 with BOM, I didn't realize there were different versions with same names and was using short hand before.
I found the issue, with the thought of there being a difference between UTF-8 and UTF-8 with BOM, I used a different text editor (notepad++) than the one I usually use (atom) to verify the encoding. All of the english files are in UTF-8 with BOM but only 2 of the files copied over to the german folder was still in UTF-8 with BOM, the other 2 (and the ones giving me trouble) switched to UTF-8 at some point during editing/saving the files. After switching the encoding in notepad++ it worked as expected. Thanks everyone for you help with this.
 
  • 1
Reactions:
I can't figure out this gui bug in my mod for the life of me. In the declare war ui there's no text for "holy war for county" unless it's the only county the defender has:
2021_11_22_1.png
2021_11_22_2.png


I've used KDiff3 to help me. I don't see anything in gui/interaction_war_gui nor in the file that overwrites 00_religious_war that could cause this problem but here they are:

Code:
minor_religious_war = {
    group = religious

    defender_faith_can_join = yes

    combine_into_one = yes
    should_show_war_goal_subview = yes
    mutually_exclusive_titles = { always = yes }

    # Already defined in 00_casus_belli_groups.txt
    allowed_for_character = {
        scope:attacker.faith = {
            NOT = { has_doctrine = unreformed_faith_doctrine }
        }
    }

    allowed_for_character_display_regardless = {
        trigger_if = {
            limit = {
                has_variable_list = humsacd_hofs
                is_target_in_variable_list = {
                    name = humsacd_hofs
                    target = scope:attacker.faith
                }
            }
            piety_level >= 0
        }
        trigger_else = { piety_level >= 1 }
    }

    allowed_against_character = {
        scope:attacker = {
            faith = {
                faith_hostility_level = {
                    target = scope:defender.faith
                    value >= religious_cb_enabled_hostility_level
                }
            }
            ALL_FALSE = {
                top_liege = scope:defender.top_liege
                liege = scope:defender
            }
        }
    }
    target_titles = neighbor_land_or_water
    target_title_tier = all
    target_de_jure_regions_above = yes
    ignore_effect = change_title_holder

    ai_score_mult = {
        value = get_ai_score_mult_value_for_holy_war
    }

    valid_to_start = {
        scope:target = {
            tier = tier_county
        }
    }

    should_invalidate = {
        OR = {
            NOT = {
                any_in_list = {
                    list = target_titles
                    any_in_de_jure_hierarchy = {
                        tier = tier_county
                        holder = {
                            OR = {
                                this = scope:defender
                                target_is_liege_or_above = scope:defender
                            }
                        }
                    }
                }
            }
            #Faith change does not immediately invalidate, it's run through event war_event.3100
            scope:war = { exists = var:invalidate_defender_faith_change }
            scope:war = { exists = var:invalidate_attacker_faith_change }
        }
    }

    on_invalidated_desc = {
        first_valid = {
            triggered_desc = {
                trigger = {
                    NOT = {
                        any_in_list = {
                            list = target_titles
                            any_in_de_jure_hierarchy = {
                                tier = tier_county
                                holder = {
                                    OR = {
                                        this = scope:defender
                                        target_is_liege_or_above = scope:defender
                                    }
                                }
                            }
                        }
                    }
                }
                desc = msg_religious_war_invalidation_region_message
            }
            triggered_desc = {
                trigger = {
                    scope:war = {
                        OR = {
                            exists = var:invalidate_defender_faith_change
                            exists = var:invalidate_attacker_faith_change
                        }
                    }
                }
                desc = msg_religious_war_invalidated_hostility_level_message
            }
        }
    }

    on_invalidated = {
        
    }
    
    ai_score_mult = {
        value = 1
        # Holy War are limited to connected neighbour to limit big empire expansions over weak realms.
        add = {
            if = {
                limit = {  religious_war_vassals_constraints = yes }
                add = -1000
            }
        }
    }

    cost = {
        piety = {
            add = {
                value = 100
                desc = CB_BASE_COST
            }
            # Faith Doctrine Piety Discounts
            if = {
                limit = {
                    scope:attacker.faith = {
                        has_doctrine_parameter = divine_destiny_holy_war_cost_reduction
                    }
                }
                multiply = {
                    value = 0.5
                    desc = CB_DIVINE_DESTINY_COST
                }
            }

            if = {
                limit = {
                    scope:attacker.faith = {
                        has_doctrine_parameter = cheaper_holy_wars_active
                    }
                }
                multiply = {
                    value = 0.8
                    desc = CB_REDUCED_HOLY_WAR_COST
                }
            }

            # Innovation Piety Discounts
            if = {
                limit = {
                    scope:attacker = {
                        culture = {
                            has_innovation = innovation_reconquista
                        }
                    }
                }
                multiply = {
                    value = 0.9
                    desc = CB_RECONQUISTA_COST
                }
            }

            # Bellum Justum Perk
            if = {
                limit = {
                    scope:attacker = {
                        has_perk = bellum_justum_perk
                    }
                }
                multiply = {
                    add = bellum_justum_discount_percentage
                    divide = 100
                    desc = CB_ATTACKER_BELLUM_JUSTUM
                }
            }

            # Dynasty Warfare Perk
            if = {
                limit = {
                    scope:attacker = {
                        has_dynasty = yes
                        dynasty = {
                            has_dynasty_perk = warfare_legacy_2
                        }
                    }
                }
                multiply = {
                    value = warfare_legacy_2_discount
                    desc = CB_ATTACKER_DYNASTY_WARFARE
                }
            }

            # Vassal contract in-realm cost reduction
            if = {
                limit = {
                    scope:attacker = {
                        is_independent_ruler = no
                        vassal_contract_has_flag = vassal_contract_war_override
                        liege = scope:defender.liege
                    }
                }
                multiply = {
                    value = war_declaration_rights_allowed_cost_reduction
                    desc = "CB_ATTACKER_VASSAL_CONTRACT"
                }
            }

            # Someone in the target region sacrificed your HoF.
            if = {
                limit = {
                    scope:defender = {
                        has_variable_list = humsacd_hofs
                        is_target_in_variable_list = {
                            name = humsacd_hofs
                            target = scope:attacker.faith
                        }
                    }
                }
                multiply = {
                    value = religious_cb_piety_discount_against_hof_humsac
                    desc = "CB_ATTACKER_HOF_HUMSACD"
                }
            }

            if = {
                limit = {
                    has_game_rule = no_cost_casus_belli_costs
                }
                multiply = {
                    value = 0
                    desc = CB_GAME_RULE_NO_COST
                }
            }
        }
    }

    on_declaration = {
        on_declared_war = yes
    }

    on_victory_desc = {
        first_valid = {
            triggered_desc = {
                trigger = {
                    scope:attacker.faith = {
                        has_doctrine = doctrine_pluralism_pluralistic
                    }
                }
                desc = religious_war_victory_desc_doctrine_pluralism
            }
            desc = religious_war_victory_desc
        }
    }

    on_victory = {
        scope:attacker = { show_pow_release_message_effect = yes }
        create_title_and_vassal_change = {
            type = conquest_holy_war
            save_scope_as = change
            add_claim_on_loss = yes
        }

        # go through the dejure hierarchy under target titles, transfer titles with same or worse tolerance holders (their religion equaly or less tolerated than the defender's),
        # take the holder as vassal otherwise and don't go deeper
        every_in_list = {
            list = target_titles
            custom_tooltip = RELIGIOUS_CB_TITLE

            conquest_cb_title_transfer = {
                RELIGIOUS_WAR = yes
            }
        }

        every_in_list = {
            list = vassals_taken
            change_liege = {
                liege = scope:attacker
                change = scope:change
            }
        }
        
        every_in_list = {
            list = titles_taken
            change_title_holder = {
                holder = scope:attacker
                change = scope:change
                take_baronies = yes
            }
        }

        resolve_title_and_vassal_change = scope:change

        # Prestige for the attacker's war allies
        add_from_contribution_attackers = {
            prestige = religious_cb_ally_prestige_county
            opinion = {
                modifier = contributed_in_war
            }
        }

        # Prestige for the defender's war allies
        add_from_contribution_defenders = {
            prestige = religious_cb_ally_prestige_county
            opinion = {
                modifier = contributed_in_war
            }
        }

        # Piety Progress for the Attacker
        every_in_list = {
            list = target_titles
            scope:attacker = {
                add_piety_experience = {
                    add = religious_cb_piety_gain_county
                    if = {
                        limit = {
                            scope:attacker.faith = {
                                has_doctrine_parameter = bonus_holy_war_piety_active
                            }
                        }
                        multiply = 1.5
                    }
                }
            }
        }

        scope:attacker.faith = {
            change_fervor = -1
        }
        scope:defender.faith = {
            change_fervor = 3
        }

        # Truce
        add_truce_attacker_victory_effect = yes

        # FP1: note the victory for future memorialisation via stele (if applicable).
        scope:attacker = { fp1_remember_recent_conquest_victory_effect = yes }
    }

    on_white_peace_desc = {
        desc = religious_war_white_peace_desc
    }

    on_white_peace = {
        scope:attacker = { show_pow_release_message_effect = yes }

        # Prestige for the attacker's war allies
        add_from_contribution_attackers = {
            prestige = religious_cb_ally_prestige_county
            opinion = {
                modifier = contributed_in_war
            }
        }

        # Prestige for the defender's war allies
        add_from_contribution_defenders = {
            prestige = religious_cb_ally_prestige_county
            opinion = {
                modifier = contributed_in_war
            }
        }

        # Truce
        add_truce_white_peace_effect = yes

        scope:attacker = {
            add_piety = religious_cb_piety_white_peace
            stress_impact = {
                ambitious = medium_stress_impact_gain
                arrogant = medium_stress_impact_gain
            }
        }

        scope:defender = {
            stress_impact = {
                arrogant = medium_stress_impact_gain
            }
        }
    }

    on_defeat_desc = {
        desc = religious_war_defeat_desc
    }

    on_defeat = {
        scope:attacker = { show_pow_release_message_effect = yes }

        # Prestige for the attacker's war allies
        add_from_contribution_attackers = {
            prestige = religious_cb_ally_prestige_county
            opinion = {
                modifier = contributed_in_war
            }
        }
        scope:attacker = {
            every_vassal = {
                limit = { faith = scope:attacker.faith }
                custom = all_attackers_vassals_same_faith
                add_opinion = {
                    modifier = liege_lost_declared_religious_war
                    target = scope:attacker
                }
            }
        }

        # Prestige for the defender's war allies
        add_from_contribution_defenders = {
            prestige = religious_cb_ally_prestige_county
            opinion = {
                modifier = contributed_in_war
            }
        }

        # piety change
        every_in_list = {
            list = target_titles

            scope:defender = {
                add_piety = {
                    add = religious_cb_piety_gain_county
                    if = {
                        limit = {
                            scope:defender.faith = {
                                has_doctrine_parameter = bonus_holy_war_piety_active
                            }
                        }
                        multiply = 1.5
                    }
                }
            }

            scope:attacker = {
                if = {
                    limit = {
                        monthly_character_income > 0
                    }
                    pay_short_term_income = {
                        years = 2
                        target = scope:defender
                    }
                }
                else = {
                    pay_short_term_gold = {
                        target = scope:defender
                        gold = medium_gold_value
                    }
                }
            }
        }

        # Truce
        add_truce_attacker_defeat_effect = yes

        scope:attacker = {
            save_temporary_scope_as = loser
        }
        on_lost_aggression_war_discontent_loss = yes
    }

    on_primary_attacker_death = inherit
    on_primary_defender_death = inherit

    transfer_behavior = transfer

    attacker_allies_inherit = yes
    defender_allies_inherit = yes

    war_name = "RELIGIOUS_WAR_NAME"
    cb_name = "HOLY_WAR_COUNTY_NAME"

    is_holy_war = yes

    interface_priority = 80

    use_de_jure_wargoal_only = yes

    attacker_wargoal_percentage = 0.8

    max_ai_diplo_distance_to_title = 500
    min_ai_score = 100
}

religious_war = {
    group = religious

    defender_faith_can_join = yes

    combine_into_one = yes
    should_show_war_goal_subview = yes
    mutually_exclusive_titles = { always = yes }

    # Additional requirements to the defines in 00_casus_belli_groups.txt
    allowed_for_character = {
        scope:attacker.faith = {
            NOT = { has_doctrine = unreformed_faith_doctrine }
        }
    }

    allowed_for_character_display_regardless = {
        trigger_if = {
            limit = {
                has_variable_list = humsacd_hofs
                is_target_in_variable_list = {
                    name = humsacd_hofs
                    target = scope:attacker.faith
                }
            }
            piety_level >= 1
        }
        trigger_else = { piety_level >= 2 }
    }

    allowed_against_character = {
        scope:attacker = {
            faith = {
                faith_hostility_level = {
                    target = scope:defender.faith
                    value >= religious_cb_enabled_hostility_level
                }
            }
            ALL_FALSE = {
                top_liege = scope:defender.top_liege
                liege = scope:defender
            }
        }
    }
    target_titles = neighbor_land_or_water
    target_title_tier = all
    target_de_jure_regions_above = yes
    ignore_effect = change_title_holder

    ai_score_mult = {
        value = get_ai_score_mult_value_for_holy_war
    }

    valid_to_start = {
        scope:target = {
            tier = tier_duchy
        }
    }

    should_invalidate = {
        OR = {
            NOT = {
                any_in_list = {
                    list = target_titles
                    any_in_de_jure_hierarchy = {
                        tier = tier_county
                        holder = {
                            OR = {
                                this = scope:defender
                                target_is_liege_or_above = scope:defender
                            }
                        }
                    }
                }
            }
            #Faith change does not immediately invalidate, it's run through event war_event.3100
            scope:war = { exists = var:invalidate_defender_faith_change }
            scope:war = { exists = var:invalidate_attacker_faith_change }
        }
    }

    on_invalidated_desc = {
        first_valid = {
            triggered_desc = {
                trigger = {
                    NOT = {
                        any_in_list = {
                            list = target_titles
                            any_in_de_jure_hierarchy = {
                                tier = tier_county
                                holder = {
                                    OR = {
                                        this = scope:defender
                                        target_is_liege_or_above = scope:defender
                                    }
                                }
                            }
                        }
                    }
                }
                desc = msg_religious_war_invalidation_region_message
            }
            triggered_desc = {
                trigger = {
                    scope:war = {
                        OR = {
                            exists = var:invalidate_defender_faith_change
                            exists = var:invalidate_attacker_faith_change
                        }
                    }
                }
                desc = msg_religious_war_invalidated_hostility_level_message
            }
        }
    }

    on_invalidated = {
        
    }

    cost = {
        piety = {
            add = {
                value = 200
                desc = CB_BASE_COST
            }
            # Faith Doctrine Piety Discounts
            if = {
                limit = {
                    scope:attacker.faith = {
                        has_doctrine_parameter = divine_destiny_holy_war_cost_reduction
                    }
                }
                multiply = {
                    value = 0.5
                    desc = CB_DIVINE_DESTINY_COST
                }
            }

            if = {
                limit = {
                    scope:attacker.faith = {
                        has_doctrine_parameter = cheaper_holy_wars_active
                    }
                }
                multiply = {
                    value = 0.8
                    desc = CB_REDUCED_HOLY_WAR_COST
                }
            }

            # Innovation Piety Discounts
            if = {
                limit = {
                    scope:attacker = {
                        culture = {
                            has_innovation = innovation_reconquista
                        }
                    }
                }
                multiply = {
                    value = 0.9
                    desc = CB_RECONQUISTA_COST
                }
            }

            # Bellum Justum Perk
            if = {
                limit = {
                    scope:attacker = {
                        has_perk = bellum_justum_perk
                    }
                }
                multiply = {
                    add = bellum_justum_discount_percentage
                    divide = 100
                    desc = CB_ATTACKER_BELLUM_JUSTUM
                }
            }

            # Dynasty Warfare Perk
            if = {
                limit = {
                    scope:attacker = {
                        has_dynasty = yes
                        dynasty = {
                            has_dynasty_perk = warfare_legacy_2
                        }
                    }
                }
                multiply = {
                    value = warfare_legacy_2_discount
                    desc = CB_ATTACKER_DYNASTY_WARFARE
                }
            }

            # Vassal contract in-realm cost reduction
            if = {
                limit = {
                    scope:attacker = {
                        is_independent_ruler = no
                        vassal_contract_has_flag = vassal_contract_war_override
                        liege = scope:defender.liege
                    }
                }
                multiply = {
                    value = war_declaration_rights_allowed_cost_reduction
                    desc = "CB_ATTACKER_VASSAL_CONTRACT"
                }
            }

            # Someone in the target region sacrificed your HoF.
            if = {
                limit = {
                    scope:defender = {
                        has_variable_list = humsacd_hofs
                        is_target_in_variable_list = {
                            name = humsacd_hofs
                            target = scope:attacker.faith
                        }
                    }
                }
                multiply = {
                    value = religious_cb_piety_discount_against_hof_humsac
                    desc = "CB_ATTACKER_HOF_HUMSACD"
                }
            }

            if = {
                limit = {
                    has_game_rule = no_cost_casus_belli_costs
                }
                multiply = {
                    value = 0
                    desc = CB_GAME_RULE_NO_COST
                }
            }
        }
    }

    on_declaration = {
        on_declared_war = yes
    }

    on_victory_desc = {
        first_valid = {
            triggered_desc = {
                trigger = {
                    scope:attacker.faith = {
                        has_doctrine = doctrine_pluralism_pluralistic
                    }
                }
                desc = religious_war_victory_desc_doctrine_pluralism
            }
            desc = religious_war_victory_desc
        }
    }

    on_victory = {
        scope:attacker = { show_pow_release_message_effect = yes }
        create_title_and_vassal_change = {
            type = conquest_holy_war
            save_scope_as = change
            add_claim_on_loss = yes
        }

        # go through the dejure hierarchy under target titles, transfer titles with same or worse tolerance holders (their religion equaly or less tolerated than the defender's),
        # take the holder as vassal otherwise and don't go deeper
        every_in_list = {
            list = target_titles
            custom_tooltip = RELIGIOUS_CB_TITLE

            conquest_cb_title_transfer = {
                RELIGIOUS_WAR = yes
            }
        }

        every_in_list = {
            list = vassals_taken
            change_liege = {
                liege = scope:attacker
                change = scope:change
            }
        }
        
        every_in_list = {
            list = titles_taken
            change_title_holder = {
                holder = scope:attacker
                change = scope:change
                take_baronies = yes
            }
        }


        resolve_title_and_vassal_change = scope:change

        # Prestige for the attacker's war allies
        add_from_contribution_attackers = {
            prestige = religious_cb_ally_prestige_duchy
            opinion = {
                modifier = contributed_in_war
            }
        }

        # Prestige for the defender's war allies
        add_from_contribution_defenders = {
            prestige = religious_cb_ally_prestige_duchy
            opinion = {
                modifier = contributed_in_war
            }
        }

        # Piety Progress for the Attacker
        every_in_list = {
            list = target_titles
                scope:attacker = {
                add_piety_experience = {
                    add = religious_cb_piety_gain_duchy
                    if = {
                        limit = {
                            scope:attacker.faith = {
                                has_doctrine_parameter = bonus_holy_war_piety_active
                            }
                        }
                        multiply = 1.5
                    }
                }
            }
        }

        scope:attacker.faith = {
            change_fervor = -2
        }
        scope:defender.faith = {
            change_fervor = 4
        }

        # Truce
        add_truce_attacker_victory_effect = yes

        # FP1: note the victory for future memorialisation via stele (if applicable).
        scope:attacker = { fp1_remember_recent_conquest_victory_effect = yes }
    }

    on_white_peace_desc = {
        desc = religious_war_white_peace_desc
    }

    on_white_peace = {
        scope:attacker = { show_pow_release_message_effect = yes }

        # Prestige for the attacker's war allies
        add_from_contribution_attackers = {
            prestige = religious_cb_ally_prestige_duchy
            opinion = {
                modifier = contributed_in_war
            }
        }

        # Prestige for the defender's war allies
        add_from_contribution_defenders = {
            prestige = religious_cb_ally_prestige_duchy
            opinion = {
                modifier = contributed_in_war
            }
        }

        # Truce
        add_truce_white_peace_effect = yes

        scope:attacker = {
            add_piety = religious_cb_piety_white_peace
            stress_impact = {
                ambitious = medium_stress_impact_gain
                arrogant = medium_stress_impact_gain
            }
        }

        scope:defender = {
            stress_impact = {
                arrogant = medium_stress_impact_gain
            }
        }
    }

    on_defeat_desc = {
        desc = religious_war_defeat_desc
    }

    on_defeat = {
        scope:attacker = { show_pow_release_message_effect = yes }

        # Prestige for the attacker's war allies
        add_from_contribution_attackers = {
            prestige = religious_cb_ally_prestige_duchy
            opinion = {
                modifier = contributed_in_war
            }
        }

        # Prestige for the defender's war allies
        add_from_contribution_defenders = {
            prestige = religious_cb_ally_prestige_duchy
            opinion = {
                modifier = contributed_in_war
            }
        }

        # piety change
        every_in_list = {
            list = target_titles

            scope:defender = {
                add_piety = {
                    add = religious_cb_piety_gain_duchy
                    if = {
                        limit = {
                            scope:defender.faith = {
                                has_doctrine_parameter = bonus_holy_war_piety_active
                            }
                        }
                        multiply = 1.5
                    }
                }
            }

            scope:attacker = {
                if = {
                    limit = {
                        monthly_character_income > 0
                    }
                    pay_short_term_income = {
                        years = 3
                        target = scope:defender
                    }
                }
                else = {
                    pay_short_term_gold = {
                        target = scope:defender
                        gold = medium_gold_value
                    }
                }
            }
        }

        scope:attacker = {
            every_vassal = {
                limit = { faith = scope:attacker.faith }
                custom = all_attackers_vassals_same_faith
                add_opinion = {
                    modifier = liege_lost_declared_religious_war
                    target = scope:attacker
                }
            }
        }

        # Truce
        add_truce_attacker_defeat_effect = yes

        scope:attacker = {
            save_temporary_scope_as = loser
        }
        on_lost_aggression_war_discontent_loss = yes
    }

    on_primary_attacker_death = inherit
    on_primary_defender_death = inherit

    transfer_behavior = transfer

    attacker_allies_inherit = yes
    defender_allies_inherit = yes

    war_name = "RELIGIOUS_WAR_NAME"
    cb_name = "HOLY_WAR_DUCHY_NAME"

    is_holy_war = yes

    interface_priority = 80

    use_de_jure_wargoal_only = yes

    attacker_wargoal_percentage = 0.8

    max_ai_diplo_distance_to_title = 500

    ai_score_mult = {
        value = 1
        # Holy War are limited to connected neighbour to limit big empire expansions over weak realms.
        add = {
            if = {
                limit = {  religious_war_vassals_constraints = yes }
                add = -1000
            }
        }
    }
}

major_religious_war = {
    group = religious

    defender_faith_can_join = yes

    combine_into_one = yes
    should_show_war_goal_subview = yes
    mutually_exclusive_titles = { always = yes }

    # Additional requirements to the defines in 00_casus_belli_groups.txt
    allowed_for_character = {
        scope:attacker.faith = {
            NOT = { has_doctrine = unreformed_faith_doctrine }
        }
    }

    allowed_for_character_display_regardless = {
        trigger_if = {
            limit = {
                has_variable_list = humsacd_hofs
                is_target_in_variable_list = {
                    name = humsacd_hofs
                    target = scope:attacker.faith
                }
            }
            piety_level >= 3
        }
        trigger_else = { piety_level >= 4 }
        custom_description = {
            text = declared_major_religious_war_flag_tt
            NOT = { has_character_flag = declared_major_religious_war_flag }
        }
    }

    allowed_against_character = {
        scope:attacker = {
            faith = {
                faith_hostility_level = {
                    target = scope:defender.faith
                    value >= religious_cb_enabled_hostility_level
                }
            }
            ALL_FALSE = {
                top_liege = scope:defender.top_liege
                liege = scope:defender
            }
        }
    }
    target_titles = neighbor_land_or_water
    target_title_tier = all
    target_de_jure_regions_above = yes
    ignore_effect = change_title_holder

    ai_score_mult = {
        value = get_ai_score_mult_value_for_holy_war
    }

    valid_to_start = {
        scope:target = {
            tier = tier_kingdom
        }
    }

    should_invalidate = {
        OR = {
            NOT = {
                any_in_list = {
                    list = target_titles
                    any_in_de_jure_hierarchy = {
                        tier = tier_county
                        holder = {
                            OR = {
                                this = scope:defender
                                target_is_liege_or_above = scope:defender
                            }
                        }
                    }
                }
            }
            #Faith change does not immediately invalidate, it's run through event war_event.3100
            scope:war = { exists = var:invalidate_defender_faith_change }
            scope:war = { exists = var:invalidate_attacker_faith_change }
        }
    }

    on_invalidated_desc = {
        first_valid = {
            triggered_desc = {
                trigger = {
                    NOT = {
                        any_in_list = {
                            list = target_titles
                            any_in_de_jure_hierarchy = {
                                tier = tier_county
                                holder = {
                                    OR = {
                                        this = scope:defender
                                        target_is_liege_or_above = scope:defender
                                    }
                                }
                            }
                        }
                    }
                }
                desc = msg_religious_war_invalidation_region_message
            }
            triggered_desc = {
                trigger = {
                    scope:war = {
                        OR = {
                            exists = var:invalidate_defender_faith_change
                            exists = var:invalidate_attacker_faith_change
                        }
                    }
                }
                desc = msg_religious_war_invalidated_hostility_level_message
            }
        }
    }
    
    on_invalidated = {
        
    }

    cost = {
        piety = {
            add = {
                value = 750
                desc = CB_BASE_COST
            }
            # Faith Doctrine Piety Discounts
            if = {
                limit = {
                    scope:attacker.faith = {
                        has_doctrine_parameter = divine_destiny_holy_war_cost_reduction
                    }
                }
                multiply = {
                    value = 0.5
                    desc = CB_DIVINE_DESTINY_COST
                }
            }

            if = {
                limit = {
                    scope:attacker.faith = {
                        has_doctrine_parameter = cheaper_holy_wars_active
                    }
                }
                multiply = {
                    value = 0.8
                    desc = CB_REDUCED_HOLY_WAR_COST
                }
            }

            # Innovation Piety Discounts
            if = {
                limit = {
                    scope:attacker = {
                        culture = {
                            has_innovation = innovation_reconquista
                        }
                    }
                }
                multiply = {
                    value = 0.9
                    desc = CB_RECONQUISTA_COST
                }
            }

            # Bellum Justum Perk
            if = {
                limit = {
                    scope:attacker = {
                        has_perk = bellum_justum_perk
                    }
                }
                multiply = {
                    add = bellum_justum_discount_percentage
                    divide = 100
                    desc = CB_ATTACKER_BELLUM_JUSTUM
                }
            }

            # Dynasty Warfare Perk
            if = {
                limit = {
                    scope:attacker = {
                        has_dynasty = yes
                        dynasty = {
                            has_dynasty_perk = warfare_legacy_2
                        }
                    }
                }
                multiply = {
                    value = warfare_legacy_2_discount
                    desc = CB_ATTACKER_DYNASTY_WARFARE
                }
            }

            # Vassal contract in-realm cost reduction
            if = {
                limit = {
                    scope:attacker = {
                        is_independent_ruler = no
                        vassal_contract_has_flag = vassal_contract_war_override
                        liege = scope:defender.liege
                    }
                }
                multiply = {
                    value = war_declaration_rights_allowed_cost_reduction
                    desc = "CB_ATTACKER_VASSAL_CONTRACT"
                }
            }

            # Someone in the target region sacrificed your HoF.
            if = {
                limit = {
                    scope:defender = {
                        has_variable_list = humsacd_hofs
                        is_target_in_variable_list = {
                            name = humsacd_hofs
                            target = scope:attacker.faith
                        }
                    }
                }
                multiply = {
                    value = religious_cb_piety_discount_against_hof_humsac
                    desc = "CB_ATTACKER_HOF_HUMSACD"
                }
            }

            if = {
                limit = {
                    has_game_rule = no_cost_casus_belli_costs
                }
                multiply = {
                    value = 0
                    desc = CB_GAME_RULE_NO_COST
                }
            }
        }
    }

    on_declaration = {
        on_declared_war = yes
        scope:attacker = { add_character_flag = declared_major_religious_war_flag }
    }

    on_victory_desc = {
        first_valid = {
            triggered_desc = {
                trigger = {
                    scope:attacker.faith = {
                        has_doctrine = doctrine_pluralism_pluralistic
                    }
                }
                desc = religious_war_victory_desc_doctrine_pluralism
            }
            desc = religious_war_victory_desc
        }
        triggered_desc = {
            trigger = { scope:attacker = { is_local_player = yes } }
            desc = major_religious_war_warning_desc
        }
    }

    on_victory = {
        scope:attacker = { show_pow_release_message_effect = yes }
        create_title_and_vassal_change = {
            type = conquest_holy_war
            save_scope_as = change
            add_claim_on_loss = yes
        }
        # go through the dejure hierarchy under target titles, transfer titles with same or worse tolerance holders (their religion equaly or less tolerated than the defender's),
        # take the holder as vassal otherwise and don't go deeper
        every_in_list = {
            list = target_titles
            custom_tooltip = RELIGIOUS_CB_TITLE

            conquest_cb_title_transfer = {
                RELIGIOUS_WAR = yes
            }
        }

        every_in_list = {
            list = vassals_taken
            change_liege = {
                liege = scope:attacker
                change = scope:change
            }
        }
        
        every_in_list = {
            list = titles_taken
            change_title_holder = {
                holder = scope:attacker
                change = scope:change
                take_baronies = yes
            }
        }

        resolve_title_and_vassal_change = scope:change

        # Prestige for the attacker's war allies
        add_from_contribution_attackers = {
            prestige = religious_cb_ally_prestige_kingdom
            opinion = {
                modifier = contributed_in_war
            }
        }

        # Prestige for the defender's war allies
        add_from_contribution_defenders = {
            prestige = religious_cb_ally_prestige_kingdom
            opinion = {
                modifier = contributed_in_war
            }
        }

        # Piety Progress for the Attacker
        every_in_list = {
            list = target_titles
                scope:attacker = {
                add_piety_experience = {
                    add = religious_cb_piety_gain_kingdom
                    if = {
                        limit = {
                            scope:attacker.faith = {
                                has_doctrine_parameter = bonus_holy_war_piety_active
                            }
                        }
                        multiply = 1.5
                    }
                }
            }
        }

        scope:attacker.faith = {
            change_fervor = -5
        }
        scope:defender.faith = {
            change_fervor = 10
        }

        # Truce
        add_truce_attacker_victory_effect = yes

        # FP1: note the victory for future memorialisation via stele (if applicable).
        scope:attacker = { fp1_remember_recent_conquest_victory_effect = yes }
    }

    on_white_peace_desc = {
        desc = religious_war_white_peace_desc
    }

    on_white_peace = {
        scope:attacker = { show_pow_release_message_effect = yes }

        # Prestige for the attacker's war allies
        add_from_contribution_attackers = {
            prestige = religious_cb_ally_prestige_kingdom
            opinion = {
                modifier = contributed_in_war
            }
        }

        # Prestige for the defender's war allies
        add_from_contribution_defenders = {
            prestige = religious_cb_ally_prestige_kingdom
            opinion = {
                modifier = contributed_in_war
            }
        }

        scope:attacker = {
            add_piety = religious_cb_piety_white_peace
            stress_impact = {
                ambitious = medium_stress_impact_gain
                arrogant = medium_stress_impact_gain
            }
        }

        scope:defender = {
            stress_impact = {
                arrogant = medium_stress_impact_gain
            }
        }

        # Truce
        add_truce_white_peace_effect = yes
    }

    on_defeat_desc = {
        desc = religious_war_defeat_desc
    }

    on_defeat = {
        scope:attacker = { show_pow_release_message_effect = yes }

        # Prestige for the attacker's war allies
        add_from_contribution_attackers = {
            prestige = religious_cb_ally_prestige_kingdom
            opinion = {
                modifier = contributed_in_war
            }
        }

        # Prestige for the defender's war allies
        add_from_contribution_defenders = {
            prestige = religious_cb_ally_prestige_kingdom
            opinion = {
                modifier = contributed_in_war
            }
        }

        # piety change
        every_in_list = {
            list = target_titles

            scope:defender = {
                add_piety = {
                    add = religious_cb_piety_gain_kingdom
                    if = {
                        limit = {
                            scope:defender.faith = {
                                has_doctrine_parameter = bonus_holy_war_piety_active
                            }
                        }
                        multiply = 1.5
                    }
                }
            }

            scope:attacker = {
                if = {
                    limit = {
                        monthly_character_income > 0
                    }
                    pay_short_term_income = {
                        years = 4
                        target = scope:defender
                    }
                }
                else = {
                    pay_short_term_gold = {
                        target = scope:defender
                        gold = medium_gold_value
                    }
                }
            }
        }

        scope:attacker = {
            every_vassal = {
                limit = { faith = scope:attacker.faith }
                custom = all_attackers_vassals_same_faith
                add_opinion = {
                    modifier = liege_lost_declared_religious_war
                    target = scope:attacker
                }
            }
        }

        # Truce
        add_truce_attacker_defeat_effect = yes

        scope:attacker = {
            save_temporary_scope_as = loser
        }
        on_lost_aggression_war_discontent_loss = yes
    }

    on_primary_attacker_death = inherit
    on_primary_defender_death = inherit

    transfer_behavior = transfer

    attacker_allies_inherit = yes
    defender_allies_inherit = yes

    war_name = "RELIGIOUS_WAR_NAME"
    cb_name = "HOLY_WAR_KINGDOM_NAME"

    is_holy_war = yes

    interface_priority = 80

    use_de_jure_wargoal_only = yes

    attacker_wargoal_percentage = 0.8

    max_ai_diplo_distance_to_title = 500

    ai_score_mult = {
        value = 1
        # Holy War are limited to connected neighbour to limit big empire expansions over weak realms.
        add = {
            if = {
                limit = {  religious_war_vassals_constraints = yes }
                add = -1000
            }
        }
    }
}

excommunication_war = {
    group = religious
    ai_only_against_neighbors = yes

    # Already defined in 00_casus_belli_groups.txt
    # allowed_for_character = {}

    allowed_against_character = {
        scope:defender = {
            #Defender must be an excommunicated member of our faith.
            has_trait = excommunicated
            is_independent_ruler = yes
            faith = {
                has_doctrine_parameter = excommunication_active
                this = scope:attacker.faith
            }
        }

        scope:attacker = {
            #We can't DoW our own liege
            NOT = {
                liege = scope:defender
            }

            trigger_if = {
                limit = { is_ai = no } # Already pre-filtered by the AI due to ai_only_against_neighbors = yes. any_neighboring_top_liege_realm_owner is expensive
                #We have to be neighboring the excommunicated ruler.
                any_neighboring_top_liege_realm_owner = {
                    this = scope:defender
                }
            }
        }
    }

    target_de_jure_regions_above = yes

    valid_to_start = {
        always = yes
    }

    on_declaration = {
        on_declared_war = yes
    }

    on_victory_desc = {
        first_valid = {
            triggered_desc = {
                trigger = {
                    scope:defender = { is_local_player = yes }
                }
                desc = excommunication_war_victory_desc_defender
            }
            desc = excommunication_war_victory_desc
        }
    }

    on_victory = {
        scope:attacker = { show_pow_release_message_effect = yes }
        scope:attacker = {
            reverse_add_opinion = {
                modifier = pleased_opinion
                target = faith.religious_head
                opinion = 20
            }
        }

        #Handle all piety gains/losses in scripted effects.
        excommunication_cb_piety_change = {
            WINNER = scope:attacker
            LOSER = scope:defender
        }

        #This is ddown here in it's own section to control how the tooltips are ordered.
        scope:defender = {
            depose = yes
        }

        # Truce
        add_truce_attacker_victory_effect = yes
    }

    on_white_peace_desc = {
        first_valid = {
            triggered_desc = {
                trigger = {
                    scope:defender = { is_local_player = yes }
                }
                desc = excommunication_war_white_peace_desc_defender
            }
            desc = excommunication_war_white_peace_desc
        }
    }

    on_white_peace = {
        scope:attacker = { show_pow_release_message_effect = yes }
        scope:attacker = {
            add_piety = excommunication_cb_piety_white_peace
            stress_impact = {
                ambitious = medium_stress_impact_gain
                arrogant = medium_stress_impact_gain
            }
        }

        scope:defender = {
            stress_impact = {
                arrogant = medium_stress_impact_gain
            }
        }

        # Truce
        add_truce_white_peace_effect = yes
    }

    on_defeat_desc = {
        first_valid = {
            triggered_desc = {
                trigger = {
                    scope:attacker = { is_local_player = yes }
                }
                desc = excommunication_war_defeat_desc_attacker
            }
            triggered_desc = {
                trigger = {
                    scope:defender = { is_local_player = yes }
                }
                desc = excommunication_war_defeat_desc_defender
            }
            desc = excommunication_war_defeat_desc
        }
    }

    on_defeat = {
        scope:attacker = { show_pow_release_message_effect = yes }
        #Handle all piety gains/losses in scripted effects.
        excommunication_cb_piety_change = {
            LOSER = scope:attacker
            WINNER = scope:defender
        }

        scope:defender = {
            remove_trait = excommunicated
            add_character_modifier = {
                modifier = excommunication_recently_lifted
                years = 10
            }
        }

        scope:attacker = {
            reverse_add_opinion = {
                modifier = disappointed_opinion
                target = faith.religious_head
                opinion = -20
            }
        }

        # Truce
        add_truce_attacker_defeat_effect = yes
    }
    
    should_invalidate = {
        scope:defender = {
            NOT = {
                has_trait = excommunicated
            }
        }
    }

    on_invalidated_desc = {
        first_valid = {
            triggered_desc = {
                trigger = {
                    scope:defender = {
                        NOT = {
                            has_trait = excommunicated
                        }
                    }
                }
                desc = msg_excommunication_war_invalidation_trait_message
            }
            desc = msg_invalidate_war_title
        }
    }
    
    on_invalidated = {
        scope:attacker = {
            #Used for the piety_change scripted effect.
            save_scope_as = winner
        }

        #Handle all piety gains/losses in scripted effects.
        excommunication_cb_piety_change = {
            WINNER = scope:attacker
            LOSER = scope:defender
        }

        scope:defender = {
            depose = yes

            #Used for the piety_change scripted effect.
            save_scope_as = loser
        }
    }

    on_primary_attacker_death = invalidate
    on_primary_defender_death = inherit

    transfer_behavior = transfer

    attacker_allies_inherit = yes
    defender_allies_inherit = yes

    war_name = "EXCOMMUNICATION_WAR_NAME"

    interface_priority = 80

    use_de_jure_wargoal_only = yes

    attacker_wargoal_percentage = 0.8

    attacker_score_from_occupation_scale = 50
    defender_score_from_occupation_scale = 50
    #attacker_score_from_battles_scale = 50
    #defender_score_from_battles_scale = 50
    max_attacker_score_from_battles = 100
    max_defender_score_from_battles = 100

    max_ai_diplo_distance_to_title = 500

    ai_score_mult = {
        value = 1
        # Holy War are limited to connected neighbour to limit big empire expansions over weak realms.
        add = {
            if = {
                limit = {  religious_war_vassals_constraints = yes }
                add = -1000
            }
        }
    }
}

flowery_war_cb = {
    group = religious_disorganised
    ai_only_against_neighbors = yes

    # Root is the title
    # scope:attacker is the attacker
    # scope:defender is the defender
    allowed_against_character = {
        scope:attacker = {
            faith = { has_doctrine_parameter = flower_war_cb_active }
            NOT = {    #Must not have any leftover sacrificial prisoners/easy ability to get any.
                any_prisoner = { has_character_modifier = designated_human_sacrifice_modifier }
            }
        }

        scope:defender = {
            is_independent_ruler = yes
            trigger_if = {
                limit = { scope:attacker = { is_ai = no } } # Already pre-filtered by the AI due to ai_only_against_neighbors = yes. any_neighboring_top_liege_realm_owner is expensive
                scope:attacker = {
                    any_neighboring_top_liege_realm_owner = {
                        this = scope:defender
                    }
                }
            }
        }
    }

    cost = {
        piety = {
            add = {
                value = 100
                desc = CB_BASE_COST
            }
            # Faith Doctrine Piety Discounts
            if = {
                limit = {
                    scope:attacker.faith = {
                        has_doctrine_parameter = divine_destiny_holy_war_cost_reduction
                    }
                }
                multiply = {
                    value = 0.5
                    desc = CB_DIVINE_DESTINY_COST
                }
            }

            if = {
                limit = {
                    scope:attacker.faith = {
                        has_doctrine_parameter = cheaper_holy_wars_active
                    }
                }
                multiply = {
                    value = 0.8
                    desc = CB_REDUCED_HOLY_WAR_COST
                }
            }

            # Innovation Piety Discounts
            if = {
                limit = {
                    scope:attacker = {
                        culture = {
                            has_innovation = innovation_reconquista
                        }
                    }
                }
                multiply = {
                    value = 0.9
                    desc = CB_RECONQUISTA_COST
                }
            }

            # Bellum Justum Perk
            if = {
                limit = {
                    scope:attacker = {
                        has_perk = bellum_justum_perk
                    }
                }
                multiply = {
                    add = bellum_justum_discount_percentage
                    divide = 100
                    desc = CB_ATTACKER_BELLUM_JUSTUM
                }
            }

            # Dynasty Warfare Perk
            if = {
                limit = {
                    scope:attacker = {
                        has_dynasty = yes
                        dynasty = {
                            has_dynasty_perk = warfare_legacy_2
                        }
                    }
                }
                multiply = {
                    value = warfare_legacy_2_discount
                    desc = CB_ATTACKER_DYNASTY_WARFARE
                }
            }

            # Vassal contract in-realm cost reduction
            if = {
                limit = {
                    scope:attacker = {
                        is_independent_ruler = no
                        vassal_contract_has_flag = vassal_contract_war_override
                        liege = scope:defender.liege
                    }
                }
                multiply = {
                    value = war_declaration_rights_allowed_cost_reduction
                    desc = "CB_ATTACKER_VASSAL_CONTRACT"
                }
            }

            if = {
                limit = {
                    has_game_rule = no_cost_casus_belli_costs
                }
                multiply = {
                    value = 0
                    desc = CB_GAME_RULE_NO_COST
                }
            }
        }
    }

    should_invalidate = {
        OR = {
            AND = {    #A formal flowery war only invalidates if neither side is an interested participant.
                scope:attacker.faith = {
                    NOT = { has_doctrine_parameter = human_sacrifice_active }
                }
                scope:defender.faith = {
                    NOT = { has_doctrine_parameter = human_sacrifice_active }
                }
            }
            scope:attacker = {
                any_prisoner = { has_character_modifier = designated_human_sacrifice_modifier }
            }
        }
    }

    on_invalidated_desc = {
        first_valid = {
            triggered_desc = {
                trigger = {
                    scope:attacker = {
                        any_prisoner = { has_character_modifier = designated_human_sacrifice_modifier }
                    }
                }
                desc = flowery_war_cb_ended_invalid.desc_other_sacrifices_attacker
            }
            desc = flowery_war_cb_ended_invalid.desc_no_sacrificers
        }
    }

    on_invalidated = {
        
    }

    on_declaration = {
        on_declared_war = yes
    }

    on_victory_desc = {
        desc = flowery_war_cb_victory_desc
    }

    on_victory = {
        scope:attacker = { show_pow_release_message_effect = yes }
        scope:attacker = {
            if = {    #If the attacker enjoys human sacrifice, then this was sacred.
                limit = {
                    faith = { has_doctrine_parameter = human_sacrifice_active }
                }
                if = {
                    limit = { scope:defender.primary_title.tier = tier_county }
                    add_piety = { value = minor_piety_gain }
                }
                if = {
                    limit = { scope:defender.primary_title.tier = tier_duchy }
                    add_piety = { value = medium_piety_gain }
                }
                if = {
                    limit = { scope:defender.primary_title.tier = tier_kingdom }
                    add_piety = { value = major_piety_gain }
                }
                if = {
                    limit = { scope:defender.primary_title.tier = tier_empire }
                    add_piety = { value = massive_piety_gain }
                }
            }
            else = {    #If the attacker has since stopped enjoying human sacrifice, then the war was just prestigious.
                if = {
                    limit = { scope:defender.primary_title.tier = tier_county }
                    add_prestige = { value = minor_prestige_gain }
                }
                if = {
                    limit = { scope:defender.primary_title.tier = tier_duchy }
                    add_prestige = { value = medium_prestige_gain }
                }
                if = {
                    limit = { scope:defender.primary_title.tier = tier_kingdom }
                    add_prestige = { value = major_prestige_gain }
                }
                if = {
                    limit = { scope:defender.primary_title.tier = tier_empire }
                    add_prestige = { value = massive_prestige_gain }
                }
            }
        }
        scope:defender = {
            if = {    #If the defender shares the faith of the attacker, then this war was sacred for them too.
                limit = {
                    faith = { this = scope:attacker.faith }
                }
                if = {
                    limit = { scope:attacker.primary_title.tier = tier_county }
                    add_piety = {
                        value = minor_piety_gain
                        multiply = 0.75
                    }
                }
                if = {
                    limit = { scope:attacker.primary_title.tier = tier_duchy }
                    add_piety = {
                        value = medium_piety_gain
                        multiply = 0.75
                    }
                }
                if = {
                    limit = { scope:attacker.primary_title.tier = tier_kingdom }
                    add_piety = {
                        value = major_piety_gain
                        multiply = 0.75
                    }
                }
                if = {
                    limit = { scope:attacker.primary_title.tier = tier_empire }
                    add_piety = {
                        value = massive_piety_gain
                        multiply = 0.75
                    }
                }
            }
            else = {    #Otherwise, the war just sucked.
                if = {
                    limit = { scope:defender.primary_title.tier = tier_county }
                    add_prestige = { value = minor_prestige_loss }
                }
                if = {
                    limit = { scope:defender.primary_title.tier = tier_duchy }
                    add_prestige = { value = medium_prestige_loss }
                }
                if = {
                    limit = { scope:defender.primary_title.tier = tier_kingdom }
                    add_prestige = { value = major_prestige_loss }
                }
                if = {
                    limit = { scope:defender.primary_title.tier = tier_empire }
                    add_prestige = { value = massive_prestige_loss }
                }
            }
        }
        scope:attacker = {    #If the attacker has the appropriate tenet, grab some suitable courtiers from the defender.
            if = {
                limit = {
                    faith = { has_doctrine_parameter = human_sacrifice_active }
                }
                custom_tooltip = flowery_war_cb_prisoners.tt_attacker
                hidden_effect = {
                    scope:defender = {
                        every_courtier_or_guest = { add_to_list = potential_captives_list }
                        random_in_list = {    #Nab someone related to the defender, preferring tangentials.
                            list = potential_captives_list
                            limit = {
                                OR = {
                                    AND = {
                                        has_dynasty = yes
                                        dynasty = scope:defender.dynasty
                                    }
                                    is_consort_of = scope:defender
                                }
                            }
                            alternative_limit = { always = yes }
                            weight = {
                                base = 1
                                modifier = {
                                    add = 25
                                    NOT = { is_close_family_of = scope:defender }
                                }
                                modifier = {
                                    add = 15
                                    NOT = { is_extended_family_of = scope:defender }
                                }
                            }
                            add_to_list = definite_captives_list
                            save_temporary_scope_as = future_captive
                                scope:attacker = {
                                    imprison = {
                                        target = scope:future_captive
                                        type = dungeon
                                    }
                                }
                        }
                        random_in_list = {    #Always try to grab a second person.
                            list = potential_captives_list
                            limit = {
                                NOT = { is_in_list = definite_captives_list }
                            }
                            weight = {
                                base = 1
                                modifier = {
                                    add = 40
                                    NOT = {
                                        any_claim = {
                                            useful_courtier_or_guest_claim_trigger = { RULER = scope:defender }
                                        }
                                    }
                                }
                                modifier = {
                                    add = 10
                                    NAND = {
                                        can_be_chancellor_trigger = { COURT_OWNER = scope:defender }
                                        diplomacy >= high_skill_rating
                                    }
                                }
                                modifier = {
                                    add = 10
                                    NAND = {
                                        can_be_marshal_trigger = { COURT_OWNER = scope:defender }
                                        martial >= high_skill_rating
                                    }
                                }
                                modifier = {
                                    add = 10
                                    NAND = {
                                        can_be_steward_trigger = { COURT_OWNER = scope:defender }
                                        stewardship >= high_skill_rating
                                    }
                                }
                                modifier = {
                                    add = 10
                                    NAND = {
                                        can_be_spymaster_trigger = { COURT_OWNER = scope:defender }
                                        intrigue >= high_skill_rating
                                    }
                                }
                                modifier = {
                                    add = 10
                                    NOT = { learning >= high_skill_rating }
                                }
                                modifier = {
                                    add = 10
                                    NOT = {    prowess >= high_skill_rating }
                                }
                                modifier = {
                                    add = 50
                                    NOT = { is_close_or_extended_family_of = scope:defender }
                                }
                            }
                            add_to_list = definite_captives_list
                            save_temporary_scope_as = future_captive
                                scope:attacker = {
                                    imprison = {
                                        target = scope:future_captive
                                        type = dungeon
                                    }
                                }
                        }
                        random_in_list = {    #Always try to grab a third person.
                            list = potential_captives_list
                            limit = {
                                NOT = { is_in_list = definite_captives_list }
                            }
                            weight = {
                                base = 1
                                modifier = {
                                    add = 40
                                    NOT = {
                                        any_claim = {
                                            useful_courtier_or_guest_claim_trigger = { RULER = scope:defender }
                                        }
                                    }
                                }
                                modifier = {
                                    add = 10
                                    NAND = {
                                        can_be_chancellor_trigger = { COURT_OWNER = scope:defender }
                                        diplomacy >= high_skill_rating
                                    }
                                }
                                modifier = {
                                    add = 10
                                    NAND = {
                                        can_be_marshal_trigger = { COURT_OWNER = scope:defender }
                                        martial >= high_skill_rating
                                    }
                                }
                                modifier = {
                                    add = 10
                                    NAND = {
                                        can_be_steward_trigger = { COURT_OWNER = scope:defender }
                                        stewardship >= high_skill_rating
                                    }
                                }
                                modifier = {
                                    add = 10
                                    NAND = {
                                        can_be_spymaster_trigger = { COURT_OWNER = scope:defender }
                                        intrigue >= high_skill_rating
                                    }
                                }
                                modifier = {
                                    add = 10
                                    NOT = { learning >= high_skill_rating }
                                }
                                modifier = {
                                    add = 10
                                    NOT = {    prowess >= high_skill_rating }
                                }
                                modifier = {
                                    add = 50
                                    NOT = { is_close_or_extended_family_of = scope:defender }
                                }
                            }
                            add_to_list = definite_captives_list
                            save_temporary_scope_as = future_captive
                                scope:attacker = {
                                    imprison = {
                                        target = scope:future_captive
                                        type = dungeon
                                    }
                                }
                        }
                        if = {    #If at least duchy-tier, try to grab a fourth person.
                            limit = { primary_title.tier >= tier_duchy }
                            random_in_list = {
                                list = potential_captives_list
                                limit = {
                                    NOT = { is_in_list = definite_captives_list }
                                }
                                weight = {
                                    base = 1
                                    modifier = {
                                        add = 40
                                        NOT = {
                                            any_claim = {
                                                useful_courtier_or_guest_claim_trigger = { RULER = scope:defender }
                                            }
                                        }
                                    }
                                    modifier = {
                                        add = 10
                                        NAND = {
                                            can_be_chancellor_trigger = { COURT_OWNER = scope:defender }
                                            diplomacy >= high_skill_rating
                                        }
                                    }
                                    modifier = {
                                        add = 10
                                        NAND = {
                                            can_be_marshal_trigger = { COURT_OWNER = scope:defender }
                                            martial >= high_skill_rating
                                        }
                                    }
                                    modifier = {
                                        add = 10
                                        NAND = {
                                            can_be_steward_trigger = { COURT_OWNER = scope:defender }
                                            stewardship >= high_skill_rating
                                        }
                                    }
                                    modifier = {
                                        add = 10
                                        NAND = {
                                            can_be_spymaster_trigger = { COURT_OWNER = scope:defender }
                                            intrigue >= high_skill_rating
                                        }
                                    }
                                    modifier = {
                                        add = 10
                                        NOT = { learning >= high_skill_rating }
                                    }
                                    modifier = {
                                        add = 10
                                        NOT = { prowess >= high_skill_rating }
                                    }
                                }
                                add_to_list = definite_captives_list
                                save_temporary_scope_as = future_captive
                                scope:attacker = {
                                    imprison = {
                                        target = scope:future_captive
                                        type = dungeon
                                    }
                                }
                            }
                        }
                        if = {    #If at least kingdom-tier, try to grab a fifth person.
                            limit = { primary_title.tier >= tier_kingdom }
                            random_in_list = {
                                list = potential_captives_list
                                limit = {
                                    NOT = { is_in_list = definite_captives_list }
                                }
                                weight = {
                                    base = 1
                                    modifier = {
                                        add = 40
                                        NOT = {
                                            any_claim = {
                                                useful_courtier_or_guest_claim_trigger = { RULER = scope:defender }
                                            }
                                        }
                                    }
                                    modifier = {
                                        add = 10
                                        NAND = {
                                            can_be_chancellor_trigger = { COURT_OWNER = scope:defender }
                                            diplomacy >= high_skill_rating
                                        }
                                    }
                                    modifier = {
                                        add = 10
                                        NAND = {
                                            can_be_marshal_trigger = { COURT_OWNER = scope:defender }
                                            martial >= high_skill_rating
                                        }
                                    }
                                    modifier = {
                                        add = 10
                                        NAND = {
                                            can_be_steward_trigger = { COURT_OWNER = scope:defender }
                                            stewardship >= high_skill_rating
                                        }
                                    }
                                    modifier = {
                                        add = 10
                                        NAND = {
                                            can_be_spymaster_trigger = { COURT_OWNER = scope:defender }
                                            intrigue >= high_skill_rating
                                        }
                                    }
                                    modifier = {
                                        add = 10
                                        NOT = { learning >= high_skill_rating }
                                    }
                                    modifier = {
                                        add = 10
                                        NOT = { prowess >= high_skill_rating }
                                    }
                                }
                                add_to_list = definite_captives_list
                                save_temporary_scope_as = future_captive
                                scope:attacker = {
                                    imprison = {
                                        target = scope:future_captive
                                        type = dungeon
                                    }
                                }
                            }
                        }
                    }
                    every_in_list = {
                        list = definite_captives_list
                        add_character_modifier = {
                            modifier = designated_human_sacrifice_modifier
                            years = 2
                        }
                    }
                    trigger_event = {
                        id = human_sacrifice.0001
                        years = 2
                    }
                }
            }
        }

        # Prestige for the attacker's war allies
        add_from_contribution_attackers = {
            prestige = {
                value = major_prestige_value
            }
            opinion = {
                modifier = contributed_in_war
            }
        }

        # Prestige for the defender's war allies
        add_from_contribution_defenders = {
            prestige = {
                value = major_prestige_value
            }
            opinion = {
                modifier = contributed_in_war
            }
        }

        # Truce
        add_truce_attacker_victory_effect = yes

    }

    on_white_peace_desc = {
        desc = flowery_war_cb_white_peace_desc
    }

    on_white_peace = {
        scope:attacker = {
            show_pow_release_message_effect = yes
            stress_impact = {
                ambitious = medium_stress_impact_gain
                arrogant = medium_stress_impact_gain
            }
        }
        scope:attacker = {    #Piety loss for the attacker if appropriate, otherwise prestige loss.
            if = {
                limit = {
                    faith = { has_doctrine_parameter = human_sacrifice_active }
                }
                add_piety = religious_cb_piety_white_peace
            }
            else = {
                add_prestige = {
                    value = medium_prestige_loss
                }
            }
        }



        # Prestige for the attacker's war allies
        add_from_contribution_attackers = {
            prestige = {
                value = major_prestige_value
            }
            opinion = {
                modifier = contributed_in_war
            }
        }

        # Prestige for the defender's war allies
        add_from_contribution_defenders = {
            prestige = {
                value = major_prestige_value
            }
            opinion = {
                modifier = contributed_in_war
            }
        }

        scope:defender = {
            stress_impact = {
                arrogant = medium_stress_impact_gain
            }
        }

        # Truce
        add_truce_attacker_victory_effect = yes

    }

    on_defeat_desc = {
        desc = flowery_war_cb_defeat_desc
    }

    on_defeat = {
        scope:attacker = { show_pow_release_message_effect = yes }
        scope:attacker = {
            if = {    #If the attacker shares the faith of the defender, and both still enjoy human sacrifice, then this war was at least sacred for them.
                limit = {
                    faith = {
                        this = scope:defender.faith
                        has_doctrine_parameter = human_sacrifice_active
                    }
                }
                if = {
                    limit = { scope:defender.primary_title.tier = tier_county }
                    add_piety = {
                        value = minor_piety_gain
                        multiply = 0.75
                    }
                }
                if = {
                    limit = { scope:defender.primary_title.tier = tier_duchy }
                    add_piety = {
                        value = medium_piety_gain
                        multiply = 0.75
                     }
                }
                if = {
                    limit = { scope:defender.primary_title.tier = tier_kingdom }
                    add_piety = {
                        value = major_piety_gain
                        multiply = 0.75
                    }
                }
                if = {
                    limit = { scope:defender.primary_title.tier = tier_empire }
                    add_piety = {
                        value = massive_piety_gain
                        multiply = 0.75
                    }
                }
            }
            else = {    #Otherwise, the war just sucked.
                if = {
                    limit = { scope:attacker.primary_title.tier = tier_county }
                    add_prestige = { value = minor_prestige_loss }
                }
                if = {
                    limit = { scope:attacker.primary_title.tier = tier_duchy }
                    add_prestige = { value = medium_prestige_loss }
                }
                if = {
                    limit = { scope:attacker.primary_title.tier = tier_kingdom }
                    add_prestige = { value = major_prestige_loss }
                }
                if = {
                    limit = { scope:attacker.primary_title.tier = tier_empire }
                    add_prestige = { value = massive_prestige_loss }
                }
            }
        }
        scope:defender = {
            if = {    #If the defender has the same faith as the attacker, and that faith still enjoys human sacrifice, then this was sacred.
                limit = {
                    faith = {
                        this = scope:attacker.faith
                        has_doctrine_parameter = human_sacrifice_active
                    }
                }
                if = {
                    limit = { scope:attacker.primary_title.tier = tier_county }
                    add_piety = { value = minor_piety_gain }
                }
                if = {
                    limit = { scope:attacker.primary_title.tier = tier_duchy }
                    add_piety = { value = medium_piety_gain }
                }
                if = {
                    limit = { scope:attacker.primary_title.tier = tier_kingdom }
                    add_piety = { value = major_piety_gain }
                }
                if = {
                    limit = { scope:attacker.primary_title.tier = tier_empire }
                    add_piety = { value = massive_piety_gain }
                }
            }
            else = {    #Otherwise, the war was just prestigious.
                if = {
                    limit = { scope:attacker.primary_title.tier = tier_county }
                    add_prestige = { value = minor_prestige_gain }
                }
                if = {
                    limit = { scope:attacker.primary_title.tier = tier_duchy }
                    add_prestige = { value = medium_prestige_gain }
                }
                if = {
                    limit = { scope:attacker.primary_title.tier = tier_kingdom }
                    add_prestige = { value = major_prestige_gain }
                }
                if = {
                    limit = { scope:attacker.primary_title.tier = tier_empire }
                    add_prestige = { value = massive_prestige_gain }
                }
            }
        }
        scope:defender = {    #If the defender has the appropriate tenet, and doesn't already have sacrificial victims, grab some suitable courtiers from the attacker.
            if = {
                limit = {
                    faith = { has_doctrine_parameter = human_sacrifice_active }
                    NOT = {    #Must not have any leftover sacrificial prisoners, lest the defender get borked sacrifice-accounting events.
                        any_prisoner = { has_character_modifier = designated_human_sacrifice_modifier }
                    }
                }
                custom_tooltip = flowery_war_cb_prisoners.tt_defender
                hidden_effect = {
                    scope:attacker = {
                        every_courtier_or_guest = { add_to_list = potential_captives_list }
                        random_in_list = {    #Nab someone related to the attacker, preferring tangentials.
                            list = potential_captives_list
                            limit = {
                                OR = {
                                    AND = {
                                        has_dynasty = yes
                                        dynasty = scope:attacker.dynasty
                                    }
                                    is_consort_of = scope:attacker
                                }
                            }
                            alternative_limit = { always = yes }
                            weight = {
                                base = 1
                                modifier = {
                                    add = 25
                                    NOT = { is_close_family_of = scope:attacker }
                                }
                                modifier = {
                                    add = 15
                                    NOT = { is_extended_family_of = scope:attacker }
                                }
                            }
                            add_to_list = definite_captives_list
                            save_temporary_scope_as = future_captive
                                scope:defender = {
                                    imprison = {
                                        target = scope:future_captive
                                        type = dungeon
                                    }
                                }
                        }
                        random_in_list = {    #Always try to grab a second person.
                            list = potential_captives_list
                            limit = {
                                NOT = { is_in_list = definite_captives_list }
                            }
                            weight = {
                                base = 1
                                modifier = {
                                    add = 40
                                    NOT = {
                                        any_claim = {
                                            useful_courtier_or_guest_claim_trigger = { RULER = scope:attacker }
                                        }
                                    }
                                }
                                modifier = {
                                    add = 10
                                    NAND = {
                                        can_be_chancellor_trigger = { COURT_OWNER = scope:attacker }
                                        diplomacy >= high_skill_rating
                                    }
                                }
                                modifier = {
                                    add = 10
                                    NAND = {
                                        can_be_marshal_trigger = { COURT_OWNER = scope:attacker }
                                        martial >= high_skill_rating
                                    }
                                }
                                modifier = {
                                    add = 10
                                    NAND = {
                                        can_be_steward_trigger = { COURT_OWNER = scope:attacker }
                                        stewardship >= high_skill_rating
                                    }
                                }
                                modifier = {
                                    add = 10
                                    NAND = {
                                        can_be_spymaster_trigger = { COURT_OWNER = scope:attacker }
                                        intrigue >= high_skill_rating
                                    }
                                }
                                modifier = {
                                    add = 10
                                    NOT = { learning >= high_skill_rating }
                                }
                                modifier = {
                                    add = 10
                                    NOT = {    prowess >= high_skill_rating }
                                }
                                modifier = {
                                    add = 50
                                    NOT = { is_close_or_extended_family_of = scope:defender }
                                }
                            }
                            add_to_list = definite_captives_list
                            save_temporary_scope_as = future_captive
                                scope:defender = {
                                    imprison = {
                                        target = scope:future_captive
                                        type = dungeon
                                    }
                                }
                        }
                        random_in_list = {    #Always try to grab a third person.
                            list = potential_captives_list
                            limit = {
                                NOT = { is_in_list = definite_captives_list }
                            }
                            weight = {
                                base = 1
                                modifier = {
                                    add = 40
                                    NOT = {
                                        any_claim = {
                                            useful_courtier_or_guest_claim_trigger = { RULER = scope:attacker }
                                        }
                                    }
                                }
                                modifier = {
                                    add = 10
                                    NAND = {
                                        can_be_chancellor_trigger = { COURT_OWNER = scope:attacker }
                                        diplomacy >= high_skill_rating
                                    }
                                }
                                modifier = {
                                    add = 10
                                    NAND = {
                                        can_be_marshal_trigger = { COURT_OWNER = scope:attacker }
                                        martial >= high_skill_rating
                                    }
                                }
                                modifier = {
                                    add = 10
                                    NAND = {
                                        can_be_steward_trigger = { COURT_OWNER = scope:attacker }
                                        stewardship >= high_skill_rating
                                    }
                                }
                                modifier = {
                                    add = 10
                                    NAND = {
                                        can_be_spymaster_trigger = { COURT_OWNER = scope:attacker }
                                        intrigue >= high_skill_rating
                                    }
                                }
                                modifier = {
                                    add = 10
                                    NOT = { learning >= high_skill_rating }
                                }
                                modifier = {
                                    add = 10
                                    NOT = {    prowess >= high_skill_rating }
                                }
                                modifier = {
                                    add = 50
                                    NOT = { is_close_or_extended_family_of = scope:defender }
                                }
                            }
                            add_to_list = definite_captives_list
                            save_temporary_scope_as = future_captive
                                scope:defender = {
                                    imprison = {
                                        target = scope:future_captive
                                        type = dungeon
                                    }
                                }
                        }
                        if = {    #If at least duchy-tier, try to grab a fourth person.
                            limit = { primary_title.tier >= tier_duchy }
                            random_in_list = {
                                list = potential_captives_list
                                limit = {
                                    NOT = { is_in_list = definite_captives_list }
                                }
                                weight = {
                                    base = 1
                                    modifier = {
                                        add = 40
                                        NOT = {
                                            any_claim = {
                                                useful_courtier_or_guest_claim_trigger = { RULER = scope:attacker }
                                            }
                                        }
                                    }
                                    modifier = {
                                        add = 10
                                        NAND = {
                                            can_be_chancellor_trigger = { COURT_OWNER = scope:attacker }
                                            diplomacy >= high_skill_rating
                                        }
                                    }
                                    modifier = {
                                        add = 10
                                        NAND = {
                                            can_be_marshal_trigger = { COURT_OWNER = scope:attacker }
                                            martial >= high_skill_rating
                                        }
                                    }
                                    modifier = {
                                        add = 10
                                        NAND = {
                                            can_be_steward_trigger = { COURT_OWNER = scope:attacker }
                                            stewardship >= high_skill_rating
                                        }
                                    }
                                    modifier = {
                                        add = 10
                                        NAND = {
                                            can_be_spymaster_trigger = { COURT_OWNER = scope:attacker }
                                            intrigue >= high_skill_rating
                                        }
                                    }
                                    modifier = {
                                        add = 10
                                        NOT = { learning >= high_skill_rating }
                                    }
                                    modifier = {
                                        add = 10
                                        NOT = { prowess >= high_skill_rating }
                                    }
                                }
                                add_to_list = definite_captives_list
                                save_temporary_scope_as = future_captive
                                scope:defender = {
                                    imprison = {
                                        target = scope:future_captive
                                        type = dungeon
                                    }
                                }
                            }
                        }
                        if = {    #If at least kingdom-tier, try to grab a fifth person.
                            limit = { primary_title.tier >= tier_kingdom }
                            random_in_list = {
                                list = potential_captives_list
                                limit = {
                                    NOT = { is_in_list = definite_captives_list }
                                }
                                weight = {
                                    base = 1
                                    modifier = {
                                        add = 40
                                        NOT = {
                                            any_claim = {
                                                useful_courtier_or_guest_claim_trigger = { RULER = scope:attacker }
                                            }
                                        }
                                    }
                                    modifier = {
                                        add = 10
                                        NAND = {
                                            can_be_chancellor_trigger = { COURT_OWNER = scope:attacker }
                                            diplomacy >= high_skill_rating
                                        }
                                    }
                                    modifier = {
                                        add = 10
                                        NAND = {
                                            can_be_marshal_trigger = { COURT_OWNER = scope:attacker }
                                            martial >= high_skill_rating
                                        }
                                    }
                                    modifier = {
                                        add = 10
                                        NAND = {
                                            can_be_steward_trigger = { COURT_OWNER = scope:attacker }
                                            stewardship >= high_skill_rating
                                        }
                                    }
                                    modifier = {
                                        add = 10
                                        NAND = {
                                            can_be_spymaster_trigger = { COURT_OWNER = scope:attacker }
                                            intrigue >= high_skill_rating
                                        }
                                    }
                                    modifier = {
                                        add = 10
                                        NOT = { learning >= high_skill_rating }
                                    }
                                    modifier = {
                                        add = 10
                                        NOT = { prowess >= high_skill_rating }
                                    }
                                }
                                add_to_list = definite_captives_list
                                save_temporary_scope_as = future_captive
                                scope:defender = {
                                    imprison = {
                                        target = scope:future_captive
                                        type = dungeon
                                    }
                                }
                            }
                        }
                    }
                    every_in_list = {
                        list = definite_captives_list
                        add_character_modifier = {
                            modifier = designated_human_sacrifice_modifier
                            years = 2
                        }
                    }
                    trigger_event = {
                        id = human_sacrifice.0001
                        years = 2
                    }
                }
            }
        }

        # Prestige for the attacker's war allies
        add_from_contribution_attackers = {
            prestige = {
                value = major_prestige_value
            }
            opinion = {
                modifier = contributed_in_war
            }
        }

        # Prestige for the defender's war allies
        add_from_contribution_defenders = {
            prestige = {
                value = major_prestige_value
            }
            opinion = {
                modifier = contributed_in_war
            }
        }

        # Truce
        add_truce_attacker_victory_effect = yes

        scope:attacker = { save_temporary_scope_as = loser }
        on_lost_aggression_war_discontent_loss = yes
    }

    on_primary_attacker_death = inherit
    on_primary_defender_death = inherit

    attacker_allies_inherit = yes
    defender_allies_inherit = yes

    war_name = "FLOWERY_WAR_CB_NAME"
    war_name_base = "FLOWERY_WAR_WAR_NAME_BASE"
    cb_name = "FLOWERY_WAR_CB_NAME"
    interface_priority = 80

    ticking_war_score_targets_entire_realm = yes
    attacker_ticking_warscore = 0
    attacker_wargoal_percentage = 0.01
    attacker_score_from_occupation_scale = 50
    defender_score_from_occupation_scale = 50
    attacker_score_from_battles_scale = 200
    defender_score_from_battles_scale = 200

    max_attacker_score_from_battles = 200
    max_defender_score_from_battles = 200

    max_ai_diplo_distance_to_title = 500

    ai_score_mult = {
        value = 1
        # Holy War are limited to connected neighbour to limit big empire expansions over weak realms.
        add = {
            if = {
                limit = {  religious_war_vassals_constraints = yes }
                add = -1000
            }
        }
    }
}

undirected_great_holy_war = {
    group = religious_script_only

    war_name = "GREAT_HOLY_WAR_WAR_NAME"

    target_titles = all
    target_title_tier = all
    target_de_jure_regions_above = yes
    use_de_jure_wargoal_only = yes
    check_all_defenders_for_ticking_war_score = yes # All defenders land in the Crusade Kingdom should count
    defender_ticking_warscore = 0.125
    attacker_ticking_warscore = 0.125
    max_defender_score_from_occupation = 50
    max_attacker_score_from_occupation = 150
    full_occupation_by_defender_gives_victory = no
    imprisonment_by_attacker_give_war_score = no
    imprisonment_by_defender_give_war_score = no
    attacker_capital_gives_war_score = no
    defender_capital_gives_war_score = no
    is_great_holy_war = yes
    landless_attacker_needs_armies = no
    
    defender_score_from_battles_scale = 125
    attacker_score_from_battles_scale = 125
    
    max_defender_score_from_battles = 150

    occupation_participation_mult = 0.5
    siege_participation_mult = 1
    battle_participation_mult = 7.5
    on_primary_attacker_death = inherit
    on_primary_defender_death = inherit
    transfer_behavior = transfer

    white_peace_possible = no

    allowed_for_character = {
        always = yes
    }

    valid_to_start = {
        scope:target = {
            tier = tier_kingdom
            any_in_de_jure_hierarchy = { #Any ruler in the dejure of the targeted Kingdom belongs to a Faith that the HoF's Faith is hostile enough to Holy War against.
                continue = { tier > tier_county }
                tier = tier_county
                scope:attacker.faith = {
                    is_hostile_enough_for_holy_war_trigger = { FAITH = prev.holder.top_liege.faith }
                }
            }
        }
    }

    on_declaration = {
        scope:attacker.faith.great_holy_war = {
            if = { #Clear forced participation flag.
                limit = {
                    any_pledged_attacker = {
                        has_character_flag = variable_ghw_papal_hooked_pledge
                    }
                }
                every_pledged_attacker = {
                    limit = {
                        has_character_flag = variable_ghw_papal_hooked_pledge
                    }
                    remove_character_flag = variable_ghw_papal_hooked_pledge
                }
            }
        }
        scope:attacker.faith.great_holy_war.ghw_target_title = {
            save_scope_as = target_kingdom
        }
        scope:attacker = { #Loc keys for localization fluff.
            save_scope_as = ghw_sponsor
        }
        scope:defender = {
            save_scope_as = ghw_defender
        }
        scope:attacker.faith = {
            save_scope_as = the_faith
        }
        scope:attacker.faith.great_holy_war = {
            save_scope_as = the_ghw
        }
        force_truce_GHW_defenders_effect = yes
        every_player = { #Fluff for attackers/defenders
            limit = {
                scope:attacker.faith.great_holy_war = {
                    OR = {
                        has_pledged_attacker = prev
                        has_pledged_defender = prev
                    }
                }
            }
            trigger_event = great_holy_war.0051
        }
        on_declared_war = yes
        scope:attacker.faith.great_holy_war = {
            divide_war_chest = {
                fraction = ghw_war_start_handout_percentage
            }
        }

        # First of the Crusader Kings achievement tracking.
        if = {
            limit = {
                scope:attacker.faith = faith:catholic
                NOT = { exists = global_var:had_first_catholic_crusade }
            }
            # Credit where chredit is due.
            scope:attacker.faith.great_holy_war = {
                every_pledged_attacker = {
                    limit = { fp1_achievement_culture_norse_trigger = yes }
                    add_achievement_flag_effect = { FLAG = first_of_the_crusader_kings_achievement_flag }
                }
            }
            # Mark the first crusade as having happened.
            set_global_variable = {
                name = had_first_catholic_crusade
                value = yes
            }
        }

        debug_log = undirected_ghw_debug_loc
    }

    on_invalidated_desc = msg_invalidate_war_title
    
    on_invalidated = {
        scope:attacker.faith.great_holy_war.ghw_target_title = {
            save_scope_as = target_kingdom
        }
        scope:attacker = { #Loc keys for localization fluff.
            save_scope_as = ghw_sponsor
        }
        scope:defender = {
            save_scope_as = ghw_defender
        }
        scope:attacker.faith = {
            save_scope_as = the_faith
        }
        scope:attacker.faith.great_holy_war = {
            save_scope_as = the_ghw
        }
        every_player = {
            limit = { is_within_diplo_range = { CHARACTER = scope:defender } }
            trigger_event = great_holy_war.0056
        }
        hidden_effect = {
            if = { #Clear pledged gold flag.
                limit = {
                    any_player = {
                        has_character_flag = ghw_pledged_gold
                    }
                }
                every_player = {
                    limit = {
                        has_character_flag = ghw_pledged_gold
                    }
                    remove_character_flag = ghw_pledged_gold
                }
            }
        }

        debug_log = "Undirected Great Holy War invalidated"
    }

    on_victory_desc = {
        desc = great_holy_war_victory_desc
    }

    on_victory = {
        scope:attacker = { show_pow_release_message_effect = yes }
        create_title_and_vassal_change = {
            type = conquest_holy_war
            save_scope_as = change
            add_claim_on_loss = yes
        }
        scope:attacker.faith.great_holy_war.ghw_target_title = { #Loc keys for localization fluff.
            save_scope_as = target_kingdom
        }
        scope:attacker = {
            save_scope_as = ghw_sponsor
        }
        scope:defender = {
            save_scope_as = ghw_defender
        }
        scope:attacker.faith = {
            save_scope_as = the_faith
        }
        scope:attacker.faith.great_holy_war = {
            save_scope_as = the_ghw
        }

        scope:attacker = {    #Achievement setup.
            every_character_war = {
                limit = {
                    is_attacker = scope:attacker
                    is_defender = scope:defender
                }
                every_war_attacker = {
                    add_achievement_flag_effect = { FLAG = achievement_for_the_faith_flag }
                }
            }
        }

        hidden_effect = {
            if = { #Recipient is going to be the Papal's chosen Recipient or, if the main contributor is overriding the Papal will, his Beneficiary.
                limit = {
                    exists = scope:attacker.faith.great_holy_war.ghw_title_recipient
                }
                scope:attacker.faith.great_holy_war.ghw_title_recipient = {
                    save_scope_as = title_recipient
                }
            }
            else = { #If no Recipient or Beneficiary, check for any random claimants that might have cropped in the meantime.
                undirected_ghw_recipient_selection_on_victory_effect = yes
            }
            if = {
                limit = {
                    exists = scope:the_ghw
                    NOT = { exists = scope:title_recipient }
                    scope:the_ghw = {
                        has_variable = var_fallback_recipient
                        var:var_fallback_recipient = {
                            is_alive = yes
                        }
                    }
                }
                scope:the_ghw = {
                    var:var_fallback_recipient = {
                        save_scope_as = title_recipient
                        set_designated_winner = scope:title_recipient
                    }
                }
            }
            if = { #If for some reason there is no title recipient selected yet, create character from scratch.
                limit = {
                    exists = scope:the_ghw
                    NOT = { exists = scope:title_recipient }
                    NOT = {
                        scope:the_ghw = {
                            has_variable = var_fallback_recipient
                        }
                    }
                }
                create_character = {
                    location = scope:ghw_sponsor.capital_province
                    template = new_commander_character
                    faith = scope:the_faith
                    culture = scope:ghw_sponsor
                    save_scope_as = title_recipient
                    gender_female_chance = {
                        if = {
                            limit = { scope:the_faith = { has_doctrine = doctrine_gender_male_dominated } }
                            add = 0
                        }
                        else_if = {
                            limit = { scope:the_faith = { has_doctrine = doctrine_gender_female_dominated } }
                            add = 100
                        }
                        else = {
                            add = 50
                        }
                    }
                }
                scope:the_faith.great_holy_war = {
                    set_designated_winner = scope:title_recipient
                }
            }
            if = { #Check if Recipient is landless to give him the Crusader King buff.
                limit = {
                    exists = scope:title_recipient
                    scope:title_recipient = { is_ruler = no }
                }
                scope:title_recipient = {
                    add_character_flag = {
                        flag = ghw_recipient_will_be_crusader_king
                    }
                }
            }
        }
        every_in_list = {
            list = target_titles
            save_scope_as = target
        }

        if = { #Tooltip explaining who gets the first title when a Recipient exists (otherwise avoid or it will show the fallback character).
            limit = {
                exists = scope:attacker.faith.great_holy_war.ghw_title_recipient
            }
            show_as_tooltip = {
                scope:target = {
                    change_title_holder = {
                        holder = scope:attacker.faith.great_holy_war.ghw_title_recipient
                        change = scope:change
                    }
                }
            }
        }
        else_if = {
            limit = {
                exists = scope:the_ghw
                scope:the_ghw = {
                    has_variable = var_fallback_recipient
                }
            }
            scope:the_ghw = {
                var:var_fallback_recipient = {
                    save_scope_as = ghw_fallback_recipient
                }
            }
            show_as_tooltip = {
                scope:target = {
                    change_title_holder = {
                        holder = scope:ghw_fallback_recipient
                        change = scope:change
                    }
                }
            }
        }

        # Create a dynamic title if the kingdom itself can't be created/taken
        if = {
            limit = { #In the event that, for ex. k_jerusalem exists and is held by a foreign ruler who is not involved in the war in any way.
                exists = scope:the_ghw
                exists = scope:target_kingdom
                exists = scope:target_kingdom.holder
                scope:the_ghw = {
                    NOR = {
                        #Do not create a titular title if the target is held by a defender.
                        has_pledged_defender = scope:target_kingdom.holder
                        has_forced_defender = scope:target_kingdom.holder
                        #Or, if the title_recipient is the current holder of the target_kingdom.
                        scope:title_recipient = scope:target_kingdom.holder
                    }
                }
            }
            hidden_effect = {
                random_list = {
                    50 = {
                        create_dynamic_title = {
                            tier = kingdom
                            name = CRUSADER_STATE_CRUSADER_TITLE_NAME
                        }
                    }
                    50 = {
                        create_dynamic_title = {
                            tier = kingdom
                            name = CRUSADER_STATE_FAITH_TITLE_NAME
                        }
                    }
                }
                scope:new_title = {
                    change_title_holder = {
                        holder = scope:title_recipient
                        change = scope:change
                    }
                }
            }
            scope:the_ghw = {
                do_ghw_title_handout = scope:change
                divide_war_chest = {}
            }
            scope:new_title = { generate_coa = yes }
        }
        else_if = { #Otherwise hand out titles normally.
            limit = {
                exists = scope:the_ghw
            }
            hidden_effect = {
                if = {
                    limit = {
                        NAND = {
                            exists = scope:target.holder
                            scope:target.holder = scope:title_recipient
                        }
                    }
                    scope:target = {
                        change_title_holder = {
                            holder = scope:title_recipient
                            change = scope:change
                        }
                    }
                }
            }
            scope:the_ghw = {
                do_ghw_title_handout = scope:change
                divide_war_chest = {}
            }
        }

        hidden_effect = {
            every_player = { #Fluff for players
                limit = {
                    OR = {
                        this = scope:attacker
                        this = scope:defender
                        any_war_enemy = { this = scope:attacker }
                        any_war_enemy = { this = scope:defender }
                        is_within_diplo_range = { CHARACTER = scope:defender }
                    }
                }
                trigger_event = great_holy_war.0052 #Differentiate depending on faith (compared to scope:attacker)
            }

            if = {
                limit = { exists = scope:title_recipient }
                scope:title_recipient = {
                    every_realm_county = { # Crusading troops seizing control
                        change_county_control = 50
                    }
                    every_realm_province = {
                        refill_levy = yes
                        refill_garrison = yes
                    }
                }
            }
            if = { #If Recipient was landless give him the Crusader King buff.
                limit = {
                    exists = scope:title_recipient
                    scope:title_recipient = { has_character_flag = ghw_recipient_will_be_crusader_king }
                }
                scope:title_recipient = {
                    add_trait = crusader_king
                    remove_character_flag = ghw_recipient_will_be_crusader_king
                    add_realm_law_skip_effects = crown_authority_1
                    
                    if = { # Set the appropriate Succession Law
                        limit = {
                            can_have_single_heir_succession_law_trigger = yes
                            NOT = {
                                has_realm_law = single_heir_succession_law
                            }
                        }
                        add_realm_law_skip_effects = single_heir_succession_law
                    }
                    else_if = {
                        limit = {
                            can_have_high_partition_succession_law_trigger = yes
                            NOT = {
                                has_realm_law = high_partition_succession_law
                            }
                        }
                        add_realm_law_skip_effects = high_partition_succession_law
                    }
                    else_if = {
                        limit = {
                            can_have_partition_succession_law_trigger = yes
                            NOT = {
                                has_realm_law = partition_succession_law
                            }
                        }
                        add_realm_law_skip_effects = partition_succession_law
                    }
                    
                    spawn_army = { # Spawn a temporary army so that the Crusader King isn't helpless, symbolizing Crusaders staying behind
                        levies = {
                            value = 100
                            scope:attacker.faith.great_holy_war = {
                                every_pledged_attacker = {
                                    add = 100
                                }
                            }
                        }
                        men_at_arms = {
                            type = teutonic_knights
                            stacks = {
                                value = 1
                                scope:attacker.faith.great_holy_war = {
                                    every_pledged_attacker = {
                                        add = 0.2
                                    }
                                }
                            }
                        }
                        inheritable = no
                        uses_supply = no
                        location = capital_province
                        name = house_beneficiary_won_ghw
                    }
                    every_vassal = { # Vassals should not want to revolt too soon after inaguration
                        add_opinion = {
                            modifier = respect_opinion
                            target = scope:title_recipient
                            opinion = 50
                        }
                    }
                    add_gold = 500 # Some extra plunder
                    add_prestige = 500
                    add_piety = 500
                }
            }
            scope:attacker.faith.great_holy_war = { #Give Prestige/Piety modifier to Dynasty/House of the winners' Beneficiaries (only if they gained any land in the GHW).
                every_pledged_attacker = {
                    limit = { exists = ghw_beneficiary }
                    ghw_beneficiary = { trigger_event = great_holy_war.0061 }
                }
                if = { #Chance to switch-play to Crusader King.
                    limit = {
                        exists = scope:title_recipient
                        exists = scope:title_recipient.dynasty
                        scope:title_recipient = {
                            is_ai = yes
                            has_trait = crusader_king
                        }
                        any_pledged_attacker = {
                            is_ai = no
                            dynasty = scope:title_recipient.dynasty
                        }
                    }
                    random_pledged_attacker = {
                        limit = {
                            is_ai = no
                            dynasty = scope:title_recipient.dynasty
                            scope:title_recipient = {
                                is_ai = yes
                                has_trait = crusader_king
                            }
                        }
                        trigger_event = { id = great_holy_war.0070 days = 5 }
                    }
                }
            }
        }
        
        #Set 30 years cooldown.
        hidden_effect = {
            scope:attacker.faith = {
                set_variable = {
                    name = variable_ghw_cooldown
                    value = yes
                    years = 30
                }
            }
            if = { #Clear pledged gold flag.
                limit = {
                    any_player = {
                        has_character_flag = ghw_pledged_gold
                    }
                }
                every_player = {
                    limit = {
                        has_character_flag = ghw_pledged_gold
                    }
                    remove_character_flag = ghw_pledged_gold
                }
            }
        }

        scope:attacker.faith = {
            change_fervor = -25
        }
        scope:defender.faith = {
            change_fervor = 30
        }

        #Truce between the chief beneficiary & all defenders
        add_truce_GHW_attacker_victory_effect = yes
        debug_log = undirected_ghw_victory_debug_message

        # FP1: note the victory for future memorialisation via stele (if applicable).
        scope:attacker = { fp1_remember_recent_conquest_victory_effect = yes }
    }

    on_white_peace_desc = {
        desc = WHITE_PEACE_DISABLED
    }

    on_defeat_desc = {
        desc = great_holy_war_defeat_desc
    }

    on_defeat = {
        scope:attacker = { show_pow_release_message_effect = yes }
        scope:attacker.faith.great_holy_war = {
            divide_war_chest = {
                defenders = yes
                gold = no
            }
        }

        scope:attacker = {
            faith = {
                change_fervor = -15
            }
        }
        scope:attacker.faith.great_holy_war.ghw_target_title = { #Loc keys for localization fluff.
            save_scope_as = target_kingdom
        }
        scope:attacker = {
            save_scope_as = ghw_sponsor
        }
        scope:defender = {
            save_scope_as = ghw_defender
        }
        scope:attacker.faith = {
            save_scope_as = the_faith
        }
        scope:attacker.faith.great_holy_war = {
            save_scope_as = the_ghw
        }

        scope:defender = {    #Achievement setup.
            every_character_war = {
                limit = {
                    is_attacker = scope:attacker
                    is_defender = scope:defender
                }
                every_war_defender = {
                    add_achievement_flag_effect = { FLAG = achievement_for_the_faith_flag }
                }
            }
        }

        every_player = { #Fluff for players
            limit = {
                OR = {
                    this = scope:attacker
                    this = scope:defender
                    any_war_enemy = { this = scope:attacker }
                    any_war_enemy = { this = scope:defender }
                    is_within_diplo_range = { CHARACTER = scope:defender }
                }
            }
            trigger_event = great_holy_war.0053 #Differentiate depending on faith (compared to scope:attacker)
        }

        # Truce
        add_truce_attacker_defeat_effect = yes

        #Set 30 years cooldown.
        hidden_effect = {
            scope:attacker.faith = {
                set_variable = {
                    name = variable_ghw_cooldown
                    value = yes
                    years = 30
                }
            }
            if = { #Clear pledged gold flag.
                limit = {
                    any_player = {
                        has_character_flag = ghw_pledged_gold
                    }
                }
                every_player = {
                    limit = {
                        has_character_flag = ghw_pledged_gold
                    }
                    remove_character_flag = ghw_pledged_gold
                }
            }
        }
        debug_log = undirected_ghw_defeat_debug_message
    }
}

directed_great_holy_war = {
    group = religious

    war_name = "GREAT_HOLY_WAR_WAR_NAME"
    cb_name = "GREAT_HOLY_WAR_WAR_CB_NAME"

    combine_into_one = yes
    should_show_war_goal_subview = yes
    mutually_exclusive_titles = { always = yes }

    target_titles = all
    target_title_tier = all
    target_de_jure_regions_above = yes
    use_de_jure_wargoal_only = yes
    check_all_defenders_for_ticking_war_score = yes # All defenders land in the Crusade Kingdom should count
    defender_ticking_warscore = 0.05
    attacker_ticking_warscore = 0.05
    max_defender_score_from_occupation = 50
    max_attacker_score_from_occupation = 150
    imprisonment_by_attacker_give_war_score = no
    defender_capital_gives_war_score = no
    is_great_holy_war = yes
    ai_only_against_neighbors = yes

    occupation_participation_mult = 0.5
    siege_participation_mult = 1
    battle_participation_mult = 7.5

    white_peace_possible = no
    gui_attacker_faith_might_join = yes
    gui_defender_faith_might_join = yes
    on_primary_attacker_death = inherit
    on_primary_defender_death = inherit
    transfer_behavior = transfer

    allowed_for_character = {
        faith = {
            exists = religious_head
            suitable_faith_for_directed_ghw_trigger = yes #Right Doctrines
            scope:attacker = this.religious_head
            religion = { exists = var:variable_ghw_unlocked } #Activated by event for every religion.
        }
    }

    allowed_for_character_display_regardless = {
        custom_description = {
            text = great_holy_war_cooldown
            NOT = {    scope:attacker.faith = { exists = var:variable_ghw_cooldown }}
        }
    }

    allowed_against_character = {
        scope:attacker.faith = {
            is_hostile_enough_for_holy_war_trigger = { FAITH = scope:defender.faith }
        }
    }

    valid_to_start = {
        scope:attacker.faith = {
            NOR = {
                # No active GHW already.
                exists = great_holy_war

                # If GHWs have just been unlocked, AI rulers will wait a little bit before declaring them.
                trigger_if = {
                    limit = { scope:attacker = { is_ai = yes } }
                    religion = { exists = var:variable_first_ghw_cooldown }
                }
            }
        }

        scope:target = {
            tier = tier_kingdom
            any_in_de_jure_hierarchy = { #Any ruler in the dejure of the targeted Kingdom belongs to a Faith that the Caliph's Faith is hostile enough to Holy War against.
                continue = { tier > tier_county }
                tier = tier_county
                scope:attacker.faith = {
                    is_hostile_enough_for_holy_war_trigger = { FAITH = prev.holder.top_liege.faith }
                }
            }
        }
    }

    on_declaration = {
        every_in_list = {
            list = target_titles
            save_scope_as = target
        }
        hidden_effect = {
            scope:attacker.faith = {
                start_great_holy_war = {
                    target_character = scope:defender
                    target_title = scope:target
                    war = root.war
                }
                great_holy_war = {
                    pledge_attacker = scope:attacker
                }
            }
        }
        scope:attacker.faith.great_holy_war = {
            every_pledged_attacker = { #Add Beneficiary automatically on victory of direct GHW for any attacker that doesn't have one already.
                limit = {
                    NOT = {
                        exists = ghw_beneficiary
                    }
                }
                trigger_event = great_holy_war.0026
            }
        }
        scope:attacker.faith.great_holy_war.ghw_target_title = {
            save_scope_as = target_kingdom
        }
        scope:attacker = { #Loc keys for localization fluff.
            save_scope_as = ghw_sponsor
        }
        scope:defender = {
            save_scope_as = ghw_defender
        }
        scope:defender.faith = {
            save_scope_as = target_faith
        }
        scope:attacker.faith = {
            save_scope_as = the_faith
        }
        scope:attacker.faith.great_holy_war = {
            save_scope_as = the_ghw
        }
        force_truce_GHW_defenders_effect = yes
        hidden_effect = {
            every_ruler = {
                limit = {
                    faith = scope:attacker.faith
                    is_ai = yes
                    is_landed = yes
                    highest_held_title_tier >= tier_county
                    NOT = { this = scope:ghw_sponsor }
                    exists = scope:attacker.faith.great_holy_war
                    NOT = { scope:attacker.faith.great_holy_war = { has_pledged_attacker = prev } }
                }
                trigger_event = great_holy_war.0092 #AI pledging.
            }
            every_ruler = {
                limit = {
                    faith = scope:defender.faith
                    is_ai = yes
                    is_landed = yes
                    highest_held_title_tier >= tier_county
                    exists = scope:attacker.faith.great_holy_war
                    NOT = { scope:attacker.faith.great_holy_war = { has_pledged_defender = prev } }
                    NOT = { scope:defender = top_liege }
                }
                trigger_event = great_holy_war.0093 #AI counterpledging.
            }
            scope:attacker.faith = {
                every_faith_holy_order = {
                    trigger_event = great_holy_war.0090 # Holy orders always join
                }
            }
            scope:defender.faith = {
                every_faith_holy_order = {
                    trigger_event = great_holy_war.0091 # Holy orders always join
                }
            }
        }

        every_player = { #Fluff for attackers/defenders
            limit = {
                OR = {
                    faith = scope:the_faith
                    faith = scope:ghw_defender.faith
                    is_vassal_of = scope:attacker
                    is_vassal_of = scope:defender
                }
            }
            trigger_event = great_holy_war.0071
        }
        on_declared_war = yes

        debug_log = directed_ghw_debug_loc
    }

    on_victory_desc = {
        desc = great_holy_war_directed_victory_desc
    }

    on_victory = {
        scope:attacker = { show_pow_release_message_effect = yes }
        scope:attacker.faith.great_holy_war.ghw_target_title = { #Loc keys for localization fluff.
            save_scope_as = target_kingdom
        }
        scope:attacker = {
            save_scope_as = ghw_sponsor
        }
        scope:defender = {
            save_scope_as = ghw_defender
        }
        scope:attacker.faith = {
            save_scope_as = the_faith
        }
        scope:attacker.faith.great_holy_war = {
            save_scope_as = the_ghw
        }

        scope:attacker = {    #Achievement setup.
            every_character_war = {
                limit = {
                    is_attacker = scope:attacker
                    is_defender = scope:defender
                }
                every_war_attacker = {
                    add_achievement_flag_effect = { FLAG = achievement_for_the_faith_flag }
                }
            }
        }

        if = {
            limit = { exists = scope:attacker.faith.great_holy_war.ghw_title_recipient }
            scope:attacker.faith.great_holy_war.ghw_title_recipient = {
                save_scope_as = title_recipient
            }
        }
        else = {
            scope:attacker = {
                save_scope_as = title_recipient
            }
        }

        create_title_and_vassal_change = {
            type = conquest_holy_war
            save_scope_as = change
            add_claim_on_loss = yes
        }
        every_in_list = {
            list = target_titles
            save_scope_as = target
        }
        scope:attacker.faith.great_holy_war = {
            show_as_tooltip = { #Otherwise hand out titles normally.
                scope:target = {
                    change_title_holder = {
                        holder = scope:title_recipient
                        change = scope:change
                    }
                }
                do_ghw_title_handout = scope:change
            }
        }
        # Create a dynamic title if the kingdom itself can't be created/taken
        hidden_effect = {
            if = {
                limit = { #In the event that, for ex. k_jerusalem exists and is held by a foreign ruler who is not involved in the war in any way.
                    exists = scope:target
                    exists = scope:target.holder
                    scope:target.holder = {
                        is_alive = yes
                        faith = scope:attacker.faith
                    }
                }
                random_list = {
                    50 = {
                        create_dynamic_title = {
                            tier = kingdom
                            name = CRUSADER_STATE_CRUSADER_TITLE_NAME
                        }
                    }
                    50 = {
                        create_dynamic_title = {
                            tier = kingdom
                            name = CRUSADER_STATE_FAITH_TITLE_NAME
                        }
                    }
                }
                scope:attacker.faith.great_holy_war = {
                    scope:new_title = {
                        change_title_holder = {
                            holder = scope:title_recipient
                            change = scope:change
                        }
                    }
                    do_ghw_title_handout = scope:change
                }
                scope:new_title = { generate_coa = yes }
            }
            else = { #Otherwise hand out titles normally.
                scope:attacker.faith.great_holy_war = {
                    scope:target = {
                        change_title_holder = {
                            holder = scope:title_recipient
                            change = scope:change
                        }
                    }
                    do_ghw_title_handout = scope:change
                }
            }
            scope:title_recipient = {
                every_realm_province = {
                    refill_levy = yes
                    refill_garrison = yes
                }
            }
        }
        #Set 30 years cooldown.
        hidden_effect = {
            scope:attacker = {
                faith = {
                    set_variable = {
                        name = variable_ghw_cooldown
                        value = yes
                        years = 30
                    }
                }
            }
            scope:attacker.faith.great_holy_war = { #Give Prestige/Piety modifier to Dynasty/House of the winners' Beneficiaries (only if they gained any land in the GHW).
                every_pledged_attacker = {
                    limit = { exists = ghw_beneficiary }
                    ghw_beneficiary = { trigger_event = great_holy_war.0061 }
                }
            }
        }

        scope:attacker.faith = {
            change_fervor = -25
        }
        scope:defender.faith = {
            change_fervor = 30
        }

        #Truce between the chief beneficiary & all defenders
        add_truce_GHW_attacker_victory_effect = yes

        every_player = { #Fluff for players
            limit = {
                OR = {
                    this = scope:attacker
                    this = scope:defender
                    any_war_enemy = { this = scope:attacker }
                    any_war_enemy = { this = scope:defender }
                    is_within_diplo_range = { CHARACTER = scope:defender }
                }
            }
            trigger_event = great_holy_war.0052 #Differentiate depending on faith (compared to scope:attacker)
        }

        # FP1: note the victory for future memorialisation via stele (if applicable).
        scope:attacker = { fp1_remember_recent_conquest_victory_effect = yes }
    }

    on_white_peace_desc = {
        desc = WHITE_PEACE_DISABLED
    }

    on_defeat_desc = {
        desc = great_holy_war_defeat_desc
    }

    on_defeat = {
        scope:attacker = { show_pow_release_message_effect = yes }
        scope:attacker.faith.great_holy_war.ghw_target_title = { #Loc keys for localization fluff.
            save_scope_as = target_kingdom
        }
        scope:attacker = {
            save_scope_as = ghw_sponsor
        }
        scope:defender = {
            save_scope_as = ghw_defender
        }
        scope:attacker.faith = {
            save_scope_as = the_faith
        }
        scope:attacker.faith.great_holy_war = {
            save_scope_as = the_ghw
        }

        scope:defender = {    #Achievement setup.
            every_character_war = {
                limit = {
                    is_attacker = scope:attacker
                    is_defender = scope:defender
                }
                every_war_defender = {
                    add_achievement_flag_effect = { FLAG = achievement_for_the_faith_flag }
                }
            }
        }

        every_player = { #Fluff for players
            limit = {
                OR = {
                    this = scope:attacker
                    this = scope:defender
                    any_war_enemy = { this = scope:attacker }
                    any_war_enemy = { this = scope:defender }
                    is_within_diplo_range = { CHARACTER = scope:defender }
                }
            }
            trigger_event = great_holy_war.0053 #Differentiate depending on faith (compared to scope:attacker)
        }

        # Truce
        add_truce_attacker_defeat_effect = yes

        scope:attacker = {
            faith = {
                change_fervor = -15
            }
        }
        #Set 30 years cooldown.
        hidden_effect = {
            scope:attacker = {
                faith = {
                    set_variable = {
                        name = variable_ghw_cooldown
                        value = yes
                        years = 30
                    }
                }
            }
        }
    }

    on_invalidated_desc = msg_invalidate_war_title

    max_ai_diplo_distance_to_title = 750
}
 
declare war ui
Code:
######################################################
#################### DECLARE WAR "####################
######################################################

# These ~50 first lines are a placeholder way to show who will defend
window = {
    name = "declare_war_window"
    datacontext = "[DeclareWarInteractionWindow.GetCharacterInteractionConfirmationWindow]"
    parentanchor = top|right
    position = { -15 90 }
    size = { 640 1060 } #1020
    allow_outside = yes
    movable = yes
    layer = middle

    state = {
        name = _show
        using = Animation_FadeIn_Quick
        using = Sound_WindowShow_Standard
    }

    state = {
        name = _hide
        using = Animation_FadeOut_Quick
        using = Sound_WindowHide_Standard
    }


# Removing this unil we got a proper UX design for jihad and kingdom conquering participants
#    scrollarea = {
#        size = { 90 100% }
#
#        scrollbar_vertical = {
#            using = Scrollbar_Vertical
#        }
#
#        scrollbarpolicy_horizontal = always_off
#
#        scrollwidget = {
#
#            fixedgridbox = {
#                name = "forced_defenders"
#                datamodel = "[DeclareWarInteractionWindow.GetDefenders]"
#                position = { 0 0 }
#                addrow = 90
#                addcolumn = 90
#
#                item = {
#                    portrait_head_small = {
#                        datacontext = "[WarAllyItem.GetCharacter]"
#
#                        tooltip = "[WarAllyItem.GetAllianceReason]"
#
#                        blockoverride "opinion_box" {}
#
#                        blockoverride "portrait_button_template_tooltip"
#                        {
#                            tooltip = "WAR_DEFENDER_ALLY_TOOLTIP"
#                        }
#                    }
#                }
#            }
#        }
#    }

    widget = {
        name = "declare_war_window"
        size = { 640 100% }

        using = Window_Background
        using = Window_Decoration_Warfare

        vbox = {
            using = Window_Margins

            header_pattern_interaction = {
                layoutpolicy_horizontal = expanding

                blockoverride "header_text"
                {
                    text = "[DeclareWarInteractionWindow.GetHeader]"
                }

                blockoverride "button_close"
                {
                    onclick = "[DeclareWarInteractionWindow.Close]"
                }
            }

            widget = {
                layoutpolicy_horizontal = expanding
                size = { 0 240 }

                background = {                   
                    using = Background_Area_Dark
                    alpha = 0.7
                }

                widget = {
                    name = "layer_one_war"
                    size = { 100% 100% }

                    vbox = {
                        datacontext = "[DeclareWarInteractionWindow.GetMilitaryStrengthInfo]"

                        layoutpolicy_vertical = expanding
                        layoutpolicy_horizontal = expanding
                        margin_top = 24

                        declare_war_progressbar = {}

                        hbox = {
                            margin_top = 6
                            margin_bottom = -4
                            
                            hbox = {
                                name = "your_army"
                                margin_top = 6
                                margin_bottom = 6
                                margin_right = 4
                                margin_left = 60

                                background = {
                                    using = Background_Area_Dark
                                }
                                
                                soldiers_and_quality_small = {
                                    datacontext = "[DeclareWarInteractionWindow.GetAttackerCharacter]"
                                    datacontext = "[CharacterItem.GetComposition]"
                                    layoutpolicy_vertical = expanding

                                    blockoverride "spacing"
                                    {
                                        size = { 44 8 }
                                    }
                                }
                            }

                            icon = {
                                name = "icon_strength_balance"
                                size = { 60 60 }
                                texture = "gfx/interface/icons/icon_strength_balance.dds"
                                framesize = { 60 60 }
                                frame = "[GuiMilitaryStrength.GetFrame]"
                            }

                            hbox = {
                                name = "enemy_army"
                                margin_top = 6
                                margin_bottom = 6
                                margin_left = 4
                                margin_right = 60

                                background = {
                                    using = Background_Area_Dark
                                }
                                
                                soldiers_and_quality_small = {
                                    datacontext = "[DeclareWarInteractionWindow.GetDefenderCharacter]"
                                    datacontext = "[CharacterItem.GetComposition]"
                                    layoutpolicy_vertical = expanding
                                    
                                    blockoverride "spacing"
                                    {
                                        size = { 44 8 }
                                    }
                                }
                            }
                        }
                    
                        hbox = {
                            name = "gold"
                            spacing = 80

                            character_gold = {
                                name = "your_gold"
                                datacontext = "[DeclareWarInteractionWindow.GetAttackerCharacter]"
                                margin_top = 6
                                margin_bottom = 6
                                margin_right = 10
                                margin_left = 60

                                background = {
                                    using = Background_Area_Dark
                                }
                            }
                            
                            character_gold = {
                                name = "enemy_gold"
                                datacontext = "[DeclareWarInteractionWindow.GetDefenderCharacter]"
                                margin_top = 6
                                margin_bottom = 6
                                margin_left = 10
                                margin_right = 60

                                background = {
                                    using = Background_Area_Dark
                                }
                            }
                        }

                        text_multi = {
                            name = "comparison_text"
                            margin_top = 16
                            text = "[DeclareWarInteractionWindow.GetMilitaryStrength]"
                            autoresize = yes
                            max_width = 210
                            align = center                   
                        }
                        expand = {}
                    }
                }

                widget = {
                    name = "layer_two_characters"
                    size = { 100% 100% }

                    hbox = {
                        alwaystransparent = yes
                        margin = { 10 6 }

                        declare_war_character_portrait = {
                            name = "player_character"
                            datacontext = "[DeclareWarInteractionWindow.GetAttackerCharacter]"
                        }

                        expand = {}

                        declare_war_character_portrait = {
                            name = "enemy_character"               
                            datacontext = "[DeclareWarInteractionWindow.GetDefenderCharacter]"

                            blockoverride "portrait_transformation"
                            {
                                portrait_scale = { -1 1 }
                                portrait_offset = { 1 0 }
                            }
                        }
                    }
                }
            }

            text_single = {
                text = "DECLARE_WAR_CHOOSE_CASUS_BELLI_INSTRUCTION"
                visible = "[Not(DeclareWarInteractionWindow.HasSelectedCasusBelli)]"
                margin_bottom = 8
                default_format = "#I"
            }

            vbox = {
                name = "casus_belli_scroll_box"
                layoutpolicy_horizontal = expanding
                layoutpolicy_vertical = expanding
                visible = "[Not(DeclareWarInteractionWindow.HasSelectedCasusBelli)]"

                ### Casus Belli Scrollarea
                scrollbox = {
                    visible = "[Not(DeclareWarInteractionWindow.HasSelectedCasusBelli)]"
                    layoutpolicy_horizontal = expanding
                    layoutpolicy_vertical = expanding

                    blockoverride "scrollbox_margins"
                    {
                        margin = { 10 15 }
                    }
                    

                    blockoverride "scrollbox_empty"
                    {
                        text = NO_VALID_CASUS_BELLIS
                        visible = "[DeclareWarInteractionWindow.HasNoValidCasusBellis]"
                    }

                    blockoverride "scrollbox_content"
                    {
                        vbox = {
                            name = "casus_belli_items"
                            datamodel = "[DeclareWarInteractionWindow.GetCasusBelliItems]"
                            spacing = 5
                            layoutpolicy_horizontal = expanding

                            item = {
                                button_standard = {
                                    layoutpolicy_horizontal = expanding
                                    size = { 0 40 }
                                    down = "[CasusBelliItem.IsSelected]"
                                    onclick = "[CasusBelliItem.OnClick]"
                                    onclick = "[PdxGuiTriggerAllAnimations('declare_war_goal_refresh')]"

                                    declare_war_casus_belli_item = {}
                                }
                            }
                        }
                    }
                }

            }

            ### Selected casus belli
            vbox = {
                visible = "[DeclareWarInteractionWindow.HasSelectedCasusBelli]"
                layoutpolicy_horizontal = expanding
                margin_top = 8
                margin_left = 10
                margin_right = 10
                margin_bottom = 8

                background = {
                    using = Background_Area
                }

                button_standard = {
                    datacontext = "[DeclareWarInteractionWindow.GetSelectedCasusBelliItem]"
                    layoutpolicy_horizontal = expanding
                    minimumsize = { -1 40 }
                    onclick = "[CasusBelliItem.OnClick]"

                    declare_war_casus_belli_item = {
                        layoutpolicy_horizontal = expanding

                        button_change = {
                            name = "reset_casus_belli_item"
                            visible = "[CasusBelliItem.IsSelected]"
                            onclick = "[CasusBelliItem.OnClick]"
                        }
                    }
                }
            }

            text_single = {
                visible = "[And(DeclareWarInteractionWindow.HasSelectedCasusBelli, DeclareWarInteractionWindow.CanShowWarGoalSubview)]"
                margin_bottom = 6
                text = "DECLARE_WAR_CHOOSE_WARGOAL_INSTRUCTION"
                default_format = "#I"
            }

            ### War preview after selecting a Casus Belli
            vbox = {
                name = "war_preview"
                visible = "[DeclareWarInteractionWindow.HasSelectedCasusBelli]"
                layoutpolicy_horizontal = expanding
                layoutpolicy_vertical = expanding
                margin_bottom = 6
                using = Animation_Tab_Switch


                vbox = {
                    layoutpolicy_horizontal = expanding
                    layoutpolicy_vertical = expanding
                    spacing = 8

                    scrollbox = {
                        visible = "[DeclareWarInteractionWindow.CanShowWarGoalSubview]"
                        layoutpolicy_horizontal = expanding
                        layoutpolicy_vertical = expanding

                        blockoverride "scrollbox_margins"
                        {
                            margin = { 10 10 }
                        }

                        blockoverride "scrollbox_content"
                        {
                            vbox = {
                                datamodel = "[DeclareWarInteractionWindow.GetTitleItems]"
                                layoutpolicy_horizontal = expanding
                                spacing = 6

                                state = {
                                    name = "declare_war_goal_refresh"
                                    using = Animation_Refresh_FadeOut
                                }

                                state = {
                                    using = Animation_Refresh_FadeIn
                                }

                                item = {
                                    button_standard = {
                                        layoutpolicy_horizontal = expanding
                                        size = { 0 45 }
                                        down = "[CasusBelliTitleItem.IsSelected]"
                                        onclick = "[CasusBelliTitleItem.OnClick]"

                                        hbox = {

                                            widget = {
                                                layoutpolicy_vertical = expanding
                                                size = { 45 0 }

                                                coa_title_tiny_crown = {
                                                    datacontext = "[CasusBelliTitleItem.GetTitle]"
                                                    parentanchor = center
                                                    using = tooltip_ne
                                                }
                                            }

                                            text_single = {
                                                name = "text"
                                                layoutpolicy_horizontal = expanding
                                                text = "[CasusBelliTitleItem.GetTitle.GetNameNoTooltip]"
                                                autoresize = no
                                                default_format = "#high"
                                                align = nobaseline
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    expand = {}
                    
                    hbox = {
                        name = "war_outcomes_tabs"
                        layoutpolicy_horizontal = expanding

                        text_single = {
                            layoutpolicy_horizontal = expanding
                            margin_left = 15
                            text = "[DeclareWarInteractionWindow.GetCurrentTabEffectsLabel]"
                            align = nobaseline
                        }

                        background = {
                            using = Background_Area
                        }

                        ### Tabs
                        hbox = {
                            name = "outcome_effect_tabs"
                            spacing = 5
                            margin_right = 10

                            button_standard = {
                                name = "victory_button"
                                size = { 45 40 }
                                down = "[DeclareWarInteractionWindow.IsEffectsTabVictory]"
                                onclick = "[DeclareWarInteractionWindow.SetEffectsTabVictory]"

                                tooltip = "TAB_VICTORY"
                                using = tooltip_se

                                button_icon_war_victory = {
                                    parentanchor = center
                                    alwaystransparent = yes
                                }
                            }

                            button_standard = {
                                name = "white_peace_button"
                                size = { 45 40 }

                                down = "[DeclareWarInteractionWindow.IsEffectsTabWhitePeace]"
                                onclick = "[DeclareWarInteractionWindow.SetEffectsTabWhitePeace]"
                                visible = "[DeclareWarInteractionWindow.GetCbType.IsWhitePeacePossible]"
                                tooltip = "TAB_WHITE_PEACE"
                                using = tooltip_se

                                button_icon_war_peace = {
                                    parentanchor = center
                                    alwaystransparent = yes
                                }
                            }

                            button_standard = {
                                name = "defeat_button"
                                size = { 45 40 }

                                down = "[DeclareWarInteractionWindow.IsEffectsTabDefeat]"
                                onclick = "[DeclareWarInteractionWindow.SetEffectsTabDefeat]"
                                tooltip = "TAB_DEFEAT"
                                using = tooltip_se

                                button_icon_war_defeat = {
                                    parentanchor = center
                                    alwaystransparent = yes
                                }

                            }
                        }
                    }

                    ### Info
                    scrollbox = {
                        name = "war_outcome_info"
                        layoutpolicy_horizontal = expanding
                        layoutpolicy_vertical = fixed
                        size = {-1 160}

                        blockoverride "scrollbox_content"
                        {
                            hbox = {
                                layoutpolicy_horizontal = expanding
                                layoutpolicy_vertical = expanding

                                vbox = {
                                    layoutpolicy_horizontal = expanding
                                    layoutpolicy_vertical = expanding

                                    hbox = {
                                        layoutpolicy_horizontal = expanding
                                        spacing = 5

                                        vbox = {
                                            layoutpolicy_vertical = expanding

                                            button_expand = {
                                                name = "button_expand_other_war_effects"
                                                frame = "[BoolTo1And2(DeclareWarInteractionWindow.IsWarEffectsExpanded)]"

                                                onclick = "[DeclareWarInteractionWindow.ToggleWarEffectsExpanded]"
                                            }
                                            expand = {}
                                        }

                                        text_multi = {
                                            name = "main_end_war_effect"
                                            layoutpolicy_horizontal = expanding
                                            autoresize = yes
                                            max_width = 320
                                            default_format = "#high"
                                            text = "[DeclareWarInteractionWindow.GetCurrentTabMainOutputDescription]"
                                        }

                                        expand = {}
                                    }

                                    text_multi = {
                                        name = "other_end_war_effects"
                                        visible = "[DeclareWarInteractionWindow.IsWarEffectsExpanded]"
                                        layoutpolicy_horizontal = expanding
                                        text = "[DeclareWarInteractionWindow.GetCurrentTabEffectsDescription]"
                                        autoresize = yes
                                        max_width = 360
                                    }

                                    expand = {}
                                }

                                vbox = {
                                    layoutpolicy_vertical = expanding
                                    datacontext = "[DeclareWarInteractionWindow.GetClaimant]"

                                    portrait_head = {
                                        visible = "[Character.IsValid]"
                                    }

                                    expand = {}
                                }
                            }
                        }
                    }
                }

                vbox = {
                    name = "additional_warning_box"
                    layoutpolicy_horizontal = expanding

                    hbox = {
                        spacing = 10
                        margin_top = 4

                        icon = {
                            name = "attacker_faith_might_join"
                            datacontext = "[GetPlayer]"
                            visible = "[DeclareWarInteractionWindow.GetCbType.GuiAttackerFaithMightJoin]"
                            size = { 40 40 }

                            texture = "[Character.GetFaith.GetIcon]"
                            tooltip = "WAR_ATTACKER_FAITH_MIGHT_JOIN"

                            icon = {
                                position = { 5 0 }
                                parentanchor = bottom|right
                                size = { 25 25 }
                                texture = "gfx/interface/icons/casus_bellis/_default.dds"
                            }
                        }

                        icon = {
                            name = "defender_faith_might_join"
                            datacontext = "[CharacterInteractionConfirmationWindow.GetRecipient]"
                            visible = "[DeclareWarInteractionWindow.GetCbType.GuiDefenderFaithMightJoin]"
                            size = { 40 40 }

                            texture = "[Character.GetFaith.GetIcon]"
                            tooltip = "WAR_DEFENDER_FAITH_MIGHT_JOIN"

                            icon = {
                                size = { 25 25 }
                                position = { 5 0 }
                                parentanchor = bottom|right
                                texture = "gfx/interface/icons/symbols/icon_warning.dds"
                            }
                        }

                        hbox = {
                            visible = "[DeclareWarInteractionWindow.ShouldShowAdditionalWarning]"
                            spacing = 8
                            margin_top = 2

                            icon = {
                                size = { 25 25 }
                                texture = "gfx/interface/icons/symbols/icon_warning.dds"
                            }

                            text_multi = {
                                text = "[DeclareWarInteractionWindow.WriteAdditionalWarningMessage]"
                                max_width = 350
                                autoresize = yes
                            }
                        }
                    }
                    scrollarea = {
                        name = "defenders_scrollarea"
                        visible = "[Not(IsDataModelEmpty(DeclareWarInteractionWindow.GetDefenders))]"
                        size = { 500 120 }
                        scrollbarpolicy_vertical = always_off
                        scrollbarpolicy_horizontal = as_needed
                        scrollbar_horizontal = {
                            using = Scrollbar_Horizontal
                        }

                        scrollwidget = {
                            hbox = {
                                using = Scrollbox_Margins

                                fixedgridbox = {
                                    datamodel_reuse_widgets = yes
                                    maxverticalslots = 1
                                    flipdirection = yes

                                    name = "defenders"
                                    datamodel = "[DeclareWarInteractionWindow.GetDefenders]"
                                    addcolumn = 80
                                    addrow = 90

                                    item = {
                                        portrait_head_small = {
                                            datacontext = "[WarAllyItem.GetCharacter]"

                                            tooltip = "[WarAllyItem.GetAllianceReason]"

                                            blockoverride "opinion_box" {}

                                            blockoverride "portrait_button_template_tooltip"
                                            {
                                                tooltip = "WAR_DEFENDER_ALLY_TOOLTIP"
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                vbox_interaction_options = {
                    visible = "[DeclareWarInteractionWindow.HasSelectedCasusBelli]"
                    layoutpolicy_horizontal = expanding
                }
                
                vbox = {
                    layoutpolicy_horizontal = expanding
                    margin_top = 10

                    ### COST
                    declare_war_cost = {}
                }


            }

            hbox = {
                margin_top = 4
                margin_bottom = 5

                hbox = {
                    name = "declare_war_send_button"

                    button_standard_big = {
                        name = "send_button"
                        enabled = "[DeclareWarInteractionWindow.CanSend]"
                        onclick = "[DeclareWarInteractionWindow.Send]"

                        text = "[CharacterInteractionConfirmationWindow.GetSendName]"
                        default_format = "#high"

                        tooltip = "[DeclareWarInteractionWindow.GetDeclareWarButtonTooltip]"

                        clicksound = "event:/SFX/UI/War/sfx_ui_war_declare_war"

                        # animation_aggressive = {
                        #     visible = "[DeclareWarInteractionWindow.CanSend]"
                        # }

                        hbox = {
                            layoutpolicy_horizontal = expanding
                            margin_right = 10

                            expand = {}

                            icon = {
                                name = "player_cost_ignore"
                                visible = "[And(DeclareWarInteractionWindow.HasSelectedCasusBelli, Or( Or( Not( DeclareWarInteractionWindow.CanAffordCosts ), DeclareWarInteractionWindow.IsBreakingTruce), DeclareWarInteractionWindow.IsBreakingAlliance))]"
                                texture = "gfx/interface/icons/symbols/icon_warning.dds"
                                size = { 30 30 }
                            }
                        }
                    }
                }
            }
        }
    }

    window = {
        name = "character_ally_list_subview"
        datacontext = "[DeclareWarInteractionWindow.GetAllyListContext]"
        visible = "[AllyListSubview.IsShown]"
        parentanchor = top|right
        position = { -615 120 }
        size = { 480 750 }
        movable = no

        using = Window_Background_Subwindow
        using = Animation_ShowHide_Standard

        vbox = {
            margin = { 3 3 }

            header_pattern = {
                layoutpolicy_horizontal = expanding

                blockoverride "header_text"
                {
                    text = "[AllyListSubview.GetHeaderTitle]"
                }
                blockoverride "button_close"
                {
                    onclick = "[AllyListSubview.Close]"
                }
            }

            hbox = {
                layoutpolicy_horizontal = expanding
                margin_left = 20
                spacing = 5

                text_single = {
                    text = "SORT_BY"
                    align = nobaseline
                }

                dropdown_sort_characterlist = {
                    datamodel = "[AllyListSubview.GetSortItems]"
                    onselectionchanged = "[AllyListSubview.SetCurrentFilterFromIndex]"
                    selectedindex = "[AllyListSubview.GetCurrentFilterIndex]"
                }

                expand = {}
            }

            expand = {}

            scrollbox = {
                layoutpolicy_horizontal = expanding
                layoutpolicy_vertical = expanding

                blockoverride "scrollbox_margins"
                {
                    margin = { 10 15 }
                }

                blockoverride "scrollbox_content"
                {
                    vbox = {
                        datamodel = "[AllyListSubview.GetAllyList]"
                        layoutpolicy_horizontal = expanding
                        spacing = 15

                        item = {

                            hbox = {

                                background = {
                                    using = Background_Area
                                }
                                
                                layoutpolicy_horizontal = expanding
                                portrait_head_small = {}

                                vbox = {
                                    layoutpolicy_vertical = expanding

                                    expand = {}

                                    text_single = {
                                        name = "ally_character_name"
                                        text = "[Character.GetName]"
                                        using = Font_Size_Medium
                                        align = nobaseline
                                    }

                                    hbox = {
                                        layoutpolicy_horizontal = expanding

                                        text_single = {
                                            name = "ally_military_strength_text"
                                            text = "DECLARE_WAR_ALLY_MILITARY_STRENGTH_DESC"
                                            align = nobaseline
                                        }

                                        expand = {}
                                    }
                                    expand = {}
                                }
                                expand = {}
                            }
                        }
                    }
                }
            }
        }
    }
}

types DeclareWarTypes
{
    type declare_war_cost = vbox {
        name = "cost"
        margin = { 10 0 }

        background = {
            visible = "[Not( DeclareWarInteractionWindow.CanAffordCosts )]"
            using = Status_Bad
            margin_top = 5
        }

        hbox = {
            name = "costs"
            visible = "[DeclareWarInteractionWindow.HasCost]"
            layoutpolicy_horizontal = expanding
            layoutpolicy_vertical = expanding
            spacing = 5

            text_single = {
                name = "cost_heading"
                align = nobaseline
                text = "WAR_COST"
                using = Font_Size_Big
            }

            hbox = {
                datacontext = "[DeclareWarInteractionWindow.GetCostBreakdown( 'piety' )]"
                tooltipwidget = { widget_value_breakdown_tooltip = {} }
                spacing = 2

                icon = {
                    name = "icon_piety"
                    datacontext = "[DeclareWarInteractionWindow.GetCostBreakdown( 'piety' )]"
                    visible = "[NotEqualTo_CFixedPoint( DeclareWarInteractionWindow.GetSpecificCost( 'piety' ), '(CFixedPoint)0' )]"
                    size = { 30 30 }
                    texture = "[GetPlayer.GetPietyLevelTexture]"
                }

                text_single = {
                    name = "piety"
                    datacontext = "[DeclareWarInteractionWindow.GetCostBreakdown( 'piety' )]"
                    visible = "[NotEqualTo_CFixedPoint( DeclareWarInteractionWindow.GetSpecificCost( 'piety' ), '(CFixedPoint)0' )]"
                    
                    text = "[DeclareWarInteractionWindow.GetSpecificCost( 'piety' )|0]"
                    align = nobaseline
                    using = Font_Size_Big
                    default_format = "#high"
                }
            }

            text_single = {
                name = "prestige"
                datacontext = "[DeclareWarInteractionWindow.GetCostBreakdown( 'prestige' )]"
                visible = "[NotEqualTo_CFixedPoint( DeclareWarInteractionWindow.GetSpecificCost( 'prestige' ), '(CFixedPoint)0' )]"

                text = "@prestige_icon![DeclareWarInteractionWindow.GetSpecificCost( 'prestige' )|0]"
                using = Font_Size_Big
                align = nobaseline
                default_format = "#high"

                tooltipwidget = { widget_value_breakdown_tooltip = {} }
            }

            text_single = {
                name = "renown"
                datacontext = "[DeclareWarInteractionWindow.GetCostBreakdown( 'renown' )]"
                visible = "[NotEqualTo_CFixedPoint( DeclareWarInteractionWindow.GetSpecificCost( 'renown' ), '(CFixedPoint)0' )]"

                text = "@dynasty_prestige_icon![DeclareWarInteractionWindow.GetSpecificCost( 'renown' )|0]"
                align = nobaseline
                using = Font_Size_Big
                default_format = "#high"

                tooltipwidget = { widget_value_breakdown_tooltip = {} }
            }

            text_single = {
                name = "gold"
                datacontext = "[DeclareWarInteractionWindow.GetCostBreakdown( 'gold' )]"
                visible = "[NotEqualTo_CFixedPoint( DeclareWarInteractionWindow.GetSpecificCost( 'gold' ), '(CFixedPoint)0' )]"

                text = "@gold_icon![DeclareWarInteractionWindow.GetSpecificCost( 'gold' )|0]"
                align = nobaseline
                using = Font_Size_Big
                default_format = "#high"

                tooltipwidget = { widget_value_breakdown_tooltip = {} }
            }
        }

        text_single  = {
            visible = "[Not(DeclareWarInteractionWindow.HasCost)]"
            text = "DECLARE_WAR_NO_COST"
            using = Font_Size_Medium
            align = nobaseline
        }
    }
}

types CharacterInteractionDeclareWar
{
    type widget_progressbar_declare_war = widget {
        widget = {
            size = { 100% 100% }
            scissor = yes

            icon = {               
                block "progressbar_texture"
                {
                    texture = "gfx/interface/progressbars/war_progress_blue.dds"
                }
                size = { 100% 100% }
                spriteType = Corneredtiled

                modify_texture = {
                    name = overlay
                    texture = "gfx/interface/component_masks/mask_fade_horizontal_middle_solid.dds"
                    blend_mode = mask
                }
            }
        }
        
        icon = {
            using = Animation_ShowHide_Standard
            parentanchor = right|vcenter
            position = { 5 0 }

            size = { 20 100% }
            texture = "gfx/interface/progressbars/progressbar_center_glow.dds"

            state = {
                name = a
                next = b
                trigger_on_create = yes
                duration = 0.1
                alpha = 1
            }

            state = {
                name = b
                next = a
                duration = 0.2
                alpha = 0.9
            }
        }
    }

    type declare_war_progressbar =     widget {
        size = { 200 24 }

        widget = {
            size = { 100% 100% }
            scissor = yes

            widget = {
                size = { 100% 100% }

                background = {
                    texture = "gfx/interface/progressbars/war_progress_red.dds"
                }
            }

            hbox = {
                widget_progressbar_declare_war = {
                    layoutpolicy_horizontal = expanding
                    layoutpolicy_vertical = expanding
                    layoutstretchfactor_horizontal = "[GetProgressBarValueMaxScaled( GuiMilitaryStrength.GetRatio, '(float)100', '(int32)200' )]"

                    blockoverride "progressbar_texture"
                    {
                        texture = "gfx/interface/progressbars/war_progress_blue.dds"
                    }
                }

                widget = {
                    layoutpolicy_horizontal = expanding
                    layoutpolicy_vertical = expanding
                    layoutstretchfactor_horizontal = "[GetProgressBarValueMaxOtherScaled( GuiMilitaryStrength.GetRatio, '(float)100', '(int32)200' )]"
                }
            }           
        }

        widget = {
            name = "power_bar_frame"
            parentanchor = top
            size = { 100% 100% }
            alwaystransparent = yes

            background = {
                texture = "gfx/interface/progressbars/progress_frame_war.dds"
                spriteType = Corneredstretched
                spriteborder = { 10 10 }
                margin = { 5 4 }
            }
        }
    }


    type declare_war_character_portrait = hbox {

        vbox = {
            datacontext = "[CharacterItem.GetCharacter]"
            spacing = -37

            portrait_torso = {
                blockoverride "status_icons" {}
                blockoverride "portrait_texture"
                {
                    portrait_texture = "[Character.GetPortrait('environment_torso', 'camera_torso', 'war_attacker', PdxGetWidgetScreenSize(PdxGuiWidget.Self))]"
                }
                blockoverride "portrait_button" {
                    
                    vbox = {
                        layoutpolicy_vertical = expanding
                        layoutpolicy_horizontal = expanding

                        expand = {}

                        hbox = {
                            layoutpolicy_horizontal = expanding
                            
                            expand = {
                                layoutpolicy_horizontal = expanding
                            }

                            spacer = {
                                size = { 8 0 }
                            }
                        }
                    }
                }
                blockoverride "opinion_box" {}
            }

            hbox = {
                layoutpolicy_horizontal = expanding
                expand = {}

                button_standard = {
                    name = "view_allies"
                    enabled = "[GreaterThan_int32( CharacterItem.GetAllyCount, '(int32)0' )]"
                    size = { 120 30 }
                    onclick = "[CharacterItem.ShowAllyList]"
                    text = "DECLARE_WAR_ALLY_COUNT"
                }
            }
        }
    }

    type declare_war_casus_belli_item = hbox {
        name = "casus_belli_item"
        layoutpolicy_horizontal = expanding
        margin = { 5 0 }
        spacing = 5
        alwaystransparent = yes
        using = tooltip_es

        icon = {
            name = "icon"
            texture = "[CasusBelliItem.GetType.GetIcon]"
            size = { 33 33 }
            alwaystransparent = yes
        }

        text_single = {
            name = "name"
            layoutpolicy_horizontal = expanding
            text = "[CasusBelliItem.GetLabel]"
            align = nobaseline
            autoresize = no
            alwaystransparent = yes
        }

        icon = {
            visible = "[Not( CasusBelliItem.IsValid )]"
            size = { 25 25 }
            texture = "gfx/interface/icons/symbols/icon_warning.dds"
            alwaystransparent = yes
            tooltip = "[CasusBelliItem.GetInvalidText]"
        }
    }
}

types CharacterGold
{
    type character_gold = hbox {
        datacontext = "[DeclareWarInteractionWindow.GetAttackerCharacter]"
        margin_top = -4
        spacing = 4

        icon = {
            name = "gold_icon"
            size = { 30 30 }
            texture = "gfx/interface/icons/icon_gold.dds"
        }

        text_single = {
            name = "gold_value_positive"
            visible = "[GreaterThanOrEqualTo_CFixedPoint(CharacterItem.GetGold, '(CFixedPoint)0')]"
            layoutpolicy_horizontal = expanding

            text = "[CharacterItem.GetGold|0]"
            align = nobaseline
            default_format = "#high"
            using = Font_Size_Medium
            max_width = 50
        }

        text_single = {
            name = "gold_value_negative"
            visible = "[LessThan_CFixedPoint(CharacterItem.GetGold, '(CFixedPoint)0')]"
            layoutpolicy_horizontal = expanding

            text = "[CharacterItem.GetGold|0]"
            default_format = "#N"
            using = Font_Size_Medium
            max_width = 50
        }
    }
}
 
Quick question for those familiar with map editor -- my map is painted with the right textures when I open it in map editor, but appears entirely different when I boot it up in game. Any ideas for what might be causing this?
 

Attachments

  • mapeditor.png
    mapeditor.png
    2,3 MB · Views: 0
  • ingame.png
    ingame.png
    2,9 MB · Views: 0