Various NML related questions

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

Moderator: Graphics Moderators

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

Re: Various NML related questions

Post by 3iff »

Yes, that's what I found (and suspected). Setting production to 0 per cycle generates 180-225t/month (45t per treecut instance). If I set production to 10 per cycle (256 ticks) I get 800t per month!

I would support some change. I might like a flag that cut trees but didn't produce anything - that could be handled by 'normal' production settings every 256 ticks. That would make the tree cutting a cosmetic effect and the lumber mill (or whatever industry is the source) be able to produce cargo regardless of whether there are local trees to cut or not.

That essentially is what I was aiming for but it was just an experiment that currently doesn't work. I didn't realise it was a can of worms.

If there are any changes in this area I'd appreciate being kept up to date...and I'm happy to beta test anything should that be needed.

Alon
Engineer
Engineer
Posts: 17
Joined: 22 Jul 2019 14:07

Re: Various NML related questions

Post by Alon »

Hi,
I'm trying to create a rail track with smooth curves using nml. What I'm trying to achieve is automatically changing the sprite of connected rail depending in the change of direction eg. Track NE connected to track N, they both change their sprite to create a smooth edges of tracks.


Is it possible a railpiece can detect the type of the other railpiece connected to them?(maybe an example will help)


If someone already created a smooth trackset it can be more helpful to see their source.

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

Re: Various NML related questions

Post by planetmaker »

Alon wrote:
22 May 2020 03:27
Is it possible a railpiece can detect the type of the other railpiece connected to them?(maybe an example will help)
No, that's currently not possible. You cannot read the tracks directions of adjacent tiles. IIRC, one of the main reasons is the performance impact this might have on the game - but my memory might be fuzzy there.

That said, a solution similar to how canals/rivers are handled can be envisioned in form of some patch series / pull requests to OpenTTD's source code. But that would need to go through much scrutiny as tracks are much more abundant and there's more track types than water types as the latter cannot be user-defined)

User avatar
jfs
Tycoon
Tycoon
Posts: 1208
Joined: 08 Jan 2003 23:09
Location: Denmark

Re: Various NML related questions

Post by jfs »

Curved track would also need to affect where trains running on it are drawn, and players would probably begin requesting more rotation sprites for the trains too.

Alon
Engineer
Engineer
Posts: 17
Joined: 22 Jul 2019 14:07

Re: Various NML related questions

Post by Alon »

jfs wrote:
22 May 2020 17:36
Curved track would also need to affect where trains running on it are drawn, and players would probably begin requesting more rotation sprites for the trains too.
That is not a problem, extra rotation sprites are now used in some Trainset grfs like CETS(which is unavailable) and Polish PKP set 2.0(partially supports additional rotation sprites). For normal trainsets a parameter or checks should be made to disable the curved tracks.


That's why I came up an idea to create a trackset with smooth curves, for Trainset that support extra rotation sprites.


Conclusion: if that's really possible someone should have done the similar idea before. Maybe in future this can be implemented.

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

Re: Various NML related questions

Post by TrainLover »

I was finally able to figure out how to setup a MakeFile, but whenever I use it, I keep getting an unexpected token in header.pnml. Do you know what is happening and how I could fix it?

User avatar
jfs
Tycoon
Tycoon
Posts: 1208
Joined: 08 Jan 2003 23:09
Location: Denmark

Re: Various NML related questions

Post by jfs »

Remember "pnml" is a Python script, not an NML file, you need to have it run with the correct version of Python.

User avatar
2TallTyler
Engineer
Engineer
Posts: 83
Joined: 11 Aug 2019 18:15
Contact:

Re: Various NML related questions

Post by 2TallTyler »

jfs wrote:
17 Jun 2020 16:33
Remember "pnml" is a Python script, not an NML file, you need to have it run with the correct version of Python.
Is it? I've always seen them used to hold a portion of the NML code, which is combined by a Python script (.py extension) into one long NML file, then that merged file is processed with NMLC into the .grf. The file extension is somewhat arbitrary, possibly meaning "pre-nml" or "partial-nml".

This is how my projects are set up, although I use .nml rather than .pnml as my arbitrary file extension. My makefile is a Windows Batch file (.bat) which simply runs the Python script, then NMLC, then moves the completed file to my OpenTTD NewGRF directory. For reference, here is a project repository with explanatory comments in the admittedly-flawed makefile.

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

Re: Various NML related questions

Post by planetmaker »

