New to NML and many questions

Discussions about the technical aspects of graphics development, including NewGRF tools and utilities.

Moderator: Graphics Moderators

User avatar
MagicBuzz
Tycoon
Tycoon
Posts: 1354
Joined: 15 Feb 2003 17:32
Location: Vergezac, France

New to NML and many questions

Post by MagicBuzz »

Hello,

I'm discovering the NML language and my goal is to create a new trainset.

I followed the NML Tutorial from the OpenTTD wiki : https://www.tt-wiki.net/wiki/NMLTutorial/Train

I use to program with C# and I'm scared about the big mess I obtained at the end of the tutorial.

So here are a few questions:

Is it possible to include files from one main nml file by example 1 for each vehicle and graphics?
How do I disable basic trains?
Is there a visual tool to help aligning template on spritessets? (and may be to generate some parts of the NML?)
Is there some "good practices" or some "nml samples" for common features (such as attaching a tender to the steam engine, changing wagons liveries according to the engine, changing engine livery according to the wagons, forbidding mixing some wagon cargo on a train, etc.)

Right now I can't see where to start from...
Brickblock1
Engineer
Engineer
Posts: 117
Joined: 04 Apr 2022 12:44
Location: The openttd discord server

Re: New to NML and many questions

Post by Brickblock1 »

MagicBuzz wrote: 10 Feb 2023 07:34
Is it possible to include files from one main nml file by example 1 for each vehicle and graphics?
Not within nml it self but there are other programs that allow you to do it, for example:
viewtopic.php?f=68&t=83239
MagicBuzz wrote: 10 Feb 2023 07:34 How do I disable basic trains?

Code: Select all

disable_item(FEAT_TRAINS);
MagicBuzz wrote: 10 Feb 2023 07:34 Is there a visual tool to help aligning template on spritessets? (and may be to generate some parts of the NML?)
There is a sprite aligner in-game but the values are 4 times as large as they should be for normal zoom. You can find it under the question mark.
User avatar
MagicBuzz
Tycoon
Tycoon
Posts: 1354
Joined: 15 Feb 2003 17:32
Location: Vergezac, France

Re: New to NML and many questions

Post by MagicBuzz »

Thank you Brickblock1 for your answer.

The softwareyou linked uses "pnml" for "precompiled nml".
What is that? How can it help me?

Next, I found this morning the disable_item function you mentioned.

But I have some questions about it as the document is... short.

I tried myself to put this at the top of my NML file:

Code: Select all

disable_item(FEAT_TRAINS, 1, 255);
As I understand it, it will disable any engineID between 1 and 255 that is a train (or wagon).
Is there any difference with your proposal?

Code: Select all

disable_item(FEAT_TRAINS);
I tried to load other NewGRF and their trains are still there.
So disable_item() disable only legacy items, and if I want to disable some other GRF items I must use another function, right?

Where can I find a list of constants? By exemple, how to disable only trains engines?
Brickblock1
Engineer
Engineer
Posts: 117
Joined: 04 Apr 2022 12:44
Location: The openttd discord server

Re: New to NML and many questions

Post by Brickblock1 »

MagicBuzz wrote: 10 Feb 2023 13:10 Thank you Brickblock1 for your answer.

The softwareyou linked uses "pnml" for "precompiled nml".
What is that? How can it help me?
I apologise for not explaining it earlier but the advantage of pnml is that you make a main pnml file and within it you can write

Code: Select all

#include "filename.pnml"
and it will paste to contents of the specified .pnml file in to a big nml file which you can later compile in to a working .grf. Therefore it allows you to split it in to multible files but it does take up more space on your hard drive.

MagicBuzz wrote: 10 Feb 2023 13:10 Next, I found this morning the disable_item function you mentioned.

But I have some questions about it as the document is... short.
The only difference between them is that one disables all of the trains and the other one only the ones within the specified range. In this case that would probably mean all of them regardless.
MagicBuzz wrote: 10 Feb 2023 13:10 I tried to load other NewGRF and their trains are still there.
So disable_item() disable only legacy items, and if I want to disable some other GRF items I must use another function, right?

Where can I find a list of constants? By exemple, how to disable only trains engines?
If you want to remove trains form other grfs you have to overide them by using a engine_override block in your code and setting the climate availability property of the trains you want to remove to no climates. In order for this to work you have to know the id of the original train you want to override and use the same one in your code. The easiest way of finding the ids is probably to look at the source code but I believe you can find them in game.

