NML - a Newgrf Meta Language

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

Moderator: Graphics Moderators

User avatar
GarryG
Tycoon
Tycoon
Posts: 5889
Joined: 14 Feb 2015 00:44
Location: Newcastle, Australia

Re: NML - a Newgrf Meta Language

Post by GarryG »

Thank you for your response. I will check those out and see if they help me.

My main objective is to try make a smaller stand alone industry. I like many of the Industry sets already made, but just like to add additional file with a few extra Industries that other sets don't have or for additional options for in game play. I doubt I'd make anything too big. Getting a bit old in the tooth to go to in depth.

Just to do a few simple projects to keep the old mind active.
Soot Happens
Screenshot Of The Month Winner March 2020
All my projects are GPLv2 License unless stated.
Auz Road Sets: viewtopic.php?f=29&t=87335
Auz Project Releases: viewtopic.php?f=67&t=84725
Auz Trains: http://www.tt-forums.net/viewtopic.php?f=26&t=74193
Auz Industry Sets: http://www.tt-forums.net/viewtopic.php?f=26&t=74471
Auz Objects: viewtopic.php?f=26&t=75657
Auz Bridges: viewtopic.php?f=26&t=75248
Auz Stations: viewtopic.php?f=26&t=76390
Auz Tracks: viewtopic.php?f=26&t=82691
Auz Subway Stations: viewtopic.php?f=26&t=85335
Auz Eyecandy TramTracks: viewtopic.php?t=89908
User avatar
3iff
Tycoon
Tycoon
Posts: 1094
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: NML - a Newgrf Meta Language

Post by 3iff »

Regarding the horrible ansi codes in the windows console, I'm currently trying a freeware program that enhances the display and eliminates the ansi code mess. I've also added a small batch file to make my compiling easier and it has lots of pretty colours - including printing in red when I do something stupid.

I'll test it a bit more then report back here...next week, probably.
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 »

3iff wrote:Regarding the horrible ansi codes in the windows console, I'm currently trying a freeware program that enhances the display and eliminates the ansi code mess. I've also added a small batch file to make my compiling easier and it has lots of pretty colours - including printing in red when I do something stupid.

I'll test it a bit more then report back here...next week, probably.
It should not need an additional programme but the use of correct library within NML itself really... so any effort would probably be spent much better on that part of the NML code itself
https://hg.openttdcoop.org/nml/changese ... 67515b4485 <-- this check doesn't seem to do what it should do (check for the platform being windows and omitting the ansi codes)
User avatar
3iff
Tycoon
Tycoon
Posts: 1094
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: NML - a Newgrf Meta Language

Post by 3iff »

I understand, but that is something I can fix at my end. The 'new' command window is better than the existing windows version so I'm very likely to be using it for other purposes and I won't be wasting my efforts.
andrevv
Engineer
Engineer
Posts: 4
Joined: 21 Sep 2015 20:25

Re: NML - a Newgrf Meta Language

Post by andrevv »

Hello everyone!
I'm having a little trouble with replacenew COAST_TILES_BASEGFX and the associated alternative_spritese. Does anyone have a working example? I don't know why it doesn't work for me. I could change everything with replace but these extra coast tiles don't want to change.
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 »

andrevv wrote:Hello everyone!
I'm having a little trouble with replacenew COAST_TILES_BASEGFX and the associated alternative_spritese. Does anyone have a working example? I don't know why it doesn't work for me. I could change everything with replace but these extra coast tiles don't want to change.
Have a look at the source of OpenGFX+Landscape (NewGRF version) or the extra grf of OpenGFX itself (baseset version). It replaces all coast tiles. Mind that base sets and NewGRFs have to use slightly different code (and sprites!) for replacement (COAST_TILES_BASEGFX vs COAST_TILES).
http://newgrf-specs.tt-wiki.net/wiki/NM ... ew_sprites and also see http://newgrf-specs.tt-wiki.net/wiki/Ac ... le_sprites
andrevv
Engineer
Engineer
Posts: 4
Joined: 21 Sep 2015 20:25

Re: NML - a Newgrf Meta Language

Post by andrevv »

The second link explains why it doesn't work, I need to override all of them at once with the 16 tile version. I will try it tomorrow.
Thank you very much!
TadeuszD
Transport Coordinator
Transport Coordinator
Posts: 329
Joined: 07 Nov 2011 19:32
Location: PL

Re: NML - a Newgrf Meta Language

Post by TadeuszD »

I encountered the problem while compiling my train set using latest version of nmlc (r5741):

Code: Select all

