Automatic assignment of entities
This commit is contained in:
@@ -6,37 +6,37 @@ import mindustry.gen.*;
|
||||
class AllDefs{
|
||||
|
||||
@GroupDef(value = Entityc.class, mapping = true)
|
||||
class all{
|
||||
class gall{
|
||||
|
||||
}
|
||||
|
||||
@GroupDef(value = Playerc.class, mapping = true)
|
||||
class player{
|
||||
class gplayer{
|
||||
|
||||
}
|
||||
|
||||
@GroupDef(value = Bulletc.class, spatial = true, collide = {unit.class})
|
||||
class bullet{
|
||||
@GroupDef(value = Bulletc.class, spatial = true, collide = {gunit.class})
|
||||
class gbullet{
|
||||
|
||||
}
|
||||
|
||||
@GroupDef(value = Unitc.class, spatial = true, collide = {unit.class}, mapping = true)
|
||||
class unit{
|
||||
@GroupDef(value = Unitc.class, spatial = true, collide = {gunit.class}, mapping = true)
|
||||
class gunit{
|
||||
|
||||
}
|
||||
|
||||
@GroupDef(Tilec.class)
|
||||
class tile{
|
||||
class gtile{
|
||||
|
||||
}
|
||||
|
||||
@GroupDef(value = Syncc.class, mapping = true)
|
||||
class sync{
|
||||
class gsync{
|
||||
|
||||
}
|
||||
|
||||
@GroupDef(Drawc.class)
|
||||
class draw{
|
||||
class gdraw{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,6 +126,24 @@ public class Units{
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Returns the closest ally of this team. Filter by predicate. No range. */
|
||||
public static Unitc closest(Team team, float x, float y, Boolf<Unitc> predicate){
|
||||
result = null;
|
||||
cdist = 0f;
|
||||
|
||||
for(Unitc e : Groups.unit){
|
||||
if(!predicate.get(e) || e.team() != team) continue;
|
||||
|
||||
float dist = e.dst2(x, y);
|
||||
if(result == null || dist < cdist){
|
||||
result = e;
|
||||
cdist = dist;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Returns the closest ally of this team. Filter by predicate. */
|
||||
public static Unitc closest(Team team, float x, float y, float range, Boolf<Unitc> predicate){
|
||||
result = null;
|
||||
|
||||
@@ -25,6 +25,8 @@ import static mindustry.Vars.*;
|
||||
@EntityDef(value = {Playerc.class}, serialize = false)
|
||||
@Component
|
||||
abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc, Drawc{
|
||||
static final float deathDelay = 30f;
|
||||
|
||||
@NonNull @ReadOnly Unitc unit = Nulls.unit;
|
||||
|
||||
@ReadOnly Team team = Team.sharded;
|
||||
@@ -33,6 +35,7 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc, Dra
|
||||
boolean admin, typing;
|
||||
Color color = new Color();
|
||||
float mouseX, mouseY;
|
||||
float deathTimer;
|
||||
|
||||
String lastText = "";
|
||||
float textFadeTime;
|
||||
@@ -76,8 +79,12 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc, Dra
|
||||
x(unit.x());
|
||||
y(unit.y());
|
||||
unit.team(team);
|
||||
deathTimer = 0;
|
||||
}else if(core != null){
|
||||
core.requestSpawn((Playerc)this);
|
||||
deathTimer += Time.delta();
|
||||
if(deathTimer >= deathDelay){
|
||||
core.requestSpawn((Playerc)this);
|
||||
}
|
||||
}
|
||||
|
||||
textFadeTime -= Time.delta() / (60 * 5);
|
||||
|
||||
Reference in New Issue
Block a user