/*
 * Radar.java
 *
 * Created on April 7, 2003, 6:56 PM
 */

/**
 * Radar Data Structure
 * This will destroy an {@link Asset}
 * @author  Nick Cole
 * @version 1.0
 */
public class Radar {
    private double radius;          //radius of radar coverage
    private double maxRadius;       //maximum coverage
    private String Tid;             //target id
    private int Ttype;              //type
    private LatLong Tmaploc;
    private ScreenLoc Tsloc;
    private String TTtype;
    int ArrayPos;
    private double Importance;	// how important is hitting this target?
    
    private double strength;
    
    public void SetArrayPos(int i) {
        ArrayPos=i;
    }
    public int GetArrayPos() {
        return ArrayPos;
    }
    public double GetImportance() {
        return Importance;
    }
    public LatLong GetLatLong() {
        return Tmaploc;
    }
    public String GetTType() {
        return TTtype;
    }
    public ScreenLoc GetScreenLoc() {
        return Tsloc;
    }
    
    /* Creates a new instance of Radar\
     * @param tid string which describes radar
     * @param tloc location of radar as LatLong
     * @param TargetMap StrikeMap this radar will placed on
     * @param importance double which indicates importance of radar
     * @param newRadius newRadius of radar
     * @param newMaxRadius maximum size of the radius
     */
    public Radar(String tid, LatLong tloc, String ttype, StrikeMap TargetMap,
        double importance, double newRadius, double newMaxRadius, 
        double newStrength) {
        Tid=tid;
        Tmaploc=tloc;
        TTtype=ttype;
        Importance=importance;
        ArrayPos=-1;
        if(TargetMap!=null) Tsloc=TargetMap.MapToScreenCoords(tloc);
        else Tsloc = null;            
        radius = newRadius;                 //set the radii up
        maxRadius = newMaxRadius;
        strength = newStrength;
    }
    
    
    public double GetRadius(){
        return radius;
    }
    
    public double GetMaxRadius(){
        return maxRadius;
    }
    
    /* Sets the radius to the new radius, if and only
     * if it is less than or equal to the max radius  
     */
    public boolean ChangeRadius( double newRadius ){
        boolean rv = false;         //return value
        
        if( newRadius <= maxRadius ){
            rv = true;
            radius = newRadius;
        }
        return rv;
    }
    
    /* Returns description
     * @author Nick Cole
     */
    public String GetTID() {
        return Tid;
    }
    
    public double GetStr() {
        return strength;
    }
    
    public void SetScreenLoc( ScreenLoc newSL ){
        Tsloc = newSL;
    }
    
    /* One should really use the other method
     * (@link ChangeRadius) since it checks to 
     * ensure a valid radius is being set.  This method
     * will be used by Chris' router to scale the
     * radius down to a small pathfinding map
     */
    public void SetRadius( double newRad ){
        radius = newRad;
    }
    
    
    /* Routing functions
     * @author C. Miles
     */
    public double dangerTo( int x0, int y0 ) {
        double strength = 0.1;
        //changed to y0-Tsloc
	double distance = (float) Math.sqrt( (Math.pow( (x0-Tsloc.GetX()),2 ) +
            Math.pow( (y0-Tsloc.GetY()),2 )));
	return func( distance / radius ) * 500.0;//strength;
    }
   
    /* Func
     * @author C. Miles
     */
    public double func( double f ){
        if( f > 1.0 ) return 0.0;
//        else if( f > .9 ){
//            f -= .9;
//            f *= 10.0;
//            return 1.0f - f;
//        }
        else return 1.0;
    }

    
    /* 
     * Convert Radar to String
     *
     * @param None 
     */
    public String toString() {
        if(Tsloc==null)
            return new String(Tid);
        else
            return new String("Radar: "+Tid+ " at " + Tmaploc);
    }
}
