Scripted Universe Generation!

Programmers discuss here anything related to FreeOrion programming. Primarily for the developers to discuss.

Moderator: Committer

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

Re: Scripted Universe Generation!

#31 Post by Geoff the Medio »

I wanted to move all the lists of names (stars, ships, empires) from separate .txt files into the stringtable (as in the attached patch) so that they can be localized. This is going OK, and based on the OrderedSitrepTemplateStrings() list parsing code, my replacement of the dedicated-file-reading code with stringtable entry parsing in the functions LoadSystemNames, LoadEmpireNames, and LoadShipNames works OK...

Code: Select all

    void LoadSystemNames(std::list<std::string>& names) {
        std::istringstream template_stream(UserString("STAR_NAMES"));
        std::copy(std::istream_iterator<std::string>(template_stream),
                  std::istream_iterator<std::string>(),
                  std::back_inserter<std::list<std::string> >(names));
    }

    void LoadEmpireNames(std::list<std::string>& names) {
        std::istringstream template_stream(UserString("EMPIRE_NAMES"));
        std::copy(std::istream_iterator<std::string>(template_stream),
                  std::istream_iterator<std::string>(),
                  std::back_inserter<std::list<std::string> >(names));
    }
...except for system names, because these are presently actually set in Python code using Python-internal reading of the starname.txt file which never accesses the LoadSystemNames function. Would it be difficult to modify that Python code to get the list of names from C++, already formatted, or to extract the list from the appropriate stringtable entry instead of starnames.txt?
Attachments

[The extension patch has been deactivated and can no longer be displayed.]


User avatar
Vezzra
Release Manager, Design
Posts: 6095
Joined: Wed Nov 16, 2011 12:56 pm
Location: Sol III

Re: Scripted Universe Generation!

#32 Post by Vezzra »

