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

@ -33,6 +33,7 @@ import mindustry.world.*;
import mindustry.world.blocks.ConstructBlock.*;
import mindustry.world.blocks.*;
import mindustry.world.blocks.environment.*;
import mindustry.world.blocks.heat.*;
import mindustry.world.blocks.logic.LogicBlock.*;
import mindustry.world.blocks.payloads.*;
import mindustry.world.blocks.power.*;
@ -40,6 +41,8 @@ import mindustry.world.consumers.*;
import mindustry.world.meta.*;
import mindustry.world.modules.*;
import java.util.*;
import static mindustry.Vars.*;
@EntityDef(value = {Buildingc.class}, isFinal = false, genio = false, serialize = false)
@ -281,6 +284,23 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
return true;
}
public float calculateHeat(float[] sideHeat){
Arrays.fill(sideHeat, 0f);
float heat = 0f;
for(var edge : block.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;
}
}
return heat;
}
public void applyBoost(float intensity, float duration){
//do not refresh time scale when getting a weaker intensity
if(intensity >= this.timeScale - 0.001f){

View File

@ -176,7 +176,7 @@ public class ErekirPlanetGenerator extends PlanetGenerator{
tiles.getn(endX, endY).setOverlay(Blocks.spawn);
//TODO tech is lazy and boring
tech(Blocks.darkPanel3, Blocks.darkPanel5, Blocks.darkMetal);
//tech(Blocks.darkPanel3, Blocks.darkPanel5, Blocks.darkMetal);
//ores
pass((x, y) -> {
@ -234,7 +234,7 @@ public class ErekirPlanetGenerator extends PlanetGenerator{
}
}
decoration(0.015f);
decoration(0.017f);
//not allowed
state.rules.hiddenBuildItems.addAll(Items.copper, Items.titanium, Items.coal, Items.lead, Items.blastCompound, Items.pyratite, Items.sporePod, Items.metaglass, Items.plastanium);

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();
}