## normal scopes(including posttitle scopes) ##
# ROOT = receiver
# FROM = giver
# <no scope change> = attacker or receiver
## title scopes ##
# ROOT = receiver
# FROM = giver
# <no scope change> = thirdparty landed title	
#
# the following effects/triggers exists (example execution order: on_success->on_success_title->on_success_posttitle):
# is_valid, is_valid_title, on_add, on_add_title, on_add_posttitle, on_success, on_success_title, on_success_posttitle, on_fail, on_fail_title, on_fail_posttitle, on_reverse_demand, on_reverse_demand_title, on_reverse_demand_posttitle
#
# Added on_attacker_leader_death, on_defender_leader_death and on_thirdparty_death, which all trigger when corresponding character dies
# These three all have war scopes, which currently has the following scope changes: 
# attacker, defender, thirdparty(only valid if thirdparty character is involved), thirdparty_title(only valid if thirdparty title is involved)
#
# ai_will_do: modifies value AI places on the CB compared to other CBs (default: 1) Note: is in title scope
# can_use_gui: If otherwise valid, the CB is listed in the Diplo View, but you can't declare war unless 'can_use_gui' is also valid (also shows a trigger tooltip.)
#
# Free the Love: Based on crusade

free_the_love = {
	name = FREE_THE_LOVE
	war_name = LOVE_FREEDOM
	sprite = 11
	truce_days = 365
	is_permanent = yes
	is_holy_war = yes
	can_ask_to_join_war = yes
	battle_warscore_mult = 0.5
	check_de_jure_tier = KING # this scans all de jure kingdoms for the counties which are held by or vassals(or below) of selected character. Only valid if is_permanent = yes
	
	can_use_gui = {
		ROOT = {
			religion_authority = 0.05
			religion_group = harem_group
		}
	}

	can_use = {
		ROOT = {
			religion_group = harem_group
		}
		FROM = {
			OR = {
				NOT = { religion_group = ROOT }
				is_heresy_of = ROOT
				is_parent_religion = ROOT
			}
		}
	}

	can_use_title = {
		FROM = {
			any_realm_title = {
				de_jure_liege_or_above = PREVPREV
			}
			
			independent = yes # Don't declare Crusades on revolters - chances are high the war will invalidate
			
			num_of_realm_counties = {
				value = 6
				title = PREV
			}
		}
	}
	
	is_valid = {
		FROM = {
			OR = {
				NOT = { religion_group = ROOT }
				is_heresy_of = ROOT
				is_parent_religion = ROOT
			}
		}
	}

	is_valid_title = {
		FROM = {
			any_realm_title = {
				de_jure_liege_or_above = PREVPREV
			}
		}
	}

	on_success_title = {
	
		# Should we give the seized land to its current king?
		if = {
			limit = {
				has_holder = yes
				holder_scope = {
					religion = ROOT
				}
			}
			holder_scope = {
				gain_settlements_under_title = {
					title = PREV
					enemy = FROM
					is_crusade = yes # Even if the title holder is not participating in the war, gain holdings occupied by all Crusade participants
					type = holy_war
				}
			}
		}
		
		# Should we give the seized land to a claimant of our faith?
		if = {
			limit = {
				OR = {
					has_holder = no
					holder_scope = {
						NOT = { religion = ROOT }
					}
				}
				
				best_crusade_claimant = {
					always = yes # There is a "best" claimant
				}
			}
			
			# Claimants must be of ROOT's religion, and are ranked by strength of claim and actual contribution to the war
			best_crusade_claimant = {
				gain_settlements_under_title = {
					title = PREV
					enemy = FROM
					is_crusade = yes # Even if the title holder is not participating in the war, gain holdings occupied by all Crusade participants
					type = holy_war
				}
				if  = {
					limit = {
						PREV = { has_holder = no }
						OR = {
							independent = yes
							is_ruler = no
							liege = {
								tier = EMPEROR
							}
						}
					}
					usurp_title = { target = PREV type = holy_war }
				}
			}
		}
		
		# Give the seized land to the main contributor of the Crusade
		if = {
			limit = {
				OR = {
					has_holder = no
					NOT = {
						holder_scope = {
							religion = ROOT
						}
					}
				}
				NOT = {
					best_crusade_claimant = {
						always = yes
					}
				}
			}
			most_participating_attacker = {
				gain_settlements_under_title = {
					title = PREV
					enemy = FROM
					type = holy_war
				}
				if  = {
					limit = {
						primary_title = { is_primary_type_title = no } # Mercs, the Pope, Holy Orders, etc
						PREV = { has_holder = no }
						NOT = { character = ROOT }
						OR = {
							independent = yes
							liege = {
								tier = EMPEROR
							}
						}
					}
					usurp_title = { target = PREV type = holy_war }
					
					if = {
						limit = {
							NOT = { culture = PREV }
						}
						hidden_tooltip = { conquest_culture = ROOT }
					}
				}
				hidden_tooltip = {
					if = {
						limit = {
							has_nickname = no
						}
						random_list = {
							15 = { give_nickname = nick_the_glorious }
							15 = { give_nickname = nick_the_lionheart }
							15 = { give_nickname = nick_the_great }
							15 = { give_nickname = nick_the_hammer }
							40 = { give_nickname = nick_the_liberator }
						}
					}
				}
			}
		}
		
		any_attacker = {
			limit = { character = ROOT }
			participation_scaled_prestige = 500
			participation_scaled_piety = 1000
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { 
				participation_scaled_prestige = 500
				participation_scaled_piety = 1000
			}
		}
		any_attacker = {
			limit = {
				ai = no
				NOT = { has_character_flag = achievement_crusader }
			}
			set_character_flag = achievement_crusader
		}
		
		ROOT = {
			religion_authority = {
				modifier = won_crusade
				years = 20
			}
		}
		
		FROM = {
			piety = -100
			religion_authority = {
				modifier = lost_crusade
				years = 20
			}			
		}
	}

	on_fail = {
		ROOT = {
			piety = -100
		}
		
		any_defender = {
			limit = { character = FROM }
			participation_scaled_piety = 200
			participation_scaled_prestige = 100
			if = {
				limit = {
					uses_decadence = yes
				}
				participation_scaled_decadence = -50
			}
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { 
				participation_scaled_piety = 200
				participation_scaled_prestige = 100
				if = {
					limit = {
						uses_decadence = yes
					}
					participation_scaled_decadence = -50
				}
			}
		}
		
		FROM = {
			if = {
				limit = { 
					has_dlc = "Legacy of Rome"
					OR = { 
						has_landed_title = e_byzantium
						has_landed_title = e_roman_empire
					}
					religion_group = christian
				}
				hidden_tooltip = { character_event = { id = LoR.30 days = 12 } }
			}
			
			hidden_tooltip = {
				if = {
					limit = {
						has_nickname = no
					}
					random_list = {
						10 = { give_nickname = nick_the_holy }
						10 = { give_nickname = nick_the_glorious }
						10 = { give_nickname = nick_the_lionheart }
						10 = { give_nickname = nick_the_great }
						10 = { give_nickname = nick_the_hammer }
						20 = {
							modifier = {
								factor = 0
								religion_group = christian
							}
							give_nickname = nick_the_sword_of_god
						}
					}
				}
			}
		}
	}

	on_reverse_demand = {
		ROOT = {
			piety = -200
			religion_authority = {
				modifier = lost_crusade
				years = 20
			}
		}
		FROM = {
			piety = 100
			religion_authority = {
				modifier = won_crusade
				years = 20
			}
		}
		any_defender = {
			limit = { character = FROM }
			participation_scaled_piety = 300
			participation_scaled_prestige = 150
			if = {
				limit = {
					uses_decadence = yes
				}
				participation_scaled_decadence = -100
			}
		}
		FROM = {
			if = {
				limit = { 
					has_dlc = "Legacy of Rome"
					OR = { 
						has_landed_title = e_byzantium
						has_landed_title = e_roman_empire
					}
					religion_group = christian
				}
				hidden_tooltip = { character_event = { id = LoR.30 days = 12 } }
			}
			hidden_tooltip = {
				if = {
					limit = {
						has_nickname = no
					}
					random_list = {
						10 = { give_nickname = nick_the_holy }
						10 = { give_nickname = nick_the_glorious }
						10 = { give_nickname = nick_the_lionheart }
						10 = { give_nickname = nick_the_great }
						10 = { give_nickname = nick_the_hammer }
						20 = {
							modifier = {
								factor = 0
								religion_group = christian
							}
							give_nickname = nick_the_sword_of_god
						}
					}
				}
			}
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { 
				participation_scaled_piety = 300
				participation_scaled_prestige = 150
				if = {
					limit = {
						uses_decadence = yes
					}
					participation_scaled_decadence = -100
				}
			}
		}
	}

	attacker_ai_victory_worth = {
		factor = -1 # always accept
	}
	
	attacker_ai_defeat_worth = {
		factor = 100
	}

	defender_ai_victory_worth = {
		factor = -1 # always accept
	}
	
	defender_ai_defeat_worth = {
		factor = 100
	}
}