﻿### EK NOTE: Dynamic religious hostility

suggestion_recruit_maa = {
	weight = {
		base = 0

		modifier = { # Is the suggestion available at all?
			add = 0.5
			number_of_maa_regiments < recommended_num_maa_regiments_value
			trigger_if = {
				limit = { government_has_flag = government_is_tribal }
				prestige >= 150 # Cost of Archers for tribal rulers, a good middle-of-the-road MaA unit.
			}
			trigger_if = {
				limit = { NOT = { government_has_flag = government_is_tribal} }
				gold >= 75 # Cost of Archers for non-trbal rulers, a good middle-of-the-road MaA unit.
			}
		}

		modifier = { # Much more likely if you have no men-at-arms at all
			add = 1
			number_of_maa_regiments = 0
		}

		modifier = { # More likely if you have a lot of extra money
			add = 0.5
			trigger_if = {
				limit = { government_has_flag = government_is_tribal }
				prestige >= 300 # Cost of some elite men-at-arms for tribal rulers
			}
			trigger_if = {
				limit = { NOT = { government_has_flag = government_is_tribal} }
				gold >= 150 # Cost of some elite men-at-arms for tribal rulers
			}
		}
	}

	check_create_suggestion = {
		try_create_suggestion = {
			suggestion_type = suggestion_recruit_maa
		}
	}

	effect = {
		open_view = military
	}

	is_valid = {
		number_of_maa_regiments < recommended_num_maa_regiments_value # Still under the recommended regiment count.
		trigger_if = {
			limit = { government_has_flag = government_is_tribal }
			prestige >= 150 # Cost of Archers for tribal rulers, a good middle-of-the-road MaA unit.
		}
		trigger_if = {
			limit = { NOT = { government_has_flag = government_is_tribal} }
			gold >= 75 # Cost of Archers for non-trbal rulers, a good middle-of-the-road MaA unit.
		}
	}
}
 
