# Triggers and effects will be given the Actor's scope, with the Recipient's as FROM
# Icons are used from the messageicons.dds
static_actions = { # static_actions is a reserved token.
	# alert_index maps to the frame of the alert icon
	royal_marriage = 										{ alert_index = 1 alert_tooltip = ICON_RM }
	requestpeace = 										{ alert_index = 2 alert_tooltip = ICON_PEACE  } # alert_index will be overwritten in code for this one.
	allianceaction = 										{ alert_index = 3 alert_tooltip = ICON_ALLIANCE }
	# 4 is currently unused.
	integrationaction = 									{ alert_index = 5 alert_tooltip = ICON_ANNEX }
	annexationaction =									{ alert_index = 5 alert_tooltip = ICON_ANNEX }
	vassalaction = 										{ alert_index = 6 alert_tooltip = ICON_VASSAL }
	milaccess = 											{ alert_index = 7 alert_tooltip = ICON_ASKMIL }
	fleet_access = 										{ alert_index = 8 alert_tooltip = ICON_ASKFLEET }
	offermilaccess = 										{ alert_index = 9 alert_tooltip = ICON_OFFACC }
	callaction = 											{ alert_index = 10 alert_tooltip = ICON_CALLALLY } # This one is referred to in the code (settings.cpp)
	offerloan = 												{ alert_index = 11 alert_tooltip = ICON_OFFERLOAN }
	sellprov = 												{ alert_index = 12 alert_tooltip = ICON_PROVSALE }
		#13 is cursed
	request_to_join_federation = 						{ alert_index = 14 alert_tooltip = ICON_FEDERATIONREQUEST }
	invite_to_federation = 								{ alert_index = 15 alert_tooltip = ICON_FEDERATIONINVITE }
	transfer_trade_power = 							{ alert_index = 16 alert_tooltip = TRANSFER_TRADE_POWER }
	religious_unity_action = 							{ alert_index = 17 alert_tooltip = ICON_RELIGIOUS_UNITY }
		# 18 is used by requestpeace
	form_coalition = 										{ alert_index = 19 alert_tooltip = ICON_FORM_COALITION }
	enforce_peace = 										{ alert_index = 20 alert_tooltip = ICON_ENFORCE_PEACE } # This one may be overwritten in code.
	grant_electorate = 									{ alert_index = 21 alert_tooltip = ICON_GRANT_ELECTORATE }
	demand_unlawful_territory_action = 			{ alert_index = 22 alert_tooltip = ICON_DEMAND_UNLAWFUL_TERRITORY }
		# 23 is used by requestpeace
		# 24 is used by requestpeace
		# 25 is used by requestpeace
		# 26 is used by requestpeace
		# 27 is used by enforce_peace (when actor is coalition leader) with tooltip "ICON_ENFORCE_PEACE_COALITION_LEADER"
	support_independence_action = 					{ alert_index = 28 alert_tooltip = support_independence }
	steer_trade = 										{ alert_index = 29 alert_tooltip = ICON_STEER_TRADE }
	ask_for_march = 										{ alert_index = 30 alert_tooltip = ICON_MARCH }
	sell_ships_action = 									{ alert_index = 31 alert_tooltip = ICON_FLEETSALE }
	grant_freecity = 										{ alert_index = 32 alert_tooltip = ICON_GRANT_FREECITY }
	# 33 is currently unused
	invite_to_trade_league = 							{ alert_index = 34 alert_tooltip = ICON_TRADELEAGUEINVITE }
	request_to_join_trade_league = 					{ alert_index = 35 alert_tooltip = ICON_TRADELEAGUEREQUEST }
	sharemap = 											{ alert_index = 36 alert_tooltip = ICON_REQUESTSHAREMAP } # alert_tooltip gets special treatment in the code
	condottieri_action = 								{ alert_index = 37 alert_tooltip = ICON_CONDOTTIERI }
	offer_fleet_access = 								{ alert_index = 38 alert_tooltip = ICON_OFFERFLEET }
	break_alliance = 										{ alert_index = 39 alert_tooltip = ICON_BREAK_ALLIANCE }
	tributary_state_action = 							{ alert_index = 40 alert_tooltip = ICON_TRIBUTARY }
	ask_for_tributary_state_action = 				{ alert_index = 41 alert_tooltip = ICON_ASK_TRIBUTARY }
	knowledge_sharing = 								{ alert_index = 42 alert_tooltip = ICON_KNOWLEDGESHARE } #The answer to life
	# 43 is currently unused
	charter_company = 								{ alert_index = 44 alert_tooltip = ICON_CHARTERCOMPANY }
	reduce_relations_favor = { alert_index = 45 alert_tooltip = ICON_TRADEFAVORSFORREDUCERELATIONS }
	return_core_favor = { alert_index = 46 alert_tooltip = ICON_TRADEFAVORSFORRETURNCORE }
	break_alliance_favor = { alert_index = 47 alert_tooltip = ICON_TRADEFAVORSFORBREAKALLIANCE }
	trade_favors_for_trust = { alert_index = 48 alert_tooltip = ICON_TRADEFAVORSFORTRUST }
	trade_favors_for_men = { alert_index = 49 alert_tooltip = ICON_TRADEFAVORSFORMEN }
	trade_favors_for_sailors = { alert_index = 50 alert_tooltip = ICON_TRADEFAVORSFORSAILORS }
	trade_favors_for_heir = { alert_index = 51 alert_tooltip = ICON_TRADEFAVORSFORHEIR }
	trade_favors_for_war_prep = { alert_index = 52 alert_tooltip = ICON_TRADEFAVORSFORWARPREP }
	trade_favors_for_gold = { alert_index = 53 alert_tooltip = ICON_TRADEFAVORSFORGOLD }
}

# Create new diplomatic actions like this. AI will currently never send them.
joinwar = {
	category = alliance
	
	alert_index = 40

	require_acceptance = yes
	
	is_visible = {
		always = yes
	}
	
	is_allowed = {
		any_country = {
			AND = {
				OR = {
					is_in_war = {
						defender_leader = FROM
					}
					is_in_war = {
						attacker_leader = FROM
					}
				}
				NOT = {
					has_opinion = {
						who = ROOT
						value = -25
					}
				}
				NOT = {
					truce_with = ROOT
				}
			}
		}
		FROM = {
			has_opinion = {
				who = ROOT
				value = 150
			}
			is_neighbor_of = ROOT
		}
		ROOT = {
			is_at_war = no
		}
	}
	on_accept = {
		join_all_offensive_wars_of = FROM
		join_all_defensive_wars_of = FROM
	}
	ai_acceptance = {
		add_entry = {
			name = OPINION
			export_to_variable = {
				variable_name = ai_value
				value = opinion
				who = FROM
				with = ROOT
			}
			multiply_variable = {
				which = ai_value 
				value = 0.2
			}
		}
		add_entry = {
			name = AI_DIPLOMATIC_REPUTATION
			export_to_variable = {
				variable_name = ai_value
				value = trigger_value:diplomatic_reputation
			}
			#1 rep = 4
			multiply_variable = {
				which = ai_value
				value = 4
			}
		}
		add_entry = {
			name = attitude_friendly_DIPLO_ATTITUDE_TT
			limit = { FROM = { ai_attitude = { who = ROOT attitude = attitude_friendly } } }
			export_to_variable = { variable_name = ai_value value = 1 }
			multiply_variable = { which = ai_value value = 50 }
		}
	}
	ai_will_do = { # this is a trigger
		NOT = {
			is_at_war = yes
		}
	}
}
#demand_dummy = {
#	category = influence
#
#	alert_index = 40
#	alert_tooltip = demand_dummy_alert_tooltip
#
#	require_acceptance = yes # Whether the recipient gets an option to decline
#
#	is_visible = {
#		always = no ############################ Remove this line to unleash the magic ########################################
#		religion_group = christian
#		is_subject = no
#		FROM = {
#			is_subject = no
#		}
#	}
#	is_allowed = {
#		variable_arithmetic_trigger = {
#			custom_tooltip = HAS_OLDER_RULER_THAN_THEIR_HEIR
#			export_to_variable = { # All export to variable will happen first. Then the other effects and triggers will be executed/evaluated in order
#				variable_name = my_age
#				value = trigger_value:ruler_age
#			}
#			export_to_variable = {
#				variable_name = their_age
#				value = trigger_value:heir_age
#				who = FROM
#			}
#			ruler_age = 0 # This is a normal trigger.
#			FROM = {
#				heir_age = 0 # This is a normal trigger too.
#			}
#			check_variable = { # This trigger is only allowed inside a variable_arithmetic_trigger.
#				which = my_age
#				which = their_age
#			}
#		}
#		religion = catholic
#	}
#	on_accept = {
#		add_trust = {
#			who = FROM
#			value = 20
#			mutual = yes
#		}
#		create_subject = {
#			subject_type = dummy
#			subject = FROM
#		}
#	}
#	on_decline =
#	{
#		add_trust = {
#			who = FROM
#			value = -100
#			mutual = no
#		}
#	}
#
#	ai_acceptance = { # This works similarly to variable_arithmetic_trigger, but does not support triggers generally. Instead, "limit" will be evaluated first and the rest ignored if it isn't passed.
#		add_entry = {
#			name = TRUST
#			limit = { religion = catholic }
#			export_to_variable = {
#				variable_name = ai_value # Each "add_entry" must create one variable called "ai_value", the value of which will be extracted after executing all effects
#				value = trust
#				who = FROM
#				with = THIS
#			}
#			subtract_variable = { which = ai_value value = 50 }
#			multiply_variable = { which = ai_value value = 2 }
#		}
#		add_entry = {
#			name = TRUST
#			limit = { NOT = { religion = catholic } }
#			export_to_variable = {
#				variable_name = ai_value
#				value = trust
#				who = FROM
#				with = THIS
#			}
#			export_to_variable = {
#				variable_name = is_defender
#				value = trigger_value:is_defender_of_faith # This sets is_defender to either 0.0 or 1.0
#			}
#			multiply_variable = {
#				which = is_defender
#				value = 10
#			}
#			change_variable = {
#				which = ai_value
#				which = is_defender # This adds 10 to ai_value if you are defender of faith
#			}
#			subtract_variable = { which = ai_value value = 50 }
#		}
#		add_entry = {
#			name = OPINION
#			export_to_variable = {
#				variable_name = ai_value
#				value = opinion
#				who = FROM
#				with = THIS
#			}
#			divide_variable = { which = ai_value value = 4 }
#		}
#	}
#
#	ai_will_do = { # this is a trigger
#		has_opinion_modifier = {
#			modifier = insulted
#			who = FROM
#		}
#	}
#}
#
#cancel_dummy =  {
#	category = influence
#	require_acceptance = no
#	is_visible = {
#		overlord_of = FROM
#		FROM = {
#			is_subject_of_type = dummy
#		}
#	}
#	is_allowed = {
#		reverse_has_opinion_modifier = {
#			modifier = insulted
#			who = FROM
#		}
#	}
#	on_accept = {
#		add_trust = {
#			who = FROM
#			value = -100
#			mutual = yes
#		}
#		FROM = {
#			grant_independence = yes
#		}
#	}
#	ai_will_do = {
#		always = no
#	}
#}

