where in the code?

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: winston, another_commander

Post Reply
User avatar
maaarcooose
---- E L I T E ----
---- E L I T E ----
Posts: 397
Joined: Sun May 29, 2011 9:36 pm
Location: Devon, UK
Contact:

where in the code?

Post by maaarcooose »

Not sure if this is the best section on the forum for discussions about the code of OOlite itself but here goes.

Can someone direct me to where in the code there is a function that would return planet details.
Seeing as everything about a planet is scripted, I'm guessing there should be a function that you can just pass the galaxy and planet number and it will return all the details about that planet.

With the little utility I'm writing, I currently read info for the planets from a group of CSV files, but I'd like to just replicate the internal OOlite function. The CSV files I have do not have all details and the downloadable excel file of the galaxies doesn't have all the information in them. The list of planets on: http://wiki.alioth.net/index.php/Oolite ... t/Galaxy_1 does seem to show everything, but not in a particularly handy format.

Anyone help me here or shall I just bite the bullet and create my own CSV's from the WIKI info?


Cheers.

!m!
Trading computers and writing stuff....
Website: http://www.theramist.co.uk/
OOliteInfo: http://www.theramist.co.uk/ooliteinfo/oo.php
User avatar
DaddyHoggy
Intergalactic Spam Assassin
Intergalactic Spam Assassin
Posts: 8515
Joined: Tue Dec 05, 2006 9:43 pm
Location: Newbury, UK
Contact:

Re: where in the code?

Post by DaddyHoggy »

maaarcooose wrote:
Not sure if this is the best section on the forum for discussions about the code of OOlite itself but here goes.

Can someone direct me to where in the code there is a function that would return planet details.
Seeing as everything about a planet is scripted, I'm guessing there should be a function that you can just pass the galaxy and planet number and it will return all the details about that planet.

With the little utility I'm writing, I currently read info for the planets from a group of CSV files, but I'd like to just replicate the internal OOlite function. The CSV files I have do not have all details and the downloadable excel file of the galaxies doesn't have all the information in them. The list of planets on: http://wiki.alioth.net/index.php/Oolite ... t/Galaxy_1 does seem to show everything, but not in a particularly handy format.

Anyone help me here or shall I just bite the bullet and create my own CSV's from the WIKI info?


Cheers.

!m!
I think Oolite still replicates the original pseudo-random planet info generation that was used in the original 8-bit machines, that is to say, there is a galaxy seed, from this, the planet's location, size, description and name are generated. These can be subsequently over-written by a player created plist, but you won't find in the code all those descriptions etc...

I know that doesn't help, but it may be possible to extract and convert the galaxy generation code and convert that into another format...
Selezen wrote:
Apparently I was having a DaddyHoggy moment.
Oolite Life is now revealed here
User avatar
maaarcooose
---- E L I T E ----
---- E L I T E ----
Posts: 397
Joined: Sun May 29, 2011 9:36 pm
Location: Devon, UK
Contact:

Re: where in the code?

Post by maaarcooose »

DaddyHoggy wrote:

I know that doesn't help, but it may be possible to extract and convert the galaxy generation code and convert that into another format...
Indeed, that's what I was hoping to do. At the moment, I'm creating a group of CSV files. I think they will still be useful.

I'd just like to call a function and that function replicates the random number generators.

!m!
Trading computers and writing stuff....
Website: http://www.theramist.co.uk/
OOliteInfo: http://www.theramist.co.uk/ooliteinfo/oo.php
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: where in the code?

Post by Eric Walch »

You could use JS and the console to write all planet info to a log file. I think most relevant stuf is available through SystemInfo This includes all (or most) info from planetInfo.plist
User avatar
maaarcooose
---- E L I T E ----
---- E L I T E ----
Posts: 397
Joined: Sun May 29, 2011 9:36 pm
Location: Devon, UK
Contact:

Re: where in the code?

Post by maaarcooose »

Okay, I'll take a look at that.

In the planet list, http://wiki.alioth.net/index.php/Oolite ... t/Galaxy_1 what is the HC value for each planet?