suggestion_declare_war = {
	weight = {
		base = 0

		modifier = { #Is the suggestion available at all?
			add = 1
			any_neighboring_and_across_water_top_liege_realm_owner = {
				root = {
					# Must have a valid CB.
					has_any_cb_on = prev
					
					# Can be suggested at most for rulers 1 tier above (e.g., Counts can have Dukes suggested, but never Kings.)
					tier_difference = {
						target = prev
						value >= -1
					}

					# Must not be allied to or have truce with recipient.
					NOR = {
						is_allied_to = prev
						has_truce = prev
					}

					# Not in an activity 
					NOT = { exists = involved_activity }
				}			
			}
		}

		modifier = { #More likely if you have a de jure claim
			add = 0.5
			any_de_jure_claim = {
				holder = { any_neighboring_and_across_water_top_liege_realm_owner = { this = root } }
				holder.top_liege = {
					root = {
						has_any_cb_on = prev
							tier_difference = {
							target = prev
							value >= -1
						}
						NOR = {
							is_allied_to = prev
							has_truce = prev
						}
					}
				}
			}
		}

		modifier = { #Less likely if you're at war
			add = -0.75
			is_at_war = yes
		}

		modifier = { #Less likely if they're possibly stronger than you
			add = -0.5
			any_neighboring_and_across_water_top_liege_realm_owner = {
				current_military_strength < root.current_military_strength
				root = {
					# Must have a valid CB.
					has_any_cb_on = prev
					
					# Can be suggested at most for rulers 1 tier above (e.g., Counts can have Dukes suggested, but never Kings.)
					tier_difference = {
						target = prev
						value >= -1
					}

					# Must not be allied to or have truce with recipient.
					NOR = {
						is_allied_to = prev
						has_truce = prev
					}
				}			
			}
		}
	}

	check_create_suggestion = {
		every_neighboring_and_across_water_top_liege_realm_owner = {
			limit = {
				root = {
					# Must have a valid CB.
					has_any_cb_on = prev
					
					# Can be suggested at most for rulers 1 tier above (e.g., Counts can have Dukes suggested, but never Kings.)
					tier_difference = {
						target = prev
						value >= -1
					}

					# Must not be allied to or have truce with recipient.
					NOR = {
						is_allied_to = prev
						has_truce = prev
					}

					# Not in an activity 
					NOT = { exists = involved_activity }
				}
			}
			try_create_suggestion = {
				suggestion_type = suggestion_declare_war
				actor = root
				recipient = this
			}
		}			
	}

	effect = {
		open_interaction_window = {
			interaction = declare_war_interaction
			actor = scope:actor
			recipient = scope:recipient
		}
	}

	score = {
		modifier = {
			add = {
				# Base Score
				value = 100

				##################################################################################################################################################################
				# Adds between 100-625 Score depending on the highest-tier title you have a claim for. Stacks if the appropriate innovation is unlocked.
				if = {
					# Can press multiple claims at once, adds strength of all claims together.
					limit = {
						scope:actor = {
							culture = {
								has_innovation = innovation_divine_right
							}
						}
					}
					scope:actor = {
						every_claim = {
							limit = {
								tier >= tier_county
								holder.top_liege = scope:recipient
							}
							add = { # Counties 100, Duchies 225, Kingdoms 400, Empires 625
								add = tier
								multiply = tier
								multiply = 25
				
								# Reduced score for claims on foreign land (you will need to invest in converting it's culture).
								if = {
									limit = {
										title_capital_county.culture = scope:actor.culture
									}
									multiply = 1
								}
								else_if = {
									limit = {
										title_capital_county.culture = { has_same_culture_heritage = scope:actor.culture }
									}
									multiply = 0.75
								}
								else = {
									multiply = 0.5
								}
							}
						}
					}
				}
				else = {
					# Can only press one claim at a time, adds strength of highest-valued claim.
					scope:actor = {
						ordered_claim = {
							limit = {
								tier >= tier_county
								holder.top_liege = scope:recipient
								exists = title_capital_county.culture
							}
							max = 1
							order_by = {
								add = tier
								multiply = 10
								if = {
									limit = {
										NOT = {
											title_capital_county.culture = scope:actor.culture
										}
									}
									add = -2
								}
								if = {
									limit = {
										NOT = {
											title_capital_county.culture = { has_same_culture_heritage = scope:actor.culture }
										}
									}
									add = -5
								}
							}
							add = { # County 100, Duchy 225, Kingdom 400, Empire 625
								add = tier
								multiply = tier
								multiply = 25
							}
								
							# Reduced score for claims on foreign land (you will need to invest in converting it's culture).
							if = {
								limit = {
									title_capital_county.culture = scope:actor.culture
								}
								multiply = 1
							}
							else_if = {
								limit = {
									title_capital_county.culture = { has_same_culture_heritage = scope:actor.culture }
								}
								multiply = 0.75
							}
							else = {
								multiply = 0.5
							}				
						}
					}
				}

				# Scoring for De Jure claims
				scope:actor = {
					add = {
						every_de_jure_claim = {
							limit = {
								holder.top_liege = scope:recipient
							}
							add = tier
						}
					}
				}

				# Is the target your religious head? Then chill a bit
				scope:actor = {
					add = {
						every_claim = {
							limit = {
								holder.top_liege = scope:recipient
								scope:actor.faith.religious_head = scope:recipient
							}
							add = -100
						}
					}
				}

				#Less likely if they're stronger than you
				if = {
					limit = {
						scope:actor.current_military_strength > scope:recipient.current_military_strength
					}
					add = -50
				}
				

				#Higher development, higher chance
				scope:actor = {
					add = {
						every_claim = {
							limit = {
								exists = title_capital_county
								holder.top_liege = scope:recipient
								title_capital_county = {
									development_level > medium_development_level
								}
							}
							add = development_level
						}
					}
				}

				# Multiplies the whole thing by the ratio of each ruler's military strength.
				multiply = {
					add = 1
					add = scope:actor.current_military_strength
					divide = {
						add = 1 # No division by zero!
						add = scope:recipient.current_military_strength
					}
					min = 0.25
					max = 4.0
				}
			}
		}
	}

	is_valid = {
		scope:actor = {
			has_any_cb_on = scope:recipient
			NOR = {
				is_at_war = yes
				is_allied_to = scope:recipient
				has_truce = scope:recipient
			}
			# Not in an activity 
			NOT = { exists = involved_activity }
			gold >= 0
		}
	}
}

suggestion_construct_building = {

	weight = {
		base = 0

		modifier = { #Is the suggestion available at all?
			add = 0.5
			any_directly_owned_province = {
				has_free_building_slot = yes
			}
		}

		modifier = { #Less likely if you're at war
			add = -0.75
			is_at_war = yes
		}

		modifier = { #Less likely if you're bankrupt
			add = -0.75
			gold < 0
		}

		modifier = { #Less likely if you've built a lot
			add = -0.25
			any_directly_owned_province = {
				free_building_slots < 2
			}
		}
		modifier = { #More likely if you haven't built a lot
			add = 0.25
			any_directly_owned_province = {
				free_building_slots > 2
			}
		}
	}

	check_create_suggestion = {
		every_directly_owned_province = {
			limit = {
				has_free_building_slot = yes
			}

			try_create_suggestion = {
				suggestion_type = suggestion_construct_building
				landed_title = barony
			}
		}
	}
	effect = {
		scope:landed_title.title_province = {
			open_view_data = {
				view = holding_view
			}
		}
	}

	score = {
		base = 100
		modifier = {
			add = {
				# Scaling score based on development level.
				add = scope:landed_title.county.development_level

				# Multiplier for provinces of a different culture
				if = {
					limit = {
						root.culture = scope:landed_title.culture
					}
					multiply = 1.00
				}
				else_if = {
					limit = {
						root.culture = { has_same_culture_heritage = scope:landed_title.culture }
					}
					multiply = 0.80
				}
				else = {
					multiply = 0.50
				}

				# Multiplier for provinces of a different faith
				if = {
					limit = {
						root.faith = scope:landed_title.faith
					}
					multiply = 1.00
				}
				else_if = {
					limit = {
						root.religion = scope:landed_title.religion
					}
					multiply = 0.80
				}
				else = {
					multiply = 0.50
				}


				# Extra score for the player's Capital.
				if = {
					limit = {
						root.capital_barony = scope:landed_title
					}
					add = 25
				}

				#Extra score for un-developed provinces
				if = {
					limit = {
						scope:landed_title.title_province = { free_building_slots > 1 }
					}
					if = {
						limit = {
							scope:landed_title.title_province = { free_building_slots >= 5 }
						}
						add = 20
					}
					else_if = {
						limit = {
							scope:landed_title.title_province = { free_building_slots >= 3 }
						}
						add = 10
					}
					else = {
						add = 5
					}
				}
			}
		}
	}

	is_valid = {
		scope:landed_title.title_province = {
			has_ongoing_construction = no
			has_free_building_slot = yes
		}
	}	
}

