﻿task_promote_minority = {
	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

	asset = {
		icon = "gfx/interface/icons/council_task_types/task_promote_minority.dds"
		background = "gfx/interface/buttons/button_round_bg.dds"
		frame = "gfx/interface/buttons/button_round_frame.dds"
		glow = "gfx/particles/halo.dds"
	}

	effect_desc = {
		triggered_desc = {
			trigger = { exists = scope:county.var:faith_to_convert }
			desc = task_promote_minority_effect_desc_faith
		}
		triggered_desc = {
			trigger = { exists = scope:county.var:culture_to_convert }
			desc = task_promote_minority_effect_desc_culture
		}
		triggered_desc = {
			trigger = {
				NOT = {
					exists = scope:county.var:culture_to_convert
					exists = scope:county.var:faith_to_convert
				}
			}
			desc = task_promote_minority_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
			}
		}
	}

	is_shown = {
		has_game_rule = zgc_minorities_on
	}

	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

		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 = {
				has_game_rule = significantly_faster_culture_conversion_speed
			}
			multiply = {
				value = significantly_faster_game_rule_value
				desc = GAME_RULE_SIGNIFICANTLY_FASTER_REASON
			}
		}
		if = {
			limit = {
				has_game_rule = faster_culture_conversion_speed
			}
			multiply = {
				value = faster_game_rule_value
				desc = GAME_RULE_FASTER_REASON
			}
		}

		# Because the task needs to complete 3 times with the minority system
		multiply = 3
	}

	potential_county = {
		scope:county = {
			### Minority stuff ###
			scope:councillor_liege = {
				OR = {
					# Need to at least tolerate some minorities
					has_realm_law = cultural_minority_status_1
					has_realm_law = cultural_minority_status_2
					has_realm_law = religious_minority_status_1
					has_realm_law = religious_minority_status_2
				}
			}
			custom_tooltip = {
				text = must_have_different_faith_or_culture_to_promote_tt

				OR = {
					# Has minorities that aren't your own faith
					AND = {
						county_has_minority_faith_trigger = yes
						OR = {
							any_in_list = {
								variable = faith_minorities_large
								NOT = { THIS = scope:councillor_liege.faith }
							}
							any_in_list = {
								variable = faith_minorities_small
								NOT = { THIS = scope:councillor_liege.faith }
							}
						}
					}

					#...Or aren't your own culture
					AND = {
						county_has_minority_culture_trigger = yes
						OR = {
							any_in_list = {
								variable = culture_minorities_large
								NOT = { THIS = scope:councillor_liege.culture }
							}
							any_in_list = {
								variable = culture_minorities_small
								NOT = { THIS = scope:councillor_liege.culture }
							}
						}
					}
				}
			}
			### End Minority stuff ###
		}
	}

	county_modifier = {
		name = steward_convert_county_modifier
		county_opinion_add = -10
	}

	monthly_on_action = task_promote_culture_side_effects

	on_start_task_county = {
		scope:councillor_liege = {
			trigger_event = minorities.2001
		}
	}
	on_finish_task_county = {
		scope:county = {
			if = {
				limit = { exists = scope:county.var:faith_to_convert }
				promote_faith_minority_effect = { FAITH = scope:county.var:faith_to_convert }
			}
			else_if = {
				limit = { exists = scope:county.var:culture_to_convert }
				promote_culture_minority_effect = { CULTURE = scope:county.var:culture_to_convert }
				scope:county.var:culture_to_convert = {
					change_cultural_acceptance = {
						target = scope:councillor_liege.culture
						value = {
							value = 0.1
							multiply = scope:county.development_level
							if = {
								limit = {
									OR = {
										scope:county.culture = { has_cultural_parameter = cheaper_to_hybridize }
										scope:councillor_liege.culture = { has_cultural_parameter = cheaper_to_hybridize }
									}
								}
								multiply = 2
							}
							if = {
								limit = {
									OR = {
										scope:county.culture = { has_cultural_parameter = harder_to_hybridize }
										scope:councillor_liege.culture = { has_cultural_parameter = harder_to_hybridize }
									}
								}
								divide = 2
							}
						}
						desc = cultural_acceptance_loss_promote_culture
					}
				}
				if = {
					limit = {
						scope:councillor_liege.culture = {
							has_cultural_tradition = tradition_ruling_caste
						}
					}
					add_prestige = minor_prestige_gain
				}
			}
			remove_variable = faith_to_convert
			remove_variable = culture_to_convert	
		}
		scope:councillor = {
			start_default_task = yes
		}
	}

	on_cancel_task_county = {
		remove_variable = faith_to_convert
		remove_variable = culture_to_convert
	}
}