Excruciating FOCS doubts

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

Moderators: Oberlus, Committer

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

Re: Excruciating FOCS doubts

#136 Post by LienRag »

Geoff the Medio wrote: Wed Dec 22, 2021 9:23 pm How should an automated system know which species should like or dislike your arbitrary new building or other content?
Well, a dual system (putting the likes/dislikes either in the Species focs files or in the buildings/policies focs file) would allow to create a Policy focs file and let the system manage the likes and dislikes resulting from it.
An automated way of modifying all the Species files from the new Policy/Building file would have a similar result I guess.
Thing is, when one updates the game and simply copy the files to the folder dedicated to his modded versions, new FOCS files are not overwritten but the modified FOCS files are, so one has to re-copy all the modified ones to the specific folder they belong to, which can be tedious if there are a lot to change - and if the new files differ from the old files, then the new get overwritten if the player doesn't do a diff before the copy. So basically, it's a complete mess.


Geoff the Medio wrote: Wed Dec 22, 2021 9:23 pmYou can add a macro to like / dislike lists and add your building to the macro definition.
Interesting idea.
But I'm not sure that I get it entirely...
The macro would be different for each Species ?
Or it would be a general macro used by all Species ? Then what would be its syntax ?
Is there a "case" in FOCS ?

Code: Select all

Dislikes [
Case Species =
Scylior : Neutronium Forge
Etty : Interstellar Lighthouse
]

Geoff the Medio wrote: Wed Dec 22, 2021 9:23 pm
LienRag wrote: Wed Dec 22, 2021 7:59 pm That would explain though why so many Policies have likes/dislikes either existent or stub-like.
Not sure what that means, but most species were semi-randomly given a few policies to like or dislike, along with various other types of liked or disliked content.
I meant that a lot of the new Policies (those created after the initial release of the Influence version) have no likes/dislikes from Species, and my hypothesis is that it's because the creator of these Policies (and buildings) did not care to go to each Species file to add a like or dislike.

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

Re: Excruciating FOCS doubts

#137 Post by Geoff the Medio »

LienRag wrote: Mon Dec 27, 2021 9:14 am...when one updates the game and simply copy the files to the folder dedicated to his modded versions, new FOCS files are not overwritten but the modified FOCS files are
I don't understand the what this means. If you copy a directory into another, new files will be copied as well. If you use git to control the versions, then everything also works fine for removing and adding files when switching between revisions.
The macro would be different for each Species ?
You could create a few themed macros that you can add to selected species that would add the same set of likes or dislikes to all the species that have the macros in their likes / dislikes lists.
Is there a "case" in FOCS ?
Macros do text substitution, that's all. There is no "if", but there are parameters that are substituted.
I meant that a lot of the new Policies (those created after the initial release of the Influence version) have no likes/dislikes from Species, and my hypothesis is that it's because the creator of these Policies (and buildings) did not care to go to each Species file to add a like or dislike.
Probably partly true, though partly also because some policies were intentionally left off my list of likeable policies, and I stopped adding likes and dislikes to species without having gone through all of them, so the species alphabetically from SP_FURTHEST to SP_SCYLIOR don't have many / any policy preferences, while the others mostly do. I figured I'd eventually finish going through them with more of a focus on the newer policies since I did the initial like / dislike adds.

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

Re: Excruciating FOCS doubts

#138 Post by LienRag »

