/*
* This section holds snippetbot's events - onScannedRobot and onRobotDeath
* onRobotDeath makes snippetBot select a new target if the target is our enemy
* onScannedRobot updates all the information held on our current target
*/


public void onScannedRobot(ScannedRobotEvent e) {
        //if we have found a closer robot than our current target or we have another scan on our current target...
        if ((e.getDistance() < target.distance)||(target.name == e.getName())) {
                //the next line gets the absolute bearing to the point where the bot is
                double absbearing_rad = (getHeadingRadians()+e.getBearingRadians())%(2*PI);
                //this section sets all the information about our target
                target.name = e.getName();
                target.x = getX()+Math.sin(absbearing_rad)*e.getDistance(); //works out the x coordinate of where the target is
                target.y = getY()+Math.cos(absbearing_rad)*e.getDistance(); //works out the y coordinate of where the target is
                target.bearing = e.getBearingRadians();
                target.head = e.getHeadingRadians();
                target.ctime = getTime();				//game time at which this scan was produced
                target.speed = e.getVelocity();
                target.distance = e.getDistance();
        }
}

public void onRobotDeath(RobotDeathEvent e) {
        if (e.getName() == target.name)
        target.distance = 10000; //this will effectively make it search for a new target
}