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: 2148
Joined: Fri May 17, 2019 5:03 pm

Re: Excruciating FOCS doubts

#151 Post by LienRag »

Ophiuchus wrote: Mon Dec 27, 2021 10:33 pm if you do not know how to code in python - you probably do not need that power.
Define "know".
I dabble in Python and created some small programs, but I need to check the documentation for nearly everything, and also I don't have fundamental education in software programming nor computer science (so I'm not sure what "structures" are).
I know how to do a loop and a if-else statement, not much more.

I did look at o01eg's code, it makes my brain hurts¹. With documentation/tutorial I probably could begin to understand it, without that I'm not sure I could really make head or tail of this mess.


¹ I'm not suggesting that it's bad, it's cleanly presented and commented, but you seem unaware how this is alien to anyone who's not used to coding and how physically intense a concentration it requires to try to make any sense out of it.
It's a bit like getting back to old mathematical reasoning you haven't used for years and lost familiarity with, you know it's possible to decipher it but it's deciphering, not reading, so very hard to do and sometimes even nauseating.

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

Re: Excruciating FOCS doubts

#152 Post by o01eg »

LienRag wrote: Tue Dec 28, 2021 12:59 am I did look at o01eg's code, it makes my brain hurts¹. With documentation/tutorial I probably could begin to understand it, without that I'm not sure I could really make head or tail of this mess.


¹ I'm not suggesting that it's bad, it's cleanly presented and commented, but you seem unaware how this is alien to anyone who's not used to coding and how physically intense a concentration it requires to try to make any sense out of it.
It's a bit like getting back to old mathematical reasoning you haven't used for years and lost familiarity with, you know it's possible to decipher it but it's deciphering, not reading, so very hard to do and sometimes even nauseating.
But this python code is a copy of https://github.com/freeorion/freeorion/ ... nes.macros
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

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

Re: Excruciating FOCS doubts

#153 Post by Ophiuchus »

o01eg wrote: Tue Dec 28, 2021 5:56 am But this python code is a copy of https://github.com/freeorion/freeorion/ ... nes.macros
and the mines code is very good example. because the python code uses control structures (if-then-else) where the FOCS code uses nested macro expansion for the same purpose.
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
Grummel7
Space Dragon
Posts: 335
Joined: Mon Oct 09, 2017 3:44 pm

Re: Excruciating FOCS doubts

#154 Post by Grummel7 »

Ophiuchus wrote: Tue Dec 28, 2021 7:53 am and the mines code is very good example. because the python code uses control structures (if-then-else) where the FOCS code uses nested macro expansion for the same purpose.
As far as I understand it, that this control structures can however only check for macro argument that are fixed values.
FORTRESS e.g. calls the original macro with [[EG_SYSTEM_MINES(3,70,SOURCE)]]

Calling it with with something like [[EG_SYSTEM_MINES(3,70,Source.name)]] would not work.
FOCS would look for a macro names SYSTEM_MINES_SCOPE_Source.name and the python equivalent throws and exception.

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

Re: Excruciating FOCS doubts

#155 Post by LienRag »

Ophiuchus wrote: Tue Dec 28, 2021 7:53 am
o01eg wrote: Tue Dec 28, 2021 5:56 am But this python code is a copy of https://github.com/freeorion/freeorion/ ... nes.macros
and the mines code is very good example. because the python code uses control structures (if-then-else) where the FOCS code uses nested macro expansion for the same purpose.

I gave it a second try and my brain didn't explode.
It's really a matter of being used to it.

So that's why documentation is really important. I know where to find Python documentation (mostly) but it would be nice to have python-FOCS documentation.

What are the & in o01eg's code, for example ?

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

Re: Excruciating FOCS doubts

#156 Post by Oberlus »

LienRag wrote: Tue Dec 28, 2021 2:47 pm So that's why documentation is really important. I know where to find Python documentation (mostly) but it would be nice to have python-FOCS documentation.

What are the & in o01eg's code, for example ?
If you learn python, that question will be answered.

Start with a python tutorial.

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

Re: Excruciating FOCS doubts

#157 Post by LienRag »

I don't remember ever using them in Python...

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

Re: Excruciating FOCS doubts

#158 Post by Oberlus »

LienRag wrote: Tue Dec 28, 2021 2:56 pm I don't remember ever using them in Python...
If not willing to try a tutorial, you can google for each thing you have doubts about.
For example:

https://www.google.com/search?q=python+ ... d+operator

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

Re: Excruciating FOCS doubts

#159 Post by o01eg »

LienRag wrote: Tue Dec 28, 2021 2:47 pm What are the & in o01eg's code, for example ?
It's an And from FOCS with infix notation.
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
Grummel7
Space Dragon
Posts: 335
Joined: Mon Oct 09, 2017 3:44 pm

