﻿# Event-only coalition war created only when enough refusers actually coordinate.
ddm_grand_capitulation_coalition_cb = {
    icon = independence_faction_war
    group = independence
    target_titles = none
    ai = no
    should_check_for_interface_availability = no
    white_peace_possible = yes
    ticking_war_score_targets_entire_realm = yes
    attacker_ticking_warscore_delay = { months = 6 }
    defender_ticking_warscore_delay = { months = 6 }
    attacker_ticking_warscore = 0.2
    defender_ticking_warscore = 0.2
    attacker_score_from_battles_scale = 175
    defender_score_from_battles_scale = 175
    defender_capital_gives_war_score = yes
    truce_days = 3650

    allowed_for_character = { is_landed = yes }
    allowed_against_character = { scope:defender = { is_landed = yes } }
    valid_to_start = {
        scope:attacker = { is_alive = yes is_at_war = no }
        scope:defender = { is_alive = yes is_at_war = no }
    }
    should_invalidate = {
        OR = { scope:attacker = { is_alive = no } scope:defender = { is_alive = no } }
    }
    on_declaration = { on_declared_war = yes }

    on_victory_desc = { desc = DDM_GRAND_CAP_COALITION_VICTORY_DESC }
    on_white_peace_desc = { desc = DDM_GRAND_CAP_COALITION_WHITE_PEACE_DESC }
    on_defeat_desc = { desc = DDM_GRAND_CAP_COALITION_DEFEAT_DESC }
    on_invalidated_desc = { desc = DDM_GRAND_CAP_COALITION_INVALIDATED_DESC }

    # Coalition wins: the hegemonic bluff is broken. Recently submitted direct vassals may throw off the
    # new arrangement, and the player suffers a major legitimacy/prestige reversal.
    on_victory = {
        scope:defender = {
            add_prestige = -2500
            if = { limit = { has_legitimacy = yes } add_legitimacy = -500 }
            add_character_flag = { flag = ddm_grand_capitulation_cooldown years = 10 }
            every_vassal = {
                limit = { has_character_flag = ddm_grand_capitulation_recent_submitter }
                create_title_and_vassal_change = { type = independency save_scope_as = ddm_cap_independence_change add_claim_on_loss = yes }
                becomes_independent = { change = scope:ddm_cap_independence_change }
                resolve_title_and_vassal_change = scope:ddm_cap_independence_change
                remove_character_flag = ddm_grand_capitulation_recent_submitter
            }
        }
        scope:war = { every_war_attacker = { add_prestige = 250 } }
    }

    on_white_peace = {
        scope:defender = { add_prestige = -500 add_character_flag = { flag = ddm_grand_capitulation_cooldown years = 7 } }
        scope:war = { every_war_attacker = { add_prestige = 100 } }
    }

    # Player wins: every surviving independent coalition participant is forced through a harsher version
    # of the same surrender. We reuse the 80% transfer then add extra legitimacy/prestige humiliation.
    on_defeat = {
        scope:defender = {
            save_scope_as = ddm_cap_actor
            ddm_snapshot_capitulation_government_effect = yes
        }
        scope:war = {
            every_war_attacker = {
                limit = { is_alive = yes is_landed = yes is_independent_ruler = yes }
                save_temporary_scope_as = ddm_cap_target
                scope:defender = { ddm_apply_grand_capitulation_submission_effect = yes }
                add_prestige = -1000
                if = { limit = { has_legitimacy = yes } add_legitimacy = -250 }
            }
        }
        scope:defender = {
            ddm_restore_capitulation_government_effect = yes
            remove_variable = ddm_cap_original_government
            add_prestige = 1500
            if = { limit = { has_legitimacy = yes } add_legitimacy = 150 }
        }
    }

    on_invalidated = { }
    war_name = DDM_GRAND_CAP_COALITION_WAR_NAME
}
