001package com.fs.starfarer.api.impl.campaign.intel.events; 002 003import java.awt.Color; 004import java.util.LinkedHashSet; 005import java.util.Set; 006 007import com.fs.starfarer.api.Global; 008import com.fs.starfarer.api.campaign.CampaignFleetAPI; 009import com.fs.starfarer.api.campaign.StarSystemAPI; 010import com.fs.starfarer.api.impl.campaign.ids.Factions; 011import com.fs.starfarer.api.ui.Alignment; 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.TooltipMakerAPI.TooltipLocation; 016import com.fs.starfarer.api.ui.UIPanelAPI; 017import com.fs.starfarer.api.util.Misc; 018 019public class RemnantNexusActivityCause extends BaseHostileActivityCause2 { 020 021 public static float MAX_MAG = 0.5f; 022 023 public static int PROGRESS_NEXUS_DAMAGED = Global.getSettings().getInt("remnantNexusPointsDamaged"); 024 public static int PROGRESS_NEXUS_NORMAL = Global.getSettings().getInt("remnantNexusPointsNormal"); 025 026 public RemnantNexusActivityCause(HostileActivityEventIntel intel) { 027 super(intel); 028 } 029 030 @Override 031 public void addExtraRows(TooltipMakerAPI info, BaseEventIntel intel) { 032 Set<CampaignFleetAPI> seen = new LinkedHashSet<CampaignFleetAPI>(); 033 for (final StarSystemAPI system : Misc.getSystemsWithPlayerColonies(false)) { 034 CampaignFleetAPI nexus = RemnantHostileActivityFactor.getRemnantNexus(system); 035 if (nexus == null) continue; 036 037 if (nexus == null || seen.contains(nexus)) continue; 038 039 040 int numColonies = Misc.getMarketsInLocation(system, Factions.PLAYER).size(); 041 final String colonies = numColonies != 1 ? "colonies" : "colony"; 042 final String isOrAre = numColonies != 1 ? "are" : "is"; 043 044 String desc = "Remnant Nexus in the " + system.getNameWithLowercaseTypeShort(); 045 046 final int progress = getProgressForNexus(nexus); 047 String progressStr = "+" + progress; 048 if (progress < 0) progressStr = "" + progress; 049 Color descColor = getDescColor(intel); 050 Color progressColor = getProgressColor(intel); 051 052 info.addRowWithGlow(Alignment.LMID, descColor, " " + desc, 053 Alignment.RMID, progressColor, progressStr); 054 055 TooltipCreator t = new BaseFactorTooltip() { 056 @Override 057 public void createTooltip(TooltipMakerAPI tooltip, boolean expanded, Object tooltipParam) { 058 float opad = 10f; 059 060 MapParams params = new MapParams(); 061 params.showSystem(system); 062 063 float w = tooltip.getWidthSoFar(); 064 float h = Math.round(w / 1.6f); 065 params.positionToShowAllMarkersAndSystems(true, Math.min(w, h)); 066 067 //UIPanelAPI map = tooltip.createSectorMap(w, h, params, aStr + " " + Misc.ucFirst(systems)); 068 UIPanelAPI map = tooltip.createSectorMap(w, h, params, system.getNameWithLowercaseType()); 069 070 tooltip.addPara("Your " + colonies + " in the " + system.getNameWithLowercaseTypeShort() + 071 " " + isOrAre + " threatened by a Remnant Nexus located in the system. " + 072 "This results in a greater risk of trade fleets being attacked, and eventual " 073 + "existential danger for your " + colonies + ".", 0f, Misc.getNegativeHighlightColor(), 074 "existential danger for your " + colonies); 075 076 tooltip.addPara("Even when relatively dormant, " + 077 "the Remnant fleets are a constant thorn in your side, wasting defensive resources and " 078 + "exposing your " + colonies + 079 " to other dangers.", opad); 080 081 tooltip.addPara("%s should address all these concerns.", opad, 082 Misc.getHighlightColor(), "Destroying the Nexus"); 083 084 tooltip.addCustom(map, opad); 085 } 086 }; 087 info.addTooltipToAddedRow(t, TooltipLocation.RIGHT, false); 088 } 089 } 090 091 @Override 092 public boolean shouldShow() { 093 return getProgress() != 0; 094 } 095 096 public int getProgress() { 097 int total = 0; 098 for (final StarSystemAPI system : Misc.getSystemsWithPlayerColonies(false)) { 099 CampaignFleetAPI nexus = RemnantHostileActivityFactor.getRemnantNexus(system); 100 if (nexus == null) continue; 101 total += getProgressForNexus(nexus); 102 } 103 return total; 104 } 105 106 107 protected int getProgressForNexus(CampaignFleetAPI nexus) { 108 if (nexus == null) return 0; 109 110 boolean damaged = nexus.getMemoryWithoutUpdate().getBoolean("$damagedStation"); 111 if (damaged) { 112 return PROGRESS_NEXUS_DAMAGED; 113 } 114 return PROGRESS_NEXUS_NORMAL; 115 } 116 117 118 119 public String getDesc() { 120 return null; 121 } 122 123 public float getMagnitudeContribution(StarSystemAPI system) { 124 if (getProgress() <= 0) return 0f; 125 126 CampaignFleetAPI nexus = RemnantHostileActivityFactor.getRemnantNexus(system); 127 if (nexus == null) return 0f; 128 129 boolean damaged = nexus.getMemoryWithoutUpdate().getBoolean("$damagedStation"); 130 if (damaged) { 131 return MAX_MAG * 0.5f; 132 } 133 134 return MAX_MAG; 135 } 136 137 138} 139 140