SVN 6421 When good things turn bad (Industry and Population)

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

Moderators: Oberlus, Committer

Post Reply
Message
Author
User avatar
Cluesen
Space Floater
Posts: 42
Joined: Mon May 20, 2013 4:40 pm

SVN 6421 When good things turn bad (Industry and Population)

#1 Post by Cluesen »

GoodIndustry.jpg
GoodIndustry.jpg (20.18 KiB) Viewed 1828 times
In this example a malus is derived from GoodIndustry and the tiny planet effected doesn't even have an industry focus.
The Xenophobic Harresment gives a malus of -1 and the GoodIndustry adds 50% .

To correct this i suggest the following modification in species.txt
[edit]
The first code I posted was unproperly tested and erratic.
Meanwhile I corrected this.
In this context I noticed, that most of the species-effects are not limited to planets, which could fire some extra thousand effects and lower performance greatly.
I will test this and report later in the thread.
[/edit]

Code: Select all

BAD_INDUSTRY
'''[[AVERAGE_INDUSTRY]]
        EffectsGroup
            scope = And [
                Source
                Planet
                TargetIndustry Low = 0
                Focus type = "FOCUS_INDUSTRY"
            ]
            activation = Planet
            accountinglabel = "BAD_INDUSTRY_LABEL"
            effects = SetTargetIndustry Value*[[BAD_MULTIPLIER]]
'''

AVERAGE_INDUSTRY
'''        EffectsGroup
              scope = And [
                  Source
                  Planet
                  TargetIndustry Low = 0
                  Focus type = "FOCUS_INDUSTRY"
              ]
              accountinglabel = "FOCUS_INDUSTRY_LABEL"
              effects = SetTargetIndustry Value + Target.Population * [[INDUSTRY_PER_POP]]
            
        EffectsGroup                    // removes residual production from a dead planet
            scope = Source
            activation = And [
                Planet
                TargetPopulation low = 0 high = 0
            ]
            effects = SetIndustry Value = 0
'''

GOOD_INDUSTRY
'''[[AVERAGE_INDUSTRY]]

        EffectsGroup
            scope = And [
                Source
                Planet
                TargetIndustry Low = 0
                Focus type = "FOCUS_INDUSTRY"
            ]
            activation = Planet
            accountinglabel = "GOOD_INDUSTRY_LABEL"
            effects = SetTargetIndustry Value*[[GOOD_MULTIPLIER]]
'''

GREAT_INDUSTRY
'''[[AVERAGE_INDUSTRY]]

        EffectsGroup
            scope = And [
                Source
                Planet
                TargetIndustry Low = 0
                Focus type = "FOCUS_INDUSTRY"
            ]
            activation = Planet
            accountinglabel = "GREAT_INDUSTRY_LABEL"
            effects = SetTargetIndustry Value*[[GREAT_MULTIPLIER]]
'''

ULTIMATE_INDUSTRY
'''[[AVERAGE_INDUSTRY]]

        EffectsGroup
            scope = And [
                Source
                Planet
                TargetIndustry Low = 0
                Focus type = "FOCUS_INDUSTRY"
            ]
            activation = Planet
            accountinglabel = "ULTIMATE_INDUSTRY_LABEL"
            effects = SetTargetIndustry Value*[[ULTIMATE_MULTIPLIER]]
'''
Similar negation of effects happens with the population modifiers on unhabitable planets, Good Population turns into a malus and BadPopulation into a bonus.
This can be important when you want to colonize a gaian planet which is currently unhabitle for you.
The extra loss can make 1 turn difference for the gaia special to trigger and turn the planet inhabitable.

I suggest this modification to species.txt:

Code: Select all

BAD_POPULATION
'''     [[AVERAGE_POPULATION]]
    
        EffectsGroup
            scope = And [
                Source
                TargetPopulation low = 0
            ]
            activation = Planet
            accountinglabel = "BAD_POPULATION_LABEL"
            effects = SetTargetPopulation Value*.75   // doesn't matter if these modifiers don't match ther other 'bad' modifiers.
'''

GOOD_POPULATION
'''     [[AVERAGE_POPULATION]]

        EffectsGroup
            scope = And [
                Source
                TargetPopulation low = 0
            ]
            activation = Planet
            accountinglabel = "GOOD_POPULATION_LABEL"
            effects = SetTargetPopulation Value*1.25  // doesn't matter if these modifiers don't match ther other 'good' modifiers.
'''
The beauty of travel is visiting foreign countries and meeting new people.
G.Khan
_______________________________________________________________________
All code provided is released under the CC-BY-SA 3.0 and GPL 2.0 or later licenses

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

