###JD Decisions###

# Written by:
# Drikus Kuiper
# Matthew Clohessy

decisions = {

	adopt_chinese_imperialism = {
		ai_check_interval = 60

		is_high_prio = yes

		only_independent = yes

		potential = {
			independent = yes
			has_dlc = "Jade Dragon"
			chinese_imperial_government_culture_trigger = yes
			is_feudal = yes
			holy_order = no
			NOT = { government = chinese_imperial_government }

			trigger_if  = {
				limit = { ai = yes }

				trigger_if = {
					limit = {
						OR = {
							trait = proud
							trait = ambitious
						}
					}

					prestige >= 40000
				}
				trigger_else = {
					prestige >= 120000
				}
			}
		}

		allow = {
			real_tier = EMPEROR
			is_tributary = no
			is_adult = yes
			prisoner = no
			is_incapable = no
			realm_size >= 200

			trigger_if = {
				limit = { religion = taoist }

				prestige >= 8000
				wealth   >=  500
			}
			trigger_else = {
				prestige >= 16000
				wealth   >=  1000
			}

			offmap_china = {
				show_scope_change = no
				offmap_ruler = { NOT = { dynasty = ROOT } }
			}
		}

		effect = {
			set_character_flag = receiving_special_empire

			if = {
				limit = { religion = taoist }
				wealth = -500
			}
			else = {
				wealth = -1000
			}

			if = {
				limit = {
					has_dlc = "Holy Fury"

					NOT = {
						any_owned_bloodline = {
							has_bloodline_flag = created_bloodline
						}
					}
				}

				narrative_event = {
					id = HF.24240
					tooltip = tooltip_evt_hf_24240
				}
			}

			custom_tooltip = {
				text = adopt_chinese_imperialism_tt

				primary_title = {
					create_title = {
						tier = EMPEROR
						culture = ROOT
						holder = ROOT
						base_title = THIS
						landless = no
						temporary = no
						custom_created = yes
						short_name = yes
						copy_title_laws = yes
					}

					new_title = {
						# Titles with this flag give their heirs a temple name via on_death event
						set_title_flag = uses_temple_names_by_script

						# Blocks all grace interactions
						set_title_flag = pretender_chinese_empire

						# Use WP adj as it is "Chinese" but also gives the right one in different languages
						adjective = e_china_west_governor_adj

						# Random Empire name that China doesn't have
						random_list = {
							1 = {
								trigger = { NOT = { offmap_china = { has_offmap_name = tang_china } } }
								set_name = "Tang Empire"
								set_title_flag = china_name_Tang
							}
							1 = {
								trigger = { NOT = { offmap_china = { has_offmap_name = jin_china } } }
								set_name = "Jin Empire"
								set_title_flag = china_name_Jin
							}
							1 = {
								trigger = { NOT = { offmap_china = { has_offmap_name = wei_china } } }
								set_name = "Wei Empire"
								set_title_flag = china_name_Wei
							}
							1 = {
								trigger = { NOT = { offmap_china = { has_offmap_name = qi_china } } }
								set_name = "Qi Empire"
								set_title_flag = china_name_Qi
							}
							1 = {
								trigger = { NOT = { offmap_china = { has_offmap_name = zhou_china } } }
								set_name = "Zhou Empire"
								set_title_flag = china_name_Zhou
							}
							1 = {
								trigger = { NOT = { offmap_china = { has_offmap_name = han_china } } }
								set_name = "Han Empire"
								set_title_flag = china_name_Han
							}
							1 = {
								trigger = { NOT = { offmap_china = { has_offmap_name = qin_china } } }
								set_name = "Qin Empire"
								set_title_flag = china_name_Qin
							}
							1 = {
								trigger = { NOT = { offmap_china = { has_offmap_name = yan_china } } }
								set_name = "Yan Empire"
								set_title_flag = china_name_Yan
							}
							1 = {
								trigger = { NOT = { offmap_china = { has_offmap_name = zhao_china } } }
								set_name = "Zhao Empire"
								set_title_flag = china_name_Zhao
							}
							1 = {
								trigger = { NOT = { offmap_china = { has_offmap_name = liao_china } } }
								set_name = "Liao Empire"
								set_title_flag = china_name_Liao
							}
							1 = {
								trigger = { NOT = { offmap_china = { has_offmap_name = yuan_china } } }
								set_name = "Yuan Empire"
								set_title_flag = china_name_Yuan
							}
							1 = {
								trigger = { NOT = { offmap_china = { has_offmap_name = xia_china } } }
								set_name = "Xia Empire"
								set_title_flag = china_name_Xia
							}
							1 = {
								trigger = { NOT = { offmap_china = { has_offmap_name = qing_china } } }
								set_name = "Qing Empire"
								set_title_flag = china_name_Qing
							}
							1 = {
								trigger = { NOT = { offmap_china = { has_offmap_name = dai_china } } }
								set_name = "Dai Empire"
								set_title_flag = china_name_Dai
							}
							1 = {
								trigger = { NOT = { offmap_china = { has_offmap_name = cheng_china } } }
								set_name = "Cheng Empire"
								set_title_flag = china_name_Cheng
							}
							1 = {
								trigger = { NOT = { offmap_china = { has_offmap_name = liang_china } } }
								set_name = "Liang Empire"
								set_title_flag = china_name_Liang
							}
							1 = {
								trigger = { NOT = { offmap_china = { has_offmap_name = song_china } } }
								set_name = "Song Empire"
								set_title_flag = china_name_Song
							}
							1 = {
								trigger = { NOT = { offmap_china = { has_offmap_name = ming_china } } }
								set_name = "Ming Empire"
								set_title_flag = china_name_Ming
							}
							1 = {
								trigger = { NOT = { offmap_china = { has_offmap_name = shu_china } } }
								set_name = "Shu Empire"
								set_title_flag = china_name_Shu
							}
							1 = {
								trigger = { NOT = { offmap_china = { has_offmap_name = wu_china } } }
								set_name = "Wu Empire"
								set_title_flag = china_name_Wu
							}
							1 = {
								trigger = { NOT = { offmap_china = { has_offmap_name = chu_china } } }
								set_name = "Chu Empire"
								set_title_flag = china_name_Chu
							}
							1 = {
								trigger = { NOT = { offmap_china = { has_offmap_name = yue_china } } }
								set_name = "Yue Empire"
								set_title_flag = china_name_Yue
							}
							1 = {
								trigger = { NOT = { offmap_china = { has_offmap_name = yin_china } } }
								set_name = "Yin Empire"
								set_title_flag = china_name_Yin
							}
							1 = {
								trigger = { NOT = { offmap_china = { has_offmap_name = shun_china } } }
								set_name = "Shun Empire"
								set_title_flag = china_name_Shun
							}
						}

						set_title_flag = non_manual_law_change # No prestige loss

						add_law = {
							law = succ_primogeniture
							cooldown = no
							opinion_effect = no
						}

						clr_title_flag = non_manual_law_change # No prestige loss
					}
				}
			}

			any_demesne_title = {
				limit = {
					tier = EMPEROR
					NOT = { has_title_flag = pretender_chinese_empire }
				}
				destroy_landed_title = THIS
			}

			set_government_type = chinese_imperial_government
			custom_tooltip = { text = adopt_chinese_imperialism_gov_tt }

			custom_tooltip = {
				text = adopt_chinese_imperialism_temple_name_tt

				set_character_flag = given_temple_name_by_script

				# Give a temple name
				random_list = {
					1 = { set_name = Gaozu }
					1 = { set_name = Taizu }
					1 = { set_name = Shizu }
					1 = { set_name = Zhaozu }
					1 = { set_name = Jingzu }
					1 = { set_name = Xianzu }
					1 = { set_name = Liezu }
					1 = { set_name = Chengzu }
				}
			}

			clr_character_flag = receiving_special_empire
		}
	}

	raise_chinese_honor_guard = {
		is_high_prio = yes
		is_mercenary = yes

		only_playable = yes

		potential = {
			is_landed = yes

			OR = {
				any_spouse = { has_character_flag = chinese_honor_guard } # Need to be married to Chinese prince/princess
				any_consort = { has_character_flag = chinese_honor_guard } # Need to be married to Chinese prince/princess

				any_courtier = {
					dynasty = ROOT
					is_landed = no
					vassal_of = ROOT  # No prisoners from other courts, etc.

					OR = {
						any_spouse = { has_character_flag = chinese_honor_guard }
						any_consort = { has_character_flag = chinese_honor_guard }
					}
				}
			}
		}

		allow = {
			custom_tooltip = {
				text = primary_defender_or_attacker_tt

				OR = {
					is_primary_war_defender = yes
					is_primary_war_attacker = yes
				}
			}

			custom_tooltip = {
				text = earmarked_regiments_tt

				NOT = { has_earmarked_regiments = honor_guard }
			}

			custom_tooltip = {
				text = raise_chinese_honor_guard_TT

				NOT = { has_character_modifier = jd_chinese_honor_guard_timer }
			}
		}

		effect = {
			add_character_modifier = {
				name = jd_chinese_honor_guard_timer
				years = 1 # Can't use it too often
				hidden = yes
			}

			trigger_switch = {
				on_trigger = real_tier

				EMPEROR = {
					spawn_unit = {
						owner = ROOT
						province = capital_scope
						home = capital_scope
						attrition = 1.0
						disband_on_peace = yes
						maintenance_multiplier = 0.25
						earmark = honor_guard

						troops = {
							archers = { 1000 1000 }
							heavy_infantry = { 200 200 }
							pikemen = { 800 800 }
						}
					}
				}

				KING = {
					spawn_unit = {
						owner = ROOT
						province = capital_scope
						home = capital_scope
						attrition = 1.0
						disband_on_peace = yes
						maintenance_multiplier = 0.25
						earmark = honor_guard

						troops = {
							archers = { 800 800 }
							heavy_infantry = { 100 100 }
							pikemen = { 600 600 }
						}

					}
				}

				DUKE = {
					spawn_unit = {
						owner = ROOT
						province = capital_scope
						home = capital_scope
						attrition = 1.0
						disband_on_peace = yes
						maintenance_multiplier = 0.25
						earmark = honor_guard

						troops = {
							archers = { 500 500 }
							heavy_infantry = { 100 100 }
							pikemen = { 400 400 }
						}
					}
				}

				fallback = {
					spawn_unit = {
						owner = ROOT
						province = capital_scope
						home = capital_scope
						attrition = 1.0
						disband_on_peace = yes
						maintenance_multiplier = 0.25
						earmark = honor_guard

						troops = {
							archers = { 250 250 }
							heavy_infantry = { 50 50 }
							pikemen = { 200 200 }
						}
					}
				}
			}
		}

		ai_will_do = {
			factor = 0 # decisions with "is_mercenary = yes" are not calculated from script
		}
	}

	raise_chinese_regiment = {
		is_high_prio = yes
		is_mercenary = yes

		only_playable = yes

		potential = {
			is_tributary = {
				type = offmap
			}

			is_landed = yes
		}

		allow = {
			is_primary_war_defender = yes

			custom_tooltip = {
				text = war_with_other_tributary_tt

				any_war = {
					attacker = {
						NOT = {
							is_tributary = {
								type = offmap
							}
						}
					}
				}
			}

			custom_tooltip = {
				text = already_raised_TT
				NOT = { has_earmarked_regiments = chinese_regiment }
			}

			custom_tooltip = {
				text = raise_chinese_regiment_TT
				NOT = { has_character_modifier = jd_chinese_regiment_timer }
			}

			offmap_china = {
				NOR = {
					has_status = china_unrest
					has_status = china_plague
					has_status = china_famine
					has_status = china_civil_war
					has_status = china_mongol_invasion
					has_status = china_jurchen_invasion
				}
			}
		}

		effect = {
			add_character_modifier = {
				name = jd_chinese_regiment_timer
				years = 1 # Can't use it too often
				hidden = yes
			}

			if = {
				limit = {
					trigger_if = {
						limit = { is_nomadic = yes }
						num_of_count_titles_in_realm > 16
					}
					trigger_else = {
						real_tier = EMPEROR
					}
				}

				spawn_unit = {
					province = capital_scope
					home = capital_scope
					owner = ROOT
					attrition = 1.0
					disband_on_peace = yes
					maintenance_multiplier = 0.25
					earmark = chinese_regiment

					troops = {
						light_infantry = { 1500 1500 }
						archers = { 1500 1500 }
						heavy_infantry = { 450 450 }
						pikemen = { 750 750 }
						light_cavalry = { 600 600 }
					}
				}
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = { is_nomadic = yes }
						num_of_count_titles_in_realm > 12
					}
					trigger_else = {
						real_tier = KING
					}
				}

				spawn_unit = {
					province = capital_scope
					home = capital_scope
					owner = ROOT
					attrition = 1.0
					disband_on_peace = yes
					maintenance_multiplier = 0.25
					earmark = chinese_regiment

					troops = {
						light_infantry = { 1250 1250 }
						archers = { 1250 1250 }
						heavy_infantry = { 375 375 }
						pikemen = { 625 625 }
						light_cavalry = { 500 500 }
					}
				}
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = { is_nomadic = yes }
						num_of_count_titles_in_realm > 8
					}
					trigger_else = {
						real_tier = DUKE
					}
				}

				spawn_unit = {
					province = capital_scope
					home = capital_scope
					owner = ROOT
					attrition = 1.0
					disband_on_peace = yes
					maintenance_multiplier = 0.25
					earmark = chinese_regiment

					troops = {
						light_infantry = { 1000 1000 }
						archers = { 1000 1000 }
						heavy_infantry = { 300 300 }
						pikemen = { 500 500 }
						light_cavalry = { 400 400 }
					}
				}
			}
			else = {
				spawn_unit = {
					province = capital_scope
					home = capital_scope
					owner = ROOT
					attrition = 1.0
					disband_on_peace = yes
					maintenance_multiplier = 0.25
					earmark = chinese_regiment

					troops = {
						light_infantry = { 750 750 }
						archers = { 750 750 }
						heavy_infantry = { 225 225 }
						pikemen = { 375 375 }
						light_cavalry = { 300 300 }
					}
				}
			}
		}

		ai_will_do = {
			factor = 0 # decisions with "is_mercenary = yes" are not alculated from script
		}
	}

	tributary_independence_normal = {
		ai_check_interval = 6

		is_high_prio = yes

		only_playable = yes

		potential = {
			OR = {
				is_tributary = { type = default }
				is_tributary = { type = permanent }
				is_tributary = { type = nomadic }
			}
		}

		allow = {
			war = no

			trigger_if = {
				limit = {
					is_tributary = {
						type = default
					}
				}

				suzerain = {
					independent = no
				}
			}
			trigger_else_if = {
				limit = {
					is_tributary = {
						type = permanent
					}
				}

				suzerain = {
					OR = {
						independent = no

						relative_realm_size = {
							who = ROOT
							size < 1
						}

						AND = {
							prestige < 0

							ROOT = {
								prestige >= 0
							}

							custom_tooltip = {
								text = recently_made_tributary_tt

								ROOT = {
									NOT = {
										has_opinion_modifier = {
											name = opinion_forced_tributary
											who = PREV
										}
									}
								}
							}
						}
					}
				}
			}
			trigger_else_if = {
				limit = {
					is_tributary = {
						type = nomadic
					}
				}

				suzerain = {
					OR = {
						is_nomadic = no

						AND = {
							prestige < 0

							ROOT = {
								prestige >= 0
							}

							custom_tooltip = {
								text = recently_made_tributary_tt

								ROOT = {
									NOT = {
										has_opinion_modifier = {
											name = opinion_forced_tributary
											who = PREV
										}
									}
								}
							}
						}
					}
				}
			}
		}

		effect = {
			any_suzerain = {
				show_scope_change = no

				character_event = { id = JD.2200 }
				remove_tributary = ROOT
			}
		}

		ai_will_do = {
			factor = 1

			mult_modifier = {
				factor = 0.5
				NOT = { trait = ambitious }
			}
		}
	}

	tributary_independence_china = {
		ai_check_interval = 24

		is_high_prio = yes

		only_playable = yes

		potential = {
			is_tributary = {
				type = offmap
			}
		}

		allow = {
			offmap_china = {
				OR = {
					has_status = china_civil_war
					has_status = china_mongol_invasion
					has_status = china_jurchen_invasion
				}
			}
		}

		effect = {
			any_suzerain = {
				remove_tributary = ROOT
			}

			if = {
				limit = {
					offmap_china = { offmap_has_like = likes_tributaries }
				}

				detract_grace_massive_effect = yes
			}

			else = {
				detract_grace_major_effect = yes
			}

			custom_tooltip = {
				text = tributary_independence_china_tt

				add_character_modifier = {
					name = chinese_grace_tributary_timer
					years = 30
					hidden = yes
				}
			}

			letter_event = { id = JD.60011 }
		}

		ai_will_do = {
			factor = 1

			trigger = {
				NOR = {
					trait = content
					trait = craven
				}
			}

			mult_modifier = {
				factor = 0.5
				NOT = { trait = ambitious }
			}
		}
	}

	china_sends_reinforcements = {
		ai_check_interval = 2

		only_independent = yes

		potential = {
			war = yes

			offmap_china = {
				governor = {
					character = ROOT
				}

				# Don't spawn reinforcements immediately
				had_offmap_tmp_flag = {
					flag = china_entered_war
					years >= 3
				}

				# Only spawn reinforcements once
				trigger_if = {
					limit = { has_offmap_tmp_flag = china_sent_war_reinforcements }

					# Exception: Really long wars
					had_offmap_tmp_flag = {
						flag = china_sent_war_reinforcements
						years >= 30
					}
				}

				# Don't spawn reinforcements for the following statuses in China
				NOR = {
					has_status = china_famine
					has_status = china_civil_war
					has_status = china_mongol_invasion
					has_status = china_jurchen_invasion
					has_status = china_plague
				}
			}

			# Only if China is losing a war by 50 war score
			any_war = {
				trigger_if = {
					limit = { is_primary_war_attacker = yes }
					war_score < -50
				}
				trigger_else = {
					is_primary_war_defender = yes
					war_score >= 50
				}
			}
		}

		allow = {
		}

		effect = {
			offmap_china = {
				clr_offmap_flag = china_sent_war_reinforcements
				set_offmap_flag = china_sent_war_reinforcements
			}

			### To manipulate the troop spawning for specific situations modify the parameter valiables (china_war_troop_quantity, china_war_troop_quality, china_war_target_match_mult, and china_war_minimum_commander_martial) after the following block.

			# 8 regiments of ~500 units
			set_variable = {
				which = china_war_troop_quantity
				value = 8
			}

			# Value between 1-7 [A value less than 1 or higher than 7 will be evaluated as 1 and 7 respectively]
			set_variable = {
				which = china_war_troop_quality
				value = 4
			}

			set_variable = {
				which = china_war_target_match_mult
				value = 0.75
			}

			set_variable = {
				which = china_war_minimum_commander_martial
				value = 14
			}

			###

			# Manipulate the parameter variables dependent on the current status in China
			china_war_modify_variables_by_status_effect = yes

			# Manipulate the parameter variables dependent on the current century
			china_war_modify_variables_by_century_effect = yes

			### Match mult calculation against war enemies and sending notification events to enemy war leaders
			any_war = {
				if = {
					limit = {
						defender = { character = ROOT }
					}

					attacker = {
						save_event_target_as = enemy
					}

					any_attacker = {
						save_event_target_as = temp_war_ally_calc

						ROOT = {
							# Match mult the variable against the opponents troops
							export_to_variable = {
								which = china_temp_troop_calc
								value = realm_levies
								who = event_target:temp_war_ally_calc
							}

							divide_variable = {
								which = china_temp_troop_calc
								value = 500
							}

							multiply_variable = {
								which = china_temp_troop_calc
								which = china_war_target_match_mult
							}

							change_variable = {
								which = china_war_troop_quantity
								which = china_temp_troop_calc
							}
						}
					}
				}

				else_if = {
					limit = {
						attacker = { character = ROOT }
					}

					defender = {
						save_event_target_as = enemy
					}

					any_defender = {
						save_event_target_as = temp_war_ally_calc

						ROOT = {
							# Match mult the variable against the opponents troops.
							export_to_variable = {
								which = china_temp_troop_calc
								value = realm_levies_plus_allies
								who = event_target:temp_war_ally_calc
							}

							divide_variable = {
								which = china_temp_troop_calc
								value = 500
							}

							multiply_variable = {
								which = china_temp_troop_calc
								which = china_war_target_match_mult
							}

							change_variable = {
								which = china_war_troop_quantity
								which = china_temp_troop_calc
							}
						}
					}
				}
			}

			# Hardcap at 50k troopspawn
			if = {
				limit = {
					check_variable = {
						which = china_war_troop_quantity
						value > 100
					}
				}

				set_variable = {
					which = china_war_troop_quantity
					value = 100
				}
			}

			if = {
				limit = {
					ROOT = {
						capital_scope = {
							NOT = { region = world_india }
						}
					}
				}

				c_jiuquan = {
					location = {
						save_event_target_as = spawn_province
					}
				}
			}
			else = {
				offmap_china = {
					set_offmap_flag = troop_spawn_india_temp
				}

				c_samatata = {
					location = {
						save_event_target_as = spawn_province

						sea_zone = { # Ganges Delta
							save_event_target_as = fleet_spawn_location
						}
					}
				}

				set_variable = {
					which = boat_spawns
					which = china_war_troop_quantity
				}

				multiply_variable = {
					which = boat_spawns
					value = 5
				}

				while = {
					limit = {
						check_variable = {
							which = boat_spawns
							value >= 1
						}
					}

					change_variable = {
						which = boat_spawns
						value = -1
					}

					spawn_fleet = {
						province = event_target:fleet_spawn_location # Ganges Delta
						owner = ROOT
						disband_on_peace = yes
						merge = yes

						troops = {
							galleys = { 1 1 }
						}
					}
				}
			}

			event_target:enemy = {
				character_event = { id = JD.30047 }
			}

			china_war_spawn_troops_effect = yes
			# Requires the current things to function properly:
			# event_target:spawn_province
			# variable: china_war_troop_quality
			# variable: china_war_troop_quantity
		}

		ai_will_do = {
			factor = 1
		}
	}

	write_a_book = {
		ai_check_interval = 36

		only_playable = yes

		potential = {
			has_dlc = "Jade Dragon"
			is_landed = yes
			is_lowborn = no
			age >= 10
			learning >= 1
		}

		allow = {
			learning >= 8

			scaled_wealth = {
				value = 1
				min =   50
				max = 1000
			}

			custom_tooltip = {
				text = not_currently_working_on_a_book_tt
				NOT = { has_character_flag = currently_working_on_a_book }
			}

			custom_tooltip = {
				text = has_not_explored_all_topics_tt
				NOT = { has_character_flag = has_explored_all_topics }

				OR = {
					NOT = { has_character_flag = wrote_about_dynasty }

					custom_tooltip = {
						text = has_an_education_or_related_attribute_above_ten_tt

						OR = {
							AND = {
								NOT = { has_character_flag = wrote_about_battle }

								OR = {
									martial >= 10
									has_education_martial_trigger = yes
								}
							}

							AND = {
								NOT = { has_character_flag = wrote_about_administration }

								OR = {
									stewardship >= 10
									has_education_stewardship_trigger = yes
								}
							}

							AND = {
								NOT = { has_character_flag = wrote_about_religion }

								OR = {
									learning >= 10
									is_monastic_member_trigger = yes
									has_education_learning_trigger = yes
								}
							}

							AND = {
								NOT = { has_character_flag = wrote_about_relationships }

								OR = {
									diplomacy >= 10
									intrigue >= 10
									has_education_diplomacy_trigger = yes
									has_education_intrigue_trigger = yes
								}
							}
						}
					}
				}
			}

			NOT = { has_character_modifier = uninspired }
		}

		effect = {
			custom_tooltip = {
				text = choose_a_topic_tt

				set_character_flag = currently_working_on_a_book
				character_event = { id = JD.10060 }
			}

			scaled_wealth = {
				value = -1
				min =   -50
				max = -1000
			}
		}


		ai_will_do = {
			factor = 0.1

			trigger = {
				NOT = {
					any_artifact = {
						has_artifact_flag = book
					}
				}
			}

			mult_modifier = {
				factor = 0.1
				is_republic = no
				is_theocracy = no
			}

			mult_modifier = {
				factor = 0.1
				trait = slothful
			}

			mult_modifier = {
				factor = 0.1
				war = yes
			}

			mult_modifier = {
				factor = 0.1
				is_inaccessible_trigger = yes
			}

			mult_modifier = {
				factor = 0.1
				is_learned_trigger = no
			}

			mult_modifier = {
				factor = 0.1
				has_top_tier_education_trait_trigger = no
			}

			mult_modifier = {
				factor = 0.1
				has_bottom_tier_education_trait_trigger = yes
			}
		}
	}

	bon_tolerate_indians = {
		ai_check_interval = 36

		ai = no

		potential = {
			always = no # Disabled in CK2Plus
			religion = bon_pagan # Only unreformed. Reformers can pick the Syncretism Doctrine to sympathize with everyone they wish.

			NOR = {
				trait = sympathy_indian

				has_alternate_start_parameter = {
					key = religion_names
					value = random
				}
			}
		}

		allow = {
			NOT = { trait = zealous }

			custom_tooltip = {
				text = bon_sympathy_eastern

				OR = {
					any_vassal = {
						religion_group = indian_group
					}

					any_liege = {
						religion_group = indian_group
					}

					any_realm_province = {
						religion_group = indian_group
						held_under_PREV = yes
					}
				}
			}

			piety >= 50
		}

		effect = {
			add_trait = sympathy_indian
			piety = -50
		}

		ai_will_do = {
			factor = 1
		}
	}
}

