Various NML related questions

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

Moderator: Graphics Moderators

User avatar
LaDoncella
Traffic Manager
Traffic Manager
Posts: 249
Joined: 28 Sep 2004 16:01
Contact:

Re: Various NML related questions

Post by LaDoncella »

eGRVTS2 was probably coded in nml 0.1.* or 0.2.*

I have not been able to find an example of vehicle animation in nml so I cannot compare and figure where the problem is.

stripped down code of the animation code in eGRVTS2:

Code: Select all

/* 2HORSE Animation Switches */
switch (FEAT_ROADVEHS, PARENT, switch_2HORSE_v1_animation, motion_counter) {
	1:  spriteset_2HORSE_v1_a1;
	2:  spriteset_2HORSE_v1_a1;
	3:  spriteset_2HORSE_v1_a2;
	4:  spriteset_2HORSE_v1_a2;
	7:  spriteset_2HORSE_v1_a1;
	8:  spriteset_2HORSE_v1_a1;
	9:  spriteset_2HORSE_v1_a2;
	10:  spriteset_2HORSE_v1_a2;
	13:  spriteset_2HORSE_v1_a1;
	14:  spriteset_2HORSE_v1_a1;
	15:  spriteset_2HORSE_v1_a2;	
	spriteset_2HORSE_v1_a3;
}

switch (FEAT_ROADVEHS, PARENT, switch_2HORSE_v2_animation, motion_counter) {
	[...]
}

switch (FEAT_ROADVEHS, PARENT, switch_2HORSE_v3_animation, motion_counter) {
	[...]
}

switch (FEAT_ROADVEHS, PARENT, switch_2HORSE_v4_animation, motion_counter) {
	[...]
}

/* HORSE SPRITES RANDOMIZERS */
random_switch (FEAT_ROADVEHS, SELF, random_switch_spriteset_2HORSE) {
	dependent: random_switch_spriteset_1HORSE;
	1: return switch_2HORSE_v1_animation;
 	1: return switch_2HORSE_v2_animation;
	1: return switch_2HORSE_v3_animation; 
	1: return switch_2HORSE_v4_animation; //1+1+1+1 = 4 = 2^2
}


