New town names

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Post Reply
kokutetsu
Engineer
Engineer
Posts: 31
Joined: 02 Dec 2018 05:50

New town names

Post by kokutetsu »

So I downloaded Erato's DPRK Town Names file (download/file.php?id=203852) and I edited the names.nml file to expand it. However, I've been searching for a couple days now but I can't for the life of me figure out how to compile it to make a grf... can someone please help? Thanks! :)
User avatar
Redirect Left
Tycoon
Tycoon
Posts: 7238
Joined: 22 Jan 2005 19:31
Location: Wakefield, West Yorkshire

Re: New town names

Post by Redirect Left »

Have you looked on OpenTTD wiki?
One of these pages may have what you're searching for;

https://dev.openttdcoop.org/projects/nml - NML is I beleive what most people use for GRFs these days.
https://wiki.openttd.org/NewGRF_development_tools
Image
Need some good tested AI? - Unofficial AI Tester, list of good stuff & thread is here.
kokutetsu
Engineer
Engineer
Posts: 31
Joined: 02 Dec 2018 05:50

Re: New town names

Post by kokutetsu »

Redirect Left wrote:Have you looked on OpenTTD wiki?
One of these pages may have what you're searching for;

https://dev.openttdcoop.org/projects/nml - NML is I beleive what most people use for GRFs these days.
https://wiki.openttd.org/NewGRF_development_tools
I've downloaded the NML but the documentation is kinda opaque (or I'm just dense?)... when I try to run (Windows) it a command line window comes up, there's some writing for an instant that I then can't see because it closes at once...

I've also looked around on the wiki but I couldn't find anything obvious about how to compile NML source into a usable GRF...
User avatar
Pyoro
Tycoon
Tycoon
Posts: 2558
Joined: 17 Oct 2008 12:17
Location: Virgo Supercluster

Re: New town names

Post by Pyoro »

This should help: https://www.tt-wiki.net/wiki/NMLTutorial

Quickest way for one time use (imo) is shove everything in appropriate NML folder; navigate there with CMD, type in nml command; done. Tutorial should explain the details ;)
User avatar
kamnet
Moderator
Moderator
Posts: 8548
Joined: 28 Sep 2009 17:15
Location: Eastern KY
Contact:

Re: New town names

Post by kamnet »

kokutetsu wrote:... when I try to run (Windows) it a command line window comes up...
NML is not a Windows GUI executable, it is a command line executable.
kokutetsu
Engineer
Engineer
Posts: 31
Joined: 02 Dec 2018 05:50

Re: New town names

Post by kokutetsu »

Thanks for the replies! They've been a help - I've got NML installed.

But when I tried to run
nmlc -c --grf dprknames2.grf dprknames.pnml
It returned
Illegal character '#' (character code 0x23) at "dprknames.pnml", line 2, column 1
The entire body of said pnml file is
// Define GRF
#include "src/header.pnml"
#include "src/names.pnml"

//cd /mnt/c/Temp/MMT
//make -B
I didn't write this part, this was part of the original source I downloaded that (I imagine) works properly... the only thing I changed anywhere was the stuff in the names.pnml file.
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: New town names

Post by planetmaker »

nmlc -c --grf dprknames2.grf dprknames.pnml
That is the correct way to call it - on an nml file.

The filename already gives it away, it ends with pnml:
// Define GRF
#include "src/header.pnml"
#include "src/names.pnml"

//cd /mnt/c/Temp/MMT
//make -B
the "p" indicates that the file still needs pre-processing. The #include statements and similar are not part of the nml syntax itself. That file still needs pre-processing so that the files mentioned there are included at the given point, in this case by the cpp pre-processor (that is of the gcc). Maybe you can get away with simply copy & pasting the mentioned files in place of the #include "filename".

Usually such filenames are used to easier separate different parts of projects and then they are built using make and cpp as suggested by the last commented line in your quote. Those commands could be available also on windows when you install them in the linux subsystem.
kokutetsu
Engineer
Engineer
Posts: 31
Joined: 02 Dec 2018 05:50

Re: New town names

Post by kokutetsu »

planetmaker wrote:Maybe you can get away with simply copy & pasting the mentioned files in place of the #include "filename".
I'm not sure I get what you mean - do you mean to copy & paste the actual contents of the two .pnml files in place of the #include lines?
Usually such filenames are used to easier separate different parts of projects and then they are built using make and cpp as suggested by the last commented line in your quote. Those commands could be available also on windows when you install them in the linux subsystem.
Hmm, that sounds like a lot of reading and learning for me before I dare take a stab at that... I'm not even entirely sure I understood it right, so for now I'll just give your first suggestion a try and hope for the best.
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: New town names

