﻿######################
# Legends
######################

#### SPREAD CHANCE ###
# Chance for an legend of this quality to spread to an adjacent province per month
# % from 0-100 inclusive
# root = potential province
# scope:legend = the legend

### CONTROL VALUES ###
# These should be enough to change the balance of legends

# legend seed drop chance

legend_seed_chance_very_low = 5
legend_seed_chance_low = 15
legend_seed_chance_medium = 40
legend_seed_chance_high = 75

# Spread

legend_spread_chance_base = 0.5

legend_spread_increase_add_miniscule = 0.06
legend_spread_increase_add_very_low = 0.12
legend_spread_increase_add_low = 0.25
legend_spread_increase_add_medium = 0.5
legend_spread_increase_add_high = 1
legend_spread_increase_add_very_high = 1.5

legend_spread_decrease_add_very_low = -0.12
legend_spread_decrease_add_low = -0.25
legend_spread_decrease_add_medium = -0.5
legend_spread_decrease_add_high = -1

legend_spread_increase_mult_low = 0.25
legend_spread_increase_mult_medium = 0.75
legend_spread_increase_mult_high = 1.5

legend_spread_decrease_mult_low = -0.15
legend_spread_decrease_mult_medium = -0.25
legend_spread_decrease_mult_high = -0.5
legend_spread_decrease_mult_unlikely = -0.99