jfs wrote:
17 Jun 2020 16:33
Remember "pnml" is a Python script, not an NML file, you need to have it run with the correct version of Python.
For all projects I meddled with that's not correct (and that's probably the majority where you find files with that extention). In those cases it's an nml file which still needs pre-processing; thus it needs running it through the cpp pre-processor in order to handle some macros expansion and including further source files.

User avatar
Tintinfan
Engineer
Engineer
Posts: 69
Joined: 29 Sep 2010 11:36

Re: Various NML related questions

Post by Tintinfan »

Hello,

I've been trying to access "num_vehs_in_vehid_chain" through "var[0x61, 0, 0x00FF0000, 0x41]" - but I'm always getting a CB_FAILED/default response (nothing in the range 1-256). I have been able to use "var[0x61, 0, 0x000000FF, 0x41]" to obtain the "position_in_vehid_chain" - and figured moving the "FF" over to the position as shown in the nfo format and debug panel would work just as well but I get nothing.

Is my formatting here wrong or am I trying to access something that I shouldn't be? I have tried it both ways round as well - running 0x000000FF before 0x00FF0000...but 0x00FF0000 is not happy. :(

Code Snippets:
[+] Spoiler

Code: Select all

switch(FEAT_TRAINS, SELF, sw_E233_gfx_rev_pantograph_numofcars, [STORE_TEMP(position_in_consist_from_end-position_in_consist, 0x10F), var[0x61, 0, 0x00FF0000, 0x41]]){ //look at opposite num_vehs_in_vehid_chain
  1..5: sw_E233_gfx_rev_flippedcheck_pantograph_single;
  6..256: sw_E233_gfx_rev_flippedcheck_pantogaph_dual;
  CB_FAILED; //always fails here
}
switch(FEAT_TRAINS, SELF, sw_E233_gfx_rev_pantograph_pos, [STORE_TEMP(position_in_consist_from_end-position_in_consist, 0x10F), var[0x61, 0, 0x000000FF, 0x41]%8]){ //look at opposite position_in_vehid_chain
  1: sw_E233_gfx_rev_pantograph_numofcars;
  5: sw_E233_gfx_rev_flippedcheck_pantograph_single;
  7: sw_E233_gfx_rev_flippedcheck_pantograph_single;
  default: sw_E233_gfx_rev_flippedcheck_mucar;
}

Code: Select all

switch(FEAT_TRAINS, SELF, sw_E233_gfx_rev_pantogroup_B, [STORE_TEMP(position_in_consist_from_end-position_in_consist, 0x10F), var[0x61, 0, 0x000000FF, 0x41]]){ //look at opposite position_in_vehid_chain
  1: sw_E233_gfx_rev_flippedcheck_pantogaph_dual;
  5: sw_E233_gfx_rev_flippedcheck_pantograph_single;
  7: sw_E233_gfx_rev_flippedcheck_pantograph_single;
  default: sw_E233_gfx_rev_flippedcheck_mucar;
}
switch(FEAT_TRAINS, SELF, sw_E233_gfx_rev_pantogroup_A, [STORE_TEMP(position_in_consist_from_end-position_in_consist, 0x10F), var[0x61, 0, 0x000000FF, 0x41]]){ //look at opposite position_in_vehid_chain
  1: sw_E233_gfx_rev_flippedcheck_pantograph_single;
  5: sw_E233_gfx_rev_flippedcheck_pantograph_single;
  7: sw_E233_gfx_rev_flippedcheck_pantograph_single;
  default: sw_E233_gfx_rev_flippedcheck_mucar;
}
switch(FEAT_TRAINS, SELF, sw_E233_gfx_rev_pantograph_pos, [STORE_TEMP(position_in_consist_from_end-position_in_consist, 0x10F), var[0x61, 0, 0x00FF0000, 0x41]]){ //look at opposite num_vehs_in_vehid_chain
  0..5: sw_E233_gfx_rev_pantogroup_A;
  6..256: sw_E233_gfx_rev_pantogroup_B;
  CB_FAILED; //always fails here
}
Regards,

Tinny/Tintinfan. :)

User avatar
Tintinfan
Engineer
Engineer
Posts: 69
Joined: 29 Sep 2010 11:36

Re: Various NML related questions

Post by Tintinfan »

Tintinfan wrote:
20 Jun 2020 09:40
Hello,

I've been trying to access "num_vehs_in_vehid_chain" through "var[0x61, 0, 0x00FF0000, 0x41]" - but I'm always getting a CB_FAILED/default response (nothing in the range 1-256). I have been able to use "var[0x61, 0, 0x000000FF, 0x41]" to obtain the "position_in_vehid_chain" - and figured moving the "FF" over to the position as shown in the nfo format and debug panel would work just as well but I get nothing.

