#if = {
#limit = {
#	NOT = {
#		has_idea = MNT_idea_clan_partial_mobilisation
#	}
#}
#custom_effect_tooltip = chaotic_mobilisation
#hidden_effect = {
#	random = {
#		chance = 80
#		random_list = {
#			10 = {
#				if = {
#					limit = {
#						check_variable = {
#							var = montenegro_KUCI_loyalty
#							value = -2
#							compare = greater_than_or_equals
#						}
#					}
#					add_to_variable = {
#						var = montenegro_KUCI_loyalty
#						value = -1
#					}
#				}
#			}
#			10 = {
#				if = {
#					limit = {
#						check_variable = {
#							var = montenegro_VASOJEVICI_loyalty
#							value = -2
#							compare = greater_than_or_equals
#						}
#					}
#					add_to_variable = {
#						var = montenegro_VASOJEVICI_loyalty
#						value = -1
#					}
#				}
#			}
#			10 = {
#				if = {
#					limit = {
#						check_variable = {
#							var = montenegro_DROBNJACI_loyalty
#							value = -2
#							compare = greater_than_or_equals
#						}
#					}
#					add_to_variable = {
#						var = montenegro_DROBNJACI_loyalty
#						value = -1
#					}
#				}
#			}
#			10 = {
#				if = {
#					limit = {
#						check_variable = {
#							var = montenegro_GRAHOVO_loyalty
#							value = -2
#							compare = greater_than_or_equals
#						}
#					}
#					add_to_variable = {
#						var = montenegro_GRAHOVO_loyalty
#						value = -1
#					}
#				}
#			}
#			10 = {
#				if = {
#					limit = {
#						check_variable = {
#							var = montenegro_PIPERI_loyalty
#							value = -2
#							compare = greater_than_or_equals
#						}
#					}
#					add_to_variable = {
#						var = montenegro_PIPERI_loyalty
#						value = -1
#					}
#				}
#			}
#			10 = {
#				if = {
#					limit = {
#						check_variable = {
#							var = montenegro_CUCE_loyalty
#							value = -2
#							compare = greater_than_or_equals
#						}
#					}
#					add_to_variable = {
#						var = montenegro_CUCE_loyalty
#						value = -1
#					}
#				}
#			}
#			10 = {
#				if = {
#					limit = {
#						check_variable = {
#							var = montenegro_NJEGUSI_loyalty
#							value = -2
#							compare = greater_than_or_equals
#						}
#					}
#					add_to_variable = {
#						var = montenegro_NJEGUSI_loyalty
#						value = -1
#					}
#				}
#			}
#			10 = {
#				if = {
#					limit = {
#						check_variable = {
#							var = montenegro_CEKLIN_loyalty
#							value = -2
#							compare = greater_than_or_equals
#						}
#					}
#					add_to_variable = {
#						var = montenegro_CEKLIN_loyalty
#						value = -1
#					}
#				}
#			}
#			10 = {
#				if = {
#					limit = {
#						check_variable = {
#							var = montenegro_BJELICE_loyalty
#							value = -2
#							compare = greater_than_or_equals
#						}
#					}
#					add_to_variable = {
#						var = montenegro_BJELICE_loyalty
#					value = -1
#					}
#				}
#			}
#			10 = {
#				if = {
#					limit = {
#						check_variable = {
#							var = montenegro_BJELICE_loyalty
#							value = -2
#							compare = greater_than_or_equals
#						}
#					}
#					add_to_variable = {
#						var = montenegro_BJELICE_loyalty
#						value = -1
#					}
#				}
#			}
#		}
#	}
#}
#}


can_add_clans_rebels_division_templates = {
	if = {
		limit = {
			OR = {
				NOT = {
					has_template = "small clan army"
				}
			}
		}
		division_template = {
			name = "small clan army"
			is_locked = yes
			division_cap = 0
			priority = 0
			template_counter = 0
			regiments = {
				irregular_infantry = {
					x = 0
					y = 0
				}
			}
		}
	}
	if = {
		limit = {
			OR = {
				NOT = {
					has_template = "medium clan army"
				}
			}
		}
		division_template = {
			name = "medium clan army"
			is_locked = yes
			division_cap = 0
			priority = 0
			template_counter = 0
			regiments = {
				irregular_infantry = {
					x = 0
					y = 0
				}
				irregular_infantry = {
					x = 0
					y = 1
				}
			}
		}
	}
	if = {
		limit = {
			OR = {
				NOT = {
					has_template = "large clan army"
				}
			}
		}
		division_template = {
			name = "large clan army"
			is_locked = yes
			division_cap = 0
			priority = 0
			template_counter = 0
			regiments = {
				irregular_infantry = {
					x = 0
					y = 0
				}
				irregular_infantry = {
					x = 0
					y = 1
				}
				irregular_infantry = {
					x = 0
					y = 2
				}
			}
		}
	}
}