Geoff the Medio wrote:...except for system names, because these are presently actually set in Python code using Python-internal reading of the starname.txt file which never accesses the LoadSystemNames function. Would it be difficult to modify that Python code to get the list of names from C++, already formatted, or to extract the list from the appropriate stringtable entry instead of starnames.txt?
That shouldn't be too difficult to do, although in the meantime LoadEmpireNames is affected too, as I'm using Python-internal reading of empire_names.txt now (these changes haven't been committed yet). I've been planning to throw out the Load*Names functions, as interfacing with C code just to read a plain list of strings from a text file is kind of overkill (with the exception of LoadShipNames, as the CreateShip function I expose to Python chooses a ship name if the calling Python code doesn't provide a name, so CreateShip needs to access the ship names list). This actually applies to all the content files that are used with universe generation, just provide a plain list of strings and don't need parsing (like starting_buildings.txt). Of course, if you move the name lists into the string tables, interfacing with C code to get these lists needs to be provided, and as I said, I don't see any particular difficulties with it. It's just a bit more complex.

However, I wonder why you want to do this? I mean, what's the point of localizing names?

Another thing I wondered (assuming we do that change) when I look at the code of LoadSystemNames and LoadEmpireNames you quoted: These two functions are completely identical (unless my eyes are betraying me) with the exception of the name of the list passed to the UserString call of course. Why not make one generic function and pass the name of the list as parameter, instead of hardcoding that into two separate functions? That would give content scripters more flexibility.

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

Re: Scripted Universe Generation!

#33 Post by Geoff the Medio »

Vezzra wrote:...if you move the name lists into the string tables, interfacing with C code to get these lists needs to be provided, and as I said, I don't see any particular difficulties with it. It's just a bit more complex.
The list will be in a stringtable entry, so couldn't you use existing stringtable lookup methods to get the text which could then be broken into individual names within Python (assuming you don't want to expose a function that returns a vector<string> that C++ has already broken up...)
Vezzra wrote:However, I wonder why you want to do this? I mean, what's the point of localizing names?
For empire and ship names, which are often nouns, localizing would make them understandable in other languages, and potentially less strange looking in the context of non-english interface text. For star names, there could be various non-latin characters used that presently can't be. Cultural references might also make sense in some languages, but not others.
Why not make one generic function and pass the name of the list as parameter, instead of hardcoding that into two separate functions? That would give content scripters more flexibility.
Sure, that could be done. The initial changes were done using the existing function interfaces for relatively simplicity. I don't see how this will help scripters, though...

User avatar
Vezzra
Release Manager, Design
Posts: 6095
Joined: Wed Nov 16, 2011 12:56 pm
Location: Sol III

Re: Scripted Universe Generation!

#34 Post by Vezzra »

Geoff the Medio wrote:The list will be in a stringtable entry, so couldn't you use existing stringtable lookup methods to get the text which could then be broken into individual names within Python
If that means that I can retrieve the entire list with one call to UserString as a block of text where the single entries/names are separated e.g. by line endings (CR, LF or CR/LF), then yes, that would be great. In that case things would become simpler than more complex. UserString is already exposed to Python.
For empire and ship names, which are often nouns, localizing would make them understandable in other languages, and potentially less strange looking in the context of non-english interface text. For star names, there could be various non-latin characters used that presently can't be. Cultural references might also make sense in some languages, but not others.
Ah, yes, that makes sense.
I don't see how this will help scripters, though...
Never mind, I initially thought that I would have to expose these functions. But if the name lists can be retrieved by a call to UserString, then content scripters will have all the flexibility they can possibly want.

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

Re: Scripted Universe Generation!

#35 Post by Geoff the Medio »

Vezzra wrote:If that means that I can retrieve the entire list with one call to UserString as a block of text where the single entries/names are separated e.g. by line endings (CR, LF or CR/LF), then yes, that would be great. In that case things would become simpler than more complex. UserString is already exposed to Python.
That should work... Can you try it and report back (after adding the names lists to the stringtable as in the patch...)?

User avatar
Vezzra
Release Manager, Design
Posts: 6095
Joined: Wed Nov 16, 2011 12:56 pm
Location: Sol III

Re: Scripted Universe Generation!

#36 Post by Vezzra »

Geoff the Medio wrote:Can you try it and report back (after adding the names lists to the stringtable as in the patch...)?
Works smoothly. As you've probably already noticed, I've committed a major update to scripted universe generation today (rev 6608). I went ahead and already included a helper function "getNameList" in UniverseGenerator.py (lines 67-69), so all you need to do if you want to try yourself how it works (or make the necessary adjustments to the Python script before you commit) are the following replacements in UniverseGenerator.py:

Replace line#423:

Code: Select all

star_names = loadStringList("starnames.txt")
with:

Code: Select all

star_names = getNameList("STAR_NAMES")
and line#504:

Code: Select all

empire_names = loadStringList("empire_names.txt")
with:

Code: Select all

empire_names = getNameList("EMPIRE_NAMES")
There are no code changes necessary in C++ code, the LoadSystemNames and LoadEmpireNames functions in UniverseGenerator.* are actually obsolete and can be deleted.

So you can either go ahead and make all the necessary changes yourself, or, if you want, I can make the adjustments to the Python script myself and commit them together with your patch. In that case I just need to know if I should also go ahead and remove starnames.txt and empire_names.txt, as they are rendered obsolete by that change.

User avatar
Vezzra
Release Manager, Design
Posts: 6095
Joined: Wed Nov 16, 2011 12:56 pm
Location: Sol III

Re: Scripted Universe Generation!

#37 Post by Vezzra »

REV 6608

As I've already mentioned in my post above, I've just committed another major update to scripted universe generation. This time I finally got to some of the juicy stuff, most of it related to empire setup. In Python you can now (in addition to what we already had):
  • Set the empires names, pre-unlocked items (techs, ship parts, etc.) and homeworlds (including selecting starting species)
  • Get/set colony focus
  • Add buildings to planets
  • Create ship designs and add them to empires
  • Get the premade ship designs and monster ship designs
  • Create ships and fleets
  • ...
Take a look at UniverseGenerator.py to see what's already done there. This should give you some ideas about what's possible. Just start playing around :)
MatGB wrote:LMK if there's anything you want looking out for
Huh, good question. Most importantly look out for things that might be wrong or you think/feel are different now, as I've tried to stay close to the original behaviour. One thing specifically that I'm unsure of is the RNG. In the Python script I make use of the random library provided by python. Of course you can seed Pythons RNG, but I'm not 100% sure if it gives the same results independent of platform. So if you can check if identical game setup options result in reproducible universes across different platforms, that would be helpful.

Another thing is trying out extrem galaxy settings (like 20 AIs in 10 systems, many AIs and everything set to "high", huge galaxies etc.) and see what results universe generation produces. Just try to give it a hard time.

