Skip to content

Commit a1b47b1

Browse files
per-team toggles for core no-build radius / placement range check (#11448)
* per-team toggles for core no-build radius / placement range check * oops * fair enough
1 parent 85b69d3 commit a1b47b1

File tree

7 files changed

+39
-11
lines changed

7 files changed

+39
-11
lines changed

core/assets/bundles/bundle.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,6 +1474,10 @@ rules.cleanupdeadteams = Clean Up Defeated Team Buildings (PvP)
14741474
rules.corecapture = Capture Core On Destruction
14751475
rules.polygoncoreprotection = Polygonal Core Protection
14761476
rules.placerangecheck = Placement Range Check
1477+
rules.protectcores = Protect Cores
1478+
rules.protectcores.info = When disabled, the core no-build radius won't affect this team.\nPlayers won't be assigned to unprotected teams.
1479+
rules.checkplacement = Check Placement
1480+
rules.checkplacement.info = When disabled, buildings of this team are ignored in placement range checks.
14771481
rules.enemyCheat = Infinite Enemy Team Resources
14781482
rules.blockhealthmultiplier = Block Health Multiplier
14791483
rules.blockdamagemultiplier = Block Damage Multiplier

core/src/mindustry/core/NetServer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class NetServer implements ApplicationListener{
5252
if(state.rules.pvp){
5353
//find team with minimum amount of players and auto-assign player to that.
5454
TeamData re = state.teams.getActive().min(data -> {
55-
if((state.rules.waveTeam == data.team && state.rules.waves) || !data.hasCore() || data.team == Team.derelict) return Integer.MAX_VALUE;
55+
if((state.rules.waveTeam == data.team && state.rules.waves) || !data.hasCore() || data.team == Team.derelict || !data.team.rules().protectCores) return Integer.MAX_VALUE;
5656

5757
int count = 0;
5858
for(Player other : players){

core/src/mindustry/game/Rules.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public boolean hasEnv(int env){
248248
}
249249

250250
public float buildRadius(Team team){
251-
return enemyCoreBuildRadius + teams.get(team).extraCoreBuildRadius;
251+
return !teams.get(team).protectCores ? 0f : enemyCoreBuildRadius + teams.get(team).extraCoreBuildRadius;
252252
}
253253

254254
public float unitBuildSpeed(Team team){
@@ -299,6 +299,10 @@ public boolean isBanned(UnitType unit){
299299
public static class TeamRule{
300300
/** Whether, when AI is enabled, ships should be spawned from the core. TODO remove / unnecessary? */
301301
public boolean aiCoreSpawn = true;
302+
/** Whether the core no-build radius/polygonal protection applies to this team, unprotected teams are ignored by team assigner */
303+
public boolean protectCores = true;
304+
/** Whether the placeRangeCheck applies to this team */
305+
public boolean checkPlacement = true;
302306
/** If true, blocks don't require power or resources. */
303307
public boolean cheat;
304308
/** If true, the core is always filled to capacity with all items. */
@@ -345,8 +349,18 @@ public static class TeamRule{
345349
/** Extra spacing added to the no-build zone around the core. */
346350
public float extraCoreBuildRadius = 0f;
347351

348-
349352
//build cost disabled due to technical complexity
353+
354+
//for reading from json
355+
public TeamRule(){
356+
}
357+
358+
public TeamRule(Team team){
359+
if(team == Team.derelict){
360+
protectCores = false;
361+
checkPlacement = false;
362+
}
363+
}
350364
}
351365

352366
/** A simple map for storing TeamRules in an efficient way without hashing. */
@@ -355,7 +369,7 @@ public static class TeamRules implements JsonSerializable{
355369

356370
public TeamRule get(Team team){
357371
TeamRule out = values[team.id];
358-
return out == null ? (values[team.id] = new TeamRule()) : out;
372+
return out == null ? (values[team.id] = new TeamRule(team)) : out;
359373
}
360374

361375
@Override

core/src/mindustry/game/Teams.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public CoreBuild closestCore(float x, float y, Team team){
5858

5959
public boolean anyEnemyCoresWithinBuildRadius(Team team, float x, float y){
6060
for(TeamData data : active){
61-
if(team != data.team){
61+
if(team != data.team && data.team.rules().protectCores){
6262
for(CoreBuild tile : data.cores){
6363
if(tile.within(x, y, state.rules.buildRadius(tile.team) + tilesize)){
6464
return true;
@@ -71,7 +71,7 @@ public boolean anyEnemyCoresWithinBuildRadius(Team team, float x, float y){
7171

7272
public boolean anyEnemyCoresWithin(Team team, float x, float y, float radius){
7373
for(TeamData data : active){
74-
if(team != data.team){
74+
if(team != data.team && data.team.rules().protectCores){
7575
for(CoreBuild tile : data.cores){
7676
if(tile.within(x, y, radius)){
7777
return true;

core/src/mindustry/graphics/OverlayRenderer.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,12 @@ private void updateCoreEdges(){
5050

5151
Seq<Vec2> pos = new Seq<>();
5252
Seq<CoreBuild> teams = new Seq<>();
53-
for(TeamData team : state.teams.active){
54-
for(CoreBuild b : team.cores){
53+
for(TeamData data : state.teams.active){
54+
if(!data.team.rules().protectCores){
55+
continue;
56+
}
57+
58+
for(CoreBuild b : data.cores){
5559
teams.add(b);
5660
pos.add(new Vec2(b.x, b.y));
5761
}
@@ -179,7 +183,7 @@ public void drawTop(){
179183
state.teams.eachEnemyCore(player.team(), core -> {
180184
//it must be clear that there is a core here.
181185
float br = state.rules.buildRadius(core.team);
182-
if(/*core.wasVisible && */Core.camera.bounds(Tmp.r1).overlaps(Tmp.r2.setCentered(core.x, core.y, br * 2f))){
186+
if(/*core.wasVisible && */br > 0f && Core.camera.bounds(Tmp.r1).overlaps(Tmp.r2.setCentered(core.x, core.y, br * 2f))){
183187
Draw.color(Color.darkGray);
184188
Lines.circle(core.x, core.y - 2,br);
185189
Draw.color(Pal.accent, core.team.color, 0.5f + Mathf.absin(Time.time, 10f, 0.5f));

core/src/mindustry/ui/dialogs/CustomRulesDialog.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,9 @@ void setupMain(){
309309
check("@rules.buildai", b -> teams.buildAi = b, () -> teams.buildAi, () -> team != rules.defaultTeam && rules.env != Planets.erekir.defaultEnv && !rules.pvp);
310310
number("@rules.buildaitier", false, f -> teams.buildAiTier = f, () -> teams.buildAiTier, () -> teams.buildAi && rules.env != Planets.erekir.defaultEnv && !rules.pvp, 0, 1);
311311

312-
number("@rules.extracorebuildradius", f -> teams.extraCoreBuildRadius = f * tilesize, () -> Math.min(teams.extraCoreBuildRadius / tilesize, 200), () -> !rules.polygonCoreProtection);
312+
check("@rules.protectcores", b -> teams.protectCores = b, () -> teams.protectCores);
313+
number("@rules.extracorebuildradius", f -> teams.extraCoreBuildRadius = f * tilesize, () -> Math.min(teams.extraCoreBuildRadius / tilesize, 200), () -> !rules.polygonCoreProtection && teams.protectCores);
314+
check("@rules.checkplacement", b -> teams.checkPlacement = b, () -> teams.checkPlacement);
313315

314316
check("@rules.infiniteresources", b -> teams.infiniteResources = b, () -> teams.infiniteResources);
315317
check("@rules.fillitems", b -> teams.fillItems = b, () -> teams.fillItems);

core/src/mindustry/world/Build.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ public static boolean validPlaceIgnoreUnits(Block type, Team team, int x, int y,
191191
float mindst = Float.MAX_VALUE;
192192
CoreBuild closest = null;
193193
for(TeamData data : state.teams.active){
194+
if(!data.team.rules().protectCores){
195+
continue;
196+
}
197+
194198
for(CoreBuild tile : data.cores){
195199
float dst = tile.dst2(x * tilesize + type.offset, y * tilesize + type.offset);
196200
if(dst < mindst){
@@ -265,7 +269,7 @@ public static boolean validPlaceIgnoreUnits(Block type, Team team, int x, int y,
265269
}
266270

267271
public static @Nullable Building getEnemyOverlap(Block block, Team team, int x, int y){
268-
return indexer.findEnemyTile(team, x * tilesize + block.size, y * tilesize + block.size, block.placeOverlapRange + 4f, p -> true);
272+
return indexer.findEnemyTile(team, x * tilesize + block.size, y * tilesize + block.size, block.placeOverlapRange + 4f, b -> b.team.rules().checkPlacement);
269273
}
270274

271275
public static boolean contactsGround(int x, int y, Block block){

0 commit comments

Comments
 (0)