mobilise_clan_army = {
	if = {### KUCI unit creating 
		limit = {
			check_variable = {
				var = montenegro_KUCI_loyalty
				value = -2
				compare = greater_than_or_equals
			}
		}
		if = {
			limit = {
				check_variable = {
					var = montenegro_KUCI_power
					value = 1
					compare = equals
				}
			}
			942 = {
				create_unit = {
					division = "name = \"Kuči clan army\" division_template = \"small clan army\" start_experience_factor = 0.7"
					owner = MNT
				}
			}
		}
		else_if = {
			limit = {
				check_variable = {
					var = montenegro_KUCI_power
					value = 2
					compare = equals
				}
			}
			942 = {
				create_unit = {
					division = "name = \"Kuči clan army\" division_template = \"medium clan army\" start_experience_factor = 0.7"
					owner = MNT
				}
			}
		}
		else_if = {
			limit = {
				check_variable = {
					var = montenegro_KUCI_power
					value = 3
					compare = equals
				}
			}
			942 = {
				create_unit = {
					division = "name = \"Kuči clan army\" division_template = \"large clan army\" start_experience_factor = 0.7"
					owner = MNT
				}
			}
		}
	}
	else_if = {
		limit = {
			check_variable = {
				var = montenegro_KUCI_loyalty
				value = -3
				compare = equals
			}
		}
		custom_effect_tooltip = kuci_disloyal_clan
	}
	if = {### VASOJEVICI unit creating 
		limit = {
			check_variable = {
				var = montenegro_VASOJEVICI_loyalty
				value = -2
				compare = greater_than_or_equals
			}
		}
		if = {
			limit = {
				check_variable = {
					var = montenegro_VASOJEVICI_power
					value = 1
					compare = equals
				}
			}
			942 = {
				create_unit = {
					division = "name = \"Vasojevici clan army\" division_template = \"small clan army\" start_experience_factor = 0.7"
					owner = MNT
				}
			}
		}
		else_if = {
			limit = {
				check_variable = {
					var = montenegro_VASOJEVICI_power
					value = 2
					compare = equals
				}
			}
			942 = {
				create_unit = {
					division = "name = \"Vasojevici clan army\" division_template = \"medium clan army\" start_experience_factor = 0.7"
					owner = MNT
				}
			}
		}
		else_if = {
			limit = {
				check_variable = {
					var = montenegro_VASOJEVICI_power
					value = 3
					compare = equals
				}
			}
			942 = {
				create_unit = {
					division = "name = \"Vasojevici clan army\" division_template = \"large clan army\" start_experience_factor = 0.7"
					owner = MNT
				}
			}
		}
	}
	else_if = {
		limit = {
			check_variable = {
				var = montenegro_VASOJEVICI_loyalty
				value = -3
				compare = equals
			}
		}
		custom_effect_tooltip = VASOJEVICI_disloyal_clan
	}
	if = { ### DROBNJACI unit creating 
		limit = {
			check_variable = {
				var = montenegro_DROBNJACI_loyalty
				value = -2
				compare = greater_than_or_equals
			}
		}
		if = {
			limit = {
				check_variable = {
					var = montenegro_DROBNJACI_power
					value = 1
					compare = equals
				}
			}
			942 = {
				create_unit = {
						division = "name = \"Drobnjaci clan army\" division_template = \"small clan army\" start_experience_factor = 0.7"
						owner = MNT
					}
				}
		}
		else_if = {
			limit = {
				check_variable = {
					var = montenegro_DROBNJACI_power
					value = 2
					compare = equals
				}
			}
				942 = {
					create_unit = {
						division = "name = \"Drobnjaci clan army\" division_template = \"medium clan army\" start_experience_factor = 0.7"
						owner = MNT
					}
				}
			}
		else_if = {
			limit = {
				check_variable = {
					var = montenegro_DROBNJACI_power
					value = 3
					compare = equals
				}
			}
			942 = {
				create_unit = {
					division = "name = \"Drobnjaci clan army\" division_template = \"large clan army\" start_experience_factor = 0.7"
					owner = MNT
				}
			}
		}
	}
	else_if = {
		limit = {
			check_variable = {
				var = montenegro_DROBNJACI_loyalty
				value = -3
				compare = equals
			}
		}
		custom_effect_tooltip = DROBNJACI_disloyal_clan
	}
	if = {
		### PIPERI unit creating 
		limit = {
			check_variable = {
				var = montenegro_PIPERI_loyalty
				value = -2
				compare = greater_than_or_equals
			}
		}
		if = {
			limit = {
				check_variable = {
					var = montenegro_PIPERI_power
					value = 1
					compare = equals
				}
			}
			942 = {
				create_unit = {
					division = "name = \"Piperi clan army\" division_template = \"small clan army\" start_experience_factor = 0.7"
					owner = MNT
				}
			}
		}
		else_if = {
			limit = {
				check_variable = {
					var = montenegro_PIPERI_power
					value = 2
					compare = equals
				}
			}
			942 = {
				create_unit = {
					division = "name = \"Piperi clan army\" division_template = \"medium clan army\" start_experience_factor = 0.7"
					owner = MNT
				}
			}
		}
		else_if = {
			limit = {
				check_variable = {
					var = montenegro_PIPERI_power
					value = 3
					compare = equals
				}
			}
			942 = {
				create_unit = {
					division = "name = \"Piperi clan army\" division_template = \"large clan army\" start_experience_factor = 0.7"
					owner = MNT
				}
			}
		}
	}
	else_if = {
		limit = {
			check_variable = {
				var = montenegro_PIPERI_loyalty
				value = -3
				compare = equals
			}
		}
		custom_effect_tooltip = PIPERI_disloyal_clan
	}
	if = {### CUCE unit creating 
		limit = {
			check_variable = {
				var = montenegro_CUCE_loyalty
				value = -2
				compare = greater_than_or_equals
			}
		}
		if = {
			limit = {
				check_variable = {
					var = montenegro_CUCE_power
					value = 1
					compare = equals
				}
			}
			942 = {
				create_unit = {
					division = "name = \"Cuce clan army\" division_template = \"small clan army\" start_experience_factor = 0.7"
					owner = MNT
				}
			}
		}
		else_if = {
			limit = {
				check_variable = {
					var = montenegro_CUCE_power
					value = 2
					compare = equals
				}
			}
			942 = {
				create_unit = {
					division = "name = \"Cuce clan army\" division_template = \"medium clan army\" start_experience_factor = 0.7"
					owner = MNT
				}
			}
		}
		else_if = {
			limit = {
				check_variable = {
					var = montenegro_CUCE_power
					value = 3
					compare = equals
				}
			}
			942 = {
				create_unit = {
					division = "name = \"Cuce clan army\" division_template = \"large clan army\" start_experience_factor = 0.7"
					owner = MNT
				}
			}
		}
	}
	else_if = {
		limit = {
			check_variable = {
				var = montenegro_CUCE_loyalty
				value = -3
				compare = equals
			}
		}
		custom_effect_tooltip = CUCE_disloyal_clan
	}
	if = {
		### NJEGUSI unit creating 
		limit = {
			check_variable = {
				var = montenegro_NJEGUSI_loyalty
				value = -2
				compare = greater_than_or_equals
			}
		}
		if = {
			limit = {
				check_variable = {
					var = montenegro_NJEGUSI_power
					value = 1
					compare = equals
				}
			}
			942 = {
				create_unit = {
					division = "name = \"Njeguši clan army\" division_template = \"small clan army\" start_experience_factor = 0.7"
					owner = MNT
				}
			}
		}
		else_if = {
			limit = {
				check_variable = {
					var = montenegro_NJEGUSI_power
					value = 2
					compare = equals
				}
			}
			942 = {
				create_unit = {
					division = "name = \"Njeguši clan army\" division_template = \"medium clan army\" start_experience_factor = 0.7"
					owner = MNT
				}
			}
		}
		else_if = {
			limit = {
				check_variable = {
					var = montenegro_NJEGUSI_power
					value = 3
					compare = equals
				}
			}
			942 = {
				create_unit = {
					division = "name = \"Njeguši clan army\" division_template = \"large clan army\" start_experience_factor = 0.7"
					owner = MNT
				}
			}
		}
	}
	else_if = {
		limit = {
			check_variable = {
				var = montenegro_NJEGUSI_loyalty
				value = -3
				compare = equals
			}
		}
		custom_effect_tooltip = NJEGUSI_disloyal_clan
	}
	if = {
		### CEKLIN unit creating 
		limit = {
			check_variable = {
				var = montenegro_CEKLIN_loyalty
				value = -2
				compare = greater_than_or_equals
			}
		}
		if = {
			limit = {
				check_variable = {
					var = montenegro_CEKLIN_power
					value = 1
					compare = equals
				}
			}
			942 = {
				create_unit = {
					division = "name = \"Ceklin clan army\" division_template = \"small clan army\" start_experience_factor = 0.7"
					owner = MNT
				}
			}
		}
		else_if = {
			limit = {
				check_variable = {
					var = montenegro_CEKLIN_power
					value = 2
					compare = equals
				}
			}
			942 = {
				create_unit = {
					division = "name = \"Ceklin clan army\" division_template = \"medium clan army\" start_experience_factor = 0.7"
					owner = MNT
				}
			}
		}
		else_if = {
			limit = {
				check_variable = {
					var = montenegro_CEKLIN_power
					value = 3
					compare = equals
				}
			}
			942 = {
				create_unit = {
					division = "name = \"Ceklin clan army\" division_template = \"large clan army\" start_experience_factor = 0.7"
					owner = MNT
				}
			}
		}
	}
	else_if = {
		limit = {
			check_variable = {
				var = montenegro_CEKLIN_loyalty
				value = -3
				compare = equals
			}
		}
		custom_effect_tooltip = CEKLIN_disloyal_clan
	}
	if = {### BJELICE unit creating 
		limit = {
			check_variable = {
				var = montenegro_BJELICE_loyalty
				value = -2
				compare = greater_than_or_equals
			}
		}
		if = {
			limit = {
				check_variable = {
					var = montenegro_BJELICE_power
					value = 1
					compare = equals
				}
			}
			942 = {
				create_unit = {
					division = "name = \"Bjelice clan army\" division_template = \"small clan army\" start_experience_factor = 0.7"
					owner = MNT
					}
				}
			}
		else_if = {
			limit = {
				check_variable = {
					var = montenegro_BJELICE_power
					value = 2
					compare = equals
				}
			}               
			942 = {
				create_unit = {
					division = "name = \"Bjelice clan army\" division_template = \"medium clan army\" start_experience_factor = 0.7"
					owner = MNT
				}
			}
		}
		else_if = {
			limit = {
				check_variable = {
					var = montenegro_BJELICE_power
					value = 3
					compare = equals
				}
			}
			942 = {
				create_unit = {
					division = "name = \"Bjelice clan army\" division_template = \"large clan army\" start_experience_factor = 0.7"
					owner = MNT
				}
			}	
		}
	}
	else_if = {
		limit = {
			check_variable = {
				var = montenegro_BJELICE_loyalty
				value = -3
				compare = equals
			}
		}
		custom_effect_tooltip = BJELICE_disloyal_clan
	}
	if = {
		### GRAHOVO unit creating 
		limit = {
			check_variable = {
				var = montenegro_GRAHOVO_loyalty
				value = -2
				compare = greater_than_or_equals
			}
		}
		if = {
			limit = {
				check_variable = {
					var = montenegro_GRAHOVO_power
					value = 1
					compare = equals
				}
			}
			942 = {
				create_unit = {
					division = "name = \"Grahovo clan army\" division_template = \"small clan army\" start_experience_factor = 0.7"
					owner = MNT
				}
			}
		}
		else_if = {
			limit = {
				check_variable = {
					var = montenegro_GRAHOVO_power
					value = 2
					compare = equals
				}
			}
			942 = {
				create_unit = {
					division = "name = \"Grahovo clan army\" division_template = \"medium clan army\" start_experience_factor = 0.7"
					owner = MNT
				}
			}
		}
		else_if = {
			limit = {
				check_variable = {
					var = montenegro_GRAHOVO_power
					value = 3
					compare = equals
				}
			}
			942 = {
				create_unit = {
					division = "name = \"Grahovo clan army\" division_template = \"large clan army\" start_experience_factor = 0.7"
					owner = MNT
				}
			}
		}
	}
	else_if = {
		limit = {
			check_variable = {
				var = montenegro_GRAHOVO_loyalty
				value = -3
				compare = equals
			}
		}
		custom_effect_tooltip = GRAHOVO_disloyal_clan
	}
	add_timed_idea = {
		idea = MNT_idea_clan_mobilisation
		days = 200
	}
}

