Random bits in Var 2

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
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5631
Joined: 13 Sep 2004 13:21
Location: The Moon

Random bits in Var 2

Post by PikkaBird »

Cookie up for grabs.

[How] Can I access the random bits (of an industry tile) in a var action 2?

'Create a random action 2 that picks between n var2s, set constants in the var2s then point all the var2s to a 1C test' would work, but is a little inelegant...
User avatar
mart3p
Tycoon
Tycoon
Posts: 1030
Joined: 31 Oct 2005 21:00
Location: UK

Re: Random bits in Var 2

Post by mart3p »

For station tiles, I tried using variable 5F. This works fine in TTDPatch but is unsupported by OpenTTD.

I ended up using a random action 2 that chooses between a number of values, then using a procedure call (variable 7E) to call the random action 2.
Image
DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Re: Random bits in Var 2

Post by DaleStan »

If 5F is giving you random bits, I'm pretty sure it's broken. The documentation says "random triggers", and I remember discussion to the effect of "this is triggers, not bits, as bits are accessible via a random 2".

I'm not aware of any more elegant way to read an industry tile's (or house's) random bits.
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
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5631
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: Random bits in Var 2

Post by PikkaBird »

Indeed, that's what I thought when I read the spec for 5F.

I ended up using my inelegant solution, and it works well enough.
User avatar
mart3p
Tycoon
Tycoon
Posts: 1030
Joined: 31 Oct 2005 21:00
Location: UK

Re: Random bits in Var 2

Post by mart3p »

DaleStan wrote:If 5F is giving you random bits, I'm pretty sure it's broken. The documentation says "random triggers", and I remember discussion to the effect of "this is triggers, not bits, as bits are accessible via a random 2".
So "random triggers" means the trigger bits themselves (i.e. bit 0 - new cargo waiting, bit 1 - no more cargo, etc.)?

I tried it anyway, to see what would happen and as I say, it seemed to give random bits. The value returned was certainly different for each station tile of any one platform. But I was only using bits 16 and 17, so maybe these just contain junk. This shouldn’t be the case though, as the spec says var 5F is a doubleword...


Edit: Here’s a test GRF and the NFO code that demonstrates this behaviour. It simply selects a sprite layout with numbers 0 to 3, using var 5F bits 16 and 17.
var5F.png
var5F.png (10.29 KiB) Viewed 2210 times
I also tested with bits 0 and 1, this also gives random selection of the sprites but for the whole station. This is what would be expected if var 5F was accessing the random bits but not the random triggers.
Attachments
Var 5F test.zip
(2.87 KiB) Downloaded 71 times
Image
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 991
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: Random bits in Var 2

Post by frosch »

Hmm, indeed, this var is missing in ottd. However mart3p is right here:
newsprit.asm wrote:.getrandomtriggers:
jmp [getrandombits+ecx*4]
It does return random bits.

So what should it return? IMO randombits are more useful than random triggers. Though 32bits have enough room for both.
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
michael blunck
Tycoon
Tycoon
Posts: 5954
Joined: 27 Apr 2005 07:09
Contact:

Re: Random bits in Var 2

Post by michael blunck »

Yes, this is faulty. Var 5F should´ve returned all trigger bits which have been triggered so far.

AFAIR, this feature had been introduced by Josef a long time ago on my request (to be working together with CB32), but even back then this bug seemed to have been in existence. Obviously it had never been fixed, and after a while it went out of focus. 8)

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

Re: Random bits in Var 2

Post by DaleStan »

So, since obviously no one has ever used 5F for its documented purpose, should I/we/someone/whoever:
1) Fix it to agree with the documentation?
2) Fix the documentation to agree with the behaviour?
3) Add the triggers in the third byte and update the documentation appropriately?
4) Move the bits to the high word, put the triggers in the low byte, and update the documentation appropriately?
5) Something else?
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
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 991
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: Random bits in Var 2

Post by frosch »

Wrt 3): Fourth byte. Stations need 3 bytes for the bits.
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
peter1138
OpenTTD Developer
OpenTTD Developer
Posts: 1794
Joined: 30 Mar 2005 09:43

Re: Random bits in Var 2

Post by peter1138 »

This has been changed to triggers bits in the low byte and random bits in the top three bytes, and is also now supported in OpenTTD.
He's like, some kind of OpenTTD developer.
Post Reply

Return to “Graphics Development”

Who is online

Users browsing this forum: Google [Bot] and 7 guests