Page 1 of 2

About NFO

Posted: 01 Jul 2017 12:44
by DeletedUser10
I'm now learning coding NFO.
I want to code a tram Grf, but how to modify that whether it will be normal rv or be a tram?
I looked up the NFO tutorial but it didn't help.

Re: About NFO

Posted: 01 Jul 2017 18:33
by Eddi

Re: About NFO

Posted: 01 Jul 2017 19:00
by Cadde
More specifically, since the link goes to the bottom of the page.

Miscellaneous flags (1C)

This is a bit mask, with the following bits:

Code: Select all

Bit     Value   Meaning
0        1        Vehicle is a tram/light rail vehicle and requires tram tracks to operate
...

Re: About NFO

Posted: 01 Jul 2017 22:35
by Eddi
Cadde wrote:the link goes to the bottom of the page.
what are you talking about? you must have a weird browser. i've seen browsers mess up page positioning when they're zoomed. my browser takes me to the exact lines you quoted.

Re: About NFO

Posted: 01 Jul 2017 22:43
by Cadde
My "weird browser" has nothing to do with it.

Image

If one doesn't know what to look for, following that link could make them think it's got something to do with callbacks.

But, i can see how it could have something to do with a weird resolution. If you are using an 800x600 pixel screen then it would kinda end up at the top when following said link.

Re: About NFO

Posted: 02 Jul 2017 00:46
by Eddi
oh, so your problem is just that your window is huge and your font size is tiny...

Re: About NFO

Posted: 02 Jul 2017 08:50
by Cadde
Or, maybe my problem is i am not of < peasant class. ;)

Re: About NFO

Posted: 03 Jul 2017 07:45
by DeletedUser10
Thank you everyone.
My browser is also Very Poor,so I didn't realize that.

Re: About NFO

Posted: 04 Jul 2017 09:02
by DeletedUser10
By the way, why everyone says that nml is better than nfo?
Is it easier or more convenient?

Re: About NFO

Posted: 04 Jul 2017 10:53
by Alberth
Both I think. Being able to use readable text to know what property you change helps in avoiding mistakes.
nml also handles conversion of normal infix expressions to nfo codes, and does constant folding.

Re: About NFO

Posted: 04 Jul 2017 13:45
by Cadde
Indeed, NML is a "human readable" format whereas NFO is more along the lines of machine code.
The only advantage NFO has over NML is that NFO (or even hex editing the GRF) has some features that NML doesn't have yet. Or that's my understanding of it anyways.

If you are adding trams, then NML is going to be more than enough for your project.

At the end of the day, NML and NFO both turn into the same product. A grf file.

Re: About NFO

Posted: 05 Jul 2017 07:52
by DeletedUser10
The NML tutorial is too hard to understand, so I chose NFO even it is outdated.

There is no sample code on the nml tutorial.

Re: About NFO

Posted: 05 Jul 2017 07:55
by DeletedUser10
By the way, what will happen if I decompile grf made with nml using grfcodec, what kind of file will be outputed?

Re: About NFO

Posted: 05 Jul 2017 09:17
by Cadde
An NFO file, albeit without the formatting. It's a real PITA to read an NFO decoded by grfcodec.

I get it, there's hardly any tutorials on NML. I had problems in the beginning too!
But since you've been learning NFO, NML should be rather simple. You know what's needed, all you need to know now is what to type.

