Optimizing Event Checks for Yagami's Auto-Pop migration

  • We have updated our Community Code of Conduct. Please read through the new rules for the forum that are an integral part of Paradox Interactive’s User Agreement.

mial42

Lt. General
21 Badges
Sep 28, 2020
1.441
3.096
  • Stellaris - Path to Destruction bundle
  • Stellaris: Nemesis
  • Stellaris: Necroids
  • Stellaris: Federations
  • Stellaris: Lithoids
  • Stellaris: Ancient Relics
  • Stellaris: Megacorp
  • Stellaris: Distant Stars
  • Stellaris: Apocalypse
  • Stellaris: Humanoids Species Pack
  • Stellaris: Synthetic Dawn
  • Crusader Kings II
  • Stellaris: Leviathans Story Pack
  • Stellaris: Digital Anniversary Edition
  • Stellaris: Galaxy Edition
  • Stellaris: Galaxy Edition
  • Stellaris
  • Crusader Kings II: Horse Lords
  • Crusader Kings II: The Republic
  • Crusader Kings II: The Old Gods
  • Crusader Kings II: Charlemagne
I was looking through the files of Yagami's Auto-Pop Migration, and I was wondering if this events file could be optimized:

namespace = pabam_events


country_event = {
id = pabam_events.1
hide_window = yes

trigger = {
any_owned_planet = {
has_planet_flag = pab_migration_target
}
OR = {
AND = {
has_policy_flag = pabam_2000_energy
has_resource = { type = energy amount >= 2000 }
}
AND = {
has_policy_flag = pabam_5000_energy
has_resource = { type = energy amount >= 5000 }
}
AND = {
has_policy_flag = pabam_10000_energy
has_resource = { type = energy amount >= 10000 }
}
}
any_owned_planet = {
has_planet_flag = pab_migration_source
count_owned_pops = {
limit = {
OR = {
is_unemployed = yes
has_job = servant
}
NOT = { has_citizenship_type = { type = citizenship_assimilation } }
}
count > 0
}
}
}

immediate = {
random_owned_planet = {
limit = {
has_planet_flag = pab_migration_target
}
save_event_target_as = migration_target
}

random_owned_planet = {
limit = {
has_planet_flag = pab_migration_source
count_owned_pops = {
limit = {
OR = {
is_unemployed = yes
has_job = servant
}
NOT = { has_citizenship_type = { type = citizenship_assimilation } }
}
count > 0
}
}
random_pop = {
limit = {
NOT = { has_citizenship_type = { type = citizenship_assimilation } }
OR = {
is_unemployed = yes
has_job = servant
}
}
resettle_pop = { pop = this planet = event_target:migration_target }
log = "pop resettled: [This.GetName]"

if = {
limit = { has_trait = trait_nomadic }
ROOT = { add_resource = { energy = 37 } }
}
else_if = {
limit = { has_trait = trait_sedentary }
ROOT = { add_resource = { energy = -37 } }
}

ROOT = {
add_resource = { energy = -100 }
if = {
limit = {
has_tradition = tr_diplomacy_secure_shipping
OR = {
has_valid_civic = civic_fanatic_purifiers
has_valid_civic = civic_inwards_perfection
is_hive_empire = yes
is_machine_empire = yes
has_valid_civic = civic_barbaric_despoilers
}
}
add_resource = { energy = 50 }
}
if = {
limit = { has_civic = civic_corvee_system }
add_resource = { energy = 37 }
}

}
}
}
}
}


It seems to be looping through every planet in every empire every day looking for the pab_migration_target and pab_migration_source flags, and I was wondering if that could be streamlined. I'm also not sure if the actual resettling can be streamlined (is it possible to restrict that random selection of planets to only source planets rather than keep picking random planets until you find a source?), but if anyone can come up with a more efficient way to do these checks, I'd appreciate it.
 
He's looping every day? What the fuck.