public ShipComponent(ArrayList<Double> stat, String shipType, int team) 
    {
        try{
            music = AudioSystem.getAudioInputStream(new File("CylonProjectile.wav"));
            clip = AudioSystem.getClip();
            clip.open(music);
        }catch (UnsupportedAudioFileException|IOException|LineUnavailableException e)
        {
            System.out.println("Error reading sound file");
        }

        rec = new Rectangle2D.Double(-50,-50,100,100); //centered around origin of graphics
        xPos = stat.get(0); //sets all the starting stuff based on input.
        yPos = stat.get(1);
        theta = stat.get(7);
        xVel = stat.get(2);
        yVel = stat.get(3);
        xAcc = stat.get(4);
        yAcc = stat.get(5);
        speed = stat.get(6);
        turnSpeed = stat.get(8);
        teamNumber = team;
        maxSpeed = 0;
        maxTheta = 0;

        lastPressProcessed = 0;

        toTurn = 0;
        close = true;

        scrollX = 0;
        scrollY = 0;

        targetX = xPos;
        targetY = yPos;

        firingTargetX = 0;
        firingTargetY = 0;

        numWeapons = 0;
        weaponOffsetX = new int[0];
        weaponOffsetY = new int[0];
        weaponDirectionality = new int[0];
        weaponDamage = new double[0];
        weaponFireRate = new int[0];

        weaponFile = new int[0];

        lastFired = new long[0];

        //fireRate = 200;
        lastFire = System.currentTimeMillis();

        isFiring = false;

        shippic = new ImageIcon("failure.png");
        shipimg = shippic.getImage();
        polyFileName = shipType;

        numPoints = 0;
        xPa = new int[0];
        yPa = new int[0];

        hp=0;
        destroyed = false;

        //now with individual weapon directionality!
        try {
            BufferedReader inputStream = new BufferedReader(new FileReader(polyFileName + ".poly"));
            inputStream.readLine();

            String imgFile = inputStream.readLine();
            if(team == 1){
                imgFile = imgFile.substring(0, imgFile.indexOf(".")) + "Red" + imgFile.substring(imgFile.indexOf("."), imgFile.length());
                //System.out.println(imgFile);
            }
            else if (team == 2)
            {
                imgFile = imgFile.substring(0, imgFile.indexOf(".")) + "Blue" + imgFile.substring(imgFile.indexOf("."), imgFile.length());
            }
            shippic = new ImageIcon("ships/" + imgFile);
            shipimg = shippic.getImage();

            String defaultvars = inputStream.readLine();
            maxSpeed = Double.parseDouble(defaultvars.substring(0, defaultvars.indexOf(",")));
            maxTheta = Double.parseDouble(defaultvars.substring(defaultvars.indexOf(",")+1, nthIndexOf(defaultvars,',',2)));
            hp = Integer.parseInt(defaultvars.substring(nthIndexOf(defaultvars,',',2)+1, nthIndexOf(defaultvars,',',3)));
            maxHP = hp;
            //fireRate = Integer.parseInt(defaultvars.substring(nthIndexOf(defaultvars,',',3)+1,defaultvars.length()));

            numWeapons = Integer.parseInt(inputStream.readLine());
            weaponOffsetX = new int[numWeapons];
            weaponOffsetY = new int[numWeapons];
            weaponDirectionality = new int[numWeapons];
            weaponDamage = new double[numWeapons];
            weaponFireRate = new int[numWeapons];
            lastFired = new long[numWeapons];
            weaponFile = new int[numWeapons];
            for(long l: lastFired)
            {
                l = System.currentTimeMillis();
            }

            String test = "";
            for(int i = 0; i<numWeapons; i++)
            {
                test = inputStream.readLine();
                weaponOffsetX[i] = (int) Double.parseDouble(test.substring(0, test.indexOf(",")));
                weaponOffsetY[i] = (int) Double.parseDouble(test.substring(test.indexOf(",")+1,nthIndexOf(test,',',2)));
                weaponDirectionality[i] = (int) Double.parseDouble(test.substring(nthIndexOf(test,',',2)+1, nthIndexOf(test,',',3)));
                weaponDamage[i] = Double.parseDouble(test.substring(nthIndexOf(test,',',3)+1, nthIndexOf(test,',',4)));
                weaponFireRate[i] = (int) Double.parseDouble(test.substring(nthIndexOf(test,',',4)+1, nthIndexOf(test,',',5)));
                weaponFile[i] = (int) Integer.parseInt(test.substring(nthIndexOf(test,',',5)+1, test.length()));
            }

            numPoints = Integer.parseInt(inputStream.readLine());

            xPa = new int[numPoints];
            yPa = new int[numPoints];

            test = "";
            for(int i = 0; i<numPoints; i++)
            {
                test = inputStream.readLine();
                xPa[i] = (int) Double.parseDouble(test.substring(0, test.indexOf(",")));
                yPa[i] = (int) Double.parseDouble(test.substring(test.indexOf(",")+1, test.length()));
            }

            inputStream.close();
        } catch(IOException|NumberFormatException i) {
            System.out.println("Error parsing polygon file " + polyFileName);

        }
    }