Hello!
I used random_switch for industry and needed to re randomise it.
WIKI says that "Industry tiles can rerandomise both their own random bits as well as the random bits of the industry (via type PARENT)." So I did a test. I created 4 independent random_switch for industry, which stores 4 variables and placed them in monthly_prod_change callback
And I placed random_switch in random trigger of industry tiles in order to re randomize the first 4.
I expected my variables to change every month, but the actual result was very surprising to me.
In fact, my variables only changed their values once. And they were never changed again. Moreover, the variables of different farms took the same value.
And what surprised me the most is that each time I did this test (new game), I got the same sequence of variables: 1, 1, 1, 2. How this could be?
After that I decided to determine how often in fact the random_trigger triggers.
If I understood the WIKI correctly, the frequency of the random_trigger call depends on random_switch trigger event.
So I created 3 counters 0->5 and place one of them in produce_256_ticks callback. The other 2 were placed in random_trigger, which called random_switch with TRIGGER_INDUSTRYTILE_256_TICKS
I expected my counters to change at the same time or at the same frequency. But in fact the last 2 counters (placed in random_trigger) changed it's value faster. The farm has only 1 tile of these types, if it does matter.
So the questions are
What I was doing wrong or misunderstanding?
Is there any way to re randomize random_switch for industry?
How often does random_trigger called?
Using random_switch for industry
Moderator: Graphics Moderators
Re: Using random_switch for industry
I'll hazard a guess that this is because rerandomization happens in an undocumented callback 1, which means random switches inside other callback chains are never seen during rerandomization. The solution would be to repeat your random switches in a manner that they are seen outside the callback chains.
He's like, some kind of OpenTTD developer.
-
- Tycoon
- Posts: 5950
- Joined: 27 Apr 2005 07:09
- Contact:
Re: Using random_switch for industry
@Michpi
See discussion between Peter and me on missing re-randomisation in callback chains for stations and vehicles.
regards
Michael
See discussion between Peter and me on missing re-randomisation in callback chains for stations and vehicles.
regards
Michael
Re: Using random_switch for industry
I had exactly the same problem and I got around it by setting a random value then calling a standard switch and setting the return values on return...something like this...
STORE_TEMP( random_bits & 15, 2): << I think that's how it's done - this has the random value of 0-15
then call
switch (..... LOAD_TEMP(2))
{
0..2: return 1;
3..8: return 2;
9: return 3;
return 4;
}
(syntax is not guaranteed to be 100% accurate!)
You can obviously set your own numbers, extend the random range or even do
return [STORE_PERM(1,7)]; returning a 1 into register 7 (for example).
I would have preferred being able to call a random number within a random_switch but it doesn't do that at the moment.
Hope this helps.
STORE_TEMP( random_bits & 15, 2): << I think that's how it's done - this has the random value of 0-15
then call
switch (..... LOAD_TEMP(2))
{
0..2: return 1;
3..8: return 2;
9: return 3;
return 4;
}
(syntax is not guaranteed to be 100% accurate!)
You can obviously set your own numbers, extend the random range or even do
return [STORE_PERM(1,7)]; returning a 1 into register 7 (for example).
I would have preferred being able to call a random number within a random_switch but it doesn't do that at the moment.
Hope this helps.
-
- Tycoon
- Posts: 5950
- Joined: 27 Apr 2005 07:09
- Contact:
Re: Using random_switch for industry
Just for the record, in m4nfo this is done by using function rerandom() like this:
regards
Michael
Code: Select all
[...]
// top platform
def(6) randomcb(_TOP, ARRIVE, 16, ref(1), ref(2), ref(2), ref(3))
// bottom platform
def(7) randomcb(_BOTTOM, {ARRIVE, NOCARGO}, 16, ref(1), ref(2))
def(8) plt_num(
self(
ref(6) if(0) // top platform
ref(7) else // bottom platform
)
)
[...]
def(9) rerandom(_TOP,
ref(0) // graphics
)
def(10) rerandom(_BOTTOM,
ref(0) // graphics
)
def(11) plt_num(
self(
ref(9) if(0) // top platform
ref(10) else // bottom platform
)
)
// check callbacks
def(12) callback(
ref(8) if(CB_LAYOUT)
ref(11) else // graphics / re-randomisation
)
Michael
Who is online
Users browsing this forum: No registered users and 0 guests