spread_chance_legends_default_value = {
	value = legend_spread_chance_base

	if = {
		limit = {
			scope:legend = { legend_quality = illustrious }
		}
		add = legend_spread_increase_add_low
	}
	else_if = {
		limit = {
			scope:legend = { legend_quality = mythical }
		}
		add = legend_spread_increase_add_medium
	}
	
	#Buildings in which people gossip
	if = {
		limit = {
			has_building_or_higher = common_tradeport_01
		}
		add = legend_spread_increase_add_miniscule
	}
	if = {
		limit = {
			has_building_or_higher = common_tradeport_03
		}
		add = legend_spread_increase_add_very_low 
	}
	if = {
		limit = {
			has_building_or_higher = common_tradeport_05
		}
		add = legend_spread_increase_add_low 
	}
	if = {
		limit = {
			has_building_or_higher = common_tradeport_07
		}
		add = legend_spread_increase_add_low 
	}

	if = {
		limit = {
			has_building_or_higher = city_02
		}
		add = legend_spread_increase_add_miniscule
	}
	if = {
		limit = {
			has_building_or_higher = city_03
		}
		add = legend_spread_increase_add_low 
	}

	if = {
		limit = {
			has_building_or_higher = market_villages_01
		}
		add = legend_spread_increase_add_miniscule
	}
	if = {
		limit = {
			has_building_or_higher = market_villages_02
		}
		add = legend_spread_increase_add_low 
	}

	# Legend type bonuses

	if = {
		limit = {
			has_building_or_higher = warrior_lodges_03
			scope:legend.legend_type = legend_type:heroic 
		}
		add = legend_spread_increase_add_low 
	}
	if = {
		limit = {
			has_building_or_higher = warrior_lodges_05
			scope:legend.legend_type = legend_type:heroic 
		}
		add = legend_spread_increase_add_low 
	}

	if = {
		limit = {
			faith = scope:legend.legend_owner.faith
			scope:legend.legend_type = legend_type:holy
		}
		add = legend_spread_increase_add_very_low
	}
	else_if = {
		limit = {
			scope:legend.legend_type = legend_type:holy
			faith = {
				faith_hostility_level = {
					target = scope:legend.legend_owner.faith
					value >= faith_astray_level
				}
			}
		}
		add = legend_spread_decrease_add_medium
	}
	else_if = {
		limit = {
			scope:legend.legend_type = legend_type:holy
			faith = {
				faith_hostility_level = {
					target = scope:legend.legend_owner.faith
					value > faith_astray_level
				}
			}
		}
		add = legend_spread_decrease_add_high
	}

	if = {
		limit = {
			scope:legend.legend_type = legend_type:legitimizing
			OR = {
				county.holder.dynasty = scope:legend.legend_owner.dynasty
				county.holder.top_liege.dynasty = scope:legend.legend_owner.dynasty
			}
		}
		add = legend_spread_increase_add_very_low
	}
	else_if = {
		limit = {
			scope:legend.legend_type = legend_type:legitimizing
		}
		add = legend_spread_decrease_add_low
	}

	
	#Terrain
	if = {
		limit = {
			OR = {
				terrain = hills
				terrain = drylands
				terrain = forest
				terrain = floodplains
				terrain = wetlands
			}
		}
		add = legend_spread_decrease_add_low
	}
	else_if = {
		limit = {
			OR = {
				terrain = jungle
				terrain = taiga
			}
		}
		add = legend_spread_decrease_add_medium
	}
	else_if = {
		limit = {
			OR = {
				terrain = desert
				terrain = desert_mountains
				terrain = mountains
			}
		}
		add = legend_spread_decrease_add_high
	}
	#Island?
	if = {
		limit = {
			geographical_region = divergence_island_regions
		}
		add = legend_spread_decrease_add_medium
	}

	#prestige levels

	if = {
		limit = {
			scope:legend = {
				legend_owner = {
					prestige_level > 4
				}
			}
		}
		add = legend_spread_increase_add_low
	}
	else_if = {
		limit = {
			scope:legend = {
				legend_owner = {
					prestige_level > 3
				}
			}
		}
		add = legend_spread_increase_add_very_low
	}

	if = {
		limit = {
			scope:legend = {
				any_legend_promoter = {
					prestige_level > 4
				}
			}
		}
		add = legend_spread_increase_add_low
	}


	#Less patchy
	if = {
		limit = {
			county = {
				any_county_province = {
					any_province_legend = {
						this = scope:legend
					}
				}
			}
		}
		add = legend_spread_increase_add_very_low
	}


	#Is this in your realm? 
	if = {
		limit = { county.holder = scope:legend.legend_owner }
		add = legend_spread_increase_add_very_high
	}
	else_if = {
		limit = {
			scope:legend = {
				any_legend_promoter = {
					root.county.holder = this
				}
			}
		}
		add = legend_spread_increase_add_high
	}
	else_if = {
		limit = { county.holder.top_liege = scope:legend.legend_owner }
		add = legend_spread_increase_add_medium
	}
	else_if = {
		limit = {
			scope:legend = {
				any_legend_promoter = {
					root.county.holder.top_liege = this
				}
			}
		}
		add = legend_spread_increase_add_low
	}
	else = {
		add = legend_spread_decrease_add_low
	}

	#Languages 

	if = {
		limit = {
			culture = { has_same_culture_language = scope:legend.legend_owner.culture }
		}
		add = legend_spread_increase_add_low
	}
	else_if = {
		limit = {
			county.holder = { knows_language_of_culture = scope:legend.legend_owner.culture }
		}
		add = legend_spread_increase_add_very_low
	}
	else_if = {
		limit = {
			scope:legend.legend_owner = {
				has_royal_court = yes
				has_dlc_feature = royal_court
			}
			county.holder = { knows_court_language_of = scope:legend.legend_owner }
		}
		add = legend_spread_increase_add_very_low
	}
	else_if = {
		limit = {
			scope:legend = {
				any_legend_promoter = {
					this.culture = { has_same_culture_language = root.culture }
				}
			}
		}
		add = legend_spread_increase_add_miniscule
	}
	else_if = {
		limit = {
			culture = { has_same_culture_heritage = scope:legend.legend_owner.culture }
		}
		add = legend_spread_increase_add_miniscule
	}
	else_if = {
		limit = {
			scope:legend.legend_owner = {
				has_royal_court = yes
				has_dlc_feature = royal_court
			}
			OR = {
				county.holder.top_liege = {
					has_royal_court = yes
					has_same_court_language = scope:legend.legend_owner
				}
				county.holder = {
					has_royal_court = yes 
					has_same_court_language = scope:legend.legend_owner
				}
			}
		}
		add = legend_spread_decrease_add_very_low
	}
	else_if = {
		limit = {
			culture = {
				cultural_acceptance = { target = scope:legend.legend_owner.culture value > 40 }
			}
		}
		add = legend_spread_decrease_add_low
	}
	else_if = {
		limit = {
			culture = {
				cultural_acceptance = { target = scope:legend.legend_owner.culture value > 20 }
			}
		}
		add = legend_spread_decrease_add_medium
	}
	else_if = {
		limit = {
			scope:legend = {
				any_legend_promoter = {
					this.culture = {
						cultural_acceptance = { target = root.culture value > 40 }
					}
				}
			}
		}
		add = legend_spread_decrease_add_medium
	}
	else = {
		add = legend_spread_decrease_add_high
	}

	#County holder opinion of legend owner

	if = {
		limit = {
			OR = {
				OR = {
					county.holder = { has_any_good_relationship_with_character_trigger = { CHARACTER = scope:legend.legend_owner } }
				}
			}
		}
		add = legend_spread_increase_add_medium
	}
	else_if = {
		limit = {
			OR = {
				county.holder = { has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:legend.legend_owner } }
			}
		}
		add = legend_spread_decrease_add_high
	}
	else_if = {
		limit = {
			scope:legend = {
				any_legend_promoter = {
					this = { has_any_good_relationship_with_character_trigger = { CHARACTER = root.county.holder } }
				}
			}
		}
		add = legend_spread_increase_add_high
	}
	else = {
		add = legend_spread_decrease_add_low
	}

	#Coastal Statistics Squash
	if = {
		limit = {
			OR = {
				is_coastal = yes
				is_riverside_province = yes
			}
			NOR = {
				county = {
					any_county_province = {
						any_province_legend = {
							this = scope:legend
						}
					}
				}
				culture = { has_same_culture_language = scope:legend.legend_owner.culture }
			}
		}
		add = legend_spread_decrease_add_high
	}
}