support_montengro = {
	reverse_add_opinion_modifier = {
		target = MNT
		modifier = supporter_of_Montenegro
	}
	reverse_add_opinion_modifier = {
		target = OTO
		modifier = supporter_of_Montenegro_OTO
	}
}

stop_support_montengro = {
	MNT = {
		remove_opinion_modifier = {
			target = FROM
			modifier = supporter_of_Montenegro
		}
	}
	OTO = {
		remove_opinion_modifier = {
			target = FROM
			modifier = supporter_of_Montenegro_OTO
		}
	}
}

support_ottoman_empire = {
	MNT = {
		add_opinion_modifier = {
			target = FROM
			modifier = supporter_of_Montenegro_OTO
		}
	}
	OTO = {
		add_opinion_modifier = {
			target = FROM
			modifier = supporter_of_Montenegro
		}
	}
}

stop_support_ottoman_empire = {
	MNT = {
		remove_opinion_modifier = {
			target = FROM
			modifier = supporter_of_Montenegro_OTO
		}
	}
	OTO = {
		remove_opinion_modifier = {
			target = FROM
			modifier = supporter_of_Montenegro
		}
	}
}

mostar_negotiations_effect = {
	if = {
		limit = {
			OR = {
				MNT = {
					has_country_flag = have_indenpendence_montengro
				}
				MNT = {
					has_country_flag = not_gained_independence
				}
			}
			OR = {
				MNT = {
					has_country_flag = have_outer_montenegro
				}
				MNT = {
					has_country_flag = not_gained_outer_montenegro
				}
			}
		}
		MNT = {
			country_event = OTO_battleofgrahovac.24
		}
		OTO = {
			country_event = OTO_battleofgrahovac.24
		}
		hidden_effect = {
			MNT = {
				country_event = {
					id = OTO_battleofgrahovac.16
					days = 20
				}
			}
		}
	}
	else_if = {
		limit = {
			NOT = {
				OR = {
					MNT = {
						has_country_flag = have_indenpendence_montengro
					}
					MNT = {
						has_country_flag = not_gained_independence
					}
				}
				OR = {
					MNT = {
						has_country_flag = have_outer_montenegro
					}
					MNT = {
						has_country_flag = not_gained_outer_montenegro
					}
				}
			}
		}
		clr_global_flag = montenegro_ottomans_neogotiations
		MNT = {
			country_event = OTO_battleofgrahovac.23
		}
		OTO = {
			country_event = OTO_battleofgrahovac.23
		}
	}
	else_if = {
		limit = {
			OR = {
				NOT = {
					has_global_flag = have_indenpendence_montengro
					has_global_flag = not_gained_independence
				}
				NOT = {
					has_global_flag = have_indenpendence_montengro
					has_global_flag = not_gained_independence
				}
			}
		}
		clr_global_flag = montenegro_ottomans_neogotiations
		MNT = {
			country_event = OTO_battleofgrahovac.23
		}
		OTO = {
			country_event = OTO_battleofgrahovac.23
		}
	}
}

