
#Triggers: any province has the basic conditions, country has adm tech 4
estate_church_build_temple_in_y = {
	can_select = {
		adm_tech = 4
		any_owned_province = {
			is_state_core = root
			NOT = { has_building = cathedral }
			OR = {
				AND = {
					NOT = { has_building = temple }
					num_free_building_slots = 1
				}
				AND = {
					ROOT = { adm_tech = 19 }
					has_building = temple
				}
			}
		}
	}
	selection_weight = {
		factor = 1
		modifier = {
			factor = 0.65
			NOT = {
				any_owned_province = {
					is_state_core = root
					base_tax = 4
					NOT = { has_building = cathedral }
					OR = {
						AND = {
							NOT = { has_building = temple }
							num_free_building_slots = 1
						}
						AND = {
							ROOT = { adm_tech = 19 }
							has_building = temple
						}
					}
				}
			}
		}
		modifier = {
			factor = 1.2
			any_owned_province = {
				is_state_core = root
				base_tax = 7
				NOT = { has_building = cathedral }
				OR = {
					AND = {
						NOT = { has_building = temple }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { adm_tech = 19 }
						has_building = temple
					}
				}
			}
		}
		modifier = {
			factor = 2
			NOT = {
				crown_land_share = 15
			}
		}
	}
	pre_effect = {
		set_variable = {
			which = estate_church_build_temple_in_y_var
			value = 0
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				NOT = { has_building = cathedral }
				OR = {
					AND = {
						NOT = { has_building = temple }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { adm_tech = 19 }
						has_building = temple
					}
				}
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				base_tax = 4
				NOT = { has_building = cathedral }
				OR = {
					AND = {
						NOT = { has_building = temple }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { adm_tech = 19 }
						has_building = temple
					}
				}
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				base_tax = 7
				NOT = { has_building = cathedral }
				OR = {
					AND = {
						NOT = { has_building = temple }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { adm_tech = 19 }
						has_building = temple
					}
				}
			}
			save_event_target_as = agenda_province
		}
		event_target:agenda_province = {
			if = {
				limit = {
					NOT = { has_building = temple }
				}
				ROOT = {
					set_variable = {
						which = estate_church_build_temple_in_y_var
						value = 1
					}
				}
			}
			else = {
				ROOT = {
					set_variable = {
						which = estate_church_build_temple_in_y_var
						value = 2
					}
				}
			}
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_church
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_church
			}
		}
		else = {
			if = {
				limit = {
					check_variable = {
						which = estate_church_build_temple_in_y_var
						value = 2
					}
				}
				event_target:agenda_province = {
					has_building = cathedral
				}
			}
			else = {
				event_target:agenda_province = {
					OR = {
						has_building = temple
						has_building = cathedral
					}
				}
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_church
		}
		add_estate_loyalty = {
			estate = estate_church
			loyalty = 10
		}
		if = {
			limit = {
				NOT = { crown_land_share = 15 }
				estate_territory = {
					estate = estate_church
					territory = 10
				}
				estate_not_has_exempt_from_seize_land_privilege = { estate = estate_church }
			}
			take_estate_land_share_small = { estate = estate_church }
		}
		else = {
			event_target:agenda_province = {
				add_base_tax = 1
			}
		}
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_clergy_displeased
					value = 5
				}
			}
		}
		add_estate_loyalty_modifier = {
			estate = estate_church
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
		}
    }
}

estate_brahmins_build_temple_in_y = {
	can_select = {
		adm_tech = 4
		if = {
			limit = {
				NOT = { religion = hinduism }
			}
			any_owned_province = {
				is_state_core = root
				religion = hinduism
				NOT = { has_building = cathedral }
				OR = {
					AND = {
						NOT = { has_building = temple }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { adm_tech = 19 }
						has_building = temple
					}
				}
			}
		}
		else = {
			any_owned_province = {
				is_state_core = root
				NOT = { has_building = cathedral }
				OR = {
					AND = {
						NOT = { has_building = temple }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { adm_tech = 19 }
						has_building = temple
					}
				}
			}
		}
	}
	selection_weight = {
		factor = 1
		modifier = {
			factor = 0.65
			NOT = {
				any_owned_province = {
					religion = hinduism
					is_state_core = root
					base_tax = 4
					NOT = { has_building = cathedral }
					OR = {
						AND = {
							NOT = { has_building = temple }
							num_free_building_slots = 1
						}
						AND = {
							ROOT = { adm_tech = 19 }
							has_building = temple
						}
					}
				}
			}
		}
		modifier = {
			factor = 1.2
			any_owned_province = {
				religion = hinduism
				is_state_core = root
				base_tax = 7
				NOT = { has_building = cathedral }
				OR = {
					AND = {
						NOT = { has_building = temple }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { adm_tech = 19 }
						has_building = temple
					}
				}
			}
		}
		modifier = {
			factor = 2
			NOT = {
				crown_land_share = 15
			}
		}
	}
	pre_effect = {
		set_variable = {
			which = estate_church_build_temple_in_y_var
			value = 0
		}
		random_owned_province = {
			limit = {
				if = {
					limit = {
						root = { NOT = { religion = hinduism } }
					}
					religion = hinduism
				}
				is_state_core = root
				NOT = { has_building = cathedral }
				OR = {
					AND = {
						NOT = { has_building = temple }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { adm_tech = 19 }
						has_building = temple
					}
				}
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				if = {
					limit = {
						root = { NOT = { religion = hinduism } }
					}
					religion = hinduism
				}
				is_state_core = root
				base_tax = 4
				NOT = { has_building = cathedral }
				OR = {
					AND = {
						NOT = { has_building = temple }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { adm_tech = 19 }
						has_building = temple
					}
				}
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				if = {
					limit = {
						root = { NOT = { religion = hinduism } }
					}
					religion = hinduism
				}
				is_state_core = root
				base_tax = 7
				NOT = { has_building = cathedral }
				OR = {
					AND = {
						NOT = { has_building = temple }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { adm_tech = 19 }
						has_building = temple
					}
				}
			}
			save_event_target_as = agenda_province
		}
		event_target:agenda_province = {
			if = {
				limit = {
					NOT = { has_building = temple }
				}
				ROOT = {
					set_variable = {
						which = estate_church_build_temple_in_y_var
						value = 1
					}
				}
			}
			else = {
				ROOT = {
					set_variable = {
						which = estate_church_build_temple_in_y_var
						value = 2
					}
				}
			}
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_brahmins
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_brahmins
			}
		}
		else = {
			if = {
				limit = {
					check_variable = {
						which = estate_church_build_temple_in_y_var
						value = 2
					}
				}
				event_target:agenda_province = {
					has_building = cathedral
				}
			}
			else = {
				event_target:agenda_province = {
					OR = {
						has_building = temple
						has_building = cathedral
					}
				}
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_brahmins
		}
		add_estate_loyalty = {
			estate = estate_brahmins
			loyalty = 10
		}
		if = {
			limit = {
				NOT = { crown_land_share = 15 }
				estate_territory = {
					estate = estate_brahmins
					territory = 10
				}
				estate_not_has_exempt_from_seize_land_privilege = { estate = estate_brahmins }
			}
			take_estate_land_share_small = { estate = estate_brahmins }
		}
		else = {
			event_target:agenda_province = {
				add_base_tax = 1
			}
		}
		event_target:agenda_province = {
			if = {
				limit = {
					root = { NOT = { religion = hinduism } }
				}
				add_province_modifier = { #balances out +3 missionary strength from cathedrals
					name = agenda_brahmins_get_a_church
					duration = 10950
				}
			}
		}
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_brahmins_displeased
					value = 5
				}
			}
		}
		add_estate_loyalty_modifier = {
			estate = estate_brahmins
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
		}
    }
}