If you want an example you can look at my grf which overrides Swedish trains:
https://github.com/Brickblock1/Swedish-trains-fix

To my knowlage there aren't any constants which you would be able to use, but depending on what you want to do it might not be needed.
Brickblock1
Engineer
Engineer
Posts: 117
Joined: 04 Apr 2022 12:44
Location: The openttd discord server

Re: New to NML and many questions

Post by Brickblock1 »

Brickblock1 wrote: 10 Feb 2023 16:35 To my knowlage there aren't any constants which you would be able to use, but depending on what you want to do it might not be needed.
Actually ignore that I found a guide:
https://newgrf-specs.tt-wiki.net/wiki/N ... ehicle_IDs
User avatar
MagicBuzz
Tycoon
Tycoon
Posts: 1354
Joined: 15 Feb 2003 17:32
Location: Vergezac, France

Re: New to NML and many questions

Post by MagicBuzz »

Hello,

I'm progressing a bit, and still have many things I can't understand...

Firstly, thank you Brickblock1 for your help. Includes work fine, it's really easier to read now :)

Now, a new question :D
I can't understand how vehicule size works.

My engine and my wagon are a bit larger than the standard vehicle size.
So the graphics are overlapping :
vehicle_length.png
vehicle_length.png (1.8 KiB) Viewed 3167 times
In the "length" property I can type only integers 1..8 and 8 iis the default
=> What it is?

My engine actually is bigger that the standard size, so I would type 9... but this value is not recognized.

Then I thought the vahicle size is deducted from the sprite size, so I drew a bigger blue rectangle, but nothing changes: my wagons and engines still overlap...


Another question is about the colours.
With the same code, for some graphics a recolouring occurs according to the company colour, while for some other graphics the original color remains.
How can I choose which part of the picture will be recoloured?
User avatar
MagicBuzz
Tycoon
Tycoon
Posts: 1354
Joined: 15 Feb 2003 17:32
Location: Vergezac, France

Re: New to NML and many questions

Post by MagicBuzz »

Hello,

I have another question about the rail_type.
The tutorial is too simple as it uses only ELRL track type, and the documentation isn't very clear.

I want my set to be usable by people using or not a trackset.
I found on the NML wiki a list of available track types, and the corresponding GRF : https://newgrf-specs.tt-wiki.net/wiki/TracktypeLabels

So I will use for now USSR trackset.

Then I declared the railtypes like this :

Code: Select all

/* Define a rail type table,
 * this allows referring to railtypes
 * irrespective of the grfs loaded.
 */