### EK EDIT: Using script values for religious hostility
suggestion_fabricate_claim = {

	weight = {
		base = 0

		modifier = { #Is the suggestion available at all?
			add = 0.75
			any_character_to_title_neighboring_county = {
				exists = this
				save_temporary_scope_as = this_title
				root = {
					NOT = { has_claim_on = scope:this_title } # We do not already have a claim on this county.
					NOT = {
						any_claim = {
							is_de_jure_liege_or_above_target = scope:this_title # We do not already have a claim on a title which includes this county.
						}
					}
					NOT = {						
						any_held_title = {
							is_de_jure_liege_or_above_target = scope:this_title # County does not already belong to us De Jure (because then we already have a CB for it).
						}
					}
					NOT = {
						faith = {
							faith_hostility_level = {
								target = scope:this_title.holder.top_liege.faith
								value >= faith_hostile_level # Holy Wars generally allowed in this case, so we don't need to fabricate.
							}
						}
					}
					NOR = {
						# Don't fabricate claims on our allies!
						is_allied_to = scope:this_title.holder
						is_allied_to = scope:this_title.holder.top_liege
					}
				}
			}
		}

		modifier = { #Less likely if chaplain is already fabricating another claim
			add = -0.5
			exists = cp:councillor_court_chaplain
			cp:councillor_court_chaplain = {
				is_performing_council_task = task_fabricate_claim
			}
		}

		modifier = { #More likely if you don't have any claims
			add = 0.5
			any_claim = {
				count < 1
			}
		}

		modifier = { #Less likely if you have many claims
			add = -0.75
			any_claim = {
				count >= 5
			}
		}
	}

	check_create_suggestion = {
		every_character_to_title_neighboring_county = {
			limit = {
				exists = this
				save_temporary_scope_as = this_title
				root = {
					NOT = { has_claim_on = scope:this_title } # We do not already have a claim on this county.
					NOT = {
						any_claim = {
							is_de_jure_liege_or_above_target = scope:this_title # We do not already have a claim on a title which includes this county.
						}
					}
					NOT = {						
						any_held_title = {
							is_de_jure_liege_or_above_target = scope:this_title # County does not already belong to us De Jure (because then we already have a CB for it).
						}
					}
					NOT = {
						faith = {
							faith_hostility_level = {
								target = scope:this_title.holder.top_liege.faith
								value >= faith_hostile_level # Holy Wars generally allowed in this case, so we don't need to fabricate.
							}
						}
					}
					NOR = {
						# Don't fabricate claims on our allies!
						is_allied_to = scope:this_title.holder
						is_allied_to = scope:this_title.holder.top_liege
					}
				}
			}
			try_create_suggestion = {
				suggestion_type = suggestion_fabricate_claim
				landed_title = this
			}
		}
	}

	effect = {
		scope:landed_title = {
			open_view_data = {
				view = title_view_window
			}
		}
	}

	score = {
		base = 100
		modifier = {
			add = {
				scope:landed_title = {
					add = development_level # Adds between 0 and 100 points, based on development level.
				}

				if = {
					limit = {
						scope:landed_title = {
							title_province = {
								OR = {
									terrain = oasis
									terrain = farmlands
									terrain = floodplains
								}
							}
						}
					}
					add = 25 # Bonus for high-potential terrains.
				}
				else_if = {
					limit = {
						scope:landed_title = {
							title_province = {
								OR = {
									terrain = hills
									terrain = forest
									terrain = taiga
								}
							}
						}
					}
					add = -100
					add = scope:landed_title.development_level
					multiply = 0.1 # Up to a -10 penalty for 'undeveloped' provinces of this type, due to the difficulty of increasing development there.
				}
				else_if = {
					limit = {
						scope:landed_title = {
							title_province = {
								OR = {
									terrain = desert
									terrain = wetlands
									terrain = steppe
								}
							}
						}
					}
					add = -100
					add = scope:landed_title.development_level
					multiply = 0.25 # Up to a -25 penalty for 'undeveloped' provinces of this type, due to the difficulty of increasing development there.
				}
				else_if = {
					limit = {
						scope:landed_title = {
							title_province = {
								OR = {
									terrain = mountains
									terrain = desert_mountains
									terrain = jungle
								}
							}
						}
					}
					add = -100
					add = scope:landed_title.development_level
					multiply = 0.5 # Up to a -50 penalty for 'undeveloped' provinces of this type, due to the great difficulty of increasing development there.
				}

				# Multiplier for provinces of a different culture
				if = {
					limit = {
						root.culture = scope:landed_title.title_province.culture
					}
					multiply = 1.00
				}
				else_if = {
					limit = {
						root.culture = { has_same_culture_heritage = scope:landed_title.title_province.culture }
					}
					multiply = 0.90
				}
				else = {
					multiply = 0.75
				}

				# Multiplier for provinces of a different faith
				if = {
					limit = {
						root.faith = scope:landed_title.title_province.faith
					}
					multiply = 1.00
				}
				else_if = {
					limit = {
						root.religion = scope:landed_title.title_province.religion
					}
					multiply = 0.90
				}
				else = {
					multiply = 0.75
				}

				#A lot of buildings?
				if = {
					limit = {
						scope:landed_title.title_province = { num_buildings > 1 }
					}
					add = {
						add = scope:landed_title.title_province.num_buildings
						multiply = 5
					}
				}

				#Any special buildings?
				if = {
					limit = {
						scope:landed_title.title_province = { has_special_building = yes }
					}
					add = 25
				}

				###################################################################################
				# Modify total score based on how easy it will be to conquer once we have the CB. #
				###################################################################################
				if = {
					# If it's in another realm, compare our military strength to the top liege's strength (Denmark should avoid fabricating a claim on the HRE!).
					limit = {
						NOT = { root.top_liege = scope:landed_title.holder.top_liege }
					}
					multiply = {
						add = 1
						add = root.current_military_strength
						divide = {
							add = 1 # No division by zero!
							add = scope:landed_title.holder.top_liege.current_military_strength
						}
						min = 0.75
						max = 1.5
					}
				}
				else = {
					# Otherwise, just compare it to the holder's direct military strength (not perfectly accurate since they can still have a liege to protect them, but it's close enough).
					multiply = {
						add = 1
						add = root.current_military_strength
						divide = {
							add = 1 # No division by zero!
							add = scope:landed_title.holder.current_military_strength
						}
						min = 0.75
						max = 1.5
					}
				}				
			}	
		}
	}

	is_valid = {
		# We do not already have a claim on this county.
		NOT = { has_claim_on = scope:landed_title }

		# Not already fabricating this claim.
		trigger_if = {
			limit = {
				exists = root.cp:councillor_court_chaplain
				root.cp:councillor_court_chaplain = { is_performing_council_task = task_fabricate_claim }
			}
			root.cp:councillor_court_chaplain = {
				NOT = { councillor_task_target = scope:landed_title.title_province }
			}
		}
	}
}

