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

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

Moderators: Oberlus, Committer

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

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

#1 Post 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?
Last edited by Ophiuchus on Fri Jun 09, 2017 8:43 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
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

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

#2 Post 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.

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

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

#3 Post 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 :)
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
MatGB
Creative Contributor
Posts: 3310
Joined: Fri Jun 28, 2013 11:45 pm

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

#4 Post 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 ;-)
Mat Bowles

Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

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

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

#5 Post 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.
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!

Post Reply