###JD Decisions###

#Written by:
#Drikus Kuiper
#Matthew Clohessy


decisions = {

	adopt_chinese_imperialism = {
		only_independent = yes
		is_high_prio = yes
		ai_check_interval = 60
		potential = {
			OR = {
				culture_group = chinese_group
				culture = khitan
				culture = tangut
				culture = jurchen
			}
			is_nomadic = no
			is_feudal = yes
			NOT = { government = chinese_imperial_government }
			has_dlc = "Jade Dragon"
			holy_order = no
			OR = {
				ai = no
				AND = {
					trait = proud
					prestige = 40000
				}
				AND = {
					trait = ambitious
					prestige = 40000
				}
				prestige = 120000
			}
		}
		allow = {
			independent = yes
			is_adult = yes
			prisoner = no
			NOT = { trait = incapable }
			is_tributary = no
			tier = EMPEROR
			realm_size = 200
			conditional_tooltip = {
				trigger = { religion = taoist }
				prestige = 8000
				wealth = 500
			}
			conditional_tooltip = {
				trigger = { NOT = { religion = taoist } }
				prestige = 16000
				wealth = 1000
			}

			offmap_china = {
				show_scope_change = no
				offmap_ruler = { NOT = { dynasty = ROOT } }
			}
		}
		effect = {
			if = {
			    limit = { religion = taoist }
			    wealth = -500
			}
			else = {
			    wealth = -1000
			}
			if = {
				limit = {
					has_dlc = "Holy Fury"
					NOT = {
						any_owned_bloodline = { 
							has_bloodline_flag = created_bloodline
						}
					}
				}
				character_event = { id = HF.24240 tooltip = tooltip_evt_hf_24240 }
			}
			custom_tooltip = {
				text = adopt_chinese_imperialism_tt
				hidden_effect = {
					create_title = {
						tier = EMPEROR
						landless = no
						temporary = no
						custom_created = yes
						culture = ROOT
						holder = ROOT
						base_title = THIS
						short_name = yes
						copy_title_laws = yes
					}
					new_title = {
						set_title_flag = uses_temple_names_by_script #Titles with this flag give their heirs a temple name via on_death event
						set_title_flag = pretender_chinese_empire #Blocks all grace interactions
						adjective = e_china_west_governor_adj #Use WP adj as it is "Chinese" but also gives the right one in different languages
						random_list = { #Random Empire name that China doesn't have
							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
							}
						}
						add_law = {
							law = succ_primogeniture
							cooldown = no
							opinion_effect = no
						}
					}
				}
			}
			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
				hidden_effect = {
					random_list = { #Give a temple name
						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 }
					}
					set_character_flag = given_temple_name_by_script
				}
			}
		}
	}

	raise_chinese_honor_guard = {
		only_playable = yes
		is_high_prio = yes
		is_mercenary = 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 = {
					is_landed = no
					liege = { character = ROOT }
					dynasty = ROOT
					OR = {
						any_spouse = { has_character_flag = chinese_honor_guard }
						any_consort = { has_character_flag = chinese_honor_guard }
					}
				}
			}
			OR = {
				ai = no
				any_war = {
					OR = {
						any_defender = {
							character = ROOT
							is_primary_war_defender = yes
						}
						any_attacker = {
							character = ROOT
							is_primary_war_attacker = yes
						}
					}
				}
			}
		}
		allow = {
			custom_tooltip = {
				text = primary_defender_or_attacker_tt
				hidden_tooltip = {
					any_war = {
						OR = {
							any_defender = {
								character = ROOT
								is_primary_war_defender = yes
							}
							any_attacker = {
								character = ROOT
								is_primary_war_attacker = yes
							}
						}
					}
				}
			}
			custom_tooltip = {
				text = earmarked_regiments_tt
				hidden_tooltip = {
					NOT = {
						has_earmarked_regiments = honor_guard
					}
				}
			}
			custom_tooltip = {
				text = raise_chinese_honor_guard_TT
				NOT = { has_character_modifier = jd_chinese_honor_guard_timer }
			}
		}
		effect = {
			hidden_effect = {
				add_character_modifier = { #Can't use it too often
					name = jd_chinese_honor_guard_timer
					hidden = yes
					years = 1
				}
			}
			if = {
				limit = {
					tier = emperor
				}
				capital_scope = {
					PREV = {
						spawn_unit = {
							owner = ROOT
							province = PREV
							home = PREV
							troops = {
								archers = { 1000 1000 }
								heavy_infantry = { 200 200 }
								pikemen = { 800 800 }
							}
							attrition = 1.0
							disband_on_peace = yes
							maintenance_multiplier = 0.25
							earmark = honor_guard
						}
					}
				}
				break = yes
			}
			if = {
				limit = {
					tier = king
				}
				capital_scope = {
					PREV = {
						spawn_unit = {
							owner = ROOT
							province = PREV
							home = PREV
							troops = {
								archers = { 800 800 }
								heavy_infantry = { 100 100 }
								pikemen = { 600 600 }
							}
							attrition = 1.0
							disband_on_peace = yes
							maintenance_multiplier = 0.25
							earmark = honor_guard
						}
					}
				}
				break = yes
			}
			if = {
				limit = {
					tier = duke
				}
				capital_scope = {
					PREV = {
						spawn_unit = {
							owner = ROOT
							province = PREV
							home = PREV
							troops = {
								archers = { 500 500 }
								heavy_infantry = { 100 100 }
								pikemen = { 400 400 }
							}
							attrition = 1.0
							disband_on_peace = yes
							maintenance_multiplier = 0.25
							earmark = honor_guard
						}
					}
				}
				break = yes
			}
			capital_scope = {
				PREV = {
					spawn_unit = {
						owner = ROOT
						province = PREV
						home = PREV
						troops = {
							archers = { 250 250 }
							heavy_infantry = { 50 50 }
							pikemen = { 200 200 }
						}
						attrition = 1.0
						disband_on_peace = yes
						maintenance_multiplier = 0.25
							earmark = honor_guard
					}
				}
			}

		}
		ai_will_do = {
			factor = 0 # decisions with the "is_mercenary" will not be calculated from the script
		}
	}
	
	raise_chinese_regiment = {
		only_playable = yes
		is_high_prio = yes
		is_mercenary = yes

		potential = {
			is_playable = yes
			is_landed = yes
			is_tributary = {
				type = offmap
			}
		}
		allow = {
			war = yes
			custom_tooltip = {
				text = primary_defender_TT
				hidden_tooltip = {
					any_war = {
						any_defender = {
							character = ROOT
							is_primary_war_defender = yes
						}
					}
				}
			}
			custom_tooltip = {
				text = war_with_other_tributary_tt
				hidden_tooltip = {
					any_war = {
						any_attacker = {
							is_primary_war_attacker = yes
							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 = {
			hidden_effect = {
				add_character_modifier = { #Can't use it too often
					name = jd_chinese_regiment_timer
					hidden = yes
					duration = 365
				}
			}
			capital_scope = {
				PREV = {
					if = {
						limit = {
							ROOT = {
								OR = {
									AND = {
										tier = EMPEROR
										is_nomadic = no
									}
									AND = {
										is_nomadic = yes
										num_of_count_titles_in_realm > 16
									}
								}
							}
						}
						spawn_unit = {
							province = PREV
							home = PREV
							owner = ROOT
							troops = {
								light_infantry = { 1500 1500 }
								archers = { 1500 1500 }
								heavy_infantry = { 450 450 }
								pikemen = { 750 750 }
								light_cavalry = { 600 600 }
							}
							attrition = 1.0
							disband_on_peace = yes
							maintenance_multiplier = 0.25
							earmark = chinese_regiment
						}
					}
					else_if = {
						limit = {
							ROOT = {
								OR = {
									tier = KING
									AND = {
										is_nomadic = yes
										num_of_count_titles_in_realm > 12
									}
								}
							}
						}
						spawn_unit = {
							province = PREV
							home = PREV
							owner = ROOT
							troops = {
								light_infantry = { 1250 1250 }
								archers = { 1250 1250 }
								heavy_infantry = { 375 375 }
								pikemen = { 625 625 }
								light_cavalry = { 500 500 }
							}
							attrition = 1.0
							disband_on_peace = yes
							maintenance_multiplier = 0.25
							earmark = chinese_regiment
						}
					}
					else_if = {
						limit = {
							ROOT = {
								OR = {
									tier = DUKE
									AND = {
										is_nomadic = yes
										AND = {
											is_nomadic = yes
											num_of_count_titles_in_realm > 8
										}
									}
								}
							}
						}
						spawn_unit = {
							province = PREV
							home = PREV
							owner = ROOT
							troops = {
								light_infantry = { 1000 1000 }
								archers = { 1000 1000 }
								heavy_infantry = { 300 300 }
								pikemen = { 500 500 }
								light_cavalry = { 400 400 }
							}
							attrition = 1.0
							disband_on_peace = yes
							maintenance_multiplier = 0.25
							earmark = chinese_regiment
						}
					}
					else = {
						spawn_unit = {
							province = PREV
							home = PREV
							owner = ROOT
							troops = {
								light_infantry = { 750 750 }
								archers = { 750 750 }
								heavy_infantry = { 225 225 }
								pikemen = { 375 375 }
								light_cavalry = { 300 300 }
							}
							attrition = 1.0
							disband_on_peace = yes
							maintenance_multiplier = 0.25
							earmark = chinese_regiment
						}
					}
				}
			}

		}
		ai_will_do = {
			factor = 0 # decisions with the "is_mercenary" will not be calculated from the script
		}
	}
	
	tributary_independence_normal = {
		only_playable = yes
		is_high_prio = yes
		ai_check_interval = 6

		potential = {
			OR = {
				is_tributary = {
					type = default
				}
				is_tributary = {
					type = permanent
				}
				is_tributary = {
					type = nomadic
				}
			}
		}
		allow = {
			war = no
			conditional_tooltip = {
				trigger = { 
					is_tributary = {
						type = default
					}
				}
				suzerain = {
					independent = no
				}
			}
			conditional_tooltip = {
				trigger = { 
					is_tributary = {
						type = permanent
					}
				}
				suzerain = {
					OR = {
						AND = {
							NOT = {
								prestige = 0
							}
							ROOT = {
								prestige = 0
							}
							custom_tooltip = {
								text = recently_made_tributary_tt
								hidden_tooltip = {
									ROOT = {
										NOT = {
											has_opinion_modifier = {
												modifier = opinion_forced_tributary
												who = PREV
											}
										}
									}
								}
							}
						}
						relative_realm_size = {
							who = ROOT 
							size < 1
						}
						independent = no
					}
				}
			}
			conditional_tooltip = {
				trigger = { 
					is_tributary = {
						type = nomadic
					}
				}
				suzerain = {
					OR = {
						AND = {
							NOT = {
								prestige = 0
							}
							ROOT = {
								prestige = 0
							}
							custom_tooltip = {
								text = recently_made_tributary_tt
								hidden_tooltip = {
									suzerain = {
										ROOT = {
											NOT = {
												has_opinion_modifier = {
													modifier = opinion_forced_tributary
													who = PREV
												}
											}
										}
									}
								}
							}
						}
						is_nomadic = no
					}
				}
			}
		}
		effect = {
			any_suzerain = {
				character_event = { id = JD.2200 }
				remove_tributary = ROOT
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0.5 # Slow down
				NOT = {
					trait = ambitious
				}
			}
		}
	}
	
	tributary_independence_china = {
		only_playable = yes
		is_high_prio = yes
		ai_check_interval = 24

		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 = {
					hidden = yes
					name = chinese_grace_tributary_timer
					years = 30
				}
			}
			hidden_effect = { offmap_china = { governor = { character_event = { id = JD.60010 } } } }
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0.5 # Slow down
				NOT = {
					trait = ambitious
				}
			}
			modifier = {
				factor = 0
				OR = {
					trait = content
					trait = craven
				}
			}
		}
	}

	china_sends_reinforcements = {
		ai_check_interval = 2
		only_independent = yes

		potential = {
			ai = yes
			war = yes
			offmap_china = {
				governor = {
					character = ROOT
				}
				# Don't spawn reinforcements immediately
				had_offmap_tmp_flag = {
					flag = china_entered_war
					years = 3
				}
				OR = {
					NOT = {
						# Only spawn reinforcements once
						has_offmap_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 = {
				OR = {
					AND = {
						attacker = {
							character = ROOT
						}
						NOT = { war_score = -49 }
					}
					AND = {
						defender = {
							character = ROOT
						}
						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.
			set_variable = {
				which = china_war_troop_quantity
				value = 8
				# 8 regiments of ~500 units
			}
			set_variable = {
				which = china_war_troop_quality
				value = 4
				# 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_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 = {
				attacker = {
					if = {
						limit = {
							NOT = { character = ROOT }
							PREV = {
								defender = {
									character = ROOT
								}
							}
						}
						save_event_target_as = enemy
						PREV = {
							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
									}
								}
							}
						}
					}
				}
				defender = {
					if = {
						limit = {
							NOT = { character = ROOT }
							PREV = {
								attacker = {
									character = ROOT
								}
							}
						}
						save_event_target_as = enemy
						PREV = {
							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_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 = {
					FROM = {
						capital_scope = {
							NOT = { region = world_india }
						}
					}
				}
				1513 = { # Jiuquan
					save_event_target_as = spawn_province
				}
			}
			else = {
				offmap_china = { set_offmap_flag = troop_spawn_india_temp }
				1318 = { # Samatata
					save_event_target_as = spawn_province
				}
				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 = 1411 # ganges delta
						owner = ROOT
						disband_on_peace = yes
						troops =
						{
							galleys = { 1 1 }
						}
						merge = yes
					}
				}
			}
			
			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
		}
		revoke_allowed = {
			always = no
		}
		ai_will_do = {
			factor = 1
		}
	}

	write_a_book = {
		only_playable = yes
		ai_check_interval = 36

		potential = {
			age = 10
			learning = 1
			has_dlc = "Jade Dragon"
			is_landed = yes
			is_lowborn = no
		}
		allow = {
			learning = 8
			scaled_wealth = {
			    value = 1
			    min = 50
			    max = 1002
			}
			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
			}
			scaled_wealth = {
			    value = -1
			    min = -50
			    max = -1002
			}

			set_character_flag = currently_working_on_a_book
			character_event = { id = JD.10060 }
		}
		
		revoke_allowed = {
			always = no
		}

		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0.1 #Slow down
			}
			modifier = {
				factor = 0.1
				NOR = {
					government = theocracy_government
					government = republic_government
				}
			}
			modifier = {
				factor = 0
				any_artifact = {
					has_artifact_flag = book
				}
			}
			modifier = {
				factor = 0.1
				trait = slothful
			}
			modifier = {
				factor = 0.1
				war = yes
			}
			modifier = {
				factor = 0.1
				is_inaccessible_trigger = yes
			}
			modifier = {
				factor = 0.1
				is_learned_trigger = no
			}
			modifier = {
				factor = 0.1
				has_top_tier_education_trait_trigger = no
			}
			modifier = {
				factor = 0.1
				has_bottom_tier_education_trait_trigger = yes
			}
		}
	}
	
	bon_tolerate_indians = {
		only_playable = yes
		ai_check_interval = 36

		potential = {
			OR = {
			religion = bon # Only unreformed. Reformers can pick the Syncretism Doctrine to sympathize with everyone they wish.
			religion = nestorian
			}
			NOT = {
				trait = sympathy_indian
			}
			NOT = {
				has_alternate_start_parameter = { key = religion_names value = random }
			}
		}
		allow = {
			NOT = {
				trait = zealous
			}
			custom_tooltip = {
				text = bon_sympathy_eastern
				hidden_tooltip = {
					OR = {
						any_vassal = {
							religion_group = indian_group
						}
						any_liege = {
							religion_group = indian_group
						}
						any_realm_province = {
							religion_group = indian_group
						}
					}
				}
			}
			piety = 50
		}
		effect = {
			add_trait = sympathy_indian
			piety = -50
		}
		ai_will_do = {
			factor = 1
		}
	}
}

targeted_decisions = {
	negotiate_with_adventurer = {
		only_playable = yes
		
		filter = independent_rulers
		ai_target_filter = independent_rulers
		
		is_high_prio = yes

		ai_check_interval = 24

		from_potential = {
			independent = yes
		}

		potential = {
			has_character_flag = raiding_adventurer
			OR = {
				location = {
					county = {
						holder_scope = {
							top_liege = {
								character = FROM
							}
						}
					}
				}
				any_unit = {
					location = {
						county = {
							holder_scope = {
								top_liege = {
									character = FROM
								}
							}
						}
					}
				}
			}
		}

		allow = {
			FROM = {
				show_scope_change = no
				higher_tier_than = DUKE
			}
			custom_tooltip = {
				text = not_negotiated_recently_tt
				hidden_tooltip = {
					FROM = {
						NOT = {
							has_character_modifier = adventurer_negotiate_cd
						}
					}
				}
			}
			custom_tooltip = {
				text = has_valid_province_tt
				hidden_tooltip = {
					FROM = {
						OR = {
							any_demesne_province = {
								is_capital = no 
								num_of_settlements = 1
								NOT = {
									has_province_modifier = nomad_agitation
								}
								OR = {
									AND = {
										ROOT = { is_seafarer = yes }
										port = yes
									}
									ROOT = { is_seafarer = no }
									NOT = { any_demesne_province = { port = yes } }
								}
							}
							any_vassal = {
								any_demesne_province = {
									is_capital = no 
									num_of_settlements = 1
									NOT = {
										has_province_modifier = nomad_agitation
									}
									OR = {
										AND = {
											ROOT = { is_seafarer = yes }
											port = yes
										}
										ROOT = { is_seafarer = no }
										NOT = { any_demesne_province = { port = yes } }
									}
								}
							}
						}
					}
				}
			}
		}

		effect = {
			FROM = {
				save_event_target_as = adventurer_decision_taker_override
				set_character_flag = negotiating_with_adventurer
				set_character_flag = peaceful_negotiation
				hidden_effect = {
					add_character_modifier = {
						name = adventurer_negotiate_cd
						hidden = yes
						years = 1
					}
				}
			}
			save_event_target_as = adventurer_decision_target_override
			FROM = {
				character_event = { id = ADV.1 }
			}
			custom_tooltip = {
				text = dangerous_negotiations_tt
			}
		}

		revoke_allowed = { always = no }

		ai_will_do = {
			factor = 0
		}
	}
}