add_prestige_battle_of_grahovac = {
	custom_effect_tooltip = add_negotiations_effect
	set_temp_variable = {
		var = add_negotiations_bonus_MNT
		value = 0
	}
	if = {
		limit = {
			has_country_flag = not_gained_independence
		}
		add_to_temp_variable = {
			add_negotiations_bonus = -1
		}
	}
	if = {
		limit = {
			has_country_flag = have_indenpendence_montengro
		}
		add_to_temp_variable = {
			add_negotiations_bonus = 3
		}
	}
	if = {
		limit = {
			has_country_flag = have_outer_montenegro
		}
		add_to_temp_variable = {
			add_negotiations_bonus = 2
		}
	}
	if = {
		limit = {
			has_country_flag = not_gained_outer_montenegro
		}
		add_to_temp_variable = {
			add_negotiations_bonus = -1
		}
	}
	if = {
		limit = {
			has_country_flag = have_arms_import
		}
		add_to_temp_variable = {
			add_negotiations_bonus = 1
		}
	}
	set_temp_variable = {
		eoanb_prestige_change = add_negotiations_bonus
	}
	eoanb_change_prestige_score = yes
	#clr_global_flag = have_indenpendence_montengro
	#clr_global_flag = not_gained_independence
	#clr_global_flag = not_gained_outer_montenegro
	#have_outer_montenegro deliberately omitted , if you remove the flag the evaluation of the war of 1862 will not work
	#clr_global_flag = MNT_neogotiate_arms_import
	#clr_global_flag = deport_mirko_petrovic_njegos
	#clr_global_flag = protect_muslim_landlords	
	#clr_global_flag = demanded_debt_repayment
}