So, you want to add a tram in NML? Here's a list of the things you need.
  • The GRF header. (https://newgrf-specs.tt-wiki.net/wiki/N ... parameters)

    Code: Select all

    grf {
        grfid: "ABC\01";
        name: string(STR_GRF_NAME);
        desc: string(STR_GRF_DESCRIPTION);
        version: 1;
        min_compatible_version: 0;
    }
    • grfid - The unique 4 character identifier of your GRF. No different from the NFO equivalent. (https://newgrf-specs.tt-wiki.net/wiki/Action8#GRFID)
    • name - The text that's supposed to be shown in the newgrf settings window. As well as in some other irrelevant places. The "string(...)" statement here refers to an entry in a language file. (https://newgrf-specs.tt-wiki.net/wiki/N ... uage_files)
    • desc - The description as shown in the information panel when you select the grf in the newgrf settings window. Again, using the "string(...)" statement from before.
    • version - The GRF file version. Letting the game know which file to use if there's duplicates etc. Or just letting the user see which version he's using and thusly being able to report issues with that version rather than just guessing.
    • min_compatible_version - The version of OTTD that this GRF file is compatible against. And so should be beyond. As grf specs have changed in ottd versions past, your grf may be using features that didn't exist before that specific version. Technically speaking, you should set the number to the current OTTD revision you've been testing against.
  • The sprites.

    Code: Select all

    spriteset (spriteset_tram_Le_Tram_Mk1, "gfx/Le_Tram_Mk1.png")
    {
      [0, 0, 16, 16, 0, -3]
    }
    
    spriteset (spriteset_tram_Le_Tram_Mk1_purchase, "gfx/Le_Tram_Mk1.png")
    {
      [0, 17, 16, 16, 0, -3]
    }
    spritesets are something i haven't bothered learning about myself yet. You can read about them here: https://newgrf-specs.tt-wiki.net/wiki/NML:Spriteset
    I would recommend using templates, you can find out more in the link. Templates are another powerful feature of NML that NFO does not provide.
  • The item(s)

    Code: Select all

    item(FEAT_ROADVEHS, item_tram_Le_Tram_Mk1) {
        property {
            name:                   string(STR_LE_TRAM_MK1);
            misc_flags;             bitmask(ROADVEH_FLAG_TRAM, ROADVEH_FLAG_2CC);
            introduction_date:      date(1935,1,1);
            model_life:             35;
            vehicle_life:           15;
            cost_factor:            25;
            running_cost_factor:    22;
            speed:                  32 km/h;
            power:                  15 hp;
            cargo_capacity:         20;
            weight:                 10 ton;
            sprite_id:              SPRITE_ID_NEW_ROADVEH;
        ... etc
        }
        graphics {
            purchase: spriteset_tram_Le_Tram_Mk1_purchase;
            spriteset_tram_Le_Tram_Mk1;
        }
    }
    • misc_flags - The one you were asking about. Setting this to a bitmask like above is the same as setting it = 3 in NFO (Bit 0 and Bit 1 set)
    • graphics block - This can be used to define callbacks, the "complicated ones" are out of the scope of this quick guide.
      You have already defined the sprite sets earlier. Here you declare which sprites the vehicle will use.
      purchase - The sprite to be used for purchase.
      The default callback is the sprite of the vehicle in the world.
    • OTHERS - I refer you to the documentation: https://newgrf-specs.tt-wiki.net/wiki/N ... properties
    As you can see, the properties are the same as they are in NFO, they just carry names instead of hexadecimal id's. Thus making it much easier to see what's what and what is being assigned.
  • Fine tuning and possible callbacks etc. (totally optional)
It's that "simple" really. Either way, it's much simpler than using NFO. It's also faster to set up and make future edits for. It compiles into an optimized GRF file to the best of NML's abilities. Thus saving you the hassle of all of the hex editing etc.
Compared to NFO, simple really IS simple. Compared to say eating a hamburger, NML still is rather complex but at least it's human readable.

CONCLUSION

Your final NML file may (or may not) look like:

Code: Select all

grf {
    grfid: "ABC\01";
    name: string(STR_GRF_NAME);
    desc: string(STR_GRF_DESCRIPTION);
    version: 1;
    min_compatible_version: 0;
}
graphics {
    purchase: spriteset_tram_Le_Tram_Mk1_purchase;
    spriteset_tram_Le_Tram_Mk1;
}

spriteset (spriteset_tram_Le_Tram_Mk1, "gfx/Le_Tram_Mk1.png")
{
  [0, 0, 16, 16, 0, -3]
}

spriteset (spriteset_tram_Le_Tram_Mk1_purchase, "gfx/Le_Tram_Mk1.png")
{
  [0, 17, 16, 16, 0, -3]
}

item(FEAT_ROADVEHS, item_tram_Le_Tram_Mk1) {
    property {
        name:                   string(STR_LE_TRAM_MK1);
        misc_flags;             bitmask(ROADVEH_FLAG_TRAM, ROADVEH_FLAG_2CC);
        introduction_date:      date(1935,1,1);
        model_life:             35;
        vehicle_life:           15;
        cost_factor:            25;
        running_cost_factor:    22;
        speed:                  32 km/h;
        power:                  15 hp;
        cargo_capacity:         20;
        weight:                 10 ton;
        sprite_id:              SPRITE_ID_NEW_ROADVEH;
    ... etc
    }
    graphics {
        purchase: spriteset_tram_Le_Tram_Mk1_purchase;
        spriteset_tram_Le_Tram_Mk1;
    }
}
And at that point, all that's left to do is create a "lang" folder with "english.lng" (and other languages as you see fit) and a "gfx" folder with the respective sprite graphics in it.
Your language (english.lng) file may... Or may not... Look like:

Code: Select all

##grflangid 0x01
# This is the English language file

# GRF name and description definitions
STR_GRF_NAME        :Le tram (v0.01)
STR_GRF_DESCRIPTION :Le super awesome Le Tram Mk1 from Le internets.

STR_LE_TRAM_MK1     :Le Tram 'Baguette' Mk. 1
And your graphics may... Or may not... Be based on:
Image

As i said, i leave the graphics editing to others.

NB: I reserve the right to be wrong. There may have been a number of mistakes made. This was merely constructed out of my memory and checking a few sources along the way.

EDIT: Oh and the NMLC repository does contain a number of samples.
Here's the repository: https://hg.openttdcoop.org/nml
And here's a sample road vehicle NML file: https://hg.openttdcoop.org/nml/files/af ... ehicle.nml

Re: About NFO

Posted: 05 Jul 2017 11:26
by Alberth
I agree there could be more or better NML tutorials. Feel free to make some, it's a wiki

Re: About NFO

Posted: 05 Jul 2017 12:00
by michael blunck
@ir1n1o57

There´s also m4nfo a high-level frontend producing efficient nfo code. It is small and fast, user-expandable, and provides full access to the underlying M4 macro processor, thus allows for all types of templating applications. There´s a user guide including a number of tutorials on its home page.

regards
Michael

Re: About NFO

Posted: 06 Jul 2017 10:50
by DeletedUser10
Thank you very much.
I think nfo is confusing, and nml is too long.
Maybe m4nfo is the best idea.

Re: About NFO

Posted: 06 Jul 2017 13:08
by Cadde
Hey, at least you don't have to code them into the OTTD sources directly.

Re: About NFO

Posted: 08 Jul 2017 06:23
by DeletedUser10
I downloaded newgrf source from the internet, but how can i edit it with M4NFO?

Re: About NFO

Posted: 09 Jul 2017 06:12
by Alberth
ir1n1o57 wrote:I downloaded newgrf source from the internet, but how can i edit it with M4NFO?
Not, unless it was written with m4nfo in the first place (which very few sets are, afaik).

If you download source from the net, you do have to be able to understand and work in that source language.

This is not different from needing a Windows system when you download a Windows program, and a Unix system when you download a Unix program.