the_grand_dance_$ETHIC$ = {
	name = "pft_the_grand_dance"
	desc = "pft_the_grand_dance_desc"
	icon = "GFX_faction_icon_the_grand_dance"
	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.75

	country_modifier = {
		country_trust_growth = 0.06
	}

	extortion_resource = {
		category = pop_factions
		produces = {
			minerals = @faction_base_output
			mult = @faction_extortion_minerals_ratio
		}
	}

	is_potential = {
		is_secret_societies_empire = yes
		has_country_flag = the_grand_dance_$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_GRAND_DANCE_PROMENADE"
		unfulfilled_title = "THE_GRAND_DANCE_PROMENADE"
		desc = "THE_GRAND_DANCE_PROMENADE_DESC"

		fulfilled_effect = 5
		unfulfilled_effect = -5

		potential = {
			exists = owner
			owner = {
				num_communications >= 1
			}
			count_playable_country = {
				count < 2
				limit = {
					has_communications = root.owner
					opinion_level = {
						who = root.owner
						level >= good
					}
				}
			}
		}

		trigger = {
			any_playable_country = {
				has_communications = root.owner
				opinion_level = {
					who = root.owner
					level >= good
				}
			}
		}
	}

	demand = {
		title = "THE_GRAND_DANCE_PROMENADE2"
		unfulfilled_title = "THE_GRAND_DANCE_PROMENADE2"
		desc = "THE_GRAND_DANCE_PROMENADE2_DESC"

		fulfilled_effect = 10
		unfulfilled_effect = -0.001

		potential = {
			exists = owner
			owner = {
				num_communications >= 2
			}
			count_playable_country = {
				count = 2
				limit = {
					has_communications = root.owner
					opinion_level = {
						who = root.owner
						level >= good
					}
				}
			}
		}

		trigger = {
			count_playable_country = {
				count = 2
				limit = {
					has_communications = root.owner
					opinion_level = {
						who = root.owner
						level >= good
					}
				}
			}
		}
	}

	demand = {
		title = "THE_GRAND_DANCE_PROMENADE3"
		unfulfilled_title = "THE_GRAND_DANCE_PROMENADE3"
		desc = "THE_GRAND_DANCE_PROMENADE3_DESC"

		fulfilled_effect = 15
		unfulfilled_effect = -0.001

		potential = {
			exists = owner
			owner = {
				num_communications >= 3
			}
			count_playable_country = {
				count > 2
				limit = {
					has_communications = root.owner
					opinion_level = {
						who = root.owner
						level >= good
					}
				}
			}
		}

		trigger = {
			count_playable_country = {
				count > 2
				limit = {
					has_communications = root.owner
					opinion_level = {
						who = root.owner
						level >= good
					}
				}
			}
		}
	}

	demand = {
		title = "THE_GRAND_DANCE_PLAYING_BOTH_SIDES"
		unfulfilled_title = "THE_GRAND_DANCE_PLAYING_BOTH_SIDES"
		desc = "THE_GRAND_DANCE_PLAYING_BOTH_SIDES_DESC"

		fulfilled_effect = 10
		unfulfilled_effect = -0.001

		potential = {
			exists = owner
			owner = {
				num_communications >= 2
			}
		}

		trigger = {
			owner = {
				has_country_flag = playing_both_sides_demand
			}
		}
	}

	demand = {
		title = "THE_GRAND_DANCE_ACTIVE_SENSOR"
		unfulfilled_title = "THE_GRAND_DANCE_ACTIVE_SENSOR"
		desc = "THE_GRAND_DANCE_ACTIVE_SENSOR_DESC"

		fulfilled_effect = 5
		unfulfilled_effect = -0.001

		potential = {
			exists = owner
			owner = {
				num_communications >= 1
			}
		}

		trigger = {
			any_country = {
				OR = {
					has_sensor_link_from = root.owner
					root.owner = { has_sensor_link_from = prev }
				}
			}
		}
	}

	demand = {
		title = "THE_GRAND_DANCE_INNOCENT_PRANK"
		unfulfilled_title = "THE_GRAND_DANCE_INNOCENT_PRANK"
		desc = "THE_GRAND_DANCE_INNOCENT_PRANK_DESC"

		fulfilled_effect = 5
		unfulfilled_effect = -0.001

		potential = {
			exists = owner
			owner = {
				num_communications >= 2
			}
		}

		trigger = {
			owner = {
				has_country_flag = innocent_prank_demand
			}
		}
	}

	demand = {
		title = "THE_GRAND_DANCE_DARK_WHISPERS"
		unfulfilled_title = "THE_GRAND_DANCE_DARK_WHISPERS"
		desc = "THE_GRAND_DANCE_DARK_WHISPERS_DESC"

		fulfilled_effect = 5
		unfulfilled_effect = -5

		potential = {
			exists = owner
			owner = {
				num_communications >= 2
			}
		}

		trigger = {
			owner = {
				count_envoy = {
					limit = {
						OR = {
							has_envoy_task = { task = improve_relations }
							has_envoy_task = { task = harm_relations }
						}
					}
					count >= 2
				}
			}
		}
	}

	demand = {
		title = "THE_GRAND_DANCE_SHADOW_PUPPET"
		unfulfilled_title = "THE_GRAND_DANCE_SHADOW_PUPPET"
		desc = "THE_GRAND_DANCE_SHADOW_PUPPET_DESC"

		fulfilled_effect = 10
		unfulfilled_effect = -0.001

		potential = {
			exists = owner
			owner = {
				num_communications >= 2
				has_active_tradition = tr_diplomacy_diplomatic_networking
			}
		}

		trigger = {
			any_country = {
				has_secret_fealty_with = root.owner
			}
		}
	}

	demand = {
		title = "THE_GRAND_DANCE_RIGHT_CHOICE"
		unfulfilled_title = "THE_GRAND_DANCE_RIGHT_CHOICE"
		desc = "THE_GRAND_DANCE_RIGHT_CHOICE_DESC"

		fulfilled_effect = 5
		unfulfilled_effect = -5

		potential = {
			exists = owner
			owner = {
				NOT = { has_election_type = none }
			}
		}

		trigger = {
			owner = {
				has_country_flag = right_choice_demand
			}
		}
	}

	# 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_grand_dance_$ETHIC$_selected
		roll_grand_dance_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
			}
		}
	}
}
