EQS_remove_civil_war_ideas = {
	remove_ideas = eqs_civil_war
	hidden_effect = {
		remove_ideas = SOL_civil_war
		remove_ideas = communist_civil_war
		if = {
			limit = {
				EQS_princess_celestia = {
					is_country_leader = yes
					NOT = {
						OR = {
							has_trait = stout_defender
							has_character_flag = EQS_celestia_is_db
						}
					}
				}
			}
			EQS = {
				add_country_leader_trait = stout_defender
			}
		}
	}
}

EQS_create_new_commanders = {
	set_country_flag = EQS_create_new_commanders_flag

	custom_effect_tooltip = applejack_stats_tp

	custom_effect_tooltip = allen_spark_stats_tp

	custom_effect_tooltip = swift_wing_stats_tp

	custom_effect_tooltip = fireflight_stats_tp

	custom_effect_tooltip = anonfilly_stats_tp

	custom_effect_tooltip = sergeant_reckless_stats_tp

	custom_effect_tooltip = big_macintosh_stats_tp
	if = {
		limit = { NOT = { has_global_flag = EQS_Braeburn_created } }

		custom_effect_tooltip = braeburn_stats_tp
		set_global_flag = EQS_Braeburn_created
	}

	add_corps_commander_role = {
		character = EQS_sentinel

		desc = "ancap_trench_boi_desc"
		traits = { vigilant_sentinel inflexible_strategist pony_race_trait }
		skill = 3
		attack_skill = 2
		defense_skill = 3
		planning_skill = 3
		logistics_skill = 2
		legacy_id = 19
	}
	custom_effect_tooltip = thunderbolt_sentinel_stats_tp
	if = {
		limit = { NOT = { has_global_flag = EQS_pinkie_pie_created } }


		custom_effect_tooltip = pinkamena_diana_pie_stats_tp
		set_global_flag = EQS_pinkie_pie_created
	}
	add_corps_commander_role = {
		character = EQS_maudpie
		traits = { pony_race_trait rock_girl }
		skill = 3
		attack_skill = 1
		defense_skill = 4
		planning_skill = 1
		logistics_skill = 4
		legacy_id = 73241
		desc = "EQS_maudpie_desc"
	}
	custom_effect_tooltip = maud_pie_stats_tp

	custom_effect_tooltip = caltrop_deekay_stats_tp

	custom_effect_tooltip = sun_marble_stats_tp

	custom_effect_tooltip = orion_star_stats_tp

	custom_effect_tooltip = bernard_hoofgonery_stats_tp
	if = {
		limit = { NOT = { has_global_flag = EQS_Eisenstadt_created } }

		custom_effect_tooltip = august_von_eisenstadt_stats_tp
		set_global_flag = EQS_Eisenstadt_created
	}
	add_corps_commander_role = {
		character = EQS_fizzlepop
		traits = { fortress_buster pony_race_trait }
		skill = 3
		legacy_id = 12
		attack_skill = 4
		defense_skill = 2
		planning_skill = 3
		logistics_skill = 1
		desc = "EQS_tempy_desc"
	}
	custom_effect_tooltip = fizzlepop_berrytwist_stats_tp

	custom_effect_tooltip = sunrise_moonshadow_stats_tp
	if = {
		limit = {
			has_global_flag = celestia_and_luna_fused
			NOT = { has_global_flag = EQS_Tempest_Wind_created }
		}

		custom_effect_tooltip = tempest_wind_stats_tp
		set_global_flag = EQS_Tempest_Wind_created
	}
	if = {
		limit = {
			has_global_flag = celestia_and_luna_fused
			NOT = { has_global_flag = EQS_Selenite_created }
		}

		custom_effect_tooltip = selenite_stats_tp
		set_global_flag = EQS_Selenite_created
	}
	if = {
		limit = {
			has_global_flag = celestia_and_luna_fused
			NOT = { has_global_flag = EQS_Bipen_created }
		}

		custom_effect_tooltip = bipen_stats_tp
		set_global_flag = EQS_Bipen_created
	}
	if = {
		limit = {
			has_global_flag = celestia_and_luna_fused
			NOT = { has_global_flag = EQS_Midnight_Oil_created }
		}

		custom_effect_tooltip = midnight_oil_stats_tp
		set_global_flag = EQS_Midnight_Oil_created
	}
	if = {
		limit = {
			has_global_flag = celestia_and_luna_fused
			NOT = { has_global_flag = EQS_Oligarch_created }
		}

		custom_effect_tooltip = oli_equites_stats_tp
		set_global_flag = EQS_Oligarch_created
	}
}

EQS_SOL_remove_ideas = {
	remove_ideas = {
		harmonic_stagnation
		harmonic_stagnation2
		harmonic_stagnation3
		alicorn_sisters
		friendly_harmony
		home_of_ponies
		equestrian_communists
		war_communism
		celestial_resistance
		revolution_triumph
		collectivization_effort_eqs
		agrarian_reforms
		eqs_nationalization
		royal_family_imprisoned
		eqs_conscription_crisis
		eqs_defeatists
		popular_discontent
		democratic_protest
		lone_princess
		transitional_government
		charter_liberties
		charter_republic
		charter_commonwealth
		bastion_harmony
		arsenal_harmony
		EQS_cel_executive
		EQS_cel_figurehead
		species_rights_act
		new_harmonic_administration
		commoner_kingdom
		merchant_republic
		diet_commoners
		diet_nobles
		centralization
		maintain_autonomies
		grand_army
	}
}