suggestion_create_title = {

	weight = {
		base = 0

		modifier = { #Is the suggestion available at all?
			add = 0.75
			any_alert_creatable_title = {
				count >= 1
			}
		}

		modifier = { #Less likely if you're at war
			add = -0.5
			is_at_war = yes
		}

		modifier = { #Less likely if you're bankrupt
			add = -0.75
			gold < 0
		}
	}

	check_create_suggestion = {
		every_alert_creatable_title = {
			try_create_suggestion = {
				suggestion_type = suggestion_create_title
				landed_title = this
			}
		}
	}

	effect = {
		scope:landed_title = {
			open_view_data = {
				view = title_view_window
			}
		}
	}

	score = {
		base = -200 # Since all titles will gain points based on tier.
		modifier = {
			add = {
				# Score based on title tier (higher tiered titles worth more).
				scope:landed_title = {
					add = tier
					multiply = 100 # Duchies = 100 base, Kingdoms 200, Empires 300.
				}

				# Additional points if player currently has any vassals who are the De Jure vassal of this title.
				root = {
					every_vassal = {
						limit = {
							primary_title = {
								target_is_de_jure_liege_or_above = scope:landed_title
							}
						}
						add = {
							add = highest_held_title_tier
							multiply = 10
						}
					}
				}

				# Also additional points if it would give the player De Jure CBs.
				scope:landed_title = {
					every_de_jure_county_holder = {
						limit = {
							NOT = { target_is_liege_or_above = root }
						}
						add = 20
					}
				}

				# Reduced score for stacking duchies.
				if = {
					limit = {
						root = {
							highest_held_title_tier >= tier_kingdom
						}
						scope:landed_title = {
							tier = tier_duchy
						}
					}
					add = 150
					root = {
						every_held_title = {
							limit = {
								tier = tier_duchy
							}

							# Since Kings and Emperors get penalties for having too many duchies, this modifies the suggestion score for making new duchies if you already have a lot.
							# 250 at 0 duchies, 150 at 1, 50 at 2, -50 at 3, -150 at 4, etc.
							# Once you have 3+ duchies it will stop suggesting them unless there is a clear benefit, and at 4+ it usually stops suggesting them entirely.
							add = -100
						}
					}
				}
			}
		}
	}

	is_valid = {
		scope:landed_title = {
			is_title_created = no
		}
	}
}