Is my formatting here wrong or am I trying to access something that I shouldn't be? I have tried it both ways round as well - running 0x000000FF before 0x00FF0000...but 0x00FF0000 is not happy. :(

Code Snippets:
[+] Spoiler

Code: Select all

switch(FEAT_TRAINS, SELF, sw_E233_gfx_rev_pantograph_numofcars, [STORE_TEMP(position_in_consist_from_end-position_in_consist, 0x10F), var[0x61, 0, 0x00FF0000, 0x41]]){ //look at opposite num_vehs_in_vehid_chain
  1..5: sw_E233_gfx_rev_flippedcheck_pantograph_single;
  6..256: sw_E233_gfx_rev_flippedcheck_pantogaph_dual;
  CB_FAILED; //always fails here
}
switch(FEAT_TRAINS, SELF, sw_E233_gfx_rev_pantograph_pos, [STORE_TEMP(position_in_consist_from_end-position_in_consist, 0x10F), var[0x61, 0, 0x000000FF, 0x41]%8]){ //look at opposite position_in_vehid_chain
  1: sw_E233_gfx_rev_pantograph_numofcars;
  5: sw_E233_gfx_rev_flippedcheck_pantograph_single;
  7: sw_E233_gfx_rev_flippedcheck_pantograph_single;
  default: sw_E233_gfx_rev_flippedcheck_mucar;
}

Code: Select all

switch(FEAT_TRAINS, SELF, sw_E233_gfx_rev_pantogroup_B, [STORE_TEMP(position_in_consist_from_end-position_in_consist, 0x10F), var[0x61, 0, 0x000000FF, 0x41]]){ //look at opposite position_in_vehid_chain
  1: sw_E233_gfx_rev_flippedcheck_pantogaph_dual;
  5: sw_E233_gfx_rev_flippedcheck_pantograph_single;
  7: sw_E233_gfx_rev_flippedcheck_pantograph_single;
  default: sw_E233_gfx_rev_flippedcheck_mucar;
}
switch(FEAT_TRAINS, SELF, sw_E233_gfx_rev_pantogroup_A, [STORE_TEMP(position_in_consist_from_end-position_in_consist, 0x10F), var[0x61, 0, 0x000000FF, 0x41]]){ //look at opposite position_in_vehid_chain
  1: sw_E233_gfx_rev_flippedcheck_pantograph_single;
  5: sw_E233_gfx_rev_flippedcheck_pantograph_single;
  7: sw_E233_gfx_rev_flippedcheck_pantograph_single;
  default: sw_E233_gfx_rev_flippedcheck_mucar;
}
switch(FEAT_TRAINS, SELF, sw_E233_gfx_rev_pantograph_pos, [STORE_TEMP(position_in_consist_from_end-position_in_consist, 0x10F), var[0x61, 0, 0x00FF0000, 0x41]]){ //look at opposite num_vehs_in_vehid_chain
  0..5: sw_E233_gfx_rev_pantogroup_A;
  6..256: sw_E233_gfx_rev_pantogroup_B;
  CB_FAILED; //always fails here
}
Well, it looks like after a little bit more digging that "var[0x61, 16, 0x000000FF, 0x41]" does the trick - or at least seems to do the trick, not sure if luck or logic but this document helped.
Regards,

Tinny/Tintinfan. :)

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

Re: Various NML related questions

Post by Eddi »

Tintinfan wrote:
21 Jun 2020 07:16
Hello,

I've been trying to access "num_vehs_in_vehid_chain" through "var[0x61, 0, 0x00FF0000, 0x41]" - but I'm always getting a CB_FAILED/default response (nothing in the range 1-256).
[...]
Well, it looks like after a little bit more digging that "var[0x61, 16, 0x000000FF, 0x41]" does the trick
Well, OK then, let's step this through what each of these does, and why one works and the other doesn't.

so you check var 41 (via var 61), which is apparently bitstuffing several BYTE values into one DWORD (i haven't checked which ones, but it doesn't matter), so var 41 will return a number like 0xaabbccdd.

so the var[num, shift, mask, parameter] syntax will first shift the result, and then apply a mask.

in var[0x61, 0, 0x00FF0000, 0x41] the result will be shifted by 0, intermediate result will be 0xaabbccdd
and then apply a mask of 0x00FF0000, so the result will be 0x00bb0000
in var[0x61, 16, 0x000000FF, 0x41] the result will be shifted by 16, intermediate result will be 0x0000aabb
and then apply a mask of 0x000000FF, so the result will be 0x000000bb
You might not exactly be interested in Ferion, but if you are, have fun :)

Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 3 guests