Re: SVN 6421 When good things turn bad (Industry and Populat

#2 Post by Geoff the Medio »

Cluesen wrote:In this context I noticed, that most of the species-effects are not limited to planets, which could fire some extra thousand effects and lower performance greatly.
If the effectsgroup has an activation condition that tests if the source is a planet, and then the scope has Source in it, a further condition to check that the source is a planet is redundant. It would probably actually be better to put any additional checks on the source planet within the activation as well, so that the scope is just Source, as this is a special case scope that can be optimized, and if the activation fails, then various additional steps can be skipped.

User avatar
Cluesen
Space Floater
Posts: 42
Joined: Mon May 20, 2013 4:40 pm

Re: SVN 6421 When good things turn bad (Industry and Populat

#3 Post by Cluesen »

Here are modifications for Species.txt that respect your demands.
I'm posting the whole blocks to replace.
This eliminates the negation of positive effects and should also be a tad more performant than the current code since the activation conditions are a bit more limiting.
- Added TargetPopulation Low = 0 Condition to population-modifiers.
- Added focus-requirement to industry and research modifiers.
- Added TargetIndustry Low = 0 Condition to industry-modifiers.

Population-Modifiers:

Code: Select all

BAD_POPULATION
'''     [[AVERAGE_POPULATION]]
    
        EffectsGroup
            scope = Source
            activation = And [
                Source
                Planet
                TargetPopulation low = 0
            ]
            accountinglabel = "BAD_POPULATION_LABEL"
            effects = SetTargetPopulation Value*.75   // doesn't matter if these modifiers don't match ther other 'bad' modifiers.
'''

GOOD_POPULATION
'''     [[AVERAGE_POPULATION]]

        EffectsGroup
            scope = Source
            activation = And [
                Source
                Planet
                TargetPopulation low = 0
            ]
            accountinglabel = "GOOD_POPULATION_LABEL"
            effects = SetTargetPopulation Value*1.25  // doesn't matter if these modifiers don't match ther other 'good' modifiers.
'''
Industry & Research-Modifiers:

Code: Select all

//#####      I N D U S T R Y    #####//

NO_INDUSTRY
'''
'''

BAD_INDUSTRY
'''[[AVERAGE_INDUSTRY]]

        EffectsGroup
            scope = Source
            activation = And [
                Source
                Planet
                TargetIndustry Low = 0
                Focus type = "FOCUS_INDUSTRY"
            ]
            accountinglabel = "BAD_INDUSTRY_LABEL"
            effects = SetTargetIndustry Value*[[BAD_MULTIPLIER]]
'''

AVERAGE_INDUSTRY
'''        EffectsGroup
            scope = Source
            activation = And [
                Source
                Planet
                TargetIndustry Low = 0
                Focus type = "FOCUS_INDUSTRY"
            ]
            accountinglabel = "FOCUS_INDUSTRY_LABEL"
            effects = SetTargetIndustry Value + Target.Population * [[INDUSTRY_PER_POP]]
            
        EffectsGroup                    // removes residual production from a dead planet
            scope = Source
            activation = And [
                Planet
                TargetPopulation low = 0 high = 0
            ]
            effects = SetIndustry Value = 0
'''

GOOD_INDUSTRY
'''[[AVERAGE_INDUSTRY]]

        EffectsGroup
            scope = Source
            activation = And [
                Source
                Planet
                TargetIndustry Low = 0
                Focus type = "FOCUS_INDUSTRY"
            ]
            accountinglabel = "GOOD_INDUSTRY_LABEL"
            effects = SetTargetIndustry Value*[[GOOD_MULTIPLIER]]
'''

GREAT_INDUSTRY
'''[[AVERAGE_INDUSTRY]]

        EffectsGroup
            scope = Source
            activation = And [
                Source
                Planet
                TargetIndustry Low = 0
                Focus type = "FOCUS_INDUSTRY"
            ]
            accountinglabel = "GREAT_INDUSTRY_LABEL"
            effects = SetTargetIndustry Value*[[GREAT_MULTIPLIER]]
'''

ULTIMATE_INDUSTRY
'''[[AVERAGE_INDUSTRY]]

        EffectsGroup
            scope = Source
            activation = And [
                Source
                Planet
                TargetIndustry Low = 0
                Focus type = "FOCUS_INDUSTRY"
            ]
            accountinglabel = "ULTIMATE_INDUSTRY_LABEL"
            effects = SetTargetIndustry Value*[[ULTIMATE_MULTIPLIER]]
'''

//#####      R E S E A R C H    #####//

NO_RESEARCH
'''
'''

BAD_RESEARCH
'''[[AVERAGE_RESEARCH]]

        EffectsGroup
            scope = Source
            activation = And [
                Source
                Planet
                Focus type = "FOCUS_RESEARCH"
            ]
            accountinglabel = "BAD_RESEARCH_LABEL"
            effects = SetTargetResearch Value*[[BAD_MULTIPLIER]]
'''

AVERAGE_RESEARCH
'''EffectsGroup
            scope = Source
            activation = And [
                Source
                Planet
                Focus type = "FOCUS_RESEARCH"
            ]
            accountinglabel = "FOCUS_RESEARCH_LABEL"
            effects = SetTargetResearch Value + Target.Population * [[RESEARCH_PER_POP]]
            
        EffectsGroup      // removes residual production from a dead planet
            scope = Source
            activation = And [
                Planet
                TargetPopulation low = 0 high = 0
            ]
            effects = SetResearch Value = 0
'''

GOOD_RESEARCH
'''[[AVERAGE_RESEARCH]]

        EffectsGroup
            scope = Source
            activation = And [
                Source
                Planet
                Focus type = "FOCUS_RESEARCH"
            ]
            accountinglabel = "GOOD_RESEARCH_LABEL"
            effects = SetTargetResearch Value*[[GOOD_MULTIPLIER]]
'''

GREAT_RESEARCH
'''[[AVERAGE_RESEARCH]]

        EffectsGroup
            scope = Source
            activation = And [
                Source
                Planet
                Focus type = "FOCUS_RESEARCH"
            ]
            accountinglabel = "GREAT_RESEARCH_LABEL"
            effects = SetTargetResearch Value*[[GREAT_MULTIPLIER]]
'''

ULTIMATE_RESEARCH
'''[[AVERAGE_RESEARCH]]

        EffectsGroup
            scope = Source
            activation = And [
                Source
                Planet
                Focus type = "FOCUS_RESEARCH"
            ]
            accountinglabel = "ULTIMATE_RESEARCH_LABEL"
            effects = SetTargetResearch Value*[[ULTIMATE_MULTIPLIER]]
'''
The beauty of travel is visiting foreign countries and meeting new people.
G.Khan
_______________________________________________________________________
All code provided is released under the CC-BY-SA 3.0 and GPL 2.0 or later licenses

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

Re: SVN 6421 When good things turn bad (Industry and Populat

#4 Post by Geoff the Medio »

Do the "TargetPopulation low = 0" actually do what you intended? The conditions are supposed to be evaluated on the initial meter values, not the values after some but not all effects have acted on a meter.

User avatar
Cluesen
Space Floater
Posts: 42
Joined: Mon May 20, 2013 4:40 pm

Re: SVN 6421 When good things turn bad (Industry and Populat

#5 Post by Cluesen »

In this case yes.

Actually it should be checked after ALL meters are applied, as it only matters that the result is positive.
As far as I monitored it works, the Good/Bad-Population bonus is applied last.
Else you'd never get a positive bonus in a hostile environment.

This does not create any bonus for unhabitable planets, it only keeps the Good/Bad boni from beeing applied and negating their original effects.
The beauty of travel is visiting foreign countries and meeting new people.
G.Khan
_______________________________________________________________________
All code provided is released under the CC-BY-SA 3.0 and GPL 2.0 or later licenses

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

Re: SVN 6421 When good things turn bad (Industry and Populat

#6 Post by Geoff the Medio »

I don't think you fully understand the potential problem I'm noting.

Problem cases would be when the previous turn's meter value was positive, based on which the condition decides to apply the effect, but then when the effect is applied, the meter value accumulation has a negative value, which is multiplied to give a negative "bonus".

If the meter values are stable and positive always, that won't be an issue, but it could if there is a transition.

Rather than using conditions to decide whether to apply this effect, it might be better to use an Abs function or Max function to control the sign of the adjustment.

"Value + Abs(Value * 0.25)" would always give a positive adjustment, even if the Value is negative, and "Value + Max(0, Value*0.25)" would give a positive adjustment when Value is positive, and no change when Value is negative.

User avatar
Cluesen
Space Floater
Posts: 42
Joined: Mon May 20, 2013 4:40 pm

Re: SVN 6421 When good things turn bad (Industry and Populat

#7 Post by Cluesen »

hmmm...

But the scenario you're describing would lead to a wrong result regardless which formular is used.
That is nothing that can be done with scripting, the code must provide the ensurance that the formula is not applied to outdated or incomplete values.

Using the max-function should lead to the same result as the Population Low = 0, it would be applied at the same point of execution.
The abs function however will return different values.

Let's look into an example.
No techs researched, a tiny planet poor environment for the species to colonize, Gaia special.
That makes -2 for poor environment.
A GoodPopulation species gets 1.25times the population = -2.5
A BadPopulation species gets 0.75times the population = -1.5
That is current code.
My suggestion / using max-function should return -2 for both Good and Bad Population.
Using an abs-function like <Value> +/-0,25*abs<Value> should return -1,5 for Good and -2,5 for Bad Population.
So, take your choice. I like the idea with the abs-funtion even more than my own. ;)

On any casual planet the population would be on the brink of extinction anyway, it only makes sense on gaia planets.
If the habitability is -1.5 instead of -2.5 the GoodPopulation species got a better chance to survive until the gaia special triggers.
I've been in this situation in approximately 2 of 50 games.

... I just downloaded SVN 6432 I'll test with the abs-function modification you described.

[edit]
I started a new games as Gysache ... some results of planets in my homesystem(s)
Medium terran (poor) : habitability of -4.5 = -6 + 0,25*abs(-6) | OK
Small tundra (hostile), solid core : habitability of -8 = -8 -2 +0,25*abs(-10) | OK
Tiny Desert (hostile) habitability of -3 = -4 +0,25*abs(-4) | OK
Medium Tundra (hostile) : habitability of -9 = -12 +0,25*abs(-12) | OK
Small Tundra (hostile) : habitability of -6 = -8 +0,25*abs(-8) | OK
Large Ocean (adequate) : habitability of 0 = 0 +0,25*abs(0) | OK
Looks like it works.

Code: Select all

BAD_POPULATION
'''     [[AVERAGE_POPULATION]]
    
        EffectsGroup
            scope = Source
            activation = And [
                Source
                Planet
            ]
            accountinglabel = "BAD_POPULATION_LABEL"
            effects = SetTargetPopulation Value -0.25*abs(Value) 
'''

GOOD_POPULATION
'''     [[AVERAGE_POPULATION]]

        EffectsGroup
            scope = Source
            activation = And [
                Source
                Planet
            ]
            accountinglabel = "GOOD_POPULATION_LABEL"
            effects = SetTargetPopulation Value +0.25*abs(Value) 
'''
[/edit]
The beauty of travel is visiting foreign countries and meeting new people.
G.Khan
_______________________________________________________________________
All code provided is released under the CC-BY-SA 3.0 and GPL 2.0 or later licenses

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

Re: SVN 6421 When good things turn bad (Industry and Populat

#8 Post by Geoff the Medio »

Cluesen wrote:Using the max-function should lead to the same result as the Population Low = 0, it would be applied at the same point of execution.
You need to look more carefully at how condition and effect execution works. The scope and activation conditions are not tested at the same time as each effect is executed.

Rather, all scope and activations are checked before any effects are applied each turn. Any meter-value-dependent conditions will thus use the values the meters had on the previous turns, before any effects of the current turn are applied.

Max and Target meters are then reset to 0, and then effects are applied based on already-determined scope / activation results.

Any meter value references in effect values also use the previous turn's values, except "Value", which refers to whatever is being set by the current effect and returns the value as its being accumulated through a series of effect executions. Thus "Value" will depend on the order of effects executions within a turn.
My suggestion / using max-function should return -2 for both Good and Bad Population.
Your suggestion would base the decision about whether to apply an effect on the previous turn's meter value. This may not be the same as the current turn's result or the value as it's being accumulated at the time the effect is executed. See my previous post.

User avatar
Cluesen
Space Floater
Posts: 42
Joined: Mon May 20, 2013 4:40 pm

Re: SVN 6421 When good things turn bad (Industry and Populat

#9 Post by Cluesen »

I still don't get it...

The Population modification posted last works and does not include the Target.Population low = 0 anymore.

But still it would make no sense to test anything unless current values are beeing tested.
Which as far as I monitored is the case.
i.e. for [AVERAGE_INDUSTRY] there exists an effect in current code wich tests for TargetPopulation low = 0 high = 0 and sets TargetIndustry to 0 if true.
This is current code (and not from me), but would make no sense unless tested against current values.

In the verbose logs I see the effects beeing tested and executed in order of appearence, first in first out.
(The bad thing is, one does not see effects that do not trigger in there and the reason why they did not)
Some results (like destruction of ships) are delayed, but nethertheless most effects are handeled immediately.
(Some even multiple times, see my post viewtopic.php?f=28&t=7815 )
The beauty of travel is visiting foreign countries and meeting new people.
G.Khan
_______________________________________________________________________
All code provided is released under the CC-BY-SA 3.0 and GPL 2.0 or later licenses

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

Re: SVN 6421 When good things turn bad (Industry and Populat

#10 Post by Geoff the Medio »

Scope and activation conditions are checked first, which determines what effects will execute. Any reference to a meter value in a scope or activation condition will use the value the meter had at the end of the previous turn.

Then all effects are executed. The results of executing effects can't change what other effects will execute, because that decision has already been made.

If you want to submit changes for actual use, a more convenient form, such as (preferably) a SVN diff or a (probably zipped) full file with the changes made should be posted. Also note in a post, if you haven't already, that you release the changes under the CC-BY-SA 3.0 license and the GPL 2.0 or later license.

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

Re: SVN 6421 When good things turn bad (Industry and Populat

#11 Post by Geoff the Medio »

Committed the relevant changes, I think.

Post Reply