From 631e4d9eefca8b94de4fc52e57387b2c2f4ffecf Mon Sep 17 00:00:00 2001 From: TranquillyUnpleasant <62061444+TranquillyUnpleasant@users.noreply.github.com> Date: Tue, 16 Feb 2021 06:15:56 +0500 Subject: [PATCH] Unit cap (#4689) * Add unit caps as a map setting. * Use int and add maximum and minimum handling. * Put a lower limit of 0 for unit cap --- core/assets/bundles/bundle.properties | 2 ++ core/src/mindustry/entities/Units.java | 2 +- core/src/mindustry/game/Rules.java | 2 ++ .../src/mindustry/ui/dialogs/CustomRulesDialog.java | 13 +++++++++++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index 357d5290cc..af0e18042c 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -957,6 +957,8 @@ rules.blockdamagemultiplier = Block Damage Multiplier rules.unitbuildspeedmultiplier = Unit Production Speed Multiplier rules.unithealthmultiplier = Unit Health Multiplier rules.unitdamagemultiplier = Unit Damage Multiplier +rules.unitcapvariable = Cores Contribute To Unit Cap +rules.unitcap = Base Unit Cap rules.enemycorebuildradius = Enemy Core No-Build Radius:[lightgray] (tiles) rules.wavespacing = Wave Spacing:[lightgray] (sec) rules.buildcostmultiplier = Build Cost Multiplier diff --git a/core/src/mindustry/entities/Units.java b/core/src/mindustry/entities/Units.java index 3d73faebd6..970374811b 100644 --- a/core/src/mindustry/entities/Units.java +++ b/core/src/mindustry/entities/Units.java @@ -76,7 +76,7 @@ public class Units{ if((team == state.rules.waveTeam && !state.rules.pvp) || (state.isCampaign() && team == state.rules.waveTeam)){ return Integer.MAX_VALUE; } - return state.rules.unitCap + indexer.getExtraUnits(team); + return Math.max(0, state.rules.unitCapVariable ? state.rules.unitCap + indexer.getExtraUnits(team) : state.rules.unitCap); } /** @return whether this player can interact with a specific tile. if either of these are null, returns true.*/ diff --git a/core/src/mindustry/game/Rules.java b/core/src/mindustry/game/Rules.java index eb34bab55f..538422fef0 100644 --- a/core/src/mindustry/game/Rules.java +++ b/core/src/mindustry/game/Rules.java @@ -44,6 +44,8 @@ public class Rules{ public boolean fire = true; /** Whether units use and require ammo. */ public boolean unitAmmo = false; + /** Whether cores add to unit limit */ + public boolean unitCapVariable = true; /** How fast unit pads build units. */ public float unitBuildSpeedMultiplier = 1f; /** How much damage any other units deal. */ diff --git a/core/src/mindustry/ui/dialogs/CustomRulesDialog.java b/core/src/mindustry/ui/dialogs/CustomRulesDialog.java index b150b5fa9f..94ea454d21 100644 --- a/core/src/mindustry/ui/dialogs/CustomRulesDialog.java +++ b/core/src/mindustry/ui/dialogs/CustomRulesDialog.java @@ -161,6 +161,8 @@ public class CustomRulesDialog extends BaseDialog{ title("@rules.title.unit"); check("@rules.unitammo", b -> rules.unitAmmo = b, () -> rules.unitAmmo); + check("@rules.unitcapvariable", b -> rules.unitCapVariable = b, () -> rules.unitCapVariable); + number("@rules.unitcap", true, f -> rules.unitCap = f, () -> rules.unitCap, -999, 999); number("@rules.unitdamagemultiplier", f -> rules.unitDamageMultiplier = f, () -> rules.unitDamageMultiplier); number("@rules.unitbuildspeedmultiplier", f -> rules.unitBuildSpeedMultiplier = f, () -> rules.unitBuildSpeedMultiplier, 0.001f, 50f); @@ -204,6 +206,17 @@ public class CustomRulesDialog extends BaseDialog{ number(text, false, cons, prov, condition, 0, Float.MAX_VALUE); } + void number(String text, boolean integer, Intc cons, Intp prov, int min, int max){ + main.table(t -> { + t.left(); + t.add(text).left().padRight(5); + t.field((integer ? (int)prov.get() : prov.get()) + "", s -> cons.get(Strings.parseInt(s))) + .padRight(100f) + .valid(f -> Strings.parseInt(f) >= min && Strings.parseInt(f) <= max).width(120f).left().addInputDialog(); + }).padTop(0); + main.row(); + } + void number(String text, boolean integer, Floatc cons, Floatp prov, Boolp condition, float min, float max){ main.table(t -> { t.left();