#ROOT is EQS
EQS_SOL_wartime_change = {
	clr_country_flag = manpower_laws_blocked
	clr_country_flag = economic_laws_blocked
	if = {
		limit = { NOT = { has_completed_focus = Friendship_Games } }
		complete_national_focus = Friendship_Games
	}
	if = {
		limit = { NOT = { has_completed_focus = examine_the_situation } }
		complete_national_focus = examine_the_situation
	}
	if = {
		limit = { NOT = { has_completed_focus = Ministry_of_defense } }
		complete_national_focus = Ministry_of_defense
	}
	if = {
		limit = { NOT = { has_completed_focus = worrisome_changelings } }
		complete_national_focus = worrisome_changelings
	}
	if = {
		limit = {
			has_idea = alicorn_sisters
		}
		add_stability = -0.1
		remove_ideas = alicorn_sisters
	}

	set_global_flag = daybreaker_spawned
	set_country_flag = sol_wartime_change
	set_cosmetic_tag = EQS_SOL
	set_faction_name = SOL_faction

	#set_country_flag = SOL_new_generals_flag
	set_party_name = { ideology = democratic long_name = EQS_republic_long name = EQS_republic }
	save_global_event_target_as = solar_empire
	clear_global_event_target = equestria
	set_politics = { ruling_party = fascism }
	add_popularity = {
		ideology = fascism
		popularity = 0.10
	}
	hidden_effect = {
		EQS_princess_celestia = {
			set_character_name = EQS_SOL_daybreaker
			set_portraits = {
				civilian = {
					large = GFX_DaybreakerPortrait
				}
				army = {
					large = GFX_DaybreakerPortrait
					small = GFX_idea_EQS_SOL_daybreaker
				}
			}
			if = {
				limit = {
					has_game_rule = {
						rule = tbk_april_fool
						option = TBK_APRIL_FOOL
					}
				}
				set_character_name = TBK_AF_daybreaker
				set_portraits = {
					civilian = {
						large = "gfx/leaders/TBK_AF/doubtbreaker.tga"
					}
					army = {
						large = "gfx/leaders/TBK_AF/doubtbreaker.tga"
					}
				}
			}
			add_country_leader_role = {
				promote_leader = yes

				country_leader = {
					expire = "1965.1.1"
					desc = "POLITICS_DAYBREAKER_DESC"
					ideology = nazism
					traits = { }
					id = -1
				}
			}
			set_character_flag = EQS_celestia_is_db
		}
		add_opinion_modifier = {
			target = BAT
			modifier = mortal_enemies
		}
		reverse_add_opinion_modifier = {
			target = BAT
			modifier = mortal_enemies
		}
	}

	SOL = {
		set_politics = { ruling_party = democratic }
		save_global_event_target_as = equestria
	}
	clr_country_flag = nightmare_moon
	if = {
		limit = { EQS_princess_luna = { is_unit_leader = yes } }
		EQS_princess_luna = {
			remove_unit_leader_role = yes
			if = {
				limit = {
					is_high_command = yes
				}
				remove_advisor_role = {
					slot = high_command
				}
			}
			if = {
				limit = {
					is_army_chief = yes
				}
				remove_advisor_role = {
					slot = army_chief
				}
			}
			#using a flag doesnt seem to work
			set_character_flag = EQS_luna_leader_disabled
			promote_character = alicornrule
		}
		set_country_flag = EQS_had_luna
	}
	if = {
		limit = { EQS_NLR_tempest_wind = { is_unit_leader = yes } }
		EQS_NLR_tempest_wind = { set_nationality = SOL }
	}
	if = {
		limit = { EQS_NLR_bipen = { is_unit_leader = yes } }
		EQS_NLR_bipen = { set_nationality = SOL }
	}
	if = {
		limit = { EQS_NLR_midnight_oil = { is_unit_leader = yes } }
		EQS_NLR_midnight_oil = { set_nationality = SOL }
	}
	every_country = {
		limit = { original_tag = CRY is_subject_of = EQS }
		set_country_flag = is_sol_puppet
	}
	country_event = { id = solarempire.17 days = 4 }
	if = {
		limit = { has_war_with = NLR }
		every_other_country = {
			limit = {
				OR = {
					is_subject_of = ROOT
					AND = { is_in_faction_with = ROOT is_subject = no }
				}
			}
			if = {
				limit = { is_subject = yes is_ai = no }
				set_rule = { can_decline_call_to_war = yes }
			}
			country_event = { id = solarempire.14 hours = 1 }
		}
	}
	else = {
		set_province_name = { id = 6023 name = EQS_SOL_invicta_vp }
	}
	if = {
		limit = { surrender_progress > 0.4 }
		set_country_flag = remove_db_70_days
	}
	EQS_SOL_remove_ideas = yes
	country_event = { id = solarempire.1018 }
	if = {
		limit = { country_exists = CES }
		CES = {
			country_event = {
				id = daring.20
			}
		}
		#CES = { load_focus_tree = celestial_state_civil_war_focus }
	}
	if = {
		limit = {
			BUF = {
				is_ai = yes
				is_subject_of = ROOT
			}
		}
		annex_country = {
			target = BUF transfer_troops = yes
		}
	}
	#EQS_SOL_show_advisors = yes
	country_event = { id = solarempire.2 days = 2 }
	news_event = { id = news.sol.4 hours = 6 }
}

