001package com.fs.starfarer.api.impl.campaign.fleets; 002 003import com.fs.starfarer.api.Global; 004import com.fs.starfarer.api.campaign.CampaignFleetAPI; 005import com.fs.starfarer.api.campaign.StarSystemAPI; 006import com.fs.starfarer.api.campaign.econ.MarketAPI; 007import com.fs.starfarer.api.campaign.econ.MarketConditionAPI; 008import com.fs.starfarer.api.impl.campaign.ids.Conditions; 009import com.fs.starfarer.api.impl.campaign.ids.Factions; 010import com.fs.starfarer.api.impl.campaign.ids.FleetTypes; 011import com.fs.starfarer.api.impl.campaign.ids.MemFlags; 012import com.fs.starfarer.api.impl.campaign.intel.bases.LuddicPathCells; 013import com.fs.starfarer.api.impl.campaign.intel.bases.PirateBaseManager; 014import com.fs.starfarer.api.util.Misc; 015 016/** 017 * Adds the following types of fleets: 018 * 1) Occasional pather fleet in hyper around a populated system 019 * 2) A few more in and around systems with pather/church presence 020 * 021 * @author Alex Mosolov 022 * 023 * Copyright 2018 Fractal Softworks, LLC 024 */ 025public class DisposableLuddicPathFleetManager extends DisposableFleetManager { 026 027 protected Object readResolve() { 028 super.readResolve(); 029 return this; 030 } 031 032 @Override 033 protected String getSpawnId() { 034 return "luddic_path"; // not a faction id, just an identifier for this spawner 035 } 036 037 @Override 038 protected int getDesiredNumFleetsForSpawnLocation() { 039 MarketAPI pather = getLargestMarket(Factions.LUDDIC_PATH); 040 MarketAPI church = getLargestMarket(Factions.LUDDIC_CHURCH); 041 042 float desiredNumFleets = 1f; 043 044 if (church != null) { 045 desiredNumFleets++; 046 } 047 if (pather != null) { 048 desiredNumFleets += pather.getSize(); 049 } 050 051 int cells = getPatherCellsLevel(); 052 desiredNumFleets += cells; 053 054 return (int) Math.round(desiredNumFleets); 055 } 056 057 protected int getPatherCellsLevel() { 058 if (currSpawnLoc == null) return 0; 059 int total = 0; 060 for (MarketAPI market : Global.getSector().getEconomy().getMarkets(currSpawnLoc)) { 061 if (market.isHidden()) continue; 062 MarketConditionAPI mc = market.getCondition(Conditions.PATHER_CELLS); 063 if (mc != null && mc.getPlugin() instanceof LuddicPathCells) { 064 LuddicPathCells cells = (LuddicPathCells) mc.getPlugin(); 065 if (cells.getIntel() != null) { 066 if (cells.getIntel().isSleeper()) { 067 total++; 068 } else { 069 total += 2; 070 } 071 } 072 } 073 } 074 return 0; 075 } 076 077 078 protected MarketAPI getLargestMarket(String faction) { 079 if (currSpawnLoc == null) return null; 080 MarketAPI largest = null; 081 int maxSize = 0; 082 for (MarketAPI market : Global.getSector().getEconomy().getMarkets(currSpawnLoc)) { 083 if (market.isHidden()) continue; 084 if (!market.getFactionId().equals(faction)) continue; 085 086 if (market.getSize() > maxSize) { 087 maxSize = market.getSize(); 088 largest = market; 089 } 090 } 091 return largest; 092 } 093 094 protected CampaignFleetAPI spawnFleetImpl() { 095 StarSystemAPI system = currSpawnLoc; 096 if (system == null) return null; 097 098 CampaignFleetAPI player = Global.getSector().getPlayerFleet(); 099 if (player == null) return null; 100 101 int num = Misc.getMarketsInLocation(system).size(); 102 if (Misc.getMarketsInLocation(system, Factions.PLAYER).size() == num && num > 0) { 103 return null; // handled by HostileActivityIntel, DisposableHostileActivityFleetManager, etc 104 } 105 106 107 String fleetType = FleetTypes.PATROL_SMALL; 108 109 110 float combat = 1; 111 for (int i = 0; i < 3; i++) { 112 if ((float) Math.random() > 0.5f) { 113 combat++; 114 } 115 } 116 117 float desired = getDesiredNumFleetsForSpawnLocation(); 118 if (desired > 2) { 119 float timeFactor = (PirateBaseManager.getInstance().getDaysSinceStart() - 180f) / (365f * 2f); 120 if (timeFactor < 0) timeFactor = 0; 121 if (timeFactor > 1) timeFactor = 1; 122 123 combat += ((desired - 2) * (0.5f + (float) Math.random() * 0.5f)) * 1f * timeFactor; 124 //combat += (desired - 2) * (0.5f + (float) Math.random() * 0.5f); 125 } 126 127 combat *= 5f; 128 129 FleetParamsV3 params = new FleetParamsV3( 130 null, // source market 131 system.getLocation(), 132 Factions.LUDDIC_PATH, 133 null, 134 fleetType, 135 combat, // combatPts 136 0, // freighterPts 137 0, // tankerPts 138 0f, // transportPts 139 0f, // linerPts 140 0f, // utilityPts 141 0f // qualityMod 142 ); 143 params.ignoreMarketFleetSizeMult = true; 144 145 //params.random = random; 146 CampaignFleetAPI fleet = FleetFactoryV3.createFleet(params); 147 if (fleet == null || fleet.isEmpty()) return null; 148 149 // setting the below means: transponder off and more "go dark" use when traveling 150 //fleet.getMemoryWithoutUpdate().set(MemFlags.MEMORY_KEY_PIRATE, true); 151 152 fleet.getMemoryWithoutUpdate().set(MemFlags.FLEET_NO_MILITARY_RESPONSE, true); 153 154 float nf = getDesiredNumFleetsForSpawnLocation(); 155 156 if (nf == 1) { 157 setLocationAndOrders(fleet, 1f, 1f); 158 } else { 159 setLocationAndOrders(fleet, 0.5f, 1f); 160 } 161 162 return fleet; 163 } 164 165} 166 167 168 169 170 171 172 173