Colonialism formula

Describe your experience with the latest version of FreeOrion to help us improve it.

Moderator: Oberlus

Forum rules
Always mention the exact version of FreeOrion you are testing.

When reporting an issue regarding the AI, if possible provide the relevant AI log file and a save game file that demonstrates the issue.
Message
Author
User avatar
LienRag
Cosmic Dragon
Posts: 2148
Joined: Fri May 17, 2019 5:03 pm

Colonialism formula

#1 Post by LienRag »

On a test game I have a very low (nearly useless, actually) value for the colonialism bonus : I should have something like +8 and I have +0,61.
It is three jumps away from a system with three independent planets totaling 8 industry, and no other planet belonging to my Empire is on industry focus in less than three jumps away from the system that has the independant planets.

The code is here (I play with the slowgame snap version) :

Code: Select all

Policy
    name = "PLC_COLONIALISM"
    description = "PLC_COLONIALISM_DESC"
    short_description = "PLC_COLONIALISM_SHORT_DESC"
    category = "ECONOMIC_CATEGORY"
    adoptioncost = 5 + floor(5 + 0.1 * Statistic Count condition = And [
                                            Planet
                                            Unowned
                                            Species
                                            Not ContainedBy Contains And [
                                                Planet
                                                Species
                                                OwnedBy empire = Source.Owner
                                            ]
                                            ResourceSupplyConnected empire = Source.Owner condition = And [
                                                Planet
                                                Species
                                                OwnedBy empire = Source.Owner
                                            ]
                                        ])
    prerequisites = [ "PLC_INTERSTELLAR_INFRA" ]
    exclusions = [ "PLC_ISOLATION" "PLC_NATIVE_APPROPRIATION" "PLC_RACIAL_PURITY" ]
    effectsgroups = [
        [[SPECIES_LIKES_OR_DISLIKES_POLICY_STABILITY_EFFECTS]]

        // industry-focused planets collect industry output from neutral planets that are in nearby systems in the supply network
        EffectsGroup
            scope = And [
                Planet
                OwnedBy empire = Source.Owner
                Focus type = "FOCUS_INDUSTRY"
                ResourceSupplyConnected empire = Source.Owner condition = And [ // needs to be connected to at least one candidate to take industry from...
                    Not InSystem id = RootCandidate.SystemID
                    Planet
                    Species
                    Unowned
                    WithinStarlaneJumps jumps = 3 condition = RootCandidate
                ]
            ]
            effects = SetTargetIndustry value = Value +
                (Statistic Sum
                    value = (LocalCandidate.Industry / max(1.0, Statistic Count condition = And [ // adjust industry of planets that are collected from by the number of planets that might be simultaneously taking from them
                        Not InSystem id = RootCandidate.SystemID
                        Planet
                        OwnedBy empire = Source.Owner
                        Focus type = "FOCUS_INDUSTRY"
                        ResourceSupplyConnected empire = Source.Owner condition = And [
                            Not InSystem id = RootCandidate.SystemID
                            Planet
                            Species
                            OwnedBy empire = Source.Owner
                            Focus type = "FOCUS_INDUSTRY"
                            WithinStarlaneJumps jumps = 3 condition = RootCandidate
                        ]
                    ]))
                    condition = And [ // collect industry from neutral populated planets that are within 3 jumps and that are resource supply connected to the target planet
                        Not InSystem id = Target.SystemID
                        Planet
                        Unowned
                        Species
                        WithinStarlaneJumps jumps = 3 condition = Target
                        ResourceSupplyConnected empire = Source.Owner condition = Target
                    ])
    ]
    graphic = "icons/policies/economic_colonialism.png"

#include "/scripting/policies/policies.macros"
#include "/scripting/common/priorities.macros"
I guess that the problem is in this part below but I wasn't able to find where exactly (the code being quite complex).
I suspect that too many planets are counted in "Statistic Count" but I wasn't able to check if there's a subtle error in the code (there is none that is obvious to me).
Note that I'm not sure how this code would behave in a situation where many planets in the same system are set to Industry (due to the Not InSystem condition).
Also I don't understand why it checks twice for the Industry focus