←[K nmlc info: 5002 sprites, 4842 cached, 0 orphaned, 160 duplicates, 0 newly encoded (native)
←[K nmlc info: Train items: 111/65420
←[K nmlc info: Concurrent spritesets: 8/255 ("src\\wagons\\res.pnml", line 51)
←[K nmlc info: Concurrent spritegroups: 39/256 ("src\\engines\\enxx-common.pnml", line 150)
←[K nmlc info: Concurrent Action2 registers: 16/127 ("src\\switches.pnml", line 105)
←[K nmlc info: Concurrent ActionD registers: 50/64 (None)
←[K nmlc info: GRF parameter registers: 3/64
←[K nmlc info: Cargo translation table: 57/254
←[K nmlc info: D0xx strings: 99/1024
←[Knmlc ERROR: nmlc: An internal error has occurred:
nmlc-version: unknown
Error:    (AssertionError) .
Command:  ['nmlc', '-c', '--grf', 'pkp-set-2.0.12.grf', 'tmp\\pkp-set.nml']
Location: File "nml\output_base.py", line 130, in prepare_byte
The source code for PKP Set 2.0 is here: http://dev.openttdcoop.org/projects/pkpset/repository
The problem occurs when I turn on power and purchase_power callbacks for steam engines Tp4 (tp4.pnml, line 88) and Ok1 (ok1.pnml, line 101).
Image
Eddi
Tycoon
Tycoon
Posts: 8271
Joined: 17 Jan 2007 00:14

Re: NML - a Newgrf Meta Language

Post by Eddi »

at first, i could not compile your code, because a) in src/pkp.pnml you use "\" instead of "/" for directory separator, and b) the *-x2.png sprites are missing.

after i fixed that, i could reproduce the error.

during output of the GRF, in the action3 for vehicle ID 124, it uses the invalid value "927" for "cargo"

Code: Select all

> nml/actions/action3.py(68)write()
-> file.print_bytex(cargo)
(Pdb) l
 63             file.print_bytex(1 if not self.is_livery_override else 0x81) # a single id
 64             file.print_varx(self.id, 3 if self.feature <= 3 else 1)
 65             file.print_byte(len(self.cid_mappings))
 66             file.newline()
 67             for cargo, cid, comment in self.cid_mappings:
 68  ->             file.print_bytex(cargo)
 69                 file.print_wordx(cid)
 70                 file.newline(comment)
 71             file.print_wordx(self.def_cid)
 72             file.newline(self.default_comment)
 73             file.end_sprite()
(Pdb) p self
<nml.actions.action3.Action3 object at 0x7f287dcd89e8>
(Pdb) p self.id
124
(Pdb) p self.cid_mappings
[(255, 226, '@action3_8;'), (927, 229, '@action3_9;')]
now. i have no idea how this value got there. the assert breaks on this value not being between 0 and 255.


pro tip:

Code: Select all

echo off
should be

Code: Select all

@echo off
so that the line itself is also not showing.
TadeuszD
Transport Coordinator
Transport Coordinator
Posts: 329
Joined: 07 Nov 2011 19:32
Location: PL

Re: NML - a Newgrf Meta Language

Post by TadeuszD »

Eddi wrote:during output of the GRF, in the action3 for vehicle ID 124, it uses the invalid value "927" for "cargo"
now. i have no idea how this value got there. the assert breaks on this value not being between 0 and 255..
Thank You, for very quick and helpful answer.
Now I should investigate what is the "cargo" with value 927. It looks like my fault, because I use preprocessor's macro with that number to enable power callbacks for one of mentioned engines:

Code: Select all

ENGINE_POWER_CALLBACKS(927)
EDIT:
I found the bug! I messed letter case in my code. I used lowercase 'power' as macro argument. :(
Thank You, again. Your hints was very helpful.
Image
Eddi
Tycoon
Tycoon
Posts: 8271
Joined: 17 Jan 2007 00:14

Re: NML - a Newgrf Meta Language

Post by Eddi »

i'm glad that this helped you isolate the cause for the error. however, it's still a bug in nmlc that this invalid value was not caught earlier
User avatar
GarryG
Tycoon
Tycoon
Posts: 5889
Joined: 14 Feb 2015 00:44
Location: Newcastle, Australia

Re: NML - a Newgrf Meta Language

Post by GarryG »

Hi fellas, wonder if someone can help me. I been trying to learn this NML language and still got a long way to go (not easy teaching this old dog new tricks).

Is there a command to build a industry within a certain radius of a town?

This spec_flags: bitmask(IND_FLAG_BUILT_NEAR_TOWN); build on the edge of town, but it measures from the label on the town. So some times if a large town the industry ends up in the town.

So wonder if can show a command for it to build say with a 30 square radius or between 10 to 40 squares from town .. some thing like that.

I seen can make oil rigs build a certain distance from land, so wonder if something simular for what I hoping for.

Thanks kindly
Soot Happens
Screenshot Of The Month Winner March 2020
All my projects are GPLv2 License unless stated.
Auz Road Sets: viewtopic.php?f=29&t=87335
Auz Project Releases: viewtopic.php?f=67&t=84725
Auz Trains: http://www.tt-forums.net/viewtopic.php?f=26&t=74193
Auz Industry Sets: http://www.tt-forums.net/viewtopic.php?f=26&t=74471
Auz Objects: viewtopic.php?f=26&t=75657
Auz Bridges: viewtopic.php?f=26&t=75248
Auz Stations: viewtopic.php?f=26&t=76390
Auz Tracks: viewtopic.php?f=26&t=82691
Auz Subway Stations: viewtopic.php?f=26&t=85335
Auz Eyecandy TramTracks: viewtopic.php?t=89908
Eddi
Tycoon
Tycoon
Posts: 8271
Joined: 17 Jan 2007 00:14

Re: NML - a Newgrf Meta Language

Post by Eddi »

the usual method is to search a (circular, meaning rectangular) area, and check for houses, in the construction callback. there may also be a way to count the population in this area, but i'm not sure about this.
User avatar
GarryG
Tycoon
Tycoon
Posts: 5889
Joined: 14 Feb 2015 00:44
Location: Newcastle, Australia

Re: NML - a Newgrf Meta Language

Post by GarryG »

Do you now of any commands that I could try .. experiment with? Or where to look to get some ideas?
Soot Happens
Screenshot Of The Month Winner March 2020
All my projects are GPLv2 License unless stated.
Auz Road Sets: viewtopic.php?f=29&t=87335
Auz Project Releases: viewtopic.php?f=67&t=84725
Auz Trains: http://www.tt-forums.net/viewtopic.php?f=26&t=74193
Auz Industry Sets: http://www.tt-forums.net/viewtopic.php?f=26&t=74471
Auz Objects: viewtopic.php?f=26&t=75657
Auz Bridges: viewtopic.php?f=26&t=75248
Auz Stations: viewtopic.php?f=26&t=76390
Auz Tracks: viewtopic.php?f=26&t=82691
Auz Subway Stations: viewtopic.php?f=26&t=85335
Auz Eyecandy TramTracks: viewtopic.php?t=89908
Wahazar
Tycoon
Tycoon
Posts: 1451
Joined: 18 Jan 2014 18:10

Re: NML - a Newgrf Meta Language

Post by Wahazar »

GarryG wrote:Do you now of any commands that I could try .. experiment with? Or where to look to get some ideas?
Try location_check callback, you have access to variables such town_manhattan_dist or town_euclidean_dist, see http://newgrf-specs.tt-wiki.net/wiki/NM ... _variables

EDIT: If you mean distance from town outer zone, you can estimate radius of this zone by square root of town size:
http://newgrf-specs.tt-wiki.net/wiki/TownZones
and compare it with euclidean distance to town label.
It should give good result at least for town unaffected by terrain and player constructions.
User avatar
GarryG
Tycoon
Tycoon
Posts: 5889
Joined: 14 Feb 2015 00:44
Location: Newcastle, Australia

Re: NML - a Newgrf Meta Language

Post by GarryG »

Can I ask a big favour and ask for a sample how to use those commands?

If I try town_euclidean_dist: [20, 20]; I get the message unknown property name.

I've tried different numbers for the x,y and I tried ( ) and no brackets.

Possible I putting it in wrong place?
Soot Happens
Screenshot Of The Month Winner March 2020
All my projects are GPLv2 License unless stated.
Auz Road Sets: viewtopic.php?f=29&t=87335
Auz Project Releases: viewtopic.php?f=67&t=84725
Auz Trains: http://www.tt-forums.net/viewtopic.php?f=26&t=74193
Auz Industry Sets: http://www.tt-forums.net/viewtopic.php?f=26&t=74471
Auz Objects: viewtopic.php?f=26&t=75657
Auz Bridges: viewtopic.php?f=26&t=75248
Auz Stations: viewtopic.php?f=26&t=76390
Auz Tracks: viewtopic.php?f=26&t=82691
Auz Subway Stations: viewtopic.php?f=26&t=85335
Auz Eyecandy TramTracks: viewtopic.php?t=89908
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4763
Joined: 09 Sep 2007 05:03
Location: home

Re: NML - a Newgrf Meta Language

Post by Alberth »

http://dev.openttdcoop.org/projects/fir ... .pnml#L101
looks like what you want.

(Many thanks to Andy, code is really readable!)
Being a retired OpenTTD developer does not mean I know what I am doing.
User avatar
GarryG
Tycoon
Tycoon
Posts: 5889
Joined: 14 Feb 2015 00:44
Location: Newcastle, Australia

Re: NML - a Newgrf Meta Language

Post by GarryG »

Hi Alberth, I think what mention is what I need, but I tried a few setting, but I not understand just how to fill the requirements as getting nowhere with it.

Can you show me how please?

#define CHECK_TOWN_ZONE(switchname, minzone, maxzone, next) \
switch (FEAT_INDUSTRIES, SELF, switchname, town_zone(0, 0)) { \
minzone .. maxzone: next; \
return CB_RESULT_LOCATION_DISALLOW; \

The industry is called freight_depot .. it one I made up to act like the Bulk Terminals do in FIRS, except it don't need to be on water.

I want to try make it build hopefully between 10 and 20 square from a town.

I've tried different ideas without success.

Hope you can help.
Soot Happens
Screenshot Of The Month Winner March 2020
All my projects are GPLv2 License unless stated.
Auz Road Sets: viewtopic.php?f=29&t=87335
Auz Project Releases: viewtopic.php?f=67&t=84725
Auz Trains: http://www.tt-forums.net/viewtopic.php?f=26&t=74193
Auz Industry Sets: http://www.tt-forums.net/viewtopic.php?f=26&t=74471
Auz Objects: viewtopic.php?f=26&t=75657
Auz Bridges: viewtopic.php?f=26&t=75248
Auz Stations: viewtopic.php?f=26&t=76390
Auz Tracks: viewtopic.php?f=26&t=82691
Auz Subway Stations: viewtopic.php?f=26&t=85335
Auz Eyecandy TramTracks: viewtopic.php?t=89908
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 »

GarryG wrote:Hi Alberth, I think what mention is what I need, but I tried a few setting, but I not understand just how to fill the requirements as getting nowhere with it.

Can you show me how please?

#define CHECK_TOWN_ZONE(switchname, minzone, maxzone, next) \
switch (FEAT_INDUSTRIES, SELF, switchname, town_zone(0, 0)) { \
minzone .. maxzone: next; \
return CB_RESULT_LOCATION_DISALLOW; \

The industry is called freight_depot .. it one I made up to act like the Bulk Terminals do in FIRS, except it don't need to be on water.

I want to try make it build hopefully between 10 and 20 square from a town.

I've tried different ideas without success.

Hope you can help.
You quoted already the code... albeit in a general form. Boilt down to your case you want to use this switch for the location_check callback of the industry:

Code: Select all

switch (FEAT_INDUSTRIES, SELF, build_distance_check, town_zone(0, 0)) {
  10 .. 20: CB_RESULT_LOCATION_ALLOW;
  return CB_RESULT_LOCATION_DISALLOW;
}
If you want to check different things, don't immediately return CB_RESULT_LOCATION_ALLOW but simply call the next switch which checks another thing and only return CB_RESULT_LOCATION_ALLOW in the final check.
User avatar
GarryG
Tycoon
Tycoon
Posts: 5889
Joined: 14 Feb 2015 00:44
Location: Newcastle, Australia

Re: NML - a Newgrf Meta Language

Post by GarryG »

Appreciate all your fellas trying to help this old dog.

I tried

switch (FEAT_INDUSTRIES, SELF, build_distance_check, town_zone(0, 0)) {
10 .. 20: CB_RESULT_LOCATION_ALLOW;
return CB_RESULT_LOCATION_DISALLOW;
}


also tried

switch (FEAT_INDUSTRIES, SELF, freight_depot_build_distance_check, town_zone(0, 0)) {
10 .. 20: CB_RESULT_LOCATION_ALLOW;
return CB_RESULT_LOCATION_DISALLOW;

}

but get this message

[K nmlc warning: "Auzind_V3.nml", line 149138: Block 'build_distance_check' is not referenced, ignoring

and

[K nmlc warning: "Auzind_V3.nml", line 149138: Block 'freight_depot_build_distance_check' is not referenced, ignoring

Seems like I still not getting it right.

Am I suppose to put the name of the Industry somewhere in the command?
Soot Happens
Screenshot Of The Month Winner March 2020
All my projects are GPLv2 License unless stated.
Auz Road Sets: viewtopic.php?f=29&t=87335
Auz Project Releases: viewtopic.php?f=67&t=84725
Auz Trains: http://www.tt-forums.net/viewtopic.php?f=26&t=74193
Auz Industry Sets: http://www.tt-forums.net/viewtopic.php?f=26&t=74471
Auz Objects: viewtopic.php?f=26&t=75657
Auz Bridges: viewtopic.php?f=26&t=75248
Auz Stations: viewtopic.php?f=26&t=76390
Auz Tracks: viewtopic.php?f=26&t=82691
Auz Subway Stations: viewtopic.php?f=26&t=85335
Auz Eyecandy TramTracks: viewtopic.php?t=89908
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 4 guests