

### dragon tribalisation war
dragon_tribalism_cb = {
    name = DRAGON_LOOT_CB
    war_name = DRAGON_LOOT_WAR_NAME
    sprite = 16
    truce_days = 2000

    is_permanent = yes
    hostile_against_others = yes
    full_hostility = yes
    can_ask_to_join_war = yes
    allow_whitepeace = no
    allowed_to_target_tributaries = no

    attacker_can_call_allies = no   #no one want to help dragon looting without rewards
    defender_can_call_allies = yes
    can_attack_vassals = no
    check_all_titles = yes

	allow_distant = yes

    attacker_ai_victory_worth = {
        factor = -1 # always accept
    }
	attacker_ai_defeat_worth = {
		factor = 100
	}
	defender_ai_victory_worth = {
		factor = -1 # always accept
	}
	defender_ai_defeat_worth = {
		factor = 100
	}

    battle_warscore_mult = 2
    sort_priority = 1500

    max_defender_occupation_score = 100
    max_attacker_occupation_score = 99
    max_defender_battle_score     = 100
    max_attacker_battle_score     = 100
    defender_unoccupied_warscore  = yes
    attacker_unoccupied_warscore  = no
    capturing_attacker_is_complete_victory = yes
    capturing_defender_is_complete_victory = yes

    can_use = { #if cb appear on screen
        ROOT = {
            culture_group = dragon_group
            independent = yes
        }
    }
    can_use_title = { # what is the target title of the war
		has_holder = yes
        tier = COUNT
        ROOT_can_integrate_title_trigger = yes
    }
    can_use_gui = { # if can press button "declare war" with this cb
        ROOT = {
            #war = no
            dragon_is_adult_trigger = yes
        }
    }

    is_valid = { # condition continue the war (not stopping it with invalid reason)
        ROOT = {
            government = dragon_tribal_gov
        }
    }
    is_valid_title = {
        holder_scope = {
            top_liege = {
                character = FROM
            }
        }
    }

    #attacker's win
    on_success = {
        FROM = { # removing all existing tributaries
            any_suzerain = {
                remove_tributary = PREV
            }
        }
        if = {
            limit = {
                FROM = {
                    NOT = { culture_group = dragon_group }
                }
            }
            ROOT = {
                make_tributary = {
                    who = FROM
                    tributary_type = dragon_vassal_tributary
                }
            }
        }
        ROOT = {
            prestige = 100
        }
        any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
    }
    on_success_title = {
        if = {
            limit = {
                FROM = {
                    culture_group = dragon_group
                }
            }
            gain_title = {
                target = ROOT
                type = invasion
            }
            location = {
                culture = ROOT
            }
        }

        hidden_tooltip = {
            destroy_fort = location
        }
        create_fort = location

        location = {
            add_to_extra_holding = {
                type = fort
                building = fo_drg_guardian_01
            }
            hidden_tooltip = {
                if = {
                    limit = {
                        FROM = {
                            culture_group = dragon_group
                        }
                    }
                    add_to_extra_holding = {
                        type = fort
                        building = fo_drg_guardian_02
                    }
                    add_to_extra_holding = {
                        type = fort
                        building = fo_drg_guardian_03
                    }
                    add_to_extra_holding = {
                        type = fort
                        building = fo_drg_guardian_04
                    }
                    add_to_extra_holding = {
                        type = fort
                        building = fo_drg_guardian_05
                    }
                }
            }
        }
    }

    on_reverse_demand = {
        ROOT = {
            # clear_wealth = yes
            transfer_scaled_wealth = {
                to = FROM
                value = all
            }
        }   
        ROOT = {
            wealth = -1000 # forcibly put to -1000 gold
        }
        any_defender = {
            participation_scaled_piety = 1000
        }
    }

    ai_will_do = {
        factor = 10
    }
}