spread_chance_legends_mult_value = {
	#NO ADD AFTER THIS POINT
	#NO ADD ONLY MULT
	value = 1
	min = 0.001

	#Coastal Statistics Squash
	if = {
		limit = {
			OR = {
				is_coastal = yes
				is_riverside_province = yes
			}
			NOR = {
				county = {
					any_county_province = {
						any_province_legend = {
							this = scope:legend
						}
					}
				}
			}
		}
		add = legend_spread_decrease_mult_high
	}

	#Is this in your realm?
	if = {
		limit = {
			county.holder = scope:legend.legend_owner
		}
		add = legend_spread_increase_mult_medium
	} 
	else_if = {
		limit = {
			OR = {
				county.holder.top_liege = scope:legend.legend_owner
				scope:legend = {
					any_legend_promoter = {
						OR = {
							root.county.holder = this
							root.county.holder.top_liege = this
						}
					}
				}
			}
		}
		add = legend_spread_increase_mult_low
	}
	else = {
		add = legend_spread_decrease_mult_medium
	}

	#Cultural Traditions
	if = {
		limit = {
			county.culture = {
				OR = {
					has_cultural_tradition = tradition_chanson_de_geste
					has_cultural_tradition = tradition_fp1_northern_stories
					has_cultural_tradition = tradition_storytellers
					has_cultural_tradition = tradition_poetry
				}
			}
		}
		add = legend_spread_increase_mult_medium
	}
	else_if = {
		limit = {
			county.culture = {
				OR = {
					has_cultural_tradition = tradition_esteemed_hospitality
					has_cultural_tradition = tradition_horse_lords
					has_cultural_tradition = tradition_caravaneers
					has_cultural_tradition = tradition_seafaring
					has_cultural_tradition = tradition_city_keepers
					has_cultural_tradition = tradition_maritime_mercantilism
				}
			}
		}
		add = legend_spread_increase_mult_low
	}
	else_if = {
		limit = {
			county.culture = {
				OR = {
					has_cultural_tradition = tradition_practiced_pirates
					has_cultural_tradition = tradition_parochialism
				}
			}
		}
		add = legend_spread_increase_mult_low
	}

	#Development
	if = {
		limit = {
			county.development_level >= good_development_level
		}
		add = legend_spread_decrease_mult_medium
	}
	else_if = {
		limit = {
			county.development_level >= medium_development_level 
		}
		add = legend_spread_decrease_mult_low
	}

	#County holder and top liege opinion of legend owner
	if = {
		limit = { #slight mult increase for owner and promoter domain
			OR = {
				county.holder = scope:legend.legend_owner
				county.holder = { promoted_legend ?= scope:legend }
			}
		}
		add = legend_spread_increase_mult_medium
	}
	else_if = {
		limit = {
			OR = {
				county.holder.top_liege = { has_any_good_relationship_with_character_trigger = { CHARACTER = scope:legend.legend_owner } }
				county.holder = { has_any_good_relationship_with_character_trigger = { CHARACTER = scope:legend.legend_owner } }
			}
		}
		add = legend_spread_increase_mult_low
	}
	else_if = {
		limit = {
			OR = {
				county.holder.top_liege = { has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:legend.legend_owner } }
				county.holder = { has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:legend.legend_owner } }
			}
		}
		add = legend_spread_decrease_mult_high
	}
	else = {
		add = legend_spread_decrease_mult_low
	}

	# Game rules
	if = {
		limit = {
			has_game_rule = legend_spread_chance_high
		}
		add = legend_spread_increase_mult_low
	}
	else_if = {
		limit = {
			has_game_rule = legend_spread_chance_very_high
		}
		add = legend_spread_increase_mult_medium
	}
	else_if = {
		limit = {
			has_game_rule = legend_spread_chance_low
		}
		add = legend_spread_decrease_mult_low
	}
	else_if = {
		limit = {
			has_game_rule = legend_spread_chance_very_low
		}
		add = legend_spread_decrease_mult_medium
	}
}

