One complex EffectsGroup or many simpler?

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

Moderators: Oberlus, Committer

Post Reply
Message
Author
User avatar
Oberlus
Cosmic Dragon
Posts: 5713
Joined: Mon Apr 10, 2017 4:25 pm

One complex EffectsGroup or many simpler?

#1 Post by Oberlus »

While reviewing FOCS changes for PR#2756 I got this doubt:

Are the FOCS scripts in techs, weapon parts, etc., like the one in SHP_FIGHTERS_2.focs.txt, executed every turn?

Could one of these alternatives be faster (require less condition checks) than the other?

One EffectsGroup with a single "scope" for different cases and a single "effects" with conditional effects to distinguish between cases.

Code: Select all

    effectsgroups =
        EffectsGroup
            scope = And [
                Ship
                OwnedBy empire = Source.Owner
                Or [
                    DesignHasPart  name = "FT_HANGAR_1"
                    DesignHasPart  name = "FT_HANGAR_2"
                    DesignHasPart  name = "FT_HANGAR_3"
                ]
            ]
            effects = [
                SetMaxCapacity      partname = "FT_HANGAR_1" value = Value + (PartsInShipDesign name = "FT_HANGAR_1" design = Target.DesignID)
                SetMaxSecondaryStat partname = "FT_HANGAR_2" value = Value + 2
                SetMaxSecondaryStat partname = "FT_HANGAR_3" value = Value + 3
                ]

One EffectsGroup for each scope case, each with a simple "effects":

Code: Select all

    effectsgroups = [
        EffectsGroup
            scope = And [
                Ship
                OwnedBy empire = Source.Owner
                DesignHasPart  name = "FT_HANGAR_1"
            ]
            effects = SetMaxCapacity      partname = "FT_HANGAR_1" value = Value + (PartsInShipDesign name = "FT_HANGAR_1" design = Target.DesignID)

        EffectsGroup
            scope = And [
                Ship
                OwnedBy empire = Source.Owner
                DesignHasPart  name = "FT_HANGAR_2"
            ]
            effects = SetMaxSecondaryStat partname = "FT_HANGAR_2" value = Value + 2

        EffectsGroup
            scope = And [
                Ship
                OwnedBy empire = Source.Owner
                DesignHasPart  name = "FT_HANGAR_3"
            ]
            effects =  SetMaxSecondaryStat partname = "FT_HANGAR_3" value = Value + 3
    ]
The "partname" parameter is always mandatory, right?

(Not sure if this should be here or in Programming.)

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

Re: One complex EffectsGroup or many simpler?

#2 Post by Ophiuchus »

the target object is the ship. partname is mandatory, it is used to look up the part to which you want to apply the effect.
I think you are right, splitting the application of the effect would make it (neglibly) faster. OTH i am not sure if splitting the condition helps or not.

I guess the change wont matter either way. But if you are intrrigued: measure both implementations against each other (use the logs luke)
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: One complex EffectsGroup or many simpler?

#3 Post by Geoff the Medio »

I'd guess the multi-effect first example would be a bit faster, as some of the initial filtering doesn't need to be repeated. If attempting to set a part meter that a ship doesn't have generates an error message in the log, that might dominate, though. It might also depend on how many ships would have multiple effects executed on them unnecessarily in the combined case.

But testing to be sure would be best, but qould also probably show minimal difference...

Post Reply