Starsector API
Loading...
Searching...
No Matches
GateHaulerEntityPlugin.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.entities;
2
3import java.awt.Color;
4
5import org.lwjgl.util.vector.Vector2f;
6
7import com.fs.starfarer.api.Global;
8import com.fs.starfarer.api.campaign.CampaignEngineLayers;
9import com.fs.starfarer.api.campaign.SectorEntityToken;
10import com.fs.starfarer.api.combat.ViewportAPI;
11import com.fs.starfarer.api.impl.campaign.BaseCustomEntityPlugin;
12import com.fs.starfarer.api.util.CampaignEngineGlowIndividualEngine;
13import com.fs.starfarer.api.util.CampaignEngineGlowUtil;
14import com.fs.starfarer.api.util.CampaignEntityMovementUtil;
15import com.fs.starfarer.api.util.Misc;
16
17public class GateHaulerEntityPlugin extends BaseCustomEntityPlugin { // implements EngineGlowControls {
18
19 public static float MAX_SPEED = 1000f;
20 public static float ACCELERATION = 5f;
21
22 protected CampaignEntityMovementUtil movement;
23 protected CampaignEngineGlowUtil engineGlow;
24 protected boolean longBurn = false;
25 //protected boolean acceleratedThisFrame = false;
26
27 public void init(SectorEntityToken entity, Object pluginParams) {
28 super.init(entity, pluginParams);
29 readResolve();
30 }
31
32 Object readResolve() {
33 if (engineGlow == null) {
34 Color fringe = new Color(255, 0, 0, 255);
35 Color flame = new Color(255, 100, 100, 255);
36 Color core = new Color(255, 255, 255, 255);
37
38 engineGlow = new CampaignEngineGlowUtil(entity, fringe, core, flame, 0.25f);
39 CampaignEngineGlowIndividualEngine engine = new CampaignEngineGlowIndividualEngine(
40 90f, 300f, 50f, 400f, new Vector2f(-115f, 0f), engineGlow);
41 engine.setFlameTexSpanMult(0.5f);
42 engineGlow.addEngine(engine);
43 }
44
45 if (movement == null) {
46 movement = new CampaignEntityMovementUtil(entity, 0.5f, 3f, ACCELERATION, MAX_SPEED);
47 movement.setEngineGlow(engineGlow);
48 }
49
50 return this;
51 }
52
53 public CampaignEntityMovementUtil getMovement() {
54 return movement;
55 }
56
57 public CampaignEngineGlowUtil getEngineGlow() {
58 return engineGlow;
59 }
60
61 public boolean isActivated() {
62 return entity.getMemoryWithoutUpdate().getBoolean("$activated");
63 }
64 public boolean isActivating() {
65 return entity.getMemoryWithoutUpdate().getBoolean("$activating");
66 }
67 public boolean isInTransit() {
68 return entity.getMemoryWithoutUpdate().getBoolean("$inTransit");
69 }
71 return entity.getMemoryWithoutUpdate().getExpire("$activating");
72 }
73
74 public void advance(float amount) {
75 if (entity.isInCurrentLocation() || isInTransit()) {
76 engineGlow.advance(amount);
77
78 float soundVolume = engineGlow.getLengthMult().getCurr() * 0.5f;
79 if (soundVolume > 0.5f) soundVolume = 0.5f;
80
81 if (isActivating()) {
82 // full time is 1 day, set in rules
83 float remaining = getRemainingActivationDays();
84 float f = remaining/1f;
85 if (f < 0f) f = 0f;
86 if (f > 1f) f = 1f;
87 engineGlow.getFlickerRateMult().shift(this, 1f + 25f * f, 0f, 0.1f, 1f);
88 engineGlow.getFlickerMult().shift(this, f, 0f, 0.1f, 1f);
89 } if (!isActivated()) {
90 engineGlow.showSuppressed();
91 } else if (isActivated()) {
92 if (longBurn && movement.isDesiredFacingSet()) {
93 float angleDiff = Misc.getAngleDiff(movement.getDesiredFacing(), entity.getFacing());
94 if (angleDiff < 2f) {
95 Vector2f dir = Misc.getUnitVectorAtDegreeAngle(movement.getDesiredFacing());
96 float speedInDesiredDir = Vector2f.dot(dir, entity.getVelocity());
97 if (movement.isFaceInOppositeDirection()) {
98 speedInDesiredDir *= -1f;
99 }
100 float speed = entity.getVelocity().length();
101
102 if (speedInDesiredDir > 10f && speedInDesiredDir > speed * 0.7f) {
103 float speedForMaxEngineLength = 100f;
104 float f = speedInDesiredDir / speedForMaxEngineLength;
105 if (f < 0f) f = 0f;
106 if (f > 1f) f = 1f;
107
108 soundVolume = Math.min(soundVolume + f * 0.5f, 1f);
109
110 //System.out.println("longBurn factor: " + f);
111
112 float flickerZone = 0.5f;
113 if (f < flickerZone) {
114 engineGlow.getFlickerRateMult().shift(this, 5f, 0f, 0.1f, 1f);
115 engineGlow.getFlickerMult().shift(this, 0.33f - 0.33f * f / flickerZone, 0f, 0.1f, 1f);
116 }
117
118 engineGlow.getGlowMult().shift(this, 2f, 1f, 1f, f);
119 engineGlow.getLengthMult().shift(this, 5f, 1f, 1f, f);
120 engineGlow.getWidthMult().shift(this, 3f, 1f, 1f, f);
121 }
122
123 }
124 }
125 }
126
127 if (soundVolume > 0) {
128 if (entity.isInCurrentLocation() && entity.isVisibleToPlayerFleet()) {
129 Global.getSoundPlayer().playLoop("gate_hauler_engine_loop", entity,
130 1f, soundVolume,
131 entity.getLocation(), entity.getVelocity());
132 }
133 }
134 }
135
136 if (isActivated()) {
137 movement.advance(amount);
138 }
139 }
140
141 public void render(CampaignEngineLayers layer, ViewportAPI viewport) {
142 float alphaMult = viewport.getAlphaMult();
143 alphaMult *= entity.getSensorFaderBrightness();
144 alphaMult *= entity.getSensorContactFaderBrightness();
145 if (alphaMult <= 0f) return;
146
147 engineGlow.render(alphaMult);
148 }
149
150 public float getRenderRange() {
151 return entity.getRadius() + 3000f; // for engine glow/trails
152 }
153
154 public boolean isLongBurn() {
155 return longBurn;
156 }
157
158 public void setLongBurn(boolean longBurn) {
159 this.longBurn = longBurn;
160 }
161
162// public void showAccelerating() {
163// engineGlow.showAccelerating();
164// acceleratedThisFrame = true;
165// }
166//
167// public void showIdling() {
168// engineGlow.showIdling();
169// }
170//
171// public void showSuppressed() {
172// engineGlow.showSuppressed();
173// }
174//
175// public void showOtherAction() {
176// engineGlow.showOtherAction();
177// }
178
179
180
181}
182
183
184
185
186
187
188
189
static SoundPlayerAPI getSoundPlayer()
Definition Global.java:43
void render(CampaignEngineLayers layer, ViewportAPI viewport)
void playLoop(String id, Object playingEntity, float pitch, float volume, Vector2f loc, Vector2f vel)