Code: Select all

            effects = SetTargetIndustry value = Value +
                (Statistic Sum
                    value = (LocalCandidate.Industry / max(1.0, Statistic Count condition = And [ // adjust industry of planets that are collected from by the number of planets that might be simultaneously taking from them
                        Not InSystem id = RootCandidate.SystemID
                        Planet
                        OwnedBy empire = Source.Owner
                        Focus type = "FOCUS_INDUSTRY"
                        ResourceSupplyConnected empire = Source.Owner condition = And [
                            Not InSystem id = RootCandidate.SystemID
                            Planet
                            Species
                            OwnedBy empire = Source.Owner
                            Focus type = "FOCUS_INDUSTRY"
                            WithinStarlaneJumps jumps = 3 condition = RootCandidate
                        ]
                    ]))
Note that the Pedia description for the Policy never specify that the planets in the same system than the independant ones won't benefit from the bonus...

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

Re: Colonialism formula

#2 Post by Ophiuchus »

Save game?
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
LienRag
Cosmic Dragon
Posts: 2148
Joined: Fri May 17, 2019 5:03 pm

Re: Colonialism formula

#3 Post by LienRag »

Ophiuchus wrote: Tue Jan 03, 2023 8:18 amSave game?
Error : file too large.

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

Re: Colonialism formula

#4 Post by Ophiuchus »

LienRag wrote: Wed Jan 04, 2023 10:53 am
Ophiuchus wrote: Tue Jan 03, 2023 8:18 amSave game?
Error : file too large.
did you put it in a compressed archive? also attach to github issue?
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
Oberlus
Cosmic Dragon
Posts: 5715
Joined: Mon Apr 10, 2017 4:25 pm

Re: Colonialism formula

#5 Post by Oberlus »

Also split into multiple parts.

User avatar
LienRag
Cosmic Dragon
Posts: 2148
Joined: Fri May 17, 2019 5:03 pm

Re: Colonialism formula

#6 Post by LienRag »

I didn't, but apparently even the 15 Mb compressed are still too big.

I was able to add it to the issue I created, though.

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

Re: Colonialism formula

#7 Post by Ophiuchus »

the effectsgroups works like this;
  • for each empire: it collects all industry-focused self-owned planets which have unowned in-supply colonies 1 to 3 jumps away as targets. So this gonna be the set of industry sinks.
  • for each target: it looks to add a sum of the local industry (divided by a count) for all unowned in-supply colonies 1 to 3 jumps away of the target. So this is a sum over the set of industry-sources for each sink.
  • For each industry-source, the count used in the divisor is the number of all industry-focused self-owned planets in other (not rootcandidate) systems, which are supply connected to industry-focused self-owned planets (not in the rootcandidate system) inside 3 jump distance from the RootCandidate. I think the RootCandidate set is the industry-source/the result of the Statistic Sum condition (so the unowned in-supply colonies 1 to 3 jumps away of the target). This is mostly confusing/more complex than it should be. The intended result is the number of industry sinks per industry-source.
the idea is that if there N targets, you add to each of those N targets the industry/N (so the local industry gets distributed). note i think this can be milked by multiple empires (which i consider a bug/unintended exploit).

The main problem when coding this is that one does not know N when calculating industry/N, so one has to (re)calculate that number.
LienRag wrote: Tue Jan 03, 2023 1:46 am Note that the Pedia description for the Policy never specify that the planets in the same system than the independant ones won't benefit from the bonus...
geoff should comment. i think same-system bonus should apply. far fetched guess: maybe geoff wanted to add a second effect for distributing in-system PP differently (namely only to sinks in that system) and then forgot(?).
LienRag wrote: Tue Jan 03, 2023 1:46 am..
edit: i put up a fix at https://github.com/freeorion/freeorion/pull/4351

please also test if the result is expected; note your test game is really slow on my machine (too big?), but the fix seems to work

git cherry-pick 91684622971473b36774f8bd2753e9714b1d6fee
Last edited by Ophiuchus on Thu Jan 05, 2023 12:58 am, edited 1 time in total.
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
LienRag
Cosmic Dragon
Posts: 2148
Joined: Fri May 17, 2019 5:03 pm

Re: Colonialism formula

#8 Post by LienRag »

Feudalism works in-system.
But Colonialism doesn't, and the pedia isn't clear about that.

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

Re: Colonialism formula

#9 Post by Ophiuchus »

LienRag wrote: Thu Jan 05, 2023 12:58 am But Colonialism doesn't, and the pedia isn't clear about that.
yes. you already said that. and i said geoff should say what the intention was. and if it is a documentation bug, please kill it.

meanwhile i hopefully fixed the bug as we know it (see end of last post)
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
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Colonialism formula

#10 Post by Geoff the Medio »

Ophiuchus wrote: Wed Jan 04, 2023 10:51 pmi think same-system bonus should apply. far fetched guess: maybe geoff wanted to add a second effect for distributing in-system PP differently (namely only to sinks in that system) and then forgot(?).
The idea was that Feudalism takes from same-system planets, while colonialism takes from other-system planets.

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

Re: Colonialism formula

#11 Post by Geoff the Medio »

Ophiuchus wrote: Wed Jan 04, 2023 10:51 pm the effectsgroups works like this;
  • for each empire: it collects all industry-focused self-owned planets which have unowned in-supply colonies 1 to 3 jumps away as targets. So this gonna be the set of industry sinks.
  • for each target: it looks to add a sum of the local industry (divided by a count) for all unowned in-supply colonies 1 to 3 jumps away of the target. So this is a sum over the set of industry-sources for each sink.
  • For each industry-source, the count used in the divisor is the number of all industry-focused self-owned planets in other (not rootcandidate) systems, which are supply connected to industry-focused self-owned planets (not in the rootcandidate system) inside 3 jump distance from the RootCandidate. I think the RootCandidate set is the industry-source/the result of the Statistic Sum condition (so the unowned in-supply colonies 1 to 3 jumps away of the target). This is mostly confusing/more complex than it should be. The intended result is the number of industry sinks per industry-source.
the idea is that if there N targets, you add to each of those N targets the industry/N (so the local industry gets distributed). note i think this can be milked by multiple empires (which i consider a bug/unintended exploit).
The intention was to make it not beneficial to have multiple sink planets within range of a given source planet. If there are multiple sinks near a source, that source's output should be spread between the sinks, but not change its total output when summed over sinks.

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

Re: Colonialism formula

#12 Post by Ophiuchus »

Geoff the Medio wrote: Sun Jan 08, 2023 12:12 pm
Ophiuchus wrote: Wed Jan 04, 2023 10:51 pmi think same-system bonus should apply. far fetched guess: maybe geoff wanted to add a second effect for distributing in-system PP differently (namely only to sinks in that system) and then forgot(?).
The idea was that Feudalism takes from same-system planets, while colonialism takes from other-system planets.
So this is a documentation bug according to LienRag's report.

One implementation question: should one be able to milk those planets vice versa ( so if one has a second sink in a neighboring system)?
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
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Colonialism formula

#13 Post by Geoff the Medio »

Ophiuchus wrote: Sun Jan 08, 2023 1:25 pmOne implementation question: should one be able to milk those planets vice versa ( so if one has a second sink in a neighboring system)?
...?:
Geoff the Medio wrote: Sun Jan 08, 2023 12:20 pm The intention was to make it not beneficial to have multiple sink planets within range of a given source planet. If there are multiple sinks near a source, that source's output should be spread between the sinks, but not change its total output when summed over sinks.
The idea was partly to make it possible to have a big empire without having to own all the planets in it. That means making it not beneficial to own all the planets. That meant making it give no benefit for having more than one planet directly controlled every 3 systems or so. Because, if it did, then players would want to directly control all the planets. And then they'd complain that they can't have a big empire because when they control too many planets, large empire instability penalties get more problematic.

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

Re: Colonialism formula

#14 Post by Ophiuchus »

With the current implementation, a sink does not get a benefit for unowned colonies in the system where the sink is located.

Using a second sink outside that system does get the benefit from those unowned colonies (if I am not mistaken).

So if I understood the constraints correctly, the second sink should not give extra benefits.

So there are two valid interpretations:

a) unowned colonies in systems with sinks never give benefits

b) unowned colonies in systems with sinks always give benefits. (exactly like they would if they are in neighbouring system

I am for b) and I am not sure which one you intended.
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
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Colonialism formula

#15 Post by Geoff the Medio »

Ophiuchus wrote: Sun Jan 08, 2023 3:55 pma) unowned colonies in systems with sinks never give benefits

b) unowned colonies in systems with sinks always give benefits. (exactly like they would if they are in neighbouring system

I am for b) and I am not sure which one you intended.
I hadn't considered that interaction. Giving benefits from the same system is simpler, so probably OK.

Post Reply