#ROOT is EQS
EQS_SOL_civil_war = {
	set_global_flag = daybreaker_spawned
	set_global_flag = equestrian_civil_war_daybreaker
	clr_country_flag = nightmare_moon
	clr_country_flag = manpower_laws_blocked
	clr_country_flag = economic_laws_blocked
	if = {
		limit = { NOT = { has_completed_focus = Friendship_Games } }
		complete_national_focus = Friendship_Games
	}
	if = {
		limit = { NOT = { has_completed_focus = examine_the_situation } }
		complete_national_focus = examine_the_situation
	}
	if = {
		limit = { NOT = { has_completed_focus = Ministry_of_defense } }
		complete_national_focus = Ministry_of_defense
	}
	if = {
		limit = { NOT = { has_completed_focus = worrisome_changelings } }
		complete_national_focus = worrisome_changelings
	}
	every_country = {
		limit = { exists = yes is_guaranteed_by = EQS }
		EQS = { diplomatic_relation = { country = PREV relation = guarantee active = no } }
	}
	if = {
		limit = { has_idea = alicorn_sisters }
		set_country_flag = luna_alive
	}
	every_other_country = {
		limit = {
			OR = {
				is_subject_of = ROOT
				AND = { is_in_faction_with = ROOT is_subject = no }
			}
		}
		if = {
			limit = { is_subject = yes is_ai = no }
			set_rule = { can_decline_call_to_war = yes }
		}
		country_event = { id = solarempire.6 hours = 1 }
	}
	if = {
		limit = {
			NOT = { has_idea = alicorn_sisters }
		}
		add_popularity = {
			ideology = fascism
			popularity = 0.10
		}
	}
	set_cosmetic_tag = EQS_SOL
	set_temp_variable = { var = civil_war_size value = 1 }
	subtract_from_temp_variable = { var = civil_war_size value = party_popularity@fascism }
	set_party_name = { ideology = democratic long_name = EQS_republic_long name = EQS_republic }
	divide_temp_variable = { var = civil_war_size value = 2.5 }
	add_to_temp_variable = { var = civil_war_size value = 0.04 }
	start_civil_war = {
		ruling_party = fascism
		ideology = democratic
		size = civil_war_size
		capital = 75
	}
	set_politics = { ruling_party = fascism }
	if = {
		limit = { is_faction_leader = no }
		create_faction_from_template = faction_template_EQS_SOL_faction
	}
	else = {
		set_faction_name = SOL_faction
	}
	save_global_event_target_as = solar_empire
	clear_global_event_target = equestria
	add_ideas = SOL_civil_war
	add_ideas = SOL_harmonic_resistance_idea
	add_stability = -0.1
	country_event = { id = solarempire.1018 }
	country_event = { id = solarempire.17 days = 4 }
	news_event = { id = news.sol.1 hours = 6 }
	random_other_country = {
		limit = {
			original_tag = EQS
			has_government = democratic
		}
		save_global_event_target_as = equestria
		#load_focus_tree = { tree = equestria_focus keep_completed = yes }
		set_capital = { state = 75 remember_old_capital = no }
		add_political_power = 450
		set_party_name = { ideology = fascism long_name = EQS_fascism_generic_party_long name = EQS_fascism_generic_party }
		add_stability = -0.3
		set_cosmetic_tag = EQS_DEM
		if = {
			limit = {
				ROOT = { has_country_flag = luna_alive }
			}
			clr_country_flag = luna_alive
			every_possible_country = {
				limit = {
					has_character = EQS_princess_luna
				}
				EQS_princess_luna = {
					set_nationality = PREV.PREV
				}
			}
			EQS_princess_luna = {
				promote_character = alicornrule
			}
			set_country_flag = EQD_dem_luna
			add_stability = -0.1
			remove_ideas = alicorn_sisters
			ROOT = {
				add_stability = -0.1
			}
		}
		else = {
			set_country_flag = EQS_force_republic
			complete_national_focus = eqs_come_to_compromise
			complete_national_focus = eqs_allow_the_vote
			set_country_flag = congress_president
			set_cosmetic_tag = EQS_DEM1
			set_party_name = { ideology = democratic long_name = EQS_republic_long name = EQS_republic }
			country_event = { hours = 24 id = equestriadem.1 }
			remove_ideas = alicorn_sisters
		}
		add_ideas = SOL_civil_war
		set_country_flag = { flag = celestia_evil_meter value = 0 }
		every_character = {
			limit = {
				OR = {
					is_character = EQS_princess_celestia
					is_character = EQS_prince_blueblood
					is_character = EQS_SOL_august_fon_eisenstadt
					is_character = EQS_SOL_comet_trail
				}
			}
			set_nationality = event_target:solar_empire
		}
	}
	every_character = {
		limit = {
			OR = {
				is_character = EQS_applejack
				is_character = EQS_sergeant_reckless
				is_character = EQS_big_macintosh
				# is_character = 8
				is_character = EQS_pinkie_pie
				is_character = EQS_caltrop_decay
				is_character = EQS_braeburn
				is_character = EQS_NLR_tempest_wind
				is_character = EQS_NLR_midnight_oil
				is_character = EQS_oli_equites
				is_character = EQS_NLR_bipen
			}
		}
		set_nationality = event_target:equestria
	}
	hidden_effect = {
		EQS_princess_celestia = {
			set_character_name = EQS_SOL_daybreaker
			set_portraits = {
				civilian = {
					large = GFX_DaybreakerPortrait
				}
				army = {
					large = GFX_DaybreakerPortrait
                    small = GFX_idea_EQS_SOL_daybreaker
				}
			}
			if = {
				limit = {
					has_game_rule = {
						rule = tbk_april_fool
						option = TBK_APRIL_FOOL
					}
				}
				set_character_name = TBK_AF_daybreaker
				set_portraits = {
					civilian = {
						large = "gfx/leaders/TBK_AF/doubtbreaker.tga"
					}
					army = {
						large = "gfx/leaders/TBK_AF/doubtbreaker.tga"
					}
				}
			}
			add_country_leader_role = {
				promote_leader = yes

				country_leader = {
					expire = "1965.1.1"
					desc = "POLITICS_DAYBREAKER_DESC"
					ideology = nazism
					traits = { }
					id = -1
				}
			}

			set_character_flag = EQS_celestia_is_db
		}
		add_opinion_modifier = {
			target = BAT
			modifier = mortal_enemies
		}
		reverse_add_opinion_modifier = {
			target = BAT
			modifier = mortal_enemies
		}
	}
	EQS_SOL_remove_ideas = yes
	if = {
		limit = { country_exists = CES }
		CES = {
			country_event = {
				id = daring.20
			}
		}
		
		#CES = { load_focus_tree = celestial_state_civil_war_focus }
	}
	#EQS_SOL_show_advisors = yes
}

