Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@QuadStorm
Last active May 27, 2019 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save QuadStorm/d1d840b3decab5eba8940b27f380ee46 to your computer and use it in GitHub Desktop.
Save QuadStorm/d1d840b3decab5eba8940b27f380ee46 to your computer and use it in GitHub Desktop.
Terrain to File, v2
//BrickifyTerrain
//Turns map terrain into a 4x4 cubescape (I couldn't think of a better name)
%cubes = forceRequiredAddOn("Brick_Large_Cubes");
if(%cubes == $Error::AddOn_NotFound)
return;
$dbSp = 1;
$factor = 3;
$factor2 = 1;
function ServerCmdBrickifyTerrainAvgFile(%client, %bound, %color, %filename)
{
if (!%client.isAdmin)
return;
$processCurPos = %client.player.getPosition();
echo("Current Position - (" @ $processCurPos @ ")");
$processFileName = %filename;
$processBound = %bound;
$terrainColor = %color;
$topCt = 0;
%hbound = $processBound * $dbSp / 2;
$pRPos = mRound(getWord($processCurPos,0),2) SPC mRound(getWord($processCurPos,1),2) SPC getWord($processCurPos,2);
$processStart = vectorAdd($pRPos,%hbound SPC %hbound @ " 0");
messageAll('',"Brickifying started \c6(" @ getDateTime() @ ") @" SPC "(" @ getWords($pRPos, 0, 1) @ ")");
$terrainFileObject = new FileObject();
$terrainFileObject.openForAppend("config/server/terrain_" @ $processFileName @ ".blsf");
processTerrain(0, 0);
}
function processTerrain(%x, %y)
{
cancel($terrainProcess);
$xPos = getWord($processStart,0) - $dbSp * %x;
$yPos = getWord($processStart,1) - $dbSp * %y;
%avgHeight = 0;
%xPosB = 0;
%yPosB = 0;
for (%xa = -$factor; %xa <= $factor; %xa++)
{
for (%ya = -$factor; %ya <= $factor; %ya++)
{
%xPosB = $xPos + %xa * $dbSp * $factor2;
%yPosB = $yPos + %ya * $dbSp * $factor2;
%avgHeight += mRound(getTerrainHeight(%xPosB SPC %yPosB) - 16, 5);
}
}
%avgHeight = %avgHeight / mPow($factor * 2 + 1, 2);
%zPos = mRound(%avgHeight, 5);
//%zPos = mRound(getTerrainHeight(%xPos SPC %yPos),5);
%place = $xPos SPC $yPos SPC %zPos;
$terrainFileObject.writeLine("2x2x200f\"" SPC %place SPC "0 1" SPC $terrainColor SPC " 0 0 1 1 1"); // https://forum.blockland.us/index.php?topic=290622.0
$topCt++;
if (%x == ($processBound - 1) && %y == ($processBound - 1))
{
TerraFinish($topCt);
}
if (%x < $processBound - 1)
{
$terrainProcess = schedule(0, 0, processTerrain, %x++, %y);
}
if (%y < $processBound - 1)
{
$terrainProcess = schedule(0, 0, processTerrain, 0, %y++);
}
}
function TerraFinish(%topCt)
{
messageAll('',"Brickifying completed \c6(" @ getDateTime() @ ")");
messageAll('',"\c6" @ %topCt @ "\c0 bricks written to file");
$terrainFileObject.close();
$terrainFileObject.delete();
}
function mRound(%float,%index)
{
%float *= %index;
if(mAbs(%float - mFloor(%float)) >= 0.5)
return mCeil(%float) / %index;
else
return mFloor(%float) / %index;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment