Author Topic: Supporting Bricks Tool  (Read 2377 times)

The duplicator doesn't need to figure out whether bricks are still connected to the ground if you remove a brick from the tree.
No, but it does check the bricks above it, which could be enough to check if the base brick is a supported brick
(not floating)

There's also the getDistanceFromGround function...

I believe getDistanceFromGround was in relation to terrain. If I'm right, it's incredibly useless because you can just use the z position now, and if I'm wrong, welp.

There's also the getDistanceFromGround function...

Yes, that tells you how far you're away from a baseplate / root brick. It'd be the basis of this test.

For example:



If you want to delete the brick marked on the right, you will have to check whether it leaves the two connected ones unsupported. Our current distance is 3.

The lower one is easy, it's distance is smaller than the current. It's safe.

The top one however... you have to follow through the tree until you discover a brick with a distance that is smaller than the current one. So that's all the way across to the other side, then back. You also have to make sure you're not getting stuck in loops, and do this for every connected brick. It'll be an enormous task to handle in torkscript.

::willCauseChainKill() does pretty much exactly this in c++.

Keeping in mind I have almost no knowledge of how Tork works...

If you knew which bricks were connected to the checked brick, could you simulate a wand hit, not actually showing it to the player, and then check to see what bricks, if any, were still there?
« Last Edit: February 07, 2016, 04:20:17 PM by DaBlocko »

If you knew which bricks were connected to the checked brick, could you simulate a wand hit, not actually showing it to the player, and then check to see what bricks, if any, were still there?

Not really.

If you just want a hacky solution, you could record all data about the brick in question, delete it, check whether any of the previously connected ones are now floating, then put a new brick where it was before.

I was bored, so I made the hacky solution anyways.

Code: chainKillBricks.cs (152 lines)
function findChainKillBricks(%this)
{
    //Get the connected bricks
    %upCount = %this.getNumUpBricks();
    %downCount = %this.getNumDownBricks();

    for(%i = 0; %i < %upCount; %i++)
        %upBrick[%i] = %this.getUpBrick(%i);

    for(%i = 0; %i < %downCount; %i++)
        %downBrick[%i] = %this.getDownBrick(%i);

    //Record all data
    %datablock = %this.getDatablock();
    %position = %this.position;
    %rotation = %this.rotation;
    %angleID = %this.angleID;
    %colorID = %this.colorID;
    %printID = %this.printID;
    %colorFxID = %this.colorFxID;
    %shapeFxID = %this.shapeFxID;
    %stackBL_ID = %this.stackBL_ID;
    %isBasePlate = %this.isBasePlate;
    %client = %this.client;
    %group = %this.getGroup();
    %ntName = %this.getName();

    //Record dynamic fields
    %i = 0;

    while(true)
    {
        %field = %this.getTaggedField(%i);

        if(%field $= "")
            break;

        %field[%i] = getField(%field, 0);
        %value[%i] = getFields(%field, getFieldCount(%field) - 1);
        %i++;
    }

    %fieldCount = %i;

    //Remove brick
    %this.delete();

    //Highlight the ones that are now floating
    %floatCount = 0;

    for(%i = 0; %i < %upCount; %i++)
    {
        if(%upBrick[%i].getDistanceFromGround() == 2147483647)
        {
            %floatCount++;

            %upBrick[%i].schedule(5000, setColor, %upBrick[%i].colorID);
            %upBrick[%i].setColor(0);

            %upBrick[%i].schedule(5000, setColorFx, %upBrick[%i].colorFxID);
            %upBrick[%i].setColorFx(3);
        }
    }

    for(%i = 0; %i < %downCount; %i++)
    {
        if(%downBrick[%i].getDistanceFromGround() == 2147483647)
        {
            %floatCount++;

            %downBrick[%i].schedule(5000, setColor, %upBrick[%i].colorID);
            %downBrick[%i].setColor(0);

            %downBrick[%i].schedule(5000, setColorFx, %upBrick[%i].colorFxID);
            %downBrick[%i].setColorFx(3);
        }
    }

    //Create a new brick
    %brick = new FxDTSBrick()
    {
        datablock = %datablock;
        position = %position;
        rotation = %rotation;
        angleID = %angleID;
        colorID = %colorID;
        printID = %printID;
        colorFxID = %colorFxID;
        shapeFxID = %shapeFxID;
        stackBL_ID = %stackBL_ID;
        isBasePlate = %isBasePlate;
        client = %client;
        isPlanted = true;
    };

    //Plant it
    %group.add(%brick);
    %brick.plant();
    %brick.trustCheckFinished();

    //If brick was a root, this will fix it
    if(%isBasePlate)
    {
        %brick.isBasePlate = %isBasePlate;
        %brick.willCauseChainKill();
    }

    //Apply nt name
    if(strlen(%ntName))
        %brick.setNTObjectName(%ntName);

    //Apply dynamic fields
    for(%i = 0; %i < %fieldCount; %i++)
    {
        %name = %field[%i];
        %value = %value[%i];
        %insert = getSubStr(%name, 1, strlen(%name));

        switch (stripos("_abcdefghijklmnopqrstuvwxyz", getSubStr(%name, 0, 1)))
        {
            case  0: %brick._[%insert] = %value;
            case  1: %brick.a[%insert] = %value;
            case  2: %brick.b[%insert] = %value;
            case  3: %brick.c[%insert] = %value;
            case  4: %brick.d[%insert] = %value;
            case  5: %brick.e[%insert] = %value;
            case  6: %brick.f[%insert] = %value;
            case  7: %brick.g[%insert] = %value;
            case  8: %brick.h[%insert] = %value;
            case  9: %brick.i[%insert] = %value;
            case 10: %brick.j[%insert] = %value;
            case 11: %brick.k[%insert] = %value;
            case 12: %brick.l[%insert] = %value;
            case 13: %brick.m[%insert] = %value;
            case 14: %brick.n[%insert] = %value;
            case 15: %brick.o[%insert] = %value;
            case 16: %brick.p[%insert] = %value;
            case 17: %brick.q[%insert] = %value;
            case 18: %brick.r[%insert] = %value;
            case 19: %brick.s[%insert] = %value;
            case 20: %brick.t[%insert] = %value;
            case 21: %brick.u[%insert] = %value;
            case 22: %brick.v[%insert] = %value;
            case 23: %brick.w[%insert] = %value;
            case 24: %brick.x[%insert] = %value;
            case 25: %brick.y[%insert] = %value;
            case 26: %brick.z[%insert] = %value;
        }
    }

    messageAll('', "\c6This brick directly supports " @ %floatCount @ " other bricks.");
}



If you look at a brick and say /getId, then put this id in findChainKillBricks(id); it'll highlight them in red:


Good job Zeb ;)

should totally release this if you get it all "stable"
« Last Edit: February 07, 2016, 10:02:17 PM by Goth77 »

Given that I know nothing about executing scripts, how do I execute this?  Or rather, how do I get it into the game.

Thanks so much!

Code: chainKillBricks.cs (152 lines)
I wonder if you're gonna be willing to share what you used to highlight all that this time

what's with the massive pagestretch

There is no page stretch.


Looks like that style you're using is broken. The posts shouldn't be so far to the right.

There is no page stretch.

Do you have a screen resolution of 5,000+ or something?

I have a 1920 X 1080 sized monitor and there is a super loving page stretch.

Do you have a screen resolution of 5,000+ or something?

No? I'm using a normal 1080p screen and it's all fine.