Author Topic: any resources for planting bricks procedurally?  (Read 13977 times)

i'm interested in making a map generator for blockland using wave function collapse to place chunks of bricks together. in the few years i haven't played i've lost all my code resources for how to place multiple bricks programmatically. i remember there was a way to spawn groups of bricks, but i ran into trouble with brick group trust ownership, global rotation of generated brick structures, and generally serializing the bricks in the game (sometimes the bricks would visually persist even after destruction)

if anyone has any resources for this and can share them, i would greatly appreciate it. i've tried looking at new duplicator's source code but it's a little too complex for my needs. the hopeful end result of this line of research would be a nice lightweight procedural map generator for blockland, time permitted

Maybe the code for gsf's procedural terrain generator? I doubt its with wave function though. Is terrain generator not lightweight enough? With the amount of features it has I think its small enough.

generating a city block with randomized trees, cars, buildings and other hand-built assets is not supported by gsf's terrain generator. it does not use wave function collapse to produce results, it takes layered noise and outputs a heightmap

i think his point is to reference that code to relearn how to place bricks, thinking that the code in gsf's terrain generator is simple. its very much not - despite the terrain gen being rather simple, doing anything as complicated as that in ts is incredibly difficult/annoying due to the slow performance of ts and lack of basic language features like arrays.

you can place bricks via creating new fxDTSBrick() object instances, assigning them a datablock, position, and rotation. if you give an invalid position it will actually helpfully auto-snap to a valid position.... but not necessarily the closest one (ie you need to make your own position rounding function). brick positions are set at the center of their bounding box, and the grid is 0.5x0.5x0.2 per 1x1f

ex:
valid position for a 1x1:0.25 0.25 0.3
valid position for a 1x2:0.25 0.5 0.3
valid position for a 2x2f:0 0 0.1
valid position for a 2x2x2 plate tall:0.5 25.5 0.2

valid rotations:
Code: [Select]
function getRandomBrickOrthoRot()
{
%rand = getRandom(0, 3);
switch (%rand)
{
case 0: return "1 0 0 0";
case 1: return "0 0 1 " @ 90;
case 2: return "0 0 1 " @ 180;
case 3: return "0 0 -1 " @ 90;
}
}



once creating the brick, run %brick.plant(); and capture the output for errors. error codes:
Code: [Select]
case 0: return 0;
case 1: return "overlap";
case 2: return "float";
case 3: return "stuck";
case 4: return "unstable";
case 5: return "buried";

note that trust is NOT checked here. you'll have to do that manually if you care about trust - use `getTrustLevel(%obj1, %obj2);` to check that (0 for none, 1 for build, 2 for full, 3 for self-owned)

after that, run %brick.setTrusted(1);. this does not actually check trust - this just makes it possible to plant bricks horizontally around it properly. not sure why its in the game but it is and you need to run it if you want people to be able to plant bricks around it.


some key notes:
if you dont care about saving/loading the bricks, or will override .plant(); to always return 0, you can actually just straight up ignore plant errors and the bricks will collide and work just fine after running .plant();.
similar goes for .setTrusted();

also hit me up in discord next time smh