suggestion_convert_county = {

	weight = {
		base = 0

		modifier = { #Is the suggestion available at all?
			add = 0.75

			any_sub_realm_title = {
				tier = tier_county
				title_province = {
					NOT = { faith = root.faith }
					trigger_if = { #chaplain is not already converting the county
						limit = {
							exists = root.cp:councillor_court_chaplain
							root.cp:councillor_court_chaplain = {
								is_performing_council_task = task_conversion
							}
						}
						root.cp:councillor_court_chaplain = {
							NOT = { councillor_task_target = prev }
						}
					}
				}
			}
		}

		modifier = { #More likely if it's your capital province
			add = 0.5
			any_sub_realm_title = {
				tier = tier_county
				title_province = {
					NOT = { faith = root.faith }
					this = root.capital_province
					trigger_if = { #chaplain is not already converting the county
						limit = {
							exists = root.cp:councillor_court_chaplain
							root.cp:councillor_court_chaplain = {
								is_performing_council_task = task_conversion
							}
						}
						root.cp:councillor_court_chaplain = {
							NOT = { councillor_task_target = prev }
						}
					}
				}
			}
		}

		modifier = { #More likely if there's a faction against you
			add = 0.25
			any_sub_realm_title = {
				tier = tier_county
				title_province = {
					NOT = { faith = root.faith }
					trigger_if = { #chaplain is not already converting the county
						limit = {
							exists = root.cp:councillor_court_chaplain
							root.cp:councillor_court_chaplain = {
								is_performing_council_task = task_conversion
							}
						}
						root.cp:councillor_court_chaplain = {
							NOT = { councillor_task_target = prev }
						}
					}
				}
				save_temporary_scope_as = county_check
				root = {
					any_targeting_faction = {
						faction_is_type = peasant_faction
						any_faction_county_member = {
							NOT = { this.title_province.faith = root.faith }
							this = scope:county_check
						}
					}
				}
			}
		}
	}

	check_create_suggestion = {
		
		every_sub_realm_title = {
			limit = {
				tier = tier_county
				title_province = {
					NOT = { faith = root.faith }
					trigger_if = { #chaplain is not already converting the county
						limit = {
							exists = root.cp:councillor_court_chaplain
							root.cp:councillor_court_chaplain = {
								is_performing_council_task = task_conversion
							}
						}
						root.cp:councillor_court_chaplain = {
							NOT = { councillor_task_target = prev }
						}
					}
				}
			}

			try_create_suggestion = {
				suggestion_type = suggestion_convert_county
				landed_title = this
			}
		}
	}

	effect = {
		open_view_data = {
			view = council_window
		}
		pan_camera_to_title = scope:landed_title
	}

	score = {
		base = 100
		modifier = {
			add = {
				# Scaling score based on development level.
				scope:landed_title = {
					add = development_level
				}

				# Extra score for the player's Capital Province.
				if = {
					limit = {
						root.capital_province = scope:landed_title.title_province
					}
					add = 25
				}

				#Faction?
				if = {
					limit = {
						root = {
							any_targeting_faction = {
								faction_is_type = peasant_faction
								any_faction_county_member = {
									NOT = { this.title_province.faith = root.faith }
									this = scope:landed_title
								}
							}
						}
					}
					add = 50
				}
			}
		}
	}

	is_valid = {
		scope:landed_title = {
			holder.top_liege = root
			NOT = { faith = root.faith }
		}
		trigger_if = {
			limit = {
				exists = root.cp:councillor_court_chaplain
				root.cp:councillor_court_chaplain = {
					is_performing_council_task = task_conversion
				}
			}
			root.cp:councillor_court_chaplain = {
				NOT = { councillor_task_target = scope:landed_title.title_province }
			}
		}
	}
}


