﻿task_collect_taxes = {
	default_task = yes
	position = councillor_steward

	task_type = task_type_general
	task_progress = task_progress_infinite

	effect_desc = {
		desc = task_collect_taxes_effect_desc
		triggered_desc = {
			trigger = { liege = { has_perk = tax_man_perk } }
			desc = task_collect_taxes_tax_man_bonus_desc
		}
		triggered_desc = {
			trigger = {
				exists = liege.dynasty
				liege.dynasty = { has_dynasty_perk = erudition_legacy_5 }
				}
			desc = task_collect_taxes_erudition_bonus_desc
		}
		desc = {
			desc = council_task_possible_side_effects
			triggered_desc = {
				trigger = {
					stewardship > mediocre_skill_rating
				}
				desc = task_collect_taxes_extra_taxes
			}
			triggered_desc = {
				trigger = {
					stewardship < high_skill_rating
					any_sub_realm_county = {
						steward_task_county_corruption_county_trigger = yes
					}
				}
				desc = task_collect_taxes_county_corruption
			}
		}
	}

	council_owner_modifier = {
		name = task_collect_taxes_modifier
		domain_tax_mult = 1
		scale = steward_collect_taxes_total_scale
	}

	on_start_task = {
		liege = {
			add_character_flag = {
				flag = no_steward_side_effects_first_month
				days = 30
			}
		}
	}

	on_monthly = {
		liege = {
			if = {
				limit = {
					has_character_flag = no_steward_side_effects_first_month
				}
				remove_character_flag = no_steward_side_effects_first_month
			}
			else = {
				trigger_event = {
					on_action = task_collect_taxes_side_effects
					days = { 1 30 }
				}
			}
		}
	}

	ai_will_do = {
		value = 1 # Always a good backup
		if = {
			limit = {
				scope:councillor_liege.gold < 100
			}
			add = 100
		}
	}
}