Re: Excruciating FOCS doubts

#160 Post by Grummel7 »

o01eg wrote: Tue Dec 28, 2021 3:05 pm It's an And from FOCS with infix notation.
Actually it should be 'and' in python, too.

'&' is a bit-wise operation. Using it for logical operations is bad style at least and may not always do the expected.

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

Re: Excruciating FOCS doubts

#161 Post by Ophiuchus »

Grummel7 wrote: Thu Dec 30, 2021 9:01 pm
o01eg wrote: Tue Dec 28, 2021 3:05 pm It's an And from FOCS with infix notation.
Actually it should be 'and' in python, too.

'&' is a bit-wise operation. Using it for logical operations is bad style at least and may not always do the expected.
uhm not completely sure how to answer. well i'll try:

this is an embedded language (FOCS) inside of python. it is not python. if you expect it to work like python - it will not.

i find infix operator a good choice here, and '&' and '|' are better operators for And and Not than '+' and .. dunno.
In python 'and' and 'or' are keywords and not operators in python (as such you can't override them in python). they work on booleans but FOCS And and Or work on sets like all FOCS conditions (actually they usually shift objects between a matches and a non_matches set). I am not sure if one can do legal python syntax for all scripting purposes when using the keywords - it certainly would fake the hell out of typing.

if you have style guide/best practices for embedded languages in python, please post a link (can be a paper as well), i totally would appreciate that.

So on a more serious note I shout: THIS... IS.. ...FOCS... *pushing-grummel-into-the-well-if-wisdom*. :lol:
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
Grummel7
Space Dragon
Posts: 335
Joined: Mon Oct 09, 2017 3:44 pm

Re: Excruciating FOCS doubts

#162 Post by Grummel7 »

Ophiuchus wrote: Sat Jan 01, 2022 3:29 pm So on a more serious note I shout: THIS... IS.. ...FOCS... *pushing-grummel-into-the-well-if-wisdom*. :lol:
*Grummel7 dives into the well-of-wisdom and comes up wiser*

So

Code: Select all

Planet() & OwnedBy(empire=Source.Owner)
returns a FOCS object that evaluates to a boolean, while

Code: Select all

Planet() and OwnedBy(empire=Source.Owner)
would simply return boolean.

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

Re: Excruciating FOCS doubts

#163 Post by Ophiuchus »

disclaimer: I didnt have a look at how the magic works o01eg is doing.
Grummel7 wrote: Sat Jan 01, 2022 7:14 pmSo

Code: Select all

Planet() & OwnedBy(empire=Source.Owner)
returns a FOCS object that evaluates to a boolean
If it is executed in python it should evaluate to a representation of a FOCS Condition object, which one can evaluate taking parameters context,matches,non_matches. So not a boolean.

but it could also just be that o01eg parses the python code, gets back an abstract syntax tree and runs a visitor along, creating a FOCS condition in the backend for it on the way. in this case, the python code would not be executed
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!

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

Re: Excruciating FOCS doubts

#164 Post by o01eg »

Ophiuchus wrote: Sun Jan 02, 2022 12:10 pm but it could also just be that o01eg parses the python code, gets back an abstract syntax tree and runs a visitor along, creating a FOCS condition in the backend for it on the way. in this case, the python code would not be executed
I considered this option but ended up use executable python.
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
Oberlus
Cosmic Dragon
Posts: 5715
Joined: Mon Apr 10, 2017 4:25 pm

Re: Excruciating FOCS doubts

#165 Post by Oberlus »

Ophiuchus wrote: Sun Jun 06, 2021 9:35 am You could use XXX.DamageStructurePerBattleMax valueref for getting the correct maximum damage against a ship.
What is this for exactly?

For the Flux Lance, it has this value:

Code: Select all

    damageStructurePerBattleMax =
        max(0,ShipPartMeter part = "SR_FLUX_LANCE" meter = Capacity object = Source.ID - Value(Target.Shield))
        * ShipPartMeter part = "SR_FLUX_LANCE" meter = SecondaryStat object = Source.ID
        * ( NamedRealLookup name = "NUM_REAL_COMBAT_ROUNDS_IN_CLOSE_TARGETING_RANGE" + [[ONE_IF_CHARGING]] )
So max(0, damage-target.shield)*shots*(2 or 3), the total damage that the weapon could inflict to a given (shielded) ship during a whole combat.

Should all hulls include this? Is there a default value for those hulls that doesn't have it?
What uses have this valueref presently in backend or scripting? I see they are declared, but what effects have this in game?

Post Reply