### GOLD COSTS ###

legend_base_cost_value = {
	value = 200
}

legend_base_cost = {
	value = legend_base_cost_value
	#Scale by tier
	multiply = {
		value = root.primary_title.tier
		subtract = 1
		multiply = 0.5
		min = 1
	}
	if = {
		limit = {
			root = {
				government_has_flag = government_is_tribal
			}
		}
		multiply = 0.8
	}
	#Scale by era
	add = {
		value = legend_base_cost_value
		multiply =  legend_cost_scale_by_era
		subtract = legend_base_cost_value
		desc = legend_cost_scale_by_era_desc
	}
	#Legends Dynasty Track discounts
	add = legend_cost_dynasty_discounts

	# Game rules
	if = {
		limit = {
			has_game_rule = legend_cost_high
		}
		multiply = 2
	}
	else_if = {
		limit = {
			has_game_rule = legend_cost_very_high
		}
		multiply = 4
	}
	else_if = {
		limit = {
			has_game_rule = legend_cost_low
		}
		divide = 2
	}
	else_if = {
		limit = {
			has_game_rule = legend_cost_very_low
		}
		divide = 4
	}
}

legend_cost_scale_by_era = {
	value = 0
	if = {
		limit = {
			exists = culture
		}
		culture = {
			if = {
				limit = {
					has_cultural_era_or_later = culture_era_late_medieval
				}
				add = 1.6
			}
			else_if = {
				limit = {
					has_cultural_era_or_later = culture_era_high_medieval
				}
				add = 1.4
			}
			else_if = {
				limit = {
					has_cultural_era_or_later = culture_era_early_medieval
				}
				add = 1.2
			}
			else = {
				add = 1
			}
		}
	}
}