# Sell indulgence
sell_indulgence = {
	category = economy

	alert_index = 17
	alert_tooltip = sell_indulgence_alert_tooltip

	require_acceptance = yes # Whether the recipient gets an option to decline

	is_visible = {
		has_government_attribute = can_sell_indulgences
		religion = catholic
	}
	is_allowed = {
		if = {
			limit = { FROM = { NOT = { religion = catholic } } }
			custom_trigger_tooltip = {
				tooltip = sell_indulgence_catholic
				FROM = { religion = catholic }
			}
		}
		if = {
			limit = { FROM = { tag = PAP } }
			custom_trigger_tooltip = {
				tooltip = sell_indulgence_pope
				FROM = { NOT = { tag = PAP } }
			}
		}
		if = {
			limit = { FROM = { is_subject_other_than_tributary_trigger = yes } }
			custom_trigger_tooltip = {
				tooltip = sell_indulgence_subject
				FROM = { is_free_or_tributary_trigger = yes }
			}
		}
		if = {
			limit = { NOT = { papal_influence = 50 } NOT = { tag = PAP } }
			custom_trigger_tooltip = {
				tooltip = sell_indulgence_pi
				papal_influence = 50
			}
		}
		if = {
			limit = { war_with = FROM }
			custom_trigger_tooltip = {
				tooltip = sell_indulgence_war
				NOT = { war_with = FROM }
			}
		}
	}
	on_accept = {
		if = {
			limit = { NOT = { tag = PAP } }
			add_papal_influence = -50
		}
		else = {
			add_corruption = 0.5
		}
		add_reform_desire = 0.0025
		FROM = {
			add_stability = 1
			add_prestige = 10
			country_event = {
				id = flavor_rig.5
			}
		}
		change_variable = {
			which = sold_indulgences
			value = 1
		}
	}
	on_decline = {
	}

	ai_acceptance = { # This works similarly to variable_arithmetic_trigger, but does not support triggers generally. Instead, "limit" will be evaluated first and the rest ignored if it isn't passed.
		add_entry = {
			name = TRUST
			export_to_variable = {
				variable_name = ai_value
				value = trust
				who = FROM
				with = ROOT
			}			
			subtract_variable = { 
				which = ai_value
				value = 50
			}
			#1 trust = +4 ai points
			multiply_variable = {
				which = ai_value
				value = 0.4
			}
		}
		add_entry = {
			name = OPINION
			export_to_variable = {
				variable_name = ai_value
				value = opinion
				who = FROM
				with = ROOT
			}
			multiply_variable = {
				which = ai_value 
				value = 0.2
			}
		}
		add_entry = {
			name = DIPLO_IS_RIVAL
			limit = {
				FROM = {
					ai_attitude = {
						who = ROOT
						attitude = attitude_rivalry
					}
				}
			}
			export_to_variable = {
				variable_name = ai_value
				value = 1
			}
			
			multiply_variable = {
				which = ai_value
				value = -1000
			}
		}
		add_entry = {
			name = diplomatic_reputation
			limit = { }
			export_to_variable = {
				variable_name = ai_value
				value = trigger_value:diplomatic_reputation
			}
			#1 rep = 2
			multiply_variable = {
				which = ai_value
				value = 2
			}
		}
		add_entry = {
			name = STABILITY_AI_MODIFIER
			export_to_variable = {
				variable_name = ai_value
				value = stability
				who = FROM
				with = ROOT
			}
			multiply_variable = {
				which = ai_value 
				value = -25
			}
		}
	}

	ai_will_do = { # this is a trigger
		has_opinion = {
			who = FROM
			value = 50
		}
		FROM = {
			NOT = { stability = 2 }
		}
		NOT = { is_rival = FROM }
		NOT = { is_enemy = FROM }
		trust = {
			who = FROM
			value = 65
		}
	}
}

# Fabricate Ottoman Campaign of Conquest cb
fabricate_ottoman_invasion_cb = {
	category = covert

	require_acceptance = no

	is_visible = {
		has_government_attribute = has_eyalets
	}
	is_allowed = {
		if = {
			limit = {
				FROM = { total_development = 150 }
			}
			custom_trigger_tooltip = {
				tooltip = FROM_HAS_NOT_150_TOTAL_DEV
				FROM = { NOT = { total_development = 150 } }
			}
		}
		if = {
			limit = {
				NOT = {
					has_spy_network_in = {
						who = FROM
						value = 30
					}
				}
				NOT = { full_idea_group = spy_ideas }
			}
			custom_trigger_tooltip = {
				tooltip = REQUIRES_30_SPY_NETWORK_TT
				has_spy_network_in = {
					who = FROM
					value = 30
				}
			}
		}
		if = {
			limit = {
				NOT = {
					has_spy_network_in = {
						who = FROM
						value = 24
					}
				}
				full_idea_group = spy_ideas
			}
			custom_trigger_tooltip = {
				tooltip = REQUIRES_24_SPY_NETWORK_TT
				has_spy_network_in = {
					who = FROM
					value = 24
				}
			}
		}
		if = {
			limit = {
				has_casus_belli = {
					type = cb_ottoman_subjugation_war
					target = FROM
				}
			}
			custom_trigger_tooltip = {
				tooltip = HAS_OTTOMAN_INVASION_CB_ALREADY_TT
				NOT = {
					has_casus_belli = {
						type = cb_ottoman_subjugation_war
						target = FROM
					}
				}
			}
		}
		if = {
			limit = {
				FROM = { is_subject = yes }
			}
			custom_trigger_tooltip = {
				tooltip = CANNOT_DO_ACTION_TO_SUBJECTS_TT
				FROM = { is_subject = no }
			}
		}
		if = {
			limit = {
				NOT = { is_neighbor_of = FROM }
			}
			custom_trigger_tooltip = {
				tooltip = FROM_MUST_BE_NEIGHBOR_TT
				is_neighbor_of = FROM
			}
		}
	}
	on_accept = {
		if = {
			limit = {
				full_idea_group = spy_ideas
			}
			add_spy_network_in = {
				who = FROM
				value = -24
			}
		}
		else = {
			add_spy_network_in = {
				who = FROM
				value = -30
			}
		}
		add_casus_belli = {
			target = FROM
			type = cb_ottoman_subjugation_war
			months = 60
		}
		FROM = {
			set_country_flag = got_invasion_cb_fabricated_by_@ROOT
		}
	}
	on_decline = {
	}

	ai_will_do = { # this is a trigger
		has_spy_network_in = {
			who = FROM
			value = 50
		}
	}
}

