##############################
# Progressive Faction
##############################

progressive = {
	election_header = "GFX_faction_header_yellow"
	guiding_ethic = ethic_egalitarian
	visual_ethic = "progressive_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
					}
				}
			}
			society_research = @faction_major_output
			physics_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
					}
				}
			}
			society_research = @faction_base_output
			mult = @faction_extortion_research_ratio
		}
		produces = {
			trigger = {
				owner = {
					OR = {
						has_valid_civic = civic_crowdsourcing
						has_valid_civic = civic_corporate_crowdsourcing
					}
				}
			}
			society_research = @faction_major_output
			physics_research = @faction_minor_output
			mult = @faction_extortion_crowdsourcing_ratio
		}
	}

	is_potential = {
		is_faction_allowed = yes
	}

	can_join_pre_triggers = {
		is_enslaved = no
		is_being_purged = no
	}

	can_join_faction = {
		inline_script = pop_faction_types/can_join_faction/base
	}

	inline_script = pop_faction_types/attraction/promote_suppress_tags
	pop_attraction_tag = {
		desc = POP_ATTRACTION_CITIZENSHIP_NEG
		trigger = {
			owner? = {
				any_owned_pop_group = {
					has_citizenship_rights = no
				}
			}
		}
	}

	attraction = {
		base = 150

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

		modifier = {
			factor = 0.25
			has_citizenship_rights = no
		}
	}

	leader = {
		base = 100

		modifier = {
			factor = 0
			is_ruler = yes
			owner = { is_imperial_authority = yes }
		}

		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_progressive
	}

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

	demand = {
		title = "PROGRESSIVE_NO_AUTO"
		unfulfilled_title = "PROGRESSIVE_AUTO"
		desc = "PROGRESSIVE_DEMOCRATIC_GOVERNMENT_DESC"

		fulfilled_effect = 10
		unfulfilled_effect = -15

		potential = {
			exists = owner
		}

		trigger = {
			owner = {
				NOR = {
					is_imperial_authority = yes
					is_dictatorial_authority = yes
				}
			}
		}
	}

	demand = {
		title = "PROGRESSIVE_FREE_MOVEMENT"
		unfulfilled_title = "PROGRESSIVE_NO_FREE_MOVEMENT"
		desc = "PROGRESSIVE_FREE_MOVEMENT_DESC"

		fulfilled_effect = 10
		unfulfilled_effect = -10

		potential = {
			exists = owner
			owner = { has_encountered_other_species = yes }
		}

		trigger = {
			owner = {
				NOR = {
					has_policy_flag = resettlement_allowed
					any_owned_pop_group = {
						has_migration_control = { type = yes }
						is_sapient = yes
						is_enslaved = no
						is_being_purged = no
						is_shackled_robot = no
						is_robot_pop_group = no
					}
				}
			}
		}
	}

	demand = {
		title = "PROGRESSIVE_REPRODUCTIVE_FREEDOM"
		unfulfilled_title = "PROGRESSIVE_NO_REPRODUCTIVE_FREEDOM"
		desc = "PROGRESSIVE_REPRODUCTIVE_FREEDOM_DESC"

		fulfilled_effect = 5
		unfulfilled_effect = -20

		potential = {
			exists = owner
		}

		trigger = {
			NOT = {
				owner = { has_policy_flag = population_controls_allowed }
			}
		}
	}

	demand = {
		title = "PROGRESSIVE_NO_STRATIFIED"
		unfulfilled_title = "PROGRESSIVE_STRATIFIED"
		desc = "PROGRESSIVE_NO_STRATIFIED_DESC"

		unfulfilled_effect = -25
		fulfilled_effect = 0.001

		potential = {
			exists = owner
		}

		trigger = {
			owner = {
				NOT = {
					any_owned_species = {
						OR = {
							has_living_standard = { type = living_standard_dystopian_society country = prev }
							has_living_standard = { type = living_standard_stratified country = prev }
						}
					}
				}
			}
		}
	}

	demand = {
		title = "PROGRESSIVE_NO_ELITISM"
		unfulfilled_title = "PROGRESSIVE_ELITISM"
		desc = "PROGRESSIVE_NO_ELITISM_DESC"

		fulfilled_effect = 5
		unfulfilled_effect = -5

		potential = {
			exists = owner
			owner = {
				OR = {
					has_technology = tech_selected_lineages
					has_technology = tech_capacity_boosters
				}
			}
		}

		trigger = {
			owner = {
				NOR = {
					has_policy_flag = leader_enhancement_selected_lineages
					has_policy_flag = leader_enhancement_capacity_boosters
				}
			}
		}
	}

	demand = {
		title = "COOPERATIVE_DIPLO_STANCE"
		unfulfilled_title = "COOPERATIVE_DIPLO_STANCE"
		desc = "COOPERATIVE_DIPLO_STANCE_DESC"

		fulfilled_effect = 5
		unfulfilled_effect = -0.001

		potential = {
			exists = owner
			owner = {
				is_homicidal = no
				is_country_type = default
				has_policy_flag = diplo_stance_cooperative
			}
		}

		trigger = {
			owner = {
				has_policy_flag = diplo_stance_cooperative
			}
		}
	}

	demand = {
		title = PROGRESSIVE_FEDERATION
		unfulfilled_title = PROGRESSIVE_FEDERATION_NOT_HEGEMONY
		desc = PROGRESSIVE_FEDERATION_DESC

		unfulfilled_effect = -10
		fulfilled_effect = 0.001

		potential = {
			exists = owner.federation
			owner.federation = { has_federation_type = hegemony_federation }
		}

		trigger = {
			OR = {
				NOT = { exists = owner.federation }
				owner.federation = {
					NOT = { has_federation_type = hegemony_federation }
				}
			}
		}
	}

	demand = {
		title = "PROGRESSIVE_BENEVOLENT_SUBJUGATION_POLICY"
		unfulfilled_title = "PROGRESSIVE_BENEVOLENT_NO_OPPRESSIVE_SUBJUGATION_POLICY"
		desc = "PROGRESSIVE_BENEVOLENT_NO_OPPRESSIVE_SUBJUGATION_POLICY_DESC"

		unfulfilled_effect = -0.001
		fulfilled_effect = 5

		potential = {
			exists = owner
			owner = { is_subject = no }
		}

		trigger = {
			owner = {
				has_policy_flag = benevolent_terms
			}
		}
	}

	demand = { # Unplugged: De-Cyberize
		title = PROGRESSIVE_UNPLUGGED_DECYBERIZE
		unfulfilled_title = PROGRESSIVE_UNPLUGGED_NOT_DECYBERIZE
		desc = PROGRESSIVE_UNPLUGGED_DECYBERIZE_DESC

		unfulfilled_effect = -10
		fulfilled_effect = 5

		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
							}
						}
					}
				}
			}
		}
	}

	# Faction Demands for Ruler and Council positions.
	inline_script = {
		script = "pop_faction_types/global_faction_demands"
		ETHIC = ethic_egalitarian
		ETHIC_FANATIC = ethic_fanatic_egalitarian
		ETHIC_OPPOSED = ethic_authoritarian
	}

	demand = { # "PROGRESSIVE_NO_NOMAD_FORCED_LABOR"
		title = "PROGRESSIVE_NO_NOMAD_FORCED_LABOR"
		unfulfilled_title = "PROGRESSIVE_NOMAD_FORCED_LABOR"
		desc = "PROGRESSIVE_NO_NOMAD_FORCED_LABOR_DESC"

		fulfilled_effect = 0.001
		unfulfilled_effect = -15

		potential = {
			exists = owner
			owner = {
				is_nomadic = no
				any_country = {
					is_nomadic = yes
					has_communications = root.owner
				}
			}
		}

		trigger = {
			owner = {
				NOR = {
					has_policy_flag = arkship_raid_relocate_pops
					has_policy_flag = arkship_raid_purge_pops
				}
			}
		}
	}

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

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

	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_egalitarian" }
				}
			}

			effect = {
				add_modifier = { modifier = embraced_faction days = 3600 }
				owner = {
					set_country_flag = has_embraced_faction
					shift_ethic = ethic_egalitarian
					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_egalitarian
					}
				}
				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 = egalitarian
	}
	inline_script = {
		script = pop_faction_types/actions/suppress_faction
		ETHIC = egalitarian
	}
	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 = society_research_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
			}
		}
	}
}
