Author Topic: Finding supported bricks  (Read 1423 times)

Do they give all of the bricks connected, or just the ones directly below?

I'm guessing that it's just direct connections. You could then loop through those and repeat on each of them, and so on until you find the ground or run out of downBricks to loop through.

Code: [Select]
function getSupportedBricks(%brick)
{
   %ss = new simSet();
   for(%i=0; %i<%brick.getNumUpBricks();%i++)
      %ss.add(%brick.getUpBrick(%i));
   %brick.setName(oldBrick);
   %newbrick = new fxDTSBrick(newBrick:oldBrick);
   %newbrick.setName();
   %brick.getGroup().add(%newbrick);
   %brick.delete();
   %supportBricksSet = new simSet();
   for(%i=0; %i<%ss.getCount(); %i++)
   {
      if(!%ss.getObject(%i).hasPathToGround())
         %supportBricksSet.add(%ss.getObject(%i));
   }
   %ss.delete();
   %newbrick.plant();
   %newbrick.setTrusted(1);
   return %supportBricksSet;
}
This should return a group containing bricks that are supported by provided brick. This will, however, clear the events on the brick. There are ways around that, I was just too lazy to put it in.

That doesn't look it works...
Could you explain it maybe?

That doesn't look it works...
Could you explain it maybe?
Yeah, sure.

Code: [Select]
function getSupportedBricks(%brick)
{
   %ss = new simSet(); // Create a new group to store all potential supportees
   for(%i=0; %i<%brick.getNumUpBricks();%i++)
      %ss.add(%brick.getUpBrick(%i)); //Add all potential suportees to group
   %brick.setName(oldBrick); // Name the brick in question oldBrick
   %newbrick = new fxDTSBrick(newBrick:oldBrick); // Duplicate this brick, but leave it as a ghost brick so it won't continue to support the bricks later.
   %newbrick.setName(); // Clear the name of the brick
   %brick.getGroup().add(%newbrick); // Add the new brick into the client's brickgroup, it's going to be replacing it later and we want it functional
   %brick.delete(); // Get rid of the brick in question. This will leave all bricks it's supporting still there, and we can check if they're floating.
   %supportBricksSet = new simSet(); // Make a group to put the definitely supported bricks in
   for(%i=0; %i<%ss.getCount(); %i++) //Loop through potential supportees
   {
      if(!%ss.getObject(%i).hasPathToGround()) //If they are floating
         %supportBricksSet.add(%ss.getObject(%i)); //Add them to the definitely supported brick group
   }
   %ss.delete(); // Get rid of the potential group. We don't need it anymore.
   %newbrick.plant(); // Plant the replacement brick, after all we deleted the brick we were testing.
   %newbrick.setTrusted(1); // Just makes things work. Part of brick planting.
   return %supportBricksSet; // Output the list of supported bricks
}

Oh I see now
The way you got all the possible supportees is wrong I'm pretty sure, but the rest looks like it would work great. Thanks!

Also, I've been working on an alternate way to do this without doing anything to the bricks. I'll post it when it's done.

The way you got all the possible supportees is wrong I'm pretty sure, but the rest looks like it would work great. Thanks!
Yeah, I guess you're right. Supported bricks can be below it. Run a second loop on the bricks under it.
Also, this will only get 1 layer deep. You'd have to run this function on EVERY brick that's returned as supported to get the full list of supported bricks.

Yeah, I guess you're right. Supported bricks can be below it. Run a second loop on the bricks under it.
Also, this will only get 1 layer deep. You'd have to run this function on EVERY brick that's returned as supported to get the full list of supported bricks.
Yep, that's exactly what I meant

Path-to-Ground
%brick.hasPathToGround() - ()Returns true if brick is attached to a baseplate.
could that method be modified so that floating baseplates could be created, which act as a building surface?

I think so. That's why I'm using if(%brick.getDistanceFromGround == 0)

so, how would i go about parenting it?
Code: [Select]
package ducks
{
    function fxDTSBrick::hasPathToGround()
    {
        if(baseplatecheckstuffhere)
            return true;
        return parent fxDTSBrick::hasPathToGround();
    }
}activatePackage(duck);
like that?

What would be the purpose of such a package?

so if you have floating baseplates, they can be used as building platforms

so, how would i go about parenting it?
Code: [Select]
package ducks
{
    function fxDTSBrick::hasPathToGround()
    {
        if(baseplatecheckstuffhere)
            return true;
        return parent fxDTSBrick::hasPathToGround();
    }
}activatePackage(duck);
like that?
Nope, parent::hasPathToGround();

so if you have floating baseplates, they can be used as building platforms
Sorry I'm not quite understanding. You want to be able to build on floating baseplates? Keep in mind that the function already tells if a brick is connected to a baseplate (I haven't tested it though, so I'm not 100% sure)

Edit: fill out the following blanks
"If the brick is _______, I would like the function to return true. If the brick is _______, I want the function to return as it operates normally."
« Last Edit: May 02, 2012, 10:44:39 AM by Treynolds416 »