Skip to content

Commit

Permalink
Add initialization, fix build radius checks
Browse files Browse the repository at this point in the history
  • Loading branch information
BasedUser committed Jan 14, 2024
1 parent 2ff8d82 commit fb535a9
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
2 changes: 1 addition & 1 deletion core/src/mindustry/entities/bullet/BulletType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 17 additions & 2 deletions core/src/mindustry/game/Team.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public class Team implements Comparable<Team>{
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){
Expand Down Expand Up @@ -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;
Expand Down
25 changes: 25 additions & 0 deletions core/src/mindustry/game/Teams.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)){
Expand All @@ -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<Building> ret){
for(TeamData data : active){
if(team.isEnemy(data.team)){
Expand All @@ -78,6 +93,16 @@ public void eachEnemyCore(Team team, Cons<Building> ret){
}
}

public void eachRadiusCore(Team team, Cons<Building> 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];
Expand Down
2 changes: 1 addition & 1 deletion core/src/mindustry/graphics/OverlayRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit fb535a9

Please sign in to comment.