suggestion_increase_control = {

	weight = {
		base = 0

		modifier = { #Is the suggestion available at all?
			add = 0.75

			any_sub_realm_title = {
				tier = tier_county
				OR = {
					has_county_corruption_trigger = yes
					county_control < full_county_control
				}
				trigger_if = { #marshal is not already converting the county
					limit = {
						exists = root.cp:councillor_marshal
						root.cp:councillor_marshal = {
							is_performing_council_task = task_increase_control
						}
					}
					title_province = {
						root.cp:councillor_marshal = {
							NOT = { councillor_task_target = prev }
						}
					}
				}
			}
		}
	}

	check_create_suggestion = {
		
		every_sub_realm_title = {
			limit = {
				tier = tier_county
				OR = {
					has_county_corruption_trigger = yes
					county_control < full_county_control
				}
				trigger_if = { #marshal is not already converting the county
					limit = {
						exists = root.cp:councillor_marshal
						root.cp:councillor_marshal = {
							is_performing_council_task = task_increase_control
						}
					}
					title_province = {
						root.cp:councillor_marshal = {
							NOT = { councillor_task_target = prev }
						}
					}
				}
			}

			try_create_suggestion = {
				suggestion_type = suggestion_increase_control
				landed_title = this
			}
		}
	}

	effect = {
		open_view_data = {
			view = council_window
		}
		pan_camera_to_title = scope:landed_title
	}

	score = {
		base = 100
		modifier = {
			add = {
				# Scaling score based on development level.
				scope:landed_title = {
					add = development_level
				}

				# Extra score for the player's Capital Province.
				if = {
					limit = {
						root.capital_province = scope:landed_title.title_province
					}
					add = 25
				}

				#Extra score for low control
				if = {
					limit = {
						scope:landed_title = { county_control > medium_county_control }
					}
					add = 10
				}
				else_if = {
					limit = {
						scope:landed_title = { county_control > low_county_control }
					}
					add = 20
				}
				else = {
					add = 30
				}
			}
		}
	}

	is_valid = {
		scope:landed_title = {
			OR = {
				has_county_corruption_trigger = yes
				county_control < full_county_control
			}
		}
		trigger_if = {
			limit = {
				exists = root.cp:councillor_marshal
				root.cp:councillor_marshal = {
					is_performing_council_task = task_increase_control
				}
			}
			root.cp:councillor_marshal = {
				NOT = { councillor_task_target = scope:landed_title.title_province }
			}
		}
	}
}


suggestion_increase_opinion = {

	weight = {
		base = 0

		modifier = { #Since the scheme is blocked for kids
			add = -5
			is_adult = no
		}

		modifier = { #Is the suggestion available at all?
			add = 0.5
			OR = {
				any_councillor = {
					opinion = {
						target = root
						value <= 0
					}
					NOT = { #you're not already scheming against them (since that implies you already have an agenda)
						any_targeting_scheme = {
							scheme_owner = root
						}
					}
				}
				any_vassal = {
					opinion = {
						target = root
						value <= 0
					}
					NOT = { #you're not already scheming against them (since that implies you already have an agenda)
						any_targeting_scheme = {
							scheme_owner = root
						}
					}
				}
				liege = {
					opinion = {
						target = root
						value <= 0
					}
					NOT = { #you're not already scheming against them (since that implies you already have an agenda)
						any_targeting_scheme = {
							scheme_owner = root
						}
					}
				}
			}
		}

		modifier = { #More likely if you have no active friendly schemes
			add = 0.5
			NOT = {
				any_scheme = {
					friendly_scheme_trigger = yes
				}
			}
		}
		modifier = { #More likely if your liege really dislikes you
			add = 0.5
			liege = {
				opinion = {
					target = root
					value <= -35
				}
				NOT = { #you're not already scheming against them (since that implies you already have an agenda)
					any_targeting_scheme = {
						scheme_owner = root
					}
				}
			}
		}

		modifier = { #More likely if any vassal really dislikes you
			add = 0.25
			any_vassal = {
				opinion = {
					target = root
					value <= -35
				}
				NOT = { #you're not already scheming against them (since that implies you already have an agenda)
					any_targeting_scheme = {
						scheme_owner = root
					}
				}
			}
		}

		modifier = { #More likely if any powerful vassal dislikes you
			add = 0.5
			any_vassal = {
				is_powerful_vassal_of = root
				opinion = {
					target = root
					value <= -20
				}
				NOT = { #you're not already scheming against them (since that implies you already have an agenda)
					any_targeting_scheme = {
						scheme_owner = root
					}
				}
			}
		}

		modifier = { #Councillors are also prioritised, whether landed or not
			add = 0.5
			any_councillor = {
				opinion = {
					target = root
					value <= -35
				}
				NOT = { #you're not already scheming against them (since that implies you already have an agenda)
					any_targeting_scheme = {
						scheme_owner = root
					}
				}
			}
		}

		modifier = { #Extra score to boost councillors who are unlanded 
			add = 0.5
			any_councillor = {
				opinion = {
					target = root
					value <= 0
				}
				is_landed_or_landless_administrative = no
				OR = { 
					#excluding spouse for this one
    				has_council_position = councillor_marshal
    				has_council_position = councillor_chancellor
    				has_council_position = councillor_steward
    				has_council_position = councillor_spymaster
    				has_council_position = councillor_court_chaplain
    				is_kurultai_trigger = yes
   				}
			}
		}
	}

	check_create_suggestion = {
		every_vassal = {
			limit = {
				opinion = {
					target = root
					value <= 0
				}
				NOT = { #you're not already scheming against them (since that implies you already have an agenda)
					any_targeting_scheme = {
						scheme_owner = root
					}
				}
			}
			try_create_suggestion = {
				suggestion_type = suggestion_increase_opinion
				actor = root
				recipient = this
			}
		}
		if = {
			limit = {
				liege = {
					opinion = {
						target = root
						value <= 0
					}
					NOT = { #you're not already scheming against them (since that implies you already have an agenda)
						any_targeting_scheme = {
							scheme_owner = root
						}
					}
				}
			}
			liege = {

				try_create_suggestion = {
					suggestion_type = suggestion_increase_opinion
					actor = root
					recipient = this
				}
			}
		}
		every_councillor = {
			limit = {
				opinion = {
					target = root
					value <= 0
				}
				NOT = { #you're not already scheming against them (since that implies you already have an agenda)
					any_targeting_scheme = {
						scheme_owner = root
					}
				}
			}
			try_create_suggestion = {
				suggestion_type = suggestion_increase_opinion
				actor = root
				recipient = this
			}
		}
	}

	effect = {
		open_interaction_window = {
			interaction = sway_interaction
			actor = scope:actor
			recipient = scope:recipient
		}
	}

	score = {
		base = 50

		modifier = { #Score higher if it's your liege
			add = 50
			scope:actor = {
				liege = scope:recipient
			}
		}

		modifier = { #Extra score for powerful vassals
			add = 50
			scope:recipient = {
				is_powerful_vassal_of = scope:actor
			}
		}

		modifier = { #Extra score for court chaplain that doesn't endorse you
			add = 50
			scope:recipient = {
				opinion = {
					target = root
					value <= 0
				}
				has_council_position = councillor_court_chaplain
			}
		}

		modifier = { #Extra score if councillor is unlanded 
			add = 50
			scope:recipient  = {
				opinion = {
					target = root
					value <= 0
				}
				is_councillor_of = root
				is_landed_or_landless_administrative = no
				OR = { 
    				has_council_position = councillor_marshal
    				has_council_position = councillor_chancellor
    				has_council_position = councillor_steward
    				has_council_position = councillor_spymaster
    				has_council_position = councillor_court_chaplain
   				}
			}
		}
	}

	is_valid = {
		scope:recipient = {
			opinion = {
				target = root
				value <= 0
			}
			NOT = {
				any_targeting_scheme = {
					scheme_owner = root
				}
			}
			is_alive = yes
		}
	}
}

