Page 1 of 1

[solved] Effect if species on source building & target match

Posted: Wed Jun 07, 2017 9:04 am
by Ophiuchus
Hi I got a problem with FOCS with an effectsgroup for a building.

I am having a building and one of it effects is that it should add some happiness to all the empires planets with the same kind of species.


This didnt work, I think buildings match no species condition:

Code: Select all

EffectsGroup /* add happiness for species */
            scope = And [
                PopulationCenter
                Species name = Source.Species
                OwnedBy empire = Source.Owner
            ]
            activation = Source
            effects = [
                    SetTargetHappiness value = Value + [[GOVERNMENT_FUNCTION_HAPPINESS_FOR_SPECIES]]
            ]
This doesnt work as well:

Code: Select all

EffectsGroup /* add happiness for species */
            scope = And [
                PopulationCenter
                OwnedBy empire = Source.Owner
            ]
            activation = Source
            effects = [
                If condition = And [ 
                    Object id = Source.PlanetID
                    Planet
                    Species name = Target.Species
                ] effects = [
                    SetTargetHappiness value = Value + [[GOVERNMENT_FUNCTION_HAPPINESS_FOR_SPECIES]]
                ] 
            ]
Current code is in EFFECTS_GROUPS_GOVERNMENT_FUNCTION_HAPPINESS macro.

Any help greatly appreciated. I was bumping my head against this one last night.

Also, shouldnt buildings "have" a species (there is a one-to-one-relationship) for the Species condition to match?

Re: Effect only if species on source building and target mat

Posted: Wed Jun 07, 2017 9:26 am
by Geoff the Medio
Ophiuchus wrote:Any help greatly appreciated. I was bumping my head against this one last night.

Also, shouldnt buildings "have" a species (there is a one-to-one-relationship) for the Species condition to match?
No; Planets or ships have a species. Buildings are on a planet, which can have a species, but don't themselves have a species. So use Source.Planet.Species rather than Source.Species for a building source object.

Re: Effect only if species on source building and target mat

Posted: Wed Jun 07, 2017 10:58 am
by Ophiuchus
Geoff the Medio wrote:
Ophiuchus wrote:Any help greatly appreciated. I was bumping my head against this one last night.

Also, shouldnt buildings "have" a species (there is a one-to-one-relationship) for the Species condition to match?
No; Planets or ships have a species. Buildings are on a planet, which can have a species, but don't themselves have a species. So use Source.Planet.Species rather than Source.Species for a building source object.
Thats even better. Somehow missed (or forgot) that you could chain those references.

Works great now. Thaaanks for your help again :)

Re: Effect only if species on source building and target mat

Posted: Wed Jun 07, 2017 12:39 pm
by MatGB
Hint ;-) Always look at similar effects that already work freeorion/IMPERIAL_PALACE.focs.txt at master · freeorion/freeorion

It's the only way I can get anything done at all, this rolling your own from scratch understanding the actual code is way too complex for me ;-)

Re: Effect only if species on source building and target mat

Posted: Wed Jun 07, 2017 4:39 pm
by Ophiuchus
MatGB wrote:Hint ;-) Always look at similar effects that already work freeorion/IMPERIAL_PALACE.focs.txt at master · freeorion/freeorion

It's the only way I can get anything done at all, this rolling your own from scratch understanding the actual code is way too complex for me ;-)
Oh. I didnt know about that happyness bonus... Thanks.