argh
This commit is contained in:
@@ -12,12 +12,12 @@ import static mindustry.Vars.*;
|
||||
/** Utility class for unit and team interactions.*/
|
||||
public class Units{
|
||||
private static Rect hitrect = new Rect();
|
||||
private static Unitc result;
|
||||
private static Unit result;
|
||||
private static float cdist;
|
||||
private static boolean boolResult;
|
||||
|
||||
@Remote(called = Loc.server)
|
||||
public static void onUnitDeath(Unitc unit){
|
||||
public static void onUnitDeath(Unit unit){
|
||||
unit.killed();
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public class Units{
|
||||
}
|
||||
|
||||
/** @return whether this player can interact with a specific tile. if either of these are null, returns true.*/
|
||||
public static boolean canInteract(Playerc player, Tilec tile){
|
||||
public static boolean canInteract(Player player, Building tile){
|
||||
return player == null || tile == null || tile.interactable(player.team());
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ public class Units{
|
||||
}
|
||||
|
||||
/** See {@link #invalidateTarget(Posc, Team, float, float, float)} */
|
||||
public static boolean invalidateTarget(Teamc target, Unitc targeter, float range){
|
||||
public static boolean invalidateTarget(Teamc target, Unit targeter, float range){
|
||||
return invalidateTarget(target, targeter.team(), targeter.x(), targeter.y(), range);
|
||||
}
|
||||
|
||||
@@ -91,18 +91,18 @@ public class Units{
|
||||
}
|
||||
|
||||
/** Returns the neareset damaged tile. */
|
||||
public static Tilec findDamagedTile(Team team, float x, float y){
|
||||
public static Building findDamagedTile(Team team, float x, float y){
|
||||
Tile tile = Geometry.findClosest(x, y, indexer.getDamaged(team));
|
||||
return tile == null ? null : tile.entity;
|
||||
}
|
||||
|
||||
/** Returns the neareset ally tile in a range. */
|
||||
public static Tilec findAllyTile(Team team, float x, float y, float range, Boolf<Tilec> pred){
|
||||
public static Building findAllyTile(Team team, float x, float y, float range, Boolf<Building> pred){
|
||||
return indexer.findTile(team, x, y, range, pred);
|
||||
}
|
||||
|
||||
/** Returns the neareset enemy tile in a range. */
|
||||
public static Tilec findEnemyTile(Team team, float x, float y, float range, Boolf<Tilec> pred){
|
||||
public static Building findEnemyTile(Team team, float x, float y, float range, Boolf<Building> pred){
|
||||
if(team == Team.derelict) return null;
|
||||
|
||||
return indexer.findEnemyTile(team, x, y, range, pred);
|
||||
@@ -110,19 +110,19 @@ public class Units{
|
||||
|
||||
/** Returns the closest target enemy. First, units are checked, then tile entities. */
|
||||
public static Teamc closestTarget(Team team, float x, float y, float range){
|
||||
return closestTarget(team, x, y, range, Unitc::isValid);
|
||||
return closestTarget(team, x, y, range, Unit::isValid);
|
||||
}
|
||||
|
||||
/** Returns the closest target enemy. First, units are checked, then tile entities. */
|
||||
public static Teamc closestTarget(Team team, float x, float y, float range, Boolf<Unitc> unitPred){
|
||||
public static Teamc closestTarget(Team team, float x, float y, float range, Boolf<Unit> unitPred){
|
||||
return closestTarget(team, x, y, range, unitPred, t -> true);
|
||||
}
|
||||
|
||||
/** Returns the closest target enemy. First, units are checked, then tile entities. */
|
||||
public static Teamc closestTarget(Team team, float x, float y, float range, Boolf<Unitc> unitPred, Boolf<Tilec> tilePred){
|
||||
public static Teamc closestTarget(Team team, float x, float y, float range, Boolf<Unit> unitPred, Boolf<Building> tilePred){
|
||||
if(team == Team.derelict) return null;
|
||||
|
||||
Unitc unit = closestEnemy(team, x, y, range, unitPred);
|
||||
Unit unit = closestEnemy(team, x, y, range, unitPred);
|
||||
if(unit != null){
|
||||
return unit;
|
||||
}else{
|
||||
@@ -131,7 +131,7 @@ public class Units{
|
||||
}
|
||||
|
||||
/** Returns the closest enemy of this team. Filter by predicate. */
|
||||
public static Unitc closestEnemy(Team team, float x, float y, float range, Boolf<Unitc> predicate){
|
||||
public static Unit closestEnemy(Team team, float x, float y, float range, Boolf<Unit> predicate){
|
||||
if(team == Team.derelict) return null;
|
||||
|
||||
result = null;
|
||||
@@ -151,11 +151,11 @@ public class Units{
|
||||
}
|
||||
|
||||
/** 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){
|
||||
public static Unit closest(Team team, float x, float y, Boolf<Unit> predicate){
|
||||
result = null;
|
||||
cdist = 0f;
|
||||
|
||||
for(Unitc e : Groups.unit){
|
||||
for(Unit e : Groups.unit){
|
||||
if(!predicate.get(e) || e.team() != team) continue;
|
||||
|
||||
float dist = e.dst2(x, y);
|
||||
@@ -169,7 +169,7 @@ public class Units{
|
||||
}
|
||||
|
||||
/** 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){
|
||||
public static Unit closest(Team team, float x, float y, float range, Boolf<Unit> predicate){
|
||||
result = null;
|
||||
cdist = 0f;
|
||||
|
||||
@@ -188,7 +188,7 @@ public class Units{
|
||||
|
||||
/** Returns the closest ally of this team. Filter by predicate.
|
||||
* Unlike the closest() function, this only guarantees that unit hitboxes overlap the range. */
|
||||
public static Unitc closestOverlap(Team team, float x, float y, float range, Boolf<Unitc> predicate){
|
||||
public static Unit closestOverlap(Team team, float x, float y, float range, Boolf<Unit> predicate){
|
||||
result = null;
|
||||
cdist = 0f;
|
||||
|
||||
@@ -206,12 +206,12 @@ public class Units{
|
||||
}
|
||||
|
||||
/** Iterates over all units in a rectangle. */
|
||||
public static void nearby(Team team, float x, float y, float width, float height, Cons<Unitc> cons){
|
||||
public static void nearby(Team team, float x, float y, float width, float height, Cons<Unit> cons){
|
||||
teamIndex.tree(team).intersect(x, y, width, height, cons);
|
||||
}
|
||||
|
||||
/** Iterates over all units in a circle around this position. */
|
||||
public static void nearby(Team team, float x, float y, float radius, Cons<Unitc> cons){
|
||||
public static void nearby(Team team, float x, float y, float radius, Cons<Unit> cons){
|
||||
nearby(team, x - radius, y - radius, radius*2f, radius*2f, unit -> {
|
||||
if(unit.within(x, y, radius)){
|
||||
cons.get(unit);
|
||||
@@ -220,24 +220,24 @@ public class Units{
|
||||
}
|
||||
|
||||
/** Iterates over all units in a rectangle. */
|
||||
public static void nearby(float x, float y, float width, float height, Cons<Unitc> cons){
|
||||
public static void nearby(float x, float y, float width, float height, Cons<Unit> cons){
|
||||
Groups.unit.intersect(x, y, width, height, cons);
|
||||
}
|
||||
|
||||
/** Iterates over all units in a rectangle. */
|
||||
public static void nearby(Rect rect, Cons<Unitc> cons){
|
||||
public static void nearby(Rect rect, Cons<Unit> cons){
|
||||
nearby(rect.x, rect.y, rect.width, rect.height, cons);
|
||||
}
|
||||
|
||||
/** Iterates over all units that are enemies of this team. */
|
||||
public static void nearbyEnemies(Team team, float x, float y, float width, float height, Cons<Unitc> cons){
|
||||
public static void nearbyEnemies(Team team, float x, float y, float width, float height, Cons<Unit> cons){
|
||||
for(Team enemy : state.teams.enemiesOf(team)){
|
||||
nearby(enemy, x, y, width, height, cons);
|
||||
}
|
||||
}
|
||||
|
||||
/** Iterates over all units that are enemies of this team. */
|
||||
public static void nearbyEnemies(Team team, Rect rect, Cons<Unitc> cons){
|
||||
public static void nearbyEnemies(Team team, Rect rect, Cons<Unit> cons){
|
||||
nearbyEnemies(team, rect.x, rect.y, rect.width, rect.height, cons);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user