001package com.fs.starfarer.api.impl.campaign.fleets; 002 003import org.lwjgl.util.vector.Vector2f; 004 005import com.fs.starfarer.api.Global; 006import com.fs.starfarer.api.campaign.CampaignFleetAPI; 007import com.fs.starfarer.api.campaign.FleetAssignment; 008import com.fs.starfarer.api.campaign.LocationAPI; 009import com.fs.starfarer.api.campaign.SectorEntityToken; 010import com.fs.starfarer.api.campaign.StarSystemAPI; 011import com.fs.starfarer.api.campaign.econ.MarketAPI; 012import com.fs.starfarer.api.impl.campaign.ids.Factions; 013import com.fs.starfarer.api.impl.campaign.ids.FleetTypes; 014import com.fs.starfarer.api.impl.campaign.ids.Tags; 015import com.fs.starfarer.api.util.Misc; 016import com.fs.starfarer.api.util.WeightedRandomPicker; 017 018public class LuddicPathFleetManager extends BaseLimitedFleetManager { 019 020 @Override 021 protected int getMaxFleets() { 022 int count = 0; 023 for (MarketAPI market : Global.getSector().getEconomy().getMarketsCopy()) { 024 String fid = market.getFactionId(); 025 if (fid.equals(Factions.LUDDIC_CHURCH) || 026 fid.equals(Factions.LUDDIC_PATH) || 027 fid.equals(Factions.KOL)) { 028 count += market.getSize(); 029 } 030 } 031 return count; 032 } 033 034 @Override 035 protected CampaignFleetAPI spawnFleet() { 036 StarSystemAPI target = pickTargetSystem(); 037 if (true) return null; 038 if (target == null) return null; 039 040 String fleetType = FleetTypes.PATROL_SMALL; 041 042 float combat = 1; 043 for (int i = 0; i < 3; i++) { 044 if ((float) Math.random() > 0.5f) { 045 combat++; 046 } 047 } 048 049 combat *= 5f; 050 051// CampaignFleetAPI fleet = FleetFactoryV2.createFleet(new FleetParams( 052// target.getLocation(), // location 053// null, // market 054// Factions.LUDDIC_CHURCH, // pick a luddic church market to spawn from 055// Factions.LUDDIC_PATH, // fleet's faction, if different from above, which is also used for source market picking 056// fleetType, 057// combat, // combatPts 058// 0, // freighterPts 059// 0, // tankerPts 060// 0f, // transportPts 061// 0f, // linerPts 062// 0f, // civilianPts 063// 0f, // utilityPts 064// 0f, // qualityBonus 065// -1f, // qualityOverride 066// 1f, // officer num mult 067// 0 // officer level bonus 068// )); 069// if (fleet == null) return null; 070 071 FleetParamsV3 params = new FleetParamsV3( 072 null, // source market 073 target.getLocation(), 074 Factions.LUDDIC_PATH, 075 null, 076 fleetType, 077 combat, // combatPts 078 0, // freighterPts 079 0, // tankerPts 080 0f, // transportPts 081 0f, // linerPts 082 0f, // utilityPts 083 0f // qualityMod 084 ); 085 //params.random = random; 086 CampaignFleetAPI fleet = FleetFactoryV3.createFleet(params); 087 if (fleet == null || fleet.isEmpty()) return null; 088 089 // setting the below means: transponder off and more "go dark" use when traveling 090 //fleet.getMemoryWithoutUpdate().set(MemFlags.MEMORY_KEY_PIRATE, true); 091 092 MarketAPI source = Misc.getSourceMarket(fleet); 093 if (source == null) return null; 094 095 CampaignFleetAPI player = Global.getSector().getPlayerFleet(); 096 boolean spawnAtSource = true; 097 if (player != null) { 098 float sourceToPlayer = Misc.getDistance(player.getLocation(), source.getLocationInHyperspace()); 099 float targetToPlayer = Misc.getDistance(player.getLocation(), target.getLocation()); 100 spawnAtSource = sourceToPlayer < targetToPlayer; 101 } 102 103 if (spawnAtSource) { 104 source.getPrimaryEntity().getContainingLocation().addEntity(fleet); 105 fleet.setLocation(source.getPrimaryEntity().getLocation().x, source.getPrimaryEntity().getLocation().y); 106 107 fleet.addAssignment(FleetAssignment.ORBIT_PASSIVE, source.getPrimaryEntity(), 2f + (float) Math.random() * 2f, 108 "orbiting " + source.getName()); 109 } else { 110 Vector2f loc = Misc.pickHyperLocationNotNearPlayer(target.getLocation(), Global.getSettings().getMaxSensorRangeHyper() + 500f); 111 Global.getSector().getHyperspace().addEntity(fleet); 112 fleet.setLocation(loc.x, loc.y); 113 } 114 115 116 Vector2f dest = Misc.getPointAtRadius(target.getLocation(), 1500); 117 LocationAPI hyper = Global.getSector().getHyperspace(); 118 SectorEntityToken token = hyper.createToken(dest.x, dest.y); 119 120 fleet.addAssignment(FleetAssignment.GO_TO_LOCATION, token, 1000, 121 "traveling to the " + target.getBaseName() + " star system"); 122 123 if ((float) Math.random() > 0.75f) { 124 fleet.addAssignment(FleetAssignment.RAID_SYSTEM, target.getHyperspaceAnchor(), 20, 125 "raiding around the " + target.getBaseName() + " star system"); 126 } else { 127 fleet.addAssignment(FleetAssignment.RAID_SYSTEM, target.getCenter(), 20, 128 "raiding the " + target.getBaseName() + " star system"); 129 } 130 fleet.addAssignment(FleetAssignment.GO_TO_LOCATION, source.getPrimaryEntity(), 1000, 131 "returning to " + source.getName()); 132 fleet.addAssignment(FleetAssignment.ORBIT_PASSIVE, source.getPrimaryEntity(), 2f + 2f * (float) Math.random(), 133 "orbiting " + source.getName()); 134 135 return fleet; 136 } 137 138 139 protected StarSystemAPI pickTargetSystem() { 140 WeightedRandomPicker<StarSystemAPI> picker = new WeightedRandomPicker<StarSystemAPI>(); 141 for (StarSystemAPI system : Global.getSector().getStarSystems()) { 142 if (system.hasTag(Tags.SYSTEM_CUT_OFF_FROM_HYPER)) { 143 continue; 144 } 145 146 float mult = Misc.getSpawnChanceMult(system.getLocation()); 147 148 149 // want: large, unstable 150 float weight = 0f; 151 for (MarketAPI market : Misc.getMarketsInLocation(system)) { 152 if (market.getFactionId().equals(Factions.LUDDIC_CHURCH)) continue; 153 if (market.getFactionId().equals(Factions.LUDDIC_PATH)) continue; 154 if (market.getFactionId().equals(Factions.KOL)) continue; 155 156 float w = 11f - market.getStabilityValue() + market.getSize(); 157 if (w > weight) weight = w; 158 } 159 weight *= mult; 160 161 picker.add(system, weight); 162 //System.out.println("System: " + system.getBaseName() + ", weight: " + weight); 163 } 164 return picker.pick(); 165 } 166 167 168} 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183