Starsector API
Loading...
Searching...
No Matches
GuideGhostCreator.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.ghosts.types;
2
3import java.util.ArrayList;
4import java.util.List;
5
6import com.fs.starfarer.api.Global;
7import com.fs.starfarer.api.campaign.CampaignFleetAPI;
8import com.fs.starfarer.api.campaign.LocationAPI;
9import com.fs.starfarer.api.campaign.SectorEntityToken;
10import com.fs.starfarer.api.campaign.StarSystemAPI;
11import com.fs.starfarer.api.impl.campaign.ghosts.BaseSensorGhostCreator;
12import com.fs.starfarer.api.impl.campaign.ghosts.GhostFrequencies;
13import com.fs.starfarer.api.impl.campaign.ghosts.SensorGhost;
14import com.fs.starfarer.api.impl.campaign.ghosts.SensorGhostManager;
15import com.fs.starfarer.api.impl.campaign.ids.Tags;
16import com.fs.starfarer.api.util.Misc;
17import com.fs.starfarer.api.util.WeightedRandomPicker;
18
20
21 public static float GUIDE_GHOST_RADIUS_LY = 5f;
22
23
24 @Override
25 public List<SensorGhost> createGhost(SensorGhostManager manager) {
26 if (!Global.getSector().getCurrentLocation().isHyperspace()) return null;
27 CampaignFleetAPI pf = Global.getSector().getPlayerFleet();
28
29 WeightedRandomPicker<SectorEntityToken> picker = new WeightedRandomPicker<SectorEntityToken>(manager.getRandom());
30
31 LocationAPI hyper = Global.getSector().getHyperspace();
32
33 for (SectorEntityToken curr : hyper.getEntitiesWithTag(Tags.NEUTRINO_HIGH)) {
34 if (curr.isPlayerFleet()) continue;
35 float distLY = Misc.getDistanceLY(curr.getLocation(), pf.getLocationInHyperspace());
36 if (distLY > GUIDE_GHOST_RADIUS_LY) continue;
37 picker.add(curr, 1f);
38 }
39
40 for (StarSystemAPI system : Global.getSector().getStarSystems()) {
41 float distLY = Misc.getDistanceLY(system.getLocation(), pf.getLocationInHyperspace());
42 if (distLY > GUIDE_GHOST_RADIUS_LY) continue;
43
44 float score = 0f;
45 for (SectorEntityToken curr : system.getEntitiesWithTag(Tags.NEUTRINO_HIGH)) {
46 if (curr.hasTag(Tags.OBJECTIVE)) continue;
47 if (score == 0) score = 1f;
48 score += score;
49 }
50
51 if (score > 0 && system.getHyperspaceAnchor() != null) {
52 picker.add(system.getHyperspaceAnchor(), score);
53 }
54 }
55
56 for (SectorEntityToken item : new ArrayList<SectorEntityToken>(picker.getItems())) {
57 if (Misc.crossesAnySlipstream(Global.getSector().getHyperspace(),
58 pf.getLocation(), item.getLocation())) {
59 picker.remove(item);
60 }
61 }
62
63
64 SectorEntityToken target = picker.pick();
65 if (target == null) return null;
66
67 List<SensorGhost> result = new ArrayList<SensorGhost>();
68 GuideGhost g = new GuideGhost(manager, target);
69 if (g.isCreationFailed()) return null;
70 result.add(g);
71 return result;
72 }
73
74
75 @Override
76 public float getFrequency(SensorGhostManager manager) {
77 return GhostFrequencies.getGuideFrequency(manager);
78 //return 10000f;
79 }
80
81}
static SectorAPI getSector()
Definition Global.java:59
static float getGuideFrequency(SensorGhostManager manager)
List< SensorGhost > createGhost(SensorGhostManager manager)