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.Industry; 007import com.fs.starfarer.api.campaign.econ.MarketAPI; 008import com.fs.starfarer.api.impl.campaign.ids.Industries; 009import com.fs.starfarer.api.impl.campaign.ids.Strings; 010import com.fs.starfarer.api.ui.TooltipMakerAPI; 011import com.fs.starfarer.api.ui.TooltipMakerAPI.TooltipCreator; 012import com.fs.starfarer.api.util.Misc; 013 014public class HAColonyDefensesFactor extends BaseEventFactor { 015 016 public static float PATROL_HQ_MULT = 0.9f; 017 public static float MILITARY_BASE_MULT = 0.7f; 018 public static float HIGH_COMMAND_MULT = 0.5f; 019 020 public static class HAColonyDefenseData { 021 public MarketAPI market; 022 public Industry industry; 023 public float mult = 1f; 024 } 025 026 public HAColonyDefensesFactor() { 027 } 028 029 @Override 030 public TooltipCreator getMainRowTooltip(BaseEventIntel intel) { 031 return new BaseFactorTooltip() { 032 public void createTooltip(TooltipMakerAPI tooltip, boolean expanded, Object tooltipParam) { 033 Color h = Misc.getHighlightColor(); 034 float opad = 10f; 035 036 037 tooltip.addPara("The presence of military infrastructure slows down event progress, but does not actually stop or reverse it. " 038 + "The highest level military structure present on any of your colonies determines the multiplier.", 0f); 039 040 HAColonyDefenseData data = getDefenseData(null); 041 042 tooltip.beginTable(Misc.getBasePlayerColor(), Misc.getDarkPlayerColor(), Misc.getBrightPlayerColor(), 043 20f, "Infrastructure", 200f, "Multiplier", 100f); 044 045 Color c = Misc.getGrayColor(); 046 Color c2 = Misc.getGrayColor(); 047 if (data.industry != null && data.industry.getId().equals(Industries.PATROLHQ)) { 048 c = Misc.getHighlightColor(); 049 c2 = Misc.getPositiveHighlightColor(); 050 } 051 tooltip.addRow(c, "Patrol HQ", c2, Strings.X + Misc.getRoundedValueMaxOneAfterDecimal(PATROL_HQ_MULT)); 052 053 c = Misc.getGrayColor(); 054 c2 = Misc.getGrayColor(); 055 if (data.industry != null && data.industry.getId().equals(Industries.MILITARYBASE)) { 056 c = Misc.getHighlightColor(); 057 c2 = Misc.getPositiveHighlightColor(); 058 } 059 tooltip.addRow(c, "Military Base", c2, Strings.X + Misc.getRoundedValueMaxOneAfterDecimal(MILITARY_BASE_MULT)); 060 061 c = Misc.getGrayColor(); 062 c2 = Misc.getGrayColor(); 063 if (data.industry != null && data.industry.getId().equals(Industries.HIGHCOMMAND)) { 064 c = Misc.getHighlightColor(); 065 c2 = Misc.getPositiveHighlightColor(); 066 } 067 tooltip.addRow(c, "High Command", c2, Strings.X + Misc.getRoundedValueMaxOneAfterDecimal(HIGH_COMMAND_MULT)); 068 069 tooltip.addTable("None", 0, opad); 070 tooltip.addSpacer(5f); 071 072 if (data.industry != null && data.market != null) { 073 tooltip.addPara("You have a %s at %s.", opad, h, 074 data.industry.getCurrentName(), data.market.getName()); 075 } 076 } 077 }; 078 } 079 080 081 @Override 082 public boolean shouldShow(BaseEventIntel intel) { 083 //HAColonyDefenseData data = getDefenseData(intel); 084 return true; 085 } 086 087 088 public float getAllProgressMult(BaseEventIntel intel) { 089 HAColonyDefenseData data = getDefenseData(intel); 090 return data.mult; 091 } 092 093 094 @Override 095 public Color getProgressColor(BaseEventIntel intel) { 096 HAColonyDefenseData data = getDefenseData(intel); 097 if (data.mult < 1) { 098 return Misc.getPositiveHighlightColor(); 099 } else if (data.mult > 1) { 100 return Misc.getNegativeHighlightColor(); 101 } 102 return Misc.getHighlightColor(); // no text anyway 103 } 104 105 @Override 106 public String getProgressStr(BaseEventIntel intel) { 107 HAColonyDefenseData data = getDefenseData(intel); 108 if (data.mult != 1) { 109 return Strings.X + Misc.getRoundedValueMaxOneAfterDecimal(data.mult); 110 } 111 return ""; 112 } 113 114 public String getDesc(BaseEventIntel intel) { 115 HAColonyDefenseData data = getDefenseData(intel); 116 if (data.industry == null) { 117 return "Military infrastructure"; 118 } 119 return data.industry.getCurrentName(); 120 } 121 122 @Override 123 public Color getDescColor(BaseEventIntel intel) { 124 if (getDefenseData(intel).market == null) { 125 return Misc.getGrayColor(); 126 } 127 return super.getDescColor(intel); 128 } 129 130 public HAColonyDefenseData getDefenseData(BaseEventIntel intel) { 131 HAColonyDefenseData best = new HAColonyDefenseData(); 132 133 List<MarketAPI> markets = Misc.getPlayerMarkets(false); 134 for (MarketAPI market : markets) { 135 float mult = 1f; 136 Industry industry = null; 137 if (market.hasFunctionalIndustry(Industries.PATROLHQ)) { 138 mult = PATROL_HQ_MULT; 139 industry = market.getIndustry(Industries.PATROLHQ); 140 } 141 if (Misc.isMilitary(market)) { 142 if (market.hasFunctionalIndustry(Industries.HIGHCOMMAND)) { 143 mult = HIGH_COMMAND_MULT; 144 industry = market.getIndustry(Industries.HIGHCOMMAND); 145 } else { 146 mult = MILITARY_BASE_MULT; 147 industry = market.getIndustry(Industries.MILITARYBASE); 148 } 149 } 150 151 if (industry != null && mult < best.mult) { 152 best.market = market; 153 best.industry = industry; 154 best.mult = mult; 155 } 156 } 157 158 return best; 159 } 160 161}