Author Topic: Line Island Generator v1.0.1  (Read 2177 times)

After staying up until 5:00 I have finished a really sloppy and efficient island generator.


Feel free to use and tweak. This just generates really basic stuff by itself.

Example usage
GenerateTerrain("-128 -128 12 16","128 128 18 32",0,3,4,16);

Parameters:
GenerateTerrain("MinX MinY MinWidth MinLength","same params as min but max",Z,DecreaseWidth,MaxHeight,IslandNum);
Code: [Select]
if(!isObject(BlobTGSO)){ new ScriptObject(BlobTGSO); }

function RoundedVectorRotate2D(%x, %y, %angle)
{
%cos = mCos(%angle);
%sin = mSin(%angle);
%nx = (%cos * %x) - (%sin * %y);
%ny = (%sin * %x) + (%cos * %y);
return mfloatlength(%nx,0) SPC mfloatlength(%ny,0);
}

function BlobTGSO::MakeBlob(%this, %x, %y, %z, %dx, %dy, %r)
{
//rasterize two circles
for(%cx=-%r;%cx<=%r;%cx++)
{
%ptr = mSqrt((%r*%r) - (%cx*%cx));
%pt = ~~%ptr;
for(%cy=-%pt;%cy<=%pt;%cy++)
{
%this.PlaceBrick(%x+%cx,%y+%cy,%z);
%this.PlaceBrick(%x+%cx+%dx,%y+%cy+%dy,%z+%dz);
}
}
//talk("made circles");
//rasterize a rotated rectangle
%rot = mAtan(%dx,%dy);
%len = VectorDist("0 0 0", %dx SPC %dy SPC 0);
//Get our points.
%p0 = RoundedVectorRotate2D(%r,0,%rot); //Point A
%p1 = RoundedVectorRotate2D(%r,%len,%rot); //Point B
%p2 = RoundedVectorRotate2D(-%r,%len,%rot); //Point C
%p3 = RoundedVectorRotate2D(-%r,0,%rot); //Point D
%highest = 4; //for portability. this algorithm can draw /any/ convex polygon

//Sort the Y-ordinates of these points in order to get the lowest.
%sorter = new GuiTextListCtrl(){};
for(%i=0;%i<%highest;%i++)
%sorter.addRow(%i,getword(%p[%i],1));

%sorter.sortNumerical(0,1);
for(%i = 0; %i < %highest; %i++)
{
%lyo[%i] = %sorter.getRowText(%i); //lyo[0] is the lowest Y ordinate
for(%j=0;%j<%highest;%j++)
{
if(getword(%p[%j],0) SPC %lyo[%i] $= %p[%j] && !%taken[%j] && %pnum[%i] $= "")
{
%taken[%j]=1;
%pnum[%i] = %j;
}
}
//talk("lyop:"@%p[%pnum[%i]] SPC "lyo:"@%lyo[%i] SPC "p:"@%p[%i] SPC "pnum:"@%pnum[%i]);
}
%sorter.delete();
for(%i=0;%i<%highest;%i++) //for easiness
{
%px[%i] = getword(%p[%i],0);
%py[%i] = getword(%p[%i],1);
}
//by doing run over rise, you exploit your dpy == 0 protection AND make calculations easier
//we'll call the reciprocated slope "n"
//n(y-y1) = x-x1
//n(y-y1)+x1 = x
//ny - ny1 + x1 = x
for(%j=0;%j<4;%j++)
{
if(%pnum[%j] == %highest-1) //special case
%nextp = 0;
else
%nextp = %pnum[%j]+1;
%thisp = %pnum[%j];

%dpy = %py[%nextp] - %py[%thisp]; //change of our y points, needed to choose which xbuf
%dpx = %px[%nextp] - %px[%thisp]; //just for slope

if(%dpy < 0) //dpy is less than 0, thus indicating a __decrease__ in Y
{
%n = %dpx / %dpy;
for(%i=%py[%thisp];%i>=%py[%nextp];%i--)
{
%ptx = (%n * %i) - (%n * %py[%thisp]) + %px[%thisp];
%xmax[%i] = %ptx;
}
}
else if(%dpy > 0) //dpy is greater than 0, thus indicating an __increase__ in y
{
%n = %dpx / %dpy;
for(%i=%py[%thisp];%i<=%py[%nextp];%i++)
{
%ptx = (%n * %i) - (%n * %py[%thisp]) + %px[%thisp];
%xmin[%i] = %ptx;
}
}
else //dpy == 0, or some other bizarre condition
{
for(%k=0;%k<%highest;%k++) //which point matches this one?
{
if(%py[%k] == %py[%thisp] && %k != %thisp)
%ppick = %k;
}
%xmin[%py[%thisp]] = (%px[%ppick] > %px[%thisp] ? %px[%thisp] : %px[%ppick]);
%xmax[%py[%thisp]] = (%px[%ppick] <= %px[%thisp] ? %px[%thisp] : %px[%ppick]); //idiot safety in case of doubles
}
}
for(%i=%lyo0;%i<=%lyo[%highest-1];%i++)
{
//for some reason i messed up and xmin and xmax are swapped...
for(%j=%xmax[%i];%j<=%xmin[%i];%j++)
{
%this.PlaceBrick(%x - %j, %i + %y,%z);
}
}
}