# Elevate Eyalet to Vassal status
reign_in_eyalet = {
	category = influence

	alert_index = 20
	alert_tooltip = reign_in_eyalet_alert_tooltip

	require_acceptance = yes

	is_visible = {
		has_government_attribute = has_eyalets
		FROM = {
			is_subject_of = ROOT
			is_subject_of_type = eyalet
		}
	}
	is_allowed = {
		if = {
			limit = {
				FROM = { liberty_desire = 50 }
			}
			custom_trigger_tooltip = {
				tooltip = FROM_IS_REBELLIOUS_TT
				FROM = { liberty_desire = 50 }
			}
		}
	}
	on_accept = {
		create_subject = {
			subject_type = core_eyalet
			subject = FROM
			keep_liberty_desire = yes
		}
	}
	on_decline = {
	}

	ai_will_do = { # this is a trigger
		always = yes	#There is never a reason for the Ottomans to not want to integrate their eyalets
	}

	ai_acceptance = {
        add_entry = {
            name = DIPLO_OPPINION
			export_to_variable = {
				variable_name = ai_value
				value = opinion
				who = FROM
				with = ROOT
			}
			multiply_variable = {
				which = ai_value 
				value = 0.2
			}
        }
		add_entry = {
			name = AI_TRUST_TOWARDS_ROOT
			export_to_variable = {
				variable_name = ai_value
				value = trust
				who = FROM
				with = ROOT
			}			
			subtract_variable = { 
				which = ai_value
				value = 50
			}
			#1 trust = +4 ai points
			multiply_variable = {
				which = ai_value
				value = 0.4
			}
		}
		add_entry = {
			name = AI_DIPLOMATIC_REPUTATION
			export_to_variable = {
				variable_name = ai_value
				value = trigger_value:diplomatic_reputation
			}
			#1 rep = 4
			multiply_variable = {
				which = ai_value
				value = 4
			}
		}
		add_entry = {
			name = AI_TOTAL_DEVELOPMENT
			export_to_variable = {
				variable_name = ai_value
				value = total_development
				who = FROM
			}
			#4 dev = -1
			multiply_variable = {
				which = ai_value
				value = -0.25
			}
		}
		add_entry = {
			name = HAS_BONUS_REIGN_IN_REASON
			limit = {
				has_country_flag = tur_reduced_requirements_for_core_eyalet
			}
			export_to_variable = {
				variable_name = ai_value
				value = 1
			}
			multiply_variable = {
				which = ai_value
				value = 20
			}
		}
		add_entry = {
			name = AI_LIBERTY_DESIRE
			export_to_variable = {
				variable_name = ai_value
				value = liberty_desire
				who = FROM
			}
			multiply_variable = {
				which = ai_value
				value = -1
			}
		}
	}
}

# Call Eyalet into wars
call_eyalet_into_wars = {
	category = influence

	require_acceptance = no

	is_visible = {
		has_government_attribute = has_eyalets
		FROM = {
			is_subject_of = ROOT
			is_subject_of_type = eyalet
		}
	}
	is_allowed = {
		if = {
			limit = {
				FROM = { liberty_desire = 50 }
			}
			custom_trigger_tooltip = {
				tooltip = FROM_IS_REBELLIOUS_TT
				FROM = { liberty_desire = 50 }
			}
		}
		if = {
			limit = {
				is_at_war = no
			}
			custom_trigger_tooltip = {
				tooltip = ROOT_IS_NOT_AT_WAR_TT
				is_at_war = yes
			}
		}
		if = {
			limit = {
				FROM = {
					NOT = {
						owes_favors = {
							who = ROOT
							value = 10
						}
					}
				}
				is_in_war = {
					defender_leader = ROOT
				}
			}
			custom_trigger_tooltip = {
				tooltip = FROM_MUST_OWE_10_FAVORS_DEFENSIVE_WAR_TT
				FROM = {
					owes_favors = {
						who = ROOT
						value = 10
					}
				}
			}
		}
		if = {
			limit = {
				FROM = {
					NOT = {
						owes_favors = {
							who = ROOT
							value = 20
						}
					}
				}
				NOT = {
					is_in_war = {
						defender_leader = ROOT
					}
				}
			}
			custom_trigger_tooltip = {
				tooltip = FROM_MUST_OWE_20_FAVORS_TT
				FROM = {
					owes_favors = {
						who = ROOT
						value = 20
					}
				}
			}
		}
		if = {
			limit = {
				FROM = { is_at_war = yes }
			}
			custom_trigger_tooltip = {
				tooltip = FROM_IS_AT_WAR_TT
				FROM = { is_at_war = no }
			}
		}
	}
	on_accept = {
		FROM = {
			ROOT = {
				add_favors = {
					who = PREV
					amount = -10
				}
			}
			join_all_defensive_wars_of = ROOT
		}
		if = {
			limit = {
				FROM = {
					owes_favors = {
						who = ROOT
						value = 10
					}
				}
			}
			FROM = {
				ROOT = {
					add_favors = {
						who = PREV
						amount = -10
					}
				}
				join_all_offensive_wars_of = ROOT
			}
		}
	}
	on_decline = {
	}

	ai_will_do = { # this is a trigger
		always = yes
	}
}

fabricate_tributary_cb = {
	category = covert

	require_acceptance = no

	is_visible = {
		has_country_flag = jap_enable_fabricating_trib_CB_flag
	}
	is_allowed = {
		if = {
			limit = {
				NOT = {
					has_spy_network_in = {
						who = FROM
						value = 100
					}
				}
				NOT = { full_idea_group = spy_ideas }
			}
			custom_trigger_tooltip = {
				tooltip = REQUIRES_100_SPY_NETWORK_TT
				has_spy_network_in = {
					who = FROM
					value = 100
				}
			}
		}
		if = {
			limit = {
				NOT = {
					has_spy_network_in = {
						who = FROM
						value = 80
					}
				}
				full_idea_group = spy_ideas
			}
			custom_trigger_tooltip = {
				tooltip = REQUIRES_100_SPY_NETWORK_TT
				has_spy_network_in = {
					who = FROM
					value = 80
				}
			}
		}
		if = {
			limit = {
				has_casus_belli = {
					type = cb_force_tributary_mission
					target = FROM
				}
			}
			custom_trigger_tooltip = {
				tooltip = has_force_trib_cb_already_tt
				NOT = {
					has_casus_belli = {
						type = cb_force_tributary_mission
						target = FROM
					}
				}
			}
		}
		if = {
			limit = {
				FROM = { is_subject = yes }
			}
			custom_trigger_tooltip = {
				tooltip = CANNOT_DO_ACTION_TO_SUBJECTS_TT
				FROM = { is_subject = no }
			}
		}
		if = {
			limit = {
				NOT = { total_development = FROM } 
			}
			custom_trigger_tooltip = {
				tooltip = we_need_more_dev_tt
				total_development = FROM 
			}
		}
	}
	on_accept = {
		if = {
			limit = {
				full_idea_group = spy_ideas
			}
			add_spy_network_in = {
				who = FROM
				value = -80
			}
		}
		else = {
			add_spy_network_in = {
				who = FROM
				value = -100
			}
		}
		add_casus_belli = {
			target = FROM
			type = cb_force_tributary_mission
			months = 60
		}
	}
	on_decline = {
	}

	ai_will_do = { # this is a trigger
		has_spy_network_in = {
			who = FROM
			value = 100
		}
	}
}

