Skip to content
Snippets Groups Projects
Commit 18985ad4 authored by deuce's avatar deuce
Browse files

More stuff... still incomplete and unusable.

parent a7f4b565
Branches
Tags
No related merge requests found
...@@ -6,13 +6,25 @@ ...@@ -6,13 +6,25 @@
* *
*/ */
var sectors=1000; var sectors=1000; // Total sectors in the known universe
var warpradius=1.5; // Ratio of radius of a sphere containing the averge
// volume of space per sector to radius of max jump
// distance
// Eg: if the average sector was a 10 cubic mile
// sphere, it would have a radius of 1.34 miles.
// The maximum warp distance would be warpradius*1.34
// or (assuming 1.5) 2.01 miles.
// Obviously, the units we're using are a bit bigger.
var spin=0.1; // Distance in known universe radii the universe
// using the same ration to average bolume as above
var wr=Math.pow(((4/3*Math.PI)/sectors)/((4/3)*Math.PI),1/3)*warpradius; // Calculate warp radius
var so=Math.pow(1/sectors,1/3)*spin; // Calculate spin offset
var universe=[]; var universe=[];
var ports=[]; var ports=[];
var planets=[]; var planets=[];
var i,j; var i,j,k;
var sol; var sol;
var warpradius=1.5;
function SectorDistance(other) function SectorDistance(other)
{ {
...@@ -23,6 +35,15 @@ function SectorDistance(other) ...@@ -23,6 +35,15 @@ function SectorDistance(other)
)); ));
} }
function WarpDistance(other)
{
return(Math.sqrt(
Math.pow(this.X-other.X,2)+
Math.pow(this.Y-other.Y-so,2)+
Math.pow(this.Z-other.Z,2)
));
}
function CubicSector(x,y,z) function CubicSector(x,y,z)
{ {
this.X=x; // -1 to 1 this.X=x; // -1 to 1
...@@ -36,6 +57,7 @@ function CubicSector(x,y,z) ...@@ -36,6 +57,7 @@ function CubicSector(x,y,z)
this.Az=Math.atan2(this.Y,this.X); // Azimuth from coreward (Radians) this.Az=Math.atan2(this.Y,this.X); // Azimuth from coreward (Radians)
this.Al=Math.acos(this.Z/this.R); // Altitude from galactic plane (Radians) this.Al=Math.acos(this.Z/this.R); // Altitude from galactic plane (Radians)
this.Distance=SectorDistance; this.Distance=SectorDistance;
this.WDistance=WarpDistance;
} }
function SphereSector(R, Al, Az) function SphereSector(R, Al, Az)
...@@ -47,6 +69,7 @@ function SphereSector(R, Al, Az) ...@@ -47,6 +69,7 @@ function SphereSector(R, Al, Az)
this.Y=this.R*Math.sin(Al)*Math.sin(Az); this.Y=this.R*Math.sin(Al)*Math.sin(Az);
this.Z=this.R*Math.cos(Al); this.Z=this.R*Math.cos(Al);
this.Distance=SectorDistance; this.Distance=SectorDistance;
this.WDistance=WarpDistance;
} }
var sol=new CubicSector(0,0,0); var sol=new CubicSector(0,0,0);
...@@ -56,7 +79,7 @@ for(i=0; i<sectors; i++) { ...@@ -56,7 +79,7 @@ for(i=0; i<sectors; i++) {
universe.push(sol); universe.push(sol);
} }
else { else {
var x,y,z; var x,y,z,n;
check: check:
do { do {
...@@ -70,27 +93,40 @@ check: ...@@ -70,27 +93,40 @@ check:
log("Duplicate location"); log("Duplicate location");
continue check; continue check;
} }
} }
universe.push(new CubicSector(x,y,z)); n=new CubicSector(x,y,z);
} while(0); if(sol.Distance(n)>1) // Ensure the universe is spherical
continue check;
universe.push(n);
break;
} while(1);
} }
} }
log("len="+universe.length);
universe.sort(function(a,b) { return(a.Distance(sol) - b.Distance(sol)) }); universe.sort(function(a,b) { return(a.Distance(sol) - b.Distance(sol)) });
var wr=Math.pow((2*2*2/sectors)/((4/3)*Math.PI),1/3)*warpradius; // warpradius 1.5 times the average sector sphere.
var totalwarps=0; var totalwarps=0;
for(i in universe) { for(i in universe) {
universe[i].Warps=[]; universe[i].Warps=[];
for(j in universe) { for(j in universe) {
if(i==j) if(i==j)
continue; continue;
if(universe[i].Distance(universe[j]) <= wr) { if(universe[i].WDistance(universe[j]) <= wr) {
universe[i].Warps.push(j); universe[i].Warps.push(j);
totalwarps++; totalwarps++;
} }
} }
writeln(format("%f/%f/%f - %f",universe[i].X,universe[i].Y,universe[i].Z,universe[i].Distance(sol)));
writeln(" Warps: "+universe[i].Warps.join(', '));
} }
log("Radius="+wr);
log("Average warps per sector: "+(totalwarps/sectors)); log("Average warps per sector: "+(totalwarps/sectors));
log("Total Warps: "+totalwarps);
// Check for one-way warps
var oneways=0;
for(i in universe) {
for(j in universe[i].Warps) {
if(!universe[universe[i].Warps[j]].Warps.some(function(a,b,c) { return(a==i) } ))
oneways++;
}
}
log("One-way warps: "+oneways+" ("+parseInt(oneways/totalwarps*100)+"%)");
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment