Various NML related questions

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

Moderator: Graphics Moderators

McZapkie
Tycoon
Tycoon
Posts: 1183
Joined: 18 Jan 2014 18:10

Re: Various NML related questions

Post by McZapkie »

Is there any easy check of the nearby tile object class?
If I understand correctly, nearby_tile_object_type gives ID of particular object, whereas nearby_tile_class is true if any object exist here.
How to check if nearby tile contain any object from given object class?
My experimental openTTD server: 149.156.194.203:3979 non-standard client, now testing: JGRPP http://tiny.pl/ggnch
Projects: Reproducible Map Generation patch, NewGRFs: Manpower industries, PolTrams, Polroad, 600mm narrow gauge, preindustrial houses, wired, ECS industry extension, V4 CEE train set.
Addicted to freeciv longturn.

Kruemelchen
Traffic Manager
Traffic Manager
Posts: 167
Joined: 18 Feb 2017 17:47

Re: Various NML related questions

Post by Kruemelchen »

I'm atm creating a RVs set, which has RVs, that can be refitted to use trailers.
So the RVs can run either without a trailer, or with at least one trailer.
The latter requires the RV to be an articulated RV.

Now the question: Is there a possibility, that the RV runs as un-articulated RV, when no trailer is attached?

User avatar
supermop
Tycoon
Tycoon
Posts: 1056
Joined: 21 Feb 2010 00:15
Location: Fitzroy North - 96

Re: Various NML related questions

Post by supermop »

Hi all,

I am adding a truck with a long (9/8) trailer to my RV set, which I am coding as 3*3/8, with special curve sprites to appear rigid in corners. Rather than have the cargo loading sprites show up as gradually filling up from front to back, I want to define a specific effect: each segment gets one cargo sprite, in increments of 20% loads, then each gets a 2nd sprite only after the first 'row' is full. I would know how to do this if only there were variables for cargo_count and cargo_capacity that applied to the whole consist rather than just the vehicle part in question. is such a thing possible in nml?

Code: Select all

switch (FEAT_ROADVEHS, SELF, car_top_front, (((cargo_count)/(cargo_capacity))*100) ){
    0..20:      spriteset_x_null;
    default:    car_top_load;
}
switch (FEAT_ROADVEHS, SELF, car_top_mid, (((cargo_count)/(cargo_capacity))*100) ){
    0..40:      spriteset_x_null;
    default:    car_top_load;
}
switch (FEAT_ROADVEHS, SELF, car_top_end, (((cargo_count)/(cargo_capacity))*100) ){
    0..60:      spriteset_x_null;
    default:    car_top_load;
}
where cargo_count etc is actually something like cargo_count_consist and cargo_capacity_consist, or some other variable that is just 'total load percentage of whole vehicle'

Separately, I have a very dumb question about other_veh_curve_info. I want to check the curvature relative to the segment two units ahead, rather than just next or previous. Other_veh_curve_info does exactly what I want, but I don't know where I put the offset argument...

I assume it would be something like this?:

Code: Select all

switch (FEAT_ROADVEHS, SELF, truck_low_mid, other_veh_curve_info, -2 ){
    -1:         truck_low_l1;
    0:          truck_low_0;
    1:          truck_low_r1;
    default:    truck_low_0;
}

User avatar
Gwyd
Chief Executive
Chief Executive
Posts: 703
Joined: 17 Apr 2017 16:52
Location: Western Ile-de-France Region

Re: Various NML related questions

Post by Gwyd »

For the first part I guess you could use parent in the switch, not sure about the second part

User avatar
supermop
Tycoon
Tycoon
Posts: 1056
Joined: 21 Feb 2010 00:15
Location: Fitzroy North - 96

Re: Various NML related questions

Post by supermop »

I believe I will use PARENT for now - it will mean that the truck 'cab' will have to have all of the cargo capacity, but should be fine

McZapkie
Tycoon
Tycoon
Posts: 1183
Joined: 18 Jan 2014 18:10

Re: Various NML related questions

Post by McZapkie »

