Documentation, cleanup, incremental resource usage, core seeking
This commit is contained in:
@@ -2,7 +2,7 @@ package io.anuke.mindustry.entities;
|
||||
|
||||
import com.badlogic.gdx.utils.Queue;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.resource.Recipe;
|
||||
import io.anuke.mindustry.type.Recipe;
|
||||
import io.anuke.mindustry.world.Build;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.BuildBlock;
|
||||
@@ -76,10 +76,17 @@ public interface BlockBuilder {
|
||||
getPlaceQueue().removeFirst();
|
||||
}
|
||||
}else{
|
||||
TileEntity core = unit.getClosestCore();
|
||||
|
||||
//if there is no core to build with, stop building!
|
||||
if(core == null){
|
||||
return;
|
||||
}
|
||||
|
||||
//otherwise, update it.
|
||||
BuildEntity entity = tile.entity();
|
||||
|
||||
entity.progress += 1f / entity.recipe.cost;
|
||||
entity.addProgress(core.items, 1f / entity.recipe.cost);
|
||||
unit.rotation = Mathf.slerpDelta(unit.rotation, unit.angleTo(entity), 0.4f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
package io.anuke.mindustry.entities;
|
||||
|
||||
import com.badlogic.gdx.math.Interpolation;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.ucore.entities.Entity;
|
||||
import io.anuke.ucore.entities.TimedEntity;
|
||||
import io.anuke.ucore.function.Callable;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
/**This class should not be used anymore, as the animation does not fit the style well.*/
|
||||
@Deprecated
|
||||
public class ItemAnimationEffect extends TimedEntity {
|
||||
private static final float size = 5f;
|
||||
|
||||
private final Vector2 vec = new Vector2();
|
||||
private final Vector2 from = new Vector2();
|
||||
private final Vector2 to = new Vector2();
|
||||
private final Item item;
|
||||
private final Callable removed;
|
||||
|
||||
public Interpolation interp = Interpolation.fade;
|
||||
public float endSize = 0.9f;
|
||||
|
||||
public ItemAnimationEffect(Item item, float x, float y, float tox, float toy, Callable removed) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.item = item;
|
||||
this.removed = removed;
|
||||
from.set(x, y);
|
||||
to.set(tox, toy);
|
||||
lifetime = 40f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removed() {
|
||||
super.removed();
|
||||
removed.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
|
||||
vec.set(from).interpolate(to, fin(), interp);
|
||||
x = vec.x;
|
||||
y = vec.y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw() {
|
||||
float s = size * (1f-Mathf.curve(fin(), endSize));
|
||||
Draw.rect(item.region, x, y, s, s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Entity> T add() {
|
||||
return super.add(Vars.effectGroup);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package io.anuke.mindustry.entities;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.ucore.entities.Entity;
|
||||
import io.anuke.ucore.entities.TimedEntity;
|
||||
import io.anuke.ucore.function.Callable;
|
||||
|
||||
public class ItemTransfer extends TimedEntity {
|
||||
|
||||
|
||||
public static void create(Item item, float fromx, float fromy, float tox, float toy, Callable done){
|
||||
|
||||
}
|
||||
|
||||
private ItemTransfer(){}
|
||||
|
||||
@Override
|
||||
public void removed() {
|
||||
super.removed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Entity> T add() {
|
||||
return super.add(Vars.effectGroup);
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,10 @@ import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.graphics.Palette;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.net.NetEvents;
|
||||
import io.anuke.mindustry.resource.*;
|
||||
import io.anuke.mindustry.type.ItemStack;
|
||||
import io.anuke.mindustry.type.Mech;
|
||||
import io.anuke.mindustry.type.Upgrade;
|
||||
import io.anuke.mindustry.type.Weapon;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.Floor;
|
||||
import io.anuke.ucore.core.*;
|
||||
@@ -375,12 +378,12 @@ public class Player extends Unit implements BlockBuilder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsAmmo(Item item) {
|
||||
public boolean acceptsAmmo(io.anuke.mindustry.type.Item item) {
|
||||
return weapon.getAmmoType(item) != null && inventory.canAcceptAmmo(weapon.getAmmoType(item));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAmmo(Item item) {
|
||||
public void addAmmo(io.anuke.mindustry.type.Item item) {
|
||||
inventory.addAmmo(weapon.getAmmoType(item));
|
||||
}
|
||||
|
||||
|
||||
@@ -8,10 +8,13 @@ public class StatusEffect{
|
||||
private static final Array<StatusEffect> array = new Array<>();
|
||||
private static int lastid;
|
||||
|
||||
/**Duration of this status effect in ticks at maximum power.*/
|
||||
public final float baseDuration;
|
||||
public final int id;
|
||||
|
||||
/**Set of 'opposite' effects, which will decrease the duration of this effect when applied.*/
|
||||
protected ObjectSet<StatusEffect> opposites = new ObjectSet<>();
|
||||
/**The strength of time decrease when met with an opposite effect, as a fraction of the other's duration.*/
|
||||
protected float oppositeScale = 0.5f;
|
||||
|
||||
public StatusEffect(float baseDuration){
|
||||
|
||||
@@ -115,7 +115,6 @@ public abstract class SyncEntity extends DestructibleEntity{
|
||||
}
|
||||
|
||||
public void update(){
|
||||
//TODO prevent rubberbanding from getting too bad, clamp values?
|
||||
|
||||
time += 1f / spacing * Math.min(Timers.delta(), 1f);
|
||||
|
||||
|
||||
@@ -3,12 +3,14 @@ package io.anuke.mindustry.entities;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import io.anuke.mindustry.content.blocks.Blocks;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.game.TeamInfo.TeamData;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.Floor;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.entities.SolidEntity;
|
||||
import io.anuke.ucore.util.Geometry;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
@@ -76,6 +78,21 @@ public abstract class Unit extends SyncEntity implements SerializableEntity {
|
||||
this.status.set(StatusEffect.getByID(effect), etime);
|
||||
}
|
||||
|
||||
public TileEntity getClosestCore(){
|
||||
if(state.teams.has(team)){
|
||||
TeamData data = state.teams.get(team);
|
||||
|
||||
Tile tile = Geometry.findClosest(x, y, data.cores);
|
||||
if(tile == null){
|
||||
return null;
|
||||
}else{
|
||||
return tile.entity;
|
||||
}
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Floor getFloorOn(){
|
||||
Tile tile = world.tileWorld(x, y);
|
||||
return (Floor)(tile == null || (tile.floor() == null) ? Blocks.defaultFloor : tile.floor());
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package io.anuke.mindustry.entities;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.resource.AmmoEntry;
|
||||
import io.anuke.mindustry.resource.AmmoType;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.resource.ItemStack;
|
||||
import io.anuke.mindustry.type.AmmoEntry;
|
||||
import io.anuke.mindustry.type.AmmoType;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.ItemStack;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
|
||||
@@ -19,14 +19,17 @@ import static io.anuke.mindustry.Vars.*;
|
||||
public class Units {
|
||||
private static Rectangle rect = new Rectangle();
|
||||
|
||||
/**Returns the neareset ally tile in a range.*/
|
||||
public static TileEntity findAllyTile(Team team, float x, float y, float range, Predicate<Tile> pred){
|
||||
return findTile(x, y, range, tile -> !state.teams.areEnemies(team, tile.getTeam()) && pred.test(tile));
|
||||
}
|
||||
|
||||
/**Returns the neareset enemy tile in a range.*/
|
||||
public static TileEntity findEnemyTile(Team team, float x, float y, float range, Predicate<Tile> pred){
|
||||
return findTile(x, y, range, tile -> state.teams.areEnemies(team, tile.getTeam()) && pred.test(tile));
|
||||
}
|
||||
|
||||
/**Returns the neareset tile entity in a range.*/
|
||||
public static TileEntity findTile(float x, float y, float range, Predicate<Tile> pred){
|
||||
Entity closest = null;
|
||||
float dst = 0;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
package io.anuke.mindustry.entities.effect;
|
||||
|
||||
/**A flag interface for marking an effect as appearing below liquids.*/
|
||||
public interface BelowLiquidEffect {
|
||||
}
|
||||
|
||||
@@ -23,10 +23,12 @@ import io.anuke.ucore.util.Translator;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
/**Utility class for damaging in an area.*/
|
||||
public class DamageArea{
|
||||
private static Rectangle rect = new Rectangle();
|
||||
private static Translator tr = new Translator();
|
||||
|
||||
/**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);
|
||||
|
||||
@@ -9,6 +9,7 @@ import io.anuke.ucore.entities.EffectEntity;
|
||||
import io.anuke.ucore.function.EffectRenderer;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
/**A ground effect contains an effect that is rendered on the ground layer as opposed to the top layer.*/
|
||||
public class GroundEffectEntity extends EffectEntity {
|
||||
private boolean once;
|
||||
|
||||
@@ -52,8 +53,12 @@ public class GroundEffectEntity extends EffectEntity {
|
||||
once = false;
|
||||
}
|
||||
|
||||
/**An effect that is rendered on the ground layer as opposed to the top layer.*/
|
||||
public static class GroundEffect extends Effect{
|
||||
/**How long this effect stays on the ground when static.*/
|
||||
public final float staticLife;
|
||||
/**If true, this effect will stop and lie on the ground for a specific duration,
|
||||
* after its initial lifetime is over.*/
|
||||
public final boolean isStatic;
|
||||
|
||||
public GroundEffect(float life, float staticLife, EffectRenderer draw) {
|
||||
|
||||
@@ -31,6 +31,7 @@ public class Lightning extends TimedEntity implements Poolable{
|
||||
|
||||
public Color color = Palette.lancerLaser;
|
||||
|
||||
/**Create a lighting branch at a location. Use Team.none to damage everyone.*/
|
||||
public static void create(Team team, Effect effect, Color color, float damage, float x, float y, float targetAngle, int length){
|
||||
Lightning l = Pools.obtain(Lightning.class);
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import io.anuke.mindustry.entities.Bullet;
|
||||
import io.anuke.mindustry.entities.SerializableEntity;
|
||||
import io.anuke.mindustry.entities.Units;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.resource.Liquid;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
|
||||
@@ -7,10 +7,12 @@ import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import static io.anuke.mindustry.Vars.groundEffectGroup;
|
||||
|
||||
/**Class for creating block rubble on the ground.*/
|
||||
public class Rubble extends TimedEntity implements BelowLiquidEffect{
|
||||
private static final Color color = Color.valueOf("52504e");
|
||||
private int size;
|
||||
|
||||
/**Creates a rubble effect at a position. Provide a block size to use.*/
|
||||
public static void create(float x, float y, int size){
|
||||
Rubble rubble = new Rubble();
|
||||
rubble.size = size;
|
||||
|
||||
@@ -14,6 +14,7 @@ import io.anuke.ucore.util.Mathf;
|
||||
import static io.anuke.mindustry.Vars.bulletGroup;
|
||||
import static io.anuke.mindustry.Vars.shieldGroup;
|
||||
|
||||
//todo re-implement
|
||||
public class Shield extends Entity{
|
||||
public boolean active;
|
||||
public boolean hitPlayers = false;
|
||||
|
||||
@@ -5,7 +5,7 @@ import io.anuke.mindustry.entities.BulletType;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.Unit;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.world.BlockFlag;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Effects.Effect;
|
||||
|
||||
@@ -3,7 +3,7 @@ package io.anuke.mindustry.entities.units;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.Unit;
|
||||
import io.anuke.mindustry.entities.Units;
|
||||
import io.anuke.mindustry.resource.AmmoType;
|
||||
import io.anuke.mindustry.type.AmmoType;
|
||||
import io.anuke.mindustry.world.BlockFlag;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
package io.anuke.mindustry.entities.units;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.ObjectSet;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.Unit;
|
||||
import io.anuke.mindustry.entities.Units;
|
||||
import io.anuke.mindustry.game.TeamInfo.TeamData;
|
||||
import io.anuke.mindustry.resource.AmmoType;
|
||||
import io.anuke.mindustry.type.AmmoType;
|
||||
import io.anuke.mindustry.world.BlockFlag;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.Floor;
|
||||
|
||||
@@ -8,8 +8,8 @@ import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.Unit;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.net.NetEvents;
|
||||
import io.anuke.mindustry.resource.AmmoType;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.type.AmmoType;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.util.Angles;
|
||||
|
||||
Reference in New Issue
Block a user