ContinuousTurret ammo display
This commit is contained in:
@@ -5,6 +5,7 @@ import arc.struct.*;
|
|||||||
import mindustry.entities.bullet.*;
|
import mindustry.entities.bullet.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.logic.*;
|
import mindustry.logic.*;
|
||||||
|
import mindustry.world.consumers.*;
|
||||||
import mindustry.world.meta.*;
|
import mindustry.world.meta.*;
|
||||||
|
|
||||||
/** A turret that fires a continuous beam bullet with no reload or coolant necessary. The bullet only disappears when the turret stops shooting. */
|
/** A turret that fires a continuous beam bullet with no reload or coolant necessary. The bullet only disappears when the turret stops shooting. */
|
||||||
@@ -55,6 +56,19 @@ public class ContinuousTurret extends Turret{
|
|||||||
public void updateTile(){
|
public void updateTile(){
|
||||||
super.updateTile();
|
super.updateTile();
|
||||||
|
|
||||||
|
//unclean way of calculating ammo fraction to display
|
||||||
|
float ammoFract = efficiency();
|
||||||
|
var liq = consumes.getOrNull(ConsumeType.liquid);
|
||||||
|
if(liq instanceof ConsumeLiquids cons){
|
||||||
|
for(var stack : cons.liquids){
|
||||||
|
ammoFract = Math.min(ammoFract, liquids.get(stack.liquid) / liquidCapacity);
|
||||||
|
}
|
||||||
|
}else if(liq instanceof ConsumeLiquid cons){
|
||||||
|
ammoFract = Math.min(ammoFract, liquids.get(cons.liquid) / liquidCapacity);
|
||||||
|
}
|
||||||
|
|
||||||
|
unit.ammo(unit.type().ammoCapacity * ammoFract);
|
||||||
|
|
||||||
if(bullet != null){
|
if(bullet != null){
|
||||||
//check to see if bullet despawned
|
//check to see if bullet despawned
|
||||||
if(bullet.owner != this || !bullet.isAdded() || bullet.type == null){
|
if(bullet.owner != this || !bullet.isAdded() || bullet.type == null){
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ public class Turret extends ReloadTurret{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldConsume(){
|
public boolean shouldConsume(){
|
||||||
return isActive();
|
return isShooting();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -290,8 +290,8 @@ public class Turret extends ReloadTurret{
|
|||||||
public void updateTile(){
|
public void updateTile(){
|
||||||
if(!validateTarget()) target = null;
|
if(!validateTarget()) target = null;
|
||||||
|
|
||||||
//TODO can be lerp instead, that's smoother
|
//TODO make it approach instead and add interp curves to parts
|
||||||
shootWarmup = Mathf.lerpDelta(shootWarmup, isShooting() ? 1f : 0f, shootWarmupSpeed);
|
shootWarmup = Mathf.lerpDelta(shootWarmup, isShooting() && cons.canConsume() ? 1f : 0f, shootWarmupSpeed);
|
||||||
|
|
||||||
wasShooting = false;
|
wasShooting = false;
|
||||||
|
|
||||||
|
|||||||
@@ -126,6 +126,11 @@ public class Consumers{
|
|||||||
return (T)map[type.ordinal()];
|
return (T)map[type.ordinal()];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public <T extends Consume> T getOrNull(ConsumeType type){
|
||||||
|
return (T)map[type.ordinal()];
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public Consume[] all(){
|
public Consume[] all(){
|
||||||
return results;
|
return results;
|
||||||
|
|||||||
Reference in New Issue
Block a user