This commit is contained in:
Anuken
2019-01-04 15:27:39 -05:00
484 changed files with 10025 additions and 9800 deletions
@@ -1,11 +1,17 @@
package io.anuke.mindustry.entities;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import io.anuke.arc.entities.Effects;
import io.anuke.arc.entities.Effects.Effect;
import io.anuke.arc.function.Consumer;
import io.anuke.arc.function.Predicate;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.geom.Geometry;
import io.anuke.arc.math.geom.Rectangle;
import io.anuke.arc.math.geom.Vector2;
import io.anuke.arc.util.Time;
import io.anuke.mindustry.content.bullets.TurretBullets;
import io.anuke.mindustry.content.fx.ExplosionFx;
import io.anuke.mindustry.content.fx.Fx;
import io.anuke.mindustry.entities.bullet.Bullet;
import io.anuke.mindustry.entities.effect.Fire;
import io.anuke.mindustry.entities.effect.Lightning;
@@ -13,14 +19,6 @@ import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.gen.Call;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Effects.Effect;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.function.Consumer;
import io.anuke.ucore.function.Predicate;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Physics;
import io.anuke.ucore.util.Translator;
import static io.anuke.mindustry.Vars.*;
@@ -28,26 +26,26 @@ import static io.anuke.mindustry.Vars.*;
public class Damage{
private static Rectangle rect = new Rectangle();
private static Rectangle hitrect = new Rectangle();
private static Translator tr = new Translator();
private static Vector2 tr = new Vector2();
/**Creates a dynamic explosion based on specified parameters.*/
public static void dynamicExplosion(float x, float y, float flammability, float explosiveness, float power, float radius, Color color){
for(int i = 0; i < Mathf.clamp(power / 20, 0, 6); i++){
int branches = 5 + Mathf.clamp((int) (power / 30), 1, 20);
Timers.run(i * 2f + Mathf.random(4f), () -> Lightning.create(Team.none, Palette.power, 3,
Time.run(i * 2f + Mathf.random(4f), () -> Lightning.create(Team.none, Palette.power, 3,
x, y, Mathf.random(360f), branches + Mathf.range(2)));
}
for(int i = 0; i < Mathf.clamp(flammability / 4, 0, 30); i++){
Timers.run(i / 2f, () -> Call.createBullet(TurretBullets.fireball, x, y, Mathf.random(360f)));
Time.run(i / 2f, () -> Call.createBullet(TurretBullets.fireball, x, y, Mathf.random(360f)));
}
int waves = Mathf.clamp((int) (explosiveness / 4), 0, 30);
for(int i = 0; i < waves; i++){
int f = i;
Timers.run(i * 2f, () -> {
threads.run(() -> Damage.damage(x, y, Mathf.clamp(radius + explosiveness, 0, 50f) * ((f + 1f) / waves), explosiveness / 2f));
Time.run(i * 2f, () -> {
Damage.damage(x, y, Mathf.clamp(radius + explosiveness, 0, 50f) * ((f + 1f) / waves), explosiveness / 2f);
Effects.effect(ExplosionFx.blockExplosionSmoke, x + Mathf.range(radius), y + Mathf.range(radius));
});
}
@@ -119,7 +117,7 @@ public class Damage{
other.width += expand * 2;
other.height += expand * 2;
Vector2 vec = Physics.raycastRect(x, y, x2, y2, other);
Vector2 vec = Geometry.raycastRect(x, y, x2, y2, other);
if(vec != null){
Effects.effect(effect, vec.x, vec.y);
@@ -160,7 +158,7 @@ public class Damage{
/**Damages all entities and blocks in a radius that are enemies of the team.*/
public static void damage(Team team, float x, float y, float radius, float damage){
Consumer<Unit> cons = entity -> {
if(entity.team == team || entity.distanceTo(x, y) > radius){
if(entity.team == team || entity.dst(x, y) > radius){
return;
}
float amount = calculateDamage(x, y, entity.x, entity.y, radius, damage);
@@ -180,8 +178,8 @@ public class Damage{
int trad = (int) (radius / tilesize);
for(int dx = -trad; dx <= trad; dx++){
for(int dy = -trad; dy <= trad; dy++){
Tile tile = world.tile(Mathf.scl2(x, tilesize) + dx, Mathf.scl2(y, tilesize) + dy);
if(tile != null && tile.entity != null && (team == null || state.teams.areEnemies(team, tile.getTeam())) && Vector2.dst(dx, dy, 0, 0) <= trad){
Tile tile = world.tile(Math.round(x / tilesize) + dx, Math.round(y / tilesize) + dy);
if(tile != null && tile.entity != null && (team == null || state.teams.areEnemies(team, tile.getTeam())) && Mathf.dst(dx, dy, 0, 0) <= trad){
float amount = calculateDamage(x, y, tile.worldx(), tile.worldy(), radius, damage);
tile.entity.damage(amount);
}
@@ -191,7 +189,7 @@ public class Damage{
}
private static float calculateDamage(float x, float y, float tx, float ty, float radius, float damage){
float dist = Vector2.dst(x, y, tx, ty);
float dist = Mathf.dst(x, y, tx, ty);
float falloff = 0.4f;
float scaled = Mathf.lerp(1f - dist / radius, 1f, falloff);
return damage * scaled;
+109 -125
View File
@@ -1,13 +1,24 @@
package io.anuke.mindustry.entities;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Queue;
import io.anuke.annotations.Annotations.Loc;
import io.anuke.annotations.Annotations.Remote;
import io.anuke.arc.Core;
import io.anuke.arc.collection.Queue;
import io.anuke.arc.entities.Effects;
import io.anuke.arc.entities.EntityGroup;
import io.anuke.arc.entities.EntityQuery;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.*;
import io.anuke.arc.math.Angles;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.geom.Geometry;
import io.anuke.arc.math.geom.Rectangle;
import io.anuke.arc.math.geom.Vector2;
import io.anuke.arc.util.Align;
import io.anuke.arc.util.Interval;
import io.anuke.arc.util.Pack;
import io.anuke.arc.util.Time;
import io.anuke.arc.util.pooling.Pools;
import io.anuke.mindustry.content.Mechs;
import io.anuke.mindustry.content.fx.UnitFx;
import io.anuke.mindustry.entities.effect.ScorchDecal;
@@ -15,7 +26,7 @@ import io.anuke.mindustry.entities.traits.*;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.gen.Call;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.graphics.Trail;
import io.anuke.mindustry.input.Binding;
import io.anuke.mindustry.io.TypeIO;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.net.NetConnection;
@@ -24,13 +35,6 @@ import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.Floor;
import io.anuke.mindustry.world.blocks.storage.CoreBlock.CoreEntity;
import io.anuke.ucore.core.*;
import io.anuke.ucore.entities.EntityGroup;
import io.anuke.ucore.entities.EntityQuery;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Hue;
import io.anuke.ucore.graphics.Lines;
import io.anuke.ucore.util.*;
import java.io.DataInput;
import java.io.DataOutput;
@@ -63,7 +67,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
public NetConnection con;
public int playerIndex = 0;
public boolean isLocal = false;
public Timer timer = new Timer(4);
public Interval timer = new Interval(4);
public TargetTrait target;
public TargetTrait moveTarget;
@@ -71,8 +75,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
private Queue<BuildRequest> placeQueue = new Queue<>();
private Tile mining;
private CarriableTrait carrying;
private Trail trail = new Trail(12);
private Vector2 movement = new Translator();
private Vector2 movement = new Vector2();
private boolean moved;
//endregion
@@ -112,7 +115,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
}
@Override
public Timer getTimer(){
public Interval getTimer(){
return timer;
}
@@ -150,7 +153,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
}
if(interpolator.target.dst(interpolator.last) > 1f){
walktime += Timers.delta();
walktime += Time.delta();
}
}
@@ -282,18 +285,15 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
@Override
public void drawShadow(float offsetX, float offsetY){
float x = snappedX(), y = snappedY();
float scl = mech.flying ? 1f : boostHeat/2f;
float scl = mech.flying ? 1f : boostHeat / 2f;
Draw.rect(mech.iconRegion, x + offsetX*scl, y + offsetY*scl, rotation - 90);
Draw.rect(mech.iconRegion, x + offsetX * scl, y + offsetY * scl, rotation - 90);
}
@Override
public void draw(){
if(dead) return;
float x = snappedX(), y = snappedY();
if(!movement.isZero() && moved && !state.isPaused()){
walktime += movement.len() / 0.7f * getFloorOn().speedMultiplier;
baseRotation = Mathf.slerpDelta(baseRotation, movement.angle(), 0.13f);
@@ -317,9 +317,11 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
for(int i : Mathf.signs){
Draw.rect(mech.legRegion,
x + Angles.trnsx(baseRotation, ft * i + boostTrnsY, -boostTrnsX * i),
y + Angles.trnsy(baseRotation, ft * i + boostTrnsY, -boostTrnsX * i),
mech.legRegion.getRegionWidth() * i, mech.legRegion.getRegionHeight() - Mathf.clamp(ft * i, 0, 2), baseRotation - 90 + boostAng * i);
x + Angles.trnsx(baseRotation, ft * i + boostTrnsY, -boostTrnsX * i),
y + Angles.trnsy(baseRotation, ft * i + boostTrnsY, -boostTrnsX * i),
mech.legRegion.getWidth() * i * Draw.scl,
(mech.legRegion.getHeight() - Mathf.clamp(ft * i, 0, 2)) * Draw.scl,
baseRotation - 90 + boostAng * i);
}
Draw.rect(mech.baseRegion, x, y, baseRotation - 90);
@@ -337,10 +339,13 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
for(int i : Mathf.signs){
float tra = rotation - 90, trY = -mech.weapon.getRecoil(this, i > 0) + mech.weaponOffsetY;
float w = i > 0 ? -mech.weapon.equipRegion.getRegionWidth() : mech.weapon.equipRegion.getRegionWidth();
float w = i > 0 ? -mech.weapon.equipRegion.getWidth() : mech.weapon.equipRegion.getWidth();
Draw.rect(mech.weapon.equipRegion,
x + Angles.trnsx(tra, (mech.weaponOffsetX + mech.spreadX(this)) * i, trY),
y + Angles.trnsy(tra, (mech.weaponOffsetX + mech.spreadX(this)) * i, trY), w, mech.weapon.equipRegion.getRegionHeight(), rotation - 90);
x + Angles.trnsx(tra, (mech.weaponOffsetX + mech.spreadX(this)) * i, trY),
y + Angles.trnsy(tra, (mech.weaponOffsetX + mech.spreadX(this)) * i, trY),
w * Draw.scl,
mech.weapon.equipRegion.getHeight() * Draw.scl,
rotation - 90);
}
float backTrns = 4f, itemSize = 5f;
@@ -352,9 +357,9 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
float angT = i == 0 ? 0 : Mathf.randomSeedRange(i + 1, 60f);
float lenT = i == 0 ? 0 : Mathf.randomSeedRange(i + 2, 1f) - 1f;
Draw.rect(stack.item.region,
x + Angles.trnsx(rotation + 180f + angT, backTrns + lenT),
y + Angles.trnsy(rotation + 180f + angT, backTrns + lenT),
itemSize, itemSize, rotation);
x + Angles.trnsx(rotation + 180f + angT, backTrns + lenT),
y + Angles.trnsy(rotation + 180f + angT, backTrns + lenT),
itemSize, itemSize, rotation);
}
}
@@ -363,9 +368,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
@Override
public void drawStats(){
float x = snappedX(), y = snappedY();
Draw.color(Color.BLACK, team.color, healthf() + Mathf.absin(Timers.time(), healthf()*5f, 1f - healthf()));
Draw.color(Color.BLACK, team.color, healthf() + Mathf.absin(Time.time(), healthf() * 5f, 1f - healthf()));
Draw.alpha(hitTime / hitDuration);
Draw.rect(getPowerCellRegion(), x + Angles.trnsx(rotation, mech.cellTrnsY, 0f), y + Angles.trnsy(rotation, mech.cellTrnsY, 0f), rotation - 90);
Draw.color();
@@ -376,53 +379,38 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
if(dead) return;
drawBuilding(this);
if(mech.flying || boostHeat > 0.001f){
float wobblyness = 0.6f;
if(!state.isPaused()) trail.update(x + Angles.trnsx(rotation + 180f, 5f) + Mathf.range(wobblyness),
y + Angles.trnsy(rotation + 180f, 5f) + Mathf.range(wobblyness));
trail.draw(Hue.mix(mech.trailColor, mech.trailColorTo, mech.flying ? 0f : boostHeat, Tmp.c1), 5f * (isFlying() ? 1f : boostHeat));
}else{
trail.clear();
}
}
public float snappedX(){
return snapCamera && isLocal ? (int) (x + 0.0001f) : x;
}
public float snappedY(){
return snapCamera && isLocal ? (int) (y + 0.0001f) : y;
}
public void drawName(){
GlyphLayout layout = Pooling.obtain(GlyphLayout.class, GlyphLayout::new);
BitmapFont font = Core.scene.skin.getFont("default-font");
GlyphLayout layout = Pools.obtain(GlyphLayout.class, GlyphLayout::new);
boolean ints = Core.font.usesIntegerPositions();
Core.font.setUseIntegerPositions(false);
Draw.tscl(0.25f / io.anuke.ucore.scene.ui.layout.Unit.dp.scl(1f));
layout.setText(Core.font, name);
boolean ints = font.usesIntegerPositions();
font.setUseIntegerPositions(false);
font.getData().setScale(0.25f / io.anuke.arc.scene.ui.layout.Unit.dp.scl(1f));
layout.setText(font, name);
Draw.color(0f, 0f, 0f, 0.3f);
Draw.rect("blank", x, y + 8 - layout.height / 2, layout.width + 2, layout.height + 3);
Fill.rect(x, y + 8 - layout.height / 2, layout.width + 2, layout.height + 3);
Draw.color();
Draw.tcolor(color);
Draw.text(name, x, y + 8);
font.setColor(color);
font.draw(name, x, y + 8, 0, Align.center, false);
if(isAdmin){
float s = 3f;
Draw.color(color.r * 0.5f, color.g * 0.5f, color.b * 0.5f, 1f);
Draw.rect("icon-admin-small", x + layout.width / 2f + 2 + 1, y + 6.5f, s, s);
Draw.rect(Core.atlas.find("icon-admin-small"), x + layout.width / 2f + 2 + 1, y + 6.5f, s, s);
Draw.color(color);
Draw.rect("icon-admin-small", x + layout.width / 2f + 2 + 1, y + 7f, s, s);
Draw.rect(Core.atlas.find("icon-admin-small"), x + layout.width / 2f + 2 + 1, y + 7f, s, s);
}
Draw.reset();
Pooling.free(layout);
Draw.tscl(1f);
Core.font.setUseIntegerPositions(ints);
Pools.free(layout);
font.getData().setScale(1f);
font.setUseIntegerPositions(ints);
}
/**Draw all current build requests. Does not draw the beam effect, only the positions.*/
/** Draw all current build requests. Does not draw the beam effect, only the positions. */
public void drawBuildRequests(){
for(BuildRequest request : getPlaceQueue()){
if(getCurrentRequest() == request) continue;
@@ -431,42 +419,38 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
Block block = world.tile(request.x, request.y).target().block();
//draw removal request
Lines.stroke(2f);
Lines.stroke(2f, Palette.removeBack);
Draw.color(Palette.removeBack);
float rad = Mathf.absin(Timers.time(), 7f, 1f) + block.size * tilesize / 2f - 1;
float rad = Mathf.absin(Time.time(), 7f, 1f) + block.size * tilesize / 2f - 1;
Lines.square(
request.x * tilesize + block.offset(),
request.y * tilesize + block.offset() - 1,
rad);
request.x * tilesize + block.offset(),
request.y * tilesize + block.offset() - 1,
rad);
Draw.color(Palette.remove);
Lines.square(
request.x * tilesize + block.offset(),
request.y * tilesize + block.offset(),
rad);
request.x * tilesize + block.offset(),
request.y * tilesize + block.offset(),
rad);
}else{
//draw place request
Lines.stroke(2f);
Lines.stroke(2f, Palette.accentBack);
Draw.color(Palette.accentBack);
float rad = Mathf.absin(Timers.time(), 7f, 1f) - 2f + request.recipe.result.size * tilesize / 2f;
float rad = Mathf.absin(Time.time(), 7f, 1f) - 2f + request.recipe.result.size * tilesize / 2f;
Lines.square(
request.x * tilesize + request.recipe.result.offset(),
request.y * tilesize + request.recipe.result.offset() - 1,
rad);
request.x * tilesize + request.recipe.result.offset(),
request.y * tilesize + request.recipe.result.offset() - 1,
rad);
Draw.color(Palette.accent);
Lines.square(
request.x * tilesize + request.recipe.result.offset(),
request.y * tilesize + request.recipe.result.offset(),
rad);
request.x * tilesize + request.recipe.result.offset(),
request.y * tilesize + request.recipe.result.offset(),
rad);
}
}
@@ -479,7 +463,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
@Override
public void update(){
hitTime -= Timers.delta();
hitTime -= Time.delta();
if(Float.isNaN(x) || Float.isNaN(y)){
velocity.set(0f, 0f);
@@ -552,14 +536,14 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
updateBuilding(this);
x = Mathf.clamp(x, tilesize, world.width() * tilesize - tilesize);
y = Mathf.clamp(y, tilesize, world.height() * tilesize - tilesize);
x = Mathf.clamp(x, 0, world.width() * tilesize - tilesize);
y = Mathf.clamp(y, 0, world.height() * tilesize - tilesize);
}
protected void updateMech(){
Tile tile = world.tileWorld(x, y);
isBoosting = Inputs.keyDown("dash") && !mech.flying;
isBoosting = Core.input.keyDown(Binding.dash) && !mech.flying;
//if player is in solid block
if(tile != null && tile.solid()){
@@ -579,7 +563,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
}
//drop from carrier on key press
if(!ui.chatfrag.chatOpen() && Inputs.keyTap("drop_unit")){
if(!ui.chatfrag.chatOpen() && Core.input.keyTap(Binding.drop_unit)){
if(!mech.flying){
if(getCarrier() != null){
Call.dropSelf(this);
@@ -597,20 +581,19 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
movement.setZero();
String section = control.input(playerIndex).section;
float xa = Core.input.axis(Binding.move_x);
float ya = Core.input.axis(Binding.move_y);
if(!Core.input.keyDown(Binding.gridMode)){
movement.y += ya * speed;
movement.x += xa * speed;
}
float xa = Inputs.getAxis(section, "move_x");
float ya = Inputs.getAxis(section, "move_y");
movement.y += ya * speed;
movement.x += xa * speed;
Vector2 vec = Graphics.world(control.input(playerIndex).getMouseX(), control.input(playerIndex).getMouseY());
Vector2 vec = Core.input.mouseWorld(control.input(playerIndex).getMouseX(), control.input(playerIndex).getMouseY());
pointerX = vec.x;
pointerY = vec.y;
updateShooting();
movement.limit(speed).scl(Timers.delta());
movement.limit(speed).scl(Time.delta());
if(getCarrier() == null){
if(!ui.chatfrag.chatOpen()){
@@ -618,7 +601,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
}
float prex = x, prey = y;
updateVelocityStatus();
moved = distanceTo(prex, prey) > 0.001f;
moved = dst(prex, prey) > 0.001f;
}else{
velocity.setZero();
x = Mathf.lerpDelta(x, getCarrier().getX(), 0.1f);
@@ -646,7 +629,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
protected void updateFlying(){
if(Units.invalidateTarget(target, this) && !(target instanceof TileEntity && ((TileEntity) target).damaged() && target.getTeam() == team &&
mech.canHeal && distanceTo(target) < getWeapon().getAmmo().getRange())){
mech.canHeal && dst(target) < getWeapon().getAmmo().getRange())){
target = null;
}
@@ -663,7 +646,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
velocity.setAngle(Mathf.slerpDelta(velocity.angle(), angleTo(moveTarget), 0.1f));
}
if(distanceTo(moveTarget) < 2f){
if(dst(moveTarget) < 2f){
if(moveTarget instanceof CarriableTrait){
carry((CarriableTrait) moveTarget);
}else if(tapping){
@@ -686,7 +669,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
movement.set(targetX - x, targetY - y).limit(isBoosting && !mech.flying ? mech.boostSpeed : mech.speed);
movement.setAngle(Mathf.slerp(movement.angle(), velocity.angle(), 0.05f));
if(distanceTo(targetX, targetY) < attractDst){
if(dst(targetX, targetY) < attractDst){
movement.setZero();
}
@@ -695,27 +678,27 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
getHitbox(rect);
rect.x -= expansion;
rect.y -= expansion;
rect.width += expansion*2f;
rect.height += expansion*2f;
rect.width += expansion * 2f;
rect.height += expansion * 2f;
isBoosting = EntityQuery.collisions().overlapsTile(rect) || distanceTo(targetX, targetY) > 85f;
isBoosting = EntityQuery.collisions().overlapsTile(rect) || dst(targetX, targetY) > 85f;
velocity.add(movement.scl(Timers.delta()));
velocity.add(movement.scl(Time.delta()));
if(velocity.len() <= 0.2f && mech.flying){
rotation += Mathf.sin(Timers.time() + id * 99, 10f, 1f);
rotation += Mathf.sin(Time.time() + id * 99, 10f, 1f);
}else if(target == null){
rotation = Mathf.slerpDelta(rotation, velocity.angle(), velocity.len() / 10f);
}
float lx = x, ly = y;
updateVelocityStatus();
moved = distanceTo(lx, ly) > 0.001f && !isCarried();
moved = dst(lx, ly) > 0.001f && !isCarried();
if(mech.flying){
//hovering effect
x += Mathf.sin(Timers.time() + id * 999, 25f, 0.08f);
y += Mathf.cos(Timers.time() + id * 999, 25f, 0.08f);
x += Mathf.sin(Time.time() + id * 999, 25f, 0.08f);
y += Mathf.cos(Time.time() + id * 999, 25f, 0.08f);
}
//update shooting if not building, not mining and there's ammo left
@@ -725,15 +708,15 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
if(mobile){
if(target == null){
isShooting = false;
if(Settings.getBool("autotarget")){
if(Core.settings.getBool("autotarget")){
target = Units.getClosestTarget(team, x, y, getWeapon().getAmmo().getRange());
if(mech.canHeal && target == null){
target = Geometry.findClosest(x, y, world.indexer.getDamaged(Team.blue));
if(target != null && distanceTo(target) > getWeapon().getAmmo().getRange()){
if(target != null && dst(target) > getWeapon().getAmmo().getRange()){
target = null;
}else if(target != null){
target = ((Tile)target).entity;
target = ((Tile) target).entity;
}
}
@@ -742,14 +725,14 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
}
}
}else if(target.isValid() || (target instanceof TileEntity && ((TileEntity) target).damaged() && target.getTeam() == team &&
mech.canHeal && distanceTo(target) < getWeapon().getAmmo().getRange())){
mech.canHeal && dst(target) < getWeapon().getAmmo().getRange())){
//rotate toward and shoot the target
if(mech.turnCursor){
rotation = Mathf.slerpDelta(rotation, angleTo(target), 0.2f);
}
Vector2 intercept =
Predict.intercept(x, y, target.getX(), target.getY(), target.getVelocity().x - velocity.x, target.getVelocity().y - velocity.y, getWeapon().getAmmo().bullet.speed);
Predict.intercept(x, y, target.getX(), target.getY(), target.getVelocity().x - velocity.x, target.getVelocity().y - velocity.y, getWeapon().getAmmo().bullet.speed);
pointerX = intercept.x;
pointerY = intercept.y;
@@ -759,8 +742,8 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
}
}else if(isShooting()){
Vector2 vec = Graphics.world(control.input(playerIndex).getMouseX(),
control.input(playerIndex).getMouseY());
Vector2 vec = Core.input.mouseWorld(control.input(playerIndex).getMouseX(),
control.input(playerIndex).getMouseY());
pointerX = vec.x;
pointerY = vec.y;
@@ -773,7 +756,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
//region utility methods
/** Resets all values of the player.*/
/** Resets all values of the player. */
public void reset(){
resetNoAdd();
@@ -786,7 +769,8 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
inventory.clear();
placeQueue.clear();
dead = true;
trail.clear();
target = null;
moveTarget = null;
carrier = null;
health = maxHealth();
boostHeat = drownTime = hitTime = 0f;
@@ -869,7 +853,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
public void write(DataOutput buffer) throws IOException{
super.writeSave(buffer, !isLocal);
TypeIO.writeStringData(buffer, name); //TODO writing strings is very inefficient
buffer.writeByte(Bits.toByte(isAdmin) | (Bits.toByte(dead) << 1) | (Bits.toByte(isBoosting) << 2));
buffer.writeByte(Pack.byteValue(isAdmin) | (Pack.byteValue(dead) << 1) | (Pack.byteValue(isBoosting) << 2));
buffer.writeInt(Color.rgba8888(color));
buffer.writeByte(mech.id);
buffer.writeInt(mining == null ? -1 : mining.pos());
@@ -880,7 +864,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
}
@Override
public void read(DataInput buffer, long time) throws IOException{
public void read(DataInput buffer) throws IOException{
float lastx = x, lasty = y, lastrot = rotation;
super.readSave(buffer);
name = TypeIO.readStringData(buffer);
@@ -896,7 +880,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
readBuilding(buffer, !isLocal);
interpolator.read(lastx, lasty, x, y, time, rotation, baseRotation);
interpolator.read(lastx, lasty, x, y, rotation, baseRotation);
rotation = lastrot;
if(isLocal){
@@ -1,8 +1,8 @@
package io.anuke.mindustry.entities;
import com.badlogic.gdx.math.Vector2;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.geom.Vector2;
import io.anuke.mindustry.entities.traits.TargetTrait;
import io.anuke.ucore.util.Mathf;
/**
* Class for predicting shoot angles based on velocities of targets.
@@ -1,15 +1,14 @@
package io.anuke.mindustry.entities;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.utils.Array;
import io.anuke.arc.collection.Array;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.util.Time;
import io.anuke.arc.util.Tmp;
import io.anuke.arc.util.pooling.Pools;
import io.anuke.mindustry.content.StatusEffects;
import io.anuke.mindustry.entities.traits.Saveable;
import io.anuke.mindustry.type.ContentType;
import io.anuke.mindustry.type.StatusEffect;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.util.Pooling;
import io.anuke.ucore.util.ThreadArray;
import io.anuke.ucore.util.Tmp;
import java.io.DataInput;
import java.io.DataOutput;
@@ -21,9 +20,9 @@ import static io.anuke.mindustry.Vars.content;
*/
public class StatusController implements Saveable{
private static final StatusEntry globalResult = new StatusEntry();
private static final Array<StatusEntry> removals = new ThreadArray<>();
private static final Array<StatusEntry> removals = new Array<>();
private Array<StatusEntry> statuses = new ThreadArray<>();
private Array<StatusEntry> statuses = new Array<>();
private float speedMultiplier;
private float damageMultiplier;
@@ -57,7 +56,7 @@ public class StatusController implements Saveable{
}
//otherwise, no opposites found, add direct effect
StatusEntry entry = Pooling.obtain(StatusEntry.class, StatusEntry::new);
StatusEntry entry = Pools.obtain(StatusEntry.class, StatusEntry::new);
entry.set(effect, newTime);
statuses.add(entry);
}
@@ -88,10 +87,10 @@ public class StatusController implements Saveable{
removals.clear();
for(StatusEntry entry : statuses){
entry.time = Math.max(entry.time - Timers.delta(), 0);
entry.time = Math.max(entry.time - Time.delta(), 0);
if(entry.time <= 0){
Pooling.free(entry);
Pools.free(entry);
removals.add(entry);
}else{
speedMultiplier *= entry.effect.speedMultiplier;
@@ -137,7 +136,7 @@ public class StatusController implements Saveable{
@Override
public void readSave(DataInput stream) throws IOException{
for(StatusEntry effect : statuses){
Pooling.free(effect);
Pools.free(effect);
}
statuses.clear();
@@ -146,7 +145,7 @@ public class StatusController implements Saveable{
for(int i = 0; i < amount; i++){
byte id = stream.readByte();
float time = stream.readShort() / 2f;
StatusEntry entry = Pooling.obtain(StatusEntry.class, StatusEntry::new);
StatusEntry entry = Pools.obtain(StatusEntry.class, StatusEntry::new);
entry.set(content.getByID(ContentType.status, id), time);
statuses.add(entry);
}
@@ -1,11 +1,18 @@
package io.anuke.mindustry.entities;
import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.ObjectSet;
import io.anuke.annotations.Annotations.Loc;
import io.anuke.annotations.Annotations.Remote;
import io.anuke.arc.collection.Array;
import io.anuke.arc.collection.ObjectSet;
import io.anuke.arc.entities.Effects;
import io.anuke.arc.entities.EntityGroup;
import io.anuke.arc.entities.impl.BaseEntity;
import io.anuke.arc.entities.trait.HealthTrait;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.geom.Point2;
import io.anuke.arc.math.geom.Vector2;
import io.anuke.arc.util.Interval;
import io.anuke.arc.util.Time;
import io.anuke.mindustry.content.fx.Fx;
import io.anuke.mindustry.entities.bullet.Bullet;
import io.anuke.mindustry.entities.traits.TargetTrait;
@@ -20,13 +27,6 @@ import io.anuke.mindustry.world.modules.ConsumeModule;
import io.anuke.mindustry.world.modules.ItemModule;
import io.anuke.mindustry.world.modules.LiquidModule;
import io.anuke.mindustry.world.modules.PowerModule;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.EntityGroup;
import io.anuke.ucore.entities.impl.BaseEntity;
import io.anuke.ucore.entities.trait.HealthTrait;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Timer;
import java.io.DataInput;
import java.io.DataOutput;
@@ -42,7 +42,7 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
public static int sleepingEntities = 0;
public Tile tile;
public Timer timer;
public Interval timer;
public float health;
public float timeScale = 1f, timeScaleDuration;
@@ -78,7 +78,7 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
health = tile.block().health;
timer = new Timer(tile.block().timers);
timer = new Interval(tile.block().timers);
if(shouldAdd){
add();
@@ -89,12 +89,12 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
/**Scaled delta.*/
public float delta(){
return Timers.delta() * timeScale;
return Time.delta() * timeScale;
}
/**Call when nothing is happening to the entity. This increments the internal sleep timer.*/
public void sleep(){
sleepTime += Timers.delta();
sleepTime += Time.delta();
if(!sleeping && sleepTime >= timeToSleep){
remove();
sleeping = true;
@@ -169,8 +169,8 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
public void removeFromProximity(){
tile.block().onProximityRemoved(tile);
GridPoint2[] nearby = Edges.getEdges(tile.block().size);
for(GridPoint2 point : nearby){
Point2[] nearby = Edges.getEdges(tile.block().size);
for(Point2 point : nearby){
Tile other = world.tile(tile.x + point.x, tile.y + point.y);
//remove this tile from all nearby tile's proximities
if(other != null){
@@ -187,8 +187,8 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
tmpTiles.clear();
proximity.clear();
GridPoint2[] nearby = Edges.getEdges(tile.block().size);
for(GridPoint2 point : nearby){
Point2[] nearby = Edges.getEdges(tile.block().size);
for(Point2 point : nearby){
Tile other = world.tile(tile.x + point.x, tile.y + point.y);
if(other == null) continue;
@@ -258,19 +258,19 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
@Override
public Vector2 getVelocity(){
return Vector2.Zero;
return Vector2.ZERO;
}
@Override
public void update(){
//TODO better smoke effect, this one is awful
if(health != 0 && health < tile.block().health && !(tile.block() instanceof Wall) &&
Mathf.chance(0.009f * Timers.delta() * (1f - health / tile.block().health))){
Mathf.chance(0.009f * Time.delta() * (1f - health / tile.block().health))){
Effects.effect(Fx.smoke, x + Mathf.range(4), y + Mathf.range(4));
}
timeScaleDuration -= Timers.delta();
timeScaleDuration -= Time.delta();
if(timeScaleDuration <= 0f || !tile.block().canOverdrive){
timeScale = 1f;
}
+27 -26
View File
@@ -1,9 +1,20 @@
package io.anuke.mindustry.entities;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import io.anuke.arc.Core;
import io.anuke.arc.entities.Effects;
import io.anuke.arc.entities.impl.DestructibleEntity;
import io.anuke.arc.entities.trait.DamageTrait;
import io.anuke.arc.entities.trait.DrawTrait;
import io.anuke.arc.entities.trait.SolidTrait;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.g2d.Fill;
import io.anuke.arc.graphics.g2d.TextureRegion;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.geom.Geometry;
import io.anuke.arc.math.geom.Rectangle;
import io.anuke.arc.math.geom.Vector2;
import io.anuke.arc.util.Time;
import io.anuke.mindustry.content.blocks.Blocks;
import io.anuke.mindustry.entities.traits.*;
import io.anuke.mindustry.game.Team;
@@ -15,16 +26,6 @@ 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;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.impl.DestructibleEntity;
import io.anuke.ucore.entities.trait.DamageTrait;
import io.anuke.ucore.entities.trait.DrawTrait;
import io.anuke.ucore.entities.trait.SolidTrait;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Fill;
import io.anuke.ucore.util.Geometry;
import io.anuke.ucore.util.Mathf;
import java.io.DataInput;
import java.io.DataOutput;
@@ -194,7 +195,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
Units.getNearby(queryRect, t -> {
if(t == this || t.getCarrier() == this || getCarrier() == t || t.isFlying() != isFlying()) return;
float dst = distanceTo(t);
float dst = dst(t);
moveVector.set(x, y).sub(t.getX(), t.getY()).setLength(1f * (1f - (dst / queryRect.getWidth())));
applyImpulse(moveVector.x, moveVector.y);
});
@@ -235,11 +236,11 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
status.update(this);
velocity.limit(getMaxVelocity()).scl(1f + (status.getSpeedMultiplier()-1f) * Timers.delta());
velocity.limit(getMaxVelocity()).scl(1f + (status.getSpeedMultiplier()-1f) * Time.delta());
if(isFlying()){
x += velocity.x * Timers.delta();
y += velocity.y * Timers.delta();
x += velocity.x * Time.delta();
y += velocity.y * Time.delta();
}else{
boolean onLiquid = floor.isLiquid;
@@ -255,7 +256,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
}
}
if(onLiquid && velocity.len() > 0.4f && Mathf.chance((velocity.len() * floor.speedMultiplier) * 0.06f * Timers.delta())){
if(onLiquid && velocity.len() > 0.4f && Mathf.chance((velocity.len() * floor.speedMultiplier) * 0.06f * Time.delta())){
Effects.effect(floor.walkEffect, floor.liquidColor, x, y);
}
@@ -268,8 +269,8 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
}
if(onLiquid && floor.drownTime > 0){
drownTime += Timers.delta() * 1f / floor.drownTime;
if(Mathf.chance(Timers.delta() * 0.05f)){
drownTime += Time.delta() * 1f / floor.drownTime;
if(Mathf.chance(Time.delta() * 0.05f)){
Effects.effect(floor.drownUpdateEffect, floor.liquidColor, x, y);
}
}else{
@@ -283,12 +284,12 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
}
float px = x, py = y;
move(velocity.x * floor.speedMultiplier * Timers.delta(), velocity.y * floor.speedMultiplier * Timers.delta());
move(velocity.x * floor.speedMultiplier * Time.delta(), velocity.y * floor.speedMultiplier * Time.delta());
if(Math.abs(px - x) <= 0.0001f) velocity.x = 0f;
if(Math.abs(py - y) <= 0.0001f) velocity.y = 0f;
}
velocity.scl(Mathf.clamp(1f - getDrag() * (isFlying() ? 1f : floor.dragMultiplier) * Timers.delta()));
velocity.scl(Mathf.clamp(1f - getDrag() * (isFlying() ? 1f : floor.dragMultiplier) * Time.delta()));
}
public void applyEffect(StatusEffect effect, float intensity){
@@ -297,7 +298,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
}
public void damagePeriodic(float amount){
damage(amount * Timers.delta(), hitTime <= -20 + hitDuration);
damage(amount * Time.delta(), hitTime <= -20 + hitDuration);
}
public void damage(float amount, boolean withEffect){
@@ -317,14 +318,14 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
}
public void drawStats(){
Draw.color(Color.BLACK, team.color, healthf() + Mathf.absin(Timers.time(), healthf()*5f, 1f - healthf()));
Draw.color(Color.BLACK, team.color, healthf() + Mathf.absin(Time.time(), healthf()*5f, 1f - healthf()));
Draw.alpha(hitTime);
Draw.rect(getPowerCellRegion(), x, y, rotation - 90);
Draw.color();
}
public TextureRegion getPowerCellRegion(){
return Draw.region("power-cell");
return Core.atlas.find("power-cell");
}
public void drawAll(){
+13 -13
View File
@@ -1,18 +1,18 @@
package io.anuke.mindustry.entities;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import io.anuke.arc.collection.EnumSet;
import io.anuke.arc.entities.EntityGroup;
import io.anuke.arc.entities.EntityQuery;
import io.anuke.arc.function.Consumer;
import io.anuke.arc.function.Predicate;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.geom.Geometry;
import io.anuke.arc.math.geom.Rectangle;
import io.anuke.mindustry.entities.traits.TargetTrait;
import io.anuke.mindustry.entities.units.BaseUnit;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.entities.EntityGroup;
import io.anuke.ucore.entities.EntityQuery;
import io.anuke.ucore.function.Consumer;
import io.anuke.ucore.function.Predicate;
import io.anuke.ucore.util.EnumSet;
import io.anuke.ucore.util.Geometry;
import static io.anuke.mindustry.Vars.*;
@@ -38,7 +38,7 @@ public class Units{
* @return whether the target is invalid
*/
public static boolean invalidateTarget(TargetTrait target, Team team, float x, float y, float range){
return target == null || (range != Float.MAX_VALUE && target.distanceTo(x, y) > range) || target.getTeam() == team || !target.isValid();
return target == null || (range != Float.MAX_VALUE && target.dst(x, y) > range) || target.getTeam() == team || !target.isValid();
}
/**See {@link #invalidateTarget(TargetTrait, Team, float, float, float)}*/
@@ -165,7 +165,7 @@ public class Units{
if(e.isDead() || !predicate.test(e))
return;
float dist = Vector2.dst(e.x, e.y, x, y);
float dist = Mathf.dst(e.x, e.y, x, y);
if(dist < range){
if(result == null || dist < cdist){
result = e;
@@ -188,7 +188,7 @@ public class Units{
if(!predicate.test(e))
return;
float dist = Vector2.dst(e.x, e.y, x, y);
float dist = Mathf.dst(e.x, e.y, x, y);
if(dist < range){
if(result == null || dist < cdist){
result = e;
@@ -221,7 +221,7 @@ public class Units{
EntityGroup<BaseUnit> group = unitGroups[team.ordinal()];
if(!group.isEmpty()){
EntityQuery.getNearby(group, rect, entity -> {
if(entity.distanceTo(x, y) <= radius){
if(entity.dst(x, y) <= radius){
cons.accept((Unit) entity);
}
});
@@ -229,7 +229,7 @@ public class Units{
//now check all players
EntityQuery.getNearby(playerGroup, rect, player -> {
if(((Unit) player).team == team && player.distanceTo(x, y) <= radius){
if(((Unit) player).team == team && player.dst(x, y) <= radius){
cons.accept((Unit) player);
}
});
@@ -1,9 +1,9 @@
package io.anuke.mindustry.entities.bullet;
import io.anuke.mindustry.content.fx.BulletFx;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Effects.Effect;
import io.anuke.ucore.graphics.Draw;
import io.anuke.arc.entities.Effects;
import io.anuke.arc.entities.Effects.Effect;
import io.anuke.arc.graphics.g2d.Draw;
//TODO scale velocity depending on fslope()
public class ArtilleryBulletType extends BasicBulletType{
@@ -1,16 +1,17 @@
package io.anuke.mindustry.entities.bullet;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import io.anuke.arc.Core;
import io.anuke.arc.entities.Effects;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.g2d.TextureRegion;
import io.anuke.arc.math.Angles;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.util.Time;
import io.anuke.mindustry.entities.Damage;
import io.anuke.mindustry.entities.Units;
import io.anuke.mindustry.entities.traits.TargetTrait;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Mathf;
/**
* A BulletType for most ammo-based bullets shot from turrets and units.
@@ -47,8 +48,8 @@ public class BasicBulletType extends BulletType{
@Override
public void load(){
backRegion = Draw.region(bulletSprite + "-back");
frontRegion = Draw.region(bulletSprite);
backRegion = Core.atlas.find(bulletSprite + "-back");
frontRegion = Core.atlas.find(bulletSprite);
}
@Override
@@ -69,7 +70,7 @@ public class BasicBulletType extends BulletType{
if(homingPower > 0.0001f){
TargetTrait target = Units.getClosestTarget(b.getTeam(), b.x, b.y, homingRange);
if(target != null){
b.getVelocity().setAngle(Angles.moveToward(b.getVelocity().angle(), b.angleTo(target), homingPower * Timers.delta()));
b.getVelocity().setAngle(Angles.moveToward(b.getVelocity().angle(), b.angleTo(target), homingPower * Time.delta()));
}
}
}
@@ -1,8 +1,17 @@
package io.anuke.mindustry.entities.bullet;
import com.badlogic.gdx.math.Vector2;
import io.anuke.annotations.Annotations.Loc;
import io.anuke.annotations.Annotations.Remote;
import io.anuke.arc.entities.EntityGroup;
import io.anuke.arc.entities.impl.BulletEntity;
import io.anuke.arc.entities.trait.Entity;
import io.anuke.arc.entities.trait.SolidTrait;
import io.anuke.arc.entities.trait.VelocityTrait;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.geom.Vector2;
import io.anuke.arc.util.Interval;
import io.anuke.arc.util.Time;
import io.anuke.arc.util.pooling.Pools;
import io.anuke.mindustry.entities.Unit;
import io.anuke.mindustry.entities.effect.Lightning;
import io.anuke.mindustry.entities.traits.AbsorbTrait;
@@ -10,15 +19,6 @@ import io.anuke.mindustry.entities.traits.SyncTrait;
import io.anuke.mindustry.entities.traits.TeamTrait;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.EntityGroup;
import io.anuke.ucore.entities.impl.BulletEntity;
import io.anuke.ucore.entities.trait.Entity;
import io.anuke.ucore.entities.trait.SolidTrait;
import io.anuke.ucore.entities.trait.VelocityTrait;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Pooling;
import io.anuke.ucore.util.Timer;
import java.io.DataInput;
import java.io.DataOutput;
@@ -28,7 +28,7 @@ import static io.anuke.mindustry.Vars.*;
public class Bullet extends BulletEntity<BulletType> implements TeamTrait, SyncTrait, AbsorbTrait{
private static Vector2 vector = new Vector2();
public Timer timer = new Timer(3);
public Interval timer = new Interval(3);
private float lifeScl;
private Team team;
private Object data;
@@ -55,21 +55,21 @@ public class Bullet extends BulletEntity<BulletType> implements TeamTrait, SyncT
}
public static Bullet create(BulletType type, Entity owner, Team team, float x, float y, float angle, float velocityScl, float lifetimeScl, Object data){
Bullet bullet = Pooling.obtain(Bullet.class, Bullet::new);
Bullet bullet = Pools.obtain(Bullet.class, Bullet::new);
bullet.type = type;
bullet.owner = owner;
bullet.data = data;
bullet.velocity.set(0, type.speed).setAngle(angle).scl(velocityScl);
if(type.keepVelocity){
bullet.velocity.add(owner instanceof VelocityTrait ? ((VelocityTrait) owner).getVelocity() : Vector2.Zero);
bullet.velocity.add(owner instanceof VelocityTrait ? ((VelocityTrait) owner).getVelocity() : Vector2.ZERO);
}
bullet.team = team;
bullet.type = type;
bullet.lifeScl = lifetimeScl;
bullet.set(x - bullet.velocity.x * Timers.delta(), y - bullet.velocity.y * Timers.delta());
bullet.set(x - bullet.velocity.x * Time.delta(), y - bullet.velocity.y * Time.delta());
bullet.add();
return bullet;
@@ -158,7 +158,7 @@ public class Bullet extends BulletEntity<BulletType> implements TeamTrait, SyncT
}
@Override
public void read(DataInput data, long time) throws IOException{
public void read(DataInput data) throws IOException{
x = data.readFloat();
y = data.readFloat();
velocity.x = data.readFloat();
@@ -236,7 +236,7 @@ public class Bullet extends BulletEntity<BulletType> implements TeamTrait, SyncT
@Override
protected void updateLife(){
time += Timers.delta() * 1f/(lifeScl);
time += Time.delta() * 1f/(lifeScl);
time = Mathf.clamp(time, 0, type.lifetime());
if(time >= type.lifetime){
@@ -259,7 +259,7 @@ public class Bullet extends BulletEntity<BulletType> implements TeamTrait, SyncT
@Override
public void removed(){
Pooling.free(this);
Pools.free(this);
}
@Override
@@ -1,15 +1,15 @@
package io.anuke.mindustry.entities.bullet;
import io.anuke.arc.entities.Effects;
import io.anuke.arc.entities.Effects.Effect;
import io.anuke.arc.entities.impl.BaseBulletType;
import io.anuke.arc.math.geom.Vector2;
import io.anuke.mindustry.content.StatusEffects;
import io.anuke.mindustry.content.fx.BulletFx;
import io.anuke.mindustry.game.Content;
import io.anuke.mindustry.type.ContentType;
import io.anuke.mindustry.type.StatusEffect;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Effects.Effect;
import io.anuke.ucore.entities.impl.BaseBulletType;
import io.anuke.ucore.util.Translator;
public abstract class BulletType extends Content implements BaseBulletType<Bullet>{
public float lifetime;
@@ -45,7 +45,7 @@ public abstract class BulletType extends Content implements BaseBulletType<Bulle
/**Whether velocity is inherited from the shooter.*/
public boolean keepVelocity = true;
protected Translator vector = new Translator();
protected Vector2 vector = new Vector2();
public BulletType(float speed, float damage){
this.speed = speed;
@@ -1,9 +1,9 @@
package io.anuke.mindustry.entities.bullet;
import com.badlogic.gdx.math.Rectangle;
import io.anuke.arc.math.geom.Rectangle;
import io.anuke.mindustry.content.fx.BulletFx;
import io.anuke.mindustry.entities.Units;
import io.anuke.ucore.core.Timers;
import io.anuke.arc.util.Time;
public abstract class FlakBulletType extends BasicBulletType{
protected static Rectangle rect = new Rectangle();
@@ -27,9 +27,9 @@ public abstract class FlakBulletType extends BasicBulletType{
Units.getNearbyEnemies(b.getTeam(), rect.setSize(explodeRange*2f).setCenter(b.x, b.y), unit -> {
if(b.getData() instanceof Float) return;
if(unit.distanceTo(b) < explodeRange){
if(unit.dst(b) < explodeRange){
b.setData(0);
Timers.run(5f, () -> {
Time.run(5f, () -> {
if(b.getData() instanceof Integer){
b.time(b.lifetime());
}
@@ -1,18 +1,18 @@
package io.anuke.mindustry.entities.bullet;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.GridPoint2;
import io.anuke.arc.entities.Effects;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.g2d.Fill;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.geom.Geometry;
import io.anuke.arc.math.geom.Point2;
import io.anuke.mindustry.content.fx.BulletFx;
import io.anuke.mindustry.content.fx.Fx;
import io.anuke.mindustry.entities.effect.Fire;
import io.anuke.mindustry.entities.effect.Puddle;
import io.anuke.mindustry.type.Liquid;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Fill;
import io.anuke.ucore.util.Geometry;
import io.anuke.ucore.util.Mathf;
import static io.anuke.mindustry.Vars.tilesize;
import static io.anuke.mindustry.Vars.world;
@@ -60,7 +60,7 @@ public class LiquidBulletType extends BulletType{
if(liquid.temperature <= 0.5f && liquid.flammability < 0.3f){
float intensity = 400f;
Fire.extinguish(world.tileWorld(hitx, hity), intensity);
for(GridPoint2 p : Geometry.d4){
for(Point2 p : Geometry.d4){
Fire.extinguish(world.tileWorld(hitx + p.x * tilesize, hity + p.y * tilesize), intensity);
}
}
@@ -1,11 +1,11 @@
package io.anuke.mindustry.entities.bullet;
import com.badlogic.gdx.graphics.Color;
import io.anuke.arc.graphics.Color;
import io.anuke.mindustry.content.fx.BulletFx;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.util.Mathf;
import io.anuke.arc.entities.Effects;
import io.anuke.arc.util.Time;
import io.anuke.arc.math.Mathf;
public class MissileBulletType extends BasicBulletType{
protected Color trailColor = Palette.missileYellowBack;
@@ -21,7 +21,7 @@ public class MissileBulletType extends BasicBulletType{
public void update(Bullet b){
super.update(b);
if(Mathf.chance(Timers.delta() * 0.2)){
if(Mathf.chance(Time.delta() * 0.2)){
Effects.effect(BulletFx.missileTrail, trailColor, b.x, b.y, 2f);
}
}
@@ -1,12 +1,12 @@
package io.anuke.mindustry.entities.effect;
import com.badlogic.gdx.graphics.Color;
import io.anuke.arc.graphics.Color;
import io.anuke.mindustry.entities.traits.BelowLiquidTrait;
import io.anuke.ucore.entities.EntityGroup;
import io.anuke.ucore.entities.impl.TimedEntity;
import io.anuke.ucore.entities.trait.DrawTrait;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.util.Mathf;
import io.anuke.arc.entities.EntityGroup;
import io.anuke.arc.entities.impl.TimedEntity;
import io.anuke.arc.entities.trait.DrawTrait;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.math.Mathf;
import static io.anuke.mindustry.Vars.groundEffectGroup;
@@ -1,10 +1,18 @@
package io.anuke.mindustry.entities.effect;
import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.utils.IntMap;
import com.badlogic.gdx.utils.Pool.Poolable;
import io.anuke.annotations.Annotations.Loc;
import io.anuke.annotations.Annotations.Remote;
import io.anuke.arc.collection.IntMap;
import io.anuke.arc.entities.Effects;
import io.anuke.arc.entities.EntityGroup;
import io.anuke.arc.entities.impl.TimedEntity;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.geom.Geometry;
import io.anuke.arc.math.geom.Point2;
import io.anuke.arc.util.Structs;
import io.anuke.arc.util.Time;
import io.anuke.arc.util.pooling.Pool.Poolable;
import io.anuke.arc.util.pooling.Pools;
import io.anuke.mindustry.content.StatusEffects;
import io.anuke.mindustry.content.bullets.TurretBullets;
import io.anuke.mindustry.content.fx.EnvironmentFx;
@@ -16,14 +24,6 @@ import io.anuke.mindustry.gen.Call;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.EntityGroup;
import io.anuke.ucore.entities.impl.TimedEntity;
import io.anuke.ucore.util.Structs;
import io.anuke.ucore.util.Geometry;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Pooling;
import java.io.DataInput;
import java.io.DataOutput;
@@ -51,7 +51,7 @@ public class Fire extends TimedEntity implements SaveTrait, SyncTrait, Poolable{
Fire fire = map.get(tile.pos());
if(fire == null){
fire = Pooling.obtain(Fire.class, Fire::new);
fire = Pools.obtain(Fire.class, Fire::new);
fire.tile = tile;
fire.lifetime = baseLifetime;
fire.set(tile.worldx(), tile.worldy());
@@ -76,7 +76,7 @@ public class Fire extends TimedEntity implements SaveTrait, SyncTrait, Poolable{
*/
public static void extinguish(Tile tile, float intensity){
if(tile != null && map.containsKey(tile.pos())){
map.get(tile.pos()).time += intensity * Timers.delta();
map.get(tile.pos()).time += intensity * Time.delta();
}
}
@@ -92,11 +92,11 @@ public class Fire extends TimedEntity implements SaveTrait, SyncTrait, Poolable{
@Override
public void update(){
if(Mathf.chance(0.1 * Timers.delta())){
if(Mathf.chance(0.1 * Time.delta())){
Effects.effect(EnvironmentFx.fire, x + Mathf.range(4f), y + Mathf.range(4f));
}
if(Mathf.chance(0.05 * Timers.delta())){
if(Mathf.chance(0.05 * Time.delta())){
Effects.effect(EnvironmentFx.smoke, x + Mathf.range(4f), y + Mathf.range(4f));
}
@@ -104,7 +104,7 @@ public class Fire extends TimedEntity implements SaveTrait, SyncTrait, Poolable{
return;
}
time = Mathf.clamp(time + Timers.delta(), 0, lifetime());
time = Mathf.clamp(time + Time.delta(), 0, lifetime());
if(time >= lifetime() || tile == null){
Call.onFireRemoved(getID());
@@ -118,7 +118,7 @@ public class Fire extends TimedEntity implements SaveTrait, SyncTrait, Poolable{
float flammability = baseFlammability + puddleFlammability;
if(!damage && flammability <= 0){
time += Timers.delta() * 8;
time += Time.delta() * 8;
}
if(baseFlammability < 0 || block != tile.block()){
@@ -127,20 +127,20 @@ public class Fire extends TimedEntity implements SaveTrait, SyncTrait, Poolable{
}
if(damage){
lifetime += Mathf.clamp(flammability / 8f, 0f, 0.6f) * Timers.delta();
lifetime += Mathf.clamp(flammability / 8f, 0f, 0.6f) * Time.delta();
}
if(flammability > 1f && Mathf.chance(spreadChance * Timers.delta() * Mathf.clamp(flammability / 5f, 0.3f, 2f))){
GridPoint2 p = Mathf.select(Geometry.d4);
if(flammability > 1f && Mathf.chance(spreadChance * Time.delta() * Mathf.clamp(flammability / 5f, 0.3f, 2f))){
Point2 p = Geometry.d4[Mathf.random(3)];
Tile other = world.tile(tile.x + p.x, tile.y + p.y);
create(other);
if(Mathf.chance(fireballChance * Timers.delta() * Mathf.clamp(flammability / 10.0))){
if(Mathf.chance(fireballChance * Time.delta() * Mathf.clamp(flammability / 10f))){
Call.createBullet(TurretBullets.fireball, x, y, Mathf.random(360f));
}
}
if(Mathf.chance(0.1 * Timers.delta())){
if(Mathf.chance(0.1 * Time.delta())){
Puddle p = Puddle.getPuddle(tile);
if(p != null){
puddleFlammability = p.getFlammability() / 3f;
@@ -177,7 +177,7 @@ public class Fire extends TimedEntity implements SaveTrait, SyncTrait, Poolable{
}
@Override
public void read(DataInput data, long time) throws IOException{
public void read(DataInput data) throws IOException{
x = data.readFloat();
y = data.readFloat();
}
@@ -1,13 +1,13 @@
package io.anuke.mindustry.entities.effect;
import io.anuke.arc.entities.Effects;
import io.anuke.arc.entities.Effects.Effect;
import io.anuke.arc.entities.Effects.EffectRenderer;
import io.anuke.arc.entities.impl.EffectEntity;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.util.Time;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Effects.Effect;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.impl.EffectEntity;
import io.anuke.ucore.core.Effects.EffectRenderer;
import io.anuke.ucore.util.Mathf;
/**
* A ground effect contains an effect that is rendered on the ground layer as opposed to the top layer.
@@ -20,7 +20,7 @@ public class GroundEffectEntity extends EffectEntity{
GroundEffect effect = (GroundEffect) this.effect;
if(effect.isStatic){
time += Timers.delta();
time += Time.delta();
time = Mathf.clamp(time, 0, effect.staticLife);
@@ -1,26 +1,25 @@
package io.anuke.mindustry.entities.effect;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.math.Vector2;
import io.anuke.annotations.Annotations.Loc;
import io.anuke.annotations.Annotations.Remote;
import io.anuke.arc.entities.EntityGroup;
import io.anuke.arc.entities.impl.TimedEntity;
import io.anuke.arc.entities.trait.DrawTrait;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.g2d.Fill;
import io.anuke.arc.graphics.g2d.Lines;
import io.anuke.arc.math.Interpolation;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.geom.Position;
import io.anuke.arc.math.geom.Vector2;
import io.anuke.arc.util.Time;
import io.anuke.arc.util.pooling.Pools;
import io.anuke.mindustry.entities.Unit;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.EntityGroup;
import io.anuke.ucore.entities.impl.TimedEntity;
import io.anuke.ucore.entities.trait.DrawTrait;
import io.anuke.ucore.entities.trait.PosTrait;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Fill;
import io.anuke.ucore.graphics.Lines;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Pooling;
import static io.anuke.mindustry.Vars.effectGroup;
import static io.anuke.mindustry.Vars.threads;
public class ItemTransfer extends TimedEntity implements DrawTrait{
private Vector2 from = new Vector2();
@@ -28,7 +27,7 @@ public class ItemTransfer extends TimedEntity implements DrawTrait{
private Vector2 tovec = new Vector2();
private Item item;
private float seed;
private PosTrait to;
private Position to;
private Runnable done;
public ItemTransfer(){
@@ -51,14 +50,14 @@ public class ItemTransfer extends TimedEntity implements DrawTrait{
public static void transferItemTo(Item item, int amount, float x, float y, Tile tile){
if(tile == null || tile.entity == null || tile.entity.items == null) return;
for(int i = 0; i < Mathf.clamp(amount / 3, 1, 8); i++){
Timers.run(i * 3, () -> create(item, x, y, tile, () -> {
Time.run(i * 3, () -> create(item, x, y, tile, () -> {
}));
}
tile.entity.items.add(item, amount);
}
public static void create(Item item, float fromx, float fromy, PosTrait to, Runnable done){
ItemTransfer tr = Pooling.obtain(ItemTransfer.class, ItemTransfer::new);
public static void create(Item item, float fromx, float fromy, Position to, Runnable done){
ItemTransfer tr = Pools.obtain(ItemTransfer.class, ItemTransfer::new);
tr.item = item;
tr.from.set(fromx, fromy);
tr.to = to;
@@ -86,9 +85,9 @@ public class ItemTransfer extends TimedEntity implements DrawTrait{
@Override
public void removed(){
if(done != null){
threads.run(done);
done.run();
}
Pooling.free(this);
Pools.free(this);
}
@Override
@@ -108,8 +107,7 @@ public class ItemTransfer extends TimedEntity implements DrawTrait{
public void draw(){
float length = fslope() * 6f;
float angle = current.set(x, y).sub(from).angle();
Draw.color(Palette.accent);
Lines.stroke(fslope() * 2f);
Lines.stroke(fslope() * 2f, Palette.accent);
Lines.circle(x, y, fslope() * 2f);
Lines.lineAngleCenter(x, y, angle, length);
@@ -1,11 +1,24 @@
package io.anuke.mindustry.entities.effect;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.IntSet;
import io.anuke.annotations.Annotations.Loc;
import io.anuke.annotations.Annotations.Remote;
import io.anuke.arc.collection.Array;
import io.anuke.arc.collection.IntSet;
import io.anuke.arc.entities.EntityGroup;
import io.anuke.arc.entities.impl.TimedEntity;
import io.anuke.arc.entities.trait.DrawTrait;
import io.anuke.arc.entities.trait.TimeTrait;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.g2d.Lines;
import io.anuke.arc.math.Angles;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.RandomXS128;
import io.anuke.arc.math.geom.Geometry;
import io.anuke.arc.math.geom.Position;
import io.anuke.arc.math.geom.Rectangle;
import io.anuke.arc.math.geom.Vector2;
import io.anuke.arc.util.pooling.Pools;
import io.anuke.mindustry.content.bullets.TurretBullets;
import io.anuke.mindustry.entities.Unit;
import io.anuke.mindustry.entities.Units;
@@ -14,14 +27,6 @@ import io.anuke.mindustry.entities.traits.SyncTrait;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.gen.Call;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.ucore.entities.EntityGroup;
import io.anuke.ucore.entities.impl.TimedEntity;
import io.anuke.ucore.entities.trait.DrawTrait;
import io.anuke.ucore.entities.trait.PosTrait;
import io.anuke.ucore.entities.trait.TimeTrait;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Lines;
import io.anuke.ucore.util.*;
import java.io.DataInput;
import java.io.DataOutput;
@@ -31,7 +36,7 @@ import static io.anuke.mindustry.Vars.bulletGroup;
public class Lightning extends TimedEntity implements DrawTrait, SyncTrait, TimeTrait{
public static final float lifetime = 10f;
private static final SeedRandom random = new SeedRandom();
private static final RandomXS128 random = new RandomXS128();
private static final Rectangle rect = new Rectangle();
private static final Array<Unit> entities = new Array<>();
private static final IntSet hit = new IntSet();
@@ -39,7 +44,7 @@ public class Lightning extends TimedEntity implements DrawTrait, SyncTrait, Time
private static final float hitRange = 30f;
private static int lastSeed = 0;
private Array<PosTrait> lines = new Array<>();
private Array<Position> lines = new Array<>();
private Color color = Palette.lancerLaser;
/**For pooling use only. Do not call directly!*/
@@ -55,7 +60,7 @@ public class Lightning extends TimedEntity implements DrawTrait, SyncTrait, Time
@Remote(called = Loc.server)
public static void createLighting(int seed, Team team, Color color, float damage, float x, float y, float rotation, int length){
Lightning l = Pooling.obtain(Lightning.class, Lightning::new);
Lightning l = Pools.obtain(Lightning.class, Lightning::new);
Float dmg = damage;
l.x = x;
@@ -68,7 +73,7 @@ public class Lightning extends TimedEntity implements DrawTrait, SyncTrait, Time
for (int i = 0; i < length/2; i++) {
Bullet.create(TurretBullets.damageLightning, l, team, x, y, 0f, 1f, 1f, dmg);
l.lines.add(new Translator(x + Mathf.range(3f), y + Mathf.range(3f)));
l.lines.add(new Vector2(x + Mathf.range(3f), y + Mathf.range(3f)));
rect.setSize(hitRange).setCenter(x, y);
entities.clear();
@@ -103,7 +108,7 @@ public class Lightning extends TimedEntity implements DrawTrait, SyncTrait, Time
public void write(DataOutput data){}
@Override
public void read(DataInput data, long time){}
public void read(DataInput data){}
@Override
public float lifetime(){
@@ -120,15 +125,17 @@ public class Lightning extends TimedEntity implements DrawTrait, SyncTrait, Time
@Override
public void removed(){
super.removed();
Pooling.free(this);
Pools.free(this);
}
@Override
public void draw(){
float lx = x, ly = y;
Draw.color(color, Color.WHITE, fin());
//TODO this is really, really bad rendering
/*
for(int i = 0; i < lines.size; i++){
PosTrait v = lines.get(i);
Position v = lines.get(i);
float f = (float) i / lines.size;
@@ -143,11 +150,10 @@ public class Lightning extends TimedEntity implements DrawTrait, SyncTrait, Time
Lines.line(lx, ly, v.getX(), v.getY());
Lines.stroke(3f * fout() * (1f - f));
// Lines.lineAngleCenter(lx, ly, Angles.angle(lx, ly, v.getX(), v.getY()) + 90f, 20f);
lx = v.getX();
ly = v.getY();
}
}*/
Draw.color();
}
@@ -1,12 +1,23 @@
package io.anuke.mindustry.entities.effect;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.utils.IntMap;
import com.badlogic.gdx.utils.Pool.Poolable;
import io.anuke.annotations.Annotations.Loc;
import io.anuke.annotations.Annotations.Remote;
import io.anuke.arc.collection.IntMap;
import io.anuke.arc.entities.Effects;
import io.anuke.arc.entities.EntityGroup;
import io.anuke.arc.entities.impl.SolidEntity;
import io.anuke.arc.entities.trait.DrawTrait;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.g2d.Fill;
import io.anuke.arc.math.Angles;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.geom.Geometry;
import io.anuke.arc.math.geom.Point2;
import io.anuke.arc.math.geom.Rectangle;
import io.anuke.arc.util.Time;
import io.anuke.arc.util.pooling.Pool.Poolable;
import io.anuke.arc.util.pooling.Pools;
import io.anuke.mindustry.content.Liquids;
import io.anuke.mindustry.content.blocks.Blocks;
import io.anuke.mindustry.content.bullets.TurretBullets;
@@ -19,18 +30,6 @@ import io.anuke.mindustry.gen.Call;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.type.Liquid;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.EntityGroup;
import io.anuke.ucore.entities.impl.SolidEntity;
import io.anuke.ucore.entities.trait.DrawTrait;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Fill;
import io.anuke.ucore.graphics.Hue;
import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Geometry;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Pooling;
import java.io.DataInput;
import java.io.DataOutput;
@@ -85,10 +84,10 @@ public class Puddle extends SolidEntity implements SaveTrait, Poolable, DrawTrai
Puddle p = map.get(tile.pos());
if(generation == 0 && p != null && p.lastRipple <= Timers.time() - 40f){
if(generation == 0 && p != null && p.lastRipple <= Time.time() - 40f){
Effects.effect(BlockFx.ripple, tile.floor().liquidDrop.color,
(tile.worldx() + source.worldx()) / 2f, (tile.worldy() + source.worldy()) / 2f);
p.lastRipple = Timers.time();
p.lastRipple = Time.time();
}
return;
}
@@ -97,7 +96,7 @@ public class Puddle extends SolidEntity implements SaveTrait, Poolable, DrawTrai
if(p == null){
if(Net.client()) return; //not clientside.
Puddle puddle = Pooling.obtain(Puddle.class, Puddle::new);
Puddle puddle = Pools.obtain(Puddle.class, Puddle::new);
puddle.tile = tile;
puddle.liquid = liquid;
puddle.amount = amount;
@@ -108,9 +107,9 @@ public class Puddle extends SolidEntity implements SaveTrait, Poolable, DrawTrai
}else if(p.liquid == liquid){
p.accepting = Math.max(amount, p.accepting);
if(generation == 0 && p.lastRipple <= Timers.time() - 40f && p.amount >= maxLiquid / 2f){
if(generation == 0 && p.lastRipple <= Time.time() - 40f && p.amount >= maxLiquid / 2f){
Effects.effect(BlockFx.ripple, p.liquid.color, (tile.worldx() + source.worldx()) / 2f, (tile.worldy() + source.worldy()) / 2f);
p.lastRipple = Timers.time();
p.lastRipple = Time.time();
}
}else{
p.amount += reactPuddle(p.liquid, liquid, amount, p.tile, p.x, p.y);
@@ -176,14 +175,14 @@ public class Puddle extends SolidEntity implements SaveTrait, Poolable, DrawTrai
//update code
float addSpeed = accepting > 0 ? 3f : 0f;
amount -= Timers.delta() * (1f - liquid.viscosity) / (5f + addSpeed);
amount -= Time.delta() * (1f - liquid.viscosity) / (5f + addSpeed);
amount += accepting;
accepting = 0f;
if(amount >= maxLiquid / 1.5f && generation < maxGeneration){
float deposited = Math.min((amount - maxLiquid / 1.5f) / 4f, 0.3f) * Timers.delta();
for(GridPoint2 point : Geometry.d4){
float deposited = Math.min((amount - maxLiquid / 1.5f) / 4f, 0.3f) * Time.delta();
for(Point2 point : Geometry.d4){
Tile other = world.tile(tile.x + point.x, tile.y + point.y);
if(other != null && other.block() == Blocks.air && !other.hasCliffs()){
deposit(other, tile, liquid, deposited, generation + 1);
@@ -214,14 +213,14 @@ public class Puddle extends SolidEntity implements SaveTrait, Poolable, DrawTrai
}
});
if(liquid.temperature > 0.7f && tile.entity != null && Mathf.chance(0.3 * Timers.delta())){
if(liquid.temperature > 0.7f && tile.entity != null && Mathf.chance(0.3 * Time.delta())){
Fire.create(tile);
}
updateTime = 20f;
}
updateTime -= Timers.delta();
updateTime -= Time.delta();
}
@Override
@@ -232,11 +231,11 @@ public class Puddle extends SolidEntity implements SaveTrait, Poolable, DrawTrai
float smag = onLiquid ? 0.8f : 0f;
float sscl = 20f;
Draw.color(Hue.shift(tmp.set(liquid.color), 2, -0.05f));
Fill.circle(x + Mathf.sin(Timers.time() + seeds * 532, sscl, smag), y + Mathf.sin(Timers.time() + seeds * 53, sscl, smag), f * 8f);
Draw.color(tmp.set(liquid.color).shiftValue(-0.05f));
Fill.circle(x + Mathf.sin(Time.time() + seeds * 532, sscl, smag), y + Mathf.sin(Time.time() + seeds * 53, sscl, smag), f * 8f);
Angles.randLenVectors(id, 3, f * 6f, (ex, ey) -> {
Fill.circle(x + ex + Mathf.sin(Timers.time() + seeds * 532, sscl, smag),
y + ey + Mathf.sin(Timers.time() + seeds * 53, sscl, smag), f * 5f);
Fill.circle(x + ex + Mathf.sin(Time.time() + seeds * 532, sscl, smag),
y + ey + Mathf.sin(Time.time() + seeds * 53, sscl, smag), f * 5f);
seeds++;
});
Draw.color();
@@ -302,7 +301,7 @@ public class Puddle extends SolidEntity implements SaveTrait, Poolable, DrawTrai
}
@Override
public void read(DataInput data, long time) throws IOException{
public void read(DataInput data) throws IOException{
x = data.readFloat();
y = data.readFloat();
liquid = content.liquid(data.readByte());
@@ -1,7 +1,8 @@
package io.anuke.mindustry.entities.effect;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.util.Mathf;
import io.anuke.arc.Core;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.math.Mathf;
public class RubbleDecal extends Decal{
private int size;
@@ -20,7 +21,7 @@ public class RubbleDecal extends Decal{
public void drawDecal(){
String region = "rubble-" + size + "-" + Mathf.randomSeed(id, 0, 1);
if(!Draw.hasRegion(region)){
if(!Core.atlas.has(region)){
remove();
return;
}
@@ -1,10 +1,11 @@
package io.anuke.mindustry.entities.effect;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import io.anuke.arc.Core;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.g2d.TextureRegion;
import io.anuke.arc.math.Angles;
import io.anuke.arc.math.Mathf;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Mathf;
import static io.anuke.mindustry.Vars.world;
@@ -15,7 +16,7 @@ public class ScorchDecal extends Decal{
public static void create(float x, float y){
if(regions[0] == null){
for(int i = 0; i < regions.length; i++){
regions[i] = Draw.region("scorch" + (i + 1));
regions[i] = Core.atlas.find("scorch" + (i + 1));
}
}
@@ -35,7 +36,7 @@ public class ScorchDecal extends Decal{
TextureRegion region = regions[Mathf.randomSeed(id - i, 0, scorches - 1)];
float rotation = Mathf.randomSeed(id + i, 0, 360);
float space = 1.5f + Mathf.randomSeed(id + i + 1, 0, 20) / 10f;
Draw.grect(region, x + Angles.trnsx(rotation, space), y + Angles.trnsy(rotation, space), rotation - 90);
Draw.rect(region, x + Angles.trnsx(rotation, space), y + Angles.trnsy(rotation, space) + region.getHeight()/2f, region.getWidth()/2f, 0, rotation - 90);
}
}
}
@@ -1,7 +1,7 @@
package io.anuke.mindustry.entities.traits;
import io.anuke.ucore.entities.trait.DamageTrait;
import io.anuke.ucore.entities.trait.Entity;
import io.anuke.arc.entities.trait.DamageTrait;
import io.anuke.arc.entities.trait.Entity;
public interface AbsorbTrait extends Entity, TeamTrait, DamageTrait{
void absorb();
@@ -1,9 +1,19 @@
package io.anuke.mindustry.entities.traits;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Queue;
import io.anuke.arc.Core;
import io.anuke.arc.Events;
import io.anuke.arc.collection.Array;
import io.anuke.arc.collection.Queue;
import io.anuke.arc.entities.Effects;
import io.anuke.arc.entities.trait.Entity;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.g2d.Fill;
import io.anuke.arc.graphics.g2d.Lines;
import io.anuke.arc.math.Angles;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.geom.Vector2;
import io.anuke.arc.util.Time;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.content.blocks.Blocks;
import io.anuke.mindustry.content.fx.BlockFx;
@@ -13,6 +23,7 @@ import io.anuke.mindustry.entities.Unit;
import io.anuke.mindustry.game.EventType.BuildSelectEvent;
import io.anuke.mindustry.gen.Call;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.graphics.Shapes;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.type.Recipe;
@@ -21,16 +32,6 @@ import io.anuke.mindustry.world.Pos;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.BuildBlock;
import io.anuke.mindustry.world.blocks.BuildBlock.BuildEntity;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Events;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.trait.Entity;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Fill;
import io.anuke.ucore.graphics.Lines;
import io.anuke.ucore.graphics.Shapes;
import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Mathf;
import java.io.DataInput;
import java.io.DataOutput;
@@ -44,6 +45,7 @@ import static io.anuke.mindustry.Vars.*;
*/
public interface BuilderTrait extends Entity{
//these are not instance variables!
Vector2[] tmptr = new Vector2[]{new Vector2(), new Vector2(), new Vector2(), new Vector2()};
float placeDistance = 150f;
float mineDistance = 70f;
Array<BuildRequest> removal = new Array<>();
@@ -173,15 +175,19 @@ public interface BuilderTrait extends Entity{
default void updateBuilding(Unit unit){
//remove already completed build requests
removal.clear();
for(BuildRequest request : getPlaceQueue()){
if((request.breaking && world.tile(request.x, request.y).block() == Blocks.air) ||
(!request.breaking && world.tile(request.x, request.y).block() == request.recipe.result)){
removal.add(request);
}
for(BuildRequest req : getPlaceQueue()){
removal.add(req);
}
for(BuildRequest req : removal){
getPlaceQueue().removeValue(req, true);
getPlaceQueue().clear();
for(BuildRequest request : removal){
if(!((request.breaking && world.tile(request.x, request.y).block() == Blocks.air) ||
(!request.breaking &&
(world.tile(request.x, request.y).getRotation() == request.rotation || !request.recipe.result.rotate)
&& world.tile(request.x, request.y).block() == request.recipe.result))){
getPlaceQueue().addLast(request);
}
}
BuildRequest current = getCurrentRequest();
@@ -198,7 +204,7 @@ public interface BuilderTrait extends Entity{
Tile tile = world.tile(current.x, current.y);
if(unit.distanceTo(tile) > placeDistance){
if(unit.dst(tile) > placeDistance){
return;
}
@@ -228,7 +234,7 @@ public interface BuilderTrait extends Entity{
return;
}
if(unit.distanceTo(tile) <= placeDistance){
if(unit.dst(tile) <= placeDistance){
unit.rotation = Mathf.slerpDelta(unit.rotation, unit.angleTo(entity), 0.4f);
}
@@ -236,9 +242,9 @@ public interface BuilderTrait extends Entity{
if(!Net.client()){
//deconstructing is 2x as fast
if(current.breaking){
entity.deconstruct(unit, core, 2f / entity.buildCost * Timers.delta() * getBuildPower(tile));
entity.deconstruct(unit, core, 2f / entity.buildCost * Time.delta() * getBuildPower(tile));
}else{
entity.construct(unit, core, 1f / entity.buildCost * Timers.delta() * getBuildPower(tile));
entity.construct(unit, core, 1f / entity.buildCost * Time.delta() * getBuildPower(tile));
}
current.progress = entity.progress();
@@ -247,7 +253,7 @@ public interface BuilderTrait extends Entity{
}
if(!current.initialized){
Gdx.app.postRunnable(() -> Events.fire(new BuildSelectEvent(tile, unit.getTeam(), this, current.breaking)));
Core.app.post(() -> Events.fire(new BuildSelectEvent(tile, unit.getTeam(), this, current.breaking)));
current.initialized = true;
}
}
@@ -257,16 +263,16 @@ public interface BuilderTrait extends Entity{
Tile tile = getMineTile();
TileEntity core = unit.getClosestCore();
if(core == null || tile.block() != Blocks.air || unit.distanceTo(tile.worldx(), tile.worldy()) > mineDistance
if(core == null || tile.block() != Blocks.air || unit.dst(tile.worldx(), tile.worldy()) > mineDistance
|| tile.floor().drops == null || !unit.inventory.canAcceptItem(tile.floor().drops.item) || !canMine(tile.floor().drops.item)){
setMineTile(null);
}else{
Item item = tile.floor().drops.item;
unit.rotation = Mathf.slerpDelta(unit.rotation, unit.angleTo(tile.worldx(), tile.worldy()), 0.4f);
if(Mathf.chance(Timers.delta() * (0.06 - item.hardness * 0.01) * getMinePower())){
if(Mathf.chance(Time.delta() * (0.06 - item.hardness * 0.01) * getMinePower())){
if(unit.distanceTo(core) < mineTransferRange && core.tile.block().acceptStack(item, 1, core.tile, unit) == 1){
if(unit.dst(core) < mineTransferRange && core.tile.block().acceptStack(item, 1, core.tile, unit) == 1){
Call.transferItemTo(item, 1,
tile.worldx() + Mathf.range(tilesize / 2f),
tile.worldy() + Mathf.range(tilesize / 2f), core.tile);
@@ -278,7 +284,7 @@ public interface BuilderTrait extends Entity{
}
}
if(Mathf.chance(0.06 * Timers.delta())){
if(Mathf.chance(0.06 * Time.delta())){
Effects.effect(BlockFx.pulverizeSmall,
tile.worldx() + Mathf.range(tilesize / 2f),
tile.worldy() + Mathf.range(tilesize / 2f), 0f, item.color);
@@ -300,12 +306,12 @@ public interface BuilderTrait extends Entity{
Tile tile = world.tile(request.x, request.y);
if(unit.distanceTo(tile) > placeDistance){
if(unit.dst(tile) > placeDistance){
return;
}
Draw.color(Palette.accent);
float focusLen = 3.8f + Mathf.absin(Timers.time(), 1.1f, 0.6f);
Lines.stroke(1f, Palette.accent);
float focusLen = 3.8f + Mathf.absin(Time.time(), 1.1f, 0.6f);
float px = unit.x + Angles.trnsx(unit.rotation, focusLen);
float py = unit.y + Angles.trnsy(unit.rotation, focusLen);
@@ -318,7 +324,7 @@ public interface BuilderTrait extends Entity{
tmptr[3].set(tile.drawx() + sz, tile.drawy() + sz);
Arrays.sort(tmptr, (a, b) -> -Float.compare(Angles.angleDist(Angles.angle(unit.x, unit.y, a.x, a.y), ang),
Angles.angleDist(Angles.angle(unit.x, unit.y, b.x, b.y), ang)));
Angles.angleDist(Angles.angle(unit.x, unit.y, b.x, b.y), ang)));
float x1 = tmptr[0].x, y1 = tmptr[0].y,
x3 = tmptr[1].x, y3 = tmptr[1].y;
@@ -328,7 +334,7 @@ public interface BuilderTrait extends Entity{
Lines.line(px, py, x1, y1);
Lines.line(px, py, x3, y3);
Fill.circle(px, py, 1.6f + Mathf.absin(Timers.time(), 0.8f, 1.5f));
Fill.circle(px, py, 1.6f + Mathf.absin(Time.time(), 0.8f, 1.5f));
Draw.color();
}
@@ -339,22 +345,23 @@ public interface BuilderTrait extends Entity{
if(tile == null) return;
float focusLen = 4f + Mathf.absin(Timers.time(), 1.1f, 0.5f);
float focusLen = 4f + Mathf.absin(Time.time(), 1.1f, 0.5f);
float swingScl = 12f, swingMag = tilesize / 8f;
float flashScl = 0.3f;
float px = unit.x + Angles.trnsx(unit.rotation, focusLen);
float py = unit.y + Angles.trnsy(unit.rotation, focusLen);
float ex = tile.worldx() + Mathf.sin(Timers.time() + 48, swingScl, swingMag);
float ey = tile.worldy() + Mathf.sin(Timers.time() + 48, swingScl + 2f, swingMag);
float ex = tile.worldx() + Mathf.sin(Time.time() + 48, swingScl, swingMag);
float ey = tile.worldy() + Mathf.sin(Time.time() + 48, swingScl + 2f, swingMag);
Draw.color(Color.LIGHT_GRAY, Color.WHITE, 1f - flashScl + Mathf.absin(Time.time(), 0.5f, flashScl));
Draw.color(Color.LIGHT_GRAY, Color.WHITE, 1f - flashScl + Mathf.absin(Timers.time(), 0.5f, flashScl));
Shapes.laser("minelaser", "minelaser-end", px, py, ex, ey);
if(unit instanceof Player && ((Player) unit).isLocal){
Draw.color(Palette.accent);
Lines.poly(tile.worldx(), tile.worldy(), 4, tilesize / 2f * Mathf.sqrt2, Timers.time());
Lines.stroke(1f, Palette.accent);
Lines.poly(tile.worldx(), tile.worldy(), 4, tilesize / 2f * Mathf.sqrt2, Time.time());
}
Draw.color();
@@ -1,6 +1,6 @@
package io.anuke.mindustry.entities.traits;
import io.anuke.ucore.entities.trait.SolidTrait;
import io.anuke.arc.entities.trait.SolidTrait;
public interface CarriableTrait extends TeamTrait, TargetTrait, SolidTrait{
@@ -5,8 +5,8 @@ import io.anuke.annotations.Annotations.Remote;
import io.anuke.mindustry.content.fx.UnitFx;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.gen.Call;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.entities.trait.SolidTrait;
import io.anuke.arc.entities.Effects;
import io.anuke.arc.entities.trait.SolidTrait;
public interface CarryTrait extends TeamTrait, SolidTrait, TargetTrait{
@@ -1,6 +1,6 @@
package io.anuke.mindustry.entities.traits;
import io.anuke.ucore.entities.trait.Entity;
import io.anuke.arc.entities.trait.Entity;
/**
* Marks an entity as serializable.
@@ -1,12 +1,12 @@
package io.anuke.mindustry.entities.traits;
import io.anuke.arc.entities.trait.VelocityTrait;
import io.anuke.arc.util.Interval;
import io.anuke.mindustry.type.Weapon;
import io.anuke.ucore.entities.trait.VelocityTrait;
import io.anuke.ucore.util.Timer;
public interface ShooterTrait extends VelocityTrait, TeamTrait, InventoryTrait{
Timer getTimer();
Interval getTimer();
int getShootTimer(boolean left);
@@ -2,9 +2,9 @@ package io.anuke.mindustry.entities.traits;
import io.anuke.mindustry.core.NetClient;
import io.anuke.mindustry.net.Interpolator;
import io.anuke.ucore.core.Core;
import io.anuke.ucore.entities.trait.Entity;
import io.anuke.ucore.util.Tmp;
import io.anuke.arc.Core;
import io.anuke.arc.entities.trait.Entity;
import io.anuke.arc.util.Tmp;
import java.io.DataInput;
import java.io.DataOutput;
@@ -33,8 +33,7 @@ public interface SyncTrait extends Entity, TypeTrait{
if(isClipped()){
//move off screen when no longer in bounds
Tmp.r1.setSize(Core.camera.viewportWidth * Core.camera.zoom * NetClient.viewScale,
Core.camera.viewportHeight * Core.camera.zoom * NetClient.viewScale)
Tmp.r1.setSize(Core.camera.width * NetClient.viewScale, Core.camera.height * NetClient.viewScale)
.setCenter(Core.camera.position.x, Core.camera.position.y);
if(!Tmp.r1.contains(getX(), getY()) && !Tmp.r1.contains(getInterpolator().last.x, getInterpolator().last.y)){
@@ -67,5 +66,5 @@ public interface SyncTrait extends Entity, TypeTrait{
//Read and write sync data, usually position
void write(DataOutput data) throws IOException;
void read(DataInput data, long time) throws IOException;
void read(DataInput data) throws IOException;
}
@@ -1,14 +1,14 @@
package io.anuke.mindustry.entities.traits;
import io.anuke.arc.entities.trait.SolidTrait;
import io.anuke.arc.entities.trait.VelocityTrait;
import io.anuke.arc.math.geom.Position;
import io.anuke.mindustry.game.Team;
import io.anuke.ucore.entities.trait.PosTrait;
import io.anuke.ucore.entities.trait.SolidTrait;
import io.anuke.ucore.entities.trait.VelocityTrait;
/**
* Base interface for targetable entities.
*/
public interface TargetTrait extends PosTrait, VelocityTrait{
public interface TargetTrait extends Position, VelocityTrait{
boolean isDead();
@@ -1,7 +1,7 @@
package io.anuke.mindustry.entities.traits;
import io.anuke.mindustry.game.Team;
import io.anuke.ucore.entities.trait.Entity;
import io.anuke.arc.entities.trait.Entity;
public interface TeamTrait extends Entity{
Team getTeam();
@@ -1,8 +1,8 @@
package io.anuke.mindustry.entities.traits;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.ObjectIntMap;
import io.anuke.ucore.function.Supplier;
import io.anuke.arc.collection.Array;
import io.anuke.arc.collection.ObjectIntMap;
import io.anuke.arc.function.Supplier;
public interface TypeTrait{
int[] lastRegisteredID = {0};
@@ -1,9 +1,18 @@
package io.anuke.mindustry.entities.units;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Rectangle;
import io.anuke.annotations.Annotations.Loc;
import io.anuke.annotations.Annotations.Remote;
import io.anuke.arc.Core;
import io.anuke.arc.entities.Effects;
import io.anuke.arc.entities.EntityGroup;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.g2d.TextureRegion;
import io.anuke.arc.math.Angles;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.geom.Geometry;
import io.anuke.arc.math.geom.Rectangle;
import io.anuke.arc.util.Interval;
import io.anuke.arc.util.Time;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.content.fx.ExplosionFx;
import io.anuke.mindustry.entities.Damage;
@@ -24,11 +33,6 @@ import io.anuke.mindustry.type.Weapon;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.units.CommandCenter.CommandCenterEntity;
import io.anuke.mindustry.world.meta.BlockFlag;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.EntityGroup;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.util.*;
import java.io.DataInput;
import java.io.DataOutput;
@@ -46,7 +50,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
protected static final int timerShootRight = timerIndex++;
protected UnitType type;
protected Timer timer = new Timer(5);
protected Interval timer = new Interval(5);
protected StateMachine state = new StateMachine();
protected TargetTrait target;
@@ -77,7 +81,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
Effects.shake(2f, 2f, unit);
//must run afterwards so the unit's group is not null when sending the removal packet
threads.runDelay(unit::remove);
Core.app.post(unit::remove);
}
@Override
@@ -222,7 +226,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
}
@Override
public Timer getTimer(){
public Interval getTimer(){
return timer;
}
@@ -282,7 +286,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
@Override
public void update(){
hitTime -= Timers.delta();
hitTime -= Time.delta();
if(isDead()){
updateRespawning();
@@ -393,12 +397,12 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
}
@Override
public void read(DataInput data, long time) throws IOException{
public void read(DataInput data) throws IOException{
float lastx = x, lasty = y, lastrot = rotation;
super.readSave(data);
this.type = content.getByID(ContentType.unit, data.readByte());
interpolator.read(lastx, lasty, x, y, time, rotation);
interpolator.read(lastx, lasty, x, y, rotation);
rotation = lastrot;
}
@@ -1,26 +1,25 @@
package io.anuke.mindustry.entities.units;
import com.badlogic.gdx.math.Vector2;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.math.Angles;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.geom.Geometry;
import io.anuke.arc.math.geom.Vector2;
import io.anuke.arc.util.Time;
import io.anuke.mindustry.entities.Predict;
import io.anuke.mindustry.entities.Units;
import io.anuke.mindustry.entities.traits.CarriableTrait;
import io.anuke.mindustry.entities.traits.CarryTrait;
import io.anuke.mindustry.graphics.Trail;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.type.AmmoType;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.meta.BlockFlag;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.util.*;
import static io.anuke.mindustry.Vars.world;
public abstract class FlyingUnit extends BaseUnit implements CarryTrait{
protected static Translator vec = new Translator();
protected static float wobblyness = 0.6f;
protected static Vector2 vec = new Vector2();
protected Trail trail = new Trail(8);
protected CarriableTrait carrying;
protected final UnitState
@@ -75,8 +74,8 @@ public abstract class FlyingUnit extends BaseUnit implements CarryTrait{
}else{
attack(150f);
if((Mathf.angNear(angleTo(target), rotation, 15f) || !getWeapon().getAmmo().bullet.keepVelocity) //bombers don't care about rotation
&& distanceTo(target) < Math.max(getWeapon().getAmmo().getRange(), type.range)){
if((Angles.near(angleTo(target), rotation, 15f) || !getWeapon().getAmmo().bullet.keepVelocity) //bombers don't care about rotation
&& dst(target) < Math.max(getWeapon().getAmmo().getRange(), type.range)){
AmmoType ammo = getWeapon().getAmmo();
Vector2 to = Predict.intercept(FlyingUnit.this, target, ammo.bullet.speed);
@@ -99,7 +98,7 @@ public abstract class FlyingUnit extends BaseUnit implements CarryTrait{
});
if(target != null){
circle(60f + Mathf.absin(Timers.time() + id * 23525, 70f, 1200f));
circle(60f + Mathf.absin(Time.time() + id * 23525, 70f, 1200f));
}
}
},
@@ -153,9 +152,6 @@ public abstract class FlyingUnit extends BaseUnit implements CarryTrait{
updateRotation();
wobble();
}
trail.update(x + Angles.trnsx(rotation + 180f, 6f) + Mathf.range(wobblyness),
y + Angles.trnsy(rotation + 180f, 6f) + Mathf.range(wobblyness));
}
@Override
@@ -169,11 +165,6 @@ public abstract class FlyingUnit extends BaseUnit implements CarryTrait{
Draw.alpha(1f);
}
@Override
public void drawOver(){
trail.draw(type.trailColor, 5f);
}
@Override
public void behavior(){
if(health <= health * type.retreatPercent && !isCommanded() &&
@@ -200,11 +191,11 @@ public abstract class FlyingUnit extends BaseUnit implements CarryTrait{
protected void wobble(){
if(Net.client()) return;
x += Mathf.sin(Timers.time() + id * 999, 25f, 0.08f)*Timers.delta();
y += Mathf.cos(Timers.time() + id * 999, 25f, 0.08f)*Timers.delta();
x += Mathf.sin(Time.time() + id * 999, 25f, 0.08f)*Time.delta();
y += Mathf.cos(Time.time() + id * 999, 25f, 0.08f)*Time.delta();
if(velocity.len() <= 0.05f){
rotation += Mathf.sin(Timers.time() + id * 99, 10f, 2.5f)*Timers.delta();
rotation += Mathf.sin(Time.time() + id * 99, 10f, 2.5f)*Time.delta();
}
}
@@ -225,7 +216,7 @@ public abstract class FlyingUnit extends BaseUnit implements CarryTrait{
vec.rotate((circleLength - vec.len()) / circleLength * 180f);
}
vec.setLength(speed * Timers.delta());
vec.setLength(speed * Time.delta());
velocity.add(vec);
}
@@ -235,9 +226,9 @@ public abstract class FlyingUnit extends BaseUnit implements CarryTrait{
vec.set(target.getX() - x, target.getY() - y);
float length = circleLength <= 0.001f ? 1f : Mathf.clamp((distanceTo(target) - circleLength) / 100f, -1f, 1f);
float length = circleLength <= 0.001f ? 1f : Mathf.clamp((dst(target) - circleLength) / 100f, -1f, 1f);
vec.setLength(type.speed * Timers.delta() * length);
vec.setLength(type.speed * Time.delta() * length);
if(length < 0) vec.rotate(180f);
velocity.add(vec);
@@ -255,7 +246,7 @@ public abstract class FlyingUnit extends BaseUnit implements CarryTrait{
vec.setAngle(Mathf.slerpDelta(velocity.angle(), vec.angle(), 0.44f));
}
vec.setLength(type.speed * Timers.delta());
vec.setLength(type.speed * Time.delta());
velocity.add(vec);
}
@@ -1,7 +1,11 @@
package io.anuke.mindustry.entities.units;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Vector2;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.math.Angles;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.geom.Vector2;
import io.anuke.arc.util.Time;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.entities.Predict;
import io.anuke.mindustry.entities.TileEntity;
@@ -12,11 +16,6 @@ import io.anuke.mindustry.type.ContentType;
import io.anuke.mindustry.type.Weapon;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.Floor;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Translator;
import java.io.DataInput;
import java.io.DataOutput;
@@ -26,7 +25,7 @@ import static io.anuke.mindustry.Vars.content;
import static io.anuke.mindustry.Vars.world;
public abstract class GroundUnit extends BaseUnit{
protected static Translator vec = new Translator();
protected static Vector2 vec = new Vector2();
protected float walkTime;
protected float stuckTime;
@@ -42,7 +41,7 @@ public abstract class GroundUnit extends BaseUnit{
public void update(){
TileEntity core = getClosestEnemyCore();
float dst = core == null ? 0 : distanceTo(core);
float dst = core == null ? 0 : dst(core);
if(core != null && dst < getWeapon().getAmmo().getRange() / 1.1f){
target = core;
@@ -57,7 +56,7 @@ public abstract class GroundUnit extends BaseUnit{
public void update(){
TileEntity target = getClosestCore();
if(target != null){
if(distanceTo(target) > 400f){
if(dst(target) > 400f){
moveAwayFromCore();
}else{
patrol();
@@ -105,7 +104,7 @@ public abstract class GroundUnit extends BaseUnit{
@Override
public void move(float x, float y){
if(Mathf.dst(x, y) > 0.01f){
baseRotation = Mathf.slerpDelta(baseRotation, Mathf.atan2(x, y), type.baseRotateSpeed);
baseRotation = Mathf.slerpDelta(baseRotation, Mathf.angle(x, y), type.baseRotateSpeed);
}
super.move(x, y);
}
@@ -119,14 +118,14 @@ public abstract class GroundUnit extends BaseUnit{
public void update(){
super.update();
stuckTime = !vec.set(x, y).sub(lastPosition()).isZero(0.0001f) ? 0f : stuckTime + Timers.delta();
stuckTime = !vec.set(x, y).sub(lastPosition()).isZero(0.0001f) ? 0f : stuckTime + Time.delta();
if(!velocity.isZero()){
baseRotation = Mathf.slerpDelta(baseRotation, velocity.angle(), 0.05f);
}
if(stuckTime < 1f){
walkTime += Timers.delta();
walkTime += Time.delta();
}
}
@@ -188,10 +187,10 @@ public abstract class GroundUnit extends BaseUnit{
}
if(!Units.invalidateTarget(target, this)){
if(distanceTo(target) < getWeapon().getAmmo().getRange()){
if(dst(target) < getWeapon().getAmmo().getRange()){
rotate(angleTo(target));
if(Mathf.angNear(angleTo(target), rotation, 13f)){
if(Angles.near(angleTo(target), rotation, 13f)){
AmmoType ammo = getWeapon().getAmmo();
Vector2 to = Predict.intercept(GroundUnit.this, target, ammo.bullet.speed);
@@ -220,8 +219,8 @@ public abstract class GroundUnit extends BaseUnit{
}
@Override
public void read(DataInput data, long time) throws IOException{
super.read(data, time);
public void read(DataInput data) throws IOException{
super.read(data);
weapon = content.getByID(ContentType.weapon, data.readByte());
}
@@ -238,12 +237,12 @@ public abstract class GroundUnit extends BaseUnit{
}
protected void patrol(){
vec.trns(baseRotation, type.speed * Timers.delta());
vec.trns(baseRotation, type.speed * Time.delta());
velocity.add(vec.x, vec.y);
vec.trns(baseRotation, type.hitsizeTile);
Tile tile = world.tileWorld(x + vec.x, y + vec.y);
if((tile == null || tile.solid() || tile.floor().drownTime > 0) || stuckTime > 10f){
baseRotation += Mathf.sign(id % 2 - 0.5f) * Timers.delta() * 3f;
baseRotation += Mathf.sign(id % 2 - 0.5f) * Time.delta() * 3f;
}
rotation = Mathf.slerpDelta(rotation, velocity.angle(), type.rotatespeed);
@@ -258,7 +257,7 @@ public abstract class GroundUnit extends BaseUnit{
vec.rotate((circleLength - vec.len()) / circleLength * 180f);
}
vec.setLength(type.speed * Timers.delta());
vec.setLength(type.speed * Time.delta());
velocity.add(vec);
}
@@ -272,7 +271,7 @@ public abstract class GroundUnit extends BaseUnit{
float angle = angleTo(targetTile);
velocity.add(vec.trns(angleTo(targetTile), type.speed*Timers.delta()));
velocity.add(vec.trns(angleTo(targetTile), type.speed*Time.delta()));
rotation = Mathf.slerpDelta(rotation, angle, type.rotatespeed);
}
@@ -292,11 +291,11 @@ public abstract class GroundUnit extends BaseUnit{
Tile targetTile = world.pathfinder.getTargetTile(enemy, tile);
TileEntity core = getClosestCore();
if(tile == targetTile || core == null || distanceTo(core) < 90f) return;
if(tile == targetTile || core == null || dst(core) < 90f) return;
float angle = angleTo(targetTile);
velocity.add(vec.trns(angleTo(targetTile), type.speed*Timers.delta()));
velocity.add(vec.trns(angleTo(targetTile), type.speed*Time.delta()));
rotation = Mathf.slerpDelta(rotation, angle, type.rotatespeed);
}
}
@@ -1,24 +1,22 @@
package io.anuke.mindustry.entities.units;
import com.badlogic.gdx.math.Vector2;
import io.anuke.ucore.util.Translator;
import static io.anuke.mindustry.Vars.threads;
import io.anuke.arc.Core;
import io.anuke.arc.math.geom.Vector2;
/**
* Used to group entities together, for formations and such.
* Usually, squads are used by units spawned in the same wave.
*/
public class Squad{
public Vector2 direction = new Translator();
public Vector2 direction = new Vector2();
public int units;
private long lastUpdated;
protected void update(){
if(threads.getFrameID() != lastUpdated){
if(Core.graphics.getFrameId() != lastUpdated){
direction.setZero();
lastUpdated = threads.getFrameID();
lastUpdated = Core.graphics.getFrameId();
}
}
}
@@ -1,6 +1,6 @@
package io.anuke.mindustry.entities.units;
import io.anuke.ucore.util.Bundles;
import io.anuke.arc.Core;
public enum UnitCommand{
attack, retreat, patrol;
@@ -8,7 +8,7 @@ public enum UnitCommand{
private final String localized;
UnitCommand(){
localized = Bundles.get("command." + name());
localized = Core.bundle.get("command." + name());
}
public String localized(){
@@ -5,7 +5,7 @@ import io.anuke.mindustry.content.Items;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.gen.Call;
import io.anuke.mindustry.type.Item;
import io.anuke.ucore.util.Mathf;
import io.anuke.arc.math.Mathf;
public class UnitDrops{
private static Item[] dropTable;
@@ -1,8 +1,13 @@
package io.anuke.mindustry.entities.units;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.utils.ObjectSet;
import io.anuke.arc.Core;
import io.anuke.arc.collection.ObjectSet;
import io.anuke.arc.function.Supplier;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.TextureRegion;
import io.anuke.arc.scene.ui.layout.Table;
import io.anuke.arc.util.Log;
import io.anuke.arc.util.Strings;
import io.anuke.mindustry.content.Items;
import io.anuke.mindustry.content.Weapons;
import io.anuke.mindustry.entities.traits.TypeTrait;
@@ -12,12 +17,6 @@ import io.anuke.mindustry.type.ContentType;
import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.type.Weapon;
import io.anuke.mindustry.ui.ContentDisplay;
import io.anuke.ucore.function.Supplier;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.scene.ui.layout.Table;
import io.anuke.ucore.util.Bundles;
import io.anuke.ucore.util.Log;
import io.anuke.ucore.util.Strings;
public class UnitType extends UnlockableContent{
protected final Supplier<? extends BaseUnit> constructor;
@@ -51,11 +50,11 @@ public class UnitType extends UnlockableContent{
public <T extends BaseUnit> UnitType(String name, Class<T> type, Supplier<T> mainConstructor){
this.name = name;
this.constructor = mainConstructor;
this.description = Bundles.getOrNull("unit." + name + ".description");
this.description = Core.bundle.getOrNull("unit." + name + ".description");
TypeTrait.registerType(type, mainConstructor);
if(!Bundles.has("unit." + this.name + ".name")){
if(!Core.bundle.has("unit." + this.name + ".name")){
Log.err("Warning: unit '" + name + "' is missing a localized name. Add the follow to bundle.properties:");
Log.err("unit." + this.name + ".name=" + Strings.capitalize(name.replace('-', '_')));
}
@@ -68,7 +67,7 @@ public class UnitType extends UnlockableContent{
@Override
public String localizedName(){
return Bundles.get("unit." + name + ".name");
return Core.bundle.get("unit." + name + ".name");
}
@Override
@@ -78,12 +77,12 @@ public class UnitType extends UnlockableContent{
@Override
public void load(){
iconRegion = Draw.region("unit-icon-" + name);
region = Draw.region(name);
iconRegion = Core.atlas.find("unit-icon-" + name);
region = Core.atlas.find(name);
if(!isFlying){
legRegion = Draw.region(name + "-leg");
baseRegion = Draw.region(name + "-base");
legRegion = Core.atlas.find(name + "-leg");
baseRegion = Core.atlas.find(name + "-base");
}
}
@@ -1,113 +0,0 @@
package io.anuke.mindustry.entities.units.types;
import com.badlogic.gdx.math.Vector2;
import io.anuke.annotations.Annotations.Loc;
import io.anuke.annotations.Annotations.Remote;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.content.fx.UnitFx;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.entities.Predict;
import io.anuke.mindustry.entities.traits.TargetTrait;
import io.anuke.mindustry.entities.units.BaseUnit;
import io.anuke.mindustry.entities.units.FlyingUnit;
import io.anuke.mindustry.entities.units.UnitCommand;
import io.anuke.mindustry.entities.units.UnitState;
import io.anuke.mindustry.gen.Call;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.type.AmmoType;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.util.Mathf;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import static io.anuke.mindustry.Vars.*;
public class AlphaDrone extends FlyingUnit {
static final float followDistance = 80f;
public Player leader;
public final UnitState attack = new UnitState() {
@Override
public void update() {
if(leader == null || leader.isDead() || !leader.isAdded()){
damage(99999f);
return;
}
TargetTrait last = target;
target = leader;
if(last == null){
circle(leader.isShooting ? 60f : 0f);
}
target = last;
if(distanceTo(leader) < followDistance){
targetClosest();
}else{
target = null;
}
if(target != null){
attack(50f);
if((Mathf.angNear(angleTo(target), rotation, 15f) && distanceTo(target) < getWeapon().getAmmo().getRange())){
AmmoType ammo = getWeapon().getAmmo();
Vector2 to = Predict.intercept(AlphaDrone.this, target, ammo.bullet.speed);
getWeapon().update(AlphaDrone.this, to.x, to.y);
}
}
if(!leader.isShooting && distanceTo(leader) < 7f){
Call.onAlphaDroneFade(AlphaDrone.this);
}
}
};
@Remote(called = Loc.server)
public static void onAlphaDroneFade(BaseUnit drone){
if(drone == null) return;
Effects.effect(UnitFx.pickup, drone);
//must run afterwards so the unit's group is not null when sending the removal packet
threads.runDelay(drone::remove);
}
@Override
public void onCommand(UnitCommand command){
//nuh
}
@Override
public void behavior(){
//nope
}
@Override
public UnitState getStartState() {
return attack;
}
@Override
public void write(DataOutput stream) throws IOException {
super.write(stream);
stream.writeInt(leader == null ? -1 : leader.id);
}
@Override
public void read(DataInput stream, long time) throws IOException {
super.read(stream, time);
leader = Vars.playerGroup.getByID(stream.readInt());
}
@Override
public void readSave(DataInput stream) throws IOException{
super.readSave(stream);
if(!Net.active() && !headless){
leader = players[0];
}
}
}
@@ -1,6 +1,11 @@
package io.anuke.mindustry.entities.units.types;
import com.badlogic.gdx.utils.Queue;
import io.anuke.arc.Events;
import io.anuke.arc.collection.Queue;
import io.anuke.arc.entities.EntityGroup;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.geom.Geometry;
import io.anuke.arc.util.Structs;
import io.anuke.mindustry.content.blocks.Blocks;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.entities.TileEntity;
@@ -12,7 +17,6 @@ import io.anuke.mindustry.entities.units.UnitCommand;
import io.anuke.mindustry.entities.units.UnitState;
import io.anuke.mindustry.game.EventType.BuildSelectEvent;
import io.anuke.mindustry.gen.Call;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.type.ItemStack;
import io.anuke.mindustry.type.ItemType;
@@ -20,11 +24,6 @@ import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.BuildBlock;
import io.anuke.mindustry.world.blocks.BuildBlock.BuildEntity;
import io.anuke.mindustry.world.meta.BlockFlag;
import io.anuke.ucore.core.Events;
import io.anuke.ucore.entities.EntityGroup;
import io.anuke.ucore.util.Geometry;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Structs;
import java.io.DataInput;
import java.io.DataOutput;
@@ -63,7 +62,7 @@ public class Drone extends FlyingUnit implements BuilderTrait{
if(core == null) return;
if((entity.progress() < 1f || entity.progress() > 0f) && entity.tile.block() instanceof BuildBlock){ //building is valid
if(!isBuilding() && distanceTo(target) < placeDistance * 0.9f){ //within distance, begin placing
if(!isBuilding() && dst(target) < placeDistance * 0.9f){ //within distance, begin placing
if(isBreaking){
getPlaceQueue().addLast(new BuildRequest(entity.tile.x, entity.tile.y));
}else{
@@ -108,7 +107,7 @@ public class Drone extends FlyingUnit implements BuilderTrait{
if(target == null) return;
if(target.distanceTo(Drone.this) > type.range){
if(target.dst(Drone.this) > type.range){
circle(type.range*0.9f);
}else{
getWeapon().update(Drone.this, target.getX(), target.getY());
@@ -158,7 +157,7 @@ public class Drone extends FlyingUnit implements BuilderTrait{
if(target instanceof Tile){
moveTo(type.range / 1.5f);
if(distanceTo(target) < type.range && mineTile != target){
if(dst(target) < type.range && mineTile != target){
setMineTile((Tile) target);
}
@@ -196,7 +195,7 @@ public class Drone extends FlyingUnit implements BuilderTrait{
TileEntity tile = (TileEntity) target;
if(distanceTo(target) < type.range){
if(dst(target) < type.range){
if(tile.tile.block().acceptStack(inventory.getItem().item, inventory.getItem().amount, tile.tile, Drone.this) == inventory.getItem().amount){
Call.transferItemTo(inventory.getItem().item, inventory.getItem().amount, x, y, tile.tile);
inventory.clearItem();
@@ -254,7 +253,7 @@ public class Drone extends FlyingUnit implements BuilderTrait{
}
private void notifyPlaced(BuildEntity entity, boolean isBreaking){
float dist = Math.min(entity.distanceTo(x, y) - placeDistance, 0);
float dist = Math.min(entity.dst(x, y) - placeDistance, 0);
if(!state.is(build) && dist / type.maxVelocity < entity.buildCost * 0.9f){
target = entity;
@@ -311,7 +310,7 @@ public class Drone extends FlyingUnit implements BuilderTrait{
@Override
protected void updateRotation(){
if(target != null && ((state.is(repair) && target.distanceTo(this) < type.range) || state.is(mine))){
if(target != null && ((state.is(repair) && target.dst(this) < type.range) || state.is(mine))){
rotation = Mathf.slerpDelta(rotation, angleTo(target), 0.3f);
}else{
rotation = Mathf.slerpDelta(rotation, velocity.angle(), 0.3f);
@@ -333,7 +332,6 @@ public class Drone extends FlyingUnit implements BuilderTrait{
@Override
public void drawOver(){
trail.draw(Palette.lightTrail, 3f);
drawBuilding(this);
}
@@ -364,8 +362,8 @@ public class Drone extends FlyingUnit implements BuilderTrait{
}
@Override
public void read(DataInput data, long time) throws IOException{
super.read(data, time);
public void read(DataInput data) throws IOException{
super.read(data);
int mined = data.readInt();
int repairing = data.readInt();