railtypetable {
    RLA0, //	Broad (1520 mm) gauge unelectrified tracks. Speed limit 60 km/h	xUSSR train set
    RLA1, //	Broad (1520 mm) gauge unelectrified tracks. Speed limit 100 km/h	xUSSR train set
    RLA2, //	Broad (1520 mm) gauge unelectrified tracks. Speed limit 140 km/h	xUSSR train set
    RLA3, //	Broad (1520 mm) gauge unelectrified tracks. Speed limit 250 km/h	xUSSR train set
    ERd0, //	Broad (1520 mm) gauge tracks with generic DC catenary 1,5kV. Speed limit 60 km/h	xUSSR train set
    ERd1, //	Broad (1520 mm) gauge tracks with generic DC catenary 1,5kV. Speed limit 100 km/h	xUSSR train set
    ERd2, //	Broad (1520 mm) gauge tracks with generic DC catenary 1,5kV. Speed limit 140 km/h	xUSSR train set add-on
    ERd3, //	Broad (1520 mm) gauge tracks with generic DC catenary 1,5kV. Speed limit 250 km/h	xUSSR train set add-on
    ERD1, //	Broad (1520 mm) gauge tracks with generic DC catenary 3kV. Speed limit 100 km/h	xUSSR train set
    ERD2, //	Broad (1520 mm) gauge tracks with generic DC catenary 3kV. Speed limit 140 km/h	xUSSR train set
    ERD3, //	Broad (1520 mm) gauge tracks with generic DC catenary 3kV. Speed limit 250 km/h	xUSSR train set
    ERA1, //	Broad (1520 mm) gauge tracks with generic AC catenary 25kV. Speed limit 100 km/h	xUSSR train set
    ERA2, //	Broad (1520 mm) gauge tracks with generic AC catenary 25kV. Speed limit 140 km/h	xUSSR train set
    ERA3, //	Broad (1520 mm) gauge tracks with generic AC catenary 25kV. Speed limit 250 km/h	xUSSR train set
    ERA4, //	Broad (1520 mm) gauge tracks with generic AC catenary 25kV. No speed limit	xUSSR train set
    ERa0, //	Broad (1520 mm) gauge tracks with generic AC catenary 15kV. Speed limit 60 km/h	xUSSR train set
    ERa1, //	Broad (1520 mm) gauge tracks with generic AC catenary 15kV. Speed limit 100 km/h	xUSSR train set add-on
    ERa2, //	Broad (1520 mm) gauge tracks with generic AC catenary 15kV. Speed limit 140 km/h	xUSSR train set add-on
    ERa3, //	Broad (1520 mm) gauge tracks with generic AC catenary 15kV. Speed limit 250 km/h	xUSSR train set add-on
    ERa4, //	Broad (1520 mm) gauge tracks with generic AC catenary 15kV. No speed limit	xUSSR train set add-on
    ER2D, //	Broad (1520 mm) gauge tracks with DC 1,5kV / 3kV catenary. Speed limit 100 km/h	xUSSR train set
    ER2S, //	Broad (1520 mm) gauge tracks with AC 25kV / DC 3kV catenary. Speed limit 120 km/h	xUSSR train set
    ER2s, //	Broad (1520 mm) gauge tracks with AC 25kV / DC 1,5kV catenary. Speed limit 120 km/h	xUSSR train set add-on
    ER3a, //	Broad (1520 mm) gauge tracks with AC 25kV / 15kV / DC 1,5kV catenary. Speed limit 120 km/h	xUSSR train set add-on
    ER3D, //	Broad (1520 mm) gauge tracks with AC 25kV / DC 3kV / 1,5kV catenary. Speed limit 120 km/h	xUSSR train set add-on
    ER4S, //	Broad (1520 mm) gauge tracks with AC 25kV / 15kV / DC 3kV / 1,5kV catenary. Speed limit 120 km/h	xUSSR train set add-on
    //    RAIL, ELRL
}
Question : if I want the players to play without any trackset, should I enable the RAIL and ELRL back? What if I keep them enabled and the players loads a trackset? Should I add a switch to adapt the list to the available tracksets?

Now, I created an early slow steam engine. I want it to be able to run only on RLA0 and RLA1 (60 and 100 standard rails without catenary).
I tried to fill the track_type like this :

Code: Select all

item(FEAT_TRAINS, item_040TA) {
    property {
        ...
        track_type:                   RLA0 | RLA1;
        ...
    }
    graphics {
        ...
    }
}
I compiles correctly, but I can build my train and run it on other tracks such as ERD1.
Why?

-- Edit: according to my tests, I can set up only one track_type and according to the NML specs, the rail_type will internally define the list of other compatibles rail_types.
By exemple RLA0 is compatible with all other.
But ERd0 is compatible only with ERd1, ERd3 and ERd4... and ER2D, ER2s, ER3a, ER3D and ER4S.

Oh, those dual/tri/quadri voltages are not visible. They should exist to be able to do what I try to do (not in my question though) : allowing a train to run on 1,5 DC and 25 AC.
Brickblock1
Engineer
Engineer
Posts: 117
Joined: 04 Apr 2022 12:44
Location: The openttd discord server

Re: New to NML and many questions

Post by Brickblock1 »

MagicBuzz wrote: 13 Feb 2023 18:54 Now, a new question :D
I can't understand how vehicule size works.

My engine and my wagon are a bit larger than the standard vehicle size.
It seans to me like your trains are only 32 pixels wide which means that they aren't longer than standard.
MagicBuzz wrote: 13 Feb 2023 18:54 So the graphics are overlapping

In the "length" property I can type only integers 1..8 and 8 is the default
=> What it is?
As you have discovered the length property can only have the values 1 thruogh 8, but length 8 is actually 32 pixels which means that the lenght is correct. The reason you see the sprites overlapping in the depot is that you haven't set train_width_32_px to 1, which can be done in the following way:

Code: Select all

train_width_32_px = 1;
You might also have to set traininfo_y_offset in order to place the sprites at the correct height in the depot. This is done in the same way but can have other values.
MagicBuzz wrote: 13 Feb 2023 18:54 Another question is about the colours.
With the same code, for some graphics a recolouring occurs according to the company colour, while for some other graphics the original color remains.
How can I choose which part of the picture will be recoloured?
This shows what the different colours do:
https://newgrf-specs.tt-wiki.net/wiki/P ... oordinates
Brickblock1
Engineer
Engineer
Posts: 117
Joined: 04 Apr 2022 12:44
Location: The openttd discord server