And then, of course, mess with the Python script. Experiment. Create custom ship designs, add some additional buildings to the homeworlds, create additional fleets, change the homeworlds sizes, etc.

And finally, when playing around with the Python script, you'll probably sooner than later run into something you'd like to do but can't. Or want to be able to do differently. Of course I can't promise that I can/will do it, but it's still important for me to know. One thing in particular is how "user-friendly" the Python interface/script is in its current form. That is, how comfortable content scripters are with the interface, who may not have too much programming experience (some basic programming experience at least is required, Python is a programming language after all). I'm a programmer, I might not see what's probably unnecessarily complicated in the way I've set things up. There certainly is potential for improvement in that area.

So, feedback appreciated :D

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

Re: Scripted Universe Generation!

#38 Post by Geoff the Medio »

Vezzra wrote:So you can either go ahead and make all the necessary changes yourself, or, if you want, I can make the adjustments to the Python script myself and commit them together with your patch. In that case I just need to know if I should also go ahead and remove starnames.txt and empire_names.txt, as they are rendered obsolete by that change.
It'd be better to make the changes in one commit, so could you do it? Feel free to remove the extra txt files as well.

Are the functions c++ LoadEmpireNames and LoadSystemNames still used for anything? Backup C++ universe generation perhaps? If not, I suppose they could be removed, or if so, modified as in my posted code above.

User avatar
Vezzra
Release Manager, Design
Posts: 6095
Joined: Wed Nov 16, 2011 12:56 pm
Location: Sol III

Re: Scripted Universe Generation!

#39 Post by Vezzra »

Geoff the Medio wrote:Are the functions c++ LoadEmpireNames and LoadSystemNames still used for anything?
I just checked to be sure, and it turned out that although these two functions in fact aren't used anywhere else, there exist duplicates of them elsewhere (e.g. Effects.cpp). I suggest putting a generic function (like I suggested, that takes the name of the list as parameter) in util/i18n.*, using that from all the other places and get rid of the duplicates. If you want, I can do that, I just won't have time for it today. But I shall be able to get to it this week.

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

Re: Scripted Universe Generation!

#40 Post by Geoff the Medio »

Vezzra wrote:If you want, I can do that...
You seem motivated to make the change, so I leave it to you...

User avatar
Vezzra
Release Manager, Design
Posts: 6095
Joined: Wed Nov 16, 2011 12:56 pm
Location: Sol III

Re: Scripted Universe Generation!

#41 Post by Vezzra »

Geoff the Medio wrote:You seem motivated to make the change, so I leave it to you...
Done, rev 6611

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

Re: Scripted Universe Generation!

#42 Post by Geoff the Medio »

Can this bug be closed now? Or are the universe tables still used and flawed?

https://sourceforge.net/p/freeorion/bugs/515/

User avatar
Vezzra
Release Manager, Design
Posts: 6095
Joined: Wed Nov 16, 2011 12:56 pm
Location: Sol III

Re: Scripted Universe Generation!

#43 Post by Vezzra »

Geoff the Medio wrote:Can this bug be closed now? Or are the universe tables still used and flawed?
In the C++ universe generation code use of the universe tables determining planet type had been disabled, I guess because of the issue reported in this bug report. I haven't changed anything, but copied the existing behaviour exactly to Python (which is, just select a planet type randomly). However, I did expose the respective universe tables to Python, so it's possible to use them again with only a few adjustments, if we want to know if the issue is still present (which I think it is, because it doesn't look like anyone has done anything about it, and it's not likely the issue just vanished).

So, no, the universe tables causing this issue are not used, but still there and ready to be used, and most likely still flawed.

User avatar
MatGB
Creative Contributor
Posts: 3310
Joined: Fri Jun 28, 2013 11:45 pm

Re: Scripted Universe Generation!

#44 Post by MatGB »

Splitting the thread probably makes sense as this is now a completely separate discussion that'll be harder to find.

On the original thing, broadly what do you need to amend/do to make your own layout? I keep looking at the code and my eyes glaze over but I'm sure once I get the basic principle it'll be easy to go forward with the rest.
Mat Bowles

Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

User avatar
eleazar
Design & Graphics Lead Emeritus
Posts: 3858
Joined: Sat Sep 23, 2006 7:09 pm
Location: USA — midwest

Re: Scripted Universe Generation!

#45 Post by eleazar »

Discussion about star naming has been split to Making Enough Star Names for Very Large Galaxies

Post Reply