﻿recruit_mamluk_commander_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_invite_knights.dds"
	}
	desc = recruit_mamluk_commander_decision_desc
	selection_tooltip = recruit_mamluk_commander_decision_tooltip
	confirm_text = recruit_mamluk_commander_decision_confirm
	sort_order = 100

	ai_check_interval = 37 # cooldown + 1

	is_shown = {
		NOT = { has_game_rule = never_mamluk_invasion }
		is_ruler = yes
		is_landed = yes
		exists = dynasty
		exists = title:e_arabia
		exists = title:e_rajastan
		OR = {
			AND = {
				has_title = title:e_arabia
				NOT = { title:e_arabia = { has_variable = had_mamluk_coup_var } }
				title:e_arabia = { is_titular = no }
				trigger_if = {
					limit = { NOT = { has_game_rule = never_ayyubid_invasion } }
					is_target_in_global_variable_list = {
						name = historicinvasions_story_started
						target = flag:ayyubid_story_started
					}
				}
				trigger_else = {
					current_year >= 1171 # ayyubid year
				}
			}
			AND = {
				has_title = title:e_rajastan
				NOT = { title:e_rajastan = { has_variable = had_mamluk_coup_var } }
				title:e_rajastan = { is_titular = no }
				trigger_if = {
					limit = { NOT = { has_game_rule = never_ghurid_invasion } }
					is_target_in_global_variable_list = {
						name = historicinvasions_story_started
						target = flag:ghurid_story_started
					}
				}
				trigger_else = {
					current_year >= 1152 # ghurid year
				}
			}
		}
	}

	is_valid = {
		religion = religion:islam_religion
		trigger_if = { # scope for player event flavor
			limit = { is_ai = no }
			custom_tooltip = {
				text = employs_marshal_tt
				exists = cp:councillor_marshal
			}
		}
		OR = {
			has_primary_title = title:e_arabia
			has_primary_title = title:e_rajastan
		}
	}

	is_valid_showing_failures_only = {
		is_imprisoned = no
	}

	cost = {
		gold = {
			value = 0
			if = {
				limit = { is_ai = no }
				add = 75
			}
		}
		prestige = {
			value = 0
			if = {
				limit = { is_ai = no }
				add = 500
			}
		}
	}

	cooldown = { years = 3 }

	effect = {
		recruit_mamluk_commander_decision_effect = yes
		if = {
			limit = { is_ai = no }
			trigger_event = mamluk_invasion.0150
		}
	}

	ai_potential = {
		primary_title.tier = tier_empire
	}

	ai_will_do = { base = 100 }
}

# recruitment for mamluk elective realms
mamluks_recruit_mamluk_commander_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_invite_knights.dds"
	}
	desc = mamluks_recruit_mamluk_commander_decision_desc
	selection_tooltip = mamluks_recruit_mamluk_commander_decision_tooltip
	confirm_text = mamluks_recruit_mamluk_commander_decision_confirm
	sort_order = 100

	ai_check_interval = 60

	is_shown = {
		NOT = { has_game_rule = never_mamluk_invasion }
		is_ruler = yes
		is_landed = yes
		exists = dynasty
		top_liege.primary_title = { has_title_law = historicinvasions_mamluk_elective_law }
	}

	is_valid = {
		highest_held_title_tier >= tier_duchy
		religion = religion:islam_religion
		trigger_if = { # scope for event flavor
			limit = { is_ai = no }
			custom_tooltip = {
				text = employs_marshal_tt
				exists = cp:councillor_marshal
			}
		}
		custom_tooltip = {
			text = mamluks_recruit_mamluk_commander_decision_top_liege_law
			top_liege.primary_title = { has_title_law = historicinvasions_mamluk_elective_law }
		}
	}

	is_valid_showing_failures_only = {
		is_imprisoned = no
	}

	cost = {
		gold = {
			value = 25
			if = {
				limit = { is_ai = no }
				add = 50
			}
		}
		prestige = {
			value = 250
			if = {
				limit = { is_ai = no }
				add = 250
			}
		}
	}

	cooldown = { years = 12 }

	effect = {
		recruit_mamluk_commander_decision_effect = yes
		if = {
			limit = { is_ai = no }
			trigger_event = mamluk_invasion.0150
		}
	}

	ai_potential = {
		primary_title.tier >= tier_duchy
	}

	ai_will_do = { base = 100 }
}

# disabled after the coup
recruit_mamluk_regiment_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_invite_knights.dds"
	}
	desc = recruit_mamluk_regiment_decision_desc
	selection_tooltip = recruit_mamluk_regiment_decision_tooltip
	confirm_text = recruit_mamluk_regiment_decision_confirm
	sort_order = 100

	ai_check_interval = 85 # cooldown + 1

	is_shown = {
		NOT = { has_game_rule = never_mamluk_invasion }
		is_ruler = yes
		is_landed = yes
		exists = dynasty
		exists = title:e_arabia
		exists = title:e_rajastan
		OR = {
			AND = {
				has_title = title:e_arabia
				NOT = { title:e_arabia = { has_variable = had_mamluk_coup_var } }
				trigger_if = {
					limit = { NOT = { has_game_rule = never_ayyubid_invasion } }
					is_target_in_global_variable_list = {
						name = historicinvasions_story_started
						target = flag:ayyubid_story_started
					}
				}
				trigger_else = {
					current_year >= 1171 # ayyubid year
				}
			}
			AND = {
				has_title = title:e_rajastan
				NOT = { title:e_rajastan = { has_variable = had_mamluk_coup_var } }
				title:e_rajastan = { is_titular = no }
				trigger_if = {
					limit = { NOT = { has_game_rule = never_ghurid_invasion } }
					is_target_in_global_variable_list = {
						name = historicinvasions_story_started
						target = flag:ghurid_story_started
					}
				}
				trigger_else = {
					current_year >= 1152 # ghurid year
				}
			}
		}
	}

	is_valid = {
		religion = religion:islam_religion
		trigger_if = { # scope for event flavor
			limit = { is_ai = no }
			custom_tooltip = {
				text = employs_marshal_tt
				exists = cp:councillor_marshal
			}
		}
		OR = {
			has_primary_title = title:e_arabia
			has_primary_title = title:e_rajastan
		}
	}

	is_valid_showing_failures_only = {
		is_imprisoned = no
	}

	cost = {
		gold = {
			value = 0
			if = {
				limit = { is_ai = no }
				add = 75
			}
		}
		prestige = {
			value = 0
			if = {
				limit = { is_ai = no }
				add = 500
			}
		}
	}

	cooldown = { years = 7 }

	effect = {
		recruit_mamluk_regiment_decision_effect = yes
		if = {
			limit = { is_ai = no }
			trigger_event = mamluk_invasion.0151
		}
	}

	ai_potential = {
		primary_title.tier = tier_empire
	}

	ai_will_do = { base = 100 }
}