From 5e737510a3742d8286045fa397e5d8b1133312e2 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sun, 22 Aug 2021 18:48:12 -0400 Subject: [PATCH] Leg collision bugfixes --- core/src/mindustry/ai/WaveSpawner.java | 1 + core/src/mindustry/entities/comp/LegsComp.java | 10 +++++++++- core/src/mindustry/entities/comp/PayloadComp.java | 1 + core/src/mindustry/entities/comp/UnitComp.java | 5 +++++ core/src/mindustry/type/UnitType.java | 4 +++- .../mindustry/world/blocks/payloads/UnitPayload.java | 3 ++- 6 files changed, 21 insertions(+), 3 deletions(-) diff --git a/core/src/mindustry/ai/WaveSpawner.java b/core/src/mindustry/ai/WaveSpawner.java index 40be2defad..ea40754222 100644 --- a/core/src/mindustry/ai/WaveSpawner.java +++ b/core/src/mindustry/ai/WaveSpawner.java @@ -195,6 +195,7 @@ public class WaveSpawner{ unit.apply(StatusEffects.unmoving, 30f); unit.apply(StatusEffects.invincible, 60f); unit.add(); + unit.unloaded(); Call.spawnEffect(unit.x, unit.y, unit.rotation, unit.type); } diff --git a/core/src/mindustry/entities/comp/LegsComp.java b/core/src/mindustry/entities/comp/LegsComp.java index f94e351853..81073abc1f 100644 --- a/core/src/mindustry/entities/comp/LegsComp.java +++ b/core/src/mindustry/entities/comp/LegsComp.java @@ -50,10 +50,18 @@ abstract class LegsComp implements Posc, Rotc, Hitboxc, Flyingc, Unitc{ resetLegs(); } + @Override + public void unloaded(){ + resetLegs(1f); + } + public void resetLegs(){ + resetLegs(type.legLength); + } + + public void resetLegs(float legLength){ float rot = baseRotation; int count = type.legCount; - float legLength = type.legLength; this.legs = new Leg[count]; diff --git a/core/src/mindustry/entities/comp/PayloadComp.java b/core/src/mindustry/entities/comp/PayloadComp.java index 6ea64825bd..3cc63c835d 100644 --- a/core/src/mindustry/entities/comp/PayloadComp.java +++ b/core/src/mindustry/entities/comp/PayloadComp.java @@ -122,6 +122,7 @@ abstract class PayloadComp implements Posc, Rotc, Hitboxc, Unitc{ //decrement count to prevent double increment if(!u.isAdded()) u.team.data().updateCount(u.type, -1); u.add(); + u.unloaded(); return true; } diff --git a/core/src/mindustry/entities/comp/UnitComp.java b/core/src/mindustry/entities/comp/UnitComp.java index 117967906b..81b78f221c 100644 --- a/core/src/mindustry/entities/comp/UnitComp.java +++ b/core/src/mindustry/entities/comp/UnitComp.java @@ -51,6 +51,11 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I private transient boolean wasPlayer; private transient boolean wasHealed; + /** Called when this unit was unloaded from a factory or spawn point. */ + public void unloaded(){ + + } + /** Move based on preferred unit movement type. */ public void movePref(Vec2 movement){ if(type.omniMovement){ diff --git a/core/src/mindustry/type/UnitType.java b/core/src/mindustry/type/UnitType.java index fb0eb9e1cb..0897ca2cbd 100644 --- a/core/src/mindustry/type/UnitType.java +++ b/core/src/mindustry/type/UnitType.java @@ -72,7 +72,7 @@ public class UnitType extends UnlockableContent{ public float commandRadius = 150f; public float visualElevation = -1f; /** If true and this is a legged unit, this unit can walk over blocks. */ - public boolean allowLegStep = true; + public boolean allowLegStep = false; /** If true, this unit cannot drown, and will not be affected by the floor under it. */ public boolean hovering = false; public boolean omniMovement = true; @@ -327,6 +327,8 @@ public class UnitType extends UnlockableContent{ Unit example = constructor.get(); + allowLegStep = example instanceof Legsc; + //water preset if(example instanceof WaterMovec){ canDrown = false; diff --git a/core/src/mindustry/world/blocks/payloads/UnitPayload.java b/core/src/mindustry/world/blocks/payloads/UnitPayload.java index dd33a3ca91..838f987477 100644 --- a/core/src/mindustry/world/blocks/payloads/UnitPayload.java +++ b/core/src/mindustry/world/blocks/payloads/UnitPayload.java @@ -105,7 +105,7 @@ public class UnitPayload implements Payload{ if(solid.solid(tx, ty)) return false; } - //cannnot dump when there's a lot of overlap going on + //cannot dump when there's a lot of overlap going on if(!unit.type.flying && Units.count(unit.x, unit.y, unit.physicSize(), o -> o.isGrounded() && (o.type.allowLegStep == unit.type.allowLegStep)) > 0){ return false; } @@ -116,6 +116,7 @@ public class UnitPayload implements Payload{ //prevents stacking unit.vel.add(Mathf.range(0.5f), Mathf.range(0.5f)); unit.add(); + unit.unloaded(); Events.fire(new UnitUnloadEvent(unit)); return true;