offer_protectorate = {
	category = influence
	require_acceptance = yes

	alert_index = 4
	alert_tooltip = offer_protectorate_alert_tooltip

	is_visible = {
		has_government_attribute = can_establish_trade_protectorates
		is_subject = no
		FROM = { is_subject = no }
	}
	is_allowed = {
		if = {
			limit = {
				NOT = {
					FROM = {
						capital_scope = {
							trade_range = ROOT
						}
					}
				}
			}
			custom_trigger_tooltip = {
				tooltip = REQUIRES_CAPITAL_IN_TRADE_RANGE_TT
				FROM = {
					capital_scope = {
						trade_range = ROOT
					}
				}
			}
		}
		if = {
			limit = {
				FROM = { is_at_war = yes }
			}
			custom_trigger_tooltip = {
				tooltip = FROM_IS_AT_WAR_TT
				FROM = { is_at_war = no }
			}
		}
		if = {
			limit = {
				is_at_war = yes
			}
			custom_trigger_tooltip = {
				tooltip = ROOT_IS_AT_WAR_TT
				is_at_war = no
			}
		}
		if = {
			limit = {
				FROM = {
					OR = {
						has_reform = steppe_horde
						has_reform = great_mongol_state_reform
					}
				}
			}
			custom_trigger_tooltip = {
				tooltip = FROM_IS_A_HORDE_TT
				FROM = {
					NOT = { has_reform = steppe_horde }
					NOT = { has_reform = great_mongol_state_reform }
				}
			}
		}
		if = {
			limit = {
				FROM = {
					same_continent = ROOT
				}
			}
			custom_trigger_tooltip = {
				tooltip = FROM_IS_ON_ROOT_CONTINENT_TT
				FROM = {
					NOT = { same_continent = ROOT }
				}
			}
		}
	}
	on_accept = {
		create_subject = {
			subject_type = trade_protectorate
			subject = FROM
		}
	}
	on_decline = {
	}

	ai_will_do = { # this is a trigger
		OR = {
			ai_attitude = {
				who = FROM
				attitude = attitude_friendly
			}
			ai_attitude = {
				who = FROM
				attitude = attitude_protective
			}
			FROM = {
				any_neighbor_country = {
					NOT = { tag = ROOT }
					FROM = {
						ai_attitude = {
							who = PREV
							attitude = attitude_threatened
						}
					}
				}
			}
			FROM = {
				ai_attitude = {
					who = ROOT
					attitude = attitude_threatened
				}
			}
		}
		NOT = {
			ai_attitude = {
				who = FROM
				attitude = attitude_domineering
			}
		}
		NOT = {
			ai_attitude = {
				who = FROM
				attitude = attitude_hostile
			}
		}
		NOT = {
			ai_attitude = {
				who = FROM
				attitude = attitude_outraged
			}
		}
		has_opinion = {
			who = FROM
			value = 50
		}
		NOT = {
			FROM = {
				has_country_modifier = dissolve_protectorate_timer
			}
		}
	}

	ai_acceptance = {
        add_entry = {
            name = DIPLO_OPPINION
			export_to_variable = {
				variable_name = ai_value
				value = opinion
				who = FROM
				with = ROOT
			}
			multiply_variable = {
				which = ai_value 
				value = 0.125
			}
        }
		add_entry = {
			name = AI_TRUST_TOWARDS_ROOT
			export_to_variable = {
				variable_name = ai_value
				value = trust
				who = FROM
				with = ROOT
			}			
			subtract_variable = { 
				which = ai_value
				value = 50
			}
			#1 trust = +4 ai points
			multiply_variable = {
				which = ai_value
				value = 0.4
			}
		}
		add_entry = {
			name = AI_DIPLOMATIC_REPUTATION
			export_to_variable = {
				variable_name = ai_value
				value = trigger_value:diplomatic_reputation
			}
			#1 rep = 3
			multiply_variable = {
				which = ai_value
				value = 3
			}
		}
		add_entry = {
			name = AI_TOTAL_DEVELOPMENT
			export_to_variable = {
				variable_name = ai_value
				value = total_development
				who = FROM
			}
			#4 dev = -1
			multiply_variable = {
				which = ai_value
				value = -0.25
			}
		}
		add_entry = {
			name = DIPLO_HAS_AI_HAS_OWN_SUBJECTS_TT
			limit = {
				FROM = { num_of_subjects = 1 }
			}
			export_to_variable = {
				variable_name = ai_value
				value = 1
			}
			multiply_variable = {
				which = ai_value
				value = -1000
			}
		}
		add_entry = {
			name = attitude_neutral_DIPLO_ATTITUDE_TT
			limit = { FROM = { ai_attitude = { who = ROOT attitude = attitude_neutral } } }
			export_to_variable = { variable_name = ai_value value = 1 }
			multiply_variable = { which = ai_value value = -20 }
		}
		add_entry = {
			name = attitude_rivalry_DIPLO_ATTITUDE_TT
			limit = { FROM = { ai_attitude = { who = ROOT attitude = attitude_rivalry } } }
			export_to_variable = { variable_name = ai_value value = 1 }
			multiply_variable = { which = ai_value value = -1000 }
		}
		add_entry = {
			name = attitude_hostile_DIPLO_ATTITUDE_TT
			limit = { FROM = { ai_attitude = { who = ROOT attitude = attitude_hostile } } }
			export_to_variable = { variable_name = ai_value value = 1 }
			multiply_variable = { which = ai_value value = -1000 }
		}
		add_entry = {
			name = attitude_friendly_DIPLO_ATTITUDE_TT
			limit = { FROM = { ai_attitude = { who = ROOT attitude = attitude_friendly } } }
			export_to_variable = { variable_name = ai_value value = 1 }
			multiply_variable = { which = ai_value value = 10 }
		}
		add_entry = {
			name = attitude_threatened_DIPLO_ATTITUDE_TT
			limit = { FROM = { ai_attitude = { who = ROOT attitude = attitude_threatened } } }
			export_to_variable = { variable_name = ai_value value = 1 }
			multiply_variable = { which = ai_value value = 10 }
		}
		add_entry = {
			name = attitude_outraged_DIPLO_ATTITUDE_TT
			limit = { FROM = { ai_attitude = { who = ROOT attitude = attitude_outraged } } }
			export_to_variable = { variable_name = ai_value value = 1 }
			multiply_variable = { which = ai_value value = -1000 }
		}
		add_entry = {
			name = attitude_domineering_DIPLO_ATTITUDE_TT
			limit = { FROM = { ai_attitude = { who = ROOT attitude = attitude_domineering } } }
			export_to_variable = { variable_name = ai_value value = 1 }
			multiply_variable = { which = ai_value value = -1000 }
		}
		add_entry = {
			name = DIPLO_BORDER_DISTANCE_TT
			export_to_variable = {
				variable_name = ai_value
				value = border_distance
				who = FROM
				with = ROOT
			}
			#2 units = -1
			multiply_variable = {
				which = ai_value
				value = -0.5
			}
		}
	}
}

dissolve_protectorate = {
	category = influence
	require_acceptance = no

	is_visible = {
		OR = {
			AND = {
				is_subject_of = FROM
				is_subject_of_type = trade_protectorate
			}
			FROM = {
				is_subject_of = ROOT
				is_subject_of_type = trade_protectorate
			}
		}
	}
	is_allowed = {
	}
	on_accept = {
		if = {
			limit = {
				is_subject_of = FROM
				is_subject_of_type = trade_protectorate
			}
			grant_independence = yes		
		}
		else = {
			FROM = {
				grant_independence = yes
			}
		}
		if = {
			limit = {
				is_subject_of = FROM
				is_subject_of_type = trade_protectorate
				NOT = { liberty_desire = 100 }
			}
			if = {
				limit = {
					has_stab_reduction_from_dip_action_modifier = yes
				}
				add_prestige = -1
			}
			else = {
				add_stability = -1
			}
			add_country_modifier = {
				name = dissolve_protectorate_timer
				duration = 3650
				hidden = yes
			}
		}
		else_if = {
			limit = {
				FROM = {
					NOT = { liberty_desire = 100 }
				}
			}
			if = {
				limit = {
					has_stab_reduction_from_dip_action_modifier = yes
				}
				add_prestige = -1
			}
			else = {
				add_stability = -1
			}
			FROM = {
				add_country_modifier = {
					name = dissolve_protectorate_timer
					duration = 3650
					hidden = yes
				}
			}
		}
	}
	on_decline = {
	}

	ai_will_do = { # Overlords will never want to break the relationship
		is_subject_of = FROM
		OR = {
			liberty_desire = 100
			AND = {
				stability = 1
				liberty_desire = 90
				NOT = {
					has_opinion = {
						who = ROOT
						value = -50
					}
				}
			}
			AND = {
				stability = 1
				liberty_desire = 80
				NOT = {
					has_opinion = {
						who = ROOT
						value = -100
					}
				}
			}
			AND = {
				stability = 1
				liberty_desire = 70
				NOT = {
					has_opinion = {
						who = ROOT
						value = -150
					}
				}
			}
			AND = {
				stability = 1
				liberty_desire = 60
				NOT = {
					has_opinion = {
						who = ROOT
						value = -199
					}
				}
			}
		}
		NOT = {
			any_neighbor_country = {
				ROOT = {
					ai_attitude = {
						who = PREV
						attitude = attitude_threatened
					}
				}
			}
		}
	}
}