Re: New to NML and many questions

Post by Brickblock1 »

The best option when choosing what railtypes to use is the standardised railtype scheme:
https://newgrf-specs.tt-wiki.net/wiki/S ... ype_Scheme

Implementing that will allow your trains to work on any trackset which follows the same standard and supports the extended voltages. Both xussr rails and v4 trains support this.

In order for your trains to work with or without a trackset you have to make it fallback to the default railtype labels (RAIL and ELRL). This is done like this:

Code: Select all

railtypetable {
	STANDARD_GAUGE: [SAAN, RAIL],
	STANDARD_GAUGE_MULTI: [SAAX, SAAE, ELRL],  // Standard gauge 15kv and 25kv ac will show up on dc most of the time x is place holder
	STANDARD_GAUGE_25KV: [SAAA, SAAE, ELRL],  // Standard gauge 25kv ac
	STANDARD_GAUGE_15KV: [SAAa, SAAA, SAAE, ELRL]  // Standard gauge 15kv ac
}
And set track_type to one of the identifiers.

In this code the train will first try to use the first label but if it doesn't exist it will use the one which is further down the list.

You might want to change SAAX into something from xussr instad as curently the standard does not allow for two voltages to be on one tile yet xussr still does.
User avatar
MagicBuzz
Tycoon
Tycoon
Posts: 1354
Joined: 15 Feb 2003 17:32
Location: Vergezac, France

Re: New to NML and many questions

Post by MagicBuzz »

Brickblock1 wrote: 14 Feb 2023 11:44

Code: Select all

train_width_32_px = 1;
Thank you very much.
Now the sprites don't overlap anymore :bow:

Are there other variable such as this one I should know?
What will happen if I have sprites bigger than 32px?
User avatar
MagicBuzz
Tycoon
Tycoon
Posts: 1354
Joined: 15 Feb 2003 17:32
Location: Vergezac, France

Re: New to NML and many questions

Post by MagicBuzz »

Brickblock1 wrote: 14 Feb 2023 12:22 In order for your trains to work with or without a trackset you have to make it fallback to the default railtype labels (RAIL and ELRL). This is done like this:

Code: Select all

railtypetable {
	STANDARD_GAUGE: [SAAN, RAIL],
	STANDARD_GAUGE_MULTI: [SAAX, SAAE, ELRL],  // Standard gauge 15kv and 25kv ac will show up on dc most of the time x is place holder
	STANDARD_GAUGE_25KV: [SAAA, SAAE, ELRL],  // Standard gauge 25kv ac
	STANDARD_GAUGE_15KV: [SAAa, SAAA, SAAE, ELRL]  // Standard gauge 15kv ac
}
Hmmm, it's far better than what I found working :D

Code: Select all

