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: 3076
Joined: 14 Feb 2015 00:44
Location: Newcastle, Australia

Re: NML - a Newgrf Meta Language

Post by GarryG » 26 Nov 2016 21:08

Hi Pyoro and frosch,

I seem to have won and not getting any undefined string messages now. At least not see any visible.

What I done in the language files for instance like Pyoro mention I reduced the strings on many of the objects from this:

Code: Select all

STR_reef4                  :Reef Large Rocks
STR_reef4_purchase_view1   :Reef Rocks
STR_reef4_purchase_view2   :Reef Rocks
STR_reef4_purchase_view3   :Reef Rocks
STR_reef4_purchase_view4   :Reef Rocks
to this

Code: Select all

STR_reef4            :Reef Large Rocks
There would have been over 100 entries that I was able to change like that above and still some I can change in the other object sets I done and doing.

And in the NML file I delete the code for the string switch (switch (FEAT_OBJECTS, SELF, switch_add_text_STR_reef4, view) ...). Not needed anymore, obviously.

Also changed reference to the PURCHASE sprites.

Code: Select all

spriteset (spriteset_reef4_PURCHASE) {
    template_building_low(0,0,"gfx/reef4.png")
}
I did this for all objects that the Purchase sprite was same size as the normal sprite.
frosch wrote:About your sprite sharing: You can share sprites between different graphic chains and even different objects just fine. Sharing them reduces memory usage.
Good if I can do this, I will alter the class and classnames again so this will share same chains.

Thank you all kindly for your help in solving this problem.

Cheers fellas

Garry
Soot Happens
All my projects are GPLv2 License unless stated.
Auz Project Releases: viewtopic.php?f=67&t=84725
AuzTrains: 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
AuzObjects: viewtopic.php?f=26&t=75657
AuzBridges: viewtopic.php?f=26&t=75248
AuzStations: viewtopic.php?f=26&t=76390
AuzTracks: viewtopic.php?f=26&t=82691
AuzSubwayStations: viewtopic.php?f=26&t=85335

User avatar
Quast65
Tycoon
Tycoon
Posts: 1660
Joined: 09 Oct 2011 13:51
Location: The Netherlands

Re: NML - a Newgrf Meta Language

Post by Quast65 » 30 Nov 2016 11:36

Suggestion:
Not sure if it is at all possible (if not please ignore this ;-) )

I often like to make minute changes to other GRFs, replacing just certain graphics and keeping the rest as is. (for example I have edited the UK-roadset in my games in such a way that it displays sidewalks also on rural roads)
Now I do this by recompiling the edited GRF, just with a change to the original name and keeping the same GRF-ID, so I can easily find it in my unused GRF-list next to its original version and it will also not disrupt my save-games or scenarios.

However, in some cases depending on the license of the GRF, these kind of changes are not allowed to be publically released and one needs to contact the original creator(s) of the GRF and donate these sprites, hoping they will be implimented (or implimented as extra option via parameter). This process can take up some time as some creators cant be contacted easily or dont want to make the changes to their GRF.
An example I could give for this is with one of my own sets, the Fake Airport Objects. For the taxiways I use yellow lines, some people suggested that they would like these lines to be thinner/sharper. I dont agree ;-) Therefor I wont impliment this (not even as a parameter, I really dont like the look of it ;-) ). The set is GPL licensed though, so someone else could make these changes and re-release the set, but if they dont add it as a parameter they will need to release it as a completely separate set, including also graphics that havent been changed.
But hopefully that wont be necessary anymore if my suggestion is feasible....

Therefor I would like to know if it is possible to have an option to change graphics within a GRF, working a bit like Action-5 in NFO for replacing base set sprites not present in the original TTD.
For example, by combining the unique GRF-ID of a GRF with an offset to the graphics within it that you want to change.

Is this at all possible and if so, interesting enough to impliment?
Projects: http://www.tt-forums.net/viewtopic.php?f=26&t=57266
Screenshots: http://www.tt-forums.net/viewtopic.php?f=47&t=56959

Winner of the following screenshot competitions:
sep 2012, jan 2013, apr 2013, aug 2013, mar 2014, mar 2016
All my work is released under GPL-license (either V2 or V3), if not clearly stated otherwise.

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

Re: NML - a Newgrf Meta Language

Post by GarryG » 07 Jan 2017 22:36

Bounding Boxes.

Can anyone tell me how to add bounding boxes to my coding?

Been told could be reason I having a few graphic issues in the object sets I doing.

Cheers
Soot Happens
All my projects are GPLv2 License unless stated.
Auz Project Releases: viewtopic.php?f=67&t=84725
AuzTrains: 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
AuzObjects: viewtopic.php?f=26&t=75657
AuzBridges: viewtopic.php?f=26&t=75248
AuzStations: viewtopic.php?f=26&t=76390
AuzTracks: viewtopic.php?f=26&t=82691
AuzSubwayStations: viewtopic.php?f=26&t=85335