request_protectorate = {
	category = influence
	require_acceptance = yes

	alert_index = 4
	alert_tooltip = request_protectorate_alert_tooltip

	is_visible = {
		FROM = { has_government_attribute = can_establish_trade_protectorates }
		is_subject = no
		FROM = { is_subject = no }
		NOT = { has_reform = steppe_horde }
		NOT = { has_reform = great_mongol_state_reform }
	}
	is_allowed = {
		if = {
			limit = {
				NOT = {
					capital_scope = {
						trade_range = FROM
					}
				}
			}
			custom_trigger_tooltip = {
				tooltip = REQUIRES_FROM_TO_BE_IN_TRADE_RANGE_TT
				capital_scope = {
					trade_range = FROM
				}
			}
		}
		if = {
			limit = {
				FROM = { is_at_war = yes }
			}
			custom_trigger_tooltip = {
				tooltip = FROM_IS_AT_WAR_TT
				FROM = { is_at_war = no }
			}
		}
		if = {
			limit = {
				is_at_war = yes
			}
			custom_trigger_tooltip = {
				tooltip = ROOT_IS_AT_WAR_TT
				is_at_war = no
			}
		}
		if = {
			limit = {
				FROM = {
					same_continent = ROOT
				}
			}
			custom_trigger_tooltip = {
				tooltip = FROM_IS_ON_ROOT_CONTINENT_TT
				FROM = {
					NOT = { same_continent = ROOT }
				}
			}
		}
	}
	on_accept = {
		every_subject_country = {
			limit = {
				NOT = { is_subject_of_type = colony }
				NOT = { is_subject_of_type = crown_colony }
				NOT = { is_subject_of_type = private_enterprise }
				NOT = { is_subject_of_type = self_governing_colony }
			}
			ROOT = {
				release = PREV
			}
		}
		FROM = {
			create_subject = {
				subject_type = trade_protectorate
				subject = ROOT
			}
		}
	}
	on_decline = {
	}

	ai_will_do = { # this is a trigger
		OR = {
			ai_attitude = {
				who = FROM
				attitude = attitude_threatened
			}
			any_neighbor_country = {
				NOT = { tag = FROM }
				ROOT = {
					ai_attitude = {
						who = PREV
						attitude = attitude_threatened
					}
				}
			}
			FROM = {
				OR = {
					ai_attitude = {
						who = ROOT
						attitude = attitude_domineering
					}
					ai_attitude = {
						who = ROOT
						attitude = attitude_protective
					}
				}
			}
		}
		NOT = { mil_tech = FROM }
		OR = {
			NOT = { army_size = FROM }
			AND = {
				capital_scope = { is_island = yes }
				NOT = { navy_size = FROM }
			}
			FROM = {
				military_strength = {
					who = ROOT
					value = 2
				}
			}
		}
		NOT = { has_country_modifier = dissolve_protectorate_timer }
		NOT = {
			ai_attitude = {
				who = FROM
				attitude = attitude_rivalry
			}
		}
		NOT = {
			ai_attitude = {
				who = FROM
				attitude = attitude_hostile
			}
		}
		NOT = {
			ai_attitude = {
				who = FROM
				attitude = attitude_outraged
			}
		}
		NOT = {
			ai_attitude = {
				who = FROM
				attitude = attitude_domineering
			}
		}
	}

	ai_acceptance = {
        add_entry = {
            name = DIPLO_OPPINION
			export_to_variable = {
				variable_name = ai_value
				value = opinion
				who = FROM
				with = ROOT
			}
			multiply_variable = {
				which = ai_value 
				value = 0.125
			}
        }
		add_entry = {
			name = AI_TRUST_TOWARDS_ROOT
			export_to_variable = {
				variable_name = ai_value
				value = trust
				who = FROM
				with = ROOT
			}			
			subtract_variable = { 
				which = ai_value
				value = 50
			}
			#1 trust = +4 ai points
			multiply_variable = {
				which = ai_value
				value = 0.4
			}
		}
		add_entry = {
			name = AI_DIPLOMATIC_REPUTATION
			export_to_variable = {
				variable_name = ai_value
				value = trigger_value:diplomatic_reputation
			}
			#1 rep = 3
			multiply_variable = {
				which = ai_value
				value = 3
			}
		}
		add_entry = {
			name = DIPLO_OUR_TOTAL_DEVELOPMENT_TT
			export_to_variable = {
				variable_name = ai_value
				value = total_development
				who = ROOT
			}
			#10 dev = -1
			multiply_variable = {
				which = ai_value
				value = -0.1
			}
		}
		add_entry = {
			name = attitude_neutral_DIPLO_ATTITUDE_TT
			limit = { FROM = { ai_attitude = { who = ROOT attitude = attitude_neutral } } }
			export_to_variable = { variable_name = ai_value value = 1 }
			multiply_variable = { which = ai_value value = -20 }
		}
		add_entry = {
			name = attitude_rivalry_DIPLO_ATTITUDE_TT
			limit = { FROM = { ai_attitude = { who = ROOT attitude = attitude_rivalry } } }
			export_to_variable = { variable_name = ai_value value = 1 }
			multiply_variable = { which = ai_value value = -1000 }
		}
		add_entry = {
			name = attitude_hostile_DIPLO_ATTITUDE_TT
			limit = { FROM = { ai_attitude = { who = ROOT attitude = attitude_hostile } } }
			export_to_variable = { variable_name = ai_value value = 1 }
			multiply_variable = { which = ai_value value = -1000 }
		}
		add_entry = {
			name = attitude_friendly_DIPLO_ATTITUDE_TT
			limit = { FROM = { ai_attitude = { who = ROOT attitude = attitude_friendly } } }
			export_to_variable = { variable_name = ai_value value = 1 }
			multiply_variable = { which = ai_value value = 50 }
		}
		add_entry = {
			name = attitude_outraged_DIPLO_ATTITUDE_TT
			limit = { FROM = { ai_attitude = { who = ROOT attitude = attitude_outraged } } }
			export_to_variable = { variable_name = ai_value value = 1 }
			multiply_variable = { which = ai_value value = -1000 }
		}
		add_entry = {
			name = attitude_domineering_DIPLO_ATTITUDE_TT
			limit = { FROM = { ai_attitude = { who = ROOT attitude = attitude_domineering } } }
			export_to_variable = { variable_name = ai_value value = 1 }
			multiply_variable = { which = ai_value value = 1000 }
		}
		add_entry = {
			name = attitude_protective_DIPLO_ATTITUDE_TT
			limit = { FROM = { ai_attitude = { who = ROOT attitude = attitude_protective } } }
			export_to_variable = { variable_name = ai_value value = 1 }
			multiply_variable = { which = ai_value value = 1000 }
		}
		add_entry = {
			name = DIPLO_BORDER_DISTANCE_TT
			export_to_variable = {
				variable_name = ai_value
				value = border_distance
				who = FROM
				with = ROOT
			}
			#2 units = -1
			multiply_variable = {
				which = ai_value
				value = -0.5
			}
		}
	}
}

# Call Protectorate into wars
call_trade_protectorate_into_wars = {
	category = influence

	require_acceptance = no

	is_visible = {
		FROM = {
			is_subject_of = ROOT
			is_subject_of_type = trade_protectorate
		}
	}
	is_allowed = {
		if = {
			limit = {
				FROM = { liberty_desire = 50 }
			}
			custom_trigger_tooltip = {
				tooltip = FROM_IS_REBELLIOUS_TT
				FROM = { liberty_desire = 50 }
			}
		}
		if = {
			limit = {
				is_at_war = no
			}
			custom_trigger_tooltip = {
				tooltip = ROOT_IS_NOT_AT_WAR_TT
				is_at_war = yes
			}
		}
		if = {
			limit = {
				FROM = {
					NOT = {
						has_opinion = {
							who = ROOT
							value = 0
						}
					}
				}
			}
			custom_trigger_tooltip = {
				tooltip = FROM_MUST_HAVE_POSITIVE_OPINION_TT
				FROM = {
					has_opinion = {
						who = ROOT
						value = 0
					}
				}
			}
		}
		if = {
			limit = {
				FROM = { is_at_war = yes }
			}
			custom_trigger_tooltip = {
				tooltip = FROM_IS_AT_WAR_TT
				FROM = { is_at_war = no }
			}
		}
	}
	on_accept = {
		FROM = {
			add_opinion = {
				who = ROOT
				modifier = trade_protectorate_called_into_war
			}
			join_all_defensive_wars_of = ROOT
		}
		if = {
			limit = {
				is_in_war = { attackers = ROOT }
			}
			FROM = {
				add_opinion = {
					who = ROOT
					modifier = trade_protectorate_called_into_war
				}
				join_all_offensive_wars_of = ROOT
			}
		}
	}
	on_decline = {
	}

	ai_will_do = { # this is a trigger
		always = yes
	}
}

