My second post, how I use the Fib sequence.
Step 1: load the file into the game
`
` load in a pregenerated Fibonacci sequence
'
function myfib()
open to read 1, "E:\TWOE\elite\fibonacci.dat"
read string 1, fib$
a$ = fib$
endfunction a$
This is called via
`load the stored fibbonacci sequence in M$
m$ = myfib()
Step 2: find a random start point within the fib string (this is the real secret source)
`
` find a random starting point within the Fibbonacci sequence
` the returning value is the numerical location within the fib sequence - not
` the value of the location - that has to be determined later
`
function fibstart(fib as string)
fiblen = len(fib) - 1
for x = 1 to 10 `short sequence to select a random starting point
fibseed = 1 + rnd(fiblen) `this number determines the "random" starting point along the fib seq
next x
endfunction fibseed
This is called via
`find the start point within the fib sequence
fbloc = fibstart(m$)
Now an example of how I put this into use, the example shows how I determine the number of star systems per galaxy they are.
First up the data I'm going to be referring to
stardata:
`how many star systems in the universe
data 300,350,500,600,650,700,750,800,900,1000
planetdata:
` The following data statement represents the number of planetary bodies per solar system
data 5,10,15,18,20,22,25,30,35,40
planet_types:
data "sun","gas giant","desert","water","swamp","jungle","forest","glacial","moon","asteroid"
planet_sizes:
data 1000,3000,5000,7000,12000,15000,20000,75000,95000
temperature:
data "hot","warm","termperate","cool","cold","icy"
Next the code...
fibvalue = getfibvalue(m$,fbloc)
restore stardata
for a = 0 to fibvalue
read stnbr
next a
numberofstarsystems = stnbr
for a = 1 to numberofstarsystems
`define where the star systems are located in the game universe
`might want to do some positioning based on racial type
rx = 1+rnd (xgrid-1)
ry = 1+rnd(ygrid-1)
zy = rnd(zgrid)
fibvalue = getfibvalue(fbstring, fbloc)
mp = ppl(fibvalue) ` the number of planets to assign to the current star system
starsystems(a).id = a
starsystems(a).tag = "Dummy:" + str$(a)
starsystems(a).maxplanets = mp
` starsystems(a).maxstations = 1
starsystems(a).xloc = rx
starsystems(a).yloc = ry
starsystems(a).zloc = zy
` populate_starsystems(starsystems(a).maxplanets)
next a
`
` get the next numerical value from the fibbonacci sequence and move the pointer on by +1
`
function getfibvalue(fibstring as string, fbloc as integer )
fibloc = fbloc
fbv = val(mid$(fibstring, fibloc))
inc fbloc,1
endfunction fbv
For your purposes assume the fibstring is stored in the data file as 123456789012345 (starts at element zero)
and the fbloc is picked as 3 then the fibvalue 4, then the number of star systems in this galaxy is 600.
I would then apply this technique to every aspect of a planet (size, population, techlevel, environment, etc).
By changing the "seed" or fbloc variable you can generate a vast amount of content without much effort. But by storing the seed you can instantly recreate any game start point.
Let me know if you have questions.
Steve.
Marriage is a circle of rings....
Engagement ring, Wedding ring, Suffering!