Note that the current implementation has arbitrary parameters for what value = is set to... it can be just Value, or Value + 5, or Max(Value, 5), or Value*3 + 1, or sin(Value^log(Value)), or various other complicated expressions... Point being, don't just think of needing to overload the add methods due to that being the most common case.em3 wrote:My 2c: Value could be made of type with __add__ and __radd__ methods overloaded...
Potential replacement of FOCS with Python
Moderator: Committer
- Geoff the Medio
- Programming, Design, Admin
- Posts: 13587
- Joined: Wed Oct 08, 2003 1:33 am
- Location: Munich
Re: Potential replacement of FOCS with Python
Re: Potential replacement of FOCS with Python
I just wanted to note, that example created by adrian_bother could be discouraging to some people because of the syntax:Geoff the Medio wrote:Note that the current implementation has arbitrary parameters for what value = is set to... it can be just Value, or Value + 5, or Max(Value, 5), or Value*3 + 1, or sin(Value^log(Value)), or various other complicated expressions... Point being, don't just think of needing to overload the add methods due to that being the most common case.
Code: Select all
Set("Detection", Add(Value, 10))
I understand, that designing everything about potential foss replacement in python is a bit too soon, as far as this discussion is concerned. I just wanted to make it sound like a better idea to people that would be bothered by the implied complexity.
https://github.com/mmoderau
[...] for Man has earned his right to hold this planet against all comers, by virtue of occasionally producing someone totally batshit insane. - Randall Munroe, title text to xkcd #556
[...] for Man has earned his right to hold this planet against all comers, by virtue of occasionally producing someone totally batshit insane. - Randall Munroe, title text to xkcd #556
-
- Space Squid
- Posts: 66
- Joined: Mon Aug 27, 2012 7:24 pm
Re: Potential replacement of FOCS with Python
Effects groups could be made callable. That would eliminate any special handling or typing requirements.
Code: Select all
Special(
name = "WORLDTREE_SPECIAL",
description = "WORLDTREE_SPECIAL_DESC",
stealth = 0,
spawnrate = 1.0,
spawnlimit = 1,
location = lambda planet: (
isinstance(planet, Planet)
and (planet.planet_type not in [PlanetType.Asteroids, PlanetType.GasGiant, PlanetType.Inferno])
and (planet.size not in [PlanetSize.TINY, PlanetSize.HUGE])
and not (within_starlane_jumps(planet, jumps=2, condition=lambda system: (
isinstance(system, System)
and not [planet2 for planet2 in system.planets if planet2.owner]
)))),
)
All contributions are submitted under GPL or LGPL v2 or later, or under appropriate Creative Commons licence, consistent with project guidlines.
Re: Potential replacement of FOCS with Python
I think the whole point is for effects to not be executed in python, just constructed from python scripts (compiled into already existing engine structures).spikethehobbit wrote:Effects groups could be made callable. That would eliminate any special handling or typing requirements.Code: Select all
[...]
https://github.com/mmoderau
[...] for Man has earned his right to hold this planet against all comers, by virtue of occasionally producing someone totally batshit insane. - Randall Munroe, title text to xkcd #556
[...] for Man has earned his right to hold this planet against all comers, by virtue of occasionally producing someone totally batshit insane. - Randall Munroe, title text to xkcd #556
-
- Space Squid
- Posts: 66
- Joined: Mon Aug 27, 2012 7:24 pm
Re: Potential replacement of FOCS with Python
Fair enough.em3 wrote:I think the whole point is for effects to not be executed in python, just constructed from python scripts (compiled into already existing engine structures).spikethehobbit wrote:Effects groups could be made callable. That would eliminate any special handling or typing requirements.Code: Select all
[...]
All contributions are submitted under GPL or LGPL v2 or later, or under appropriate Creative Commons licence, consistent with project guidlines.
Re: Potential replacement of FOCS with Python
It's a little necroposting but there are AST modules for Python 2 and Python 3: https://docs.python.org/3/library/ast.html https://docs.python.org/2/library/ast.htmlem3 wrote: ↑Tue Oct 25, 2016 10:07 amI think the whole point is for effects to not be executed in python, just constructed from python scripts (compiled into already existing engine structures).spikethehobbit wrote:Effects groups could be made callable. That would eliminate any special handling or typing requirements.Code: Select all
[...]
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
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
Re: Potential replacement of FOCS with Python
No really. It's been mentioned recently the common desire to substitute FOCS with Python for several reasons (compilation time and requirements, many more people know Python than FOCS, ...). So good to resurrect this.
Re: Potential replacement of FOCS with Python
As far as i get it these modules are for accessing the python a.syntax tree. So usuable for tools and metaprogramming python. I dont see how these help in generating/metaprogramming FOCS (?)o01eg wrote: ↑Sun May 05, 2019 9:20 amIt's a little necroposting but there are AST modules for Python 2 and Python 3: https://docs.python.org/3/library/ast.html https://docs.python.org/2/library/ast.htmlem3 wrote: ↑Tue Oct 25, 2016 10:07 amI think the whole point is for effects to not be executed in python, just constructed from python scripts (compiled into already existing engine structures).spikethehobbit wrote:Effects groups could be made callable. That would eliminate any special handling or typing requirements.Code: Select all
[...]
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!
Look, ma... four combat bouts!
Re: Potential replacement of FOCS with Python
I suppose this is the entire thread about replace FOCS with Python.Ophiuchus wrote: ↑Sun May 05, 2019 6:30 pmAs far as i get it these modules are for accessing the python a.syntax tree. So usuable for tools and metaprogramming python. I dont see how these help in generating/metaprogramming FOCS (?)o01eg wrote: ↑Sun May 05, 2019 9:20 amIt's a little necroposting but there are AST modules for Python 2 and Python 3: https://docs.python.org/3/library/ast.html https://docs.python.org/2/library/ast.html
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
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
Re: Potential replacement of FOCS with Python
Yes, but you do not answer my question/the topic.o01eg wrote: ↑Sun May 05, 2019 6:36 pmI suppose this is the entire thread about replace FOCS with Python.Ophiuchus wrote: ↑Sun May 05, 2019 6:30 pmAs far as i get it these modules are for accessing the python a.syntax tree. So usuable for tools and metaprogramming python. I dont see how these help in generating/metaprogramming FOCS (?)o01eg wrote: ↑Sun May 05, 2019 9:20 am
It's a little necroposting but there are AST modules for Python 2 and Python 3: https://docs.python.org/3/library/ast.html https://docs.python.org/2/library/ast.html
The OP is about replacing FOCS as a text format. (For me extending the capabilities would actually be enough).
Python would be used to generate definition structure which we could freeorion content [abstract syntax] tree (FOCT/FOCAST)?
So we are talking about FOCAST not python AST.
I will rephrase:
As far as i get it these modules are for accessing the python a.syntax tree. So usuable for tools and metaprogramming python. I dont see how these help in generating/metaprogramming freeorion content.
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!
Look, ma... four combat bouts!
Re: Potential replacement of FOCS with Python
A bump here as oleg mentioned and adrian is working on something related.
Given I have the content specified in python and I have the ability to understand what has to be done (by some binding or analysing the python file using python-ast)
Given I have the content specified in python and I have the ability to understand what has to be done (by some binding or analysing the python file using python-ast)
- (how) can I create all game structures in the game via python?
- (how) can I start python in the backend?
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!
Look, ma... four combat bouts!
- Geoff the Medio
- Programming, Design, Admin
- Posts: 13587
- Joined: Wed Oct 08, 2003 1:33 am
- Location: Munich
Re: Potential replacement of FOCS with Python
Your questions are unclear. Do you mean:Ophiuchus wrote: ↑Sun May 31, 2020 8:06 amGiven I have the content specified in python and I have the ability to understand what has to be done (by some binding or analysing the python file using python-ast)
- (how) can I create all game structures in the game via python?
- (how) can I start python in the backend?
-How can you use Python right now to define stuff like building types or species? You can't. Such a system doesn't exist.
-How could you use Python if FOCS was replaced with a Python parser to defined stuff like buildings or species? Don't know; such a system doesn't exist.
-How can you implement support for such a system? Not sure; it would be a bit complicated to set up.
Python is already run on the server for turn events, and for AI clients. You can check how that's done in the C++ code by searching... Perhaps that answers part of your questions?
Re: Potential replacement of FOCS with Python
Ophiuchus wrote: ↑Sun May 31, 2020 8:06 am A bump here as oleg mentioned and adrian is working on something related.
Given I have the content specified in python and I have the ability to understand what has to be done (by some binding or analysing the python file using python-ast)
- (how) can I create all game structures in the game via python?
- (how) can I start python in the backend?
- I suppose you should feed file to ast.parse. Then convert python object to AST object with PyAST_obj2mod. And then somehow process resulting structure.
- Maybe you mean background?
I suppose it could be done by using sub-interpreters in non-main thread.
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
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
Re: Potential replacement of FOCS with Python
Yes, thank you. I am interested in creating the c++ building types/species... via python. So it seems that is currently not possible.Geoff the Medio wrote: ↑Sun May 31, 2020 10:14 amYour questions are unclear. Do you mean:Ophiuchus wrote: ↑Sun May 31, 2020 8:06 amGiven I have the content specified in python and I have the ability to understand what has to be done (by some binding or analysing the python file using python-ast)
- (how) can I create all game structures in the game via python?
- (how) can I start python in the backend?
-How can you use Python right now to define stuff like building types or species? You can't. Such a system doesn't exist.
-How could you use Python if FOCS was replaced with a Python parser to defined stuff like buildings or species? Don't know; such a system doesn't exist.
-How can you implement support for such a system? Not sure; it would be a bit complicated to set up.
Python is already run on the server for turn events, and for AI clients. You can check how that's done in the C++ code by searching... Perhaps that answers part of your questions?
Does any of you pythonistas have experience with creating c data structures from python? Or would i need to provide an api like we have and expose that?
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!
Look, ma... four combat bouts!
- Geoff the Medio
- Programming, Design, Admin
- Posts: 13587
- Joined: Wed Oct 08, 2003 1:33 am
- Location: Munich
Re: Potential replacement of FOCS with Python
Even if there was a way to create the C++ data structures in Python, similar to how they are created when parsing FOCS files, you'd need to then pass them into the server and clients, either sending them from server to clients or ensuring they are created the same way on both. You'd need some sort of API exposed to do that regardless.Ophiuchus wrote: ↑Sun May 31, 2020 2:11 pmI am interested in creating the c++ building types/species... via python. So it seems that is currently not possible.
Does any of you pythonistas have experience with creating c data structures from python? Or would i need to provide an api like we have and expose that?