Heat turret support

This commit is contained in:
Anuken
2021-12-07 13:48:21 -05:00
parent 3644825dc5
commit c51e755f71
4 changed files with 55 additions and 18 deletions

View File

@@ -22,6 +22,7 @@ import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.logic.*;
import mindustry.type.*;
import mindustry.ui.*;
import mindustry.world.blocks.*;
import mindustry.world.draw.*;
import mindustry.world.meta.*;
@@ -56,6 +57,8 @@ public class Turret extends ReloadTurret{
public int maxAmmo = 30;
public int ammoPerShot = 1;
public float heatRequirement = -1f;
public float maxHeatEfficiency = 3f;
//TODO all the fields below should be deprecated and moved into a ShootPattern class or similar
//TODO ...however, it would be nice to unify the weapon and turret systems into one.
@@ -143,6 +146,20 @@ public class Turret extends ReloadTurret{
stats.add(Stat.targetsAir, targetAir);
stats.add(Stat.targetsGround, targetGround);
if(ammoPerShot != 1) stats.add(Stat.ammoUse, ammoPerShot, StatUnit.perShot);
if(heatRequirement > 0) stats.add(Stat.input, heatRequirement, StatUnit.heatUnits);
}
@Override
public void setBars(){
super.setBars();
if(heatRequirement > 0){
bars.add("heat", (TurretBuild entity) ->
new Bar(() ->
Core.bundle.format("bar.heatpercent", (int)entity.heatReq, (int)(Math.min(entity.heatReq / heatRequirement, maxHeatEfficiency) * 100)),
() -> Pal.lightOrange,
() -> entity.heatReq / heatRequirement));
}
}
@Override
@@ -194,6 +211,9 @@ public class Turret extends ReloadTurret{
public BlockUnitc unit = (BlockUnitc)UnitTypes.block.create(team);
public boolean wasShooting, charging;
public float heatReq;
public float[] sideHeat = new float[4];
@Override
public float warmup(){
return shootWarmup;
@@ -324,6 +344,10 @@ public class Turret extends ReloadTurret{
logicControlTime -= Time.delta;
}
if(heatRequirement > 0){
heatReq = calculateHeat(sideHeat);
}
//turret always reloads regardless of whether it's targeting something
updateReload();
@@ -403,6 +427,14 @@ public class Turret extends ReloadTurret{
return !charging;
}
@Override
public float efficiency(){
if(heatRequirement > 0){
return Math.min(heatReq / heatRequirement, maxHeatEfficiency) * super.efficiency();
}
return super.efficiency();
}
/** Consume ammo and return a type. */
public BulletType useAmmo(){
if(cheating()) return peekAmmo();

View File

@@ -2,14 +2,10 @@ package mindustry.world.blocks.production;
import arc.*;
import arc.math.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.ui.*;
import mindustry.world.blocks.heat.*;
import mindustry.world.meta.*;
import java.util.*;
/** A crafter that requires contact from heater blocks to craft. */
public class HeatCrafter extends GenericCrafter{
/** Base heat requirement for 100% efficiency. */
@@ -48,19 +44,8 @@ public class HeatCrafter extends GenericCrafter{
@Override
public void updateTile(){
Arrays.fill(sideHeat, 0f);
heat = 0f;
heat = calculateHeat(sideHeat);
for(var edge : getEdges()){
Building build = nearby(edge.x, edge.y);
if(build != null && build.team == team && build instanceof HeatBlock heater && (!build.block.rotate || (relativeTo(build) + 2) % 4 == build.rotation)){
//heat is distributed across building size
float add = heater.heat() / build.block.size;
sideHeat[Mathf.mod(relativeTo(build), 4)] += add;
heat += add;
}
}
super.updateTile();
}