﻿# Rota Fortunae — script values. Realm state lives on the primary title.

############ Readers (character scope) ############
rf_menace_value = {
	value = 0
	if = { limit = { exists = primary_title.var:rf_menace } add = primary_title.var:rf_menace }
}
rf_fortune_value = {
	value = 50
	if = { limit = { exists = primary_title.var:rf_fortune } value = primary_title.var:rf_fortune }
}
rf_phase_value = {
	value = 0
	if = { limit = { exists = primary_title.var:rf_phase } value = primary_title.var:rf_phase }
}
rf_phase_years_value = {
	value = 0
	if = { limit = { exists = primary_title.var:rf_phase_years } value = primary_title.var:rf_phase_years }
}
rf_fortune_delta_value = {
	value = 0
	if = { limit = { exists = primary_title.var:rf_fortune_delta } value = primary_title.var:rf_fortune_delta }
}
# 0 calm, 1 concerning, 2 threatening, 3 feared
rf_menace_tier_value = {
	value = 0
	if = { limit = { rf_menace_value >= 75 } value = 3 }
	else_if = { limit = { rf_menace_value >= 50 } value = 2 }
	else_if = { limit = { rf_menace_value >= 25 } value = 1 }
}

############ Menace ############
rf_menace_speed_mult_value = {
	value = 1
	if = { limit = { has_game_rule = rf_menace_slow } value = 0.6 }
	else_if = { limit = { has_game_rule = rf_menace_fast } value = 1.5 }
}

# Title scope (the conquered county). scope:rf_conquest_mult must be set.
rf_county_menace_gain_value = {
	value = 3
	add = { value = development_level divide = 10 max = 4 }
	multiply = scope:rf_conquest_mult
}

# Character scope (independent ruler): yearly structural pressure from sheer size.
rf_menace_structural_value = {
	value = 0
	if = { limit = { realm_size >= 200 } value = 3 }
	else_if = { limit = { realm_size >= 120 } value = 2 }
	else_if = { limit = { realm_size >= 60 } value = 1 }
	# The hegemon of the known world is watched by everyone.
	if = {
		limit = {
			exists = primary_title.var:rf_gp_rank
			primary_title.var:rf_gp_rank = 1
		}
		add = 2
	}
	multiply = rf_menace_speed_mult_value
}

# Character scope: yearly decay.
rf_menace_decay_value = {
	value = 4
	add = { value = diplomacy divide = 5 }
	if = { limit = { rf_phase_value = 2 } add = 1 }
	if = {
		limit = { any_character_war = { primary_attacker = root } }
		multiply = 0.5
	}
}

############ Coalitions ############
# Character scope = a coalition target. Combined strength of its coalition.
rf_coalition_strength_value = {
	value = 0
	if = {
		limit = { primary_title = { has_variable_list = rf_coalition } }
		primary_title = {
			every_in_list = {
				variable = rf_coalition
				limit = { exists = holder }
				add = holder.max_military_strength
			}
		}
	}
}
rf_coalition_size_value = {
	value = 0
	if = {
		limit = { primary_title = { has_variable_list = rf_coalition } }
		primary_title = {
			every_in_list = {
				variable = rf_coalition
				limit = { exists = holder }
				add = 1
			}
		}
	}
}
# Percentage of the target's own strength (100 = equal).
rf_coalition_ratio_value = {
	value = rf_coalition_strength_value
	multiply = 100
	divide = { value = max_military_strength min = 1 }
	round = yes
}

# Character scope = candidate member, scope:rf_threat = the threatening ruler.
# Yearly percentage chance to join a coalition against scope:rf_threat.
rf_coalition_join_chance_value = {
	value = scope:rf_threat.rf_menace_value
	subtract = 40
	multiply = 1.2
	# What this ruler thinks of the threat (this already includes the wariness its menace
	# inspires): -1 point per 2 opinion, between -50 and +25.
	add = {
		value = "opinion(scope:rf_threat)"
		multiply = -0.5
		max = 25
		min = -50
	}
	# Smaller neighbours fear more
	if = {
		limit = { max_military_strength < scope:rf_threat.rf_half_strength_value }
		add = 10
	}
	# The threat took land from us
	if = {
		limit = {
			exists = var:rf_lost_land_to
			var:rf_lost_land_to = scope:rf_threat.primary_title
		}
		add = 20
	}
	# A menace still on the rise is more alarming.
	if = {
		limit = {
			exists = scope:rf_threat.primary_title.var:rf_menace_trend
			scope:rf_threat.primary_title.var:rf_menace_trend > 0
		}
		add = 5
	}
	# Personal relations
	if = { limit = { has_relation_rival = scope:rf_threat } add = 15 }
	if = { limit = { has_relation_nemesis = scope:rf_threat } add = 30 }
	if = { limit = { house ?= scope:rf_threat.house } add = -30 }
	if = { limit = { is_close_family_of = scope:rf_threat } add = -20 }
	# Farther realms are less concerned.
	if = {
		limit = {
			NOT = { any_neighboring_top_liege_realm_owner = { this = scope:rf_threat } }
			capital_province = {
				squared_distance = { target = scope:rf_threat.capital_province value > squared_distance_medium }
			}
		}
		add = -10
	}
	# Personality
	if = { limit = { has_trait = craven } add = -10 }
	if = { limit = { has_trait = brave } add = 5 }
	if = { limit = { has_trait = vengeful } add = 5 }
	if = { limit = { has_trait = content } add = -10 }
	max = 60
	min = 0
}
rf_half_strength_value = {
	value = max_military_strength
	divide = 2
}

