FooBar's Random NFO-related Problems

Discuss, get help with, or post new graphics for TTDPatch and OpenTTD, using the NewGRF system, here. Graphics for plain TTD also acceptable here.

Moderator: Graphics Moderators

Post Reply
User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

FooBar's Random NFO-related Problems

Post by FooBar »

One particular vehicle in my set has a long list of requirements concerning it's livery. One of those requirements is that it should have a randomly picked livery starting from the year 2007. Most items of the list are working the way they should, but the random part is giving me troubles.

Symptoms:
Randomisation is applied to every single part of the articulated vehicle, not to the vehicle as a whole (see screenshot below).

As I can't seem to figure out what I'm doing wrong (I tried two different varAction2 chains, see below), I'm asking: What do I have to do to get this working correctly*?

*) I might need to explain 'correctly' a bit more. What I want to accomplish is the following:
Starting from 2007 the vehicle should be available in two different liveries (RED and WHITE). The game should pick one of both liveries at random as soon as a new vehicle is bought. The vehicle needs to have a complete RED or a complete WHITE livery (and not something in between as shown in screenshot below).


All help is appreciated. This should become the most interesting feature of the set. Only thing left is getting it to work :wink:


Below, my two attempts.

Code: Select all

//1st attempt

-1 * 0	 02 01 20 81 40 00 FF 02 31 00 00 00 32 00 01 01 33 00 //what spritesets to use (set 3) red/white

-1 * 0	 02 01 19 81 40 00 FF 02 15 00 00 00 16 00 01 01 17 00 //what spritesets to use (set 2) red/beige

-1 * 0	 02 01 11 81 40 00 FF 02 12 00 00 00 13 00 01 01 14 00 //what spritesets to use (set 1) blue/grey


-1 * 0	 02 01 30 80 00 00 08 19 00 20 00 19 00 19 00 19 00 19 00 19 00 19 00 //random livery for years 2007+


-1 * 0	 02 01 18 81 C4 00 FF 03  19 00 \b0 \b71  11 00 \b72 \b80  19 00 \b81 \b86  30 00 
//find out the year built (value since 1920, range) and use the appropriate liveries [19] if year [1925-2175] 
//otherwise [11] default


-1 * 0	 02 01 10 81 10 00 FF 01 46 80 01 02 FF 80 //build articulated vehicle add 01 to 02 wagons

-1 * 0	 02 01 09 81 10 00 FF 01 49 80 01 01 18 00 //use sound 01 //otherwise[18]

-1 * 0	 02 01 08 81 0C 00 FF 02 09 00 33 33 10 00 16 16 18 00 
//sound effect callback [09] //articulated vehicle callback [10] //otherwise [18]

//and now for buy menu
-1 * 0	 02 01 FD 81 01 00 FF 01 FB 00 \b72 \b80 FC 00 
//find out the year and use the appropriate buy menu gfx [FC] if year [1925-2175] //otherwise [FB] default


-1 * 0	 03 01 01 46 01 FF FD 00 08 00
From bottom to top: Action 3; Set graphic for buy menu depending on year; callbacks; set sound; build articulated vehicle; year-dependant liveries; random livery for 2007+; possible liveries.

Code: Select all

//2nd attempt

-1 * 0	 02 01 33 81 0C 00 FF 01 02 80 11 11 CC 00

-1 * 0	 02 01 32 81 0C 00 FF 01 05 80 11 11 CB 00

-1 * 0	 02 01 31 81 0C 00 FF 01 02 80 11 11 CA 00

-1 * 0	 02 01 23 81 0C 00 FF 01 02 80 11 11 BC 00

-1 * 0	 02 01 22 81 0C 00 FF 01 05 80 11 11 BB 00

-1 * 0	 02 01 21 81 0C 00 FF 01 02 80 11 11 BA 00

-1 * 0	 02 01 13 81 0C 00 FF 01 02 80 11 11 AC 00

-1 * 0	 02 01 12 81 0C 00 FF 01 05 80 11 11 AB 00

-1 * 0	 02 01 11 81 0C 00 FF 01 02 80 11 11 AA 00




-1 * 0	 02 01 73 81 40 00 FF 02 31 00 00 00 32 00 01 01 33 00 //what spritesets to use (set 3) red/white

-1 * 0	 02 01 72 81 40 00 FF 02 21 00 00 00 22 00 01 01 23 00 //what spritesets to use (set 2) red/beige

