diff --git a/core/src/io/anuke/mindustry/content/UnitTypes.java b/core/src/io/anuke/mindustry/content/UnitTypes.java index 35eb9890bd..d6e1dd232a 100644 --- a/core/src/io/anuke/mindustry/content/UnitTypes.java +++ b/core/src/io/anuke/mindustry/content/UnitTypes.java @@ -17,7 +17,7 @@ public class UnitTypes implements ContentList{ @Override public void load(){ - draug = new UnitType("draug", Draug::new){{ + draug = new UnitType("draug", MinerDrone::new){{ flying = true; drag = 0.01f; speed = 0.3f; @@ -32,7 +32,7 @@ public class UnitTypes implements ContentList{ }}; }}; - spirit = new UnitType("spirit", Spirit::new){{ + spirit = new UnitType("spirit", RepairDrone::new){{ flying = true; drag = 0.01f; speed = 0.42f; @@ -53,7 +53,7 @@ public class UnitTypes implements ContentList{ }}; }}; - phantom = new UnitType("phantom", Phantom::new){{ + phantom = new UnitType("phantom", BuilderDrone::new){{ flying = true; drag = 0.01f; mass = 2f; @@ -76,7 +76,7 @@ public class UnitTypes implements ContentList{ }}; }}; - dagger = new UnitType("dagger", Dagger::new){{ + dagger = new UnitType("dagger", GroundUnit::new){{ maxVelocity = 1.1f; speed = 0.2f; drag = 0.4f; @@ -92,7 +92,7 @@ public class UnitTypes implements ContentList{ }}; }}; - crawler = new UnitType("crawler", Crawler::new){{ + crawler = new UnitType("crawler", GroundUnit::new){{ maxVelocity = 1.27f; speed = 0.285f; drag = 0.4f; @@ -123,7 +123,7 @@ public class UnitTypes implements ContentList{ }}; }}; - titan = new UnitType("titan", Titan::new){{ + titan = new UnitType("titan", GroundUnit::new){{ maxVelocity = 0.8f; speed = 0.22f; drag = 0.4f; @@ -145,7 +145,7 @@ public class UnitTypes implements ContentList{ }}; }}; - fortress = new UnitType("fortress", Fortress::new){{ + fortress = new UnitType("fortress", GroundUnit::new){{ maxVelocity = 0.78f; speed = 0.15f; drag = 0.4f; @@ -167,7 +167,7 @@ public class UnitTypes implements ContentList{ }}; }}; - eruptor = new UnitType("eruptor", Eruptor::new){{ + eruptor = new UnitType("eruptor", GroundUnit::new){{ maxVelocity = 0.81f; speed = 0.16f; drag = 0.4f; @@ -189,7 +189,7 @@ public class UnitTypes implements ContentList{ }}; }}; - chaosArray = new UnitType("chaos-array", Dagger::new){{ + chaosArray = new UnitType("chaos-array", GroundUnit::new){{ maxVelocity = 0.68f; speed = 0.12f; drag = 0.4f; @@ -213,7 +213,7 @@ public class UnitTypes implements ContentList{ }}; }}; - eradicator = new UnitType("eradicator", Dagger::new){{ + eradicator = new UnitType("eradicator", GroundUnit::new){{ maxVelocity = 0.68f; speed = 0.12f; drag = 0.4f; @@ -238,7 +238,7 @@ public class UnitTypes implements ContentList{ }}; }}; - wraith = new UnitType("wraith", Wraith::new){{ + wraith = new UnitType("wraith", FlyingUnit::new){{ speed = 0.3f; maxVelocity = 1.9f; drag = 0.01f; @@ -257,7 +257,7 @@ public class UnitTypes implements ContentList{ }}; }}; - ghoul = new UnitType("ghoul", Ghoul::new){{ + ghoul = new UnitType("ghoul", FlyingUnit::new){{ health = 220; speed = 0.2f; maxVelocity = 1.4f; @@ -281,7 +281,7 @@ public class UnitTypes implements ContentList{ }}; }}; - revenant = new UnitType("revenant", Revenant::new){{ + revenant = new UnitType("revenant", HoverUnit::new){{ health = 1000; mass = 5f; hitsize = 20f; @@ -312,7 +312,7 @@ public class UnitTypes implements ContentList{ }}; }}; - lich = new UnitType("lich", Revenant::new){{ + lich = new UnitType("lich", HoverUnit::new){{ health = 6000; mass = 20f; hitsize = 40f; @@ -345,7 +345,7 @@ public class UnitTypes implements ContentList{ }}; }}; - reaper = new UnitType("reaper", Revenant::new){{ + reaper = new UnitType("reaper", HoverUnit::new){{ health = 11000; mass = 30f; hitsize = 56f; diff --git a/core/src/io/anuke/mindustry/entities/type/base/Crawler.java b/core/src/io/anuke/mindustry/entities/type/base/Crawler.java deleted file mode 100644 index 44da8bea5f..0000000000 --- a/core/src/io/anuke/mindustry/entities/type/base/Crawler.java +++ /dev/null @@ -1,4 +0,0 @@ -package io.anuke.mindustry.entities.type.base; - -public class Crawler extends GroundUnit{ -} diff --git a/core/src/io/anuke/mindustry/entities/type/base/Dagger.java b/core/src/io/anuke/mindustry/entities/type/base/Dagger.java deleted file mode 100644 index 09a39daaa7..0000000000 --- a/core/src/io/anuke/mindustry/entities/type/base/Dagger.java +++ /dev/null @@ -1,5 +0,0 @@ -package io.anuke.mindustry.entities.type.base; - -public class Dagger extends GroundUnit{ - -} diff --git a/core/src/io/anuke/mindustry/entities/type/base/Draug.java b/core/src/io/anuke/mindustry/entities/type/base/Draug.java deleted file mode 100644 index 47b7caed25..0000000000 --- a/core/src/io/anuke/mindustry/entities/type/base/Draug.java +++ /dev/null @@ -1,4 +0,0 @@ -package io.anuke.mindustry.entities.type.base; - -public class Draug extends MinerDrone{ -} diff --git a/core/src/io/anuke/mindustry/entities/type/base/Eruptor.java b/core/src/io/anuke/mindustry/entities/type/base/Eruptor.java deleted file mode 100644 index 4c86371811..0000000000 --- a/core/src/io/anuke/mindustry/entities/type/base/Eruptor.java +++ /dev/null @@ -1,4 +0,0 @@ -package io.anuke.mindustry.entities.type.base; - -public class Eruptor extends GroundUnit{ -} diff --git a/core/src/io/anuke/mindustry/entities/type/base/Fortress.java b/core/src/io/anuke/mindustry/entities/type/base/Fortress.java deleted file mode 100644 index c4f36dba69..0000000000 --- a/core/src/io/anuke/mindustry/entities/type/base/Fortress.java +++ /dev/null @@ -1,4 +0,0 @@ -package io.anuke.mindustry.entities.type.base; - -public class Fortress extends GroundUnit{ -} diff --git a/core/src/io/anuke/mindustry/entities/type/base/Ghoul.java b/core/src/io/anuke/mindustry/entities/type/base/Ghoul.java deleted file mode 100644 index 0c4294645a..0000000000 --- a/core/src/io/anuke/mindustry/entities/type/base/Ghoul.java +++ /dev/null @@ -1,5 +0,0 @@ -package io.anuke.mindustry.entities.type.base; - -public class Ghoul extends FlyingUnit{ - -} diff --git a/core/src/io/anuke/mindustry/entities/type/base/Revenant.java b/core/src/io/anuke/mindustry/entities/type/base/HoverUnit.java similarity index 96% rename from core/src/io/anuke/mindustry/entities/type/base/Revenant.java rename to core/src/io/anuke/mindustry/entities/type/base/HoverUnit.java index 393c134891..6aae538484 100644 --- a/core/src/io/anuke/mindustry/entities/type/base/Revenant.java +++ b/core/src/io/anuke/mindustry/entities/type/base/HoverUnit.java @@ -5,7 +5,7 @@ import io.anuke.arc.math.Angles; import io.anuke.arc.math.Mathf; import io.anuke.mindustry.entities.Units; -public class Revenant extends FlyingUnit{ +public class HoverUnit extends FlyingUnit{ @Override public void drawWeapons(){ diff --git a/core/src/io/anuke/mindustry/entities/type/base/Phantom.java b/core/src/io/anuke/mindustry/entities/type/base/Phantom.java deleted file mode 100644 index 1a50115647..0000000000 --- a/core/src/io/anuke/mindustry/entities/type/base/Phantom.java +++ /dev/null @@ -1,5 +0,0 @@ -package io.anuke.mindustry.entities.type.base; - -public class Phantom extends BuilderDrone{ - -} diff --git a/core/src/io/anuke/mindustry/entities/type/base/Spirit.java b/core/src/io/anuke/mindustry/entities/type/base/Spirit.java deleted file mode 100644 index d43fc658b0..0000000000 --- a/core/src/io/anuke/mindustry/entities/type/base/Spirit.java +++ /dev/null @@ -1,4 +0,0 @@ -package io.anuke.mindustry.entities.type.base; - -public class Spirit extends RepairDrone{ -} diff --git a/core/src/io/anuke/mindustry/entities/type/base/Titan.java b/core/src/io/anuke/mindustry/entities/type/base/Titan.java deleted file mode 100644 index 9324d4d215..0000000000 --- a/core/src/io/anuke/mindustry/entities/type/base/Titan.java +++ /dev/null @@ -1,5 +0,0 @@ -package io.anuke.mindustry.entities.type.base; - -public class Titan extends GroundUnit{ - -} diff --git a/core/src/io/anuke/mindustry/entities/type/base/Wraith.java b/core/src/io/anuke/mindustry/entities/type/base/Wraith.java deleted file mode 100644 index c8923e309f..0000000000 --- a/core/src/io/anuke/mindustry/entities/type/base/Wraith.java +++ /dev/null @@ -1,5 +0,0 @@ -package io.anuke.mindustry.entities.type.base; - -public class Wraith extends FlyingUnit{ - -} diff --git a/core/src/io/anuke/mindustry/io/versions/LegacyTypeTable.java b/core/src/io/anuke/mindustry/io/versions/LegacyTypeTable.java index 419d91e7ed..6e04863262 100644 --- a/core/src/io/anuke/mindustry/io/versions/LegacyTypeTable.java +++ b/core/src/io/anuke/mindustry/io/versions/LegacyTypeTable.java @@ -12,6 +12,60 @@ Latest data: [build 81] 0 = Player 1 = Fire 2 = Puddle +3 = MinerDrone +4 = RepairDrone +5 = BuilderDrone +6 = GroundUnit +7 = GroundUnit +8 = GroundUnit +9 = GroundUnit +10 = GroundUnit +11 = FlyingUnit +12 = FlyingUnit +13 = Revenant + +Before removal of lightining/bullet: [build 80] + +0 = Player +1 = Fire +2 = Puddle +3 = Bullet +4 = Lightning +5 = MinerDrone +6 = RepairDrone +7 = BuilderDrone +8 = GroundUnit +9 = GroundUnit +10 = GroundUnit +11 = GroundUnit +12 = GroundUnit +13 = FlyingUnit +14 = FlyingUnit +15 = Revenant + +Before addition of new units: [build 79 and below] + +0 = Player +1 = Fire +2 = Puddle +3 = Bullet +4 = Lightning +5 = RepairDrone +6 = GroundUnit +7 = GroundUnit +8 = GroundUnit +9 = GroundUnit +10 = GroundUnit +11 = FlyingUnit +12 = FlyingUnit +13 = BuilderDrone +14 = Revenant + */ +public class LegacyTypeTable{ + /* + 0 = Player +1 = Fire +2 = Puddle 3 = Draug 4 = Spirit 5 = Phantom @@ -23,97 +77,59 @@ Latest data: [build 81] 11 = Wraith 12 = Ghoul 13 = Revenant - -Before removal of lightining/bullet: [build 80] - -0 = Player -1 = Fire -2 = Puddle -3 = Bullet -4 = Lightning -5 = Draug -6 = Spirit -7 = Phantom -8 = Dagger -9 = Crawler -10 = Titan -11 = Fortress -12 = Eruptor -13 = Wraith -14 = Ghoul -15 = Revenant - -Before addition of new units: [build 79 and below] - -0 = Player -1 = Fire -2 = Puddle -3 = Bullet -4 = Lightning -5 = Spirit -6 = Dagger -7 = Crawler -8 = Titan -9 = Fortress -10 = Eruptor -11 = Wraith -12 = Ghoul -13 = Phantom -14 = Revenant - */ -public class LegacyTypeTable{ + */ private static final Prov[] build81Table = { Player::new, Fire::new, Puddle::new, - Draug::new, - Spirit::new, - Phantom::new, - Dagger::new, - Crawler::new, - Titan::new, - Fortress::new, - Eruptor::new, - Wraith::new, - Ghoul::new, - Revenant::new + MinerDrone::new, + RepairDrone::new, + BuilderDrone::new, + GroundUnit::new, + GroundUnit::new, + GroundUnit::new, + GroundUnit::new, + GroundUnit::new, + FlyingUnit::new, + FlyingUnit::new, + HoverUnit::new }; private static final Prov[] build80Table = { Player::new, Fire::new, Puddle::new, - Bullet::new, //TODO reading these may crash + Bullet::new, Lightning::new, - Draug::new, - Spirit::new, - Phantom::new, - Dagger::new, - Crawler::new, - Titan::new, - Fortress::new, - Eruptor::new, - Wraith::new, - Ghoul::new, - Revenant::new + MinerDrone::new, + RepairDrone::new, + BuilderDrone::new, + GroundUnit::new, + GroundUnit::new, + GroundUnit::new, + GroundUnit::new, + GroundUnit::new, + FlyingUnit::new, + FlyingUnit::new, + HoverUnit::new }; private static final Prov[] build79Table = { Player::new, Fire::new, Puddle::new, - Bullet::new, //TODO reading these may crash + Bullet::new, Lightning::new, - Spirit::new, - Dagger::new, - Crawler::new, - Titan::new, - Fortress::new, - Eruptor::new, - Wraith::new, - Ghoul::new, - Phantom::new, - Revenant::new + RepairDrone::new, + GroundUnit::new, + GroundUnit::new, + GroundUnit::new, + GroundUnit::new, + GroundUnit::new, + FlyingUnit::new, + FlyingUnit::new, + BuilderDrone::new, + HoverUnit::new }; public static Prov[] getTable(int build){ diff --git a/core/src/io/anuke/mindustry/mod/ContentParser.java b/core/src/io/anuke/mindustry/mod/ContentParser.java index 78a4628473..909c80d232 100644 --- a/core/src/io/anuke/mindustry/mod/ContentParser.java +++ b/core/src/io/anuke/mindustry/mod/ContentParser.java @@ -36,6 +36,19 @@ import java.lang.reflect.*; public class ContentParser{ private static final boolean ignoreUnknownFields = true; private ObjectMap, ContentType> contentTypes = new ObjectMap<>(); + private StringMap legacyUnitMap = StringMap.of( + "Dagger", "GroundUnit", + "Eruptor", "GroundUnit", + "Titan", "GroundUnit", + "Fortress", "GroundUnit", + "Crawler", "GroundUnit", + "Revenant", "HoverUnit", + "Draug", "MinerDrone", + "Phantom", "BuilderDrone", + "Spirit", "RepairDrone", + "Wraith", "FlyingUnit", + "Ghoul", "FlyingUnit" + ); private ObjectMap, FieldParser> classParsers = new ObjectMap, FieldParser>(){{ put(Effect.class, (type, data) -> field(Fx.class, data)); put(StatusEffect.class, (type, data) -> field(StatusEffects.class, data)); @@ -260,8 +273,14 @@ public class ContentParser{ ContentType.unit, (TypeParser)(mod, name, value) -> { readBundle(ContentType.unit, name, value); - Class type = resolve(getType(value), "io.anuke.mindustry.entities.type.base"); - UnitType unit = new UnitType(mod + "-" + name, supply(type)); + UnitType unit; + if(locate(ContentType.unit, name) == null){ + Class type = resolve(legacyUnitMap.get(Strings.capitalize(getType(value)), getType(value)), "io.anuke.mindustry.entities.type.base"); + unit = new UnitType(mod + "-" + name, supply(type)); + }else{ + unit = locate(ContentType.unit, name); + } + currentContent = unit; read(() -> readFields(unit, value, true)); diff --git a/core/src/io/anuke/mindustry/type/UnitType.java b/core/src/io/anuke/mindustry/type/UnitType.java index c559177139..1a7335b032 100644 --- a/core/src/io/anuke/mindustry/type/UnitType.java +++ b/core/src/io/anuke/mindustry/type/UnitType.java @@ -16,8 +16,7 @@ import io.anuke.mindustry.ui.*; public class UnitType extends UnlockableContent{ public @NonNull TypeID typeID; - public @NonNull - Prov constructor; + public @NonNull Prov constructor; public float health = 60; public float hitsize = 7f; @@ -49,7 +48,7 @@ public class UnitType extends UnlockableContent{ create(mainConstructor); } - public UnitType(String name){ + public UnitType(String name){ super(name); } diff --git a/tests/src/test/java/ApplicationTests.java b/tests/src/test/java/ApplicationTests.java index 58f51ad473..12409c364f 100644 --- a/tests/src/test/java/ApplicationTests.java +++ b/tests/src/test/java/ApplicationTests.java @@ -289,8 +289,8 @@ public class ApplicationTests{ void buildingOverlap(){ initBuilding(); - Phantom d1 = (Phantom)UnitTypes.phantom.create(Team.sharded); - Phantom d2 = (Phantom)UnitTypes.phantom.create(Team.sharded); + BuilderDrone d1 = (BuilderDrone)UnitTypes.phantom.create(Team.sharded); + BuilderDrone d2 = (BuilderDrone)UnitTypes.phantom.create(Team.sharded); d1.set(10f, 20f); d2.set(10f, 20f); @@ -311,8 +311,8 @@ public class ApplicationTests{ void buildingDestruction(){ initBuilding(); - Phantom d1 = (Phantom)UnitTypes.phantom.create(Team.sharded); - Phantom d2 = (Phantom)UnitTypes.phantom.create(Team.sharded); + BuilderDrone d1 = (BuilderDrone)UnitTypes.phantom.create(Team.sharded); + BuilderDrone d2 = (BuilderDrone)UnitTypes.phantom.create(Team.sharded); d1.set(10f, 20f); d2.set(10f, 20f);