From 5e8da856e7587d9c086f4c0c54eb7f2b94d92364 Mon Sep 17 00:00:00 2001 From: Anuken Date: Tue, 17 Sep 2019 18:54:30 -0400 Subject: [PATCH] Conclusively fixed status effect null issue --- .../mindustry/content/StatusEffects.java | 1 + .../src/io/anuke/mindustry/core/Platform.java | 6 ++++++ .../anuke/mindustry/entities/EntityGroup.java | 11 ++++++++++ .../anuke/mindustry/entities/type/Unit.java | 20 ++++++++++++++----- .../mindustry/entities/units/Statuses.java | 9 ++------- .../io/anuke/mindustry/type/StatusEffect.java | 2 +- 6 files changed, 36 insertions(+), 13 deletions(-) diff --git a/core/src/io/anuke/mindustry/content/StatusEffects.java b/core/src/io/anuke/mindustry/content/StatusEffects.java index cb4035dd0e..fb94a881ce 100644 --- a/core/src/io/anuke/mindustry/content/StatusEffects.java +++ b/core/src/io/anuke/mindustry/content/StatusEffects.java @@ -46,6 +46,7 @@ public class StatusEffects implements ContentList{ if(unit.getTeam() == waveTeam){ Events.fire(Trigger.shock); } + result.set(this, time); })); opposite(() -> burning); }}; diff --git a/core/src/io/anuke/mindustry/core/Platform.java b/core/src/io/anuke/mindustry/core/Platform.java index 7ccb700499..29e5c0d5ea 100644 --- a/core/src/io/anuke/mindustry/core/Platform.java +++ b/core/src/io/anuke/mindustry/core/Platform.java @@ -2,6 +2,7 @@ package io.anuke.mindustry.core; import io.anuke.arc.*; import io.anuke.arc.Input.*; +import io.anuke.arc.collection.*; import io.anuke.arc.files.*; import io.anuke.arc.function.*; import io.anuke.arc.math.*; @@ -25,6 +26,11 @@ public interface Platform{ /** Steam: Share a map on the workshop.*/ default void publishMap(Map map){} + /** Steam: Return external workshop maps to be loaded.*/ + default Array getExternalMaps(){ + return Array.with(); + } + /** Steam: Open workshop for maps.*/ default void openWorkshop(){} diff --git a/core/src/io/anuke/mindustry/entities/EntityGroup.java b/core/src/io/anuke/mindustry/entities/EntityGroup.java index ff48a1ad2e..07057d0436 100644 --- a/core/src/io/anuke/mindustry/entities/EntityGroup.java +++ b/core/src/io/anuke/mindustry/entities/EntityGroup.java @@ -18,6 +18,8 @@ public class EntityGroup{ private final Array entityArray = new Array<>(false, 32); private final Array entitiesToRemove = new Array<>(false, 32); private final Array entitiesToAdd = new Array<>(false, 32); + private final Array intersectArray = new Array<>(); + private final Rectangle intersectRect = new Rectangle(); private IntMap map; private QuadTree tree; private Consumer removeListener; @@ -161,6 +163,15 @@ public class EntityGroup{ tree().getIntersect(out, x, y, width, height); } + @SuppressWarnings("unchecked") + public Array intersect(float x, float y, float width, float height){ + intersectArray.clear(); + //don't waste time for empty groups + if(isEmpty()) return intersectArray; + tree().getIntersect(intersectArray, intersectRect.set(x, y, width, height)); + return intersectArray; + } + public QuadTree tree(){ if(!useTree) throw new RuntimeException("This group does not support quadtrees! Enable quadtrees when creating it."); return tree; diff --git a/core/src/io/anuke/mindustry/entities/type/Unit.java b/core/src/io/anuke/mindustry/entities/type/Unit.java index 3dfd2e0364..bbf3197621 100644 --- a/core/src/io/anuke/mindustry/entities/type/Unit.java +++ b/core/src/io/anuke/mindustry/entities/type/Unit.java @@ -2,6 +2,7 @@ package io.anuke.mindustry.entities.type; import io.anuke.annotations.Annotations.*; import io.anuke.arc.*; +import io.anuke.arc.collection.*; import io.anuke.arc.graphics.*; import io.anuke.arc.graphics.g2d.*; import io.anuke.arc.math.*; @@ -212,15 +213,24 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ float radScl = 1.5f; float fsize = getSize() / radScl; moveVector.setZero(); + float cx = x - fsize/2f, cy = y - fsize/2f; - Units.nearby(x - fsize/2f, y - fsize/2f, fsize, fsize, en -> { - if(en == this || en.isFlying() != isFlying()) return; + for(Team team : Team.all){ + avoid(unitGroups[team.ordinal()].intersect(cx, cy, fsize, fsize)); + } + + avoid(playerGroup.intersect(cx, cy, fsize, fsize)); + velocity.add(moveVector.x / mass() * Time.delta(), moveVector.y / mass() * Time.delta()); + } + + private void avoid(Array arr){ + float radScl = 1.5f; + + for(Unit en : arr){ float dst = dst(en); float scl = Mathf.clamp(1f - dst / (getSize()/(radScl*2f) + en.getSize()/(radScl*2f))); moveVector.add(Tmp.v1.set((x - en.x) * scl, (y - en.y) * scl).limit(0.4f)); - }); - - velocity.add(moveVector.x / mass() * Time.delta(), moveVector.y / mass() * Time.delta()); + } } public @Nullable TileEntity getClosestCore(){ diff --git a/core/src/io/anuke/mindustry/entities/units/Statuses.java b/core/src/io/anuke/mindustry/entities/units/Statuses.java index 7a92a2c128..b96937bfcb 100644 --- a/core/src/io/anuke/mindustry/entities/units/Statuses.java +++ b/core/src/io/anuke/mindustry/entities/units/Statuses.java @@ -32,16 +32,16 @@ public class Statuses implements Saveable{ if(statuses.size > 0){ //check for opposite effects for(StatusEntry entry : statuses){ - if(entry.effect == null) continue; //extend effect if(entry.effect == effect){ entry.time = Math.max(entry.time, duration); return; }else if(entry.effect.reactsWith(effect)){ //find opposite + globalResult.effect = entry.effect; entry.effect.getTransition(unit, effect, entry.time, duration, globalResult); entry.time = globalResult.time; - if(globalResult.effect != entry.effect && globalResult.effect != null){ + if(globalResult.effect != entry.effect){ entry.effect = globalResult.effect; } @@ -84,10 +84,6 @@ public class Statuses implements Saveable{ removals.clear(); for(StatusEntry entry : statuses){ - if(entry.effect == null){ - removals.add(entry); - continue; - } entry.time = Math.max(entry.time - Time.delta(), 0); applied.set(entry.effect.id); @@ -127,7 +123,6 @@ public class Statuses implements Saveable{ public void writeSave(DataOutput stream) throws IOException{ stream.writeByte(statuses.size); for(StatusEntry entry : statuses){ - stream.writeByte(entry.effect.id); stream.writeFloat(entry.time); } diff --git a/core/src/io/anuke/mindustry/type/StatusEffect.java b/core/src/io/anuke/mindustry/type/StatusEffect.java index 19b662d76c..ae74288758 100644 --- a/core/src/io/anuke/mindustry/type/StatusEffect.java +++ b/core/src/io/anuke/mindustry/type/StatusEffect.java @@ -5,7 +5,7 @@ import io.anuke.arc.collection.ObjectMap; import io.anuke.arc.function.Supplier; import io.anuke.arc.graphics.Color; import io.anuke.arc.math.Mathf; -import io.anuke.arc.util.Time; +import io.anuke.arc.util.*; import io.anuke.mindustry.content.Fx; import io.anuke.mindustry.entities.Effects; import io.anuke.mindustry.entities.Effects.Effect;