railtypetable {
    RLA0, //	Broad (1520 mm) gauge unelectrified tracks. Speed limit 60 km/h	xUSSR train set
    RLA1, //	Broad (1520 mm) gauge unelectrified tracks. Speed limit 100 km/h	xUSSR train set
    RLA2, //	Broad (1520 mm) gauge unelectrified tracks. Speed limit 140 km/h	xUSSR train set
    RLA3, //	Broad (1520 mm) gauge unelectrified tracks. Speed limit 250 km/h	xUSSR train set
    ERd0, //	Broad (1520 mm) gauge tracks with generic DC catenary 1,5kV. Speed limit 60 km/h	xUSSR train set
    ERd1, //	Broad (1520 mm) gauge tracks with generic DC catenary 1,5kV. Speed limit 100 km/h	xUSSR train set
    ERd2, //	Broad (1520 mm) gauge tracks with generic DC catenary 1,5kV. Speed limit 140 km/h	xUSSR train set add-on
    ERd3, //	Broad (1520 mm) gauge tracks with generic DC catenary 1,5kV. Speed limit 250 km/h	xUSSR train set add-on
    ERD1, //	Broad (1520 mm) gauge tracks with generic DC catenary 3kV. Speed limit 100 km/h	xUSSR train set
    ERD2, //	Broad (1520 mm) gauge tracks with generic DC catenary 3kV. Speed limit 140 km/h	xUSSR train set
    ERD3, //	Broad (1520 mm) gauge tracks with generic DC catenary 3kV. Speed limit 250 km/h	xUSSR train set
    ERA1, //	Broad (1520 mm) gauge tracks with generic AC catenary 25kV. Speed limit 100 km/h	xUSSR train set
    ERA2, //	Broad (1520 mm) gauge tracks with generic AC catenary 25kV. Speed limit 140 km/h	xUSSR train set
    ERA3, //	Broad (1520 mm) gauge tracks with generic AC catenary 25kV. Speed limit 250 km/h	xUSSR train set
    ERA4, //	Broad (1520 mm) gauge tracks with generic AC catenary 25kV. No speed limit	xUSSR train set
    ERa0, //	Broad (1520 mm) gauge tracks with generic AC catenary 15kV. Speed limit 60 km/h	xUSSR train set
    ERa1, //	Broad (1520 mm) gauge tracks with generic AC catenary 15kV. Speed limit 100 km/h	xUSSR train set add-on
    ERa2, //	Broad (1520 mm) gauge tracks with generic AC catenary 15kV. Speed limit 140 km/h	xUSSR train set add-on
    ERa3, //	Broad (1520 mm) gauge tracks with generic AC catenary 15kV. Speed limit 250 km/h	xUSSR train set add-on
    ERa4, //	Broad (1520 mm) gauge tracks with generic AC catenary 15kV. No speed limit	xUSSR train set add-on
    ER2D, //	Broad (1520 mm) gauge tracks with DC 1,5kV / 3kV catenary. Speed limit 100 km/h	xUSSR train set
    ER2S, //	Broad (1520 mm) gauge tracks with AC 25kV / DC 3kV catenary. Speed limit 120 km/h	xUSSR train set
    ER2s, //	Broad (1520 mm) gauge tracks with AC 25kV / DC 1,5kV catenary. Speed limit 120 km/h	xUSSR train set add-on
    ER3a, //	Broad (1520 mm) gauge tracks with AC 25kV / 15kV / DC 1,5kV catenary. Speed limit 120 km/h	xUSSR train set add-on
    ER3D, //	Broad (1520 mm) gauge tracks with AC 25kV / DC 3kV / 1,5kV catenary. Speed limit 120 km/h	xUSSR train set add-on
    ER4S, //	Broad (1520 mm) gauge tracks with AC 25kV / 15kV / DC 3kV / 1,5kV catenary. Speed limit 120 km/h	xUSSR train set add-on
    RAIL, ELRL // Standard rails if xUSSR is not loaded
}

v_RLA0 = RAIL;
v_ERd0 = ELRL;
v_ERD1 = ELRL;
v_ERA1 = ELRL;
v_ERa0 = ELRL;
v_ER2D = ELRL;
v_ER2S = ELRL;
v_ER2s = ELRL;
v_ER3a = ELRL;
v_ER3D = ELRL;
v_ER3D = ELRL;
v_ER4S = ELRL;

if (grf_order_behind("\4D\65\6F\B1") == 0) // WTF the test is inversed 0 = true ? Documentation says it should return 1: https://newgrf-specs.tt-wiki.net/wiki/NML:Builtin_functions
{
    v_RLA0 = RLA0;
    v_ERd0 = ERd0;
    v_ERD1 = ERD1;
    v_ERA1 = ERA1;
    v_ERa0 = ERa0;
    v_ER2D = ER2D;
    v_ER2S = ER2S;
    v_ER2s = ER2s;
    v_ER3a = ER3a;
    v_ER3D = ER3D;
    v_ER3D = ER3D;
    v_ER4S = ER4S;
}
And then:

Code: Select all

item(FEAT_TRAINS, item_BB26000) {
    property {
        name:                         string(STR_SNCF_TRAIN_BB26000_NAME);
        ...
        track_type:                   v_ER2s;
        ...    }
    graphics {
        ...
    }
}
I'll try this right now :)
Brickblock1
Engineer
Engineer
Posts: 117
Joined: 04 Apr 2022 12:44
Location: The openttd discord server

Re: New to NML and many questions

Post by Brickblock1 »

MagicBuzz wrote: 14 Feb 2023 12:42
Brickblock1 wrote: 14 Feb 2023 11:44

Code: Select all

train_width_32_px = 1;
Thank you very much.
Now the sprites don't overlap anymore :bow:

