From 702ba0ae84c31a42d7005f23a1b3d771811c55f6 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sun, 4 Oct 2020 12:48:33 -0400 Subject: [PATCH] Bugfixes --- .../mindustry/entities/comp/BuildingComp.java | 9 +++-- core/src/mindustry/logic/Controllable.java | 1 + core/src/mindustry/logic/LAccess.java | 8 +++++ core/src/mindustry/logic/LExecutor.java | 6 +++- .../world/blocks/defense/turrets/Turret.java | 36 ++++++++++++++----- .../blocks/distribution/StackConveyor.java | 8 ++--- .../world/consumers/ConsumeLiquidBase.java | 2 +- 7 files changed, 51 insertions(+), 19 deletions(-) diff --git a/core/src/mindustry/entities/comp/BuildingComp.java b/core/src/mindustry/entities/comp/BuildingComp.java index 42358c9cf6..1b57f81362 100644 --- a/core/src/mindustry/entities/comp/BuildingComp.java +++ b/core/src/mindustry/entities/comp/BuildingComp.java @@ -496,7 +496,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc, } public void transferLiquid(Building next, float amount, Liquid liquid){ - float flow = Math.min(next.block.liquidCapacity - next.liquids.get(liquid) - 0.001f, amount); + float flow = Math.min(next.block.liquidCapacity - next.liquids.get(liquid), amount); if(next.acceptLiquid(self(), liquid, flow)){ next.handleLiquid(self(), liquid, flow); @@ -528,7 +528,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc, float ofract = next.liquids.get(liquid) / next.block.liquidCapacity; float fract = liquids.get(liquid) / block.liquidCapacity * block.liquidPressure; float flow = Math.min(Mathf.clamp((fract - ofract) * (1f)) * (block.liquidCapacity), liquids.get(liquid)); - flow = Math.min(flow, next.block.liquidCapacity - next.liquids.get(liquid) - 0.001f); + flow = Math.min(flow, next.block.liquidCapacity - next.liquids.get(liquid)); if(flow > 0f && ofract <= fract && next.acceptLiquid(self(), liquid, flow)){ next.handleLiquid(self(), liquid, flow); @@ -1266,6 +1266,11 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc, } } + @Override + public void control(LAccess type, Object p1, double p2, double p3, double p4){ + + } + @Override public void remove(){ if(sound != null){ diff --git a/core/src/mindustry/logic/Controllable.java b/core/src/mindustry/logic/Controllable.java index 31baf31a1e..3785eae4b6 100644 --- a/core/src/mindustry/logic/Controllable.java +++ b/core/src/mindustry/logic/Controllable.java @@ -3,4 +3,5 @@ package mindustry.logic; /** An object that can be controlled with logic. */ public interface Controllable{ void control(LAccess type, double p1, double p2, double p3, double p4); + void control(LAccess type, Object p1, double p2, double p3, double p4); } diff --git a/core/src/mindustry/logic/LAccess.java b/core/src/mindustry/logic/LAccess.java index 2b7f0b1908..f38745447c 100644 --- a/core/src/mindustry/logic/LAccess.java +++ b/core/src/mindustry/logic/LAccess.java @@ -30,10 +30,12 @@ public enum LAccess{ //values with parameters are considered controllable enabled("to"), //"to" is standard for single parameter access shoot("x", "y", "shoot"), + shootp(true, "unit", "shoot") ; public final String[] parameters; + public final boolean isObj; public static final LAccess[] all = values(), @@ -42,5 +44,11 @@ public enum LAccess{ LAccess(String... parameters){ this.parameters = parameters; + isObj = false; + } + + LAccess(boolean obj, String... parameters){ + this.parameters = parameters; + isObj = obj; } } diff --git a/core/src/mindustry/logic/LExecutor.java b/core/src/mindustry/logic/LExecutor.java index ad5936a3d3..053d1e9c1a 100644 --- a/core/src/mindustry/logic/LExecutor.java +++ b/core/src/mindustry/logic/LExecutor.java @@ -164,7 +164,11 @@ public class LExecutor{ Object obj = exec.obj(target); if(obj instanceof Controllable){ Controllable cont = (Controllable)obj; - cont.control(type, exec.num(p1), exec.num(p2), exec.num(p3), exec.num(p4)); + if(type.isObj){ + cont.control(type, exec.obj(p1), exec.num(p2), exec.num(p3), exec.num(p4)); + }else{ + cont.control(type, exec.num(p1), exec.num(p2), exec.num(p3), exec.num(p4)); + } } } } diff --git a/core/src/mindustry/world/blocks/defense/turrets/Turret.java b/core/src/mindustry/world/blocks/defense/turrets/Turret.java index 9aaa15768c..9d925af2f3 100644 --- a/core/src/mindustry/world/blocks/defense/turrets/Turret.java +++ b/core/src/mindustry/world/blocks/defense/turrets/Turret.java @@ -175,6 +175,20 @@ public abstract class Turret extends Block{ super.control(type, p1, p2, p3, p4); } + @Override + public void control(LAccess type, Object p1, double p2, double p3, double p4){ + if(type == LAccess.shootp && !unit.isPlayer()){ + logicControlTime = logicControlCooldown; + logicShooting = !Mathf.zero(p2); + + if(p1 instanceof Posc){ + targetPosition((Posc)p1); + } + } + + super.control(type, p1, p2, p3, p4); + } + @Override public double sense(LAccess sensor){ return switch(sensor){ @@ -199,6 +213,18 @@ public abstract class Turret extends Block{ return target != null || (logicControlled() && logicShooting) || (isControlled() && unit.isShooting()); } + public void targetPosition(Posc pos){ + BulletType bullet = peekAmmo(); + float speed = bullet.speed; + //slow bullets never intersect + if(speed < 0.1f) speed = 9999999f; + + targetPos.set(Predict.intercept(this, pos, speed)); + if(targetPos.isZero()){ + targetPos.set(target); + } + } + @Override public void draw(){ Draw.rect(baseRegion, x, y); @@ -246,15 +272,7 @@ public abstract class Turret extends Block{ }else if(logicControlled()){ //logic behavior canShoot = logicShooting; }else{ //default AI behavior - BulletType type = peekAmmo(); - float speed = type.speed; - //slow bullets never intersect - if(speed < 0.1f) speed = 9999999f; - - targetPos.set(Predict.intercept(this, target, speed)); - if(targetPos.isZero()){ - targetPos.set(target); - } + targetPosition(target); if(Float.isNaN(rotation)){ rotation = 0; diff --git a/core/src/mindustry/world/blocks/distribution/StackConveyor.java b/core/src/mindustry/world/blocks/distribution/StackConveyor.java index ce77b978df..e7095a686c 100644 --- a/core/src/mindustry/world/blocks/distribution/StackConveyor.java +++ b/core/src/mindustry/world/blocks/distribution/StackConveyor.java @@ -200,11 +200,7 @@ public class StackConveyor extends Block implements Autotiler{ } }else{ //transfer if(state != stateLoad || (items.total() >= getMaximumAccepted(lastItem))){ - if(front() != null - && front().team == team - && front().block instanceof StackConveyor){ - StackConveyorBuild e = (StackConveyorBuild)front(); - + if(front() instanceof StackConveyorBuild e && e.team == team){ // sleep if its occupied if(e.link == -1){ e.items.addAll(items); @@ -227,7 +223,7 @@ public class StackConveyor extends Block implements Autotiler{ if(builds.first() instanceof ConveyorBuild build){ Item item = build.items.first(); if(item != null){ - handleStack(item, build.items.get(itemCapacity), null); + handleStack(item, build.items.get(item), null); } } } diff --git a/core/src/mindustry/world/consumers/ConsumeLiquidBase.java b/core/src/mindustry/world/consumers/ConsumeLiquidBase.java index f2cae7676e..47b1eb8834 100644 --- a/core/src/mindustry/world/consumers/ConsumeLiquidBase.java +++ b/core/src/mindustry/world/consumers/ConsumeLiquidBase.java @@ -23,6 +23,6 @@ public abstract class ConsumeLiquidBase extends Consume{ } protected float use(Building entity){ - return Math.min(amount * entity.delta(), entity.block.liquidCapacity); + return Math.min(amount * entity.edelta(), entity.block.liquidCapacity); } }