From 140e1fa53ee63121b285d711ace21f2ea33d95a2 Mon Sep 17 00:00:00 2001 From: Anuken Date: Tue, 2 Jun 2020 23:45:39 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=AEUpgrade=20cleanup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/mindustry/content/Blocks.java | 6 +++++ core/src/mindustry/content/UnitTypes.java | 19 --------------- .../entities/comp/BlockUnitComp.java | 5 ++++ .../mindustry/entities/comp/PlayerComp.java | 2 +- core/src/mindustry/type/UnitType.java | 2 -- .../world/blocks/units/Reconstructor.java | 23 +++++++++++++------ 6 files changed, 28 insertions(+), 29 deletions(-) diff --git a/core/src/mindustry/content/Blocks.java b/core/src/mindustry/content/Blocks.java index f232526d49..7cf1f78954 100644 --- a/core/src/mindustry/content/Blocks.java +++ b/core/src/mindustry/content/Blocks.java @@ -1701,6 +1701,12 @@ public class Blocks implements ContentList{ itemCapacity = 30; constructTime = 60f * 5f; + + upgrades = new UnitType[][]{ + {UnitTypes.dagger, UnitTypes.titan}, + {UnitTypes.crawler, UnitTypes.eruptor}, + {UnitTypes.wraith, UnitTypes.ghoul}, + }; }}; repairPoint = new RepairPoint("repair-point"){{ diff --git a/core/src/mindustry/content/UnitTypes.java b/core/src/mindustry/content/UnitTypes.java index 8aff8f7f1c..cbeb59fbd8 100644 --- a/core/src/mindustry/content/UnitTypes.java +++ b/core/src/mindustry/content/UnitTypes.java @@ -99,9 +99,6 @@ public class UnitTypes implements ContentList{ }}; titan = new UnitType("titan"){{ - dagger.upgrade = this; - tier = 2; - speed = 0.4f; hitsize = 9f; range = 10f; @@ -193,9 +190,6 @@ public class UnitTypes implements ContentList{ }; fortress = new UnitType("fortress"){{ - titan.upgrade = this; - tier = 3; - speed = 0.38f; hitsize = 13f; rotateSpeed = 3f; @@ -226,9 +220,6 @@ public class UnitTypes implements ContentList{ }}; eruptor = new UnitType("eruptor"){{ - crawler.upgrade = this; - tier = 2; - speed = 0.4f; drag = 0.4f; hitsize = 10f; @@ -269,9 +260,6 @@ public class UnitTypes implements ContentList{ }}; ghoul = new UnitType("ghoul"){{ - wraith.upgrade = this; - tier = 2; - health = 220; speed = 2f; accel = 0.08f; @@ -297,9 +285,6 @@ public class UnitTypes implements ContentList{ }}; revenant = new UnitType("revenant"){{ - ghoul.upgrade = this; - tier = 3; - health = 220; speed = 1.9f; accel = 0.04f; @@ -459,8 +444,6 @@ public class UnitTypes implements ContentList{ }}; oculon = new UnitType("oculon"){{ - tier = 2; - drillTier = -1; speed = 0.6f; hitsize = 9f; @@ -492,8 +475,6 @@ public class UnitTypes implements ContentList{ }}; trident = new UnitType("trident"){{ - //wraith.upgrade = this; - tier = 3; health = 500; speed = 2f; diff --git a/core/src/mindustry/entities/comp/BlockUnitComp.java b/core/src/mindustry/entities/comp/BlockUnitComp.java index b30a4b9f53..3af40d00f8 100644 --- a/core/src/mindustry/entities/comp/BlockUnitComp.java +++ b/core/src/mindustry/entities/comp/BlockUnitComp.java @@ -44,6 +44,11 @@ abstract class BlockUnitComp implements Unitc{ return tile == null || tile.dead(); } + @Replace + public boolean isValid(){ + return tile != null && tile.isValid(); + } + @Replace public void team(Team team){ if(tile != null && this.team != team){ diff --git a/core/src/mindustry/entities/comp/PlayerComp.java b/core/src/mindustry/entities/comp/PlayerComp.java index 1516d7ad95..31dfb655dd 100644 --- a/core/src/mindustry/entities/comp/PlayerComp.java +++ b/core/src/mindustry/entities/comp/PlayerComp.java @@ -80,7 +80,7 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc, Dra @Override public void update(){ - if(unit.dead() || !unit.isAdded()){ + if(!unit.isValid()){ clearUnit(); } diff --git a/core/src/mindustry/type/UnitType.java b/core/src/mindustry/type/UnitType.java index b0bc0573f6..f313554716 100644 --- a/core/src/mindustry/type/UnitType.java +++ b/core/src/mindustry/type/UnitType.java @@ -32,8 +32,6 @@ public class UnitType extends UnlockableContent{ public boolean flying; public @NonNull Prov constructor; public @NonNull Prov defaultController = () -> !flying ? new GroundAI() : new FlyingAI(); - public @Nullable UnitType upgrade; - public int tier = 1; public float speed = 1.1f, boostMultiplier = 1f, rotateSpeed = 5f, baseRotateSpeed = 5f; public float drag = 0.3f, accel = 0.5f, landShake = 0f; public float health = 200f, range = -1, armor = 0f; diff --git a/core/src/mindustry/world/blocks/units/Reconstructor.java b/core/src/mindustry/world/blocks/units/Reconstructor.java index 0732871627..7670c7f801 100644 --- a/core/src/mindustry/world/blocks/units/Reconstructor.java +++ b/core/src/mindustry/world/blocks/units/Reconstructor.java @@ -9,6 +9,7 @@ import mindustry.entities.*; import mindustry.entities.units.*; import mindustry.gen.*; import mindustry.graphics.*; +import mindustry.type.*; import mindustry.ui.*; import mindustry.world.blocks.payloads.*; import mindustry.world.meta.*; @@ -19,8 +20,8 @@ public class Reconstructor extends UnitBlock{ public @Load(value = "@-top", fallback = "factory-top") TextureRegion topRegion; public @Load(value = "@-out", fallback = "factory-out") TextureRegion outRegion; public @Load(value = "@-in", fallback = "factory-in") TextureRegion inRegion; - public int tier = 1; public float constructTime = 60 * 2; + public UnitType[][] upgrades = {}; public Reconstructor(String name){ super(name); @@ -57,8 +58,7 @@ public class Reconstructor extends UnitBlock{ return this.payload == null && relativeTo(source) != rotation() && payload instanceof UnitPayload - && ((UnitPayload)payload).unit.type().upgrade != null - && ((UnitPayload)payload).unit.type().tier == tier; + && hasUpgrade(((UnitPayload)payload).unit.type()); } @Override @@ -79,7 +79,7 @@ public class Reconstructor extends UnitBlock{ Draw.alpha(1f - progress/ constructTime); Draw.rect(payload.unit.type().icon(Cicon.full), x, y, rotdeg() - 90); Draw.reset(); - Drawf.construct(this, payload.unit.type().upgrade, rotdeg() - 90f, progress / constructTime, speedScl, time); + Drawf.construct(this, upgrade(payload.unit.type()), rotdeg() - 90f, progress / constructTime, speedScl, time); }); }else{ Draw.z(Layer.blockOver); @@ -98,7 +98,7 @@ public class Reconstructor extends UnitBlock{ if(payload != null){ //check if offloading - if(payload.unit.type().upgrade == null || payload.unit.type().tier != tier){ + if(!hasUpgrade(payload.unit.type())){ moveOutPayload(); }else{ //update progress if(moveInPayload()){ @@ -109,7 +109,7 @@ public class Reconstructor extends UnitBlock{ //upgrade the unit if(progress >= constructTime){ - payload.unit = payload.unit.type().upgrade.create(payload.unit.team()); + payload.unit = upgrade(payload.unit.type()).create(payload.unit.team()); progress = 0; Effects.shake(2f, 3f, this); Fx.producesmoke.at(this); @@ -124,7 +124,16 @@ public class Reconstructor extends UnitBlock{ } public boolean constructing(){ - return payload != null && payload.unit.type().upgrade != null && payload.unit.type().tier == tier; + return payload != null && hasUpgrade(payload.unit.type()); + } + + public boolean hasUpgrade(UnitType type){ + return upgrade(type) != null; + } + + public UnitType upgrade(UnitType type){ + UnitType[] r = Structs.find(upgrades, arr -> arr[0] == type); + return r == null ? null : r[1]; } } }