﻿# Per-attendee stance score for an Ecumenical Council tenet debate (first/second debate)
ecumenical_council_attendee_base_support_value = {
	value = 0
	add = {
		value = 0
		if = {
			limit = {
				has_personal_tenet = scope:tenet
			}
			add = 6
		}
		if = {
			limit = {
				any_desired_tenet = { this = scope:tenet }
			}
			add = 4
		}
		multiply = ecumenical_council_tenet_attachment_direction_value
	}
	if = {
		limit = {
			has_trait = zealous
		}
		add = -3
	}
	if = {
		limit = {
			has_trait = cynical
		}
		add = 3
	}
	# Learned churchmen are more comfortable revisiting doctrine
	if = {
		limit = {
			has_trait = theologian
		}
		add = 2
	}
	if = {
		limit = {
			has_trait = lifestyle_scholar
		}
		add = 1
	}
	# The more pious, the more attached to the faith as it currently stands
	add = {
		value = piety_level
		multiply = -0.5
	}
	
	#MGR: Conservatism rule
	if = {
		limit = { has_game_rule = mgr_ecumenical_conservatism_conservative_bias }
		add = -10
	}
	else_if = {
		limit = { has_game_rule = mgr_ecumenical_conservatism_conservative_lean }
		add = -5
	}
	else_if = {
		limit = { has_game_rule = mgr_ecumenical_conservatism_innovator_lean }
		add = 5
	}
	else_if = {
		limit = { has_game_rule = mgr_ecumenical_conservatism_innovator_bias }
		add = 10
	}

	# (Rivals of the host are already excluded from ever supporting in the sort effect.)
	add = {
		value = "opinion(scope:host)"
		divide = 25
	}

	# Resistance to how radical the status change is (same in either direction)
	add = {
		value = ecumenical_council_proposal_change_magnitude_value
		multiply = -1
	}
	# What the faith at large makes of the tenet, which the rest of this score never sees.
	add = ecumenical_council_tenet_popularity_support_value
	# And what the tenet would make of the attendee: a saint by the new rite, or a sinner.
	add = ecumenical_council_tenet_judgement_support_value
	# Blocked: make_core of a still-prohibited tenet
	if = {
		limit = {
			scope:activity.var:current_debate_proposal ?= flag:make_core
			scope:host.faith.main_rite = {
				has_tenet_status = {
					tenet = scope:tenet
					status = prohibited
				}
			}
		}
		add = -16
	}
	# Zealots are the most scandalized by loosening a ban
	if = {
		limit = {
			has_trait = zealous
			scope:host.faith.main_rite = {
				has_tenet_status = {
					tenet = scope:tenet
					status = prohibited
				}
			}
			OR = {
				scope:activity.var:current_debate_proposal ?= flag:permit
				scope:activity.var:current_debate_proposal ?= flag:make_core
			}
		}
		add = -3
	}
	if = {
		limit = {
			pam_ec_tenet_is_christian_abomination_trigger = yes
			ecumenical_council_proposal_direction_value > 0
		}
		add = -30
	}
}

#This value is the one that actually matters for sorting
ecumenical_council_attendee_support_value = {
	value = ecumenical_council_attendee_base_support_value
	add = {
		value = ecumenical_council_social_alignment_value
		min = -2
		max = 2
	}
}

ecumenical_council_doctrine_entrenchment_value = {
	value = 0
	if = {
		limit = { pam_ec_doctrine_is_change_trigger = yes }
		add = 25
		add = {
			value = ecumenical_council_doctrine_status_magnitude_value
			subtract = 1
			min = 0
			multiply = 20
		}
		if = {
			limit = { pam_ec_doctrine_is_binary_trigger = yes }
			add = 35
		}
		add = {
			value = ecumenical_council_doctrine_christian_offence_delta_value
			min = 0
		}
		add = {
			value = ecumenical_council_doctrine_christian_offence_delta_value
			max = 0
			multiply = -0.4
		}
		add = {
			value = piety_level
			multiply = 3
		}
		if = {
			limit = {
				OR = {
					faith.religious_head ?= this
					rite.head_of_rite ?= this
				}
			}
			add = 15
		}
		if = {
			limit = { has_trait = zealous }
			multiply = 1.5
		}
		else_if = {
			limit = { has_trait = cynical }
			multiply = 0.6
		}
		if = {
			limit = { has_trait = theologian }
			multiply = 0.85
		}
		if = {
			limit = { the_christian_church_radical_change_allowed_trigger = yes }
			multiply = 0.6
		}
		#MGR: Conservatism rule
		if = {
			limit = { has_game_rule = mgr_ecumenical_conservatism_conservative_bias }
			multiply = 3
		}
		else_if = {
			limit = { has_game_rule = mgr_ecumenical_conservatism_conservative_lean }
			multiply = 1.5
		}
		else_if = {
			limit = { has_game_rule = mgr_ecumenical_conservatism_innovator_lean }
			multiply = 0.67
		}
		else_if = {
			limit = { has_game_rule = mgr_ecumenical_conservatism_innovator_bias }
			multiply = 0.33
		}
	}
	min = 0
}

#MGR: Important value
ecumenical_council_doctrine_attendee_base_support_value = {
	value = ecumenical_council_doctrine_desire_value
	add = ecumenical_council_doctrine_personal_judgement_value
	add = ecumenical_council_doctrine_status_support_value
	subtract = ecumenical_council_doctrine_entrenchment_value
}

ecumenical_council_doctrine_attendee_support_value = {
	value = 0
	if = {
		limit = { exists = scope:doctrine }
		add = ecumenical_council_doctrine_attendee_base_support_value
		add = {
			value = ecumenical_council_doctrine_social_alignment_value
			min = -30
			max = 30
		}
	}
}