the_masquerade_$ETHIC$ = {
	name = "pft_the_masquerade"
	desc = "pft_the_masquerade_desc"
	icon = "GFX_faction_icon_the_masquerade"
	election_header = "GFX_faction_header_yellow"
	guiding_ethic = ethic_$ETHIC$
	visual_ethic = $VISUAL_ETHIC$

	persistent_faction = yes
	use_guiding_ethic_as_pop_filter = no
	use_guiding_ethic_as_growth_factor = no
	can_rename = no
	unique = yes
	support_weight_exponent = 0.7

	country_modifier = {
		diplo_weight_mult = 0.003
	}

	extortion_resource = {
		category = pop_factions
		produces = {
			energy = @faction_base_output
			mult = @faction_extortion_energy_ratio
		}
	}

	is_potential = {
		is_secret_societies_empire = yes
		has_country_flag = the_masquerade_$ETHIC$_selected
	}

	can_join_pre_triggers = {
		is_enslaved = no
		is_being_purged = no
	}

	can_join_faction = {
		custom_tooltip_icon = {
			fail_text = POP_CAN_THINK
			can_think = yes
		}
	}

	inline_script = pop_faction_types/attraction/promote_suppress_tags

	attraction = {
		base = 100

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

	leader = {
		base = 100

		modifier = {
			factor = 0.0
			is_event_leader = yes
		}
	}

	demand = {
		title = "THE_MASQUERADE_SPECIAL_POWERS1"
		unfulfilled_title = "THE_MASQUERADE_SPECIAL_POWERS1"
		desc = "THE_MASQUERADE_SPECIAL_POWERS_DESC1"

		fulfilled_effect = 5
		unfulfilled_effect = -0.001

		potential = {
			is_galactic_council_established = yes
			exists = owner
			owner = {
				num_communications >= value:get_num_empires_percent|PERC|0.5|
			}
		}

		trigger = {
			owner = {
				is_part_of_galactic_council = yes
			}
		}
	}

	demand = {
		title = "THE_MASQUERADE_SPECIAL_POWERS2"
		unfulfilled_title = "THE_MASQUERADE_SPECIAL_POWERS2"
		desc = "THE_MASQUERADE_SPECIAL_POWERS_DESC2"

		fulfilled_effect = 10
		unfulfilled_effect = -0.001

		potential = {
			is_galactic_council_established = yes
			exists = owner
			owner = {
				num_communications >= value:get_num_empires_percent|PERC|0.5|
				is_part_of_galactic_council = yes
			}
		}

		trigger = {
			owner = {
				OR = {
					is_galactic_custodian = yes
					is_galactic_emperor = yes
				}
			}
		}
	}

	demand = {
		title = "THE_MASQUERADE_SPECIAL_POWERS3"
		unfulfilled_title = "THE_MASQUERADE_SPECIAL_POWERS3"
		desc = "THE_MASQUERADE_SPECIAL_POWERS_DESC3"

		fulfilled_effect = 20
		unfulfilled_effect = -0.001

		potential = {
			is_galactic_council_established = yes
			exists = owner
			owner = {
				num_communications >= value:get_num_empires_percent|PERC|0.5|
				is_part_of_galactic_council = yes
				OR = {
					is_galactic_custodian = yes
					is_galactic_emperor = yes
				}
			}
		}

		trigger = {
			owner = {
				is_galactic_emperor = yes
			}
		}
	}

	demand = {
		title = "THE_MASQUERADE_THANKFUL_FRIENDS"
		unfulfilled_title = "THE_MASQUERADE_THANKFUL_FRIENDS"
		desc = "THE_MASQUERADE_THANKFUL_FRIENDS_DESC"

		fulfilled_effect = 5
		unfulfilled_effect = -5

		potential = {
			is_galactic_community_formed = yes
			exists = owner
			owner = {
				num_communications >= value:get_num_empires_percent|PERC|0.5|
			}
		}

		trigger = {
			any_country = {
				root.owner = {
					num_favors = {
						target = prev
						value >= @the_masquerade_thankful_friends_favors
					}
				}
			}
		}
	}

	demand = {
		title = "THE_MASQUERADE_CONTROL_OF_THE_LAW"
		unfulfilled_title = "THE_MASQUERADE_CONTROL_OF_THE_LAW"
		desc = "THE_MASQUERADE_CONTROL_OF_THE_LAW_DESC"

		fulfilled_effect = 10
		unfulfilled_effect = -0.001

		potential = {
			is_galactic_community_formed = yes
			exists = owner
			owner = {
				num_communications >= value:get_num_empires_percent|PERC|0.5|
			}
		}

		trigger = {
			owner = {
				has_passed_resolution = { years = @the_masquerade_control_of_the_law_years }
			}
		}
	}

	demand = {
		title = "THE_MASQUERADE_POLITICAL_ACTOR"
		unfulfilled_title = "THE_MASQUERADE_POLITICAL_ACTOR"
		desc = "THE_MASQUERADE_POLITICAL_ACTOR_DESC"

		fulfilled_effect = 5
		unfulfilled_effect = -5

		potential = {
			is_galactic_community_formed = yes
			exists = owner
			owner = {
				num_communications >= value:get_num_empires_percent|PERC|0.5|
			}
		}

		trigger = {
			owner = {
				has_galactic_community_emissary = yes
			}
		}
	}

	demand = {
		title = "THE_MASQUERADE_NARRATIVE_CONTROL"
		unfulfilled_title = "THE_MASQUERADE_NARRATIVE_CONTROL"
		desc = "THE_MASQUERADE_NARRATIVE_CONTROL_DESC"

		fulfilled_effect = 5
		unfulfilled_effect = -0.001

		potential = {
			exists = owner
			owner = {
				num_communications >= value:get_num_empires_percent|PERC|0.5|
				is_galactic_community_formed = yes
			}
		}

		trigger = {
			owner = {
				has_country_flag = narrative_control
			}
		}
	}

	demand = {
		title = "THE_MASQUERADE_PRICE_SETTER"
		unfulfilled_title = "THE_MASQUERADE_PRICE_SETTER"
		desc = "THE_MASQUERADE_PRICE_SETTER_DESC"

		fulfilled_effect = 10
		unfulfilled_effect = -0.001

		potential = {
			has_federations_dlc = yes
			has_megacorp = yes
			is_galactic_community_formed = yes
			exists = owner
			owner = {
				num_communications >= value:get_num_empires_percent|PERC|0.5|
			}
		}

		trigger = {
			owner = {
				is_market_leader = yes
			}
		}
	}

	demand = {
		title = "THE_MASQUERADE_UNITED_PURPOSE"
		unfulfilled_title = "THE_MASQUERADE_UNITED_PURPOSE"
		desc = "THE_MASQUERADE_UNITED_PURPOSE_DESC"

		fulfilled_effect = 5
		unfulfilled_effect = -0.001

		potential = {
			is_galactic_community_formed = yes
			exists = owner
			owner = {
				num_communications >= value:get_num_empires_percent|PERC|0.5|
			}
		}

		trigger = {
			owner = {
				has_country_flag = united_in_purpose
			}
		}
	}

	# Faction Demands for Ruler and Council positions.
	inline_script = {
		script = "pop_faction_types/global_faction_demands"
		ETHIC = ethic_$ETHIC$
		ETHIC_FANATIC = ethic_fanatic_$ETHIC$
		ETHIC_OPPOSED = ethic_$ETHIC_OPPOSED$
	}

	on_destroy = {
		remove_country_flag = the_masquerade_$ETHIC$_selected
		roll_masquerade_secret_faction = yes
		inline_script = {
			script = pop_faction_types/effect/promote_on_destroy
			ETHIC = $ETHIC$
		}
		inline_script = {
			script = pop_faction_types/effect/suppress_on_destroy
			ETHIC = $ETHIC$
		}
	}

	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 = {
					is_fanatic_$ETHIC$ = no
				}
			}

			effect = {
				add_modifier = { modifier = embraced_faction days = 3600 }
				owner = {
					shift_ethic = ethic_$ETHIC$
					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_$ETHIC$
					}
				}
				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 = $ETHIC$
	}
	inline_script = {
		script = pop_faction_types/actions/suppress_faction
		ETHIC = $ETHIC$
	}
	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
				}
				is_faction_extorted = no
			}

			effect = {
				set_faction_extorted = yes
				custom_tooltip = engineering_research_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
			}
		}
	}
}
