##############################
# Imperialist Faction
##############################

imperialist = {
	election_header = "GFX_faction_header_yellow"
	guiding_ethic = ethic_militarist
	visual_ethic = "imperialist_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
					}
				}
			}
			engineering_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
					}
				}
			}
			alloys = @faction_base_output
			mult = @faction_extortion_alloys_ratio
		}
		produces = {
			trigger = {
				owner = {
					OR = {
						has_valid_civic = civic_crowdsourcing
						has_valid_civic = civic_corporate_crowdsourcing
					}
				}
			}
			engineering_research = @faction_major_output
			society_research = @faction_minor_output
			mult = @faction_extortion_crowdsourcing_ratio
		}
	}

	#Note: number of potential or actual members is checked by POP_FACTION_MIN_POTENTIAL_MEMBERS define
	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_AUTHORITARIAN_POS
		trigger = {
			owner? = {
				is_authoritarian = yes
			}
		}
	}
	pop_attraction_tag = {
		desc = POP_FACTION_ATTRACTION_CITIZENSHIP_POS
		trigger = {
			owner? = {
				any_owned_pop_group = {
					has_citizenship_rights = yes
				}
			}
		}
	}

	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_AUTHORITARIAN
			owner? = { is_authoritarian = yes }
		}

		modifier = {
			factor = 1.25
			has_citizenship_rights = yes
		}
	}

	leader = {
		base = 100

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

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

	demand = {
		title = "IMPERIALIST_PHILOSOPHY"
		unfulfilled_title = "IMPERIALIST_NO_PHILOSOPHY"
		desc = "IMPERIALIST_PHILOSOPHY_DESC"

		unfulfilled_effect = -30
		fulfilled_effect = 0.001

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

		trigger = {
			owner = {
				OR = {
					has_policy_flag = unrestricted_wars
					has_policy_flag = liberation_wars
				}
			}
		}
	}

	demand = {
		title = "IMPERIALIST_CONQUEST"
		unfulfilled_title = "IMPERIALIST_NO_CONQUEST"
		desc = "IMPERIALIST_CONQUEST_DESC"

		fulfilled_effect = 10
		unfulfilled_effect = -0.001

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

		trigger = {
			owner = {
				has_country_flag = imperialist_conquest_timed_flag
			}
		}
	}

	demand = {
		title = "SUPREMACIST_FANATIC_PURIFIERS"
		unfulfilled_title = "SUPREMACIST_NOT_FANATIC_PURIFIERS"
		desc = "SUPREMACIST_FANATIC_PURIFIERS_DESC"

		fulfilled_effect = 10
		unfulfilled_effect = -0.001

		potential = {
			exists = owner
			owner = {
				has_valid_civic = civic_fanatic_purifiers
			}
		}

		trigger = {
			owner = {
				has_valid_civic = civic_fanatic_purifiers
			}
		}
	}

	demand = {
		title = "IMPERIALIST_RIVALS1"
		unfulfilled_title = "IMPERIALIST_FEW_RIVALS1"
		desc = "IMPERIALIST_RIVALS_DESC1"

		fulfilled_effect = 5
		unfulfilled_effect = -5

		potential = {
			exists = owner
			owner = {
				num_communications > 2
				NOT = { has_valid_civic = civic_fanatic_purifiers }
				num_rivals < 2
			}
		}

		trigger = {
			owner = {
				num_rivals > 0
			}
		}
	}

	demand = {
		title = "IMPERIALIST_RIVALS2"
		unfulfilled_title = "IMPERIALIST_FEW_RIVALS2"
		desc = "IMPERIALIST_RIVALS_DESC2"

		fulfilled_effect = 10
		unfulfilled_effect = -0.001

		potential = {
			exists = owner
			owner = {
				num_communications > 2
				NOT = { has_valid_civic = civic_fanatic_purifiers }
				num_rivals = 2
			}
		}

		trigger = {
			owner = {
				num_rivals > 1
			}
		}
	}

	demand = {
		title = "IMPERIALIST_RIVALS3"
		unfulfilled_title = "IMPERIALIST_FEW_RIVALS3"
		desc = "IMPERIALIST_RIVALS_DESC3"

		fulfilled_effect = 15
		unfulfilled_effect = -0.001

		potential = {
			exists = owner
			owner = {
				num_communications > 2
				NOT = { has_valid_civic = civic_fanatic_purifiers }
				num_rivals > 2
			}
		}

		trigger = {
			owner = {
				num_rivals > 2
			}
		}
	}

	demand = {
		title = "IMPERIALIST_OVERLORD" #Imperial Hegemony
		unfulfilled_title = "IMPERIALIST_NOT_OVERLORD"
		desc = "IMPERIALIST_OVERLORD_DESC"

		fulfilled_effect = 5
		unfulfilled_effect = -0.001

		potential = {
			exists = owner
			owner = {
				num_communications > 2
				NOT = { has_valid_civic = civic_fanatic_purifiers }
			}
		}

		trigger = {
			OR = {
				owner = {
					is_overlord = yes
				}
				owner = {
					has_federation = yes
					federation = {
						has_federation_type = hegemony_federation
					}
					is_federation_leader = yes
				}
			}
		}
	}

	demand = {
		title = IMPERIALIST_FEDERATION
		unfulfilled_title = IMPERIALIST_FEDERATION_NOT_MILITARIST
		desc = "IMPERIALIST_FEDERATION_DESC"

		fulfilled_effect = 5
		unfulfilled_effect = -0.001

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

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

	demand = {
		title = IMPERIALIST_FLEET_USAGE_HIGH
		unfulfilled_title = IMPERIALIST_FLEET_USAGE_NOT_HIGH
		desc = IMPERIALIST_FLEET_USAGE_HIGH_DESC

		fulfilled_effect = 5
		unfulfilled_effect = -0.001

		potential = {
			exists = owner
			owner = {
				OR = {
					used_naval_capacity_percent > 0.75
					is_at_war = yes
				}
			}
		}

		trigger = {
			owner = { used_naval_capacity_percent > 1 }
		}
	}

	demand = {
		title = IMPERIALIST_FLEET_USAGE_LOW
		unfulfilled_title = IMPERIALIST_FLEET_USAGE_NOT_LOW
		desc = IMPERIALIST_FLEET_USAGE_LOW_DESC

		fulfilled_effect = 0.001
		unfulfilled_effect = -10

		potential = {
			exists = owner
			owner = {
				used_naval_capacity_percent <= 0.75
				is_at_war = no
			}
		}

		trigger = {
			owner = { used_naval_capacity_percent > 0.75 }
		}
	}

	demand = {
		title = "IMPERIALIST_UNDERLING"
		unfulfilled_title = "IMPERIALIST_NOT_UNDERLING"
		desc = "IMPERIALIST_UNDERLING_DESC"

		unfulfilled_effect = -25
		fulfilled_effect = 0.001

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

		trigger = {
			owner = {
				is_subject = no
			}
		}
	}

	demand = {
		title = "IMPERIALIST_BULWARK"
		unfulfilled_title = "IMPERIALIST_NOT_BULWARK"
		desc = "IMPERIALIST_BULWARK_DESC"

		unfulfilled_effect = -25
		fulfilled_effect = 0.001

		potential = {
			exists = owner
			owner = {
				has_overlord_dlc = yes
				is_subject = yes
			}
		}

		trigger = {
			owner = {
				OR = {
					is_subject = no
					is_specialist_subject_type = { TYPE = bulwark }
				}
			}
		}
	}

	demand = {
		title = "IMPERIALIST_SLAYER"
		unfulfilled_title = "IMPRERIALIST_NOT_SLAYER"
		desc = "IMPERIALIST_SLAYER_DESC"

		fulfilled_effect = 5
		unfulfilled_effect = -0.001

		potential = {
			exists = owner
			owner = {
				OR = {
					has_country_flag = killed_guardian
					any_relation = { is_guardian_country = yes }
				}
			}
		}

		trigger = {
			owner = {
				has_country_flag = killed_guardian
			}
		}
	}

	demand = {
		title = "IMPERIALIST_MILITARY_APPLICATIONS"
		unfulfilled_title = "IMPERIALIST_NO_MILITARY_APPLICATIONS"
		desc = "IMPERIALIST_MILITARY_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_military_application_army
					has_modifier = artifact_find_military_application_shield_damage
					has_modifier = artifact_find_military_application_armor_damage
				}
			}
		}

		trigger = {
			owner = {
				OR = {
					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 = "IMPERIALIST_PEACEFUL_APPLICATIONS"
		unfulfilled_title = "IMPERIALIST_NO_PEACEFUL_APPLICATIONS"
		desc = "IMPERIALIST_PEACEFUL_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_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 = {
				NOR = {
					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 = "STRONG_DIPLO_STANCE"
		unfulfilled_title = "STRONG_DIPLO_STANCE"
		desc = "STRONG_DIPLO_STANCE_DESC"

		fulfilled_effect = 10
		unfulfilled_effect = -0.001

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

		trigger = {
			owner = {
				OR = {
					has_policy_flag = diplo_stance_belligerent
					has_policy_flag = diplo_stance_supremacist
					has_policy_flag = diplo_stance_animosity
				}
			}
		}
	}

	demand = {
		title = "WEAK_DIPLO_STANCE"
		unfulfilled_title = "WEAK_DIPLO_STANCE"
		desc = "WEAK_DIPLO_STANCE_DESC"

		fulfilled_effect = 0.01
		unfulfilled_effect = -10

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

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

	demand = {
		title = "IMPERIALIST_BENEVOLENT_SUBJUGATION_POLICY"
		unfulfilled_title = "IMPERIALIST_NO_BENEVOLENT_SUBJUGATION_POLICY"
		desc = "IMPERIALIST_BENEVOLENT_SUBJUGATION_POLICY_DESC"

		unfulfilled_effect = -5
		fulfilled_effect = 0.001

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

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

	demand = {
		title = "IMPERIALIST_OPPRESSIVE_SUBJUGATION_POLICY"
		unfulfilled_title = "IMPERIALIST_ADOPT_OPPRESSIVE_SUBJUGATION_POLICY"
		desc = "IMPERIALIST_OPPRESSIVE_SUBJUGATION_POLICY_DESC"

		fulfilled_effect = 5
		unfulfilled_effect = -0.001

		potential = {
			exists = owner
			owner = {
				is_subject = no
				NOT = { has_policy_flag = benevolent_terms }
			}
		}

		trigger = {
			owner = {
				has_policy_flag = oppressive_terms
			}
		}
	}

	demand = { # Unplugged: Cyberize
		title = IMPERIALIST_UNPLUGGED_CYBERIZE
		unfulfilled_title = IMPERIALIST_UNPLUGGED_NOT_CYBERIZE
		desc = IMPERIALIST_UNPLUGGED_CYBERIZE_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 Cyberize stage
							current_stage = unplugged_identity_stage_3
							situation_monthly_progress > 0
						}
						AND = { # trending towards 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_militarist
		ETHIC_FANATIC = ethic_fanatic_militarist
		ETHIC_OPPOSED = ethic_pacifist
	}

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

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

	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_militarist = no
				}
			}

			effect = {
				add_modifier = { modifier = embraced_faction days = 3600 }
				owner = {
					set_country_flag = has_embraced_faction
					shift_ethic = ethic_militarist
					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_militarist
					}
				}
				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 = militarist
	}
	inline_script = {
		script = pop_faction_types/actions/suppress_faction
		ETHIC = militarist
	}
	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 = alloys_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
			}
		}
	}
}