#ROOT is EQS
EQS_NLR_civil_war = {
	set_global_flag = equestrian_civil_war
	#random_list = { 50 = { set_country_flag = SCS_gonna_appear } 50 = { }}
	news_event = { hours = 6 id = news.200 }
	country_event = { id = equestria.229 days = 10 }
	STG = {
		country_event = { id = stalliongrad.5 days = 2 }
	}
	every_other_country = {
		limit = { exists = yes is_guaranteed_by = ROOT }
		ROOT = { diplomatic_relation = { country = PREV relation = guarantee active = no } }
	}
	every_other_country = {
		limit = {
			OR = {
				is_subject_of = ROOT
				AND = { is_in_faction_with = ROOT is_subject = no }
			}
			NOT = {
				original_tag = NLR
			}
		}
		if = {
			limit = { is_subject = yes is_ai = no }
			set_rule = { can_decline_call_to_war = yes }
		}
		country_event = { id = solarempire.5 hours = 1 }
	}
	every_possible_country = {
		limit = {
			has_character = EQS_princess_luna
		}
		EQS_princess_luna = {
			retire = yes
		}
	}
	set_stability = 0.6
	add_popularity = {
		ideology = democratic
		popularity = 0.10
	}
	add_popularity = {
		ideology = communism
		popularity = 0.08
	}
	#GRF = {
	#	transfer_state = 241
	#}
	every_state = {
		limit = {
			OR = {
				state = 5
				state = 1
				state = 39
				state = 75
				state = 12
				state = 28
				state = 110
				state = 13
				state = 15
				state = 106
				state = 16
				state = 525
				state = 29
				state = 109
				state = 226
				state = 187
				state = 157
				state = 160
				state = 351
				state = 107
				state = 24
				state = 33
				state = 32
				state = 50
				state = 167
				state = 184
				state = 228
				state = 82
				state = 40
				state = 108
				state = 67
				state = 653
				state = 229
				state = 662
				state = 352
				state = 156
				state = 122
				state = 116
				state = 162
				state = 159
				state = 183
				state = 326
				state = 34
				state = 88
				state = 102
				state = 164
				state = 26
				state = 111
				state = 63
				state = 188
				state = 185
				state = 661
				state = 113
				state = 90
				state = 81
				state = 231
				state = 349
				state = 97
				state = 84
				state = 223
				state = 177
				state = 115
				state = 120
				state = 158
				state = 348
				state = 25
				state = 186
				state = 232
				state = 112
				state = 65
				state = 86
				state = 227
				state = 52
				state = 79
				state = 36
				state = 230
				state = 182
				state = 155
				state = 27
				state = 35
				state = 154
				state = 327
				state = 31
				state = 83
				state = 353
				state = 350
				state = 221
				state = 30
				state = 17
				state = 37
			}
		}
		add_core_of = NLR
	}

	every_state = {
		limit = {
			NOT = { is_core_of = NLR }
			OR = {
				is_core_of = EQS
				is_claimed_by = EQS
			}
		}
		add_claim_by = NLR
	}

	every_owned_state = {
		limit = {
			is_controlled_by = PREV
			OR = {
				state = 5
				state = 1
				state = 39
				state = 75
				state = 12
				state = 28
				state = 110
				state = 13
				state = 15
				state = 106
				state = 16
				state = 525
				state = 29
				state = 109
				state = 226
				state = 187
				state = 157
				state = 160
				state = 351
				state = 107
				state = 24
				state = 33
				state = 32
				state = 50
				state = 167
				state = 184
				state = 228
				state = 82
				state = 40
				state = 108
				state = 67
				state = 653
				state = 229
				state = 662
				state = 352
				state = 156
				state = 122
				state = 116
				state = 162
				state = 159
				state = 183
				state = 326
				state = 34
				state = 88
				state = 102
				state = 164
				state = 26
				state = 111
				state = 63
				state = 188
				state = 185
				state = 661
				state = 113
				state = 90
				state = 81
				state = 231
				state = 349
				state = 97
				state = 84
				state = 223
				state = 177
				state = 115
				state = 120
				state = 158
				state = 348
				state = 25
				state = 186
				state = 232
				state = 112
				state = 65
				state = 86
				state = 227
				state = 52
				state = 79
				state = 36
				state = 230
				state = 182
				state = 155
				state = 27
				state = 35
				state = 154
				state = 327
				state = 31
				state = 83
				state = 353
				state = 350
				state = 221
				state = 30
				state = 17
				state = 37
			}
		}
		NLR = { transfer_state = PREV }
	}

	#set_variable = { civil_war_size = 0.3 }

	#Modify civil war size by NMM's agressiveness
	#if = {
	#	limit = {
	#		check_variable = {
	#			var = NMM_aggressive
	#			value = 3
	#			compare = greater_than_or_equals
	#		}
	#	}
	#	set_variable = { civil_war_size = 0.70 }
	#}
	#else_if = {
	#	limit = {
	#		check_variable = {
	#			var = NMM_aggressive
	#			value = 2
	#			compare = equals
	#		}
	#	}
	#	set_variable = { civil_war_size = 0.60 }
	#}
	#else_if = {
	#	limit = {
	#		check_variable = {
	#			var = NMM_aggressive
	#			value = 1
	#			compare = equals
	#		}
	#	}
	#	set_variable = { civil_war_size = 0.50 }
	#}
	#else = {
	#	set_variable = { civil_war_size = 0.30 }
	#}
	#if = { #Tiny size if early discovery
	#	limit = { has_country_flag = nlr_early_discovery }
	#	set_variable = { civil_war_size = 0.20 }
	#}
	#transfer_units_fraction = {
	#	target = NLR
	#   #army_ratio = 0.001
	#	air_ratio = 0.3
	#	navy_ratio = 0.3
	#	stockpile_ratio = 0.3
	#	keep_unit_leaders_trigger = { always = yes }
	#}
	#log = "EQS NLR civil war size: [?civil_war_size]"
	#clear_variable = civil_war_size
	if = {
		limit = {
			EQS_chancellor_neighsay = {
				can_be_country_leader = yes
			}
		}
		EQS_chancellor_neighsay = {
			promote_character = falangism
		}
	}
	else = {
		add_country_leader_role = {
			character = EQS_chancellor_neighsay
			promote_leader = yes

			country_leader = {
				desc="CHANCELLOR_NEIGHSAY_DESC"
				ideology=falangism
				expire="1965.1.1.1"
			}
		}
	}
	remove_ideas = alicorn_sisters
	add_ideas = eqs_civil_war
	40 = {
		add_building_construction = {
			type = air_base
			level = 1
			instant_build = yes
		}
	}
	NLR = {
		every_controlled_state = {
			teleport_armies = {
				limit = { tag = EQS }
				#to_state_array = EQS.controlled_states
			}
		}
	}
	EQS = {
		transfer_ship = {
    		type = battleship
    		target = NLR
		}
		transfer_ship = {
    		type = battleship
    		target = NLR
		}
		transfer_ship = {
    		type = battle_cruiser
    		target = NLR
		}
		transfer_ship = {
    		type = battle_cruiser
    		target = NLR
		}
		transfer_ship = {
    		type = light_cruiser
    		target = NLR
		}
		transfer_ship = {
   			type = destroyer
   	 		target = NLR
		}
		transfer_ship = {
	    	type = destroyer
	    	target = NLR
		}
		transfer_ship = {
   			type = destroyer
   			target = NLR
		}
		transfer_ship = {
			type = destroyer
			target = NLR
		}
		transfer_ship = {
   			type = destroyer
   			target = NLR
		}
		transfer_ship = {
			type = destroyer
			target = NLR
		}
		transfer_ship = {
   			type = destroyer
   			target = NLR
		}
		transfer_ship = {
	    	type = destroyer
	    	target = NLR
		}
		transfer_ship = {
   			type = destroyer
   	 		target = NLR
		}
		transfer_ship = {
	    	type = destroyer
	    	target = NLR
		}
		add_equipment_to_stockpile = {
			type = train_equipment_1
			amount = -50
		}
	}


	EQS = {
		if = {
			limit = {
				check_variable = { NMM_partisans = 3 }
			}
			add_timed_idea = { idea = EQS_moonshine_partisans_3 days = 180 }
		}
		else_if = {
			limit = {
				check_variable = { NMM_partisans = 2 }
			}
		    add_timed_idea = { idea = EQS_moonshine_partisans_2 days = 180 }
		}
		else_if = {
			limit = {
				check_variable = { NMM_partisans = 1 }
			}
			add_timed_idea = { idea = EQS_moonshine_partisans_1 days = 180 }
		}
		else = {
			add_timed_idea = { idea = EQS_moonshine_partisans_0 days = 180 }
		}
	}
	if = {
		limit = {
			BAT = {
				has_country_flag = BAT_infiltrated_urban_centers
			}
		}
		EQS = {
			add_timed_idea = {
				idea = BAT_infiltrate_urban_centers_idea
				days = 180
			}
		}
    }
	if = {
		limit = {
			BAT = {
				has_country_flag = BAT_academia_infiltration
			}
		}
		EQS = {
			add_timed_idea = {
			    idea = BAT_academic_infiltration_idea
				days = 180
			}
		}
	}
	if = {
		limit = {
			BAT = {
				has_country_flag = BAT_terror_bombs
			}
		}
		EQS = {
			add_ideas = BAT_terror_bombing_idea
		}
	}
	load_oob = "EQS_Civil_War"
	set_global_flag = { flag = ECW_block_SCS days = 240 }
	EQS = {
		if = {
			limit = {
				has_global_flag = EQS_Bipen_created
			}
			if = {
				limit = { NOT = { has_character = EQS_NLR_bipen } }
				every_possible_country = {
					limit = {
						has_character = EQS_NLR_bipen
					}
					EQS_NLR_bipen = {
						set_nationality = NLR
					}
				}
			}
		}
		else = {
			custom_effect_tooltip = bipen_stats_tp
			set_global_flag = EQS_Bipen_created
			EQS_NLR_bipen = { set_nationality =  NLR }
		}
		if = {
			limit = {
				has_global_flag = EQS_Selenite_created
			}
			if = {
				limit = { NOT = { has_character = EQS_NLR_celenite } }
				every_possible_country = {
					limit = {
						has_character = EQS_NLR_celenite
					}
					EQS_NLR_celenite = {
						set_nationality = NLR
					}
				}
			}
		}
		else = {
			custom_effect_tooltip = selenite_stats_tp
			set_global_flag = EQS_Selenite_created
			EQS_NLR_celenite = { set_nationality = NLR }
		}
		if = {
			limit = {
				has_global_flag = EQS_Tempest_Wind_created
			}
			if = {
				limit = { NOT = { has_character = EQS_NLR_tempest_wind }}
				every_possible_country = {
					limit = {
						has_character = EQS_NLR_tempest_wind
					}
					EQS_NLR_tempest_wind = {
						set_nationality = NLR
					}
				}
			}
		}
		else = {
			custom_effect_tooltip = tempest_wind_stats_tp
			set_global_flag = EQS_Tempest_Wind_created
			EQS_NLR_tempest_wind = { set_nationality = NLR }
		}
		if = {
			limit = {
				has_global_flag = EQS_Midnight_Oil_created
			}
			if = {
				limit = { NOT = { has_character = EQS_NLR_midnight_oil } }
				every_possible_country = {
					limit = {
						has_character = EQS_NLR_midnight_oil
					}
					EQS_NLR_midnight_oil = {
						set_nationality = NLR
					}
				}
			}
		}
		else = {
			custom_effect_tooltip = midnight_oil_stats_tp_1
			set_global_flag = EQS_Midnight_Oil_created
			EQS_NLR_midnight_oil = { set_nationality = NLR }
		}
		if = {
			limit = {
				has_global_flag = EQS_Selenite_created
			}
			if = {
				limit = { NOT = { has_character = EQS_NLR_celenite } }
				every_possible_country = {
					limit = {
						has_character = EQS_NLR_celenite
					}
					EQS_NLR_celenite = {
						set_nationality = NLR
					}
				}
			}
		}
		else = {
			custom_effect_tooltip = selenite_stats_tp
			set_global_flag = EQS_Selenite_created
			EQS_NLR_celenite = { set_nationality = NLR }
		}
	}
	NLR = {
		if = {
			limit = { is_ai = yes }
			Evil_unicorn_magic = yes
		}
		if = {
			limit = {
				NOT = {
					has_game_rule = {
						rule = equestria_united_status
						option = EQS_STATUS_CIVIL_WAR
					}
				}
			}
			country_event = { id = lunas.2 days = 7 }#days to hours applied
		}
		country_event = civwar.110
		country_event = { id = equestria.229 days = 10 } #rarity captured
		set_country_flag = recovery_idea_bypass
		set_stability = 0.7
		add_popularity = {
			ideology = fascism
			popularity = 0.1
		}
		load_oob = "NLR_Civil_War"
		if = {
			limit = { has_dlc = "By Blood Alone" }
			load_oob = "NLR_Civil_War_air_bba"

			else = {
				load_oob = "NLR_Civil_War_air_legacy"
			}
		}
		add_ideas = eqs_civil_war
		if = {
			limit = { country_exists = EQS }
			hidden_effect = {
				create_wargoal = {
					type = civil_war
					target = EQS
				}
			}
			declare_war_on = {
				target = EQS type = civil_war
			}
			add_civil_war_target = EQS
		}
		clr_country_flag = recovery_idea_bypass
		add_ideas = NLR_fragile_rule_1
		### Moonshine national spirits ###
		country_event = { id = lunas.1 days = 1 }
		if = {
			limit = {
				EQS = { check_variable = { NMM_weaponstealers = 3 } }
			}
			add_timed_idea = { idea = NLR_moonshine_weaponstealers_3 days = 180 }
		}
		else_if = {
			limit = {
				EQS = { check_variable = { NMM_weaponstealers = 2 } }
			}
			add_timed_idea = { idea = NLR_moonshine_weaponstealers_2 days = 180 }
		}
		else_if = {
			limit = {
				EQS = { check_variable = { NMM_weaponstealers = 1 } }
			}
			add_timed_idea = { idea = NLR_moonshine_weaponstealers_1 days = 180 }
		}
		else = {
			add_timed_idea = { idea = NLR_moonshine_weaponstealers_0 days = 180 }
		}
		if = {
			limit = {
				EQS = { check_variable = { NMM_workers = 3 } }
			}
			add_timed_idea = { idea = NLR_moonshine_workers_3 days = 180 }
		}
		else_if = {
			limit = {
				EQS = { check_variable = { NMM_workers = 2 } }
			}
			add_timed_idea = { idea = NLR_moonshine_workers_2 days = 180 }
		}
		else_if = {
			limit = {
				EQS = { check_variable = { NMM_workers = 1 } }
			}
			add_timed_idea = { idea = NLR_moonshine_workers_1 days = 180 }
		}
		else = {
			add_timed_idea = { idea = NLR_moonshine_workers_0 days = 180 }
		}
		if = {
			limit = {
				EQS = { check_variable = { NMM_bats = 3 } }
			}
			add_timed_idea = { idea = NLR_moonshine_bats_3 days = 180 }
		}
		else_if = {
			limit = {
				EQS = { check_variable = { NMM_bats = 2 } }
			}
			add_timed_idea = { idea = NLR_moonshine_bats_2 days = 180 }
		}
		else_if = {
			limit = {
				EQS = { check_variable = { NMM_bats = 1 } }
			}
			add_timed_idea = { idea = NLR_moonshine_bats_1 days = 180 }
		}
		else = {
			add_timed_idea = { idea = NLR_moonshine_bats_0 days = 180 }
		}
		create_faction_from_template = faction_template_NLR_lunar_hegemony
		if = {
		    limit = {
			   	BAT = {
				    has_country_flag = BAT_supplies
				}
			}
			NLR = {
				add_ideas = BAT_focus_on_supplies_idea
			}
		}
		if = {
		    limit = {
			    BAT = {
				    has_country_flag = BAT_weapons
				}
			}
			NLR = {
				add_ideas = BAT_focus_on_weaponry_idea
			}
		}
		if = {
		   	limit = {
		    	BAT = {
			    	has_country_flag = BAT_send_resources
				}
			}
			NLR = {
				add_offsite_building = {
		           	type = arms_factory
		           	level = 3
				}
			}
		}
		if = {
	    	limit = {
		   	    BAT = {
			    	has_country_flag = BAT_sent_officers
				}
			}
			NLR = {
				every_unit_leader = {
			       	add_logistics = 1
				   	add_planning = 1
                   	add_defense = 1
				   	add_attack = 1
			    }
			}
		}
	}
	BAT = {
		country_event = {
			id = bat.15
		}
	}
}

