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.Global; 008import com.fs.starfarer.api.campaign.StarSystemAPI; 009import com.fs.starfarer.api.campaign.econ.Industry; 010import com.fs.starfarer.api.campaign.econ.MarketAPI; 011import com.fs.starfarer.api.impl.campaign.ids.Commodities; 012import com.fs.starfarer.api.impl.campaign.ids.Factions; 013import com.fs.starfarer.api.impl.campaign.intel.PerseanLeagueMembership; 014import com.fs.starfarer.api.ui.LabelAPI; 015import com.fs.starfarer.api.ui.TooltipMakerAPI; 016import com.fs.starfarer.api.ui.TooltipMakerAPI.TooltipCreator; 017import com.fs.starfarer.api.util.Misc; 018 019public class HegemonyAICoresActivityCause extends BaseHostileActivityCause2 { 020 021 public static int IGNORE_COLONY_THRESHOLD = 3; 022 023 024 public HegemonyAICoresActivityCause(HostileActivityEventIntel intel) { 025 super(intel); 026 } 027 028 @Override 029 public TooltipCreator getTooltip() { 030 return new BaseFactorTooltip() { 031 public void createTooltip(TooltipMakerAPI tooltip, boolean expanded, Object tooltipParam) { 032 float opad = 10f; 033 tooltip.addPara("The Hegemony considers the use of %s illegal, though it is unlikely " 034 + "to take much notice of what goes on at colonies of size %s or smaller.", 0f, 035 Misc.getHighlightColor(), "AI cores", "" + IGNORE_COLONY_THRESHOLD); 036 037 if (isNegatedByPLMembership()) { 038 Color c = Global.getSector().getFaction(Factions.PERSEAN).getBaseUIColor(); 039 LabelAPI label = tooltip.addPara("However, your membership in the Persean League makes it politically " 040 + "difficult for the Hegemony to pursue the matter.", opad); 041 label.setHighlight("Persean League", "politically difficult"); 042 label.setHighlightColors(c, Misc.getPositiveHighlightColor()); 043 } 044 } 045 }; 046 } 047 048 public boolean isNegatedByPLMembership() { 049 //if (true) return true; 050 return PerseanLeagueMembership.isLeagueMember() && getProgress(false) > 0; 051 } 052 053 @Override 054 public String getProgressStr() { 055 if (isNegatedByPLMembership()) return EventFactor.NEGATED_FACTOR_PROGRESS; 056 return super.getProgressStr(); 057 } 058 059 @Override 060 public Color getProgressColor(BaseEventIntel intel) { 061 if (isNegatedByPLMembership()) return Misc.getPositiveHighlightColor(); 062 return super.getProgressColor(intel); 063 } 064 065 @Override 066 public boolean shouldShow() { 067 return getProgress() != 0 || isNegatedByPLMembership(); 068 } 069 070 public int getProgress() { 071 return getProgress(true); 072 } 073 public int getProgress(boolean checkNegated) { 074 if (HegemonyHostileActivityFactor.isPlayerDefeatedHegemony()) return 0; 075 if (checkNegated && isNegatedByPLMembership()) return 0; 076 077 int progress = (int) Math.round(getTotalAICorePoints()); 078 079 float unit = Global.getSettings().getFloat("hegemonyProgressUnit"); 080 float mult = Global.getSettings().getFloat("hegemonyProgressMult"); 081 //progress = 200; 082 int rem = progress; 083 float adjusted = 0; 084 while (rem > unit) { 085 adjusted += unit; 086 rem -= unit; 087 rem *= mult; 088 } 089 adjusted += rem; 090 091 int reduced = Math.round(adjusted); 092 if (progress > 0 && reduced < 1) reduced = 1; 093 progress = reduced; 094 095// int reduced = (int) Math.round(Math.pow(progress, 0.8f)); 096// if (progress > 0 && reduced <= 0) reduced = 1; 097// progress = reduced; 098 099 return progress; 100 } 101 102 public String getDesc() { 103 return "AI core use"; 104 } 105 106 public float getTotalAICorePoints() { 107 float total = 0f; 108 for (StarSystemAPI system : Misc.getPlayerSystems(false)) { 109 total += getAICorePoints(system); 110 } 111 return total; 112 } 113 114 public static float getAICorePoints(StarSystemAPI system) { 115 float total = 0f; 116 List<MarketAPI> markets = Misc.getMarketsInLocation(system, Factions.PLAYER); 117 for (MarketAPI market : markets) { 118 if (market.getSize() <= IGNORE_COLONY_THRESHOLD) continue; 119 float interest = getAICorePoints(market); 120 total += interest; 121 } 122 return total; 123 } 124 125 public static float getAICorePoints(MarketAPI market) { 126 float total = 0f; 127 128 float admin = Global.getSettings().getFloat("hegemonyPointsAdmin"); 129 float alpha = Global.getSettings().getFloat("hegemonyPointsAlpha"); 130 float beta = Global.getSettings().getFloat("hegemonyPointsBeta"); 131 float gamma = Global.getSettings().getFloat("hegemonyPointsGamma"); 132 133 String aiCoreId = market.getAdmin().getAICoreId(); 134 if (aiCoreId != null) { 135 total += admin; 136 } 137 138 for (Industry ind : market.getIndustries()) { 139 String core = ind.getAICoreId(); 140 if (Commodities.ALPHA_CORE.equals(core)) { 141 total += alpha; 142 } else if (Commodities.BETA_CORE.equals(core)) { 143 total += beta; 144 } else if (Commodities.GAMMA_CORE.equals(core)) { 145 total += gamma; 146 } 147 } 148 149 return total; 150 } 151 152 public float getMagnitudeContribution(StarSystemAPI system) { 153 if (HegemonyHostileActivityFactor.isPlayerDefeatedHegemony()) return 0f; 154 if (isNegatedByPLMembership()) return 0f; 155 156 if (getProgress() <= 0) return 0f; 157 158 List<MarketAPI> markets = Misc.getMarketsInLocation(system, Factions.PLAYER); 159 160 float total = 0f; 161 for (MarketAPI market : markets) { 162 float points = getAICorePoints(market); 163 total += points; 164 } 165 166 total = Math.round(total * 100f) / 100f; 167 168 return total; 169 } 170 171}