Source reformat
This commit is contained in:
@@ -7,10 +7,7 @@ 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.Point2;
|
||||
import io.anuke.arc.math.geom.Rectangle;
|
||||
import io.anuke.arc.math.geom.Vector2;
|
||||
import io.anuke.arc.math.geom.*;
|
||||
import io.anuke.arc.util.Time;
|
||||
import io.anuke.mindustry.content.Bullets;
|
||||
import io.anuke.mindustry.content.Fx;
|
||||
@@ -27,7 +24,7 @@ import io.anuke.mindustry.world.Tile;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
/**Utility class for damaging in an area.*/
|
||||
/** Utility class for damaging in an area. */
|
||||
public class Damage{
|
||||
private static Rectangle rect = new Rectangle();
|
||||
private static Rectangle hitrect = new Rectangle();
|
||||
@@ -35,19 +32,19 @@ public class Damage{
|
||||
private static GridBits bits = new GridBits(30, 30);
|
||||
private static IntQueue propagation = new IntQueue();
|
||||
|
||||
/**Creates a dynamic explosion based on specified parameters.*/
|
||||
/** 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);
|
||||
int branches = 5 + Mathf.clamp((int)(power / 30), 1, 20);
|
||||
Time.run(i * 2f + Mathf.random(4f), () -> Lightning.create(Team.none, Pal.power, 3,
|
||||
x, y, Mathf.random(360f), branches + Mathf.range(2)));
|
||||
x, y, Mathf.random(360f), branches + Mathf.range(2)));
|
||||
}
|
||||
|
||||
for(int i = 0; i < Mathf.clamp(flammability / 4, 0, 30); i++){
|
||||
Time.run(i / 2f, () -> Call.createBullet(Bullets.fireball, x, y, Mathf.random(360f)));
|
||||
}
|
||||
|
||||
int waves = Mathf.clamp((int) (explosiveness / 4), 0, 30);
|
||||
int waves = Mathf.clamp((int)(explosiveness / 4), 0, 30);
|
||||
|
||||
for(int i = 0; i < waves; i++){
|
||||
int f = i;
|
||||
@@ -67,7 +64,7 @@ public class Damage{
|
||||
|
||||
float shake = Math.min(explosiveness / 4f + 3f, 9f);
|
||||
Effects.shake(shake, shake, x, y);
|
||||
Effects.effect(Fx.dynamicExplosion, x, y, radius/8f);
|
||||
Effects.effect(Fx.dynamicExplosion, x, y, radius / 8f);
|
||||
}
|
||||
|
||||
public static void createIncend(float x, float y, float range, int amount){
|
||||
@@ -136,7 +133,7 @@ public class Damage{
|
||||
Units.getNearbyEnemies(team, rect, cons);
|
||||
}
|
||||
|
||||
/**Damages all entities and blocks in a radius that are enemies of the team.*/
|
||||
/** Damages all entities and blocks in a radius that are enemies of the team. */
|
||||
public static void damageUnits(Team team, float x, float y, float size, float damage, Predicate<io.anuke.mindustry.entities.type.Unit> predicate, Consumer<io.anuke.mindustry.entities.type.Unit> acceptor){
|
||||
Consumer<io.anuke.mindustry.entities.type.Unit> cons = entity -> {
|
||||
if(!predicate.test(entity)) return;
|
||||
@@ -157,17 +154,17 @@ public class Damage{
|
||||
}
|
||||
}
|
||||
|
||||
/**Damages everything in a radius.*/
|
||||
/** Damages everything in a radius. */
|
||||
public static void damage(float x, float y, float radius, float damage){
|
||||
damage(null, x, y, radius, damage, false);
|
||||
}
|
||||
|
||||
/**Damages all entities and blocks in a radius that are enemies of the team.*/
|
||||
/** 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){
|
||||
damage(team, x, y, radius, damage, false);
|
||||
}
|
||||
|
||||
/**Damages all entities and blocks in a radius that are enemies of the team.*/
|
||||
/** 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, boolean complete){
|
||||
Consumer<Unit> cons = entity -> {
|
||||
if(entity.getTeam() == team || entity.dst(x, y) > radius){
|
||||
@@ -201,11 +198,11 @@ public class Damage{
|
||||
public static void tileDamage(Team team, int startx, int starty, int radius, float baseDamage){
|
||||
bits.clear();
|
||||
propagation.clear();
|
||||
int bitOffset = bits.width()/2;
|
||||
int bitOffset = bits.width() / 2;
|
||||
|
||||
propagation.addFirst(PropCell.get((byte)0, (byte)0, (short)baseDamage));
|
||||
//clamp radius to fit bits
|
||||
radius = Math.min(radius, bits.width()/2);
|
||||
radius = Math.min(radius, bits.width() / 2);
|
||||
|
||||
while(!propagation.isEmpty()){
|
||||
int prop = propagation.removeLast();
|
||||
@@ -242,7 +239,7 @@ public class Damage{
|
||||
}
|
||||
|
||||
private static void completeDamage(Team team, float x, float y, float radius, float damage){
|
||||
int trad = (int) (radius / tilesize);
|
||||
int trad = (int)(radius / tilesize);
|
||||
for(int dx = -trad; dx <= trad; dx++){
|
||||
for(int dy = -trad; dy <= trad; dy++){
|
||||
Tile tile = world.tile(Math.round(x / tilesize) + dx, Math.round(y / tilesize) + dy);
|
||||
|
||||
@@ -3,10 +3,7 @@ package io.anuke.mindustry.entities;
|
||||
import io.anuke.arc.collection.Array;
|
||||
import io.anuke.arc.collection.IntSet;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.arc.math.geom.Geometry;
|
||||
import io.anuke.arc.math.geom.QuadTree;
|
||||
import io.anuke.arc.math.geom.Rectangle;
|
||||
import io.anuke.arc.math.geom.Vector2;
|
||||
import io.anuke.arc.math.geom.*;
|
||||
import io.anuke.mindustry.entities.traits.Entity;
|
||||
import io.anuke.mindustry.entities.traits.SolidTrait;
|
||||
|
||||
@@ -135,7 +132,7 @@ public class EntityCollisions{
|
||||
|
||||
for(Entity entity : group.all()){
|
||||
if(entity instanceof SolidTrait){
|
||||
SolidTrait s = (SolidTrait) entity;
|
||||
SolidTrait s = (SolidTrait)entity;
|
||||
s.lastPosition().set(s.getX(), s.getY());
|
||||
tree.insert(s);
|
||||
}
|
||||
@@ -144,8 +141,8 @@ public class EntityCollisions{
|
||||
|
||||
private void checkCollide(Entity entity, Entity other){
|
||||
|
||||
SolidTrait a = (SolidTrait) entity;
|
||||
SolidTrait b = (SolidTrait) other;
|
||||
SolidTrait a = (SolidTrait)entity;
|
||||
SolidTrait b = (SolidTrait)other;
|
||||
|
||||
a.hitbox(this.r1);
|
||||
b.hitbox(this.r2);
|
||||
@@ -228,7 +225,7 @@ public class EntityCollisions{
|
||||
if(!(entity instanceof SolidTrait) || collided.contains(entity.getID()))
|
||||
continue;
|
||||
|
||||
SolidTrait solid = (SolidTrait) entity;
|
||||
SolidTrait solid = (SolidTrait)entity;
|
||||
|
||||
solid.hitbox(r1);
|
||||
r1.x += (solid.lastPosition().x - solid.getX());
|
||||
|
||||
@@ -46,7 +46,7 @@ public class EntityDraw{
|
||||
for(Entity e : group.all()){
|
||||
if(!(e instanceof DrawTrait) || !toDraw.test((T)e) || !e.isAdded()) continue;
|
||||
|
||||
if(!clip || rect.setSize(((DrawTrait) e).drawSize()).setCenter(e.getX(), e.getY()).overlaps(viewport)){
|
||||
if(!clip || rect.setSize(((DrawTrait)e).drawSize()).setCenter(e.getX(), e.getY()).overlaps(viewport)){
|
||||
cons.accept((T)e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ public class EntityGroup<T extends Entity>{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**Returns the logic-only array for iteration.*/
|
||||
/** Returns the logic-only array for iteration. */
|
||||
public Array<T> all(){
|
||||
return entityArray;
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ public class EntityQuery{
|
||||
float cdist = 0f;
|
||||
Array<SolidTrait> entities = getNearby(group, x, y, range * 2f);
|
||||
for(int i = 0; i < entities.size; i++){
|
||||
T e = (T) entities.get(i);
|
||||
T e = (T)entities.get(i);
|
||||
if(!pred.test(e))
|
||||
continue;
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ public class Predict{
|
||||
|
||||
/**
|
||||
* Calculates of intercept of a stationary and moving target. Do not call from multiple threads!
|
||||
*
|
||||
* @param srcx X of shooter
|
||||
* @param srcy Y of shooter
|
||||
* @param dstx X of target
|
||||
@@ -28,7 +27,7 @@ public class Predict{
|
||||
dstvx /= Time.delta();
|
||||
dstvy /= Time.delta();
|
||||
float tx = dstx - srcx,
|
||||
ty = dsty - srcy;
|
||||
ty = dsty - srcy;
|
||||
|
||||
// Get quadratic equation components
|
||||
float a = dstvx * dstvx + dstvy * dstvy - v * v;
|
||||
@@ -57,8 +56,8 @@ public class Predict{
|
||||
*/
|
||||
public static Vector2 intercept(TargetTrait src, TargetTrait dst, float v){
|
||||
return intercept(src.getX(), src.getY(), dst.getX(), dst.getY(),
|
||||
dst.getTargetVelocityX() - src.getTargetVelocityX(),
|
||||
dst.getTargetVelocityY() - src.getTargetVelocityY(), v);
|
||||
dst.getTargetVelocityX() - src.getTargetVelocityX(),
|
||||
dst.getTargetVelocityY() - src.getTargetVelocityY(), v);
|
||||
}
|
||||
|
||||
private static Vector2 quad(float a, float b, float c){
|
||||
|
||||
@@ -7,10 +7,7 @@ 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.type.Player;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.entities.type.BaseUnit;
|
||||
import io.anuke.mindustry.entities.type.Unit;
|
||||
import io.anuke.mindustry.entities.type.*;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
@@ -29,7 +26,6 @@ public class Units{
|
||||
|
||||
/**
|
||||
* Validates a target.
|
||||
*
|
||||
* @param target The target to validate
|
||||
* @param team The team of the thing doing tha targeting
|
||||
* @param x The X position of the thing doign the targeting
|
||||
@@ -41,17 +37,17 @@ public class Units{
|
||||
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)}*/
|
||||
/** See {@link #invalidateTarget(TargetTrait, Team, float, float, float)} */
|
||||
public static boolean invalidateTarget(TargetTrait target, Team team, float x, float y){
|
||||
return invalidateTarget(target, team, x, y, Float.MAX_VALUE);
|
||||
}
|
||||
|
||||
/**See {@link #invalidateTarget(TargetTrait, Team, float, float, float)}*/
|
||||
/** See {@link #invalidateTarget(TargetTrait, Team, float, float, float)} */
|
||||
public static boolean invalidateTarget(TargetTrait target, Unit targeter){
|
||||
return invalidateTarget(target, targeter.getTeam(), targeter.x, targeter.y, targeter.getWeapon().bullet.range());
|
||||
}
|
||||
|
||||
/**Returns whether there are any entities on this tile.*/
|
||||
/** Returns whether there are any entities on this tile. */
|
||||
public static boolean anyEntities(Tile tile){
|
||||
Block type = tile.block();
|
||||
rect.setSize(type.size * tilesize, type.size * tilesize);
|
||||
@@ -60,7 +56,7 @@ public class Units{
|
||||
return anyEntities(rect);
|
||||
}
|
||||
|
||||
/**Can be called from any thread.*/
|
||||
/** Can be called from any thread. */
|
||||
public static boolean anyEntities(Rectangle rect){
|
||||
boolResult = false;
|
||||
|
||||
@@ -78,7 +74,7 @@ public class Units{
|
||||
return boolResult;
|
||||
}
|
||||
|
||||
/**Returns whether there are any entities on this tile, with the hitbox expanded.*/
|
||||
/** Returns whether there are any entities on this tile, with the hitbox expanded. */
|
||||
public static boolean anyEntities(Tile tile, float expansion, Predicate<Unit> pred){
|
||||
Block type = tile.block();
|
||||
rect.setSize(type.size * tilesize + expansion, type.size * tilesize + expansion);
|
||||
@@ -100,18 +96,18 @@ public class Units{
|
||||
return value[0];
|
||||
}
|
||||
|
||||
/**Returns the neareset damaged tile.*/
|
||||
/** Returns the neareset damaged tile. */
|
||||
public static TileEntity findDamagedTile(Team team, float x, float y){
|
||||
Tile tile = Geometry.findClosest(x, y, world.indexer.getDamaged(team));
|
||||
return tile == null ? null : tile.entity;
|
||||
}
|
||||
|
||||
/**Returns the neareset ally tile in a range.*/
|
||||
/** Returns the neareset ally tile in a range. */
|
||||
public static TileEntity findAllyTile(Team team, float x, float y, float range, Predicate<Tile> pred){
|
||||
return world.indexer.findTile(team, x, y, range, pred);
|
||||
}
|
||||
|
||||
/**Returns the neareset enemy tile in a range.*/
|
||||
/** Returns the neareset enemy tile in a range. */
|
||||
public static TileEntity findEnemyTile(Team team, float x, float y, float range, Predicate<Tile> pred){
|
||||
if(team == Team.none) return null;
|
||||
|
||||
@@ -124,7 +120,7 @@ public class Units{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**Iterates over all units on all teams, including players.*/
|
||||
/** Iterates over all units on all teams, including players. */
|
||||
public static void allUnits(Consumer<Unit> cons){
|
||||
//check all unit groups first
|
||||
for(EntityGroup<BaseUnit> group : unitGroups){
|
||||
@@ -141,17 +137,17 @@ public class Units{
|
||||
}
|
||||
}
|
||||
|
||||
/**Returns the closest target enemy. First, units are checked, then tile entities.*/
|
||||
/** Returns the closest target enemy. First, units are checked, then tile entities. */
|
||||
public static TargetTrait getClosestTarget(Team team, float x, float y, float range){
|
||||
return getClosestTarget(team, x, y, range, Unit::isValid);
|
||||
}
|
||||
|
||||
/**Returns the closest target enemy. First, units are checked, then tile entities.*/
|
||||
/** Returns the closest target enemy. First, units are checked, then tile entities. */
|
||||
public static TargetTrait getClosestTarget(Team team, float x, float y, float range, Predicate<Unit> unitPred){
|
||||
return getClosestTarget(team, x, y, range, unitPred, t -> true);
|
||||
}
|
||||
|
||||
/**Returns the closest target enemy. First, units are checked, then tile entities.*/
|
||||
/** Returns the closest target enemy. First, units are checked, then tile entities. */
|
||||
public static TargetTrait getClosestTarget(Team team, float x, float y, float range, Predicate<Unit> unitPred, Predicate<Tile> tilePred){
|
||||
Unit unit = getClosestEnemy(team, x, y, range, unitPred);
|
||||
if(unit != null){
|
||||
@@ -161,7 +157,7 @@ public class Units{
|
||||
}
|
||||
}
|
||||
|
||||
/**Returns the closest enemy of this team. Filter by predicate.*/
|
||||
/** Returns the closest enemy of this team. Filter by predicate. */
|
||||
public static Unit getClosestEnemy(Team team, float x, float y, float range, Predicate<Unit> predicate){
|
||||
if(team == Team.none) return null;
|
||||
|
||||
@@ -186,7 +182,7 @@ public class Units{
|
||||
return result;
|
||||
}
|
||||
|
||||
/**Returns the closest ally of this team. Filter by predicate.*/
|
||||
/** Returns the closest ally of this team. Filter by predicate. */
|
||||
public static Unit getClosest(Team team, float x, float y, float range, Predicate<Unit> predicate){
|
||||
result = null;
|
||||
cdist = 0f;
|
||||
@@ -209,21 +205,21 @@ public class Units{
|
||||
return result;
|
||||
}
|
||||
|
||||
/**Iterates over all units in a rectangle.*/
|
||||
/** Iterates over all units in a rectangle. */
|
||||
public static void getNearby(Team team, Rectangle rect, Consumer<Unit> cons){
|
||||
|
||||
EntityGroup<BaseUnit> group = unitGroups[team.ordinal()];
|
||||
if(!group.isEmpty()){
|
||||
EntityQuery.getNearby(group, rect, entity -> cons.accept((Unit) entity));
|
||||
EntityQuery.getNearby(group, rect, entity -> cons.accept((Unit)entity));
|
||||
}
|
||||
|
||||
//now check all players
|
||||
EntityQuery.getNearby(playerGroup, rect, player -> {
|
||||
if(((Unit) player).getTeam() == team) cons.accept((Unit) player);
|
||||
if(((Unit)player).getTeam() == team) cons.accept((Unit)player);
|
||||
});
|
||||
}
|
||||
|
||||
/**Iterates over all units in a circle around this position.*/
|
||||
/** Iterates over all units in a circle around this position. */
|
||||
public static void getNearby(Team team, float x, float y, float radius, Consumer<Unit> cons){
|
||||
rect.setSize(radius * 2).setCenter(x, y);
|
||||
|
||||
@@ -231,53 +227,53 @@ public class Units{
|
||||
if(!group.isEmpty()){
|
||||
EntityQuery.getNearby(group, rect, entity -> {
|
||||
if(entity.dst(x, y) <= radius){
|
||||
cons.accept((Unit) entity);
|
||||
cons.accept((Unit)entity);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//now check all players
|
||||
EntityQuery.getNearby(playerGroup, rect, player -> {
|
||||
if(((Unit) player).getTeam() == team && player.dst(x, y) <= radius){
|
||||
cons.accept((Unit) player);
|
||||
if(((Unit)player).getTeam() == team && player.dst(x, y) <= radius){
|
||||
cons.accept((Unit)player);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**Iterates over all units in a rectangle.*/
|
||||
/** Iterates over all units in a rectangle. */
|
||||
public static void getNearby(Rectangle rect, Consumer<Unit> cons){
|
||||
|
||||
for(Team team : Team.all){
|
||||
EntityGroup<BaseUnit> group = unitGroups[team.ordinal()];
|
||||
if(!group.isEmpty()){
|
||||
EntityQuery.getNearby(group, rect, entity -> cons.accept((Unit) entity));
|
||||
EntityQuery.getNearby(group, rect, entity -> cons.accept((Unit)entity));
|
||||
}
|
||||
}
|
||||
|
||||
//now check all enemy players
|
||||
EntityQuery.getNearby(playerGroup, rect, player -> cons.accept((Unit) player));
|
||||
EntityQuery.getNearby(playerGroup, rect, player -> cons.accept((Unit)player));
|
||||
}
|
||||
|
||||
/**Iterates over all units that are enemies of this team.*/
|
||||
/** Iterates over all units that are enemies of this team. */
|
||||
public static void getNearbyEnemies(Team team, Rectangle rect, Consumer<Unit> cons){
|
||||
EnumSet<Team> targets = state.teams.enemiesOf(team);
|
||||
|
||||
for(Team other : targets){
|
||||
EntityGroup<BaseUnit> group = unitGroups[other.ordinal()];
|
||||
if(!group.isEmpty()){
|
||||
EntityQuery.getNearby(group, rect, entity -> cons.accept((Unit) entity));
|
||||
EntityQuery.getNearby(group, rect, entity -> cons.accept((Unit)entity));
|
||||
}
|
||||
}
|
||||
|
||||
//now check all enemy players
|
||||
EntityQuery.getNearby(playerGroup, rect, player -> {
|
||||
if(targets.contains(((Player) player).getTeam())){
|
||||
cons.accept((Unit) player);
|
||||
if(targets.contains(((Player)player).getTeam())){
|
||||
cons.accept((Unit)player);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**Iterates over all units.*/
|
||||
/** Iterates over all units. */
|
||||
public static void getAllUnits(Consumer<Unit> cons){
|
||||
|
||||
for(Team team : Team.all){
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package io.anuke.mindustry.entities.bullet;
|
||||
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.mindustry.entities.Effects.Effect;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.mindustry.content.Fx;
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.mindustry.entities.Effects.Effect;
|
||||
|
||||
//TODO scale velocity depending on fslope()
|
||||
public class ArtilleryBulletType extends BasicBulletType{
|
||||
|
||||
@@ -6,7 +6,7 @@ import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||
import io.anuke.mindustry.graphics.Pal;
|
||||
|
||||
/**An extended BulletType for most ammo-based bullets shot from turrets and units.*/
|
||||
/** An extended BulletType for most ammo-based bullets shot from turrets and units. */
|
||||
public class BasicBulletType extends BulletType{
|
||||
public Color backColor = Pal.bulletYellowBack, frontColor = Pal.bulletYellow;
|
||||
public float bulletWidth = 5f, bulletHeight = 7f;
|
||||
|
||||
@@ -5,9 +5,7 @@ import io.anuke.annotations.Annotations.Remote;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.arc.math.geom.Rectangle;
|
||||
import io.anuke.arc.math.geom.Vector2;
|
||||
import io.anuke.arc.util.Interval;
|
||||
import io.anuke.arc.util.Time;
|
||||
import io.anuke.arc.util.Tmp;
|
||||
import io.anuke.arc.util.*;
|
||||
import io.anuke.arc.util.pooling.Pool.Poolable;
|
||||
import io.anuke.arc.util.pooling.Pools;
|
||||
import io.anuke.mindustry.entities.EntityGroup;
|
||||
@@ -18,9 +16,7 @@ import io.anuke.mindustry.entities.type.Unit;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
@@ -36,7 +32,7 @@ public class Bullet extends SolidEntity implements DamageTrait, ScaleTrait, Pool
|
||||
protected Entity owner;
|
||||
protected float time;
|
||||
|
||||
/**Internal use only!*/
|
||||
/** Internal use only! */
|
||||
public Bullet(){
|
||||
}
|
||||
|
||||
@@ -64,7 +60,7 @@ public class Bullet extends SolidEntity implements DamageTrait, ScaleTrait, Pool
|
||||
|
||||
bullet.velocity.set(0, type.speed).setAngle(angle).scl(velocityScl);
|
||||
if(type.keepVelocity){
|
||||
bullet.velocity.add(owner instanceof VelocityTrait ? ((VelocityTrait) owner).velocity() : Vector2.ZERO);
|
||||
bullet.velocity.add(owner instanceof VelocityTrait ? ((VelocityTrait)owner).velocity() : Vector2.ZERO);
|
||||
}
|
||||
|
||||
bullet.team = team;
|
||||
@@ -85,13 +81,13 @@ public class Bullet extends SolidEntity implements DamageTrait, ScaleTrait, Pool
|
||||
return create(type, parent.owner, parent.team, x, y, angle, velocityScl);
|
||||
}
|
||||
|
||||
/**Internal use only.*/
|
||||
/** Internal use only. */
|
||||
@Remote(called = Loc.server, unreliable = true)
|
||||
public static void createBullet(BulletType type, float x, float y, float angle){
|
||||
create(type, null, Team.none, x, y, angle);
|
||||
}
|
||||
|
||||
/**ok*/
|
||||
/** ok */
|
||||
@Remote(called = Loc.server, unreliable = true)
|
||||
public static void createBullet(BulletType type, Team team, float x, float y, float angle){
|
||||
create(type, null, team, x, y, angle);
|
||||
@@ -133,7 +129,7 @@ public class Bullet extends SolidEntity implements DamageTrait, ScaleTrait, Pool
|
||||
|
||||
public float damageMultiplier(){
|
||||
if(owner instanceof Unit){
|
||||
return ((Unit) owner).getDamageMultipler();
|
||||
return ((Unit)owner).getDamageMultipler();
|
||||
}
|
||||
return 1f;
|
||||
}
|
||||
@@ -194,7 +190,7 @@ public class Bullet extends SolidEntity implements DamageTrait, ScaleTrait, Pool
|
||||
|
||||
@Override
|
||||
public boolean collides(SolidTrait other){
|
||||
return type.collides && (other != owner && !(other instanceof DamageTrait)) && !supressCollision && !(other instanceof Unit && ((Unit) other).isFlying() && !type.collidesAir);
|
||||
return type.collides && (other != owner && !(other instanceof DamageTrait)) && !supressCollision && !(other instanceof Unit && ((Unit)other).isFlying() && !type.collidesAir);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -203,7 +199,7 @@ public class Bullet extends SolidEntity implements DamageTrait, ScaleTrait, Pool
|
||||
type.hit(this, x, y);
|
||||
|
||||
if(other instanceof Unit){
|
||||
Unit unit = (Unit) other;
|
||||
Unit unit = (Unit)other;
|
||||
unit.velocity().add(Tmp.v3.set(other.getX(), other.getY()).sub(x, y).setLength(type.knockback / unit.mass()));
|
||||
unit.applyEffect(type.status, type.statusDuration);
|
||||
}
|
||||
@@ -218,7 +214,7 @@ public class Bullet extends SolidEntity implements DamageTrait, ScaleTrait, Pool
|
||||
|
||||
velocity.scl(Mathf.clamp(1f - type.drag * Time.delta()));
|
||||
|
||||
time += Time.delta() * 1f/(lifeScl);
|
||||
time += Time.delta() * 1f / (lifeScl);
|
||||
time = Mathf.clamp(time, 0, type.lifetime);
|
||||
|
||||
if(time >= type.lifetime){
|
||||
@@ -336,12 +332,12 @@ public class Bullet extends SolidEntity implements DamageTrait, ScaleTrait, Pool
|
||||
velocity.limit(f);
|
||||
}
|
||||
|
||||
/** Sets the bullet's rotation in degrees.*/
|
||||
/** Sets the bullet's rotation in degrees. */
|
||||
public void rot(float angle){
|
||||
velocity.setAngle(angle);
|
||||
}
|
||||
|
||||
/** @return the bullet's rotation.*/
|
||||
/** @return the bullet's rotation. */
|
||||
public float rot(){
|
||||
float angle = Mathf.atan2(velocity.x, velocity.y) * Mathf.radiansToDegrees;
|
||||
if(angle < 0) angle += 360;
|
||||
|
||||
@@ -4,10 +4,8 @@ import io.anuke.arc.math.Angles;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.mindustry.content.Fx;
|
||||
import io.anuke.mindustry.content.StatusEffects;
|
||||
import io.anuke.mindustry.entities.Damage;
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.mindustry.entities.*;
|
||||
import io.anuke.mindustry.entities.Effects.Effect;
|
||||
import io.anuke.mindustry.entities.Units;
|
||||
import io.anuke.mindustry.entities.effect.Lightning;
|
||||
import io.anuke.mindustry.entities.traits.TargetTrait;
|
||||
import io.anuke.mindustry.game.Content;
|
||||
@@ -26,39 +24,39 @@ public abstract class BulletType extends Content{
|
||||
public boolean pierce;
|
||||
public Effect hitEffect, despawnEffect;
|
||||
|
||||
/**Effect created when shooting.*/
|
||||
/** Effect created when shooting. */
|
||||
public Effect shootEffect = Fx.shootSmall;
|
||||
/**Extra smoke effect created when shooting.*/
|
||||
/** Extra smoke effect created when shooting. */
|
||||
public Effect smokeEffect = Fx.shootSmallSmoke;
|
||||
/**Extra inaccuracy when firing.*/
|
||||
/** Extra inaccuracy when firing. */
|
||||
public float inaccuracy = 0f;
|
||||
/**How many bullets get created per ammo item/liquid.*/
|
||||
/** How many bullets get created per ammo item/liquid. */
|
||||
public float ammoMultiplier = 1f;
|
||||
/**Multiplied by turret reload speed to get final shoot speed.*/
|
||||
/** Multiplied by turret reload speed to get final shoot speed. */
|
||||
public float reloadMultiplier = 1f;
|
||||
/**Recoil from shooter entities.*/
|
||||
/** Recoil from shooter entities. */
|
||||
public float recoil;
|
||||
|
||||
public float splashDamage = 0f;
|
||||
/**Knockback in velocity.*/
|
||||
/** Knockback in velocity. */
|
||||
public float knockback;
|
||||
/**Whether this bullet hits tiles.*/
|
||||
/** Whether this bullet hits tiles. */
|
||||
public boolean hitTiles = true;
|
||||
/**Status effect applied on hit.*/
|
||||
/** Status effect applied on hit. */
|
||||
public StatusEffect status = StatusEffects.none;
|
||||
/**Intensity of applied status effect in terms of duration.*/
|
||||
/** Intensity of applied status effect in terms of duration. */
|
||||
public float statusDuration = 60 * 1f;
|
||||
/**Whether to sync this bullet to clients.*/
|
||||
/** Whether to sync this bullet to clients. */
|
||||
public boolean syncable;
|
||||
/**Whether this bullet type collides with tiles.*/
|
||||
/** Whether this bullet type collides with tiles. */
|
||||
public boolean collidesTiles = true;
|
||||
/**Whether this bullet type collides with tiles that are of the same team.*/
|
||||
/** Whether this bullet type collides with tiles that are of the same team. */
|
||||
public boolean collidesTeam = false;
|
||||
/**Whether this bullet type collides with air units.*/
|
||||
/** Whether this bullet type collides with air units. */
|
||||
public boolean collidesAir = true;
|
||||
/**Whether this bullet types collides with anything at all.*/
|
||||
/** Whether this bullet types collides with anything at all. */
|
||||
public boolean collides = true;
|
||||
/**Whether velocity is inherited from the shooter.*/
|
||||
/** Whether velocity is inherited from the shooter. */
|
||||
public boolean keepVelocity = true;
|
||||
|
||||
//additional effects
|
||||
@@ -67,7 +65,7 @@ public abstract class BulletType extends Content{
|
||||
public float fragVelocityMin = 0.2f, fragVelocityMax = 1f;
|
||||
public BulletType fragBullet = null;
|
||||
|
||||
/**Use a negative value to disable splash damage.*/
|
||||
/** Use a negative value to disable splash damage. */
|
||||
public float splashDamageRadius = -1f;
|
||||
|
||||
public int incendAmount = 0;
|
||||
@@ -90,7 +88,7 @@ public abstract class BulletType extends Content{
|
||||
despawnEffect = Fx.hitBulletSmall;
|
||||
}
|
||||
|
||||
/**Returns maximum distance the bullet this bullet type has can travel.*/
|
||||
/** Returns maximum distance the bullet this bullet type has can travel. */
|
||||
public float range(){
|
||||
return speed * lifetime * (1f - drag);
|
||||
}
|
||||
@@ -136,7 +134,7 @@ public abstract class BulletType extends Content{
|
||||
hit(b);
|
||||
}
|
||||
|
||||
for (int i = 0; i < lightining; i++) {
|
||||
for(int i = 0; i < lightining; i++){
|
||||
Lightning.create(b.getTeam(), Pal.surge, damage, b.x, b.y, Mathf.random(360f), lightningLength);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package io.anuke.mindustry.entities.bullet;
|
||||
|
||||
import io.anuke.arc.math.geom.Rectangle;
|
||||
import io.anuke.arc.util.Time;
|
||||
import io.anuke.mindustry.content.Fx;
|
||||
import io.anuke.mindustry.entities.Units;
|
||||
import io.anuke.arc.util.Time;
|
||||
|
||||
public abstract class FlakBulletType extends BasicBulletType{
|
||||
protected static Rectangle rect = new Rectangle();
|
||||
@@ -24,7 +24,7 @@ public abstract class FlakBulletType extends BasicBulletType{
|
||||
if(b.getData() instanceof Integer) return;
|
||||
|
||||
if(b.timer.get(2, 6)){
|
||||
Units.getNearbyEnemies(b.getTeam(), rect.setSize(explodeRange*2f).setCenter(b.x, b.y), unit -> {
|
||||
Units.getNearbyEnemies(b.getTeam(), rect.setSize(explodeRange * 2f).setCenter(b.x, b.y), unit -> {
|
||||
if(b.getData() instanceof Float) return;
|
||||
|
||||
if(unit.dst(b) < explodeRange){
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package io.anuke.mindustry.entities.bullet;
|
||||
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.arc.graphics.Color;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.arc.graphics.g2d.Fill;
|
||||
@@ -8,6 +7,7 @@ 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;
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.mindustry.entities.effect.Fire;
|
||||
import io.anuke.mindustry.entities.effect.Puddle;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
@@ -35,11 +35,11 @@ public class LiquidBulletType extends BulletType{
|
||||
|
||||
@Override
|
||||
public float range(){
|
||||
return speed * lifetime /2f;
|
||||
return speed * lifetime / 2f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Bullet b) {
|
||||
public void update(Bullet b){
|
||||
super.update(b);
|
||||
|
||||
if(liquid.canExtinguish()){
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package io.anuke.mindustry.entities.bullet;
|
||||
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
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.mindustry.content.Fx;
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.mindustry.graphics.Pal;
|
||||
import io.anuke.mindustry.world.blocks.distribution.MassDriver.DriverBulletData;
|
||||
|
||||
@@ -45,7 +45,7 @@ public class MassDriverBolt extends BulletType{
|
||||
|
||||
float hitDst = 7f;
|
||||
|
||||
DriverBulletData data = (DriverBulletData) b.getData();
|
||||
DriverBulletData data = (DriverBulletData)b.getData();
|
||||
|
||||
//if the target is dead, just keep flying until the bullet explodes
|
||||
if(data.to.isDead()){
|
||||
@@ -87,7 +87,7 @@ public class MassDriverBolt extends BulletType{
|
||||
|
||||
if(!(b.getData() instanceof DriverBulletData)) return;
|
||||
|
||||
DriverBulletData data = (DriverBulletData) b.getData();
|
||||
DriverBulletData data = (DriverBulletData)b.getData();
|
||||
data.to.isRecieving = false;
|
||||
|
||||
for(int i = 0; i < data.items.length; i++){
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package io.anuke.mindustry.entities.bullet;
|
||||
|
||||
import io.anuke.arc.graphics.Color;
|
||||
import io.anuke.mindustry.content.Fx;
|
||||
import io.anuke.mindustry.graphics.Pal;
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.arc.util.Time;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.arc.util.Time;
|
||||
import io.anuke.mindustry.content.Fx;
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.mindustry.graphics.Pal;
|
||||
|
||||
public class MissileBulletType extends BasicBulletType{
|
||||
protected Color trailColor = Pal.missileYellowBack;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package io.anuke.mindustry.entities.effect;
|
||||
|
||||
import io.anuke.arc.graphics.Color;
|
||||
import io.anuke.mindustry.entities.traits.BelowLiquidTrait;
|
||||
import io.anuke.mindustry.entities.EntityGroup;
|
||||
import io.anuke.mindustry.entities.impl.TimedEntity;
|
||||
import io.anuke.mindustry.entities.traits.DrawTrait;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.mindustry.entities.EntityGroup;
|
||||
import io.anuke.mindustry.entities.impl.TimedEntity;
|
||||
import io.anuke.mindustry.entities.traits.BelowLiquidTrait;
|
||||
import io.anuke.mindustry.entities.traits.DrawTrait;
|
||||
|
||||
import static io.anuke.mindustry.Vars.groundEffectGroup;
|
||||
|
||||
|
||||
@@ -3,9 +3,6 @@ package io.anuke.mindustry.entities.effect;
|
||||
import io.anuke.annotations.Annotations.Loc;
|
||||
import io.anuke.annotations.Annotations.Remote;
|
||||
import io.anuke.arc.collection.IntMap;
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.mindustry.entities.EntityGroup;
|
||||
import io.anuke.mindustry.entities.impl.TimedEntity;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.arc.math.geom.Geometry;
|
||||
import io.anuke.arc.math.geom.Point2;
|
||||
@@ -13,22 +10,17 @@ 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.Bullets;
|
||||
import io.anuke.mindustry.content.StatusEffects;
|
||||
import io.anuke.mindustry.content.Fx;
|
||||
import io.anuke.mindustry.entities.Damage;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.content.*;
|
||||
import io.anuke.mindustry.entities.*;
|
||||
import io.anuke.mindustry.entities.impl.TimedEntity;
|
||||
import io.anuke.mindustry.entities.traits.SaveTrait;
|
||||
import io.anuke.mindustry.entities.traits.SyncTrait;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.gen.Call;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Pos;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.*;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
@@ -42,10 +34,11 @@ public class Fire extends TimedEntity implements SaveTrait, SyncTrait, Poolable{
|
||||
private float baseFlammability = -1, puddleFlammability;
|
||||
private float lifetime;
|
||||
|
||||
/**Deserialization use only!*/
|
||||
public Fire(){}
|
||||
/** Deserialization use only! */
|
||||
public Fire(){
|
||||
}
|
||||
|
||||
/**Start a fire on the tile. If there already is a file there, refreshes its lifetime.*/
|
||||
/** Start a fire on the tile. If there already is a file there, refreshes its lifetime. */
|
||||
public static void create(Tile tile){
|
||||
if(Net.client() || tile == null) return; //not clientside.
|
||||
|
||||
@@ -153,8 +146,8 @@ public class Fire extends TimedEntity implements SaveTrait, SyncTrait, Poolable{
|
||||
entity.damage(0.4f);
|
||||
}
|
||||
Damage.damageUnits(null, tile.worldx(), tile.worldy(), tilesize, 3f,
|
||||
unit -> !unit.isFlying() && !unit.isImmune(StatusEffects.burning),
|
||||
unit -> unit.applyEffect(StatusEffects.burning, 60 * 5));
|
||||
unit -> !unit.isFlying() && !unit.isImmune(StatusEffects.burning),
|
||||
unit -> unit.applyEffect(StatusEffects.burning, 60 * 5));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package io.anuke.mindustry.entities.effect;
|
||||
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.arc.util.Time;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.mindustry.entities.Effects.Effect;
|
||||
import io.anuke.mindustry.entities.Effects.EffectRenderer;
|
||||
import io.anuke.mindustry.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;
|
||||
|
||||
/**
|
||||
@@ -17,7 +17,7 @@ public class GroundEffectEntity extends EffectEntity{
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
GroundEffect effect = (GroundEffect) this.effect;
|
||||
GroundEffect effect = (GroundEffect)this.effect;
|
||||
|
||||
if(effect.isStatic){
|
||||
time += Time.delta();
|
||||
@@ -41,7 +41,7 @@ public class GroundEffectEntity extends EffectEntity{
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
GroundEffect effect = (GroundEffect) this.effect;
|
||||
GroundEffect effect = (GroundEffect)this.effect;
|
||||
|
||||
if(once && effect.isStatic)
|
||||
Effects.renderEffect(id, effect, color, lifetime(), rotation, x, y, data);
|
||||
|
||||
@@ -2,18 +2,16 @@ package io.anuke.mindustry.entities.effect;
|
||||
|
||||
import io.anuke.annotations.Annotations.Loc;
|
||||
import io.anuke.annotations.Annotations.Remote;
|
||||
import io.anuke.mindustry.entities.EntityGroup;
|
||||
import io.anuke.mindustry.entities.impl.TimedEntity;
|
||||
import io.anuke.mindustry.entities.traits.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.graphics.g2d.*;
|
||||
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.EntityGroup;
|
||||
import io.anuke.mindustry.entities.impl.TimedEntity;
|
||||
import io.anuke.mindustry.entities.traits.DrawTrait;
|
||||
import io.anuke.mindustry.entities.type.Unit;
|
||||
import io.anuke.mindustry.graphics.Pal;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
|
||||
@@ -4,27 +4,18 @@ 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.graphics.g2d.Fill;
|
||||
import io.anuke.arc.graphics.g2d.Lines;
|
||||
import io.anuke.mindustry.entities.EntityGroup;
|
||||
import io.anuke.mindustry.entities.impl.TimedEntity;
|
||||
import io.anuke.mindustry.entities.traits.DrawTrait;
|
||||
import io.anuke.mindustry.entities.traits.TimeTrait;
|
||||
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.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.graphics.g2d.*;
|
||||
import io.anuke.arc.math.*;
|
||||
import io.anuke.arc.math.geom.*;
|
||||
import io.anuke.arc.util.pooling.Pools;
|
||||
import io.anuke.mindustry.content.Bullets;
|
||||
import io.anuke.mindustry.entities.type.Unit;
|
||||
import io.anuke.mindustry.entities.EntityGroup;
|
||||
import io.anuke.mindustry.entities.Units;
|
||||
import io.anuke.mindustry.entities.bullet.Bullet;
|
||||
import io.anuke.mindustry.entities.traits.SyncTrait;
|
||||
import io.anuke.mindustry.entities.impl.TimedEntity;
|
||||
import io.anuke.mindustry.entities.traits.*;
|
||||
import io.anuke.mindustry.entities.type.Unit;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.gen.Call;
|
||||
import io.anuke.mindustry.graphics.Pal;
|
||||
@@ -48,16 +39,16 @@ public class Lightning extends TimedEntity implements DrawTrait, SyncTrait, Time
|
||||
private Array<Position> lines = new Array<>();
|
||||
private Color color = Pal.lancerLaser;
|
||||
|
||||
/**For pooling use only. Do not call directly!*/
|
||||
/** For pooling use only. Do not call directly! */
|
||||
public Lightning(){
|
||||
}
|
||||
|
||||
/**Create a lighting branch at a location. Use Team.none to damage everyone.*/
|
||||
/** Create a lighting branch at a location. Use Team.none to damage everyone. */
|
||||
public static void create(Team team, Color color, float damage, float x, float y, float targetAngle, int length){
|
||||
Call.createLighting(lastSeed++, team, color, damage, x, y, targetAngle, length);
|
||||
}
|
||||
|
||||
/**Do not invoke!*/
|
||||
/** Do not invoke! */
|
||||
@Remote(called = Loc.server)
|
||||
public static void createLighting(int seed, Team team, Color color, float damage, float x, float y, float rotation, int length){
|
||||
|
||||
@@ -72,7 +63,7 @@ public class Lightning extends TimedEntity implements DrawTrait, SyncTrait, Time
|
||||
random.setSeed(seed);
|
||||
hit.clear();
|
||||
|
||||
for (int i = 0; i < length/2; i++) {
|
||||
for(int i = 0; i < length / 2; i++){
|
||||
Bullet.create(Bullets.damageLightning, l, team, x, y, 0f, 1f, 1f, dmg);
|
||||
l.lines.add(new Vector2(x + Mathf.range(3f), y + Mathf.range(3f)));
|
||||
|
||||
@@ -94,8 +85,8 @@ public class Lightning extends TimedEntity implements DrawTrait, SyncTrait, Time
|
||||
y = furthest.y;
|
||||
}else{
|
||||
rotation += random.range(20f);
|
||||
x += Angles.trnsx(rotation, hitRange/2f);
|
||||
y += Angles.trnsy(rotation, hitRange/2f);
|
||||
x += Angles.trnsx(rotation, hitRange / 2f);
|
||||
y += Angles.trnsy(rotation, hitRange / 2f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -106,10 +97,12 @@ public class Lightning extends TimedEntity implements DrawTrait, SyncTrait, Time
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput data){}
|
||||
public void write(DataOutput data){
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput data){}
|
||||
public void read(DataInput data){
|
||||
}
|
||||
|
||||
@Override
|
||||
public float lifetime(){
|
||||
@@ -144,7 +137,7 @@ public class Lightning extends TimedEntity implements DrawTrait, SyncTrait, Time
|
||||
int i = 0;
|
||||
|
||||
for(Position p : lines){
|
||||
Fill.square(p.getX(), p.getY(), (5f - (float)i++/lines.size*2f) * fout(), 45);
|
||||
Fill.square(p.getX(), p.getY(), (5f - (float)i++ / lines.size * 2f) * fout(), 45);
|
||||
}
|
||||
Draw.reset();
|
||||
}
|
||||
|
||||
@@ -3,36 +3,25 @@ package io.anuke.mindustry.entities.effect;
|
||||
import io.anuke.annotations.Annotations.Loc;
|
||||
import io.anuke.annotations.Annotations.Remote;
|
||||
import io.anuke.arc.collection.IntMap;
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.mindustry.entities.EntityGroup;
|
||||
import io.anuke.mindustry.entities.impl.SolidEntity;
|
||||
import io.anuke.mindustry.entities.traits.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.math.geom.*;
|
||||
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;
|
||||
import io.anuke.mindustry.content.Bullets;
|
||||
import io.anuke.mindustry.content.Fx;
|
||||
import io.anuke.mindustry.entities.Units;
|
||||
import io.anuke.mindustry.entities.traits.SaveTrait;
|
||||
import io.anuke.mindustry.entities.traits.SyncTrait;
|
||||
import io.anuke.mindustry.content.*;
|
||||
import io.anuke.mindustry.entities.*;
|
||||
import io.anuke.mindustry.entities.impl.SolidEntity;
|
||||
import io.anuke.mindustry.entities.traits.*;
|
||||
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 java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
@@ -55,21 +44,21 @@ public class Puddle extends SolidEntity implements SaveTrait, Poolable, DrawTrai
|
||||
private float accepting;
|
||||
private byte generation;
|
||||
|
||||
/**Deserialization use only!*/
|
||||
/** Deserialization use only! */
|
||||
public Puddle(){
|
||||
}
|
||||
|
||||
/**Deposists a puddle between tile and source.*/
|
||||
/** Deposists a puddle between tile and source. */
|
||||
public static void deposit(Tile tile, Tile source, Liquid liquid, float amount){
|
||||
deposit(tile, source, liquid, amount, 0);
|
||||
}
|
||||
|
||||
/**Deposists a puddle at a tile.*/
|
||||
/** Deposists a puddle at a tile. */
|
||||
public static void deposit(Tile tile, Liquid liquid, float amount){
|
||||
deposit(tile, tile, liquid, amount, 0);
|
||||
}
|
||||
|
||||
/**Returns the puddle on the specified tile. May return null.*/
|
||||
/** Returns the puddle on the specified tile. May return null. */
|
||||
public static Puddle getPuddle(Tile tile){
|
||||
return map.get(tile.pos());
|
||||
}
|
||||
@@ -79,13 +68,13 @@ public class Puddle extends SolidEntity implements SaveTrait, Poolable, DrawTrai
|
||||
|
||||
if(tile.floor().isLiquid && !canStayOn(liquid, tile.floor().liquidDrop)){
|
||||
reactPuddle(tile.floor().liquidDrop, liquid, amount, tile,
|
||||
(tile.worldx() + source.worldx()) / 2f, (tile.worldy() + source.worldy()) / 2f);
|
||||
(tile.worldx() + source.worldx()) / 2f, (tile.worldy() + source.worldy()) / 2f);
|
||||
|
||||
Puddle p = map.get(tile.pos());
|
||||
|
||||
if(generation == 0 && p != null && p.lastRipple <= Time.time() - 40f){
|
||||
Effects.effect(Fx.ripple, tile.floor().liquidDrop.color,
|
||||
(tile.worldx() + source.worldx()) / 2f, (tile.worldy() + source.worldy()) / 2f);
|
||||
(tile.worldx() + source.worldx()) / 2f, (tile.worldy() + source.worldy()) / 2f);
|
||||
p.lastRipple = Time.time();
|
||||
}
|
||||
return;
|
||||
@@ -99,14 +88,14 @@ public class Puddle extends SolidEntity implements SaveTrait, Poolable, DrawTrai
|
||||
puddle.tile = tile;
|
||||
puddle.liquid = liquid;
|
||||
puddle.amount = amount;
|
||||
puddle.generation = (byte) generation;
|
||||
puddle.generation = (byte)generation;
|
||||
puddle.set((tile.worldx() + source.worldx()) / 2f, (tile.worldy() + source.worldy()) / 2f);
|
||||
puddle.add();
|
||||
map.put(tile.pos(), puddle);
|
||||
}else if(p.liquid == liquid){
|
||||
p.accepting = Math.max(amount, p.accepting);
|
||||
|
||||
if(generation == 0 && p.lastRipple <= Time.time() - 40f && p.amount >= maxLiquid / 2f){
|
||||
if(generation == 0 && p.lastRipple <= Time.time() - 40f && p.amount >= maxLiquid / 2f){
|
||||
Effects.effect(Fx.ripple, p.liquid.color, (tile.worldx() + source.worldx()) / 2f, (tile.worldy() + source.worldy()) / 2f);
|
||||
p.lastRipple = Time.time();
|
||||
}
|
||||
@@ -123,10 +112,10 @@ public class Puddle extends SolidEntity implements SaveTrait, Poolable, DrawTrai
|
||||
return liquid == Liquids.oil && other == Liquids.water;
|
||||
}
|
||||
|
||||
/**Reacts two liquids together at a location.*/
|
||||
/** Reacts two liquids together at a location. */
|
||||
private static float reactPuddle(Liquid dest, Liquid liquid, float amount, Tile tile, float x, float y){
|
||||
if((dest.flammability > 0.3f && liquid.temperature > 0.7f) ||
|
||||
(liquid.flammability > 0.3f && dest.temperature > 0.7f)){ //flammable liquid + hot liquid
|
||||
(liquid.flammability > 0.3f && dest.temperature > 0.7f)){ //flammable liquid + hot liquid
|
||||
Fire.create(tile);
|
||||
if(Mathf.chance(0.006 * amount)){
|
||||
Call.createBullet(Bullets.fireball, x, y, Mathf.random(360f));
|
||||
@@ -234,7 +223,7 @@ public class Puddle extends SolidEntity implements SaveTrait, Poolable, DrawTrai
|
||||
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(Time.time() + seeds * 532, sscl, smag),
|
||||
y + ey + Mathf.sin(Time.time() + seeds * 53, sscl, smag), f * 5f);
|
||||
y + ey + Mathf.sin(Time.time() + seeds * 53, sscl, smag), f * 5f);
|
||||
seeds++;
|
||||
});
|
||||
Draw.color();
|
||||
@@ -295,7 +284,7 @@ public class Puddle extends SolidEntity implements SaveTrait, Poolable, DrawTrai
|
||||
data.writeFloat(x);
|
||||
data.writeFloat(y);
|
||||
data.writeByte(liquid.id);
|
||||
data.writeShort((short) (amount * 4));
|
||||
data.writeShort((short)(amount * 4));
|
||||
data.writeInt(tile.pos());
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ public class RubbleDecal extends Decal{
|
||||
private static final TextureRegion[][] regions = new TextureRegion[16][0];
|
||||
private TextureRegion region;
|
||||
|
||||
/**Creates a rubble effect at a position. Provide a block size to use.*/
|
||||
/** Creates a rubble effect at a position. Provide a block size to use. */
|
||||
public static void create(float x, float y, int size){
|
||||
if(headless) return;
|
||||
|
||||
|
||||
@@ -40,10 +40,10 @@ public class ScorchDecal extends Decal{
|
||||
float space = 1.5f + Mathf.randomSeed(id + i + 1, 0, 20) / 10f;
|
||||
Draw.rect(region,
|
||||
x + Angles.trnsx(rotation, space),
|
||||
y + Angles.trnsy(rotation, space) + region.getHeight()/2f*Draw.scl,
|
||||
y + Angles.trnsy(rotation, space) + region.getHeight() / 2f * Draw.scl,
|
||||
region.getWidth() * Draw.scl,
|
||||
region.getHeight() * Draw.scl,
|
||||
region.getWidth()/2f*Draw.scl, 0, rotation - 90);
|
||||
region.getWidth() / 2f * Draw.scl, 0, rotation - 90);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package io.anuke.mindustry.entities.impl;
|
||||
|
||||
|
||||
import io.anuke.mindustry.entities.traits.DamageTrait;
|
||||
import io.anuke.mindustry.entities.traits.HealthTrait;
|
||||
import io.anuke.mindustry.entities.traits.SolidTrait;
|
||||
import io.anuke.mindustry.entities.traits.*;
|
||||
|
||||
public abstract class DestructibleEntity extends SolidEntity implements HealthTrait{
|
||||
public transient boolean dead;
|
||||
@@ -18,7 +16,7 @@ public abstract class DestructibleEntity extends SolidEntity implements HealthTr
|
||||
public void collision(SolidTrait other, float x, float y){
|
||||
if(other instanceof DamageTrait){
|
||||
onHit(other);
|
||||
damage(((DamageTrait) other).damage());
|
||||
damage(((DamageTrait)other).damage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,9 +5,7 @@ import io.anuke.arc.Events;
|
||||
import io.anuke.arc.collection.Array;
|
||||
import io.anuke.arc.collection.Queue;
|
||||
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.graphics.g2d.*;
|
||||
import io.anuke.arc.math.Angles;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.arc.math.geom.Vector2;
|
||||
@@ -16,29 +14,23 @@ import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.content.Blocks;
|
||||
import io.anuke.mindustry.content.Fx;
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.mindustry.entities.type.Player;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.entities.type.Unit;
|
||||
import io.anuke.mindustry.entities.type.*;
|
||||
import io.anuke.mindustry.game.EventType.BuildSelectEvent;
|
||||
import io.anuke.mindustry.gen.Call;
|
||||
import io.anuke.mindustry.graphics.Pal;
|
||||
import io.anuke.mindustry.graphics.Shapes;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Build;
|
||||
import io.anuke.mindustry.world.Pos;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.*;
|
||||
import io.anuke.mindustry.world.blocks.BuildBlock;
|
||||
import io.anuke.mindustry.world.blocks.BuildBlock.BuildEntity;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
import static io.anuke.mindustry.entities.traits.BuilderTrait.BuildDataStatic.*;
|
||||
import static io.anuke.mindustry.entities.traits.BuilderTrait.BuildDataStatic.removal;
|
||||
import static io.anuke.mindustry.entities.traits.BuilderTrait.BuildDataStatic.tmptr;
|
||||
|
||||
/**
|
||||
* Interface for units that build, break or mine things.
|
||||
@@ -54,25 +46,25 @@ public interface BuilderTrait extends Entity, TeamTrait{
|
||||
static Vector2[] tmptr = new Vector2[]{new Vector2(), new Vector2(), new Vector2(), new Vector2()};
|
||||
}
|
||||
|
||||
/**Returns the queue for storing build requests.*/
|
||||
/** Returns the queue for storing build requests. */
|
||||
Queue<BuildRequest> getPlaceQueue();
|
||||
|
||||
/**Returns the tile this builder is currently mining.*/
|
||||
/** Returns the tile this builder is currently mining. */
|
||||
Tile getMineTile();
|
||||
|
||||
/**Sets the tile this builder is currently mining.*/
|
||||
/** Sets the tile this builder is currently mining. */
|
||||
void setMineTile(Tile tile);
|
||||
|
||||
/**Returns the minining speed of this miner. 1 = standard, 0.5 = half speed, 2 = double speed, etc.*/
|
||||
/** Returns the minining speed of this miner. 1 = standard, 0.5 = half speed, 2 = double speed, etc. */
|
||||
float getMinePower();
|
||||
|
||||
/**Build power, can be any float. 1 = builds recipes in normal time, 0 = doesn't build at all.*/
|
||||
/** Build power, can be any float. 1 = builds recipes in normal time, 0 = doesn't build at all. */
|
||||
float getBuildPower(Tile tile);
|
||||
|
||||
/**Returns whether or not this builder can mine a specific item type.*/
|
||||
/** Returns whether or not this builder can mine a specific item type. */
|
||||
boolean canMine(Item item);
|
||||
|
||||
/**Whether this type of builder can begin creating new blocks.*/
|
||||
/** Whether this type of builder can begin creating new blocks. */
|
||||
default boolean canCreateBlocks(){
|
||||
return true;
|
||||
}
|
||||
@@ -106,13 +98,13 @@ public interface BuilderTrait extends Entity, TeamTrait{
|
||||
float progress = input.readFloat();
|
||||
BuildRequest request;
|
||||
|
||||
if(type == 1){ //remove
|
||||
request = new BuildRequest(Pos.x(position), Pos.y(position));
|
||||
}else{ //place
|
||||
byte block = input.readByte();
|
||||
byte rotation = input.readByte();
|
||||
request = new BuildRequest(Pos.x(position), Pos.y(position), rotation, content.block(block));
|
||||
}
|
||||
if(type == 1){ //remove
|
||||
request = new BuildRequest(Pos.x(position), Pos.y(position));
|
||||
}else{ //place
|
||||
byte block = input.readByte();
|
||||
byte rotation = input.readByte();
|
||||
request = new BuildRequest(Pos.x(position), Pos.y(position), rotation, content.block(block));
|
||||
}
|
||||
|
||||
request.progress = progress;
|
||||
|
||||
@@ -124,17 +116,17 @@ public interface BuilderTrait extends Entity, TeamTrait{
|
||||
}
|
||||
}
|
||||
|
||||
/**Return whether this builder's place queue contains items.*/
|
||||
/** Return whether this builder's place queue contains items. */
|
||||
default boolean isBuilding(){
|
||||
return getPlaceQueue().size != 0;
|
||||
}
|
||||
|
||||
/**Clears the placement queue.*/
|
||||
/** Clears the placement queue. */
|
||||
default void clearBuilding(){
|
||||
getPlaceQueue().clear();
|
||||
}
|
||||
|
||||
/**Add another build requests to the tail of the queue, if it doesn't exist there yet.*/
|
||||
/** Add another build requests to the tail of the queue, if it doesn't exist there yet. */
|
||||
default void addBuildRequest(BuildRequest place){
|
||||
for(BuildRequest request : getPlaceQueue()){
|
||||
if(request.x == place.x && request.y == place.y){
|
||||
@@ -172,8 +164,8 @@ public interface BuilderTrait extends Entity, TeamTrait{
|
||||
|
||||
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.block.rotate)
|
||||
&& world.tile(request.x, request.y).block() == request.block))){
|
||||
(!request.breaking && (world.tile(request.x, request.y).getRotation() == request.rotation || !request.block.rotate)
|
||||
&& world.tile(request.x, request.y).block() == request.block))){
|
||||
getPlaceQueue().addLast(request);
|
||||
}
|
||||
}
|
||||
@@ -249,14 +241,14 @@ public interface BuilderTrait extends Entity, TeamTrait{
|
||||
}
|
||||
}
|
||||
|
||||
/**Do not call directly.*/
|
||||
/** Do not call directly. */
|
||||
default void updateMining(){
|
||||
Unit unit = (Unit)this;
|
||||
Tile tile = getMineTile();
|
||||
TileEntity core = unit.getClosestCore();
|
||||
|
||||
if(core == null || tile.block() != Blocks.air || dst(tile.worldx(), tile.worldy()) > mineDistance
|
||||
|| tile.drop() == null || !unit.acceptsItem(tile.drop()) || !canMine(tile.drop())){
|
||||
|| tile.drop() == null || !unit.acceptsItem(tile.drop()) || !canMine(tile.drop())){
|
||||
setMineTile(null);
|
||||
}else{
|
||||
Item item = tile.drop();
|
||||
@@ -266,25 +258,25 @@ public interface BuilderTrait extends Entity, TeamTrait{
|
||||
|
||||
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);
|
||||
tile.worldx() + Mathf.range(tilesize / 2f),
|
||||
tile.worldy() + Mathf.range(tilesize / 2f), core.tile);
|
||||
}else if(unit.acceptsItem(item)){
|
||||
Call.transferItemToUnit(item,
|
||||
tile.worldx() + Mathf.range(tilesize / 2f),
|
||||
tile.worldy() + Mathf.range(tilesize / 2f),
|
||||
unit);
|
||||
tile.worldx() + Mathf.range(tilesize / 2f),
|
||||
tile.worldy() + Mathf.range(tilesize / 2f),
|
||||
unit);
|
||||
}
|
||||
}
|
||||
|
||||
if(Mathf.chance(0.06 * Time.delta())){
|
||||
Effects.effect(Fx.pulverizeSmall,
|
||||
tile.worldx() + Mathf.range(tilesize / 2f),
|
||||
tile.worldy() + Mathf.range(tilesize / 2f), 0f, item.color);
|
||||
tile.worldx() + Mathf.range(tilesize / 2f),
|
||||
tile.worldy() + Mathf.range(tilesize / 2f), 0f, item.color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**Draw placement effects for an entity. This includes mining*/
|
||||
/** Draw placement effects for an entity. This includes mining */
|
||||
default void drawBuilding(){
|
||||
Unit unit = (Unit)this;
|
||||
BuildRequest request;
|
||||
@@ -317,10 +309,10 @@ public interface BuilderTrait extends Entity, TeamTrait{
|
||||
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;
|
||||
x3 = tmptr[1].x, y3 = tmptr[1].y;
|
||||
|
||||
Draw.alpha(1f);
|
||||
|
||||
@@ -332,7 +324,7 @@ public interface BuilderTrait extends Entity, TeamTrait{
|
||||
Draw.color();
|
||||
}
|
||||
|
||||
/**Internal use only.*/
|
||||
/** Internal use only. */
|
||||
default void drawMining(){
|
||||
Unit unit = (Unit)this;
|
||||
Tile tile = getMineTile();
|
||||
@@ -353,7 +345,7 @@ public interface BuilderTrait extends Entity, TeamTrait{
|
||||
|
||||
Shapes.laser("minelaser", "minelaser-end", px, py, ex, ey, 0.75f);
|
||||
|
||||
if(unit instanceof Player && ((Player) unit).isLocal){
|
||||
if(unit instanceof Player && ((Player)unit).isLocal){
|
||||
Lines.stroke(1f, Pal.accent);
|
||||
Lines.poly(tile.worldx(), tile.worldy(), 4, tilesize / 2f * Mathf.sqrt2, Time.time());
|
||||
}
|
||||
@@ -361,7 +353,7 @@ public interface BuilderTrait extends Entity, TeamTrait{
|
||||
Draw.color();
|
||||
}
|
||||
|
||||
/**Class for storing build requests. Can be either a place or remove request.*/
|
||||
/** Class for storing build requests. Can be either a place or remove request. */
|
||||
class BuildRequest{
|
||||
public final int x, y, rotation;
|
||||
public final Block block;
|
||||
@@ -370,7 +362,7 @@ public interface BuilderTrait extends Entity, TeamTrait{
|
||||
public float progress;
|
||||
public boolean initialized;
|
||||
|
||||
/**This creates a build request.*/
|
||||
/** This creates a build request. */
|
||||
public BuildRequest(int x, int y, int rotation, Block block){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
@@ -379,7 +371,7 @@ public interface BuilderTrait extends Entity, TeamTrait{
|
||||
this.breaking = false;
|
||||
}
|
||||
|
||||
/**This creates a remove request.*/
|
||||
/** This creates a remove request. */
|
||||
public BuildRequest(int x, int y){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package io.anuke.mindustry.entities.traits;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
|
||||
public interface Saveable{
|
||||
void writeSave(DataOutput stream) throws IOException;
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package io.anuke.mindustry.entities.traits;
|
||||
|
||||
|
||||
import io.anuke.mindustry.entities.EntityQuery;
|
||||
import io.anuke.arc.math.geom.Position;
|
||||
import io.anuke.arc.math.geom.*;
|
||||
import io.anuke.arc.math.geom.QuadTree.QuadTreeObject;
|
||||
import io.anuke.arc.math.geom.Rectangle;
|
||||
import io.anuke.arc.math.geom.Vector2;
|
||||
import io.anuke.mindustry.entities.EntityQuery;
|
||||
|
||||
public interface SolidTrait extends QuadTreeObject, MoveTrait, VelocityTrait, Entity, Position{
|
||||
|
||||
@@ -35,7 +33,8 @@ public interface SolidTrait extends QuadTreeObject, MoveTrait, VelocityTrait, En
|
||||
return true;
|
||||
}
|
||||
|
||||
default void collision(SolidTrait other, float x, float y){}
|
||||
default void collision(SolidTrait other, float x, float y){
|
||||
}
|
||||
|
||||
default void move(float x, float y){
|
||||
EntityQuery.collisions().move(this, x, y);
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
package io.anuke.mindustry.entities.traits;
|
||||
|
||||
import io.anuke.mindustry.core.NetClient;
|
||||
import io.anuke.mindustry.net.Interpolator;
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.arc.util.Tmp;
|
||||
import io.anuke.mindustry.core.NetClient;
|
||||
import io.anuke.mindustry.net.Interpolator;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
|
||||
public interface SyncTrait extends Entity, TypeTrait{
|
||||
|
||||
/**Sets the position of this entity and updated the interpolator.*/
|
||||
/** Sets the position of this entity and updated the interpolator. */
|
||||
default void setNet(float x, float y){
|
||||
set(x, y);
|
||||
|
||||
@@ -24,7 +22,7 @@ public interface SyncTrait extends Entity, TypeTrait{
|
||||
}
|
||||
}
|
||||
|
||||
/**Interpolate entity position only. Override if you need to interpolate rotations or other values.*/
|
||||
/** Interpolate entity position only. Override if you need to interpolate rotations or other values. */
|
||||
default void interpolate(){
|
||||
if(getInterpolator() == null){
|
||||
throw new RuntimeException("This entity must have an interpolator to interpolate()!");
|
||||
@@ -47,17 +45,17 @@ public interface SyncTrait extends Entity, TypeTrait{
|
||||
setY(getInterpolator().pos.y);
|
||||
}
|
||||
|
||||
/**Return the interpolator used for smoothing the position. Optional.*/
|
||||
/** Return the interpolator used for smoothing the position. Optional. */
|
||||
default Interpolator getInterpolator(){
|
||||
return null;
|
||||
}
|
||||
|
||||
/**Whether syncing is enabled for this entity; true by default.*/
|
||||
/** Whether syncing is enabled for this entity; true by default. */
|
||||
default boolean isSyncing(){
|
||||
return true;
|
||||
}
|
||||
|
||||
/**Whether this entity is clipped and not synced when out of viewport.*/
|
||||
/** Whether this entity is clipped and not synced when out of viewport. */
|
||||
default boolean isClipped(){
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -14,14 +14,14 @@ public interface TargetTrait extends Position, VelocityTrait{
|
||||
|
||||
default float getTargetVelocityX(){
|
||||
if(this instanceof SolidTrait){
|
||||
return ((SolidTrait) this).getDeltaX();
|
||||
return ((SolidTrait)this).getDeltaX();
|
||||
}
|
||||
return velocity().x;
|
||||
}
|
||||
|
||||
default float getTargetVelocityY(){
|
||||
if(this instanceof SolidTrait){
|
||||
return ((SolidTrait) this).getDeltaY();
|
||||
return ((SolidTrait)this).getDeltaY();
|
||||
}
|
||||
return velocity().y;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public interface VelocityTrait extends MoveTrait{
|
||||
velocity().scl(1f - drag() * Time.delta());
|
||||
|
||||
if(this instanceof SolidTrait){
|
||||
((SolidTrait) this).move(velocity().x * Time.delta(), velocity().y * Time.delta());
|
||||
((SolidTrait)this).move(velocity().x * Time.delta(), velocity().y * Time.delta());
|
||||
}else{
|
||||
moveBy(velocity().x * Time.delta(), velocity().y * Time.delta());
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ import java.io.*;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
/**Base class for AI units.*/
|
||||
/** Base class for AI units. */
|
||||
public abstract class BaseUnit extends Unit implements ShooterTrait{
|
||||
|
||||
protected static int timerIndex = 0;
|
||||
@@ -45,7 +45,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
||||
|
||||
protected int spawner = noSpawner;
|
||||
|
||||
/**internal constructor used for deserialization, DO NOT USE*/
|
||||
/** internal constructor used for deserialization, DO NOT USE */
|
||||
public BaseUnit(){
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
||||
return type.drag;
|
||||
}
|
||||
|
||||
/**Initialize the type and team of this unit. Only call once!*/
|
||||
/** Initialize the type and team of this unit. Only call once! */
|
||||
public void init(UnitType type, Team team){
|
||||
if(this.type != null) throw new RuntimeException("This unit is already initialized!");
|
||||
|
||||
@@ -99,7 +99,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
||||
}
|
||||
|
||||
public boolean targetHasFlag(BlockFlag flag){
|
||||
return target instanceof TileEntity && ((TileEntity) target).tile.block().flags.contains(flag);
|
||||
return target instanceof TileEntity && ((TileEntity)target).tile.block().flags.contains(flag);
|
||||
}
|
||||
|
||||
public void setState(UnitState state){
|
||||
@@ -112,14 +112,14 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
||||
}
|
||||
}
|
||||
|
||||
/**Only runs when the unit has a target.*/
|
||||
/** Only runs when the unit has a target. */
|
||||
public void behavior(){
|
||||
|
||||
}
|
||||
|
||||
public void updateTargeting(){
|
||||
if(target == null || (target instanceof Unit && (target.isDead() || target.getTeam() == team))
|
||||
|| (target instanceof TileEntity && ((TileEntity) target).tile.entity == null)){
|
||||
|| (target instanceof TileEntity && ((TileEntity)target).tile.entity == null)){
|
||||
target = null;
|
||||
}
|
||||
}
|
||||
@@ -166,9 +166,9 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
||||
float angT = i == 0 ? 0 : Mathf.randomSeedRange(i + 2, 60f);
|
||||
float lenT = i == 0 ? 0 : Mathf.randomSeedRange(i + 3, 1f) - 1f;
|
||||
Draw.rect(item.item.icon(Item.Icon.large),
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,11 +127,11 @@ public abstract class FlyingUnit extends BaseUnit{
|
||||
public void drawEngine(){
|
||||
Draw.color(Pal.engine);
|
||||
Fill.circle(x + Angles.trnsx(rotation + 180, type.engineOffset), y + Angles.trnsy(rotation + 180, type.engineOffset),
|
||||
type.engineSize + Mathf.absin(Time.time(), 2f, type.engineSize/4f));
|
||||
type.engineSize + Mathf.absin(Time.time(), 2f, type.engineSize / 4f));
|
||||
|
||||
Draw.color(Color.WHITE);
|
||||
Fill.circle(x + Angles.trnsx(rotation + 180, type.engineOffset-1f), y + Angles.trnsy(rotation + 180, type.engineOffset-1f),
|
||||
(type.engineSize + Mathf.absin(Time.time(), 2f, type.engineSize/4f)) / 2f);
|
||||
Fill.circle(x + Angles.trnsx(rotation + 180, type.engineOffset - 1f), y + Angles.trnsy(rotation + 180, type.engineOffset - 1f),
|
||||
(type.engineSize + Mathf.absin(Time.time(), 2f, type.engineSize / 4f)) / 2f);
|
||||
Draw.color();
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ public abstract class FlyingUnit extends BaseUnit{
|
||||
if(Units.invalidateTarget(target, this)){
|
||||
for(boolean left : Mathf.booleans){
|
||||
int wi = Mathf.num(left);
|
||||
weaponAngles[wi] = Mathf.slerpDelta(weaponAngles[wi],rotation, 0.1f);
|
||||
weaponAngles[wi] = Mathf.slerpDelta(weaponAngles[wi], rotation, 0.1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -154,8 +154,8 @@ public abstract class FlyingUnit extends BaseUnit{
|
||||
protected void wobble(){
|
||||
if(Net.client()) return;
|
||||
|
||||
x += Mathf.sin(Time.time() + id * 999, 25f, 0.05f)*Time.delta();
|
||||
y += Mathf.cos(Time.time() + id * 999, 25f, 0.05f)*Time.delta();
|
||||
x += Mathf.sin(Time.time() + id * 999, 25f, 0.05f) * Time.delta();
|
||||
y += Mathf.cos(Time.time() + id * 999, 25f, 0.05f) * Time.delta();
|
||||
|
||||
if(velocity.len() <= 0.05f){
|
||||
//rotation += Mathf.sin(Time.time() + id * 99, 10f, 2f * type.speed)*Time.delta();
|
||||
|
||||
@@ -111,7 +111,7 @@ public abstract class GroundUnit extends BaseUnit{
|
||||
public void draw(){
|
||||
Draw.mixcol(Color.WHITE, hitTime / hitDuration);
|
||||
|
||||
float ft = Mathf.sin(walkTime * type.speed*5f, 6f, 2f + type.hitsize/15f);
|
||||
float ft = Mathf.sin(walkTime * type.speed * 5f, 6f, 2f + type.hitsize / 15f);
|
||||
|
||||
Floor floor = getFloorOn();
|
||||
|
||||
@@ -121,9 +121,9 @@ public abstract class GroundUnit extends BaseUnit{
|
||||
|
||||
for(int i : Mathf.signs){
|
||||
Draw.rect(type.legRegion,
|
||||
x + Angles.trnsx(baseRotation, ft * i),
|
||||
y + Angles.trnsy(baseRotation, ft * i),
|
||||
type.legRegion.getWidth() * i * Draw.scl, type.legRegion.getHeight() * Draw.scl - Mathf.clamp(ft * i, 0, 2), baseRotation - 90);
|
||||
x + Angles.trnsx(baseRotation, ft * i),
|
||||
y + Angles.trnsy(baseRotation, ft * i),
|
||||
type.legRegion.getWidth() * i * Draw.scl, type.legRegion.getHeight() * Draw.scl - Mathf.clamp(ft * i, 0, 2), baseRotation - 90);
|
||||
}
|
||||
|
||||
if(floor.isLiquid){
|
||||
@@ -138,10 +138,10 @@ public abstract class GroundUnit extends BaseUnit{
|
||||
|
||||
for(int i : Mathf.signs){
|
||||
float tra = rotation - 90, trY = -type.weapon.getRecoil(this, i > 0) + type.weaponOffsetY;
|
||||
float w = - i * type.weapon.region.getWidth() * Draw.scl;
|
||||
float w = -i * type.weapon.region.getWidth() * Draw.scl;
|
||||
Draw.rect(type.weapon.region,
|
||||
x + Angles.trnsx(tra, getWeapon().width * i, trY),
|
||||
y + Angles.trnsy(tra, getWeapon().width * i, trY), w, type.weapon.region.getHeight() * Draw.scl, rotation - 90);
|
||||
x + Angles.trnsx(tra, getWeapon().width * i, trY),
|
||||
y + Angles.trnsy(tra, getWeapon().width * i, trY), w, type.weapon.region.getHeight() * Draw.scl, rotation - 90);
|
||||
}
|
||||
|
||||
drawItems();
|
||||
@@ -211,7 +211,7 @@ public abstract class GroundUnit extends BaseUnit{
|
||||
|
||||
if(tile == targetTile) return;
|
||||
|
||||
velocity.add(vec.trns(angleTo(targetTile), type.speed*Time.delta()));
|
||||
velocity.add(vec.trns(angleTo(targetTile), type.speed * Time.delta()));
|
||||
if(Units.invalidateTarget(target, this)){
|
||||
rotation = Mathf.slerpDelta(rotation, baseRotation, type.rotatespeed);
|
||||
}
|
||||
@@ -235,7 +235,7 @@ public abstract class GroundUnit extends BaseUnit{
|
||||
|
||||
if(tile == targetTile || core == null || dst(core) < 90f) return;
|
||||
|
||||
velocity.add(vec.trns(angleTo(targetTile), type.speed*Time.delta()));
|
||||
velocity.add(vec.trns(angleTo(targetTile), type.speed * Time.delta()));
|
||||
rotation = Mathf.slerpDelta(rotation, baseRotation, type.rotatespeed);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -365,11 +365,11 @@ public class Player extends Unit implements BuilderTrait, ShooterTrait{
|
||||
float size = mech.engineSize * (mech.flying ? 1f : boostHeat);
|
||||
Draw.color(mech.engineColor);
|
||||
Fill.circle(x + Angles.trnsx(rotation + 180, mech.engineOffset), y + Angles.trnsy(rotation + 180, mech.engineOffset),
|
||||
size + Mathf.absin(Time.time(), 2f, size/4f));
|
||||
size + Mathf.absin(Time.time(), 2f, size / 4f));
|
||||
|
||||
Draw.color(Color.WHITE);
|
||||
Fill.circle(x + Angles.trnsx(rotation + 180, mech.engineOffset-1f), y + Angles.trnsy(rotation + 180, mech.engineOffset-1f),
|
||||
(size + Mathf.absin(Time.time(), 2f, size/4f)) / 2f);
|
||||
Fill.circle(x + Angles.trnsx(rotation + 180, mech.engineOffset - 1f), y + Angles.trnsy(rotation + 180, mech.engineOffset - 1f),
|
||||
(size + Mathf.absin(Time.time(), 2f, size / 4f)) / 2f);
|
||||
Draw.color();
|
||||
}
|
||||
|
||||
@@ -443,15 +443,16 @@ public class Player extends Unit implements BuilderTrait, ShooterTrait{
|
||||
TextureRegion region = draw.region;
|
||||
|
||||
Draw.rect(region,
|
||||
request.x * tilesize + request.block.offset(), request.y * tilesize + request.block.offset(),
|
||||
region.getWidth() * 1f * Draw.scl * draw.scalex,
|
||||
region.getHeight() * 1f * Draw.scl * draw.scaley, request.block.rotate ? draw.rotation * 90 : 0);
|
||||
request.x * tilesize + request.block.offset(), request.y * tilesize + request.block.offset(),
|
||||
region.getWidth() * 1f * Draw.scl * draw.scalex,
|
||||
region.getHeight() * 1f * Draw.scl * draw.scaley, request.block.rotate ? draw.rotation * 90 : 0);
|
||||
|
||||
Draw.color(Pal.accent);
|
||||
for(int i = 0; i < 4; i++){
|
||||
Point2 p = Geometry.d8edge[i];
|
||||
float offset = -Math.max(request.block.size-1, 0)/2f * tilesize;
|
||||
if(i % 2 == 0) Draw.rect("block-select", request.x * tilesize + request.block.offset() + offset * p.x, request.y * tilesize + request.block.offset() + offset * p.y, i * 90);
|
||||
float offset = -Math.max(request.block.size - 1, 0) / 2f * tilesize;
|
||||
if(i % 2 == 0)
|
||||
Draw.rect("block-select", request.x * tilesize + request.block.offset() + offset * p.x, request.y * tilesize + request.block.offset() + offset * p.y, i * 90);
|
||||
}
|
||||
Draw.color();
|
||||
|
||||
@@ -615,7 +616,7 @@ public class Player extends Unit implements BuilderTrait, ShooterTrait{
|
||||
}
|
||||
|
||||
protected void updateFlying(){
|
||||
if(Units.invalidateTarget(target, this) && !(target instanceof TileEntity && ((TileEntity) target).damaged() && target.getTeam() == team &&
|
||||
if(Units.invalidateTarget(target, this) && !(target instanceof TileEntity && ((TileEntity)target).damaged() && target.getTeam() == team &&
|
||||
mech.canHeal && dst(target) < getWeapon().bullet.range())){
|
||||
target = null;
|
||||
}
|
||||
@@ -635,7 +636,7 @@ public class Player extends Unit implements BuilderTrait, ShooterTrait{
|
||||
|
||||
if(dst(moveTarget) < 2f){
|
||||
if(tapping){
|
||||
Tile tile = ((TileEntity) moveTarget).tile;
|
||||
Tile tile = ((TileEntity)moveTarget).tile;
|
||||
tile.block().tapped(tile, this);
|
||||
}
|
||||
|
||||
@@ -695,7 +696,7 @@ public class Player extends Unit implements BuilderTrait, ShooterTrait{
|
||||
if(target != null && dst(target) > getWeapon().bullet.range()){
|
||||
target = null;
|
||||
}else if(target != null){
|
||||
target = ((Tile) target).entity;
|
||||
target = ((Tile)target).entity;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -703,7 +704,7 @@ public class Player extends Unit implements BuilderTrait, ShooterTrait{
|
||||
setMineTile(null);
|
||||
}
|
||||
}
|
||||
}else if(target.isValid() || (target instanceof TileEntity && ((TileEntity) target).damaged() && target.getTeam() == team &&
|
||||
}else if(target.isValid() || (target instanceof TileEntity && ((TileEntity)target).damaged() && target.getTeam() == team &&
|
||||
mech.canHeal && dst(target) < getWeapon().bullet.range())){
|
||||
//rotate toward and shoot the target
|
||||
if(mech.turnCursor){
|
||||
@@ -840,7 +841,7 @@ public class Player extends Unit implements BuilderTrait, ShooterTrait{
|
||||
buffer.writeByte(mech.id);
|
||||
buffer.writeInt(mining == null ? noSpawner : mining.pos());
|
||||
buffer.writeInt(spawner == null ? noSpawner : spawner.getTile().pos());
|
||||
buffer.writeShort((short) (baseRotation * 2));
|
||||
buffer.writeShort((short)(baseRotation * 2));
|
||||
|
||||
writeBuilding(buffer);
|
||||
}
|
||||
|
||||
@@ -20,18 +20,11 @@ import io.anuke.mindustry.entities.traits.TargetTrait;
|
||||
import io.anuke.mindustry.game.EventType.BlockDestroyEvent;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.gen.Call;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Edges;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.*;
|
||||
import io.anuke.mindustry.world.blocks.defense.Wall;
|
||||
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.mindustry.world.modules.*;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
|
||||
import static io.anuke.mindustry.Vars.tileGroup;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
@@ -39,7 +32,7 @@ import static io.anuke.mindustry.Vars.world;
|
||||
public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
||||
public static final float timeToSleep = 60f * 4; //4 seconds to fall asleep
|
||||
private static final ObjectSet<Tile> tmpTiles = new ObjectSet<>();
|
||||
/**This value is only used for debugging.*/
|
||||
/** This value is only used for debugging. */
|
||||
public static int sleepingEntities = 0;
|
||||
|
||||
public Tile tile;
|
||||
@@ -53,7 +46,7 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
||||
public LiquidModule liquids;
|
||||
public ConsumeModule cons;
|
||||
|
||||
/**List of (cached) tiles with entities in proximity, used for outputting to*/
|
||||
/** List of (cached) tiles with entities in proximity, used for outputting to */
|
||||
private Array<Tile> proximity = new Array<>(8);
|
||||
private boolean dead = false;
|
||||
private boolean sleeping;
|
||||
@@ -76,7 +69,7 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
||||
tile.entity.onDeath();
|
||||
}
|
||||
|
||||
/**Sets this tile entity data to this tile, and adds it if necessary.*/
|
||||
/** Sets this tile entity data to this tile, and adds it if necessary. */
|
||||
public TileEntity init(Tile tile, boolean shouldAdd){
|
||||
this.tile = tile;
|
||||
x = tile.drawx();
|
||||
@@ -93,12 +86,12 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
||||
return this;
|
||||
}
|
||||
|
||||
/**Scaled delta.*/
|
||||
/** Scaled delta. */
|
||||
public float delta(){
|
||||
return Time.delta() * timeScale;
|
||||
}
|
||||
|
||||
/**Call when nothing is happening to the entity. This increments the internal sleep timer.*/
|
||||
/** Call when nothing is happening to the entity. This increments the internal sleep timer. */
|
||||
public void sleep(){
|
||||
sleepTime += Time.delta();
|
||||
if(!sleeping && sleepTime >= timeToSleep){
|
||||
@@ -108,7 +101,7 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
||||
}
|
||||
}
|
||||
|
||||
/**Call when this entity is updating. This wakes it up.*/
|
||||
/** Call when this entity is updating. This wakes it up. */
|
||||
public void noSleep(){
|
||||
sleepTime = 0f;
|
||||
if(sleeping){
|
||||
@@ -126,13 +119,17 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
||||
return dead || tile.entity != this;
|
||||
}
|
||||
|
||||
public void write(DataOutput stream) throws IOException{}
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
}
|
||||
|
||||
public void writeConfig(DataOutput stream) throws IOException{}
|
||||
public void writeConfig(DataOutput stream) throws IOException{
|
||||
}
|
||||
|
||||
public void read(DataInput stream) throws IOException{}
|
||||
public void read(DataInput stream) throws IOException{
|
||||
}
|
||||
|
||||
public void readConfig(DataInput stream) throws IOException{}
|
||||
public void readConfig(DataInput stream) throws IOException{
|
||||
}
|
||||
|
||||
public boolean collide(Bullet other){
|
||||
return true;
|
||||
@@ -269,7 +266,7 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
||||
public void update(){
|
||||
//TODO better smoke effect, this one is awful
|
||||
if(health != 0 && health < block.health && !(block instanceof Wall) &&
|
||||
Mathf.chance(0.009f * Time.delta() * (1f - health / block.health))){
|
||||
Mathf.chance(0.009f * Time.delta() * (1f - health / block.health))){
|
||||
Effects.effect(Fx.smoke, x + Mathf.range(4), y + Mathf.range(4));
|
||||
}
|
||||
|
||||
|
||||
@@ -24,26 +24,21 @@ import io.anuke.mindustry.game.Teams.TeamData;
|
||||
import io.anuke.mindustry.graphics.Pal;
|
||||
import io.anuke.mindustry.net.Interpolator;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.ItemStack;
|
||||
import io.anuke.mindustry.type.StatusEffect;
|
||||
import io.anuke.mindustry.type.Weapon;
|
||||
import io.anuke.mindustry.type.*;
|
||||
import io.anuke.mindustry.world.Pos;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.Floor;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public abstract class Unit extends DestructibleEntity implements SaveTrait, TargetTrait, SyncTrait, DrawTrait, TeamTrait{
|
||||
/**Total duration of hit flash effect*/
|
||||
/** Total duration of hit flash effect */
|
||||
public static final float hitDuration = 9f;
|
||||
/**Percision divisor of velocity, used when writing. For example a value of '2' would mean the percision is 1/2 = 0.5-size chunks.*/
|
||||
/** Percision divisor of velocity, used when writing. For example a value of '2' would mean the percision is 1/2 = 0.5-size chunks. */
|
||||
public static final float velocityPercision = 8f;
|
||||
/**Maximum absolute value of a velocity vector component.*/
|
||||
/** Maximum absolute value of a velocity vector component. */
|
||||
public static final float maxAbsVelocity = 127f / velocityPercision;
|
||||
public static final int noSpawner = Pos.get(-1, 1);
|
||||
|
||||
@@ -106,9 +101,9 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
||||
if(isDead()) return false;
|
||||
|
||||
if(other instanceof DamageTrait){
|
||||
return other instanceof TeamTrait && state.teams.areEnemies((((TeamTrait) other).getTeam()), team);
|
||||
return other instanceof TeamTrait && state.teams.areEnemies((((TeamTrait)other).getTeam()), team);
|
||||
}else{
|
||||
return other instanceof Unit && ((Unit) other).isFlying() == isFlying();
|
||||
return other instanceof Unit && ((Unit)other).isFlying() == isFlying();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,10 +193,10 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
||||
stream.writeBoolean(isDead());
|
||||
stream.writeFloat(net ? interpolator.target.x : x);
|
||||
stream.writeFloat(net ? interpolator.target.y : y);
|
||||
stream.writeByte((byte) (Mathf.clamp(velocity.x, -maxAbsVelocity, maxAbsVelocity) * velocityPercision));
|
||||
stream.writeByte((byte) (Mathf.clamp(velocity.y, -maxAbsVelocity, maxAbsVelocity) * velocityPercision));
|
||||
stream.writeShort((short) (rotation * 2));
|
||||
stream.writeShort((short) health);
|
||||
stream.writeByte((byte)(Mathf.clamp(velocity.x, -maxAbsVelocity, maxAbsVelocity) * velocityPercision));
|
||||
stream.writeByte((byte)(Mathf.clamp(velocity.y, -maxAbsVelocity, maxAbsVelocity) * velocityPercision));
|
||||
stream.writeShort((short)(rotation * 2));
|
||||
stream.writeShort((short)health);
|
||||
stream.writeByte(item.item.id);
|
||||
stream.writeShort((short)item.amount);
|
||||
status.writeSave(stream);
|
||||
@@ -258,10 +253,10 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
||||
moveVector.setZero();
|
||||
for(int cx = -rad; cx <= rad; cx++){
|
||||
for(int cy = -rad; cy <= rad; cy++){
|
||||
Tile tile = world.tileWorld(x + cx*tilesize, y + cy*tilesize);
|
||||
Tile tile = world.tileWorld(x + cx * tilesize, y + cy * tilesize);
|
||||
if(tile == null) continue;
|
||||
int weight = flying ? tile.airWeight : tile.weight;
|
||||
float scl = (rad - Mathf.dst(tile.worldx(), tile.worldy(), x, y)/(8f * 1.2f * Mathf.sqrt2)) * 0.1f;
|
||||
float scl = (rad - Mathf.dst(tile.worldx(), tile.worldy(), x, y) / (8f * 1.2f * Mathf.sqrt2)) * 0.1f;
|
||||
|
||||
moveVector.add(Mathf.sign(x - tile.worldx()) * scaling * weight * scl, Mathf.sign(y - tile.worldy()) * scaling * weight * scl);
|
||||
}
|
||||
@@ -301,12 +296,13 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
||||
|
||||
public Floor getFloorOn(){
|
||||
Tile tile = world.tileWorld(x, y);
|
||||
return tile == null ? (Floor) Blocks.air : tile.floor();
|
||||
return tile == null ? (Floor)Blocks.air : tile.floor();
|
||||
}
|
||||
|
||||
public void onRespawn(Tile tile){}
|
||||
public void onRespawn(Tile tile){
|
||||
}
|
||||
|
||||
/**Updates velocity and status effects.*/
|
||||
/** Updates velocity and status effects. */
|
||||
public void updateVelocityStatus(){
|
||||
Floor floor = getFloorOn();
|
||||
|
||||
@@ -314,7 +310,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
||||
|
||||
status.update(this);
|
||||
|
||||
velocity.limit(maxVelocity()).scl(1f + (status.getSpeedMultiplier()-1f) * Time.delta());
|
||||
velocity.limit(maxVelocity()).scl(1f + (status.getSpeedMultiplier() - 1f) * Time.delta());
|
||||
|
||||
if(x < -finalWorldBounds || y < -finalWorldBounds || x >= world.width() * tilesize + finalWorldBounds || y >= world.height() * tilesize + finalWorldBounds){
|
||||
kill();
|
||||
@@ -420,7 +416,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
||||
}
|
||||
|
||||
public void drawStats(){
|
||||
Draw.color(Color.BLACK, team.color, healthf() + Mathf.absin(Time.time(), healthf()*5f, 1f - healthf()));
|
||||
Draw.color(Color.BLACK, team.color, healthf() + Mathf.absin(Time.time(), healthf() * 5f, 1f - healthf()));
|
||||
Draw.rect(getPowerCellRegion(), x, y, rotation - 90);
|
||||
Draw.color();
|
||||
}
|
||||
|
||||
@@ -2,31 +2,24 @@ package io.anuke.mindustry.entities.type.base;
|
||||
|
||||
import io.anuke.arc.Events;
|
||||
import io.anuke.arc.collection.Queue;
|
||||
import io.anuke.mindustry.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;
|
||||
import io.anuke.mindustry.entities.type.Player;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.entities.EntityGroup;
|
||||
import io.anuke.mindustry.entities.Units;
|
||||
import io.anuke.mindustry.entities.traits.BuilderTrait;
|
||||
import io.anuke.mindustry.entities.type.BaseUnit;
|
||||
import io.anuke.mindustry.entities.type.FlyingUnit;
|
||||
import io.anuke.mindustry.entities.type.*;
|
||||
import io.anuke.mindustry.entities.units.UnitState;
|
||||
import io.anuke.mindustry.game.EventType.BuildSelectEvent;
|
||||
import io.anuke.mindustry.gen.Call;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.ItemStack;
|
||||
import io.anuke.mindustry.type.ItemType;
|
||||
import io.anuke.mindustry.type.*;
|
||||
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 java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
|
||||
import static io.anuke.mindustry.Vars.unitGroups;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
@@ -48,7 +41,7 @@ public class Drone extends FlyingUnit implements BuilderTrait{
|
||||
}
|
||||
|
||||
public void update(){
|
||||
BuildEntity entity = (BuildEntity) target;
|
||||
BuildEntity entity = (BuildEntity)target;
|
||||
TileEntity core = getClosestCore();
|
||||
|
||||
if(entity == null){
|
||||
@@ -105,7 +98,7 @@ public class Drone extends FlyingUnit implements BuilderTrait{
|
||||
if(target == null) return;
|
||||
|
||||
if(target.dst(Drone.this) > type.range){
|
||||
circle(type.range*0.9f);
|
||||
circle(type.range * 0.9f);
|
||||
}else{
|
||||
getWeapon().update(Drone.this, target.getX(), target.getY());
|
||||
}
|
||||
@@ -155,10 +148,10 @@ public class Drone extends FlyingUnit implements BuilderTrait{
|
||||
moveTo(type.range / 1.5f);
|
||||
|
||||
if(dst(target) < type.range && mineTile != target){
|
||||
setMineTile((Tile) target);
|
||||
setMineTile((Tile)target);
|
||||
}
|
||||
|
||||
if(((Tile) target).block() != Blocks.air){
|
||||
if(((Tile)target).block() != Blocks.air){
|
||||
setState(drop);
|
||||
}
|
||||
}
|
||||
@@ -190,7 +183,7 @@ public class Drone extends FlyingUnit implements BuilderTrait{
|
||||
|
||||
if(target == null) return;
|
||||
|
||||
TileEntity tile = (TileEntity) target;
|
||||
TileEntity tile = (TileEntity)target;
|
||||
|
||||
if(dst(target) < type.range){
|
||||
if(tile.tile.block().acceptStack(item.item, item.amount, tile.tile, Drone.this) == item.amount){
|
||||
@@ -312,7 +305,7 @@ public class Drone extends FlyingUnit implements BuilderTrait{
|
||||
@Override
|
||||
public void behavior(){
|
||||
if(health <= health * type.retreatPercent &&
|
||||
Geometry.findClosest(x, y, world.indexer.getAllied(team, BlockFlag.repair)) != null){
|
||||
Geometry.findClosest(x, y, world.indexer.getAllied(team, BlockFlag.repair)) != null){
|
||||
setState(retreat);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ public class Revenant extends FlyingUnit{
|
||||
float tra = rotation - 90, trY = -getWeapon().getRecoil(this, i > 0) + type.weaponOffsetY;
|
||||
float w = i > 0 ? -12 : 12;
|
||||
float wx = x + Angles.trnsx(tra, getWeapon().width * i, trY), wy = y + Angles.trnsy(tra, getWeapon().width * i, trY);
|
||||
int wi = (i + 1)/2;
|
||||
int wi = (i + 1) / 2;
|
||||
Draw.rect(getWeapon().region, wx, wy, w, 12, weaponAngles[wi] - 90);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,12 +12,11 @@ import io.anuke.mindustry.entities.type.Unit;
|
||||
import io.anuke.mindustry.type.ContentType;
|
||||
import io.anuke.mindustry.type.StatusEffect;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
|
||||
import static io.anuke.mindustry.Vars.content;
|
||||
/** Class for controlling status effects on an entity.*/
|
||||
|
||||
/** Class for controlling status effects on an entity. */
|
||||
public class Statuses implements Saveable{
|
||||
private static final StatusEntry globalResult = new StatusEntry();
|
||||
private static final Array<StatusEntry> removals = new Array<>();
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package io.anuke.mindustry.entities.units;
|
||||
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.content.Items;
|
||||
import io.anuke.mindustry.entities.type.BaseUnit;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.gen.Call;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
|
||||
public class UnitDrops{
|
||||
private static Item[] dropTable;
|
||||
@@ -37,7 +37,8 @@ public class UnitDrops{
|
||||
if(Mathf.chance(0.03)){
|
||||
int amount = Mathf.random(20, 40);
|
||||
amount = core.tile.block().acceptStack(item, amount, core.tile, null);
|
||||
if (amount > 0) Call.transferItemTo(item, amount, unit.x + Mathf.range(2f), unit.y + Mathf.range(2f), core.tile);
|
||||
if(amount > 0)
|
||||
Call.transferItemTo(item, amount, unit.x + Mathf.range(2f), unit.y + Mathf.range(2f), core.tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user