package general;

import java.io.*;
import java.util.*;

public class LoObject implements Serializable {

    private static final LoObject unknown = new LoObject("U", "sidenet", false, "UKN");
    private static final HashMap<String, LoObject> objectTypes = new HashMap<String, LoObject>();
    private static final double shortBtRange = 25000, stdBtRange = 42596, longBtRange = 53000;
    public final double burnThroughRange;
    public final String rwrDisplayName, wavFile, NCTRname;
    public final boolean airborne;

    @Override
    public final LoObject clone() {
        return new LoObject(this);
    }

    private LoObject(final LoObject old) {
        this.burnThroughRange = old.burnThroughRange;
        this.rwrDisplayName = old.rwrDisplayName;
        this.wavFile = old.wavFile;
        this.NCTRname = old.NCTRname;
        this.airborne = old.airborne;
    }

    public LoObject(final String displayName, final String wavFile, final boolean airborne, final String NCTRname, final double... btRange) {
        this.rwrDisplayName = displayName;
        this.wavFile = wavFile;
        this.airborne = airborne;
        this.burnThroughRange = btRange.length > 0 ? btRange[0] : stdBtRange;
        this.NCTRname = NCTRname;
    }

    public final boolean isActiveMissile() {
        return rwrDisplayName.equals("M");
    }

    public final LoObject lookUp(int t1, int t2, int t3, int t4) {
        String key = String.valueOf(t1) + "," + String.valueOf(t2) + "," + String.valueOf(t3) + "," + String.valueOf(t4);
        return objectTypes.get(key);
    }

