wg_nomad_raid = {
	casus_belli = cb_nomad_raid
	release_occupied_systems_on_status_quo = no
	set_defender_wargoal = wg_nomad_raid

	galactic_empire_joins_defender = {
		from = { is_galactic_emperor = yes }
		imperial_authority >= 100
	}

	surrender_acceptance = -50

	potential = {
		has_total_war_cb = no
		is_nomadic = yes
		from = { is_nomadic = yes }
	}
	possible = {
		custom_tooltip = {
			fail_text = cannot_use_against_emperor
			OR = {
				from = { is_galactic_emperor = no }
				is_galactic_community_member = no
			}
		}
		custom_tooltip = {
			fail_text = pax_galactica_active
			NAND = {
				is_active_resolution = resolution_emperor_pax_galactica
				is_galactic_community_member = yes
				from = { is_galactic_community_member = yes }
			}
		}
	}
	on_accept = {
		custom_tooltip = wg_nomad_raid_effects
		# Main defender; saved outside hidden_effect so the peace-tooltip walk resolves event_target:nomad_raid_defender
		from = { save_event_target_as = nomad_raid_defender }
		hidden_effect = {
			nomad_raid_seize_ark_effect = yes
			nomad_raid_loot_waystations_effect = yes
			nomad_raid_seize_disabled_waystations_effect = yes
			# Secondary nomadic defenders
			fromfrom = {
				every_defender = {
					limit = {
						is_nomadic = yes
						NOT = { is_same_value = event_target:nomad_raid_defender }
					}
					save_event_target_as = nomad_raid_defender
					root = {
						nomad_raid_seize_ark_effect = yes
						nomad_raid_loot_waystations_effect = yes
						nomad_raid_seize_disabled_waystations_effect = yes
					}
				}
			}
		}
	}

	on_status_quo = {
		custom_tooltip = wg_nomad_raid_status_quo_effects
		# Main defender; saved outside hidden_effect so the peace-tooltip walk resolves event_target:nomad_raid_defender
		from = { save_event_target_as = nomad_raid_defender }
		hidden_effect = {
			nomad_raid_seize_disabled_waystations_effect = yes
			# Secondary nomadic defenders
			fromfrom = {
				every_defender = {
					limit = {
						is_nomadic = yes
						NOT = { is_same_value = event_target:nomad_raid_defender }
					}
					save_event_target_as = nomad_raid_defender
					root = {
						nomad_raid_seize_disabled_waystations_effect = yes
					}
				}
			}
		}
	}

	ai_weight = {
		weight = 10
	}
}

wg_heirs_call_of_the_satrapies = {
	casus_belli = cb_imposed_inclusion
	release_occupied_systems_on_status_quo = yes

	surrender_acceptance = -100

	war_exhaustion = 0.5

	potential = {
		has_country_flag = heir_of_the_khan_khan
	}

	possible = {
		custom_tooltip = {
			fail_text = cannot_subjugate_empire_member
			NAND = {
				has_galactic_emperor = yes
				is_galactic_community_member = no
				from = { is_galactic_community_member = yes }
			}
		}
		custom_tooltip = {
			fail_text = "cannot_use_against_custodian"
			from = { is_galactic_custodian = no }
		}
		custom_tooltip = {
			fail_text = "cannot_use_against_emperor"
			from = { is_galactic_emperor = no }
		}
		custom_tooltip = {
			fail_text = "cannot_use_against_btc"
			from = { has_been_declared_crisis = no }
		}
	}


	on_accept = {
		hidden_effect = {
			from = {
				add_threat = {
					who = root
					amount = 0.5
				}
			}
		}
		from = {
			set_subject_of = {
				who = ROOT
				preset = preset_relic_satrapy
			}
			add_modifier = {
				modifier = newly_subjugated_loyalty
				years = 5
			}
		}
	}

	on_status_quo = {
		if = {
			limit = {
				exists = last_created_country
				last_created_country = {
					has_country_flag = released_empire
				}
			}

			last_created_country = {
				set_origin_effect = { SOURCE_COUNTRY = from }
				set_subject_of = {
					who = ROOT
					preset = preset_relic_satrapy
				}
				add_modifier = {
					modifier = newly_subjugated_loyalty
					years = 5
				}
			}

			if = {
				limit = {
					root = { is_megacorp = yes }
					last_created_country = { is_megacorp = yes }
				}
				last_created_country = {
					set_merchant_government_effect = yes
				}
			}
		}
	}

	ai_weight = {
		weight = 100
	}
}

wg_end_threat_vs_heir_khan = {
	casus_belli = cb_containment

	hide = no_cb
	total_war = yes
	set_defender_wargoal = wg_heirs_call_of_the_satrapies

	forbidden_peace_offers = {
		demand_surrender = ""
	}

	surrender_acceptance = -1000

	potential = {
		from = { has_country_flag = heir_of_the_khan_khan }
	}
	possible = {
		always = yes
	}

	on_accept = {
		custom_tooltip = will_kill_khan_tt
		hidden_effect = {
			from = {
				ruler = { kill_leader = {} }
			}
		}
	}

	ai_weight = {
		weight = 30
		modifier = {
			factor = event_target:great_khan_empire.value:num_satrapies
			event_target:great_khan_empire = {
				any_agreement = { agreement_preset = preset_relic_satrapy }
			}
		}
	}
}