frosch
OpenTTD Developer
OpenTTD Developer
Posts: 979
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: NML - a Newgrf Meta Language

Post by frosch » 08 Jan 2017 12:14

Bounding boxes are mostly a myth. While there is a thing called "bounding boxes" in the game, I am 99% sure whoever hinted towards them did not know how bounding boxes work, and bounding boxes won't help fix your issues.
The purpose of bounding boxes is to sort sprites within a tile. But in case of NewObjects there is only one thing on the tile (your object), so there is not much to sort. People often think they can use bounding boxes to sort stuff against stuff on neighbouring tiles, however bounding boxes have hardly any influence on that. (mostly because bounding boxes only affect "how" to draw, but not "what" to draw)

Regarding bounding boxes:
For NewObjects the only part you may possibly want to adjust is "zextent" in the "building" part of your "spritelayout".
Set it to approximately reflect the height of your object. That helps in case of bridges next to your object.

Regarding glitches:
You need to distinguish two types of glitches:
* Glitches because sprites change the order they are drawn in. ("how" to draw)
* Glitches because sprites are skipped, and not drawn at all. ("what" to draw)

Bounding boxes help in the first case, but not in the second.
The most often glitch I see is the second case, when sprites extent over the left or right corner of the tile. In that case you have to cut the object more precisely. (Changing bounding boxes does not affect this, because this is an issue about "what" to draw, and bounding boxes have no influence on that)
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁

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

Re: NML - a Newgrf Meta Language

Post by GarryG » 08 Jan 2017 12:28

Thank you kindly frosch for explain that too me.

Much appreciated and a relief as not need to find out how to install it.

Cheers pal
Soot Happens
All my projects are GPLv2 License unless stated.
Auz Project Releases: viewtopic.php?f=67&t=84725
AuzTrains: 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
AuzObjects: viewtopic.php?f=26&t=75657
AuzBridges: viewtopic.php?f=26&t=75248
AuzStations: viewtopic.php?f=26&t=76390
AuzTracks: viewtopic.php?f=26&t=82691
AuzSubwayStations: viewtopic.php?f=26&t=85335

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

Re: NML - a Newgrf Meta Language

Post by GarryG » 12 Jan 2017 09:17

I having a play around with my Industry set seeing if I can figure out what different codes do and where to find things.

I playing around with a Industry to open a certain date or close before a certain date.

When I insert this code:

Code: Select all

/* Allow only within the availability years */
switch (FEAT_INDUSTRIES, SELF, timber_siding_check_availability, current_date) {
 date(1840,1,1) .. date(5000000,12,31): timber_siding_available_game_mode;
 return CB_RESULT_IND_NO_CONSTRUCTION;
}
I get this error:
Unrecognized identifier 'timber_siding_available_game_mode' encounted
Can someone tell me what am I missing?

Thanks kindly
Soot Happens
All my projects are GPLv2 License unless stated.
Auz Project Releases: viewtopic.php?f=67&t=84725
AuzTrains: 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
AuzObjects: viewtopic.php?f=26&t=75657
AuzBridges: viewtopic.php?f=26&t=75248
AuzStations: viewtopic.php?f=26&t=76390
AuzTracks: viewtopic.php?f=26&t=82691
AuzSubwayStations: viewtopic.php?f=26&t=85335

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

Re: NML - a Newgrf Meta Language

Post by planetmaker » 12 Jan 2017 11:44

GarryG wrote: I get this error:
Unrecognized identifier 'timber_siding_available_game_mode' encounted
Can someone tell me what am I missing?
It is not defined in the code above. Does it exist or did you mis-spell it?

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

Re: NML - a Newgrf Meta Language

Post by GarryG » 12 Jan 2017 12:11

checked and re-check spelling and all looks correct.

The code is what I copied from the Oil_Rigs and I just changed the file it reference to.

Seems like I left some other code out .. as you mentioned "It is not defined in the code above."

I'll sleep on it tonight and try again a fresh in morning.

Cheers and thanks for helping
Soot Happens
All my projects are GPLv2 License unless stated.
Auz Project Releases: viewtopic.php?f=67&t=84725
AuzTrains: 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
AuzObjects: viewtopic.php?f=26&t=75657
AuzBridges: viewtopic.php?f=26&t=75248
AuzStations: viewtopic.php?f=26&t=76390
AuzTracks: viewtopic.php?f=26&t=82691
AuzSubwayStations: viewtopic.php?f=26&t=85335

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

Re: NML - a Newgrf Meta Language

Post by Eddi » 24 Feb 2017 00:40