legend_cost_dynasty_discounts = {
	if = {
		limit = {
			dynasty ?= {
				ce1_heroic_track_perks >= 4
			}
		}
		multiply = 0.75
	}
	else_if = {
		limit = {
			dynasty ?= {
				ce1_heroic_track_perks >= 3
			}
		}
		multiply = 0.85
	}
}

legend_upgrade_cost = {
	value = legend_base_cost #includes scaling by era, tier and game rules
	multiply = 0.8
	if = {
		limit = {
			promoted_legend ?= { has_variable = legend_quality_progress }
		}
		subtract = {
			#Legend costs until now
			value = legend_base_cost
			multiply = 0.6
			#We give you 50% discount max based on your progress
			multiply = {
				value = promoted_legend.var:legend_quality_progress
				divide = 200
			}
		}
	}
}

legend_era_cost = {
	value = monthly_character_income
	multiply = legend_cost_scale_by_era
	subtract = monthly_character_income
	desc = legend_cost_scale_by_era_desc
}

legend_game_rule_multiplier = {
	value = 1
	
	# Game rules
	if = {
		limit = {
			has_game_rule = legend_cost_high
		}
		value = 2
	}
	else_if = {
		limit = {
			has_game_rule = legend_cost_very_high
		}
		value = 4
	}
	else_if = {
		limit = {
			has_game_rule = legend_cost_low
		}
		value = 0.5
	}
	else_if = {
		limit = {
			has_game_rule = legend_cost_very_low
		}
		value = 0.25
	}
}

famed_legend_owner_cost = {
	value = monthly_character_income
	multiply = 0.1
	min = 3
	add = 1
	multiply = legend_cost_scale_by_era
	multiply = legend_game_rule_multiplier
	max = 300
}

illustrious_legend_owner_cost = {
	value = monthly_character_income
	multiply = 0.15
	min = 4.5
	add = 2
	multiply = legend_cost_scale_by_era
	multiply = legend_game_rule_multiplier
	max = 450
}

mythical_legend_owner_cost = {
	value = monthly_character_income
	multiply = 0.25
	min = 8
	add = 4
	multiply = legend_cost_scale_by_era
	multiply = legend_game_rule_multiplier  
	max = 800
}

# Promoter costs

famed_legend_promoter_cost = {
	value = monthly_character_income
	multiply = 0.05
	add = 0.5
	multiply = legend_cost_scale_by_era
	multiply = legend_game_rule_multiplier
}

illustrious_legend_promoter_cost = {
	value = monthly_character_income
	multiply = 0.1
	add = 1
	multiply = legend_cost_scale_by_era
	multiply = legend_game_rule_multiplier
}

mythical_legend_promoter_cost = {
	value = monthly_character_income
	multiply = 0.2
	add = 1.5
	multiply = legend_cost_scale_by_era
	multiply = legend_game_rule_multiplier
}

# We want higher AI income than cost when starting promoting, so we do not toggle start/stop promoting too much, or spend all their income on it

ai_famed_legend_promoter_start_required_income = {
	value = famed_legend_promoter_cost
	multiply = 1.4
}

ai_illustrious_legend_promoter_start_required_income = {
	value = illustrious_legend_promoter_cost
	multiply = 1.4
}

ai_mythical_legend_promoter_start_required_income = {
	value = mythical_legend_promoter_cost
	multiply = 1.4
}

### Prestige costs ###

legend_prestige_cost = {
	value = 200
	#Scale by tier
	multiply = {
		value = root.primary_title.tier
		subtract = 1
		multiply = 0.5
		min = 1
	}
	if = {
		limit = {
			root = {
				government_has_flag = government_is_tribal
			}
		}
		multiply = 0.8
	}
	#Scale by era
	add = {
		value = legend_base_cost_value
		multiply =  legend_cost_scale_by_era
		subtract = legend_base_cost_value
		desc = legend_cost_scale_by_era_desc
	}

	# Game rules
	if = {
		limit = {
			has_game_rule = legend_cost_high
		}
		multiply = 2
	}
	else_if = {
		limit = {
			has_game_rule = legend_cost_very_high
		}
		multiply = 4
	}
	else_if = {
		limit = {
			has_game_rule = legend_cost_low
		}
		divide = 2
	}
	else_if = {
		limit = {
			has_game_rule = legend_cost_very_low
		}
		divide = 4
	}
}