Are there other variable such as this one I should know?
Only train_y_info_offset which I already mentioned
MagicBuzz wrote: 14 Feb 2023 12:42 What will happen if I have sprites bigger than 32px?
Sprites longer than 32 pixels aren't supported but you can hack it a bit to make it work. The way the hack works is that you make the wagon articulated with 3 parts and only add the graphics to center part but make it large enough to overlapp the other parts without graphics.
User avatar
MagicBuzz
Tycoon
Tycoon
Posts: 1354
Joined: 15 Feb 2003 17:32
Location: Vergezac, France

Re: New to NML and many questions

Post by MagicBuzz »

Hello,

I have a little problem with a switch:

Code: Select all

switch (FEAT_TRAINS, SELF, sw_attach_no_passenger, cargo_classes & bitmask(CC_PASSENGERS))
{
    0: CB_RESULT_ATTACH_ALLOW;
    default: string(ERR_NO_PASSENGER);
}
I call it in the engines definition, with the "can_attach_wagon" callback.

It works fine with wagons, but... it displays also a message with engines... My engines doesn't have a cargo bitmask:

Code: Select all

item(FEAT_TRAINS, item_BB27000) {
    property {
        name:                         string(STR_SNCF_TRAIN_BB27000_NAME);
        climates_available:           bitmask(CLIMATE_TEMPERATE, CLIMATE_ARCTIC, CLIMATE_TROPICAL); 
        introduction_date:            date(2001, 1, 1);
        model_life:                   VEHICLE_NEVER_EXPIRES;
        vehicle_life:                 37;
        reliability_decay:            9;
        refittable_cargo_classes:     bitmask();
        non_refittable_cargo_classes: bitmask();
        loading_speed:                0; 
        cost_factor:                  90;
        running_cost_factor:          143;
        sprite_id:                    SPRITE_ID_NEW_TRAIN;
        speed:                        140 km/h;
        misc_flags:                   bitmask();
        refit_cost:                   0;
        track_type:                   AC25DC15;
        ai_special_flag:              AI_FLAG_PASSENGER | AI_FLAG_CARGO;
        power:                        5630 hp;
        running_cost_base:            RUNNING_COST_ELECTRIC;
        dual_headed:                  0;
        cargo_capacity:               0;
        weight:                       90 ton;
        ai_engine_rank:               0;
        engine_class:                 ENGINE_CLASS_ELECTRIC;
        extra_power_per_wagon:        0 kW;
        tractive_effort_coefficient:  0.350;
        air_drag_coefficient:         0.06;
        visual_effect_and_powered:    visual_effect_and_powered(VISUAL_EFFECT_ELECTRIC, 2, DISABLE_WAGON_POWER);
        extra_weight_per_wagon:       0 ton;
        bitmask_vehicle_info:         0;
    }
    graphics {
        default:                      set_BB27000_graphics;
        purchase:                     set_BB27000_graphics_purchase;
        additional_text:              return string(STR_SNCF_TRAIN_BB27000_ADDITIONAL_TEXT);
        can_attach_wagon:             sw_attach_no_passenger;
   }
}
Any idea why it thinks my engine is a passenger coach? It's not the "ai_special_flag" property, when I disable it I still have the issue.
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5602
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: New to NML and many questions

Post by PikkaBird »

All vehicles have a cargo type, even if their capacity is 0. Try setting default_cargo_type to something other than passengers if you don't want that switch to see it as a passenger vehicle.
User avatar
MagicBuzz
Tycoon
Tycoon
Posts: 1354
Joined: 15 Feb 2003 17:32
Location: Vergezac, France

Re: New to NML and many questions

Post by MagicBuzz »

PikkaBird wrote: 17 Feb 2023 01:49 All vehicles have a cargo type, even if their capacity is 0. Try setting default_cargo_type to something other than passengers if you don't want that switch to see it as a passenger vehicle.
Ok, you mean this line:

Code: Select all

refittable_cargo_classes:     bitmask();
Actually is the same as:

Code: Select all

refittable_cargo_classes:     ALL_CARGO_CLASSES;
And not:

Code: Select all

refittable_cargo_classes:     NO_CARGO_CLASS;
?

It's a bit weird, a bitmask without bit set to 1 should be 0, right?

But apparently the problem is elsewhere:

Code: Select all