### dragon hunting
dragon_hunting_war = {
    name = DRAGON_HUNTING_CB_NAME
    war_name = DRAGON_HUNTING_WAR_NAME
    sprite = 25

    truce_days = 5475
    is_permanent = yes
    is_independence = yes
    hostile_against_others = no
    can_ask_to_join_war = yes
    allow_whitepeace = yes
    can_call_allies = yes
    can_call_vassals = yes
    allow_distant = yes

    attacker_ai_victory_worth = {
        factor = -1 # always accept
    }
	attacker_ai_defeat_worth = {
		factor = 100
	}
	defender_ai_victory_worth = {
		factor = -1 # always accept
	}
	defender_ai_defeat_worth = {
		factor = 100
	}

    battle_warscore_mult = 3
    infamy_modifier = 0
    max_defender_occupation_score = 100
    max_attacker_occupation_score = 100
    max_defender_battle_score = 500
    max_attacker_battle_score = 500

    defender_unoccupied_warscore = yes
    sort_priority = 800

    can_use = {
        FROM = {
            government = dragon_tribal_gov
            OR = {
                any_tributary = {
                    always = yes
                }
                any_vassal = {
                    higher_tier_than = BARON
                }
            }
        }
        ROOT = {
            NOT = {
                culture_group = dragon_group
            }
            OR = {
                liege = {
                    character = FROM
                }
                suzerain = {
                    character = FROM
                }
                AND = {
                    OR = {
                        ai = no
                        ai_zeal = 30
                    }
                    NOT = {
                        religion_group = FROM
                    }
                }
            }
        }
    }
    is_valid = {
        FROM = {
            government = dragon_tribal_gov
            NOT = { religion_group = ROOT }
        }
    }
    on_success = {
        hidden_tooltip = {
            generate_tooltip = no
            any_defender = {
                set_character_flag = dragon_hunting_war_looser
            }
        }
        FROM = {
            custom_tooltip = {
                text = TT_DRAGON_VASSAL_GOES_INDEP
                any_vassal = {
                    limit = {
                        NOT = { has_character_flag = dragon_hunting_war_looser}
                    }
                    set_defacto_liege = THIS
                }
            }

            custom_tooltip = {
                text = TT_LOOSE_ALL_PROVINCE_FORT
                any_realm_province = {
                    if = {
                        limit = {
                            OR = {
                                is_capital = no
                                NOT = { fort_has_building = fo_drg_heart_1 }
                            }
                        }
                        destroy_fort = THIS
                    }
                    else = {
                        destroy_in_extra_holding = {
                            type = fort
                            building = fo_drg_retinue_1
                        }
                        destroy_in_extra_holding = {
                            type = fort
                            building = fo_drg_retinue_2
                        }
                        destroy_in_extra_holding = {
                            type = fort
                            building = fo_drg_retinue_3
                        }
                        destroy_in_extra_holding = {
                            type = fort
                            building = fo_drg_heart_1
                        }
                        destroy_in_extra_holding = {
                            type = fort
                            building = fo_drg_heart_2
                        }
                        destroy_in_extra_holding = {
                            type = fort
                            building = fo_drg_heart_3
                        }
                        destroy_in_extra_holding = {
                            type = fort
                            building = fo_drg_trainee
                        }
                        destroy_in_extra_holding = {
                            type = fort
                            building = fo_drg_academy_1
                        }
                        destroy_in_extra_holding = {
                            type = fort
                            building = fo_drg_academy_2
                        }
                        destroy_in_extra_holding = {
                            type = fort
                            building = fo_drg_academy_3
                        }
                        destroy_in_extra_holding = {
                            type = fort
                            building = fo_drg_casus_belli_1
                        }
                        destroy_in_extra_holding = {
                            type = fort
                            building = fo_drg_casus_belli_2
                        }
                        destroy_in_extra_holding = {
                            type = fort
                            building = fo_drg_casus_belli_3
                        }
                        destroy_in_extra_holding = {
                            type = fort
                            building = fo_drg_guardian_10
                        }
                        destroy_in_extra_holding = {
                            type = fort
                            building = fo_drg_guardian_09
                        }
                        destroy_in_extra_holding = {
                            type = fort
                            building = fo_drg_guardian_08
                        }
                        destroy_in_extra_holding = {
                            type = fort
                            building = fo_drg_guardian_07
                        }
                        destroy_in_extra_holding = {
                            type = fort
                            building = fo_drg_guardian_06
                        }
                    }
                }
            }
        }
        custom_tooltip = {
            text = TT_ALL_DRAGON_DIES
            any_defender = {
                clear_wealth = yes
                death = {
                    death_reason = death_execution_impaling
                    killer = ROOT
                }
            }
        }

        ROOT = {
            wealth = 1000
            prestige = 1000
            piety = 1000
        }

        hidden_effect = {
            FROM = {
                any_tributary = {
                    remove_tributary = PREV
                }
            }
        }
        custom_tooltip = {
            text = TT_DRG_ATTACKER_REPART_PRESTIGE_AND_PIETY
            any_attacker = {
                limit = { NOT = { character = ROOT } }
                participation_scaled_prestige = 2000
                participation_scaled_piety = 1000
            }
        }
    }
    on_fail = {
        FROM = {
            prestige = 150            
        }
        ROOT = {
            prestige = -200
            piety = -300
        }
    }
    on_reverse_demand = {
        hidden_effect = {
            any_defender = {
                set_character_flag = dragon_war_hunt_defender
            }
        }

        custom_tooltip = {
            text = TT_FORT_CREATED
            FROM = {
                save_event_target_as = target_looter
            }
            any_attacker = {
                character_event = { id = ani_plus.261 }
            }
        }

        custom_tooltip = {
            text = TT_ATTACKER_BECOME_TRIBUTARY
            any_attacker = {
                limit = {
                    independent = yes
                }
                FROM = {
                    show_scope_change = no
                    make_tributary = {
                        who = PREV
                        tributary_type = dragon_vassal_tributary
                    }
                }
            }
        }

        custom_tooltip = {
            text = TT_GIVE_ALL_ITS_FORTUNE
            any_attacker = {
                if = {
                    limit = {
                        wealth = 500
                    }
                    transfer_scaled_wealth = {
                        to = FROM
                        value = all
                    }
                }
                else = {
                    wealth = -500
                    FROM = { wealth = 500 }
                }
                prestige = -2000
                piety = -1000
            }
        }

        hidden_effect = {
            any_defender = {
                clr_character_flag = dragon_war_hunt_defender
            }
        }

        custom_tooltip = {
            text = TT_DRG_DEFENDER_REPART_PRESTIGE_AND_PIETY
            any_defender = {
                limit = { NOT = { character = FROM } }
                participation_scaled_prestige = 2000
                participation_scaled_piety = 1000
            }
        }
    }
    on_add = {
        any_player = {
            narrative_event = { id = ani_plus.262 days = 1}
        }
    }
}