!m!
Trading computers and writing stuff....
Website: http://www.theramist.co.uk/
OOliteInfo: http://www.theramist.co.uk/ooliteinfo/oo.php
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: where in the code?

Post by Eric Walch »

maaarcooose wrote:
what is the HC value for each planet?

!m!
Hub Count is not a property of planets, it is just an result of building the system. But you can count the number of systems in 7LY reach. That should give the same result (At least I think that both use the same number rounding)
User avatar
maaarcooose
---- E L I T E ----
---- E L I T E ----
Posts: 397
Joined: Sun May 29, 2011 9:36 pm
Location: Devon, UK
Contact:

Re: where in the code?

Post by maaarcooose »

Makes sense.
It seems to match the number of systems in 7Ly range.

Interestingly during my programming of the jumps within range, I decided to do it by calculating the distances between the systems instead of using the data from the files. To get the all the jumps, I have to use 7.1 as my range. It might be down to rounding issues but I imagine the original BBC version only calculated in integers.
Even at this number, I think some jump routes are incorrect, missing or where they shouldn't be. 7.0 misses a couple, and 7.1 adds one that shouldn't be there.
I'm guessing it's due to my scaling up the X,Y values and that the X value is doubled.

!m!
Trading computers and writing stuff....
Website: http://www.theramist.co.uk/
OOliteInfo: http://www.theramist.co.uk/ooliteinfo/oo.php
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: where in the code?

Post by Eric Walch »

maaarcooose wrote:
It might be down to rounding issues but I imagine the original BBC version only calculated in integers.

!m!
Yes, to obtain the same connections as the original, one must use the same rounding as the original. In Oolite its calculated as:

Code: Select all

OOINLINE double distanceBetweenPlanetPositions ( int x1, int y1, int x2, int y2)
{
	int dx = x1 - x2;
	int dy = (y1 - y2)/2;
	int dist = sqrtf(dx*dx + dy*dy);	// N.b. Rounding error due to truncation is desired.
	return 0.4 * dist;
}
But I assume Oolites filtering by distance uses the same formula. When examining closely, this formula excludes all distances ending on an odd number. So 7.1 will be impossible as result. :wink:
Last edited by Eric Walch on Mon Sep 05, 2011 12:57 pm, edited 1 time in total.
User avatar
DaddyHoggy
Intergalactic Spam Assassin
Intergalactic Spam Assassin
Posts: 8515
Joined: Tue Dec 05, 2006 9:43 pm
Location: Newbury, UK
Contact:

Re: where in the code?

Post by DaddyHoggy »

Although a ship's maximum range is 7.0LY there are no systems that are exactly 7.0LY from each other - the original 8-bit systems had increments of 0.4 LY for range - so systems would go 6.8 to 7.2 LY apart...
Selezen wrote:
Apparently I was having a DaddyHoggy moment.
Oolite Life is now revealed here
User avatar
Mauiby de Fug
---- E L I T E ----
---- E L I T E ----
Posts: 847
Joined: Tue Sep 07, 2010 2:23 pm

Re: where in the code?

Post by Mauiby de Fug »

maaarcooose wrote:
With the little utility I'm writing, I currently read info for the planets from a group of CSV files, but I'd like to just replicate the internal OOlite function. The CSV files I have do not have all details and the downloadable excel file of the galaxies doesn't have all the information in them. The list of planets on: http://wiki.alioth.net/index.php/Oolite ... t/Galaxy_1 does seem to show everything, but not in a particularly handy format.
Huh! I had an idea for an oxp which put things in a system depending on the system data (for example, a monitoring station orbiting the sun in planets ravaged/scourged/plagued by frequent/unpredictable/deadly solar activity) and reckoned it would be nice to be able to sort the planet descriptions by things like that, eg bring up a list of those with earthquakes, good food, not worth going to... So I manually went about inputting the data from G1 into a spreadsheet. I'd done about 200 or so planets when my computer crashed whilst the file was open and corrupted the file, and the only backup I had was one with 30 planets done. So I gave up on the idea of doing it manually and googled to find a way to auto-input into a spreadsheet and discovered CSVs. I've been using regex matching to try and format the stuff copied from the wiki and delete things I don't want, but that still leaves a lot to go through manually to get it into the format I originally wanted. And I've now had the idea to vary what I originally had planned by using data other than simply the planet descriptions. So what with that and my laptop being an the verge of complete death, i haven't got very far...
Eric Walch wrote:
You could use JS and the console to write all planet info to a log file. I think most relevant stuf is available through SystemInfo This includes all (or most) info from planetInfo.plist
Bugger! Wish I'd thought of that earlier! That's inspired!
User avatar
maaarcooose
---- E L I T E ----
---- E L I T E ----
Posts: 397
Joined: Sun May 29, 2011 9:36 pm
Location: Devon, UK
Contact:

