# INSTRUCTIONS:
#
# condition				A diplomatic action can have any number of condition blocks, each with its own
#						tooltip, potential and allow section
#
# 	tooltip					Sets a custom text string similar to the hardcoded limits
# 							If no tooltip is scripted, the tooltip for the actual trigger will be shown
#							Note that the custom tooltip is only shown if the allow trigger is NOT met
#
# 	potential				Determines if the trigger is applicable or not
# 	allow					Determines if the action is valid or not
#
# effect				A diplomatic action can only have one effect block

# ROOT					actor
# FROM					target

########################################
# DIPLOMATIC ACTIONS
########################################
# royal_marriage
# declarewar
# requestpeace
# support_independence_action
# allianceaction
# embargoaction
# annexationaction
# integrationaction
# vassalaction
# guaranteeaction
# warningaction
# threaten_war
# milaccess
# fleet_access
# offer_fleet_access
# offermilaccess
# insultaction
# giftaction
# claimaction
# callaction
# offerloan
# warsubsidy
# sellprov
# imperial_relations_action
# imperial_realm_war_action
# religious_unity_action
# grant_electorate
# remove_electorate
# grant_freecity
# remove_freecity
# demand_unlawful_territory_action
# call_crusade_action
# excommunicate_action
# enforce_peace
# improve_relation
# fabricate_claim
# justify_trade_conflict
# transfer_trade_power
# infiltrate_administration
# sabotage_reputation
# support_rebels
# sow_discontent
# agitate_for_liberty
# form_coalition
# request_to_join_federation
# invite_to_federation
# support_heir
# break_marriage
# designate_march
# ask_for_march
# sell_ships_action
# abandon_union
# takeondebt
# influence_nation
# claim_states
# steer_trade
# stealmap
# spy_network
# invite_to_trade_league
# request_to_join_trade_league
# sharemap
# intervene_in_war
# break_alliance
# tributary_state_action
# ask_for_tributary_state_action
# knowledge_sharing


#Cut because the Grand Crusade war doesn't really have any place in the current content, but it could be very useful for the future.
#Also modders should have the chance to just uncomment it all so they can experience the great 30 Years War like Crusade.
joinwar = {
	condition = {
		tooltip = GRAND_CRUSADE_NO_OTHER_WAR
		potential = { }
		allow = {
			AND = {
				any_country = {
					OR = {
						is_in_war = {
							defender_leader = FROM
						}
						is_in_war = {
							attacker_leader = FROM
						}
						is_rival
						is_enemy
					}
					NOT = {
						has_opinion = {
							who = ROOT
							value = 0
						}
					}
				}
				FROM = {
					has_opinion = {
						who = ROOT
						value = 100
					}
				}
			}
			ROOT = {
				is_at_war = no
			}
		}
	}
}
declarewar = {
	#condition = {
	#	tooltip = GRAND_CRUSADE_NO_OTHER_WAR
	#	potential = { }
	#	allow = {
	#		NOT = {
	#			is_in_war = {
	#				attacker_leader = ROOT
	#				casus_belli = cb_grand_crusade
	#			}
	#		}
	#	}
	#}
	#effect = {
	#	if = {
	#		limit = {
	#			has_global_flag = grand_crusades_enabled
	#			has_country_flag = grand_crusader_war_monger_flag
	#			is_in_war = {
	#				attacker_leader = ROOT
	#				casus_belli = cb_grand_crusade
	#			}
	#		}
	#		FROM = {
	#			save_global_event_target_as = grand_crusade_target
	#		}
	#	}
	#}
	condition = {
		tooltip = AI_CANNOT_DECLARE_WHEN_STABILITY_LOSS
		potential = {
			ai = yes
		}
		allow = {
			ai = yes
			NOT = {
				has_global_modifier_value = {
					which = stability_cost_to_declare_war
					value = 1
				}
			}
		}
	}
	condition = {
		tooltip = CANNOT_DECLARE_WARS_OTHER_THAN_INDEPENDENCE_WARS
		potential = {
			has_country_modifier = revoked_war_rights
			FROM = { NOT = { overlord_of = ROOT } }
		}
		allow = {
			OR = {
				NOT = { has_country_modifier = revoked_war_rights }
				FROM = { overlord_of = ROOT }
			}
		}
	}
	condition = {
		tooltip = CANNOT_DECLARE_WARS_TEUTONS_HRE
		potential = {
			ai = yes 
			has_country_flag = teu_joined_the_hre
			FROM = { is_part_of_hre = yes }
		}
		allow = { 
			FROM = { is_part_of_hre = no }
		}
	}
	effect = {
		on_war_declaration_effect = yes
		if = {
			limit = { 
				has_country_flag = nor_norwegian_independence_modifier
				FROM = { tag = DAN }
			}
			add_country_modifier = {
				name = nor_norwegian_independence_war_mod
				duration = -1
			}
		}
		if = {
			limit = {
				has_country_flag = teu_joined_the_hre
				tag = TEU
				is_part_of_hre = yes
				FROM = { is_part_of_hre = yes }
			}
			clr_country_flag = teu_joined_the_hre
			country_event = {
				id = flavor_teu.33
				days = 10
			}
		}
	}
}