going back to the bounding box discussion:

if you want to check your bounding boxes, you can enable newgrf developer tools in the console, and then press Ctrl+B ingame to have the game display them.

what you want to do is have your bounding box roughly the size of the object you draw, but avoid having two bounding boxes overlap (touch is usually fine, although there are some exceptions). that means, sometimes you can avoid glitches by making the bounding box smaller, instead of larger.

the game handles overlapping bounding boxes very poorly (and also, there is no good way to handle it. fixing it for one case will break it for other cases)
You might not exactly be interested in Ferion, but if you are, have fun :)

TadeuszD
Transport Coordinator
Transport Coordinator
Posts: 330
Joined: 07 Nov 2011 19:32
Location: PL

Re: NML - a Newgrf Meta Language

Post by TadeuszD » 21 Mar 2017 10:39

Hello!
How can I check in NML whether the leading vehicle in the train is engine or not?
I'm using some switches with PARENT argument to determine wagons appearance. But they generates some glitches when the train is waiting in the depot without engine. In this case variable date_of_last_service for the first vehicle (wagon) returns undefined value.
Is it posible to check engine-specific variable (for example: power) to determine vehicle type?
Image

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

Re: NML - a Newgrf Meta Language

Post by Transportman » 21 Mar 2017 17:33

TadeuszD wrote:Hello!
How can I check in NML whether the leading vehicle in the train is engine or not?
I'm using some switches with PARENT argument to determine wagons appearance. But they generates some glitches when the train is waiting in the depot without engine. In this case variable date_of_last_service for the first vehicle (wagon) returns undefined value.
Is it posible to check engine-specific variable (for example: power) to determine vehicle type?
I think you have 4 options, based on needs, requirements and future plans:
1: You could check for vehicle_is_potentially_powered, if I read the spec right it should return false if the leading vehicle cannot deliver power, which defines a wagon. I'm not sure what would happen if you also use the power callback and that returns 0 in some cases for engines.
2: You check for a range of vehicle IDs, just like I do in the 2cc TrainsInNML to check if wagons can be attached to a train. The check itself has no potential side effects, as it only depends on one value that does not change unless you change it. Downside is that it would break compatibility if you already released your work and the ID grouping has not yet been implemented.
3: Define livery overrides for the wagons on the engines. This only makes sense if the wagons should normally not be used separately of engines and the properties depend on the engine that is in front of them.
4: Check for vehicle_is_in_depot and show some default graphics if that is the case.
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML

TadeuszD
Transport Coordinator
Transport Coordinator
Posts: 330
Joined: 07 Nov 2011 19:32
Location: PL

Re: NML - a Newgrf Meta Language

Post by TadeuszD » 21 Mar 2017 20:56

Transportman wrote:You could check for vehicle_is_potentially_powered, if I read the spec right it should return false if the leading vehicle cannot deliver power, which defines a wagon. I'm not sure what would happen if you also use the power callback and that returns 0 in some cases for engines.
Thank you, Transportman! I hope that vehicle_is_potentially_powered will be good way for better research. :D
Other methods looks like less usefull, because I have too many loco's and wagon's combinations in my set to prepare all livery overrides or to check all dependencies ID by ID (my engines are not grouped in the way easy to do it).
Image

User avatar
Pyoro
Tycoon
Tycoon
Posts: 2473
Joined: 17 Oct 2008 12:17
Location: Virgo Supercluster

Re: NML - a Newgrf Meta Language

Post by Pyoro » 08 Apr 2017 14:46

I'm trying to figure out how to properly animate an object in NML, but the one example I found kinda didn't help me. Well, it did get me started:
First I got this:

Code: Select all

