
# Upon conquest, convert any nomadic province(s) to tribal before transferring
# title. Should be used in target title scope of virtually every CB.
emf_cb_nomadic_province_effect = {
	hidden_tooltip = {
		if = {
			limit = {
				tier = count
				location = {
					not = {
						any_province_holding = {
							not = { holding_type = nomad }
						}
					}
					or = {
						ROOT = { is_nomadic = no }
						not = { culture = ROOT }
						not = { religion = ROOT }
					}
					has_empty_holding = yes
				}
			}
			location = {
				build_holding = {
					type = tribal
				}
				random_province_holding = {
					limit = {
						ROOT = { is_nomadic = yes }
						holding_type = tribal
						is_capital = yes
					}
					revoke_capital_holding = yes
				}
				random_province_holding = {
					limit = {
						ROOT = { is_nomadic = no }
						holding_type = tribal
						is_capital = no
					}
					make_capital_holding = yes
				}
			}
		}
		if = {
			limit = { higher_tier_than = count }
			any_de_jure_vassal_title = {
				limit = {
					tier = count
					holder_scope = {
						or = {
							character = FROM
							is_liege_or_above = FROM
						}
					}
					location = {
						not = {
							any_province_holding = {
								not = { holding_type = nomad }
							}
						}
						or = {
							ROOT = { is_nomadic = no }
							not = { culture = ROOT }
							not = { religion = ROOT }
						}
						has_empty_holding = yes
					}
				}
				location = {
					build_holding = {
						type = tribal
					}
					random_province_holding = {
						limit = {
							ROOT = { is_nomadic = yes }
							holding_type = tribal
							is_capital = yes
						}
						revoke_capital_holding = yes
					}
					random_province_holding = {
						limit = {
							ROOT = { is_nomadic = no }
							holding_type = tribal
							is_capital = no
						}
						make_capital_holding = yes
					}
				}
			}
		}
	}
}


## WAR AMBITION EFFECT HELPERS (not used directly in CBs) ##
emf_cb_obj_win_war_effect = {
	hidden_tooltip = {
		any_attacker = {
			add_character_modifier = { name = victory_timer duration = 1 hidden = yes }
		}
		any_attacker = {
			limit = { has_ambition = obj_win_a_war }
			ambition_succeeds = yes
		}
	}
}
emf_cb_obj_win_war_reverse_effect = {
	hidden_tooltip = {
		any_defender = {
			add_character_modifier = { name = victory_timer duration = 1 hidden = yes }
		}
		any_defender = {
			limit = { has_ambition = obj_win_a_war }
			ambition_succeeds = yes
		}
	}
}


## STANDARD WAR OUTCOME EFFECTS ##

emf_cb_victory_effect = {
	emf_cb_obj_win_war_effect = yes
	ROOT = { if = { limit = { rebel = no } pf_glory_plus2_effect = yes } }
	FROM = { pf_glory_minus2_effect = yes }
}

emf_cb_defeat_effect = {
	emf_cb_obj_win_war_reverse_effect = yes
	ROOT = { if = { limit = { rebel = no } pf_glory_minus2_effect = yes } }
	FROM = { pf_glory_plus2_effect = yes }
}

emf_cb_victory_other_effect = { # 3rd-party (assumes enclosing scope is attacker)
	emf_cb_obj_win_war_effect = yes
	pf_glory_plus2_effect = yes
	FROM = { pf_glory_minus2_effect = yes }
}

emf_cb_defeat_other_effect = { # 3rd-party (assumes enclosing scope is attacker)
	emf_cb_obj_win_war_reverse_effect = yes
	pf_glory_minus2_effect = yes
	FROM = { pf_glory_plus2_effect = yes }
}

emf_cb_holy_victory_effect = {
	emf_cb_obj_win_war_effect = yes
	ROOT = {
		if = {
			limit = { rebel = no }
			pf_glory_plus2_effect = yes
			pf_tradition_plus4_effect = yes
		}
	}
	FROM = { pf_glory_minus2_effect = yes }
	FROM = { pf_tradition_minus4_effect = yes }
}

emf_cb_holy_defeat_effect = {
	emf_cb_obj_win_war_reverse_effect = yes
	ROOT = {
		if = {
			limit = { rebel = no }
			pf_glory_minus2_effect = yes
			pf_tradition_minus4_effect = yes
		}
	}
	FROM = { pf_glory_plus2_effect = yes }
	FROM = { pf_tradition_plus4_effect = yes }
}


## DYNLEVY AUTO-ADJUSTMENT EFFECTS FOR MAJOR REVOLTS ##

# regular major_revolt CBs
emf_cb_dynlevy_effect = {
	hidden_tooltip = {
		ROOT = { character_event = { id = emf_dynlevy.20 } }
		FROM = { character_event = { id = emf_dynlevy.20 } }
	}
}

# 3rd-party CBs: assumes enclosing scope is attacker
emf_cb_dynlevy_other_effect = {
	hidden_tooltip = {
		FROM = { character_event = { id = emf_dynlevy.20 } }
		character_event = { id = emf_dynlevy.20 }
	}
}
