diff --git a/core/src/mindustry/entities/bullet/BulletType.java b/core/src/mindustry/entities/bullet/BulletType.java index ff7f9062000d..87971f02701a 100644 --- a/core/src/mindustry/entities/bullet/BulletType.java +++ b/core/src/mindustry/entities/bullet/BulletType.java @@ -362,7 +362,7 @@ public boolean heals(){ } public boolean testCollision(Bullet bullet, Building tile){ - return !heals() || bullet.team.canDamage(bullet.team) || tile.healthf() < 1f; + return !heals() || bullet.team.canDamage(tile.team) || tile.healthf() < 1f; } /** If direct is false, this is an indirect hit and the tile was already damaged. diff --git a/core/src/mindustry/game/Team.java b/core/src/mindustry/game/Team.java index defc80d66222..8a828285559b 100644 --- a/core/src/mindustry/game/Team.java +++ b/core/src/mindustry/game/Team.java @@ -50,6 +50,11 @@ public class Team implements Comparable{ new Team(i, "team#" + i, Color.HSVtoRGB(360f * Mathf.random(), 100f * Mathf.random(0.4f, 1f), 100f * Mathf.random(0.6f, 1f), 1f)); } Mathf.rand.setSeed(new Rand().nextLong()); + //weakly initialize team flags + for(int i = 0; i < 256; i++){ + all[i].flags[0] = TeamFlags.derelictTarget; + all[i].flags[i] = TeamFlags.genericSelf; + } } public static Team get(int id){ @@ -126,13 +131,23 @@ public boolean needsFlowField(){ return isAI() && !rules().rtsAi; } - /** flag bindings */ + /** Reset all flags to their default values. **/ + public void initializeFlags(){ + for(int i = 0; i < 256; i++){ + for(int j = 1; j < 256; j++){ + all[i].flags[j] = TeamFlags.genericEnemy; + } + all[i].flags[0] = TeamFlags.derelictTarget; + all[i].flags[i] = TeamFlags.genericSelf; + } + } + + /** Flag binding methods. */ public boolean isEnemy(Team other){ if(other == null) return false; return (this.flags[other.id] & TeamFlags.isNeutral) == 0; } - /** used for rendering */ public boolean isAlly(Team other){ if(other == null) return false; return (this.flags[other.id] & TeamFlags.allyCheck) == TeamFlags.allyCheck; diff --git a/core/src/mindustry/game/Teams.java b/core/src/mindustry/game/Teams.java index c9767f6613db..38c81590b3f5 100644 --- a/core/src/mindustry/game/Teams.java +++ b/core/src/mindustry/game/Teams.java @@ -55,6 +55,7 @@ public CoreBuild closestCore(float x, float y, Team team){ return Geometry.findClosest(x, y, get(team).cores); } + //possibly deprecate: formerly only used in Build public boolean anyEnemyCoresWithin(Team team, float x, float y, float radius){ for(TeamData data : active){ if(team.isEnemy(data.team)){ @@ -68,6 +69,20 @@ public boolean anyEnemyCoresWithin(Team team, float x, float y, float radius){ return false; } + public boolean anyRadiusCoresWithin(Team team, float x, float y, float radius){ + for(TeamData data : active){ + if(!team.ignoresBuildRadius(data.team)){ + for(CoreBuild tile : data.cores){ + if(tile.within(x, y, radius)){ + return true; + } + } + } + } + return false; + } + + //possibly deprecate: formerly only used in OverlayRenderer public void eachEnemyCore(Team team, Cons ret){ for(TeamData data : active){ if(team.isEnemy(data.team)){ @@ -78,6 +93,16 @@ public void eachEnemyCore(Team team, Cons ret){ } } + public void eachRadiusCore(Team team, Cons ret){ + for(TeamData data : active){ + if(team.ignoresBuildRadius(data.team)){ + for(Building tile : data.cores){ + ret.get(tile); + } + } + } + } + /** Returns team data by type. */ public TeamData get(Team team){ return map[team.id] == null ? (map[team.id] = new TeamData(team)) : map[team.id]; diff --git a/core/src/mindustry/graphics/OverlayRenderer.java b/core/src/mindustry/graphics/OverlayRenderer.java index 1e360c3af2d9..24b290ea01a7 100644 --- a/core/src/mindustry/graphics/OverlayRenderer.java +++ b/core/src/mindustry/graphics/OverlayRenderer.java @@ -182,7 +182,7 @@ public void drawTop(){ Draw.color(); }else{ - state.teams.eachEnemyCore(player.team(), core -> { + state.teams.eachRadiusCore(player.team(), core -> { //it must be clear that there is a core here. if(/*core.wasVisible && */Core.camera.bounds(Tmp.r1).overlaps(Tmp.r2.setCentered(core.x, core.y, state.rules.enemyCoreBuildRadius * 2f))){ Draw.color(Color.darkGray);