From 832aac0e6e4903c040c6265b2413121c086fe9c5 Mon Sep 17 00:00:00 2001 From: Anuken Date: Wed, 7 Nov 2018 16:41:33 -0500 Subject: [PATCH] Fixed potential spawner issues --- core/src/io/anuke/mindustry/core/Renderer.java | 2 +- .../io/anuke/mindustry/entities/Player.java | 8 ++++---- core/src/io/anuke/mindustry/entities/Unit.java | 2 ++ .../mindustry/entities/units/BaseUnit.java | 18 +++++------------- 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/core/src/io/anuke/mindustry/core/Renderer.java b/core/src/io/anuke/mindustry/core/Renderer.java index b9e9ea9567..7931a10827 100644 --- a/core/src/io/anuke/mindustry/core/Renderer.java +++ b/core/src/io/anuke/mindustry/core/Renderer.java @@ -145,7 +145,7 @@ public class Renderer extends RendererModule{ if(players[0].isDead()){ TileEntity core = players[0].getClosestCore(); - if(core != null && players[0].spawner == -1){ + if(core != null && players[0].spawner == Unit.noSpawner){ smoothCamera(core.x, core.y, 0.08f); }else{ smoothCamera(position.x + 0.0001f, position.y + 0.0001f, 0.08f); diff --git a/core/src/io/anuke/mindustry/entities/Player.java b/core/src/io/anuke/mindustry/entities/Player.java index d4abe7e77d..38d4724446 100644 --- a/core/src/io/anuke/mindustry/entities/Player.java +++ b/core/src/io/anuke/mindustry/entities/Player.java @@ -60,7 +60,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra public boolean achievedFlight; public Color color = new Color(); public Mech mech; - public int spawner = -1; + public int spawner = noSpawner; public NetConnection con; public int playerIndex = 0; @@ -497,7 +497,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra updateRespawning(); return; }else{ - spawner = -1; + spawner = noSpawner; } avoidOthers(1f); @@ -787,7 +787,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra public void updateRespawning(){ - if(spawner != -1 && world.tile(spawner) != null && world.tile(spawner).entity instanceof SpawnerTrait){ + if(spawner != noSpawner && world.tile(spawner) != null && world.tile(spawner).entity instanceof SpawnerTrait){ ((SpawnerTrait) world.tile(spawner).entity).updateSpawning(this); }else{ CoreEntity entity = (CoreEntity) getClosestCore(); @@ -803,7 +803,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra } public void endRespawning(){ - spawner = -1; + spawner = noSpawner; } //endregion diff --git a/core/src/io/anuke/mindustry/entities/Unit.java b/core/src/io/anuke/mindustry/entities/Unit.java index 62e1d20232..9508693e30 100644 --- a/core/src/io/anuke/mindustry/entities/Unit.java +++ b/core/src/io/anuke/mindustry/entities/Unit.java @@ -12,6 +12,7 @@ import io.anuke.mindustry.net.Interpolator; import io.anuke.mindustry.net.Net; import io.anuke.mindustry.type.StatusEffect; import io.anuke.mindustry.type.Weapon; +import io.anuke.mindustry.world.Pos; import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.blocks.Floor; import io.anuke.ucore.core.Effects; @@ -39,6 +40,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ public static final float velocityPercision = 8f; /**Maximum absolute value of a velocity vector component.*/ public static final float maxAbsVelocity = 127f / velocityPercision; + public static final int noSpawner = Pos.get(-1, 1); private static final Rectangle queryRect = new Rectangle(); private static final Vector2 moveVector = new Vector2(); diff --git a/core/src/io/anuke/mindustry/entities/units/BaseUnit.java b/core/src/io/anuke/mindustry/entities/units/BaseUnit.java index 0c0ed161b6..74472c764a 100644 --- a/core/src/io/anuke/mindustry/entities/units/BaseUnit.java +++ b/core/src/io/anuke/mindustry/entities/units/BaseUnit.java @@ -55,7 +55,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{ protected boolean isWave; protected Squad squad; - protected int spawner = -1; + protected int spawner = noSpawner; /**internal constructor used for deserialization, DO NOT USE*/ public BaseUnit(){ @@ -114,18 +114,10 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{ return type; } - public Tile getSpawner(){ - return world.tile(spawner); - } - public void setSpawner(Tile tile){ this.spawner = tile.pos(); } - public void setIntSpawner(int pos){ - this.spawner = pos; - } - /**Sets this to a 'wave' unit, which means it has slightly different AI and will not run out of ammo.*/ public void setWave(){ isWave = true; @@ -146,7 +138,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{ } public void updateRespawning(){ - if(spawner == -1) return; + if(spawner == noSpawner) return; Tile tile = world.tile(spawner); if(tile != null && tile.entity != null){ @@ -154,7 +146,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{ ((SpawnerTrait) tile.entity).updateSpawning(this); } }else{ - spawner = -1; + spawner = noSpawner; } } @@ -308,7 +300,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{ avoidOthers(1.25f); - if(spawner != -1 && (world.tile(spawner) == null || world.tile(spawner).entity == null)){ + if(spawner != noSpawner && (world.tile(spawner) == null || world.tile(spawner).entity == null)){ damage(health); } @@ -341,7 +333,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{ @Override public void removed(){ - spawner = -1; + spawner = noSpawner; } @Override