Post by planetmaker »

You could simply start with something where it is already in one file (+ lang files):
https://dev.openttdcoop.org/projects/du ... tnames.nml
kokutetsu
Engineer
Engineer
Posts: 31
Joined: 02 Dec 2018 05:50

Re: New town names

Post by kokutetsu »

planetmaker wrote:You could simply start with something where it is already in one file (+ lang files):
https://dev.openttdcoop.org/projects/du ... tnames.nml
Oh, well that's an idea too! I think I'll do that for now with real town names, and then save the thing I've written with pre and post sections for generating fake town names, for later...
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: New town names

Post by planetmaker »

http://bundles.openttdcoop.org/german-t ... es/LATEST/ is a more complex example, including real and fantasy names composed from parts. Its original is also in a format which needs a pre-compiler, but for convenience there's the pre-compiled NML as well on the build artefacts server.
kokutetsu
Engineer
Engineer
Posts: 31
Joined: 02 Dec 2018 05:50

Re: New town names

Post by kokutetsu »

I'm going ahead with doing just a simple grf with real place names for the moment, so I tried to test-compile that dtnames.nml file, but when I tried to run the nmlc etc command, it returned this:
nmlc ERROR: "dtnames.nml", line 16: Unknown string "STR_GRF_DESCRIPTION"
I made no changes at all to the file, just tried to compile it as I got it from the link...

To take a little step back, I decided to do this test-compile of the original dtnames.nml because when I tried compiling the .nml file I made based on it, I got a return of:
nmlc ERROR: "dprknames2.nml", line 1: Syntax error, unexpected token "{"
This surprised me, because the first line of the file contains only
//
User avatar
Pyoro
Tycoon
Tycoon
Posts: 2558
Joined: 17 Oct 2008 12:17
Location: Virgo Supercluster

Re: New town names

Post by Pyoro »

You need the lang folder of the project too.

The tutorial explains this, but GRFs are basically made of
a) a .nml file where all the code goes
b) a lang folder where all the strings are defined for different game languages (like STR_GRF_DESCRIPTION)
c) a grf folder where all the graphics go; typically not needed for town names
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4763
Joined: 09 Sep 2007 05:03
Location: home

Re: New town names

Post by Alberth »

just grab the source archive from the nightlies (german-townnames-nightly-r35-source.tar.gz)
simplest is to drop the nml file in the 'german-townnames-nightly-r35-source' directory, change the directory of the shell to it ('cd german-townnames-nightly-r35-source') and run nmlc.

Otherwise, you need the 'lang' directory next to the nml file. The language files contain the texts describing the content of the grf, and setting parameters. (they are utf-8 text files, you can open them with a somewhat sane text editor.)