task_develop_county = {
	position = councillor_steward

	task_type = task_type_county
	county_target = realm
	ai_county_target = domain
	task_progress = task_progress_value
	task_current_value = scope:councillor_liege.steward_develop_county_current_progress
	task_max_value = 100
	highlight_own_realm = yes

	effect_desc = {
		desc = task_develop_county_complete_effect_desc
		desc = task_develop_county_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_develop_county_efficient_taxation
			}
			triggered_desc = {
				trigger = {
					stewardship > mediocre_skill_rating
					trigger_if = {
						limit = { exists = scope:county }
						scope:county = {
							county_control < full_county_control
						}
					}
				}
				desc = task_develop_county_increased_control
			}
			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_develop_county_increased_control
			}
			triggered_desc = {
				trigger = {
					stewardship < high_skill_rating
					trigger_if = {
						limit = { exists = scope:county }
						scope:county = {
							NOT = { has_county_modifier = steward_construction_slowdown_modifier }
						}
					}
				}
				desc = task_develop_county_slow_construction
			}
			triggered_desc = {
				trigger = {
					stewardship < high_skill_rating
					trigger_if = {
						limit = { exists = scope:county }
						scope:county = {
							NOT = { has_county_modifier = steward_population_mismanaged_modifier }
						}
					}
				}
				desc = task_develop_county_loss_of_opinion
			}
			triggered_desc = {
				trigger = {
					stewardship < high_skill_rating
					trigger_if = {
						limit = { exists = scope:county }
						scope:county = {
							county_control > low_county_control
						}
					}
				}
				desc = task_develop_county_loss_of_control
			}
		}
	}

	# TOTAL PROGRESS MUST MATCH THE TOTAL OF THE COUNTY MODIFIERS BELOW
		# Add all new progress values to the script value steward_develop_county_total
		# Note that for Develop County, the County Modifiers apply the actual values, while progress is for player info only
	progress = {
		value = 0
		add = {
			value = steward_develop_county_base
			desc = STEWARD_PROGRESS_BASE
		}
		add = {
			value = scope:councillor.steward_develop_county_monthly_increase
			desc = SCALED_COUNCILLOR_STEWARDSHIP_VALUE
		}
		if = {
			limit = {
				scope:councillor_liege = { has_perk = planned_cultivation_perk }
			}
			add = {
				value = scope:councillor.steward_develop_county_perk_bonus_monthly_increase
				desc = DEVELOP_COUNTY_PERK_BONUS_VALUE
			}
		}
		if = {
			limit = {
				exists = scope:councillor_liege.dynasty
				scope:councillor_liege.dynasty = { has_dynasty_perk = erudition_legacy_5 }
			}
			add = {
				value = scope:councillor.steward_develop_county_erudition_bonus_monthly_increase
				desc = ERUDITION_DYNASTY_PERK_BONUS_VALUE
			}
		}

		# Relation Bonuses/Penalties
		if = { # Friend
			limit = {
				scope:councillor_liege = {
					has_relation_friend = scope:councillor
					NOT = { has_relation_best_friend = scope:councillor }
				}
			}
			add = {
				value = scope:councillor.steward_develop_county_monthly_increase_friend_bonus
				desc = COUNCILLOR_IS_YOUR_FRIEND
			}
		}
		if = { # Best Friend
			limit = {
				scope:councillor_liege = {
					has_relation_best_friend = scope:councillor
				}
			}
			add = {
				value = scope:councillor.steward_develop_county_monthly_increase_best_friend_bonus
				desc = COUNCILLOR_IS_YOUR_BEST_FRIEND
			}
		}
		if = { # Rival
			limit = {
				scope:councillor_liege = {
					has_relation_rival = scope:councillor
					NOT = { has_relation_nemesis = scope:councillor }
				}
			}
			add = {
				value = scope:councillor.steward_develop_county_monthly_increase_rival_bonus
				desc = COUNCILLOR_IS_YOUR_RIVAL
			}
		}
		if = { # Nemesis
			limit = {
				scope:councillor_liege = {
					has_relation_nemesis = scope:councillor
				}
			}
			add = {
				value = scope:councillor.steward_develop_county_monthly_increase_nemesis_bonus
				desc = COUNCILLOR_IS_YOUR_NEMESIS
			}
		}
		if = { #Tribal penalty
			limit = {
				scope:councillor_liege = {
					should_apply_tribal_development_penalty_trigger = yes	
				}
			}
			add = {
				value = scope:councillor.steward_develop_county_tribal_penalty
				desc = DEVELOP_COUNTY_TRIBAL_PENALTY_VALUE
			}
		}	
		if = { # Development reduces the speed.
			limit = {
				exists = scope:county
				scope:county = {
					development_level > 0
				}
			}
			add = {
				value = scope:county.current_development_penalty
				desc = STEWARD_CURRENT_DEVELOPMENT_PENALTY
			}
		}
		
		if = {
			limit = { exists = scope:county }
			multiply = {
				value = scope:county.development_rate_modifier
				desc = STEWARD_COUNTY_SPEED_MODIFIERS
			}
		}
	}
	full_progress = steward_develop_county_full_progress
	custom_other_loc = STEWARD_COUNTY_SPEED_OTHER

	potential_county = {
		scope:county = {
			development_level < max_development_level
			trigger_if = {
				limit = {
					scope:councillor_liege = { is_ai = yes }
				}
				OR = {
					this = scope:councillor_liege.capital_county
					title_province = {
						OR = {
							terrain = oasis
							terrain = farmlands
							terrain = floodplains
						}
					}
				}
			}
		}
	}

	county_modifier = {
		name = steward_develop_county_modifier
		development_growth = 100
		holding_build_speed = -7
		#holding_build_gold_cost = -1
		build_speed = -7
		#build_gold_cost = -1
		scale = { value = steward_develop_county_total divide = 100 }
	}

	county_modifier = {
		name = steward_develop_county_current_development_modifier
		development_growth = 100
		scale = { value = scope:councillor.current_development_penalty divide = 100 }
	}

	county_modifier = {
		name = steward_develop_county_tribal_penalty_modifier
		development_growth = 100
		scale = {
			value = 0
			if = {
				limit = {
					scope:councillor_liege = {
						should_apply_tribal_development_penalty_trigger = yes
					}
				}
				value = scope:councillor.steward_develop_county_tribal_penalty
				divide = 100
			}
		}
	}

	on_finish_task_county = {
		if = {
			limit = {
				OR = {
					AND = {
						exists = scope:county
						scope:county = {
							development_level = max_development_level
						}
					}
					scope:councillor_liege = {
						is_ai = yes
					}
				}
			}
			start_default_task = yes
		}
		scope:councillor_liege = {
			add_character_flag = {
				flag = no_ai_increase_development
				years = 10
			}
		}
	}

	on_start_task = {
		liege = {
			add_character_flag = {
				flag = no_steward_side_effects_first_month
				days = 30
			}
		}
	}

	on_monthly_county = {
		scope:councillor_liege = {
			if = {
				limit = {
					has_character_flag = no_steward_side_effects_first_month
				}
				remove_character_flag = no_steward_side_effects_first_month
				add_character_flag = {
					flag = ai_development_max_years
					years = 10
				}
			}
			else = {
				trigger_event = {
					on_action = task_develop_county_side_effects
					days = { 1 30 }
				}
			}
			
			if = {
				limit = {
					NOT = {
						has_character_flag = ai_development_max_years
					}
				}
				add_character_flag = {
					flag = no_ai_increase_development
					years = 10
				}
			}
		}
	}

	ai_will_do = {
		value = 0
		if = {
			# Don't do this too often
			limit = {
				scope:councillor_liege = { has_character_flag = no_ai_increase_development }
			}
		}
		else_if = {
			limit = {
				scope:councillor_liege.gold >= steward_increase_development_value
			}
			add = 100
		}
	}
}

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
	
	is_shown = {
		NOT = { liege = { has_government = patrician_government } }
	}
	
	effect_desc = {
		desc = task_promote_culture_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
		}
		# Relation Bonuses/Penalties
		if = { # Friend
			limit = {
				scope:councillor_liege = {
					has_relation_friend = scope:councillor
					NOT = { has_relation_best_friend = scope:councillor }
				}
			}
			add = {
				value = scope:councillor.steward_promote_culture_monthly_increase_friend_bonus
				desc = COUNCILLOR_IS_YOUR_FRIEND
			}
		}
		if = { # Best Friend
			limit = {
				scope:councillor_liege = {
					has_relation_best_friend = scope:councillor
				}
			}
			add = {
				value = scope:councillor.steward_promote_culture_monthly_increase_best_friend_bonus
				desc = COUNCILLOR_IS_YOUR_BEST_FRIEND
			}
		}
		if = { # Rival
			limit = {
				scope:councillor_liege = {
					has_relation_rival = scope:councillor
					NOT = { has_relation_nemesis = scope:councillor }
				}
			}
			add = {
				value = scope:councillor.steward_promote_culture_monthly_increase_rival_bonus
				desc = COUNCILLOR_IS_YOUR_RIVAL
			}
		}
		if = { # Nemesis
			limit = {
				scope:councillor_liege = {
					has_relation_nemesis = scope:councillor
				}
			}
			add = {
				value = scope:councillor.steward_promote_culture_monthly_increase_nemesis_bonus
				desc = COUNCILLOR_IS_YOUR_NEMESIS
			}
		}
		if = {
			limit = {
				exists = scope:councillor_liege.dynasty
				scope:councillor_liege.dynasty = { has_dynasty_perk = erudition_legacy_5 }
			}
			add = {
				value = steward_promote_culture_erudition_bonus
				desc = ERUDITION_DYNASTY_PERK_BONUS_VALUE
			}
		}
		if = {
			limit = {
				exists = scope:county
				scope:councillor_liege.faith = {
					has_doctrine_parameter = same_faith_promote_culture_bonus_active
				}
				scope:county.faith = scope:councillor_liege.faith
			}
			add = {
				value = scope:councillor.promote_culture_communal_identity_bonus
				desc = STEWARD_PROMOTE_CULTURE_COMMUNAL_IDENTITY_BONUS_MODIFIER
			}
		}
		if = {
			limit = {
				scope:councillor_liege.culture = {
					has_innovation = innovation_east_settling
				}
			}
			add = {
				value = scope:councillor.promote_culture_east_settling_bonus
				desc = STEWARD_PROMOTE_CULTURE_INNOVATION_BONUS_EAST_SETTLING
			}
		}
		if = { # Development reduces the speed.
			limit = {
				exists = scope:county
				scope:county = {
					development_level > 0
				}
			}
			add = {
				value = scope:county.promote_culture_development_penalty
				desc = STEWARD_PROMOTE_CULTURE_DEVELOPMENT_PENALTY
			}
		}
		#Reduce for various county modifiers.
		if = { #Reduced conversion speed if the county has protected traditions.
			limit = {
				exists = scope:county
				scope:county = {
					has_county_modifier = governance_1073_conversion_resistance_modifier
				}
			}
			add = {
				value = scope:councillor.promote_culture_local_traditions_respected_penalty
				desc = STEWARD_PROMOTE_CULTURE_LOCAL_TRADITIONS_RESPECTED
			}
		}
		if = {
			limit  = {
				exists = scope:county
				scope:county = {
					has_county_modifier = county_shuubiyya_modifier
				}
			}
			add = {
				value = scope:councillor.promote_culture_shuubiyya_penalty
				desc = STEWARD_PROMOTE_CULTURE_SHUUBIYYA
			}
		}
		if = {
			limit = {
				OR = {
					scope:councillor_liege.culture_group = culture_group:goidelic_group
					scope:councillor_liege.culture_group = culture_group:brythonic_group
				}
				exists = scope:county
				scope:county = {
					has_county_modifier = reclaim_britannia_culture_modifier
					NOR= {
						culture_group = culture_group:goidelic_group
						culture_group = culture_group:brythonic_group
					}
				}
			}
			add = {
				value = promote_culture_reclaimed_brittania_bonus
				desc = STEWARD_PROMOTE_CULTURE_RECLAIMING_BRITANNIA
			}
		}
		if = {
			limit = {
				exists = scope:county
				scope:county = {
					OR = {
						has_county_modifier = enthusiastic_nomad_settlement_saharan_modifier
						has_county_modifier = nomad_settlement_saharan_modifier
					}
				}
			}
			add = {
				value = scope:councillor.promote_culture_allowed_nomad_settlement_penalty
				desc = STEWARD_PROMOTE_CULTURE_ALLOWED_NOMAD_SETTLEMENT
			}
		}
		
		# 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
			}
		}
	}

	potential_county = {
		scope:county = {
			NOT = { culture = scope:councillor_liege.culture }
		}
		trigger_if = {
			limit = {
				scope:councillor_liege = { is_ai = yes }
			}
			OR = {
				is_independent_ruler = yes
				scope:councillor_liege.primary_title.tier > tier_county
				AND = {
					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 = {
					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 = {
						# Unless they're a nomadic culture converting in the steppe or Asia Minor...
						AND = {
							OR = {
								scope:councillor_liege.culture_group = culture_group:mongolic_group
								scope:councillor_liege.culture_group = culture_group:turkic_group
							}
							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
							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_group = culture_group:west_germanic_group
								scope:county.culture_group = culture_group:goidelic_group
								scope:county.culture_group = culture_group:brythonic_group
							}
						}
						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_group = culture_group:iberian_group
							NOT = { scope:councillor_liege.culture = culture:portuguese }
							scope:county.culture = culture:visigothic
						}
					}
				}
			}
		}
	}

	on_finish_task_county = {
		scope:councillor_liege = {
			trigger_event = steward_task.0301
			if = {
				limit = {
					is_independent_ruler = no
				}
				add_character_flag = {
					flag = no_ai_culture_convert
					years = 50
				}
			}
			else = {
				add_character_flag = {
					flag = no_ai_culture_convert
					years = 20
				}
			}
		}
	}

	on_start_task = {
		liege = {
			add_character_flag = {
				flag = no_steward_side_effects_first_month
				days = 30
			}
		}
	}

	on_monthly_county = {
		scope:councillor_liege = {
			if = {
				limit = {
					has_character_flag = no_steward_side_effects_first_month
				}
				remove_character_flag = no_steward_side_effects_first_month
			}
			else = {
				trigger_event = {
					on_action = task_promote_culture_side_effects
					days = { 1 30 }
				}
			}
		}
	}

	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 = culture:outremer
				scope:councillor_liege = {
					gold >= steward_convert_culture_value
				}
			}
			add = 500
		}
		else_if = {
			limit = {
				scope:councillor_liege = {
					gold >= steward_convert_culture_value
				}
			}
			add = 200
		}
		if = {
			# The Czechs are welcome in the HRE
			limit = {
				OR = {
					scope:councillor_liege.culture = culture:czech
					scope:councillor_liege.culture = culture:german
				}
				OR = {
					scope:councillor_liege.culture = culture:czech
					scope:councillor_liege.culture = culture:german
				}
			}
			multiply = 0
		}
		if = {
			# Don't do this too often
			limit = {
				scope:councillor_liege = { has_character_flag = no_ai_culture_convert }
			}
			multiply = 0
		}
		if = {
			# Interrupt this task if you're bankrupt
			limit = {
				scope:councillor_liege = {
					gold < -50
				}
			}
			multiply = 0
		}
	}
}