    static {
        objectTypes.put("1,1,1,1", new LoObject("23", "MIG23", true, "Mig-23", longBtRange));		// mig23
        objectTypes.put("1,1,1,2", new LoObject("29", "Slotback", true, "Mig-29", longBtRange));	// mig29A
        objectTypes.put("1,1,1,3", new LoObject("29", "Slotback", true, "Su-27", stdBtRange));	// Su-27
        objectTypes.put("1,1,1,4", new LoObject("29", "Slotback", true, "Su-27", stdBtRange));	// Su-33
        objectTypes.put("1,1,1,5", new LoObject("14", "F14", true, "F-14", stdBtRange));		// F-14
        objectTypes.put("1,1,1,6", new LoObject("15", "F15", true, "F-15", stdBtRange));		// F-15
        objectTypes.put("1,1,1,7", new LoObject("16", "F16", true, "F-16", longBtRange));		// F-16C
        objectTypes.put("1,1,3,8", new LoObject("25", "MIG25", true, "Mig-25", longBtRange));		// mig25
        objectTypes.put("1,1,3,9", new LoObject("31", "MIG31", true, "Mig-31", longBtRange));		// mig31
        objectTypes.put("1,1,1,10", new LoObject("2", "F4", true, "F-2", longBtRange));
        objectTypes.put("1,1,1,11", new LoObject("27", "F4", true, "Mig-27", longBtRange));
        objectTypes.put("1,1,1,12", new LoObject("24", "MIG23", true, "Su-24", longBtRange));
        objectTypes.put("1,1,1,13", new LoObject("30", "Slotback", true, "Su-30", stdBtRange));	// Su30
        objectTypes.put("1,1,1,14", new LoObject("18", "F15", true, "F-18", stdBtRange));		// F-18A
        objectTypes.put("1,1,1,15", new LoObject("111", "F4", true, "F-111", stdBtRange));
        objectTypes.put("1,1,6,16", new LoObject("25", "MIG25", true, "Su-25", stdBtRange));
        objectTypes.put("1,1,6,17", new LoObject("A10", "F4", true, "A-10", stdBtRange));
        objectTypes.put("1,1,2,18", new LoObject("160", "F4", true, "Tu-160", stdBtRange));
        objectTypes.put("1,1,2,19", new LoObject("B1", "F4", true, "B-1", stdBtRange));
        objectTypes.put("1,1,1,20", new LoObject("30", "Slotback", true, "Su-34", stdBtRange));	// Su34
        objectTypes.put("1,1,4,21", new LoObject("95", "F4", true, "Tu-95", stdBtRange));
        objectTypes.put("1,1,4,22", new LoObject("142", "F4", true, "Tu-142", stdBtRange));
        objectTypes.put("1,1,4,23", new LoObject("B52", "F4", true, "B-52", stdBtRange));
        objectTypes.put("1,1,3,24", new LoObject("25", "MIG25", true, "Mig-25", longBtRange));		// mig25
        objectTypes.put("1,1,2,25", new LoObject("22M3", "F4", true, "Tu-22M3", stdBtRange));
        objectTypes.put("1,1,5,26", new LoObject("50", "A50", true, "A-50", stdBtRange));		// A-50 AWACS
        objectTypes.put("1,1,5,27", new LoObject("E3", "E3", true, "E-3", stdBtRange));		// E-3 AWACS
        objectTypes.put("1,1,5,28", new LoObject("78", "F4", true, "IL-78", stdBtRange));
        objectTypes.put("1,1,5,29", new LoObject("K10", "F4", true, "KC-10", stdBtRange));
        objectTypes.put("1,1,5,30", new LoObject("76", "F4", true, "IL-76", stdBtRange));
        objectTypes.put("1,1,5,31", new LoObject("130", "F4", true, "C-130", stdBtRange));
        objectTypes.put("1,1,1,32", new LoObject("29", "Slotback", true, "Mig-29", longBtRange)); //29k
        objectTypes.put("1,1,5,33", new LoObject("S3", "F4", true, "S-3R", stdBtRange));
        objectTypes.put("1,1,1,34", new LoObject("20", "F16", true, "Mirage", stdBtRange));		// Mirage-2000
        objectTypes.put("1,1,5,35", new LoObject("143", "F4", true, "Tu-143", stdBtRange));
        objectTypes.put("1,1,5,36", new LoObject("141", "F4", true, "Tu-141", stdBtRange));
        objectTypes.put("1,1,6,37", new LoObject("117", "MIG25", true, "F-117", stdBtRange));
        objectTypes.put("1,1,6,38", new LoObject("39", "Slotback", true, "Su-39", stdBtRange));
        objectTypes.put("1,1,5,39", new LoObject("26B", "F4", true, "AN-26B", stdBtRange));
        objectTypes.put("1,1,5,40", new LoObject("30M", "F4", true, "AN-30M", stdBtRange));
        objectTypes.put("1,1,5,41", new LoObject("E2", "E2C", true, "E-2", stdBtRange));		// E-2 AWACS
        objectTypes.put("1,1,5,42", new LoObject("S3A", "F4", true, "S-3A", stdBtRange));
        objectTypes.put("1,1,1,43", new LoObject("AV8", "F4", true, "AV-8B", stdBtRange));
        objectTypes.put("1,1,1,44", new LoObject("EA6", "F4", true, "EA-6B", stdBtRange));
        objectTypes.put("1,1,1,45", new LoObject("4", "F4", true, "F-4", longBtRange));		// F-4
        objectTypes.put("1,1,1,46", new LoObject("5", "F5", true, "F-5", longBtRange));		// F-5
        objectTypes.put("1,1,5,47", new LoObject("C17", "F4", true, "C-17", stdBtRange));
        objectTypes.put("1,1,1,48", new LoObject("17", "MIG23", true, "Su-17", longBtRange));
        objectTypes.put("1,1,1,49", new LoObject("29", "Slotback", true, "Mig-29", longBtRange));	// 29G
        objectTypes.put("1,1,1,50", new LoObject("29", "Slotback", true, "Mig-29", longBtRange));	// mig29S
        objectTypes.put("1,1,1,51", new LoObject("24", "MIG23", true, "Su-24", longBtRange));
        objectTypes.put("1,1,1,52", new LoObject("16", "F16", true, "F-16", longBtRange));		// F-16A
        objectTypes.put("1,1,1,53", new LoObject("18", "F15", true, "F-18", stdBtRange));		// F-18C
        objectTypes.put("1,1,6,54", new LoObject("25", "Slotback", true, "Su-25T", stdBtRange));
        objectTypes.put("1,1,6,55", new LoObject("Prd", "F4", true, "Predator", longBtRange));
        objectTypes.put("1,1,1,56", new LoObject("T", "F16", true, "Tornado", longBtRange));
        objectTypes.put("1,1,5,57", new LoObject("Y40", "F4", true, "YAK-40", stdBtRange));
        objectTypes.put("2,16,101,1", new LoObject("EW", "sidenet", false, ""));	// 1L13 EWR
        objectTypes.put("2,16,101,2", new LoObject("EW", "sidenet", false, ""));	// second ewr
        objectTypes.put("2,16,101,7", new LoObject("BB", "flatlib", false, ""));	// Sa-10 Search Radar Big Bird
        objectTypes.put("2,16,101,5", new LoObject("CS", "SA10", false, ""));		// Sa-10 Track radar in Search
        objectTypes.put("2,16,101,4", new LoObject("10", "SA10", false, ""));        // Sa-10 Track
        objectTypes.put("2,16,101,27", new LoObject("D", "dogear", false, ""));	// Dog ear rdr
        objectTypes.put("2,16,101,21", new LoObject("6", "SA6", false, ""));		// Sa-6
        objectTypes.put("2,16,101,32", new LoObject("R", "SA8", false, ""));		// Roland search radar
        objectTypes.put("2,16,101,34", new LoObject("P", "Patriot", false, ""));	// Patriot
        objectTypes.put("2,16,101,39", new LoObject("H", "MSQ50", false, ""));		// HAWK search radar
        objectTypes.put("2,16,101,40", new LoObject("H", "HAWK", false, ""));		// Hawk general track radar
        objectTypes.put("2,16,101,18", new LoObject("11", "SA6", false, ""));		// Sa-11 Search radar
        objectTypes.put("2,16,102,19", new LoObject("11", "SA6", false, ""));		// Sa-11 Track radar
        objectTypes.put("2,16,102,28", new LoObject("15", "SA8", false, ""));		// Sa-15
        objectTypes.put("2,16,102,31", new LoObject("R", "SA10", false, ""));		// Roland ADS
        objectTypes.put("2,16,102,23", new LoObject("8", "SA8", false, ""));		// Sa-8 OSA
        objectTypes.put("2,16,103,29", new LoObject("S6", "2S6", false, ""));		// 2S6 Tunguska
        objectTypes.put("2,16,105,30", new LoObject("Shl", "gundish", false, ""));	// Shilka
        objectTypes.put("2,16,105,46", new LoObject("Vu", "gundish", false, ""));	// Vulcan
        objectTypes.put("3,12,14,11", new LoObject("Shp", "flatlib", false, ""));	// Albatros
        objectTypes.put("3,12,14,28", new LoObject("Shp", "gundish", false, ""));	// Neusrta.....Whatever
        objectTypes.put("3,12,14,14", new LoObject("Shp", "gundish", false, ""));	// Rez..
        objectTypes.put("3,12,14,17", new LoObject("Shp", "Patriot", false, ""));	// Perry
        objectTypes.put("3,12,14,21", new LoObject("Shp", "Patriot", false, ""));	// Ticonderoga
        objectTypes.put("3,12,14,15", new LoObject("Shp", "gundish", false, ""));	// Molniya
        objectTypes.put("3,12,12,11", new LoObject("Ku", "SA6", false, ""));		// Admiral Search
        objectTypes.put("3,12,12,2", new LoObject("70", "SPY1A", false, ""));		// CVN
        objectTypes.put("3,12,12,1", new LoObject("15", "SA8", false, ""));		// Admiral TOR
        objectTypes.put("3,12,13,3", new LoObject("10", "flatlib", false, ""));	// Moscow
    }
    private static final LoObject activeMissile = new LoObject("M", "amraam", true, "Pwnd");

    public static LoObject lookUp(String key) {
        LoObject out = objectTypes.get(key);
        if (out != null) {
            return out;
        } else if (key.length() > 3 && key.charAt(0) == '4') {
            return activeMissile;
        }
        return unknown;
    }
}
