Playing around with Stealth/Defenses for Natives/Specials

Creation, discussion, and balancing of game content such as techs, buildings, ship parts.

Moderators: Oberlus, Committer

Message
Author
wobbly
Cosmic Dragon
Posts: 1873
Joined: Thu Oct 10, 2013 6:48 pm

Re: Playing around with Stealth/Defenses for Natives/Specials

#16 Post by wobbly »

Geoff the Medio wrote: Thu Mar 03, 2022 9:15 am But aside from all that, do you even need these hard-to-write If effects? The EffectsGroup has source = Scope and a complicated activation condition. The purpose of the existing If condition effects else effect (before the new additions in the linked pull request) is to ensure that exactly one of two things, randomly selected with a set probability, happens to objects that have a resource special on turn 0: either a ship is created or the planet species is set. Your additional conditional effect that picks between different kinds of ships to create depending on whether there is an asteroid planet in the system doesn't need this check to be done when executing the effect. Rather, it could be put into the activation condition or scope condition, with two separate effectsgroups that handle the two cases. This would involve substantial script duplication, so might be not worth doing in that sense, but could be easier to script and read.
Missed this edit till now. I could certainly rewrite it if you believe it would be more readable or efficient, I'm not convinced it would be, but then again I'm not convinced it wouldn't be. I just changed it in the way that seemed most obvious to me at the time.
Geoff the Medio wrote: Thu Mar 03, 2022 9:15 am The purpose of the existing If condition effects else effect (before the new additions in the linked pull request) is to ensure that exactly one of two things, randomly selected with a set probability, happens to objects that have a resource special on turn 0
This is something I'm finding a bit awkward. ensuring 1 of 2 seems straightforward. What happens when you want to ensure 1 of 3? e.g. guard ship/ancient guardians/stealth. Unless I'm missing the simple method, this is hard to do without making the scripting cumbersome. A second issue is OneOf is great if the probabilities are equal, but what about the case of unequal probabilities?

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Playing around with Stealth/Defenses for Natives/Specials

#17 Post by Geoff the Medio »

wobbly wrote: Fri Mar 04, 2022 6:59 amI could certainly rewrite it if you believe it would be more readable or efficient...
In this case, it's inside some other scripts that can't be moved to activation or scope, so it's probably fine, but just keep in mind that using activation and scope where reasonable is preferable to trying to encode everything within the effect itself.

Also, note that the details of what the scripted effectsgroups will do is also different with different constructions in cases where there are multiple target objects. Scripting with Random in the activation condition lets one pick whether an effectsgroup should execute on all potential targets at the same time, but can only ensure that exactly one of the possible effects is applied by using stacking groups and multiple effectsgroups that contain the different effects and suitable priority ordering of those effectsgroups. Scripting with an If condition = Random effect or OneOf valueref within an effect lets one pick one of several options independnetly for each target, but not to ensure all targets get the same effect applied.

It would probably be useful to add another valueref operation that works like OneOf but which is only evaluated once per execution, rather than once per target object or condition candidate object, but actually doing that would be tricky. There is a mechanism to evaluate valuerefs within effects or other valuerefs or conditions just once if their result is not dependent on (called "invariant to") the separate objects that are being considered in a condition or separate targets being acted on by an effect, but whether that get evaluated once or multiple happends usually requires all the parameters to an effect or condition to be invariant, and not each parameter independently of the others. So really, doing that with the activation condition would be more realistic and already-supported.
This is something I'm finding a bit awkward. ensuring 1 of 2 seems straightforward. What happens when you want to ensure 1 of 3? e.g. guard ship/ancient guardians/stealth. Unless I'm missing the simple method, this is hard to do without making the scripting cumbersome.
You can chain the if-else effects... If condition = C1 effects = E1 else = If condition = C2 effects = E2 else = E3
A second issue is OneOf is great if the probabilities are equal, but what about the case of unequal probabilities?
There was some discussion about weighted OneOf: viewtopic.php?p=107531#p107531

Ophiuchus
Programmer
Posts: 3433
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Re: Playing around with Stealth/Defenses for Natives/Specials

#18 Post by Ophiuchus »

I have an implementation of currently unknown status in branch 2021115_WeightedAlternativesOf

here forum discussion. i think the latest changes made it commutative/consistent with geoff's demands.
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Look, ma... four combat bouts!

User avatar
stpa
Space Kraken
Posts: 157
Joined: Mon Mar 12, 2018 1:08 pm

Re: Playing around with Stealth/Defenses for Natives/Specials