### Piety costs ###

legend_piety_cost = {
	value = 200
	#Scale by tier
	multiply = {
		value = root.primary_title.tier
		subtract = 1
		multiply = 0.5
		min = 1
	}
	if = {
		limit = {
			root = {
				government_has_flag = government_is_tribal
			}
		}
		multiply = 0.8
	}
	#Scale by era
	add = {
		value = legend_base_cost_value
		multiply =  legend_cost_scale_by_era
		subtract = legend_base_cost_value
		desc = legend_cost_scale_by_era_desc
	}

	# Game rules
	if = {
		limit = {
			has_game_rule = legend_cost_high
		}
		multiply = 2
	}
	else_if = {
		limit = {
			has_game_rule = legend_cost_very_high
		}
		multiply = 4
	}
	else_if = {
		limit = {
			has_game_rule = legend_cost_low
		}
		divide = 2
	}
	else_if = {
		limit = {
			has_game_rule = legend_cost_very_low
		}
		divide = 4
	}
}

### COURT POSITION TASKS ###

monthly_court_position_task_cost_value = {
	value = 0.1
}

monthly_court_position_task_cost = {
	value = monthly_court_position_task_cost_value
	#Scale by tier
	multiply = {
		value = scope:liege.primary_title.tier
		subtract = 1
		min = 1
	}
	#Scale by era
	add = {
		value = monthly_court_position_task_cost_value
		multiply = legend_cost_scale_by_era
		subtract = monthly_court_position_task_cost_value
		desc = legend_cost_scale_by_era_desc
	}
}

monthly_court_position_task_cost_double = {
	value = monthly_court_position_task_cost
	multiply = 2
}

### DYNAMIC VALUES ###
legend_piety_gain = {
	value = 0
	if = {
		limit = { root = { legend_quality = famed } }
		value = minor_piety_gain
	}
	else_if = {
		limit = { root = { legend_quality = illustrious } }
		value = medium_piety_gain
	}
	else = { #mythical
		value = major_piety_gain
	}
}

legend_prestige_gain = {
	value = 0
	if = {
		limit = { root = { legend_quality = famed } }
		value = minor_prestige_gain
	}
	else_if = {
		limit = { root = { legend_quality = illustrious } }
		value = medium_prestige_gain
	}
	else = { #mythical
		value = major_prestige_gain
	}
}

legend_dynasty_prestige_gain = {
	value = 0
	if = {
		limit = { root = { legend_quality = famed } }
		value = miniscule_dynasty_prestige_gain
	}
	else_if = {
		limit = { root = { legend_quality = illustrious } }
		value = minor_dynasty_prestige_gain
	}
	else = { #mythical
		value = major_dynasty_prestige_gain
	}
}

major_legend_quality_increase = 50
medium_legend_quality_increase = 20
minor_legend_quality_increase = 10
minor_legend_quality_decrease = {
	value = 0
	subtract = minor_legend_quality_increase
}
medium_legend_quality_decrease = {
	value = 0
	subtract = medium_legend_quality_increase
}
major_legend_quality_decrease = {
	value = 0
	subtract = major_legend_quality_increase
}