add_to_war_EQS_against_SOL = {
	#SOL is EQS
	event_target:equestria = {
		ROOT = {
			add_to_war = { targeted_alliance = PREV enemy = EQS }
		}
	}
}

add_to_war_SOL_against_EQS = {
	#SOL is EQS
	event_target:equestria = {
		ROOT = {
			add_to_war = { enemy = PREV targeted_alliance = EQS }
		}
	}
}

add_to_war_EQS_against_NLR = {
	event_target:equestria = {
		ROOT = {
			add_to_war = { enemy = NLR targeted_alliance = PREV }
		}
	}
}

add_to_war_NLR_against_EQS = {
	event_target:equestria = {
		ROOT = {
			add_to_war = { enemy = PREV targeted_alliance = NLR }
		}
	}
}

spawn_GRF_volunteers = {
	if = {
		limit = { NOT = { has_country_flag = has_GRF_volunteers } }
		division_template = {
			name = "Free Griffon Division"
			is_locked = yes
			priority = 0
			regiments = {
				infantry = { x = 0 y = 0 }
				infantry = { x = 0 y = 1 }
				infantry = { x = 0 y = 2 }
				infantry = { x = 0 y = 3 }
				infantry = { x = 1 y = 0 }
				infantry = { x = 1 y = 1 }
				infantry = { x = 1 y = 2 }
				infantry = { x = 1 y = 3 }
			}
		}
		if = {
			limit = {
				capital_scope = {
					is_fully_controlled_by = PREV
				}
			}
			capital_scope = {
				create_unit = {
					division = "name = \"Weter's Own Volunteer Regiment\" division_template = \"Free Griffon Division\" start_experience_factor = 0.4 start_equipment_factor = 1"
					owner = PREV
				}
				create_unit = {
					division = "name = \"Mystic Warriors\" division_template = \"Free Griffon Division\" start_experience_factor = 0.4 start_equipment_factor = 1"
					owner = PREV
				}
				create_unit = {
					division = "name = \"Fetermyst Guard\" division_template = \"Free Griffon Division\" start_experience_factor = 0.4 start_equipment_factor = 1"
					owner = PREV
				}
			}
		}
		else_if = {
			limit = {
				any_owned_state = {
					is_fully_controlled_by = PREV
					is_coastal = yes
				}
			}
			random_owned_controlled_state = {
				limit = {
					is_fully_controlled_by = PREV
					is_coastal = yes
				}
				create_unit = {
					division = "name = \"Weter's Own Volunteer Regiment\" division_template = \"Free Griffon Division\" start_experience_factor = 0.4 start_equipment_factor = 1"
					owner = PREV
				}
				create_unit = {
					division = "name = \"Mystic Warriors\" division_template = \"Free Griffon Division\" start_experience_factor = 0.4 start_equipment_factor = 1"
					owner = PREV
				}
				create_unit = {
					division = "name = \"Fetermyst Guard\" division_template = \"Free Griffon Division\" start_experience_factor = 0.4 start_equipment_factor = 1"
					owner = PREV
				}
			}
		}
		else = {
			random_owned_controlled_state = {
				limit = {
					is_fully_controlled_by = PREV
				}
				create_unit = {
					division = "name = \"Weter's Own Volunteer Regiment\" division_template = \"Free Griffon Division\" start_experience_factor = 0.4 start_equipment_factor = 1"
					owner = PREV
				}
				create_unit = {
					division = "name = \"Mystic Warriors\" division_template = \"Free Griffon Division\" start_experience_factor = 0.4 start_equipment_factor = 1"
					owner = PREV
				}
				create_unit = {
					division = "name = \"Fetermyst Guard\" division_template = \"Free Griffon Division\" start_experience_factor = 0.4 start_equipment_factor = 1"
					owner = PREV
				}
			}
		}
	}
	set_country_flag = has_GRF_volunteers
}
EQS_add_glostor_gladiator_template = {
	create_equipment_variant = {
		name = "Gloster Gladiator"
		type = small_plane_airframe_0
		design_team = mio:EQS_wonderbolt_concern_organization
		modules = {
				fixed_main_weapon_slot = light_mg_4x
				engine_type_slot = radial_engine_1_1x
				special_type_slot_1 = non_strategic_materials_small
				special_type_slot_7 = normally_aspirated_engine
				special_type_slot_8 = canopy0
		}
		icon = "GFX_ENG_early_fighter_medium"
	}
}
EQS_add_glostor_sea_gladiator_template = {
	create_equipment_variant = {
		name = "Gloster Sea Gladiator"
		type = cv_small_plane_airframe_0
		modules = {
				fixed_main_weapon_slot = light_mg_4x
				engine_type_slot = radial_engine_1_1x
				special_type_slot_1 = NACA_cowling
				special_type_slot_2 = non_strategic_materials_small
				special_type_slot_7 = normally_aspirated_engine
				special_type_slot_8 = canopy1
		}
		icon = "GFX_ENG_early_fighter_medium"
	}
}
EQS_add_hawker_hurricane_template = {
	create_equipment_variant = {
		name = "Hawker Hurricane"
		type = small_plane_airframe_1
		design_team = mio:EQS_wonderbolt_concern_organization
		modules = {
				fixed_main_weapon_slot = light_mg_4x
				fixed_auxiliary_weapon_slot_1 = light_mg_4x
				engine_type_slot = engine_2_1x
				special_type_slot_1 = empty
				special_type_slot_2 = non_strategic_materials_small
				special_type_slot_7 = normally_aspirated_engine
				special_type_slot_8 = canopy1
		}
		icon = "GFX_ENG_fighter1_medium"
	}
}
EQS_add_hawker_sea_hurricane_template = {
	create_equipment_variant = {
		name = "Hawker Hurricane"
		type = cv_small_plane_airframe_1
		modules = {
				fixed_main_weapon_slot = light_mg_4x
				fixed_auxiliary_weapon_slot_1 = light_mg_4x
				engine_type_slot = engine_2_1x
				special_type_slot_1 = empty
				special_type_slot_2 = non_strategic_materials_small
				special_type_slot_7 = normally_aspirated_engine
				special_type_slot_8 = canopy1
		}
		icon = "GFX_ENG_fighter1_medium"
	}
}
EQS_add_blackburn_skua_template = {
	create_equipment_variant = {
		name = "Blackburn Skua"
		type = cv_small_plane_cas_airframe_1
		design_team = mio:EQS_stratus_organization
		modules = {
				fixed_main_weapon_slot = torpedo_mounting
				engine_type_slot = radial_engine_1_1x
				fixed_auxiliary_weapon_slot_6 = lmg_defense_turret
				special_type_slot_1 = non_strategic_materials_small
				special_type_slot_7 = normally_aspirated_engine
				special_type_slot_8 = canopy0
		}
		icon = "GFX_ENG_CAS1_medium"
	}
}
EQS_add_supermarine_spitfire_template = {
	create_equipment_variant = {
		name = "Supermarine Spitfire"
		type = small_plane_airframe_2
		design_team = mio:EQS_wonderbolt_concern_organization
		modules = {
				fixed_main_weapon_slot = aircraft_cannon_1_2x
				fixed_auxiliary_weapon_slot_1 = light_mg_4x
				fixed_auxiliary_weapon_slot_2 = empty
				fixed_auxiliary_weapon_slot_3 = empty
				fixed_auxiliary_weapon_slot_4 = reflex_gunsight_2	
				engine_type_slot = engine_2_1x
				special_type_slot_1 = drop_tanks
				special_type_slot_2 = pressurized_cockpit
				special_type_slot_3 = water_injection_small
				special_type_slot_4 = armor_plate_small
				special_type_slot_5 = self_sealing_fuel_tanks_small	
				special_type_slot_6 = empty
				special_type_slot_7 = supercharger
				special_type_slot_8 = canopy2	
		}
		icon = "GFX_ENG_fighter2_medium"
	}
}
EQS_add_supermarine_seafire_template = {
	create_equipment_variant = {
		name = "Supermarine Seafire"
		type = cv_small_plane_airframe_2
		design_team = mio:EQS_ultramarine_organization
		modules = {
				fixed_main_weapon_slot = aircraft_cannon_1_2x
				fixed_auxiliary_weapon_slot_1 = light_mg_4x
				fixed_auxiliary_weapon_slot_2 = empty
				fixed_auxiliary_weapon_slot_3 = empty
				fixed_auxiliary_weapon_slot_4 = reflex_gunsight_2	
				engine_type_slot = engine_2_1x
				special_type_slot_1 = drop_tanks
				special_type_slot_2 = pressurized_cockpit
				special_type_slot_3 = water_injection_small
				special_type_slot_4 = armor_plate_small
				special_type_slot_5 = self_sealing_fuel_tanks_small	
				special_type_slot_6 = empty
				special_type_slot_7 = supercharger
				special_type_slot_8 = canopy2	
		}
		icon = "GFX_ENG_fighter2_medium"
	}
}
EQS_add_hawker_typhoon_template = {
	create_equipment_variant = {
		name = "Hawker Typhoon"
		type = small_plane_cas_airframe_2
		design_team = mio:EQS_stratus_organization
		modules = {
				fixed_main_weapon_slot = tank_buster_1
				fixed_auxiliary_weapon_slot_1 = rocket_rails
				fixed_auxiliary_weapon_slot_2 = rocket_rails
				fixed_auxiliary_weapon_slot_3 = rocket_rails			
				engine_type_slot = engine_3_1x
				special_type_slot_1 = armor_plate_small
				special_type_slot_2 = self_sealing_fuel_tanks_small
				special_type_slot_3 = empty
				special_type_slot_4 = aerodynamic_pylons_small
				special_type_slot_5 = aerodynamic_pylons_small
				special_type_slot_6 = empty
				special_type_slot_7 = supercharger
				special_type_slot_8 = canopy1
		}
		icon = "GFX_ENG_CAS2_medium"
	}
}
EQS_add_hawker_tempest_template = {
	create_equipment_variant = {
		name = "Hawker Tempest"
		type = small_plane_cas_airframe_3
		design_team = mio:EQS_stratus_organization
		modules = {
				fixed_main_weapon_slot = aircraft_cannon_2_2x
				fixed_auxiliary_weapon_slot_1 = aircraft_cannon_2_2x
				fixed_auxiliary_weapon_slot_2 = empty
				fixed_auxiliary_weapon_slot_3 = empty
				fixed_auxiliary_weapon_slot_4 = reflex_gunsight_2	
				engine_type_slot = engine_4_1x
				special_type_slot_1 = drop_tanks
				special_type_slot_2 = pressurized_cockpit
				special_type_slot_3 = water_injection_small
				special_type_slot_4 = armor_plate_small
				special_type_slot_5 = self_sealing_fuel_tanks_small	
				special_type_slot_6 = empty
				special_type_slot_7 = supercharger
				special_type_slot_8 = canopy2	
		}
		icon = "GFX_ENG_CAS3_medium"
	}
}
EQS_add_supermarine_spiteful_template = {
	create_equipment_variant = {
		name = "Supermarine Spiteful"
		type = small_plane_airframe_3
		design_team = mio:EQS_wonderbolt_concern_organization
		modules = {
				fixed_main_weapon_slot = aircraft_cannon_2_2x
				fixed_auxiliary_weapon_slot_1 = aircraft_cannon_2_2x
				fixed_auxiliary_weapon_slot_2 = empty
				fixed_auxiliary_weapon_slot_3 = rocket_rails
				fixed_auxiliary_weapon_slot_4 = reflex_gunsight_2	
				engine_type_slot = engine_4_1x
				special_type_slot_1 = drop_tanks
				special_type_slot_2 = pressurized_cockpit
				special_type_slot_3 = water_injection_small
				special_type_slot_4 = armor_plate_small
				special_type_slot_5 = self_sealing_fuel_tanks_small	
				special_type_slot_6 = empty
				special_type_slot_7 = supercharger
				special_type_slot_8 = canopy2	
		}
		icon = "GFX_ENG_fighter3_medium"
	}
}
EQS_add_gloster_meteor_template = {
	create_equipment_variant = {
		name = "Gloster Meteor"
		type = small_plane_airframe_4
		design_team = mio:EQS_wonderbolt_concern_organization
		modules = {
				fixed_main_weapon_slot = aircraft_cannon_2_2x
				fixed_auxiliary_weapon_slot_1 = aircraft_cannon_2_2x
				fixed_auxiliary_weapon_slot_2 = empty
				fixed_auxiliary_weapon_slot_3 = rocket_rails
				fixed_auxiliary_weapon_slot_4 = reflex_gunsight_2	
				engine_type_slot = jet_engine_1x
				special_type_slot_1 = drop_tanks
				special_type_slot_2 = pressurized_cockpit
				special_type_slot_3 = water_injection_small
				special_type_slot_4 = armor_plate_small
				special_type_slot_5 = self_sealing_fuel_tanks_small	
				special_type_slot_6 = empty
				special_type_slot_7 = supercharger
				special_type_slot_8 = canopy2	
		}
		icon = "GFX_ENG_jet_plane_1_medium"
	}
}
EQS_add_hawker_sea_fury_template = {
	create_equipment_variant = {
		name = "Hawker Sea Fury"
		type = cv_small_plane_airframe_4
		design_team = mio:EQS_ultramarine_organization
		modules = {
				fixed_main_weapon_slot = aircraft_cannon_2_2x
				fixed_auxiliary_weapon_slot_1 = aircraft_cannon_2_2x
				fixed_auxiliary_weapon_slot_2 = empty
				fixed_auxiliary_weapon_slot_3 = bomb_locks
				fixed_auxiliary_weapon_slot_4 = reflex_gunsight_2	
				engine_type_slot = engine_4_1x
				special_type_slot_1 = drop_tanks
				special_type_slot_2 = pressurized_cockpit
				special_type_slot_3 = water_injection_small
				special_type_slot_4 = armor_plate_small
				special_type_slot_5 = self_sealing_fuel_tanks_small	
				special_type_slot_6 = empty
				special_type_slot_7 = supercharger
				special_type_slot_8 = canopy2	
		}
		icon = "GFX_ENG_fighter3_medium"
	}
}
EQS_muletilda_template = {
	create_equipment_variant = {
		name = "Muletilda"
		type = light_tank_chassis_2
		design_team = mio:EQS_mustang_organization
		parent_version = 1
		modules = {
			main_armament_slot = tank_small_cannon_2
			turret_type_slot = tank_light_three_man_tank_turret
			suspension_type_slot = tank_bogie_suspension
			armor_type_slot = tank_welded_armor
			engine_type_slot = tank_diesel_engine
			special_type_slot_1 = tank_radio_1
			special_type_slot_2 = armor_skirts
		}
		upgrades = {
			tank_nsb_engine_upgrade = 8
			tank_nsb_armor_upgrade = 13
		}
		icon = "GFX_commonwealth_2d_improved_light_tank_medium"
	}
}
EQS_platinum_template = {
	create_equipment_variant = {
		name = "Platinum"
		type = light_tank_chassis_2
		design_team = mio:EQS_mustang_organization
		parent_version = 1
		modules = {
			main_armament_slot = tank_high_velocity_cannon
			turret_type_slot = tank_light_three_man_tank_turret
			suspension_type_slot = tank_bogie_suspension
			armor_type_slot = tank_riveted_armor
			engine_type_slot = tank_diesel_engine
			special_type_slot_1 = tank_radio_1
			special_type_slot_2 = armor_skirts
			special_type_slot_3 = secondary_turret_hmg
		}
		upgrades = {
			tank_nsb_engine_upgrade = 10
			tank_nsb_armor_upgrade = 3
		}
		icon = "GFX_commonwealth_2d_advanced_light_tank_medium"
	}
}