OTO_add_prestige_battle_of_grahovac_tooltip = {
	set_temp_variable = {
		var = add_negotiations_bonus_OTO
		value = 0
	}
	add_to_temp_variable = {
		add_negotiations_bonus_OTO = deport_mirko_petrovic_njegos
	}
	add_to_temp_variable = {
		add_negotiations_bonus_OTO = protect_muslim_landlords
	}
	add_to_temp_variable = {
		add_negotiations_bonus_OTO = demanded_debt_repayment
	}
	effect_tooltip = {
		OTO = {
			add_stability = add_negotiations_bonus_OTO
		}
	}
}

increase_tension_by_1 = {
	add_to_variable = {
		var = montenegro_tension
		value = 1
		tooltip = increase_tension_by_1_t
	}
}

decrease_tension_by_5 = {
	add_to_variable = {
		var = montenegro_tension
		value = -5
	}
}

decrease_tension_by_2 = {
	add_to_variable = {
		var = montenegro_tension
		value = -2
	}
}

increase_negotiated_items = {
	add_to_variable = {
		var = global.negotiatied_items
		value = 1
	}
}

improve_agriculture_spirit = {
	if = {
		limit = {
			has_idea = MNT_Disastrous_Agriculture
		}
		swap_ideas = {
			remove_idea = MNT_Disastrous_Agriculture
			add_idea = MNT_Disastrous_Agriculture1
		}
	}
	else_if = {
		limit = {
			has_idea = MNT_Disastrous_Agriculture1
		}
		swap_ideas = {
			remove_idea = MNT_Disastrous_Agriculture1
			add_idea = MNT_Disastrous_Agriculture2
		}
	}
	else_if = {
		limit = {
			has_idea = MNT_Disastrous_Agriculture2
		}
		swap_ideas = {
			remove_idea = MNT_Disastrous_Agriculture2
			add_idea = MNT_Disastrous_Agriculture3
		}
	}
	else_if = {
		limit = {
			has_idea = MNT_Disastrous_Agriculture3
		}
		swap_ideas = {
			remove_idea = MNT_Disastrous_Agriculture3
			add_idea = MNT_Disastrous_Agriculture4
		}
	}
}

improve_mechanized_agriculture = {
	if = {
		limit = {
			NOT = {
				has_idea = MNT_mechanised_agriculture
			}
		}
		add_ideas = MNT_mechanised_agriculture
	}
	else_if = {
		limit = {
			has_idea = MNT_mechanised_agriculture
		}
		swap_ideas = {
			remove_idea = MNT_mechanised_agriculture
			add_idea = MNT_mechanised_agriculture1
		}
	}
	else_if = {
		limit = {
			has_idea = MNT_mechanised_agriculture1
		}
		swap_ideas = {
			remove_idea = MNT_mechanised_agriculture1
			add_idea = MNT_mechanised_agriculture2
		}
	}
	else_if = {
		limit = {
			has_idea = MNT_mechanised_agriculture2
		}
		swap_ideas = {
			remove_idea = MNT_mechanised_agriculture2
			add_idea = MNT_mechanised_agriculture3
		}
	}
}

improve_education_system = {
	if = {
		limit = {
			has_idea = MNT_Nonexistent_education_system
		}
		swap_ideas = {
			remove_idea = MNT_Nonexistent_education_system
			add_idea = MNT_Nonexistent_education_system1
		}
	}
	else_if = {
		limit = {
			has_idea = MNT_Nonexistent_education_system1
		}
		swap_ideas = {
			remove_idea = MNT_Nonexistent_education_system1
			add_idea = MNT_Nonexistent_education_system2
		}
	}
	else_if = {
		limit = {
			has_idea = MNT_Nonexistent_education_system2
		}
		swap_ideas = {
			remove_idea = MNT_Nonexistent_education_system2
			add_idea = MNT_Nonexistent_education_system3
		}
	}
}