suggestion_raid = {

	weight = {
		base = 0

		modifier = { #Is the suggestion available at all?
			add = 0.75
			any_character_to_title_neighboring_county = {
				holder = {
					valid_raid_target_trigger = yes
				}
			}
		}

		modifier = { #More likely if you're bankrupt
			add = 0.5
			gold < 0
		}

		modifier = { #More likely if you don't have a lot of gold
			add = 0.25
			gold < root.minor_gold_value
		}

		modifier = { #More likely if you're stronger than possible target
			add = 0.25
			any_character_to_title_neighboring_county = {
				holder = {
					valid_raid_target_trigger = yes
					current_military_strength < root.current_military_strength
				}
			}
		}

		modifier = { #More likely if possible target is at war
			add = 0.25
			any_character_to_title_neighboring_county = {
				holder = {
					valid_raid_target_trigger = yes
					is_at_war = yes
				}
			}
		}
	}

	check_create_suggestion = {
		every_character_to_title_neighboring_county = {
			limit = {
				holder = {
					valid_raid_target_trigger = yes
				}
			}
			every_county_province = {
				try_create_suggestion = {
					suggestion_type = suggestion_raid
					landed_title = barony
				}
			}
		}
	}

	effect = {
		open_view = military
		scope:landed_title.title_province = {
			open_view_data = holding_view
		}
		pan_camera_to_title = scope:landed_title
	}

	score = {
		base = 50
		modifier = {
			add = {
				#Score higher if they're at war
				if = {
					limit = {
						scope:landed_title.county.holder = {
							is_at_war = yes
						}
					}
					add = 50
				}
				#Score higher if they're weaker than you
				if = {
					limit = {
						scope:landed_title.county.holder.current_military_strength < root.current_military_strength
					}
					add = 60
				}
				#Score higher if there is a lot of loot to grab
				if = {
					limit = {
						scope:landed_title.title_province.available_loot >= low_available_loot_value
					}
					add = 5
				}
				if = {
					limit = {
						scope:landed_title.title_province.available_loot >= medium_available_loot_value
					}
					add = 20
				}
				if = {
					limit = {
						scope:landed_title.title_province.available_loot >= high_available_loot_value
					}
					add = 40
				}
			}
		}
	}

	is_valid = {
		is_at_war = no
		can_raid_trigger = yes

		NOT = { #You are not already raiding
			any_army = {
				is_army_in_raid = yes
			}
		}
	}
}


