001package com.fs.starfarer.api.impl.campaign.intel.group; 002 003import java.util.List; 004import java.util.Random; 005 006import java.awt.Color; 007 008import org.lwjgl.util.vector.Vector2f; 009 010import com.fs.starfarer.api.Global; 011import com.fs.starfarer.api.campaign.CampaignFleetAPI; 012import com.fs.starfarer.api.campaign.FactionAPI; 013import com.fs.starfarer.api.campaign.SectorEntityToken; 014import com.fs.starfarer.api.campaign.StarSystemAPI; 015import com.fs.starfarer.api.campaign.econ.MarketAPI; 016import com.fs.starfarer.api.impl.campaign.ids.Factions; 017import com.fs.starfarer.api.impl.campaign.ids.Industries; 018import com.fs.starfarer.api.impl.campaign.intel.group.FGRaidAction.FGRaidParams; 019import com.fs.starfarer.api.impl.campaign.missions.FleetCreatorMission; 020import com.fs.starfarer.api.impl.campaign.missions.hub.BaseHubMission; 021import com.fs.starfarer.api.ui.Alignment; 022import com.fs.starfarer.api.ui.TooltipMakerAPI; 023import com.fs.starfarer.api.util.Misc; 024import com.fs.starfarer.api.util.WeightedRandomPicker; 025 026public class TestFleetGroupIntel extends FleetGroupIntel { 027 028 public static String PREPARE_ACTION = "prepare_action"; 029 public static String TRAVEL_ACTION = "travel_action"; 030 public static String RAID_ACTION = "raid_action"; 031 public static String RETURN_ACTION = "return_action"; 032 033 034 protected SectorEntityToken origin; 035 protected FGRaidAction raidAction; 036 037 public TestFleetGroupIntel() { 038 super(); 039 040 MarketAPI garnir = Global.getSector().getEconomy().getMarket("corvus_IIIa"); 041 MarketAPI jangala = Global.getSector().getEconomy().getMarket("jangala"); 042 MarketAPI gilead = Global.getSector().getEconomy().getMarket("gilead"); 043 MarketAPI asher = Global.getSector().getEconomy().getMarket("asher"); 044 045 //gilead = Global.getSector().getEconomy().getMarket("market_system_192c:planet_1"); 046 047// gilead = jangala; 048// addAction(new FGWaitAction(jangala.getPrimaryEntity(), 1f, "preparing for expedition")); 049// addAction(new FGTravelAction(jangala.getPrimaryEntity(), gilead.getPrimaryEntity().getStarSystem().getCenter())); 050// addAction(new FGTravelAction(gilead.getPrimaryEntity(), jangala.getPrimaryEntity())); 051 052 setFaction(Factions.PIRATES); 053 addAction(new FGWaitAction(garnir.getPrimaryEntity(), 1f, "preparing for raid"), PREPARE_ACTION); 054 addAction(new FGTravelAction(garnir.getPrimaryEntity(), 055 gilead.getPrimaryEntity().getStarSystem().getCenter()), 056 TRAVEL_ACTION); 057// addAction(new FGWaitAction(gilead.getPrimaryEntity().getStarSystem().getCenter(), 5f, 058// "preparing for raid"), POST_RAID_ACTION); 059 060 061 FGRaidParams params = new FGRaidParams(); 062 params.where = gilead.getPrimaryEntity().getStarSystem(); 063 params.allowedTargets.add(gilead); 064 params.allowedTargets.add(asher); 065 //params.setBombardment(BombardType.SATURATION); 066 params.setDisrupt(Industries.FARMING, Industries.MEGAPORT); 067 068 raidAction = new FGRaidAction(params, 3f); 069 addAction(raidAction, RAID_ACTION); 070 071 addAction(new FGTravelAction(gilead.getPrimaryEntity().getStarSystem().getCenter(), 072 garnir.getPrimaryEntity().getStarSystem().getCenter()), 073 RETURN_ACTION); 074 075 076 origin = garnir.getPrimaryEntity(); 077 078 createRoute(Factions.PIRATES, 30, 7, null, null); 079 } 080 081 protected void spawnFleets() { 082 MarketAPI garnir = Global.getSector().getEconomy().getMarket("corvus_IIIa"); 083 Vector2f loc = garnir.getLocationInHyperspace(); 084 085 Float damage = null; 086 if (route != null && route.getExtra() != null) { 087 damage = route.getExtra().damage; 088 } 089 if (damage == null) damage = 0f; 090 091 String factionId; 092 factionId = Factions.LUDDIC_CHURCH; 093 factionId = Factions.PIRATES; 094 095 096 WeightedRandomPicker<Integer> picker = new WeightedRandomPicker<Integer>(getRandom()); 097 picker.add(3); 098 picker.add(4); 099 picker.add(6); 100 picker.add(7); 101 picker.add(9); 102 picker.add(10); 103 picker.add(10); 104 105 float total = 0; 106 for (Integer i : picker.getItems()) total += i; 107 108 float spawnsToSkip = total * damage * 0.5f; 109 float skipped = 0f; 110 111 112 while (!picker.isEmpty()) { 113 Integer size = picker.pickAndRemove(); 114 if (skipped < spawnsToSkip && getRandom().nextFloat() < damage) { 115 skipped += size; 116 continue; 117 } 118 119 FleetCreatorMission m = new FleetCreatorMission(new Random()); 120 m.beginFleet(); 121 122 m.createQualityFleet(size, factionId, loc); 123 m.setFleetSource(garnir); 124 m.setFleetDamageTaken(damage); 125 //m.triggerSetFleetFaction(); 126 //m.triggerFleetAllowLongPursuit(); 127 m.triggerSetPirateFleet(); 128 //m.triggerSetWarFleet(); 129 m.triggerMakeNoRepImpact(); 130 131 CampaignFleetAPI fleet = m.createFleet(); 132 if (fleet != null && route != null) { 133 setLocationAndCoordinates(fleet, route.getCurrent()); 134 fleets.add(fleet); 135 } 136 } 137 138 } 139 140 protected void addNonUpdateBulletPoints(TooltipMakerAPI info, Color tc, Object param, ListInfoMode mode, float initPad) { 141 Color h = Misc.getHighlightColor(); 142 FGAction curr = getCurrentAction(); 143 StarSystemAPI system = raidAction.getParams().where; 144 145 float untilDeparture = getETAUntil(TRAVEL_ACTION); 146 float untilRaid = getETAUntil(RAID_ACTION); 147 float untilReturn = getETAUntil(RETURN_ACTION, true); 148 149 if (mode == ListInfoMode.MESSAGES) { // initial notification only, not updates 150 info.addPara("Targeting the " + system.getNameWithLowercaseTypeShort(), tc, initPad); 151 initPad = 0f; 152 } 153 if (untilDeparture > 0) { 154 addETABulletPoints(null, null, false, untilDeparture, ETAType.DEPARTURE, info, tc, initPad); 155 } 156 if (untilRaid > 0 && getSource().getContainingLocation() != system) { 157 addETABulletPoints(system.getNameWithLowercaseTypeShort(), null, false, untilRaid, ETAType.ARRIVING, 158 info, tc, initPad); 159 initPad = 0f; 160 } 161 if (untilReturn > 0 && isSucceeded() && getSource().getContainingLocation() != system) { 162 StarSystemAPI from = getSource().getStarSystem(); 163 164 addETABulletPoints(from.getNameWithLowercaseTypeShort(), null, false, untilReturn, ETAType.RETURNING, 165 info, tc, initPad); 166 initPad = 0f; 167 } 168 if (mode == ListInfoMode.INTEL && curr != null && curr.getId().equals(RAID_ACTION)) { 169 info.addPara("Operating in the " + system.getNameWithLowercaseTypeShort(), tc, initPad); 170 initPad = 0f; 171 } 172 if (mode != ListInfoMode.IN_DESC && isEnding()) { 173 if (!isSucceeded()) { 174 info.addPara("The raiding forces have been defeated and scatter", tc, initPad); 175 } 176 } 177 } 178 179 protected void addUpdateBulletPoints(TooltipMakerAPI info, Color tc, Object param, ListInfoMode mode, float initPad) { 180 StarSystemAPI system = raidAction.getParams().where; 181 //Color h = Misc.getHighlightColor(); 182 if (ABORT_UPDATE.equals(param)) { 183 info.addPara("The raiding forces have been defeated and scatter", tc, initPad); 184 } else if (PREPARE_ACTION.equals(param)) { 185 float untilRaid = getETAUntil(RAID_ACTION); 186 addETABulletPoints(system.getNameWithLowercaseTypeShort(), null, true, untilRaid, ETAType.ARRIVING, 187 info, tc, initPad); 188 } else if (TRAVEL_ACTION.equals(param)) { 189 addArrivedBulletPoint(system.getNameWithLowercaseTypeShort(), null, info, tc, initPad); 190 } else if (RAID_ACTION.equals(param)) { 191 if (isSucceeded()) { 192 info.addPara("The raiding forces are withdrawing", tc, initPad); 193 } else { 194 info.addPara("The raiding forces have been defeated and scatter", tc, initPad); 195 } 196 } 197 } 198 199 @Override 200 protected boolean shouldSendIntelUpdateWhenActionFinished(FGAction action) { 201 if (RETURN_ACTION.equals(action.getId())) return false; 202 if (RAID_ACTION.equals(action.getId())) { 203 // if it failed, will send an update on abort() instead 204 return isSucceeded(); 205 } 206 if (TRAVEL_ACTION.equals(action.getId())) { 207 // no update for "arriving" when traveling from one planet in-system to another 208 return getSource().getContainingLocation() != raidAction.getParams().where; 209 } 210 211 return super.shouldSendIntelUpdateWhenActionFinished(action); 212 } 213 214 protected void addBasicDescription(TooltipMakerAPI info, float width, float height, float opad) { 215 info.addImage(getFaction().getLogo(), width, 128, opad); 216 217 StarSystemAPI system = raidAction.getParams().where; 218 219 info.addPara(Misc.ucFirst(faction.getPersonNamePrefixAOrAn()) + " %s raid against " 220 + "the " + system.getNameWithLowercaseTypeShort() + ".", opad, 221 faction.getBaseUIColor(), faction.getEntityNamePrefix()); 222 } 223 224 protected void addAssessmentSection(TooltipMakerAPI info, float width, float height, float opad) { 225 Color h = Misc.getHighlightColor(); 226 227 FactionAPI faction = getFaction(); 228 229 List<MarketAPI> targets = raidAction.getParams().allowedTargets; 230 231 if (!isEnding() && !isSucceeded()) { 232 info.addSectionHeading("Assessment", 233 faction.getBaseUIColor(), faction.getDarkUIColor(), Alignment.MID, opad); 234 if (targets.isEmpty()) { 235 info.addPara("There are no colonies for the raid to target in the system.", opad); 236 } else { 237 StarSystemAPI system = raidAction.getParams().where; 238 239 boolean potentialDanger = addStrengthDesc(info, opad, system, "raiding forces", 240 "the raid is unlikely to find success", 241 "the raid's outcome is uncertain", 242 "the raid is likely to find success"); 243 244 if (potentialDanger) { 245 showMarketsInDanger(info, opad, width, system, targets, 246 "should be safe from the raid", 247 "are at risk of being raided and losing stability:", 248 "losing stability"); 249 } 250 } 251 } 252 } 253 254 255 protected void addStatusSection(TooltipMakerAPI info, float width, float height, float opad) { 256 FGAction curr = getCurrentAction(); 257 258 boolean showStatus = curr != null || isEnding() || isSucceeded(); 259 260 if (showStatus) { 261 info.addSectionHeading("Status", 262 faction.getBaseUIColor(), faction.getDarkUIColor(), Alignment.MID, opad); 263 if (isEnding() && !isSucceeded()) { 264 info.addPara("The raiding forces have been defeated and any " 265 + "remaining ships are retreating in disarray.", opad); 266 } else if (isEnding() || isSucceeded()) { 267 info.addPara("The raid was successful and the raiding forces are withdrawing.", opad); 268 } else if (curr != null) { 269 //StarSystemAPI from = getSource().getStarSystem(); 270 StarSystemAPI to = raidAction.getParams().where; 271 if (PREPARE_ACTION.equals(curr.getId())) { 272 BaseHubMission.addStandardMarketDesc("Making preparations in orbit around", 273 getSource().getMarket(), info, opad); 274 } else if (TRAVEL_ACTION.equals(curr.getId())) { 275 info.addPara("Traveling from " + getSource().getMarket().getName() + " to the " + 276 to.getNameWithLowercaseTypeShort() + ".", opad); 277 } else if (RAID_ACTION.equals(curr.getId())) { 278 info.addPara("Conducting operations in the " + 279 to.getNameWithLowercaseTypeShort() + ".", opad); 280 } 281 } 282 } 283 } 284 285 286 public String getBaseName() { 287 return Misc.ucFirst(getFaction().getPersonNamePrefix()) + " Raid"; 288 } 289 290 public boolean isSucceeded() { 291 return raidAction.getSuccessFraction() > 0f && raidAction.isActionFinished(); 292 } 293 294 protected SectorEntityToken getSource() { 295 return origin; 296 } 297 298 protected SectorEntityToken getDestination() { 299 return raidAction.getParams().where.getHyperspaceAnchor(); 300 } 301 302 @Override 303 protected boolean isPlayerTargeted() { 304 return true; 305 } 306} 307 308 309 310