As for error messages, line numbers are not absolutely correct for several reasons. They do give a good rough indication of the point of where the compiler gives up though (which is not always the same as the point of the error), especially if your file is longer than about 5 lines. Off by 1 is quite comon, especially around white space (comment doesn't exist for the compiler, line 1 is "" to it rather than the "//" that you see.)
Being a retired OpenTTD developer does not mean I know what I am doing.
kokutetsu
Engineer
Engineer
Posts: 31
Joined: 02 Dec 2018 05:50

Re: New town names

Post by kokutetsu »

Well, progress - I figured out what the issue about the "token {" was... well now I've installed notepad++ and that issue is settled!

I've got my new grf successfully compiled, started a new game to test, and (naturally!) noticed an issue... as you can see in the picture, a town was generated with a blank name. If you look at the names in the town directory list, you'll see that all the UTF-8 characters show up just fine, so that's not the issue.

Image

I started three new games, and one blank-name town turned up in each of the three games... but in the nml body there isn't a line that's text(" ", 1), of course...
Attachments
nameissue.png
nameissue.png (680.3 KiB) Viewed 1253 times
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4763
Joined: 09 Sep 2007 05:03
Location: home

Re: New town names

Post by Alberth »

I started three new games, and one blank-name town turned up in each of the three games... but in the nml body there isn't a line that's text(" ", 1), of course...
First of all, congrats, you got stuff running, and it worked (mostly).

I fully agree with you that the name of the town is not visible. Having a name consisting of a single space is one form of an 'empty' name (technically it's not empty, it's a non-visible non-empty name, since the string has one space character in it). Other options are of course

Code: Select all

text("", 1)
(0 spaces, ie the really empty string) or

Code: Select all

text("  ", 1)
(with 2 spaces), etc.

Iirc, a town name may consist of several parts, where parts can be optional, so another way to construct an empty name, is to have all parts optional, so the computer can skip all parts, leaving you with 'nothing' as a name.

As for how to find what happens, you can debug it. Make a copy of the source code and store it somewhere out of the way. Then start hacking the source code. Make it smaller/simpler while you check if the problem continues to exist. If you have 15 choices somewhere, 2 are sufficient, etc. At some point the problem will go away. Then you know the crucial change was in the edits that you did since the last test. Eventually, you will find the edit that makes the problem disappear. At that point, try to understand why the behavior changes (computer use rules for deciding something, understand that rule).
Once you understand the rule, go back to your stored copy (and make a copy of your copy, just in case the fix doesn't work out as you expect), and fix the problem.

Another way is to get external help, like here at the forum, or at the #openttd IRC channel. You will need to supply the source code, so others can read it, look for errors, or even debug it like described above. Generally, you'll get pointed to the problem spot, so you can fix it.
Being a retired OpenTTD developer does not mean I know what I am doing.
kokutetsu
Engineer
Engineer
Posts: 31
Joined: 02 Dec 2018 05:50

Re: New town names

Post by kokutetsu »

Alberth wrote:First of all, congrats, you got stuff running, and it worked (mostly).
Thanks! It's a small thing, to be sure, but it does boost one's confidence... :)
I fully agree with you that the name of the town is not visible. Having a name consisting of a single space is one form of an 'empty' name (technically it's not empty, it's a non-visible non-empty name, since the string has one space character in it). Other options are of course

Code: Select all

text("", 1)
(0 spaces, ie the really empty string) or

Code: Select all

text("  ", 1)
(with 2 spaces), etc.

Iirc, a town name may consist of several parts, where parts can be optional, so another way to construct an empty name, is to have all parts optional, so the computer can skip all parts, leaving you with 'nothing' as a name.
Well, this one is using only a single group of names - so unlike the town name grfs that call a "prefix" and a "suffix" to create random names by combining two elements, this is just calling a single element, without making any combinations.

And in that single group, there are no elements like

Code: Select all

text("", 1)
or

Code: Select all

text("  ", 1)
- each one has an actual string of text (town name) within the double quotes.

Here is the entire nml: https://pastebin.com/vek7dx6a

In the meantime I'm going to go through the code chunk by chunk as you suggest.
at the #openttd IRC channel
I've been connected there for a week now and have seen no activity at all apart from some automated (?) stuff from DevZone...
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4763
Joined: 09 Sep 2007 05:03
Location: home

Re: New town names

Post by Alberth »

There are several #openttd channels, You're in #openttdcoop.devzone ?

Try the #openttd channel (without "coop" and without ".<something>")

EDIT: Ah, a pastebin, thanks.
So, what do you think

Code: Select all

town_names {
    styles : string(STR_STYLES);
    {
        text("", 5),
        town_names(prefix, 1),
    }
}
does, in particular the 'text("", 5),' line ?

Just to be sure we're on the same page, I'll tell you any way :)
This is the main entry point. It makes a random selection between "", and a name in 'prefix' (the long list above), with a ratio 5:1. Since OpenTTD discards double names, you'll get only one "" name in the game.

The solution is to delete that line of course. But then this code makes a selection from 1 option only, which is a bit silly. Instead move the long list of names to here, and drop the 'prefix' block.

For more extensive documentation, see https://newgrf-specs.tt-wiki.net/wiki/NML:Town_names
Being a retired OpenTTD developer does not mean I know what I am doing.
kokutetsu
Engineer
Engineer
Posts: 31
Joined: 02 Dec 2018 05:50

Re: New town names

Post by kokutetsu »

Ohhhhh well now I feel silly for not having thought of that!

I went ahead and changed it as you suggested, so that now it's like

Code: Select all

town_names {
    styles : string(STR_STYLES);
    {
        text("foo", 5),
        text("bar", 5),
        text("baz", 5),
    }
}
and it's working just fine! Thank you!! :)

And yeah, I've now joined #openttdcoop... I've been sitting on #openttdcoop.devzone all this time...

Well, now time to start learning the less easy stuff! :)
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 9 guests