Page 12 of 14

Re: Various NML related questions

Posted: 02 Jun 2021 22:12
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;
	}

Re: Various NML related questions

Posted: 02 Jun 2021 22:58
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)

Re: Various NML related questions

Posted: 03 Jun 2021 09:59
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.

Re: Various NML related questions

Posted: 03 Jun 2021 15:20
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!

Re: Various NML related questions

Posted: 03 Jun 2021 17:21
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.

Re: Various NML related questions

Posted: 03 Jun 2021 19:23
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.

Re: Various NML related questions

Posted: 03 Jun 2021 20:57
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.

Re: Various NML related questions

Posted: 28 Jun 2021 13:36
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)
}}

Re: Various NML related questions

Posted: 28 Jun 2021 18:14
by Eddi
an immediate way to do this to add a town name part that is an empty string.

Re: Various NML related questions

Posted: 20 Aug 2021 20:31
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

Re: Various NML related questions

Posted: 21 Aug 2021 08:21
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

Re: Various NML related questions

Posted: 22 Aug 2021 15:00
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 8434 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 8434 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 8434 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? :)

Re: Various NML related questions

Posted: 22 Aug 2021 20:13
by Eddi
can you try switching off OpenGL?

Re: Various NML related questions

Posted: 23 Aug 2021 00:08
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:

Re: Various NML related questions

Posted: 23 Aug 2021 00:28
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?

Re: Various NML related questions

Posted: 26 Aug 2021 09:27
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!

Re: Various NML related questions

Posted: 26 Aug 2021 09:41
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.

Re: Various NML related questions

Posted: 30 Aug 2021 01:16
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? :)

Re: Various NML related questions

Posted: 31 Aug 2021 09:08
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.

Re: Various NML related questions

Posted: 31 Aug 2021 20:22
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)?