suggestion_grant_title = {

	weight = {
		base = 0

		modifier = { #Is the suggestion available at all?
			add = 2
			any_held_county = {
				count > 1
			}
			any_held_title = {
				tier < tier_empire
				exists = de_jure_liege
				de_jure_liege = {
					exists = holder
					NOT = { holder = root }
					holder = {
						target_is_liege_or_above = root
					}
				}
			}
		}
	}

	check_create_suggestion = {
		every_held_title = {
			limit = {
				tier < tier_empire
				exists = de_jure_liege
				de_jure_liege = {
					exists = holder
					NOT = { holder = root }
					holder = {
						is_alive = yes
						target_is_liege_or_above = root
					}
				}
			}
			save_scope_as = landed_title
			de_jure_liege = {
				holder = {
					try_create_suggestion = {
						suggestion_type = suggestion_grant_title
						actor = root
						recipient = this
					}
				}
			}
		}
	}

	effect = {
		open_interaction_window = {
			interaction = grant_titles_interaction
			actor = scope:actor
			recipient = scope:recipient
		}
	}

	score = {
		base = 50

		modifier = { #Extra score for powerful vassals
			add = 50
			scope:recipient = {
				is_powerful_vassal_of = scope:actor
			}
		}

		modifier = { #Extra score for court chaplain that doesn't endorse you
			add = 50
			scope:recipient = {
				opinion = {
					target = root
					value <= 0
				}
				has_council_position = councillor_court_chaplain
			}
		}
	}

	is_valid = {
		scope:landed_title = {
			holder = root
			de_jure_liege = {
				exists = holder
				NOT = { holder = root }
				holder = {
					this = scope:recipient
					is_alive = yes
					target_is_liege_or_above = root
				}
			}
		}
	}
}

#HIRE MORE COURT POSITIONS
suggestion_can_hire_court_positions = {
	weight = {
		base = 0

		modifier = { # Much more likely if you have no positions occupied
			add = 1
			any_court_position_holder = {
				count <= 0
			}
		}

		modifier = { # More likely if you have few positions occupied
			add = 0.5
			any_court_position_holder = {
				count <= 2
			}
		}

		modifier = { # More likely if you have a lot of extra money
			add = 0.5
			monthly_character_income >= monthly_character_expenses_plus_fourty_percent
		}

		modifier = { # More likely if you are at least a king
			add = 0.5
			OR = {
				highest_held_title_tier >= tier_kingdom
				has_royal_court = yes
			}
		}

		modifier = { # Much more likely if you have a prestigious court
			add = 1
			court_grandeur_current_level >= 5
		}

		modifier = {	# More interesting positions with the dlc
			add = 0.5
			has_ep1_court_positions_dlc_trigger = yes
		}
	}

	check_create_suggestion = {
		try_create_suggestion = {
			suggestion_type = suggestion_can_hire_court_positions
		}
	}

	effect = {
		open_view_data = { view = court_window }
	}

	is_valid = {
		court_positions_currently_filled < court_positions_currently_available
	}
}

suggestion_request_war_aid_petition = {
	weight = {
		base = 5
	}

	check_create_suggestion = {
		try_create_suggestion = {
			suggestion_type = suggestion_request_war_aid_petition
		}
	}

	effect = {
		liege = {
			open_view_data = {
				view = royal_court
				player = root
			}
		}
	}

	is_valid = {
		NOT = { is_decision_on_cooldown = petition_liege_decision }
		is_playable_character = yes
		is_independent_ruler = no
		liege = { has_royal_court = yes }
		is_at_war_with_liege = no
		petition_liege_war_aid_share_trigger = yes
		petition_liege_war_aid_trigger = yes
		petition_war_aid_liege_ally_value >= petition_war_aid_rebels_value
		petition_liege_war_liege_involvement_trigger = yes
	}
}

# Create a Nation Fracturing Faction
suggestion_create_nation_fracturing_faction = {
	weight = {
		base = 10
	}

	check_create_suggestion = {
		try_create_suggestion = {
			suggestion_type = suggestion_create_nation_fracturing_faction
		}
	}

	effect = {
		open_view_data = {
			view = factions_window
		}
	}

	is_valid = {
		has_fp2_dlc_trigger = yes
		is_playable_character = yes
		is_independent_ruler = no
		is_a_faction_member = no
		is_a_faction_leader = no
		is_powerful_vassal_of = liege
		NOT  = { is_allied_to = liege }

		any_character_struggle = {
			involvement = involved
		}
		liege = {
			any_character_struggle = {
				involvement = involved
			}
		}
		liege.primary_title.tier >= tier_kingdom
	}
}