base_legend_create_ai = {
	value = 10

	add = {
		value = ai_greed
		multiply = -1
	}

	if = {
		limit = {
			highest_held_title_tier <= tier_duchy
		}
		add = -10
	}
	
	if = {
		limit = { 
			monthly_character_income < mythical_legend_owner_cost
		}
		multiply = 0.2
	}
	if = {
		limit = {
			monthly_character_income <= monthly_character_expenses
		}
		multiply = 0
	}
	if = {
		limit = {
			has_trait = arrogant
		}
		multiply = 2
	}
	if = {
		limit = {
			has_trait = ambitious
		}
		multiply = 2
	}

	#you need to be this rich to create legends
	if = {
		limit = {
			OR = {
				is_at_war = yes
				monthly_character_income < illustrious_legend_owner_cost
			}
		}
		value = 0
	}
	if = {
		limit = {
			ai_has_conqueror_personality = yes
			gold < 2500
		}
		multiply = 0
	}
	if = {
		limit = {
			ai_should_focus_on_building_in_their_capital = yes
		}
		multiply = 0
	}
}

heroic_legend_create_ai = {
	value = base_legend_create_ai
	add = ai_honor
	if = {
		limit = {
			ai_has_warlike_personality = yes
		}
		multiply = 2
	}
	if = {
		limit = {
			ai_has_cautious_personality = yes
		}
		multiply = 0.1
	}
	if = {
		limit = {
			ai_has_economical_boom_personality = yes
		}
		multiply = 0.75
	}
	if = {
		limit = {
			ai_has_conqueror_personality = yes
			gold < 2500
		}
		multiply = 0
	}
	if = {
		limit = {
			ai_should_focus_on_building_in_their_capital = yes
		}
		multiply = 0
	}
}

holy_legend_create_ai = {
	value = base_legend_create_ai
	add = ai_zeal
	if = {
		limit = {
			ai_has_warlike_personality = yes
		}
		multiply = 1.1
	}
	if = {
		limit = {
			ai_has_cautious_personality = yes
		}
		multiply = 0.9
	}
	if = {
		limit = {
			ai_has_economical_boom_personality = yes
		}
		multiply = 0.75
	}
	if = {
		limit = {
			ai_has_conqueror_personality = yes
			gold < 2500
		}
		multiply = 0
	}
	if = {
		limit = {
			ai_should_focus_on_building_in_their_capital = yes
		}
		multiply = 0
	}
}

legitimizing_legend_create_ai = {
	value = base_legend_create_ai
	add = ai_rationality	
	if = {
		limit = {
			ai_has_warlike_personality = yes
		}
		multiply = 1.1
	}
	if = {
		limit = {
			ai_has_cautious_personality = yes
		}
		multiply = 0.1
	}
	if = {
		limit = {
			ai_has_economical_boom_personality = yes
		}
		multiply = 0.9
	}
	if = {
		limit = {
			ai_has_conqueror_personality = yes
			gold < 2500
		}
		multiply = 0
	}
	if = {
		limit = {
			ai_should_focus_on_building_in_their_capital = yes
		}
		multiply = 0
	}
}

illustrious_legend_create_ai = {
	add = 25
	if = {
		limit = {
			monthly_character_income < illustrious_legend_promoter_cost
		}
		value = 0
	}
}

mythical_legend_create_ai = {
	add = 50
	if = {
		limit = {
			monthly_character_income < mythical_legend_promoter_cost
		}
		value = 0
	}
}