# Grant Autonomy to Core Eyalet
grant_autonomy_to_core_eyalet = {
	category = influence

	require_acceptance = no

	is_visible = {
		has_government_attribute = has_eyalets
		FROM = {
			is_subject_of = ROOT
			is_subject_of_type = core_eyalet
		}
	}
	is_allowed = {
		if = {
			limit = {
				FROM = { liberty_desire = 50 }
			}
			custom_trigger_tooltip = {
				tooltip = FROM_IS_REBELLIOUS_TT
				FROM = { liberty_desire = 50 }
			}
		}
	}
	on_accept = {
		create_subject = {
			subject_type = eyalet
			subject = FROM
			keep_liberty_desire = yes
		}
	}
	on_decline = {
	}

	ai_will_do = { # this is a trigger
		always = no	#AI should never want to have its eyalet to be less centralized
	}
}

# Turn Eyalet to Vassal status
promote_vassal_to_eyalet = {
	category = influence

	require_acceptance = yes

	alert_index = 6
	alert_tooltip = promote_vassal_to_eyalet_alert_tooltip

	is_visible = {
		has_government_attribute = has_eyalets
		FROM = {
			is_subject_of = ROOT
			is_subject_of_type = vassal
		}
	}
	is_allowed = {
		if = {
			limit = {
				FROM = { liberty_desire = 50 }
			}
			custom_trigger_tooltip = {
				tooltip = FROM_IS_REBELLIOUS_TT
				FROM = { liberty_desire = 50 }
			}
		}
	}
	on_accept = {
		create_subject = {
			subject_type = eyalet
			subject = FROM
			keep_liberty_desire = yes
		}
		FROM = {
			if = {
				limit = {
					NOT = { has_reform = papacy_reform }
					NOT = { has_reform = celestial_empire }
					NOT = { has_reform = shogunate }
				}
				if = {
					limit = {
						OR = {
							culture_group = maghrebi
							has_reform = pirate_republic_reform
						}
					}
					set_country_flag = pirate_eyalet
				}
				if = {
					limit = { NOT = { government = monarchy } }
					change_government = monarchy
				}
				if = {
					limit = { has_country_flag = pirate_eyalet }
					clr_country_flag = pirate_eyalet
					add_government_reform = barbary_eyalet_government
				}
				else = {
					add_government_reform = eyalet_government
				}
				set_country_flag = has_eyalet_color
				set_country_flag = has_overriden_color_flag
				change_country_color = { country = ROOT }
			}
		}
	}
	on_decline = {
	}

	ai_will_do = { # this is a trigger
		always = no	#Too risky to test this out with the AI
	}

	ai_acceptance = {
        add_entry = {
            name = DIPLO_OPPINION
			export_to_variable = {
				variable_name = ai_value
				value = opinion
				who = FROM
				with = ROOT
			}
			multiply_variable = {
				which = ai_value 
				value = 0.2
			}
        }
		add_entry = {
			name = AI_TRUST_TOWARDS_ROOT
			export_to_variable = {
				variable_name = ai_value
				value = trust
				who = FROM
				with = ROOT
			}			
			subtract_variable = { 
				which = ai_value
				value = 50
			}
			#1 trust = +4 ai points
			multiply_variable = {
				which = ai_value
				value = 0.4
			}
		}
		add_entry = {
			name = AI_DIPLOMATIC_REPUTATION
			export_to_variable = {
				variable_name = ai_value
				value = trigger_value:diplomatic_reputation
			}
			#1 rep = 4
			multiply_variable = {
				which = ai_value
				value = 4
			}
		}
		add_entry = {
			name = AI_LIBERTY_DESIRE
			export_to_variable = {
				variable_name = ai_value
				value = liberty_desire
				who = FROM
			}
			multiply_variable = {
				which = ai_value
				value = -1
			}
		}
	}
}

# Promote Appanage Heir
promote_appanage_heir = {
	category = influence

	require_acceptance = no

	is_visible = {
		has_government_attribute = heir
		FROM = {
			is_subject_of = ROOT
			is_subject_of_type = appanage
			has_government_attribute = heir
		}
	}
	is_allowed = {
		if = {
			limit = {
				FROM = { liberty_desire = 50 }
			}
			custom_trigger_tooltip = {
				tooltip = FROM_IS_REBELLIOUS_TT
				FROM = { liberty_desire = 50 }
			}
		}
		if = {
			limit = {
				has_heir = yes
			}
			custom_trigger_tooltip = {
				tooltip = ROOT_HAS_HEIR_TT
				has_heir = no
			}
		}
		if = {
			limit = {
				FROM = { has_heir = no }
			}
			custom_trigger_tooltip = {
				tooltip = FROM_HAS_NO_HEIR_TT
				FROM = { has_heir = YES }
			}
		}
	}
	on_accept = {
		FROM = { exile_heir_as = appanage_heir }
		set_heir = appanage_heir
	}
	on_decline = {
	}

	ai_will_do = { # this is a trigger
		FROM = {
			OR = {
				AND = {
					heir_adm = 3
					heir_dip = 3
					heir_mil = 3
				}
				AND = {
					heir_adm = 5
					OR = {
						heir_dip = 2
						heir_mil = 2
					}
				}
				AND = {
					heir_dip = 5
					OR = {
						heir_adm = 2
						heir_mil = 2
					}
				}
				AND = {
					heir_mil = 5
					OR = {
						heir_dip = 2
						heir_adm = 2
					}
				}
			}
		}
	}

	#ai_acceptance = {
    #    add_entry = {
    #        name = DIPLO_OPPINION
	#		export_to_variable = {
	#			variable_name = ai_value
	#			value = opinion
	#			who = FROM
	#			with = ROOT
	#		}
	#		multiply_variable = {
	#			which = ai_value 
	#			value = 0.2
	#		}
    #    }
	#	add_entry = {
	#		name = AI_TRUST_TOWARDS_ROOT
	#		export_to_variable = {
	#			variable_name = ai_value
	#			value = trust
	#			who = FROM
	#			with = ROOT
	#		}			
	#		subtract_variable = { 
	#			which = ai_value
	#			value = 50
	#		}
	#		#1 trust = +4 ai points
	#		multiply_variable = {
	#			which = ai_value
	#			value = 0.4
	#		}
	#	}
	#	add_entry = {
	#		name = AI_DIPLOMATIC_REPUTATION
	#		export_to_variable = {
	#			variable_name = ai_value
	#			value = trigger_value:diplomatic_reputation
	#		}
	#		#1 rep = 4
	#		multiply_variable = {
	#			which = ai_value
	#			value = 4
	#		}
	#	}
	#	add_entry = {
	#		name = AI_LIBERTY_DESIRE
	#		export_to_variable = {
	#			variable_name = ai_value
	#			value = liberty_desire
	#			who = FROM
	#		}
	#		multiply_variable = {
	#			which = ai_value
	#			value = -1
	#		}
	#	}
	#}
}

# Allow Commercial Enterprise to dow
grant_war_rights = {
	category = influence

	require_acceptance = no

	is_visible = {
		FROM = {
			is_subject_of = ROOT
			is_subject_of_type = commercial_enterprise
			has_country_modifier = revoked_war_rights
		}
	}
	is_allowed = {
		always = yes
	}
	on_accept = {
		FROM = {
			remove_country_modifier = revoked_war_rights
		}
	}
	on_decline = {
	}

	ai_will_do = { # this is a trigger
		always = no
	}
}