targeted_decisions = {
	negotiate_with_adventurer = {
		# filter = independent_rulers # CleanSlate: Nonfunctional

		is_high_prio = yes

		ai = no

		from_potential = {
			independent = yes
		}

		potential = {
			has_character_flag = raiding_adventurer

			OR = {
				location = {
					owner = {
						top_liege = {
							character = FROM
						}
					}
				}

				any_unit = {
					location = {
						owner = {
							top_liege = {
								character = FROM
							}
						}
					}
				}
			}
		}

		allow = {
			FROM = {
				show_scope_change = no

				higher_real_tier_than = DUKE
			}

			custom_tooltip = {
				text = not_negotiated_recently_tt

				FROM = {
					NOT = { has_character_modifier = adventurer_negotiate_cd }
				}
			}

			custom_tooltip = {
				text = has_valid_province_tt

				FROM = {
					OR = {
						any_demesne_province = {
							is_capital = no
							num_of_settlements >= 1
							owned_by = PREV

							trigger_if = {
								limit = { ROOT = { is_seafarer = yes } }
								is_coastal = yes
							}
							trigger_else = {
								is_coastal = no
							}

							NOT = { has_province_modifier = nomad_agitation }
						}

						any_vassal = {
							any_demesne_province = {
								is_capital = no
								num_of_settlements >= 1
								NOT = { has_province_modifier = nomad_agitation }
								owned_by = PREV

								trigger_if = {
									limit = { ROOT = { is_seafarer = yes } }
									is_coastal = yes
								}
								trigger_else = {
									is_coastal = no
								}
							}
						}
					}
				}
			}
		}

		effect = {
			custom_tooltip = {
				text = dangerous_negotiations_tt

				save_event_target_as = adventurer_decision_target_override

				FROM = {
					save_event_target_as = adventurer_decision_taker_override
					set_character_flag = negotiating_with_adventurer
					set_character_flag = peaceful_negotiation

					character_event = { id = adv.001 } # Start negatiation

					add_character_modifier = {
						name = adventurer_negotiate_cd
						years = 1
						hidden = yes
					}
				}
			}
		}

		ai_will_do = {
			factor = 0
		}
	}
}