############################################
############ border wars system ############
####### only attack ######
MNT_attack_border_war_honestly = {
	OTO = {
		country_event = OTO_battleofgrahovac.14
	}
	set_country_flag = play_honestly_1
	if = {
		limit = {
			has_country_flag = MNT_battle_advantage
			has_idea = MNT_idea_clan_mobilisation
		}
		custom_effect_tooltip = bonus_10
		start_border_war = {
			change_state_after_war = no
			attacker = {
				state = 942
				num_provinces = 1
				on_win = OTO_battleofgrahovac.20
				on_cancel = OTO_battleofgrahovac.21
				on_lose = OTO_battleofgrahovac.22
				modifier = 0.2
			}
			defender = {
				state = 1204
				num_provinces = 1
				on_win = OTO_battleofgrahovac.20
				on_cancel = OTO_battleofgrahovac.21
				on_lose = OTO_battleofgrahovac.22
			}
		}
	}
	else_if = {
		limit = {
			OR = {
				has_country_flag = MNT_battle_advantage
				has_idea = MNT_idea_clan_mobilisation
			}
		}
		custom_effect_tooltip = bonus_5
		start_border_war = {
			change_state_after_war = no
			attacker = {
				state = 942
				num_provinces = 1
				on_win = OTO_battleofgrahovac.20
				on_cancel = OTO_battleofgrahovac.21
				on_lose = OTO_battleofgrahovac.22
				modifier = 0.15
			}
			defender = {
				state = 1204
				num_provinces = 1
				on_win = OTO_battleofgrahovac.20
				on_cancel = OTO_battleofgrahovac.21
				on_lose = OTO_battleofgrahovac.22
			}
		}
	}
	else_if = {
		limit = {
			NOT = {
				has_country_flag = MNT_battle_advantage
			}
			NOT = {
				has_idea = MNT_idea_clan_mobilisation
			}
		}
		start_border_war = {
			change_state_after_war = no
			attacker = {
				state = 942
				num_provinces = 1
				on_win = OTO_battleofgrahovac.20
				on_cancel = OTO_battleofgrahovac.21
				on_lose = OTO_battleofgrahovac.22
				modifier = 0.1
			}
			defender = {
				state = 1204
				num_provinces = 1
				on_win = OTO_battleofgrahovac.20
				on_cancel = OTO_battleofgrahovac.21
				on_lose = OTO_battleofgrahovac.22
			}
		}
	}
}

MNT_attack_border_war_dishonestly = {
	OTO = {
		country_event = OTO_battleofgrahovac.14
	}
	set_country_flag = play_dishonestly_1
	if = {
		limit = {
			has_country_flag = MNT_battle_advantage
			has_idea = MNT_idea_clan_mobilisation
		}
		start_border_war = {
			change_state_after_war = no
			attacker = {
				state = 942
				num_provinces = 1
				on_win = OTO_battleofgrahovac.20
				on_cancel = OTO_battleofgrahovac.21
				on_lose = OTO_battleofgrahovac.22
				modifier = 0.3
			}
			defender = {
				state = 1204
				num_provinces = 1
				on_win = OTO_battleofgrahovac.20
				on_cancel = OTO_battleofgrahovac.21
				on_lose = OTO_battleofgrahovac.22
			}
		}
	}
	else_if = {
		limit = {
			OR = {
				has_country_flag = MNT_battle_advantage
				has_idea = MNT_idea_clan_mobilisation
			}
		}
		start_border_war = {
			change_state_after_war = no
			attacker = {
				state = 942
				num_provinces = 1
				on_win = OTO_battleofgrahovac.20
				on_cancel = OTO_battleofgrahovac.21
				on_lose = OTO_battleofgrahovac.22
				modifier = 0.25
			}
			defender = {
				state = 1204
				num_provinces = 1
				on_win = OTO_battleofgrahovac.20
				on_cancel = OTO_battleofgrahovac.21
				on_lose = OTO_battleofgrahovac.22
			}
		}
	}
	else_if = {
		limit = {
			NOT = {
				has_country_flag = MNT_battle_advantage
			}
			NOT = {
				has_idea = MNT_idea_clan_mobilisation
			}
		}
		start_border_war = {
			change_state_after_war = no
			attacker = {
				state = 942
				num_provinces = 1
				on_win = OTO_battleofgrahovac.20
				on_cancel = OTO_battleofgrahovac.21
				on_lose = OTO_battleofgrahovac.22
				modifier = 0.2
			}
			defender = {
				state = 1204
				num_provinces = 1
				on_win = OTO_battleofgrahovac.20
				on_cancel = OTO_battleofgrahovac.21
				on_lose = OTO_battleofgrahovac.22
			}
		}
	}
}