wg_expel_nomads = {
	casus_belli = cb_expel_nomads
	hide = no_cb
	release_occupied_systems_on_status_quo = no
	set_defender_wargoal = wg_humiliation

	galactic_empire_joins_defender = {
		from = { is_galactic_emperor = yes }
		imperial_authority >= 100
	}

	surrender_acceptance = 0

	potential = {
		has_total_war_cb = no
	}
	possible = {
		custom_tooltip = {
			fail_text = cannot_use_against_emperor
			OR = {
				from = { is_galactic_emperor = no }
				is_galactic_community_member = no
			}
		}
		custom_tooltip = {
			fail_text = pax_galactica_active
			NAND = {
				is_active_resolution = resolution_emperor_pax_galactica
				is_galactic_community_member = yes
				from = { is_galactic_community_member = yes }
			}
		}
	}
	on_status_quo = {
		from = {
			save_event_target_as = defender
		}
		if = {
			limit = {
				is_overlord = no
			}
			custom_tooltip = wg_expel_nomads_status_quo_effects
			hidden_effect = {
				if = {
					limit = {
						is_nomadic = no
					}
					expel_nomads_destroy_waystation_effect = yes
				}
			}
		}
		else = {
			custom_tooltip = wg_expel_nomads_subject_status_quo_effects
			hidden_effect = {
				if = {
					limit = {
						is_nomadic = no
					}
					expel_nomads_destroy_waystation_effect = yes
				}
				every_subject = {
					if = {
						limit = {
							is_nomadic = no
						}
						expel_nomads_destroy_waystation_effect = yes
					}
				}
			}
		}
		hidden_effect = {
			fromfrom = {
				every_war_participant = {
					limit = {
						prev = {
							using_war_goal = {
								type = wg_expel_nomads
								owner = prev
							}
						}
					}
					if = {
						limit = {
							is_nomadic = no
						}
						expel_nomads_destroy_waystation_effect = yes
					}
					if = {
						limit = { is_overlord = yes }
						every_subject = {
							if = {
								limit = {
									is_nomadic = no
								}
								expel_nomads_destroy_waystation_effect = yes
							}
						}
					}
				}
			}
		}
	}
	on_accept = {
		from = {
			save_event_target_as = defender
		}
		if = {
			limit = {
				is_overlord = no
			}
			custom_tooltip = wg_expel_nomads_effects
			hidden_effect = {
				if = {
					limit = {
						is_nomadic = no
					}
					expel_nomads_destroy_waystation_and_take_stockpile_effect = yes
				}
			}
		}
		else = {
			custom_tooltip = wg_expel_nomads_subject_effects
			hidden_effect = {
				if = {
					limit = {
						is_nomadic = no
					}
					expel_nomads_destroy_waystation_and_take_stockpile_effect = yes
				}
				every_subject = {
					limit = {
						is_nomadic = no
					}
					expel_nomads_destroy_waystation_and_take_stockpile_effect = yes
				}
			}
		}
		# ... and their allies, if applicable.
		hidden_effect = {
			fromfrom = {
				every_attacker = {
					limit = {
						prev = {
							using_war_goal = {
								type = wg_expel_nomads
								owner = prev
							}
						}
					}
					if = {
						limit = {
							is_nomadic = no
						}
						expel_nomads_destroy_waystation_and_take_stockpile_effect = yes
					}
					if = {
						limit = { is_overlord = yes }
						every_subject = {
							limit = {
								is_nomadic = no
							}
							expel_nomads_destroy_waystation_and_take_stockpile_effect = yes
						}
					}
				}
			}
		}
	}

	ai_weight = {
		weight = 10
	}
}

wg_end_threat_dyson_gun = {
	casus_belli = cb_stop_dyson_gun
	hide = no_cb
	total_war = yes
	set_defender_wargoal = wg_fired_dyson_gun

	galactic_empire_joins_defender = {
		from = { is_galactic_emperor = yes }
		imperial_authority >= 100
	}

	forbidden_peace_offers = {
		demand_surrender = ""
		surrender = ""
	}

	surrender_acceptance = -1000

	potential = {
		NAND = {
			is_galactic_emperor = yes
			from = { is_galactic_community_member = yes }
		}
	}
	possible = {
		custom_tooltip = {
			fail_text = cannot_use_against_emperor
			OR = {
				from = { is_galactic_emperor = no }
				is_galactic_community_member = no
			}
		}
		custom_tooltip = {
			fail_text = pax_galactica_active
			NAND = {
				is_active_resolution = resolution_emperor_pax_galactica
				is_galactic_community_member = yes
				from = { is_galactic_community_member = yes }
			}
		}
	}

	ai_weight = {
		weight = 100
	}
}

wg_fired_dyson_gun = {
	casus_belli = cb_fired_dyson_gun
	hide = no_cb
	total_war = yes
	set_defender_wargoal = wg_end_threat_dyson_gun

	galactic_empire_joins_defender = {
		from = { is_galactic_emperor = yes }
		imperial_authority >= 100
	}

	forbidden_peace_offers = {
		demand_surrender = ""
		surrender = ""
	}

	surrender_acceptance = -1000

	potential = {
		NAND = {
			is_galactic_emperor = yes
			from = { is_galactic_community_member = yes }
		}
	}
}

wg_raid_contract = {
	casus_belli = cb_nomad_raid_contract
	set_defender_wargoal = wg_humiliation
	threat_multiplier = 0.25

	war_exhaustion = 2.5 #Skirmish war should end fast

	potential = {
		always = no
	}
	possible = {
		always = yes
	}

	cede_claims = no #no taking anythin during a raid contract

	forbidden_peace_offers = { #no surrendering, only white peace
 		demand_surrender = "wg_raid_contract_no_surrender"
		surrender = "wg_raid_contract_no_surrender"
	}

	surrender_acceptance = -1000

	ai_weight = {
		weight = 2
	}
}
