001package com.fs.starfarer.api.impl.campaign.intel.events;
002
003import java.awt.Color;
004import java.util.List;
005
006import com.fs.starfarer.api.campaign.econ.MarketAPI;
007import com.fs.starfarer.api.impl.campaign.ids.Industries;
008import com.fs.starfarer.api.impl.campaign.ids.Strings;
009import com.fs.starfarer.api.ui.Alignment;
010import com.fs.starfarer.api.ui.TooltipMakerAPI;
011import com.fs.starfarer.api.ui.TooltipMakerAPI.TooltipCreator;
012import com.fs.starfarer.api.ui.TooltipMakerAPI.TooltipLocation;
013import com.fs.starfarer.api.util.Misc;
014
015@Deprecated public class HADefensiveMeasuresFactor extends BaseEventFactor {
016        
017        public static int PATROL_HQ_POINTS = 5;
018        public static float MILITARY_SIZE_MULT = 2;
019        public static float HIGH_COMMAND_SIZE_MULT = 3;
020        
021        public HADefensiveMeasuresFactor() {
022        }
023
024        @Override
025        public TooltipCreator getMainRowTooltip(BaseEventIntel intel) {
026                return new BaseFactorTooltip() {
027                        public void createTooltip(TooltipMakerAPI tooltip, boolean expanded, Object tooltipParam) {
028                                Color h = Misc.getHighlightColor();
029                                float opad = 10f;
030                                
031                                tooltip.addPara("Defensive measures taken by your colonies.", 0f);
032                        }
033                };
034        }
035        
036        
037        @Override
038        public boolean shouldShow(BaseEventIntel intel) {
039                MarketAPI biggest = getBiggestColony();
040                MarketAPI mil = getBestMilitaryMarket();
041                return biggest != null || mil != null;
042        }
043
044        @Override
045        public void addExtraRows(TooltipMakerAPI info, BaseEventIntel intel) {
046                MarketAPI biggest = getBiggestColony();
047                MarketAPI mil = getBestMilitaryMarket();
048                Color tc = Misc.getTextColor();
049                
050                if (biggest != null) {
051                        int p = getColonyIncreasedDefensesScore(intel, biggest);
052                        if (p != 0) {
053                        //info.addRowWithGlow(Alignment.LMID, tc, "    Largest colony",
054                                info.addRowWithGlow(Alignment.LMID, tc, "    Increased defenses",
055                                            Alignment.RMID, intel.getProgressColor(p), "" + p);
056                                
057                                TooltipCreator t = new BaseFactorTooltip() {
058                                        public void createTooltip(TooltipMakerAPI tooltip, boolean expanded, Object tooltipParam) {
059                                                float opad = 10f;
060                                                tooltip.addPara("Based on the size and stability of the largest colony "
061                                                                + "under your control. If multiple colonies have the same size, the one with higher "
062                                                                + "stability is used.", 0f);
063                                                MarketAPI biggest = getBiggestColony();
064                                                if (biggest != null && biggest.getStarSystem() != null) {
065                                                        tooltip.addPara("Biggest colony: %s, size: %s, stability: %s", opad, Misc.getHighlightColor(), 
066                                                                        biggest.getName(),
067                                                                        "" + biggest.getSize(),
068                                                                        "" + (int) biggest.getStabilityValue());
069                                                        float w = tooltip.getWidthSoFar();
070                                                        float h2 = Math.round(w / 1.6f);
071                                                        tooltip.addSectorMap(w, h2, biggest.getStarSystem(), opad);
072                                                }
073                                        }
074                                };
075                                info.addTooltipToAddedRow(t, TooltipLocation.RIGHT, false);
076                        }
077                }
078                
079                int p = getMilitaryScore(mil);
080                if (mil != null && mil.hasFunctionalIndustry(Industries.HIGHCOMMAND)) {
081                        info.addRowWithGlow(Alignment.LMID, tc, "    High Command",
082                                    Alignment.RMID, intel.getProgressColor(p), "" + p);
083                } else if (Misc.isMilitary(mil)) {
084                        info.addRowWithGlow(Alignment.LMID, tc, "    Military base",
085                                    Alignment.RMID, intel.getProgressColor(p), "" + p);
086                } else if (mil != null && mil.hasFunctionalIndustry(Industries.PATROLHQ)) {
087                        info.addRowWithGlow(Alignment.LMID, tc, "    Patrol HQ",
088                                    Alignment.RMID, intel.getProgressColor(p), "" + p);
089                } else {
090                        info.addRowWithGlow(Alignment.LMID, Misc.getGrayColor(), "    Military infrastructure",
091                                    Alignment.RMID, intel.getProgressColor(p), "");
092                }
093                
094                TooltipCreator t = new BaseFactorTooltip() {
095                        public void createTooltip(TooltipMakerAPI tooltip, boolean expanded, Object tooltipParam) {
096                                float opad = 10f;
097                                tooltip.addPara("Based on the size the largest colony under your control that has a Patrol HQ, "
098                                                + "a Military Base, or a High Command.", 0f);
099                                
100                                tooltip.addPara("A Patrol HQ reduces monthly progress by %s points. A Military Base and a High Command "
101                                                + "reduce progress by %s and %s the colony's size, respectively. Only the highest-scoring colony is used, "
102                                                + "building multiple military bases has no effect.", opad, Misc.getHighlightColor(),
103                                                "" + PATROL_HQ_POINTS, 
104                                                "" + (int)MILITARY_SIZE_MULT + Strings.X,
105                                                "" + (int)HIGH_COMMAND_SIZE_MULT + Strings.X);
106                                                
107                                MarketAPI mil = getBestMilitaryMarket();
108                                if (mil != null && mil.getStarSystem() != null) {
109                                        int score = -1 * getMilitaryScore(mil);
110                                        if (score > 0) {
111                                                tooltip.addPara("Best military colony: %s, size: %s, score: %s points", opad, Misc.getHighlightColor(), 
112                                                                mil.getName(),
113                                                                "" + mil.getSize(),
114                                                                "" + score);
115                                                float w = tooltip.getWidthSoFar();
116                                                float h2 = Math.round(w / 1.6f);
117                                                tooltip.addSectorMap(w, h2, mil.getStarSystem(), opad);
118                                        }
119                                }
120                        }
121                };
122                info.addTooltipToAddedRow(t, TooltipLocation.RIGHT, false);
123                
124//              int def = getIncreasedDefensesScore(intel);
125//              if (def != 0) {
126//                      info.addRowWithGlow(Alignment.LMID, tc, "    Increased defenses",
127//                                  Alignment.RMID, intel.getProgressColor(def), "" + def);
128//                      
129//                      t = new BaseFactorTooltip() {
130//                              public void createTooltip(TooltipMakerAPI tooltip, boolean expanded, Object tooltipParam) {
131//                                      tooltip.addPara("Event progress reduced further by %s the other defense factors.", 0f,
132//                                                      Misc.getHighlightColor(), "" + (int)INCREASED_DEFENSES_MULT + Strings.X);
133//                              }
134//                      };
135//                      info.addTooltipToAddedRow(t, TooltipLocation.RIGHT, false);
136//              }
137        }
138
139//      public int getProgress(BaseEventIntel intel) {
140//              return getProgress(intel, true);
141//      }
142        public int getProgress(BaseEventIntel intel) {
143                int p = getColonyIncreasedDefensesScore(intel, getBiggestColony()) + getMilitaryScore(getBestMilitaryMarket());
144                return p;
145        }
146        
147        public float getAllProgressMult(BaseEventIntel intel) {
148                return 1f;
149        }
150        
151//      public int getIncreasedDefensesScore(BaseEventIntel intel) {
152//              if (intel.isStageOrOneOffEventReached(Stage.INCREASED_DEFENSES)) {
153//                      return (int) Math.round(getProgress(intel, false) * INCREASED_DEFENSES_MULT);
154//              }
155//              return 0;
156//      }
157        
158        public int getColonyIncreasedDefensesScore(BaseEventIntel intel, MarketAPI market) {
159                if (market == null) return 0;
160//              if (intel.isStageOrOneOffEventReached(Stage.INCREASED_DEFENSES)) {
161//                      return -1 * Math.round(market.getSize() + market.getStabilityValue());
162//              }
163                return 0;
164        }
165        
166        @Override
167        public String getProgressStr(BaseEventIntel intel) {
168                return "";
169        }
170
171        public String getDesc(BaseEventIntel intel) {
172                return "Defensive measures";
173        }       
174
175        @Override
176        public Color getDescColor(BaseEventIntel intel) {
177                if (getProgress(intel) == 0) {
178                        return Misc.getGrayColor();
179                }
180                return super.getDescColor(intel);
181        }
182
183        public MarketAPI getBiggestColony() {
184                List<MarketAPI> markets = Misc.getPlayerMarkets(false);
185                MarketAPI biggest = null;
186                float max = 0;
187                for (MarketAPI market : markets) {
188                        float size = market.getSize();
189                        if (size >= max) {
190                                if (size == max && biggest != null) {
191                                        if (biggest.getStabilityValue() > market.getStabilityValue()) {
192                                                continue;
193                                        }
194                                }
195                                max = size;
196                                biggest = market;
197                        }
198                }
199                return biggest;
200        }
201        
202        public int getMilitaryScore(MarketAPI market) {
203                if (market == null) return 0;
204                
205                if (market.hasFunctionalIndustry(Industries.PATROLHQ)) {
206                        return -1 * PATROL_HQ_POINTS;
207                }
208                if (Misc.isMilitary(market)) {
209                        if (market.hasFunctionalIndustry(Industries.HIGHCOMMAND)) {
210                                return -1 * Math.round(market.getSize() * HIGH_COMMAND_SIZE_MULT);
211                        }
212                        return -1 * Math.round(market.getSize() * MILITARY_SIZE_MULT);
213                }
214                return 0;
215        }
216        
217        public MarketAPI getBestMilitaryMarket() {
218                List<MarketAPI> markets = Misc.getPlayerMarkets(false);
219                MarketAPI best = null;
220                int max = 0;
221                for (MarketAPI market : markets) {
222                        int curr = -1 * getMilitaryScore(market);
223                        if (curr > max) {
224                                max = curr;
225                                best = market;
226                        }
227                }
228                return best;
229        }
230}