imperial_reconquest_carthage = {
	name = CB_NAME_IMPERIAL_CARTHAGE
	war_name = WAR_NAME_IMPERIAL_CARTHAGE
	sprite = 21
	truce_days = 3650
	is_permanent = yes
	check_de_jure_tier = DUKE # this scans all dejure duchies for the counties which are held by or vassals(or below) of selected character. Only valid if is_permanent = yes

	allowed_to_target_tributaries = no
	
	sort_priority = 1900
    
    can_use_gui = {
        ROOT = {
			independent = yes
			OR = { 
				religion = amazigh
				religion = amazigh_reformed
			}
        }
    }

	can_use_title = {
        ROOT = {
            has_landed_title = e_carthage
            NOT = { same_realm = FROM }
            mercenary = no
        }
		OR = {
            de_jure_liege_or_above = k_africa
            de_jure_liege_or_above = k_mauretania
            de_jure_liege_or_above = k_sicily
            de_jure_liege_or_above = k_sardinia
            de_jure_liege_or_above = k_valencia
            de_jure_liege_or_above = k_badajoz
            de_jure_liege_or_above = k_andalusia
		}
	}
	
	is_valid = {
		ROOT = {
			independent = yes
			OR = { 
				religion = amazigh
				religion = amazigh_reformed
			}
			NOT = { same_realm = FROM }
		}
	}

	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 = {
		ROOT = {
			participation_scaled_prestige = 100
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { 
				participation_scaled_prestige = 100
			}
		}
		
		FROM = { prestige = -100 }
	}

	on_success_title = {
		custom_tooltip = { 
			text = other_invasion_succ_tip
			hidden_tooltip = {
				ROOT = {
					vassalize_or_take_under_title = {
						title = PREV
						enemy = FROM
						type = invasion
					}
				}
			}
		}
		if = {
			limit = {
				holder_scope = { character = FROM }
			}
			usurp_title_only = { target = ROOT type = invasion }
		}

		hidden_tooltip = {
			check_if_reconquista_finished_effect = yes
			FROM = {
				landless_pope_effect = yes
			}
		}
	}

	on_fail = {
		ROOT = { prestige = -150 }
	}

	on_reverse_demand = {
		ROOT = {
			transfer_scaled_wealth = {
				to = FROM
				value = 4.0
			}
			ROOT = { prestige = -200 }
		}
		FROM = {
			participation_scaled_piety = 100
			participation_scaled_prestige = 200
			if = {
				limit = {
					uses_decadence = yes
				}
				participation_scaled_decadence = -10
			}
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { 
				participation_scaled_piety = 100
				participation_scaled_prestige = 200
				if = {
					limit = {
						uses_decadence = yes
					}
					participation_scaled_decadence = -10
				}
			}
		}
	}

	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
	}
}

