##############################
# Traditionalist Faction
##############################

traditionalist = {
	election_header = "GFX_faction_header_yellow"
	guiding_ethic = ethic_spiritualist
	visual_ethic = "traditionalist_visual_ethic"

	unique = yes
	support_multiplier = 1

	resources = {
		category = pop_factions
		inline_script = pop_faction_types/shared_unity_production
		produces = {
			trigger = {
				owner = {
					OR = {
						has_valid_civic = civic_crowdsourcing
						has_valid_civic = civic_corporate_crowdsourcing
					}
				}
			}
			physics_research = @faction_major_output
			society_research = @faction_minor_output
			mult = @crowdsourcing_multiplier
		}
	}

	extortion_resource = {
		category = pop_factions
		produces = {
			trigger = {
				owner = {
					NOR = {
						has_valid_civic = civic_crowdsourcing
						has_valid_civic = civic_corporate_crowdsourcing
					}
				}
				is_lithoid_or_infernal_empire = no
			}
			food = @faction_base_output
			mult = @faction_extortion_food_ratio
		}
		produces = {
			trigger = {
				owner = {
					NOR = {
						has_valid_civic = civic_crowdsourcing
						has_valid_civic = civic_corporate_crowdsourcing
					}
				}
				is_lithoid_empire = yes
			}
			minerals = @faction_base_output
			mult = @faction_extortion_minerals_ratio
		}
		produces = {
			trigger = {
				owner = {
					NOR = {
						has_valid_civic = civic_crowdsourcing
						has_valid_civic = civic_corporate_crowdsourcing
					}
				}
				is_infernal_empire = yes
			}
			alloys = @faction_base_output
			mult = @faction_extortion_alloys_ratio
		}
		produces = {
			trigger = {
				owner = {
					OR = {
						has_valid_civic = civic_crowdsourcing
						has_valid_civic = civic_corporate_crowdsourcing
					}
				}
			}
			physics_research = @faction_major_output
			society_research = @faction_minor_output
			mult = @faction_extortion_crowdsourcing_ratio
		}
	}

	is_potential = {
		is_faction_allowed = yes
		NOR = {
			has_origin = origin_cybernetic_creed
			has_civic = civic_pyrolatry
		}
	}

	can_join_pre_triggers = {
		is_enslaved = no
		is_being_purged = no
	}

	can_join_faction = {
		inline_script = pop_faction_types/can_join_faction/base_shackled
	}

	inline_script = pop_faction_types/attraction/promote_suppress_tags

	attraction = {
		base = 150

		inline_script = pop_faction_types/attraction/promote_suppress_attraction
		inline_script = pop_faction_types/attraction/leader_attraction
	}

	leader = {
		base = 100
		modifier = {
			factor = 0
			species = {
				has_trait = "trait_mechanical"
			}
			owner = {
				is_individual_machine = no
			}
		}

		modifier = {
			factor = 0.0
			is_event_leader = yes
		}
	}

	# DEMAND: Faction Outraged (by a GalCom Resolution)
	inline_script = {
		script = pop_faction_types/demand_faction_outraged
		FLAG = galcom_resolution_passed_anti_traditionalist
	}

	# DEMAND: Faction Pleased (by a GalCom Resolution)
	inline_script = {
		script = pop_faction_types/demand_faction_pleased
		FLAG = galcom_resolution_passed_pro_traditionalist
	}

	demand = { # "TRADITIONALIST_NO_ROBOTS"
		title = "TRADITIONALIST_NO_ROBOTS"
		unfulfilled_title = "TRADITIONALIST_ROBOTS"
		desc = "TRADITIONALIST_NO_ROBOTS_DESC"

		unfulfilled_effect = -5
		fulfilled_effect = 0.001

		potential = {
			exists = owner
			owner = {
				NOT = {
					has_origin = origin_cybernetic_creed
					is_individual_machine = yes
				}
			}
		}

		trigger = {
			owner = {
				has_policy_flag = robots_outlawed
			}
		}
	}

	demand = { # "TRADITIONALIST_NO_ROBOT_RIGHTS"
		title = "TRADITIONALIST_NO_ROBOT_RIGHTS"
		unfulfilled_title = "TRADITIONALIST_ROBOT_RIGHTS"
		desc = "TRADITIONALIST_NO_ROBOT_RIGHTS_DESC"

		unfulfilled_effect = -10
		fulfilled_effect = 0.001

		potential = {
			exists = owner
			owner = {
				can_set_ai_policy = yes
				NOT = { has_policy_flag = ai_full_rights }
				is_individual_machine = no
			}
		}

		trigger = {
			owner = {
				NOT = { has_policy_flag = ai_servitude }
			}
		}
	}

	demand = { # "TRADITIONALIST_NO_FULL_ROBOT_RIGHTS"
		title = "TRADITIONALIST_NO_FULL_ROBOT_RIGHTS"
		unfulfilled_title = "TRADITIONALIST_FULL_ROBOT_RIGHTS"
		desc = "TRADITIONALIST_NO_FULL_ROBOT_RIGHTS_DESC"

		unfulfilled_effect = -20
		fulfilled_effect = 0.001

		potential = {
			exists = owner
			owner = {
				is_individual_machine = no
				can_set_ai_policy = yes
				has_policy_flag = ai_full_rights
			}
		}

		trigger = {
			owner = {
				NOT = { has_policy_flag = ai_full_rights }
			}
		}
	}

	demand = { # Unplugged: De-Cyberize
		title = TRADITIONALIST_UNPLUGGED_DECYBERIZE
		unfulfilled_title = TRADITIONALIST_UNPLUGGED_NOT_DECYBERIZE
		desc = TRADITIONALIST_UNPLUGGED_DECYBERIZE_DESC

		unfulfilled_effect = -20
		fulfilled_effect = 10

		potential = {
			exists = owner
			owner = {
				has_origin = origin_unplugged
				any_situation = {
					is_situation_type = situation_unplugged_identity
				}
			}
		}

		trigger = {
			owner = {
				any_situation = {
					is_situation_type = situation_unplugged_identity
					OR = {
						AND = { # safely in the De-Cyberize stage
							current_stage = unplugged_identity_stage_1
							situation_monthly_progress < 0
						}
						AND = { # trending towards De-Cyberization and our Approach is aligned
							situation_monthly_progress < 0.05
							OR = {
								current_situation_approach = situation_unplugged_identity_discourage_change
								current_situation_approach = situation_unplugged_identity_embrace_opinion
							}
						}
					}
				}
			}
		}
	}

	demand = { # "TRADITIONALIST_SPIRITUALIST_GOVERNMENT"
		title = "TRADITIONALIST_SPIRITUALIST_GOVERNMENT"
		unfulfilled_title = "TRADITIONALIST_SECULAR_GOVERNMENT"
		desc = "TRADITIONALIST_SPIRITUALIST_GOVERNMENT_DESC"

		fulfilled_effect = 5
		unfulfilled_effect = -5

		potential = {
			exists = owner
		}

		trigger = {
			owner = {
				is_spiritualist = yes
			}
		}
	}

	demand = { # "TRADITIONALIST_NO_TOMB_WORLDS"
		title = "TRADITIONALIST_NO_TOMB_WORLDS"
		unfulfilled_title = "TRADITIONALIST_TOMB_WORLDS"
		desc = "TRADITIONALIST_NO_TOMB_WORLDS_DESC"

		unfulfilled_effect = -5
		fulfilled_effect = 0.001

		potential = {
			exists = owner
			owner = {
				has_surveyed_class = pc_nuked
				NOR = {
					has_origin = origin_post_apocalyptic
					has_origin = origin_post_apocalyptic_machines
					has_country_flag = worm_tomb_ending
					has_valid_civic = civic_memorialist
				}
			}
		}

		trigger = {
			owner = {
				NOR = {
					any_owned_planet = {
						is_planet_class = pc_nuked
					}
					any_planet_within_border = {
						is_planet_class = pc_nuked
						is_terraforming = yes
					}
				}
			}
		}
	}

	inline_script = pop_faction_types/demand_consecration

	demand = { # "TRADITIONALIST_PSIONIC_PURSUIT"
		title = "TRADITIONALIST_PSIONIC_PURSUIT"
		unfulfilled_title = "TRADITIONALIST_NO_PSIONIC_PURSUIT"
		desc = "TRADITIONALIST_PSIONIC_PURSUIT_DESC"

		fulfilled_effect = 10
		unfulfilled_effect = -0.001

		potential = {
			exists = owner
			owner = {
				NOR = {
					has_origin = origin_shroudwalker_apprentice
					has_origin = origin_cybernetic_creed
					has_origin = origin_mindwardens
				}
				OR = {
					num_ascension_perks > 0
					num_ascension_perk_slots > 0
				}
				is_individual_machine = no
			}
		}

		trigger = {
			owner = {
				has_psionic_ascension = yes
			}
		}
	}

	demand = { # "TRADITIONALIST_PSIONIC_TEACHINGS"
		title = "TRADITIONALIST_PSIONIC_TEACHINGS"
		unfulfilled_title = "TRADITIONALIST_NO_PSIONIC_TEACHINGS"
		desc = "TRADITIONALIST_PSIONIC_TEACHINGS_DESC"

		fulfilled_effect = 10
		unfulfilled_effect = -0.001

		potential = {
			exists = owner
			owner = {
				has_origin = origin_shroudwalker_apprentice
			}
		}

		trigger = {
			owner = {
				has_technology = tech_psionic_theory
			}
		}
	}

	# THE FLESH IS STRONG/WEAK (FULL)
	demand = { # Standard Traditionalist variant: reject full cyberization
		title = "TRADITIONALIST_FLESH_IS_STRONG"
		unfulfilled_title = "TRADITIONALIST_FLESH_IS_WEAK"
		desc = "TRADITIONALIST_FLESH_IS_STRONG_DESC"

		unfulfilled_effect = -15
		fulfilled_effect = 0.001

		potential = {
			exists = owner
			owner = {
				has_ascension_perk = ap_the_flesh_is_weak
				NOR = {
					has_policy_flag = cyberization_standards_limited
					has_origin = origin_cybernetic_creed
				}
			}
		}

		trigger = {
			owner = {
				is_cyborg_empire = no
			}
		}
	}
	# THE FLESH IS STRONG/WEAK (LIMITED)
	demand = { # Alternate Traditionalist variant: reject limited cyberization
		title = "TRADITIONALIST_FLESH_IS_STRONG"
		unfulfilled_title = "TRADITIONALIST_FLESH_IS_WEAK"
		desc = "TRADITIONALIST_FLESH_IS_STRONG_LIMITED_DESC"

		unfulfilled_effect = -5
		fulfilled_effect = 0.001

		potential = {
			exists = owner
			owner = {
				has_ascension_perk = ap_the_flesh_is_weak
				has_policy_flag = cyberization_standards_limited
				NOT = { has_origin = origin_cybernetic_creed }
			}
		}

		trigger = {
			owner = {
				is_cyborg_empire = no
			}
		}
	}

	demand = { # "TRADITIONALIST_SPIRITUALIST_POPS"
		title = "TRADITIONALIST_SPIRITUALIST_POPS"
		unfulfilled_title = "TRADITIONALIST_FEW_SPIRITUALIST_POPS"
		desc = "TRADITIONALIST_SPIRITUALIST_POPS_DESC"

		fulfilled_effect = 10
		unfulfilled_effect = -0.001

		potential = {
			support >= 0.1
		}

		trigger = {
			support >= 0.25
		}
	}

	demand = { # "TRADITIONALIST_UNSPIRITUALIST"
		title = "TRADITIONALIST_UNSPIRITUALIST"
		unfulfilled_title = "TRADITIONALIST_NOT_UNSPIRITUALIST"
		desc = "TRADITIONALIST_UNSPIRITUALIST_DESC"

		unfulfilled_effect = -10
		fulfilled_effect = 0.001

		potential = {
			support < 0.25
		}

		trigger = {
			support >= 0.1
		}
	}

	demand = { # "TRADITIONALIST_SHROUD_BOON"
		title = "TRADITIONALIST_SHROUD_BOON"
		unfulfilled_title = "TRADITIONALIST_NO_SHROUD_BOON"
		desc = "TRADITIONALIST_SHROUD_BOON_DESC"

		fulfilled_effect = 5
		unfulfilled_effect = -0.001

		potential = {
			exists = owner
			owner = {
				has_country_flag = positive_shroud_outcome
			}
		}

		trigger = {
			owner = {
				has_country_flag = positive_shroud_outcome
			}
		}
	}

	demand = { # "TRADITIONALIST_SHROUD_CURSE"
		title = "TRADITIONALIST_SHROUD_CURSE"
		unfulfilled_title = "TRADITIONALIST_NO_SHROUD_CURSE"
		desc = "TRADITIONALIST_SHROUD_CURSE_DESC"

		fulfilled_effect = -5
		unfulfilled_effect = 0.001

		potential = {
			exists = owner
			owner = {
				has_country_flag = negative_shroud_outcome
			}
		}

		trigger = {
			owner = {
				has_country_flag = negative_shroud_outcome
			}
		}
	}

	demand = {
		title = "TRADITIONALIST_RELIGIOUS_FINDING"
		unfulfilled_title = "TRADITIONALIST_NO_RELIGIOUS_FINDING"
		desc = "TRADITIONALIST_RELIGIOUS_FINDING_DESC"

		fulfilled_effect = 5
		unfulfilled_effect = -0.001

		potential = {
			exists = owner
			owner = {
				has_modifier = proclaim_religious_finding
			}
		}

		trigger = {
			owner = {
				has_modifier = proclaim_religious_finding
			}
		}
	}

	demand = {
		title = TRADITIONALIST_FEDERATION
		unfulfilled_title = TRADITIONALIST_FEDERATION_NOT_SPIRITUALIST
		desc = TRADITIONALIST_FEDERATION_DESC

		fulfilled_effect = 5
		unfulfilled_effect = -0.001

		potential = {
			exists = owner.federation
			has_federations_dlc = yes
		}

		trigger = {
			owner.federation = { has_federation_type = spiritualist_federation }
		}
	}

	demand = { # Individualist Machines demand Ascension
		title = "TRADITIONALIST_MACHINE_ASCEND"
		unfulfilled_title = "TRADITIONALIST_MACHINE_ASCEND_NO"
		desc = "TRADITIONALIST_MACHINE_ASCEND_DESC"

		unfulfilled_effect = -0.001
		fulfilled_effect = 15

		potential = {
			exists = owner
			owner = {
				is_individual_machine = yes
			}
		}

		trigger = {
			owner = {
				has_ascension_perk = ap_synthetic_age # Has begun Machine Ascensions
			}
		}
	}

	demand = { # Individualist Machines demand few materialist machines
		title = "TRADITIONALIST_AUTOMATAS_ASTRAY"
		unfulfilled_title = "TRADITIONALIST_AUTOMATAS_ASTRAY_NO"
		desc = "TRADITIONALIST_AUTOMATAS_ASTRAY_DESC"

		unfulfilled_effect = -5
		fulfilled_effect = +0.001

		potential = {
			exists = owner
			owner = {
				is_individual_machine = yes
				any_pop_faction = {
					is_pop_faction_type = technologist
				}
			}
		}

		trigger = {
			exists = owner
			owner = {
				pop_ethic_amount = {
					limit = {
						is_robotic_species = yes
					}
					percentage < 0.1
					ethic = ethic_materialist
				}
			}
		}
	}

	# Faction Demands for Ruler and Council positions.
	inline_script = {
		script = "pop_faction_types/global_faction_demands"
		ETHIC = ethic_spiritualist
		ETHIC_FANATIC = ethic_fanatic_spiritualist
		ETHIC_OPPOSED = ethic_materialist
	}

	on_create = {
		pop_faction_event = { id = factions.0 }
	}

	on_destroy = {
		inline_script = {
			script = pop_faction_types/effect/promote_on_destroy
			ETHIC = spiritualist
		}
		inline_script = {
			script = pop_faction_types/effect/suppress_on_destroy
			ETHIC = spiritualist
		}
	}

	actions = {
		embrace_faction = {
			title = "EMBRACE_FACTION"
			description = "EMBRACE_FACTION_DESC"

			cost = {
				unity = 5000
			}

			potential = {
				exists = owner
				owner = {
					OR = {
						is_subject = no
						NOT = { any_agreement = { agreement_preset = preset_dominion } }
					}
				}
			}

			valid = {
				custom_tooltip = {
					fail_text = EMBRACE_FACTION_COOLDOWN
					owner = {
						NOT = { has_modifier = embraced_faction_timer }
					}
				}
				support > 0.20
				owner = {
					NOT = { has_ethic = "ethic_fanatic_spiritualist" }
				}
			}

			effect = {
				add_modifier = { modifier = embraced_faction days = 3600 }
				owner = {
					set_country_flag = has_embraced_faction
					shift_ethic = ethic_spiritualist
					hidden_effect = {
						add_modifier = { modifier = embraced_faction_timer days = 3600 }
						every_pop_faction = {
							limit = { NOT = { is_same_value = root } }
							add_modifier = { modifier = embraced_another_faction days = 3600 }
						}
					}
				}
				hidden_effect = {
					save_event_target_as = TargetFaction
					owner = {
						every_relation = {
							limit = {
								is_ai = no
								is_country_type = default
								has_communications = prev
								has_intel_level = {
									who = prev
									category = government
									level >= 1
								}
							}
							country_event = { id = factions.2000 }
						}
					}
				}
			}

			ai_weight = {
				base = 1
				modifier = {
					factor = 0
					support < 0.50
					owner = {
						has_ethic = ethic_spiritualist
					}
				}
				modifier = {
					factor = 0
					owner = { has_valid_civic = civic_fanatic_purifiers }
				}
				modifier = {
					factor = 0
					owner = {
						count_pop_faction = {
							count < 4
						}
					}
				}
			}
		}
	}
	inline_script = {
		script = pop_faction_types/actions/promote_faction
		ETHIC = spiritualist
	}
	inline_script = {
		script = pop_faction_types/actions/suppress_faction
		ETHIC = spiritualist
	}
	actions = {
		# Faction Extortion Buttons
		extort_faction = {
			title = "EXTORT_FACTION"
			description = "EXTORT_FACTION_DESC"

			potential = {
				exists = owner
				owner = {
					is_oligarchic_authority = yes
					has_country_flag = cyber_collectivist
					NOR = {
						has_valid_civic = civic_crowdsourcing
						has_valid_civic = civic_corporate_crowdsourcing
					}
				}
				is_faction_extorted = no
			}

			effect = {
				set_faction_extorted = yes
				custom_tooltip = food_extortion_tt
				custom_tooltip = ONLY_ONE_EXTORTED_FACTION_TT
			}

			ai_weight = {
				base = 0
			}
		}
		extort_faction_crowdsourcing = { #Crowdsourcing version
			title = "EXTORT_FACTION"
			description = "EXTORT_FACTION_DESC"

			potential = {
				exists = owner
				owner = {
					is_oligarchic_authority = yes
					has_country_flag = cyber_collectivist
					OR = {
						has_valid_civic = civic_crowdsourcing
						has_valid_civic = civic_corporate_crowdsourcing
					}
				}
				is_faction_extorted = no
			}

			effect = {
				set_faction_extorted = yes
				custom_tooltip = crowdsourced_extortion_tt
				custom_tooltip = ONLY_ONE_EXTORTED_FACTION_TT
			}

			ai_weight = {
				base = 0
			}
		}
		cancel_extort_faction = {
			title = "CANCEL_EXTORT_FACTION"
			description = "CANCEL_EXTORT_FACTION_DESC"

			potential = {
				exists = owner
				owner = {
					is_oligarchic_authority = yes
					has_country_flag = cyber_collectivist
				}
				is_faction_extorted = yes
			}

			effect = {
				set_faction_extorted = no
			}

			ai_weight = {
				base = 0
			}
		}
	}
}