base_legend_promote_ai = {
	value = 0
	if = {
		limit = {
			has_any_best_good_relationship_with_character_trigger = { CHARACTER = scope:legend.legend_owner }
		}
		add = 20
	}
	else_if = {
		limit = {
			has_friendly_relationship_with_character_trigger = { CHARACTER = scope:legend.legend_owner }
		}
		add = 8
	}
	else_if = {
		limit = {
			likes_character_trigger = { CHARACTER = scope:legend.legend_owner }
		}
		add = 2
	}
	if = {
		limit = {
			culture = {
				OR = {
					has_cultural_tradition = tradition_chanson_de_geste
					has_cultural_tradition = tradition_fp1_northern_stories
					has_cultural_tradition = tradition_storytellers
					has_cultural_tradition = tradition_poetry
				}
			}
		}
		add = 2
	}
	if = { # The protag is my relative
		limit = {
			is_close_or_extended_family_of = scope:legend.legend_owner
		}
		add = 2
	}

	if = {
		limit = {
			has_trait = arrogant # I want to create my own legend >:(
		}
		add = -4
	}
	if = {
		limit = {
			has_trait = cynical
		}
		add = -4
	}

	if = {
		limit = {
			is_independent_ruler = no
		}
		add = -4
	}
	
	add = {
		value = "opinion(scope:legend.legend_owner)"
		multiply = 0.05
	}	

	if = {
		limit = {
			any_character_to_title_neighboring_county = {
				any_county_province = {
					any_province_legend = {
						this = scope:legend
					}
				}
			}
		}
		add = 2
	}
	else = {
		add = -8
	}

	if = { #no free meals
		limit = {
			primary_title.tier = tier_empire
		}
		add = -16
	}
	else_if = {
		limit = {
			primary_title.tier = tier_kingdom
		}
		add = -8
	}
	else_if = { #you need to be this tall to promote legends
		limit = {
			primary_title.tier < tier_duchy
		}
		value = 0
	}

	if = {
		limit = {
			scope:legend = {
				legend_quality = illustrious
			}
		}
		multiply = 1.2
	}
	else_if = {
		limit = {
			scope:legend = {
				legend_quality = mythical
			}
		}
		multiply = 1.4
	}

	if = {
		limit = {
			OR = {
				# War is no time for idle spending
				is_at_war = yes

				# Opt out if we do not have enough income to promote this legend
				# (only for legends we're not currently promoting - stopping the currently promoting legend is handled by code)
				AND = {
					NOT = { promoted_legend ?= scope:legend }
					OR = {
						AND = {
							scope:legend = {
								legend_quality = famed
							}
							monthly_character_income < ai_famed_legend_promoter_start_required_income
						}
						AND = {
							scope:legend = {
								legend_quality = illustrious
							}
							monthly_character_income < ai_illustrious_legend_promoter_start_required_income
						}
						AND = {
							scope:legend = {
								legend_quality = mythical
							}
							monthly_character_income < ai_mythical_legend_promoter_start_required_income
						}
					}
				}
			}
		}
		value = 0
	}
	#to prevent AI switching promoters too often
	if = {
		limit = {
			exists = promoted_legend
		}
		multiply = 0.4
	}
	if = {
		limit = {
			ai_has_conqueror_personality = yes
			gold < 2500
		}
		multiply = 0
	}
	if = {
		limit = {
			ai_should_focus_on_building_in_their_capital = yes
		}
		multiply = 0
	}
}

base_legend_complete_ai = {
	value = 0
	if = { # I cannot afford the current levels monthly cost anymore
        limit = {
            scope:can_afford_current_level = no
        }
        add = 100
    }
	if = { # My legend is done
		limit = {
			scope:legend = { legend_quality = mythical }
		}
		add = 100
	}
	if = { # This legend is going nowhere :(
		limit = {
			current_year >= {
				value = scope:legend.legend_start_date
				add = 100
			}
		}
		add = 10
	}
	if = {
		limit = {
			current_year >= {
				value = scope:legend.legend_start_date
				add = 200
			}
		}
		add = 20
	}
	if = {
		limit = {
			scope:legend = {
				any_spread_province > { count = 350 }
			}
		}
		add = 40
	}
	if = {
		limit = {
			monthly_character_income <= monthly_character_expenses 
			debt_level = 2 #Is one year in debt.
		}
		add = 10
	}
	else_if = {
		limit = {
			monthly_character_income <= monthly_character_expenses
			debt_level > 2 # Is two years in debt.
		}
		add = 25
	}
	if = {
		limit = {
			debt_level = 5	# Is four years in debt
		}
		add = 40
	}
}

base_chronicler_promote_legend_realm_cost = {
	value = 0
	if = {
		limit = {
			scope:liege = {
				promoted_legend ?= {
					legend_owner = scope:liege
				}
			}
		}
		add = scope:liege.famed_legend_owner_cost
	}
	else = {
		add = scope:liege.famed_legend_promoter_cost
	}
	multiply = 0.8
}
