Starsector API
Loading...
Searching...
No Matches
SustainedBurnAbilityAI.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.Global;
6import com.fs.starfarer.api.campaign.CampaignFleetAPI;
7import com.fs.starfarer.api.campaign.FleetAssignment;
8import com.fs.starfarer.api.campaign.SectorEntityToken;
9import com.fs.starfarer.api.campaign.ai.FleetAIFlags;
10import com.fs.starfarer.api.campaign.ai.ModularFleetAIAPI;
11import com.fs.starfarer.api.campaign.rules.MemoryAPI;
12import com.fs.starfarer.api.impl.campaign.ids.MemFlags;
13import com.fs.starfarer.api.util.IntervalUtil;
14import com.fs.starfarer.api.util.Misc;
15
17
18 public static final float AI_FREQUENCY_MULT = 1f;
19
20 private IntervalUtil interval = new IntervalUtil(0.05f, 0.15f);
21
22// public EmergencyBurnAbilityAI(AbilityPlugin ability, ModularFleetAIAPI ai) {
23// super(ability, ai);
24// }
25
26 public void advance(float days) {
27 interval.advance(days * SustainedBurnAbilityAI.AI_FREQUENCY_MULT);
28 if (!interval.intervalElapsed()) return;
29
30 MemoryAPI mem = fleet.getMemoryWithoutUpdate();
31 if (ability.isActiveOrInProgress()) {
32 mem.set(FleetAIFlags.HAS_SPEED_BONUS, true, 0.2f);
33 mem.set(FleetAIFlags.HAS_HIGHER_DETECTABILITY, true, 0.2f);
34 }
35
36 boolean smuggler = mem.getBoolean(MemFlags.MEMORY_KEY_SMUGGLER);
37 if (smuggler) {
38 if (ability.isActive()) ability.deactivate();
39 return;
40 }
41
42
43 if (fleet.getAI() instanceof ModularFleetAIAPI) {
44 ModularFleetAIAPI ai = (ModularFleetAIAPI) fleet.getAI();
45 if (ai.getTacticalModule().isMaintainingContact()) {
46 if (ability.isActive()) ability.deactivate();
47 return;
48 }
49 }
50
51 if (mem.getBoolean(FleetAIFlags.HAS_LOWER_DETECTABILITY) && !ability.isActive()) {
52 return;
53 }
54
55// if (true) {
56// if (!ability.isActive()) {
57// ability.activate();
58// } else {
59// ability.deactivate();
60// }
61// return;
62// }
63// if (fleet.getAI() != null && fleet.getAI().getCurrentAssignmentType() == FleetAssignment.STANDING_DOWN) {
64// return;
65// }
66
67 CampaignFleetAPI pursueTarget = mem.getFleet(FleetAIFlags.PURSUIT_TARGET);
68 CampaignFleetAPI fleeingFrom = mem.getFleet(FleetAIFlags.NEAREST_FLEEING_FROM);
69
70// float moveDir = Misc.getDesiredMoveDir(fleet);
71
72 float burn = Misc.getBurnLevelForSpeed(fleet.getVelocity().length());
73// if (ability.isActive() && burn >= 5f) {
74// float diff = Misc.getAngleDiff(moveDir, Misc.getAngleInDegrees(fleet.getVelocity()));
75// if (diff > 90f) {
76// ability.deactivate();
77// return;
78// }
79// }
80
81
82 float activationTime = ability.getSpec().getActivationDays() * Global.getSector().getClock().getSecondsPerDay();
83 if (fleeingFrom != null) {
84 float dist = Misc.getDistance(fleet.getLocation(), fleeingFrom.getLocation());
85 float speed = Math.max(1f, fleeingFrom.getTravelSpeed());
86 float time = dist / speed;
87 if (!ability.isActive()) { // far enough to wind up and get away
88 if (time >= activationTime + 5f) {
89 ability.activate();
90 }
91 } else { // too close to wind up, better chance of getting away by turning SB off
92 if (burn <= 3 && time < 5f) {
93 ability.deactivate();
94 }
95 }
96 return;
97 }
98
99 if (pursueTarget != null) {
100// if (pursueTarget.isPlayerFleet()) {
101// System.out.println("fwefewwe");
102// }
103 if (ability.isActive()) {
104 float toTarget = Misc.getAngleInDegrees(fleet.getLocation(), pursueTarget.getLocation());
105 float velDir = Misc.getAngleInDegrees(fleet.getVelocity());
106 float diff = Misc.getAngleDiff(toTarget, velDir);
107 if (diff > 60f) {
108 ability.deactivate();
109 }
110 }
111 return;
112 }
113
114
115 if (fleet.getAI() != null && fleet.getAI().getCurrentAssignment() != null) {
116 FleetAssignment curr = fleet.getAI().getCurrentAssignmentType();
117 SectorEntityToken target = fleet.getAI().getCurrentAssignment().getTarget();
118 boolean inSameLocation = target != null && target.getContainingLocation() == fleet.getContainingLocation();
119 float distToTarget = 100000f;
120 if (inSameLocation) {
121 distToTarget = Misc.getDistance(target.getLocation(), fleet.getLocation());
122 }
123 boolean close = distToTarget < 2000;
124
125 if (close &&
126 (curr == FleetAssignment.ORBIT_PASSIVE ||
127 curr == FleetAssignment.ORBIT_AGGRESSIVE ||
128 curr == FleetAssignment.DELIVER_CREW ||
129 curr == FleetAssignment.DELIVER_FUEL ||
130 curr == FleetAssignment.DELIVER_MARINES ||
131 curr == FleetAssignment.DELIVER_PERSONNEL ||
132 curr == FleetAssignment.DELIVER_RESOURCES ||
133 curr == FleetAssignment.DELIVER_SUPPLIES ||
134 curr == FleetAssignment.RESUPPLY ||
135 curr == FleetAssignment.GO_TO_LOCATION ||
136 curr == FleetAssignment.GO_TO_LOCATION_AND_DESPAWN)
137 ) {
138 if (ability.isActive()) ability.deactivate();
139 return;
140 }
141 if (inSameLocation && (
142 curr == FleetAssignment.RAID_SYSTEM ||
143 curr == FleetAssignment.PATROL_SYSTEM)) {
144 if (ability.isActive()) ability.deactivate();
145 return;
146 }
147 }
148
149
150 Vector2f travelDest = mem.getVector2f(FleetAIFlags.TRAVEL_DEST);
151 if (travelDest != null) {
152 float dist = Misc.getDistance(fleet.getLocation(), travelDest);
153 float speed = Math.max(1f, fleet.getTravelSpeed());
154 float time = dist / speed;
155 if (!ability.isActive()) {
156 if (time > activationTime * 2f) {
157 ability.activate();
158 }
159 }
160 return;
161 }
162
163
164
165 }
166
167
168}
169
170
171
172
173
174
static SectorAPI getSector()
Definition Global.java:59