-1 * 0	 02 01 71 81 40 00 FF 02 11 00 00 00 12 00 01 01 13 00 //what spritesets to use (set 1) blue/grey


-1 * 0	 02 01 63 81 10 00 FF 01 46 80 01 02 FF 80 //build articulated vehicle add 01 to 02 wagons

-1 * 0	 02 01 53 81 10 00 FF 01 49 80 01 01 73 00 //use sound 01 //otherwise[18]

-1 * 0	 02 01 43 81 0C 00 FF 02 53 00 33 33 63 00 16 16 73 00 
//sound effect callback [09] //articulated vehicle callback [10] //otherwise [18]


-1 * 0	 02 01 62 81 10 00 FF 01 46 80 01 02 FF 80 //build articulated vehicle add 01 to 02 wagons

-1 * 0	 02 01 52 81 10 00 FF 01 49 80 01 01 72 00 //use sound 01 //otherwise[18]

-1 * 0	 02 01 42 81 0C 00 FF 02 52 00 33 33 62 00 16 16 72 00 
//sound effect callback [09] //articulated vehicle callback [10] //otherwise [18]


-1 * 0	 02 01 61 81 10 00 FF 01 46 80 01 02 FF 80 //build articulated vehicle add 01 to 02 wagons

-1 * 0	 02 01 51 81 10 00 FF 01 49 80 01 01 71 00 //use sound 01 //otherwise[18]

-1 * 0	 02 01 41 81 0C 00 FF 02 51 00 33 33 61 00 16 16 71 00 
//sound effect callback [09] //articulated vehicle callback [10] //otherwise [18]


-1 * 0	 02 01 44 80 00 00 08 42 00 43 00 42 00 42 00 42 00 42 00 42 00 42 00 //random livery for years 2007+

-1 * 0	 02 01 40 81 C4 00 FF 03  42 00 \b0 \b71  41 00 \b72 \b80  42 00 \b81 \b86  44 00 
//find out the year built (value since 1920, range) and use the appropriate liveries [19] if year [1925-2175] 
//otherwise [11] default


//and now for buy menu
-1 * 0	 02 01 FD 81 01 00 FF 01 FB 00 \b72 \b80 FC 00 
//find out the year and use the appropriate buy menu gfx [FC] if year [1925-2175] //otherwise [FB] default

-1 * 0	 03 01 01 46 01 FF FD 00 40 00
For this setup I first determine what livery to use, then callbacks for sound and articulated vehicle etc.

The results of both attempts are equal.
Attachments
Funny, but not what I want.
Funny, but not what I want.
Naamloos-1.png (9.02 KiB) Viewed 1899 times
Last edited by FooBar on 15 Aug 2008 19:29, edited 2 times in total.
DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Re: Articulated Vehicle Random Livery

Post by DaleStan »

I'm not seeing an 83 byte there. If you want the randomness to be consistent throughout the entire vehicle, you need a type 83 random, not a type 80.
To get a good answer, ask a Smart Question. Similarly, if you want a bug fixed, write a Useful Bug Report. No TTDPatch crashlog? Then follow directions.
Projects: NFORenum (download) | PlaneSet (Website) | grfcodec (download) | grfdebug.log parser
User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: Articulated Vehicle Random Livery

Post by FooBar »

Thanks again, DaleStan!

I don't know where I'd be without your great knowledge, but that really wouldn't be here trying to create GRFs!
User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: FooBar's Random NFO-related Problems

Post by FooBar »

I figured I could as wel use this topic again for my next problem...


I currently have this code which should replace the title of the maglev construction toolbar:

Code: Select all

-1 * 0 04 48 FF  01  0B 10 "Metro rail construction" 00 //for toolbar
It actually does replace the text, but with strange results. The text is not being displayed in the usual white, but in some bright orange. Even more strange is, when I move the toolbar, the colour of the text changes to all colours of the rainbow, depending on the position of the toolbar!

Is it me doing something wrong, is it Patch doing something wrong, or is it intended behaviour?

Using patch r1975, no other newgrfs but the one I'm working on (with just some basic action 0A, 05 and 09, and ofcourse this 04).
Attachments
weird.png
weird.png (3.38 KiB) Viewed 1496 times
User avatar
Lakie
TTDPatch Developer
TTDPatch Developer
Posts: 1799
Joined: 26 May 2004 16:37
Location: Britain
Contact:

Re: FooBar's Random NFO-related Problems

Post by Lakie »

If I read the text ids correctly, you should have put a colour code in front of the string. In this particular case 0x94 (White).
You can read what colour codes are currently used for the strings you are replacing here.