##########################
####### only defend ######
##########################
MNT_defend_border_war_honestly = {
	set_country_flag = play_honestly_1
	if = {
		limit = {
			has_country_flag = MNT_battle_advantage
			has_idea = MNT_idea_clan_mobilisation
		}
		set_border_war_data = {
			attacker = 1204
			defender = 942
			defender_modifier = 0.2
			combat_width = 100
		}
	}
	else_if = {
		limit = {
			OR = {
				has_country_flag = MNT_battle_advantage
				has_idea = MNT_idea_clan_mobilisation
			}
		}
		set_border_war_data = {
			attacker = 1204
			defender = 942
			defender_modifier = 0.15
			combat_width = 100
		}
	}
	else_if = {
		limit = {
			NOT = {
				has_country_flag = MNT_battle_advantage
			}
			NOT = {
				has_idea = MNT_idea_clan_mobilisation
			}
		}
		set_border_war_data = {
			attacker = 1204
			defender = 942
			defender_modifier = 0.1
			combat_width = 100
		}
	}
}

MNT_defend_border_war_dis_honestly = {
	set_country_flag = play_dishonestly_1
	if = {
		limit = {
			has_country_flag = MNT_battle_advantage
			has_idea = MNT_idea_clan_mobilisation
		}
		set_border_war_data = {
			attacker = 1204
			defender = 942
			defender_modifier = 0.3
			combat_width = 100
		}
	}
	else_if = {
		limit = {
			OR = {
				has_country_flag = MNT_battle_advantage
				has_idea = MNT_idea_clan_mobilisation
			}
		}
		set_border_war_data = {
			attacker = 1204
			defender = 942
			defender_modifier = 0.25
			combat_width = 100
		}
	}
	else_if = {
		limit = {
			NOT = {
				has_country_flag = MNT_battle_advantage
			}
			NOT = {
				has_idea = MNT_idea_clan_mobilisation
			}
		}
		set_border_war_data = {
			attacker = 1204
			defender = 942
			defender_modifier = 0.2
			combat_width = 100
		}
	}
}

########## clans ########
can_add_clans_division_templates = {
	if = {
		limit = {
			NOT = {
				has_template = "clan army"
			}
		}
		division_template = {
			name = "clan army"
			is_locked = yes
			division_cap = 0
			priority = 0
			template_counter = 0
			regiments = {
				irregular_infantry = {
					x = 0
					y = 0
				}
			}
		}
	}
}

MNT_mostar_conditions_visible = {
	if = {
		limit = {
			has_global_flag = not_gained_independence
		}
		effect_tooltip = {
			OTO = {
				puppet = MNT
			}
		}
	}
	if = {
		limit = {
			has_global_flag = have_outer_montenegro
		}
		effect_tooltip = {
			MNT = {
				transfer_state = 1204
			}
		}
	}
	if = {
		limit = {
			has_global_flag = not_gained_outer_montenegro
		}
		effect_tooltip = {
			MNT = {
				delete_units = {
					division_template = "clan rebels"
					disband = no
				}
			}
		}
	}
}

MNT_mostar_conditions = {
	if = {
		limit = {
			has_global_flag = have_indenpendence_montengro
		}
		custom_effect_tooltip = MNT_indenpendence_forever
	}
	else_if = {
		limit = {
			has_global_flag = not_gained_independence
		}
		if = {
			limit = {
				tag = MNT
			}
			set_country_flag = not_gained_independence_C
		}
		OTO = {
			puppet = MNT
		}
	}
	if = {
		limit = {
			has_global_flag = have_outer_montenegro
		}
		if = {
			limit = {
				tag = MNT
			}
			set_country_flag = have_outer_montenegro_C
		}
		MNT = {
			transfer_state = 1204
		}
	}
	else_if = {
		limit = {
			has_global_flag = not_gained_outer_montenegro
		}
		if = {
			limit = {
				tag = MNT
			}
			set_country_flag = not_gained_outer_montenegro_C
		}
		custom_effect_tooltip = OTO_control_outer_montenegro
		MNT = {
			delete_units = {
				division_template = "clan rebels"
				disband = no
			}
		}
	}
	if = {
		limit = {
			has_global_flag = MNT_neogotiate_arms_import
		}
		if = {
			limit = {
				tag = MNT
			}
			set_country_flag = MNT_neogotiate_arms_import_C
		}
		custom_effect_tooltip = arms_import_yes
	}
	else_if = {
		limit = {
			NOT = {
				has_global_flag = MNT_neogotiate_arms_import
			}
		}
		custom_effect_tooltip = arms_import_no
	}
	if = {
		limit = {
			has_global_flag = deport_mirko_petrovic_njegos
		}
		if = {
			limit = {
				tag = MNT
			}
			set_country_flag = deport_mirko_petrovic_njegos_C
		}
		custom_effect_tooltip = MNT_we_lose_mirko
		MNT = {
			remove_unit_leader = 123456
		}
	}
	if = {
		limit = {
			has_global_flag = protect_muslim_landlords
		}
		if = {
			limit = {
				tag = MNT
			}
			set_country_flag = protect_muslim_landlords_C
		}
		custom_effect_tooltip = MNT_we_must_protect_muslim_rights
	}
	if = {
		limit = {
			has_global_flag = demanded_debt_repayment
		}
		custom_effect_tooltip = MNT_we_must_pay_OTO_debt
		OTO = {
			set_temp_variable = {
				loans_amount = -4
			}
			take_loan_without_inflation_effect = yes
		}
		MNT = {
			add_timed_idea = {
				idea = MNT_repaying_Ottoman_debt
				days = 180
			}
		}
	}
}

