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

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

Moderator: Committer

Post Reply
Message
Author
Ophiuchus
Vacuum Dragon
Posts: 506
Joined: Tue Sep 30, 2014 10:01 am

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

#1 Post by Ophiuchus » Wed Jun 07, 2017 9:04 am

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.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 12249
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 » Wed Jun 07, 2017 9:26 am

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
Vacuum Dragon
Posts: 506
Joined: Tue Sep 30, 2014 10:01 am

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

#3 Post by Ophiuchus » Wed Jun 07, 2017 10:58 am

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.

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 » Wed Jun 07, 2017 12:39 pm

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
Vacuum Dragon
Posts: 506
Joined: Tue Sep 30, 2014 10:01 am

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

#5 Post by Ophiuchus » Wed Jun 07, 2017 4:39 pm

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.

Post Reply