#19 Post by stpa »

wobbly wrote: Tue Mar 01, 2022 4:02 pm Aims:
  1. Occasional stealth on monster nests
overshot, in my opinion it is not necessary to add yet more stealth-spewing master-cloud-monsters. this could better be applied to just the one planet. and there was also the idea of nest tending species to occur on nest worlds, who again could have smth like increased planetary stealth as traits.

and per default adding additional dyson tree monsters to some natives also seems like an unnecessry exponential growth time bomb due to floater production.

Ophiuchus
Programmer
Posts: 3433
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Re: Playing around with Stealth/Defenses for Natives/Specials

#20 Post by Ophiuchus »

stpa wrote: Sat Mar 05, 2022 12:33 pm
wobbly wrote: Tue Mar 01, 2022 4:02 pm Aims:
  1. Occasional stealth on monster nests
...in my opinion it is not necessary to add yet more stealth-spewing master-cloud-monsters. this could better be applied to just the one planet...
i think you misunderstood. the "clouds" is a special, it has nothing to do with monsters. it adds stealth to a planet.
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Look, ma... four combat bouts!

Ophiuchus
Programmer
Posts: 3433
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Re: Playing around with Stealth/Defenses for Natives/Specials

#21 Post by Ophiuchus »

wobbly wrote: Fri Mar 04, 2022 6:59 am A second issue is OneOf is great if the probabilities are equal, but what about the case of unequal probabilities?
wobbly, do you currently have use for WeightedAlternativesOf ?

i.e. a condition where there are different alternative categories of candidates and the categories are chosen in a random weighted way.

geoff is correct that one can simulate arbitrary random choice of effects using if-else chains. But those are still cumbersome, and one has to calculate dependent probabilities beforehand (e.g. 3x1/3 is 1/3+(2x1/2) ) instead of simply writing down the resulting probabilities which is a bit confusing
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Look, ma... four combat bouts!

wobbly
Cosmic Dragon
Posts: 1873
Joined: Thu Oct 10, 2013 6:48 pm

Re: Playing around with Stealth/Defenses for Natives/Specials

#22 Post by wobbly »

stpa wrote: Sat Mar 05, 2022 12:33 pm
wobbly wrote: Tue Mar 01, 2022 4:02 pm Aims:
  1. Occasional stealth on monster nests
overshot, in my opinion it is not necessary to add yet more stealth-spewing master-cloud-monsters. this could better be applied to just the one planet. and there was also the idea of nest tending species to occur on nest worlds, who again could have smth like increased planetary stealth as traits.
As Ophiuchus has mentioned this is just the cloud cover special, not the floating cloud monster. The idea has as much to do with the tower defense mode in current MP. Hide some nests so you can immediately slap down outposts on all of them
stpa wrote: Sat Mar 05, 2022 12:33 pm and per default adding additional dyson tree monsters to some natives also seems like an unnecessry exponential growth time bomb due to floater production.
I'm not convinced its a huge increase in dyson/floaters. Its as many extra dysons as there are biege goo colonies. So usually 0, more then 2 extras would be rare. It doesn't have to be a dyson forest, it just seemed like something unique and interesting for them.
Last edited by wobbly on Sat Mar 05, 2022 5:02 pm, edited 2 times in total.

wobbly
Cosmic Dragon
Posts: 1873
Joined: Thu Oct 10, 2013 6:48 pm

Re: Playing around with Stealth/Defenses for Natives/Specials

#23 Post by wobbly »

Ophiuchus wrote: Sat Mar 05, 2022 4:15 pm
wobbly wrote: Fri Mar 04, 2022 6:59 am A second issue is OneOf is great if the probabilities are equal, but what about the case of unequal probabilities?
wobbly, do you currently have use for WeightedAlternativesOf ?

i.e. a condition where there are different alternative categories of candidates and the categories are chosen in a random weighted way.

geoff is correct that one can simulate arbitrary random choice of effects using if-else chains. But those are still cumbersome, and one has to calculate dependent probabilities beforehand (e.g. 3x1/3 is 1/3+(2x1/2) ) instead of simply writing down the resulting probabilities which is a bit confusing
I'm not sure. Here:

