I think that I will need your help one more time...
My "Elite Planet Browser" is basically complete now and running on 40 different systems, the only thing that's left to be done is the planet description string.
I understand the basic concept: it all starts with "[14] is [22]", and each [..] is expanded using "system_description" from descriptions.plist, returning either a string or recursively leading into another expansion.
But I still haven't figured out how exactly the pseudo-random index (based on the planet seed) for which of the five description items to use is calculated - the way I do it leads to wrong values.
Let's take a look at QUBE, the second planet of the first galaxy. Its description string is:
"Qube is reasonably well known for its great dense forests but scourged by deadly civil war."
So the indices should be like this (the value on the right), I assume that the expansion is done in this order:
Code: Select all
"[14] is [22]"
( // [14] --> 0
"%H",
"The planet %H",
"The world %H",
"This planet",
"This world"
),
( // [22] --> 3
"[1] [0] for [9]",
"[1] [0] for [9] and [9]",
"[7] by [8]",
"[1] [0] for [9] but [7] by [8]",
"a[15] [16]"
),
[1] - resonably --> 3
[0] - well known --> 2
[9] - "its [2] [3]" --> 0
[2] - great --> 2
[3] - "[19] forests" --> 3
[19] - dense --> 1
[7] - scourged --> 4
[8] - "[21] civil war" --> 0
[21] - deadly --> 4
What I do is: I first set up the separate description seed just as it is done in OOLite 1.80 in seed_RNG_only_for_planet_description(). Then I repeatedly call the gen_rnd_number() function which is almost an exact copy of the function from the OOLite 1.80 source. This function returns a pseudo-random index and rotates the description seed. I expected to get the values shown above, but what I get is this:
The resulting index is the value in the middle, which is the value in parentheses modulo 5.
Here is my code just in case that any of you want to take a look at it. For the planet seed I am using the w0 /w1 / w2 notation from the
Wiki page, see my posting above.
Code: Select all
...
// Seed variables
int w0;
int w1;
int w2;
// Extra seed variables used for the planet description
int rnd_seed_a; // = s_seed.c;
int rnd_seed_b; // = s_seed.d;
int rnd_seed_c; // = s_seed.e;
int rnd_seed_d; // = s_seed.f;
int gen_rnd_number()
{
// Generates a pseudo random number based on the current seed and makes a seed rotation
// This function was taken from the OOLite 1.80 source and modified
int a,x;
x = (rnd_seed_a * 2) & 0xFF;
a = x + rnd_seed_c;
if (rnd_seed_a > 127)
a++;
rnd_seed_a = a & 0xFF;
rnd_seed_c = x;
a = a / 256; /* a = any carry left from above */
x = rnd_seed_b;
a = (a + x + rnd_seed_d) & 0xFF;
rnd_seed_b = a;
rnd_seed_d = x;
return a;
}
void main()
{
...
MoveToPlanet(1,1,0); // Moves the planet seed to the desired planet
printf("planet seed w0 w1 w2:\n%x %x %x\n\n",w0,w1,w2);
// set rnd_seed_a to s_seed.c --> lsb of w1 -> w1 & 0x00FF
rnd_seed_a = w1 & 0x00FF;
// set rnd_seed_b to s_seed.d --> hsb of w1 -> (w1 >> 8) & 0x00FF
rnd_seed_b = (w1 >> 8) & 0x00FF;
// set rnd_seed_c to s_seed.e --> lsb of w2 -> w2 & 0x00FF
rnd_seed_c = w2 & 0x00FF;
// set rnd_seed_d to s_seed.f --> hsb of w2 -> (w2 >> 8) & 0x00FF
rnd_seed_d = (w2 >> 8) & 0x00FF;
printf("rnd seed abcd:\n%x %x %x %x\n\n",rnd_seed_a,rnd_seed_b,rnd_seed_c,rnd_seed_d);
int rndnum;
for (int i = 1; i <11; i++)
{
rndnum = gen_rnd_number();
printf("%-2d. %d (%d)\n",i,rndnum % 5, rndnum);
}
}
So something is wrong, but what...?