/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util;

import com.jme.renderer.ColorRGBA;
import java.util.HashMap;
import java.util.Random;

/**
 *
 * @author eccastro
 */
public class Constants {

    public static final int PORT = 4011;
    public static final String colorRED = "Red";
    public static final String colorGREEN = "Green";
    public static final String colorBLUE = "Blue";
    public static final String colorYELLOW = "Yellow";
    public static final String colorMAGENTA = "Magenta";
    public static final String colorWHITE = "White";
    public static final String colorDARKGRAY = "DarkGray";
    public static final String colorORANGE = "Orange";
    public static final String PFOOD = "PerishableFood";
    public static final String NPFOOD = "NonPerishableFood";
    public static final int categoryCREATURE = 0;
    public static final int categoryBRICK = 1;
    public static final int categoryFOOD = 2;
    public static final int categoryPFOOD = 21;
    public static final int categoryNPFOOD = 22;
    public static final int categoryJEWEL = 3;
    public static final int categoryDeliverySPOT = 4;
    public static final int categoryCAGE = 5;
    public static final double[] deliverySpotCoords = {0, 0};
    public static final double M_PI = Math.PI;
    
    //Affordances:
    public static final int Affordance__VIEWABLE = 30;
    public static final int Affordance__HIDEABLE = 31;
    public static final int Affordance__UNHIDEABLE = 32;
    public static final int Affordance__GRASPABLE = 33;
    public static final int Affordance__EATABLE = 34;
    public static final int Affordance__PUTINBAGABLE = 35;//sth that can be put in a bag
    public static final int Affordance__OPENABLE = 36; //sth that can be opened (eg. a cage)
    public static final int Affordance__CLOSEABLE = 37;//sth than be closed (eg. a cage)
    public static final int Affordance__INSERTABLE = 38;//sth than can contain another thing (which had been inserted into this sth)[eg. a container]
    public static final int Affordance__REMOVEFROMABLE = 39;//sth from whose inside another thing is removed (eg. a container)
    
    //Error code: used in the WS3DProxy. Do not change it.
    public static final String ERROR_CODE = "@@@";
    
    // State of a cage: (Note: mnj --> apple-nut-jewel)
    ///////Never use "-1" for new states. It is used to notify errors 
    /////// (see class CageFSM).
    public static final int EMPTY_OPENED = 0; //"Container_empty_opened";
    public static final int EMPTY_CLOSED = 1; //"Container_empty_closed";
    public static final int FULL_CLOSED_APPLE = 2; // "Container_full_closed_apple";
    public static final int FULL_OPENED_APPLE = 3; //"Container_full_opened_apple";
    public static final int FULL_CLOSED_NUT = 4; //"Container_full_closed_nut";
    public static final int FULL_OPENED_NUT = 5;//"Container_full_opened_nut";
    public static final int FULL_OPENED_JEWEL = 6; //"Container_full_opened_jewel";
    public static final int FULL_CLOSED_JEWEL = 7; //"Container_full_closed_jewel";
    public static final int FULL_OPENED_MNJ = 8; //"Container_full_opened_mnj";
    public static final int FULL_CLOSED_MNJ = 9; //"Container_full_closed_mnj";
    public static final int FULL_OPENED_MN = 10; //"Container_full_opened_mn";
    public static final int FULL_CLOSED_MN = 11; //"Container_full_closed_mn";
    public static final int FULL_OPENED_MJ = 12; //"Container_full_opened_mj";
    public static final int FULL_CLOSED_MJ = 13; //"Container_full_closed_mj";
    public static final int FULL_OPENED_NJ = 14; //"Container_full_opened_nj";
    public static final int FULL_CLOSED_NJ = 15; //"Container_full_closed_nj";

    
    //Spurious value for angular velocity:
    public static final double WNULL = 1001;
    public static final double CREATURE_MAX_FUEL = 1000.0;
    //how much energy is decrement at each timer cycle:
    public static final double CREATURE_FUEL_DEC = 50.0;
    public final static int MAX_NUMBER_OF_LEAFLETS = 3;
    public final static int LEAFLET_ITEMS_NUMBER = 3;
    public final static int MAX_NUMBER_OF_COLORS = 6; //see EditJewelFrame
    public static final String[] arrayOfColors = {Constants.colorRED, Constants.colorGREEN, Constants.colorBLUE, Constants.colorYELLOW, Constants.colorMAGENTA, Constants.colorWHITE, Constants.colorDARKGRAY, Constants.colorORANGE};
    public static final double M_PI_2 = Math.PI / 2.0;
    public static final int NUMBER_CAMERAS = 2;
    private static final HashMap<String, ColorRGBA> colorMap = new HashMap();
    