allianceaction = {
	condition = {
		tooltip = PIRATE_DENIED_ALLIANCE
		potential = {
			has_government_attribute = cannot_ally_non_pirates
		}
		allow = {
			OR = {
				NOT = { has_government_attribute = cannot_ally_non_pirates }
				FROM = { has_government_attribute = is_pirate_republic_reform }
			}
		}
	}
	condition = {
		tooltip = FROM_PIRATE_DENIED_ALLIANCE
		potential = {
			FROM = {
				has_government_attribute = cannot_ally_non_pirates
			}
			NOT = { has_government_attribute = is_pirate_republic_reform }
		}
		allow = {
			OR = {
				has_government_attribute = is_pirate_republic_reform
				NOT = { FROM = { has_government_attribute = cannot_ally_non_pirates } }
			}
		}
	}
	condition = {
		tooltip = REPUBLIC_DENIED_ALLIANCE
		potential = {
			has_government_attribute = cannot_ally_non_republics
		}
		allow = {
			OR = {
				NOT = { has_government_attribute = cannot_ally_non_republics }
				FROM = { government = republic }
			}
		}
	}
	condition = {
		tooltip = FROM_REPUBLIC_DENIED_ALLIANCE
		potential = {
			FROM = {
				has_government_attribute = cannot_ally_non_republics
			}
			NOT = { government = republic }
		}
		allow = {
			OR = {
				government = republic
				NOT = { FROM = { has_government_attribute = cannot_ally_non_republics } }
			}
		}
	}
	condition = {
		tooltip = REV_REPUBLIC_DENIED_ALLIANCE
		potential = {
			has_government_attribute = cannot_ally_non_republics_or_non_rev
		}
		allow = {
			OR = {
				NOT = { has_government_attribute = cannot_ally_non_republics_or_non_rev }
				FROM = { 
					OR = {
						government = republic 
						is_revolutionary = yes
					}
				}
			}
		}
	}
	condition = {
		tooltip = FROM_REV_REPUBLIC_DENIED_ALLIANCE
		potential = {
			FROM = {
				has_government_attribute = cannot_ally_non_republics_or_non_rev
			}
			NOT = { government = republic }
			is_revolutionary = no
		}
		allow = {
			OR = {
				government = republic 
				is_revolutionary = yes
				NOT = { FROM = { has_government_attribute = cannot_ally_non_republics_or_non_rev } }
			}
		}
	}
	condition = {
		tooltip = CANNOT_MAKE_ALLIANCES
		potential = {
			has_government_attribute = cannot_form_alliances
		}
		allow = {
			NOT = { has_government_attribute = cannot_form_alliances }
		}
	}
	condition = {
		tooltip = FROM_CANNOT_MAKE_ALLIANCES
		potential = {
			FROM = {
				has_government_attribute = cannot_form_alliances
			}
		}
		allow = {
			NOT = { FROM = { has_government_attribute = cannot_form_alliances } }
		}
	}
}

enforce_peace = {
	#do this before the peace is enforced, or there is no war enemy country
	pre_effect = {
		if = {
			limit = {
				has_country_modifier = liv_protector_of_the_catholics
				FROM = {
					any_war_enemy_country = {
						religion = catholic
						is_in_war = {
							defender_leader = THIS
							attacker_leader = FROM
						}
					}
				}
			}
			add_papal_influence = 25
		}
	}
}

royal_marriage = {
	condition = {
		tooltip = MARWAR
		potential = {
		}
		allow = {
			NOT = { war_with = FROM }
		}
	}
}

