001package com.fs.starfarer.api.impl.campaign.intel.events; 002 003import java.awt.Color; 004import java.util.LinkedHashSet; 005import java.util.List; 006import java.util.Set; 007 008import com.fs.starfarer.api.Global; 009import com.fs.starfarer.api.campaign.StarSystemAPI; 010import com.fs.starfarer.api.campaign.econ.MarketAPI; 011import com.fs.starfarer.api.impl.campaign.ids.Factions; 012import com.fs.starfarer.api.impl.campaign.intel.bases.LuddicPathBaseIntel; 013import com.fs.starfarer.api.impl.campaign.intel.bases.LuddicPathBaseManager; 014import com.fs.starfarer.api.impl.campaign.intel.bases.LuddicPathCellsIntel; 015import com.fs.starfarer.api.impl.campaign.rulecmd.HA_CMD; 016import com.fs.starfarer.api.ui.TooltipMakerAPI; 017import com.fs.starfarer.api.ui.TooltipMakerAPI.TooltipCreator; 018import com.fs.starfarer.api.util.Misc; 019 020public class StandardLuddicPathActivityCause2 extends BaseHostileActivityCause2 { 021 022 public StandardLuddicPathActivityCause2(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("Use of advanced technology and AI cores attracts the attention of Pathers.", 0f, 032 Misc.getHighlightColor(), "advanced technology", "AI cores"); 033 034 Set<LuddicPathBaseIntel> seen = new LinkedHashSet<LuddicPathBaseIntel>(); 035 for (MarketAPI market : Misc.getPlayerMarkets(false)) { 036 LuddicPathBaseIntel base = LuddicPathCellsIntel.getClosestBase(market); 037 if (base == null) continue; 038 039 if (seen.contains(base)) continue; 040 041 LuddicPathCellsIntel cells = LuddicPathCellsIntel.getCellsForMarket(market); 042 if (cells == null || cells.isSleeper()) continue; 043 044 seen.add(base); 045 046 Color h = Misc.getHighlightColor(); 047 String system = ""; 048 if (base.isPlayerVisible()) { 049 system = " located in the " + base.getSystem().getNameWithLowercaseTypeShort() + ""; 050 } 051 tooltip.addPara("Active Pather cells on some of your colonies are being supported " 052 + "by a Pather base" + system + ". %s " 053 + "will reduce the level of Pather fleet actvity.", opad, h, 054 "Dealing with this base"); 055 break; 056 } 057 058 for (MarketAPI market : Misc.getPlayerMarkets(false)) { 059 LuddicPathCellsIntel cells = LuddicPathCellsIntel.getCellsForMarket(market); 060 if (cells == null) continue; 061 if (cells.getSleeperTimeout() > 0) { 062 tooltip.addPara("Pather cells on some of your colonies have been disrupted, reducing " 063 + "the Pather interest contribution from these colonies to event progress.", opad, 064 Misc.getPositiveHighlightColor(), "disrupted"); 065 break; 066 } 067 068 } 069 } 070 }; 071 } 072 073 @Override 074 public boolean shouldShow() { 075 return getProgress() != 0 || HA_CMD.playerHasPatherAgreement(); 076 } 077 078 @Override 079 public String getProgressStr() { 080 if (HA_CMD.playerHasPatherAgreement()) return EventFactor.NEGATED_FACTOR_PROGRESS; 081 return super.getProgressStr(); 082 } 083 084 @Override 085 public Color getProgressColor(BaseEventIntel intel) { 086 if (HA_CMD.playerHasPatherAgreement()) return Misc.getPositiveHighlightColor(); 087 return super.getProgressColor(intel); 088 } 089 090 public int getProgress() { 091 if (HA_CMD.playerHasPatherAgreement()) return 0; 092 if (LuddicPathHostileActivityFactor.isPlayerDefeatedPatherExpedition()) return 0; 093 094 int progress = (int) Math.round(getTotalPatherInterest()); 095 096 float unit = Global.getSettings().getFloat("patherProgressUnit"); 097 float mult = Global.getSettings().getFloat("patherProgressMult"); 098 //progress = 200; 099 int rem = progress; 100 float adjusted = 0; 101 while (rem > unit) { 102 adjusted += unit; 103 rem -= unit; 104 rem *= mult; 105 } 106 adjusted += rem; 107 108 int reduced = Math.round(adjusted); 109 if (progress > 0 && reduced < 1) reduced = 1; 110 progress = reduced; 111 112// int reduced = (int) Math.round(Math.pow(progress, 0.8f)); 113// if (progress > 0 && reduced <= 0) reduced = 1; 114// progress = reduced; 115 116 return progress; 117 } 118 119 public String getDesc() { 120 return "Technology and AI core use"; 121 } 122 123 public float getTotalPatherInterest() { 124 float total = 0f; 125 for (StarSystemAPI system : Misc.getPlayerSystems(false)) { 126 float noCells = Global.getSettings().getFloat("patherProgressMultNoCells"); 127 float sleeperCells = Global.getSettings().getFloat("patherProgressMultSleeperCells"); 128 float activeCells = Global.getSettings().getFloat("patherProgressMultActiveCells"); 129 130// noCells = 0f; 131// sleeperCells = 0.25f; 132// activeCells = 1f; 133 total += getPatherInterest(system, noCells, sleeperCells, activeCells); 134 } 135 return total; 136 } 137 138 public static float getPatherInterest(StarSystemAPI system, float multIfNoCells, float multIfSleeper, float multIfActive) { 139 return getPatherInterest(system, multIfNoCells, multIfSleeper, multIfActive, false); 140 } 141 public static float getPatherInterest(StarSystemAPI system, float multIfNoCells, float multIfSleeper, float multIfActive, boolean countCellsOnly) { 142 float total = 0f; 143 List<MarketAPI> markets = Misc.getMarketsInLocation(system, Factions.PLAYER); 144 for (MarketAPI market : markets) { 145 float mult = 1f; 146 LuddicPathCellsIntel intel = LuddicPathCellsIntel.getCellsForMarket(market); 147 if (intel == null) { 148 mult = multIfNoCells; 149 } else if (intel.isSleeper()) { 150 mult = multIfSleeper; 151 } else { 152 mult = multIfActive; 153 } 154 155 float interest = LuddicPathBaseManager.getLuddicPathMarketInterest(market); 156 if (countCellsOnly) interest = 1f; 157 total += (interest * mult); 158 } 159 return total; 160 } 161 162 163 public float getMagnitudeContribution(StarSystemAPI system) { 164 if (HA_CMD.playerHasPatherAgreement()) return 0f; 165 if (LuddicPathHostileActivityFactor.isPlayerDefeatedPatherExpedition()) return 0f; 166 167 List<MarketAPI> markets = Misc.getMarketsInLocation(system, Factions.PLAYER); 168 169// float noCells = Global.getSettings().getFloat("luddicPathNoCellsInterestMult"); 170// float sleeperCells = Global.getSettings().getFloat("luddicPathSleeperInterestMult"); 171// float activeCells = Global.getSettings().getFloat("luddicPathActiveInterestMult"); 172 173 float perSleeperBase = Global.getSettings().getFloat("luddicPathSleeperCellsBase"); 174 float perSleeperSize = Global.getSettings().getFloat("luddicPathSleeperCellsPerSize"); 175 float perActiveBase = Global.getSettings().getFloat("luddicPathActiveCellsBase"); 176 float perActiveSize = Global.getSettings().getFloat("luddicPathActiveCellsPerSize"); 177 float perPointOfInterest = Global.getSettings().getFloat("luddicPathPerPointOfInterest"); 178 179 float max = 0f; 180 for (MarketAPI market : markets) { 181 LuddicPathCellsIntel intel = LuddicPathCellsIntel.getCellsForMarket(market); 182 if (intel == null) continue; 183 184 float curr = 0f; 185 if (intel.isSleeper()) { 186 curr += perSleeperBase + market.getSize() * perSleeperSize; 187 } else { 188 curr += perActiveBase + market.getSize() * perActiveSize; 189 } 190 191 float interest = LuddicPathBaseManager.getLuddicPathMarketInterest(market); 192 curr += interest * perPointOfInterest; 193 194 if (curr >= max) { 195 max = curr; 196 } 197 } 198 199 max = Math.round(max * 100f) / 100f; 200 201 return max; 202 } 203 204}