Geoff the Medio wrote: Mon Dec 27, 2021 9:44 am
LienRag wrote: Mon Dec 27, 2021 9:14 am...when one updates the game and simply copy the files to the folder dedicated to his modded versions, new FOCS files are not overwritten but the modified FOCS files are
I don't understand the what this means. If you copy a directory into another, new files will be copied as well. If you use git to control the versions, then everything also works fine for removing and adding files when switching between revisions.
Yeah, I probably should learn git.
But then you build each new version of the game ? I use the Snap usually, won't work with my own git repository.
What I do it refresh the snap, then copy the directory in my ~/freeorion directory. Which means that all the files that exist in both are overwritten (so I lose all modifications I made to existing files) and the only files that are not overwritten are the ones I created entirely.
Then I have to check if the ones I modified (like focus.macro when I have a special that can provide a Growth focus) have changed since last version, and either copy-paste my own modifications in them (for the en.txt file which is nearly always different) or overwrite the standard file with my modified one if the standard file is the same than the base I modified.
So being able to put all the modifications in one file when I create a new thing is way simpler (that's why I prefer to create a new tech that unlocks a building so I can put "unlocked by" in the new tech description, rather than having to modify a standard tech to add to it that it unlocks the new building).

Geoff the Medio wrote: Mon Dec 27, 2021 9:44 am
LienRag wrote: Mon Dec 27, 2021 9:14 amThe macro would be different for each Species ?
You could create a few themed macros that you can add to selected species that would add the same set of likes or dislikes to all the species that have the macros in their likes / dislikes lists.
Oh, right. But if I do it on my end, it doesn't really solve the problem above since I'd still have to modify each Species FOCS file with the new macro at each revision...

Geoff the Medio wrote: Mon Dec 27, 2021 9:44 am
LienRag wrote: Mon Dec 27, 2021 9:14 amIs there a "case" in FOCS ?
Macros do text substitution, that's all. There is no "if", but there are parameters that are substituted.
I understand the "text substitution" part I guess (the name of the macro is substituted by the entirety of the macro file content inside the calling file), but could you explain/give an example of parameters substitution ? I don't really get it...

User avatar
Oberlus
Cosmic Dragon
Posts: 5714
Joined: Mon Apr 10, 2017 4:25 pm

Re: Excruciating FOCS doubts

#139 Post by Oberlus »

LienRag wrote: Mon Dec 27, 2021 10:03 am I understand the "text substitution" part I guess (the name of the macro is substituted by the entirety of the macro file content inside the calling file), but could you explain/give an example of parameters substitution ? I don't really get it...
An example could help:

You have this macro in species/common/detection.macros

Code: Select all

// param 1: species
COMMUNAL_VISION
'''        EffectsGroup
            description = "COMMUNAL_VISION_DESC"
            scope = And [
                Planet
                Species name = "@1@"
                Not OwnedBy empire = Source.Owner   // would be redundant to re-assign visbility to own planets
            ]
            activation = And [
                Planet
                Not Unowned
            ]
            effects = SetVisibility empire = Source.Owner visibility = Full 
'''
George have this in its FOCS file:

Code: Select all

[[COMMUNAL_VISION(SP_GEORGE)]]
The parser will make the substitutions, so that "[[COMMUNAL_VISION(SP_GEORGE)]]" is readed as:

Code: Select all

EffectsGroup
            description = "COMMUNAL_VISION_DESC"
            scope = And [
                Planet
                Species name = "SP_GEORGE"
                Not OwnedBy empire = Source.Owner   // would be redundant to re-assign visbility to own planets
            ]
            activation = And [
                Planet
                Not Unowned
            ]
            effects = SetVisibility empire = Source.Owner visibility = Full
Notice how @1@ is now just the text that appeared between parenthesis in the call to the macro.

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

Re: Excruciating FOCS doubts

#140 Post by Geoff the Medio »

LienRag wrote: Mon Dec 27, 2021 10:03 amWhat I do it refresh the snap, then copy the directory in my ~/freeorion directory. Which means that all the files that exist in both are overwritten (so I lose all modifications I made to existing files) and the only files that are not overwritten are the ones I created entirely.
Then I have to check if the ones I modified (like focus.macro when I have a special that can provide a Growth focus) have changed since last version, and either copy-paste my own modifications in them (for the en.txt file which is nearly always different) or overwrite the standard file with my modified one if the standard file is the same than the base I modified.
So being able to put all the modifications in one file when I create a new thing is way simpler (that's why I prefer to create a new tech that unlocks a building so I can put "unlocked by" in the new tech description, rather than having to modify a standard tech to add to it that it unlocks the new building).
I think you need a better workflow that can handle adding and removing files, not for the scripting engine and tech gameplay mechanics to be modified...
I understand the "text substitution" part I guess (the name of the macro is substituted by the entirety of the macro file content inside the calling file), but could you explain/give an example of parameters substitution ? I don't really get it...
For a more self-contained example, see: https://github.com/freeorion/freeorion/ ... xt#L18-L38

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

Re: Excruciating FOCS doubts

#141 Post by LienRag »

Oberlus wrote: Mon Dec 27, 2021 10:18 am
LienRag wrote: Mon Dec 27, 2021 10:03 am I understand the "text substitution" part I guess (the name of the macro is substituted by the entirety of the macro file content inside the calling file), but could you explain/give an example of parameters substitution ? I don't really get it...
An example could help:
(...)
Oh, thanks !
I get it now.

Would it be possible to have "if" or "case" conditions to this parameter ?

Like, in your example :

Code: Select all

// param 1: species
COMMUNAL_VISION
'''        EffectsGroup
            description = "COMMUNAL_VISION_DESC"
            scope = And [
                Planet
                Species name = "@1@"
                Not OwnedBy empire = Source.Owner   // would be redundant to re-assign visbility to own planets
            ]
            activation = And [
                Planet
                Not Unowned
            ]
            effects = SetVisibility empire = Source.Owner visibility = Full 
            if @1@ = [[SPECIES_NAME_GEORGES]] 
            [effects =  SetTargetInfluence = Target + 1 ] // just an example
            
'''


Geoff the Medio wrote: Mon Dec 27, 2021 10:28 am I think you need a better workflow that can handle adding and removing files, not for the scripting engine and tech gameplay mechanics to be modified...
Maybe, would you suggest one ? Or am I the only one with this problem ?
Does everybody that tinkers with FOCS file then build their own version of the game from their git repository ?
Isn't it a bit opposite to the goal of making customizing content easy ?
I certainly would never have started modifying FOCS files if I had to first create my own repository and build the game from it...
Last edited by LienRag on Mon Dec 27, 2021 10:49 am, edited 1 time in total.

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

Re: Excruciating FOCS doubts

#142 Post by Ophiuchus »

LienRag wrote: Mon Dec 27, 2021 10:03 am But then you build each new version of the game ? I use the Snap usually, won't work with my own git repository.
you can point the game to a "default" folder somewhere. So, you could get the game via snap and manage the FOCS files in parallel using git
LienRag wrote: Mon Dec 27, 2021 10:03 am
Geoff the Medio wrote: Mon Dec 27, 2021 9:44 am
LienRag wrote: Mon Dec 27, 2021 9:14 amThe macro would be different for each Species ?
You could create a few themed macros that you can add to selected species that would add the same set of likes or dislikes to all the species that have the macros in their likes / dislikes lists.
Oh, right. But if I do it on my end, it doesn't really solve the problem above since I'd still have to modify each Species FOCS file with the new macro at each revision...
git will merge the changes, you simply have to pull in the latest master. learn git, its good (and a great skill to have)
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: 2146
Joined: Fri May 17, 2019 5:03 pm

Re: Excruciating FOCS doubts

#143 Post by LienRag »

Ophiuchus wrote: Mon Dec 27, 2021 10:47 am learn git, its good (and a great skill to have)
I definitely should, but should we expect any new tinkerer and wannabe contributor to know git ?

User avatar
Oberlus
Cosmic Dragon
Posts: 5714
Joined: Mon Apr 10, 2017 4:25 pm

Re: Excruciating FOCS doubts

#144 Post by Oberlus »

LienRag wrote: Mon Dec 27, 2021 10:51 am should we expect any new tinkerer and wannabe contributor to know git ?
No need for git if it's just to tinker.

Contributors to the code can't really contribute if they can't code or contribute their code, so it is reasonable to expect wannabe contributors to also be wannabe git users.
Learning git is doable for anyone that devotes some time to read a tutorial, try stuff and ask relevant questions (one art contributor, with no known programming skills, learned git to be able to do the PRs with her species portraits; I learned git to make my first PR for FreeOrion; MatGB learned git to contribute to FreeOrion).
LienRag, if you devote to learning git 10% of the time you currently use to brainly criticize suggestions in this forum, you'll be making your first flawlessly PR by the end of this year.

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

Re: Excruciating FOCS doubts

#145 Post by Geoff the Medio »

LienRag wrote: Mon Dec 27, 2021 10:46 amWould it be possible to have "if" or "case" conditions to this parameter ?
In short, no:
Geoff the Medio wrote: Mon Dec 27, 2021 9:44 amMacros do text substitution, that's all. There is no "if", but there are parameters that are substituted.
But to elaborate, the macro substitution mechanism isn't going to be expanded into another layer of scripting language that generates the script with control flow / logic. If that was really needed, then it could be implemented in FOCS itself. In this case, you can just add it to the single species script, though.

To elaborate a bit more, the substitutions are iterated for nesting, so you can do a bit more with substitutions into other substitutions, like https://github.com/freeorion/freeorion/ ... os#L32-L44 so maybe can set something up that would be useful, where a substitution would pass a parameter that's appended to another macro lookup that then resolves to different things depending what's passed in.

o01eg
Programmer
Posts: 2004
Joined: Sat Dec 10, 2011 5:46 am

Re: Excruciating FOCS doubts

#146 Post by o01eg »

Geoff the Medio wrote: Mon Dec 27, 2021 11:48 am
LienRag wrote: Mon Dec 27, 2021 10:46 amWould it be possible to have "if" or "case" conditions to this parameter ?
In short, no:
Geoff the Medio wrote: Mon Dec 27, 2021 9:44 amMacros do text substitution, that's all. There is no "if", but there are parameters that are substituted.
But to elaborate, the macro substitution mechanism isn't going to be expanded into another layer of scripting language that generates the script with control flow / logic. If that was really needed, then it could be implemented in FOCS itself. In this case, you can just add it to the single species script, though.

To elaborate a bit more, the substitutions are iterated for nesting, so you can do a bit more with substitutions into other substitutions, like https://github.com/freeorion/freeorion/ ... os#L32-L44 so maybe can set something up that would be useful, where a substitution would pass a parameter that's appended to another macro lookup that then resolves to different things depending what's passed in.
I want to mention than new Python FOCS could use control flow operators: https://github.com/freeorion/freeorion/ ... es.py#L214
Gentoo Linux x64, gcc-11.2, boost-1.78.0
Ubuntu Server 22.04 x64, gcc-12, boost-1.74.0
Welcome to the slow multiplayer game at freeorion-lt.dedyn.io.Version 2024-03-15.b3de094.
Donations're welcome:BTC:bc1q007qldm6eppqcukewtfkfcj0naut9njj7audnm

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

Re: Excruciating FOCS doubts

#147 Post by LienRag »

o01eg wrote: Mon Dec 27, 2021 5:56 pm I want to mention than new Python FOCS could use control flow operators: https://github.com/freeorion/freeorion/ ... es.py#L214
Interesting, thanks.
Is there a tutorial somewhere ?
How do these new Python FOCS files interact with the old ones ?

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

Re: Excruciating FOCS doubts

#148 Post by Ophiuchus »

LienRag wrote: Mon Dec 27, 2021 9:37 pm
o01eg wrote: Mon Dec 27, 2021 5:56 pm I want to mention than new Python FOCS could use control flow operators: https://github.com/freeorion/freeorion/ ... es.py#L214
Interesting, thanks.
Is there a tutorial somewhere ?
How do these new Python FOCS files interact with the old ones ?
it is an alternative (and the future) way of creating "FOCS objects" in the backend (conditions, effects, valuerefs). but you have the full power of python to create those. so you can use python as a way of metaprogramming/super-power macros/code generation.
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: 2146
Joined: Fri May 17, 2019 5:03 pm

Re: Excruciating FOCS doubts

#149 Post by LienRag »

Ophiuchus wrote: Mon Dec 27, 2021 9:46 pm it is an alternative (and the future) way of creating "FOCS objects" in the backend (conditions, effects, valuerefs). but you have the full power of python to create those.
That's basically what I understood, yes. But I still don't know how to use them, how to write them, nor how they interact with old FOCS files.
Also, I had conflicting information about "having the full power of python to create those", so I'm even less sure.


Ophiuchus wrote: Mon Dec 27, 2021 9:46 pm so you can use python as a way of metaprogramming/super-power macros/code generation.
I don't really understand what you mean ?
Would I need to generate the FOCS files through a Python file ? That's above my meager Python level...

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

Re: Excruciating FOCS doubts

#150 Post by Ophiuchus »

LienRag wrote: Mon Dec 27, 2021 9:52 pm
Ophiuchus wrote: Mon Dec 27, 2021 9:46 pm so you can use python as a way of metaprogramming/super-power macros/code generation.
I don't really understand what you mean ?
Would I need to generate the FOCS files through a Python file ? That's above my meager Python level...
no, you do not need to generate FOCS files. you need indirectly to generate cpp structures. that is what the parser generates from FOCS files. that is what the python parser generates from python-FOCS files. Those structures are universe object blueprints (e.g. ship designs), conditions, effects, valuerefs... . You can use python instead of FOCS macros and can use e.g. loops and if-else statements to create such universe object blueprints (e.g. ship designs), conditions, effects, valuerefs.

e.g. there exists one colony building type per species. you can not create a single building type to use for any species. but you could create all of those in a python loop.

read closely the code o01eg linked. that is a python "macro" function, creating content based on parameters to the python function.

if you do not know how to code in python - you probably do not need that power. it would work to create lists of likes/dislikes as macro and use those in the species.
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