How often running costs callback is calculated?
I want to make these costs depending on vehicle load, but I'm afraid that if it would decrease overall computer performance...
My experimental openTTD server: 149.156.194.203:3979 non-standard client, now testing: JGRPP http://tiny.pl/ggnch
Projects: Reproducible Map Generation patch, NewGRFs: Manpower industries, PolTrams, Polroad, 600mm narrow gauge, preindustrial houses, wired, ECS industry extension, V4 CEE train set.
Addicted to freeciv longturn.

User avatar
supermop
Tycoon
Tycoon
Posts: 1056
Joined: 21 Feb 2010 00:15
Location: Fitzroy North - 96

Re: Various NML related questions

Post by supermop »

supermop wrote:
Separately, I have a very dumb question about other_veh_curve_info. I want to check the curvature relative to the segment two units ahead, rather than just next or previous. Other_veh_curve_info does exactly what I want, but I don't know where I put the offset argument...

I assume it would be something like this?:

Code: Select all

switch (FEAT_ROADVEHS, SELF, truck_low_mid, other_veh_curve_info, -2 ){
    -1:         truck_low_l1;
    0:          truck_low_0;
    1:          truck_low_r1;
    default:    truck_low_0;
}
Ok that doesn't work - NMLC gives the error "ERROR: "moprv65.nml", line 31617: Unrecognized identifier 'other_veh_curve_info' encountered"

Transportman
Tycoon
Tycoon
Posts: 2743
Joined: 22 Feb 2011 18:34

Re: Various NML related questions

Post by Transportman »

supermop wrote:
supermop wrote:
Separately, I have a very dumb question about other_veh_curve_info. I want to check the curvature relative to the segment two units ahead, rather than just next or previous. Other_veh_curve_info does exactly what I want, but I don't know where I put the offset argument...

I assume it would be something like this?:

Code: Select all

switch (FEAT_ROADVEHS, SELF, truck_low_mid, other_veh_curve_info, -2 ){
    -1:         truck_low_l1;
    0:          truck_low_0;
    1:          truck_low_r1;
    default:    truck_low_0;
}
Ok that doesn't work - NMLC gives the error "ERROR: "moprv65.nml", line 31617: Unrecognized identifier 'other_veh_curve_info' encountered"
I can't even find something like other_veh_curve_info in the documentation. I did look in the NFO-specs, using that, it should be possible to check the curvature of any vehicle in the chain. There is some magic needed with temporary variables and stuff, you might get some inspiration from this code.
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML

User avatar
supermop
Tycoon
Tycoon
Posts: 1056
Joined: 21 Feb 2010 00:15
Location: Fitzroy North - 96

Re: Various NML related questions

Post by supermop »

Transportman wrote:
supermop wrote:
supermop wrote:
Separately, I have a very dumb question about other_veh_curve_info. I want to check the curvature relative to the segment two units ahead, rather than just next or previous. Other_veh_curve_info does exactly what I want, but I don't know where I put the offset argument...

I assume it would be something like this?:

Code: Select all

switch (FEAT_ROADVEHS, SELF, truck_low_mid, other_veh_curve_info, -2 ){
    -1:         truck_low_l1;
    0:          truck_low_0;
    1:          truck_low_r1;
    default:    truck_low_0;
}
Ok that doesn't work - NMLC gives the error "ERROR: "moprv65.nml", line 31617: Unrecognized identifier 'other_veh_curve_info' encountered"
I can't even find something like other_veh_curve_info in the documentation. I did look in the NFO-specs, using that, it should be possible to check the curvature of any vehicle in the chain. There is some magic needed with temporary variables and stuff, you might get some inspiration from this code.
other_veh_curve_info is found in the nml specs here: https://newgrf-specs.tt-wiki.net/wiki/N ... offset_1-0 under "Variables that require an argument".

The 'argument' I need to give is the offset to the other vehicle part, but the specs do not state how arguments for variables are defined... putting the value in ( ) after the variable gives an error, "'other_veh_curve_info' is not defined as a function.", and putting it following the variable after a comma gives "Switch-block requires 4 parameters, encountered 5"