#independance war from bear tributary
independance_bear_tributary_cb = {
    name = CB_NAME_LIBERTY
    war_name = WAR_NAME_LIBERTY
    sprite = 25

    truce_days = 5475 #max 1 every 15 years
    is_permanent = yes
    is_independence = yes
    hostile_against_others = yes
    can_ask_to_join_war = no

    sort_priority = 1100

    attacker_ai_victory_worth = {
        factor = -1 # always accept
    }
	attacker_ai_defeat_worth = {
		factor = 100
	}
	defender_ai_victory_worth = {
		factor = -1 # always accept
	}
	defender_ai_defeat_worth = {
		factor = 100
	}
    max_defender_occupation_score = 100
    max_attacker_occupation_score = 100
    max_defender_battle_score     = 70
    max_attacker_battle_score     = 50
    defender_unoccupied_warscore  = no
    attacker_unoccupied_warscore  = yes
    capturing_attacker_is_complete_victory = yes
    capturing_defender_is_complete_victory = yes

    can_use = { #if cb appear on screen
        ROOT = {
            is_tributary = {
                type = bear_tributary
                suzerain = FROM
            }
        }
    }
    can_use_gui = { #if can press button "dclare war" with this cb
        ROOT = {
            has_regent = no
            prestige  = 0  #a positive amount of prestige, piety and wealth
            piety = 0
            # wealth = 0
            war = no
            NOT = { has_truce = FROM }
        }
        FROM = {
            war = no
        }
    }
    is_valid = { always = yes }
    is_valid_title = { always = yes }

    on_add = {
        hidden_tooltip = { fire_haruspicy_event_effect = yes }
		if = {
			limit = { defender = { is_offmap_governor = offmap_china } }
			attacker = {
				sound_effect = china_angered_emperor
				detract_grace_super_huge_effect = yes
			}
		}
	}


    on_success = {
        FROM = {
            prestige = -500
        }
        ROOT = {
            prestige = 400
            if = {
                limit = {
					is_tributary = yes
					suzerain = {
						OR = {
							character = FROM
							any_liege = {
								character = FROM
							}
						}
					}
				}
                suzerain = {
                    remove_tributary = PREV
                }
            }
            any_vassal = {
                limit = {
                    is_tributary = yes
					suzerain = {
						OR = {
							character = FROM
							any_liege = {
								character = FROM
							}
						}
					}
                }
                suzerain = {
					remove_tributary = PREV
				}
            }
        }
    }
    on_fail = {
        ROOT = {
            prestige = -250
        }
        FROM = {
            prestige = 200
        }
    }
    on_reverse_demand = {
        ROOT = {
            prestige = -500
            abdicate_to = FROM
        }
        FROM = {
            prestige = 400
            reverse_imprison = ROOT
        }
    }
    ai_will_do = {
        factor = 0.8

        modifier = {
            factor = 5
            ROOT = {
                NOT = {
                    government = Bear_feudal_gov
                }
            }
        }
        modifier = {
			factor = 4
			ROOT = {
                ai_ambition = 40
			}
		}
        modifier = {
            factor = 2.5
            ROOT = {
                opinion = {
                    who = FROM
                    value < 0
                }

            }
        }
    }
}

