Starsector API
Loading...
Searching...
No Matches
GoDarkAbilityAI.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.abilities.ai;
2
3import org.lwjgl.util.vector.Vector2f;
4
5import com.fs.starfarer.api.campaign.CampaignFleetAPI;
6import com.fs.starfarer.api.campaign.ai.FleetAIFlags;
7import com.fs.starfarer.api.campaign.econ.MarketAPI;
8import com.fs.starfarer.api.campaign.rules.MemoryAPI;
9import com.fs.starfarer.api.impl.campaign.abilities.GoDarkAbility;
10import com.fs.starfarer.api.impl.campaign.events.BaseEventPlugin.MarketFilter;
11import com.fs.starfarer.api.impl.campaign.ids.MemFlags;
12import com.fs.starfarer.api.util.IntervalUtil;
13import com.fs.starfarer.api.util.Misc;
14
15public class GoDarkAbilityAI extends BaseAbilityAI {
16
17 private IntervalUtil interval = new IntervalUtil(0.05f, 0.15f);
18
19// public GoDarkAbilityAI(AbilityPlugin ability, ModularFleetAIAPI ai) {
20// super(ability, ai);
21// }
22
23 public void advance(float days) {
24 interval.advance(days * EmergencyBurnAbilityAI.AI_FREQUENCY_MULT);
25 if (!interval.intervalElapsed()) return;
26
27
28 MemoryAPI mem = fleet.getMemoryWithoutUpdate();
29
30
31 if (ability.isActiveOrInProgress()) {
32 mem.set(FleetAIFlags.HAS_SPEED_PENALTY, true, 0.2f);
33 mem.set(FleetAIFlags.HAS_LOWER_DETECTABILITY, true, 0.2f);
34 }
35
36 CampaignFleetAPI pursueTarget = mem.getFleet(FleetAIFlags.PURSUIT_TARGET);
37 CampaignFleetAPI fleeingFrom = mem.getFleet(FleetAIFlags.NEAREST_FLEEING_FROM);
38 Vector2f travelDest = mem.getVector2f(FleetAIFlags.TRAVEL_DEST);
39 boolean wantsTransponderOn = mem.getBoolean(FleetAIFlags.WANTS_TRANSPONDER_ON);
40
41// if (pursueTarget != null && pursueTarget.isPlayerFleet() && fleeingFrom != null) {
42// System.out.println("dfsdfwefwe");
43// }
44
45 // if being pursued
46 if (fleeingFrom != null) {
47 float dist = Misc.getDistance(fleet.getLocation(), fleeingFrom.getLocation()) - fleet.getRadius() - fleeingFrom.getRadius();
48 if (dist < 0) return;
49 float detRange = fleeingFrom.getMaxSensorRangeToDetect(fleet);
50 float ourSpeed = fleet.getFleetData().getBurnLevel();
51 float theirSpeed = fleeingFrom.getFleetData().getBurnLevel();
52 // slower than closest pursuer, but could hide using go dark: do it
53 if (!ability.isActiveOrInProgress()) {
54 if (dist > detRange * GoDarkAbility.DETECTABILITY_MULT + 100f && ourSpeed < theirSpeed &&
55 dist > detRange && dist < detRange + 300f) {
56 ability.activate();
57 }
58 } else { // already seen by them, or faster than them with "go dark" off
59 //if (dist < detRange || ourSpeed / GoDarkAbility.MAX_BURN_MULT > theirSpeed) {
60 // since going dark means "slow moving", ourSpeed doesn't actually include that, so it's still
61 // as if go dark was turned off
62 if (dist < detRange || ourSpeed > theirSpeed) {
63 ability.deactivate();
64 }
65 }
66 return;
67 }
68
69 // if wants to use transponder & not being pursued, don't do it
70 //if (wantsTransponderOn) {
71 if (fleet.isTransponderOn()) {
72 return;
73 }
74
75// if (pursueTarget != null && pursueTarget.isPlayerFleet()) {
76// System.out.println("dfsdfwefwe");
77// }
78
79 // if ok with using it, and not being pursued
80 // if pursuing, target can't see us, and we're gaining: leave on
81 // if pursuing, target can see us or we're losing groung: turn off
82 if (pursueTarget != null) {
83 float closingSpeed = Misc.getClosingSpeed(fleet.getLocation(), pursueTarget.getLocation(),
84 fleet.getVelocity(),pursueTarget.getVelocity());
85 if (closingSpeed <= 1 && ability.isActiveOrInProgress()) {
86 ability.deactivate();
87 }
88 return;
89 }
90
91 // is the destination nearby? turn on
92 boolean smuggler = mem.getBoolean(MemFlags.MEMORY_KEY_SMUGGLER);
93 boolean pirate = mem.getBoolean(MemFlags.MEMORY_KEY_PIRATE);
94 // don't use for general pirates; too grief-y
95 pirate = false;
96
97 boolean nearestMarketHostile = false;
98 MarketAPI nearestMarket = Misc.findNearestLocalMarket(fleet, 2000, new MarketFilter() {
99 public boolean acceptMarket(MarketAPI market) {
100 return true;
101 }
102 });
103 if (nearestMarket != null && nearestMarket.getFaction().isHostileTo(fleet.getFaction())) {
104 nearestMarketHostile = true;
105 }
106
107 if ((smuggler || pirate || nearestMarketHostile) && !ability.isActiveOrInProgress() && travelDest != null) {
108 float dist = Misc.getDistance(fleet.getLocation(), travelDest);
109 if (dist < 1500) {
110 ability.activate();
111 }
112 return;
113 }
114 }
115}
116
117
118
119
120
121