Eddi
Tycoon
Tycoon
Posts: 7479
Joined: 17 Jan 2007 00:14

Re: Various NML related questions

Post by Eddi »

just posting this here for future reference:
the problem here was a misspelling, it's "curv_info", not "curve_info"

the correct syntax would be: "other_veh_curv_info(-2)"
You might not exactly be interested in Ferion, but if you are, have fun :)

User avatar
TrainLover
Engineer
Engineer
Posts: 107
Joined: 01 Jul 2015 15:03

Re: Various NML related questions

Post by TrainLover »

I have three questions: one are pnml files created through the compiler? Next, what is the easy way to determine spriteset offsets? Like the [x, x, y, y] offsets. I find that's the hardes part of coding, as the other ones is kinda like Java syntax. Last, why doesn't nml come with something like grfcodec which decodes grf files? It only has an encoder.

Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4763
Joined: 09 Sep 2007 05:03
Location: home

Re: Various NML related questions

Post by Alberth »

TrainLover wrote:I have three questions: one are pnml files created through the compiler?
No, it's the actual source code.
The compiler takes a single NML file, but if you make many similar entities, that is not very convenient. As a result, people made a file for each entity (a .pnml file), and added cpp (the C pre-processor) as pre-processing step, which can merge all those small files into 1 nml file that the compiler takes. For bonus, you also get the C macro processor in that way, for generating unique labels, and replace hard-coded numbers by a readable name etc.
TrainLover wrote:Next, what is the easy way to determine spriteset offsets? Like the [x, x, y, y] offsets. I find that's the hardes part of coding, as the other ones is kinda like Java syntax.
No experience myself, but afaik people make graphics templates for each length vehicle, with fixed position for each view. That way, the offsets are always the same, just the name of the used graphics file changes. Figure out the offset once, and it works for all vehicles by copy/pasting that. Better, by using the macro-processor from above, or use templates from nmlc itself, the copies are generated each time, so if you ever need to change a template, everything changes along with it automagically without need to update all your pasted code.
TrainLover wrote:Last, why doesn't nml come with something like grfcodec which decodes grf files? It only has an encoder.
grfcodec doesn't do much, it's mostly a transformation from numbers written in text (so you can edit them in an editor) to binary values. There is some minor stuff like computing a few lengths etc, but there is a simple 1-to-1 mapping between number in the input to binary value in the output. As you can imagine, doing the reverse isn't terribly difficult either then. In addition at the time when grfcodec was written, there was a need to be able to examine and modify the existing grfs, so converting back and forth between both forms was a fundamental requirement for grfcodec.

For nml, the story is different. Its aim is to simplify coding a grf, like a high-level language, much like Java which is so much simpler to write than byte-code. At the same time, the gap between nml source code and actual grf binary values has increased. Nml for example allows mostly arbitrary expressions, which doesn't exist in grf, so nml generates heaps of grf code for a single line nml. In addition, some grf code doesn't exist in nml at all. Grf action C and advanced uses of action 6 cannot be expressed in nml, there is simply no way to write down an action C in nml.
This means some grfs cannot faithfully be decoded at all to nml, since it may contain grf code that has no equivalent in nml. If you limit it to the subset that can be expressed, you've got the problem of a heap of grf code at one side, which needs to be recognized as some (unknown) lines of nml, which is far from trivial (there is no simple 1-to-1 mapping here, like in grfcodec). This is a decompiler problem, which is somewhat solvable, but a lot of work, and the results are not that good.

A second consideration is that source code is far more useful than anything decompiled and is generally readily available. For example, you get the collection of .pnml files, neatly organized in directories with all the vehicles in their templates etc, or you get a bunch of Python code with tables of properties that are easy to edit. Since most projects are open source anyway, it's far easier and with better results to just ask for the original commented source code from the author, than trying to reverse-engineer a grf.
Being a retired OpenTTD developer does not mean I know what I am doing.

