Trying to make sense of other_veh_z_offset

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

Moderator: Graphics Moderators

Post Reply
Bad_Brett
Transport Coordinator
Transport Coordinator
Posts: 355
Joined: 01 Feb 2007 17:59
Location: Stockholm, Sweden

Trying to make sense of other_veh_z_offset

Post by Bad_Brett »

As you may know, I'm dividing each vehicle into several parts in order to get the extra turning angles. This works pretty well, but also creates som gltiches, which has been discussed earlier. I.e entering a bridge after a slope will look really weird. So, the solution is to divide the sprites into smaller sprites and assign a sprite to every part of the vehicle (instead using dummy sprites). Right now, my solution looks like this:

Straight flat tracks: 1 sprite per articulated part
Sloped tracks: 1 sprites per every two articulated parts (because of how slopes work)
Curves: 1 sprite per vehicle

This works pretty well, except for the transition between flat tracks and sloped tracks. My idea was to use the same concept as with the extra turning angles, and use the other_veh_z_offset variable to decide when a vehicle is entering a entering a slope tile. And it ...kind of... works. But I can't figure out what's going on.
slope.png
slope.png (2.95 KiB) Viewed 3553 times
My idea was to use other_veh_z_offset to check the value of the first part and the last part (as shown in the picture):

Code: Select all

other_veh_z_offset(first_part) - other_veh_z_offset(last_part)
This should always give the same result for all the parts in the vehicle:

Code: Select all

Part 1: +0 - (-3) = 3
Part 2: +1 - (-2) = 3
Part 3: +2 - (-1 = 3
Part 4: +3 - 0 = 3
Part 5: +3 - 0 = 3
Part 6: +3 - 0 = 3
So in this case, all parta should get train_spriteset_slope_up_3:

Code: Select all

-3: return train_spriteset_slope_down_3;
-2: return train_spriteset_slope_down_2;
-1: return train_spriteset_slope_down_1;
0: return train_spriteset_normal;
1: return train_spriteset_slope_up_1;
2: return train_spriteset_slope_up_2;
3: return train_spriteset_slope_up_3;
Except that it doesn't seem to work the way I thought it would:
slope_error2.png
slope_error2.png (117.68 KiB) Viewed 3553 times
So for some reason, it picks the wrong spritesets for last parts. It picks sprites for down slopes instead, which means that the returned value must be negative, which I simply cannot understand, since the last part should return 3-0=3. How can this value ever be negative?

However, if I instead add the results by using the formula (plus instead of minus):

Code: Select all

other_veh_z_offset(first_part) + other_veh_z_offset(last_part)
...it works. But I can't figure out why. Because if we look at the picture again, I'd assume that the results would be something like this:

Code: Select all

Part 1: +0 + (-3) = -3
Part 2: +1 + (-2) = -1
Part 3: +2 + (-1) = 1
Part 4: +3 + 0 = 3
Part 5: +3 + 0 = 3
Part 6: +3 + 0 = 3
Which for some reason return the correct spritesets, even though they shouldn't. So what's going on here? Obviously there's something I don't understand.

So, my questions are:

1. A tile is 16 X/Y units, but how many Z units?
2. Can the formula other_veh_z_offset(first_part) - other_veh_z_offset(last_part) be used to achieve what I want?
3. Is there any way I can debug this and check what values the switches actually return?
4. Is there a NewGRF that has solved this problem in a similiar fashion?
Last edited by Bad_Brett on 12 Oct 2021 23:08, edited 1 time in total.
michael blunck
Tycoon
Tycoon
Posts: 5948
Joined: 27 Apr 2005 07:09
Contact:

Re: Trying to make sense of other_veh_z_offset

Post by michael blunck »

Bad_Brett wrote: 1. A tile is 16 X/Y units, but how many Z units?
IIRC, slope height is 8 px. Tile dimension is 64 × 64 px.

regards
Michael
Image
Eddi
Tycoon
Tycoon
Posts: 8254
Joined: 17 Jan 2007 00:14

Re: Trying to make sense of other_veh_z_offset

Post by Eddi »

a tile is 16 movement units along the main axis, 8 units along a diagonal trackbit, 8 units height difference on a slope, and road bits around curves is complicated...
Bad_Brett
Transport Coordinator
Transport Coordinator
Posts: 355
Joined: 01 Feb 2007 17:59
Location: Stockholm, Sweden

Re: Trying to make sense of other_veh_z_offset

Post by Bad_Brett »

Eddi wrote: 12 Oct 2021 22:07 a tile is 16 movement units along the main axis, 8 units along a diagonal trackbit, 8 units height difference on a slope, and road bits around curves is complicated...
That's what I figured... And that's why I use only half the number of sprites when entering a slope. But I still can't figure out why I get a negative number instead of a positive one.
Eddi
Tycoon
Tycoon
Posts: 8254
Joined: 17 Jan 2007 00:14

Re: Trying to make sense of other_veh_z_offset

Post by Eddi »

i tried to look for some debug output in the code, but couldn't find any. problem is that this output, if it existed, would be extremely spammy, as the callbacks are evaluated very very often.
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 2 guests