Wall-hugging ground patrol / Core storage changed to set

This commit is contained in:
Anuken
2018-09-26 10:23:06 -04:00
parent 51d619449b
commit c4e6af455d
6 changed files with 31 additions and 22 deletions

View File

@@ -6,6 +6,7 @@ import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.IntMap; import com.badlogic.gdx.utils.IntMap;
import com.badlogic.gdx.utils.ObjectSet;
import com.badlogic.gdx.utils.TimeUtils; import com.badlogic.gdx.utils.TimeUtils;
import io.anuke.annotations.Annotations.Loc; import io.anuke.annotations.Annotations.Loc;
import io.anuke.annotations.Annotations.Remote; import io.anuke.annotations.Annotations.Remote;
@@ -473,7 +474,7 @@ public class NetServer extends Module{
dataStream.writeFloat(state.wavetime); dataStream.writeFloat(state.wavetime);
dataStream.writeInt(state.wave); dataStream.writeInt(state.wave);
Array<Tile> cores = state.teams.get(player.getTeam()).cores; ObjectSet<Tile> cores = state.teams.get(player.getTeam()).cores;
dataStream.writeByte(cores.size); dataStream.writeByte(cores.size);

View File

@@ -167,9 +167,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
} }
} }
/** /**Only runs when the unit has a target.*/
* Only runs when the unit has a target.
*/
public void behavior(){ public void behavior(){
} }

View File

@@ -80,7 +80,7 @@ public abstract class GroundUnit extends BaseUnit{
public void update(){ public void update(){
target = getClosestCore(); target = getClosestCore();
if(target != null){ if(target != null){
//circle(60f + Mathf.absin(Timers.time() + id*23525, 70f, 1200f)); circle(60f + Mathf.absin(Timers.time() + id*23525, 70f, 1200f));
} }
} }
}, },
@@ -138,7 +138,7 @@ public abstract class GroundUnit extends BaseUnit{
public void update(){ public void update(){
super.update(); super.update();
if(!velocity.isZero(0.0001f) && (target == null || (distanceTo(target) > getWeapon().getAmmo().getRange()))){ if(!velocity.isZero(0.0001f) && (Units.invalidateTarget(target, this) || (distanceTo(target) > getWeapon().getAmmo().getRange()))){
rotation = Mathf.slerpDelta(rotation, velocity.angle(), 0.2f); rotation = Mathf.slerpDelta(rotation, velocity.angle(), 0.2f);
} }
} }
@@ -236,6 +236,20 @@ public abstract class GroundUnit extends BaseUnit{
super.readSave(stream); super.readSave(stream);
} }
protected void circle(float circleLength){
if(target == null) return;
vec.set(target.getX() - x, target.getY() - y);
if(vec.len() < circleLength){
vec.rotate((circleLength - vec.len()) / circleLength * 180f);
}
vec.setLength(type.speed * Timers.delta());
velocity.add(vec);
}
protected void moveToCore(){ protected void moveToCore(){
Tile tile = world.tileWorld(x, y); Tile tile = world.tileWorld(x, y);
if(tile == null) return; if(tile == null) return;

View File

@@ -1,10 +1,10 @@
package io.anuke.mindustry.game; package io.anuke.mindustry.game;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.ObjectSet;
import io.anuke.mindustry.Vars; import io.anuke.mindustry.Vars;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.util.EnumSet; import io.anuke.ucore.util.EnumSet;
import io.anuke.ucore.util.ThreadArray; import io.anuke.ucore.util.ThreadSet;
/** /**
* Class for various team-based utilities. * Class for various team-based utilities.
@@ -54,7 +54,7 @@ public class Teams{
} }
public class TeamData{ public class TeamData{
public final Array<Tile> cores = new ThreadArray<>(); public final ObjectSet<Tile> cores = new ThreadSet<>();
public final EnumSet<Team> enemies; public final EnumSet<Team> enemies;
public final Team team; public final Team team;

View File

@@ -163,10 +163,8 @@ public class TutorialSector{
//world.tile(x + 1, y - 2).block().handleStack(Items.copper, 1, world.tile(x + 1, y - 2), null); //world.tile(x + 1, y - 2).block().handleStack(Items.copper, 1, world.tile(x + 1, y - 2), null);
//since placed() is not called here, add core manually //since placed() is not called here, add core manually
if(!state.teams.get(waveTeam).cores.contains(world.tile(x, y), true)){
state.teams.get(waveTeam).cores.add(world.tile(x, y)); state.teams.get(waveTeam).cores.add(world.tile(x, y));
} }
}
private static class MarkerBlockMission extends BlockLocMission{ private static class MarkerBlockMission extends BlockLocMission{
public MarkerBlockMission(Block block, int x, int y){ public MarkerBlockMission(Block block, int x, int y){

View File

@@ -83,10 +83,8 @@ public class CoreBlock extends StorageBlock{
@Override @Override
public void onProximityUpdate(Tile tile) { public void onProximityUpdate(Tile tile) {
//add cores //add cores
if(!state.teams.get(tile.getTeam()).cores.contains(tile, true)){
state.teams.get(tile.getTeam()).cores.add(tile); state.teams.get(tile.getTeam()).cores.add(tile);
} }
}
@Override @Override
public boolean canBreak(Tile tile){ public boolean canBreak(Tile tile){
@@ -95,7 +93,7 @@ public class CoreBlock extends StorageBlock{
@Override @Override
public void removed(Tile tile){ public void removed(Tile tile){
state.teams.get(tile.getTeam()).cores.removeValue(tile, true); state.teams.get(tile.getTeam()).cores.remove(tile);
} }
@Override @Override