From 4567ee9a136639b3eb8349c054ffb69b5b36df5b Mon Sep 17 00:00:00 2001 From: Anuken Date: Wed, 17 Nov 2021 10:58:36 -0500 Subject: [PATCH] Test fixes / Building module presence saving --- core/assets/bundles/bundle.properties | 2 +- core/src/mindustry/content/Blocks.java | 26 +++++++++++++------ core/src/mindustry/content/UnitTypes.java | 6 +++-- .../mindustry/entities/comp/BuildingComp.java | 26 ++++++++++++++----- core/src/mindustry/io/SaveFileReader.java | 4 +++ core/src/mindustry/mod/ContentParser.java | 3 ++- .../blocks/production/GenericCrafter.java | 2 +- .../mindustry/world/consumers/Consumers.java | 4 +++ 8 files changed, 54 insertions(+), 19 deletions(-) diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index d3fe68457a..5f20278030 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -1446,7 +1446,7 @@ item.blast-compound.description = Used in bombs and explosive ammunition. item.pyratite.description = Used in incendiary weapons and combustion-fueled generators. liquid.water.description = Used for cooling machines and waste processing. -liquid.slag.description = Refined in separators into constituent metals, or sprayed at enemies as a weapon. +liquid.slag.description = Refined in separators into constituent metals. Consumed in liquid turrets as ammunition. liquid.oil.description = Used in advanced material production and as incendiary ammunition. liquid.cryofluid.description = Used as coolant in reactors, turrets and factories. diff --git a/core/src/mindustry/content/Blocks.java b/core/src/mindustry/content/Blocks.java index 4268fb20e1..1c59c5b9bb 100644 --- a/core/src/mindustry/content/Blocks.java +++ b/core/src/mindustry/content/Blocks.java @@ -1021,7 +1021,7 @@ public class Blocks implements ContentList{ requirements(Category.crafting, with(Items.tungsten, 60, Items.graphite, 30)); craftEffect = Fx.none; outputItem = new ItemStack(Items.carbide, 1); - craftTime = 60f * 4f; + craftTime = 60f * 3f; size = 3; itemCapacity = 20; hasPower = hasItems = true; @@ -1044,15 +1044,25 @@ public class Blocks implements ContentList{ }}; //TODO implement + //TODO "crucible" is getting old //TODO should have a useful turret ammo byproduct? //original: consumes.items(with(Items.copper, 3, Items.lead, 4, Items.titanium, 2, Items.silicon, 3)); if(false) - surgeCrucible = new GenericCrafter("surge-crucible"){{ - //needs: - //liquid lead??? - //slag (a lot of it) - //silicon - //heat + surgeCrucible = new HeatCrafter("surge-crucible"){{ + size = 3; + + itemCapacity = 20; + heatRequirement = 5f; + craftTime = 60f * 2.5f; + + ambientSound = Sounds.smelter; + ambientSoundVolume = 0.07f; + + consumes.item(Items.silicon, 3); + //TODO must consume from 2 pumps, 1, or 1.5? + //TODO consume hydrogen/ozone? + consumes.liquid(Liquids.slag, 2f * 80f / 60f); + consumes.power(2f); //TODO necessary? }}; //TODO needs to be completely redone from the ground up @@ -1534,7 +1544,7 @@ public class Blocks implements ContentList{ //TODO CUSTOM DRAW ANIMATION - pistons - repurpose DrawBlock? consumes.liquid(Liquids.hydrogen, 1.5f / 60f); - pumpAmount = 0.4f; + pumpAmount = 80f / 60f / 4f; liquidCapacity = 40f; size = 2; }}; diff --git a/core/src/mindustry/content/UnitTypes.java b/core/src/mindustry/content/UnitTypes.java index e0e6bed4ba..c5c7a4e14f 100644 --- a/core/src/mindustry/content/UnitTypes.java +++ b/core/src/mindustry/content/UnitTypes.java @@ -40,7 +40,7 @@ public class UnitTypes implements ContentList{ //air public static @EntityDef({Unitc.class}) UnitType flare, eclipse, horizon, zenith, antumbra, - evoke; //elicit, incite? + evoke; //air, legacy public static @EntityDef(value = {Unitc.class}, legacy = true) UnitType mono; @@ -50,7 +50,7 @@ public class UnitTypes implements ContentList{ //air + payload public static @EntityDef({Unitc.class, Payloadc.class}) UnitType mega, - incite; + incite, emanate; //air + payload, legacy public static @EntityDef(value = {Unitc.class, Payloadc.class}, legacy = true) UnitType quad; @@ -2526,6 +2526,8 @@ public class UnitTypes implements ContentList{ }}); }}; + //TODO emanate (+ better names) + //endregion //region internal diff --git a/core/src/mindustry/entities/comp/BuildingComp.java b/core/src/mindustry/entities/comp/BuildingComp.java index 56d1842dc0..fbb8d2635d 100644 --- a/core/src/mindustry/entities/comp/BuildingComp.java +++ b/core/src/mindustry/entities/comp/BuildingComp.java @@ -152,8 +152,10 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc, write.f(health); write.b(rotation | 0b10000000); write.b(team.id); - write.b(1); //version + write.b(2); //version write.b(enabled ? 1 : 0); + //write presence of items/power/liquids/cons, so removing/adding them does not corrupt future saves. + write.b(moduleBitmask()); if(items != null) items.write(write); if(power != null) power.write(write); if(liquids != null) liquids.write(write); @@ -167,23 +169,35 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc, team = Team.get(read.b()); rotation = rot & 0b01111111; + + int moduleBits = moduleBitmask(); boolean legacy = true; + if((rot & 0b10000000) != 0){ byte ver = read.b(); //version of entity save - if(ver == 1){ + if(ver >= 1){ byte on = read.b(); this.enabled = on == 1; if(!this.enabled){ enabledControlTime = timeToUncontrol; } } + + //get which modules should actually be read; this was added in version 2 + if(ver >= 2){ + moduleBits = read.b(); + } legacy = false; } - if(items != null) items.read(read, legacy); - if(power != null) power.read(read, legacy); - if(liquids != null) liquids.read(read, legacy); - if(cons != null) cons.read(read, legacy); + if((moduleBits & 1) != 0) (items == null ? new ItemModule() : items).read(read, legacy); + if((moduleBits & 2) != 0) (power == null ? new PowerModule() : power).read(read, legacy); + if((moduleBits & 4) != 0) (liquids == null ? new LiquidModule() : liquids).read(read, legacy); + if((moduleBits & 8) != 0) (cons == null ? new ConsumeModule(self()) : cons).read(read, legacy); + } + + public int moduleBitmask(){ + return (items != null ? 1 : 0) | (power != null ? 2 : 0) | (liquids != null ? 4 : 0) | (cons != null ? 8 : 0); } public void writeAll(Writes write){ diff --git a/core/src/mindustry/io/SaveFileReader.java b/core/src/mindustry/io/SaveFileReader.java index 10a10c8092..b991b64f85 100644 --- a/core/src/mindustry/io/SaveFileReader.java +++ b/core/src/mindustry/io/SaveFileReader.java @@ -79,6 +79,10 @@ public abstract class SaveFileReader{ protected int lastRegionLength; protected @Nullable CounterInputStream currCounter; + public static String mapFallback(String name){ + return fallback.get(name, name); + } + public void region(String name, DataInput stream, CounterInputStream counter, IORunner cons) throws IOException{ counter.resetCount(); this.currCounter = counter; diff --git a/core/src/mindustry/mod/ContentParser.java b/core/src/mindustry/mod/ContentParser.java index 6e9f49d035..a2c6c22b3a 100644 --- a/core/src/mindustry/mod/ContentParser.java +++ b/core/src/mindustry/mod/ContentParser.java @@ -28,6 +28,7 @@ import mindustry.game.*; import mindustry.game.Objectives.*; import mindustry.gen.*; import mindustry.graphics.*; +import mindustry.io.*; import mindustry.mod.Mods.*; import mindustry.type.*; import mindustry.type.ammo.*; @@ -759,7 +760,7 @@ public class ContentParser{ } //find parent node. - TechNode parent = TechTree.all.find(t -> t.content.name.equals(researchName) || t.content.name.equals(currentMod.name + "-" + researchName)); + TechNode parent = TechTree.all.find(t -> t.content.name.equals(researchName) || t.content.name.equals(currentMod.name + "-" + researchName) || t.content.name.equals(SaveVersion.mapFallback(researchName))); if(parent == null){ Log.warn("Content '" + researchName + "' isn't in the tech tree, but '" + unlock.name + "' requires it to be researched."); diff --git a/core/src/mindustry/world/blocks/production/GenericCrafter.java b/core/src/mindustry/world/blocks/production/GenericCrafter.java index fda164768f..24c7b62d20 100644 --- a/core/src/mindustry/world/blocks/production/GenericCrafter.java +++ b/core/src/mindustry/world/blocks/production/GenericCrafter.java @@ -39,7 +39,7 @@ public class GenericCrafter extends Block{ public DrawBlock drawer = new DrawBlock(); /** If set, the icon is overridden to be these strings, in order. Each string is a suffix. */ - public String[] iconOverride = null; + public @Nullable String[] iconOverride = null; public GenericCrafter(String name){ super(name); diff --git a/core/src/mindustry/world/consumers/Consumers.java b/core/src/mindustry/world/consumers/Consumers.java index 9fdba8d2ec..5a3c5f01cf 100644 --- a/core/src/mindustry/world/consumers/Consumers.java +++ b/core/src/mindustry/world/consumers/Consumers.java @@ -62,6 +62,10 @@ public class Consumers{ return add(new ConsumeLiquid(liquid, amount)); } + public ConsumeLiquids liquids(LiquidStack... stacks){ + return add(new ConsumeLiquids(stacks)); + } + /** * Creates a consumer which directly uses power without buffering it. * @param powerPerTick The amount of power which is required each tick for 100% efficiency.