salt_county = {
	name = CB_NAME_SALT_COUNTY
	war_name = WAR_NAME_SALT_COUNTY
	sprite = 21
	truce_days = 3650
	hostile_against_others = yes
	is_permanent = yes
	can_ask_to_join_war = yes
    check_all_titles = yes
	
	allowed_to_target_tributaries = no
	
	sort_priority = 2000

	can_use_gui = {
		ROOT = {
			piety = 1000
		}
		check_if_crusader_trigger = yes
        ROOT = {
            independent = yes
            NOT = { same_realm = FROM }
            OR = {   # Attacker must be Amazigh Carthaginian emperor or else not Amazigh
                AND = {
                    has_landed_title = e_carthage
                    OR = {
                        religion = amazigh
                        religion = amazigh_reformed
                    }
                }
                NOR = {
                    religion = amazigh
                    religion = amazigh_reformed
                }
            }
        }
        FROM = {   # Defender must be Amazigh Carthaginian emperor or else not Amazigh
            OR = {
                AND = {
                    has_landed_title = e_carthage
                    OR = {
                        religion = amazigh
                        religion = amazigh_reformed
                    }
                }
                NOR = {
                    religion = amazigh
                    religion = amazigh_reformed
                }
            }
        }
	}
	
	on_add = {
		ROOT = { show_scope_change = no piety = -1000 }
		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 
			}
		}
	}
    
    can_use = {
 		OR = {
			ROOT = { ai = yes }
			multiplayer = no
			NOT = {
				has_game_rule = {
					name = multiplayer_invasions
					value = off
				}
			}
		}
    }

	can_use_title = {
        OR = {
            AND = {   # Carthaginian emperor may attack Rome or Constantinople
                ROOT = { has_landed_title = e_carthage }
                OR = {
                    AND = {
                        title = c_roma
                        NOT = { has_global_flag = rome_salted }
                        333 = {
                            any_province_holding = { count = 3 }
                        }
                    }
                    AND = {
                        title = c_byzantion
                        NOT = { has_global_flag = constantinople_salted }
                        496 = {
                            any_province_holding = { count = 3 }
                        }
                    }
                }
            }
            AND = {   # Roman emperors may attack the capital of Carthage
                ROOT = {
                    OR = {
                        has_landed_title = e_byzantium
                        has_landed_title = e_roman_empire
                        has_landed_title = e_hre
                        has_landed_title = e_latin_empire
                    }
                }
                FROM = {
                    has_landed_title = e_carthage
                    capital_scope = {
                        any_province_holding = { count = 3 }
                        county = { title = PREVPREVPREV }
                    }
                }
                NOT = { has_global_flag = carthage_capital_salted }
            }
        }
	}
	
	is_valid_title = {
		FROM = {
            OR = {
                has_landed_title = PREV
                is_liege_or_above_of = PREV
            }
		}
	}
    
    is_valid = {
        OR = {
            ROOT = {
                has_landed_title = e_carthage
                OR = {
                    religion = amazigh
                    religion = amazigh_reformed
                }
            }
            AND = {
                ROOT = {
                    OR = {
                        has_landed_title = e_byzantium
                        has_landed_title = e_roman_empire
                        has_landed_title = e_hre
                        has_landed_title = e_latin_empire
                    }
                }
                FROM = {
                    has_landed_title = e_carthage
                    OR = {
                        religion = amazigh
                        religion = amazigh_reformed
                    }
                }
            }
        }
    }

	on_success = {
		ROOT = {
			show_scope_change = no
			prestige = 1000
			participation_scaled_prestige = 500
            
			if = {
				limit = { 
					has_dlc = "Legacy of Rome"
					OR = { 
						has_landed_title = e_byzantium
						has_landed_title = e_roman_empire
					}
						OR = { 
							religion_group = christian
							religion = hellenic_pagan
							religion = hellenic_pagan_reformed
						}
				}
				hidden_tooltip = { character_event = { id = LoR.30 days = 12 } }
			}
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { participation_scaled_prestige = 500 }
		}
		FROM = {
			show_scope_change = no
			prestige = -1000
		}
		ROOT = {
            custom_tooltip = {
                text = salt_county_succ_tooltip
                occupy_minors_of_occupied_settlements = FROM
                gain_all_occupied_titles = { who = FROM type = invasion }
            }
				
			if = {
				limit = {
					can_apply_cool_nickname_trigger = yes
				}
                if = {
                    limit = { has_landed_title = e_carthage }
                    give_nickname = nick_the_thunderbolt
                }
                else = {
                    give_nickname = nick_africanus
                }
            }
		}
	}
	
	on_success_title = {
		hidden_tooltip = {
            usurp_title_plus_barony_if_unlanded = { target = ROOT type = invasion }
            
            any_de_jure_vassal_title = { # take all baronies too
                limit = {
                    has_holder = yes
                    holder_scope = {
                        OR = {
                            character = FROM
                            is_liege_or_above = FROM
                            AND = {
                                is_liege_or_above = ROOT
                                NOT = { culture = ROOT }
                                NOT = { religion = ROOT }
                            }
                        }
                    }
                }
                show_scope_change = no
                usurp_title = ROOT
            }
			check_if_reconquista_finished_effect = yes
			FROM = {
				landless_pope_effect = yes
			}
		}
        if = {
            limit = {
                title = c_roma
            }
            set_global_flag = rome_salted
            ROOT = { narrative_event = { id = AFRREL.024 days = 3 } }
        }
        else_if = {
            limit = {
                title = c_byzantion
            }
            set_global_flag = constantinople_salted
            ROOT = { narrative_event = { id = AFRREL.026 days = 3 } }
        }
        else = {
            location = {
                save_event_target_as = carthage_capital
            }
            set_global_flag = carthage_capital_salted
            ROOT = { narrative_event = { id = AFRREL.028 days = 3 } }
        }
	}

	on_fail = {
		FROM = {
			show_scope_change = no
			prestige = 500
			participation_scaled_prestige = 200
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 200 }
		}
		ROOT = {
			show_scope_change = no
			prestige = -500
		}
	}

	on_reverse_demand = {
		ROOT = {
			show_scope_change = no
			prestige = -1000
			transfer_scaled_wealth = {
				to = FROM
				value = 4.0
			}
		}
		FROM = {
			show_scope_change = no
			prestige = 1000
			
			if = {
				limit = { 
					has_dlc = "Legacy of Rome"
					OR = { 
						has_landed_title = e_byzantium
						has_landed_title = e_roman_empire
					}
						OR = { 
							religion_group = christian
							religion = hellenic_pagan
							religion = hellenic_pagan_reformed
						}
				}
				hidden_tooltip = { character_event = { id = LoR.30 days = 12 } }
			}
			participation_scaled_prestige = 500
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 500 }
		}
	}

	attacker_ai_victory_worth = {
		factor = 200
	}
	
	attacker_ai_defeat_worth = {
		factor = 100
	}

	defender_ai_victory_worth = {
		factor = -1 # always accept
	}
	
	defender_ai_defeat_worth = {
		factor = 100
	}
	
	ai_will_do = { 
		factor = 1
		
		modifier = {
			factor = 0.9 # Prefer using CB's without on_add costs
		}
		modifier = { #Focus on Coronation first.
			factor = 0.1
			has_dlc = "Holy Fury"
			ROOT = {
				is_feudal = yes
				OR = {
					religion = catholic
					religion = fraticelli
				}
				NOR = {
					trait = crowned_by_priest
					trait = crowned_by_bishop
					trait = crowned_by_pope
					trait = crowned_by_myself
				}
			}
		}
	}
}