var 80+3F in NML

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

Moderator: Graphics Moderators

Post Reply
User avatar
supermop
Tycoon
Tycoon
Posts: 1104
Joined: 21 Feb 2010 00:15
Location: Fitzroy North - 96

var 80+3F in NML

Post by supermop »

Hello,

In discussion on IRC recently, I have been musing using a callback to vary sprites by cargo age (the amount it has decayed so far according to decay rate of whatever it has traveled in so far). The putative example is hot slag or iron from a blast furnace - that cargo sprites might show some orange fire cycle pixels when 'fresh', but fewer as it cools in transit, based on decay rate.

Andythenorth suggested that var 80+3F would be what to use, but we don't have any idea how to use this in NML (or at all for that matter).

Ideally, I'd be looking for something that could be used in a switch like "cargo_age_in_veh", which I would expect to return some value in days or ticks, so I could test for ranges 0..xx, xx..yy, etc.

Anyone have any idea how to use this variable?
michael blunck
Tycoon
Tycoon
Posts: 5948
Joined: 27 Apr 2005 07:09
Contact:

Re: var 80+3F in NML

Post by michael blunck »

supermop wrote: [...] Anyone have any idea how to use this variable?
By using that "var" statement; mentioned a zillion times over here, <searches ...> like this (accessing var 61):

Code: Select all

switch(FEAT_TRAINS, PARENT, switch_can_attach_unit_rail, [STORE_TEMP(position_in_consist_from_end, 0x10F), var[0x61, 0, 0x0000FFFF, 0xC6]])
Problem is it probably won´t give you the desired effect, since usually vars are heavily cached, and refreshed at weird times in recent versions of OTTD.

regards
Michael
Image
User avatar
supermop
Tycoon
Tycoon
Posts: 1104
Joined: 21 Feb 2010 00:15
Location: Fitzroy North - 96

Re: var 80+3F in NML

Post by supermop »

michael blunck wrote:Problem is it probably won´t give you the desired effect, since usually vars are heavily cached, and refreshed at weird times in recent versions of OTTD.
Well you are right - it works, but only updates when the vehicle stops or starts, or loads, or if a random switch triggers it at 32 days.

I am looking to incorporate this in a sprite stack, where the different layers each get their own recolor mapping, as outlined here: https://newgrf-specs.tt-wiki.net/wiki/N ... le_sprites

The problem is, the switches for sprite stacks that I use now only specify recoloring once, and are worded slightly differently than the specs above show. They do work perfectly for what I've used them for so far:

Code: Select all

switch(FEAT_ROADVEHS, SELF, switch_sd4_bus_front, [
	STORE_TEMP((getbits(extra_callback_info1, 8, 8) < 1 ? CB_FLAG_MORE_SPRITES : 0) | PALETTE_USE_DEFAULT, 0x100),
	getbits(extra_callback_info1, 8, 8)
	]) {
	0:	spriteset_sd_b_front_04;
	1:	switch_d_panto;
}
However, if I add another instance of the argument above, with incremented number and different recoloring, I get a weird python error from nmlc:

Code: Select all

Writing output ...[KTraceback (most recent call last):
  File "C:\Python33\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>
  File "nmlc", line 6, in <module>
  File "nml\main.py", line 425, in run
  File "nml\main.py", line 170, in main
  File "nml\main.py", line 403, in nml
  File "nml\actions\action2var.py", line 93, in write
  File "nml\actions\action2var.py", line 154, in write
  File "nml\output_base.py", line 188, in print_varx
  File "nml\output_base.py", line 328, in print_dwordx
  File "nml\output_base.py", line 321, in print_dword
  File "nml\output_base.py", line 166, in prepare_dword
AssertionError
So I must be off track.

Changing the wording to more closely how I interpret the nml documentation I get something like this:

Code: Select all

switch(FEAT_ROADVEHS, SELF, switch_pickup, [
    STORE_TEMP(CB_FLAG_MORE_SPRITES  | PALETTE_USE_DEFAULT, 0x100),
    STORE_TEMP( PALETTE_CC_BROWN, 0x100),
    getbits(extra_callback_info1, 8, 8)
    ]) {
    0:  spriteset_truck;
    1:  spritegroup_box;
    }
But that then only draws the truck in CC_BROWN (not the actual CC), and doesn't draw the second layer, the box, at all.

The documentation doesn't make it clear to me at all how I should assign a different recoloring to each layer, and I am not sure what sets might have such an example.
michael blunck
Tycoon
Tycoon
Posts: 5948
Joined: 27 Apr 2005 07:09
Contact:

Re: var 80+3F in NML

Post by michael blunck »

supermop wrote: The documentation doesn't make it clear to me at all how I should assign a different recoloring to each layer, and I am not sure what sets might have such an example.
Well, I can´t help you with an NML example. At least using different recolouring in sprite stacking works as documented in nfo/m4nfo. Here´s an example. I´ll have a go testing it with var3F.

regards
Michael
Image
User avatar
supermop
Tycoon
Tycoon
Posts: 1104
Joined: 21 Feb 2010 00:15
Location: Fitzroy North - 96

Re: var 80+3F in NML

Post by supermop »

For what it's worth, this seems to work as I'd like, though the CC_RED box looks yellow in game:

Code: Select all

switch(FEAT_ROADVEHS, SELF, switch_pickup_truck, [
    STORE_TEMP( CB_FLAG_MORE_SPRITES | PALETTE_USE_DEFAULT, 0x100),
    ]) {
    default:  spriteset_pickup;
    }
switch(FEAT_ROADVEHS, SELF, switch_pickup_box_3, [
    STORE_TEMP(PALETTE_CC_RED, 0x100),
    ]) {
    default:  spritegroup_pickup_box;
    }
switch(FEAT_ROADVEHS, SELF, switch_pickup_box_2, [
    STORE_TEMP(PALETTE_CC_ORANGE, 0x100),
    ]) {
    default:  spritegroup_pickup_box;
    } 
switch(FEAT_ROADVEHS, SELF, switch_pickup_box_1, [
    STORE_TEMP(PALETTE_CC_GREEN, 0x100),
    ]) {
    default:  spritegroup_pickup_box;
    }        

switch (FEAT_ROADVEHS, SELF, switch_pickup_box, var[0xBF,0,0xFF]) {
    0..4:               switch_pickup_box_1;
    5..9:               switch_pickup_box_2;
    default:            switch_pickup_box_3;
    }

switch(FEAT_ROADVEHS, SELF, switch_pickup, [
    getbits(extra_callback_info1, 8, 8)
    ]) {
    0:      switch_pickup_truck;
    1:      switch_pickup_box;
    }  
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 3 guests