namespace = ccrebel_perf

@dpe_pops_small_cluster = 5
@dpe_pops_medium_cluster = 11
@dpe_pops_large_cluster = 24

#biannual
event = {
	id = ccrebel_perf.3
	is_triggered_only = yes
	hide_window = yes
	
	immediate = {
		every_country = {
			limit = {
				is_country_type_with_subjects = yes
				is_gestalt = no
			}
			every_owned_planet = {
				limit = {
					count_owned_pop_amount = {
						limit = { has_ethic = ethic_spiritualist }
						count > @dpe_pops_medium_cluster
					}
				}
				set_timed_carrier_flag = {
					flag = ccrebel_perf_spiritualists_2
					years = 2
				}
			}
			
			every_owned_planet = {
				limit = {
					count_owned_pop_amount = {
						limit = { has_ethic = ethic_xenophile }
						count > @dpe_pops_small_cluster
					}
				}
				set_timed_carrier_flag = {
					flag = ccrebel_perf_xenophiles_1
					years = 2
				}
				if = {
					limit = {
						count_owned_pop_amount = {
							limit = { has_ethic = ethic_xenophile }
							count > @dpe_pops_medium_cluster
						}
					}
					set_timed_carrier_flag = {
						flag = ccrebel_perf_xenophiles_2
						years = 2
					}
					if = {
						limit = {
							owner = {
								is_xenophobe = yes
							}
						}
						set_timed_carrier_flag = {
							flag = cc_opposite_ethic_to_ruler
							years = 2
						}
					}
					if = {
						limit = {
							count_owned_pop_amount = {
								limit = { has_ethic = ethic_xenophile }
								count > @dpe_pops_large_cluster
							}
						}
						set_timed_carrier_flag = {
							flag = ccrebel_perf_xenophiles_3
							years = 2
						}
					}
				}
			}
			
			every_owned_planet = {
				limit = {
					count_owned_pop_amount = {
						limit = { has_ethic = ethic_xenophobe }
						count > @dpe_pops_small_cluster
					}
				}
				set_timed_carrier_flag = {
					flag = ccrebel_perf_xenophobes_1
					years = 2
				}
				if = {
					limit = {
						count_owned_pop_amount = {
							limit = { has_ethic = ethic_xenophobe }
							count > @dpe_pops_medium_cluster
						}
					}
					set_timed_carrier_flag = {
						flag = ccrebel_perf_xenophobes_2
						years = 2
					}
					if = {
						limit = {
							owner = {
								is_xenophile = yes
							}
						}
						set_timed_carrier_flag = {
							flag = cc_opposite_ethic_to_ruler
							years = 2
						}
					}
					if = {
						limit = {
							count_owned_pop_amount = {
								limit = { has_ethic = ethic_xenophobe }
								count > @dpe_pops_large_cluster
							}
						}
						set_timed_carrier_flag = {
							flag = ccrebel_perf_xenophobes_3
							years = 2
						}
					}
				}
			}
		}
	}
}