estate_nobles_build_army_building_in_y = {
	can_select = {
		mil_tech = 6
		any_owned_province = {
			is_state_core = root
			OR = {
				NOT = { has_building = training_fields }
				NOT = { has_building = conscription_center }
			}
			OR = {
				AND = {
					NOT = { has_building = barracks }
					num_free_building_slots = 1
				}
				AND = {
					ROOT = { mil_tech = 8 }
					NOT = { has_building = regimental_camp }
					num_free_building_slots = 1
				}
				AND = {
					NOT = { has_building = training_fields }
					ROOT = { mil_tech = 16 }
					OR = {
						has_building = barracks
						num_free_building_slots = 1
					}
				}
				AND = {
					NOT = { has_building = conscription_center }
					ROOT = { mil_tech = 22 }
					OR = {
						has_building = regimental_camp
						num_free_building_slots = 1
					}
				}
			}
		}
	}
	selection_weight = {
		factor = 1
		modifier = {
			factor = 0.65
			NOT = {
				any_owned_province = {
					is_state_core = root
					base_manpower = 3
					OR = {
						NOT = { has_building = training_fields }
						NOT = { has_building = conscription_center }
					}
					OR = {
						AND = {
							NOT = { has_building = barracks }
							num_free_building_slots = 1
						}
						AND = {
							ROOT = { mil_tech = 8 }
							NOT = { has_building = regimental_camp }
							num_free_building_slots = 1
						}
						AND = {
							NOT = { has_building = training_fields }
							ROOT = { mil_tech = 16 }
							OR = {
								has_building = barracks
								num_free_building_slots = 1
							}
						}
						AND = {
							NOT = { has_building = conscription_center }
							ROOT = { mil_tech = 22 }
							OR = {
								has_building = regimental_camp
								num_free_building_slots = 1
							}
						}
					}
				}
			}
		}
		modifier = {
			factor = 1.2
			any_owned_province = {
				is_state_core = root
				base_manpower = 6
				OR = {
					NOT = { has_building = training_fields }
					NOT = { has_building = conscription_center }
				}
				OR = {
					AND = {
						NOT = { has_building = barracks }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { mil_tech = 8 }
						NOT = { has_building = regimental_camp }
						num_free_building_slots = 1
					}
					AND = {
						NOT = { has_building = training_fields }
						ROOT = { mil_tech = 16 }
						OR = {
							has_building = barracks
							num_free_building_slots = 1
						}
					}
					AND = {
						NOT = { has_building = conscription_center }
						ROOT = { mil_tech = 22 }
						OR = {
							has_building = regimental_camp
							num_free_building_slots = 1
						}
					}
				}
			}
		}
		modifier = {
			factor = 2
			NOT = {
				crown_land_share = 15
			}
		}
	}
	pre_effect = {
		set_variable = {
			which = estate_nobles_build_army_building_in_y_var
			value = 0
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				OR = {
					NOT = { has_building = training_fields }
					NOT = { has_building = conscription_center }
				}
				OR = {
					AND = {
						NOT = { has_building = barracks }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { mil_tech = 8 }
						NOT = { has_building = regimental_camp }
						num_free_building_slots = 1
					}
					AND = {
						NOT = { has_building = training_fields }
						ROOT = { mil_tech = 16 }
						OR = {
							has_building = barracks
							num_free_building_slots = 1
						}
					}
					AND = {
						NOT = { has_building = conscription_center }
						ROOT = { mil_tech = 22 }
						OR = {
							has_building = regimental_camp
							num_free_building_slots = 1
						}
					}
				}
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				base_manpower = 3
				OR = {
					NOT = { has_building = training_fields }
					NOT = { has_building = conscription_center }
				}
				OR = {
					AND = {
						NOT = { has_building = barracks }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { mil_tech = 8 }
						NOT = { has_building = regimental_camp }
						num_free_building_slots = 1
					}
					AND = {
						NOT = { has_building = training_fields }
						ROOT = { mil_tech = 16 }
						OR = {
							has_building = barracks
							num_free_building_slots = 1
						}
					}
					AND = {
						NOT = { has_building = conscription_center }
						ROOT = { mil_tech = 22 }
						OR = {
							has_building = regimental_camp
							num_free_building_slots = 1
						}
					}
				}
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				base_manpower = 6
				OR = {
					NOT = { has_building = training_fields }
					NOT = { has_building = conscription_center }
				}
				OR = {
					AND = {
						NOT = { has_building = barracks }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { mil_tech = 8 }
						NOT = { has_building = regimental_camp }
						num_free_building_slots = 1
					}
					AND = {
						NOT = { has_building = training_fields }
						ROOT = { mil_tech = 16 }
						OR = {
							has_building = barracks
							num_free_building_slots = 1
						}
					}
					AND = {
						NOT = { has_building = conscription_center }
						ROOT = { mil_tech = 22 }
						OR = {
							has_building = regimental_camp
							num_free_building_slots = 1
						}
					}
				}
			}
			save_event_target_as = agenda_province
		}
		event_target:agenda_province = {
			if = {
				limit = {
					NOT = { has_building = training_fields }
					ROOT = { mil_tech = 16 }
					OR = {
						num_free_building_slots = 1
						has_building = barracks
					}
				}
				ROOT = {
					set_variable = {
						which = estate_nobles_build_army_building_in_y_var
						value = 4
					}
				}
			}
			else_if = {
				limit = {
					NOT = { has_building = barracks }
					NOT = { has_building = training_fields }
					num_free_building_slots = 1
				}
				ROOT = {
					set_variable = {
						which = estate_nobles_build_army_building_in_y_var
						value = 3
					}
				}
			}
			else_if = {
				limit = {
					has_building = regimental_camp
					ROOT = { mil_tech = 22 }
				}
				ROOT = {
					set_variable = {
						which = estate_nobles_build_army_building_in_y_var
						value = 2
					}
				}
			}
			else = {
				ROOT = {
					set_variable = {
						which = estate_nobles_build_army_building_in_y_var
						value = 1
					}
				}
			}
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_nobles
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_nobles
			}
		}
		else = {
			if = {
				limit = {
					check_variable = {
						which = estate_nobles_build_army_building_in_y_var
						value = 4
					}
				}
				event_target:agenda_province = {
					has_building = training_fields
				}
			}
			else_if = {
				limit = {
					check_variable = {
						which = estate_nobles_build_army_building_in_y_var
						value = 3
					}
				}
				event_target:agenda_province = {
					OR = {
						has_building = barracks
						has_building = training_fields
					}
				}
			}
			else_if = {
				limit = {
					check_variable = {
						which = estate_nobles_build_army_building_in_y_var
						value = 2
					}
				}
				event_target:agenda_province = {
					has_building = conscription_center
				}
			}
			else = {
				event_target:agenda_province = {
					OR = {
						has_building = regimental_camp
						has_building = conscription_center
					}
				}
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_nobles
		}
		add_estate_loyalty = {
			estate = estate_nobles
			loyalty = 10
		}
		if = {
			limit = {
				NOT = { crown_land_share = 15 }
				estate_territory = {
					estate = estate_nobles
					territory = 10
				}
				estate_not_has_exempt_from_seize_land_privilege = { estate = estate_nobles }
			}
			take_estate_land_share_small = { estate = estate_nobles }
		}
		else = {
			event_target:agenda_province = {
				add_base_manpower = 1
			}
		}
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_nobles_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_nobles
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_rajput_build_army_building_in_y = {
	can_select = {
		mil_tech = 6
		any_owned_province = {
			is_state_core = root
			OR = {
				NOT = { has_building = training_fields }
				NOT = { has_building = conscription_center }
			}
			OR = {
				AND = {
					NOT = { has_building = barracks }
					num_free_building_slots = 1
				}
				AND = {
					ROOT = { mil_tech = 8 }
					NOT = { has_building = regimental_camp }
					num_free_building_slots = 1
				}
				AND = {
					NOT = { has_building = training_fields }
					ROOT = { mil_tech = 16 }
					OR = {
						has_building = barracks
						num_free_building_slots = 1
					}
				}
				AND = {
					NOT = { has_building = conscription_center }
					ROOT = { mil_tech = 22 }
					OR = {
						has_building = regimental_camp
						num_free_building_slots = 1
					}
				}
			}
		}
	}
	selection_weight = {
		factor = 1
		modifier = {
			factor = 0.65
			NOT = {
				any_owned_province = {
					is_state_core = root
					base_manpower = 3
					OR = {
						NOT = { has_building = training_fields }
						NOT = { has_building = conscription_center }
					}
					OR = {
						AND = {
							NOT = { has_building = barracks }
							num_free_building_slots = 1
						}
						AND = {
							ROOT = { mil_tech = 8 }
							NOT = { has_building = regimental_camp }
							num_free_building_slots = 1
						}
						AND = {
							NOT = { has_building = training_fields }
							ROOT = { mil_tech = 16 }
							OR = {
								has_building = barracks
								num_free_building_slots = 1
							}
						}
						AND = {
							NOT = { has_building = conscription_center }
							ROOT = { mil_tech = 22 }
							OR = {
								has_building = regimental_camp
								num_free_building_slots = 1
							}
						}
					}
				}
			}
		}
		modifier = {
			factor = 1.2
			any_owned_province = {
				is_state_core = root
				base_manpower = 6
				OR = {
					NOT = { has_building = training_fields }
					NOT = { has_building = conscription_center }
				}
				OR = {
					AND = {
						NOT = { has_building = barracks }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { mil_tech = 8 }
						NOT = { has_building = regimental_camp }
						num_free_building_slots = 1
					}
					AND = {
						NOT = { has_building = training_fields }
						ROOT = { mil_tech = 16 }
						OR = {
							has_building = barracks
							num_free_building_slots = 1
						}
					}
					AND = {
						NOT = { has_building = conscription_center }
						ROOT = { mil_tech = 22 }
						OR = {
							has_building = regimental_camp
							num_free_building_slots = 1
						}
					}
				}
			}
		}
		modifier = {
			factor = 2
			NOT = {
				crown_land_share = 15
			}
		}
	}
	pre_effect = {
		set_variable = {
			which = estate_nobles_build_army_building_in_y_var
			value = 0
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				OR = {
					NOT = { has_building = training_fields }
					NOT = { has_building = conscription_center }
				}
				OR = {
					AND = {
						NOT = { has_building = barracks }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { mil_tech = 8 }
						NOT = { has_building = regimental_camp }
						num_free_building_slots = 1
					}
					AND = {
						NOT = { has_building = training_fields }
						ROOT = { mil_tech = 16 }
						OR = {
							has_building = barracks
							num_free_building_slots = 1
						}
					}
					AND = {
						NOT = { has_building = conscription_center }
						ROOT = { mil_tech = 22 }
						OR = {
							has_building = regimental_camp
							num_free_building_slots = 1
						}
					}
				}
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				base_manpower = 3
				OR = {
					NOT = { has_building = training_fields }
					NOT = { has_building = conscription_center }
				}
				OR = {
					AND = {
						NOT = { has_building = barracks }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { mil_tech = 8 }
						NOT = { has_building = regimental_camp }
						num_free_building_slots = 1
					}
					AND = {
						NOT = { has_building = training_fields }
						ROOT = { mil_tech = 16 }
						OR = {
							has_building = barracks
							num_free_building_slots = 1
						}
					}
					AND = {
						NOT = { has_building = conscription_center }
						ROOT = { mil_tech = 22 }
						OR = {
							has_building = regimental_camp
							num_free_building_slots = 1
						}
					}
				}
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				base_manpower = 6
				OR = {
					NOT = { has_building = training_fields }
					NOT = { has_building = conscription_center }
				}
				OR = {
					AND = {
						NOT = { has_building = barracks }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { mil_tech = 8 }
						NOT = { has_building = regimental_camp }
						num_free_building_slots = 1
					}
					AND = {
						NOT = { has_building = training_fields }
						ROOT = { mil_tech = 16 }
						OR = {
							has_building = barracks
							num_free_building_slots = 1
						}
					}
					AND = {
						NOT = { has_building = conscription_center }
						ROOT = { mil_tech = 22 }
						OR = {
							has_building = regimental_camp
							num_free_building_slots = 1
						}
					}
				}
			}
			save_event_target_as = agenda_province
		}
		event_target:agenda_province = {
			if = {
				limit = {
					NOT = { has_building = training_fields }
					ROOT = { mil_tech = 16 }
					OR = {
						num_free_building_slots = 1
						has_building = barracks
					}
				}
				ROOT = {
					set_variable = {
						which = estate_nobles_build_army_building_in_y_var
						value = 4
					}
				}
			}
			else_if = {
				limit = {
					NOT = { has_building = training_fields }
					NOT = { has_building = barracks }
					num_free_building_slots = 1
				}
				ROOT = {
					set_variable = {
						which = estate_nobles_build_army_building_in_y_var
						value = 3
					}
				}
			}
			else_if = {
				limit = {
					has_building = regimental_camp
				}
				ROOT = {
					set_variable = {
						which = estate_nobles_build_army_building_in_y_var
						value = 2
					}
				}
			}
			else = {
				ROOT = {
					set_variable = {
						which = estate_nobles_build_army_building_in_y_var
						value = 1
					}
				}
			}
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_rajput
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_rajput
			}
		}
		else = {
			if = {
				limit = {
					check_variable = {
						which = estate_nobles_build_army_building_in_y_var
						value = 4
					}
				}
				event_target:agenda_province = {
					has_building = training_fields
				}
			}
			else_if = {
				limit = {
					check_variable = {
						which = estate_nobles_build_army_building_in_y_var
						value = 3
					}
				}
				event_target:agenda_province = {
					OR = {
						has_building = barracks
						has_building = training_fields
					}
				}
			}
			else_if = {
				limit = {
					check_variable = {
						which = estate_nobles_build_army_building_in_y_var
						value = 2
					}
				}
				event_target:agenda_province = {
					has_building = conscription_center
				}
			}
			else = {
				event_target:agenda_province = {
					OR = {
						has_building = regimental_camp
						has_building = conscription_center
					}
				}
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_rajput
		}
		add_estate_loyalty = {
			estate = estate_rajput
			loyalty = 10
		}
		if = {
			limit = {
				NOT = { crown_land_share = 15 }
				estate_territory = {
					estate = estate_rajput
					territory = 10
				}
				estate_not_has_exempt_from_seize_land_privilege = { estate = estate_rajput }
			}
			take_estate_land_share_small = { estate = estate_rajput }
		}
		else = {
			event_target:agenda_province = {
				add_base_manpower = 1
			}
		}
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_rajputs_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_rajput
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_maratha_build_army_building_in_y = {
	can_select = {
		mil_tech = 6
		any_owned_province = {
			is_state_core = root
			OR = {
				NOT = { has_building = training_fields }
				NOT = { has_building = conscription_center }
			}
			OR = {
				AND = {
					NOT = { has_building = barracks }
					num_free_building_slots = 1
				}
				AND = {
					ROOT = { mil_tech = 8 }
					NOT = { has_building = regimental_camp }
					num_free_building_slots = 1
				}
				AND = {
					NOT = { has_building = training_fields }
					ROOT = { mil_tech = 16 }
					OR = {
						has_building = barracks
						num_free_building_slots = 1
					}
				}
				AND = {
					NOT = { has_building = conscription_center }
					ROOT = { mil_tech = 22 }
					OR = {
						has_building = regimental_camp
						num_free_building_slots = 1
					}
				}
			}
		}
	}
	selection_weight = {
		factor = 1
		modifier = {
			factor = 0.65
			NOT = {
				any_owned_province = {
					is_state_core = root
					base_manpower = 3
					OR = {
						NOT = { has_building = training_fields }
						NOT = { has_building = conscription_center }
					}
					OR = {
						AND = {
							NOT = { has_building = barracks }
							num_free_building_slots = 1
						}
						AND = {
							ROOT = { mil_tech = 8 }
							NOT = { has_building = regimental_camp }
							num_free_building_slots = 1
						}
						AND = {
							NOT = { has_building = training_fields }
							ROOT = { mil_tech = 16 }
							OR = {
								has_building = barracks
								num_free_building_slots = 1
							}
						}
						AND = {
							NOT = { has_building = conscription_center }
							ROOT = { mil_tech = 22 }
							OR = {
								has_building = regimental_camp
								num_free_building_slots = 1
							}
						}
					}
				}
			}
		}
		modifier = {
			factor = 1.2
			any_owned_province = {
				is_state_core = root
				base_manpower = 6
				OR = {
					NOT = { has_building = training_fields }
					NOT = { has_building = conscription_center }
				}
				OR = {
					AND = {
						NOT = { has_building = barracks }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { mil_tech = 8 }
						NOT = { has_building = regimental_camp }
						num_free_building_slots = 1
					}
					AND = {
						NOT = { has_building = training_fields }
						ROOT = { mil_tech = 16 }
						OR = {
							has_building = barracks
							num_free_building_slots = 1
						}
					}
					AND = {
						NOT = { has_building = conscription_center }
						ROOT = { mil_tech = 22 }
						OR = {
							has_building = regimental_camp
							num_free_building_slots = 1
						}
					}
				}
			}
		}
		modifier = {
			factor = 2
			NOT = {
				crown_land_share = 15
			}
		}
	}
	pre_effect = {
		set_variable = {
			which = estate_nobles_build_army_building_in_y_var
			value = 0
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				OR = {
					NOT = { has_building = training_fields }
					NOT = { has_building = conscription_center }
				}
				OR = {
					AND = {
						NOT = { has_building = barracks }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { mil_tech = 8 }
						NOT = { has_building = regimental_camp }
						num_free_building_slots = 1
					}
					AND = {
						NOT = { has_building = training_fields }
						ROOT = { mil_tech = 16 }
						OR = {
							has_building = barracks
							num_free_building_slots = 1
						}
					}
					AND = {
						NOT = { has_building = conscription_center }
						ROOT = { mil_tech = 22 }
						OR = {
							has_building = regimental_camp
							num_free_building_slots = 1
						}
					}
				}
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				base_manpower = 3
				OR = {
					NOT = { has_building = training_fields }
					NOT = { has_building = conscription_center }
				}
				OR = {
					AND = {
						NOT = { has_building = barracks }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { mil_tech = 8 }
						NOT = { has_building = regimental_camp }
						num_free_building_slots = 1
					}
					AND = {
						NOT = { has_building = training_fields }
						ROOT = { mil_tech = 16 }
						OR = {
							has_building = barracks
							num_free_building_slots = 1
						}
					}
					AND = {
						NOT = { has_building = conscription_center }
						ROOT = { mil_tech = 22 }
						OR = {
							has_building = regimental_camp
							num_free_building_slots = 1
						}
					}
				}
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				base_manpower = 6
				OR = {
					NOT = { has_building = training_fields }
					NOT = { has_building = conscription_center }
				}
				OR = {
					AND = {
						NOT = { has_building = barracks }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { mil_tech = 8 }
						NOT = { has_building = regimental_camp }
						num_free_building_slots = 1
					}
					AND = {
						NOT = { has_building = training_fields }
						ROOT = { mil_tech = 16 }
						OR = {
							has_building = barracks
							num_free_building_slots = 1
						}
					}
					AND = {
						NOT = { has_building = conscription_center }
						ROOT = { mil_tech = 22 }
						OR = {
							has_building = regimental_camp
							num_free_building_slots = 1
						}
					}
				}
			}
			save_event_target_as = agenda_province
		}
		event_target:agenda_province = {
			if = {
				limit = {
					NOT = { has_building = training_fields }
					ROOT = { mil_tech = 16 }
					OR = {
						num_free_building_slots = 1
						has_building = barracks
					}
				}
				ROOT = {
					set_variable = {
						which = estate_nobles_build_army_building_in_y_var
						value = 4
					}
				}
			}
			else_if = {
				limit = {
					NOT = { has_building = barracks }
					NOT = { has_building = training_fields }
					num_free_building_slots = 1
				}
				ROOT = {
					set_variable = {
						which = estate_nobles_build_army_building_in_y_var
						value = 3
					}
				}
			}
			else_if = {
				limit = {
					has_building = regimental_camp
				}
				ROOT = {
					set_variable = {
						which = estate_nobles_build_army_building_in_y_var
						value = 2
					}
				}
			}
			else = {
				ROOT = {
					set_variable = {
						which = estate_nobles_build_army_building_in_y_var
						value = 1
					}
				}
			}
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_maratha
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_maratha
			}
		}
		else = {
			if = {
				limit = {
					check_variable = {
						which = estate_nobles_build_army_building_in_y_var
						value = 4
					}
				}
				event_target:agenda_province = {
					has_building = training_fields
				}
			}
			else_if = {
				limit = {
					check_variable = {
						which = estate_nobles_build_army_building_in_y_var
						value = 3
					}
				}
				event_target:agenda_province = {
					OR = {
						has_building = barracks
						has_building = training_fields
					}
				}
			}
			else_if = {
				limit = {
					check_variable = {
						which = estate_nobles_build_army_building_in_y_var
						value = 2
					}
				}
				event_target:agenda_province = {
					has_building = conscription_center
				}
			}
			else = {
				event_target:agenda_province = {
					OR = {
						has_building = regimental_camp
						has_building = conscription_center
					}
				}
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_maratha
		}
		add_estate_loyalty = {
			estate = estate_maratha
			loyalty = 10
		}
		if = {
			limit = {
				NOT = { crown_land_share = 15 }
				estate_territory = {
					estate = estate_maratha
					territory = 10
				}
				estate_not_has_exempt_from_seize_land_privilege = { estate = estate_maratha }
			}
			take_estate_land_share_small = { estate = estate_maratha }
		}
		else = {
			event_target:agenda_province = {
				add_base_manpower = 1
			}
		}
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_marathas_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_maratha
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_qizilbash_build_army_building_in_y = {
	can_select = {
		mil_tech = 6
		any_owned_province = {
			NOT = { religion_group = ROOT }
			is_state_core = root
			OR = {
				NOT = { has_building = training_fields }
				NOT = { has_building = conscription_center }
			}
			OR = {
				AND = {
					NOT = { has_building = barracks }
					num_free_building_slots = 1
				}
				AND = {
					ROOT = { mil_tech = 8 }
					NOT = { has_building = regimental_camp }
					num_free_building_slots = 1
				}
				AND = {
					NOT = { has_building = training_fields }
					ROOT = { mil_tech = 16 }
					OR = {
						has_building = barracks
						num_free_building_slots = 1
					}
				}
				AND = {
					NOT = { has_building = conscription_center }
					ROOT = { mil_tech = 22 }
					OR = {
						has_building = regimental_camp
						num_free_building_slots = 1
					}
				}
			}
		}
	}
	selection_weight = {
		factor = 1
		modifier = {
			factor = 0.65
			NOT = {
				any_owned_province = {
					NOT = { religion_group = ROOT }
					is_state_core = root
					base_manpower = 3
					OR = {
						NOT = { has_building = training_fields }
						NOT = { has_building = conscription_center }
					}
					OR = {
						AND = {
							NOT = { has_building = barracks }
							num_free_building_slots = 1
						}
						AND = {
							ROOT = { mil_tech = 8 }
							NOT = { has_building = regimental_camp }
							num_free_building_slots = 1
						}
						AND = {
							NOT = { has_building = training_fields }
							ROOT = { mil_tech = 16 }
							OR = {
								has_building = barracks
								num_free_building_slots = 1
							}
						}
						AND = {
							NOT = { has_building = conscription_center }
							ROOT = { mil_tech = 22 }
							OR = {
								has_building = regimental_camp
								num_free_building_slots = 1
							}
						}
					}
				}
			}
		}
		modifier = {
			factor = 1.2
			any_owned_province = {
				NOT = { religion_group = ROOT }
				is_state_core = root
				base_manpower = 6
				OR = {
					NOT = { has_building = training_fields }
					NOT = { has_building = conscription_center }
				}
				OR = {
					AND = {
						NOT = { has_building = barracks }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { mil_tech = 8 }
						NOT = { has_building = regimental_camp }
						num_free_building_slots = 1
					}
					AND = {
						NOT = { has_building = training_fields }
						ROOT = { mil_tech = 16 }
						OR = {
							has_building = barracks
							num_free_building_slots = 1
						}
					}
					AND = {
						NOT = { has_building = conscription_center }
						ROOT = { mil_tech = 22 }
						OR = {
							has_building = regimental_camp
							num_free_building_slots = 1
						}
					}
				}
			}
		}
		modifier = {
			factor = 2
			NOT = {
				crown_land_share = 15
			}
		}
		modifier = {
			factor = 0
			has_estate_privilege = estate_janissary_allow_other_professions
		}
	}
	pre_effect = {
		set_variable = {
			which = estate_qizilbash_build_army_building_in_y_var
			value = 0
		}
		random_owned_province = {
			limit = {
				NOT = { religion_group = ROOT }
				is_state_core = root
				OR = {
					NOT = { has_building = training_fields }
					NOT = { has_building = conscription_center }
				}
				OR = {
					AND = {
						NOT = { has_building = barracks }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { mil_tech = 8 }
						NOT = { has_building = regimental_camp }
						num_free_building_slots = 1
					}
					AND = {
						NOT = { has_building = training_fields }
						ROOT = { mil_tech = 16 }
						OR = {
							has_building = barracks
							num_free_building_slots = 1
						}
					}
					AND = {
						NOT = { has_building = conscription_center }
						ROOT = { mil_tech = 22 }
						OR = {
							has_building = regimental_camp
							num_free_building_slots = 1
						}
					}
				}
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				NOT = { religion_group = ROOT }
				is_state_core = root
				base_manpower = 3
				OR = {
					NOT = { has_building = training_fields }
					NOT = { has_building = conscription_center }
				}
				OR = {
					AND = {
						NOT = { has_building = barracks }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { mil_tech = 8 }
						NOT = { has_building = regimental_camp }
						num_free_building_slots = 1
					}
					AND = {
						NOT = { has_building = training_fields }
						ROOT = { mil_tech = 16 }
						OR = {
							has_building = barracks
							num_free_building_slots = 1
						}
					}
					AND = {
						NOT = { has_building = conscription_center }
						ROOT = { mil_tech = 22 }
						OR = {
							has_building = regimental_camp
							num_free_building_slots = 1
						}
					}
				}
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				NOT = { religion_group = ROOT }
				is_state_core = root
				base_manpower = 6
				OR = {
					NOT = { has_building = training_fields }
					NOT = { has_building = conscription_center }
				}
				OR = {
					AND = {
						NOT = { has_building = barracks }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { mil_tech = 8 }
						NOT = { has_building = regimental_camp }
						num_free_building_slots = 1
					}
					AND = {
						NOT = { has_building = training_fields }
						ROOT = { mil_tech = 16 }
						OR = {
							has_building = barracks
							num_free_building_slots = 1
						}
					}
					AND = {
						NOT = { has_building = conscription_center }
						ROOT = { mil_tech = 22 }
						OR = {
							has_building = regimental_camp
							num_free_building_slots = 1
						}
					}
				}
			}
			save_event_target_as = agenda_province
		}
		event_target:agenda_province = {
			if = {
				limit = {
					NOT = { has_building = training_fields }
					ROOT = { mil_tech = 16 }
					OR = {
						num_free_building_slots = 1
						has_building = barracks
					}
				}
				ROOT = {
					set_variable = {
						which = estate_qizilbash_build_army_building_in_y_var
						value = 4
					}
				}
			}
			else_if = {
				limit = {
					NOT = { has_building = barracks }
					NOT = { has_building = training_fields }
					num_free_building_slots = 1
				}
				ROOT = {
					set_variable = {
						which = estate_qizilbash_build_army_building_in_y_var
						value = 3
					}
				}
			}
			else_if = {
				limit = {
					has_building = regimental_camp
					ROOT = { mil_tech = 22 }
				}
				ROOT = {
					set_variable = {
						which = estate_qizilbash_build_army_building_in_y_var
						value = 2
					}
				}
			}
			else = {
				ROOT = {
					set_variable = {
						which = estate_qizilbash_build_army_building_in_y_var
						value = 1
					}
				}
			}
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				check_variable = {
					which = estate_qizilbash_build_army_building_in_y_var
					value = 4
				}
			}
			event_target:agenda_province = {
				has_building = training_fields
			}
		}
		else_if = {
			limit = {
				check_variable = {
					which = estate_qizilbash_build_army_building_in_y_var
					value = 3
				}
			}
			event_target:agenda_province = {
				OR = {
					has_building = barracks
					has_building = training_fields
				}
			}
		}
		else_if = {
			limit = {
				check_variable = {
					which = estate_qizilbash_build_army_building_in_y_var
					value = 2
				}
			}
			event_target:agenda_province = {
				has_building = conscription_center
			}
		}
		else = {
			event_target:agenda_province = {
				OR = {
					has_building = regimental_camp
					has_building = conscription_center
				}
			}
		}
    }
    task_completed_effect = {
		add_estate_loyalty = {
			estate = estate_qizilbash
			loyalty = 10
		}
		if = {
			limit = {
				NOT = { crown_land_share = 15 }
				estate_territory = {
					estate = estate_qizilbash
					territory = 10
				}
			}
			take_estate_land_share_small = { estate = estate_qizilbash }
		}
		else = {
			event_target:agenda_province = {
				add_base_manpower = 1
			}
		}
    }
    failing_effect = {
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_qizilbash_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_qizilbash
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_ghulams_build_army_building_in_y = {
	can_select = {
		mil_tech = 6
		any_owned_province = {
			NOT = { religion_group = ROOT }
			is_state_core = root
			OR = {
				NOT = { has_building = training_fields }
				NOT = { has_building = conscription_center }
			}
			OR = {
				AND = {
					NOT = { has_building = barracks }
					num_free_building_slots = 1
				}
				AND = {
					ROOT = { mil_tech = 8 }
					NOT = { has_building = regimental_camp }
					num_free_building_slots = 1
				}
				AND = {
					NOT = { has_building = training_fields }
					ROOT = { mil_tech = 16 }
					OR = {
						has_building = barracks
						num_free_building_slots = 1
					}
				}
				AND = {
					NOT = { has_building = conscription_center }
					ROOT = { mil_tech = 22 }
					OR = {
						has_building = regimental_camp
						num_free_building_slots = 1
					}
				}
			}
		}
	}
	selection_weight = {
		factor = 1
		modifier = {
			factor = 0.65
			NOT = {
				any_owned_province = {
					NOT = { religion_group = ROOT }
					is_state_core = root
					base_manpower = 3
					OR = {
						NOT = { has_building = training_fields }
						NOT = { has_building = conscription_center }
					}
					OR = {
						AND = {
							NOT = { has_building = barracks }
							num_free_building_slots = 1
						}
						AND = {
							ROOT = { mil_tech = 8 }
							NOT = { has_building = regimental_camp }
							num_free_building_slots = 1
						}
						AND = {
							NOT = { has_building = training_fields }
							ROOT = { mil_tech = 16 }
							OR = {
								has_building = barracks
								num_free_building_slots = 1
							}
						}
						AND = {
							NOT = { has_building = conscription_center }
							ROOT = { mil_tech = 22 }
							OR = {
								has_building = regimental_camp
								num_free_building_slots = 1
							}
						}
					}
				}
			}
		}
		modifier = {
			factor = 1.2
			any_owned_province = {
				NOT = { religion_group = ROOT }
				is_state_core = root
				base_manpower = 6
				OR = {
					NOT = { has_building = training_fields }
					NOT = { has_building = conscription_center }
				}
				OR = {
					AND = {
						NOT = { has_building = barracks }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { mil_tech = 8 }
						NOT = { has_building = regimental_camp }
						num_free_building_slots = 1
					}
					AND = {
						NOT = { has_building = training_fields }
						ROOT = { mil_tech = 16 }
						OR = {
							has_building = barracks
							num_free_building_slots = 1
						}
					}
					AND = {
						NOT = { has_building = conscription_center }
						ROOT = { mil_tech = 22 }
						OR = {
							has_building = regimental_camp
							num_free_building_slots = 1
						}
					}
				}
			}
		}
		modifier = {
			factor = 2
			NOT = {
				crown_land_share = 15
			}
		}
		modifier = {
			factor = 0
			has_estate_privilege = estate_janissary_allow_other_professions
		}
	}
	pre_effect = {
		set_variable = {
			which = estate_ghulams_build_army_building_in_y_var
			value = 0
		}
		random_owned_province = {
			limit = {
				NOT = { religion_group = ROOT }
				is_state_core = root
				OR = {
					NOT = { has_building = training_fields }
					NOT = { has_building = conscription_center }
				}
				OR = {
					AND = {
						NOT = { has_building = barracks }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { mil_tech = 8 }
						NOT = { has_building = regimental_camp }
						num_free_building_slots = 1
					}
					AND = {
						NOT = { has_building = training_fields }
						ROOT = { mil_tech = 16 }
						OR = {
							has_building = barracks
							num_free_building_slots = 1
						}
					}
					AND = {
						NOT = { has_building = conscription_center }
						ROOT = { mil_tech = 22 }
						OR = {
							has_building = regimental_camp
							num_free_building_slots = 1
						}
					}
				}
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				NOT = { religion_group = ROOT }
				is_state_core = root
				base_manpower = 3
				OR = {
					NOT = { has_building = training_fields }
					NOT = { has_building = conscription_center }
				}
				OR = {
					AND = {
						NOT = { has_building = barracks }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { mil_tech = 8 }
						NOT = { has_building = regimental_camp }
						num_free_building_slots = 1
					}
					AND = {
						NOT = { has_building = training_fields }
						ROOT = { mil_tech = 16 }
						OR = {
							has_building = barracks
							num_free_building_slots = 1
						}
					}
					AND = {
						NOT = { has_building = conscription_center }
						ROOT = { mil_tech = 22 }
						OR = {
							has_building = regimental_camp
							num_free_building_slots = 1
						}
					}
				}
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				NOT = { religion_group = ROOT }
				is_state_core = root
				base_manpower = 6
				OR = {
					NOT = { has_building = training_fields }
					NOT = { has_building = conscription_center }
				}
				OR = {
					AND = {
						NOT = { has_building = barracks }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { mil_tech = 8 }
						NOT = { has_building = regimental_camp }
						num_free_building_slots = 1
					}
					AND = {
						NOT = { has_building = training_fields }
						ROOT = { mil_tech = 16 }
						OR = {
							has_building = barracks
							num_free_building_slots = 1
						}
					}
					AND = {
						NOT = { has_building = conscription_center }
						ROOT = { mil_tech = 22 }
						OR = {
							has_building = regimental_camp
							num_free_building_slots = 1
						}
					}
				}
			}
			save_event_target_as = agenda_province
		}
		event_target:agenda_province = {
			if = {
				limit = {
					NOT = { has_building = training_fields }
					ROOT = { mil_tech = 16 }
					OR = {
						num_free_building_slots = 1
						has_building = barracks
					}
				}
				ROOT = {
					set_variable = {
						which = estate_ghulams_build_army_building_in_y_var
						value = 4
					}
				}
			}
			else_if = {
				limit = {
					NOT = { has_building = barracks }
					NOT = { has_building = training_fields }
					num_free_building_slots = 1
				}
				ROOT = {
					set_variable = {
						which = estate_ghulams_build_army_building_in_y_var
						value = 3
					}
				}
			}
			else_if = {
				limit = {
					has_building = regimental_camp
					ROOT = { mil_tech = 22 }
				}
				ROOT = {
					set_variable = {
						which = estate_ghulams_build_army_building_in_y_var
						value = 2
					}
				}
			}
			else = {
				ROOT = {
					set_variable = {
						which = estate_ghulams_build_army_building_in_y_var
						value = 1
					}
				}
			}
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				check_variable = {
					which = estate_ghulams_build_army_building_in_y_var
					value = 4
				}
			}
			event_target:agenda_province = {
				has_building = training_fields
			}
		}
		else_if = {
			limit = {
				check_variable = {
					which = estate_ghulams_build_army_building_in_y_var
					value = 3
				}
			}
			event_target:agenda_province = {
				OR = {
					has_building = barracks
					has_building = training_fields
				}
			}
		}
		else_if = {
			limit = {
				check_variable = {
					which = estate_ghulams_build_army_building_in_y_var
					value = 2
				}
			}
			event_target:agenda_province = {
				has_building = conscription_center
			}
		}
		else = {
			event_target:agenda_province = {
				OR = {
					has_building = regimental_camp
					has_building = conscription_center
				}
			}
		}
    }
    task_completed_effect = {
		add_estate_loyalty = {
			estate = estate_ghulams
			loyalty = 10
		}
		if = {
			limit = {
				NOT = { crown_land_share = 15 }
				estate_territory = {
					estate = estate_ghulams
					territory = 10
				}
			}
			take_estate_land_share_small = { estate = estate_ghulams }
		}
		else = {
			event_target:agenda_province = {
				add_base_manpower = 1
			}
		}
    }
    failing_effect = {
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_ghulams_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_ghulams
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_nobles_build_fort_building_in_y = {
	can_select = {
		any_owned_province = {
			OR = {
				AND = {
					NOT = { has_building = fort_15th }
					NOT = { has_building = fort_16th }
					NOT = { has_building = fort_17th }
					NOT = { has_building = fort_18th }
					num_free_building_slots = 1
					any_neighbor_province = {
						owner = {
							OR = {
								is_rival = root
								root = { is_rival = prev }
								AND = {
									is_subject_other_than_tributary_trigger = yes
									overlord = {
										OR = {
											is_rival = root
											root = { is_rival = prev }
										}
									}
								}
							}
						}
					}
					NOT = {
						any_neighbor_province = {
							owned_by = root
							OR = {
								has_building = fort_15th
								has_building = fort_16th
								has_building = fort_17th
								has_building = fort_18th
							}
						}
					}
				}
				AND = {
					NOT = { has_building = fort_15th }
					NOT = { has_building = fort_16th }
					NOT = { has_building = fort_17th }
					NOT = { has_building = fort_18th }
					num_free_building_slots = 1
					any_neighbor_province = {
						owned_by = root
						any_neighbor_province = {
							owner = {
								OR = {
									is_rival = root
									root = { is_rival = prev }
									AND = {
										is_subject_other_than_tributary_trigger = yes
										overlord = {
											OR = {
												is_rival = root
												root = { is_rival = prev }
											}
										}
									}
								}
							}
							NOT = {
								any_neighbor_province = {
									owned_by = root
									OR = {
										has_building = fort_15th
										has_building = fort_16th
										has_building = fort_17th
										has_building = fort_18th
									}
								}
							}
						}
					}
				}
				AND = {
					has_building = fort_15th
					ROOT = { mil_tech = 14 }
				}
				AND = {
					has_building = fort_16th
					ROOT = { mil_tech = 19 }
				}
				AND = {
					has_building = fort_17th
					ROOT = { mil_tech = 24 }
				}
			}
			NOT = { has_building = fort_18th }
		}
	}
	selection_weight = {
		factor = 1
		modifier = {
			factor = 1.5
			any_neighbor_country = {
				OR = {
					is_rival = root
					root = { is_rival = prev }
				}
				army_size = root
			}
		}
	}
	pre_effect = {
		set_variable = {
			which = estate_nobles_build_fort_building_in_y_var
			value = 0
		}
		random_owned_province = {
			limit = {
				OR = {
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owner = {
								OR = {
									is_rival = root
									root = { is_rival = prev }
									AND = {
										is_subject_other_than_tributary_trigger = yes
										overlord = {
											OR = {
												is_rival = root
												root = { is_rival = prev }
											}
										}
									}
								}
							}
						}
						NOT = {
							any_neighbor_province = {
								owned_by = root
								OR = {
									has_building = fort_15th
									has_building = fort_16th
									has_building = fort_17th
									has_building = fort_18th
								}
							}
						}
					}
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owned_by = root
							any_neighbor_province = {
								owner = {
									OR = {
										is_rival = root
										root = { is_rival = prev }
										AND = {
											is_subject_other_than_tributary_trigger = yes
											overlord = {
												OR = {
													is_rival = root
													root = { is_rival = prev }
												}
											}
										}
									}
								}
								NOT = {
									any_neighbor_province = {
										owned_by = root
										OR = {
											has_building = fort_15th
											has_building = fort_16th
											has_building = fort_17th
											has_building = fort_18th
										}
									}
								}
							}
						}
					}
					AND = {
						has_building = fort_15th
						ROOT = { mil_tech = 14 }
					}
					AND = {
						has_building = fort_16th
						ROOT = { mil_tech = 19 }
					}
					AND = {
						has_building = fort_17th
						ROOT = { mil_tech = 24 }
					}
				}
				NOT = { has_building = fort_18th }
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				OR = {
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owner = {
								OR = {
									is_rival = root
									root = { is_rival = prev }
									AND = {
										is_subject_other_than_tributary_trigger = yes
										overlord = {
											OR = {
												is_rival = root
												root = { is_rival = prev }
											}
										}
									}
								}
							}
						}
						NOT = {
							any_neighbor_province = {
								owned_by = root
								OR = {
									has_building = fort_15th
									has_building = fort_16th
									has_building = fort_17th
									has_building = fort_18th
								}
							}
						}
						has_terrain = hills
					}
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owned_by = root
							any_neighbor_province = {
								owner = {
									OR = {
										is_rival = root
										root = { is_rival = prev }
										AND = {
											is_subject_other_than_tributary_trigger = yes
											overlord = {
												OR = {
													is_rival = root
													root = { is_rival = prev }
												}
											}
										}
									}
								}
								NOT = {
									any_neighbor_province = {
										owned_by = root
										OR = {
											has_building = fort_15th
											has_building = fort_16th
											has_building = fort_17th
											has_building = fort_18th
										}
									}
								}
							}
						}
						has_terrain = hills
					}
					AND = {
						has_building = fort_15th
						ROOT = { mil_tech = 14 }
					}
					AND = {
						has_building = fort_16th
						ROOT = { mil_tech = 19 }
					}
					AND = {
						has_building = fort_17th
						ROOT = { mil_tech = 24 }
					}
				}
				NOT = { has_building = fort_18th }
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				OR = {
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owner = {
								OR = {
									is_rival = root
									root = { is_rival = prev }
									AND = {
										is_subject_other_than_tributary_trigger = yes
										overlord = {
											OR = {
												is_rival = root
												root = { is_rival = prev }
											}
										}
									}
								}
							}
						}
						NOT = {
							any_neighbor_province = {
								owned_by = root
								OR = {
									has_building = fort_15th
									has_building = fort_16th
									has_building = fort_17th
									has_building = fort_18th
								}
							}
						}
						has_terrain = highlands
					}
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owned_by = root
							any_neighbor_province = {
								owner = {
									OR = {
										is_rival = root
										root = { is_rival = prev }
										AND = {
											is_subject_other_than_tributary_trigger = yes
											overlord = {
												OR = {
													is_rival = root
													root = { is_rival = prev }
												}
											}
										}
									}
								}
								NOT = {
									any_neighbor_province = {
										owned_by = root
										OR = {
											has_building = fort_15th
											has_building = fort_16th
											has_building = fort_17th
											has_building = fort_18th
										}
									}
								}
							}
						}
						has_terrain = highlands
					}
					AND = {
						has_building = fort_15th
						ROOT = { mil_tech = 14 }
					}
					AND = {
						has_building = fort_16th
						ROOT = { mil_tech = 19 }
					}
					AND = {
						has_building = fort_17th
						ROOT = { mil_tech = 24 }
					}
				}
				NOT = { has_building = fort_18th }
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				OR = {
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owner = {
								OR = {
									is_rival = root
									root = { is_rival = prev }
									AND = {
										is_subject_other_than_tributary_trigger = yes
										overlord = {
											OR = {
												is_rival = root
												root = { is_rival = prev }
											}
										}
									}
								}
							}
						}
						NOT = {
							any_neighbor_province = {
								owned_by = root
								OR = {
									has_building = fort_15th
									has_building = fort_16th
									has_building = fort_17th
									has_building = fort_18th
								}
							}
						}
						has_terrain = mountain
					}
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owned_by = root
							any_neighbor_province = {
								owner = {
									OR = {
										is_rival = root
										root = { is_rival = prev }
										AND = {
											is_subject_other_than_tributary_trigger = yes
											overlord = {
												OR = {
													is_rival = root
													root = { is_rival = prev }
												}
											}
										}
									}
								}
								NOT = {
									any_neighbor_province = {
										owned_by = root
										OR = {
											has_building = fort_15th
											has_building = fort_16th
											has_building = fort_17th
											has_building = fort_18th
										}
									}
								}
							}
						}
						has_terrain = mountain
					}
					AND = {
						has_building = fort_15th
						ROOT = { mil_tech = 14 }
					}
					AND = {
						has_building = fort_16th
						ROOT = { mil_tech = 19 }
					}
					AND = {
						has_building = fort_17th
						ROOT = { mil_tech = 24 }
					}
				}
				NOT = { has_building = fort_18th }
			}
			save_event_target_as = agenda_province
		}
		event_target:agenda_province = {
			if = {
				limit = {
					has_building = fort_17th
				}
				ROOT = {
					set_variable = {
						which = estate_nobles_build_fort_building_in_y_var
						value = 4
					}
				}
			}
			else_if = {
				limit = {
					has_building = fort_16th
				}
				ROOT = {
					set_variable = {
						which = estate_nobles_build_fort_building_in_y_var
						value = 3
					}
				}
			}
			else_if = {
				limit = {
					has_building = fort_15th
				}
				ROOT = {
					set_variable = {
						which = estate_nobles_build_fort_building_in_y_var
						value = 2
					}
				}
			}
			else = {
				ROOT = {
					set_variable = {
						which = estate_nobles_build_fort_building_in_y_var
						value = 1
					}
				}
			}
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_nobles
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_nobles
			}
		}
		else = {
			if = {
				limit = {
					check_variable = {
						which = estate_nobles_build_fort_building_in_y_var
						value = 4
					}
				}
				event_target:agenda_province = {
					has_building = fort_18th
				}
			}
			else_if = {
				limit = {
					check_variable = {
						which = estate_nobles_build_fort_building_in_y_var
						value = 3
					}
				}
				event_target:agenda_province = {
					OR = {
						has_building = fort_17th
						has_building = fort_18th
					}
				}
			}
			else_if = {
				limit = {
					check_variable = {
						which = estate_nobles_build_fort_building_in_y_var
						value = 2
					}
				}
				event_target:agenda_province = {
					OR = {
						has_building = fort_16th
						has_building = fort_17th
						has_building = fort_18th
					}
				}
			}
			else = {
				event_target:agenda_province = {
					OR = {
						has_building = fort_15th
						has_building = fort_16th
						has_building = fort_17th
						has_building = fort_18th
					}
				}
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_nobles
		}
		add_estate_loyalty = {
			estate = estate_nobles
			loyalty = 10
		}
		event_target:agenda_province = {
			add_base_manpower = 1
		}
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_nobles_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_nobles
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_rajput_build_fort_building_in_y = {
	can_select = {
		any_owned_province = {
			OR = {
				AND = {
					NOT = { has_building = fort_15th }
					NOT = { has_building = fort_16th }
					NOT = { has_building = fort_17th }
					NOT = { has_building = fort_18th }
					num_free_building_slots = 1
					any_neighbor_province = {
						owner = {
							OR = {
								is_rival = root
								root = { is_rival = prev }
								AND = {
									is_subject_other_than_tributary_trigger = yes
									overlord = {
										OR = {
											is_rival = root
											root = { is_rival = prev }
										}
									}
								}
							}
						}
					}
					NOT = {
						any_neighbor_province = {
							owned_by = root
							OR = {
								has_building = fort_15th
								has_building = fort_16th
								has_building = fort_17th
								has_building = fort_18th
							}
						}
					}
				}
				AND = {
					NOT = { has_building = fort_15th }
					NOT = { has_building = fort_16th }
					NOT = { has_building = fort_17th }
					NOT = { has_building = fort_18th }
					num_free_building_slots = 1
					any_neighbor_province = {
						owned_by = root
						any_neighbor_province = {
							owner = {
								OR = {
									is_rival = root
									root = { is_rival = prev }
									AND = {
										is_subject_other_than_tributary_trigger = yes
										overlord = {
											OR = {
												is_rival = root
												root = { is_rival = prev }
											}
										}
									}
								}
							}
							NOT = {
								any_neighbor_province = {
									owned_by = root
									OR = {
										has_building = fort_15th
										has_building = fort_16th
										has_building = fort_17th
										has_building = fort_18th
									}
								}
							}
						}
					}
				}
				AND = {
					has_building = fort_15th
					ROOT = { mil_tech = 14 }
				}
				AND = {
					has_building = fort_16th
					ROOT = { mil_tech = 19 }
				}
				AND = {
					has_building = fort_17th
					ROOT = { mil_tech = 24 }
				}
			}
			NOT = { has_building = fort_18th }
		}
	}
	selection_weight = {
		factor = 1
		modifier = {
			factor = 1.5
			any_neighbor_country = {
				OR = {
					is_rival = root
					root = { is_rival = prev }
				}
				army_size = root
			}
		}
	}
	pre_effect = {
		set_variable = {
			which = estate_nobles_build_fort_building_in_y_var
			value = 0
		}
		random_owned_province = {
			limit = {
				OR = {
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owner = {
								OR = {
									is_rival = root
									root = { is_rival = prev }
									AND = {
										is_subject_other_than_tributary_trigger = yes
										overlord = {
											OR = {
												is_rival = root
												root = { is_rival = prev }
											}
										}
									}
								}
							}
						}
						NOT = {
							any_neighbor_province = {
								owned_by = root
								OR = {
									has_building = fort_15th
									has_building = fort_16th
									has_building = fort_17th
									has_building = fort_18th
								}
							}
						}
					}
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owned_by = root
							any_neighbor_province = {
								owner = {
									OR = {
										is_rival = root
										root = { is_rival = prev }
										AND = {
											is_subject_other_than_tributary_trigger = yes
											overlord = {
												OR = {
													is_rival = root
													root = { is_rival = prev }
												}
											}
										}
									}
								}
								NOT = {
									any_neighbor_province = {
										owned_by = root
										OR = {
											has_building = fort_15th
											has_building = fort_16th
											has_building = fort_17th
											has_building = fort_18th
										}
									}
								}
							}
						}
					}
					AND = {
						has_building = fort_15th
						ROOT = { mil_tech = 14 }
					}
					AND = {
						has_building = fort_16th
						ROOT = { mil_tech = 19 }
					}
					AND = {
						has_building = fort_17th
						ROOT = { mil_tech = 24 }
					}
				}
				NOT = { has_building = fort_18th }
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				OR = {
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owner = {
								OR = {
									is_rival = root
									root = { is_rival = prev }
									AND = {
										is_subject_other_than_tributary_trigger = yes
										overlord = {
											OR = {
												is_rival = root
												root = { is_rival = prev }
											}
										}
									}
								}
							}
						}
						NOT = {
							any_neighbor_province = {
								owned_by = root
								OR = {
									has_building = fort_15th
									has_building = fort_16th
									has_building = fort_17th
									has_building = fort_18th
								}
							}
						}
						has_terrain = hills
					}
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owned_by = root
							any_neighbor_province = {
								owner = {
									OR = {
										is_rival = root
										root = { is_rival = prev }
										AND = {
											is_subject_other_than_tributary_trigger = yes
											overlord = {
												OR = {
													is_rival = root
													root = { is_rival = prev }
												}
											}
										}
									}
								}
								NOT = {
									any_neighbor_province = {
										owned_by = root
										OR = {
											has_building = fort_15th
											has_building = fort_16th
											has_building = fort_17th
											has_building = fort_18th
										}
									}
								}
							}
						}
						has_terrain = hills
					}
					AND = {
						has_building = fort_15th
						ROOT = { mil_tech = 14 }
					}
					AND = {
						has_building = fort_16th
						ROOT = { mil_tech = 19 }
					}
					AND = {
						has_building = fort_17th
						ROOT = { mil_tech = 24 }
					}
				}
				NOT = { has_building = fort_18th }
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				OR = {
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owner = {
								OR = {
									is_rival = root
									root = { is_rival = prev }
									AND = {
										is_subject_other_than_tributary_trigger = yes
										overlord = {
											OR = {
												is_rival = root
												root = { is_rival = prev }
											}
										}
									}
								}
							}
						}
						NOT = {
							any_neighbor_province = {
								owned_by = root
								OR = {
									has_building = fort_15th
									has_building = fort_16th
									has_building = fort_17th
									has_building = fort_18th
								}
							}
						}
						has_terrain = highlands
					}
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owned_by = root
							any_neighbor_province = {
								owner = {
									OR = {
										is_rival = root
										root = { is_rival = prev }
										AND = {
											is_subject_other_than_tributary_trigger = yes
											overlord = {
												OR = {
													is_rival = root
													root = { is_rival = prev }
												}
											}
										}
									}
								}
								NOT = {
									any_neighbor_province = {
										owned_by = root
										OR = {
											has_building = fort_15th
											has_building = fort_16th
											has_building = fort_17th
											has_building = fort_18th
										}
									}
								}
							}
						}
						has_terrain = highlands
					}
					AND = {
						has_building = fort_15th
						ROOT = { mil_tech = 14 }
					}
					AND = {
						has_building = fort_16th
						ROOT = { mil_tech = 19 }
					}
					AND = {
						has_building = fort_17th
						ROOT = { mil_tech = 24 }
					}
				}
				NOT = { has_building = fort_18th }
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				OR = {
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owner = {
								OR = {
									is_rival = root
									root = { is_rival = prev }
									AND = {
										is_subject_other_than_tributary_trigger = yes
										overlord = {
											OR = {
												is_rival = root
												root = { is_rival = prev }
											}
										}
									}
								}
							}
						}
						NOT = {
							any_neighbor_province = {
								owned_by = root
								OR = {
									has_building = fort_15th
									has_building = fort_16th
									has_building = fort_17th
									has_building = fort_18th
								}
							}
						}
						has_terrain = mountain
					}
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owned_by = root
							any_neighbor_province = {
								owner = {
									OR = {
										is_rival = root
										root = { is_rival = prev }
										AND = {
											is_subject_other_than_tributary_trigger = yes
											overlord = {
												OR = {
													is_rival = root
													root = { is_rival = prev }
												}
											}
										}
									}
								}
								NOT = {
									any_neighbor_province = {
										owned_by = root
										OR = {
											has_building = fort_15th
											has_building = fort_16th
											has_building = fort_17th
											has_building = fort_18th
										}
									}
								}
							}
						}
						has_terrain = mountain
					}
					AND = {
						has_building = fort_15th
						ROOT = { mil_tech = 14 }
					}
					AND = {
						has_building = fort_16th
						ROOT = { mil_tech = 19 }
					}
					AND = {
						has_building = fort_17th
						ROOT = { mil_tech = 24 }
					}
				}
				NOT = { has_building = fort_18th }
			}
			save_event_target_as = agenda_province
		}
		event_target:agenda_province = {
			if = {
				limit = {
					has_building = fort_17th
				}
				ROOT = {
					set_variable = {
						which = estate_nobles_build_fort_building_in_y_var
						value = 4
					}
				}
			}
			else_if = {
				limit = {
					has_building = fort_16th
				}
				ROOT = {
					set_variable = {
						which = estate_nobles_build_fort_building_in_y_var
						value = 3
					}
				}
			}
			else_if = {
				limit = {
					has_building = fort_15th
				}
				ROOT = {
					set_variable = {
						which = estate_nobles_build_fort_building_in_y_var
						value = 2
					}
				}
			}
			else = {
				ROOT = {
					set_variable = {
						which = estate_nobles_build_fort_building_in_y_var
						value = 1
					}
				}
			}
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_rajput
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_rajput
			}
		}
		else = {
			if = {
				limit = {
					check_variable = {
						which = estate_nobles_build_fort_building_in_y_var
						value = 4
					}
				}
				event_target:agenda_province = {
					has_building = fort_18th
				}
			}
			else_if = {
				limit = {
					check_variable = {
						which = estate_nobles_build_fort_building_in_y_var
						value = 3
					}
				}
				event_target:agenda_province = {
					OR = {
						has_building = fort_17th
						has_building = fort_18th
					}
				}
			}
			else_if = {
				limit = {
					check_variable = {
						which = estate_nobles_build_fort_building_in_y_var
						value = 2
					}
				}
				event_target:agenda_province = {
					OR = {
						has_building = fort_16th
						has_building = fort_17th
						has_building = fort_18th
					}
				}
			}
			else = {
				event_target:agenda_province = {
					OR = {
						has_building = fort_15th
						has_building = fort_16th
						has_building = fort_17th
						has_building = fort_18th
					}
				}
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_rajput
		}
		add_estate_loyalty = {
			estate = estate_rajput
			loyalty = 10
		}
		event_target:agenda_province = {
			add_base_manpower = 1
		}
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_rajputs_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_rajput
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_maratha_build_fort_building_in_y = {
	can_select = {
		any_owned_province = {
			OR = {
				AND = {
					NOT = { has_building = fort_15th }
					NOT = { has_building = fort_16th }
					NOT = { has_building = fort_17th }
					NOT = { has_building = fort_18th }
					num_free_building_slots = 1
					any_neighbor_province = {
						owner = {
							OR = {
								is_rival = root
								root = { is_rival = prev }
								AND = {
									is_subject_other_than_tributary_trigger = yes
									overlord = {
										OR = {
											is_rival = root
											root = { is_rival = prev }
										}
									}
								}
							}
						}
					}
					NOT = {
						any_neighbor_province = {
							owned_by = root
							OR = {
								has_building = fort_15th
								has_building = fort_16th
								has_building = fort_17th
								has_building = fort_18th
							}
						}
					}
				}
				AND = {
					NOT = { has_building = fort_15th }
					NOT = { has_building = fort_16th }
					NOT = { has_building = fort_17th }
					NOT = { has_building = fort_18th }
					num_free_building_slots = 1
					any_neighbor_province = {
						owned_by = root
						any_neighbor_province = {
							owner = {
								OR = {
									is_rival = root
									root = { is_rival = prev }
									AND = {
										is_subject_other_than_tributary_trigger = yes
										overlord = {
											OR = {
												is_rival = root
												root = { is_rival = prev }
											}
										}
									}
								}
							}
							NOT = {
								any_neighbor_province = {
									owned_by = root
									OR = {
										has_building = fort_15th
										has_building = fort_16th
										has_building = fort_17th
										has_building = fort_18th
									}
								}
							}
						}
					}
				}
				AND = {
					has_building = fort_15th
					ROOT = { mil_tech = 14 }
				}
				AND = {
					has_building = fort_16th
					ROOT = { mil_tech = 19 }
				}
				AND = {
					has_building = fort_17th
					ROOT = { mil_tech = 24 }
				}
			}
			NOT = { has_building = fort_18th }
		}
	}
	selection_weight = {
		factor = 1
		modifier = {
			factor = 1.5
			any_neighbor_country = {
				OR = {
					is_rival = root
					root = { is_rival = prev }
				}
				army_size = root
			}
		}
	}
	pre_effect = {
		set_variable = {
			which = estate_nobles_build_fort_building_in_y_var
			value = 0
		}
		random_owned_province = {
			limit = {
				OR = {
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owner = {
								OR = {
									is_rival = root
									root = { is_rival = prev }
									AND = {
										is_subject_other_than_tributary_trigger = yes
										overlord = {
											OR = {
												is_rival = root
												root = { is_rival = prev }
											}
										}
									}
								}
							}
						}
						NOT = {
							any_neighbor_province = {
								owned_by = root
								OR = {
									has_building = fort_15th
									has_building = fort_16th
									has_building = fort_17th
									has_building = fort_18th
								}
							}
						}
					}
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owned_by = root
							any_neighbor_province = {
								owner = {
									OR = {
										is_rival = root
										root = { is_rival = prev }
										AND = {
											is_subject_other_than_tributary_trigger = yes
											overlord = {
												OR = {
													is_rival = root
													root = { is_rival = prev }
												}
											}
										}
									}
								}
								NOT = {
									any_neighbor_province = {
										owned_by = root
										OR = {
											has_building = fort_15th
											has_building = fort_16th
											has_building = fort_17th
											has_building = fort_18th
										}
									}
								}
							}
						}
					}
					AND = {
						has_building = fort_15th
						ROOT = { mil_tech = 14 }
					}
					AND = {
						has_building = fort_16th
						ROOT = { mil_tech = 19 }
					}
					AND = {
						has_building = fort_17th
						ROOT = { mil_tech = 24 }
					}
				}
				NOT = { has_building = fort_18th }
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				OR = {
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owner = {
								OR = {
									is_rival = root
									root = { is_rival = prev }
									AND = {
										is_subject_other_than_tributary_trigger = yes
										overlord = {
											OR = {
												is_rival = root
												root = { is_rival = prev }
											}
										}
									}
								}
							}
						}
						NOT = {
							any_neighbor_province = {
								owned_by = root
								OR = {
									has_building = fort_15th
									has_building = fort_16th
									has_building = fort_17th
									has_building = fort_18th
								}
							}
						}
						has_terrain = hills
					}
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owned_by = root
							any_neighbor_province = {
								owner = {
									OR = {
										is_rival = root
										root = { is_rival = prev }
										AND = {
											is_subject_other_than_tributary_trigger = yes
											overlord = {
												OR = {
													is_rival = root
													root = { is_rival = prev }
												}
											}
										}
									}
								}
								NOT = {
									any_neighbor_province = {
										owned_by = root
										OR = {
											has_building = fort_15th
											has_building = fort_16th
											has_building = fort_17th
											has_building = fort_18th
										}
									}
								}
							}
						}
						has_terrain = hills
					}
					AND = {
						has_building = fort_15th
						ROOT = { mil_tech = 14 }
					}
					AND = {
						has_building = fort_16th
						ROOT = { mil_tech = 19 }
					}
					AND = {
						has_building = fort_17th
						ROOT = { mil_tech = 24 }
					}
				}
				NOT = { has_building = fort_18th }
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				OR = {
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owner = {
								OR = {
									is_rival = root
									root = { is_rival = prev }
									AND = {
										is_subject_other_than_tributary_trigger = yes
										overlord = {
											OR = {
												is_rival = root
												root = { is_rival = prev }
											}
										}
									}
								}
							}
						}
						NOT = {
							any_neighbor_province = {
								owned_by = root
								OR = {
									has_building = fort_15th
									has_building = fort_16th
									has_building = fort_17th
									has_building = fort_18th
								}
							}
						}
						has_terrain = highlands
					}
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owned_by = root
							any_neighbor_province = {
								owner = {
									OR = {
										is_rival = root
										root = { is_rival = prev }
										AND = {
											is_subject_other_than_tributary_trigger = yes
											overlord = {
												OR = {
													is_rival = root
													root = { is_rival = prev }
												}
											}
										}
									}
								}
								NOT = {
									any_neighbor_province = {
										owned_by = root
										OR = {
											has_building = fort_15th
											has_building = fort_16th
											has_building = fort_17th
											has_building = fort_18th
										}
									}
								}
							}
						}
						has_terrain = highlands
					}
					AND = {
						has_building = fort_15th
						ROOT = { mil_tech = 14 }
					}
					AND = {
						has_building = fort_16th
						ROOT = { mil_tech = 19 }
					}
					AND = {
						has_building = fort_17th
						ROOT = { mil_tech = 24 }
					}
				}
				NOT = { has_building = fort_18th }
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				OR = {
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owner = {
								OR = {
									is_rival = root
									root = { is_rival = prev }
									AND = {
										is_subject_other_than_tributary_trigger = yes
										overlord = {
											OR = {
												is_rival = root
												root = { is_rival = prev }
											}
										}
									}
								}
							}
						}
						NOT = {
							any_neighbor_province = {
								owned_by = root
								OR = {
									has_building = fort_15th
									has_building = fort_16th
									has_building = fort_17th
									has_building = fort_18th
								}
							}
						}
						has_terrain = mountain
					}
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owned_by = root
							any_neighbor_province = {
								owner = {
									OR = {
										is_rival = root
										root = { is_rival = prev }
										AND = {
											is_subject_other_than_tributary_trigger = yes
											overlord = {
												OR = {
													is_rival = root
													root = { is_rival = prev }
												}
											}
										}
									}
								}
								NOT = {
									any_neighbor_province = {
										owned_by = root
										OR = {
											has_building = fort_15th
											has_building = fort_16th
											has_building = fort_17th
											has_building = fort_18th
										}
									}
								}
							}
						}
						has_terrain = mountain
					}
					AND = {
						has_building = fort_15th
						ROOT = { mil_tech = 14 }
					}
					AND = {
						has_building = fort_16th
						ROOT = { mil_tech = 19 }
					}
					AND = {
						has_building = fort_17th
						ROOT = { mil_tech = 24 }
					}
				}
				NOT = { has_building = fort_18th }
			}
			save_event_target_as = agenda_province
		}
		event_target:agenda_province = {
			if = {
				limit = {
					has_building = fort_17th
				}
				ROOT = {
					set_variable = {
						which = estate_nobles_build_fort_building_in_y_var
						value = 4
					}
				}
			}
			else_if = {
				limit = {
					has_building = fort_16th
				}
				ROOT = {
					set_variable = {
						which = estate_nobles_build_fort_building_in_y_var
						value = 3
					}
				}
			}
			else_if = {
				limit = {
					has_building = fort_15th
				}
				ROOT = {
					set_variable = {
						which = estate_nobles_build_fort_building_in_y_var
						value = 2
					}
				}
			}
			else = {
				ROOT = {
					set_variable = {
						which = estate_nobles_build_fort_building_in_y_var
						value = 1
					}
				}
			}
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_maratha
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_maratha
			}
		}
		else = {
			if = {
				limit = {
					check_variable = {
						which = estate_nobles_build_fort_building_in_y_var
						value = 4
					}
				}
				event_target:agenda_province = {
					has_building = fort_18th
				}
			}
			else_if = {
				limit = {
					check_variable = {
						which = estate_nobles_build_fort_building_in_y_var
						value = 3
					}
				}
				event_target:agenda_province = {
					OR = {
						has_building = fort_17th
						has_building = fort_18th
					}
				}
			}
			else_if = {
				limit = {
					check_variable = {
						which = estate_nobles_build_fort_building_in_y_var
						value = 2
					}
				}
				event_target:agenda_province = {
					OR = {
						has_building = fort_16th
						has_building = fort_17th
						has_building = fort_18th
					}
				}
			}
			else = {
				event_target:agenda_province = {
					OR = {
						has_building = fort_15th
						has_building = fort_16th
						has_building = fort_17th
						has_building = fort_18th
					}
				}
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_maratha
		}
		add_estate_loyalty = {
			estate = estate_maratha
			loyalty = 10
		}
		event_target:agenda_province = {
			add_base_manpower = 1
		}
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_marathas_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_maratha
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_qizilbash_build_fort_building_in_y = {
	can_select = {
		any_owned_province = {
			OR = {
				AND = {
					NOT = { has_building = fort_15th }
					NOT = { has_building = fort_16th }
					NOT = { has_building = fort_17th }
					NOT = { has_building = fort_18th }
					num_free_building_slots = 1
					any_neighbor_province = {
						owner = {
							OR = {
								is_rival = root
								root = { is_rival = prev }
								AND = {
									is_subject_other_than_tributary_trigger = yes
									overlord = {
										OR = {
											is_rival = root
											root = { is_rival = prev }
										}
									}
								}
							}
						}
					}
					NOT = {
						any_neighbor_province = {
							owned_by = root
							OR = {
								has_building = fort_15th
								has_building = fort_16th
								has_building = fort_17th
								has_building = fort_18th
							}
						}
					}
				}
				AND = {
					NOT = { has_building = fort_15th }
					NOT = { has_building = fort_16th }
					NOT = { has_building = fort_17th }
					NOT = { has_building = fort_18th }
					num_free_building_slots = 1
					any_neighbor_province = {
						owned_by = root
						any_neighbor_province = {
							owner = {
								OR = {
									is_rival = root
									root = { is_rival = prev }
									AND = {
										is_subject_other_than_tributary_trigger = yes
										overlord = {
											OR = {
												is_rival = root
												root = { is_rival = prev }
											}
										}
									}
								}
							}
							NOT = {
								any_neighbor_province = {
									owned_by = root
									OR = {
										has_building = fort_15th
										has_building = fort_16th
										has_building = fort_17th
										has_building = fort_18th
									}
								}
							}
						}
					}
				}
				AND = {
					has_building = fort_15th
					ROOT = { mil_tech = 14 }
				}
				AND = {
					has_building = fort_16th
					ROOT = { mil_tech = 19 }
				}
				AND = {
					has_building = fort_17th
					ROOT = { mil_tech = 24 }
				}
			}
			NOT = { has_building = fort_18th }
		}
	}
	selection_weight = {
		factor = 1
		modifier = {
			factor = 1.5
			any_neighbor_country = {
				OR = {
					is_rival = root
					root = { is_rival = prev }
				}
				army_size = root
			}
		}
	}
	pre_effect = {
		set_variable = {
			which = estate_nobles_build_fort_building_in_y_var
			value = 0
		}
		random_owned_province = {
			limit = {
				OR = {
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owner = {
								OR = {
									is_rival = root
									root = { is_rival = prev }
									AND = {
										is_subject_other_than_tributary_trigger = yes
										overlord = {
											OR = {
												is_rival = root
												root = { is_rival = prev }
											}
										}
									}
								}
							}
						}
						NOT = {
							any_neighbor_province = {
								owned_by = root
								OR = {
									has_building = fort_15th
									has_building = fort_16th
									has_building = fort_17th
									has_building = fort_18th
								}
							}
						}
					}
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owned_by = root
							any_neighbor_province = {
								owner = {
									OR = {
										is_rival = root
										root = { is_rival = prev }
										AND = {
											is_subject_other_than_tributary_trigger = yes
											overlord = {
												OR = {
													is_rival = root
													root = { is_rival = prev }
												}
											}
										}
									}
								}
								NOT = {
									any_neighbor_province = {
										owned_by = root
										OR = {
											has_building = fort_15th
											has_building = fort_16th
											has_building = fort_17th
											has_building = fort_18th
										}
									}
								}
							}
						}
					}
					AND = {
						has_building = fort_15th
						ROOT = { mil_tech = 14 }
					}
					AND = {
						has_building = fort_16th
						ROOT = { mil_tech = 19 }
					}
					AND = {
						has_building = fort_17th
						ROOT = { mil_tech = 24 }
					}
				}
				NOT = { has_building = fort_18th }
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				OR = {
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owner = {
								OR = {
									is_rival = root
									root = { is_rival = prev }
									AND = {
										is_subject_other_than_tributary_trigger = yes
										overlord = {
											OR = {
												is_rival = root
												root = { is_rival = prev }
											}
										}
									}
								}
							}
						}
						NOT = {
							any_neighbor_province = {
								owned_by = root
								OR = {
									has_building = fort_15th
									has_building = fort_16th
									has_building = fort_17th
									has_building = fort_18th
								}
							}
						}
						has_terrain = hills
					}
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owned_by = root
							any_neighbor_province = {
								owner = {
									OR = {
										is_rival = root
										root = { is_rival = prev }
										AND = {
											is_subject_other_than_tributary_trigger = yes
											overlord = {
												OR = {
													is_rival = root
													root = { is_rival = prev }
												}
											}
										}
									}
								}
								NOT = {
									any_neighbor_province = {
										owned_by = root
										OR = {
											has_building = fort_15th
											has_building = fort_16th
											has_building = fort_17th
											has_building = fort_18th
										}
									}
								}
							}
						}
						has_terrain = hills
					}
					AND = {
						has_building = fort_15th
						ROOT = { mil_tech = 14 }
					}
					AND = {
						has_building = fort_16th
						ROOT = { mil_tech = 19 }
					}
					AND = {
						has_building = fort_17th
						ROOT = { mil_tech = 24 }
					}
				}
				NOT = { has_building = fort_18th }
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				OR = {
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owner = {
								OR = {
									is_rival = root
									root = { is_rival = prev }
									AND = {
										is_subject_other_than_tributary_trigger = yes
										overlord = {
											OR = {
												is_rival = root
												root = { is_rival = prev }
											}
										}
									}
								}
							}
						}
						NOT = {
							any_neighbor_province = {
								owned_by = root
								OR = {
									has_building = fort_15th
									has_building = fort_16th
									has_building = fort_17th
									has_building = fort_18th
								}
							}
						}
						has_terrain = highlands
					}
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owned_by = root
							any_neighbor_province = {
								owner = {
									OR = {
										is_rival = root
										root = { is_rival = prev }
										AND = {
											is_subject_other_than_tributary_trigger = yes
											overlord = {
												OR = {
													is_rival = root
													root = { is_rival = prev }
												}
											}
										}
									}
								}
								NOT = {
									any_neighbor_province = {
										owned_by = root
										OR = {
											has_building = fort_15th
											has_building = fort_16th
											has_building = fort_17th
											has_building = fort_18th
										}
									}
								}
							}
						}
						has_terrain = highlands
					}
					AND = {
						has_building = fort_15th
						ROOT = { mil_tech = 14 }
					}
					AND = {
						has_building = fort_16th
						ROOT = { mil_tech = 19 }
					}
					AND = {
						has_building = fort_17th
						ROOT = { mil_tech = 24 }
					}
				}
				NOT = { has_building = fort_18th }
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				OR = {
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owner = {
								OR = {
									is_rival = root
									root = { is_rival = prev }
									AND = {
										is_subject_other_than_tributary_trigger = yes
										overlord = {
											OR = {
												is_rival = root
												root = { is_rival = prev }
											}
										}
									}
								}
							}
						}
						NOT = {
							any_neighbor_province = {
								owned_by = root
								OR = {
									has_building = fort_15th
									has_building = fort_16th
									has_building = fort_17th
									has_building = fort_18th
								}
							}
						}
						has_terrain = mountain
					}
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owned_by = root
							any_neighbor_province = {
								owner = {
									OR = {
										is_rival = root
										root = { is_rival = prev }
										AND = {
											is_subject_other_than_tributary_trigger = yes
											overlord = {
												OR = {
													is_rival = root
													root = { is_rival = prev }
												}
											}
										}
									}
								}
								NOT = {
									any_neighbor_province = {
										owned_by = root
										OR = {
											has_building = fort_15th
											has_building = fort_16th
											has_building = fort_17th
											has_building = fort_18th
										}
									}
								}
							}
						}
						has_terrain = mountain
					}
					AND = {
						has_building = fort_15th
						ROOT = { mil_tech = 14 }
					}
					AND = {
						has_building = fort_16th
						ROOT = { mil_tech = 19 }
					}
					AND = {
						has_building = fort_17th
						ROOT = { mil_tech = 24 }
					}
				}
				NOT = { has_building = fort_18th }
			}
			save_event_target_as = agenda_province
		}
		event_target:agenda_province = {
			if = {
				limit = {
					has_building = fort_17th
				}
				ROOT = {
					set_variable = {
						which = estate_nobles_build_fort_building_in_y_var
						value = 4
					}
				}
			}
			else_if = {
				limit = {
					has_building = fort_16th
				}
				ROOT = {
					set_variable = {
						which = estate_nobles_build_fort_building_in_y_var
						value = 3
					}
				}
			}
			else_if = {
				limit = {
					has_building = fort_15th
				}
				ROOT = {
					set_variable = {
						which = estate_nobles_build_fort_building_in_y_var
						value = 2
					}
				}
			}
			else = {
				ROOT = {
					set_variable = {
						which = estate_nobles_build_fort_building_in_y_var
						value = 1
					}
				}
			}
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_qizilbash
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_qizilbash
			}
		}
		else = {
			if = {
				limit = {
					check_variable = {
						which = estate_nobles_build_fort_building_in_y_var
						value = 4
					}
				}
				event_target:agenda_province = {
					has_building = fort_18th
				}
			}
			else_if = {
				limit = {
					check_variable = {
						which = estate_nobles_build_fort_building_in_y_var
						value = 3
					}
				}
				event_target:agenda_province = {
					OR = {
						has_building = fort_17th
						has_building = fort_18th
					}
				}
			}
			else_if = {
				limit = {
					check_variable = {
						which = estate_nobles_build_fort_building_in_y_var
						value = 2
					}
				}
				event_target:agenda_province = {
					OR = {
						has_building = fort_16th
						has_building = fort_17th
						has_building = fort_18th
					}
				}
			}
			else = {
				event_target:agenda_province = {
					OR = {
						has_building = fort_15th
						has_building = fort_16th
						has_building = fort_17th
						has_building = fort_18th
					}
				}
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_qizilbash
		}
		add_estate_loyalty = {
			estate = estate_qizilbash
			loyalty = 10
		}
		event_target:agenda_province = {
			add_base_manpower = 1
		}
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_qizilbash_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_qizilbash
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_ghulams_build_fort_building_in_y = {
	can_select = {
		any_owned_province = {
			OR = {
				AND = {
					NOT = { has_building = fort_15th }
					NOT = { has_building = fort_16th }
					NOT = { has_building = fort_17th }
					NOT = { has_building = fort_18th }
					num_free_building_slots = 1
					any_neighbor_province = {
						owner = {
							OR = {
								is_rival = root
								root = { is_rival = prev }
								AND = {
									is_subject_other_than_tributary_trigger = yes
									overlord = {
										OR = {
											is_rival = root
											root = { is_rival = prev }
										}
									}
								}
							}
						}
					}
					NOT = {
						any_neighbor_province = {
							owned_by = root
							OR = {
								has_building = fort_15th
								has_building = fort_16th
								has_building = fort_17th
								has_building = fort_18th
							}
						}
					}
				}
				AND = {
					NOT = { has_building = fort_15th }
					NOT = { has_building = fort_16th }
					NOT = { has_building = fort_17th }
					NOT = { has_building = fort_18th }
					num_free_building_slots = 1
					any_neighbor_province = {
						owned_by = root
						any_neighbor_province = {
							owner = {
								OR = {
									is_rival = root
									root = { is_rival = prev }
									AND = {
										is_subject_other_than_tributary_trigger = yes
										overlord = {
											OR = {
												is_rival = root
												root = { is_rival = prev }
											}
										}
									}
								}
							}
							NOT = {
								any_neighbor_province = {
									owned_by = root
									OR = {
										has_building = fort_15th
										has_building = fort_16th
										has_building = fort_17th
										has_building = fort_18th
									}
								}
							}
						}
					}
				}
				AND = {
					has_building = fort_15th
					ROOT = { mil_tech = 14 }
				}
				AND = {
					has_building = fort_16th
					ROOT = { mil_tech = 19 }
				}
				AND = {
					has_building = fort_17th
					ROOT = { mil_tech = 24 }
				}
			}
			NOT = { has_building = fort_18th }
		}
	}
	selection_weight = {
		factor = 1
		modifier = {
			factor = 1.5
			any_neighbor_country = {
				OR = {
					is_rival = root
					root = { is_rival = prev }
				}
				army_size = root
			}
		}
	}
	pre_effect = {
		set_variable = {
			which = estate_nobles_build_fort_building_in_y_var
			value = 0
		}
		random_owned_province = {
			limit = {
				OR = {
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owner = {
								OR = {
									is_rival = root
									root = { is_rival = prev }
									AND = {
										is_subject_other_than_tributary_trigger = yes
										overlord = {
											OR = {
												is_rival = root
												root = { is_rival = prev }
											}
										}
									}
								}
							}
						}
						NOT = {
							any_neighbor_province = {
								owned_by = root
								OR = {
									has_building = fort_15th
									has_building = fort_16th
									has_building = fort_17th
									has_building = fort_18th
								}
							}
						}
					}
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owned_by = root
							any_neighbor_province = {
								owner = {
									OR = {
										is_rival = root
										root = { is_rival = prev }
										AND = {
											is_subject_other_than_tributary_trigger = yes
											overlord = {
												OR = {
													is_rival = root
													root = { is_rival = prev }
												}
											}
										}
									}
								}
								NOT = {
									any_neighbor_province = {
										owned_by = root
										OR = {
											has_building = fort_15th
											has_building = fort_16th
											has_building = fort_17th
											has_building = fort_18th
										}
									}
								}
							}
						}
					}
					AND = {
						has_building = fort_15th
						ROOT = { mil_tech = 14 }
					}
					AND = {
						has_building = fort_16th
						ROOT = { mil_tech = 19 }
					}
					AND = {
						has_building = fort_17th
						ROOT = { mil_tech = 24 }
					}
				}
				NOT = { has_building = fort_18th }
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				OR = {
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owner = {
								OR = {
									is_rival = root
									root = { is_rival = prev }
									AND = {
										is_subject_other_than_tributary_trigger = yes
										overlord = {
											OR = {
												is_rival = root
												root = { is_rival = prev }
											}
										}
									}
								}
							}
						}
						NOT = {
							any_neighbor_province = {
								owned_by = root
								OR = {
									has_building = fort_15th
									has_building = fort_16th
									has_building = fort_17th
									has_building = fort_18th
								}
							}
						}
						has_terrain = hills
					}
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owned_by = root
							any_neighbor_province = {
								owner = {
									OR = {
										is_rival = root
										root = { is_rival = prev }
										AND = {
											is_subject_other_than_tributary_trigger = yes
											overlord = {
												OR = {
													is_rival = root
													root = { is_rival = prev }
												}
											}
										}
									}
								}
								NOT = {
									any_neighbor_province = {
										owned_by = root
										OR = {
											has_building = fort_15th
											has_building = fort_16th
											has_building = fort_17th
											has_building = fort_18th
										}
									}
								}
							}
						}
						has_terrain = hills
					}
					AND = {
						has_building = fort_15th
						ROOT = { mil_tech = 14 }
					}
					AND = {
						has_building = fort_16th
						ROOT = { mil_tech = 19 }
					}
					AND = {
						has_building = fort_17th
						ROOT = { mil_tech = 24 }
					}
				}
				NOT = { has_building = fort_18th }
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				OR = {
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owner = {
								OR = {
									is_rival = root
									root = { is_rival = prev }
									AND = {
										is_subject_other_than_tributary_trigger = yes
										overlord = {
											OR = {
												is_rival = root
												root = { is_rival = prev }
											}
										}
									}
								}
							}
						}
						NOT = {
							any_neighbor_province = {
								owned_by = root
								OR = {
									has_building = fort_15th
									has_building = fort_16th
									has_building = fort_17th
									has_building = fort_18th
								}
							}
						}
						has_terrain = highlands
					}
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owned_by = root
							any_neighbor_province = {
								owner = {
									OR = {
										is_rival = root
										root = { is_rival = prev }
										AND = {
											is_subject_other_than_tributary_trigger = yes
											overlord = {
												OR = {
													is_rival = root
													root = { is_rival = prev }
												}
											}
										}
									}
								}
								NOT = {
									any_neighbor_province = {
										owned_by = root
										OR = {
											has_building = fort_15th
											has_building = fort_16th
											has_building = fort_17th
											has_building = fort_18th
										}
									}
								}
							}
						}
						has_terrain = highlands
					}
					AND = {
						has_building = fort_15th
						ROOT = { mil_tech = 14 }
					}
					AND = {
						has_building = fort_16th
						ROOT = { mil_tech = 19 }
					}
					AND = {
						has_building = fort_17th
						ROOT = { mil_tech = 24 }
					}
				}
				NOT = { has_building = fort_18th }
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				OR = {
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owner = {
								OR = {
									is_rival = root
									root = { is_rival = prev }
									AND = {
										is_subject_other_than_tributary_trigger = yes
										overlord = {
											OR = {
												is_rival = root
												root = { is_rival = prev }
											}
										}
									}
								}
							}
						}
						NOT = {
							any_neighbor_province = {
								owned_by = root
								OR = {
									has_building = fort_15th
									has_building = fort_16th
									has_building = fort_17th
									has_building = fort_18th
								}
							}
						}
						has_terrain = mountain
					}
					AND = {
						NOT = { has_building = fort_15th }
						NOT = { has_building = fort_16th }
						NOT = { has_building = fort_17th }
						NOT = { has_building = fort_18th }
						num_free_building_slots = 1
						any_neighbor_province = {
							owned_by = root
							any_neighbor_province = {
								owner = {
									OR = {
										is_rival = root
										root = { is_rival = prev }
										AND = {
											is_subject_other_than_tributary_trigger = yes
											overlord = {
												OR = {
													is_rival = root
													root = { is_rival = prev }
												}
											}
										}
									}
								}
								NOT = {
									any_neighbor_province = {
										owned_by = root
										OR = {
											has_building = fort_15th
											has_building = fort_16th
											has_building = fort_17th
											has_building = fort_18th
										}
									}
								}
							}
						}
						has_terrain = mountain
					}
					AND = {
						has_building = fort_15th
						ROOT = { mil_tech = 14 }
					}
					AND = {
						has_building = fort_16th
						ROOT = { mil_tech = 19 }
					}
					AND = {
						has_building = fort_17th
						ROOT = { mil_tech = 24 }
					}
				}
				NOT = { has_building = fort_18th }
			}
			save_event_target_as = agenda_province
		}
		event_target:agenda_province = {
			if = {
				limit = {
					has_building = fort_17th
				}
				ROOT = {
					set_variable = {
						which = estate_nobles_build_fort_building_in_y_var
						value = 4
					}
				}
			}
			else_if = {
				limit = {
					has_building = fort_16th
				}
				ROOT = {
					set_variable = {
						which = estate_nobles_build_fort_building_in_y_var
						value = 3
					}
				}
			}
			else_if = {
				limit = {
					has_building = fort_15th
				}
				ROOT = {
					set_variable = {
						which = estate_nobles_build_fort_building_in_y_var
						value = 2
					}
				}
			}
			else = {
				ROOT = {
					set_variable = {
						which = estate_nobles_build_fort_building_in_y_var
						value = 1
					}
				}
			}
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_ghulams
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_ghulams
			}
		}
		else = {
			if = {
				limit = {
					check_variable = {
						which = estate_nobles_build_fort_building_in_y_var
						value = 4
					}
				}
				event_target:agenda_province = {
					has_building = fort_18th
				}
			}
			else_if = {
				limit = {
					check_variable = {
						which = estate_nobles_build_fort_building_in_y_var
						value = 3
					}
				}
				event_target:agenda_province = {
					OR = {
						has_building = fort_17th
						has_building = fort_18th
					}
				}
			}
			else_if = {
				limit = {
					check_variable = {
						which = estate_nobles_build_fort_building_in_y_var
						value = 2
					}
				}
				event_target:agenda_province = {
					OR = {
						has_building = fort_16th
						has_building = fort_17th
						has_building = fort_18th
					}
				}
			}
			else = {
				event_target:agenda_province = {
					OR = {
						has_building = fort_15th
						has_building = fort_16th
						has_building = fort_17th
						has_building = fort_18th
					}
				}
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_ghulams
		}
		add_estate_loyalty = {
			estate = estate_ghulams
			loyalty = 10
		}
		event_target:agenda_province = {
			add_base_manpower = 1
		}
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_ghulams_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_ghulams
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_burghers_build_trade_building_in_y = {
	can_select = {
		dip_tech = 4
		any_owned_province = {
			is_state_core = root
			NOT = { has_building = stock_exchange }
			OR = {
				AND = {
					NOT = { has_building = marketplace }
					NOT = { has_building = trade_depot }
					num_free_building_slots = 1
				}
				AND = {
					ROOT = { dip_tech = 17 }
					NOT = { has_building = trade_depot }
					OR = {
						num_free_building_slots = 1
						has_building = marketplace
					}
				}
				AND = {
					ROOT = { dip_tech = 22 }
					OR = {
						num_free_building_slots = 1
						has_building = trade_depot
					}
				}
			}
		}
	}
	selection_weight = {
		factor = 1
		modifier = {
			factor = 0.65
			NOT = {
				any_owned_province = {
					is_state_core = root
					OR = {
						province_has_center_of_trade_of_level = 1
						province_trade_power = 10
					}
					NOT = { has_building = stock_exchange }
					OR = {
						AND = {
							NOT = { has_building = marketplace }
							NOT = { has_building = trade_depot }
							num_free_building_slots = 1
						}
						AND = {
							ROOT = { dip_tech = 17 }
							NOT = { has_building = trade_depot }
							OR = {
								num_free_building_slots = 1
								has_building = marketplace
							}
						}
						AND = {
							ROOT = { dip_tech = 22 }
							OR = {
								num_free_building_slots = 1
								has_building = trade_depot
							}
						}
					}
				}
			}
		}
		modifier = {
			factor = 1.2
			any_owned_province = {
				is_state_core = root
				OR = {
					province_has_center_of_trade_of_level = 2
					province_trade_power = 20
				}
				NOT = { has_building = stock_exchange }
				OR = {
					AND = {
						NOT = { has_building = marketplace }
						NOT = { has_building = trade_depot }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { dip_tech = 17 }
						NOT = { has_building = trade_depot }
						OR = {
							num_free_building_slots = 1
							has_building = marketplace
						}
					}
					AND = {
						ROOT = { dip_tech = 22 }
						OR = {
							num_free_building_slots = 1
							has_building = trade_depot
						}
					}
				}
			}
		}
		modifier = {
			factor = 2
			is_institution_enabled = global_trade
			NOT = { has_institution = global_trade }
		}
		modifier = {
			factor = 2
			NOT = {
				crown_land_share = 15
			}
		}
	}
	pre_effect = {
		set_variable = {
			which = estate_burghers_build_trade_building_in_y_var
			value = 0
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				NOT = { has_building = stock_exchange }
				OR = {
					AND = {
						NOT = { has_building = marketplace }
						NOT = { has_building = trade_depot }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { dip_tech = 17 }
						NOT = { has_building = trade_depot }
						OR = {
							num_free_building_slots = 1
							has_building = marketplace
						}
					}
					AND = {
						ROOT = { dip_tech = 22 }
						OR = {
							num_free_building_slots = 1
							has_building = trade_depot
						}
					}
				}
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				OR = {
					province_has_center_of_trade_of_level = 1
					province_trade_power = 10
				}
				NOT = { has_building = stock_exchange }
				OR = {
					AND = {
						NOT = { has_building = marketplace }
						NOT = { has_building = trade_depot }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { dip_tech = 17 }
						NOT = { has_building = trade_depot }
						OR = {
							num_free_building_slots = 1
							has_building = marketplace
						}
					}
					AND = {
						ROOT = { dip_tech = 22 }
						OR = {
							num_free_building_slots = 1
							has_building = trade_depot
						}
					}
				}
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				OR = {
					province_has_center_of_trade_of_level = 2
					province_trade_power = 20
				}
				NOT = { has_building = stock_exchange }
				OR = {
					AND = {
						NOT = { has_building = marketplace }
						NOT = { has_building = trade_depot }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { dip_tech = 17 }
						NOT = { has_building = trade_depot }
						OR = {
							num_free_building_slots = 1
							has_building = marketplace
						}
					}
					AND = {
						ROOT = { dip_tech = 22 }
						OR = {
							num_free_building_slots = 1
							has_building = trade_depot
						}
					}
				}
			}
			save_event_target_as = agenda_province
		}
		event_target:agenda_province = {
			if = {
				limit = {
					has_building = trade_depot
				}
				ROOT = {
					set_variable = {
						which = estate_burghers_build_trade_building_in_y_var
						value = 3
					}
				}
			}
			else_if = {
				limit = {
					has_building = marketplace
				}
				ROOT = {
					set_variable = {
						which = estate_burghers_build_trade_building_in_y_var
						value = 2
					}
				}
			}
			else = {
				ROOT = {
					set_variable = {
						which = estate_burghers_build_trade_building_in_y_var
						value = 1
					}
				}
			}
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_burghers
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_burghers
			}
		}
		else = {
			if = {
				limit = {
					check_variable = {
						which = estate_burghers_build_trade_building_in_y_var
						value = 3
					}
				}
				event_target:agenda_province = {
					has_building = stock_exchange
				}
			}
			else_if = {
				limit = {
					check_variable = {
						which = estate_burghers_build_trade_building_in_y_var
						value = 2
					}
				}
				event_target:agenda_province = {
					OR = {
						has_building = trade_depot
						has_building = stock_exchange
					}
				}
			}
			else = {
				event_target:agenda_province = {
					OR = {
						has_building = marketplace
						has_building = trade_depot
						has_building = stock_exchange
					}
				}
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_burghers
		}
		add_estate_loyalty = {
			estate = estate_burghers
			loyalty = 10
		}
		if = {
			limit = {
				NOT = { crown_land_share = 15 }
				estate_territory = {
					estate = estate_burghers
					territory = 10
				}
				estate_not_has_exempt_from_seize_land_privilege = { estate = estate_burghers }
			}
			take_estate_land_share_small = { estate = estate_burghers }
		}
		else = {
			event_target:agenda_province = {
				add_base_production = 1
			}
		}
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_burghers_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_burghers
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}


estate_burghers_build_port_building_in_y = {
	can_select = {
		dip_tech = 6
		any_owned_province = {
			is_state_core = root
			has_port = yes
			OR = {
				NOT = { has_building = grand_shipyard }
				NOT = { has_building = drydock }
			}
			OR = {
				AND = {
					NOT = { has_building = dock }
					num_free_building_slots = 1
				}
				AND = {
					ROOT = { dip_tech = 8 }
					NOT = { has_building = shipyard }
					num_free_building_slots = 1
				}
				AND = {
					ROOT = { dip_tech = 19 }
					NOT = { has_building = drydock }
					OR = {
						num_free_building_slots = 1
						has_building = dock
					}
				}
				AND = {
					ROOT = { dip_tech = 24 }
					NOT = { has_building = grand_shipyard }
					OR = {
						num_free_building_slots = 1
						has_building = shipyard
					}
				}
			}
		}
	}
	selection_weight = {
		factor = 1
		modifier = {
			factor = 0.75
			always = yes
		}
		modifier = {
			factor = 2
			NOT = {
				crown_land_share = 15
			}
		}
	}
	pre_effect = {
		set_variable = {
			which = estate_burghers_build_port_building_in_y_var
			value = 0
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				has_port = yes
				OR = {
					NOT = { has_building = grand_shipyard }
					NOT = { has_building = drydock }
				}
				OR = {
					AND = {
						NOT = { has_building = dock }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { dip_tech = 8 }
						NOT = { has_building = shipyard }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { dip_tech = 19 }
						NOT = { has_building = drydock }
						OR = {
							num_free_building_slots = 1
							has_building = dock
						}
					}
					AND = {
						ROOT = { dip_tech = 24 }
						NOT = { has_building = grand_shipyard }
						OR = {
							num_free_building_slots = 1
							has_building = shipyard
						}
					}
				}
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				development = 12
				has_port = yes
				OR = {
					NOT = { has_building = grand_shipyard }
					NOT = { has_building = drydock }
				}
				OR = {
					AND = {
						NOT = { has_building = dock }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { dip_tech = 8 }
						NOT = { has_building = shipyard }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { dip_tech = 19 }
						NOT = { has_building = drydock }
						OR = {
							num_free_building_slots = 1
							has_building = dock
						}
					}
					AND = {
						ROOT = { dip_tech = 24 }
						NOT = { has_building = grand_shipyard }
						OR = {
							num_free_building_slots = 1
							has_building = shipyard
						}
					}
				}
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				development = 20
				has_port = yes
				OR = {
					NOT = { has_building = grand_shipyard }
					NOT = { has_building = drydock }
				}
				OR = {
					AND = {
						NOT = { has_building = dock }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { dip_tech = 8 }
						NOT = { has_building = shipyard }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { dip_tech = 19 }
						NOT = { has_building = drydock }
						OR = {
							num_free_building_slots = 1
							has_building = dock
						}
					}
					AND = {
						ROOT = { dip_tech = 24 }
						NOT = { has_building = grand_shipyard }
						OR = {
							num_free_building_slots = 1
							has_building = shipyard
						}
					}
				}
			}
			save_event_target_as = agenda_province
		}
		event_target:agenda_province = {
			if = {
				limit = {
					has_building = shipyard
					NOT = { has_building = grand_shipyard }
					ROOT = { dip_tech = 24 }
				}
				ROOT = {
					set_variable = {
						which = estate_burghers_build_port_building_in_y_var
						value = 4
					}
				}
			}
			else_if = {
				limit = {
					NOT = { has_building = shipyard }
					NOT = { has_building = grand_shipyard }
					ROOT = { dip_tech = 8 }
				}
				ROOT = {
					set_variable = {
						which = estate_burghers_build_port_building_in_y_var
						value = 3
					}
				}
			}
			else_if = {
				limit = {
					has_building = dock
				}
				ROOT = {
					set_variable = {
						which = estate_burghers_build_port_building_in_y_var
						value = 2
					}
				}
			}
			else = {
				ROOT = {
					set_variable = {
						which = estate_burghers_build_port_building_in_y_var
						value = 1
					}
				}
			}
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_burghers
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_burghers
			}
		}
		else = {
			if = {
				limit = {
					check_variable = {
						which = estate_burghers_build_port_building_in_y_var
						value = 4
					}
				}
				event_target:agenda_province = {
					has_building = grand_shipyard
				}
			}
			else_if = {
				limit = {
					check_variable = {
						which = estate_burghers_build_port_building_in_y_var
						value = 3
					}
				}
				event_target:agenda_province = {
					OR = {
						has_building = shipyard
						has_building = grand_shipyard
					}
				}
			}
			else_if = {
				limit = {
					check_variable = {
						which = estate_burghers_build_port_building_in_y_var
						value = 2
					}
				}
				event_target:agenda_province = {
					has_building = drydock
				}
			}
			else = {
				event_target:agenda_province = {
					OR = {
						has_building = dock
						has_building = drydock
					}
				}
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_burghers
		}
		add_estate_loyalty = {
			estate = estate_burghers
			loyalty = 10
		}
		if = {
			limit = {
				NOT = { crown_land_share = 15 }
				estate_territory = {
					estate = estate_burghers
					territory = 10
				}
				estate_not_has_exempt_from_seize_land_privilege = { estate = estate_burghers }
			}
			take_estate_land_share_small = { estate = estate_burghers }
		}
		else = {
			event_target:agenda_province = {
				add_base_production = 1
			}
		}
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_burghers_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_burghers
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_burghers_build_production_building_in_y = {
	can_select = {
		adm_tech = 6
		any_owned_province = {
			is_state_core = root
			NOT = { has_building = counting_house }
			OR = {
				AND = {
					NOT = { has_building = workshop }
					num_free_building_slots = 1
				}
				AND = {
					ROOT = { adm_tech = 24 }
					OR = {
						has_building = workshop
						num_free_building_slots = 1
					}
				}
			}
			NOT = { trade_goods = gold }
			NOT = { trade_goods = silver }
		}
	}
	selection_weight = {
		factor = 1
		modifier = {
			factor = 0.65
			NOT = {
				any_owned_province = {
					is_state_core = root
					base_production = 4
					NOT = { has_building = counting_house }
					OR = {
						AND = {
							NOT = { has_building = workshop }
							num_free_building_slots = 1
						}
						AND = {
							ROOT = { adm_tech = 24 }
							OR = {
								has_building = workshop
								num_free_building_slots = 1
							}
						}
					}
					NOT = { trade_goods = gold }
					NOT = { trade_goods = silver }
				}
			}
		}
		modifier = {
			factor = 1.2
			any_owned_province = {
				is_state_core = root
				OR = {
					base_production = 7
					has_building = wharf
					has_building = weapons
					has_building = textile
					has_building = tradecompany
					has_building = farm_estate
					has_building = mills
					has_building = plantations
					has_building = furnace
				}
				NOT = { has_building = counting_house }
				OR = {
					AND = {
						NOT = { has_building = workshop }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { adm_tech = 24 }
						OR = {
							has_building = workshop
							num_free_building_slots = 1
						}
					}
				}
				NOT = { trade_goods = gold }
				NOT = { trade_goods = silver }
			}
		}
		modifier = {
			factor = 2
			NOT = {
				crown_land_share = 15
			}
		}
	}
	pre_effect = {
		set_variable = {
			which = estate_burghers_build_production_building_in_y_var
			value = 0
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				NOT = { has_building = counting_house }
				OR = {
					AND = {
						NOT = { has_building = workshop }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { adm_tech = 24 }
						OR = {
							has_building = workshop
							num_free_building_slots = 1
						}
					}
				}
				NOT = { trade_goods = gold }
				NOT = { trade_goods = silver }
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				base_production = 4
				NOT = { has_building = counting_house }
				OR = {
					AND = {
						NOT = { has_building = workshop }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { adm_tech = 24 }
						OR = {
							has_building = workshop
							num_free_building_slots = 1
						}
					}
				}
				NOT = { trade_goods = gold }
				NOT = { trade_goods = silver }
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				OR = {
					base_production = 7
					has_building = wharf
					has_building = weapons
					has_building = textile
					has_building = tradecompany
					has_building = farm_estate
					has_building = mills
					has_building = plantations
					has_building = furnace
				}
				NOT = { has_building = counting_house }
				OR = {
					AND = {
						NOT = { has_building = workshop }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { adm_tech = 24 }
						OR = {
							has_building = workshop
							num_free_building_slots = 1
						}
					}
				}
				NOT = { trade_goods = gold }
				NOT = { trade_goods = silver }
			}
			save_event_target_as = agenda_province
		}
		event_target:agenda_province = {
			if = {
				limit = {
					has_building = workshop
				}
				ROOT = {
					set_variable = {
						which = estate_burghers_build_production_building_in_y_var
						value = 2
					}
				}
			}
			else = {
				ROOT = {
					set_variable = {
						which = estate_burghers_build_production_building_in_y_var
						value = 1
					}
				}
			}
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_burghers
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_burghers
			}
		}
		else = {
			if = {
				limit = {
					check_variable = {
						which = estate_burghers_build_production_building_in_y_var
						value = 2
					}
				}
				event_target:agenda_province = {
					has_building = counting_house
				}
			}
			else = {
				event_target:agenda_province = {
					OR = {
						has_building = workshop
						has_building = counting_house
					}
				}
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_burghers
		}
		add_estate_loyalty = {
			estate = estate_burghers
			loyalty = 10
		}
		if = {
			limit = {
				NOT = { crown_land_share = 15 }
				estate_territory = {
					estate = estate_burghers
					territory = 10
				}
				estate_not_has_exempt_from_seize_land_privilege = { estate = estate_burghers }
			}
			take_estate_land_share_small = { estate = estate_burghers }
		}
		else = {
			event_target:agenda_province = {
				add_base_production = 1
			}
		}
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_burghers_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_burghers
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}


estate_vaisyas_build_trade_building_in_y = {
	can_select = {
		dip_tech = 4
		any_owned_province = {
			is_state_core = root
			NOT = { has_building = stock_exchange }
			OR = {
				AND = {
					NOT = { has_building = marketplace }
					NOT = { has_building = trade_depot }
					num_free_building_slots = 1
				}
				AND = {
					ROOT = { dip_tech = 17 }
					NOT = { has_building = trade_depot }
					OR = {
						num_free_building_slots = 1
						has_building = marketplace
					}
				}
				AND = {
					ROOT = { dip_tech = 22 }
					OR = {
						num_free_building_slots = 1
						has_building = trade_depot
					}
				}
			}
		}
	}
	selection_weight = {
		factor = 1
		modifier = {
			factor = 0.65
			NOT = {
				any_owned_province = {
					is_state_core = root
					OR = {
						province_has_center_of_trade_of_level = 1
						province_trade_power = 10
					}
					NOT = { has_building = stock_exchange }
					OR = {
						AND = {
							NOT = { has_building = marketplace }
							NOT = { has_building = trade_depot }
							num_free_building_slots = 1
						}
						AND = {
							ROOT = { dip_tech = 17 }
							NOT = { has_building = trade_depot }
							OR = {
								num_free_building_slots = 1
								has_building = marketplace
							}
						}
						AND = {
							ROOT = { dip_tech = 22 }
							OR = {
								num_free_building_slots = 1
								has_building = trade_depot
							}
						}
					}
				}
			}
		}
		modifier = {
			factor = 1.2
			any_owned_province = {
				is_state_core = root
				OR = {
					province_has_center_of_trade_of_level = 2
					province_trade_power = 20
				}
				NOT = { has_building = stock_exchange }
				OR = {
					AND = {
						NOT = { has_building = marketplace }
						NOT = { has_building = trade_depot }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { dip_tech = 17 }
						NOT = { has_building = trade_depot }
						OR = {
							num_free_building_slots = 1
							has_building = marketplace
						}
					}
					AND = {
						ROOT = { dip_tech = 22 }
						OR = {
							num_free_building_slots = 1
							has_building = trade_depot
						}
					}
				}
			}
		}
		modifier = {
			factor = 2
			is_institution_enabled = global_trade
			NOT = { has_institution = global_trade }
		}
		modifier = {
			factor = 2
			NOT = {
				crown_land_share = 15
			}
		}
	}
	pre_effect = {
		set_variable = {
			which = estate_vaisyas_build_trade_building_in_y_var
			value = 0
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				NOT = { has_building = stock_exchange }
				OR = {
					AND = {
						NOT = { has_building = marketplace }
						NOT = { has_building = trade_depot }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { dip_tech = 17 }
						NOT = { has_building = trade_depot }
						OR = {
							num_free_building_slots = 1
							has_building = marketplace
						}
					}
					AND = {
						ROOT = { dip_tech = 22 }
						OR = {
							num_free_building_slots = 1
							has_building = trade_depot
						}
					}
				}
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				OR = {
					province_has_center_of_trade_of_level = 1
					province_trade_power = 10
				}
				NOT = { has_building = stock_exchange }
				OR = {
					AND = {
						NOT = { has_building = marketplace }
						NOT = { has_building = trade_depot }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { dip_tech = 17 }
						NOT = { has_building = trade_depot }
						OR = {
							num_free_building_slots = 1
							has_building = marketplace
						}
					}
					AND = {
						ROOT = { dip_tech = 22 }
						OR = {
							num_free_building_slots = 1
							has_building = trade_depot
						}
					}
				}
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				OR = {
					province_has_center_of_trade_of_level = 2
					province_trade_power = 20
				}
				NOT = { has_building = stock_exchange }
				OR = {
					AND = {
						NOT = { has_building = marketplace }
						NOT = { has_building = trade_depot }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { dip_tech = 17 }
						NOT = { has_building = trade_depot }
						OR = {
							num_free_building_slots = 1
							has_building = marketplace
						}
					}
					AND = {
						ROOT = { dip_tech = 22 }
						OR = {
							num_free_building_slots = 1
							has_building = trade_depot
						}
					}
				}
			}
			save_event_target_as = agenda_province
		}
		event_target:agenda_province = {
			if = {
				limit = {
					has_building = trade_depot
				}
				ROOT = {
					set_variable = {
						which = estate_vaisyas_build_trade_building_in_y_var
						value = 3
					}
				}
			}
			else_if = {
				limit = {
					has_building = marketplace
				}
				ROOT = {
					set_variable = {
						which = estate_vaisyas_build_trade_building_in_y_var
						value = 2
					}
				}
			}
			else = {
				ROOT = {
					set_variable = {
						which = estate_vaisyas_build_trade_building_in_y_var
						value = 1
					}
				}
			}
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_vaisyas
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_vaisyas
			}
		}
		else = {
			if = {
				limit = {
					check_variable = {
						which = estate_vaisyas_build_trade_building_in_y_var
						value = 3
					}
				}
				event_target:agenda_province = {
					has_building = stock_exchange
				}
			}
			else_if = {
				limit = {
					check_variable = {
						which = estate_vaisyas_build_trade_building_in_y_var
						value = 2
					}
				}
				event_target:agenda_province = {
					OR = {
						has_building = trade_depot
						has_building = stock_exchange
					}
				}
			}
			else = {
				event_target:agenda_province = {
					OR = {
						has_building = marketplace
						has_building = trade_depot
						has_building = stock_exchange
					}
				}
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_vaisyas
		}
		add_estate_loyalty = {
			estate = estate_vaisyas
			loyalty = 10
		}
		if = {
			limit = {
				NOT = { crown_land_share = 15 }
				estate_territory = {
					estate = estate_vaisyas
					territory = 10
				}
				estate_not_has_exempt_from_seize_land_privilege = { estate = estate_vaisyas }
			}
			take_estate_land_share_small = { estate = estate_vaisyas }
		}
		else = {
			event_target:agenda_province = {
				add_base_production = 1
			}
		}
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_vaisyas_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_vaisyas
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}


estate_vaisyas_build_port_building_in_y = {
	can_select = {
		dip_tech = 6
		any_owned_province = {
			is_state_core = root
			has_port = yes
			OR = {
				NOT = { has_building = grand_shipyard }
				NOT = { has_building = drydock }
			}
			OR = {
				AND = {
					NOT = { has_building = dock }
					num_free_building_slots = 1
				}
				AND = {
					ROOT = { dip_tech = 8 }
					NOT = { has_building = shipyard }
					num_free_building_slots = 1
				}
				AND = {
					ROOT = { dip_tech = 19 }
					NOT = { has_building = drydock }
					OR = {
						num_free_building_slots = 1
						has_building = dock
					}
				}
				AND = {
					ROOT = { dip_tech = 24 }
					NOT = { has_building = grand_shipyard }
					OR = {
						num_free_building_slots = 1
						has_building = shipyard
					}
				}
			}
		}
	}
	selection_weight = {
		factor = 1
		modifier = {
			factor = 0.75
			always = yes
		}
		modifier = {
			factor = 2
			NOT = {
				crown_land_share = 15
			}
		}
	}
	pre_effect = {
		set_variable = {
			which = estate_vaisyas_build_port_building_in_y_var
			value = 0
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				has_port = yes
				OR = {
					NOT = { has_building = grand_shipyard }
					NOT = { has_building = drydock }
				}
				OR = {
					AND = {
						NOT = { has_building = dock }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { dip_tech = 8 }
						NOT = { has_building = shipyard }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { dip_tech = 19 }
						NOT = { has_building = drydock }
						OR = {
							num_free_building_slots = 1
							has_building = dock
						}
					}
					AND = {
						ROOT = { dip_tech = 24 }
						NOT = { has_building = grand_shipyard }
						OR = {
							num_free_building_slots = 1
							has_building = shipyard
						}
					}
				}
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				development = 12
				has_port = yes
				OR = {
					NOT = { has_building = grand_shipyard }
					NOT = { has_building = drydock }
				}
				OR = {
					AND = {
						NOT = { has_building = dock }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { dip_tech = 8 }
						NOT = { has_building = shipyard }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { dip_tech = 19 }
						NOT = { has_building = drydock }
						OR = {
							num_free_building_slots = 1
							has_building = dock
						}
					}
					AND = {
						ROOT = { dip_tech = 24 }
						NOT = { has_building = grand_shipyard }
						OR = {
							num_free_building_slots = 1
							has_building = shipyard
						}
					}
				}
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				development = 20
				has_port = yes
				OR = {
					NOT = { has_building = grand_shipyard }
					NOT = { has_building = drydock }
				}
				OR = {
					AND = {
						NOT = { has_building = dock }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { dip_tech = 8 }
						NOT = { has_building = shipyard }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { dip_tech = 19 }
						NOT = { has_building = drydock }
						OR = {
							num_free_building_slots = 1
							has_building = dock
						}
					}
					AND = {
						ROOT = { dip_tech = 24 }
						NOT = { has_building = grand_shipyard }
						OR = {
							num_free_building_slots = 1
							has_building = shipyard
						}
					}
				}
			}
			save_event_target_as = agenda_province
		}
		event_target:agenda_province = {
			if = {
				limit = {
					has_building = shipyard
					NOT = { has_building = grand_shipyard }
					ROOT = { dip_tech = 24 }
				}
				ROOT = {
					set_variable = {
						which = estate_vaisyas_build_port_building_in_y_var
						value = 4
					}
				}
			}
			else_if = {
				limit = {
					NOT = { has_building = shipyard }
					NOT = { has_building = grand_shipyard }
					ROOT = { dip_tech = 8 }
				}
				ROOT = {
					set_variable = {
						which = estate_vaisyas_build_port_building_in_y_var
						value = 3
					}
				}
			}
			else_if = {
				limit = {
					has_building = dock
				}
				ROOT = {
					set_variable = {
						which = estate_vaisyas_build_port_building_in_y_var
						value = 2
					}
				}
			}
			else = {
				ROOT = {
					set_variable = {
						which = estate_vaisyas_build_port_building_in_y_var
						value = 1
					}
				}
			}
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_vaisyas
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_vaisyas
			}
		}
		else = {
			if = {
				limit = {
					check_variable = {
						which = estate_vaisyas_build_port_building_in_y_var
						value = 4
					}
				}
				event_target:agenda_province = {
					has_building = grand_shipyard
				}
			}
			else_if = {
				limit = {
					check_variable = {
						which = estate_vaisyas_build_port_building_in_y_var
						value = 3
					}
				}
				event_target:agenda_province = {
					OR = {
						has_building = shipyard
						has_building = grand_shipyard
					}
				}
			}
			else_if = {
				limit = {
					check_variable = {
						which = estate_vaisyas_build_port_building_in_y_var
						value = 2
					}
				}
				event_target:agenda_province = {
					has_building = drydock
				}
			}
			else = {
				event_target:agenda_province = {
					OR = {
						has_building = dock
						has_building = drydock
					}
				}
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_vaisyas
		}
		add_estate_loyalty = {
			estate = estate_vaisyas
			loyalty = 10
		}
		if = {
			limit = {
				NOT = { crown_land_share = 15 }
				estate_territory = {
					estate = estate_vaisyas
					territory = 10
				}
				estate_not_has_exempt_from_seize_land_privilege = { estate = estate_vaisyas }
			}
			take_estate_land_share_small = { estate = estate_vaisyas }
		}
		else = {
			event_target:agenda_province = {
				add_base_production = 1
			}
		}
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_vaisyas_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_vaisyas
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_vaisyas_build_production_building_in_y = {
	can_select = {
		adm_tech = 6
		any_owned_province = {
			is_state_core = root
			NOT = { has_building = counting_house }
			OR = {
				AND = {
					NOT = { has_building = workshop }
					num_free_building_slots = 1
				}
				AND = {
					ROOT = { adm_tech = 24 }
					OR = {
						has_building = workshop
						num_free_building_slots = 1
					}
				}
			}
			NOT = { trade_goods = gold }
			NOT = { trade_goods = silver }
		}
	}
	selection_weight = {
		factor = 1
		modifier = {
			factor = 0.65
			NOT = {
				any_owned_province = {
					is_state_core = root
					base_production = 4
					NOT = { has_building = counting_house }
					OR = {
						AND = {
							NOT = { has_building = workshop }
							num_free_building_slots = 1
						}
						AND = {
							ROOT = { adm_tech = 24 }
							OR = {
								has_building = workshop
								num_free_building_slots = 1
							}
						}
					}
					NOT = { trade_goods = gold }
					NOT = { trade_goods = silver }
				}
			}
		}
		modifier = {
			factor = 1.2
			any_owned_province = {
				is_state_core = root
				OR = {
					base_production = 7
					has_building = wharf
					has_building = weapons
					has_building = textile
					has_building = tradecompany
					has_building = farm_estate
					has_building = mills
					has_building = plantations
					has_building = furnace
				}
				NOT = { has_building = counting_house }
				OR = {
					AND = {
						NOT = { has_building = workshop }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { adm_tech = 24 }
						OR = {
							has_building = workshop
							num_free_building_slots = 1
						}
					}
				}
				NOT = { trade_goods = gold }
				NOT = { trade_goods = silver }
			}
		}
		modifier = {
			factor = 2
			NOT = {
				crown_land_share = 15
			}
		}
	}
	pre_effect = {
		set_variable = {
			which = estate_vaisyas_build_production_building_in_y_var
			value = 0
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				NOT = { has_building = counting_house }
				OR = {
					AND = {
						NOT = { has_building = workshop }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { adm_tech = 24 }
						OR = {
							has_building = workshop
							num_free_building_slots = 1
						}
					}
				}
				NOT = { trade_goods = gold }
				NOT = { trade_goods = silver }
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				base_production = 4
				NOT = { has_building = counting_house }
				OR = {
					AND = {
						NOT = { has_building = workshop }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { adm_tech = 24 }
						OR = {
							has_building = workshop
							num_free_building_slots = 1
						}
					}
				}
				NOT = { trade_goods = gold }
				NOT = { trade_goods = silver }
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				OR = {
					base_production = 7
					has_building = wharf
					has_building = weapons
					has_building = textile
					has_building = tradecompany
					has_building = farm_estate
					has_building = mills
					has_building = plantations
					has_building = furnace
				}
				NOT = { has_building = counting_house }
				OR = {
					AND = {
						NOT = { has_building = workshop }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { adm_tech = 24 }
						OR = {
							has_building = workshop
							num_free_building_slots = 1
						}
					}
				}
				NOT = { trade_goods = gold }
				NOT = { trade_goods = silver }
			}
			save_event_target_as = agenda_province
		}
		event_target:agenda_province = {
			if = {
				limit = {
					has_building = workshop
				}
				ROOT = {
					set_variable = {
						which = estate_vaisyas_build_production_building_in_y_var
						value = 2
					}
				}
			}
			else = {
				ROOT = {
					set_variable = {
						which = estate_vaisyas_build_production_building_in_y_var
						value = 1
					}
				}
			}
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_church
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_church
			}
		}
		else = {
			if = {
				limit = {
					check_variable = {
						which = estate_vaisyas_build_production_building_in_y_var
						value = 2
					}
				}
				event_target:agenda_province = {
					has_building = counting_house
				}
			}
			else = {
				event_target:agenda_province = {
					OR = {
						has_building = workshop
						has_building = counting_house
					}
				}
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_vaisyas
		}
		add_estate_loyalty = {
			estate = estate_vaisyas
			loyalty = 10
		}
		if = {
			limit = {
				NOT = { crown_land_share = 15 }
				estate_territory = {
					estate = estate_vaisyas
					territory = 10
				}
				estate_not_has_exempt_from_seize_land_privilege = { estate = estate_vaisyas }
			}
			take_estate_land_share_small = { estate = estate_vaisyas }
		}
		else = {
			event_target:agenda_province = {
				add_base_production = 1
			}
		}
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_vaisyas_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_vaisyas
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}


estate_jains_build_trade_building_in_y = {
	can_select = {
		dip_tech = 4
		any_owned_province = {
			is_state_core = root
			NOT = { has_building = stock_exchange }
			OR = {
				AND = {
					NOT = { has_building = marketplace }
					NOT = { has_building = trade_depot }
					num_free_building_slots = 1
				}
				AND = {
					ROOT = { dip_tech = 17 }
					NOT = { has_building = trade_depot }
					OR = {
						num_free_building_slots = 1
						has_building = marketplace
					}
				}
				AND = {
					ROOT = { dip_tech = 22 }
					OR = {
						num_free_building_slots = 1
						has_building = trade_depot
					}
				}
			}
		}
	}
	selection_weight = {
		factor = 1
		modifier = {
			factor = 0.65
			NOT = {
				any_owned_province = {
					is_state_core = root
					OR = {
						province_has_center_of_trade_of_level = 1
						province_trade_power = 10
					}
					NOT = { has_building = stock_exchange }
					OR = {
						AND = {
							NOT = { has_building = marketplace }
							NOT = { has_building = trade_depot }
							num_free_building_slots = 1
						}
						AND = {
							ROOT = { dip_tech = 17 }
							NOT = { has_building = trade_depot }
							OR = {
								num_free_building_slots = 1
								has_building = marketplace
							}
						}
						AND = {
							ROOT = { dip_tech = 22 }
							OR = {
								num_free_building_slots = 1
								has_building = trade_depot
							}
						}
					}
				}
			}
		}
		modifier = {
			factor = 1.2
			any_owned_province = {
				is_state_core = root
				OR = {
					province_has_center_of_trade_of_level = 2
					province_trade_power = 20
				}
				NOT = { has_building = stock_exchange }
				OR = {
					AND = {
						NOT = { has_building = marketplace }
						NOT = { has_building = trade_depot }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { dip_tech = 17 }
						NOT = { has_building = trade_depot }
						OR = {
							num_free_building_slots = 1
							has_building = marketplace
						}
					}
					AND = {
						ROOT = { dip_tech = 22 }
						OR = {
							num_free_building_slots = 1
							has_building = trade_depot
						}
					}
				}
			}
		}
		modifier = {
			factor = 2
			is_institution_enabled = global_trade
			NOT = { has_institution = global_trade }
		}
		modifier = {
			factor = 2
			NOT = {
				crown_land_share = 15
			}
		}
	}
	pre_effect = {
		set_variable = {
			which = estate_jains_build_trade_building_in_y_var
			value = 0
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				NOT = { has_building = stock_exchange }
				OR = {
					AND = {
						NOT = { has_building = marketplace }
						NOT = { has_building = trade_depot }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { dip_tech = 17 }
						NOT = { has_building = trade_depot }
						OR = {
							num_free_building_slots = 1
							has_building = marketplace
						}
					}
					AND = {
						ROOT = { dip_tech = 22 }
						OR = {
							num_free_building_slots = 1
							has_building = trade_depot
						}
					}
				}
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				OR = {
					province_has_center_of_trade_of_level = 1
					province_trade_power = 10
				}
				NOT = { has_building = stock_exchange }
				OR = {
					AND = {
						NOT = { has_building = marketplace }
						NOT = { has_building = trade_depot }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { dip_tech = 17 }
						NOT = { has_building = trade_depot }
						OR = {
							num_free_building_slots = 1
							has_building = marketplace
						}
					}
					AND = {
						ROOT = { dip_tech = 22 }
						OR = {
							num_free_building_slots = 1
							has_building = trade_depot
						}
					}
				}
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				OR = {
					province_has_center_of_trade_of_level = 2
					province_trade_power = 20
				}
				NOT = { has_building = stock_exchange }
				OR = {
					AND = {
						NOT = { has_building = marketplace }
						NOT = { has_building = trade_depot }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { dip_tech = 17 }
						NOT = { has_building = trade_depot }
						OR = {
							num_free_building_slots = 1
							has_building = marketplace
						}
					}
					AND = {
						ROOT = { dip_tech = 22 }
						OR = {
							num_free_building_slots = 1
							has_building = trade_depot
						}
					}
				}
			}
			save_event_target_as = agenda_province
		}
		event_target:agenda_province = {
			if = {
				limit = {
					has_building = trade_depot
				}
				ROOT = {
					set_variable = {
						which = estate_jains_build_trade_building_in_y_var
						value = 3
					}
				}
			}
			else_if = {
				limit = {
					has_building = marketplace
				}
				ROOT = {
					set_variable = {
						which = estate_jains_build_trade_building_in_y_var
						value = 2
					}
				}
			}
			else = {
				ROOT = {
					set_variable = {
						which = estate_jains_build_trade_building_in_y_var
						value = 1
					}
				}
			}
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_jains
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_jains
			}
		}
		else = {
			if = {
				limit = {
					check_variable = {
						which = estate_jains_build_trade_building_in_y_var
						value = 3
					}
				}
				event_target:agenda_province = {
					has_building = stock_exchange
				}
			}
			else_if = {
				limit = {
					check_variable = {
						which = estate_jains_build_trade_building_in_y_var
						value = 2
					}
				}
				event_target:agenda_province = {
					OR = {
						has_building = trade_depot
						has_building = stock_exchange
					}
				}
			}
			else = {
				event_target:agenda_province = {
					OR = {
						has_building = marketplace
						has_building = trade_depot
						has_building = stock_exchange
					}
				}
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_jains
		}
		add_estate_loyalty = {
			estate = estate_jains
			loyalty = 10
		}
		if = {
			limit = {
				NOT = { crown_land_share = 15 }
				estate_territory = {
					estate = estate_jains
					territory = 10
				}
				estate_not_has_exempt_from_seize_land_privilege = { estate = estate_jains }
			}
			take_estate_land_share_small = { estate = estate_jains }
		}
		else = {
			event_target:agenda_province = {
				add_base_production = 1
			}
		}
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_jains_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_jains
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_jains_build_port_building_in_y = {
	can_select = {
		dip_tech = 6
		any_owned_province = {
			is_state_core = root
			has_port = yes
			OR = {
				NOT = { has_building = grand_shipyard }
				NOT = { has_building = drydock }
			}
			OR = {
				AND = {
					NOT = { has_building = dock }
					num_free_building_slots = 1
				}
				AND = {
					ROOT = { dip_tech = 8 }
					NOT = { has_building = shipyard }
					num_free_building_slots = 1
				}
				AND = {
					ROOT = { dip_tech = 19 }
					NOT = { has_building = drydock }
					OR = {
						num_free_building_slots = 1
						has_building = dock
					}
				}
				AND = {
					ROOT = { dip_tech = 24 }
					NOT = { has_building = grand_shipyard }
					OR = {
						num_free_building_slots = 1
						has_building = shipyard
					}
				}
			}
		}
	}
	selection_weight = {
		factor = 1
		modifier = {
			factor = 0.75
			always = yes
		}
		modifier = {
			factor = 2
			NOT = {
				crown_land_share = 15
			}
		}
	}
	pre_effect = {
		set_variable = {
			which = estate_jains_build_port_building_in_y_var
			value = 0
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				has_port = yes
				OR = {
					NOT = { has_building = grand_shipyard }
					NOT = { has_building = drydock }
				}
				OR = {
					AND = {
						NOT = { has_building = dock }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { dip_tech = 8 }
						NOT = { has_building = shipyard }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { dip_tech = 19 }
						NOT = { has_building = drydock }
						OR = {
							num_free_building_slots = 1
							has_building = dock
						}
					}
					AND = {
						ROOT = { dip_tech = 24 }
						NOT = { has_building = grand_shipyard }
						OR = {
							num_free_building_slots = 1
							has_building = shipyard
						}
					}
				}
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				development = 12
				has_port = yes
				OR = {
					NOT = { has_building = grand_shipyard }
					NOT = { has_building = drydock }
				}
				OR = {
					AND = {
						NOT = { has_building = dock }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { dip_tech = 8 }
						NOT = { has_building = shipyard }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { dip_tech = 19 }
						NOT = { has_building = drydock }
						OR = {
							num_free_building_slots = 1
							has_building = dock
						}
					}
					AND = {
						ROOT = { dip_tech = 24 }
						NOT = { has_building = grand_shipyard }
						OR = {
							num_free_building_slots = 1
							has_building = shipyard
						}
					}
				}
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				development = 20
				has_port = yes
				OR = {
					NOT = { has_building = grand_shipyard }
					NOT = { has_building = drydock }
				}
				OR = {
					AND = {
						NOT = { has_building = dock }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { dip_tech = 8 }
						NOT = { has_building = shipyard }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { dip_tech = 19 }
						NOT = { has_building = drydock }
						OR = {
							num_free_building_slots = 1
							has_building = dock
						}
					}
					AND = {
						ROOT = { dip_tech = 24 }
						NOT = { has_building = grand_shipyard }
						OR = {
							num_free_building_slots = 1
							has_building = shipyard
						}
					}
				}
			}
			save_event_target_as = agenda_province
		}
		event_target:agenda_province = {
			if = {
				limit = {
					has_building = shipyard
					NOT = { has_building = grand_shipyard }
					ROOT = { dip_tech = 24 }
				}
				ROOT = {
					set_variable = {
						which = estate_jains_build_port_building_in_y_var
						value = 4
					}
				}
			}
			else_if = {
				limit = {
					NOT = { has_building = shipyard }
					NOT = { has_building = grand_shipyard }
					ROOT = { dip_tech = 8 }
				}
				ROOT = {
					set_variable = {
						which = estate_jains_build_port_building_in_y_var
						value = 3
					}
				}
			}
			else_if = {
				limit = {
					has_building = dock
				}
				ROOT = {
					set_variable = {
						which = estate_jains_build_port_building_in_y_var
						value = 2
					}
				}
			}
			else = {
				ROOT = {
					set_variable = {
						which = estate_jains_build_port_building_in_y_var
						value = 1
					}
				}
			}
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_jains
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_jains
			}
		}
		else = {
			if = {
				limit = {
					check_variable = {
						which = estate_jains_build_port_building_in_y_var
						value = 4
					}
				}
				event_target:agenda_province = {
					has_building = grand_shipyard
				}
			}
			else_if = {
				limit = {
					check_variable = {
						which = estate_jains_build_port_building_in_y_var
						value = 3
					}
				}
				event_target:agenda_province = {
					OR = {
						has_building = shipyard
						has_building = grand_shipyard
					}
				}
			}
			else_if = {
				limit = {
					check_variable = {
						which = estate_jains_build_port_building_in_y_var
						value = 2
					}
				}
				event_target:agenda_province = {
					has_building = drydock
				}
			}
			else = {
				event_target:agenda_province = {
					OR = {
						has_building = dock
						has_building = drydock
					}
				}
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_jains
		}
		add_estate_loyalty = {
			estate = estate_jains
			loyalty = 10
		}
		if = {
			limit = {
				NOT = { crown_land_share = 15 }
				estate_territory = {
					estate = estate_jains
					territory = 10
				}
				estate_not_has_exempt_from_seize_land_privilege = { estate = estate_jains }
			}
			take_estate_land_share_small = { estate = estate_jains }
		}
		else = {
			event_target:agenda_province = {
				add_base_production = 1
			}
		}
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_jains_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_jains
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_jains_build_production_building_in_y = {
	can_select = {
		adm_tech = 6
		any_owned_province = {
			is_state_core = root
			NOT = { has_building = counting_house }
			OR = {
				AND = {
					NOT = { has_building = workshop }
					num_free_building_slots = 1
				}
				AND = {
					ROOT = { adm_tech = 24 }
					OR = {
						has_building = workshop
						num_free_building_slots = 1
					}
				}
			}
			NOT = { trade_goods = gold }
			NOT = { trade_goods = silver }
		}
	}
	selection_weight = {
		factor = 1
		modifier = {
			factor = 0.65
			NOT = {
				any_owned_province = {
					is_state_core = root
					base_production = 4
					NOT = { has_building = counting_house }
					OR = {
						AND = {
							NOT = { has_building = workshop }
							num_free_building_slots = 1
						}
						AND = {
							ROOT = { adm_tech = 24 }
							OR = {
								has_building = workshop
								num_free_building_slots = 1
							}
						}
					}
					NOT = { trade_goods = gold }
					NOT = { trade_goods = silver }
				}
			}
		}
		modifier = {
			factor = 1.2
			any_owned_province = {
				is_state_core = root
				OR = {
					base_production = 7
					has_building = wharf
					has_building = weapons
					has_building = textile
					has_building = tradecompany
					has_building = farm_estate
					has_building = mills
					has_building = plantations
					has_building = furnace
				}
				NOT = { has_building = counting_house }
				OR = {
					AND = {
						NOT = { has_building = workshop }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { adm_tech = 24 }
						OR = {
							has_building = workshop
							num_free_building_slots = 1
						}
					}
				}
				NOT = { trade_goods = gold }
				NOT = { trade_goods = silver }
			}
		}
		modifier = {
			factor = 2
			NOT = {
				crown_land_share = 15
			}
		}
	}
	pre_effect = {
		set_variable = {
			which = estate_jains_build_production_building_in_y_var
			value = 0
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				NOT = { has_building = counting_house }
				OR = {
					AND = {
						NOT = { has_building = workshop }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { adm_tech = 24 }
						OR = {
							has_building = workshop
							num_free_building_slots = 1
						}
					}
				}
				NOT = { trade_goods = gold }
				NOT = { trade_goods = silver }
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				base_production = 4
				NOT = { has_building = counting_house }
				OR = {
					AND = {
						NOT = { has_building = workshop }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { adm_tech = 24 }
						OR = {
							has_building = workshop
							num_free_building_slots = 1
						}
					}
				}
				NOT = { trade_goods = gold }
				NOT = { trade_goods = silver }
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				OR = {
					base_production = 7
					has_building = wharf
					has_building = weapons
					has_building = textile
					has_building = tradecompany
					has_building = farm_estate
					has_building = mills
					has_building = plantations
					has_building = furnace
				}
				NOT = { has_building = counting_house }
				OR = {
					AND = {
						NOT = { has_building = workshop }
						num_free_building_slots = 1
					}
					AND = {
						ROOT = { adm_tech = 24 }
						OR = {
							has_building = workshop
							num_free_building_slots = 1
						}
					}
				}
				NOT = { trade_goods = gold }
				NOT = { trade_goods = silver }
			}
			save_event_target_as = agenda_province
		}
		event_target:agenda_province = {
			if = {
				limit = {
					has_building = workshop
				}
				ROOT = {
					set_variable = {
						which = estate_jains_build_production_building_in_y_var
						value = 2
					}
				}
			}
			else = {
				ROOT = {
					set_variable = {
						which = estate_jains_build_production_building_in_y_var
						value = 1
					}
				}
			}
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_jains
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_jains
			}
		}
		else = {
			if = {
				limit = {
					check_variable = {
						which = estate_jains_build_production_building_in_y_var
						value = 2
					}
				}
				event_target:agenda_province = {
					has_building = counting_house
				}
			}
			else = {
				event_target:agenda_province = {
					OR = {
						has_building = workshop
						has_building = counting_house
					}
				}
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_jains
		}
		add_estate_loyalty = {
			estate = estate_jains
			loyalty = 10
		}
		if = {
			limit = {
				NOT = { crown_land_share = 15 }
				estate_territory = {
					estate = estate_jains
					territory = 10
				}
				estate_not_has_exempt_from_seize_land_privilege = { estate = estate_jains }
			}
			take_estate_land_share_small = { estate = estate_jains }
		}
		else = {
			event_target:agenda_province = {
				add_base_production = 1
			}
		}
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_jains_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_jains
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}


estate_nobles_build_manufactory_in_y = {
	can_select = {
		any_owned_province = {
			is_state_core = root
			root_can_build_manufactory_here_trigger = yes
			has_nobles_trade_good_trigger = yes
		}
		monthly_income = 30
	}
	selection_weight = {
		factor = 1
		modifier = {
			factor = 0.5
			OR = {
				current_age = age_of_discovery
				current_age = age_of_reformation
			}
		}
		modifier = {
			factor = 0.5
			NOT = { monthly_income = 40 }
		}
		modifier = {
			factor = 2
			monthly_income = 60
		}
		modifier = {
			factor = 2
			is_institution_enabled = manufactories
			NOT = { has_institution = manufactories }
		}
	}
	pre_effect = {
		random_owned_province = {
			limit = {
				is_state_core = root
				root_can_build_manufactory_here_trigger = yes
				has_nobles_trade_good_trigger = yes
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				base_production = 5
				root_can_build_manufactory_here_trigger = yes
				has_nobles_trade_good_trigger = yes
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				base_production = 10
				root_can_build_manufactory_here_trigger = yes
				has_nobles_trade_good_trigger = yes
			}
			save_event_target_as = agenda_province
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_nobles
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_nobles
			}
		}
		else = {
			event_target:agenda_province = {
				custom_trigger_tooltip = {
					tooltip = has_manufactory_trigger_tooltip
					OR = {
						has_building = wharf
						has_building = weapons
						has_building = textile
						has_building = tradecompany
						has_building = farm_estate
						has_building = mills
						has_building = furnace
						has_building = plantations
						has_building = ramparts
						has_building = soldier_households
						has_building = impressment_offices
						has_building = state_house
					}
				}
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_nobles
		}
		add_estate_loyalty = {
			estate = estate_nobles
			loyalty = 10
		}
		event_target:agenda_province = {
			add_base_manpower = 1
			add_province_modifier = {
				name = prospering_production
				duration = 5475
			}
		}
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_nobles_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_nobles
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_rajput_build_manufactory_in_y = {
	can_select = {
		any_owned_province = {
			is_state_core = root
			root_can_build_manufactory_here_trigger = yes
			has_nobles_trade_good_trigger = yes
		}
		monthly_income = 30
	}
	selection_weight = {
		factor = 1
		modifier = {
			factor = 0.5
			OR = {
				current_age = age_of_discovery
				current_age = age_of_reformation
			}
		}
		modifier = {
			factor = 0.5
			NOT = { monthly_income = 40 }
		}
		modifier = {
			factor = 2
			monthly_income = 60
		}
		modifier = {
			factor = 2
			is_institution_enabled = manufactories
			NOT = { has_institution = manufactories }
		}
	}
	pre_effect = {
		random_owned_province = {
			limit = {
				is_state_core = root
				root_can_build_manufactory_here_trigger = yes
				has_nobles_trade_good_trigger = yes
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				base_production = 5
				root_can_build_manufactory_here_trigger = yes
				has_nobles_trade_good_trigger = yes
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				base_production = 10
				root_can_build_manufactory_here_trigger = yes
				has_nobles_trade_good_trigger = yes
			}
			save_event_target_as = agenda_province
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_rajput
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_rajput
			}
		}
		else = {
			event_target:agenda_province = {
				custom_trigger_tooltip = {
					tooltip = has_manufactory_trigger_tooltip
					OR = {
						has_building = wharf
						has_building = weapons
						has_building = textile
						has_building = tradecompany
						has_building = farm_estate
						has_building = mills
						has_building = furnace
						has_building = plantations
						has_building = ramparts
						has_building = soldier_households
						has_building = impressment_offices
						has_building = state_house
					}
				}
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_rajput
		}
		add_estate_loyalty = {
			estate = estate_rajput
			loyalty = 10
		}
		event_target:agenda_province = {
			add_base_manpower = 1
			add_province_modifier = {
				name = prospering_production
				duration = 5475
			}
		}
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_rajputs_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_rajput
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_maratha_build_manufactory_in_y = {
	can_select = {
		any_owned_province = {
			is_state_core = root
			root_can_build_manufactory_here_trigger = yes
			has_nobles_trade_good_trigger = yes
		}
		monthly_income = 30
	}
	selection_weight = {
		factor = 1
		modifier = {
			factor = 0.5
			OR = {
				current_age = age_of_discovery
				current_age = age_of_reformation
			}
		}
		modifier = {
			factor = 0.5
			NOT = { monthly_income = 40 }
		}
		modifier = {
			factor = 2
			monthly_income = 60
		}
		modifier = {
			factor = 2
			is_institution_enabled = manufactories
			NOT = { has_institution = manufactories }
		}
	}
	pre_effect = {
		random_owned_province = {
			limit = {
				is_state_core = root
				root_can_build_manufactory_here_trigger = yes
				has_nobles_trade_good_trigger = yes
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				base_production = 5
				root_can_build_manufactory_here_trigger = yes
				has_nobles_trade_good_trigger = yes
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				base_production = 10
				root_can_build_manufactory_here_trigger = yes
				has_nobles_trade_good_trigger = yes
			}
			save_event_target_as = agenda_province
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_maratha
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_maratha
			}
		}
		else = {
			event_target:agenda_province = {
				custom_trigger_tooltip = {
					tooltip = has_manufactory_trigger_tooltip
					OR = {
						has_building = wharf
						has_building = weapons
						has_building = textile
						has_building = tradecompany
						has_building = farm_estate
						has_building = mills
						has_building = furnace
						has_building = plantations
						has_building = ramparts
						has_building = soldier_households
						has_building = impressment_offices
						has_building = state_house
					}
				}
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_maratha
		}
		add_estate_loyalty = {
			estate = estate_maratha
			loyalty = 10
		}
		event_target:agenda_province = {
			add_base_manpower = 1
			add_province_modifier = {
				name = prospering_production
				duration = 5475
			}
		}
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_marathas_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_maratha
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

#should be 2x as likely
estate_burghers_build_manufactory_in_y = {
	can_select = {
		any_owned_province = {
			is_state_core = root
			root_can_build_manufactory_here_trigger = yes
			has_burghers_trade_good_trigger = yes
		}
		monthly_income = 30
	}
	selection_weight = {
		factor = 2
		modifier = {
			factor = 0.5
			OR = {
				current_age = age_of_discovery
				current_age = age_of_reformation
			}
		}
		modifier = {
			factor = 0.5
			NOT = { monthly_income = 40 }
		}
		modifier = {
			factor = 2
			monthly_income = 60
		}
		modifier = {
			factor = 2
			is_institution_enabled = manufactories
			NOT = { has_institution = manufactories }
		}
	}
	pre_effect = {
		random_owned_province = {
			limit = {
				is_state_core = root
				root_can_build_manufactory_here_trigger = yes
				has_burghers_trade_good_trigger = yes
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				base_production = 5
				root_can_build_manufactory_here_trigger = yes
				has_burghers_trade_good_trigger = yes
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				base_production = 10
				root_can_build_manufactory_here_trigger = yes
				has_burghers_trade_good_trigger = yes
			}
			save_event_target_as = agenda_province
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_burghers
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_burghers
			}
		}
		else = {
			event_target:agenda_province = {
				custom_trigger_tooltip = {
					tooltip = has_manufactory_trigger_tooltip
					OR = {
						has_building = wharf
						has_building = weapons
						has_building = textile
						has_building = tradecompany
						has_building = farm_estate
						has_building = mills
						has_building = furnace
						has_building = plantations
						has_building = ramparts
						has_building = soldier_households
						has_building = impressment_offices
						has_building = state_house
					}
				}
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_burghers
		}
		add_estate_loyalty = {
			estate = estate_burghers
			loyalty = 10
		}
		event_target:agenda_province = {
			add_base_production = 1
			add_province_modifier = {
				name = prospering_production
				duration = 5475
			}
		}
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_burghers_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_burghers
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_vaisyas_build_manufactory_in_y = {
	can_select = {
		any_owned_province = {
			is_state_core = root
			root_can_build_manufactory_here_trigger = yes
			has_burghers_trade_good_trigger = yes
		}
		monthly_income = 30
	}
	selection_weight = {
		factor = 2
		modifier = {
			factor = 0.5
			OR = {
				current_age = age_of_discovery
				current_age = age_of_reformation
			}
		}
		modifier = {
			factor = 0.5
			NOT = { monthly_income = 40 }
		}
		modifier = {
			factor = 2
			monthly_income = 60
		}
		modifier = {
			factor = 2
			is_institution_enabled = manufactories
			NOT = { has_institution = manufactories }
		}
	}
	pre_effect = {
		random_owned_province = {
			limit = {
				is_state_core = root
				root_can_build_manufactory_here_trigger = yes
				has_burghers_trade_good_trigger = yes
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				base_production = 5
				root_can_build_manufactory_here_trigger = yes
				has_burghers_trade_good_trigger = yes
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				base_production = 10
				root_can_build_manufactory_here_trigger = yes
				has_burghers_trade_good_trigger = yes
			}
			save_event_target_as = agenda_province
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_vaisyas
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_vaisyas
			}
		}
		else = {
			event_target:agenda_province = {
				custom_trigger_tooltip = {
					tooltip = has_manufactory_trigger_tooltip
					OR = {
						has_building = wharf
						has_building = weapons
						has_building = textile
						has_building = tradecompany
						has_building = farm_estate
						has_building = mills
						has_building = furnace
						has_building = plantations
						has_building = ramparts
						has_building = soldier_households
						has_building = impressment_offices
						has_building = state_house
					}
				}
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_vaisyas
		}
		add_estate_loyalty = {
			estate = estate_vaisyas
			loyalty = 10
		}
		event_target:agenda_province = {
			add_base_production = 1
			add_province_modifier = {
				name = prospering_production
				duration = 5475
			}
		}
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_vaisyas_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_vaisyas
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_jains_build_manufactory_in_y = {
	can_select = {
		any_owned_province = {
			is_state_core = root
			root_can_build_manufactory_here_trigger = yes
			has_burghers_trade_good_trigger = yes
		}
		monthly_income = 30
	}
	selection_weight = {
		factor = 2
		modifier = {
			factor = 0.5
			OR = {
				current_age = age_of_discovery
				current_age = age_of_reformation
			}
		}
		modifier = {
			factor = 0.5
			NOT = { monthly_income = 40 }
		}
		modifier = {
			factor = 2
			monthly_income = 60
		}
		modifier = {
			factor = 2
			is_institution_enabled = manufactories
			NOT = { has_institution = manufactories }
		}
	}
	pre_effect = {
		random_owned_province = {
			limit = {
				is_state_core = root
				root_can_build_manufactory_here_trigger = yes
				has_burghers_trade_good_trigger = yes
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				base_production = 5
				root_can_build_manufactory_here_trigger = yes
				has_burghers_trade_good_trigger = yes
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				base_production = 10
				root_can_build_manufactory_here_trigger = yes
				has_burghers_trade_good_trigger = yes
			}
			save_event_target_as = agenda_province
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_jains
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_jains
			}
		}
		else = {
			event_target:agenda_province = {
				custom_trigger_tooltip = {
					tooltip = has_manufactory_trigger_tooltip
					OR = {
						has_building = wharf
						has_building = weapons
						has_building = textile
						has_building = tradecompany
						has_building = farm_estate
						has_building = mills
						has_building = furnace
						has_building = plantations
						has_building = ramparts
						has_building = soldier_households
						has_building = impressment_offices
						has_building = state_house
					}
				}
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_jains
		}
		add_estate_loyalty = {
			estate = estate_jains
			loyalty = 10
		}
		event_target:agenda_province = {
			add_base_production = 1
			add_province_modifier = {
				name = prospering_production
				duration = 5475
			}
		}
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_jains_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_jains
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_church_build_manufactory_in_y = {
	can_select = {
		any_owned_province = {
			is_state_core = root
			root_can_build_manufactory_here_trigger = yes
			has_church_trade_good_trigger = yes
		}
		monthly_income = 30
	}
	selection_weight = {
		factor = 1
		modifier = {
			factor = 0.75
			always = yes
		}
		modifier = {
			factor = 0.5
			OR = {
				current_age = age_of_discovery
				current_age = age_of_reformation
			}
		}
		modifier = {
			factor = 0.5
			NOT = { monthly_income = 40 }
		}
		modifier = {
			factor = 2
			monthly_income = 60
		}
		modifier = {
			factor = 2
			is_institution_enabled = manufactories
			NOT = { has_institution = manufactories }
		}
	}
	pre_effect = {
		random_owned_province = {
			limit = {
				is_state_core = root
				root_can_build_manufactory_here_trigger = yes
				has_church_trade_good_trigger = yes
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				base_production = 5
				root_can_build_manufactory_here_trigger = yes
				has_church_trade_good_trigger = yes
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				base_production = 10
				root_can_build_manufactory_here_trigger = yes
				has_church_trade_good_trigger = yes
			}
			save_event_target_as = agenda_province
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_church
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_church
			}
		}
		else = {
			event_target:agenda_province = {
				custom_trigger_tooltip = {
					tooltip = has_manufactory_trigger_tooltip
					OR = {
						has_building = wharf
						has_building = weapons
						has_building = textile
						has_building = tradecompany
						has_building = farm_estate
						has_building = mills
						has_building = furnace
						has_building = plantations
						has_building = ramparts
						has_building = soldier_households
						has_building = impressment_offices
						has_building = state_house
					}
				}
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_church
		}
		add_estate_loyalty = {
			estate = estate_church
			loyalty = 10
		}
		event_target:agenda_province = {
			add_base_tax = 1
			add_province_modifier = {
				name = prospering_production
				duration = 5475
			}
		}
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_clergy_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_church
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_brahmins_build_manufactory_in_y = {
	can_select = {
		any_owned_province = {
			is_state_core = root
			root_can_build_manufactory_here_trigger = yes
			has_church_trade_good_trigger = yes
		}
		monthly_income = 30
	}
	selection_weight = {
		factor = 1
		modifier = {
			factor = 0.75
			always = yes
		}
		modifier = {
			factor = 0.5
			OR = {
				current_age = age_of_discovery
				current_age = age_of_reformation
			}
		}
		modifier = {
			factor = 0.5
			NOT = { monthly_income = 40 }
		}
		modifier = {
			factor = 2
			monthly_income = 60
		}
		modifier = {
			factor = 2
			is_institution_enabled = manufactories
			NOT = { has_institution = manufactories }
		}
	}
	pre_effect = {
		random_owned_province = {
			limit = {
				is_state_core = root
				root_can_build_manufactory_here_trigger = yes
				has_church_trade_good_trigger = yes
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				base_production = 5
				root_can_build_manufactory_here_trigger = yes
				has_church_trade_good_trigger = yes
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				base_production = 10
				root_can_build_manufactory_here_trigger = yes
				has_church_trade_good_trigger = yes
			}
			save_event_target_as = agenda_province
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_brahmins
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_brahmins
			}
		}
		else = {
			event_target:agenda_province = {
				custom_trigger_tooltip = {
					tooltip = has_manufactory_trigger_tooltip
					OR = {
						has_building = wharf
						has_building = weapons
						has_building = textile
						has_building = tradecompany
						has_building = farm_estate
						has_building = mills
						has_building = furnace
						has_building = plantations
						has_building = ramparts
						has_building = soldier_households
						has_building = impressment_offices
						has_building = state_house
					}
				}
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_brahmins
		}
		add_estate_loyalty = {
			estate = estate_brahmins
			loyalty = 10
		}
		event_target:agenda_province = {
			add_base_tax = 1
			add_province_modifier = {
				name = prospering_production
				duration = 5475
			}
		}
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_brahmins_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_brahmins
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}



#Universities

estate_church_build_university_in_y = {
	can_select = {
		government = theocracy
		adm_tech = 17
		any_owned_province = {
			is_state_core = root
			NOT = { has_building = university }
			OR = {
				development = 10
				is_capital = yes
			}
		}
	}
	selection_weight = {
		factor = 1
		modifier = {
			factor = 0.75
			NOT = {
				any_owned_province = {
					is_state_core = root
					NOT = { has_building = university }
					development = 15
				}
			}
		}
		modifier = {
			factor = 1.2
			any_owned_province = {
				is_state_core = root
				NOT = { has_building = university }
				development = 20
			}
		}
		modifier = {
			factor = 2
			is_institution_enabled = enlightenment
			NOT = { has_institution = enlightenment }
		}
	}
	pre_effect = {
		random_owned_province = {
			limit = {
				is_state_core = root
				NOT = { has_building = university }
				development = 10
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				NOT = { has_building = university }
				development = 15
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				NOT = { has_building = university }
				development = 20
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				NOT = { has_building = university }
				is_capital = yes
			}
			save_event_target_as = agenda_province
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_church
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_church
			}
		}
		else = {
			event_target:agenda_province = {
				has_building = university
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_church
		}
		add_estate_loyalty = {
			estate = estate_church
			loyalty = 10
		}
		add_adm_power = 35
		add_dip_power = 35
		add_mil_power = 35
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_clergy_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_church
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_brahmins_build_university_in_y = {
	can_select = {
		government = theocracy
		adm_tech = 17
		any_owned_province = {
			is_state_core = root
			NOT = { has_building = university }
			OR = {
				development = 10
				is_capital = yes
			}
		}
	}
	selection_weight = {
		factor = 1
		modifier = {
			factor = 0.75
			NOT = {
				any_owned_province = {
					is_state_core = root
					NOT = { has_building = university }
					development = 15
				}
			}
		}
		modifier = {
			factor = 1.2
			any_owned_province = {
				is_state_core = root
				NOT = { has_building = university }
				development = 20
			}
		}
		modifier = {
			factor = 2
			is_institution_enabled = enlightenment
			NOT = { has_institution = enlightenment }
		}
	}
	pre_effect = {
		random_owned_province = {
			limit = {
				is_state_core = root
				NOT = { has_building = university }
				development = 10
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				NOT = { has_building = university }
				development = 15
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				NOT = { has_building = university }
				development = 20
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				NOT = { has_building = university }
				is_capital = yes
			}
			save_event_target_as = agenda_province
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_brahmins
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_brahmins
			}
		}
		else = {
			event_target:agenda_province = {
				has_building = university
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_brahmins
		}
		add_estate_loyalty = {
			estate = estate_brahmins
			loyalty = 10
		}
		add_adm_power = 35
		add_dip_power = 35
		add_mil_power = 35
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_brahmins_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_brahmins
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}


estate_nobles_build_university_in_y = {
	can_select = {
		government = monarchy
		adm_tech = 17
		any_owned_province = {
			is_state_core = root
			NOT = { has_building = university }
			OR = {
				development = 10
				is_capital = yes
			}
		}
	}
	selection_weight = {
		factor = 1
		modifier = {
			factor = 0.75
			NOT = {
				any_owned_province = {
					is_state_core = root
					NOT = { has_building = university }
					development = 15
				}
			}
		}
		modifier = {
			factor = 1.2
			any_owned_province = {
				is_state_core = root
				NOT = { has_building = university }
				development = 20
			}
		}
		modifier = {
			factor = 2
			is_institution_enabled = enlightenment
			NOT = { has_institution = enlightenment }
		}
	}
	pre_effect = {
		random_owned_province = {
			limit = {
				is_state_core = root
				NOT = { has_building = university }
				development = 10
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				NOT = { has_building = university }
				development = 15
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				NOT = { has_building = university }
				development = 20
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				NOT = { has_building = university }
				is_capital = yes
			}
			save_event_target_as = agenda_province
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_nobles
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_nobles
			}
		}
		else = {
			event_target:agenda_province = {
				has_building = university
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_nobles
		}
		add_estate_loyalty = {
			estate = estate_nobles
			loyalty = 10
		}
		add_adm_power = 35
		add_dip_power = 35
		add_mil_power = 35
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_nobles_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_nobles
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_maratha_build_university_in_y = {
	can_select = {
		government = monarchy
		adm_tech = 17
		any_owned_province = {
			is_state_core = root
			NOT = { has_building = university }
			OR = {
				development = 10
				is_capital = yes
			}
		}
	}
	selection_weight = {
		factor = 1
		modifier = {
			factor = 0.75
			NOT = {
				any_owned_province = {
					is_state_core = root
					NOT = { has_building = university }
					development = 15
				}
			}
		}
		modifier = {
			factor = 1.2
			any_owned_province = {
				is_state_core = root
				NOT = { has_building = university }
				development = 20
			}
		}
		modifier = {
			factor = 2
			is_institution_enabled = enlightenment
			NOT = { has_institution = enlightenment }
		}
	}
	pre_effect = {
		random_owned_province = {
			limit = {
				is_state_core = root
				NOT = { has_building = university }
				development = 10
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				NOT = { has_building = university }
				development = 15
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				NOT = { has_building = university }
				development = 20
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				NOT = { has_building = university }
				is_capital = yes
			}
			save_event_target_as = agenda_province
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_maratha
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_maratha
			}
		}
		else = {
			event_target:agenda_province = {
				has_building = university
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_maratha
		}
		add_estate_loyalty = {
			estate = estate_maratha
			loyalty = 10
		}
		add_adm_power = 35
		add_dip_power = 35
		add_mil_power = 35
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_marathas_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_maratha
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_rajput_build_university_in_y = {
	can_select = {
		government = monarchy
		adm_tech = 17
		any_owned_province = {
			is_state_core = root
			NOT = { has_building = university }
			OR = {
				development = 10
				is_capital = yes
			}
		}
	}
	selection_weight = {
		factor = 1
		modifier = {
			factor = 0.75
			NOT = {
				any_owned_province = {
					is_state_core = root
					NOT = { has_building = university }
					development = 15
				}
			}
		}
		modifier = {
			factor = 1.2
			any_owned_province = {
				is_state_core = root
				NOT = { has_building = university }
				development = 20
			}
		}
		modifier = {
			factor = 2
			is_institution_enabled = enlightenment
			NOT = { has_institution = enlightenment }
		}
	}
	pre_effect = {
		random_owned_province = {
			limit = {
				is_state_core = root
				NOT = { has_building = university }
				development = 10
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				NOT = { has_building = university }
				development = 15
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				NOT = { has_building = university }
				development = 20
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				NOT = { has_building = university }
				is_capital = yes
			}
			save_event_target_as = agenda_province
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_rajput
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_rajput
			}
		}
		else = {
			event_target:agenda_province = {
				has_building = university
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_rajput
		}
		add_estate_loyalty = {
			estate = estate_rajput
			loyalty = 10
		}
		add_adm_power = 35
		add_dip_power = 35
		add_mil_power = 35
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_rajputs_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_rajput
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_burghers_build_university_in_y = {
	can_select = {
		government = republic
		adm_tech = 17
		any_owned_province = {
			is_state_core = root
			NOT = { has_building = university }
			OR = {
				development = 10
				is_capital = yes
			}
		}
	}
	selection_weight = {
		factor = 1
		modifier = {
			factor = 0.75
			NOT = {
				any_owned_province = {
					is_state_core = root
					NOT = { has_building = university }
					development = 15
				}
			}
		}
		modifier = {
			factor = 1.2
			any_owned_province = {
				is_state_core = root
				NOT = { has_building = university }
				development = 20
			}
		}
		modifier = {
			factor = 2
			is_institution_enabled = enlightenment
			NOT = { has_institution = enlightenment }
		}
	}
	pre_effect = {
		random_owned_province = {
			limit = {
				is_state_core = root
				NOT = { has_building = university }
				development = 10
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				NOT = { has_building = university }
				development = 15
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				NOT = { has_building = university }
				development = 20
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				NOT = { has_building = university }
				is_capital = yes
			}
			save_event_target_as = agenda_province
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_burghers
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_burghers
			}
		}
		else = {
			event_target:agenda_province = {
				has_building = university
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_burghers
		}
		add_estate_loyalty = {
			estate = estate_burghers
			loyalty = 10
		}
		add_adm_power = 35
		add_dip_power = 35
		add_mil_power = 35
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_burghers_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_burghers
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_vaisyas_build_university_in_y = {
	can_select = {
		government = republic
		adm_tech = 17
		any_owned_province = {
			is_state_core = root
			NOT = { has_building = university }
			OR = {
				development = 10
				is_capital = yes
			}
		}
	}
	selection_weight = {
		factor = 1
		modifier = {
			factor = 0.75
			NOT = {
				any_owned_province = {
					is_state_core = root
					NOT = { has_building = university }
					development = 15
				}
			}
		}
		modifier = {
			factor = 1.2
			any_owned_province = {
				is_state_core = root
				NOT = { has_building = university }
				development = 20
			}
		}
		modifier = {
			factor = 2
			is_institution_enabled = enlightenment
			NOT = { has_institution = enlightenment }
		}
	}
	pre_effect = {
		random_owned_province = {
			limit = {
				is_state_core = root
				NOT = { has_building = university }
				development = 10
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				NOT = { has_building = university }
				development = 15
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				NOT = { has_building = university }
				development = 20
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				NOT = { has_building = university }
				is_capital = yes
			}
			save_event_target_as = agenda_province
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_vaisyas
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_vaisyas
			}
		}
		else = {
			event_target:agenda_province = {
				has_building = university
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_vaisyas
		}
		add_estate_loyalty = {
			estate = estate_vaisyas
			loyalty = 10
		}
		add_adm_power = 35
		add_dip_power = 35
		add_mil_power = 35
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_vaisyas_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_vaisyas
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_jains_build_university_in_y = {
	can_select = {
		government = republic
		adm_tech = 17
		any_owned_province = {
			is_state_core = root
			NOT = { has_building = university }
			OR = {
				development = 10
				is_capital = yes
			}
		}
	}
	selection_weight = {
		factor = 1
		modifier = {
			factor = 0.75
			NOT = {
				any_owned_province = {
					is_state_core = root
					NOT = { has_building = university }
					development = 15
				}
			}
		}
		modifier = {
			factor = 1.2
			any_owned_province = {
				is_state_core = root
				NOT = { has_building = university }
				development = 20
			}
		}
		modifier = {
			factor = 2
			is_institution_enabled = enlightenment
			NOT = { has_institution = enlightenment }
		}
	}
	pre_effect = {
		random_owned_province = {
			limit = {
				is_state_core = root
				NOT = { has_building = university }
				development = 10
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				NOT = { has_building = university }
				development = 15
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				NOT = { has_building = university }
				development = 20
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				NOT = { has_building = university }
				is_capital = yes
			}
			save_event_target_as = agenda_province
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_jains
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_jains
			}
		}
		else = {
			event_target:agenda_province = {
				has_building = university
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_jains
		}
		add_estate_loyalty = {
			estate = estate_jains
			loyalty = 10
		}
		add_adm_power = 35
		add_dip_power = 35
		add_mil_power = 35
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_jains_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_jains
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}




#### Develop the province

estate_church_develop_x = {
	selection_weight = {
		factor = 1
	}
	can_select = {
		capital_scope = {
			is_state_core = root
		}
	}
	pre_effect = {
		random_list = {
			1 = {
				random_owned_province = {
					limit = {
						is_state_core = root
						area_for_scope_province = {
							is_capital_of = root
						}
					}
					save_event_target_as = agenda_province
				}
			}
			2 = {
				trigger = {
					any_owned_province = {
						is_state_core = root
						OR = {
							AND = {
								religion = root
								OR = {
									culture = root
									has_owner_accepted_culture = yes
								}
							}
						}
						region_for_scope_province = {
							is_capital_of = root
						}
					}
				}
				random_owned_province = {
					limit = {
						is_state_core = root
						OR = {
							AND = {
								religion = root
								OR = {
									culture = root
									has_owner_accepted_culture = yes
								}
							}
						}
						region_for_scope_province = {
							is_capital_of = root
						}
					}
					save_event_target_as = agenda_province
				}
			}
			1 = {
				random_owned_province = {
					limit = {
						is_state_core = root
					}
					save_event_target_as = agenda_province
				}
			}
		}
		event_target:agenda_province = {
			if = {
				limit = {
					check_variable = {
						which = province_adm_var
						value = 1
					}
				}
				set_variable = {
					which = province_adm_var
					value = 0
				}
			}
			export_to_variable = {
				which = province_adm_var
				value = trigger_value:base_tax
			}
			change_variable = {
				which = province_adm_var
				value = 2
			}
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_church
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_church
			}
		}
		else = {
			event_target:agenda_province = {
				base_tax = "province_adm_var"
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_church
		}
		add_estate_loyalty = {
			estate = estate_church
			loyalty = 10
		}
		add_prestige = 10
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_clergy_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_church
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_brahmins_develop_x = {
	can_select = {
		capital_scope = {
			is_state_core = root
		}
		if = {
			limit = {
				NOT = { religion = hinduism }
			}
			any_owned_province = {
				religion = hinduism
				is_state_core = root
			}
		}
		else = {
			any_owned_province = {
				is_state_core = root
			}
		}
	}
	selection_weight = {
		factor = 1
	}
	pre_effect = {
		if = {
			limit = {
				NOT = { religion = hinduism }
			}
			random_owned_province = {
				limit = {
					religion = hinduism
					is_state_core = root
				}
				save_event_target_as = agenda_province
			}
			random_owned_province = {
				limit = {
					religion = hinduism
					is_state_core = root
				}
				save_event_target_as = agenda_province
			}
		}
		else = {
			random_list = {
				1 = {
					random_owned_province = {
						limit = {
							is_state_core = root
							area_for_scope_province = {
								is_capital_of = root
							}
						}
						save_event_target_as = agenda_province
					}
				}
				2 = {
					trigger = {
						any_owned_province = {
							is_state_core = root
							OR = {
								AND = {
									religion = root
									OR = {
										culture = root
										has_owner_accepted_culture = yes
									}
								}
							}
							region_for_scope_province = {
								is_capital_of = root
							}
						}
					}
					random_owned_province = {
						limit = {
							is_state_core = root
							OR = {
								AND = {
									religion = root
									OR = {
										culture = root
										has_owner_accepted_culture = yes
									}
								}
							}
							region_for_scope_province = {
								is_capital_of = root
							}
						}
						save_event_target_as = agenda_province
					}
				}
				1 = {
					random_owned_province = {
						limit = {
							is_state_core = root
						}
						save_event_target_as = agenda_province
					}
				}
			}
		}
		event_target:agenda_province = {
			if = {
				limit = {
					check_variable = {
						which = province_adm_var
						value = 1
					}
				}
				set_variable = {
					which = province_adm_var
					value = 0
				}
			}
			export_to_variable = {
				which = province_adm_var
				value = trigger_value:base_tax
			}
			change_variable = {
				which = province_adm_var
				value = 2
			}
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_brahmins
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_brahmins
			}
		}
		else = {
			event_target:agenda_province = {
				base_tax = "province_adm_var"
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_brahmins
		}
		add_estate_loyalty = {
			estate = estate_brahmins
			loyalty = 10
		}
		add_prestige = 10
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_brahmins_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_brahmins
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_nobles_develop_x = {
	selection_weight = {
		factor = 1
	}
	can_select = {
		capital_scope = {
			is_state_core = root
		}
	}
	pre_effect = {
		random_list = {
			1 = {
				random_owned_province = {
					limit = {
						is_state_core = root
						area_for_scope_province = {
							is_capital_of = root
						}
					}
					save_event_target_as = agenda_province
				}
			}
			2 = {
				trigger = {
					any_owned_province = {
						is_state_core = root
						OR = {
							AND = {
								religion = root
								OR = {
									culture = root
									has_owner_accepted_culture = yes
								}
							}
						}
						region_for_scope_province = {
							is_capital_of = root
						}
					}
				}
				random_owned_province = {
					limit = {
						is_state_core = root
						OR = {
							AND = {
								religion = root
								OR = {
									culture = root
									has_owner_accepted_culture = yes
								}
							}
						}
						region_for_scope_province = {
							is_capital_of = root
						}
					}
					save_event_target_as = agenda_province
				}
			}
			1 = {
				random_owned_province = {
					limit = {
						is_state_core = root
					}
					save_event_target_as = agenda_province
				}
			}
		}
		event_target:agenda_province = {
			if = {
				limit = {
					check_variable = {
						which = province_mil_var
						value = 1
					}
				}
				set_variable = {
					which = province_mil_var
					value = 0
				}
			}
			export_to_variable = {
				which = province_mil_var
				value = trigger_value:base_manpower
			}
			change_variable = {
				which = province_mil_var
				value = 2
			}
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_nobles
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_nobles
			}
		}
		else = {
			event_target:agenda_province = {
				base_manpower = "province_mil_var"
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_nobles
		}
		add_estate_loyalty = {
			estate = estate_nobles
			loyalty = 10
		}
		 add_yearly_manpower = 0.3
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_nobles_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_nobles
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_rajput_develop_x = {
	selection_weight = {
		factor = 1
	}
	can_select = {
		capital_scope = {
			is_state_core = root
		}
	}
	pre_effect = {
		random_list = {
			1 = {
				random_owned_province = {
					limit = {
						is_state_core = root
						area_for_scope_province = {
							is_capital_of = root
						}
					}
					save_event_target_as = agenda_province
				}
			}
			2 = {
				trigger = {
					any_owned_province = {
						is_state_core = root
						OR = {
							AND = {
								religion = root
								OR = {
									culture = root
									has_owner_accepted_culture = yes
								}
							}
						}
						region_for_scope_province = {
							is_capital_of = root
						}
					}
				}
				random_owned_province = {
					limit = {
						is_state_core = root
						OR = {
							AND = {
								religion = root
								OR = {
									culture = root
									has_owner_accepted_culture = yes
								}
							}
						}
						region_for_scope_province = {
							is_capital_of = root
						}
					}
					save_event_target_as = agenda_province
				}
			}
			1 = {
				random_owned_province = {
					limit = {
						is_state_core = root
					}
					save_event_target_as = agenda_province
				}
			}
		}
		event_target:agenda_province = {
			if = {
				limit = {
					check_variable = {
						which = province_mil_var
						value = 1
					}
				}
				set_variable = {
					which = province_mil_var
					value = 0
				}
			}
			export_to_variable = {
				which = province_mil_var
				value = trigger_value:base_manpower
			}
			change_variable = {
				which = province_mil_var
				value = 2
			}
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_rajput
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_rajput
			}
		}
		else = {
			event_target:agenda_province = {
				base_manpower = "province_mil_var"
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_rajput
		}
		add_estate_loyalty = {
			estate = estate_rajput
			loyalty = 10
		}
		 add_yearly_manpower = 0.3
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_rajputs_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_rajput
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_maratha_develop_x = {
	selection_weight = {
		factor = 1
	}
	can_select = {
		capital_scope = {
			is_state_core = root
		}
	}
	pre_effect = {
		random_list = {
			1 = {
				random_owned_province = {
					limit = {
						is_state_core = root
						area_for_scope_province = {
							is_capital_of = root
						}
					}
					save_event_target_as = agenda_province
				}
			}
			2 = {
				trigger = {
					any_owned_province = {
						is_state_core = root
						OR = {
							AND = {
								religion = root
								OR = {
									culture = root
									has_owner_accepted_culture = yes
								}
							}
						}
						region_for_scope_province = {
							is_capital_of = root
						}
					}
				}
				random_owned_province = {
					limit = {
						is_state_core = root
						OR = {
							AND = {
								religion = root
								OR = {
									culture = root
									has_owner_accepted_culture = yes
								}
							}
						}
						region_for_scope_province = {
							is_capital_of = root
						}
					}
					save_event_target_as = agenda_province
				}
			}
			1 = {
				random_owned_province = {
					limit = {
						is_state_core = root
					}
					save_event_target_as = agenda_province
				}
			}
		}
		event_target:agenda_province = {
			if = {
				limit = {
					check_variable = {
						which = province_mil_var
						value = 1
					}
				}
				set_variable = {
					which = province_mil_var
					value = 0
				}
			}
			export_to_variable = {
				which = province_mil_var
				value = trigger_value:base_manpower
			}
			change_variable = {
				which = province_mil_var
				value = 2
			}
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_maratha
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_maratha
			}
		}
		else = {
			event_target:agenda_province = {
				base_manpower = "province_mil_var"
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_maratha
		}
		add_estate_loyalty = {
			estate = estate_maratha
			loyalty = 10
		}
		 add_yearly_manpower = 0.3
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_marathas_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_maratha
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_burghers_develop_x = {
	selection_weight = {
		factor = 1
	}
	can_select = {
		capital_scope = {
			is_state_core = root
		}
	}
	pre_effect = {
		random_list = {
			1 = {
				random_owned_province = {
					limit = {
						is_state_core = root
						area_for_scope_province = {
							is_capital_of = root
						}
					}
					save_event_target_as = agenda_province
				}
			}
			2 = {
				trigger = {
					any_owned_province = {
						is_state_core = root
						OR = {
							AND = {
								religion = root
								OR = {
									culture = root
									has_owner_accepted_culture = yes
								}
							}
						}
						region_for_scope_province = {
							is_capital_of = root
						}
					}
				}
				random_owned_province = {
					limit = {
						is_state_core = root
						OR = {
							AND = {
								religion = root
								OR = {
									culture = root
									has_owner_accepted_culture = yes
								}
							}
						}
						region_for_scope_province = {
							is_capital_of = root
						}
					}
					save_event_target_as = agenda_province
				}
			}
			1 = {
				random_owned_province = {
					limit = {
						is_state_core = root
					}
					save_event_target_as = agenda_province
				}
			}
		}
		event_target:agenda_province = {
			if = {
				limit = {
					check_variable = {
						which = province_dip_var
						value = 1
					}
				}
				set_variable = {
					which = province_dip_var
					value = 0
				}
			}
			export_to_variable = {
				which = province_dip_var
				value = trigger_value:base_production
			}
			change_variable = {
				which = province_dip_var
				value = 2
			}
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_burghers
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_burghers
			}
		}
		else = {
			event_target:agenda_province = {
				base_production = "province_dip_var"
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_burghers
		}
		add_estate_loyalty = {
			estate = estate_burghers
			loyalty = 10
		}
		add_years_of_income = 0.3
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_burghers_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_burghers
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_vaisyas_develop_x = {
	selection_weight = {
		factor = 1
	}
	can_select = {
		capital_scope = {
			is_state_core = root
		}
	}
	pre_effect = {
		random_list = {
			1 = {
				random_owned_province = {
					limit = {
						is_state_core = root
						area_for_scope_province = {
							is_capital_of = root
						}
					}
					save_event_target_as = agenda_province
				}
			}
			2 = {
				trigger = {
					any_owned_province = {
						is_state_core = root
						OR = {
							AND = {
								religion = root
								OR = {
									culture = root
									has_owner_accepted_culture = yes
								}
							}
						}
						region_for_scope_province = {
							is_capital_of = root
						}
					}
				}
				random_owned_province = {
					limit = {
						is_state_core = root
						OR = {
							AND = {
								religion = root
								OR = {
									culture = root
									has_owner_accepted_culture = yes
								}
							}
						}
						region_for_scope_province = {
							is_capital_of = root
						}
					}
					save_event_target_as = agenda_province
				}
			}
			1 = {
				random_owned_province = {
					limit = {
						is_state_core = root
					}
					save_event_target_as = agenda_province
				}
			}
		}
		event_target:agenda_province = {
			if = {
				limit = {
					check_variable = {
						which = province_dip_var
						value = 1
					}
				}
				set_variable = {
					which = province_dip_var
					value = 0
				}
			}
			export_to_variable = {
				which = province_dip_var
				value = trigger_value:base_production
			}
			change_variable = {
				which = province_dip_var
				value = 2
			}
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_vaisyas
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_vaisyas
			}
		}
		else = {
			event_target:agenda_province = {
				base_production = "province_dip_var"
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_vaisyas
		}
		add_estate_loyalty = {
			estate = estate_vaisyas
			loyalty = 10
		}
		add_years_of_income = 0.3
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_vaisyas_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_vaisyas
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_jains_develop_x = {
	selection_weight = {
		factor = 1
	}
	can_select = {
		capital_scope = {
			is_state_core = root
		}
	}
	pre_effect = {
		random_list = {
			1 = {
				random_owned_province = {
					limit = {
						is_state_core = root
						area_for_scope_province = {
							is_capital_of = root
						}
					}
					save_event_target_as = agenda_province
				}
			}
			2 = {
				trigger = {
					any_owned_province = {
						is_state_core = root
						OR = {
							AND = {
								religion = root
								OR = {
									culture = root
									has_owner_accepted_culture = yes
								}
							}
						}
						region_for_scope_province = {
							is_capital_of = root
						}
					}
				}
				random_owned_province = {
					limit = {
						is_state_core = root
						OR = {
							AND = {
								religion = root
								OR = {
									culture = root
									has_owner_accepted_culture = yes
								}
							}
						}
						region_for_scope_province = {
							is_capital_of = root
						}
					}
					save_event_target_as = agenda_province
				}
			}
			1 = {
				random_owned_province = {
					limit = {
						is_state_core = root
					}
					save_event_target_as = agenda_province
				}
			}
		}
		event_target:agenda_province = {
			if = {
				limit = {
					check_variable = {
						which = province_dip_var
						value = 1
					}
				}
				set_variable = {
					which = province_dip_var
					value = 0
				}
			}
			export_to_variable = {
				which = province_dip_var
				value = trigger_value:base_production
			}
			change_variable = {
				which = province_dip_var
				value = 2
			}
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_jains
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_jains
			}
		}
		else = {
			event_target:agenda_province = {
				base_production = "province_dip_var"
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_jains
		}
		add_estate_loyalty = {
			estate = estate_jains
			loyalty = 10
		}
		add_years_of_income = 0.3
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_jains_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_jains
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_nomadic_tribes_develop_x = {
	selection_weight = {
		factor = 1
	}
	can_select = {
		capital_scope = {
			is_state_core = root
		}
	}
	pre_effect = {
		set_variable = {
			which = develop_x_category
			value = 0
		}
		random_list = {
			2 = { #Mil is weighted higher
				set_variable = {
					which = develop_x_category
					value = 3
				}
			}
			1 = { #dip
				set_variable = {
					which = develop_x_category
					value = 2
				}
			}
			1 = { #adm
				set_variable = {
					which = develop_x_category
					value = 1
				}
			}
		}
		random_list = {
			1 = {
				random_owned_province = {
					limit = {
						is_state_core = root
						area_for_scope_province = {
							is_capital_of = root
						}
					}
					save_event_target_as = agenda_province
				}
			}
			2 = {
				trigger = {
					any_owned_province = {
						is_state_core = root
						OR = {
							AND = {
								religion = root
								OR = {
									culture = root
									has_owner_accepted_culture = yes
								}
							}
						}
						region_for_scope_province = {
							is_capital_of = root
						}
					}
				}
				random_owned_province = {
					limit = {
						is_state_core = root
						OR = {
							AND = {
								religion = root
								OR = {
									culture = root
									has_owner_accepted_culture = yes
								}
							}
						}
						region_for_scope_province = {
							is_capital_of = root
						}
					}
					save_event_target_as = agenda_province
				}
			}
			1 = {
				random_owned_province = {
					limit = {
						is_state_core = root
						OR = {
							culture = root
							has_owner_accepted_culture = yes
							area_for_scope_province = {
								is_capital_of = root
							}
						}
					}
					save_event_target_as = agenda_province
				}
			}
		}
		event_target:agenda_province = {
			if = {
				limit = {
					root = {
						check_variable = {
							which = develop_x_category
							value = 3
						}
					}
				}
				if = {
					limit = {
						check_variable = {
							which = province_mil_var
							value = 1
						}
					}
					set_variable = {
						which = province_mil_var
						value = 0
					}
				}
				export_to_variable = {
					which = province_mil_var
					value = trigger_value:base_manpower
				}
				change_variable = {
					which = province_mil_var
					value = 2
				}
			}
			else_if = {
				limit = {
					root = {
						check_variable = {
							which = develop_x_category
							value = 2
						}
					}
				}
				if = {
					limit = {
						check_variable = {
							which = province_dip_var
							value = 1
						}
					}
					set_variable = {
						which = province_dip_var
						value = 0
					}
				}
				export_to_variable = {
					which = province_dip_var
					value = trigger_value:base_production
				}
				change_variable = {
					which = province_dip_var
					value = 2
				}
			}
			else = {
				if = {
					limit = {
						check_variable = {
							which = province_adm_var
							value = 1
						}
					}
					set_variable = {
						which = province_adm_var
						value = 0
					}
				}
				export_to_variable = {
					which = province_adm_var
					value = trigger_value:base_tax
				}
				change_variable = {
					which = province_adm_var
					value = 2
				}
			}
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_nomadic_tribes
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_nomadic_tribes
			}
		}
		else = {
			event_target:agenda_province = {
				if = {
					limit = {
						root = {
							check_variable = {
								which = develop_x_category
								value = 3
							}
						}
					}
					base_manpower = "province_mil_var"
				}
				else_if = {
					limit = {
						root = {
							check_variable = {
								which = develop_x_category
								value = 2
							}
						}
					}
					base_production = "province_dip_var"
				}
				else = {
					base_tax = "province_adm_var"
				}
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_nomadic_tribes
		}
		add_estate_loyalty = {
			estate = estate_nomadic_tribes
			loyalty = 10
		}
		if = {
			limit = {
				check_variable = {
					which = develop_x_category
					value = 3
				}
			}
			 add_yearly_manpower = 0.3
		}
		else_if = {
			limit = {
				check_variable = {
					which = develop_x_category
					value = 2
				}
			}
			add_years_of_income = 0.3
		}
		else = {
			add_prestige = 10
		}
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_nomadic_tribes_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_nomadic_tribes
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_qizilbash_develop_x = {
	selection_weight = {
		factor = 1
	}
	can_select = {
		capital_scope = {
			is_state_core = root
		}
	}
	pre_effect = {
		random_list = {
			1 = {
				random_owned_province = {
					limit = {
						is_state_core = root
						area_for_scope_province = {
							is_capital_of = root
						}
					}
					save_event_target_as = agenda_province
				}
			}
			1 = {
				trigger = {
					any_owned_province = {
						is_state_core = root
						OR = {
							AND = {
								religion = root
								OR = {
									culture = root
									has_owner_accepted_culture = yes
								}
							}
						}
						region_for_scope_province = {
							is_capital_of = root
						}
					}
				}
				random_owned_province = {
					limit = {
						is_state_core = root
						OR = {
							AND = {
								religion = root
								OR = {
									culture = root
									has_owner_accepted_culture = yes
								}
							}
						}
						region_for_scope_province = {
							is_capital_of = root
						}
					}
					save_event_target_as = agenda_province
				}
			}
			1 = {
				random_owned_province = {
					limit = {
						is_state_core = root
					}
					save_event_target_as = agenda_province
				}
			}
			7 = {
				trigger = {
					any_owned_province = {
						is_state_core = root
						OR = {
							culture = turco_iranian
							culture = azerbaijani
							culture = turkish
							culture = turkmeni
						}
						region_for_scope_province = {
							is_capital_of = root
						}
					}
				}
				random_owned_province = {
					limit = {
						is_state_core = root
					}
					save_event_target_as = agenda_province
				}
			}
		}
		event_target:agenda_province = {
			if = {
				limit = {
					check_variable = {
						which = province_mil_var
						value = 1
					}
				}
				set_variable = {
					which = province_mil_var
					value = 0
				}
			}
			export_to_variable = {
				which = province_mil_var
				value = trigger_value:base_manpower
			}
			change_variable = {
				which = province_mil_var
				value = 2
			}
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_qizilbash
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_qizilbash
			}
		}
		else = {
			event_target:agenda_province = {
				base_manpower = "province_mil_var"
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_qizilbash
		}
		add_estate_loyalty = {
			estate = estate_qizilbash
			loyalty = 10
		}
		 add_yearly_manpower = 0.3
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_qizilbash_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_qizilbash
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_ghulams_develop_x = {
	selection_weight = {
		factor = 1
	}
	can_select = {
		capital_scope = {
			is_state_core = root
		}
	}
	pre_effect = {
		random_list = {
			1 = {
				random_owned_province = {
					limit = {
						is_state_core = root
						area_for_scope_province = {
							is_capital_of = root
						}
					}
					save_event_target_as = agenda_province
				}
			}
			1 = {
				trigger = {
					any_owned_province = {
						is_state_core = root
						OR = {
							AND = {
								religion = root
								OR = {
									culture = root
									has_owner_accepted_culture = yes
								}
							}
						}
						region_for_scope_province = {
							is_capital_of = root
						}
					}
				}
				random_owned_province = {
					limit = {
						is_state_core = root
						OR = {
							AND = {
								religion = root
								OR = {
									culture = root
									has_owner_accepted_culture = yes
								}
							}
						}
						region_for_scope_province = {
							is_capital_of = root
						}
					}
					save_event_target_as = agenda_province
				}
			}
			1 = {
				random_owned_province = {
					limit = {
						is_state_core = root
					}
					save_event_target_as = agenda_province
				}
			}
			7 = {
				trigger = {
					any_owned_province = {
						is_state_core = root
						culture_group = caucasian
						region_for_scope_province = {
							is_capital_of = root
						}
					}
				}
				random_owned_province = {
					limit = {
						is_state_core = root
					}
					save_event_target_as = agenda_province
				}
			}
		}
		event_target:agenda_province = {
			if = {
				limit = {
					check_variable = {
						which = province_mil_var
						value = 1
					}
				}
				set_variable = {
					which = province_mil_var
					value = 0
				}
			}
			export_to_variable = {
				which = province_mil_var
				value = trigger_value:base_manpower
			}
			change_variable = {
				which = province_mil_var
				value = 2
			}
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_ghulams
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_ghulams
			}
		}
		else = {
			event_target:agenda_province = {
				base_manpower = "province_mil_var"
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_ghulams
		}
		add_estate_loyalty = {
			estate = estate_ghulams
			loyalty = 10
		}
		 add_yearly_manpower = 0.3
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_ghulams_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_ghulams
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_cossacks_develop_x = {
	selection_weight = {
		factor = 1
	}
	can_select = {
		any_owned_province = {
			is_state_core = root
		}
	}
	pre_effect = {
		set_variable = {
			which = develop_x_category
			value = 0
		}
		random_list = {
			2 = { #Mil is weighted higher
				set_variable = {
					which = develop_x_category
					value = 3
				}
			}
			1 = { #dip
				set_variable = {
					which = develop_x_category
					value = 2
				}
			}
			1 = { #adm
				set_variable = {
					which = develop_x_category
					value = 1
				}
			}
		}
		random_owned_province = {
			limit = {
				is_state_core = root
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				OR = {
					culture_group = east_slavic
					culture_group = slavic
				}
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				has_terrain = steppe
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				has_terrain = steppe
				OR = {
					culture_group = east_slavic
					culture_group = slavic
				}
			}
			save_event_target_as = agenda_province
		}
		event_target:agenda_province = {
			if = {
				limit = {
					root = {
						check_variable = {
							which = develop_x_category
							value = 3
						}
					}
				}
				if = {
					limit = {
						check_variable = {
							which = province_mil_var
							value = 1
						}
					}
					set_variable = {
						which = province_mil_var
						value = 0
					}
				}
				export_to_variable = {
					which = province_mil_var
					value = trigger_value:base_manpower
				}
				change_variable = {
					which = province_mil_var
					value = 2
				}
			}
			else_if = {
				limit = {
					root = {
						check_variable = {
							which = develop_x_category
							value = 2
						}
					}
				}
				if = {
					limit = {
						check_variable = {
							which = province_dip_var
							value = 1
						}
					}
					set_variable = {
						which = province_dip_var
						value = 0
					}
				}
				export_to_variable = {
					which = province_dip_var
					value = trigger_value:base_production
				}
				change_variable = {
					which = province_dip_var
					value = 2
				}
			}
			else = {
				if = {
					limit = {
						check_variable = {
							which = province_adm_var
							value = 1
						}
					}
					set_variable = {
						which = province_adm_var
						value = 0
					}
				}
				export_to_variable = {
					which = province_adm_var
					value = trigger_value:base_tax
				}
				change_variable = {
					which = province_adm_var
					value = 2
				}
			}
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
    task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_cossacks
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_cossacks
			}
		}
		else = {
			event_target:agenda_province = {
				if = {
					limit = {
						root = {
							check_variable = {
								which = develop_x_category
								value = 3
							}
						}
					}
					base_manpower = "province_mil_var"
				}
				else_if = {
					limit = {
						root = {
							check_variable = {
								which = develop_x_category
								value = 2
							}
						}
					}
					base_production = "province_dip_var"
				}
				else = {
					base_tax = "province_adm_var"
				}
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_cossacks
		}
		add_estate_loyalty = {
			estate = estate_cossacks
			loyalty = 10
		}
		if = {
			limit = {
				check_variable = {
					which = develop_x_category
					value = 3
				}
			}
			 add_yearly_manpower = 0.3
		}
		else_if = {
			limit = {
				check_variable = {
					which = develop_x_category
					value = 2
				}
			}
			add_years_of_income = 0.3
		}
		else = {
			add_prestige = 10
		}
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_cossacks_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_cossacks
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}