Adding constants to NML

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

Moderator: Graphics Moderators

Post Reply
User avatar
peignenappe
Engineer
Engineer
Posts: 9
Joined: 15 Jul 2022 19:59
Location: France

Adding constants to NML

Post by peignenappe »

Hi ! I've been playing openTTD for a while now but i'm new to tt-forums and discovered so much exciting stuff about GRFs that i wanted to create some by myself ! So i read documentation about nml and m4nfo then decided to go with nml.

I'm working on a little engine set that will contain at most like 20 engines, but i quickly got hundreds of repeating lines in my nml file. Especially for the common properties of trains.
What i would like to do is defining constants like in the following example, but i dont know what syntax to use or even if its possible as i didn't found doc about this on nml wiki. :? Anyone can help ?

Code: Select all

COMMON_ENGINE_PROPERTIES {
	track_type: ELRL;
	engine_class: ENGINE_CLASS_ELECTRIC;
	sprite_id: SPRITE_ID_NEW_TRAIN;
	and so on...
}
item(FEAT_TRAINS, EE303) {
	property {
		COMMON_ENGINE_PROPERTIES
		name: string(STR_EE303_NAME);
		speed: 201 km/h;
		power: 4200 kW;
		...
For the most curious ones here's a preview of the first engine i've made.
I plan on making a set of fictional electric engines and EMUs to enhance the default set, drawn according to OpenGFX style.
Introduced from the early 80s until 2050, these trains will provide higher speeds and power than the default electric units without upgrading your railways to monorail or maglev.
beta_preview-export.png
beta_preview-export.png (118.7 KiB) Viewed 1019 times
Should i publish a separated development thread ?
Image
Wahazar
Tycoon
Tycoon
Posts: 1451
Joined: 18 Jan 2014 18:10

Re: Adding constants to NML

Post by Wahazar »

You can use c-preprocessor #define
User avatar
peignenappe
Engineer
Engineer
Posts: 9
Joined: 15 Jul 2022 19:59
Location: France

Re: Adding constants to NML

Post by peignenappe »

Wahazar wrote: 16 Jul 2022 10:33 You can use c-preprocessor #define
Thank you ! I didn't know about preprocessors so I made some researches about it and found interesting things : I didn't used nml py-patcher yet but i'll try asap. Any kind of documentation about formating/preprocessing nml files is welcome ! :D
Image
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5656
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: Adding constants to NML

Post by andythenorth »

I'd recommend writing a python compile.

There are a few approaches to it.

I wrote (a very long time ago) a basic guide: viewtopic.php?t=58390

The python compiles for Iron Horse etc are quite complex, but simpler versions are possible: https://github.com/andythenorth/iron-ho ... master/src

A number of other grf authors have their own flavour of python compile, e.g. RUKTS as an example https://github.com/StarRaid/Representitive-UK-Trainset

OpenTTD Discord can sometimes be helpful for this sort of thing also.
User avatar
peignenappe
Engineer
Engineer
Posts: 9
Joined: 15 Jul 2022 19:59
Location: France

Re: Adding constants to NML

Post by peignenappe »

Actually i found these already but my previous answer hasn't been moderated yet ?(
I downloaded that StarRaid's NML patcher and enhanced it a little by writing more logs in the compiled file and adding fancy colors to the console logs :twisted:
I wasn't really into python until yet but it seems pretty easy to work with. Very fun to use in this case !

Thanks for your answer ! :D
Last edited by peignenappe on 16 Jul 2022 22:45, edited 1 time in total.
Image
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 4 guests