end_MNT_OTO_war_1858 = {
	clr_global_flag = MNT_war_1858
	OTO = {
		remove_mission = MNT_OTO_mission_war_1858
	}
	MNT = {
		remove_mission = MNT_OTO_mission_war_1858
	}
	MNT = {
		white_peace = {
			tag = OTO
			message = MNT_OTO_1858_war_end
		}
	}
}

MNT_OTO_mission_war_1858_cancel_effect_OTO_conquer_942 = {
	MNT = {
		white_peace = {
			tag = OTO
			message = MNT_OTO_1858_war_end
		}
	}
	MNT = {
		transfer_state = 942
	}
	MNT = {
		complete_national_focus = MNT_focus_the_mostar_convention_n
	}
	clr_global_flag = MNT_war_1858
}

MNT_OTO_mission_war_1858_cancel_effect = {
	clr_global_flag = MNT_war_1858
	if = {
		limit = {
			tag = MNT
		}
		if = {
			limit = {
				check_variable = {
					var = OTO.available_lives
					value = 0
					compare = less_than_or_equals
				}
			}
			MNT = {
				complete_national_focus = MNT_focus_strike_a_deal_with_the_ottomans_n
			}
		}
		if = {
			limit = {
				check_variable = {
					var = MNT.available_lives
					value = 0
					compare = less_than_or_equals
				}
			}
			MNT = {
				complete_national_focus = MNT_focus_the_mostar_convention_n
			}
		}
	}
	MNT = {
		white_peace = {
			tag = OTO
			message = MNT_OTO_1858_war_end
		}
	}
}

MNT_OTO_mission_war_1858_timeout_effect = {
	MNT = {
		complete_national_focus = MNT_focus_strike_a_deal_with_the_ottomans_n
	}
	custom_effect_tooltip = OTO_will_lose
	clr_global_flag = MNT_war_1858
	MNT = {
		white_peace = {
			tag = OTO
			message = MNT_OTO_1858_war_end
		}
	}
}

OTO_MNT_mission_war_1858_timeout_effect = {
	MNT = {
		complete_national_focus = MNT_focus_recognize_our_status_under_the_ottomans_n
	}
	custom_effect_tooltip = MNT_will_lose
	clr_global_flag = MNT_war_1858
	MNT = {
		white_peace = {
			tag = OTO
			message = MNT_OTO_1858_war_end
		}
	}
}

number_of_OTO_supportest = {
	if = {
		limit = {
			check_variable = {
				FRA.support_side = 2
			}
		}
		add_to_temp_variable = {
			eoanb_prestige_change = 2
		}
		custom_effect_tooltip = add_two_prestige_beacuse_france_support_you
	}
	if = {
		limit = {
			check_variable = {
				RUS.support_side = 2
			}
		}
		add_to_temp_variable = {
			eoanb_prestige_change = 2
		}
		custom_effect_tooltip = add_two_prestige_beacuse_russia_support_you
	}
	if = {
		limit = {
			check_variable = {
				AUS.support_side = 2
			}
		}
		add_to_temp_variable = {
			eoanb_prestige_change = 2
		}
		custom_effect_tooltip = add_two_prestige_beacuse_austria_support_you
	}
}

number_of_MNT_supportest = {
	if = {
		limit = {
			check_variable = {
				FRA.support_side = 1
			}
		}
		add_to_temp_variable = {
			eoanb_prestige_change = 2
		}
		custom_effect_tooltip = add_two_prestige_beacuse_france_support_you
	}
	if = {
		limit = {
			check_variable = {
				RUS.support_side = 1
			}
		}
		add_to_temp_variable = {
			eoanb_prestige_change = 2
		}
		custom_effect_tooltip = add_two_prestige_beacuse_russia_support_you
	}
	if = {
		limit = {
			check_variable = {
				AUS.support_side = 1
			}
		}
		add_to_temp_variable = {
			eoanb_prestige_change = 2
		}
		custom_effect_tooltip = add_two_prestige_beacuse_austria_support_you
	}
}

calculate_success_count = {
	if = {
		limit = {
			is_debug = yes
		}
		add_to_variable = {
			var = MNT.success
			value = 1
		}
	}
}

calculate_unsuccess_count = {
	if = {
		limit = {
			is_debug = yes
		}
		add_to_variable = {
			var = MNT.unsuccess
			value = 1
		}
	}
}

rebels_variable_effect = {
	if = {
		limit = {
			herzegovina_uprising = yes
		}
		add_to_variable = {
			var = MNT.herzegovina_rebels
			value = 200
			tooltip = add_200_rebels
		}
		custom_effect_tooltip = intensity_drop_by_1
		add_to_variable = {
			var = herzegovina_intesity
			value = -1
		}
	}
	else_if = {
		limit = {
			montenegro_revolt = yes
		}
		add_to_variable = {
			var = MNT.herzegovina_rebels
			value = 200
			tooltip = add_200_rebels
		}
		custom_effect_tooltip = intensity_drop_by_1
		add_to_variable = {
			var = herzegovina_intesity
			value = -1
		}
	}
	else_if = {
		limit = {
			MNT_OTO_neogotiations = yes
		}
		OTO = {
		}
	}
	else_if = {
		limit = {
			MNT_OTO_war_1858 = yes
		}
		add_manpower = 200
	}
}
