001package com.fs.starfarer.api.impl.campaign.intel.events; 002 003import java.util.List; 004 005import java.awt.Color; 006 007import com.fs.starfarer.api.campaign.StarSystemAPI; 008import com.fs.starfarer.api.campaign.econ.MarketAPI; 009import com.fs.starfarer.api.impl.campaign.fleets.EconomyFleetRouteManager; 010import com.fs.starfarer.api.impl.campaign.ids.Factions; 011import com.fs.starfarer.api.impl.campaign.rulecmd.KantaCMD; 012import com.fs.starfarer.api.ui.MapParams; 013import com.fs.starfarer.api.ui.TooltipMakerAPI; 014import com.fs.starfarer.api.ui.TooltipMakerAPI.TooltipCreator; 015import com.fs.starfarer.api.ui.UIPanelAPI; 016import com.fs.starfarer.api.util.Misc; 017 018public class StandardPirateActivityCause2 extends BaseHostileActivityCause2 { 019 020 public static float MAX_MAG = 0.5f; 021 022 public StandardPirateActivityCause2(HostileActivityEventIntel intel) { 023 super(intel); 024 } 025 026 @Override 027 public TooltipCreator getTooltip() { 028 return new BaseFactorTooltip() { 029 public void createTooltip(TooltipMakerAPI tooltip, boolean expanded, Object tooltipParam) { 030 float opad = 10f; 031 tooltip.addPara("Any colony, especially one outside the core, attracts some degree of piracy." 032 + " %s and %s colonies attract more pirates.", 0f, 033 Misc.getHighlightColor(), "Larger", "less stable"); 034 tooltip.addPara("Event progress value is based on the size and stability of the largest colony " 035 + "under your control. If multiple colonies have the same size, the one with higher " 036 + "stability is used.", opad); 037 038 MarketAPI biggest = getBiggestColony(); 039 if (biggest != null && biggest.getStarSystem() != null) { 040 tooltip.addPara("Biggest colony: %s, size: %s, stability: %s", opad, Misc.getHighlightColor(), 041 biggest.getName(), 042 "" + biggest.getSize(), 043 "" + (int) biggest.getStabilityValue()); 044 045 MapParams params = new MapParams(); 046 params.showSystem(biggest.getStarSystem()); 047 float w = tooltip.getWidthSoFar(); 048 float h = Math.round(w / 1.6f); 049 params.positionToShowAllMarkersAndSystems(true, Math.min(w, h)); 050 UIPanelAPI map = tooltip.createSectorMap(w, h, params, biggest.getStarSystem().getNameWithLowercaseTypeShort()); 051 tooltip.addCustom(map, opad); 052 } 053 } 054 }; 055 } 056 057 public MarketAPI getBiggestColony() { 058 List<MarketAPI> markets = Misc.getPlayerMarkets(false); 059 MarketAPI biggest = null; 060 float max = 0; 061 for (MarketAPI market : markets) { 062 float size = market.getSize(); 063 if (size >= max) { 064 if (size == max && biggest != null) { 065 if (biggest.getStabilityValue() > market.getStabilityValue()) { 066 continue; 067 } 068 } 069 max = size; 070 biggest = market; 071 } 072 } 073 return biggest; 074 } 075 076 @Override 077 public boolean shouldShow() { 078 return getProgress() != 0 || KantaCMD.playerHasProtection(); 079 } 080 081 @Override 082 public String getProgressStr() { 083 if (KantaCMD.playerHasProtection()) return EventFactor.NEGATED_FACTOR_PROGRESS; 084 return super.getProgressStr(); 085 } 086 087 @Override 088 public Color getProgressColor(BaseEventIntel intel) { 089 if (KantaCMD.playerHasProtection()) return Misc.getPositiveHighlightColor(); 090 // TODO Auto-generated method stub 091 return super.getProgressColor(intel); 092 } 093 094 public int getProgress() { 095 if (KantaCMD.playerHasProtection()) return 0; 096 097 MarketAPI biggest = getBiggestColony(); 098 if (biggest == null) return 0; 099 int progress = (int) (biggest.getSize() + (10 - biggest.getStabilityValue())); 100 return progress; 101 } 102 103 public String getDesc() { 104 return "Colony presence and instability"; 105 } 106 107 public float getMagForMarket(MarketAPI market) { 108 float val = market.getSize() * (0.33f + 0.67f * (1f - market.getStabilityValue() / 10f)); 109 val *= 0.1f; 110 if (val > MAX_MAG) val = MAX_MAG; 111 return val; 112 } 113 114 public float getMagnitudeContribution(StarSystemAPI system) { 115 if (EconomyFleetRouteManager.ENEMY_STRENGTH_CHECK_EXCLUDE_PIRATES) { 116 return 0f; 117 } 118 119 if (KantaCMD.playerHasProtection()) return 0f; 120 121 if (getProgress() <= 0) return 0f; 122 123 List<MarketAPI> markets = Misc.getMarketsInLocation(system, Factions.PLAYER); 124 125 float max = 0.1f; 126 for (MarketAPI market : markets) { 127 float val = getMagForMarket(market); 128 //float val = market.getSize() * 0.01f * 5f; 129 max = Math.max(val, max); 130 } 131 132 if (max > MAX_MAG) max = MAX_MAG; 133 134 max = Math.round(max * 100f) / 100f; 135 136 //if (true) return 0.79f; 137 return max; 138 } 139 140} 141 142 143 144