﻿task_promote_culture = {
	position = councillor_steward

	task_type = task_type_county
	county_target = realm
	ai_county_target = realm
	task_progress = task_progress_percentage
	restart_on_finish = yes
	highlight_own_realm = yes
	
	effect_desc = {
		desc = {
			desc = task_promote_culture_effect_desc
			triggered_desc = {
				trigger = {
					trigger_if = {
						limit = { exists = scope:county }
						scope:county = {
							NOT = { culture = scope:councillor_liege.culture }
						}
						NOT = {
							scope:councillor_liege.culture = {
								is_hybrid_culture = yes
								any_parent_culture = {
									this = scope:county.culture
								}
							}
						}
					}
					trigger_else = { always = no }
				}
				desc = task_promote_culture_acceptance_effect_desc
			}
		}
		desc = {
			desc = council_task_possible_side_effects
			triggered_desc = {
				trigger = {
					stewardship > mediocre_skill_rating
					trigger_if = {
						limit = { exists = scope:county }
						scope:county = {
							NOT = { has_county_modifier = steward_task_efficient_taxation_modifier }
						}
					}
				}
				desc = task_promote_culture_improve_county_opinion
			}
			triggered_desc = {
				trigger = {
					stewardship > mediocre_skill_rating
					trigger_if = {
						limit = { exists = scope:county }
						scope:county = {
							NOT = { has_county_modifier = steward_task_efficient_taxation_modifier }
						}
					}
				}
				desc = task_promote_culture_increased_taxes
			}
			triggered_desc = {
				trigger = {
					stewardship > mediocre_skill_rating
					trigger_if = {
						limit = { exists = scope:county }
						scope:county = {
							NOT = { has_county_modifier = steward_task_efficient_taxation_modifier }
						}
					}
				}
				desc = task_promote_culture_increased_levies
			}
			triggered_desc = {
				trigger = {
					stewardship < high_skill_rating
					trigger_if = {
						limit = { exists = scope:county }
						scope:county = {
							NOT = { has_county_modifier = steward_settler_resistance_modifier }
						}
					}
				}
				desc = task_promote_culture_resistance_to_settlers
			}
			triggered_desc = {
				trigger = {
					stewardship < high_skill_rating
					trigger_if = {
						limit = { exists = scope:county }
						scope:county = {
							NOT = { has_county_modifier = steward_settler_resistance_modifier }
						}
					}
				}
				desc = task_promote_culture_resistance_to_administration
			}
		}
	}

	progress = {
		value = 0
		add = {
			value = steward_promote_culture_base
			desc = STEWARD_PROGRESS_BASE
		}
		add = {
			value = scope:councillor.steward_promote_culture_monthly_increase
			desc = SCALED_COUNCILLOR_STEWARDSHIP_VALUE
		}

		add = steward_promote_culture_contextual_bonuses

		#Modded
		if = {
			limit = {
				exists = scope:county
				scope:county = { has_county_modifier = county_increased_opinion_modifier }
			}
			add = {
				value = scope:councillor.culture_local_population_pacified_mod 
				desc = county_increased_opinion_modifier
			}
		}
		if = {
			limit = {
				exists = scope:county
				scope:county = { has_county_modifier = county_increased_opinion_modifier_crusade }
			}
			add = {
				value = scope:councillor.culture_local_population_pacified_crusade_mod
				desc = county_increased_opinion_modifier
			}
		}		

		if = { # Development reduces the speed. Should be the last non-multiply modifier applied to avoid negative values
			limit = {
				exists = scope:county
				scope:county = {
					development_level > 0
				}
			}
			add = {
				value = scope:county.promote_culture_development_penalty
				desc = STEWARD_PROMOTE_CULTURE_DEVELOPMENT_PENALTY
			}
		}
		
		# Conversion speed game rules
		if = {
			limit = {
				has_game_rule = slower_culture_conversion_speed
			}
			multiply = {
				value = slower_game_rule_value
				desc = GAME_RULE_SLOWER_REASON
			}
		}
		if = {
			limit = {
				has_game_rule = significantly_slower_culture_conversion_speed
			}
			multiply = {
				value = significantly_slower_game_rule_value
				desc = GAME_RULE_SIGNIFICANTLY_SLOWER_REASON
			}
		}
		if = {
			limit = {
				#Modded for More Games Rule (MGR) compatibility
				NOT = {
					exists = global_var:mgr_is_active
				}
				has_game_rule = significantly_faster_culture_conversion_speed
			}
			multiply = {
				value = significantly_faster_game_rule_value
				desc = GAME_RULE_SIGNIFICANTLY_FASTER_REASON
			}
		}
		if = {
			limit = {
				#Modded for More Games Rule (MGR) compatibility
				NOT = {
					exists = global_var:mgr_is_active
				}			
				has_game_rule = faster_culture_conversion_speed
			}
			multiply = {
				value = faster_game_rule_value
				desc = GAME_RULE_FASTER_REASON
			}
		}
		#Modded More Game Rules (MGR) code for compatibility
		if = {
			limit = {
				exists = global_var:mgr_is_active				
				has_game_rule = no_culture_conversion
			}
			multiply = {
				value = 0
				desc = GAME_RULE_EXTREMELY_SLOW_REASON
			}
		}
		if = {
			limit = {
				exists = global_var:mgr_is_active			
				has_game_rule = extremely_slow_culture_conversion_speed
			}
			multiply = {
				value = 0.10 #significantly_slower_game_rule_value
				desc = GAME_RULE_EXTREMELY_SLOW_REASON
			}
		}
		if = {
			limit = {
				exists = global_var:mgr_is_active			
				OR = {
					has_game_rule = faster_culture_conversion_speed
					AND = {
						has_game_rule = faster_culture_conversion_speed_pl
						scope:councillor.liege = { is_ai = no }
					}
				}
			}
			multiply = {
				value = faster_game_rule_value
				desc = GAME_RULE_FASTER_REASON
			}
		}
		if = {
			limit = {
				exists = global_var:mgr_is_active			
				OR = {
					has_game_rule = significantly_faster_culture_conversion_speed
					AND = {
						has_game_rule = significantly_faster_culture_conversion_speed_pl
						scope:councillor.liege = { is_ai = no }
					}
				}

			}
			multiply = {
				value = significantly_faster_game_rule_value
				desc = GAME_RULE_SIGNIFICANTLY_FASTER_REASON
			}
		}
		# Faster conversion for FP2 Hostility ending, if county is in Iberia and culture was involved
		if = {
			limit = {
				any_in_global_list = {
					variable = fp2_struggle_ending_culture_list
					this = scope:county.culture
				}
				scope:county.title_province = { geographical_region = world_europe_west_iberia }
				scope:councillor.liege.house = {
					OR = {
						has_house_modifier = fp2_struggle_hostility_house_culture_modifier
						has_house_modifier = fp2_struggle_hostility_house_combined_modifier
					}
				}
			}
			multiply = {
				value = fp2_struggle_hostility_conversion_value
				desc = fp2_struggle_hostility_culture_conversion_task_desc
			}
		}
	}

	potential_county = {
		#Modded More Game Rules (MGR) code for compatibility
		trigger_if = {
			limit = {
				exists = global_var:mgr_is_active
			}
			NOT = { has_game_rule = no_culture_conversion }
		}
		scope:county = {
			NOT = { culture = scope:councillor_liege.culture }
			trigger_if = {
				limit = {
					scope:councillor_liege = { has_variable = hold_court_8130_culture_block }
				}
				custom_tooltip = {
					text = hold_court_8130_conversion_tt
					NOT = { culture = scope:councillor_liege.var:hold_court_8130_culture_block }
				}
			}
		}
		trigger_if = {
			limit = {
				scope:councillor_liege = { is_ai = yes }
			}
			NAND = { # Princes in the HRE tend to not convert each other's cultures
				exists = title:e_hre.holder
				scope:councillor_liege.top_liege = title:e_hre.holder
				OR = {
					scope:councillor_liege.culture = culture:czech
					scope:councillor_liege.culture = { has_cultural_pillar = heritage_central_germanic }
				}
				OR = {
					scope:county.culture = culture:czech
					scope:county.culture = { has_cultural_pillar = heritage_central_germanic }
				}
			}
			OR = {
				NOT = {
					scope:county.culture = {
						cultural_acceptance = { target = scope:councillor_liege.culture value >= 50 }
					}
				}
				scope:councillor_liege.culture = { # All AI's are motivated to spread new Hybrid/Divergent cultures
					OR = {
						is_hybrid_culture = yes
						is_divergent_culture = yes
					}
					NOT = { # Leave the Welsh alone!
						this = culture:anglo_saxon
					}
					any_parent_culture = {
						this = scope:county.culture
					}
				}
				AND = {
					# Scottish rulers should convert counties of 'old' cultures to the new one.
					scope:councillor_liege.culture = culture:scottish
					OR = {
						scope:county.culture = culture:anglo_saxon
						scope:county.culture = culture:gaelic
						scope:county.culture = culture:cumbrian
						scope:county.culture = culture:pictish
					}
				}
				AND = {
					# English rulers should convert counties of 'old' cultures to the new one.
					scope:councillor_liege.culture = culture:english
					OR = {
						scope:county.culture = culture:anglo_saxon
						scope:county.culture = culture:norman
					}
				}
			}
			OR = {
				is_independent_ruler = yes
				scope:councillor_liege.primary_title.tier > tier_county
				scope:councillor_liege.culture = { # All AI's are motivated to spread new Hybrid/Divergent cultures
					OR = {
						is_hybrid_culture = yes
						is_divergent_culture = yes
					}
					any_parent_culture = {
						this = scope:county.culture
					}
				}
				AND = {
					# Scottish rulers should convert counties of 'old' cultures to the new one.
					scope:councillor_liege.culture = culture:scottish
					OR = {
						scope:county.culture = culture:anglo_saxon
						scope:county.culture = culture:gaelic
						scope:county.culture = culture:cumbrian
						scope:county.culture = culture:pictish
					}
				}
				AND = {
					# English rulers should convert counties of 'old' cultures to the new one.
					scope:councillor_liege.culture = culture:english
					OR = {
						scope:county.culture = culture:anglo_saxon
						scope:county.culture = culture:norman
					}
				}
			}
			OR = {
				scope:county = {
					any_neighboring_county = {
						culture = scope:councillor_liege.culture # The AI only wants to convert counties bordering their own culture
					}
				}
				
				AND = {
					NOT = {
						scope:county = {
							any_neighboring_county = {
								culture = scope:councillor_liege.culture # The AI only wants to convert counties bordering their own culture
							}
						}
					}
					OR = {
						#scope:councillor_liege.culture = { # All AI's are motivated to spread new Hybrid cultures
						#	is_hybrid_culture = yes
						#	any_parent_culture = {
						#		this = scope:county.culture
						#	}
						#}
						# Unless they're a nomadic culture converting in the steppe or Asia Minor...
						#AND = { # Deprecated as of the Culture Update, nomadic cultures now try to hybridize aggressively
						#	OR = {
						#		scope:councillor_liege.culture = { has_cultural_pillar = heritage_mongolic }
						#		scope:councillor_liege.culture = { has_cultural_pillar = heritage_turkic }
						#	}
						#	scope:county.title_province = {
						#		OR = {
						#			geographical_region = world_asia_minor
						#			geographical_region = world_steppe
						#		}
						#	}
						#}
						AND = { # The English want to convert the Anglo Saxons and Cumbrians
							scope:councillor_liege.culture = culture:english
							OR = {
								scope:county.culture = culture:anglo_saxon
								scope:county.culture = culture:cumbrian
							}
						}
						AND = { # The Scots want to convert the Anglo Saxons, Cumbrians and Gaelic
							scope:councillor_liege.culture = culture:scottish
							OR = {
								scope:county.culture = culture:anglo_saxon
								scope:county.culture = culture:gaelic
								scope:county.culture = culture:cumbrian
								scope:county.culture = culture:pictish
							}
						}
						AND = { # The Gaels want to convert the Picts and Cumbrians
							scope:councillor_liege.culture = culture:gaelic
							OR = {
								scope:county.culture = culture:cumbrian
								scope:county.culture = culture:pictish
							}
						}
						AND = { # The modern scandinavians want to convert the Norse
							OR = {
								scope:councillor_liege.culture = culture:swedish
								scope:councillor_liege.culture = culture:danish
								scope:councillor_liege.culture = culture:norwegian
							}
							scope:county.culture = culture:norse
						}
						#AND = { # The vikings want to culture convert the Brits, OBSOLETE as of the Hybrid Culture update - they want to create hybrids instead!
						#	OR = {
						#		scope:councillor_liege.culture = culture:norse
						#		scope:councillor_liege.culture = culture:norwegian
						#	}
						#	scope:county = {
						#		any_county_province = {
						#			is_coastal = yes
						#		}
						#	}
						#	OR = {
						#		scope:county.culture = { has_cultural_pillar = heritage_west_germanic }
						#		scope:county.culture = { has_cultural_pillar = heritage_goidelic }
						#		scope:county.culture = { has_cultural_pillar = heritage_brythonic }
						#	}
						#}
						AND = { # The Portuguese should want to convert Suebi
							scope:councillor_liege.culture = culture:portuguese
							scope:county.culture = culture:suebi
						}
						AND = { # The Iberians want to convert Visigothic
							scope:councillor_liege.culture = { has_cultural_pillar = heritage_iberian }
							NOT = { scope:councillor_liege.culture = culture:portuguese }
							scope:county.culture = culture:visigothic
						}
					}
				}
			}
		}
	}

	on_finish_task_county = {
		scope:councillor_liege = {
			if = {
				limit = {	
					NOT = {
						culture = {
							is_hybrid_culture = yes
							any_parent_culture = {
								this = scope:county.culture
							}
						}
					}
				}
				if = {
					limit = {
						is_independent_ruler = no
					}
					add_character_flag = {
						flag = no_ai_culture_convert
						years = 60
					}
				}
				else = {
					add_character_flag = {
						flag = no_ai_culture_convert
						years = 30
					}
				}
			}
		}
		scope:county = {
			if = {
				limit = {
					NOT = {
						scope:councillor_liege.culture = {
							is_hybrid_culture = yes
							any_parent_culture = {
								this = scope:county.culture
							}
						}
					}
				}
				culture = {
					change_cultural_acceptance = {
						target = scope:councillor_liege.culture
						value = culture_conversion_acceptance_impact
						desc = cultural_acceptance_loss_promote_culture
					}
				}
			}
			set_county_culture = scope:councillor_liege.culture
		}
		scope:councillor = {
			start_default_task = yes
		}
	}

	monthly_on_action = task_promote_culture_side_effects

	ai_will_do = {
		value = 0
		if = {
			limit = {
				scope:councillor = {
					is_performing_council_task = task_promote_culture
				}
			}
			add = 10000 # Always keep going if this is already chosen
		}
		else_if = {
			limit = {
				scope:councillor_liege.culture = {
					has_innovation = innovation_desert_tactics #Best way to check if the culture is Outremer
				}
				scope:councillor_liege = {
					gold >= steward_convert_culture_value
				}
			}
			add = 500
		}
		else_if = {
			limit = {
				scope:councillor_liege = {
					OR = {
						gold >= steward_convert_culture_value
						AND = {
							gold > 0
							culture = {
								OR = {
									is_hybrid_culture = yes
									is_divergent_culture = yes
								}
							}
							any_realm_county = {
								culture = {
									save_temporary_scope_as = culture_check
									scope:councillor_liege.culture = {
										any_parent_culture = {
											this = scope:culture_check
										}
									}
								}
							}
						}
					}
				}
			}
			add = 200
		}
		if = {
			limit = {
				scope:councillor_liege = {
					culture = {
						OR = {
							is_hybrid_culture = yes
							is_divergent_culture = yes
						}
					}
					any_sub_realm_county = {
						culture = {
							save_temporary_scope_as = culture_check
							scope:councillor_liege.culture = {
								any_parent_culture = {
									this = scope:culture_check
								}
							}
						}
					}
				}
			}
			add = 200
		}
		# Motivate the AI with an escalation agenda to take this task
		if = {
			limit = {
				has_character_flag = agenda_towards_escalation
			}
			add = 500
		}
		else_if = {
			limit = {
				has_character_flag = agenda_towards_deescalation
			}
			add = -250
		}
		if = {
			# Don't do this too often
			limit = {
				scope:councillor_liege = {
					has_character_flag = no_ai_culture_convert
					NAND = { # ignore it if in Hostility with escalation
						has_character_flag = agenda_towards_escalation
						any_character_struggle = {
							involvement = involved
							is_struggle_phase = struggle_iberia_phase_hostility
						}
					}
				}
			}
			multiply = 0
		}
		if = {
			# Interrupt this task if you're bankrupt
			limit = {
				scope:councillor_liege = {
					gold < -50
				}
			}
			multiply = 0
		}
	}
}