    private static void initColorHashMap(){
        HashMap<String, ColorRGBA> map = new HashMap();
        for (String c: arrayOfColors){
            colorMap.put(c, translateIntoColor(c));
        }
    }
    ////////Poisson distribution
    //the average rate of generation of each kind of crystal:
    public static final double redLAMBDA = 2.2;
    public static final double greenLAMBDA = 2;
    public static final double blueLAMBDA = 2.5;
    public static final double yellowLAMBDA = 1.7;
    public static final double magentaLAMBDA = 1.5;
    public static final double whiteLAMBDA = 1;

    public static final double pFoodLAMBDA = 2.2;
    public static final double npFoodLAMBDA = 1.1;

    /**
     * Knuth's algorithm to generate random Poisson distributed numbers
     * @param lambda average rate of success in a Poisson distribution
     * @return random number 
     */
    public static int getPoissonRandomNumber(double lambda) {
        int k = 1;
        double p = 1.0;
        Random rd = new Random();

        do {
            k += 1;
            p *= rd.nextDouble();
        } while (p > Math.exp((double) -lambda));
        return k - 1;
    }

    public static final boolean isInArrayOfColors(String color) {
        boolean ret = false;
        for (int i = 0; i < arrayOfColors.length; i++) {
            if (arrayOfColors[i].equals(color)) {
                ret = true;
            }
        }
        return ret;
    }

    /**
     * Color name --> integer
     *
     * @param color
     * @return
     */
     public static final int getColorIndex(String color) {
        int ret = -1; //invalid
        for (int i = 0; i < arrayOfColors.length; i++) {
            if (arrayOfColors[i].equals(color)) {
                ret = i;
            }
        }
        return ret;
    }

    public static ColorRGBA translateIntoColor(String colorName) {

        if (colorName.equals(Constants.colorRED)) {
            return ColorRGBA.red;
        } else if (colorName.equals(Constants.colorGREEN)) {
            return ColorRGBA.green;
        } else if (colorName.equals(Constants.colorBLUE)) {
            return ColorRGBA.blue;
        } else if (colorName.equals(Constants.colorYELLOW)) {
            return ColorRGBA.yellow;
        } else if (colorName.equals(Constants.colorMAGENTA)) {
            return ColorRGBA.magenta;
        } else if (colorName.equals(Constants.colorWHITE)) {
            return ColorRGBA.white;
        } else if (colorName.equals(Constants.colorDARKGRAY)) {
            return ColorRGBA.darkGray;
        } else if (colorName.equals(Constants.colorORANGE)) {
            return ColorRGBA.orange;
        } else {
            return ColorRGBA.magenta; //default
        }
    }

    public static String getNameFromColor(ColorRGBA color) {
        initColorHashMap();
        String ret = "";
        for (String s : colorMap.keySet()) {
            if (colorMap.get(s).equals(color)) {
                ret = s;
            }
        }
        return ret;
    }

    /**
     * Integer color index --> color name (opposite of getColorIndex() )
     * @param index
     * @return 
     */
    public static String getColorItem(int index) {

        String ret = null;
        switch (index) {
            case 0:
                ret = colorRED;
                break;
            case 1:
                ret = colorGREEN;
                break;
            case 2:
                ret = colorBLUE;
                break;
            case 3:
                ret = colorYELLOW;
                break;
            case 4:
                ret = colorMAGENTA;
                break;
            case 5:
                ret = colorWHITE;
                break;
//            case 6: ret =  colorDARKGRAY; break;
//            case 7: ret =  colorORANGE; break;
        }
        return ret;
    }

    public static int getColorPayment(int index) {

        int ret = 0;
        switch (index) {
            case 0:
                ret = 10;       //colorRED
                break;
            case 1:
                ret = 8;        //colorGREEN
                break;
            case 2:
                ret = 6;        //colorBLUE
                break;
            case 3:
                ret = 4;        //colorYELLOW
                break;
            case 4:
                ret = 2;        //colorMAGENTA
                break;
            case 5:
                ret = 1;        //colorWHITE
                break;
        }
        return ret;
    }

}