Re: where in the code?

Post by maaarcooose »

Eric Walch wrote:
maaarcooose wrote:
It might be down to rounding issues but I imagine the original BBC version only calculated in integers.

!m!
Yes, to obtain the same connections as the original, one must use the same rounding as the original. In Oolite its calculated as:

Code: Select all

OOINLINE double distanceBetweenPlanetPositions ( int x1, int y1, int x2, int y2)
{
	int dx = x1 - x2;
	int dy = (y1 - y2)/2;
	int dist = sqrtf(dx*dx + dy*dy);	// N.b. Rounding error due to truncation is desired.
	return 0.4 * dist;
}
But I assume Oolites filtering by distance uses the same formula. When examining closely, this formula excludes all distances ending on an odd number. So 7.1 will be impossible as result. :wink:
Interesting!

I've come at it a different way.

I plot all the planets, storing the coordinates as I plot them on the grid, then I use the plotted coordinates to work out the distance, not the actual X,Y value.

Code: Select all

    Public Sub plotPlanets()

        For i = 0 To 255
            For k = 0 To 12
                planetData(k) = Me.galaxyData.Rows.Item(i).Cells(k).Value.ToString()
                'GalaxyName.Text = planetData(k)
            Next k

            drawingPoint.X = ((Int(planetData(2)) + 1) * 4) - 4
            drawingPoint.Y = ((Int(planetData(3)) + 1) * 2) - 2

            g.DrawRectangle(redPen, drawingPoint.X, drawingPoint.Y, 2, 2)
            Me.galaxyData.Rows.Item(i).Cells(13).Value = drawingPoint.X + 1
            Me.galaxyData.Rows.Item(i).Cells(14).Value = drawingPoint.Y + 1

            g.DrawEllipse(greenPen, drawingPoint.X - 2, drawingPoint.Y - 2, 6, 6)
        Next i

    End Sub

    Public Sub plotJumpRoutes()

        For i = 0 To 255
            For l = 0 To 14
                planetDataStart(l) = Me.galaxyData.Rows.Item(i).Cells(l).Value.ToString()
            Next l
            startPoint.X = Int(planetDataStart(13))
            startPoint.Y = Int(planetDataStart(14))
            For k = 0 To 255
                For l = 0 To 14
                    planetDataEnd(l) = Me.galaxyData.Rows.Item(k).Cells(l).Value.ToString()
                Next l

                If (i <> k) Then
                    xd = Int(planetDataEnd(13)) - Int(planetDataStart(13))
                    yd = Int(planetDataEnd(14)) - Int(planetDataStart(14))
                    distance = Math.Sqrt(xd * xd + yd * yd)
                    If distance <= Int(jumpDistance.Text) Then
                        endPoint.X = Int(planetDataEnd(13))
                        endPoint.Y = Int(planetDataEnd(14))
                        g.DrawLine(yellowPen, startPoint, endPoint)
                    End If
                End If

            Next k
        Next i



    End Sub
I shall look at the proper method at a later date. Might even make the whole thing zoomable, but for now it's a research tool.

Yes I am programming in VB. Quick and dirty programming, mmmmmm.

!m!
Trading computers and writing stuff....
Website: http://www.theramist.co.uk/
OOliteInfo: http://www.theramist.co.uk/ooliteinfo/oo.php
Post Reply