The Exiled
http://theexiled.pwnageservers.com/forum/

Using a camera to check deploy area
http://theexiled.pwnageservers.com/forum/viewtopic.php?f=4&t=1536
Page 1 of 1

Author:  TE-Noxwizard [ Tue Sep 05, 2006 7:08 pm ]
Post subject:  Using a camera to check deploy area

This function checks the deploy area when you use it in a deployable item. It spawns a camera at your desired deployment height, then rotates 360 degrees and checks for objects in the way. If you have an object that decends, you can use the %vert to define how high you want to look striaght up above the deployment area.
Code:
// Function to check deploy area/landing path
// Spawn a camera, rotate all the way around and check for objects
// -Noxwizard
// %pos - deploy position
// %height - height to deploy camera
// %radius - how far to look around
// %vert - how high to look up (dropships)

function checkarea(%client,%pos,%height,%radius,%vert)
{
   %camera = newObject("Camera","Turret",cameraturret,true);
   GameBase::setPosition(%camera,Vector::add(%pos,"0 0 " @ %height));

    // Look up
   if(GameBase::getLOSInfo(%camera,%vert,"1.5708 0 0"))
   {
      %name = GameBase::getDataName($los::object);

      if(!%name)
         %name = getObjectType($los::object);
        if(%name == "SimTerrain")
            Client::sendMessage(%client,0,"You are underground."); //Not likely, but possible
        else
         Client::sendMessage(%client,0,%name@" in way, "@Vector::getDistance($los::position, GameBase::getPosition(%client))@" meters up.");
      DeleteObject(%camera);
      return false;
   }
    // Look around
    for(%i = 0; %i < 6.3; %i = %i + 0.1)
    {
       if(GameBase::getLOSInfo(%camera,%radius,"0 0 " @ %i))
       {
          %name = GameBase::getDataName($los::object);

          if(!%name)
             %name = getObjectType($los::object);
            if(%name == "SimTerrain")
                Client::sendMessage(%client,0,"You are too close to hills.");
            else
             Client::sendMessage(%client,0,%name@" in way, "@Vector::getDistance($los::position, GameBase::getPosition(%client))@" meters up.");
          DeleteObject(%camera);
          return false;
       }
     }
    // Now that the circle has completed, deploy
    DeleteObject(%camera);
    return true;
}

Code Explaination:

This creates a camera at the player's position at the height defined:
Code:
%camera = newObject("Camera","Turret",cameraturret,true);
GameBase::setPosition(%camera,Vector::add(%pos,"0 0 " @ %height));

This has the camera look straight up for your defined height:
Code:
GameBase::getLOSInfo(%camera,%vert,"1.5708 0 0")

Put that into an if statement and we can check if there's an object in the camera's line-of-sight. If there's something in the way, we'll get it's name and tell the client that it's in the way, and how high up it is. Unless it's terrain. ;)
Code:
   if(GameBase::getLOSInfo(%camera,%vert,"1.5708 0 0"))
   {
      %name = GameBase::getDataName($los::object);

      if(!%name)
         %name = getObjectType($los::object);
        if(%name == "SimTerrain")
            Client::sendMessage(%client,0,"You are underground."); //Not likely, but possible
        else
         Client::sendMessage(%client,0,%name@" in way, "@Vector::getDistance($los::position, GameBase::getPosition(%client))@" meters up.");
      DeleteObject(%camera);
      return false;
   }

Now this part's a bit different. We want it to look all the way around, so we will have it look in a lot of directions, by adding 0.1, looking, adding another 0.1, looking, and so on. To do that we use a for loop. We went it to look all the way around, which will be from 0 to 6.28. It's 6.28, because that's just the way circles are handled, instead of degrees it's radians, 6.28 is the same as 360 degrees.
Code:
    // Look around
    for(%i = 0; %i < 6.3; %i = %i + 0.1)
    {
       if(GameBase::getLOSInfo(%camera,%radius,"0 0 " @ %i))
       {
          %name = GameBase::getDataName($los::object);

          if(!%name)
             %name = getObjectType($los::object);
            if(%name == "SimTerrain")
                Client::sendMessage(%client,0,"You are too close to hills.");
            else
             Client::sendMessage(%client,0,%name@" in way, "@Vector::getDistance($los::position, GameBase::getPosition(%client))@" meters up.");
          DeleteObject(%camera);
          return false;
       }
     }

So, if there's something in the way, it reports a false value, which will immediately stop checking. If it makes it through all those checks without seeing an object, it will report a true.

To use this, put this in your deployment code:
Code:
// check for other airbases/buildings/etc  -Noxwizard
%pos = $los::position;
if(!checkarea(%client,%pos,95,20,20))
    return false;

What that does is checks the area you've defined. So this spawns a camera up 95 meters above you, then looks up 20 meters, then looks around in a 20 meter radius. If it doesn't find anything, it'll go onto the next items in the deploy code. If it does find something, it will halt the deployment.

Author:  TE-Hammy [ Wed Sep 06, 2006 2:36 pm ]
Post subject: 

uhh... GO NOX! woo!

Author:  TE-4ev3r [ Wed Sep 06, 2006 6:30 pm ]
Post subject: 

So, this basically checks the item area limit, and will negate the Item in Way thing if nothing is spotted?

Author:  TE-Noxwizard [ Wed Sep 06, 2006 9:09 pm ]
Post subject: 

Think of it like sonar. The camera makes a circle, if a blip shows up, it stops the deployment.

I might add a container box fill, which will create a box with given dimensions and detect objects in it. I will still need the camera since the container doesn't detect terrain.

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/