Code: Select all

      activation = And [
                Random probability = [[FORTICATION_PROBABILITY]]
                Not ContainedBy Contains Or [
                    And [Planet HasSpecial name = "MODERATE_TECH_NATIVES_SPECIAL"]
                    And [Planet HasSpecial name = "HIGH_TECH_NATIVES_SPECIAL"]
                    And [Species HasTag name = "PRIMITIVE"]
                    ]
            ]
            effects = [
                If condition = Not Random probability = [[FORTICATION_PROBABILITY]]
                    effects = [
                        AddSpecial name = OneOf("NATIVE_FORTIFICATION_MINIMAL", "NATIVE_FORTIFICATION_LOW", "CLOUD_COVER_MASTER_SPECIAL")
                    ]
                else = [
                    AddSpecial name = OneOf("NATIVE_FORTIFICATION_MEDIUM", "NATIVE_FORTIFICATION_HIGH", "VOLCANIC_ASH_MASTER_SPECIAL")
                ]
            ]
Its making 2 probability checks, (so probability^2) to make the last 3 rarer. It could possibly be made simpler with just weighted odds.

Here:

Code: Select all

 effects = [
                AddSpecial name = "CLOUD_COVER_MASTER_SPECIAL"
            ]
it could have a chance of volcanic ash instead, at lower odds. Though maybe its fine with just cloud cover.

I'm not sure of the case of monster/ancient guardian/stealth. I was working with something that's already there, so it might be easier to just tack the if/else on rather then rewrite the whole thing. Plus I'm not sure if OneOf works for 3 seperate categories (e.g. AddSpecial, CreateShip, SetSpecies) or if they all need to be identical.

Ophiuchus
Programmer
Posts: 3433
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Re: Playing around with Stealth/Defenses for Natives/Specials

#24 Post by Ophiuchus »

wobbly wrote: Sat Mar 05, 2022 4:52 pm I'm not sure. Here:

Code: Select all

      activation = And [
                Random probability = [[FORTICATION_PROBABILITY]]
                Not ContainedBy Contains Or [
                    And [Planet HasSpecial name = "MODERATE_TECH_NATIVES_SPECIAL"]
                    And [Planet HasSpecial name = "HIGH_TECH_NATIVES_SPECIAL"]
                    And [Species HasTag name = "PRIMITIVE"]
                    ]
            ]
            effects = [
                If condition = Not Random probability = [[FORTICATION_PROBABILITY]]
                    effects = [
                        AddSpecial name = OneOf("NATIVE_FORTIFICATION_MINIMAL", "NATIVE_FORTIFICATION_LOW", "CLOUD_COVER_MASTER_SPECIAL")
                    ]
                else = [
                    AddSpecial name = OneOf("NATIVE_FORTIFICATION_MEDIUM", "NATIVE_FORTIFICATION_HIGH", "VOLCANIC_ASH_MASTER_SPECIAL")
                ]
            ]
Its making 2 probability checks, (so probability^2) to make the last 3 rarer. It could possibly be made simpler with just weighted odds.
Ok, without a bigger rewrite this is not a case for WeightedAlternativesOf. This is an effect on a species. If there was an effect lets say distributing a certain number of a certain kind of special and you wanted it to be distributed to certain kinds with different weight, then WeightedAlternativesOf could sometimes be useful.

What you wrote will depend actually on fortification probability. Not sure what the highest probability at the beginning of the game is .. something like 20%? So a really good native planet has a 16% chance of one of the lower level fortifications and a 4% chance of one of the stronger fortifications. (That is if there is no MODERATE_TECH_NATIVES_SPECIAL, HIGH_TECH_NATIVES_SPECIAL, or PRIMITIVE species in the system).

Plus I'm not sure if OneOf works for 3 seperate categories (e.g. AddSpecial, CreateShip, SetSpecies) or if they all need to be identical.
No, that does not work. OneOf is a valueref (i.e. strings, enum, int, float computation), and not to choose a different kind of effect. You cooould hack something like a named value ref to a string OneOf and use it for AddSpecial and CreateShip with the same string value (maybe + works on strings, dunno, so you could have a SD_EVIL_HACK and a EVIL_HACK_SPECIAL). But please dont.
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Look, ma... four combat bouts!

wobbly
Cosmic Dragon
Posts: 1873
Joined: Thu Oct 10, 2013 6:48 pm

Re: Playing around with Stealth/Defenses for Natives/Specials

#25 Post by wobbly »

Oberlus wrote: What about using just TargetPopulation, optionally with factors for selected species trait?

FORTICATION_PROBABILITY '''0.02 * Source.TargetPopulation'''
Does this look better?

Code: Select all

FORTICATION_PROBABILITY
'''0.1 * max(0.2 * Source.Population, Source.Research + Source.Industry)'''

Post Reply