Hope that helps,
~ Lakie
TTDpatch Developer 2005 - 2010 ~ It all started because of shortened vehicle not loading correctly, now look where I've gone with it!
Grfs coded ~ Finnish Train Set (Teaser) | Bm73 (Release 3) | Emu 680 (Release 3)| Glass Station (Release 1) | UK Roadset (Version 1.1a) | New Water Coasts (Version 7)
Pikka: "Lakie's a good coder, but before he'll add any feature to TTDP you have to convince him that you're not going to use it to destroy the world as we know it."
User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: FooBar's Random NFO-related Problems

Post by FooBar »

Thanks, putting \94 in front of the sting works beautifully! If everything was this easy...
User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: FooBar's Random NFO-related Problems

Post by FooBar »

Again I have to use this topic...

I'm currently trying to figure out how to disable my grf if it's loaded before another grf. I just can't seem to figure out why the code below doesn't work.

Code: Select all

//Skip if opengfx infra is not active but will be active
-1 * 0 09 88 04 \7gG  52 57 13 03  01
//Always skip
-1 * 0 09 9A 01 \7< 00 01
//Error message
-1 * 0 0B 03 7F 05 "OpenGFX Infrastructure" 00
IMO, what it should do is this:
If the OpenGFX infra set is not active but will be active later on (i.e. is below my grf) it skips one sprite so that the error is displayed and my grf deactivated. If OGFX infra is not not active but will be active (i.e. not loaded or loaded after my grf), the skip is not executed so the skip in the second sprite is so that the error message is ignored.

Regardless of the grf order, in Patch my grf is always disabled with error message "Error: GRF Status". In Open, it is also always disabled but displays my custom error text.

Can anyone explain to me what I'm doing wrong, or explain how I should disable my grf in case it's loaded before another grf?
User avatar
mart3p
Tycoon
Tycoon
Posts: 1030
Joined: 31 Oct 2005 21:00
Location: UK

Re: FooBar's Random NFO-related Problems

Post by mart3p »

I think the problem is your second line of code "always skip". You are using a "less than" test with a value of zero. As variable 9A sets all bits to on, the value of its lowest byte is not less than zero, so the next line is never skipped.

For an action 9 that always skips, I suggest you use the following code which uses a bit test:

Code: Select all

//Always skip
-1 * 0 09 9A 01 \71 00 01
Image
User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: FooBar's Random NFO-related Problems

Post by FooBar »

Thanks, Mart! That indeed works a lot better than my attempt!

Seems like I didn't understand the wiki. For var 9A it reads Always -1; you can use this to make unconditional jumps, so I figured -1 is a negative number (which I found a little odd anyways), so -1 < 0 and that then would be the way I needed to use that variable. Not.

Anyways, it's working charmingly now. I think I'm going to edit the wiki, which I made a habit when I didn't understand things or taken long time to figure out :D
User avatar
mart3p
Tycoon
Tycoon
Posts: 1030
Joined: 31 Oct 2005 21:00
Location: UK

Re: FooBar's Random NFO-related Problems

Post by mart3p »

Yes I agree the wiki is a little unclear as to whether the comparisons are signed or unsigned. I’ve always used a bit test in this situation to avoid the issue. ;)
Image
michael blunck
Tycoon
Tycoon
Posts: 5954
Joined: 27 Apr 2005 07:09
Contact:

Re: FooBar's Random NFO-related Problems

Post by michael blunck »

Or use any other "impossible" condition (e.g., if TTDPatch version == 0, if climate == tropical when in temperate, etc.) for an unconditional skip. BTW, constructions like these had to be used before var 9A had been introduced (for other purposes, BTW2).

regards
Michael
Image
DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Re: FooBar's Random NFO-related Problems

Post by DaleStan »

mart3p wrote:Yes I agree the wiki is a little unclear as to whether the comparisons are signed or unsigned.
All NFO operations are either unsigned unless the operation itself has documentation that says otherwise. Even if one of the operands is documented as "-1", the operation is still unsigned.

I'm not quite sure where to add this information, though.
To get a good answer, ask a Smart Question. Similarly, if you want a bug fixed, write a Useful Bug Report. No TTDPatch crashlog? Then follow directions.
Projects: NFORenum (download) | PlaneSet (Website) | grfcodec (download) | grfdebug.log parser
Post Reply

Return to “Graphics Development”

Who is online

Users browsing this forum: No registered users and 17 guests