Moved entity package from Arc / Entity code cleanup
This commit is contained in:
@@ -2,8 +2,6 @@ package io.anuke.annotations;
|
|||||||
|
|
||||||
import com.squareup.javapoet.*;
|
import com.squareup.javapoet.*;
|
||||||
import io.anuke.annotations.IOFinder.ClassSerializer;
|
import io.anuke.annotations.IOFinder.ClassSerializer;
|
||||||
import io.anuke.annotations.MethodEntry;
|
|
||||||
import io.anuke.annotations.Utils;
|
|
||||||
|
|
||||||
import javax.lang.model.element.Modifier;
|
import javax.lang.model.element.Modifier;
|
||||||
import javax.lang.model.element.TypeElement;
|
import javax.lang.model.element.TypeElement;
|
||||||
@@ -52,7 +50,7 @@ public class RemoteReadGenerator{
|
|||||||
Constructor<TypeName> cons = TypeName.class.getDeclaredConstructor(String.class);
|
Constructor<TypeName> cons = TypeName.class.getDeclaredConstructor(String.class);
|
||||||
cons.setAccessible(true);
|
cons.setAccessible(true);
|
||||||
|
|
||||||
TypeName playerType = cons.newInstance("io.anuke.mindustry.entities.Player");
|
TypeName playerType = cons.newInstance("io.anuke.mindustry.entities.type.Player");
|
||||||
//add player parameter
|
//add player parameter
|
||||||
readMethod.addParameter(playerType, "player");
|
readMethod.addParameter(playerType, "player");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ public class RemoteWriteGenerator{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!elem.getParameters().get(0).asType().toString().equals("io.anuke.mindustry.entities.Player")){
|
if(!elem.getParameters().get(0).asType().toString().equals("io.anuke.mindustry.entities.type.Player")){
|
||||||
Utils.messager.printMessage(Kind.ERROR, "Client invoke methods should have a first parameter of type Player.", elem);
|
Utils.messager.printMessage(Kind.ERROR, "Client invoke methods should have a first parameter of type Player.", elem);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -501,7 +501,7 @@ item.radioactivity = [LIGHT_GRAY]Radioactivity: {0}%
|
|||||||
unit.health = [LIGHT_GRAY]Health: {0}
|
unit.health = [LIGHT_GRAY]Health: {0}
|
||||||
unit.speed = [LIGHT_GRAY]Speed: {0}
|
unit.speed = [LIGHT_GRAY]Speed: {0}
|
||||||
mech.weapon = [LIGHT_GRAY]Weapon: {0}
|
mech.weapon = [LIGHT_GRAY]Weapon: {0}
|
||||||
mech.armor = [LIGHT_GRAY]Armor: {0}
|
mech.health = [LIGHT_GRAY]Health: {0}
|
||||||
mech.itemcapacity = [LIGHT_GRAY]Item Capacity: {0}
|
mech.itemcapacity = [LIGHT_GRAY]Item Capacity: {0}
|
||||||
mech.minespeed = [LIGHT_GRAY]Mining Speed: {0}
|
mech.minespeed = [LIGHT_GRAY]Mining Speed: {0}
|
||||||
mech.minepower = [LIGHT_GRAY]Mining Power: {0}
|
mech.minepower = [LIGHT_GRAY]Mining Power: {0}
|
||||||
|
|||||||
@@ -4,5 +4,5 @@ sourceCompatibility = 1.8
|
|||||||
sourceSets.main.java.srcDirs = ["src/"]
|
sourceSets.main.java.srcDirs = ["src/"]
|
||||||
|
|
||||||
compileJava{
|
compileJava{
|
||||||
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
|
// options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
|
||||||
}
|
}
|
||||||
@@ -2,21 +2,21 @@ package io.anuke.mindustry;
|
|||||||
|
|
||||||
import io.anuke.arc.Application.ApplicationType;
|
import io.anuke.arc.Application.ApplicationType;
|
||||||
import io.anuke.arc.Core;
|
import io.anuke.arc.Core;
|
||||||
import io.anuke.arc.entities.Entities;
|
import io.anuke.mindustry.entities.Entities;
|
||||||
import io.anuke.arc.entities.EntityGroup;
|
import io.anuke.mindustry.entities.EntityGroup;
|
||||||
import io.anuke.arc.entities.impl.EffectEntity;
|
import io.anuke.mindustry.entities.impl.EffectEntity;
|
||||||
import io.anuke.arc.entities.trait.DrawTrait;
|
import io.anuke.mindustry.entities.traits.DrawTrait;
|
||||||
import io.anuke.arc.files.FileHandle;
|
import io.anuke.arc.files.FileHandle;
|
||||||
import io.anuke.arc.graphics.Color;
|
import io.anuke.arc.graphics.Color;
|
||||||
import io.anuke.arc.util.Structs;
|
import io.anuke.arc.util.Structs;
|
||||||
import io.anuke.mindustry.core.*;
|
import io.anuke.mindustry.core.*;
|
||||||
import io.anuke.mindustry.entities.Player;
|
import io.anuke.mindustry.entities.type.Player;
|
||||||
import io.anuke.mindustry.entities.TileEntity;
|
import io.anuke.mindustry.entities.type.TileEntity;
|
||||||
import io.anuke.mindustry.entities.bullet.Bullet;
|
import io.anuke.mindustry.entities.bullet.Bullet;
|
||||||
import io.anuke.mindustry.entities.effect.Fire;
|
import io.anuke.mindustry.entities.effect.Fire;
|
||||||
import io.anuke.mindustry.entities.effect.Puddle;
|
import io.anuke.mindustry.entities.effect.Puddle;
|
||||||
import io.anuke.mindustry.entities.traits.SyncTrait;
|
import io.anuke.mindustry.entities.traits.SyncTrait;
|
||||||
import io.anuke.mindustry.entities.units.BaseUnit;
|
import io.anuke.mindustry.entities.type.BaseUnit;
|
||||||
import io.anuke.mindustry.game.GlobalData;
|
import io.anuke.mindustry.game.GlobalData;
|
||||||
import io.anuke.mindustry.game.Team;
|
import io.anuke.mindustry.game.Team;
|
||||||
import io.anuke.mindustry.game.Version;
|
import io.anuke.mindustry.game.Version;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import io.anuke.arc.function.Predicate;
|
|||||||
import io.anuke.arc.math.Mathf;
|
import io.anuke.arc.math.Mathf;
|
||||||
import io.anuke.arc.math.geom.Geometry;
|
import io.anuke.arc.math.geom.Geometry;
|
||||||
import io.anuke.mindustry.content.Blocks;
|
import io.anuke.mindustry.content.Blocks;
|
||||||
import io.anuke.mindustry.entities.TileEntity;
|
import io.anuke.mindustry.entities.type.TileEntity;
|
||||||
import io.anuke.mindustry.game.EventType.TileChangeEvent;
|
import io.anuke.mindustry.game.EventType.TileChangeEvent;
|
||||||
import io.anuke.mindustry.game.EventType.WorldLoadEvent;
|
import io.anuke.mindustry.game.EventType.WorldLoadEvent;
|
||||||
import io.anuke.mindustry.game.Team;
|
import io.anuke.mindustry.game.Team;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package io.anuke.mindustry.ai;
|
|||||||
import io.anuke.arc.Events;
|
import io.anuke.arc.Events;
|
||||||
import io.anuke.arc.collection.Array;
|
import io.anuke.arc.collection.Array;
|
||||||
import io.anuke.arc.collection.IntArray;
|
import io.anuke.arc.collection.IntArray;
|
||||||
import io.anuke.arc.entities.Effects;
|
import io.anuke.mindustry.entities.Effects;
|
||||||
import io.anuke.arc.math.Angles;
|
import io.anuke.arc.math.Angles;
|
||||||
import io.anuke.arc.math.Mathf;
|
import io.anuke.arc.math.Mathf;
|
||||||
import io.anuke.arc.util.Time;
|
import io.anuke.arc.util.Time;
|
||||||
@@ -11,7 +11,7 @@ import io.anuke.arc.util.Tmp;
|
|||||||
import io.anuke.mindustry.content.Blocks;
|
import io.anuke.mindustry.content.Blocks;
|
||||||
import io.anuke.mindustry.content.Fx;
|
import io.anuke.mindustry.content.Fx;
|
||||||
import io.anuke.mindustry.entities.Damage;
|
import io.anuke.mindustry.entities.Damage;
|
||||||
import io.anuke.mindustry.entities.units.BaseUnit;
|
import io.anuke.mindustry.entities.type.BaseUnit;
|
||||||
import io.anuke.mindustry.entities.units.Squad;
|
import io.anuke.mindustry.entities.units.Squad;
|
||||||
import io.anuke.mindustry.game.EventType.WorldLoadEvent;
|
import io.anuke.mindustry.game.EventType.WorldLoadEvent;
|
||||||
import io.anuke.mindustry.game.SpawnGroup;
|
import io.anuke.mindustry.game.SpawnGroup;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package io.anuke.mindustry.content;
|
package io.anuke.mindustry.content;
|
||||||
|
|
||||||
import io.anuke.arc.entities.Effects;
|
import io.anuke.mindustry.entities.Effects;
|
||||||
import io.anuke.arc.graphics.Color;
|
import io.anuke.arc.graphics.Color;
|
||||||
import io.anuke.arc.graphics.g2d.CapStyle;
|
import io.anuke.arc.graphics.g2d.CapStyle;
|
||||||
import io.anuke.arc.graphics.g2d.Draw;
|
import io.anuke.arc.graphics.g2d.Draw;
|
||||||
@@ -10,7 +10,7 @@ import io.anuke.arc.math.Mathf;
|
|||||||
import io.anuke.arc.util.Time;
|
import io.anuke.arc.util.Time;
|
||||||
import io.anuke.arc.util.Tmp;
|
import io.anuke.arc.util.Tmp;
|
||||||
import io.anuke.mindustry.entities.Damage;
|
import io.anuke.mindustry.entities.Damage;
|
||||||
import io.anuke.mindustry.entities.Unit;
|
import io.anuke.mindustry.entities.type.Unit;
|
||||||
import io.anuke.mindustry.entities.bullet.*;
|
import io.anuke.mindustry.entities.bullet.*;
|
||||||
import io.anuke.mindustry.entities.effect.Fire;
|
import io.anuke.mindustry.entities.effect.Fire;
|
||||||
import io.anuke.mindustry.entities.effect.Lightning;
|
import io.anuke.mindustry.entities.effect.Lightning;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package io.anuke.mindustry.content;
|
package io.anuke.mindustry.content;
|
||||||
|
|
||||||
import io.anuke.arc.Core;
|
import io.anuke.arc.Core;
|
||||||
import io.anuke.arc.entities.Effects.Effect;
|
import io.anuke.mindustry.entities.Effects.Effect;
|
||||||
import io.anuke.arc.graphics.Color;
|
import io.anuke.arc.graphics.Color;
|
||||||
import io.anuke.arc.graphics.g2d.Draw;
|
import io.anuke.arc.graphics.g2d.Draw;
|
||||||
import io.anuke.arc.graphics.g2d.Fill;
|
import io.anuke.arc.graphics.g2d.Fill;
|
||||||
@@ -10,7 +10,7 @@ import io.anuke.arc.math.Angles;
|
|||||||
import io.anuke.arc.math.Mathf;
|
import io.anuke.arc.math.Mathf;
|
||||||
import io.anuke.arc.util.Tmp;
|
import io.anuke.arc.util.Tmp;
|
||||||
import io.anuke.mindustry.entities.effect.GroundEffectEntity.GroundEffect;
|
import io.anuke.mindustry.entities.effect.GroundEffectEntity.GroundEffect;
|
||||||
import io.anuke.mindustry.entities.units.BaseUnit;
|
import io.anuke.mindustry.entities.type.BaseUnit;
|
||||||
import io.anuke.mindustry.game.ContentList;
|
import io.anuke.mindustry.game.ContentList;
|
||||||
import io.anuke.mindustry.graphics.Palette;
|
import io.anuke.mindustry.graphics.Palette;
|
||||||
import io.anuke.mindustry.graphics.Shapes;
|
import io.anuke.mindustry.graphics.Shapes;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package io.anuke.mindustry.content;
|
package io.anuke.mindustry.content;
|
||||||
|
|
||||||
import io.anuke.arc.Core;
|
import io.anuke.arc.Core;
|
||||||
import io.anuke.arc.entities.Effects;
|
import io.anuke.mindustry.entities.Effects;
|
||||||
import io.anuke.arc.graphics.Blending;
|
import io.anuke.arc.graphics.Blending;
|
||||||
import io.anuke.arc.graphics.Color;
|
import io.anuke.arc.graphics.Color;
|
||||||
import io.anuke.arc.graphics.g2d.Draw;
|
import io.anuke.arc.graphics.g2d.Draw;
|
||||||
@@ -9,7 +9,7 @@ import io.anuke.arc.graphics.g2d.TextureRegion;
|
|||||||
import io.anuke.arc.math.Mathf;
|
import io.anuke.arc.math.Mathf;
|
||||||
import io.anuke.arc.math.geom.Rectangle;
|
import io.anuke.arc.math.geom.Rectangle;
|
||||||
import io.anuke.arc.util.Time;
|
import io.anuke.arc.util.Time;
|
||||||
import io.anuke.mindustry.entities.Player;
|
import io.anuke.mindustry.entities.type.Player;
|
||||||
import io.anuke.mindustry.entities.Units;
|
import io.anuke.mindustry.entities.Units;
|
||||||
import io.anuke.mindustry.entities.effect.Lightning;
|
import io.anuke.mindustry.entities.effect.Lightning;
|
||||||
import io.anuke.mindustry.game.ContentList;
|
import io.anuke.mindustry.game.ContentList;
|
||||||
@@ -36,7 +36,7 @@ public class Mechs implements ContentList{
|
|||||||
boostSpeed = 0.85f;
|
boostSpeed = 0.85f;
|
||||||
weapon = Weapons.blaster;
|
weapon = Weapons.blaster;
|
||||||
trailColorTo = Color.valueOf("ffd37f");
|
trailColorTo = Color.valueOf("ffd37f");
|
||||||
armor = 20f;
|
health = 250f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -54,7 +54,7 @@ public class Mechs implements ContentList{
|
|||||||
boostSpeed = 0.95f;
|
boostSpeed = 0.95f;
|
||||||
itemCapacity = 15;
|
itemCapacity = 15;
|
||||||
mass = 0.9f;
|
mass = 0.9f;
|
||||||
armor = 30f;
|
health = 220f;
|
||||||
weaponOffsetX = -1;
|
weaponOffsetX = -1;
|
||||||
weaponOffsetY = -1;
|
weaponOffsetY = -1;
|
||||||
weapon = Weapons.shockgun;
|
weapon = Weapons.shockgun;
|
||||||
@@ -92,7 +92,7 @@ public class Mechs implements ContentList{
|
|||||||
boostSpeed = 0.8f;
|
boostSpeed = 0.8f;
|
||||||
canHeal = true;
|
canHeal = true;
|
||||||
weapon = Weapons.healBlaster;
|
weapon = Weapons.healBlaster;
|
||||||
armor = 15f;
|
health = 200f;
|
||||||
trailColorTo = Palette.heal;
|
trailColorTo = Palette.heal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,7 +135,7 @@ public class Mechs implements ContentList{
|
|||||||
weaponOffsetY = 0;
|
weaponOffsetY = 0;
|
||||||
weapon = Weapons.swarmer;
|
weapon = Weapons.swarmer;
|
||||||
trailColorTo = Color.valueOf("feb380");
|
trailColorTo = Color.valueOf("feb380");
|
||||||
armor = 45f;
|
health = 300f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -188,7 +188,7 @@ public class Mechs implements ContentList{
|
|||||||
mineSpeed = 0.9f;
|
mineSpeed = 0.9f;
|
||||||
speed = 0.4f;
|
speed = 0.4f;
|
||||||
drag = 0.1f;
|
drag = 0.1f;
|
||||||
armor = 10f;
|
health = 180f;
|
||||||
weapon = Weapons.blasterSmall;
|
weapon = Weapons.blasterSmall;
|
||||||
weaponOffsetX = -1;
|
weaponOffsetX = -1;
|
||||||
weaponOffsetY = -1;
|
weaponOffsetY = -1;
|
||||||
@@ -211,7 +211,7 @@ public class Mechs implements ContentList{
|
|||||||
speed = 0.11f;
|
speed = 0.11f;
|
||||||
drag = 0.01f;
|
drag = 0.01f;
|
||||||
mass = 2f;
|
mass = 2f;
|
||||||
armor = 5f;
|
health = 170f;
|
||||||
weapon = Weapons.missiles;
|
weapon = Weapons.missiles;
|
||||||
trailColor = Color.valueOf("d3ddff");
|
trailColor = Color.valueOf("d3ddff");
|
||||||
cellTrnsY = 1f;
|
cellTrnsY = 1f;
|
||||||
@@ -266,7 +266,7 @@ public class Mechs implements ContentList{
|
|||||||
drag = 0.034f;
|
drag = 0.034f;
|
||||||
mass = 2.5f;
|
mass = 2.5f;
|
||||||
turnCursor = false;
|
turnCursor = false;
|
||||||
armor = 20f;
|
health = 220f;
|
||||||
itemCapacity = 30;
|
itemCapacity = 30;
|
||||||
trailColor = Color.valueOf("84f491");
|
trailColor = Color.valueOf("84f491");
|
||||||
weapon = Weapons.bomberTrident;
|
weapon = Weapons.bomberTrident;
|
||||||
@@ -287,7 +287,7 @@ public class Mechs implements ContentList{
|
|||||||
speed = 0.32f;
|
speed = 0.32f;
|
||||||
drag = 0.06f;
|
drag = 0.06f;
|
||||||
mass = 3f;
|
mass = 3f;
|
||||||
armor = 30f;
|
health = 240f;
|
||||||
itemCapacity = 60;
|
itemCapacity = 60;
|
||||||
trailColor = Color.valueOf("feb380");
|
trailColor = Color.valueOf("feb380");
|
||||||
cellTrnsY = 1f;
|
cellTrnsY = 1f;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package io.anuke.mindustry.content;
|
package io.anuke.mindustry.content;
|
||||||
|
|
||||||
import io.anuke.arc.entities.Effects;
|
import io.anuke.mindustry.entities.Effects;
|
||||||
import io.anuke.arc.math.Mathf;
|
import io.anuke.arc.math.Mathf;
|
||||||
import io.anuke.mindustry.game.ContentList;
|
import io.anuke.mindustry.game.ContentList;
|
||||||
import io.anuke.mindustry.type.StatusEffect;
|
import io.anuke.mindustry.type.StatusEffect;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package io.anuke.mindustry.content;
|
package io.anuke.mindustry.content;
|
||||||
|
|
||||||
import io.anuke.arc.collection.ObjectSet;
|
import io.anuke.arc.collection.ObjectSet;
|
||||||
import io.anuke.mindustry.entities.units.UnitType;
|
import io.anuke.mindustry.entities.type.types.Crawler;
|
||||||
import io.anuke.mindustry.entities.units.types.*;
|
import io.anuke.mindustry.type.UnitType;
|
||||||
import io.anuke.mindustry.game.ContentList;
|
import io.anuke.mindustry.game.ContentList;
|
||||||
|
|
||||||
public class UnitTypes implements ContentList{
|
public class UnitTypes implements ContentList{
|
||||||
@@ -13,7 +13,7 @@ public class UnitTypes implements ContentList{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void load(){
|
public void load(){
|
||||||
spirit = new UnitType("spirit", Spirit.class, Spirit::new){{
|
spirit = new UnitType("spirit", io.anuke.mindustry.entities.type.types.Spirit.class, io.anuke.mindustry.entities.type.types.Spirit::new){{
|
||||||
weapon = Weapons.healBlasterDrone;
|
weapon = Weapons.healBlasterDrone;
|
||||||
isFlying = true;
|
isFlying = true;
|
||||||
drag = 0.01f;
|
drag = 0.01f;
|
||||||
@@ -23,7 +23,7 @@ public class UnitTypes implements ContentList{
|
|||||||
health = 60;
|
health = 60;
|
||||||
}};
|
}};
|
||||||
|
|
||||||
dagger = new UnitType("dagger", Dagger.class, Dagger::new){{
|
dagger = new UnitType("dagger", io.anuke.mindustry.entities.type.types.Dagger.class, io.anuke.mindustry.entities.type.types.Dagger::new){{
|
||||||
maxVelocity = 1.1f;
|
maxVelocity = 1.1f;
|
||||||
speed = 0.2f;
|
speed = 0.2f;
|
||||||
drag = 0.4f;
|
drag = 0.4f;
|
||||||
@@ -33,7 +33,7 @@ public class UnitTypes implements ContentList{
|
|||||||
health = 130;
|
health = 130;
|
||||||
}};
|
}};
|
||||||
|
|
||||||
crawler = new UnitType("crawler", Crawler.class, Crawler::new){{
|
crawler = new UnitType("crawler", io.anuke.mindustry.entities.type.types.Crawler.class, Crawler::new){{
|
||||||
maxVelocity = 1.1f;
|
maxVelocity = 1.1f;
|
||||||
speed = 0.22f;
|
speed = 0.22f;
|
||||||
drag = 0.4f;
|
drag = 0.4f;
|
||||||
@@ -43,7 +43,7 @@ public class UnitTypes implements ContentList{
|
|||||||
health = 100;
|
health = 100;
|
||||||
}};
|
}};
|
||||||
|
|
||||||
titan = new UnitType("titan", Titan.class, Titan::new){{
|
titan = new UnitType("titan", io.anuke.mindustry.entities.type.types.Titan.class, io.anuke.mindustry.entities.type.types.Titan::new){{
|
||||||
maxVelocity = 0.8f;
|
maxVelocity = 0.8f;
|
||||||
speed = 0.18f;
|
speed = 0.18f;
|
||||||
drag = 0.4f;
|
drag = 0.4f;
|
||||||
@@ -55,7 +55,7 @@ public class UnitTypes implements ContentList{
|
|||||||
immunities.add(StatusEffects.burning);
|
immunities.add(StatusEffects.burning);
|
||||||
}};
|
}};
|
||||||
|
|
||||||
fortress = new UnitType("fortress", Fortress.class, Fortress::new){{
|
fortress = new UnitType("fortress", io.anuke.mindustry.entities.type.types.Fortress.class, io.anuke.mindustry.entities.type.types.Fortress::new){{
|
||||||
maxVelocity = 0.78f;
|
maxVelocity = 0.78f;
|
||||||
speed = 0.15f;
|
speed = 0.15f;
|
||||||
drag = 0.4f;
|
drag = 0.4f;
|
||||||
@@ -68,7 +68,7 @@ public class UnitTypes implements ContentList{
|
|||||||
health = 800;
|
health = 800;
|
||||||
}};
|
}};
|
||||||
|
|
||||||
eruptor = new UnitType("eruptor", Eruptor.class, Eruptor::new){{
|
eruptor = new UnitType("eruptor", io.anuke.mindustry.entities.type.types.Eruptor.class, io.anuke.mindustry.entities.type.types.Eruptor::new){{
|
||||||
maxVelocity = 0.81f;
|
maxVelocity = 0.81f;
|
||||||
speed = 0.16f;
|
speed = 0.16f;
|
||||||
drag = 0.4f;
|
drag = 0.4f;
|
||||||
@@ -82,7 +82,7 @@ public class UnitTypes implements ContentList{
|
|||||||
immunities = ObjectSet.with(StatusEffects.burning, StatusEffects.melting);
|
immunities = ObjectSet.with(StatusEffects.burning, StatusEffects.melting);
|
||||||
}};
|
}};
|
||||||
|
|
||||||
wraith = new UnitType("wraith", Wraith.class, Wraith::new){{
|
wraith = new UnitType("wraith", io.anuke.mindustry.entities.type.types.Wraith.class, io.anuke.mindustry.entities.type.types.Wraith::new){{
|
||||||
speed = 0.3f;
|
speed = 0.3f;
|
||||||
maxVelocity = 1.9f;
|
maxVelocity = 1.9f;
|
||||||
drag = 0.01f;
|
drag = 0.01f;
|
||||||
@@ -92,7 +92,7 @@ public class UnitTypes implements ContentList{
|
|||||||
health = 70;
|
health = 70;
|
||||||
}};
|
}};
|
||||||
|
|
||||||
ghoul = new UnitType("ghoul", Ghoul.class, Ghoul::new){{
|
ghoul = new UnitType("ghoul", io.anuke.mindustry.entities.type.types.Ghoul.class, io.anuke.mindustry.entities.type.types.Ghoul::new){{
|
||||||
health = 250;
|
health = 250;
|
||||||
speed = 0.2f;
|
speed = 0.2f;
|
||||||
maxVelocity = 1.4f;
|
maxVelocity = 1.4f;
|
||||||
@@ -103,7 +103,7 @@ public class UnitTypes implements ContentList{
|
|||||||
weapon = Weapons.bomber;
|
weapon = Weapons.bomber;
|
||||||
}};
|
}};
|
||||||
|
|
||||||
revenant = new UnitType("revenant", Revenant.class, Revenant::new){{
|
revenant = new UnitType("revenant", io.anuke.mindustry.entities.type.types.Revenant.class, io.anuke.mindustry.entities.type.types.Revenant::new){{
|
||||||
health = 250;
|
health = 250;
|
||||||
mass = 5f;
|
mass = 5f;
|
||||||
hitsize = 12f;
|
hitsize = 12f;
|
||||||
@@ -115,7 +115,7 @@ public class UnitTypes implements ContentList{
|
|||||||
weapon = Weapons.laserBurster;
|
weapon = Weapons.laserBurster;
|
||||||
}};
|
}};
|
||||||
|
|
||||||
phantom = new UnitType("phantom", Phantom.class, Phantom::new){{
|
phantom = new UnitType("phantom", io.anuke.mindustry.entities.type.types.Phantom.class, io.anuke.mindustry.entities.type.types.Phantom::new){{
|
||||||
weapon = Weapons.healBlasterDrone2;
|
weapon = Weapons.healBlasterDrone2;
|
||||||
isFlying = true;
|
isFlying = true;
|
||||||
drag = 0.01f;
|
drag = 0.01f;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import io.anuke.arc.graphics.Color;
|
|||||||
import io.anuke.arc.graphics.Pixmap;
|
import io.anuke.arc.graphics.Pixmap;
|
||||||
import io.anuke.arc.util.Log;
|
import io.anuke.arc.util.Log;
|
||||||
import io.anuke.mindustry.content.*;
|
import io.anuke.mindustry.content.*;
|
||||||
import io.anuke.mindustry.entities.Player;
|
import io.anuke.mindustry.entities.type.Player;
|
||||||
import io.anuke.mindustry.entities.bullet.Bullet;
|
import io.anuke.mindustry.entities.bullet.Bullet;
|
||||||
import io.anuke.mindustry.entities.bullet.BulletType;
|
import io.anuke.mindustry.entities.bullet.BulletType;
|
||||||
import io.anuke.mindustry.entities.effect.Fire;
|
import io.anuke.mindustry.entities.effect.Fire;
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package io.anuke.mindustry.core;
|
|||||||
import io.anuke.arc.ApplicationListener;
|
import io.anuke.arc.ApplicationListener;
|
||||||
import io.anuke.arc.Core;
|
import io.anuke.arc.Core;
|
||||||
import io.anuke.arc.Events;
|
import io.anuke.arc.Events;
|
||||||
import io.anuke.arc.entities.Effects;
|
import io.anuke.mindustry.entities.Effects;
|
||||||
import io.anuke.arc.entities.EntityQuery;
|
import io.anuke.mindustry.entities.EntityQuery;
|
||||||
import io.anuke.arc.graphics.Color;
|
import io.anuke.arc.graphics.Color;
|
||||||
import io.anuke.arc.graphics.g2d.Draw;
|
import io.anuke.arc.graphics.g2d.Draw;
|
||||||
import io.anuke.arc.graphics.g2d.TextureAtlas;
|
import io.anuke.arc.graphics.g2d.TextureAtlas;
|
||||||
@@ -15,7 +15,7 @@ import io.anuke.arc.util.Strings;
|
|||||||
import io.anuke.arc.util.Time;
|
import io.anuke.arc.util.Time;
|
||||||
import io.anuke.mindustry.content.Mechs;
|
import io.anuke.mindustry.content.Mechs;
|
||||||
import io.anuke.mindustry.core.GameState.State;
|
import io.anuke.mindustry.core.GameState.State;
|
||||||
import io.anuke.mindustry.entities.Player;
|
import io.anuke.mindustry.entities.type.Player;
|
||||||
import io.anuke.mindustry.game.Content;
|
import io.anuke.mindustry.game.Content;
|
||||||
import io.anuke.mindustry.game.EventType.*;
|
import io.anuke.mindustry.game.EventType.*;
|
||||||
import io.anuke.mindustry.game.GlobalData;
|
import io.anuke.mindustry.game.GlobalData;
|
||||||
|
|||||||
@@ -5,14 +5,14 @@ import io.anuke.annotations.Annotations.Remote;
|
|||||||
import io.anuke.arc.ApplicationListener;
|
import io.anuke.arc.ApplicationListener;
|
||||||
import io.anuke.arc.Events;
|
import io.anuke.arc.Events;
|
||||||
import io.anuke.arc.collection.ObjectSet.ObjectSetIterator;
|
import io.anuke.arc.collection.ObjectSet.ObjectSetIterator;
|
||||||
import io.anuke.arc.entities.Effects;
|
import io.anuke.mindustry.entities.Effects;
|
||||||
import io.anuke.arc.entities.Entities;
|
import io.anuke.mindustry.entities.Entities;
|
||||||
import io.anuke.arc.entities.EntityGroup;
|
import io.anuke.mindustry.entities.EntityGroup;
|
||||||
import io.anuke.arc.entities.EntityQuery;
|
import io.anuke.mindustry.entities.EntityQuery;
|
||||||
import io.anuke.arc.util.Time;
|
import io.anuke.arc.util.Time;
|
||||||
import io.anuke.mindustry.content.Fx;
|
import io.anuke.mindustry.content.Fx;
|
||||||
import io.anuke.mindustry.core.GameState.State;
|
import io.anuke.mindustry.core.GameState.State;
|
||||||
import io.anuke.mindustry.entities.TileEntity;
|
import io.anuke.mindustry.entities.type.TileEntity;
|
||||||
import io.anuke.mindustry.game.EventType.*;
|
import io.anuke.mindustry.game.EventType.*;
|
||||||
import io.anuke.mindustry.game.*;
|
import io.anuke.mindustry.game.*;
|
||||||
import io.anuke.mindustry.net.Net;
|
import io.anuke.mindustry.net.Net;
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ import io.anuke.annotations.Annotations.Variant;
|
|||||||
import io.anuke.arc.ApplicationListener;
|
import io.anuke.arc.ApplicationListener;
|
||||||
import io.anuke.arc.Core;
|
import io.anuke.arc.Core;
|
||||||
import io.anuke.arc.collection.IntSet;
|
import io.anuke.arc.collection.IntSet;
|
||||||
import io.anuke.arc.entities.Entities;
|
import io.anuke.mindustry.entities.Entities;
|
||||||
import io.anuke.arc.entities.EntityGroup;
|
import io.anuke.mindustry.entities.EntityGroup;
|
||||||
import io.anuke.arc.graphics.Color;
|
import io.anuke.arc.graphics.Color;
|
||||||
import io.anuke.arc.util.Interval;
|
import io.anuke.arc.util.Interval;
|
||||||
import io.anuke.arc.util.Log;
|
import io.anuke.arc.util.Log;
|
||||||
@@ -17,7 +17,7 @@ import io.anuke.arc.util.io.ReusableByteArrayInputStream;
|
|||||||
import io.anuke.arc.util.serialization.Base64Coder;
|
import io.anuke.arc.util.serialization.Base64Coder;
|
||||||
import io.anuke.mindustry.Vars;
|
import io.anuke.mindustry.Vars;
|
||||||
import io.anuke.mindustry.core.GameState.State;
|
import io.anuke.mindustry.core.GameState.State;
|
||||||
import io.anuke.mindustry.entities.Player;
|
import io.anuke.mindustry.entities.type.Player;
|
||||||
import io.anuke.mindustry.entities.traits.BuilderTrait.BuildRequest;
|
import io.anuke.mindustry.entities.traits.BuilderTrait.BuildRequest;
|
||||||
import io.anuke.mindustry.entities.traits.SyncTrait;
|
import io.anuke.mindustry.entities.traits.SyncTrait;
|
||||||
import io.anuke.mindustry.entities.traits.TypeTrait;
|
import io.anuke.mindustry.entities.traits.TypeTrait;
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ import io.anuke.arc.Events;
|
|||||||
import io.anuke.arc.collection.Array;
|
import io.anuke.arc.collection.Array;
|
||||||
import io.anuke.arc.collection.IntMap;
|
import io.anuke.arc.collection.IntMap;
|
||||||
import io.anuke.arc.collection.ObjectSet;
|
import io.anuke.arc.collection.ObjectSet;
|
||||||
import io.anuke.arc.entities.Entities;
|
import io.anuke.mindustry.entities.Entities;
|
||||||
import io.anuke.arc.entities.EntityGroup;
|
import io.anuke.mindustry.entities.EntityGroup;
|
||||||
import io.anuke.arc.entities.EntityQuery;
|
import io.anuke.mindustry.entities.EntityQuery;
|
||||||
import io.anuke.arc.entities.trait.Entity;
|
import io.anuke.mindustry.entities.traits.Entity;
|
||||||
import io.anuke.arc.graphics.Color;
|
import io.anuke.arc.graphics.Color;
|
||||||
import io.anuke.arc.graphics.Colors;
|
import io.anuke.arc.graphics.Colors;
|
||||||
import io.anuke.arc.math.Mathf;
|
import io.anuke.arc.math.Mathf;
|
||||||
@@ -24,7 +24,7 @@ import io.anuke.arc.util.io.CountableByteArrayOutputStream;
|
|||||||
import io.anuke.mindustry.content.Mechs;
|
import io.anuke.mindustry.content.Mechs;
|
||||||
import io.anuke.mindustry.content.Blocks;
|
import io.anuke.mindustry.content.Blocks;
|
||||||
import io.anuke.mindustry.core.GameState.State;
|
import io.anuke.mindustry.core.GameState.State;
|
||||||
import io.anuke.mindustry.entities.Player;
|
import io.anuke.mindustry.entities.type.Player;
|
||||||
import io.anuke.mindustry.entities.traits.BuilderTrait.BuildRequest;
|
import io.anuke.mindustry.entities.traits.BuilderTrait.BuildRequest;
|
||||||
import io.anuke.mindustry.entities.traits.SyncTrait;
|
import io.anuke.mindustry.entities.traits.SyncTrait;
|
||||||
import io.anuke.mindustry.game.EventType.WorldLoadEvent;
|
import io.anuke.mindustry.game.EventType.WorldLoadEvent;
|
||||||
|
|||||||
@@ -2,12 +2,12 @@ package io.anuke.mindustry.core;
|
|||||||
|
|
||||||
import io.anuke.arc.ApplicationListener;
|
import io.anuke.arc.ApplicationListener;
|
||||||
import io.anuke.arc.Core;
|
import io.anuke.arc.Core;
|
||||||
import io.anuke.arc.entities.Effects;
|
import io.anuke.mindustry.entities.Effects;
|
||||||
import io.anuke.arc.entities.EntityDraw;
|
import io.anuke.mindustry.entities.EntityDraw;
|
||||||
import io.anuke.arc.entities.EntityGroup;
|
import io.anuke.mindustry.entities.EntityGroup;
|
||||||
import io.anuke.arc.entities.impl.EffectEntity;
|
import io.anuke.mindustry.entities.impl.EffectEntity;
|
||||||
import io.anuke.arc.entities.trait.DrawTrait;
|
import io.anuke.mindustry.entities.traits.DrawTrait;
|
||||||
import io.anuke.arc.entities.trait.Entity;
|
import io.anuke.mindustry.entities.traits.Entity;
|
||||||
import io.anuke.arc.function.Consumer;
|
import io.anuke.arc.function.Consumer;
|
||||||
import io.anuke.arc.function.Predicate;
|
import io.anuke.arc.function.Predicate;
|
||||||
import io.anuke.arc.graphics.Camera;
|
import io.anuke.arc.graphics.Camera;
|
||||||
@@ -23,13 +23,13 @@ import io.anuke.arc.util.Time;
|
|||||||
import io.anuke.arc.util.pooling.Pools;
|
import io.anuke.arc.util.pooling.Pools;
|
||||||
import io.anuke.mindustry.content.Fx;
|
import io.anuke.mindustry.content.Fx;
|
||||||
import io.anuke.mindustry.core.GameState.State;
|
import io.anuke.mindustry.core.GameState.State;
|
||||||
import io.anuke.mindustry.entities.Player;
|
import io.anuke.mindustry.entities.type.Player;
|
||||||
import io.anuke.mindustry.entities.TileEntity;
|
import io.anuke.mindustry.entities.type.TileEntity;
|
||||||
import io.anuke.mindustry.entities.Unit;
|
import io.anuke.mindustry.entities.type.Unit;
|
||||||
import io.anuke.mindustry.entities.effect.GroundEffectEntity;
|
import io.anuke.mindustry.entities.effect.GroundEffectEntity;
|
||||||
import io.anuke.mindustry.entities.effect.GroundEffectEntity.GroundEffect;
|
import io.anuke.mindustry.entities.effect.GroundEffectEntity.GroundEffect;
|
||||||
import io.anuke.mindustry.entities.traits.BelowLiquidTrait;
|
import io.anuke.mindustry.entities.traits.BelowLiquidTrait;
|
||||||
import io.anuke.mindustry.entities.units.BaseUnit;
|
import io.anuke.mindustry.entities.type.BaseUnit;
|
||||||
import io.anuke.mindustry.game.Team;
|
import io.anuke.mindustry.game.Team;
|
||||||
import io.anuke.mindustry.graphics.*;
|
import io.anuke.mindustry.graphics.*;
|
||||||
|
|
||||||
@@ -116,7 +116,7 @@ public class Renderer implements ApplicationListener{
|
|||||||
|
|
||||||
if(players[0].isDead()){
|
if(players[0].isDead()){
|
||||||
TileEntity core = players[0].getClosestCore();
|
TileEntity core = players[0].getClosestCore();
|
||||||
if(core != null && players[0].spawner == Unit.noSpawner){
|
if(core != null && players[0].spawner == null){
|
||||||
camera.position.lerpDelta(core.x, core.y, 0.08f);
|
camera.position.lerpDelta(core.x, core.y, 0.08f);
|
||||||
}else{
|
}else{
|
||||||
camera.position.lerpDelta(position, 0.08f);
|
camera.position.lerpDelta(position, 0.08f);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import io.anuke.arc.Core;
|
|||||||
import io.anuke.arc.Events;
|
import io.anuke.arc.Events;
|
||||||
import io.anuke.arc.collection.Array;
|
import io.anuke.arc.collection.Array;
|
||||||
import io.anuke.arc.collection.IntArray;
|
import io.anuke.arc.collection.IntArray;
|
||||||
import io.anuke.arc.entities.EntityQuery;
|
import io.anuke.mindustry.entities.EntityQuery;
|
||||||
import io.anuke.arc.math.Mathf;
|
import io.anuke.arc.math.Mathf;
|
||||||
import io.anuke.arc.math.geom.Geometry;
|
import io.anuke.arc.math.geom.Geometry;
|
||||||
import io.anuke.arc.math.geom.Point2;
|
import io.anuke.arc.math.geom.Point2;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package io.anuke.mindustry.entities;
|
package io.anuke.mindustry.entities;
|
||||||
|
|
||||||
import io.anuke.arc.entities.Effects;
|
import io.anuke.mindustry.entities.Effects.Effect;
|
||||||
import io.anuke.arc.entities.Effects.Effect;
|
|
||||||
import io.anuke.arc.function.Consumer;
|
import io.anuke.arc.function.Consumer;
|
||||||
import io.anuke.arc.function.Predicate;
|
import io.anuke.arc.function.Predicate;
|
||||||
import io.anuke.arc.graphics.Color;
|
import io.anuke.arc.graphics.Color;
|
||||||
@@ -15,6 +14,7 @@ import io.anuke.mindustry.content.Fx;
|
|||||||
import io.anuke.mindustry.entities.bullet.Bullet;
|
import io.anuke.mindustry.entities.bullet.Bullet;
|
||||||
import io.anuke.mindustry.entities.effect.Fire;
|
import io.anuke.mindustry.entities.effect.Fire;
|
||||||
import io.anuke.mindustry.entities.effect.Lightning;
|
import io.anuke.mindustry.entities.effect.Lightning;
|
||||||
|
import io.anuke.mindustry.entities.type.Unit;
|
||||||
import io.anuke.mindustry.game.Team;
|
import io.anuke.mindustry.game.Team;
|
||||||
import io.anuke.mindustry.gen.Call;
|
import io.anuke.mindustry.gen.Call;
|
||||||
import io.anuke.mindustry.graphics.Palette;
|
import io.anuke.mindustry.graphics.Palette;
|
||||||
@@ -109,7 +109,7 @@ public class Damage{
|
|||||||
rect.width += expand * 2;
|
rect.width += expand * 2;
|
||||||
rect.height += expand * 2;
|
rect.height += expand * 2;
|
||||||
|
|
||||||
Consumer<Unit> cons = e -> {
|
Consumer<io.anuke.mindustry.entities.type.Unit> cons = e -> {
|
||||||
e.hitbox(hitrect);
|
e.hitbox(hitrect);
|
||||||
Rectangle other = hitrect;
|
Rectangle other = hitrect;
|
||||||
other.y -= expand;
|
other.y -= expand;
|
||||||
@@ -130,8 +130,8 @@ public class Damage{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**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<Unit> predicate, Consumer<Unit> acceptor){
|
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<Unit> cons = entity -> {
|
Consumer<io.anuke.mindustry.entities.type.Unit> cons = entity -> {
|
||||||
if(!predicate.test(entity)) return;
|
if(!predicate.test(entity)) return;
|
||||||
|
|
||||||
entity.hitbox(hitrect);
|
entity.hitbox(hitrect);
|
||||||
@@ -158,7 +158,7 @@ public class Damage{
|
|||||||
/**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){
|
public static void damage(Team team, float x, float y, float radius, float damage){
|
||||||
Consumer<Unit> cons = entity -> {
|
Consumer<Unit> cons = entity -> {
|
||||||
if(entity.team == team || entity.dst(x, y) > radius){
|
if(entity.getTeam() == team || entity.dst(x, y) > radius){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
float amount = calculateDamage(x, y, entity.x, entity.y, radius, damage);
|
float amount = calculateDamage(x, y, entity.x, entity.y, radius, damage);
|
||||||
|
|||||||
166
core/src/io/anuke/mindustry/entities/Effects.java
Normal file
166
core/src/io/anuke/mindustry/entities/Effects.java
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
package io.anuke.mindustry.entities;
|
||||||
|
|
||||||
|
import io.anuke.arc.Core;
|
||||||
|
import io.anuke.arc.collection.Array;
|
||||||
|
import io.anuke.arc.function.Consumer;
|
||||||
|
import io.anuke.arc.graphics.Color;
|
||||||
|
import io.anuke.arc.math.Mathf;
|
||||||
|
import io.anuke.arc.math.geom.Position;
|
||||||
|
import io.anuke.arc.util.pooling.Pools;
|
||||||
|
import io.anuke.mindustry.entities.impl.EffectEntity;
|
||||||
|
import io.anuke.mindustry.entities.traits.ScaleTrait;
|
||||||
|
|
||||||
|
public class Effects{
|
||||||
|
private static final EffectContainer container = new EffectContainer();
|
||||||
|
private static Array<Effect> effects = new Array<>();
|
||||||
|
private static ScreenshakeProvider shakeProvider;
|
||||||
|
private static float shakeFalloff = 1000f;
|
||||||
|
private static EffectProvider provider = (effect, color, x, y, rotation, data) -> {
|
||||||
|
EffectEntity entity = Pools.obtain(EffectEntity.class, EffectEntity::new);
|
||||||
|
entity.effect = effect;
|
||||||
|
entity.color = color;
|
||||||
|
entity.rotation = rotation;
|
||||||
|
entity.data = data;
|
||||||
|
entity.set(x, y);
|
||||||
|
entity.add();
|
||||||
|
};
|
||||||
|
|
||||||
|
public static void setEffectProvider(EffectProvider prov){
|
||||||
|
provider = prov;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setScreenShakeProvider(ScreenshakeProvider provider){
|
||||||
|
shakeProvider = provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void renderEffect(int id, Effect render, Color color, float life, float rotation, float x, float y, Object data){
|
||||||
|
container.set(id, color, life, render.lifetime, rotation, x, y, data);
|
||||||
|
render.draw.render(container);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Effect getEffect(int id){
|
||||||
|
if(id >= effects.size || id < 0)
|
||||||
|
throw new IllegalArgumentException("The effect with ID \"" + id + "\" does not exist!");
|
||||||
|
return effects.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Array<Effect> all(){
|
||||||
|
return effects;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void effect(Effect effect, float x, float y, float rotation){
|
||||||
|
provider.createEffect(effect, Color.WHITE, x, y, rotation, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void effect(Effect effect, float x, float y){
|
||||||
|
effect(effect, x, y, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void effect(Effect effect, Color color, float x, float y){
|
||||||
|
provider.createEffect(effect, color, x, y, 0f, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void effect(Effect effect, Position loc){
|
||||||
|
provider.createEffect(effect, Color.WHITE, loc.getX(), loc.getY(), 0f, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void effect(Effect effect, Color color, float x, float y, float rotation){
|
||||||
|
provider.createEffect(effect, color, x, y, rotation, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void effect(Effect effect, Color color, float x, float y, float rotation, Object data){
|
||||||
|
provider.createEffect(effect, color, x, y, rotation, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void effect(Effect effect, float x, float y, float rotation, Object data){
|
||||||
|
provider.createEffect(effect, Color.WHITE, x, y, rotation, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Default value is 1000. Higher numbers mean more powerful shake (less falloff). */
|
||||||
|
public static void setShakeFalloff(float falloff){
|
||||||
|
shakeFalloff = falloff;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void shake(float intensity, float duration){
|
||||||
|
if(shakeProvider == null) throw new RuntimeException("Screenshake provider is null! Set it first.");
|
||||||
|
shakeProvider.accept(intensity, duration);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void shake(float intensity, float duration, float x, float y){
|
||||||
|
if(Core.camera == null) return;
|
||||||
|
|
||||||
|
float distance = Core.camera.position.dst(x, y);
|
||||||
|
if(distance < 1) distance = 1;
|
||||||
|
|
||||||
|
shake(Mathf.clamp(1f / (distance * distance / shakeFalloff)) * intensity, duration);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void shake(float intensity, float duration, Position loc){
|
||||||
|
shake(intensity, duration, loc.getX(), loc.getY());
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface ScreenshakeProvider{
|
||||||
|
void accept(float intensity, float duration);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Effect{
|
||||||
|
private static int lastid = 0;
|
||||||
|
public final int id;
|
||||||
|
public final EffectRenderer draw;
|
||||||
|
public final float lifetime;
|
||||||
|
/** Clip size. */
|
||||||
|
public float size;
|
||||||
|
|
||||||
|
public Effect(float life, float clipsize, EffectRenderer draw){
|
||||||
|
this.id = lastid++;
|
||||||
|
this.lifetime = life;
|
||||||
|
this.draw = draw;
|
||||||
|
this.size = clipsize;
|
||||||
|
effects.add(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Effect(float life, EffectRenderer draw){
|
||||||
|
this(life, 28f, draw);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EffectContainer implements ScaleTrait{
|
||||||
|
public float x, y, time, lifetime, rotation;
|
||||||
|
public Color color;
|
||||||
|
public int id;
|
||||||
|
public Object data;
|
||||||
|
private EffectContainer innerContainer;
|
||||||
|
|
||||||
|
public void set(int id, Color color, float life, float lifetime, float rotation, float x, float y, Object data){
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.color = color;
|
||||||
|
this.time = life;
|
||||||
|
this.lifetime = lifetime;
|
||||||
|
this.id = id;
|
||||||
|
this.rotation = rotation;
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void scaled(float lifetime, Consumer<EffectContainer> cons){
|
||||||
|
if(innerContainer == null) innerContainer = new EffectContainer();
|
||||||
|
if(time <= lifetime){
|
||||||
|
innerContainer.set(id, color, time, lifetime, rotation, x, y, data);
|
||||||
|
cons.accept(innerContainer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float fin(){
|
||||||
|
return time / lifetime;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static interface EffectProvider{
|
||||||
|
void createEffect(Effect effect, Color color, float x, float y, float rotation, Object data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static interface EffectRenderer{
|
||||||
|
void render(EffectContainer effect);
|
||||||
|
}
|
||||||
|
}
|
||||||
66
core/src/io/anuke/mindustry/entities/Entities.java
Executable file
66
core/src/io/anuke/mindustry/entities/Entities.java
Executable file
@@ -0,0 +1,66 @@
|
|||||||
|
package io.anuke.mindustry.entities;
|
||||||
|
|
||||||
|
import io.anuke.arc.collection.Array;
|
||||||
|
import io.anuke.arc.collection.IntMap;
|
||||||
|
import io.anuke.mindustry.entities.traits.Entity;
|
||||||
|
|
||||||
|
public class Entities{
|
||||||
|
public static final int maxLeafObjects = 5;
|
||||||
|
private static final EntityGroup<Entity> defaultGroup;
|
||||||
|
private static final Array<EntityGroup<?>> groupArray = new Array<>();
|
||||||
|
private static final IntMap<EntityGroup<?>> groups = new IntMap<>();
|
||||||
|
|
||||||
|
static{
|
||||||
|
defaultGroup = addGroup(Entity.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void clear(){
|
||||||
|
for(EntityGroup group : groupArray){
|
||||||
|
group.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Iterable<Entity> all(){
|
||||||
|
return defaultGroup.all();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static EntityGroup<?> getGroup(int id){
|
||||||
|
return groups.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Iterable<EntityGroup<?>> getAllGroups(){
|
||||||
|
return groups.values();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static EntityGroup<Entity> defaultGroup(){
|
||||||
|
return defaultGroup;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T extends Entity> EntityGroup<T> addGroup(Class<T> type){
|
||||||
|
return addGroup(type, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T extends Entity> EntityGroup<T> addGroup(Class<T> type, boolean useTree){
|
||||||
|
EntityGroup<T> group = new EntityGroup<>(type, useTree);
|
||||||
|
groups.put(group.getID(), group);
|
||||||
|
groupArray.add(group);
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void update(){
|
||||||
|
update(defaultGroup());
|
||||||
|
EntityQuery.collideGroups(defaultGroup(), defaultGroup());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void update(EntityGroup<?> group){
|
||||||
|
group.updateEvents();
|
||||||
|
|
||||||
|
if(group.useTree()){
|
||||||
|
EntityQuery.collisions().updatePhysics(group);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(Entity e : group.all()){
|
||||||
|
e.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
261
core/src/io/anuke/mindustry/entities/EntityCollisions.java
Normal file
261
core/src/io/anuke/mindustry/entities/EntityCollisions.java
Normal file
@@ -0,0 +1,261 @@
|
|||||||
|
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.mindustry.entities.traits.Entity;
|
||||||
|
import io.anuke.mindustry.entities.traits.SolidTrait;
|
||||||
|
|
||||||
|
public class EntityCollisions{
|
||||||
|
//range for tile collision scanning
|
||||||
|
private static final int r = 2;
|
||||||
|
//move in 1-unit chunks
|
||||||
|
private static final float seg = 1f;
|
||||||
|
|
||||||
|
//tile collisions
|
||||||
|
private float tilesize;
|
||||||
|
private Rectangle tmp = new Rectangle();
|
||||||
|
private TileCollider collider;
|
||||||
|
private TileHitboxProvider hitboxProvider;
|
||||||
|
private Vector2 vector = new Vector2();
|
||||||
|
private Vector2 l1 = new Vector2();
|
||||||
|
private Rectangle r1 = new Rectangle();
|
||||||
|
private Rectangle r2 = new Rectangle();
|
||||||
|
|
||||||
|
//entity collisions
|
||||||
|
private IntSet collided = new IntSet();
|
||||||
|
private Array<SolidTrait> arrOut = new Array<>();
|
||||||
|
|
||||||
|
public void setCollider(float tilesize, TileCollider collider, TileHitboxProvider hitbox){
|
||||||
|
this.tilesize = tilesize;
|
||||||
|
this.collider = collider;
|
||||||
|
this.hitboxProvider = hitbox;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCollider(float tilesize, TileCollider collider){
|
||||||
|
setCollider(tilesize, collider, (x, y, out) -> out.setSize(tilesize).setCenter(x * tilesize, y * tilesize));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void move(SolidTrait entity, float deltax, float deltay){
|
||||||
|
|
||||||
|
boolean movedx = false;
|
||||||
|
|
||||||
|
while(Math.abs(deltax) > 0 || !movedx){
|
||||||
|
movedx = true;
|
||||||
|
moveInternal(entity, Math.min(Math.abs(deltax), seg) * Mathf.sign(deltax), 0, true);
|
||||||
|
|
||||||
|
if(Math.abs(deltax) >= seg){
|
||||||
|
deltax -= seg * Mathf.sign(deltax);
|
||||||
|
}else{
|
||||||
|
deltax = 0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean movedy = false;
|
||||||
|
|
||||||
|
while(Math.abs(deltay) > 0 || !movedy){
|
||||||
|
movedy = true;
|
||||||
|
moveInternal(entity, 0, Math.min(Math.abs(deltay), seg) * Mathf.sign(deltay), false);
|
||||||
|
|
||||||
|
if(Math.abs(deltay) >= seg){
|
||||||
|
deltay -= seg * Mathf.sign(deltay);
|
||||||
|
}else{
|
||||||
|
deltay = 0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void moveInternal(SolidTrait entity, float deltax, float deltay, boolean x){
|
||||||
|
if(collider == null)
|
||||||
|
throw new IllegalArgumentException("No tile collider specified! Call setCollider() first.");
|
||||||
|
|
||||||
|
Rectangle rect = r1;
|
||||||
|
entity.hitboxTile(rect);
|
||||||
|
entity.hitboxTile(r2);
|
||||||
|
rect.x += deltax;
|
||||||
|
rect.y += deltay;
|
||||||
|
|
||||||
|
int tilex = Math.round((rect.x + rect.width / 2) / tilesize), tiley = Math.round((rect.y + rect.height / 2) / tilesize);
|
||||||
|
|
||||||
|
for(int dx = -r; dx <= r; dx++){
|
||||||
|
for(int dy = -r; dy <= r; dy++){
|
||||||
|
int wx = dx + tilex, wy = dy + tiley;
|
||||||
|
if(collider.solid(wx, wy) && entity.collidesGrid(wx, wy)){
|
||||||
|
|
||||||
|
hitboxProvider.getHitbox(wx, wy, tmp);
|
||||||
|
|
||||||
|
if(tmp.overlaps(rect)){
|
||||||
|
Vector2 v = Geometry.overlap(rect, tmp, x);
|
||||||
|
rect.x += v.x;
|
||||||
|
rect.y += v.y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
entity.setX(entity.getX() + rect.x - r2.x);
|
||||||
|
entity.setY(entity.getY() + rect.y - r2.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean overlapsTile(Rectangle rect){
|
||||||
|
if(collider == null)
|
||||||
|
throw new IllegalArgumentException("No tile collider specified! Call setCollider() first.");
|
||||||
|
|
||||||
|
rect.getCenter(vector);
|
||||||
|
int r = 1;
|
||||||
|
|
||||||
|
//assumes tiles are centered
|
||||||
|
int tilex = Math.round(vector.x / tilesize);
|
||||||
|
int tiley = Math.round(vector.y / tilesize);
|
||||||
|
|
||||||
|
for(int dx = -r; dx <= r; dx++){
|
||||||
|
for(int dy = -r; dy <= r; dy++){
|
||||||
|
int wx = dx + tilex, wy = dy + tiley;
|
||||||
|
if(collider.solid(wx, wy)){
|
||||||
|
hitboxProvider.getHitbox(wx, wy, r2);
|
||||||
|
|
||||||
|
if(r2.overlaps(rect)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T extends Entity> void updatePhysics(EntityGroup<T> group){
|
||||||
|
collided.clear();
|
||||||
|
|
||||||
|
QuadTree tree = group.tree();
|
||||||
|
tree.clear();
|
||||||
|
|
||||||
|
for(Entity entity : group.all()){
|
||||||
|
if(entity instanceof SolidTrait){
|
||||||
|
SolidTrait s = (SolidTrait) entity;
|
||||||
|
s.lastPosition().set(s.getX(), s.getY());
|
||||||
|
tree.insert(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkCollide(Entity entity, Entity other){
|
||||||
|
|
||||||
|
SolidTrait a = (SolidTrait) entity;
|
||||||
|
SolidTrait b = (SolidTrait) other;
|
||||||
|
|
||||||
|
a.hitbox(this.r1);
|
||||||
|
b.hitbox(this.r2);
|
||||||
|
|
||||||
|
r1.x += (a.lastPosition().x - a.getX());
|
||||||
|
r1.y += (a.lastPosition().y - a.getY());
|
||||||
|
r2.x += (b.lastPosition().x - b.getX());
|
||||||
|
r2.y += (b.lastPosition().y - b.getY());
|
||||||
|
|
||||||
|
float vax = a.getX() - a.lastPosition().x;
|
||||||
|
float vay = a.getY() - a.lastPosition().y;
|
||||||
|
float vbx = b.getX() - b.lastPosition().x;
|
||||||
|
float vby = b.getY() - b.lastPosition().y;
|
||||||
|
|
||||||
|
if(a != b && a.collides(b) && b.collides(a)){
|
||||||
|
l1.set(a.getX(), a.getY());
|
||||||
|
boolean collide = r1.overlaps(r2) || collide(r1.x, r1.y, r1.width, r1.height, vax, vay,
|
||||||
|
r2.x, r2.y, r2.width, r2.height, vbx, vby, l1);
|
||||||
|
if(collide){
|
||||||
|
a.collision(b, l1.x, l1.y);
|
||||||
|
b.collision(a, l1.x, l1.y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean collide(float x1, float y1, float w1, float h1, float vx1, float vy1,
|
||||||
|
float x2, float y2, float w2, float h2, float vx2, float vy2, Vector2 out){
|
||||||
|
float px = vx1, py = vy1;
|
||||||
|
|
||||||
|
vx1 -= vx2;
|
||||||
|
vy1 -= vy2;
|
||||||
|
|
||||||
|
float xInvEntry, yInvEntry;
|
||||||
|
float xInvExit, yInvExit;
|
||||||
|
|
||||||
|
if(vx1 > 0.0f){
|
||||||
|
xInvEntry = x2 - (x1 + w1);
|
||||||
|
xInvExit = (x2 + w2) - x1;
|
||||||
|
}else{
|
||||||
|
xInvEntry = (x2 + w2) - x1;
|
||||||
|
xInvExit = x2 - (x1 + w1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(vy1 > 0.0f){
|
||||||
|
yInvEntry = y2 - (y1 + h1);
|
||||||
|
yInvExit = (y2 + h2) - y1;
|
||||||
|
}else{
|
||||||
|
yInvEntry = (y2 + h2) - y1;
|
||||||
|
yInvExit = y2 - (y1 + h1);
|
||||||
|
}
|
||||||
|
|
||||||
|
float xEntry, yEntry;
|
||||||
|
float xExit, yExit;
|
||||||
|
|
||||||
|
xEntry = xInvEntry / vx1;
|
||||||
|
xExit = xInvExit / vx1;
|
||||||
|
|
||||||
|
yEntry = yInvEntry / vy1;
|
||||||
|
yExit = yInvExit / vy1;
|
||||||
|
|
||||||
|
float entryTime = Math.max(xEntry, yEntry);
|
||||||
|
float exitTime = Math.min(xExit, yExit);
|
||||||
|
|
||||||
|
if(entryTime > exitTime || xExit < 0.0f || yExit < 0.0f || xEntry > 1.0f || yEntry > 1.0f){
|
||||||
|
return false;
|
||||||
|
}else{
|
||||||
|
float dx = x1 + w1 / 2f + px * entryTime;
|
||||||
|
float dy = y1 + h1 / 2f + py * entryTime;
|
||||||
|
|
||||||
|
out.set(dx, dy);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void collideGroups(EntityGroup<?> groupa, EntityGroup<?> groupb){
|
||||||
|
collided.clear();
|
||||||
|
|
||||||
|
for(Entity entity : groupa.all()){
|
||||||
|
if(!(entity instanceof SolidTrait) || collided.contains(entity.getID()))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
SolidTrait solid = (SolidTrait) entity;
|
||||||
|
|
||||||
|
solid.hitbox(r1);
|
||||||
|
r1.x += (solid.lastPosition().x - solid.getX());
|
||||||
|
r1.y += (solid.lastPosition().y - solid.getY());
|
||||||
|
|
||||||
|
solid.hitbox(r2);
|
||||||
|
r2.merge(r1);
|
||||||
|
|
||||||
|
arrOut.clear();
|
||||||
|
groupb.tree().getIntersect(arrOut, r2);
|
||||||
|
|
||||||
|
for(SolidTrait sc : arrOut){
|
||||||
|
sc.hitbox(r1);
|
||||||
|
if(r2.overlaps(r1) && !collided.contains(sc.getID())){
|
||||||
|
checkCollide(entity, sc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
collided.add(entity.getID());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface TileCollider{
|
||||||
|
boolean solid(int x, int y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface TileHitboxProvider{
|
||||||
|
void getHitbox(int x, int y, Rectangle out);
|
||||||
|
}
|
||||||
|
}
|
||||||
49
core/src/io/anuke/mindustry/entities/EntityDraw.java
Normal file
49
core/src/io/anuke/mindustry/entities/EntityDraw.java
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
package io.anuke.mindustry.entities;
|
||||||
|
|
||||||
|
import io.anuke.arc.Core;
|
||||||
|
import io.anuke.arc.function.Consumer;
|
||||||
|
import io.anuke.arc.function.Predicate;
|
||||||
|
import io.anuke.arc.graphics.Camera;
|
||||||
|
import io.anuke.arc.math.geom.Rectangle;
|
||||||
|
import io.anuke.mindustry.entities.traits.DrawTrait;
|
||||||
|
|
||||||
|
public class EntityDraw{
|
||||||
|
private static final Rectangle viewport = new Rectangle();
|
||||||
|
private static final Rectangle rect = new Rectangle();
|
||||||
|
private static boolean clip = true;
|
||||||
|
|
||||||
|
public static void setClip(boolean clip){
|
||||||
|
EntityDraw.clip = clip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void draw(){
|
||||||
|
draw(Entities.defaultGroup());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void draw(EntityGroup<?> group){
|
||||||
|
draw(group, e -> true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T extends DrawTrait> void draw(EntityGroup<?> group, Predicate<T> toDraw){
|
||||||
|
drawWith(group, toDraw, DrawTrait::draw);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static <T extends DrawTrait> void drawWith(EntityGroup<?> group, Predicate<T> toDraw, Consumer<T> cons){
|
||||||
|
if(clip){
|
||||||
|
Camera cam = Core.camera;
|
||||||
|
viewport.set(cam.position.x - cam.width / 2, cam.position.y - cam.height / 2, cam.width, cam.height);
|
||||||
|
}
|
||||||
|
|
||||||
|
group.forEach(e -> {
|
||||||
|
if(!(e instanceof DrawTrait)) return;
|
||||||
|
T t = (T) e;
|
||||||
|
|
||||||
|
if(!toDraw.test(t) || !e.isAdded()) return;
|
||||||
|
|
||||||
|
if(!clip || rect.setSize(((DrawTrait) e).drawSize()).setCenter(e.getX(), e.getY()).overlaps(viewport)){
|
||||||
|
cons.accept(t);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
194
core/src/io/anuke/mindustry/entities/EntityGroup.java
Normal file
194
core/src/io/anuke/mindustry/entities/EntityGroup.java
Normal file
@@ -0,0 +1,194 @@
|
|||||||
|
package io.anuke.mindustry.entities;
|
||||||
|
|
||||||
|
import io.anuke.arc.collection.Array;
|
||||||
|
import io.anuke.arc.collection.IntMap;
|
||||||
|
import io.anuke.arc.function.Consumer;
|
||||||
|
import io.anuke.arc.function.Predicate;
|
||||||
|
import io.anuke.arc.math.geom.QuadTree;
|
||||||
|
import io.anuke.arc.math.geom.Rectangle;
|
||||||
|
import io.anuke.mindustry.entities.traits.Entity;
|
||||||
|
|
||||||
|
public class EntityGroup<T extends Entity>{
|
||||||
|
private static int lastid;
|
||||||
|
private final boolean useTree;
|
||||||
|
private final int id;
|
||||||
|
private final Class<T> type;
|
||||||
|
private final Array<T> entityArray = new Array<>(false, 16);
|
||||||
|
private final Array<T> entitiesToRemove = new Array<>(false, 16);
|
||||||
|
private final Array<T> entitiesToAdd = new Array<>(false, 16);
|
||||||
|
private IntMap<T> map;
|
||||||
|
private QuadTree<T> tree;
|
||||||
|
private Consumer<T> removeListener;
|
||||||
|
private Consumer<T> addListener;
|
||||||
|
|
||||||
|
public EntityGroup(Class<T> type, boolean useTree){
|
||||||
|
this.useTree = useTree;
|
||||||
|
this.id = lastid++;
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean useTree(){
|
||||||
|
return useTree;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRemoveListener(Consumer<T> removeListener){
|
||||||
|
this.removeListener = removeListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAddListener(Consumer<T> addListener){
|
||||||
|
this.addListener = addListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityGroup<T> enableMapping(){
|
||||||
|
map = new IntMap<>();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean mappingEnabled(){
|
||||||
|
return map != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Class<T> getType(){
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getID(){
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateEvents(){
|
||||||
|
|
||||||
|
for(T e : entitiesToAdd){
|
||||||
|
if(e == null)
|
||||||
|
continue;
|
||||||
|
entityArray.add(e);
|
||||||
|
e.added();
|
||||||
|
|
||||||
|
if(map != null){
|
||||||
|
map.put(e.getID(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
entitiesToAdd.clear();
|
||||||
|
|
||||||
|
for(T e : entitiesToRemove){
|
||||||
|
entityArray.removeValue(e, true);
|
||||||
|
if(map != null){
|
||||||
|
map.remove(e.getID());
|
||||||
|
}
|
||||||
|
e.removed();
|
||||||
|
}
|
||||||
|
|
||||||
|
entitiesToRemove.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T getByID(int id){
|
||||||
|
if(map == null) throw new RuntimeException("Mapping is not enabled for group " + id + "!");
|
||||||
|
return map.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeByID(int id){
|
||||||
|
if(map == null) throw new RuntimeException("Mapping is not enabled for group " + id + "!");
|
||||||
|
T t = map.get(id);
|
||||||
|
if(t != null){ //remove if present in map already
|
||||||
|
remove(t);
|
||||||
|
}else{ //maybe it's being queued?
|
||||||
|
for(T check : entitiesToAdd){
|
||||||
|
if(check.getID() == id){ //if it is indeed queued, remove it
|
||||||
|
entitiesToAdd.removeValue(check, true);
|
||||||
|
if(removeListener != null){
|
||||||
|
removeListener.accept(check);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public QuadTree tree(){
|
||||||
|
return tree;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTree(float x, float y, float w, float h){
|
||||||
|
tree = new QuadTree<>(Entities.maxLeafObjects, new Rectangle(x, y, w, h));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEmpty(){
|
||||||
|
return entityArray.size == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int size(){
|
||||||
|
return entityArray.size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int count(Predicate<T> pred){
|
||||||
|
int count = 0;
|
||||||
|
for(int i = 0; i < entityArray.size; i++){
|
||||||
|
if(pred.test(entityArray.get(i))) count++;
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(T type){
|
||||||
|
if(type == null) throw new RuntimeException("Cannot add a null entity!");
|
||||||
|
if(type.getGroup() != null) return;
|
||||||
|
type.setGroup(this);
|
||||||
|
entitiesToAdd.add(type);
|
||||||
|
|
||||||
|
if(mappingEnabled()){
|
||||||
|
map.put(type.getID(), type);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(addListener != null){
|
||||||
|
addListener.accept(type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(T type){
|
||||||
|
if(type == null) throw new RuntimeException("Cannot remove a null entity!");
|
||||||
|
type.setGroup(null);
|
||||||
|
entitiesToRemove.add(type);
|
||||||
|
|
||||||
|
if(removeListener != null){
|
||||||
|
removeListener.accept(type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear(){
|
||||||
|
for(T entity : entityArray)
|
||||||
|
entity.setGroup(null);
|
||||||
|
|
||||||
|
for(T entity : entitiesToAdd)
|
||||||
|
entity.setGroup(null);
|
||||||
|
|
||||||
|
for(T entity : entitiesToRemove)
|
||||||
|
entity.setGroup(null);
|
||||||
|
|
||||||
|
entitiesToAdd.clear();
|
||||||
|
entitiesToRemove.clear();
|
||||||
|
entityArray.clear();
|
||||||
|
if(map != null)
|
||||||
|
map.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T find(Predicate<T> pred){
|
||||||
|
|
||||||
|
for(int i = 0; i < entityArray.size; i++){
|
||||||
|
if(pred.test(entityArray.get(i))) return entityArray.get(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**Returns the logic-only array for iteration.*/
|
||||||
|
public Array<T> all(){
|
||||||
|
return entityArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void forEach(Consumer<T> cons){
|
||||||
|
|
||||||
|
for(T t : entityArray){
|
||||||
|
cons.accept(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
95
core/src/io/anuke/mindustry/entities/EntityQuery.java
Normal file
95
core/src/io/anuke/mindustry/entities/EntityQuery.java
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
package io.anuke.mindustry.entities;
|
||||||
|
|
||||||
|
import io.anuke.arc.collection.Array;
|
||||||
|
import io.anuke.arc.function.Consumer;
|
||||||
|
import io.anuke.arc.function.Predicate;
|
||||||
|
import io.anuke.arc.math.Mathf;
|
||||||
|
import io.anuke.arc.math.geom.Rectangle;
|
||||||
|
import io.anuke.mindustry.entities.traits.Entity;
|
||||||
|
import io.anuke.mindustry.entities.traits.SolidTrait;
|
||||||
|
|
||||||
|
import static io.anuke.mindustry.entities.Entities.defaultGroup;
|
||||||
|
|
||||||
|
public class EntityQuery{
|
||||||
|
private static final EntityCollisions collisions = new EntityCollisions();
|
||||||
|
private static final Array<SolidTrait> array = new Array<>();
|
||||||
|
private static final Rectangle r1 = new Rectangle();
|
||||||
|
|
||||||
|
public static EntityCollisions collisions(){
|
||||||
|
return collisions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void init(float x, float y, float w, float h){
|
||||||
|
|
||||||
|
for(EntityGroup group : Entities.getAllGroups()){
|
||||||
|
if(group.useTree()){
|
||||||
|
group.setTree(x, y, w, h);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void init(){
|
||||||
|
init(0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void resizeTree(float x, float y, float w, float h){
|
||||||
|
init(x, y, w, h);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void getNearby(EntityGroup<?> group, Rectangle rect, Consumer<SolidTrait> out){
|
||||||
|
|
||||||
|
if(!group.useTree())
|
||||||
|
throw new RuntimeException("This group does not support quadtrees! Enable quadtrees when creating it.");
|
||||||
|
group.tree().getIntersect(out, rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Array<SolidTrait> getNearby(EntityGroup<?> group, Rectangle rect){
|
||||||
|
|
||||||
|
array.clear();
|
||||||
|
if(!group.useTree())
|
||||||
|
throw new RuntimeException("This group does not support quadtrees! Enable quadtrees when creating it.");
|
||||||
|
group.tree().getIntersect(array, rect);
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void getNearby(float x, float y, float size, Consumer<SolidTrait> out){
|
||||||
|
getNearby(defaultGroup(), r1.setSize(size).setCenter(x, y), out);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void getNearby(EntityGroup<?> group, float x, float y, float size, Consumer<SolidTrait> out){
|
||||||
|
getNearby(group, r1.setSize(size).setCenter(x, y), out);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Array<SolidTrait> getNearby(float x, float y, float size){
|
||||||
|
return getNearby(defaultGroup(), r1.setSize(size).setCenter(x, y));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Array<SolidTrait> getNearby(EntityGroup<?> group, float x, float y, float size){
|
||||||
|
return getNearby(group, r1.setSize(size).setCenter(x, y));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T extends Entity> T getClosest(EntityGroup<T> group, float x, float y, float range, Predicate<T> pred){
|
||||||
|
|
||||||
|
T closest = null;
|
||||||
|
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);
|
||||||
|
if(!pred.test(e))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
float dist = Mathf.dst(e.getX(), e.getY(), x, y);
|
||||||
|
if(dist < range)
|
||||||
|
if(closest == null || dist < cdist){
|
||||||
|
closest = e;
|
||||||
|
cdist = dist;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return closest;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void collideGroups(EntityGroup<?> groupa, EntityGroup<?> groupb){
|
||||||
|
collisions().collideGroups(groupa, groupb);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
package io.anuke.mindustry.entities;
|
|
||||||
|
|
||||||
import io.anuke.mindustry.entities.traits.Saveable;
|
|
||||||
import io.anuke.mindustry.type.Item;
|
|
||||||
import io.anuke.mindustry.type.ItemStack;
|
|
||||||
|
|
||||||
import java.io.DataInput;
|
|
||||||
import java.io.DataOutput;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.content;
|
|
||||||
|
|
||||||
public class UnitInventory implements Saveable{
|
|
||||||
private final Unit unit;
|
|
||||||
private ItemStack item = new ItemStack(content.item(0), 0);
|
|
||||||
|
|
||||||
public UnitInventory(Unit unit){
|
|
||||||
this.unit = unit;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isFull(){
|
|
||||||
return item != null && item.amount >= unit.getItemCapacity();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeSave(DataOutput stream) throws IOException{
|
|
||||||
stream.writeByte(item.amount);
|
|
||||||
stream.writeByte(item.item.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readSave(DataInput stream) throws IOException{
|
|
||||||
int iamount = stream.readUnsignedByte();
|
|
||||||
byte iid = stream.readByte();
|
|
||||||
|
|
||||||
item.item = content.item(iid);
|
|
||||||
item.amount = iamount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clear(){
|
|
||||||
item.amount = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int capacity(){
|
|
||||||
return unit.getItemCapacity();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEmpty(){
|
|
||||||
return item.amount == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int itemCapacityUsed(Item type){
|
|
||||||
if(canAcceptItem(type)){
|
|
||||||
return !hasItem() ? unit.getItemCapacity() : (unit.getItemCapacity() - item.amount);
|
|
||||||
}else{
|
|
||||||
return unit.getItemCapacity();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean canAcceptItem(Item type){
|
|
||||||
return (!hasItem() && 1 <= unit.getItemCapacity()) || (item.item == type && unit.getItemCapacity() - item.amount > 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean canAcceptItem(Item type, int amount){
|
|
||||||
return (!hasItem() && amount <= unit.getItemCapacity()) || (item.item == type && item.amount + amount <= unit.getItemCapacity());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clearItem(){
|
|
||||||
item.amount = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasItem(){
|
|
||||||
return item.amount > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasItem(Item i, int amount){
|
|
||||||
return item.item == i && item.amount >= amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addItem(Item item, int amount){
|
|
||||||
getItem().amount = getItem().item == item ? getItem().amount + amount : amount;
|
|
||||||
getItem().item = item;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemStack getItem(){
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +1,16 @@
|
|||||||
package io.anuke.mindustry.entities;
|
package io.anuke.mindustry.entities;
|
||||||
|
|
||||||
import io.anuke.arc.collection.EnumSet;
|
import io.anuke.arc.collection.EnumSet;
|
||||||
import io.anuke.arc.entities.EntityGroup;
|
|
||||||
import io.anuke.arc.entities.EntityQuery;
|
|
||||||
import io.anuke.arc.function.Consumer;
|
import io.anuke.arc.function.Consumer;
|
||||||
import io.anuke.arc.function.Predicate;
|
import io.anuke.arc.function.Predicate;
|
||||||
import io.anuke.arc.math.Mathf;
|
import io.anuke.arc.math.Mathf;
|
||||||
import io.anuke.arc.math.geom.Geometry;
|
import io.anuke.arc.math.geom.Geometry;
|
||||||
import io.anuke.arc.math.geom.Rectangle;
|
import io.anuke.arc.math.geom.Rectangle;
|
||||||
import io.anuke.mindustry.entities.traits.TargetTrait;
|
import io.anuke.mindustry.entities.traits.TargetTrait;
|
||||||
import io.anuke.mindustry.entities.units.BaseUnit;
|
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.game.Team;
|
import io.anuke.mindustry.game.Team;
|
||||||
import io.anuke.mindustry.world.Block;
|
import io.anuke.mindustry.world.Block;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
@@ -47,7 +48,7 @@ public class Units{
|
|||||||
|
|
||||||
/**See {@link #invalidateTarget(TargetTrait, Team, float, float, float)}*/
|
/**See {@link #invalidateTarget(TargetTrait, Team, float, float, float)}*/
|
||||||
public static boolean invalidateTarget(TargetTrait target, Unit targeter){
|
public static boolean invalidateTarget(TargetTrait target, Unit targeter){
|
||||||
return invalidateTarget(target, targeter.team, targeter.x, targeter.y, targeter.getWeapon().getAmmo().range());
|
return invalidateTarget(target, targeter.getTeam(), targeter.x, targeter.y, targeter.getWeapon().getAmmo().range());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**Returns whether there are any entities on this tile.*/
|
/**Returns whether there are any entities on this tile.*/
|
||||||
@@ -100,18 +101,18 @@ public class Units{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**Returns the neareset damaged tile.*/
|
/**Returns the neareset damaged tile.*/
|
||||||
public static TileEntity findDamagedTile(Team team, float x, float y){
|
public static io.anuke.mindustry.entities.type.TileEntity findDamagedTile(Team team, float x, float y){
|
||||||
Tile tile = Geometry.findClosest(x, y, world.indexer.getDamaged(team));
|
Tile tile = Geometry.findClosest(x, y, world.indexer.getDamaged(team));
|
||||||
return tile == null ? null : tile.entity;
|
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){
|
public static io.anuke.mindustry.entities.type.TileEntity findAllyTile(Team team, float x, float y, float range, Predicate<Tile> pred){
|
||||||
return world.indexer.findTile(team, x, y, range, 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){
|
public static io.anuke.mindustry.entities.type.TileEntity findEnemyTile(Team team, float x, float y, float range, Predicate<Tile> pred){
|
||||||
for(Team enemy : state.teams.enemiesOf(team)){
|
for(Team enemy : state.teams.enemiesOf(team)){
|
||||||
TileEntity entity = world.indexer.findTile(enemy, x, y, range, pred);
|
TileEntity entity = world.indexer.findTile(enemy, x, y, range, pred);
|
||||||
if(entity != null){
|
if(entity != null){
|
||||||
@@ -133,7 +134,7 @@ public class Units{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//then check all player groups
|
//then check all player groups
|
||||||
for(Player player : playerGroup.all()){
|
for(io.anuke.mindustry.entities.type.Player player : playerGroup.all()){
|
||||||
cons.accept(player);
|
cons.accept(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -209,7 +210,7 @@ public class Units{
|
|||||||
|
|
||||||
//now check all players
|
//now check all players
|
||||||
EntityQuery.getNearby(playerGroup, rect, player -> {
|
EntityQuery.getNearby(playerGroup, rect, player -> {
|
||||||
if(((Unit) player).team == team) cons.accept((Unit) player);
|
if(((Unit) player).getTeam() == team) cons.accept((Unit) player);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,7 +229,7 @@ public class Units{
|
|||||||
|
|
||||||
//now check all players
|
//now check all players
|
||||||
EntityQuery.getNearby(playerGroup, rect, player -> {
|
EntityQuery.getNearby(playerGroup, rect, player -> {
|
||||||
if(((Unit) player).team == team && player.dst(x, y) <= radius){
|
if(((Unit) player).getTeam() == team && player.dst(x, y) <= radius){
|
||||||
cons.accept((Unit) player);
|
cons.accept((Unit) player);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -261,7 +262,7 @@ public class Units{
|
|||||||
|
|
||||||
//now check all enemy players
|
//now check all enemy players
|
||||||
EntityQuery.getNearby(playerGroup, rect, player -> {
|
EntityQuery.getNearby(playerGroup, rect, player -> {
|
||||||
if(targets.contains(((Player) player).team)){
|
if(targets.contains(((Player) player).getTeam())){
|
||||||
cons.accept((Unit) player);
|
cons.accept((Unit) player);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package io.anuke.mindustry.entities.bullet;
|
package io.anuke.mindustry.entities.bullet;
|
||||||
|
|
||||||
import io.anuke.arc.entities.Effects;
|
import io.anuke.mindustry.entities.Effects;
|
||||||
import io.anuke.arc.entities.Effects.Effect;
|
import io.anuke.mindustry.entities.Effects.Effect;
|
||||||
import io.anuke.arc.graphics.g2d.Draw;
|
import io.anuke.arc.graphics.g2d.Draw;
|
||||||
import io.anuke.mindustry.content.Fx;
|
import io.anuke.mindustry.content.Fx;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package io.anuke.mindustry.entities.bullet;
|
package io.anuke.mindustry.entities.bullet;
|
||||||
|
|
||||||
import io.anuke.arc.Core;
|
import io.anuke.arc.Core;
|
||||||
import io.anuke.arc.entities.Effects;
|
import io.anuke.mindustry.entities.Effects;
|
||||||
import io.anuke.arc.graphics.Color;
|
import io.anuke.arc.graphics.Color;
|
||||||
import io.anuke.arc.graphics.g2d.Draw;
|
import io.anuke.arc.graphics.g2d.Draw;
|
||||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||||
|
|||||||
@@ -2,9 +2,8 @@ package io.anuke.mindustry.entities.bullet;
|
|||||||
|
|
||||||
import io.anuke.annotations.Annotations.Loc;
|
import io.anuke.annotations.Annotations.Loc;
|
||||||
import io.anuke.annotations.Annotations.Remote;
|
import io.anuke.annotations.Annotations.Remote;
|
||||||
import io.anuke.arc.entities.EntityGroup;
|
import io.anuke.mindustry.entities.EntityGroup;
|
||||||
import io.anuke.arc.entities.impl.SolidEntity;
|
import io.anuke.mindustry.entities.impl.SolidEntity;
|
||||||
import io.anuke.arc.entities.trait.*;
|
|
||||||
import io.anuke.arc.math.Mathf;
|
import io.anuke.arc.math.Mathf;
|
||||||
import io.anuke.arc.math.geom.Rectangle;
|
import io.anuke.arc.math.geom.Rectangle;
|
||||||
import io.anuke.arc.math.geom.Vector2;
|
import io.anuke.arc.math.geom.Vector2;
|
||||||
@@ -13,11 +12,9 @@ import io.anuke.arc.util.Time;
|
|||||||
import io.anuke.arc.util.Tmp;
|
import io.anuke.arc.util.Tmp;
|
||||||
import io.anuke.arc.util.pooling.Pool.Poolable;
|
import io.anuke.arc.util.pooling.Pool.Poolable;
|
||||||
import io.anuke.arc.util.pooling.Pools;
|
import io.anuke.arc.util.pooling.Pools;
|
||||||
import io.anuke.mindustry.entities.Unit;
|
import io.anuke.mindustry.entities.traits.*;
|
||||||
|
import io.anuke.mindustry.entities.type.Unit;
|
||||||
import io.anuke.mindustry.entities.effect.Lightning;
|
import io.anuke.mindustry.entities.effect.Lightning;
|
||||||
import io.anuke.mindustry.entities.traits.AbsorbTrait;
|
|
||||||
import io.anuke.mindustry.entities.traits.SyncTrait;
|
|
||||||
import io.anuke.mindustry.entities.traits.TeamTrait;
|
|
||||||
import io.anuke.mindustry.game.Team;
|
import io.anuke.mindustry.game.Team;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package io.anuke.mindustry.entities.bullet;
|
package io.anuke.mindustry.entities.bullet;
|
||||||
|
|
||||||
import io.anuke.arc.entities.Effects;
|
import io.anuke.mindustry.entities.Effects;
|
||||||
import io.anuke.arc.entities.Effects.Effect;
|
import io.anuke.mindustry.entities.Effects.Effect;
|
||||||
import io.anuke.mindustry.content.StatusEffects;
|
import io.anuke.mindustry.content.StatusEffects;
|
||||||
import io.anuke.mindustry.content.Fx;
|
import io.anuke.mindustry.content.Fx;
|
||||||
import io.anuke.mindustry.game.Content;
|
import io.anuke.mindustry.game.Content;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package io.anuke.mindustry.entities.bullet;
|
package io.anuke.mindustry.entities.bullet;
|
||||||
|
|
||||||
import io.anuke.arc.entities.Effects;
|
import io.anuke.mindustry.entities.Effects;
|
||||||
import io.anuke.arc.graphics.Color;
|
import io.anuke.arc.graphics.Color;
|
||||||
import io.anuke.arc.graphics.g2d.Draw;
|
import io.anuke.arc.graphics.g2d.Draw;
|
||||||
import io.anuke.arc.graphics.g2d.Fill;
|
import io.anuke.arc.graphics.g2d.Fill;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package io.anuke.mindustry.entities.bullet;
|
package io.anuke.mindustry.entities.bullet;
|
||||||
|
|
||||||
import io.anuke.arc.entities.Effects;
|
import io.anuke.mindustry.entities.Effects;
|
||||||
import io.anuke.arc.graphics.Color;
|
import io.anuke.arc.graphics.Color;
|
||||||
import io.anuke.arc.graphics.g2d.Draw;
|
import io.anuke.arc.graphics.g2d.Draw;
|
||||||
import io.anuke.arc.math.Angles;
|
import io.anuke.arc.math.Angles;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package io.anuke.mindustry.entities.bullet;
|
|||||||
import io.anuke.arc.graphics.Color;
|
import io.anuke.arc.graphics.Color;
|
||||||
import io.anuke.mindustry.content.Fx;
|
import io.anuke.mindustry.content.Fx;
|
||||||
import io.anuke.mindustry.graphics.Palette;
|
import io.anuke.mindustry.graphics.Palette;
|
||||||
import io.anuke.arc.entities.Effects;
|
import io.anuke.mindustry.entities.Effects;
|
||||||
import io.anuke.arc.util.Time;
|
import io.anuke.arc.util.Time;
|
||||||
import io.anuke.arc.math.Mathf;
|
import io.anuke.arc.math.Mathf;
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ package io.anuke.mindustry.entities.effect;
|
|||||||
|
|
||||||
import io.anuke.arc.graphics.Color;
|
import io.anuke.arc.graphics.Color;
|
||||||
import io.anuke.mindustry.entities.traits.BelowLiquidTrait;
|
import io.anuke.mindustry.entities.traits.BelowLiquidTrait;
|
||||||
import io.anuke.arc.entities.EntityGroup;
|
import io.anuke.mindustry.entities.EntityGroup;
|
||||||
import io.anuke.arc.entities.impl.TimedEntity;
|
import io.anuke.mindustry.entities.impl.TimedEntity;
|
||||||
import io.anuke.arc.entities.trait.DrawTrait;
|
import io.anuke.mindustry.entities.traits.DrawTrait;
|
||||||
import io.anuke.arc.graphics.g2d.Draw;
|
import io.anuke.arc.graphics.g2d.Draw;
|
||||||
import io.anuke.arc.math.Mathf;
|
import io.anuke.arc.math.Mathf;
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ package io.anuke.mindustry.entities.effect;
|
|||||||
import io.anuke.annotations.Annotations.Loc;
|
import io.anuke.annotations.Annotations.Loc;
|
||||||
import io.anuke.annotations.Annotations.Remote;
|
import io.anuke.annotations.Annotations.Remote;
|
||||||
import io.anuke.arc.collection.IntMap;
|
import io.anuke.arc.collection.IntMap;
|
||||||
import io.anuke.arc.entities.Effects;
|
import io.anuke.mindustry.entities.Effects;
|
||||||
import io.anuke.arc.entities.EntityGroup;
|
import io.anuke.mindustry.entities.EntityGroup;
|
||||||
import io.anuke.arc.entities.impl.TimedEntity;
|
import io.anuke.mindustry.entities.impl.TimedEntity;
|
||||||
import io.anuke.arc.math.Mathf;
|
import io.anuke.arc.math.Mathf;
|
||||||
import io.anuke.arc.math.geom.Geometry;
|
import io.anuke.arc.math.geom.Geometry;
|
||||||
import io.anuke.arc.math.geom.Point2;
|
import io.anuke.arc.math.geom.Point2;
|
||||||
@@ -17,7 +17,7 @@ import io.anuke.mindustry.content.Bullets;
|
|||||||
import io.anuke.mindustry.content.StatusEffects;
|
import io.anuke.mindustry.content.StatusEffects;
|
||||||
import io.anuke.mindustry.content.Fx;
|
import io.anuke.mindustry.content.Fx;
|
||||||
import io.anuke.mindustry.entities.Damage;
|
import io.anuke.mindustry.entities.Damage;
|
||||||
import io.anuke.mindustry.entities.TileEntity;
|
import io.anuke.mindustry.entities.type.TileEntity;
|
||||||
import io.anuke.mindustry.entities.traits.SaveTrait;
|
import io.anuke.mindustry.entities.traits.SaveTrait;
|
||||||
import io.anuke.mindustry.entities.traits.SyncTrait;
|
import io.anuke.mindustry.entities.traits.SyncTrait;
|
||||||
import io.anuke.mindustry.gen.Call;
|
import io.anuke.mindustry.gen.Call;
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package io.anuke.mindustry.entities.effect;
|
package io.anuke.mindustry.entities.effect;
|
||||||
|
|
||||||
import io.anuke.arc.entities.Effects;
|
import io.anuke.mindustry.entities.Effects;
|
||||||
import io.anuke.arc.entities.Effects.Effect;
|
import io.anuke.mindustry.entities.Effects.Effect;
|
||||||
import io.anuke.arc.entities.Effects.EffectRenderer;
|
import io.anuke.mindustry.entities.Effects.EffectRenderer;
|
||||||
import io.anuke.arc.entities.impl.EffectEntity;
|
import io.anuke.mindustry.entities.impl.EffectEntity;
|
||||||
import io.anuke.arc.math.Mathf;
|
import io.anuke.arc.math.Mathf;
|
||||||
import io.anuke.arc.util.Time;
|
import io.anuke.arc.util.Time;
|
||||||
import io.anuke.mindustry.Vars;
|
import io.anuke.mindustry.Vars;
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ package io.anuke.mindustry.entities.effect;
|
|||||||
|
|
||||||
import io.anuke.annotations.Annotations.Loc;
|
import io.anuke.annotations.Annotations.Loc;
|
||||||
import io.anuke.annotations.Annotations.Remote;
|
import io.anuke.annotations.Annotations.Remote;
|
||||||
import io.anuke.arc.entities.EntityGroup;
|
import io.anuke.mindustry.entities.EntityGroup;
|
||||||
import io.anuke.arc.entities.impl.TimedEntity;
|
import io.anuke.mindustry.entities.impl.TimedEntity;
|
||||||
import io.anuke.arc.entities.trait.DrawTrait;
|
import io.anuke.mindustry.entities.traits.DrawTrait;
|
||||||
import io.anuke.arc.graphics.g2d.Draw;
|
import io.anuke.arc.graphics.g2d.Draw;
|
||||||
import io.anuke.arc.graphics.g2d.Fill;
|
import io.anuke.arc.graphics.g2d.Fill;
|
||||||
import io.anuke.arc.graphics.g2d.Lines;
|
import io.anuke.arc.graphics.g2d.Lines;
|
||||||
@@ -14,7 +14,7 @@ import io.anuke.arc.math.geom.Position;
|
|||||||
import io.anuke.arc.math.geom.Vector2;
|
import io.anuke.arc.math.geom.Vector2;
|
||||||
import io.anuke.arc.util.Time;
|
import io.anuke.arc.util.Time;
|
||||||
import io.anuke.arc.util.pooling.Pools;
|
import io.anuke.arc.util.pooling.Pools;
|
||||||
import io.anuke.mindustry.entities.Unit;
|
import io.anuke.mindustry.entities.type.Unit;
|
||||||
import io.anuke.mindustry.graphics.Palette;
|
import io.anuke.mindustry.graphics.Palette;
|
||||||
import io.anuke.mindustry.type.Item;
|
import io.anuke.mindustry.type.Item;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
@@ -43,7 +43,7 @@ public class ItemTransfer extends TimedEntity implements DrawTrait{
|
|||||||
@Remote(called = Loc.server, unreliable = true)
|
@Remote(called = Loc.server, unreliable = true)
|
||||||
public static void transferItemToUnit(Item item, float x, float y, Unit to){
|
public static void transferItemToUnit(Item item, float x, float y, Unit to){
|
||||||
if(to == null) return;
|
if(to == null) return;
|
||||||
create(item, x, y, to, () -> to.inventory.addItem(item, 1));
|
create(item, x, y, to, () -> to.addItem(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Remote(called = Loc.server)
|
@Remote(called = Loc.server)
|
||||||
|
|||||||
@@ -4,13 +4,12 @@ import io.anuke.annotations.Annotations.Loc;
|
|||||||
import io.anuke.annotations.Annotations.Remote;
|
import io.anuke.annotations.Annotations.Remote;
|
||||||
import io.anuke.arc.collection.Array;
|
import io.anuke.arc.collection.Array;
|
||||||
import io.anuke.arc.collection.IntSet;
|
import io.anuke.arc.collection.IntSet;
|
||||||
import io.anuke.arc.entities.EntityGroup;
|
import io.anuke.mindustry.entities.EntityGroup;
|
||||||
import io.anuke.arc.entities.impl.TimedEntity;
|
import io.anuke.mindustry.entities.impl.TimedEntity;
|
||||||
import io.anuke.arc.entities.trait.DrawTrait;
|
import io.anuke.mindustry.entities.traits.DrawTrait;
|
||||||
import io.anuke.arc.entities.trait.TimeTrait;
|
import io.anuke.mindustry.entities.traits.TimeTrait;
|
||||||
import io.anuke.arc.graphics.Color;
|
import io.anuke.arc.graphics.Color;
|
||||||
import io.anuke.arc.graphics.g2d.Draw;
|
import io.anuke.arc.graphics.g2d.Draw;
|
||||||
import io.anuke.arc.graphics.g2d.Lines;
|
|
||||||
import io.anuke.arc.math.Angles;
|
import io.anuke.arc.math.Angles;
|
||||||
import io.anuke.arc.math.Mathf;
|
import io.anuke.arc.math.Mathf;
|
||||||
import io.anuke.arc.math.RandomXS128;
|
import io.anuke.arc.math.RandomXS128;
|
||||||
@@ -20,7 +19,7 @@ import io.anuke.arc.math.geom.Rectangle;
|
|||||||
import io.anuke.arc.math.geom.Vector2;
|
import io.anuke.arc.math.geom.Vector2;
|
||||||
import io.anuke.arc.util.pooling.Pools;
|
import io.anuke.arc.util.pooling.Pools;
|
||||||
import io.anuke.mindustry.content.Bullets;
|
import io.anuke.mindustry.content.Bullets;
|
||||||
import io.anuke.mindustry.entities.Unit;
|
import io.anuke.mindustry.entities.type.Unit;
|
||||||
import io.anuke.mindustry.entities.Units;
|
import io.anuke.mindustry.entities.Units;
|
||||||
import io.anuke.mindustry.entities.bullet.Bullet;
|
import io.anuke.mindustry.entities.bullet.Bullet;
|
||||||
import io.anuke.mindustry.entities.traits.SyncTrait;
|
import io.anuke.mindustry.entities.traits.SyncTrait;
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ package io.anuke.mindustry.entities.effect;
|
|||||||
import io.anuke.annotations.Annotations.Loc;
|
import io.anuke.annotations.Annotations.Loc;
|
||||||
import io.anuke.annotations.Annotations.Remote;
|
import io.anuke.annotations.Annotations.Remote;
|
||||||
import io.anuke.arc.collection.IntMap;
|
import io.anuke.arc.collection.IntMap;
|
||||||
import io.anuke.arc.entities.Effects;
|
import io.anuke.mindustry.entities.Effects;
|
||||||
import io.anuke.arc.entities.EntityGroup;
|
import io.anuke.mindustry.entities.EntityGroup;
|
||||||
import io.anuke.arc.entities.impl.SolidEntity;
|
import io.anuke.mindustry.entities.impl.SolidEntity;
|
||||||
import io.anuke.arc.entities.trait.DrawTrait;
|
import io.anuke.mindustry.entities.traits.DrawTrait;
|
||||||
import io.anuke.arc.graphics.Color;
|
import io.anuke.arc.graphics.Color;
|
||||||
import io.anuke.arc.graphics.g2d.Draw;
|
import io.anuke.arc.graphics.g2d.Draw;
|
||||||
import io.anuke.arc.graphics.g2d.Fill;
|
import io.anuke.arc.graphics.g2d.Fill;
|
||||||
|
|||||||
61
core/src/io/anuke/mindustry/entities/impl/BaseEntity.java
Executable file
61
core/src/io/anuke/mindustry/entities/impl/BaseEntity.java
Executable file
@@ -0,0 +1,61 @@
|
|||||||
|
package io.anuke.mindustry.entities.impl;
|
||||||
|
|
||||||
|
import io.anuke.mindustry.entities.EntityGroup;
|
||||||
|
import io.anuke.mindustry.entities.traits.Entity;
|
||||||
|
|
||||||
|
public abstract class BaseEntity implements Entity{
|
||||||
|
private static int lastid;
|
||||||
|
/** Do not modify. Used for network operations and mapping. */
|
||||||
|
public int id;
|
||||||
|
public float x, y;
|
||||||
|
protected transient EntityGroup group;
|
||||||
|
|
||||||
|
public BaseEntity(){
|
||||||
|
id = lastid++;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getID(){
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resetID(int id){
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EntityGroup getGroup(){
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setGroup(EntityGroup group){
|
||||||
|
this.group = group;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getX(){
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setX(float x){
|
||||||
|
this.x = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getY(){
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setY(float y){
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(){
|
||||||
|
return getClass() + " " + id;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
public abstract class DestructibleEntity extends SolidEntity implements HealthTrait{
|
||||||
|
public transient boolean dead;
|
||||||
|
public float health;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean collides(SolidTrait other){
|
||||||
|
return other instanceof DamageTrait;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collision(SolidTrait other, float x, float y){
|
||||||
|
if(other instanceof DamageTrait){
|
||||||
|
onHit(other);
|
||||||
|
damage(((DamageTrait) other).damage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void health(float health){
|
||||||
|
this.health = health;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float health(){
|
||||||
|
return health;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDead(){
|
||||||
|
return dead;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setDead(boolean dead){
|
||||||
|
this.dead = dead;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
72
core/src/io/anuke/mindustry/entities/impl/EffectEntity.java
Normal file
72
core/src/io/anuke/mindustry/entities/impl/EffectEntity.java
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
package io.anuke.mindustry.entities.impl;
|
||||||
|
|
||||||
|
import io.anuke.arc.graphics.Color;
|
||||||
|
import io.anuke.arc.util.pooling.Pool.Poolable;
|
||||||
|
import io.anuke.arc.util.pooling.Pools;
|
||||||
|
import io.anuke.mindustry.entities.Effects;
|
||||||
|
import io.anuke.mindustry.entities.Effects.Effect;
|
||||||
|
import io.anuke.mindustry.entities.traits.DrawTrait;
|
||||||
|
import io.anuke.mindustry.entities.traits.Entity;
|
||||||
|
|
||||||
|
public class EffectEntity extends TimedEntity implements Poolable, DrawTrait{
|
||||||
|
public Effect effect;
|
||||||
|
public Color color = new Color(Color.WHITE);
|
||||||
|
public Object data;
|
||||||
|
public float rotation = 0f;
|
||||||
|
|
||||||
|
public Entity parent;
|
||||||
|
public float poffsetx, poffsety;
|
||||||
|
|
||||||
|
/** For pooling use only! */
|
||||||
|
public EffectEntity(){
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParent(Entity parent){
|
||||||
|
this.parent = parent;
|
||||||
|
this.poffsetx = x - parent.getX();
|
||||||
|
this.poffsety = y - parent.getY();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float lifetime(){
|
||||||
|
return effect.lifetime;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float drawSize(){
|
||||||
|
return effect.size;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(){
|
||||||
|
if(effect == null){
|
||||||
|
remove();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
super.update();
|
||||||
|
if(parent != null){
|
||||||
|
x = parent.getX() + poffsetx;
|
||||||
|
y = parent.getY() + poffsety;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reset(){
|
||||||
|
effect = null;
|
||||||
|
color.set(Color.WHITE);
|
||||||
|
rotation = time = poffsetx = poffsety = 0f;
|
||||||
|
parent = null;
|
||||||
|
data = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(){
|
||||||
|
Effects.renderEffect(id, effect, color, time, rotation, x, y, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removed(){
|
||||||
|
Pools.free(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
19
core/src/io/anuke/mindustry/entities/impl/SolidEntity.java
Normal file
19
core/src/io/anuke/mindustry/entities/impl/SolidEntity.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package io.anuke.mindustry.entities.impl;
|
||||||
|
|
||||||
|
import io.anuke.arc.math.geom.Vector2;
|
||||||
|
import io.anuke.mindustry.entities.traits.SolidTrait;
|
||||||
|
|
||||||
|
public abstract class SolidEntity extends BaseEntity implements SolidTrait{
|
||||||
|
protected transient Vector2 velocity = new Vector2(0f, 0.0001f);
|
||||||
|
private transient Vector2 lastPosition = new Vector2();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Vector2 lastPosition(){
|
||||||
|
return lastPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Vector2 velocity(){
|
||||||
|
return velocity;
|
||||||
|
}
|
||||||
|
}
|
||||||
34
core/src/io/anuke/mindustry/entities/impl/TimedEntity.java
Normal file
34
core/src/io/anuke/mindustry/entities/impl/TimedEntity.java
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package io.anuke.mindustry.entities.impl;
|
||||||
|
|
||||||
|
import io.anuke.arc.util.pooling.Pool.Poolable;
|
||||||
|
import io.anuke.mindustry.entities.traits.ScaleTrait;
|
||||||
|
import io.anuke.mindustry.entities.traits.TimeTrait;
|
||||||
|
|
||||||
|
public abstract class TimedEntity extends BaseEntity implements ScaleTrait, TimeTrait, Poolable{
|
||||||
|
public float time;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void time(float time){
|
||||||
|
this.time = time;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float time(){
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(){
|
||||||
|
updateTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reset(){
|
||||||
|
time = 0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float fin(){
|
||||||
|
return time() / lifetime();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,5 @@
|
|||||||
package io.anuke.mindustry.entities.traits;
|
package io.anuke.mindustry.entities.traits;
|
||||||
|
|
||||||
import io.anuke.arc.entities.trait.DamageTrait;
|
|
||||||
import io.anuke.arc.entities.trait.Entity;
|
|
||||||
|
|
||||||
public interface AbsorbTrait extends Entity, TeamTrait, DamageTrait{
|
public interface AbsorbTrait extends Entity, TeamTrait, DamageTrait{
|
||||||
void absorb();
|
void absorb();
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,7 @@ import io.anuke.arc.Core;
|
|||||||
import io.anuke.arc.Events;
|
import io.anuke.arc.Events;
|
||||||
import io.anuke.arc.collection.Array;
|
import io.anuke.arc.collection.Array;
|
||||||
import io.anuke.arc.collection.Queue;
|
import io.anuke.arc.collection.Queue;
|
||||||
import io.anuke.arc.entities.Effects;
|
import io.anuke.mindustry.entities.Effects;
|
||||||
import io.anuke.arc.entities.trait.Entity;
|
|
||||||
import io.anuke.arc.graphics.Color;
|
import io.anuke.arc.graphics.Color;
|
||||||
import io.anuke.arc.graphics.g2d.Draw;
|
import io.anuke.arc.graphics.g2d.Draw;
|
||||||
import io.anuke.arc.graphics.g2d.Fill;
|
import io.anuke.arc.graphics.g2d.Fill;
|
||||||
@@ -17,9 +16,9 @@ import io.anuke.arc.util.Time;
|
|||||||
import io.anuke.mindustry.Vars;
|
import io.anuke.mindustry.Vars;
|
||||||
import io.anuke.mindustry.content.Blocks;
|
import io.anuke.mindustry.content.Blocks;
|
||||||
import io.anuke.mindustry.content.Fx;
|
import io.anuke.mindustry.content.Fx;
|
||||||
import io.anuke.mindustry.entities.Player;
|
import io.anuke.mindustry.entities.type.Player;
|
||||||
import io.anuke.mindustry.entities.TileEntity;
|
import io.anuke.mindustry.entities.type.TileEntity;
|
||||||
import io.anuke.mindustry.entities.Unit;
|
import io.anuke.mindustry.entities.type.Unit;
|
||||||
import io.anuke.mindustry.game.EventType.BuildSelectEvent;
|
import io.anuke.mindustry.game.EventType.BuildSelectEvent;
|
||||||
import io.anuke.mindustry.gen.Call;
|
import io.anuke.mindustry.gen.Call;
|
||||||
import io.anuke.mindustry.graphics.Palette;
|
import io.anuke.mindustry.graphics.Palette;
|
||||||
@@ -43,7 +42,7 @@ import static io.anuke.mindustry.Vars.*;
|
|||||||
/**
|
/**
|
||||||
* Interface for units that build, break or mine things.
|
* Interface for units that build, break or mine things.
|
||||||
*/
|
*/
|
||||||
public interface BuilderTrait extends Entity{
|
public interface BuilderTrait extends Entity, TeamTrait{
|
||||||
//these are not instance variables!
|
//these are not instance variables!
|
||||||
Vector2[] tmptr = new Vector2[]{new Vector2(), new Vector2(), new Vector2(), new Vector2()};
|
Vector2[] tmptr = new Vector2[]{new Vector2(), new Vector2(), new Vector2(), new Vector2()};
|
||||||
float placeDistance = 150f;
|
float placeDistance = 150f;
|
||||||
@@ -172,7 +171,8 @@ public interface BuilderTrait extends Entity{
|
|||||||
* Update building mechanism for this unit.
|
* Update building mechanism for this unit.
|
||||||
* This includes mining.
|
* This includes mining.
|
||||||
*/
|
*/
|
||||||
default void updateBuilding(Unit unit){
|
default void updateBuilding(){
|
||||||
|
Unit unit = (Unit)this;
|
||||||
//remove already completed build requests
|
//remove already completed build requests
|
||||||
removal.clear();
|
removal.clear();
|
||||||
for(BuildRequest req : getPlaceQueue()){
|
for(BuildRequest req : getPlaceQueue()){
|
||||||
@@ -195,7 +195,7 @@ public interface BuilderTrait extends Entity{
|
|||||||
//update mining here
|
//update mining here
|
||||||
if(current == null){
|
if(current == null){
|
||||||
if(getMineTile() != null){
|
if(getMineTile() != null){
|
||||||
updateMining(unit);
|
updateMining();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}else{
|
}else{
|
||||||
@@ -204,15 +204,15 @@ public interface BuilderTrait extends Entity{
|
|||||||
|
|
||||||
Tile tile = world.tile(current.x, current.y);
|
Tile tile = world.tile(current.x, current.y);
|
||||||
|
|
||||||
if(unit.dst(tile) > placeDistance){
|
if(dst(tile) > placeDistance){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!(tile.block() instanceof BuildBlock)){
|
if(!(tile.block() instanceof BuildBlock)){
|
||||||
if(canCreateBlocks() && !current.breaking && Build.validPlace(unit.getTeam(), current.x, current.y, current.block, current.rotation)){
|
if(canCreateBlocks() && !current.breaking && Build.validPlace(getTeam(), current.x, current.y, current.block, current.rotation)){
|
||||||
Build.beginPlace(unit.getTeam(), current.x, current.y, current.block, current.rotation);
|
Build.beginPlace(getTeam(), current.x, current.y, current.block, current.rotation);
|
||||||
}else if(canCreateBlocks() && current.breaking && Build.validBreak(unit.getTeam(), current.x, current.y)){
|
}else if(canCreateBlocks() && current.breaking && Build.validBreak(getTeam(), current.x, current.y)){
|
||||||
Build.beginBreak(unit.getTeam(), current.x, current.y);
|
Build.beginBreak(getTeam(), current.x, current.y);
|
||||||
}else{
|
}else{
|
||||||
getPlaceQueue().removeFirst();
|
getPlaceQueue().removeFirst();
|
||||||
return;
|
return;
|
||||||
@@ -259,12 +259,13 @@ public interface BuilderTrait extends Entity{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**Do not call directly.*/
|
/**Do not call directly.*/
|
||||||
default void updateMining(Unit unit){
|
default void updateMining(){
|
||||||
|
Unit unit = (Unit)this;
|
||||||
Tile tile = getMineTile();
|
Tile tile = getMineTile();
|
||||||
TileEntity core = unit.getClosestCore();
|
TileEntity core = unit.getClosestCore();
|
||||||
|
|
||||||
if(core == null || tile.block() != Blocks.air || unit.dst(tile.worldx(), tile.worldy()) > mineDistance
|
if(core == null || tile.block() != Blocks.air || dst(tile.worldx(), tile.worldy()) > mineDistance
|
||||||
|| tile.floor().itemDrop == null || !unit.inventory.canAcceptItem(tile.floor().itemDrop) || !canMine(tile.floor().itemDrop)){
|
|| tile.floor().itemDrop == null || !unit.acceptsItem(tile.floor().itemDrop) || !canMine(tile.floor().itemDrop)){
|
||||||
setMineTile(null);
|
setMineTile(null);
|
||||||
}else{
|
}else{
|
||||||
Item item = tile.floor().itemDrop;
|
Item item = tile.floor().itemDrop;
|
||||||
@@ -276,7 +277,7 @@ public interface BuilderTrait extends Entity{
|
|||||||
Call.transferItemTo(item, 1,
|
Call.transferItemTo(item, 1,
|
||||||
tile.worldx() + Mathf.range(tilesize / 2f),
|
tile.worldx() + Mathf.range(tilesize / 2f),
|
||||||
tile.worldy() + Mathf.range(tilesize / 2f), core.tile);
|
tile.worldy() + Mathf.range(tilesize / 2f), core.tile);
|
||||||
}else if(unit.inventory.canAcceptItem(item)){
|
}else if(unit.acceptsItem(item)){
|
||||||
Call.transferItemToUnit(item,
|
Call.transferItemToUnit(item,
|
||||||
tile.worldx() + Mathf.range(tilesize / 2f),
|
tile.worldx() + Mathf.range(tilesize / 2f),
|
||||||
tile.worldy() + Mathf.range(tilesize / 2f),
|
tile.worldy() + Mathf.range(tilesize / 2f),
|
||||||
@@ -293,11 +294,12 @@ public interface BuilderTrait extends Entity{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**Draw placement effects for an entity. This includes mining*/
|
/**Draw placement effects for an entity. This includes mining*/
|
||||||
default void drawBuilding(Unit unit){
|
default void drawBuilding(){
|
||||||
|
Unit unit = (Unit)this;
|
||||||
BuildRequest request;
|
BuildRequest request;
|
||||||
if(!isBuilding()){
|
if(!isBuilding()){
|
||||||
if(getMineTile() != null){
|
if(getMineTile() != null){
|
||||||
drawMining(unit);
|
drawMining();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -306,7 +308,7 @@ public interface BuilderTrait extends Entity{
|
|||||||
|
|
||||||
Tile tile = world.tile(request.x, request.y);
|
Tile tile = world.tile(request.x, request.y);
|
||||||
|
|
||||||
if(unit.dst(tile) > placeDistance){
|
if(dst(tile) > placeDistance){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -340,7 +342,8 @@ public interface BuilderTrait extends Entity{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**Internal use only.*/
|
/**Internal use only.*/
|
||||||
default void drawMining(Unit unit){
|
default void drawMining(){
|
||||||
|
Unit unit = (Unit)this;
|
||||||
Tile tile = getMineTile();
|
Tile tile = getMineTile();
|
||||||
|
|
||||||
if(tile == null) return;
|
if(tile == null) return;
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package io.anuke.mindustry.entities.traits;
|
||||||
|
|
||||||
|
public interface DamageTrait{
|
||||||
|
float damage();
|
||||||
|
}
|
||||||
10
core/src/io/anuke/mindustry/entities/traits/DrawTrait.java
Normal file
10
core/src/io/anuke/mindustry/entities/traits/DrawTrait.java
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package io.anuke.mindustry.entities.traits;
|
||||||
|
|
||||||
|
public interface DrawTrait extends Entity{
|
||||||
|
|
||||||
|
default float drawSize(){
|
||||||
|
return 20f;
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw();
|
||||||
|
}
|
||||||
46
core/src/io/anuke/mindustry/entities/traits/Entity.java
Normal file
46
core/src/io/anuke/mindustry/entities/traits/Entity.java
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
package io.anuke.mindustry.entities.traits;
|
||||||
|
|
||||||
|
import io.anuke.mindustry.entities.Entities;
|
||||||
|
import io.anuke.mindustry.entities.EntityGroup;
|
||||||
|
|
||||||
|
public interface Entity extends MoveTrait{
|
||||||
|
|
||||||
|
int getID();
|
||||||
|
|
||||||
|
void resetID(int id);
|
||||||
|
|
||||||
|
default void update(){
|
||||||
|
}
|
||||||
|
|
||||||
|
default void removed(){
|
||||||
|
}
|
||||||
|
|
||||||
|
default void added(){
|
||||||
|
}
|
||||||
|
|
||||||
|
default EntityGroup targetGroup(){
|
||||||
|
return Entities.defaultGroup();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
default void add(){
|
||||||
|
targetGroup().add(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
default void remove(){
|
||||||
|
if(getGroup() != null){
|
||||||
|
getGroup().remove(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
setGroup(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
EntityGroup getGroup();
|
||||||
|
|
||||||
|
void setGroup(EntityGroup group);
|
||||||
|
|
||||||
|
default boolean isAdded(){
|
||||||
|
return getGroup() != null;
|
||||||
|
}
|
||||||
|
}
|
||||||
48
core/src/io/anuke/mindustry/entities/traits/HealthTrait.java
Normal file
48
core/src/io/anuke/mindustry/entities/traits/HealthTrait.java
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package io.anuke.mindustry.entities.traits;
|
||||||
|
|
||||||
|
import io.anuke.arc.math.Mathf;
|
||||||
|
|
||||||
|
public interface HealthTrait{
|
||||||
|
|
||||||
|
void health(float health);
|
||||||
|
|
||||||
|
float health();
|
||||||
|
|
||||||
|
float maxHealth();
|
||||||
|
|
||||||
|
boolean isDead();
|
||||||
|
|
||||||
|
void setDead(boolean dead);
|
||||||
|
|
||||||
|
default void onHit(SolidTrait entity){
|
||||||
|
}
|
||||||
|
|
||||||
|
default void onDeath(){
|
||||||
|
}
|
||||||
|
|
||||||
|
default void damage(float amount){
|
||||||
|
health(health() - amount);
|
||||||
|
if(health() <= 0 && !isDead()){
|
||||||
|
onDeath();
|
||||||
|
setDead(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
default void clampHealth(){
|
||||||
|
health(Mathf.clamp(health(), 0, maxHealth()));
|
||||||
|
}
|
||||||
|
|
||||||
|
default float healthf(){
|
||||||
|
return health() / maxHealth();
|
||||||
|
}
|
||||||
|
|
||||||
|
default void healBy(float amount){
|
||||||
|
health(health() + amount);
|
||||||
|
clampHealth();
|
||||||
|
}
|
||||||
|
|
||||||
|
default void heal(){
|
||||||
|
health(maxHealth());
|
||||||
|
setDead(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package io.anuke.mindustry.entities.traits;
|
|
||||||
|
|
||||||
import io.anuke.mindustry.entities.UnitInventory;
|
|
||||||
|
|
||||||
public interface InventoryTrait{
|
|
||||||
UnitInventory getInventory();
|
|
||||||
}
|
|
||||||
20
core/src/io/anuke/mindustry/entities/traits/MoveTrait.java
Normal file
20
core/src/io/anuke/mindustry/entities/traits/MoveTrait.java
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package io.anuke.mindustry.entities.traits;
|
||||||
|
|
||||||
|
import io.anuke.arc.math.geom.Position;
|
||||||
|
|
||||||
|
public interface MoveTrait extends Position{
|
||||||
|
|
||||||
|
void setX(float x);
|
||||||
|
|
||||||
|
void setY(float y);
|
||||||
|
|
||||||
|
default void moveBy(float x, float y){
|
||||||
|
setX(getX() + x);
|
||||||
|
setY(getY() + y);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void set(float x, float y){
|
||||||
|
setX(x);
|
||||||
|
setY(y);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
package io.anuke.mindustry.entities.traits;
|
package io.anuke.mindustry.entities.traits;
|
||||||
|
|
||||||
import io.anuke.arc.entities.trait.Entity;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marks an entity as serializable.
|
* Marks an entity as serializable.
|
||||||
*/
|
*/
|
||||||
|
|||||||
43
core/src/io/anuke/mindustry/entities/traits/ScaleTrait.java
Normal file
43
core/src/io/anuke/mindustry/entities/traits/ScaleTrait.java
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
package io.anuke.mindustry.entities.traits;
|
||||||
|
|
||||||
|
import io.anuke.arc.math.Interpolation;
|
||||||
|
|
||||||
|
public interface ScaleTrait{
|
||||||
|
/** 0 to 1. */
|
||||||
|
float fin();
|
||||||
|
|
||||||
|
/** 1 to 0 */
|
||||||
|
default float fout(){
|
||||||
|
return 1f - fin();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 1 to 0 */
|
||||||
|
default float fout(Interpolation i){
|
||||||
|
return i.apply(fout());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 1 to 0, ending at the specified margin */
|
||||||
|
default float fout(float margin){
|
||||||
|
float f = fin();
|
||||||
|
if(f >= 1f - margin){
|
||||||
|
return 1f - (f - (1f - margin)) / margin;
|
||||||
|
}else{
|
||||||
|
return 1f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 0 to 1 **/
|
||||||
|
default float fin(Interpolation i){
|
||||||
|
return i.apply(fin());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 0 to 1 */
|
||||||
|
default float finpow(){
|
||||||
|
return Interpolation.pow3Out.apply(fin());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 0 to 1 to 0 */
|
||||||
|
default float fslope(){
|
||||||
|
return (0.5f - Math.abs(fin() - 0.5f)) * 2f;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
package io.anuke.mindustry.entities.traits;
|
package io.anuke.mindustry.entities.traits;
|
||||||
|
|
||||||
import io.anuke.arc.entities.trait.VelocityTrait;
|
|
||||||
import io.anuke.arc.util.Interval;
|
import io.anuke.arc.util.Interval;
|
||||||
import io.anuke.mindustry.type.Weapon;
|
import io.anuke.mindustry.type.Weapon;
|
||||||
|
|
||||||
public interface ShooterTrait extends VelocityTrait, TeamTrait, InventoryTrait{
|
public interface ShooterTrait extends VelocityTrait, TeamTrait{
|
||||||
|
|
||||||
Interval getTimer();
|
Interval getTimer();
|
||||||
|
|
||||||
|
|||||||
43
core/src/io/anuke/mindustry/entities/traits/SolidTrait.java
Normal file
43
core/src/io/anuke/mindustry/entities/traits/SolidTrait.java
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
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.QuadTree.QuadTreeObject;
|
||||||
|
import io.anuke.arc.math.geom.Rectangle;
|
||||||
|
import io.anuke.arc.math.geom.Vector2;
|
||||||
|
|
||||||
|
public interface SolidTrait extends QuadTreeObject, MoveTrait, VelocityTrait, Entity, Position{
|
||||||
|
|
||||||
|
void hitbox(Rectangle rectangle);
|
||||||
|
|
||||||
|
void hitboxTile(Rectangle rectangle);
|
||||||
|
|
||||||
|
Vector2 lastPosition();
|
||||||
|
|
||||||
|
default boolean collidesGrid(int x, int y){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
default float getDeltaX(){
|
||||||
|
return getX() - lastPosition().x;
|
||||||
|
}
|
||||||
|
|
||||||
|
default float getDeltaY(){
|
||||||
|
return getY() - lastPosition().y;
|
||||||
|
}
|
||||||
|
|
||||||
|
default boolean movable(){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
default boolean collides(SolidTrait other){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
default void collision(SolidTrait other, float x, float y){}
|
||||||
|
|
||||||
|
default void move(float x, float y){
|
||||||
|
EntityQuery.collisions().move(this, x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,15 @@
|
|||||||
package io.anuke.mindustry.entities.traits;
|
package io.anuke.mindustry.entities.traits;
|
||||||
|
|
||||||
import io.anuke.mindustry.entities.Unit;
|
import io.anuke.mindustry.entities.type.Player;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
|
|
||||||
public interface SpawnerTrait{
|
public interface SpawnerTrait extends TargetTrait{
|
||||||
Tile getTile();
|
Tile getTile();
|
||||||
|
|
||||||
void updateSpawning(Unit unit);
|
void updateSpawning(Player unit);
|
||||||
|
|
||||||
float getSpawnProgress();
|
@Override
|
||||||
|
default boolean isValid(){
|
||||||
|
return getTile().entity instanceof SpawnerTrait;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package io.anuke.mindustry.entities.traits;
|
|||||||
import io.anuke.mindustry.core.NetClient;
|
import io.anuke.mindustry.core.NetClient;
|
||||||
import io.anuke.mindustry.net.Interpolator;
|
import io.anuke.mindustry.net.Interpolator;
|
||||||
import io.anuke.arc.Core;
|
import io.anuke.arc.Core;
|
||||||
import io.anuke.arc.entities.trait.Entity;
|
|
||||||
import io.anuke.arc.util.Tmp;
|
import io.anuke.arc.util.Tmp;
|
||||||
|
|
||||||
import java.io.DataInput;
|
import java.io.DataInput;
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package io.anuke.mindustry.entities.traits;
|
package io.anuke.mindustry.entities.traits;
|
||||||
|
|
||||||
import io.anuke.arc.entities.trait.SolidTrait;
|
|
||||||
import io.anuke.arc.entities.trait.VelocityTrait;
|
|
||||||
import io.anuke.arc.math.geom.Position;
|
import io.anuke.arc.math.geom.Position;
|
||||||
import io.anuke.mindustry.game.Team;
|
import io.anuke.mindustry.game.Team;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package io.anuke.mindustry.entities.traits;
|
package io.anuke.mindustry.entities.traits;
|
||||||
|
|
||||||
import io.anuke.mindustry.game.Team;
|
import io.anuke.mindustry.game.Team;
|
||||||
import io.anuke.arc.entities.trait.Entity;
|
|
||||||
|
|
||||||
public interface TeamTrait extends Entity{
|
public interface TeamTrait extends Entity{
|
||||||
Team getTeam();
|
Team getTeam();
|
||||||
|
|||||||
23
core/src/io/anuke/mindustry/entities/traits/TimeTrait.java
Normal file
23
core/src/io/anuke/mindustry/entities/traits/TimeTrait.java
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package io.anuke.mindustry.entities.traits;
|
||||||
|
|
||||||
|
import io.anuke.arc.math.Mathf;
|
||||||
|
import io.anuke.arc.util.Time;
|
||||||
|
|
||||||
|
public interface TimeTrait extends ScaleTrait, Entity{
|
||||||
|
|
||||||
|
float lifetime();
|
||||||
|
|
||||||
|
void time(float time);
|
||||||
|
|
||||||
|
float time();
|
||||||
|
|
||||||
|
default void updateTime(){
|
||||||
|
time(Mathf.clamp(time() + Time.delta(), 0, lifetime()));
|
||||||
|
|
||||||
|
if(time() >= lifetime()){
|
||||||
|
remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//fin() is not implemented due to compiler issues with iOS/RoboVM
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package io.anuke.mindustry.entities.traits;
|
||||||
|
|
||||||
|
import io.anuke.arc.math.geom.Vector2;
|
||||||
|
import io.anuke.arc.util.Time;
|
||||||
|
|
||||||
|
public interface VelocityTrait extends MoveTrait{
|
||||||
|
|
||||||
|
Vector2 velocity();
|
||||||
|
|
||||||
|
default void applyImpulse(float x, float y){
|
||||||
|
velocity().x += x / mass();
|
||||||
|
velocity().y += y / mass();
|
||||||
|
}
|
||||||
|
|
||||||
|
default float maxVelocity(){
|
||||||
|
return Float.MAX_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
default float mass(){
|
||||||
|
return 1f;
|
||||||
|
}
|
||||||
|
|
||||||
|
default float drag(){
|
||||||
|
return 0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
default void updateVelocity(){
|
||||||
|
velocity().scl(1f - drag() * Time.delta());
|
||||||
|
|
||||||
|
if(this instanceof SolidTrait){
|
||||||
|
((SolidTrait) this).move(velocity().x * Time.delta(), velocity().y * Time.delta());
|
||||||
|
}else{
|
||||||
|
moveBy(velocity().x * Time.delta(), velocity().y * Time.delta());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,8 @@
|
|||||||
package io.anuke.mindustry.entities.units;
|
package io.anuke.mindustry.entities.type;
|
||||||
|
|
||||||
import io.anuke.annotations.Annotations.Loc;
|
import io.anuke.annotations.Annotations.Loc;
|
||||||
import io.anuke.annotations.Annotations.Remote;
|
import io.anuke.annotations.Annotations.Remote;
|
||||||
import io.anuke.arc.Core;
|
import io.anuke.arc.Core;
|
||||||
import io.anuke.arc.entities.Effects;
|
|
||||||
import io.anuke.arc.entities.EntityGroup;
|
|
||||||
import io.anuke.arc.graphics.g2d.Draw;
|
import io.anuke.arc.graphics.g2d.Draw;
|
||||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||||
import io.anuke.arc.math.Angles;
|
import io.anuke.arc.math.Angles;
|
||||||
@@ -14,22 +12,20 @@ import io.anuke.arc.math.geom.Rectangle;
|
|||||||
import io.anuke.arc.util.Interval;
|
import io.anuke.arc.util.Interval;
|
||||||
import io.anuke.arc.util.Time;
|
import io.anuke.arc.util.Time;
|
||||||
import io.anuke.mindustry.Vars;
|
import io.anuke.mindustry.Vars;
|
||||||
import io.anuke.mindustry.content.Fx;
|
import io.anuke.mindustry.entities.EntityGroup;
|
||||||
import io.anuke.mindustry.entities.Damage;
|
|
||||||
import io.anuke.mindustry.entities.TileEntity;
|
|
||||||
import io.anuke.mindustry.entities.Unit;
|
|
||||||
import io.anuke.mindustry.entities.Units;
|
import io.anuke.mindustry.entities.Units;
|
||||||
import io.anuke.mindustry.entities.effect.ScorchDecal;
|
|
||||||
import io.anuke.mindustry.entities.traits.ShooterTrait;
|
import io.anuke.mindustry.entities.traits.ShooterTrait;
|
||||||
import io.anuke.mindustry.entities.traits.SpawnerTrait;
|
|
||||||
import io.anuke.mindustry.entities.traits.TargetTrait;
|
import io.anuke.mindustry.entities.traits.TargetTrait;
|
||||||
|
import io.anuke.mindustry.entities.units.Squad;
|
||||||
|
import io.anuke.mindustry.entities.units.StateMachine;
|
||||||
|
import io.anuke.mindustry.entities.units.UnitDrops;
|
||||||
|
import io.anuke.mindustry.entities.units.UnitState;
|
||||||
import io.anuke.mindustry.game.Team;
|
import io.anuke.mindustry.game.Team;
|
||||||
import io.anuke.mindustry.gen.Call;
|
import io.anuke.mindustry.gen.Call;
|
||||||
import io.anuke.mindustry.graphics.Palette;
|
|
||||||
import io.anuke.mindustry.net.Net;
|
import io.anuke.mindustry.net.Net;
|
||||||
import io.anuke.mindustry.type.ContentType;
|
import io.anuke.mindustry.type.ContentType;
|
||||||
import io.anuke.mindustry.type.ItemStack;
|
|
||||||
import io.anuke.mindustry.type.StatusEffect;
|
import io.anuke.mindustry.type.StatusEffect;
|
||||||
|
import io.anuke.mindustry.type.UnitType;
|
||||||
import io.anuke.mindustry.type.Weapon;
|
import io.anuke.mindustry.type.Weapon;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.mindustry.world.meta.BlockFlag;
|
import io.anuke.mindustry.world.meta.BlockFlag;
|
||||||
@@ -70,16 +66,8 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
|||||||
UnitDrops.dropItems(unit);
|
UnitDrops.dropItems(unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
float explosiveness = 2f + (unit.inventory.hasItem() ? unit.inventory.getItem().item.explosiveness * unit.inventory.getItem().amount : 0f);
|
|
||||||
float flammability = (unit.inventory.hasItem() ? unit.inventory.getItem().item.flammability * unit.inventory.getItem().amount : 0f);
|
|
||||||
Damage.dynamicExplosion(unit.x, unit.y, flammability, explosiveness, 0f, unit.getSize() / 2f, Palette.darkFlame);
|
|
||||||
|
|
||||||
unit.onSuperDeath();
|
unit.onSuperDeath();
|
||||||
|
|
||||||
ScorchDecal.create(unit.x, unit.y);
|
|
||||||
Effects.effect(Fx.explosion, unit);
|
|
||||||
Effects.shake(2f, 2f, unit);
|
|
||||||
|
|
||||||
//must run afterwards so the unit's group is not null when sending the removal packet
|
//must run afterwards so the unit's group is not null when sending the removal packet
|
||||||
Core.app.post(unit::remove);
|
Core.app.post(unit::remove);
|
||||||
}
|
}
|
||||||
@@ -123,19 +111,6 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
|||||||
return target instanceof TileEntity && ((TileEntity) target).tile.block().flags.contains(flag);
|
return target instanceof TileEntity && ((TileEntity) target).tile.block().flags.contains(flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateRespawning(){
|
|
||||||
if(spawner == noSpawner) return;
|
|
||||||
|
|
||||||
Tile tile = world.tile(spawner);
|
|
||||||
if(tile != null && tile.entity != null){
|
|
||||||
if(tile.entity instanceof SpawnerTrait){
|
|
||||||
((SpawnerTrait) tile.entity).updateSpawning(this);
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
spawner = noSpawner;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setState(UnitState state){
|
public void setState(UnitState state){
|
||||||
this.state.set(state);
|
this.state.set(state);
|
||||||
}
|
}
|
||||||
@@ -190,14 +165,13 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
|||||||
|
|
||||||
protected void drawItems(){
|
protected void drawItems(){
|
||||||
float backTrns = 4f, itemSize = 5f;
|
float backTrns = 4f, itemSize = 5f;
|
||||||
if(inventory.hasItem()){
|
if(item.amount > 0){
|
||||||
ItemStack stack = inventory.getItem();
|
int stored = Mathf.clamp(item.amount / 6, 1, 8);
|
||||||
int stored = Mathf.clamp(stack.amount / 6, 1, 8);
|
|
||||||
|
|
||||||
for(int i = 0; i < stored; i++){
|
for(int i = 0; i < stored; i++){
|
||||||
float angT = i == 0 ? 0 : Mathf.randomSeedRange(i + 2, 60f);
|
float angT = i == 0 ? 0 : Mathf.randomSeedRange(i + 2, 60f);
|
||||||
float lenT = i == 0 ? 0 : Mathf.randomSeedRange(i + 3, 1f) - 1f;
|
float lenT = i == 0 ? 0 : Mathf.randomSeedRange(i + 3, 1f) - 1f;
|
||||||
Draw.rect(stack.item.region,
|
Draw.rect(item.item.region,
|
||||||
x + Angles.trnsx(rotation + 180f + angT, backTrns + lenT),
|
x + Angles.trnsx(rotation + 180f + angT, backTrns + lenT),
|
||||||
y + Angles.trnsy(rotation + 180f + angT, backTrns + lenT),
|
y + Angles.trnsy(rotation + 180f + angT, backTrns + lenT),
|
||||||
itemSize, itemSize, rotation);
|
itemSize, itemSize, rotation);
|
||||||
@@ -254,11 +228,6 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
|||||||
return type.health;
|
return type.health;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public float getArmor(){
|
|
||||||
return type.armor;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getSize(){
|
public float getSize(){
|
||||||
return 8;
|
return 8;
|
||||||
@@ -279,7 +248,6 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
|||||||
hitTime -= Time.delta();
|
hitTime -= Time.delta();
|
||||||
|
|
||||||
if(isDead()){
|
if(isDead()){
|
||||||
updateRespawning();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -295,10 +263,6 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
|||||||
damage(health);
|
damage(health);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(squad != null){
|
|
||||||
squad.update();
|
|
||||||
}
|
|
||||||
|
|
||||||
updateTargeting();
|
updateTargeting();
|
||||||
|
|
||||||
state.update();
|
state.update();
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package io.anuke.mindustry.entities.units;
|
package io.anuke.mindustry.entities.type;
|
||||||
|
|
||||||
import io.anuke.arc.graphics.g2d.Draw;
|
import io.anuke.arc.graphics.g2d.Draw;
|
||||||
import io.anuke.arc.math.Angles;
|
import io.anuke.arc.math.Angles;
|
||||||
@@ -9,6 +9,7 @@ import io.anuke.arc.util.Time;
|
|||||||
import io.anuke.mindustry.entities.Predict;
|
import io.anuke.mindustry.entities.Predict;
|
||||||
import io.anuke.mindustry.entities.Units;
|
import io.anuke.mindustry.entities.Units;
|
||||||
import io.anuke.mindustry.entities.bullet.BulletType;
|
import io.anuke.mindustry.entities.bullet.BulletType;
|
||||||
|
import io.anuke.mindustry.entities.units.UnitState;
|
||||||
import io.anuke.mindustry.graphics.Shaders;
|
import io.anuke.mindustry.graphics.Shaders;
|
||||||
import io.anuke.mindustry.net.Net;
|
import io.anuke.mindustry.net.Net;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package io.anuke.mindustry.entities.units;
|
package io.anuke.mindustry.entities.type;
|
||||||
|
|
||||||
import io.anuke.arc.graphics.Color;
|
import io.anuke.arc.graphics.Color;
|
||||||
import io.anuke.arc.graphics.g2d.Draw;
|
import io.anuke.arc.graphics.g2d.Draw;
|
||||||
@@ -8,9 +8,10 @@ import io.anuke.arc.math.geom.Vector2;
|
|||||||
import io.anuke.arc.util.Time;
|
import io.anuke.arc.util.Time;
|
||||||
import io.anuke.mindustry.Vars;
|
import io.anuke.mindustry.Vars;
|
||||||
import io.anuke.mindustry.entities.Predict;
|
import io.anuke.mindustry.entities.Predict;
|
||||||
import io.anuke.mindustry.entities.TileEntity;
|
|
||||||
import io.anuke.mindustry.entities.Units;
|
import io.anuke.mindustry.entities.Units;
|
||||||
import io.anuke.mindustry.entities.bullet.BulletType;
|
import io.anuke.mindustry.entities.bullet.BulletType;
|
||||||
|
import io.anuke.mindustry.entities.units.UnitState;
|
||||||
|
import io.anuke.mindustry.type.UnitType;
|
||||||
import io.anuke.mindustry.game.Team;
|
import io.anuke.mindustry.game.Team;
|
||||||
import io.anuke.mindustry.graphics.Shaders;
|
import io.anuke.mindustry.graphics.Shaders;
|
||||||
import io.anuke.mindustry.type.ContentType;
|
import io.anuke.mindustry.type.ContentType;
|
||||||
@@ -1,12 +1,9 @@
|
|||||||
package io.anuke.mindustry.entities;
|
package io.anuke.mindustry.entities.type;
|
||||||
|
|
||||||
import io.anuke.annotations.Annotations.Loc;
|
import io.anuke.annotations.Annotations.Loc;
|
||||||
import io.anuke.annotations.Annotations.Remote;
|
import io.anuke.annotations.Annotations.Remote;
|
||||||
import io.anuke.arc.Core;
|
import io.anuke.arc.Core;
|
||||||
import io.anuke.arc.collection.Queue;
|
import io.anuke.arc.collection.Queue;
|
||||||
import io.anuke.arc.entities.Effects;
|
|
||||||
import io.anuke.arc.entities.EntityGroup;
|
|
||||||
import io.anuke.arc.entities.EntityQuery;
|
|
||||||
import io.anuke.arc.graphics.Color;
|
import io.anuke.arc.graphics.Color;
|
||||||
import io.anuke.arc.graphics.g2d.*;
|
import io.anuke.arc.graphics.g2d.*;
|
||||||
import io.anuke.arc.math.Angles;
|
import io.anuke.arc.math.Angles;
|
||||||
@@ -21,7 +18,7 @@ import io.anuke.arc.util.Time;
|
|||||||
import io.anuke.arc.util.pooling.Pools;
|
import io.anuke.arc.util.pooling.Pools;
|
||||||
import io.anuke.mindustry.content.Fx;
|
import io.anuke.mindustry.content.Fx;
|
||||||
import io.anuke.mindustry.content.Mechs;
|
import io.anuke.mindustry.content.Mechs;
|
||||||
import io.anuke.mindustry.entities.effect.ScorchDecal;
|
import io.anuke.mindustry.entities.*;
|
||||||
import io.anuke.mindustry.entities.traits.BuilderTrait;
|
import io.anuke.mindustry.entities.traits.BuilderTrait;
|
||||||
import io.anuke.mindustry.entities.traits.ShooterTrait;
|
import io.anuke.mindustry.entities.traits.ShooterTrait;
|
||||||
import io.anuke.mindustry.entities.traits.SpawnerTrait;
|
import io.anuke.mindustry.entities.traits.SpawnerTrait;
|
||||||
@@ -67,7 +64,7 @@ public class Player extends Unit implements BuilderTrait, ShooterTrait{
|
|||||||
public boolean achievedFlight;
|
public boolean achievedFlight;
|
||||||
public Color color = new Color();
|
public Color color = new Color();
|
||||||
public Mech mech;
|
public Mech mech;
|
||||||
public int spawner = noSpawner;
|
public SpawnerTrait spawner;
|
||||||
|
|
||||||
public NetConnection con;
|
public NetConnection con;
|
||||||
public int playerIndex = 0;
|
public int playerIndex = 0;
|
||||||
@@ -92,12 +89,6 @@ public class Player extends Unit implements BuilderTrait, ShooterTrait{
|
|||||||
|
|
||||||
player.dead = true;
|
player.dead = true;
|
||||||
player.placeQueue.clear();
|
player.placeQueue.clear();
|
||||||
|
|
||||||
float explosiveness = 2f + (player.inventory.hasItem() ? player.inventory.getItem().item.explosiveness * player.inventory.getItem().amount : 0f);
|
|
||||||
float flammability = (player.inventory.hasItem() ? player.inventory.getItem().item.flammability * player.inventory.getItem().amount : 0f);
|
|
||||||
Damage.dynamicExplosion(player.x, player.y, flammability, explosiveness, 0f, player.getSize() / 2f, Palette.darkFlame);
|
|
||||||
|
|
||||||
ScorchDecal.create(player.x, player.y);
|
|
||||||
player.onDeath();
|
player.onDeath();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,7 +178,7 @@ public class Player extends Unit implements BuilderTrait, ShooterTrait{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float maxHealth(){
|
public float maxHealth(){
|
||||||
return 200;
|
return mech.health;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -206,8 +197,8 @@ public class Player extends Unit implements BuilderTrait, ShooterTrait{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getArmor(){
|
public float calculateDamage(float amount){
|
||||||
return mech.armor + mech.getExtraArmor(this);
|
return amount * Mathf.clamp(1f - (status.getArmorMultiplier() + mech.getExtraArmor(this)) / 100f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -356,8 +347,8 @@ public class Player extends Unit implements BuilderTrait, ShooterTrait{
|
|||||||
}
|
}
|
||||||
|
|
||||||
float backTrns = 4f, itemSize = 5f;
|
float backTrns = 4f, itemSize = 5f;
|
||||||
if(inventory.hasItem()){
|
if(item.amount > 0){
|
||||||
ItemStack stack = inventory.getItem();
|
ItemStack stack = item;
|
||||||
int stored = Mathf.clamp(stack.amount / 6, 1, 8);
|
int stored = Mathf.clamp(stack.amount / 6, 1, 8);
|
||||||
|
|
||||||
for(int i = 0; i < stored; i++){
|
for(int i = 0; i < stored; i++){
|
||||||
@@ -385,7 +376,7 @@ public class Player extends Unit implements BuilderTrait, ShooterTrait{
|
|||||||
public void drawOver(){
|
public void drawOver(){
|
||||||
if(dead) return;
|
if(dead) return;
|
||||||
|
|
||||||
drawBuilding(this);
|
drawBuilding();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawName(){
|
public void drawName(){
|
||||||
@@ -505,7 +496,7 @@ public class Player extends Unit implements BuilderTrait, ShooterTrait{
|
|||||||
updateRespawning();
|
updateRespawning();
|
||||||
return;
|
return;
|
||||||
}else{
|
}else{
|
||||||
spawner = noSpawner;
|
spawner = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
avoidOthers(1f);
|
avoidOthers(1f);
|
||||||
@@ -533,7 +524,7 @@ public class Player extends Unit implements BuilderTrait, ShooterTrait{
|
|||||||
|
|
||||||
if(!isLocal){
|
if(!isLocal){
|
||||||
interpolate();
|
interpolate();
|
||||||
updateBuilding(this); //building happens even with non-locals
|
updateBuilding(); //building happens even with non-locals
|
||||||
status.update(this); //status effect updating also happens with non locals for effect purposes
|
status.update(this); //status effect updating also happens with non locals for effect purposes
|
||||||
updateVelocityStatus(); //velocity too, for visual purposes
|
updateVelocityStatus(); //velocity too, for visual purposes
|
||||||
|
|
||||||
@@ -552,7 +543,7 @@ public class Player extends Unit implements BuilderTrait, ShooterTrait{
|
|||||||
updateMech();
|
updateMech();
|
||||||
}
|
}
|
||||||
|
|
||||||
updateBuilding(this);
|
updateBuilding();
|
||||||
|
|
||||||
if(!mech.flying){
|
if(!mech.flying){
|
||||||
clampPosition();
|
clampPosition();
|
||||||
@@ -570,10 +561,6 @@ public class Player extends Unit implements BuilderTrait, ShooterTrait{
|
|||||||
}
|
}
|
||||||
|
|
||||||
float speed = isBoosting && !mech.flying ? mech.boostSpeed : mech.speed;
|
float speed = isBoosting && !mech.flying ? mech.boostSpeed : mech.speed;
|
||||||
//fraction of speed when at max load
|
|
||||||
float carrySlowdown = 0.7f;
|
|
||||||
|
|
||||||
speed *= ((inventory.hasItem() ? Mathf.lerp(1f, carrySlowdown, (float) inventory.getItem().amount / inventory.capacity()) : 1f));
|
|
||||||
|
|
||||||
if(mech.flying){
|
if(mech.flying){
|
||||||
//prevent strafing backwards, have a penalty for doing so
|
//prevent strafing backwards, have a penalty for doing so
|
||||||
@@ -754,7 +741,7 @@ public class Player extends Unit implements BuilderTrait, ShooterTrait{
|
|||||||
public void resetNoAdd(){
|
public void resetNoAdd(){
|
||||||
status.clear();
|
status.clear();
|
||||||
team = Team.blue;
|
team = Team.blue;
|
||||||
inventory.clear();
|
item.amount = 0;
|
||||||
placeQueue.clear();
|
placeQueue.clear();
|
||||||
dead = true;
|
dead = true;
|
||||||
target = null;
|
target = null;
|
||||||
@@ -771,23 +758,23 @@ public class Player extends Unit implements BuilderTrait, ShooterTrait{
|
|||||||
|
|
||||||
public void updateRespawning(){
|
public void updateRespawning(){
|
||||||
|
|
||||||
if(spawner != noSpawner && world.tile(spawner) != null && world.tile(spawner).entity instanceof SpawnerTrait){
|
if(spawner != null && spawner.isValid()){
|
||||||
((SpawnerTrait) world.tile(spawner).entity).updateSpawning(this);
|
spawner.updateSpawning(this);
|
||||||
}else{
|
}else{
|
||||||
CoreEntity entity = (CoreEntity) getClosestCore();
|
CoreEntity entity = (CoreEntity) getClosestCore();
|
||||||
if(entity != null && !netServer.isWaitingForPlayers()){
|
if(entity != null && !netServer.isWaitingForPlayers()){
|
||||||
this.spawner = entity.tile.pos();
|
this.spawner = (SpawnerTrait)entity.tile.entity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void beginRespawning(SpawnerTrait spawner){
|
public void beginRespawning(SpawnerTrait spawner){
|
||||||
this.spawner = spawner.getTile().pos();
|
this.spawner = spawner;
|
||||||
this.dead = true;
|
this.dead = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void endRespawning(){
|
public void endRespawning(){
|
||||||
spawner = noSpawner;
|
spawner = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
@@ -844,7 +831,7 @@ public class Player extends Unit implements BuilderTrait, ShooterTrait{
|
|||||||
buffer.writeInt(Color.rgba8888(color));
|
buffer.writeInt(Color.rgba8888(color));
|
||||||
buffer.writeByte(mech.id);
|
buffer.writeByte(mech.id);
|
||||||
buffer.writeInt(mining == null ? -1 : mining.pos());
|
buffer.writeInt(mining == null ? -1 : mining.pos());
|
||||||
buffer.writeInt(spawner);
|
buffer.writeInt(spawner == null ? noSpawner : spawner.getTile().pos());
|
||||||
buffer.writeShort((short) (baseRotation * 2));
|
buffer.writeShort((short) (baseRotation * 2));
|
||||||
|
|
||||||
writeBuilding(buffer);
|
writeBuilding(buffer);
|
||||||
@@ -876,7 +863,12 @@ public class Player extends Unit implements BuilderTrait, ShooterTrait{
|
|||||||
}else{
|
}else{
|
||||||
mining = world.tile(mine);
|
mining = world.tile(mine);
|
||||||
isBoosting = boosting;
|
isBoosting = boosting;
|
||||||
this.spawner = spawner;
|
Tile tile = world.tile(spawner);
|
||||||
|
if(tile != null && tile.entity instanceof SpawnerTrait){
|
||||||
|
this.spawner = (SpawnerTrait)tile.entity;
|
||||||
|
}else{
|
||||||
|
this.spawner = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
package io.anuke.mindustry.entities;
|
package io.anuke.mindustry.entities.type;
|
||||||
|
|
||||||
import io.anuke.annotations.Annotations.Loc;
|
import io.anuke.annotations.Annotations.Loc;
|
||||||
import io.anuke.annotations.Annotations.Remote;
|
import io.anuke.annotations.Annotations.Remote;
|
||||||
import io.anuke.arc.Events;
|
import io.anuke.arc.Events;
|
||||||
import io.anuke.arc.collection.Array;
|
import io.anuke.arc.collection.Array;
|
||||||
import io.anuke.arc.collection.ObjectSet;
|
import io.anuke.arc.collection.ObjectSet;
|
||||||
import io.anuke.arc.entities.Effects;
|
import io.anuke.mindustry.entities.Effects;
|
||||||
import io.anuke.arc.entities.EntityGroup;
|
import io.anuke.mindustry.entities.EntityGroup;
|
||||||
import io.anuke.arc.entities.impl.BaseEntity;
|
import io.anuke.mindustry.entities.impl.BaseEntity;
|
||||||
import io.anuke.arc.entities.trait.HealthTrait;
|
import io.anuke.mindustry.entities.traits.HealthTrait;
|
||||||
import io.anuke.arc.math.Mathf;
|
import io.anuke.arc.math.Mathf;
|
||||||
import io.anuke.arc.math.geom.Point2;
|
import io.anuke.arc.math.geom.Point2;
|
||||||
import io.anuke.arc.math.geom.Vector2;
|
import io.anuke.arc.math.geom.Vector2;
|
||||||
@@ -1,15 +1,9 @@
|
|||||||
package io.anuke.mindustry.entities;
|
package io.anuke.mindustry.entities.type;
|
||||||
|
|
||||||
import io.anuke.arc.Core;
|
import io.anuke.arc.Core;
|
||||||
import io.anuke.arc.Events;
|
import io.anuke.arc.Events;
|
||||||
import io.anuke.arc.entities.Effects;
|
|
||||||
import io.anuke.arc.entities.impl.DestructibleEntity;
|
|
||||||
import io.anuke.arc.entities.trait.DamageTrait;
|
|
||||||
import io.anuke.arc.entities.trait.DrawTrait;
|
|
||||||
import io.anuke.arc.entities.trait.SolidTrait;
|
|
||||||
import io.anuke.arc.graphics.Color;
|
import io.anuke.arc.graphics.Color;
|
||||||
import io.anuke.arc.graphics.g2d.Draw;
|
import io.anuke.arc.graphics.g2d.Draw;
|
||||||
import io.anuke.arc.graphics.g2d.Fill;
|
|
||||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||||
import io.anuke.arc.math.Mathf;
|
import io.anuke.arc.math.Mathf;
|
||||||
import io.anuke.arc.math.geom.Geometry;
|
import io.anuke.arc.math.geom.Geometry;
|
||||||
@@ -17,12 +11,21 @@ import io.anuke.arc.math.geom.Rectangle;
|
|||||||
import io.anuke.arc.math.geom.Vector2;
|
import io.anuke.arc.math.geom.Vector2;
|
||||||
import io.anuke.arc.util.Time;
|
import io.anuke.arc.util.Time;
|
||||||
import io.anuke.mindustry.content.Blocks;
|
import io.anuke.mindustry.content.Blocks;
|
||||||
|
import io.anuke.mindustry.content.Fx;
|
||||||
|
import io.anuke.mindustry.entities.Damage;
|
||||||
|
import io.anuke.mindustry.entities.Effects;
|
||||||
|
import io.anuke.mindustry.entities.Units;
|
||||||
|
import io.anuke.mindustry.entities.effect.ScorchDecal;
|
||||||
|
import io.anuke.mindustry.entities.impl.DestructibleEntity;
|
||||||
import io.anuke.mindustry.entities.traits.*;
|
import io.anuke.mindustry.entities.traits.*;
|
||||||
|
import io.anuke.mindustry.entities.units.Statuses;
|
||||||
import io.anuke.mindustry.game.EventType.UnitDestroyEvent;
|
import io.anuke.mindustry.game.EventType.UnitDestroyEvent;
|
||||||
import io.anuke.mindustry.game.Team;
|
import io.anuke.mindustry.game.Team;
|
||||||
import io.anuke.mindustry.game.Teams.TeamData;
|
import io.anuke.mindustry.game.Teams.TeamData;
|
||||||
|
import io.anuke.mindustry.graphics.Palette;
|
||||||
import io.anuke.mindustry.net.Interpolator;
|
import io.anuke.mindustry.net.Interpolator;
|
||||||
import io.anuke.mindustry.net.Net;
|
import io.anuke.mindustry.net.Net;
|
||||||
|
import io.anuke.mindustry.type.Item;
|
||||||
import io.anuke.mindustry.type.ItemStack;
|
import io.anuke.mindustry.type.ItemStack;
|
||||||
import io.anuke.mindustry.type.StatusEffect;
|
import io.anuke.mindustry.type.StatusEffect;
|
||||||
import io.anuke.mindustry.type.Weapon;
|
import io.anuke.mindustry.type.Weapon;
|
||||||
@@ -35,7 +38,6 @@ import java.io.DataOutput;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.*;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
import static io.anuke.mindustry.Vars.tilesize;
|
|
||||||
|
|
||||||
public abstract class Unit extends DestructibleEntity implements SaveTrait, TargetTrait, SyncTrait, DrawTrait, TeamTrait{
|
public abstract class Unit extends DestructibleEntity implements SaveTrait, TargetTrait, SyncTrait, DrawTrait, TeamTrait{
|
||||||
/**Total duration of hit flash effect*/
|
/**Total duration of hit flash effect*/
|
||||||
@@ -53,7 +55,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
|||||||
|
|
||||||
protected final Interpolator interpolator = new Interpolator();
|
protected final Interpolator interpolator = new Interpolator();
|
||||||
protected final Statuses status = new Statuses();
|
protected final Statuses status = new Statuses();
|
||||||
protected final ItemStack inventory = new ItemStack(content.item(0), 0);
|
protected final ItemStack item = new ItemStack(content.item(0), 0);
|
||||||
|
|
||||||
protected Team team = Team.blue;
|
protected Team team = Team.blue;
|
||||||
protected float drownTime, hitTime;
|
protected float drownTime, hitTime;
|
||||||
@@ -109,7 +111,15 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDeath(){
|
public void onDeath(){
|
||||||
inventory.amount = 0;
|
float explosiveness = 2f + item.item.explosiveness * item.amount;
|
||||||
|
float flammability = item.item.flammability * item.amount;
|
||||||
|
Damage.dynamicExplosion(x, y, flammability, explosiveness, 0f, getSize() / 2f, Palette.darkFlame);
|
||||||
|
|
||||||
|
ScorchDecal.create(x, y);
|
||||||
|
Effects.effect(Fx.explosion, this);
|
||||||
|
Effects.shake(2f, 2f, this);
|
||||||
|
|
||||||
|
item.amount = 0;
|
||||||
drownTime = 0f;
|
drownTime = 0f;
|
||||||
status.clear();
|
status.clear();
|
||||||
Events.fire(new UnitDestroyEvent(this));
|
Events.fire(new UnitDestroyEvent(this));
|
||||||
@@ -129,6 +139,11 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValid(){
|
||||||
|
return !isDead() && isAdded();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeSave(DataOutput stream) throws IOException{
|
public void writeSave(DataOutput stream) throws IOException{
|
||||||
writeSave(stream, false);
|
writeSave(stream, false);
|
||||||
@@ -144,9 +159,12 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
|||||||
byte yv = stream.readByte();
|
byte yv = stream.readByte();
|
||||||
float rotation = stream.readShort() / 2f;
|
float rotation = stream.readShort() / 2f;
|
||||||
int health = stream.readShort();
|
int health = stream.readShort();
|
||||||
|
byte itemID = stream.readByte();
|
||||||
|
short itemAmount = stream.readShort();
|
||||||
|
|
||||||
this.status.readSave(stream);
|
this.status.readSave(stream);
|
||||||
this.inventory.readSave(stream);
|
this.item.amount = itemAmount;
|
||||||
|
this.item.item = content.item(itemID);
|
||||||
this.dead = dead;
|
this.dead = dead;
|
||||||
this.team = Team.all[team];
|
this.team = Team.all[team];
|
||||||
this.health = health;
|
this.health = health;
|
||||||
@@ -165,8 +183,9 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
|||||||
stream.writeByte((byte) (Mathf.clamp(velocity.y, -maxAbsVelocity, maxAbsVelocity) * velocityPercision));
|
stream.writeByte((byte) (Mathf.clamp(velocity.y, -maxAbsVelocity, maxAbsVelocity) * velocityPercision));
|
||||||
stream.writeShort((short) (rotation * 2));
|
stream.writeShort((short) (rotation * 2));
|
||||||
stream.writeShort((short) health);
|
stream.writeShort((short) health);
|
||||||
|
stream.writeByte(item.item.id);
|
||||||
|
stream.writeShort((short)item.amount);
|
||||||
status.writeSave(stream);
|
status.writeSave(stream);
|
||||||
inventory.writeSave(stream);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void clampPosition(){
|
protected void clampPosition(){
|
||||||
@@ -188,7 +207,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
|||||||
}
|
}
|
||||||
|
|
||||||
public float calculateDamage(float amount){
|
public float calculateDamage(float amount){
|
||||||
return amount * Mathf.clamp(1f - getArmor() / 100f * status.getArmorMultiplier());
|
return amount * Mathf.clamp(1f - status.getArmorMultiplier() / 100f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getDamageMultipler(){
|
public float getDamageMultipler(){
|
||||||
@@ -229,11 +248,6 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
|||||||
|
|
||||||
public void onRespawn(Tile tile){}
|
public void onRespawn(Tile tile){}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isValid(){
|
|
||||||
return !isDead() && isAdded();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**Updates velocity and status effects.*/
|
/**Updates velocity and status effects.*/
|
||||||
public void updateVelocityStatus(){
|
public void updateVelocityStatus(){
|
||||||
Floor floor = getFloorOn();
|
Floor floor = getFloorOn();
|
||||||
@@ -292,6 +306,31 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
|||||||
velocity.scl(Mathf.clamp(1f - drag() * (isFlying() ? 1f : floor.dragMultiplier) * Time.delta()));
|
velocity.scl(Mathf.clamp(1f - drag() * (isFlying() ? 1f : floor.dragMultiplier) * Time.delta()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean acceptsItem(Item item){
|
||||||
|
return this.item.amount <= 0 || (this.item.item == item && this.item.amount <= getItemCapacity());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addItem(Item item){
|
||||||
|
addItem(item, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addItem(Item item, int amount){
|
||||||
|
this.item.amount = this.item.item == item ? this.item.amount + amount : amount;
|
||||||
|
this.item.item = item;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearItem(){
|
||||||
|
item.amount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack item(){
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int maxAccepted(Item item){
|
||||||
|
return this.item.item != item ? 0 : getItemCapacity() - this.item.amount;
|
||||||
|
}
|
||||||
|
|
||||||
public void applyEffect(StatusEffect effect, float duration){
|
public void applyEffect(StatusEffect effect, float duration){
|
||||||
if(dead || Net.client()) return; //effects are synced and thus not applied through clients
|
if(dead || Net.client()) return; //effects are synced and thus not applied through clients
|
||||||
status.handleApply(this, effect, duration);
|
status.handleApply(this, effect, duration);
|
||||||
@@ -339,18 +378,12 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
|||||||
Draw.rect(getIconRegion(), x + offsetX, y + offsetY, rotation - 90);
|
Draw.rect(getIconRegion(), x + offsetX, y + offsetY, rotation - 90);
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getViewDistance(){
|
|
||||||
return 135f;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract TextureRegion getIconRegion();
|
public abstract TextureRegion getIconRegion();
|
||||||
|
|
||||||
public abstract Weapon getWeapon();
|
public abstract Weapon getWeapon();
|
||||||
|
|
||||||
public abstract int getItemCapacity();
|
public abstract int getItemCapacity();
|
||||||
|
|
||||||
public abstract float getArmor();
|
|
||||||
|
|
||||||
public abstract float mass();
|
public abstract float mass();
|
||||||
|
|
||||||
public abstract boolean isFlying();
|
public abstract boolean isFlying();
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package io.anuke.mindustry.entities.type.types;
|
||||||
|
|
||||||
|
import io.anuke.mindustry.entities.type.GroundUnit;
|
||||||
|
|
||||||
|
public class Crawler extends GroundUnit{
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package io.anuke.mindustry.entities.type.types;
|
||||||
|
|
||||||
|
import io.anuke.mindustry.entities.type.GroundUnit;
|
||||||
|
|
||||||
|
public class Dagger extends GroundUnit{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,18 +1,18 @@
|
|||||||
package io.anuke.mindustry.entities.units.types;
|
package io.anuke.mindustry.entities.type.types;
|
||||||
|
|
||||||
import io.anuke.arc.Events;
|
import io.anuke.arc.Events;
|
||||||
import io.anuke.arc.collection.Queue;
|
import io.anuke.arc.collection.Queue;
|
||||||
import io.anuke.arc.entities.EntityGroup;
|
import io.anuke.mindustry.entities.EntityGroup;
|
||||||
import io.anuke.arc.math.Mathf;
|
import io.anuke.arc.math.Mathf;
|
||||||
import io.anuke.arc.math.geom.Geometry;
|
import io.anuke.arc.math.geom.Geometry;
|
||||||
import io.anuke.arc.util.Structs;
|
import io.anuke.arc.util.Structs;
|
||||||
import io.anuke.mindustry.content.Blocks;
|
import io.anuke.mindustry.content.Blocks;
|
||||||
import io.anuke.mindustry.entities.Player;
|
import io.anuke.mindustry.entities.type.Player;
|
||||||
import io.anuke.mindustry.entities.TileEntity;
|
import io.anuke.mindustry.entities.type.TileEntity;
|
||||||
import io.anuke.mindustry.entities.Units;
|
import io.anuke.mindustry.entities.Units;
|
||||||
import io.anuke.mindustry.entities.traits.BuilderTrait;
|
import io.anuke.mindustry.entities.traits.BuilderTrait;
|
||||||
import io.anuke.mindustry.entities.units.BaseUnit;
|
import io.anuke.mindustry.entities.type.BaseUnit;
|
||||||
import io.anuke.mindustry.entities.units.FlyingUnit;
|
import io.anuke.mindustry.entities.type.FlyingUnit;
|
||||||
import io.anuke.mindustry.entities.units.UnitState;
|
import io.anuke.mindustry.entities.units.UnitState;
|
||||||
import io.anuke.mindustry.game.EventType.BuildSelectEvent;
|
import io.anuke.mindustry.game.EventType.BuildSelectEvent;
|
||||||
import io.anuke.mindustry.gen.Call;
|
import io.anuke.mindustry.gen.Call;
|
||||||
@@ -135,10 +135,10 @@ public class Drone extends FlyingUnit implements BuilderTrait{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//if inventory is full, drop it off.
|
//if inventory is full, drop it off.
|
||||||
if(inventory.isFull()){
|
if(item.amount >= getItemCapacity()){
|
||||||
setState(drop);
|
setState(drop);
|
||||||
}else{
|
}else{
|
||||||
if(targetItem != null && !inventory.canAcceptItem(targetItem)){
|
if(targetItem != null && !acceptsItem(targetItem)){
|
||||||
setState(drop);
|
setState(drop);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -177,13 +177,13 @@ public class Drone extends FlyingUnit implements BuilderTrait{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void update(){
|
public void update(){
|
||||||
if(inventory.isEmpty()){
|
if(item.amount == 0){
|
||||||
setState(mine);
|
setState(mine);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(inventory.getItem().item.type != ItemType.material){
|
if(item.item.type != ItemType.material){
|
||||||
inventory.clearItem();
|
item.amount = 0;
|
||||||
setState(mine);
|
setState(mine);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -195,9 +195,9 @@ public class Drone extends FlyingUnit implements BuilderTrait{
|
|||||||
TileEntity tile = (TileEntity) target;
|
TileEntity tile = (TileEntity) target;
|
||||||
|
|
||||||
if(dst(target) < type.range){
|
if(dst(target) < type.range){
|
||||||
if(tile.tile.block().acceptStack(inventory.getItem().item, inventory.getItem().amount, tile.tile, Drone.this) == inventory.getItem().amount){
|
if(tile.tile.block().acceptStack(item.item, item.amount, tile.tile, Drone.this) == item.amount){
|
||||||
Call.transferItemTo(inventory.getItem().item, inventory.getItem().amount, x, y, tile.tile);
|
Call.transferItemTo(item.item, item.amount, x, y, tile.tile);
|
||||||
inventory.clearItem();
|
item.amount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
setState(repair);
|
setState(repair);
|
||||||
@@ -299,7 +299,7 @@ public class Drone extends FlyingUnit implements BuilderTrait{
|
|||||||
target = null;
|
target = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateBuilding(this);
|
updateBuilding();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -326,7 +326,7 @@ public class Drone extends FlyingUnit implements BuilderTrait{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawOver(){
|
public void drawOver(){
|
||||||
drawBuilding(this);
|
drawBuilding();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package io.anuke.mindustry.entities.type.types;
|
||||||
|
|
||||||
|
import io.anuke.mindustry.entities.type.GroundUnit;
|
||||||
|
|
||||||
|
public class Eruptor extends GroundUnit{
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package io.anuke.mindustry.entities.units.types;
|
package io.anuke.mindustry.entities.type.types;
|
||||||
|
|
||||||
import io.anuke.mindustry.entities.Units;
|
import io.anuke.mindustry.entities.Units;
|
||||||
import io.anuke.mindustry.entities.units.GroundUnit;
|
import io.anuke.mindustry.entities.type.GroundUnit;
|
||||||
|
|
||||||
public class Fortress extends GroundUnit{
|
public class Fortress extends GroundUnit{
|
||||||
|
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package io.anuke.mindustry.entities.type.types;
|
||||||
|
|
||||||
|
import io.anuke.mindustry.entities.type.FlyingUnit;
|
||||||
|
|
||||||
|
public class Ghoul extends FlyingUnit{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package io.anuke.mindustry.entities.type.types;
|
||||||
|
|
||||||
|
public class Phantom extends Drone{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package io.anuke.mindustry.entities.type.types;
|
||||||
|
|
||||||
|
import io.anuke.mindustry.entities.type.FlyingUnit;
|
||||||
|
|
||||||
|
public class Revenant extends FlyingUnit{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package io.anuke.mindustry.entities.type.types;
|
||||||
|
|
||||||
|
public class Spirit extends Drone{
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package io.anuke.mindustry.entities.type.types;
|
||||||
|
|
||||||
|
import io.anuke.mindustry.entities.type.GroundUnit;
|
||||||
|
|
||||||
|
public class Titan extends GroundUnit{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package io.anuke.mindustry.entities.type.types;
|
||||||
|
|
||||||
|
import io.anuke.mindustry.entities.type.FlyingUnit;
|
||||||
|
|
||||||
|
public class Wraith extends FlyingUnit{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package io.anuke.mindustry.entities;
|
package io.anuke.mindustry.entities.units;
|
||||||
|
|
||||||
import io.anuke.arc.collection.Array;
|
import io.anuke.arc.collection.Array;
|
||||||
import io.anuke.arc.graphics.Color;
|
import io.anuke.arc.graphics.Color;
|
||||||
@@ -7,6 +7,7 @@ import io.anuke.arc.util.Tmp;
|
|||||||
import io.anuke.arc.util.pooling.Pools;
|
import io.anuke.arc.util.pooling.Pools;
|
||||||
import io.anuke.mindustry.content.StatusEffects;
|
import io.anuke.mindustry.content.StatusEffects;
|
||||||
import io.anuke.mindustry.entities.traits.Saveable;
|
import io.anuke.mindustry.entities.traits.Saveable;
|
||||||
|
import io.anuke.mindustry.entities.type.Unit;
|
||||||
import io.anuke.mindustry.type.ContentType;
|
import io.anuke.mindustry.type.ContentType;
|
||||||
import io.anuke.mindustry.type.StatusEffect;
|
import io.anuke.mindustry.type.StatusEffect;
|
||||||
|
|
||||||
@@ -26,7 +27,7 @@ public class Statuses implements Saveable{
|
|||||||
private float damageMultiplier;
|
private float damageMultiplier;
|
||||||
private float armorMultiplier;
|
private float armorMultiplier;
|
||||||
|
|
||||||
public void handleApply(Unit unit, StatusEffect effect, float duration){
|
public void handleApply(io.anuke.mindustry.entities.type.Unit unit, StatusEffect effect, float duration){
|
||||||
if(effect == StatusEffects.none || unit.isImmune(effect)) return; //don't apply empty or immune effects
|
if(effect == StatusEffects.none || unit.isImmune(effect)) return; //don't apply empty or immune effects
|
||||||
|
|
||||||
if(statuses.size > 0){
|
if(statuses.size > 0){
|
||||||
@@ -2,7 +2,8 @@ package io.anuke.mindustry.entities.units;
|
|||||||
|
|
||||||
import io.anuke.mindustry.Vars;
|
import io.anuke.mindustry.Vars;
|
||||||
import io.anuke.mindustry.content.Items;
|
import io.anuke.mindustry.content.Items;
|
||||||
import io.anuke.mindustry.entities.TileEntity;
|
import io.anuke.mindustry.entities.type.BaseUnit;
|
||||||
|
import io.anuke.mindustry.entities.type.TileEntity;
|
||||||
import io.anuke.mindustry.gen.Call;
|
import io.anuke.mindustry.gen.Call;
|
||||||
import io.anuke.mindustry.type.Item;
|
import io.anuke.mindustry.type.Item;
|
||||||
import io.anuke.arc.math.Mathf;
|
import io.anuke.arc.math.Mathf;
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
package io.anuke.mindustry.entities.units.types;
|
|
||||||
|
|
||||||
import io.anuke.mindustry.entities.units.GroundUnit;
|
|
||||||
|
|
||||||
public class Crawler extends GroundUnit{
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package io.anuke.mindustry.entities.units.types;
|
|
||||||
|
|
||||||
import io.anuke.mindustry.entities.units.GroundUnit;
|
|
||||||
|
|
||||||
public class Dagger extends GroundUnit{
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
package io.anuke.mindustry.entities.units.types;
|
|
||||||
|
|
||||||
import io.anuke.mindustry.entities.units.GroundUnit;
|
|
||||||
|
|
||||||
public class Eruptor extends GroundUnit{
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package io.anuke.mindustry.entities.units.types;
|
|
||||||
|
|
||||||
import io.anuke.mindustry.entities.units.FlyingUnit;
|
|
||||||
|
|
||||||
public class Ghoul extends FlyingUnit{
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package io.anuke.mindustry.entities.units.types;
|
|
||||||
|
|
||||||
public class Phantom extends Drone{
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package io.anuke.mindustry.entities.units.types;
|
|
||||||
|
|
||||||
import io.anuke.mindustry.entities.units.FlyingUnit;
|
|
||||||
|
|
||||||
public class Revenant extends FlyingUnit{
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
package io.anuke.mindustry.entities.units.types;
|
|
||||||
|
|
||||||
public class Spirit extends Drone{
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package io.anuke.mindustry.entities.units.types;
|
|
||||||
|
|
||||||
import io.anuke.mindustry.entities.units.GroundUnit;
|
|
||||||
|
|
||||||
public class Titan extends GroundUnit{
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package io.anuke.mindustry.entities.units.types;
|
|
||||||
|
|
||||||
import io.anuke.mindustry.entities.units.FlyingUnit;
|
|
||||||
|
|
||||||
public class Wraith extends FlyingUnit{
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,7 @@ package io.anuke.mindustry.game;
|
|||||||
|
|
||||||
import io.anuke.arc.Events.Event;
|
import io.anuke.arc.Events.Event;
|
||||||
import io.anuke.mindustry.core.GameState.State;
|
import io.anuke.mindustry.core.GameState.State;
|
||||||
import io.anuke.mindustry.entities.Unit;
|
import io.anuke.mindustry.entities.type.Unit;
|
||||||
import io.anuke.mindustry.entities.traits.BuilderTrait;
|
import io.anuke.mindustry.entities.traits.BuilderTrait;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package io.anuke.mindustry.game;
|
package io.anuke.mindustry.game;
|
||||||
|
|
||||||
import io.anuke.mindustry.entities.units.BaseUnit;
|
import io.anuke.mindustry.entities.type.BaseUnit;
|
||||||
import io.anuke.mindustry.entities.units.GroundUnit;
|
import io.anuke.mindustry.entities.type.GroundUnit;
|
||||||
import io.anuke.mindustry.entities.units.UnitType;
|
import io.anuke.mindustry.type.UnitType;
|
||||||
import io.anuke.mindustry.type.ItemStack;
|
import io.anuke.mindustry.type.ItemStack;
|
||||||
import io.anuke.mindustry.type.StatusEffect;
|
import io.anuke.mindustry.type.StatusEffect;
|
||||||
import io.anuke.mindustry.type.Weapon;
|
import io.anuke.mindustry.type.Weapon;
|
||||||
@@ -66,7 +66,7 @@ public class SpawnGroup{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(items != null){
|
if(items != null){
|
||||||
unit.inventory.addItem(items.item, items.amount);
|
unit.addItem(items.item, items.amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
return unit;
|
return unit;
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import io.anuke.arc.Core;
|
|||||||
import io.anuke.arc.Events;
|
import io.anuke.arc.Events;
|
||||||
import io.anuke.arc.collection.Array;
|
import io.anuke.arc.collection.Array;
|
||||||
import io.anuke.arc.collection.Sort;
|
import io.anuke.arc.collection.Sort;
|
||||||
import io.anuke.arc.entities.EntityDraw;
|
import io.anuke.mindustry.entities.EntityDraw;
|
||||||
import io.anuke.arc.entities.EntityGroup;
|
import io.anuke.mindustry.entities.EntityGroup;
|
||||||
import io.anuke.arc.graphics.Color;
|
import io.anuke.arc.graphics.Color;
|
||||||
import io.anuke.arc.graphics.Texture.TextureFilter;
|
import io.anuke.arc.graphics.Texture.TextureFilter;
|
||||||
import io.anuke.arc.graphics.g2d.Draw;
|
import io.anuke.arc.graphics.g2d.Draw;
|
||||||
@@ -13,7 +13,7 @@ import io.anuke.arc.graphics.g2d.Fill;
|
|||||||
import io.anuke.arc.graphics.glutils.FrameBuffer;
|
import io.anuke.arc.graphics.glutils.FrameBuffer;
|
||||||
import io.anuke.arc.util.Tmp;
|
import io.anuke.arc.util.Tmp;
|
||||||
import io.anuke.mindustry.content.Blocks;
|
import io.anuke.mindustry.content.Blocks;
|
||||||
import io.anuke.mindustry.entities.Unit;
|
import io.anuke.mindustry.entities.type.Unit;
|
||||||
import io.anuke.mindustry.game.EventType.TileChangeEvent;
|
import io.anuke.mindustry.game.EventType.TileChangeEvent;
|
||||||
import io.anuke.mindustry.game.EventType.WorldLoadEvent;
|
import io.anuke.mindustry.game.EventType.WorldLoadEvent;
|
||||||
import io.anuke.mindustry.game.Team;
|
import io.anuke.mindustry.game.Team;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import io.anuke.arc.graphics.g2d.TextureRegion;
|
|||||||
import io.anuke.arc.math.Mathf;
|
import io.anuke.arc.math.Mathf;
|
||||||
import io.anuke.arc.math.geom.Rectangle;
|
import io.anuke.arc.math.geom.Rectangle;
|
||||||
import io.anuke.arc.util.Disposable;
|
import io.anuke.arc.util.Disposable;
|
||||||
import io.anuke.mindustry.entities.Unit;
|
import io.anuke.mindustry.entities.type.Unit;
|
||||||
import io.anuke.mindustry.entities.Units;
|
import io.anuke.mindustry.entities.Units;
|
||||||
import io.anuke.mindustry.game.EventType.TileChangeEvent;
|
import io.anuke.mindustry.game.EventType.TileChangeEvent;
|
||||||
import io.anuke.mindustry.game.EventType.WorldLoadEvent;
|
import io.anuke.mindustry.game.EventType.WorldLoadEvent;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import io.anuke.arc.math.geom.Vector2;
|
|||||||
import io.anuke.arc.util.Time;
|
import io.anuke.arc.util.Time;
|
||||||
import io.anuke.arc.util.Tmp;
|
import io.anuke.arc.util.Tmp;
|
||||||
import io.anuke.mindustry.content.Blocks;
|
import io.anuke.mindustry.content.Blocks;
|
||||||
import io.anuke.mindustry.entities.Player;
|
import io.anuke.mindustry.entities.type.Player;
|
||||||
import io.anuke.mindustry.game.Team;
|
import io.anuke.mindustry.game.Team;
|
||||||
import io.anuke.mindustry.input.InputHandler;
|
import io.anuke.mindustry.input.InputHandler;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
@@ -102,14 +102,14 @@ public class OverlayRenderer{
|
|||||||
if(input.isDroppingItem()){
|
if(input.isDroppingItem()){
|
||||||
Vector2 v = Core.input.mouseWorld(input.getMouseX(), input.getMouseY());
|
Vector2 v = Core.input.mouseWorld(input.getMouseX(), input.getMouseY());
|
||||||
float size = 8;
|
float size = 8;
|
||||||
Draw.rect(player.inventory.getItem().item.region, v.x, v.y, size, size);
|
Draw.rect(player.item().item.region, v.x, v.y, size, size);
|
||||||
Draw.color(Palette.accent);
|
Draw.color(Palette.accent);
|
||||||
Lines.circle(v.x, v.y, 6 + Mathf.absin(Time.time(), 5f, 1f));
|
Lines.circle(v.x, v.y, 6 + Mathf.absin(Time.time(), 5f, 1f));
|
||||||
Draw.reset();
|
Draw.reset();
|
||||||
|
|
||||||
Tile tile = world.tileWorld(v.x, v.y);
|
Tile tile = world.tileWorld(v.x, v.y);
|
||||||
if(tile != null) tile = tile.target();
|
if(tile != null) tile = tile.target();
|
||||||
if(tile != null && tile.getTeam() == player.getTeam() && tile.block().acceptStack(player.inventory.getItem().item, player.inventory.getItem().amount, tile, player) > 0){
|
if(tile != null && tile.getTeam() == player.getTeam() && tile.block().acceptStack(player.item().item, player.item().amount, tile, player) > 0){
|
||||||
Draw.color(Palette.place);
|
Draw.color(Palette.place);
|
||||||
Lines.square(tile.drawx(), tile.drawy(), tile.block().size * tilesize / 2f + 1 + Mathf.absin(Time.time(), 5f, 1f));
|
Lines.square(tile.drawx(), tile.drawy(), tile.block().size * tilesize / 2f + 1 + Mathf.absin(Time.time(), 5f, 1f));
|
||||||
Draw.color();
|
Draw.color();
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import io.anuke.arc.graphics.g2d.TextureRegion;
|
|||||||
import io.anuke.arc.math.Mathf;
|
import io.anuke.arc.math.Mathf;
|
||||||
import io.anuke.mindustry.content.Blocks;
|
import io.anuke.mindustry.content.Blocks;
|
||||||
import io.anuke.mindustry.core.GameState.State;
|
import io.anuke.mindustry.core.GameState.State;
|
||||||
import io.anuke.mindustry.entities.Player;
|
import io.anuke.mindustry.entities.type.Player;
|
||||||
import io.anuke.mindustry.graphics.Palette;
|
import io.anuke.mindustry.graphics.Palette;
|
||||||
import io.anuke.mindustry.input.PlaceUtils.NormalizeDrawResult;
|
import io.anuke.mindustry.input.PlaceUtils.NormalizeDrawResult;
|
||||||
import io.anuke.mindustry.input.PlaceUtils.NormalizeResult;
|
import io.anuke.mindustry.input.PlaceUtils.NormalizeResult;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package io.anuke.mindustry.input;
|
|||||||
import io.anuke.annotations.Annotations.Loc;
|
import io.anuke.annotations.Annotations.Loc;
|
||||||
import io.anuke.annotations.Annotations.Remote;
|
import io.anuke.annotations.Annotations.Remote;
|
||||||
import io.anuke.arc.Core;
|
import io.anuke.arc.Core;
|
||||||
import io.anuke.arc.entities.Effects;
|
import io.anuke.mindustry.entities.Effects;
|
||||||
import io.anuke.arc.graphics.Color;
|
import io.anuke.arc.graphics.Color;
|
||||||
import io.anuke.arc.input.InputProcessor;
|
import io.anuke.arc.input.InputProcessor;
|
||||||
import io.anuke.arc.math.Angles;
|
import io.anuke.arc.math.Angles;
|
||||||
@@ -13,7 +13,7 @@ import io.anuke.arc.scene.ui.layout.Table;
|
|||||||
import io.anuke.arc.util.Time;
|
import io.anuke.arc.util.Time;
|
||||||
import io.anuke.mindustry.content.Blocks;
|
import io.anuke.mindustry.content.Blocks;
|
||||||
import io.anuke.mindustry.content.Fx;
|
import io.anuke.mindustry.content.Fx;
|
||||||
import io.anuke.mindustry.entities.Player;
|
import io.anuke.mindustry.entities.type.Player;
|
||||||
import io.anuke.mindustry.entities.effect.ItemTransfer;
|
import io.anuke.mindustry.entities.effect.ItemTransfer;
|
||||||
import io.anuke.mindustry.entities.traits.BuilderTrait.BuildRequest;
|
import io.anuke.mindustry.entities.traits.BuilderTrait.BuildRequest;
|
||||||
import io.anuke.mindustry.game.Team;
|
import io.anuke.mindustry.game.Team;
|
||||||
@@ -53,17 +53,17 @@ public abstract class InputHandler implements InputProcessor{
|
|||||||
|
|
||||||
@Remote(targets = Loc.client, called = Loc.server)
|
@Remote(targets = Loc.client, called = Loc.server)
|
||||||
public static void dropItem(Player player, float angle){
|
public static void dropItem(Player player, float angle){
|
||||||
if(Net.server() && !player.inventory.hasItem()){
|
if(Net.server() && player.item().amount <= 0){
|
||||||
throw new ValidateException(player, "Player cannot drop an item.");
|
throw new ValidateException(player, "Player cannot drop an item.");
|
||||||
}
|
}
|
||||||
|
|
||||||
Effects.effect(Fx.dropItem, Color.WHITE, player.x, player.y, angle, player.inventory.getItem().item);
|
Effects.effect(Fx.dropItem, Color.WHITE, player.x, player.y, angle, player.item().item);
|
||||||
player.inventory.clearItem();
|
player.clearItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Remote(targets = Loc.both, forward = true, called = Loc.server)
|
@Remote(targets = Loc.both, forward = true, called = Loc.server)
|
||||||
public static void transferInventory(Player player, Tile tile){
|
public static void transferInventory(Player player, Tile tile){
|
||||||
if(Net.server() && (!player.inventory.hasItem() || player.isTransferring)){
|
if(Net.server() && (player.item().amount <= 0 || player.isTransferring)){
|
||||||
throw new ValidateException(player, "Player cannot transfer an item.");
|
throw new ValidateException(player, "Player cannot transfer an item.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,10 +71,10 @@ public abstract class InputHandler implements InputProcessor{
|
|||||||
|
|
||||||
player.isTransferring = true;
|
player.isTransferring = true;
|
||||||
|
|
||||||
Item item = player.inventory.getItem().item;
|
Item item = player.item().item;
|
||||||
int amount = player.inventory.getItem().amount;
|
int amount = player.item().amount;
|
||||||
int accepted = tile.block().acceptStack(item, amount, tile, player);
|
int accepted = tile.block().acceptStack(item, amount, tile, player);
|
||||||
player.inventory.getItem().amount -= accepted;
|
player.item().amount -= accepted;
|
||||||
|
|
||||||
int sent = Mathf.clamp(accepted / 4, 1, 8);
|
int sent = Mathf.clamp(accepted / 4, 1, 8);
|
||||||
int removed = accepted / sent;
|
int removed = accepted / sent;
|
||||||
@@ -216,7 +216,7 @@ public abstract class InputHandler implements InputProcessor{
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean canTapPlayer(float x, float y){
|
boolean canTapPlayer(float x, float y){
|
||||||
return Mathf.dst(x, y, player.x, player.y) <= playerSelectRange && player.inventory.hasItem();
|
return Mathf.dst(x, y, player.x, player.y) <= playerSelectRange && player.item().amount > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**Tries to begin mining a tile, returns true if successful.*/
|
/**Tries to begin mining a tile, returns true if successful.*/
|
||||||
@@ -233,7 +233,7 @@ public abstract class InputHandler implements InputProcessor{
|
|||||||
return !Core.scene.hasMouse()
|
return !Core.scene.hasMouse()
|
||||||
&& tile.floor().itemDrop != null && tile.floor().itemDrop.hardness <= player.mech.drillPower
|
&& tile.floor().itemDrop != null && tile.floor().itemDrop.hardness <= player.mech.drillPower
|
||||||
&& !tile.floor().playerUnmineable
|
&& !tile.floor().playerUnmineable
|
||||||
&& player.inventory.canAcceptItem(tile.floor().itemDrop)
|
&& player.acceptsItem(tile.floor().itemDrop)
|
||||||
&& tile.block() == Blocks.air && player.dst(tile.worldx(), tile.worldy()) <= Player.mineDistance;
|
&& tile.block() == Blocks.air && player.dst(tile.worldx(), tile.worldy()) <= Player.mineDistance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -288,14 +288,14 @@ public abstract class InputHandler implements InputProcessor{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void tryDropItems(Tile tile, float x, float y){
|
public void tryDropItems(Tile tile, float x, float y){
|
||||||
if(!droppingItem || !player.inventory.hasItem() || canTapPlayer(x, y)){
|
if(!droppingItem || player.item().amount <= 0 || canTapPlayer(x, y)){
|
||||||
droppingItem = false;
|
droppingItem = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
droppingItem = false;
|
droppingItem = false;
|
||||||
|
|
||||||
ItemStack stack = player.inventory.getItem();
|
ItemStack stack = player.item();
|
||||||
|
|
||||||
if(tile.block().acceptStack(stack.item, stack.amount, tile, player) > 0 && tile.getTeam() == player.getTeam() && tile.block().hasItems){
|
if(tile.block().acceptStack(stack.item, stack.amount, tile, player) > 0 && tile.getTeam() == player.getTeam() && tile.block().hasItems){
|
||||||
Call.transferInventory(player, tile);
|
Call.transferInventory(player, tile);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package io.anuke.mindustry.input;
|
|||||||
import io.anuke.arc.Core;
|
import io.anuke.arc.Core;
|
||||||
import io.anuke.arc.collection.Array;
|
import io.anuke.arc.collection.Array;
|
||||||
import io.anuke.arc.collection.ObjectSet;
|
import io.anuke.arc.collection.ObjectSet;
|
||||||
import io.anuke.arc.entities.Effects;
|
import io.anuke.mindustry.entities.Effects;
|
||||||
import io.anuke.arc.graphics.Color;
|
import io.anuke.arc.graphics.Color;
|
||||||
import io.anuke.arc.graphics.g2d.Draw;
|
import io.anuke.arc.graphics.g2d.Draw;
|
||||||
import io.anuke.arc.graphics.g2d.Lines;
|
import io.anuke.arc.graphics.g2d.Lines;
|
||||||
@@ -21,9 +21,9 @@ import io.anuke.arc.util.Time;
|
|||||||
import io.anuke.mindustry.content.Blocks;
|
import io.anuke.mindustry.content.Blocks;
|
||||||
import io.anuke.mindustry.content.Fx;
|
import io.anuke.mindustry.content.Fx;
|
||||||
import io.anuke.mindustry.core.GameState.State;
|
import io.anuke.mindustry.core.GameState.State;
|
||||||
import io.anuke.mindustry.entities.Player;
|
import io.anuke.mindustry.entities.type.Player;
|
||||||
import io.anuke.mindustry.entities.TileEntity;
|
import io.anuke.mindustry.entities.type.TileEntity;
|
||||||
import io.anuke.mindustry.entities.Unit;
|
import io.anuke.mindustry.entities.type.Unit;
|
||||||
import io.anuke.mindustry.entities.Units;
|
import io.anuke.mindustry.entities.Units;
|
||||||
import io.anuke.mindustry.entities.traits.TargetTrait;
|
import io.anuke.mindustry.entities.traits.TargetTrait;
|
||||||
import io.anuke.mindustry.graphics.Palette;
|
import io.anuke.mindustry.graphics.Palette;
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user