From 58c044f509863a2d066b37600a9aa9a7d6bcb471 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sat, 12 Feb 2022 16:23:55 -0500 Subject: [PATCH] pain --- core/src/mindustry/ai/types/AssemblerAI.java | 1 - core/src/mindustry/content/Fx.java | 4 +- core/src/mindustry/content/UnitTypes.java | 8 +- core/src/mindustry/io/TypeIO.java | 6 ++ core/src/mindustry/type/UnitType.java | 2 +- .../blocks/distribution/DirectionBridge.java | 1 + .../world/blocks/production/WallCrafter.java | 1 + .../world/blocks/units/UnitAssembler.java | 88 ++++++++++++++----- 8 files changed, 83 insertions(+), 28 deletions(-) diff --git a/core/src/mindustry/ai/types/AssemblerAI.java b/core/src/mindustry/ai/types/AssemblerAI.java index 3a0a6f358e..c3db6f264b 100644 --- a/core/src/mindustry/ai/types/AssemblerAI.java +++ b/core/src/mindustry/ai/types/AssemblerAI.java @@ -10,7 +10,6 @@ public class AssemblerAI extends AIController{ @Override public void updateMovement(){ - //TODO if(!targetPos.isZero()){ moveTo(targetPos, 1f, 3f); } diff --git a/core/src/mindustry/content/Fx.java b/core/src/mindustry/content/Fx.java index a99ab6219d..f6de457863 100644 --- a/core/src/mindustry/content/Fx.java +++ b/core/src/mindustry/content/Fx.java @@ -313,11 +313,11 @@ public class Fx{ }), unitAssemble = new Effect(70, e -> { - if(!(e.data instanceof Unit unit)) return; + if(!(e.data instanceof UnitType type)) return; alpha(e.fout()); mixcol(Pal.accent, e.fout()); - rect(unit.type.fullIcon, unit.x, unit.y, unit.rotation - 90); + rect(type.fullIcon, e.x, e.y, e.rotation); }).layer(Layer.flyingUnit + 5f), padlaunch = new Effect(10, e -> { diff --git a/core/src/mindustry/content/UnitTypes.java b/core/src/mindustry/content/UnitTypes.java index dd15341f86..8b0b1f8103 100644 --- a/core/src/mindustry/content/UnitTypes.java +++ b/core/src/mindustry/content/UnitTypes.java @@ -3141,7 +3141,7 @@ public class UnitTypes{ mineTier = 4; buildSpeed = 0.8f; drag = 0.08f; - speed = 5.4f; + speed = 5.6f; rotateSpeed = 7f; accel = 0.09f; itemCapacity = 60; @@ -3198,7 +3198,7 @@ public class UnitTypes{ mineTier = 4; buildSpeed = 1.1f; drag = 0.08f; - speed = 6.6f; + speed = 7f; rotateSpeed = 8f; accel = 0.09f; itemCapacity = 90; @@ -3267,7 +3267,7 @@ public class UnitTypes{ mineTier = 4; buildSpeed = 1.4f; drag = 0.08f; - speed = 7.4f; + speed = 7.5f; rotateSpeed = 8f; accel = 0.08f; itemCapacity = 110; @@ -3331,6 +3331,7 @@ public class UnitTypes{ allowedInPayloads = false; logicControllable = false; envDisabled = 0; + payloadCapacity = 0f; lowAltitude = false; flying = true; @@ -3360,6 +3361,7 @@ public class UnitTypes{ health = 90; engineSize = 2f; engineOffset = 6.5f; + payloadCapacity = 0f; outlineColor = Pal.darkOutline; isCounted = false; diff --git a/core/src/mindustry/io/TypeIO.java b/core/src/mindustry/io/TypeIO.java index ab0776852e..18acb76d1d 100644 --- a/core/src/mindustry/io/TypeIO.java +++ b/core/src/mindustry/io/TypeIO.java @@ -408,6 +408,8 @@ public class TypeIO{ write.i(((Unit)ai.attackTarget).id); } } + }else if(control instanceof AssemblerAI){ //hate + write.b(5); }else{ write.b(2); } @@ -464,11 +466,15 @@ public class TypeIO{ } return ai; + }else if(type == 5){ + //augh + return prev instanceof AssemblerAI ? prev : new AssemblerAI(); }else{ //there are two cases here: //1: prev controller was not a player, carry on //2: prev controller was a player, so replace this controller with *anything else* //...since AI doesn't update clientside it doesn't matter + //TODO I hate this return (!(prev instanceof AIController) || (prev instanceof FormationAI) || (prev instanceof LogicAI)) ? new GroundAI() : prev; } } diff --git a/core/src/mindustry/type/UnitType.java b/core/src/mindustry/type/UnitType.java index 8d66221244..ee79dd414d 100644 --- a/core/src/mindustry/type/UnitType.java +++ b/core/src/mindustry/type/UnitType.java @@ -286,7 +286,7 @@ public class UnitType extends UnlockableContent{ ability.displayBars(unit, bars); } - if(unit instanceof Payloadc payload){ + if(payloadCapacity > 0 && unit instanceof Payloadc payload){ bars.add(new Bar("stat.payloadcapacity", Pal.items, () -> payload.payloadUsed() / unit.type().payloadCapacity)); bars.row(); diff --git a/core/src/mindustry/world/blocks/distribution/DirectionBridge.java b/core/src/mindustry/world/blocks/distribution/DirectionBridge.java index d8ca0b81c2..9b949ae8a5 100644 --- a/core/src/mindustry/world/blocks/distribution/DirectionBridge.java +++ b/core/src/mindustry/world/blocks/distribution/DirectionBridge.java @@ -38,6 +38,7 @@ public class DirectionBridge extends Block{ noUpdateDisabled = true; envEnabled = Env.space | Env.terrestrial | Env.underwater; drawArrow = false; + regionRotated1 = 1; } @Override diff --git a/core/src/mindustry/world/blocks/production/WallCrafter.java b/core/src/mindustry/world/blocks/production/WallCrafter.java index 352583c86b..b0a272439a 100644 --- a/core/src/mindustry/world/blocks/production/WallCrafter.java +++ b/core/src/mindustry/world/blocks/production/WallCrafter.java @@ -45,6 +45,7 @@ public class WallCrafter extends Block{ rotate = true; update = true; solid = true; + regionRotated1 = 1; envEnabled |= Env.space; } diff --git a/core/src/mindustry/world/blocks/units/UnitAssembler.java b/core/src/mindustry/world/blocks/units/UnitAssembler.java index cf4554c6b7..57f70f3c6d 100644 --- a/core/src/mindustry/world/blocks/units/UnitAssembler.java +++ b/core/src/mindustry/world/blocks/units/UnitAssembler.java @@ -45,6 +45,8 @@ public class UnitAssembler extends PayloadBlock{ rotateDraw = false; acceptsPayload = true; flags = EnumSet.of(BlockFlag.unitAssembler); + regionRotated1 = 1; + sync = true; } public Rect getRect(Rect rect, float x, float y, int rotation){ @@ -166,8 +168,22 @@ public class UnitAssembler extends PayloadBlock{ } } + @Remote(called = Loc.server) + public static void assemblerUnitSpawned(Tile tile){ + if(tile == null || !(tile.build instanceof UnitAssemblerBuild build)) return; + build.spawned(); + } + + @Remote(called = Loc.server) + public static void assemblerDroneSpawned(Tile tile, int id){ + if(tile == null || !(tile.build instanceof UnitAssemblerBuild build)) return; + build.droneSpawned(id); + } + public class UnitAssemblerBuild extends PayloadBlockBuild{ protected IntSeq readUnits = new IntSeq(); + //holds drone IDs that have been sent, but not synced yet - add to list as soon as possible + protected IntSeq whenSyncedUnits = new IntSeq(); public Seq units = new Seq<>(); public Seq modules = new Seq<>(); @@ -282,6 +298,16 @@ public class UnitAssembler extends PayloadBlock{ readUnits.clear(); } + //read newly synced drones on client end + if(units.size < dronesCreated && whenSyncedUnits.size > 0){ + whenSyncedUnits.each(id -> { + var unit = Groups.unit.getByID(id); + if(unit != null){ + units.addUnique(unit); + } + }); + } + units.removeAll(u -> !u.isAdded() || u.dead || !(u.controller() instanceof AssemblerAI)); powerWarmup = Mathf.lerpDelta(powerWarmup, efficiency() > 0.0001f ? 1f : 0f, 0.1f); @@ -289,16 +315,20 @@ public class UnitAssembler extends PayloadBlock{ totalDroneProgress += droneWarmup * Time.delta; if(units.size < dronesCreated && (droneProgress += edelta() / droneConstructTime) >= 1f){ - var unit = droneType.create(team); - if(unit instanceof BuildingTetherc bt){ - bt.building(this); + if(!net.client()){ + var unit = droneType.create(team); + if(unit instanceof BuildingTetherc bt){ + bt.building(this); + } + unit.set(x, y); + unit.rotation = 90f; + unit.add(); + units.add(unit); + Call.assemblerDroneSpawned(tile, unit.id); } - unit.set(x, y); - unit.rotation = 90f; - unit.add(); + } - Fx.spawn.at(unit); - units.add(unit); + if(units.size >= dronesCreated){ droneProgress = 0f; } @@ -320,7 +350,7 @@ public class UnitAssembler extends PayloadBlock{ wasOccupied = checkSolid(spawn, false); boolean visualOccupied = checkSolid(spawn, true); - float eff = (units.count(u -> ((AssemblerAI)u.controller()).inPosition()) / (float)dronesCreated); + float eff = (units.count(u -> ((AssemblerAI)u.controller()).inPosition()) / (float)dronesCreated); sameTypeWarmup = Mathf.lerpDelta(sameTypeWarmup, wasOccupied && !visualOccupied ? 0f : 1f, 0.1f); invalidWarmup = Mathf.lerpDelta(invalidWarmup, visualOccupied ? 1f : 0f, 0.1f); @@ -332,23 +362,38 @@ public class UnitAssembler extends PayloadBlock{ warmup = Mathf.lerpDelta(warmup, efficiency(), 0.1f); if((progress += edelta() * eff / plan.time) >= 1f){ - consume(); - - var unit = plan.unit.create(team); - unit.set(spawn.x + Mathf.range(0.001f), spawn.y + Mathf.range(0.001f)); - unit.rotation = 90f; - unit.add(); - progress = 0f; - - Fx.unitAssemble.at(unit.x, unit.y, 0f, unit); - - blocks.clear(); + Call.assemblerUnitSpawned(tile); } }else{ warmup = Mathf.lerpDelta(warmup, 0f, 0.1f); } } + public void droneSpawned(int id){ + Fx.spawn.at(x, y); + droneProgress = 0f; + if(net.client()){ + whenSyncedUnits.add(id); + } + } + + public void spawned(){ + var plan = plan(); + Vec2 spawn = getUnitSpawn(); + consume(); + + if(!net.client()){ + var unit = plan.unit.create(team); + unit.set(spawn.x + Mathf.range(0.001f), spawn.y + Mathf.range(0.001f)); + unit.rotation = 90f; + unit.add(); + } + + progress = 0f; + Fx.unitAssemble.at(spawn.x, spawn.y, 0f, plan.unit); + blocks.clear(); + } + @Override public void draw(){ Draw.rect(region, x, y); @@ -372,7 +417,7 @@ public class UnitAssembler extends PayloadBlock{ Draw.rect(topRegion, x, y); //draw drone construction - if(droneWarmup > 0){ + if(droneWarmup > 0.001f){ Draw.draw(Layer.blockOver + 0.2f, () -> { Drawf.construct(this, droneType.fullIcon, Pal.accent, 0f, droneProgress, droneWarmup, totalDroneProgress, 14f); }); @@ -503,6 +548,7 @@ public class UnitAssembler extends PayloadBlock{ for(int i = 0; i < count; i++){ readUnits.add(read.i()); } + whenSyncedUnits.clear(); blocks.read(read); }