(alt. title: "How do I scope to every system during galaxy generation?")
So, what I'm trying to do is this: I want to make it so that certain solar system initializers have a higher chance of being used for systems that are closer to a human player's homeworld than to any AI empire's homeworld.
The only way I could think of to do that is to write a scripted effect that sets a flag on all systems that meet that condition, run it from the init_effect block of a solar system initializer that's guaranteed to be used (hoping that it gets run early enough in the process), and then use that flag as a modifier to the usage_odds of the initializers whose position I want to influence.
(tl;dr: It didn't work, and I need help figuring out either an alternative solution, or how to fix it.)
Here's the scripted effect I came up with:
(I called the flag expansion_cluster because it identifies the systems that the player is most likely to be able to expand into. I put my logic in the comments to help me spot flaws in it.)
In order to test it, I made a new solar system initializer to run it in, like so:
I started up a new game to test it out, found the TEST system and checked its flags to confirm that the scripted effect executed (it did), but the systems that should have had the expansion_cluster flag didn't have it.
I ran another test with the game set to generate only 1 AI empire (to eliminate as many variables as possible), and I discovered that the TEST system itself had the expansion_cluster flag when in the right area, but it still wasn't getting set on any other systems.
I also tested the effect by running it in an on_game_start event. When I did that, the flag was set properly in all systems that should have it. So I know that the code itself works. The problem can't be a syntax error, or a flaw in the logic of the effect itself, it has to be a problem with when or where I'm running the effect.
So, my hypothesis is that init_effect blocks can't scope outside their own system, and if that's true, I'm stumped. I can't think of a way to set the expansion_cluster flags early enough to affect galaxy gen. I can't use an on_game_start event in practice, because those run after galaxy gen is already finished. And afaik, there's no way to run an effect during galaxy gen other than in init_effect blocks.
If I knew of a way to check whether a system is closer to one thing than another without setting a flag, using only triggers, then I could just use that directly as a modifier to the usage_odds of the initializers I'm trying to influence - sidestepping the flag problem entirely - but I have no idea how to do that.
Do any of you know how to check whether a system is closer to one thing than another without setting a flag? Or alternatively, do you know of a way to scope to every_system during galaxy gen? Either option would help immensely.
So, what I'm trying to do is this: I want to make it so that certain solar system initializers have a higher chance of being used for systems that are closer to a human player's homeworld than to any AI empire's homeworld.
The only way I could think of to do that is to write a scripted effect that sets a flag on all systems that meet that condition, run it from the init_effect block of a solar system initializer that's guaranteed to be used (hoping that it gets run early enough in the process), and then use that flag as a modifier to the usage_odds of the initializers whose position I want to influence.
(tl;dr: It didn't work, and I need help figuring out either an alternative solution, or how to fix it.)
Here's the scripted effect I came up with:
Code:
init_expansion_cluster_flag_effect = {
every_system = { # Find every system...
limit = {
NOR = { # Other than the following:...
exists = owner # Systems that have an owner, or...
any_neighbor_system = { # Systems that are right next to...
ignore_hyperlanes = no
exists = owner
owner = {
is_country_type = fallen_empire # Xenophobic Fallen Empires, or...
is_xenophobe = yes
}
}
has_star_flag = empire_home_system # Empire homeworlds (probably redundant), or...
has_star_flag = empire_cluster # Systems very close to empire homeworlds.
}
} # From that system...
closest_system = { # Find the closest system...
limit = {
exists = owner # That has an owner...
owner = { is_country_type = default } # Other than FE, Marauders, etc....
}
if = { # If that owner...
limit = {
owner = { is_ai = no } # Is a human player...
}
PREV = { # Go back a scope...
set_star_flag = expansion_cluster # Set the flag.
}
}
}
}
set_star_flag = ran_expansion_cluster_effect # This is just to confirm that the effect is being executed at all
}
In order to test it, I made a new solar system initializer to run it in, like so:
Code:
expansion_cluster_test_init = {
name = "TEST"
class = "rl_standard_stars"
usage = misc_system_init
usage_odds = 90000
max_instances = 1
init_effect = {
init_expansion_cluster_flag_effect = yes
}
# Planet blocks omitted for brevity
}
I started up a new game to test it out, found the TEST system and checked its flags to confirm that the scripted effect executed (it did), but the systems that should have had the expansion_cluster flag didn't have it.
I ran another test with the game set to generate only 1 AI empire (to eliminate as many variables as possible), and I discovered that the TEST system itself had the expansion_cluster flag when in the right area, but it still wasn't getting set on any other systems.
I also tested the effect by running it in an on_game_start event. When I did that, the flag was set properly in all systems that should have it. So I know that the code itself works. The problem can't be a syntax error, or a flaw in the logic of the effect itself, it has to be a problem with when or where I'm running the effect.
So, my hypothesis is that init_effect blocks can't scope outside their own system, and if that's true, I'm stumped. I can't think of a way to set the expansion_cluster flags early enough to affect galaxy gen. I can't use an on_game_start event in practice, because those run after galaxy gen is already finished. And afaik, there's no way to run an effect during galaxy gen other than in init_effect blocks.
If I knew of a way to check whether a system is closer to one thing than another without setting a flag, using only triggers, then I could just use that directly as a modifier to the usage_odds of the initializers I'm trying to influence - sidestepping the flag problem entirely - but I have no idea how to do that.
Do any of you know how to check whether a system is closer to one thing than another without setting a flag? Or alternatively, do you know of a way to scope to every_system during galaxy gen? Either option would help immensely.