# Disallow Commercial Enterprise to dow
revoke_war_rights = {
	category = influence

	require_acceptance = no

	is_visible = {
		FROM = {
			is_subject_of = ROOT
			is_subject_of_type = commercial_enterprise
			NOT = { has_country_modifier = revoked_war_rights }
		}
	}
	is_allowed = {
		always = yes
	}
	on_accept = {
		FROM = {
			add_country_modifier = {
				name = revoked_war_rights
				duration = -1
			}
			add_opinion = {
				who = ROOT
				modifier = revoked_our_right_to_war
			}
		}
	}
	on_decline = {
	}

	ai_will_do = { # this is a trigger
		always = no
	}
}

# Steal Modern Ideas
steal_modern_ideas = {
	category = covert
	require_acceptance = no

	is_visible = {
		has_government_mechanic = russian_modernization_mechanic
	}
	is_allowed = {
		if = {
			limit = {
				FROM = { NOT = { tech_difference = 0 } }
			}
			custom_trigger_tooltip = {
				tooltip = FROM_HAS_LESS_THAN_ROOT_TECHNOLOGY
				FROM = { tech_difference = 0 }
			}
		}
		if = {
			limit = {
				NOT = {
					has_spy_network_in = {
						who = FROM
						value = 30
					}
				}
				NOT = { full_idea_group = spy_ideas }
			}
			custom_trigger_tooltip = {
				tooltip = REQUIRES_30_SPY_NETWORK_TT
				has_spy_network_in = {
					who = FROM
					value = 30
				}
			}
		}
		if = {
			limit = {
				NOT = {
					has_spy_network_in = {
						who = FROM
						value = 24
					}
				}
				full_idea_group = spy_ideas
			}
			custom_trigger_tooltip = {
				tooltip = REQUIRES_24_SPY_NETWORK_TT
				has_spy_network_in = {
					who = FROM
					value = 24
				}
			}
		}
		if = {
			limit = { has_estate_privilege = estate_nobles_mestnichestvo }
			custom_trigger_tooltip = {
				tooltip = CANNOT_GAIN_ANY_MODERNIZATION_TT
				NOT = { has_estate_privilege = estate_nobles_mestnichestvo }
			}
		}
	}
	on_accept = {
		if = {
			limit = {
				full_idea_group = spy_ideas
			}
			add_spy_network_in = {
				who = FROM
				value = -24
			}
		}
		else = {
			add_spy_network_in = {
				who = FROM
				value = -30
			}
		}
		if = {
			limit = { FROM = { tech_difference = 0 } }
			add_government_power = { mechanic_type = russian_modernization_mechanic power_type = russian_modernization value = 2.0 }
		}
		if = {
			limit = { FROM = { tech_difference = 1 } }
			add_government_power = { mechanic_type = russian_modernization_mechanic power_type = russian_modernization value = 0.5 }
		}
		if = {
			limit = { FROM = { tech_difference = 2 } }
			add_government_power = { mechanic_type = russian_modernization_mechanic power_type = russian_modernization value = 0.5 }
		}
		if = {
			limit = { FROM = { tech_difference = 3 } }
			add_government_power = { mechanic_type = russian_modernization_mechanic power_type = russian_modernization value = 0.5 }
		}
		if = {
			limit = { FROM = { tech_difference = 4 } }
			add_government_power = { mechanic_type = russian_modernization_mechanic power_type = russian_modernization value = 0.5 }
		}
		if = {
			limit = { FROM = { tech_difference = 5 } }
			add_government_power = { mechanic_type = russian_modernization_mechanic power_type = russian_modernization value = 0.5 }
		}
		if = {
			limit = { FROM = { tech_difference = 6 } }
			add_government_power = { mechanic_type = russian_modernization_mechanic power_type = russian_modernization value = 0.5 }
		}
	}

	ai_will_do = { # this is a trigger
		has_spy_network_in = {
			who = FROM
			value = 30
		}
	}
}

# Study Modern Ideas
request_access_to_modern_ideas = {
	category = economy
	require_acceptance = yes

	alert_index = 11
	alert_tooltip = request_access_to_modern_ideas_alert_tooltip

	is_visible = {
		has_government_mechanic = russian_modernization_mechanic
	}
	is_allowed = {
		if = {
			limit = {
				FROM = { NOT = { tech_difference = 0 } }
			}
			custom_trigger_tooltip = {
				tooltip = FROM_HAS_LESS_THAN_ROOT_TECHNOLOGY
				FROM = { tech_difference = 0 }
			}
		}
		if = {
			limit = { NOT = { years_of_income = 0.25 } }
			years_of_income = 0.25
		}
		if = {
			limit = { has_estate_privilege = estate_nobles_mestnichestvo }
			custom_trigger_tooltip = {
				tooltip = CANNOT_GAIN_ANY_MODERNIZATION_TT
				NOT = { has_estate_privilege = estate_nobles_mestnichestvo }
			}
		}
		if = {
			limit = { war_with = FROM }
			custom_trigger_tooltip = {
				tooltip = WAR_WITH_FROM_TT
				NOT = { war_with = FROM }
			}
		}
	}
	on_accept = {
		if = {
			limit = { FROM = { tech_difference = 0 } }
			add_government_power = { mechanic_type = russian_modernization_mechanic power_type = russian_modernization value = 2.0 }
		}
		if = {
			limit = { FROM = { tech_difference = 1 } }
			add_government_power = { mechanic_type = russian_modernization_mechanic power_type = russian_modernization value = 0.5 }
		}
		if = {
			limit = { FROM = { tech_difference = 2 } }
			add_government_power = { mechanic_type = russian_modernization_mechanic power_type = russian_modernization value = 0.5 }
		}
		if = {
			limit = { FROM = { tech_difference = 3 } }
			add_government_power = { mechanic_type = russian_modernization_mechanic power_type = russian_modernization value = 0.5 }
		}
		if = {
			limit = { FROM = { tech_difference = 4 } }
			add_government_power = { mechanic_type = russian_modernization_mechanic power_type = russian_modernization value = 0.5 }
		}
		if = {
			limit = { FROM = { tech_difference = 5 } }
			add_government_power = { mechanic_type = russian_modernization_mechanic power_type = russian_modernization value = 0.5 }
		}
		if = {
			limit = { FROM = { tech_difference = 6 } }
			add_government_power = { mechanic_type = russian_modernization_mechanic power_type = russian_modernization value = 0.5 }
		}
		FROM = {
			country_event = {
				id = flavor_rus.294
			}
		}
	}
	on_decline = {
	}

	ai_will_do = { # this is a trigger
		years_of_income = 0.5
		is_in_deficit = no
		is_bankrupt = no
		is_at_war = no
	}

	ai_acceptance = {
		add_entry = {
			name = BASE_REJECTION
			limit = {
				always = yes
			}
			export_to_variable = {
				variable_name = ai_value
				value = 1
			}
			
			multiply_variable = {
				which = ai_value
				value = -50
			}
		}
        add_entry = {
            name = DIPLO_OPPINION
			export_to_variable = {
				variable_name = ai_value
				value = opinion
				who = FROM
				with = ROOT
			}
			multiply_variable = {
				which = ai_value 
				value = 0.125
			}
        }
		add_entry = {
			name = HAS_DEFICIT
			limit = {
				FROM = {
					is_in_deficit = yes
				}
			}
			export_to_variable = {
				variable_name = ai_value
				value = 1
			}
			
			multiply_variable = {
				which = ai_value
				value = 25
			}
		}
		add_entry = {
			name = SIZE_OF_LOANS
			limit = {
				FROM = {
					num_of_loans = 1
				}
			}
			export_to_variable = {
				variable_name = ai_value
				value = num_of_loans
			}			
			multiply_variable = {
				which = ai_value
				value = 10
			}
		}
		add_entry = {
			name = AI_PERSONALITY
			limit = {
				FROM = {
					OR = {
						personality = ai_capitalist
						personality = ai_balanced
					}
				}
			}
			export_to_variable = {
				variable_name = ai_value
				value = 1
			}
			
			multiply_variable = {
				which = ai_value
				value = 15
			}
		}
		add_entry = {
			name = AI_PERSONALITY
			limit = {
				FROM = {
					OR = {
						personality = ai_diplomat
						personality = ai_colonialist
					}
				}
			}
			export_to_variable = {
				variable_name = ai_value
				value = 1
			}
			
			multiply_variable = {
				which = ai_value
				value = 10
			}
		}
		add_entry = {
			name = AI_PERSONALITY
			limit = {
				FROM = {
					personality = ai_militarist
				}
			}
			export_to_variable = {
				variable_name = ai_value
				value = 1
			}
			
			multiply_variable = {
				which = ai_value
				value = -25
			}
		}
		add_entry = {
			name = AI_TRUST_TOWARDS_ROOT
			export_to_variable = {
				variable_name = ai_value
				value = trust
				who = FROM
				with = ROOT
			}			
			subtract_variable = { 
				which = ai_value
				value = 50
			}
			#1 trust = +4 ai points
			multiply_variable = {
				which = ai_value
				value = 0.4
			}
		}
		add_entry = {
			name = AI_DIPLOMATIC_REPUTATION
			export_to_variable = {
				variable_name = ai_value
				value = trigger_value:diplomatic_reputation
			}
			#1 rep = 3
			multiply_variable = {
				which = ai_value
				value = 3
			}
		}
		add_entry = {
			name = attitude_neutral_DIPLO_ATTITUDE_TT
			limit = { FROM = { ai_attitude = { who = ROOT attitude = attitude_neutral } } }
			export_to_variable = { variable_name = ai_value value = 1 }
			multiply_variable = { which = ai_value value = -20 }
		}
		add_entry = {
			name = attitude_rivalry_DIPLO_ATTITUDE_TT
			limit = { FROM = { ai_attitude = { who = ROOT attitude = attitude_rivalry } } }
			export_to_variable = { variable_name = ai_value value = 1 }
			multiply_variable = { which = ai_value value = -1000 }
		}
		add_entry = {
			name = attitude_hostile_DIPLO_ATTITUDE_TT
			limit = { FROM = { ai_attitude = { who = ROOT attitude = attitude_hostile } } }
			export_to_variable = { variable_name = ai_value value = 1 }
			multiply_variable = { which = ai_value value = -1000 }
		}
		add_entry = {
			name = attitude_friendly_DIPLO_ATTITUDE_TT
			limit = { FROM = { ai_attitude = { who = ROOT attitude = attitude_friendly } } }
			export_to_variable = { variable_name = ai_value value = 1 }
			multiply_variable = { which = ai_value value = 50 }
		}
		add_entry = {
			name = attitude_outraged_DIPLO_ATTITUDE_TT
			limit = { FROM = { ai_attitude = { who = ROOT attitude = attitude_outraged } } }
			export_to_variable = { variable_name = ai_value value = 1 }
			multiply_variable = { which = ai_value value = -1000 }
		}
		add_entry = {
			name = attitude_domineering_DIPLO_ATTITUDE_TT
			limit = { FROM = { ai_attitude = { who = ROOT attitude = attitude_domineering } } }
			export_to_variable = { variable_name = ai_value value = 1 }
			multiply_variable = { which = ai_value value = 1000 }
		}
		add_entry = {
			name = attitude_protective_DIPLO_ATTITUDE_TT
			limit = { FROM = { ai_attitude = { who = ROOT attitude = attitude_protective } } }
			export_to_variable = { variable_name = ai_value value = 1 }
			multiply_variable = { which = ai_value value = 1000 }
		}
		add_entry = {
			name = DIPLO_BORDER_DISTANCE_TT
			export_to_variable = {
				variable_name = ai_value
				value = border_distance
				who = FROM
				with = ROOT
			}
			#10 units = 1
			multiply_variable = {
				which = ai_value
				value = 0.1
			}
		}
	}
}

