NML - a Newgrf Meta Language

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

Moderator: Graphics Moderators

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

Re: NML - a Newgrf Meta Language

Post by Eddi »

in the context of cargodist, there is more to worry about than station rating. if passengers pile up at intermediate stations, they already used up some part of the ressources, but they have not paid you any money, which reduces your overall income significantly.

if you want to adjust capacities, you can decompile a GRF into NFO, and change the values there. you can't decompile it into NML.

also, there are several passenger-reducing patches in the development forum.
User avatar
ColdIce
Transport Coordinator
Transport Coordinator
Posts: 306
Joined: 25 Apr 2006 10:22
Location: Bucharest

Re: NML - a Newgrf Meta Language

Post by ColdIce »

Thanks guys for answers. I just managed to alter the grf(s) with grfcodec. It worked like a charm :D
I didn't know that you can decode/encode grfs written in nml. thank you
The rest is confetti!
Transportman
Tycoon
Tycoon
Posts: 2781
Joined: 22 Feb 2011 18:34

Re: NML - a Newgrf Meta Language

Post by Transportman »

I have a question regarding Dual-headed vehicles. Which properties are shared between the front head and the back head and which properties are only set for the front head (and need a switch-block to also be set for the back head)? It seems to me that power and costs are not set for the back head, but the other properties are.
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML
Eddi
Tycoon
Tycoon
Posts: 8272
Joined: 17 Jan 2007 00:14

Re: NML - a Newgrf Meta Language

Post by Eddi »

what about the "available for articulated part" column in this table?
http://newgrf-specs.tt-wiki.net/wiki/NM ... icle_types
Transportman
Tycoon
Tycoon
Posts: 2781
Joined: 22 Feb 2011 18:34

Re: NML - a Newgrf Meta Language

Post by Transportman »

Eddi wrote:what about the "available for articulated part" column in this table?
http://newgrf-specs.tt-wiki.net/wiki/NM ... icle_types
It follows the list mostly, but for example weight and TE coefficient are not set to 0 for dual-headed vehicles, while they are set to 0 for articulated parts.
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML
Wahazar
Tycoon
Tycoon
Posts: 1451
Joined: 18 Jan 2014 18:10

Re: NML - a Newgrf Meta Language

Post by Wahazar »

I want to implement finite resources of mines by using permanent storage:

Code: Select all