############ Wheel of Fortune ############
# Every component below is a raw yearly push; the total is multiplied by rf_wheel_pace_value
# (0.5) before it is applied.
rf_wheel_pace_value = { value = 0.5 }

rf_fortune_phase_inertia_value = {
	value = 0
	if = { limit = { rf_phase_value = 1 } value = 1.5 }
	else_if = {
		limit = { rf_phase_value = 2 }
		# Golden ages wear out: the longer the zenith, the stronger the pull down.
		value = -0.3
		subtract = {
			value = rf_phase_years_value
			multiply = 0.02
			max = 2
		}
		if = {
			limit = { exists = primary_title.var:rf_memento_mori }
			value = 0
		}
	}
	else_if = { limit = { rf_phase_value = 3 } value = 0 }
	else_if = { limit = { rf_phase_value = 4 } value = 3 }
}
rf_fortune_ruler_value = {
	value = diplomacy
	add = stewardship
	add = martial
	divide = 3
	subtract = 10
	multiply = 0.25
	if = { limit = { is_adult = no } add = -2 }
	max = 2
	min = -2
	round = yes
}
# In collapse, unrest and debt are the norm: only momentum, the ruler, wars and luck count.
rf_fortune_vassals_value = {
	value = 0
	if = {
		limit = { NOT = { rf_phase_value = 4 } }
		every_vassal = {
			limit = {
				highest_held_title_tier >= tier_county
				opinion = { target = root value < -30 }
			}
			add = -0.5
		}
	}
	min = -2
}
rf_fortune_debt_value = {
	value = 0
	if = {
		limit = {
			gold < 0
			NOT = { rf_phase_value = 4 }
		}
		value = -2
	}
}
rf_fortune_size_value = {
	value = 0
	if = { limit = { realm_size >= 250 } value = -2.5 }
	else_if = { limit = { realm_size >= 150 } value = -1.5 }
	else_if = { limit = { realm_size >= 80 } value = -0.5 }
}
rf_fortune_hubris_value = {
	value = 0
	if = { limit = { rf_menace_value >= 75 } value = -1 }
}
rf_fortune_dynasty_value = {
	value = 0
	if = {
		limit = { exists = primary_title.var:rf_dyn_years }
		if = { limit = { primary_title.var:rf_dyn_years >= 200 } value = -1 }
		else_if = { limit = { primary_title.var:rf_dyn_years >= 120 } value = -0.5 }
	}
}
rf_fortune_events_value = {
	value = 0
	if = { limit = { exists = primary_title.var:rf_fd_events } value = primary_title.var:rf_fd_events }
}

# Phase modifier strength for the selected rule (used in tooltips).
rf_wheel_intensity_value = {
	value = 1
	if = { limit = { has_game_rule = rf_wheel_gentle } value = 0.5 }
	else_if = { limit = { has_game_rule = rf_wheel_harsh } value = 1.5 }
}

############ Counter-play costs ############
rf_appease_gold_value = {
	value = 50
	add = { value = rf_menace_value multiply = 3 }
	add = { value = realm_size multiply = 0.5 }
	round = yes
}
rf_appease_prestige_value = {
	value = 150
	add = { value = rf_menace_value multiply = 5 }
	round = yes
}
# Character scope = the bribed member.
rf_defection_gold_value = {
	value = 75
	add = { value = max_military_strength divide = 40 }
	round = yes
	max = 1500
}
rf_renovatio_gold_value = {
	value = 150
	add = { value = realm_size multiply = 2 }
	round = yes
	max = 2000
}
# Character scope = the loser of a coalition war.
rf_reparations_value = {
	value = monthly_character_income
	multiply = 18
	min = 25
	round = yes
}

# Character scope: displayed army strength.
rf_strength_value = {
	value = max_military_strength
	round = yes
}


############ Great powers ############
# Character scope. Army strength (in hundreds) plus counties held in the realm.
rf_power_value = {
	value = max_military_strength
	divide = 100
	add = realm_size
	round = yes
}
rf_gp_rank_value = {
	value = 0
	if = { limit = { exists = primary_title.var:rf_gp_rank } value = primary_title.var:rf_gp_rank }
}