function BlobTGSO::PlaceBrick(%this, %xr, %yr, %zr)
{
//retain sanity
%x = mfloor(%xr);
%y = mfloor(%yr);
%z = mfloor(%zr);
//talk("placebrick @ " @ %x SPC %y SPC %z);
if(%br = %this.brick[%x,%y,%z])
return %br;

%brick = new fxDTSBrick()
{
datablock = brick4xCubeData;
position = %x*2 SPC %y*2 SPC %z*2+$BlobTGSO::Zoffset;
rotation = "0 0 0 0";
colorID = $BlobTGSO::Color;
scale = "1 1 1";
angleID = 0;
colorFXID = $BlobTGSO::ColorFX;
shapeFXID = $BlobTGSO::ShapeFX;
isPlanted = 1;
};
%brick.plant();
%brick.setTrusted(1);
%this.brick[%x,%y,%z] = %br;
BrickGroup_888888.add(%brick);
%brick.onPlant();

return %brick;
}

function GenerateTerrain(%min,%max,%z,%valslope,%maxheight,%islands)
{
for(%i=0;%i<%islands;%i++)
{
%x=getRandom(getword(%min,0),getword(%max,0));
%y=getRandom(getword(%min,1),getword(%max,1));
%r=getRandom(getword(%min,2),getword(%max,2)); //width of islands
%dx=getRandom(-1,1) * getRandom(getword(%min,3),getword(%max,3));
%dy=getRandom(-1,1) * getRandom(getword(%min,3),getword(%max,3));
$BlobTGSO::Color = 20;
BlobTGSO.MakeBlob(%x,%y,%z,%dx,%dy,%r);
for(%j=%z+1;%j<(%z+%maxheight);%j++)
{
if(%j == 2){$BlobTGSO::Color = 2;}
%r = %r - %valslope;
if(%r < 1){ break; }
BlobTGSO.MakeBlob(%x,%y,%z+%j,%dx,%dy,%r);
}
}
}
« Last Edit: October 14, 2014, 12:30:30 PM by Axo-Tak »

I picture this being useful for MERPs and fort wars

I picture this being useful for MERPs and fort wars
That's what I was thinking when I was working on this. I thought about the shape of Glass's Fort Wars islands.

I thought about the shape of Glass's Fort Wars islands.

Spent so much time building those islands.

they look like some kind of horrible bacteria i'm scared

Spent so much time building those islands.
Thanks for the effort :)

It took me a long time just to reverse engineer the islands and make my own for my base while I was playing.

just need some trees and its perfect

hold on ima post a revision to it
they look like some kind of horrible bacteria i'm scared
that's why it is called "Blob TerraGen"

that's why it is called "Blob TerraGen"
more like terrorgen hehe XD  :cookieMonster: :cookieMonster: :cookieMonster:

It looks like something you might see under a microscope.