annexationaction = {
	condition = {
		tooltip = ANNEX_TOO_LOW
		potential = {
			FROM = {
				OR = {
					is_subject_of_type = core_eyalet
					is_subject_of_type = appanage
					vassal_of = ROOT
				}
			}
		}
		allow = {
			FROM = {
				has_opinion = {
					who = ROOT
					value = 190
				}
			}
		}
	}
	#condition = {
	#	tooltip = ANNEXINVALID
	#	potential = {
	#		FROM = {
	#			vassal_of = ROOT
	#		}
	#	}
	#	allow = {
	#		FROM = {
	#			years_in_vassalage_under = {
	#				who = ROOT
	#				years = 10
	#			}
	#		}
	#	}
	#}
	condition = {
		tooltip = CANNOT_ANNEX
		potential = {
			FROM = {
				has_country_modifier = tur_mamlukian_administration
			}
		}
		allow = {
			FROM = {
				NOT = { has_country_modifier = tur_mamlukian_administration }
			}
		}
	}
	condition = {
		tooltip = NEEDS_50_CROWNLAND_TT
		potential = {
			has_government_attribute = need_crownland_to_annex
			NOT = { crown_land_share = 50 }
		}
		allow = {
			crown_land_share = 50
		}
	}
	condition = {
		tooltip = NEEDS_TO_HAVE_SEIZED_LAND
		potential = {
			has_government_attribute = has_appanages
			NOT = {
				check_variable = {
					which = can_annex_appanages_points
					value = 1
				}
			}
		}
		allow = {
			check_variable = {
				which = can_annex_appanages_points
				value = 1
			}
		}
	}
	effect = {
		if = {
			limit = {
				FROM = { is_subject_of_type = appanage }
			}
			subtract_variable = {
				which = can_annex_appanages_points
				value = 1
			}
		}
	}
}

integrationaction = {
	condition = {
		tooltip = INTEGRATETOOLOWDESC
		potential = {
			senior_union_with = FROM
		}
		allow = {
			FROM = {
				has_opinion = {
					who = ROOT
					value = 190
				}
			}
		}
	}
	condition = {
		tooltip = PUINTEGRATIONIMPOSSIBLE
		potential = {
			has_government_attribute = cannot_integrate_personal_unions
		}
		allow = {
			NOT = { has_government_attribute = cannot_integrate_personal_unions }
		}
	}
	condition = {
		tooltip = CANNOT_ANNEX
		potential = {
			FROM = {
				has_country_modifier = tur_mamlukian_administration
			}
		}
		allow = {
			FROM = {
				NOT = { has_country_modifier = tur_mamlukian_administration }
			}
		}
	}
}

vassalaction = {
	condition = {
		tooltip = VASSALINVALID
		potential = {
		}
		allow = {
			alliance_with = FROM
			FROM = {
				has_opinion = {
					who = ROOT
					value = 190
				}
			}
			FROM = { is_at_war = no }
		}
	}
}

abandon_union = {
	condition = {
		potential = {
		}
		allow = {
			ROOT = {
				senior_union_with = FROM
				is_at_war = no
			}
		}
	}
	condition = {
		tooltip = PUABANDONINGIMPOSSIBLE
		potential = {
			has_government_attribute = cannot_abandon_personal_unions
		}
		allow = {
			NOT = { has_government_attribute = cannot_abandon_personal_unions }
		}
	}
}

form_coalition = {
	condition = {
		tooltip = MINAGGRESSIVEEXPANSION
		potential = {	
		}
		allow = {
			has_opinion_modifier = {
				modifier = aggressive_expansion
				who = FROM
			}		
			NOT = {
				has_opinion_modifier = {
					modifier = aggressive_expansion
					who = FROM
					value = -49
				}
			}
		}
	}
}

request_to_join_trade_league = {
	condition = {
		tooltip = NOT_RELEVANT_TRADE_REGION_FROM
		potential = {
		}
		allow = {
			home_trade_node = {
				trade_share = {
					country = from
					share = 1
				}
			}
		}
	}
}

invite_to_trade_league = {
	condition = {
		tooltip = NOT_RELEVANT_TRADE_REGION
		potential = {
		}
		allow = {
			from = {
				home_trade_node = {
					trade_share = {
						country = root
						share = 1
					}
				}
			}
		}
	}
}

tributary_state_action = {
	condition = {
		potential = {
			ai = yes
		}
		allow = {
			OR = {
				NOT = { ROOT = { capital_scope = { superregion = china_superregion } } }
				AND = {
					ROOT = { capital_scope = { superregion = china_superregion } }
					NOT = { FROM = { capital_scope = { superregion = china_superregion } } }
				}
			}
			OR = {
				NOT = { ROOT = { capital_scope = { region = japan_region } } }
				AND = {
					ROOT = { capital_scope = { region = japan_region } }
					NOT = { FROM = { capital_scope = { region = japan_region } } }
				}
			}
		}
	}
}
ask_for_tributary_state_action = {
	condition = {
		potential = {
			ai = yes
		}
		allow = {
			OR = {
				NOT = { FROM = { capital_scope = { superregion = china_superregion } } }
				AND = {
					FROM = { capital_scope = { superregion = china_superregion } }
					NOT = { ROOT = { capital_scope = { superregion = china_superregion } } }
				}
			}
			OR = {
				NOT = { FROM = { capital_scope = { region = japan_region } } }
				AND = {
					FROM = { capital_scope = { region = japan_region } }
					NOT = { ROOT = { capital_scope = { region = japan_region } } }
				}
			}
		}
	}
}

break_alliance = {
	effect = {
		on_alliance_broken_effect = yes
	}
}