##############################
# Peaceful Prosperity Faction
##############################

prosperity = {
	election_header = "GFX_faction_header_yellow"
	guiding_ethic = ethic_pacifist
	visual_ethic = "prosperity_visual_ethics"

	unique = yes
	support_multiplier = 1

	is_potential = {
		is_faction_allowed = yes
	}

	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
					}
				}
			}
			engineering_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
					}
				}
			}
			energy = @faction_base_output
			mult = @faction_extortion_energy_ratio
		}
		produces = {
			trigger = {
				owner = {
					OR = {
						has_valid_civic = civic_crowdsourcing
						has_valid_civic = civic_corporate_crowdsourcing
					}
				}
			}
			engineering_research = @faction_major_output
			physics_research = @faction_minor_output
			mult = @faction_extortion_crowdsourcing_ratio
		}
	}

	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_XENOPHILE_POS
		trigger = {
			owner? = {
				is_xenophile = yes
			}
		}
	}
	pop_attraction_tag = {
		desc = POP_ATTRACTION_CITIZENSHIP_POS
		trigger = {
			owner? = {
				any_owned_pop_group = {
					has_citizenship_rights = no
				}
			}
		}
	}

	attraction = {
		base = 100

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

		modifier = {
			factor = 1.25
			desc = OWNER_IS_XENOPHILE
			owner? = { is_xenophile = yes }
		}

		modifier = {
			factor = 1.25
			has_citizenship_rights = no
		}
	}

	leader = {
		base = 100

		modifier = {
			factor = 0.0
			OR = {
				leader_class = commander
				leader_class = commander
			}
		}

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

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

	demand = {
		title = "PROSPERITY_LIQUIDITY"
		unfulfilled_title = "PROSPERITY_NO_LIQUIDITY"
		desc = "PROSPERITY_LIQUIDITY_DESC"

		fulfilled_effect = 10
		unfulfilled_effect = -0.001

		potential = {
			exists = owner
			owner = {
				num_owned_colonies >= 3
			}
		}

		trigger = {
			owner = { resource_stockpile_compare = { resource = energy value >= 5000 } }
		}
	}

	demand = {
		title = "PROSPERITY_PHILOSOPHY"
		unfulfilled_title = "PROSPERITY_NO_PHILOSOPHY"
		desc = "PROSPERITY_PHILOSOPHY_DESC"

		fulfilled_effect = 10
		unfulfilled_effect = -10

		potential = {
			exists = owner
			owner = {
				any_relation = {
					has_communications = root.owner
					is_country_type = default
					NOT = { exists = overlord }
				}
			}
		}

		trigger = {
			owner = {
				has_policy_flag = no_wars
			}
		}
	}

	demand = {
		title = "PROSPERITY_PEACE"
		unfulfilled_title = "PROSPERITY_NO_PEACE"
		desc = "PROSPERITY_PEACE_DESC"

		fulfilled_effect = 5
		unfulfilled_effect = -10

		potential = {
			exists = owner
		}

		trigger = {
			owner = {
				is_at_war = no
			}
		}
	}

	demand = {
		title = "PROSPERITY_NOT_AGGRESSOR"
		unfulfilled_title = "PROSPERITY_AGGRESSOR"
		desc = "PROSPERITY_NOT_AGGRESSOR_DESC"

		unfulfilled_effect = -30
		fulfilled_effect = 0.001

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

		trigger = {
			owner = {
				NOR = {
					has_country_flag = entered_war_as_attacker
					any_war = { is_war_participant = { who = prev side = attackers } }
				}
			}
		}
	}

	demand = {
		title = "PROSPERITY_PEACEFUL_APPLICATIONS"
		unfulfilled_title = "PROSPERITY_NO_PEACEFUL_APPLICATIONS"
		desc = "PROSPERITY_PEACEFUL_APPLICATIONS_DESC"

		fulfilled_effect = 5
		unfulfilled_effect = -0.001

		potential = {
			exists = owner
			owner = {
				host_has_dlc = "Ancient Relics Story Pack"
				has_technology = tech_arcane_deciphering
				OR = {
					has_modifier = artifact_find_peaceful_application_happy_bios
					has_modifier = artifact_find_peaceful_application_consumer_goods
					has_modifier = artifact_find_peaceful_application_amenities
					has_modifier = artifact_find_peaceful_application_leader_improvement
				}
			}
		}

		trigger = {
			owner = {
				OR = {
					has_modifier = artifact_find_peaceful_application_happy_bios
					has_modifier = artifact_find_peaceful_application_consumer_goods
					has_modifier = artifact_find_peaceful_application_amenities
					has_modifier = artifact_find_peaceful_application_leader_improvement
				}
			}
		}
	}

	demand = {
		title = "PROSPERITY_MILITARY_APPLICATIONS"
		unfulfilled_title = "PROSPERITY_NO_MILITARY_APPLICATIONS"
		desc = "PROSPERITY_MILITARY_APPLICATIONS_DESC"

		unfulfilled_effect = -5
		fulfilled_effect = +0.001

		potential = {
			exists = owner
			owner = {
				host_has_dlc = "Ancient Relics Story Pack"
				has_technology = tech_arcane_deciphering
				OR = {
					has_modifier = artifact_find_military_application_army
					has_modifier = artifact_find_military_application_shield_damage
					has_modifier = artifact_find_military_application_armor_damage
				}
			}
		}

		trigger = {
			owner = {
				NOR = {
					has_modifier = artifact_find_military_application_army
					has_modifier = artifact_find_military_application_shield_damage
					has_modifier = artifact_find_military_application_armor_damage
				}
			}
		}
	}

	demand = {
		title = "MERCANTILE_DIPLO_STANCE"
		unfulfilled_title = "MERCANTILE_DIPLO_STANCE"
		desc = "MERCANTILE_DIPLO_STANCE_DESC"

		fulfilled_effect = 10
		unfulfilled_effect = -0.001

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

		trigger = {
			owner = {
				has_policy_flag = diplo_stance_mercantile
			}
		}
	}

	demand = {
		title = PROSPERITY_FEDERATION
		unfulfilled_title = PROSPERITY_FEDERATION_NOT_MILITARIST
		desc = PROSPERITY_FEDERATION_DESC

		unfulfilled_effect = -10
		fulfilled_effect = 0.001

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

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

	demand = {
		title = "AGGRESSIVE_DIPLO_STANCE"
		unfulfilled_title = "AGGRESSIVE_DIPLO_STANCE"
		desc = "AGGRESSIVE_DIPLO_STANCE_DESC"

		fulfilled_effect = 0.001
		unfulfilled_effect = -10

		potential = {
			exists = owner
			owner = {
				is_homicidal = no
				is_country_type = default
				OR = {
					has_policy_flag = diplo_stance_belligerent
					has_policy_flag = diplo_stance_supremacist
				}
			}
		}

		trigger = {
			owner = {
				NOR = {
					has_policy_flag = diplo_stance_belligerent
					has_policy_flag = diplo_stance_supremacist
				}
			}
		}
	}

	demand = { # Unplugged: De-Cyberize
		title = PROSPERITY_UNPLUGGED_DECYBERIZE
		unfulfilled_title = PROSPERITY_UNPLUGGED_NOT_DECYBERIZE
		desc = PROSPERITY_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_pacifist
		ETHIC_FANATIC = ethic_fanatic_pacifist
		ETHIC_OPPOSED = ethic_militarist
	}

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

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

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

			effect = {
				add_modifier = { modifier = embraced_faction days = 3600 }
				owner = {
					set_country_flag = has_embraced_faction
					shift_ethic = ethic_pacifist
					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_pacifist
					}
				}
				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 = pacifist
	}
	inline_script = {
		script = pop_faction_types/actions/suppress_faction
		ETHIC = pacifist
	}
	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 = energy_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
			}
		}
	}
}