spritelayout spritelayout_parking_11 {
    ground {
        sprite: LOAD_TEMP(1);
	}
	building {
        sprite: spriteset_parking_ground_1(0);
    }
	building {
        sprite: spriteset_parking_cars_1(animation_counter % 4);
    }
}
Nvm the lack of dimensions and such (unless that's the problem ^^).

And then define the object:

Code: Select all

item (FEAT_OBJECTS, item_parking_1) {
    property {
        class:                  "PRLT";
		classname:				string(STR_PRLT);
        name:                   string(STR_PARKING_1);
        climates_available:     ALL_CLIMATES;
        size:                   [1,1];
        build_cost_multiplier:  1;
        remove_cost_multiplier: 1;
        introduction_date:      date(1111,1,1);
        end_of_life_date:       0xFFFFFFFF;
        object_flags:           bitmask(OBJ_FLAG_ANIMATED, OBJ_FLAG_REMOVE_IS_INCOME, OBJ_FLAG_ALLOW_BRIDGE, OBJ_FLAG_ANYTHING_REMOVE);
		animation_info:			[ANIMATION_LOOPING,4];
		animation_speed:		10;
		animation_triggers:		ANIM_TRIGGER_OBJ_TILELOOP;
        height:                 1;
        num_views:              4;
    }
    graphics {
        default:            switch_parking_1_object;
        purchase:           switch_parking_1_purchase;
        autoslope:          return(CB_RESULT_AUTOSLOPE);
        additional_text:    string(STR_PARKING_1_PURCHASE);
    }
}
The "only" problem is that the animation is incredibly fast and kinda glitchy, which I would've thought according to https://newgrf-specs.tt-wiki.net/wiki/N ... tion_speed it shouldn't be. But playing around with values and trying some different things didn't really get me anywhere. Didn't find much in the documentation about animation either :/

So as usual I don't really know what I'm doing here. I'd appreciate if someone could point me in the right direction ;)

edit: &$/$( Figured it out. Should have looked at OpenGFX landscapes first, but forgot it had an animated wind power thing. So I did the frames like that:

Code: Select all

((animation_frame + nearby_tile_random_bits(0,0)) % 3)
And most importantly didn't forget the animation CBs for graphics:

Code: Select all

		anim_control:    return CB_RESULT_NEXT_FRAME;
		anim_next_frame: return CB_RESULT_NEXT_FRAME;
I won't pretend I "get" everything but it works ;)
Last edited by Pyoro on 08 Apr 2017 16:10, edited 1 time in total.

User avatar
Quast65
Tycoon
Tycoon
Posts: 1660
Joined: 09 Oct 2011 13:51
Location: The Netherlands

Re: NML - a Newgrf Meta Language

Post by Quast65 » 08 Apr 2017 16:09

Have you tried changing

Code: Select all

ANIM_TRIGGER_OBJ_TILELOOP
to

Code: Select all

ANIM_TRIGGER_OBJ_BUILT
?

EDIT: Saw your edit, never mind the above ;-)
Projects: http://www.tt-forums.net/viewtopic.php?f=26&t=57266
Screenshots: http://www.tt-forums.net/viewtopic.php?f=47&t=56959

Winner of the following screenshot competitions:
sep 2012, jan 2013, apr 2013, aug 2013, mar 2014, mar 2016
All my work is released under GPL-license (either V2 or V3), if not clearly stated otherwise.

User avatar
Pyoro
Tycoon
Tycoon
Posts: 2473
Joined: 17 Oct 2008 12:17
Location: Virgo Supercluster

Re: NML - a Newgrf Meta Language

Post by Pyoro » 08 Apr 2017 16:14

Quast65 wrote:EDIT: Saw your edit, never mind the above ;-)
Sorry, bad timing ^^;

OBJ_BUILT had the fun effect of updating all parking lots whenever a new parking lot was built if I remember that right. Not exactly what I wanted in this case but who knows, might make sense for some obscure object of some kind (a counter-object ^^).

User avatar
Andrew350
Route Supervisor
Route Supervisor
Posts: 493
Joined: 19 Dec 2011 07:54
Location: Washington State, USA
Contact:

Re: NML - a Newgrf Meta Language

Post by Andrew350 » 19 Apr 2017 03:22

So I'm trying to change a few properties based on chosen parameter settings (properties for which there are no callbacks), and instead of defining all-new items I tried using some kind of nested ternary operators, like so:

Code: Select all

item(...) {
	property {
		speed_limit:                 ((param_difficulty == 0) ? 35 : ((param_difficulty == 1) ? 20 : 0)) mph;
It compiles fine, and seems to work just fine in the game, but is it "safe" to do something like this?

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

Re: NML - a Newgrf Meta Language

Post by Transportman » 20 Apr 2017 19:31

Why would it not be? It resolves to something constant while using it as changing parameters is a risk for the player.
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML

User avatar
Andrew350
Route Supervisor
Route Supervisor
Posts: 493
Joined: 19 Dec 2011 07:54
Location: Washington State, USA
Contact:

Re: NML - a Newgrf Meta Language

Post by Andrew350 » 22 Apr 2017 09:21

Well, I wasn't sure because I've never seen or done anything like this before; I've always defined all properties explicitly except for callbacks. After reading a post about how ternary operators should be avoided I thought there might be some fault with it, so I wanted to make sure. :)

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

Re: NML - a Newgrf Meta Language

Post by McZapkie » 08 May 2017 14:21

How to switch industry sounds off?
I tried to define it as empty array: random_sound_effects: [];
but it is not working (I can still hear sawmill sound in my logging camp)
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.

frosch
OpenTTD Developer
OpenTTD Developer
Posts: 979
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: NML - a Newgrf Meta Language

Post by frosch » 08 May 2017 17:55

Nothing wrong with that. It should work as you described.
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁

Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 1 guest