# Share Modern Ideas
share_modern_ideas = {
	category = economy
	require_acceptance = yes

	alert_index = 11
	alert_tooltip = share_modern_ideas_alert_tooltip

	is_visible = {
		FROM = { has_government_mechanic = russian_modernization_mechanic }
	}
	is_allowed = {
		if = {
			limit = {
				FROM = { ROOT = { NOT = { tech_difference = 0 } } }
			}
			custom_trigger_tooltip = {
				tooltip = ROOT_HAS_LESS_THAN_ROOT_TECHNOLOGY
				FROM = { ROOT = { tech_difference = 0 } }
			}
		}
		if = {
			limit = { war_with = FROM }
			custom_trigger_tooltip = {
				tooltip = WAR_WITH_FROM_TT
				NOT = { war_with = FROM }
			}
		}
	}
	on_accept = {
		if = {
			limit = { FROM = { ROOT = { tech_difference = 0 } } }
			FROM = { add_government_power = { mechanic_type = russian_modernization_mechanic power_type = russian_modernization value = 2.0 } }
		}
		if = {
			limit = { FROM = { ROOT = { tech_difference = 1 } } }
			FROM = { add_government_power = { mechanic_type = russian_modernization_mechanic power_type = russian_modernization value = 0.5 } }
		}
		if = {
			limit = { FROM = { ROOT = { tech_difference = 2 } } }
			FROM = { add_government_power = { mechanic_type = russian_modernization_mechanic power_type = russian_modernization value = 0.5 } }
		}
		if = {
			limit = { FROM = { ROOT = { tech_difference = 3 } } }
			FROM = { add_government_power = { mechanic_type = russian_modernization_mechanic power_type = russian_modernization value = 0.5 } }
		}
		if = {
			limit = { FROM = { ROOT = { tech_difference = 4 } } }
			FROM = { add_government_power = { mechanic_type = russian_modernization_mechanic power_type = russian_modernization value = 0.5 } }
		}
		if = {
			limit = { FROM = { ROOT = { tech_difference = 5 } } }
			FROM = { add_government_power = { mechanic_type = russian_modernization_mechanic power_type = russian_modernization value = 0.5 } }
		}
		if = {
			limit = { FROM = { ROOT = { tech_difference = 6 } } }
			FROM = { add_government_power = { mechanic_type = russian_modernization_mechanic power_type = russian_modernization value = 0.5 } }
		}
		FROM = {
			country_event = {
				id = flavor_rus.297
			}
		}
	}
	on_decline = {
	}

	ai_will_do = { # this is a trigger
		OR = {
			ai_attitude = {
				who = FROM
				attitude = attitude_friendly
			}
			ai_attitude = {
				who = FROM
				attitude = attitude_defensive
			}
			ai_attitude = {
				who = FROM
				attitude = attitude_protective
			}
			ai_attitude = {
				who = FROM
				attitude = attitude_allied
			}
			is_subject_of = FROM
		}
		FROM = {
			years_of_income = 0.5
			is_in_deficit = no
			is_bankrupt = no
			is_at_war = no
		}
		OR = {
			alliance_with = FROM
			is_subject_of = FROM
			AND = {
				is_in_deficit = yes
				num_of_loans = 2
			}
			is_bankrupt = yes
			personality = ai_capitalist
		}
		NOT = {
			ai_attitude = {
				who = FROM
				attitude = attitude_rivalry
			}
		}
		NOT = {
			ai_attitude = {
				who = FROM
				attitude = attitude_threatened
			}
		}
		NOT = {
			ai_attitude = {
				who = FROM
				attitude = attitude_hostile
			}
		}
		NOT = {
			ai_attitude = {
				who = FROM
				attitude = attitude_outraged
			}
		}
		NOT = {
			ai_attitude = {
				who = FROM
				attitude = attitude_domineering
			}
		}
	}

	ai_acceptance = {
		add_entry = {
			name = HAS_DEFICIT
			limit = {
				FROM = {
					is_in_deficit = yes
				}
			}
			export_to_variable = {
				variable_name = ai_value
				value = 1
			}
			
			multiply_variable = {
				which = ai_value
				value = -25
			}
		}
		add_entry = {
			name = HAS_BANKRUPTCY
			limit = {
				FROM = {
					is_bankrupt = yes
				}
			}
			export_to_variable = {
				variable_name = ai_value
				value = 1
			}
			
			multiply_variable = {
				which = ai_value
				value = -1000
			}
		}
		add_entry = {
			name = SIZE_OF_LOANS
			limit = {
				FROM = {
					num_of_loans = 1
				}
			}
			export_to_variable = {
				variable_name = ai_value
				value = num_of_loans
			}			
			multiply_variable = {
				which = ai_value
				value = -20
			}
		}
		add_entry = {
			name = CANNOT_AFFORD
			limit = {
				FROM = {
					NOT = { years_of_income = 0.25 }
				}
			}
			export_to_variable = {
				variable_name = ai_value
				value = 1
			}
			
			multiply_variable = {
				which = ai_value
				value = -1000
			}
		}
		add_entry = {
			name = DOES_NOT_BENEFIT
			limit = {
				FROM = {
					has_estate_privilege = estate_nobles_mestnichestvo
				}
			}
			export_to_variable = {
				variable_name = ai_value
				value = 1
			}
			
			multiply_variable = {
				which = ai_value
				value = -1000
			}
		}
	}
}