Fixed potential spawner issues

This commit is contained in:
Anuken
2018-11-07 16:41:33 -05:00
parent 6967d4e762
commit 832aac0e6e
4 changed files with 12 additions and 18 deletions
@@ -145,7 +145,7 @@ public class Renderer extends RendererModule{
if(players[0].isDead()){ if(players[0].isDead()){
TileEntity core = players[0].getClosestCore(); 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); smoothCamera(core.x, core.y, 0.08f);
}else{ }else{
smoothCamera(position.x + 0.0001f, position.y + 0.0001f, 0.08f); smoothCamera(position.x + 0.0001f, position.y + 0.0001f, 0.08f);
@@ -60,7 +60,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
public boolean achievedFlight; public boolean achievedFlight;
public Color color = new Color(); public Color color = new Color();
public Mech mech; public Mech mech;
public int spawner = -1; public int spawner = noSpawner;
public NetConnection con; public NetConnection con;
public int playerIndex = 0; public int playerIndex = 0;
@@ -497,7 +497,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
updateRespawning(); updateRespawning();
return; return;
}else{ }else{
spawner = -1; spawner = noSpawner;
} }
avoidOthers(1f); avoidOthers(1f);
@@ -787,7 +787,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
public void updateRespawning(){ 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); ((SpawnerTrait) world.tile(spawner).entity).updateSpawning(this);
}else{ }else{
CoreEntity entity = (CoreEntity) getClosestCore(); CoreEntity entity = (CoreEntity) getClosestCore();
@@ -803,7 +803,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
} }
public void endRespawning(){ public void endRespawning(){
spawner = -1; spawner = noSpawner;
} }
//endregion //endregion
@@ -12,6 +12,7 @@ import io.anuke.mindustry.net.Interpolator;
import io.anuke.mindustry.net.Net; import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.type.StatusEffect; import io.anuke.mindustry.type.StatusEffect;
import io.anuke.mindustry.type.Weapon; import io.anuke.mindustry.type.Weapon;
import io.anuke.mindustry.world.Pos;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.Floor; import io.anuke.mindustry.world.blocks.Floor;
import io.anuke.ucore.core.Effects; 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; public static final float velocityPercision = 8f;
/**Maximum absolute value of a velocity vector component.*/ /**Maximum absolute value of a velocity vector component.*/
public static final float maxAbsVelocity = 127f / velocityPercision; 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 Rectangle queryRect = new Rectangle();
private static final Vector2 moveVector = new Vector2(); private static final Vector2 moveVector = new Vector2();
@@ -55,7 +55,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
protected boolean isWave; protected boolean isWave;
protected Squad squad; protected Squad squad;
protected int spawner = -1; protected int spawner = noSpawner;
/**internal constructor used for deserialization, DO NOT USE*/ /**internal constructor used for deserialization, DO NOT USE*/
public BaseUnit(){ public BaseUnit(){
@@ -114,18 +114,10 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
return type; return type;
} }
public Tile getSpawner(){
return world.tile(spawner);
}
public void setSpawner(Tile tile){ public void setSpawner(Tile tile){
this.spawner = tile.pos(); 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.*/ /**Sets this to a 'wave' unit, which means it has slightly different AI and will not run out of ammo.*/
public void setWave(){ public void setWave(){
isWave = true; isWave = true;
@@ -146,7 +138,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
} }
public void updateRespawning(){ public void updateRespawning(){
if(spawner == -1) return; if(spawner == noSpawner) return;
Tile tile = world.tile(spawner); Tile tile = world.tile(spawner);
if(tile != null && tile.entity != null){ if(tile != null && tile.entity != null){
@@ -154,7 +146,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
((SpawnerTrait) tile.entity).updateSpawning(this); ((SpawnerTrait) tile.entity).updateSpawning(this);
} }
}else{ }else{
spawner = -1; spawner = noSpawner;
} }
} }
@@ -308,7 +300,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
avoidOthers(1.25f); 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); damage(health);
} }
@@ -341,7 +333,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
@Override @Override
public void removed(){ public void removed(){
spawner = -1; spawner = noSpawner;
} }
@Override @Override