#hedgehog conversion quest by hostility
hedgehog_hostility_province_war = {
    name = CB_NAME_HEDGE_INVASION
    war_name = WAR_NAME_HEDGE_INVASION
    sprite = 1

    truce_days = 1826
    is_permanent = no
    is_independence = yes
    hostile_against_others = yes
    full_hostility = yes
    # is_revolt_cb = yes #if put to yes, replace vassal imprisonment failed war

    allow_whitepeace = no
    max_defender_battle_score = 100
    attacker_ai_victory_worth = {
        factor = -1 # always accept
    }
	attacker_ai_defeat_worth = {
		factor = 100
	}
	defender_ai_victory_worth = {
		factor = -1 # always accept
	}
	defender_ai_defeat_worth = {
		factor = 100
	}
    att_ticking_war_score_multiplier = 2.5
    def_ticking_war_score_multiplier = 1.75

    can_use_title = {
        tier = COUNT
    }
    can_use = {
        ROOT = {
            culture_group = hedgehog_group
        }
        FROM = {
            NOT = { culture_group = hedgehog_group }
        }
    }
    is_valid = {
        FROM = {
            NOT = { culture_group = hedgehog_group }
        }
    }
    is_valid_title = { always = yes }

    apply_long_occ_mod = no
    # is_valid = {
    #     ROOT = {
    #         has_earmarked_regiments = hedge_hostility_revolt_army
    #     }
    # }
    on_success_title = { #hedgehogg wins
        location = { remove_province_modifier = hedge_hedgehog_hostile_inhabitant }

        custom_tooltip = {
            text = HEDGE_WON_HOSTILITY_WAR_TITLE_GAIN
            ROOT = { #county
                grant_title = PREV
            }
            any_de_jure_vassal_title = { #baronnies
                ROOT = {
                    grant_title = PREV
                }
            }
        }
        location = {
            culture = ROOT
        }
        FROM = {
            any_realm_province = {
                limit = {
                    has_province_flag = hedge_in_hostility_war_allies
                }
                clr_province_flag = hedge_in_hostility_war_allies
                hidden_tooltip = {
                    remove_province_modifier = hedge_hedgehog_hostile_inhabitant
                    remove_province_modifier = hedge_hedgehog_friendly_inhabitant
                    remove_province_modifier = hedge_hedgehog_inhabitant
                }
                if = {
                    limit = {
                        terrain = desert
                    }
                    culture = hedgehog_desert
                }
                else = {
                    culture = hedgehog_culture
                }
                county = {
                    ROOT = {
                        grant_title = PREV
                    }
                    any_de_jure_vassal_title = {
                        ROOT = {
                            grant_title = PREV
                        }
                    }
                }
            }
            imprison = ROOT
            prestige = -100
            piety = -100
        }
    }
    on_reverse_demand_title = {

        FROM = {
            any_realm_province = {
                clr_province_flag = hedge_in_hostility_war_allies
            }
            prestige = 150
            piety    = 75
            reverse_imprison = ROOT
        }
    }
    on_attacker_leader_death = {
        end_war = invalid
    }
    on_invalidation = {
        FROM = {
            any_realm_province = {
                clr_province_flag = hedge_in_hostility_war_allies
            }
        }
    }
}