item(FEAT_TRAINS, item_BB27000) {
    property {
        name:                         string(STR_SNCF_TRAIN_BB27000_NAME);
        climates_available:           bitmask(CLIMATE_TEMPERATE, CLIMATE_ARCTIC, CLIMATE_TROPICAL); 
        introduction_date:            date(2001, 1, 1);
        model_life:                   VEHICLE_NEVER_EXPIRES;
        vehicle_life:                 37;
        reliability_decay:            9;
        refittable_cargo_classes:     NO_CARGO_CLASS;
        non_refittable_cargo_classes: ALL_CARGO_CLASSES;
        loading_speed:                0; 
        cost_factor:                  90;
        running_cost_factor:          143;
        sprite_id:                    SPRITE_ID_NEW_TRAIN;
        speed:                        140 km/h;
        misc_flags:                   bitmask();
        refit_cost:                   0;
        track_type:                   AC25DC15;
        ai_special_flag:              AI_FLAG_PASSENGER | AI_FLAG_CARGO;
        power:                        5630 hp;
        running_cost_base:            RUNNING_COST_ELECTRIC;
        dual_headed:                  0;
        cargo_capacity:               0;
        weight:                       90 ton;
        ai_engine_rank:               0;
        engine_class:                 ENGINE_CLASS_ELECTRIC;
        extra_power_per_wagon:        0 kW;
        tractive_effort_coefficient:  0.350;
        air_drag_coefficient:         0.06;
        visual_effect_and_powered:    visual_effect_and_powered(VISUAL_EFFECT_ELECTRIC, 2, DISABLE_WAGON_POWER);
        extra_weight_per_wagon:       0 ton;
        bitmask_vehicle_info:         0;
    }
    graphics {
        default:                      set_BB27000_graphics;
        purchase:                     set_BB27000_graphics_purchase;
        additional_text:              return string(STR_SNCF_TRAIN_BB27000_ADDITIONAL_TEXT);
        can_attach_wagon:             sw_attach_no_passenger;
   }
}
=> I still can't attach a second BB27000 to itself.
Brickblock1
Engineer
Engineer
Posts: 117
Joined: 04 Apr 2022 12:44
Location: The openttd discord server

Re: New to NML and many questions

Post by Brickblock1 »

You could try and make a sepparate switch earlier which makes sure trains with a capacity of 0 get excluded from that switch.
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5602
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: New to NML and many questions

Post by PikkaBird »

MagicBuzz wrote: 17 Feb 2023 08:43 Ok, you mean this line:
MagicBuzz wrote:refittable_cargo_classes
PikkaBird wrote:default_cargo_type
What do you think, do I mean that line? :roll:
User avatar
MagicBuzz
Tycoon
Tycoon
Posts: 1354
Joined: 15 Feb 2003 17:32
Location: Vergezac, France

Re: New to NML and many questions

Post by MagicBuzz »

Dunno :wink:
I thought the "default_cargo_type" took the first possible cargo defined by the "refittable_cargo_classes" (so when no refittable, no cargo).
I just missunderstood the way it works.

I added a second switch that ensure the capacity is > 0 before raising the message.
That's a bit strange this control is needed when the engine actually can't be refitted to any cargo class. I guess PASS has an ID equal to 0 so the program can't make difference between passengers and nothing. (that could actually explain many thing IRL if SNCF have the same behaviour :D)
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5602
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: New to NML and many questions

Post by PikkaBird »

MagicBuzz wrote: 17 Feb 2023 11:23 That's a bit strange this control is needed when the engine actually can't be refitted to any cargo class.
It can understand the difference between refittable to passenger class (0x0001) and not refittable at all (0x0000), but like I said even unrefittable and 0 capacity vehicles still have a cargo type, which in turn has a cargo class. Sounds like you figured it out. :)
User avatar
MagicBuzz
Tycoon
Tycoon
Posts: 1354
Joined: 15 Feb 2003 17:32
Location: Vergezac, France

Re: New to NML and many questions

Post by MagicBuzz »

Hello,

I have a small problem with the "can_attach_wagon" callback.
It there a similar callback but in the other side? I mean something like "can_attach_to_consist" ?

I coded some EMUs and everything works well : I can couple to an EMU only the same model (or compatible).

But I can't find a way to forbid coupling an EMU to an existing train.

So I can build a steam engine pulling coal or iron orre, then couple a TGV to it. The "can_attach_wagon" will be checked only when I add something after the TGV.

I could create a generic callback "sw_no_emu" and add it to all my engines to forbid attaching an EMU, but also I won't be able to check this on other GRF's vehicles.

How can I do?
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 10 guests