/* START: item_2HORSE_TEAM */
item(FEAT_ROADVEHS, item_2HORSE_TEAM, 11) {
    property {
        [...]
    }
	graphics
	{
		colour_mapping:	switch_recolour_function;
		default: random_switch_spriteset_2HORSE;
	}
User avatar
LaDoncella
Traffic Manager
Traffic Manager
Posts: 249
Joined: 28 Sep 2004 16:01
Contact:

Re: Various NML related questions

Post by LaDoncella »

After some more digging around, looked at the animation code in timberwolf uk road vehicles. And saw the modulus operator clamping the motion_counter.
This is interesting because I'm pretty sure that in the ancient nml version I used back then this would not work. :?

Solution:

Code: Select all

switch (FEAT_ROADVEHS, PARENT, switch_2HORSE_v2_animation, motion_counter % 16)
Last edited by LaDoncella on 03 Jun 2021 16:13, edited 1 time in total.
Eddi
Tycoon
Tycoon
Posts: 8254
Joined: 17 Jan 2007 00:14

Re: Various NML related questions

Post by Eddi »

this was a misfeature in early nmlc versions, that motion counter was arbitrarily limited to 16, instead of the full range allowed by the newgrf specs. this lead to problems for example with odd animation cycle lengths.
User avatar
Greyfur
Engineer
Engineer
Posts: 112
Joined: 31 Oct 2004 12:43
Location: Slovakia - Bratislava
Contact:

Re: Various NML related questions

Post by Greyfur »

Hello,

I am fighting with thisfor a while now.

Is it possible to set certain refits to only appear in a certain year interval or from a certain year and not to be available the whole time? Like when a loco was produced 1961-1970 but certain livery was available only since 1985? How can I code this?

Thank you!
My project: CS Bus Set viewtopic.php?f=26&t=87962

Škoda - Praga - Tatra - Karosa - Oasa - Prima TL - Zliner - TAM BUS - SOR - Novoplan - Granus - Slovbus - Tedom - Irisbus - Iveco

Woof !
Wahazar
Tycoon
Tycoon
Posts: 1451
Joined: 18 Jan 2014 18:10

Re: Various NML related questions

Post by Wahazar »

Greyfur wrote: 03 Jun 2021 15:20 Like when a loco was produced 1961-1970 but certain livery was available only since 1985? How can I code this?
Try
build_year >= year
or
date_of_last_service >= date(year, 1, 1)
depending if livery should be applied during purchase or workshop maintenance.
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
Greyfur
Engineer
Engineer
Posts: 112
Joined: 31 Oct 2004 12:43
Location: Slovakia - Bratislava
Contact:

Re: Various NML related questions

Post by Greyfur »

McZapkie wrote: 03 Jun 2021 17:21 Try
build_year >= year
or
date_of_last_service >= date(year, 1, 1)
depending if livery should be applied during purchase or workshop maintenance.
I more thought about a change in cargo subtype refit options based on the year. Sorry to not be clear previously.
My project: CS Bus Set viewtopic.php?f=26&t=87962

Škoda - Praga - Tatra - Karosa - Oasa - Prima TL - Zliner - TAM BUS - SOR - Novoplan - Granus - Slovbus - Tedom - Irisbus - Iveco

Woof !
Eddi
Tycoon
Tycoon
Posts: 8254
Joined: 17 Jan 2007 00:14

Re: Various NML related questions

Post by Eddi »

subtype refit is a bit tricky to work with.

the general approach looks like this:
  • a callback is called repeatedly, each time with an increased number.
  • in the callback condition, you can combine checking this number with any other condition (like current_year), and choose the appropriate callback result
  • valid callback results are a text, that is later displayed in the cargo refit selection window, or a "stop this callback iteration"
as a rule of thumb: it's fairly easy to add new entries to the end of the list over the time, but weird things happen if you insert them in the middle, or remove them.
paritcl3s
Engineer
Engineer
Posts: 28
Joined: 15 Jun 2020 08:01

Re: Various NML related questions

Post by paritcl3s »

Relating to Town Name changes,

I've a file that compiles, an abbreviated edition is coded below.

The issue is that every names(one) category applies one from names(two), can this function be randomised to not occur from time to time?

Code: Select all

grf {
	grfid: "TT\07\01";
	name: string(STR_GRF_NAME);
	desc: string(STR_GRF_DESC);
	version: 0;
	min_compatible_version: 0;
}

town_names(one) {
{
text("Gaanrork", 1),
text("Trud", 1),
text("Qumeira", 1),
}}

town_names(two) {
{
text(" Land", 1),
text(" Area", 1),
text(" Region", 1),
}}

town_names {

styles: string(STR_NAME_SET);
{
town_names(one,1)
}
{
town_names(two,50)
}}
Image
Eddi
Tycoon
Tycoon
Posts: 8254
Joined: 17 Jan 2007 00:14

Re: Various NML related questions

Post by Eddi »

an immediate way to do this to add a town name part that is an empty string.
paritcl3s
Engineer
Engineer
Posts: 28
Joined: 15 Jun 2020 08:01

Re: Various NML related questions

Post by paritcl3s »

Uhh, kay, so,

I overwrote into generic skyscraper set, indexed the image using DOS palette and now the building is having a rave.
Would I be right to assume these are the water colours acting up mostly?
Image
Image
Eddi
Tycoon
Tycoon
Posts: 8254
Joined: 17 Jan 2007 00:14

Re: Various NML related questions

Post by Eddi »

yes. water cycle, fire cycle, some other cycles, ...

you probably made a mistake saving your image. if you convert an RGB image to an indexed image in your editor, you must make sure that none of the special colours are used. so during this conversion you must use a smaller palette that omits those animated colours.

PS: this doesn't really have anything to do with NML
Bad_Brett
Transport Coordinator
Transport Coordinator
Posts: 355
Joined: 01 Feb 2007 17:59
Location: Stockholm, Sweden

Re: Various NML related questions

Post by Bad_Brett »

Ok... So recently I've encountered a weird issue. For some reason, some sprites aren't drawn correctly when they are close to the edge of the screen. I realise that there may be tons of explanations for this, such as GPU drivers, poor nml coding, sprite overlapping and so on, but I'm just wondering if you have encountered this before:

1. Part of the tender is missing when the engine is close to the edge of the screen:
2021-08-22 16_41_12-.png
2021-08-22 16_41_12-.png (272.84 KiB) Viewed 8018 times
2. Problem is solved if I zoom out:
2021-08-22 16_41_32-OpenTTD 12.0-beta1.png
2021-08-22 16_41_32-OpenTTD 12.0-beta1.png (379.45 KiB) Viewed 8018 times
3. If I move away a bit from the edge of the screen and zoom in again, it works perfectly.:
2021-08-22 16_42_07-OpenTTD 12.0-beta1.png
2021-08-22 16_42_07-OpenTTD 12.0-beta1.png (275.71 KiB) Viewed 8018 times
The funny thing is that this only happens when the train is close to the edge of the screen. And for some reason, it only happens to the tender, not the engine, even though I use the same script to create both of them.

I'm using OpenTTD 12.0 beta (if that matters). And as you can tell, the engine and tender consist of many articulated parts, in order use the extra turning angles "hack". So... any guesses? :)
Eddi
Tycoon
Tycoon
Posts: 8254
Joined: 17 Jan 2007 00:14

Re: Various NML related questions

Post by Eddi »

can you try switching off OpenGL?
Bad_Brett
Transport Coordinator
Transport Coordinator
Posts: 355
Joined: 01 Feb 2007 17:59
Location: Stockholm, Sweden

Re: Various NML related questions

Post by Bad_Brett »

Eddi wrote: 22 Aug 2021 20:13 can you try switching off OpenGL?
I tried to turn off hardware acceleration, but it didn't make a difference. I couldn't find any other settings that seemed to have anything to do with OpenGL, so please let me know if I'm looking in the wrong places. :)

Tonight I tried my newgrf with with 1.10.2 and interestingly enough, the glitch didn't occur. So if OpenGL support was added in in 1.11, it would seem like a good guess. But... how do I turn it off properly? :oops:
Taschi
Route Supervisor
Route Supervisor
Posts: 425
Joined: 11 Oct 2014 22:58

Re: Various NML related questions

Post by Taschi »

I think Timberwolf mentioned some odd issues with very long (i. e. realistically proportioned) vehicles being only partially rendered on some occasions in the thread of his UK trainset, maybe he has some idea what might be wrong here?
User avatar
3iff
Tycoon
Tycoon
Posts: 1093
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: Various NML related questions

Post by 3iff »

A major issue has found me.

I had some strange errors on an otherwise error free nml file. I eventually traced it to the fact that my concurrent ActionD registers were 64/64 (as reported by nml 0.6.0).

So I've run out of registers. Any idea how I can free any up? If I understand the wiki correctly, it's to do with grf parameters but I'm only using 16, so many more are being eaten up by something...

Any help or guidance would be greatly appreciated because at the moment I'm stuck!
User avatar
sevenfm
Engineer
Engineer
Posts: 117
Joined: 25 Jul 2016 23:44
Location: Soviet Russia

Re: Various NML related questions

Post by sevenfm »

I think I had similar problem when I defined too much global variables. Some of them could be probably replaced with defines which need using preprocessor.
I had to rework code to reduce number of global defined variables and use parameters instead of some.
Bad_Brett
Transport Coordinator
Transport Coordinator
Posts: 355
Joined: 01 Feb 2007 17:59
Location: Stockholm, Sweden

Re: Various NML related questions

Post by Bad_Brett »

For some reason, I can't figure out how to create multi-tile objects. For industries, we have the layouts property, and for houses, we have the graphics_[north|west|east|south] callbacks.

What I've tried:

1. Let the default callback call a switch with the relative_pos variable to return the different sprite_layouts.

2. Just set the size to 2x2 and a returned a single sprite_layout.

In both cases, the game crashes. So...What is the correct way to do this? :)
User avatar
3iff
Tycoon
Tycoon
Posts: 1093
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: Various NML related questions

Post by 3iff »

The solution to the ActionD registers being used up has been solved. As sevenfm said, global variables (or free variables as I thought of them) need a register when used in a calculation. I had a lot, and soon used up the limit of 64.

Looking though my code, 2 were no longer in actual use and a few had very limited use. Once I cleared those out and made some other changes, I got down to 53/64. Now I'm at 55/64 and have 9 available for further expansion.

So, if NML complains about 'no free registers', this is most likely the cause. Hope this helps.
Bad_Brett
Transport Coordinator
Transport Coordinator
Posts: 355
Joined: 01 Feb 2007 17:59
Location: Stockholm, Sweden

Re: Various NML related questions

Post by Bad_Brett »

Short question... what's the easiest way to get the total length of a train (not the number of parts in the consist, but the length in tiles that is displayed when the engine is in the depot)?
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 1 guest