#panda faction CB
panda_cb_faction_independence = {
	name = CB_NAME_INDEPENDENCE
	war_name = WAR_NAME_FACTION_INDEPENDENCE
	sprite = 12
	truce_days = 3650
    is_permanent = yes
	major_revolt = yes

	attacker_can_call_allies = no
	can_ask_to_join_war = no

	is_independence = yes

    can_use = {
        ROOT = {
            vassal_of = FROM
            mercenary = no
        }
        FROM = {
            government = panda_bureaucratic_gov
        }
    }
	can_use_gui = {
		always = yes
	}
    on_add = {
        hidden_tooltip = { fire_haruspicy_event_effect = yes }
    }
	is_valid = {
		ROOT = {
			OR = {
				liege = {
					character = PREV # either independent
				}
				liege = {
					FROM = {
						is_liege_or_above = PREV # or have shared liege
					}
				}
			}
		}
		FROM = {
			any_demesne_title = {
				NOT = { lower_tier_than = ROOT }
				temporary = no
			}
			independent = yes
			in_revolt = no
			liege_before_war = {
				in_revolt = no
				liege_before_war = {
					in_revolt = no
				}
			}
		}
	}

    attacker_ai_victory_worth = {
        factor = -1 # always accept
    }

    attacker_ai_defeat_worth = {
        factor = 150
    }

    defender_ai_victory_worth = {
        factor = -1 # always accept
    }

    defender_ai_defeat_worth = {
        factor = 100
    }

	on_success = {
        FROM = {
            prestige = -250
        }
        custom_tooltip = {
            text = PANDA_INDEP_GRANTED

            FROM = {
                if = {
                    limit = {
                        has_law = panda_vassal_all_allowed
                    }
                    primary_title = {
                        add_law = panda_vassal_count_allowed # can't have strong vassals anymore
                    }
                }
            }
        	any_attacker = {
                capital_scope = {
                    any_neighbor_province = {
                        limit = {
                            has_owner = yes
                            county = {
                                same_realm = FROM
                            }
                        }
                        county = {
                            grant_title = PREVPREVPREV
                        }
                    }
                }
                set_defacto_liege = THIS
    		}
        }
	}
	on_fail = {
		ROOT = {
			prestige = -100
			add_character_modifier = {
				name = faction_independence_ultimatum_timer
				hidden = yes
				duration = 3650
			}
			participation_scaled_prestige = -50
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = {
				participation_scaled_prestige = -50
			}
			add_character_modifier = {
				name = faction_independence_ultimatum_timer
				hidden = yes
				duration = 3650
			}
		}
		FROM = { hidden_tooltip = { disband_event_forces = faction_loyalists } }
	}
	on_reverse_demand = {
		ROOT = {
			prestige = -100
			prisoner = FROM
			add_character_modifier = {
				name = faction_independence_ultimatum_timer
				hidden = yes
				duration = 3650
			}
			participation_scaled_prestige = -100
		}

		any_attacker = {
			limit = {
				NOT = { character = ROOT }
				liege = { character = FROM }
			}
			prisoner = FROM
			participation_scaled_prestige = -100
			hidden_tooltip = {
				add_character_modifier = {
					name = faction_independence_ultimatum_timer
					hidden = yes
					duration = 3650
				}
			}
		}

		FROM = {
			prestige = 50
			hidden_tooltip = {
				if = {
					limit = { NOT = { has_opinion_modifier = { modifier = opinion_traitor who = ROOT } } } #Allow free revocation of a title.
					opinion = {
						who = ROOT
						modifier = opinion_traitor
					}
				}
			}
		}
	}


	on_attacker_leader_death = {
		end_war = invalid
	}
}

#cat conversion quest CB
cat_basic_revolt_cb = {
    name = CB_CAT_REVOLT
    war_name = CB_CAT_REVOLT_NAME

    sprite = 1
    truce_days = 360
    is_permanent = no

    hostile_against_others = yes
    full_hostility = yes
    can_ask_to_join_war = yes

    can_call_allies = yes
    can_call_vassals = yes
    attacker_ai_victory_worth = {
        factor = -1 # always accept
    }
	attacker_ai_defeat_worth = {
		factor = 100
	}
	defender_ai_victory_worth = {
		factor = -1 # always accept
	}
	defender_ai_defeat_worth = {
		factor = 100
	}

    capturing_attacker_is_complete_victory = yes
    capturing_defender_is_complete_victory = no



    can_use_title = {
        OR = {
            tier = COUNT
            tier = BARON
        }
    }
    can_use = {
        ROOT = {
            culture_group = cat_group
        }
        FROM = {
            NOT = { culture_group = cat_group }
        }
    }
    is_valid = {
        ROOT = {
            culture_group = cat_group
        }
        FROM = {
            NOT = { culture_group = cat_group }
        }
    }
    is_valid_title = { always = yes }
    on_add = { }
    on_add_title = { }
    on_success = {
        ROOT = {
            prestige = 350
        }
        FROM = {
            prestige = -500
        }
    }
    on_success_title = {
        grant_title = {
            target = ROOT
            type = revolt
        }
        if = {
            limit = {
                tier = BARON
            }
            county = {
                grant_title = {
                    target = ROOT
                    type = revolt
                }
            }
        }
        location = {
            culture = ROOT
        }
    }
    on_fail = {
        FROM = { prestige = -100}
    }
    on_fail_title = {
        location = {
            culture = ROOT
        }
    }
    on_reverse_demand = {
        FROM = { prestige = 500 }
    }
    on_reverse_demand_title = {
        location = {
            any_province_holding = {
                remove_holding_modifier = cat_controlled_holding
            }
        }
    }
    on_attacker_leader_death = {
        end_war = invalid
    }
    on_invalidation = {
    }
}
