estate_generals_develop_theme_capital_x = {
	selection_weight = {
		factor = 1
	}
	can_select = {
		any_owned_province = {
			is_state_core = root
			estate_generals_is_theme_capital_trigger = yes
		}
	}
	pre_effect = {
		random_list = {
			# 1 = { #Disabled as it caused null provinces
				# random_owned_province = {
					# limit = {
						# is_state_core = root
						# area_for_scope_province = {
							# is_capital_of = root
						# }
						# estate_generals_is_theme_capital_trigger = yes
					# }
					# 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
								}
							}
						}
						estate_generals_is_theme_capital_trigger = 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
								}
							}
						}
						estate_generals_is_theme_capital_trigger = yes
						region_for_scope_province = {
							is_capital_of = root
						}
					}
					save_event_target_as = agenda_province
				}
			}
			1 = {
				random_owned_province = {
					limit = {
						is_state_core = root
						estate_generals_is_theme_capital_trigger = yes
					}
					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_generals
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_generals
			}
		}
		else = {
			event_target:agenda_province = {
				base_manpower = "province_mil_var"
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_generals
		}
		add_estate_loyalty = {
			estate = estate_generals
			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_theme_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_generals
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_generals_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_generals_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_generals_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_generals_build_army_building_in_y_var
						value = 3
					}
				}
			}
			else_if = {
				limit = {
					has_building = regimental_camp
					ROOT = { mil_tech = 22 }
				}
				ROOT = {
					set_variable = {
						which = estate_generals_build_army_building_in_y_var
						value = 2
					}
				}
			}
			else = {
				ROOT = {
					set_variable = {
						which = estate_generals_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_generals
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_generals
			}
		}
		else = {
			if = {
				limit = {
					check_variable = {
						which = estate_generals_build_army_building_in_y_var
						value = 4
					}
				}
				event_target:agenda_province = {
					has_building = training_fields
				}
			}
			else_if = {
				limit = {
					check_variable = {
						which = estate_generals_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_generals_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_generals
		}
		add_estate_loyalty = {
			estate = estate_generals
			loyalty = 10
		}
		if = {
			limit = {
				NOT = { crown_land_share = 15 }
				estate_territory = {
					estate = estate_generals
					territory = 10
				}
				estate_not_has_exempt_from_seize_land_privilege = { estate = estate_generals }
			}
			take_estate_land_share_small = { estate = estate_generals }
		}
		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_generals
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_generals_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_generals_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_generals_build_fort_building_in_y_var
						value = 4
					}
				}
			}
			else_if = {
				limit = {
					has_building = fort_16th
				}
				ROOT = {
					set_variable = {
						which = estate_generals_build_fort_building_in_y_var
						value = 3
					}
				}
			}
			else_if = {
				limit = {
					has_building = fort_15th
				}
				ROOT = {
					set_variable = {
						which = estate_generals_build_fort_building_in_y_var
						value = 2
					}
				}
			}
			else = {
				ROOT = {
					set_variable = {
						which = estate_generals_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_generals
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_generals
			}
		}
		else = {
			if = {
				limit = {
					check_variable = {
						which = estate_generals_build_fort_building_in_y_var
						value = 4
					}
				}
				event_target:agenda_province = {
					has_building = fort_18th
				}
			}
			else_if = {
				limit = {
					check_variable = {
						which = estate_generals_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_generals_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_generals
		}
		add_estate_loyalty = {
			estate = estate_generals
			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_theme_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_generals
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_generals_hire_a_general = {
	can_select = {
		NOT = { #Does not have a leader that is not the monarch or heir.
			AND = {
				is_heir_leader = yes
				is_monarch_leader = yes
				num_of_generals = 3
			}
			AND = {
				is_heir_leader = yes
				NOT = { is_monarch_leader = yes }
				num_of_generals = 2
			}
			AND = {
				NOT = { is_heir_leader = yes }
				is_monarch_leader = yes
				num_of_generals = 2
			}
			AND = {
				NOT = { is_heir_leader = yes }
				NOT = { is_monarch_leader = yes }
				num_of_generals = 1
			}
		}
	}
	selection_weight = {
		factor = 10
	}
	task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_generals
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_generals
			}
		}
		else = {
			custom_trigger_tooltip = {
				tooltip = has_one_general_not_heir_or_monarch_tooltip
				OR = { #Have a leader that is not the monarch or heir.
					AND = {
						is_heir_leader = yes
						is_monarch_leader = yes
						num_of_generals = 3
					}
					AND = {
						is_heir_leader = yes
						NOT = { is_monarch_leader = yes }
						num_of_generals = 2
					}
					AND = {
						NOT = { is_heir_leader = yes }
						is_monarch_leader = yes
						num_of_generals = 2
					}
					AND = {
						NOT = { is_heir_leader = yes }
						NOT = { is_monarch_leader = yes }
						num_of_generals = 1
					}
				}
			}
		}
	}
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_generals
		}
		add_estate_loyalty = {
			estate = estate_generals
			loyalty = 10
		}
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
        add_estate_loyalty_modifier = {
            estate = estate_generals
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_generals_update_fort_building_in_theme_capital_x = {
	selection_weight = {
		factor = 1
	}
	can_select = {
		any_owned_province = {
			is_state_core = root
			estate_generals_is_theme_capital_trigger = yes
			NOT = { province_has_current_tech_fort_trigger = yes }
		}
	}
	pre_effect = {
		set_variable = {
			which = estate_generals_build_fort_building_in_y_var
			value = 0
		}
		random_list = {
			1 = {
				random_owned_province = {
					limit = {
						is_state_core = root
						area_for_scope_province = {
							is_capital_of = root
						}
						estate_generals_is_theme_capital_trigger = yes
						NOT = { province_has_current_tech_fort_trigger = yes }
					}
					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
								}
							}
						}
						estate_generals_is_theme_capital_trigger = yes
						NOT = { province_has_current_tech_fort_trigger = 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
								}
							}
						}
						estate_generals_is_theme_capital_trigger = yes
						NOT = { province_has_current_tech_fort_trigger = yes }
						region_for_scope_province = {
							is_capital_of = root
						}
					}
					save_event_target_as = agenda_province
				}
			}
			1 = {
				random_owned_province = {
					limit = {
						is_state_core = root
						estate_generals_is_theme_capital_trigger = yes
						NOT = { province_has_current_tech_fort_trigger = yes }
					}
					save_event_target_as = agenda_province
				}
			}
		}
		event_target:agenda_province = {
			if = {
				limit = {
					has_building = fort_17th
				}
				ROOT = {
					set_variable = {
						which = estate_generals_build_fort_building_in_y_var
						value = 4
					}
				}
			}
			else_if = {
				limit = {
					has_building = fort_16th
				}
				ROOT = {
					set_variable = {
						which = estate_generals_build_fort_building_in_y_var
						value = 3
					}
				}
			}
			else_if = {
				limit = {
					has_building = fort_15th
				}
				ROOT = {
					set_variable = {
						which = estate_generals_build_fort_building_in_y_var
						value = 2
					}
				}
			}
			else = {
				ROOT = {
					set_variable = {
						which = estate_generals_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_generals
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_generals
			}
		}
		else = {
			if = {
				limit = {
					check_variable = {
						which = estate_generals_build_fort_building_in_y_var
						value = 4
					}
				}
				event_target:agenda_province = {
					has_building = fort_18th
				}
			}
			else_if = {
				limit = {
					check_variable = {
						which = estate_generals_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_generals_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_generals
		}
		add_estate_loyalty = {
			estate = estate_generals
			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_theme_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_generals
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_generals_fortify_theme_capital_x = {
	can_select = {
		mil_tech = 6
		any_owned_province = {
			is_state_core = root
			estate_generals_is_theme_capital_trigger = yes
			root_can_build_alternate_manufactory_here_trigger = yes
			NOT = { has_building = ramparts }
		}
		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
				estate_generals_is_theme_capital_trigger = yes
				root_can_build_alternate_manufactory_here_trigger = yes
				NOT = { has_building = ramparts }
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				estate_generals_is_theme_capital_trigger = yes
				root_can_build_alternate_manufactory_here_trigger = yes
				NOT = { has_building = ramparts }
				base_manpower = 5
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				estate_generals_is_theme_capital_trigger = yes
				root_can_build_alternate_manufactory_here_trigger = yes
				NOT = { has_building = ramparts }
				base_manpower = 10
			}
			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_generals
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_generals
			}
		}
		else = {
			event_target:agenda_province = {
				has_building = ramparts
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_generals
		}
		add_estate_loyalty = {
			estate = estate_generals
			loyalty = 10
		}
		event_target:agenda_province = {
			add_base_manpower = 2
		}
    }
    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_theme_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_generals
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_generals_soldier_households_in_theme_capital_x = {
	can_select = {
		adm_tech = 15
		any_owned_province = {
			is_state_core = root
			estate_generals_is_theme_capital_trigger = yes
			root_can_build_alternate_manufactory_here_trigger = yes
			NOT = { has_building = soldier_households }
		}
		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
				estate_generals_is_theme_capital_trigger = yes
				root_can_build_alternate_manufactory_here_trigger = yes
				NOT = { has_building = soldier_households }
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				estate_generals_is_theme_capital_trigger = yes
				root_can_build_alternate_manufactory_here_trigger = yes
				NOT = { has_building = soldier_households }
				base_manpower = 5
			}
			save_event_target_as = agenda_province
		}
		random_owned_province = {
			limit = {
				is_state_core = root
				estate_generals_is_theme_capital_trigger = yes
				root_can_build_alternate_manufactory_here_trigger = yes
				NOT = { has_building = soldier_households }
				base_manpower = 10
			}
			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_generals
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_generals
			}
		}
		else = {
			event_target:agenda_province = {
				has_building = ramparts
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_generals
		}
		add_estate_loyalty = {
			estate = estate_generals
			loyalty = 10
		}
		event_target:agenda_province = {
			add_base_manpower = 2
		}
    }
    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_theme_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_generals
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

#Give privileges
estate_generals_two_privileges = { #Copied from Cossacks, modified
	can_select = {
		NOT = {
			num_of_estate_privileges = {
				estate = estate_generals
				value = 1
			}
		}
	}
	selection_weight = {
		factor = 1
	}
	pre_effect = {
	}
	task_requirements = {
		num_of_estate_privileges = {
			estate = estate_generals
			value = 2
		}
	}
    task_completed_effect = {
		add_estate_loyalty = {
			estate = estate_generals
			loyalty = 20
		}
    }
    failing_effect = {
        add_estate_loyalty_modifier = {
            estate = estate_generals
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}