great_debate = {
	name = CB_NAME_DEBATE
	war_name = WAR_NAME_DEBATE
	sprite = 8
	truce_days = 3650
	hostile_against_others = yes
	is_permanent = yes
	can_ask_to_join_war = yes
	check_de_jure_tier = KING # this scans all de jure kingdoms 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 = 2000

	can_use_gui = {
		ROOT = {
			prestige = 500
		}
	}
	
	on_add = {
		ROOT = { show_scope_change = no prestige = -500 }
		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 
			}
		}
		if = {
			limit = { 
				attacker = { 
					any_owned_bloodline = {
						has_bloodline_flag = bloodline_great_conquerors
					} 
				} 
			}
			attacker = {  
				set_character_flag = flag_declared_bloodline_invasion
			}
		}
	}

	can_use_title = {
		ROOT = {
			OR = {
				ai = yes
				multiplayer = no
				NOT = {
					has_game_rule = {
						name = multiplayer_invasions
						value = off
					}
				}
			}
			is_nomadic = no
religion_group = logic_group
			culture = facts
		}
		
		ROOT = {
			NOT = { same_realm = FROM }
		}
		
		OR = { # This ensures that the AI doesn't declare this type of war against someone who only holds a few counties within the targeted title...
			ROOT = {
				ai = no
			}
			ROOT = {
				OR = {
					has_landed_title = e_mongol_empire
					has_landed_title = e_mexikha
				}
			}
			FROM = {
				num_of_realm_counties = {
					value = 3
					title = PREV
				}
			}
		}
	}
	
	is_valid_title = {
		FROM = {
			any_realm_province = {
				de_jure_liege_or_above = PREVPREV
			}
		}
	}

	on_success = {
		ROOT = {
			show_scope_change = no
			prestige = 200
			participation_scaled_prestige = 200
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { participation_scaled_prestige = 200 }
		}
		FROM = {
			show_scope_change = no
			prestige = -200
		}
		hidden_tooltip = {
			ROOT = {
				occupy_minors_of_occupied_settlements = FROM
				gain_all_occupied_titles = { who = FROM type = invasion }
				
				if = {
					limit = {
						has_nickname = no
					}
					random_list = {
						10 = { give_nickname = nick_the_great }
						10 = { give_nickname = nick_the_victorious }
						10 = { give_nickname = nick_the_conqueror }
						10 = { give_nickname = nick_the_brave }
						10 = { give_nickname = nick_the_dragon }
						10 = { give_nickname = nick_the_terrible }
					}
				}
			}
		}
	}
	
	on_success_title = {
	
		if = {
			limit = {
				ROOT = {
					OR = {
						character = 159136
						character = 159137
					}
				}
			}
			ROOT = {
				if = {
					limit = {
						has_dlc = "Holy Fury"
						NOT = {
							any_owned_bloodline = {
								has_bloodline_flag = arpad_bloodline
							}
						}
					}
					create_bloodline = {
						type = arpad
					}
				}
			}
		}
		
		custom_tooltip = {
			text = tribal_invasion_succ_tip
			hidden_tooltip = {
				ROOT = {
					vassalize_or_take_under_title_destroy_duchies = {
						title = PREV
						enemy = FROM
						is_crusade = yes # Even if the title holder is not participating in the war, gain holdings occupied by all Crusade participants
						type = invasion
					}
				}
				if = {
					limit = {
						e_mexikha = {
							holder = ROOT
						}
					}
					ROOT = {
						any_realm_province = {
							limit = {
								OR = {
									has_province_flag = aztec_explorers
									has_province_flag = aztec_second_wave
								}
							}
							culture = nahuatl
							religion = aztec
							clr_province_flag = aztec_explorers
							clr_province_flag = aztec_second_wave
						}
					}
				}
			}
		}

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

	on_fail = {
		FROM = {
			show_scope_change = no
			prestige = 100
			
			hidden_tooltip = {
				if = {
					limit = {
						has_nickname = no
					}
					random_list = {
						10 = { give_nickname = nick_the_great }
						10 = { give_nickname = nick_the_hammer }
						10 = { give_nickname = nick_the_avenger }
						10 = { give_nickname = nick_the_lion }
						10 = { give_nickname = nick_the_bold }
					}
				}
			}
			participation_scaled_prestige = 100
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
		ROOT = {
			show_scope_change = no
			prestige = -200
		}
	}

	on_reverse_demand = {
		ROOT = {
			show_scope_change = no
			prestige = -200
			transfer_scaled_wealth = {
				to = FROM
				value = 4.0
			}
		}
		FROM = {
			show_scope_change = no
			prestige = 200
			hidden_tooltip = {
				if = {
					limit = {
						has_nickname = no
					}
					random_list = {
						10 = { give_nickname = nick_the_great }
						10 = { give_nickname = nick_the_hammer }
						10 = { give_nickname = nick_the_avenger }
						10 = { give_nickname = nick_the_lion }
						10 = { give_nickname = nick_the_bold }
					}
				}
			}
			
			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 = 200
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 200 }
		}
	}

	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
				}
			}
		}
		
		# Try to guide the Hordes in the right direction
		modifier = {
			factor = 0.1
			ROOT = {
				OR = {
					dynasty = 613 # Seljuks
					dynasty = 800 # Timurids
					primary_title = { title = e_il-khanate }
				}
			}
			OR = {
				empire = {
					NOT = {
						OR = {
							title = e_persia
							title = e_byzantium
							title = e_arabia
						}
					}
				}
				FROM = {
					primary_title = { title = e_golden_horde }
					NOT = { year = 1300 }
				}
			}
		}
		modifier = {
			factor = 0.1
			ROOT = {
				primary_title = { title = e_golden_horde }
			}
			OR = {
				empire = {
					OR = {
						title = e_persia
						title = e_byzantium
						title = e_arabia
					}
				}
				FROM = {
					primary_title = { title = e_il-khanate }
					NOT = { year = 1300 }
				}
			}
		}
		modifier = {
			factor = 0.1
			ROOT = {
				culture = hungarian
				primary_title = {
					OR = {
						title = k_hungary
						title = e_carpathia
					}
				}
			}
			empire = {
				OR = {
					title = e_tartaria
					title = e_russia
				}
			}
		}
		modifier = {
			factor = 0
			ROOT = {
				has_character_flag = is_temujin
				has_landed_title = e_mongol_empire
				demesne_size = 1
			}
			FROM = {
				has_landed_title = e_china_west_governor
			}
		}
		modifier = {
			factor = 0
			FROM = {
				is_nomadic = yes
			}
			ROOT = {
				is_nomadic = no
				NOT = {
					is_tribal = yes
				}
			}
			NOT = {
				any_direct_de_jure_vassal_title = {
					any_direct_de_jure_vassal_title = {
						OR = {
							holding_type = castle
							holding_type = city
						}
					}
				}
			}
		}
		modifier = {
			factor = 0
			FROM = {
				is_nomadic = yes
			}
			ROOT = {
				is_tribal = yes
			}
			NOT = {
				any_direct_de_jure_vassal_title = {
					any_direct_de_jure_vassal_title = {
						OR = {
							holding_type = castle
							holding_type = city
							holding_type = tribal
						}
					}
				}
			}
		}
	}
}