From 405d6cf33ffdd051c9a9289847f29b7ce0a124ed Mon Sep 17 00:00:00 2001 From: Anuken Date: Mon, 15 Jun 2020 15:33:14 -0400 Subject: [PATCH] Per-team infinite building resources --- core/src/mindustry/entities/comp/BuilderComp.java | 8 +++++--- core/src/mindustry/game/Rules.java | 2 +- core/src/mindustry/world/blocks/BuildBlock.java | 4 ++-- gradle.properties | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/core/src/mindustry/entities/comp/BuilderComp.java b/core/src/mindustry/entities/comp/BuilderComp.java index b90fb18472..f68d22a8eb 100644 --- a/core/src/mindustry/entities/comp/BuilderComp.java +++ b/core/src/mindustry/entities/comp/BuilderComp.java @@ -44,6 +44,8 @@ abstract class BuilderComp implements Unitc{ float finalPlaceDst = state.rules.infiniteResources ? Float.MAX_VALUE : buildingRange; + boolean infinite = state.rules.infiniteResources || team().rules().infiniteResources; + Iterator it = plans.iterator(); while(it.hasNext()){ BuildPlan req = it.next(); @@ -83,7 +85,7 @@ abstract class BuilderComp implements Unitc{ if(!current.initialized && !current.breaking && Build.validPlace(current.block, team(), current.x, current.y, current.rotation)){ boolean hasAll = !Structs.contains(current.block.requirements, i -> !core.items().has(i.item)); - if(hasAll || state.rules.infiniteResources){ + if(hasAll || infinite){ Build.beginPlace(current.block, team(), current.x, current.y, current.rotation); }else{ current.stuck = true; @@ -105,7 +107,7 @@ abstract class BuilderComp implements Unitc{ } //if there is no core to build with or no build entity, stop building! - if((core == null && !state.rules.infiniteResources) || !(tile.entity instanceof BuildEntity)){ + if((core == null && !infinite) || !(tile.entity instanceof BuildEntity)){ return; } @@ -148,7 +150,7 @@ abstract class BuilderComp implements Unitc{ /** @return whether this request should be skipped, in favor of the next one. */ boolean shouldSkip(BuildPlan request, @Nullable Tilec core){ //requests that you have at least *started* are considered - if(state.rules.infiniteResources || request.breaking || core == null) return false; + if(state.rules.infiniteResources || team().rules().infiniteResources || request.breaking || core == null) return false; //TODO these are bad criteria return (request.stuck && !core.items().has(request.block.requirements)) || (Structs.contains(request.block.requirements, i -> !core.items().has(i.item)) && !request.initialized); } diff --git a/core/src/mindustry/game/Rules.java b/core/src/mindustry/game/Rules.java index eea56a5c65..e318e4e066 100644 --- a/core/src/mindustry/game/Rules.java +++ b/core/src/mindustry/game/Rules.java @@ -16,7 +16,7 @@ import mindustry.world.*; * Does not store game state, just configuration. */ public class Rules{ - /** Whether every team has infinite resources and instant build speed. */ + /** Sandbox mode: Enables infinite resources, build range and build speed. */ public boolean infiniteResources; /** Team-specific rules. */ public TeamRules teams = new TeamRules(); diff --git a/core/src/mindustry/world/blocks/BuildBlock.java b/core/src/mindustry/world/blocks/BuildBlock.java index 7cf9dd889f..6ff80cee2f 100644 --- a/core/src/mindustry/world/blocks/BuildBlock.java +++ b/core/src/mindustry/world/blocks/BuildBlock.java @@ -200,7 +200,7 @@ public class BuildBlock extends Block{ setConstruct(previous, cblock); } - float maxProgress = core == null ? amount : checkRequired(core.items(), amount, false); + float maxProgress = core == null || team.rules().infiniteResources ? amount : checkRequired(core.items(), amount, false); for(int i = 0; i < cblock.requirements.length; i++){ int reqamount = Math.round(state.rules.buildCostMultiplier * cblock.requirements[i].amount); @@ -208,7 +208,7 @@ public class BuildBlock extends Block{ totalAccumulator[i] = Math.min(totalAccumulator[i] + reqamount * maxProgress, reqamount); } - maxProgress = core == null ? maxProgress : checkRequired(core.items(), maxProgress, true); + maxProgress = core == null || team.rules().infiniteResources ? maxProgress : checkRequired(core.items(), maxProgress, true); progress = Mathf.clamp(progress + maxProgress); builderID = builder.id(); diff --git a/gradle.properties b/gradle.properties index 6250d21a17..669ca931d4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ org.gradle.daemon=true org.gradle.jvmargs=-Xms256m -Xmx1024m -archash=5c3e9ec21d1b541f3b0e6ecde5f4d468b92efc25 +archash=8560f9a35cde90ef4e0fd600419e5761ae51494a