001package com.fs.starfarer.api.campaign;
002
003public enum RepLevel {
004
005        VENGEFUL("Vengeful", getT4(), 1f),
006        HOSTILE("Hostile", getT3(), getT4()),
007        INHOSPITABLE("Inhospitable", getT2(), getT3()),
008        SUSPICIOUS("Suspicious", getT1(), getT2()),
009        NEUTRAL("Neutral", 0, getT1()),
010        FAVORABLE("Favorable", getT1(), getT2()),
011        WELCOMING("Welcoming", getT2(), getT3()),
012        FRIENDLY("Friendly", getT3(), getT4()),
013        COOPERATIVE("Cooperative", getT4(), 1f);
014
015        
016        private final String displayName;
017        private final float max;
018        private final float min;
019        private RepLevel(String displayName, float min, float max) {
020                this.displayName = displayName;
021                this.min = min;
022                this.max = max;
023        }
024        public String getDisplayName() {
025                return displayName;
026        }
027        
028        public RepLevel getOneBetter() {
029                if (this == VENGEFUL) return HOSTILE;
030                if (this == HOSTILE) return INHOSPITABLE;
031                if (this == INHOSPITABLE) return SUSPICIOUS;
032                if (this == SUSPICIOUS) return NEUTRAL;
033                if (this == NEUTRAL) return FAVORABLE;
034                if (this == FAVORABLE) return WELCOMING;
035                if (this == WELCOMING) return FRIENDLY;
036                if (this == FRIENDLY) return COOPERATIVE;
037                
038                return COOPERATIVE;
039        }
040        
041        public RepLevel getOneWorse() {
042                if (this == HOSTILE) return VENGEFUL;
043                if (this == INHOSPITABLE) return HOSTILE;
044                if (this == SUSPICIOUS) return INHOSPITABLE;
045                if (this == NEUTRAL) return SUSPICIOUS;
046                if (this == FAVORABLE) return NEUTRAL;
047                if (this == WELCOMING) return FAVORABLE;
048                if (this == FRIENDLY) return WELCOMING;
049                if (this == COOPERATIVE) return FRIENDLY;
050                
051                return VENGEFUL;
052        }
053        
054        /**
055         * Not inclusive.
056         * @return
057         */
058        public float getMin() {
059                return min;
060        }
061        /**
062         * Inclusive.
063         * @return
064         */
065        public float getMax() {
066                return max;
067        }
068        public boolean isAtWorst(RepLevel level) {
069                return ordinal() >= level.ordinal();
070        }
071        public boolean isAtBest(RepLevel level) {
072                return ordinal() <= level.ordinal();
073        }
074        
075        public boolean isNeutral() {
076                return this == NEUTRAL;
077        }
078        
079        public boolean isPositive() {
080                return isAtWorst(RepLevel.FAVORABLE);
081        }
082        
083        public boolean isNegative() {
084                return isAtBest(RepLevel.SUSPICIOUS);
085        }
086        
087        private static final float T1 = 0.09f;
088        private static final float T2 = 0.24f;
089        private static final float T3 = 0.49f;
090        private static final float T4 = 0.74f;
091//      private static final float T1 = 0.1f;
092//      private static final float T2 = 0.25f;
093//      private static final float T3 = 0.5f;
094//      private static final float T4 = 0.75f;
095        public static RepLevel getLevelFor(float r) {
096                if (r >= 0) {
097                        int rel = getRepInt(r);
098                        if (rel <= getRepInt(T1)) return NEUTRAL;
099                        if (rel <= getRepInt(T2)) return FAVORABLE;
100                        if (rel <= getRepInt(T3)) return WELCOMING;
101                        if (rel <= getRepInt(T4)) return FRIENDLY;
102                        return COOPERATIVE;
103                } else {
104                        r = -r;
105                        int rel = getRepInt(r);
106                        if (rel <= getRepInt(T1)) return NEUTRAL;
107                        if (rel <= getRepInt(T2)) return SUSPICIOUS;
108                        if (rel <= getRepInt(T3)) return INHOSPITABLE;
109                        if (rel <= getRepInt(T4)) return HOSTILE;
110                        return VENGEFUL;
111                }
112        }
113        
114        public static int getRepInt(float f) {
115                return (int) Math.round(f * 100f);
116        }
117        
118        public static float getT1() {
119                return T1;
120        }
121        public static float getT2() {
122                return T2;
123        }
124        public static float getT3() {
125                return T3;
126        }
127        public static float getT4() {
128                return T4;
129        }
130        
131        
132}
133
134
135
136
137