33 public static class ShieldPieceConnection {
34 public ShieldPiece from;
35 public ShieldPiece to;
36 public float baseLength = 0f;
38 public ShieldPieceConnection(ShieldPiece from, ShieldPiece to) {
41 baseLength = Misc.getDistance(from.offset, to.offset);
42 baseLength *= 0.9f + (float) Math.random() * 0.2f;
45 public void advance(
float amount) {
46 Vector2f fLoc = from.getAdjustedOffset();
47 Vector2f tLoc = to.getAdjustedOffset();
48 float length = Misc.getDistance(fLoc, tLoc);
49 float diff = length - baseLength;
52 float accel = diff * k;
54 Vector2f dir = Misc.getUnitVectorAtDegreeAngle(Misc.getAngleInDegrees(fLoc, tLoc));
56 dir.scale(accel * amount);
57 Vector2f.add(from.vel, dir, from.vel);
59 Vector2f.add(to.vel, dir, to.vel);
63 from.off.x += from.vel.x * amount;
64 from.off.y += from.vel.y * amount;
65 if (from.off.length() > maxOff) from.off.scale(maxOff / from.off.length());
67 to.off.x += to.vel.x * amount;
68 to.off.y += to.vel.y * amount;
69 if (to.off.length() > maxOff) to.off.scale(maxOff / to.off.length());
73 public static class ShieldPiece {
75 public Vector2f offset =
new Vector2f();
77 public Vector2f off =
new Vector2f();
78 public Vector2f vel =
new Vector2f();
80 public SpriteAPI sprite;
81 public boolean upsideDown =
false;
84 public Vector2f p1, p2, p3;
85 public float baseAlphaMult = 1f;
86 public float p1Alpha = 1f;
87 public float p2Alpha = 1f;
88 public float p3Alpha = 1f;
90 public FaderUtil fader;
91 public FlickerUtilV2 flicker;
93 public ShieldPiece(ShipAPI ship,
boolean upsideDown,
float x,
float y,
float side) {
97 this.upsideDown = upsideDown;
100 fader =
new FaderUtil(0f, 0.25f, 0.25f);
101 fader.setBrightness((
float) Math.random() * 1f);
102 fader.setBounce(
true,
true);
105 flicker =
new FlickerUtilV2();
114 float height = (float) (side * Math.sqrt(3f) / 2f);
116 p1 =
new Vector2f(x + height/2f, y);
117 p2 =
new Vector2f(x - height/2f - 1, y - side/2f);
118 p3 =
new Vector2f(x - height/2f - 1, y + side/2f);
120 p1 =
new Vector2f(x - height/2f, y);
121 p2 =
new Vector2f(x + height/2f, y - side/2f);
122 p3 =
new Vector2f(x + height/2f, y + side/2f);
127 public void updatePointAlpha() {
129 BoundsAPI bounds = ship.getExactBounds();
130 bounds.update(
new Vector2f(0, 0), 0f);
131 p1Alpha = getPointAlpha(p1);
132 p2Alpha = getPointAlpha(p2);
133 p3Alpha = getPointAlpha(p3);
135 baseAlphaMult = Math.max(p1Alpha, p2Alpha);
136 baseAlphaMult = Math.max(baseAlphaMult, p3Alpha);
141 public float getPointAlpha(Vector2f p) {
142 BoundsAPI bounds = ship.getExactBounds();
144 float minDist = Float.MAX_VALUE;
145 List<Vector2f> boundsPoints =
new ArrayList<Vector2f>();
146 for (SegmentAPI segment : bounds.getSegments()) {
147 Vector2f n = Misc.closestPointOnSegmentToPoint(segment.getP1(), segment.getP2(), p);
148 float dist = Misc.getDistance(n, p);
149 if (dist < minDist) minDist = dist;
151 boundsPoints.add(segment.getP1());
153 boundsPoints.add(bounds.getSegments().get(bounds.getSegments().size() - 1).getP2());
157 boolean inBounds = Misc.isPointInBounds(p, boundsPoints);
166 if (minDist > minAlphaAt) {
171 return Math.max(minAlpha, 1f - Math.min(1f, minDist / (minAlphaAt * 2f)));
176 public Vector2f getAdjustedOffset() {
177 return Vector2f.add(offset, off,
new Vector2f());
180 public Vector2f getCenter() {
181 Vector2f result =
new Vector2f(offset);
182 Misc.rotateAroundOrigin(result, ship.getFacing());
183 Vector2f.add(ship.getLocation(), result, result);
187 public void advance(
float amount) {
188 fader.advance(amount * (0.5f + 0.5f * (
float) Math.random()));
196 public void render(
float alphaMult) {
197 Color color =
new Color(255, 165, 100, 255);
198 color =
new Color(100, 165, 255, 255);
221 GL11.glTranslatef(off.x, off.y, 0f);
223 for (
int i = 0; i < 2; i++) {
224 GL11.glEnable(GL11.GL_TEXTURE_2D);
225 sprite.bindTexture();
226 GL11.glEnable(GL11.GL_BLEND);
227 GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
243 GL11.glBegin(GL11.GL_QUAD_STRIP);
245 Misc.setColor(color, alphaMult * p1Alpha * a);
246 GL11.glTexCoord2f(0f, 0f);
247 GL11.glVertex2f(p1.x, p1.y);
248 GL11.glTexCoord2f(0f, 1f);
249 GL11.glVertex2f(p1.x - t, p1.y);
251 Misc.setColor(color, alphaMult * p2Alpha * a);
252 GL11.glTexCoord2f(0f, 0f);
253 GL11.glVertex2f(p2.x, p2.y);
254 GL11.glTexCoord2f(0f, 1f);
255 GL11.glVertex2f(p2.x + t * 0.5f, p2.y + t);
257 Misc.setColor(color, alphaMult * p3Alpha * a);
258 GL11.glTexCoord2f(0f, 0f);
259 GL11.glVertex2f(p3.x, p3.y);
260 GL11.glTexCoord2f(0f, 1f);
261 GL11.glVertex2f(p3.x + t * 0.5f, p3.y - t);
263 Misc.setColor(color, alphaMult * p1Alpha * a);
264 GL11.glTexCoord2f(0f, 0f);
265 GL11.glVertex2f(p1.x, p1.y);
266 GL11.glTexCoord2f(0f, 1f);
267 GL11.glVertex2f(p1.x - t, p1.y);
271 GL11.glBegin(GL11.GL_QUAD_STRIP);
273 Misc.setColor(color, alphaMult * p1Alpha * a);
274 GL11.glTexCoord2f(0f, 0f);
275 GL11.glVertex2f(p1.x, p1.y);
276 GL11.glTexCoord2f(0f, 1f);
277 GL11.glVertex2f(p1.x + t, p1.y);
279 Misc.setColor(color, alphaMult * p2Alpha * a);
280 GL11.glTexCoord2f(0f, 0f);
281 GL11.glVertex2f(p2.x, p2.y);
282 GL11.glTexCoord2f(0f, 1f);
283 GL11.glVertex2f(p2.x - t * 0.5f, p2.y + t);
285 Misc.setColor(color, alphaMult * p3Alpha * a);
286 GL11.glTexCoord2f(0f, 0f);
287 GL11.glVertex2f(p3.x, p3.y);
288 GL11.glTexCoord2f(0f, 1f);
289 GL11.glVertex2f(p3.x - t * 0.5f, p3.y - t);
291 Misc.setColor(color, alphaMult * p1Alpha * a);
292 GL11.glTexCoord2f(0f, 0f);
293 GL11.glVertex2f(p1.x, p1.y);
294 GL11.glTexCoord2f(0f, 1f);
295 GL11.glVertex2f(p1.x + t, p1.y);
306 GL11.glDisable(GL11.GL_TEXTURE_2D);
307 GL11.glEnable(GL11.GL_BLEND);
308 GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
309 GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
316 alphaMult *= baseAlphaMult;
320 GL11.glBegin(GL11.GL_TRIANGLES);
328 Misc.setColor(color, alphaMult * p1Alpha);
329 GL11.glVertex2f(p1.x + i, p1.y + j);
330 Misc.setColor(color, alphaMult * p2Alpha);
331 GL11.glVertex2f(p2.x + i, p2.y + j);
332 Misc.setColor(color, alphaMult * p3Alpha);
333 GL11.glVertex2f(p3.x + i, p3.y + j);
362 public static class TriadShieldVisuals
extends BaseCombatLayeredRenderingPlugin {
364 public TriadShieldStatsBackup script;
365 public List<ShieldPiece> pieces =
new ArrayList<ShieldPiece>();
366 public List<ShieldPieceConnection> connections =
new ArrayList<ShieldPieceConnection>();
368 public TriadShieldVisuals(ShipAPI ship, TriadShieldStatsBackup script) {
370 this.script = script;
374 public void addShieldPieces() {
382 float height = (float) (side * Math.sqrt(3f) / 2f);
383 float centerFromBottom = (float) (Math.sin(Math.toRadians(30f)) * height);
385 int gridHeight = (int) (ship.getCollisionRadius() / side) * 2;
386 if (gridHeight / 2 != 0) gridHeight++;
387 if (gridHeight < 6) gridHeight = 6;
388 int gridWidth = (int) (ship.getCollisionRadius() / height) * 2;
389 if (gridWidth / 2 != 0) gridWidth++;
390 if (gridWidth < 6) gridWidth = 6;
391 for (
int i = -gridWidth/2; i < gridWidth/2; i++) {
392 for (
int j = -gridHeight/2; j < gridHeight/2; j++) {
393 float lowX = i * height + height/2f;
394 float highX = (i + 1) * height + height/2f;
395 float centerY = j * side + side/2f;
396 ShieldPiece piece =
new ShieldPiece(ship,
true, lowX + centerFromBottom, centerY, side - 2f);
397 if (piece.baseAlphaMult > 0) {
401 if (j != gridHeight/2 - 1) {
403 piece =
new ShieldPiece(ship,
false, highX - centerFromBottom, centerY, side - 2f);
404 if (piece.baseAlphaMult > 0) {
412 for (
int i = 0; i < pieces.size() - 1; i++) {
413 ShieldPiece curr = pieces.get(i);
414 for (
int j = i + 1; j < pieces.size(); j++) {
415 ShieldPiece other = pieces.get(j);
416 if (curr == other)
continue;
417 if (Misc.getDistance(curr.offset, other.offset) > maxDist)
continue;
419 ShieldPieceConnection conn =
new ShieldPieceConnection(curr, other);
420 connections.add(conn);
426 public EnumSet<CombatEngineLayers> getActiveLayers() {
427 return EnumSet.of(CombatEngineLayers.ABOVE_SHIPS_AND_MISSILES_LAYER);
430 public boolean isExpired() {
434 public float getRenderRadius() {
435 return ship.getCollisionRadius() + 100f;
439 public void advance(
float amount) {
440 entity.getLocation().set(ship.getLocation());
441 if (Global.getCombatEngine().isPaused())
return;
443 for (ShieldPiece piece : pieces) {
444 piece.advance(amount);
447 for (ShieldPieceConnection conn : connections) {
448 conn.advance(amount);
453 public void render(CombatEngineLayers layer, ViewportAPI viewport) {
454 float alphaMult = viewport.getAlphaMult();
456 ShipSystemAPI system = ship.getPhaseCloak();
457 if (system ==
null) system = ship.getSystem();
458 alphaMult *= system.getEffectLevel();
459 if (alphaMult <= 0f)
return;
462 GL11.glTranslatef(ship.getLocation().x, ship.getLocation().y, 0);
463 GL11.glRotatef(ship.getFacing(), 0, 0, 1);
465 for (ShieldPiece piece : pieces) {
466 piece.render(alphaMult);
501 public String
modifyDamageTaken(Object param, CombatEntityAPI target, DamageAPI damage, Vector2f point,
boolean shieldHit) {
505 public void apply(MutableShipStatsAPI stats, String
id, State state,
float effectLevel) {
507 boolean player =
false;
508 if (stats.getEntity() instanceof ShipAPI) {
509 ship = (ShipAPI) stats.getEntity();
511 id =
id +
"_" + ship.getId();
517 visuals =
new TriadShieldVisuals(ship,
this);
519 ship.addListener(
this);
528 if (state == State.COOLDOWN || state == State.IDLE) {
533 ShipSystemAPI system = ship.getPhaseCloak();
534 if (system ==
null) system = ship.getSystem();
537 if (state == State.IN || state == State.ACTIVE) {
539 }
else if (state == State.OUT) {
545 public void unapply(MutableShipStatsAPI stats, String
id) {
547 boolean player =
false;
548 if (stats.getEntity() instanceof ShipAPI) {
549 ship = (ShipAPI) stats.getEntity();
551 id =
id +
"_" + ship.getId();
559 public StatusData
getStatusData(
int index, State state,
float effectLevel) {