Eddi
Tycoon
Tycoon
Posts: 7479
Joined: 17 Jan 2007 00:14

Re: Various NML related questions

Post by Eddi »

TrainLover wrote:Next, what is the easy way to determine spriteset offsets? Like the [x, x, y, y] offsets.
it may be a bit tricky to explain by text, but i'll try:
  1. Enable NewGRF developer tools in the game
  2. Press Ctrl+B to enable showing of bounding boxes (requires NewGRF developer tools)
    (small clarification: bounding boxes have nothing to do with how big your sprites are, it's an internal method to determine what sprites should be in front)
  3. of this bounding box, there is one corner that is not visible, this is the most relevant corner
  4. use that invisible corner as the anchor point for your offsets
  5. now go to the sprite picker in the ?-Menu (requires NewGRF developer tools)
  6. there you can click on your sprite and temporarily modify the offsets until they look right
  7. put these new offsets in your grf file to make them permanent
  8. as said before, now try to make a template, so every item in your GRF uses the same offsets.
You might not exactly be interested in Ferion, but if you are, have fun :)

User avatar
3iff
Tycoon
Tycoon
Posts: 1012
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: Various NML related questions

Post by 3iff »

I want to create a grf that has the ability to change the cargo delivery prices in another grf. The idea is to load 'say' FIRS3 then have another grf that is able to modify the prices (by placing it after the FIRS3 grf) and then changing it by a specified percentage.

However, it seems that I'm unable to reference the CARGO - price_factor: value from the FIS3 grf in my grf, and so everything fails.

I could do it by copying all the "price_factor: values" in FIRS3 and using them as something I can change but it means collecting all the values and associating them with the relevant cargo numbers...and it would only apply to FIRS3 (or even a specific version of FIRS3).

Now, I could do that but is there any way I can get the value direct from a grf and then manipulate it?

michael blunck
Tycoon
Tycoon
Posts: 5878
Joined: 27 Apr 2005 07:09
Contact:

Re: Various NML related questions

Post by michael blunck »

You can only read the values of its parameters from a foreign grf.
But o/c you can overwrite cargo properties unconditionally.

regards
Michael
Image

User avatar
andythenorth
Tycoon
Tycoon
Posts: 5217
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: Various NML related questions

Post by andythenorth »

For this case, you're probably better off forking from FIRS somehow, and then generating your grf from a specific version of FIRS.

How comfortable are you with git / python?

User avatar
3iff
Tycoon
Tycoon
Posts: 1012
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: Various NML related questions

Post by 3iff »

I know I can overwrite the parameters but I want to modify the parameters in another grf (based on their current values in that grf) ...so that's probably an impossibility.

As for git...it's too complex, and I don't have regular internet access, only on a PC in the library, so not an easy option as I'm unable to run any program not already installed. Python is something I can just about cope with. That's why I generally prefer the full nml source as one file as it cuts out all the creation process from the raw files.

I think I will try manually extracting prices from an industry grf (FIRS) and using those directly within my grf. That should work even though it's more fiddly than I hoped.

Thanks for the tips.

User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9415
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: Various NML related questions

Post by planetmaker »

Seems there exists a mechanism to change vehicles defined in another NewGRF, but no such mechanism for anything else like industries, houses, stations or objects: https://newgrf-specs.tt-wiki.net/wiki/N ... er_NewGRFs

User avatar
3iff
Tycoon
Tycoon
Posts: 1012
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: Various NML related questions

Post by 3iff »

Not in itself helpful, but it has suggested a way I can do this as I intended. At least it's given me something to try.

Thanks for mentioning this...helpful as always!

User avatar
stefino_cz
Traffic Manager
Traffic Manager
Posts: 250
Joined: 02 Jul 2015 08:05
Location: Czech Republic
Contact:

Re: Various NML related questions

Post by stefino_cz »

Hi, I have a short question about NRT in NML. When the NRT flags will be add in NML? In Wiki pages there are 4 flags like "No houses along the roadtype" but NML doesn't know it. Thanks :)
Image

Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 3 guests