switch(FEAT_INDUSTRIES, SELF, core_mine_resources_on_build, STORE_PERM(initial_resource,1)) {
 return 16;
}
switch(FEAT_INDUSTRIES, SELF, core_mine_monthly_prod_change, 
(STORE_PERM(LOAD_PERM(1)-produced_this_month_1,1))) { 
 return CB_RESULT_IND_PROD_NO_CHANGE; 
}
however seems that it is not working (I'm checking storage levels by means of industry extra text switch).
Should I push permanent storage to the temporary one during substraction, or there is my another mistake?
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: NML - a Newgrf Meta Language

Post by planetmaker »

McZapkie wrote:I want to implement finite resources of mines by using permanent storage:

Code: Select all

switch(FEAT_INDUSTRIES, SELF, core_mine_resources_on_build, STORE_PERM(initial_resource,1)) {
 return 16;
}
switch(FEAT_INDUSTRIES, SELF, core_mine_monthly_prod_change, 
(STORE_PERM(LOAD_PERM(1)-produced_this_month_1,1))) { 
 return CB_RESULT_IND_PROD_NO_CHANGE; 
}
however seems that it is not working (I'm checking storage levels by means of industry extra text switch).
Should I push permanent storage to the temporary one during substraction, or there is my another mistake?
You don't seem to actually check for the variable. You only assign a new value. Additionally you always return 'no production change', whatever your variable value.

Try

Code: Select all

switch(FEAT_INDUSTRIES, SELF, core_mine_monthly_prod_change, 
    [STORE_PERM(MAX(LOAD_PERM(1)-produced_this_month_1,0),1), LOAD_PERM(1)]
) { 
 0: return  CB_RESULT_IND_PROD_CLOSE;  // close when no ressource left anymore)
 return CB_RESULT_IND_PROD_NO_CHANGE; 
}
(Totally untested though)
Wahazar
Tycoon
Tycoon
Posts: 1451
Joined: 18 Jan 2014 18:10

Re: NML - a Newgrf Meta Language

Post by Wahazar »

planetmaker wrote:
You don't seem to actually check for the variable. You only assign a new value. Additionally you always return 'no production change', whatever your variable value.
I'm testing via:

Code: Select all

switch(FEAT_INDUSTRIES, SELF, core_mine_extra_text, (LOAD_PERM(1) > 0 ? (LOAD_PERM(1)>initial_resource-1 ? 2 : 1 ): 0) ) {
 0: return string(STR_MINE_EXHAUSTED);     
 1: return string(STR_MINE_1);   
 2: return string(STR_MINE_2);     
 return string(STR_NUMBER_UNDEF);
}
and still STR_MINE_2 is returned, regardless how much cargo is delivered from mine to factory.
I removed all production change procedures to simplify code.

EDIT: there was funny mistake, I used produced_this_month in monthly_prod_change switch, wich is called at the beginning of each month - obviously this variable is equal zero.
With produced_last_month everything works OK.
Formerly known as: McZapkie
Projects: Reproducible Map Generation patch, NewGRFs: Manpower industries, PolTrams, Polroad, 600mm narrow gauge, wired, ECS industry extension, V4 CEE train set, HotHut.
Another favorite games: freeciv longturn, OHOL/2HOL.
Wahazar
Tycoon
Tycoon
Posts: 1451
Joined: 18 Jan 2014 18:10

Re: NML - a Newgrf Meta Language

Post by Wahazar »

How to change type of cargo produced?
There is cargo_output callback, but it is unclear for me how it works.
I want to have one cargo produced permanently and the second one switched from one type to another and back, repeatedly.
Formerly known as: McZapkie
Projects: Reproducible Map Generation patch, NewGRFs: Manpower industries, PolTrams, Polroad, 600mm narrow gauge, wired, ECS industry extension, V4 CEE train set, HotHut.
Another favorite games: freeciv longturn, OHOL/2HOL.
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: NML - a Newgrf Meta Language

Post by planetmaker »

There are the cargo_input and cargo_output callbacks.

Code: Select all

switch (FEAT_INDUSTRIES, SELF, decide_output_cargo, extra_callback_info1) {
  0: return cargotype("WATR");
  1: return cargotype("OIL_");
  return 0xFF;
}

...

item (FEAT_INDUSTRIES, well) {
  graphics {
    cargo_output: decide_output_cargo;
  }
}
But think twice, better three times before you start making use of those. People generally expect that an industry always accepts the same cargo types and also produces the same cargo types. it also doesn't work well with the industry chain view which also assumes constant cargo chains. And it will possibly also break AIs.
Transportman
Tycoon
Tycoon
Posts: 2781
Joined: 22 Feb 2011 18:34

Re: NML - a Newgrf Meta Language

Post by Transportman »

McZapkie wrote:How to change type of cargo produced?
There is cargo_output callback, but it is unclear for me how it works.
I want to have one cargo produced permanently and the second one switched from one type to another and back, repeatedly.
Sounds like you are trying to work around a game limitation, and I'm not sure if this is the right way to do that.
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML
Wahazar
Tycoon
Tycoon
Posts: 1451
Joined: 18 Jan 2014 18:10

Re: NML - a Newgrf Meta Language

Post by Wahazar »

planetmaker wrote:There are the cargo_input and cargo_output callbacks.
...
But think twice, better three times before you start making use of those. People generally expect that an industry always accepts the same cargo types and also produces the same cargo types. it also doesn't work well with the industry chain view which also assumes constant cargo chains. And it will possibly also break AIs.
I need it to accept and produce passengers in case of farms, however let me redirect eventual discussion to another thread:
http://www.tt-forums.net/viewtopic.php?f=67&t=71105

I have another question related to parsing NML files and using variable substitution within #define sttement -
sometimes there is variable_name ## something, sometimes variable_name ##something_without_space - what is a difference?
Is it possible to make #define template for switches names within graphic statement or only explicit names can be used?
Eddi
Tycoon
Tycoon
Posts: 8272
Joined: 17 Jan 2007 00:14

Re: NML - a Newgrf Meta Language

Post by Eddi »

space after ## does not make a difference.

you can make a #define containing a switch or any other text sequence, it will be replaced textually before nmlc processing. use \ at the end of line to make a define cover multiple lines (for easier overview)

for more information about #define see https://gcc.gnu.org/onlinedocs/cpp/
Transportman
Tycoon
Tycoon
Posts: 2781
Joined: 22 Feb 2011 18:34

Re: NML - a Newgrf Meta Language

Post by Transportman »

Eddi wrote:you can make a #define containing a switch or any other text sequence, it will be replaced textually before nmlc processing. use \ at the end of line to make a define cover multiple lines (for easier overview)
For an example of the use of \, see this code
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML
Transportman
Tycoon
Tycoon
Posts: 2781
Joined: 22 Feb 2011 18:34

Re: NML - a Newgrf Meta Language

Post by Transportman »

I have a question regarding running_cost_base. Is it for train vehicles fine to set it to RUNNING_COST_ROADVEH? According to the specifications it is, but are there side-effects I should be aware of?
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5602
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: NML - a Newgrf Meta Language

Post by PikkaBird »

Transportman wrote:I have a question regarding running_cost_base. Is it for train vehicles fine to set it to RUNNING_COST_ROADVEH? According to the specifications it is, but are there side-effects I should be aware of?
It's "fine", but has exactly the drawbacks you've already identified in the 2cc thread.

If you want different cost bases with slightly less potential for other grfs buggering things up, you could do what I do in 10CC: use RUNNING_COST_STEAM for all locomotives, and RUNNING_COST_DIESEL for all wagons.
Eddi
Tycoon
Tycoon
Posts: 8272
Joined: 17 Jan 2007 00:14

Re: NML - a Newgrf Meta Language

Post by Eddi »

the side effect of using RUNNING_COST_ROADVEH is that changes to it are going to be global, if you don't actually define a road vehicle (you can easily define a dummy road vehicle that never becomes available to avoid this)
Transportman
Tycoon
Tycoon
Posts: 2781
Joined: 22 Feb 2011 18:34

Re: NML - a Newgrf Meta Language

Post by Transportman »

Eddi wrote:the side effect of using RUNNING_COST_ROADVEH is that changes to it are going to be global, if you don't actually define a road vehicle (you can easily define a dummy road vehicle that never becomes available to avoid this)
Okay, that is a bit of a downside, also because of the potential that base cost NewGRFs have to accidentally influence them as RVs. I'll stick to PikkaBirds suggestion to use one base for engines and stuff and one base for wagons/coaches. That still gives me the control I need, without the pesky side-effects.

Thanks for the information, saved me from a less handy decision.
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML
Wahazar
Tycoon
Tycoon
Posts: 1451
Joined: 18 Jan 2014 18:10

Re: NML - a Newgrf Meta Language

Post by Wahazar »

Is it possible to create industry tile callback dependent on industry variables?
For example, I want to set industry tile anim_control callback dependent on industry production level.
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5602
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: NML - a Newgrf Meta Language

Post by PikkaBird »

Certainly. Industry tiles can use the PARENT scope in switches to test the variables of the industry.
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 19 guests