1
0
mirror of https://github.com/Anuken/Mindustry.git synced 2024-11-13 07:15:28 +03:00

Correct liquid boost display for turrets

This commit is contained in:
Anuken 2019-10-21 17:50:26 -04:00
parent ad5cb37ed5
commit 01f6fff823
9 changed files with 98 additions and 37 deletions

View File

@ -1616,7 +1616,7 @@ public class Blocks implements ContentList{
size = 4;
shootShake = 2f;
range = 190f;
reload = 50f;
reload = 80f;
firingMoveFract = 0.5f;
shootDuration = 220f;
powerUse = 14f;
@ -1633,7 +1633,7 @@ public class Blocks implements ContentList{
draugFactory = new UnitFactory("draug-factory"){{
requirements(Category.units, ItemStack.with(Items.copper, 30, Items.lead, 70));
type = UnitTypes.draug;
unitType = UnitTypes.draug;
produceTime = 2500;
size = 2;
maxSpawn = 1;
@ -1643,7 +1643,7 @@ public class Blocks implements ContentList{
spiritFactory = new UnitFactory("spirit-factory"){{
requirements(Category.units, ItemStack.with(Items.metaglass, 45, Items.lead, 55, Items.silicon, 45));
type = UnitTypes.spirit;
unitType = UnitTypes.spirit;
produceTime = 4000;
size = 2;
maxSpawn = 1;
@ -1653,7 +1653,7 @@ public class Blocks implements ContentList{
phantomFactory = new UnitFactory("phantom-factory"){{
requirements(Category.units, ItemStack.with(Items.titanium, 50, Items.thorium, 60, Items.lead, 65, Items.silicon, 105));
type = UnitTypes.phantom;
unitType = UnitTypes.phantom;
produceTime = 4400;
size = 2;
maxSpawn = 1;
@ -1670,7 +1670,7 @@ public class Blocks implements ContentList{
wraithFactory = new UnitFactory("wraith-factory"){{
requirements(Category.units, ItemStack.with(Items.titanium, 30, Items.lead, 40, Items.silicon, 45));
type = UnitTypes.wraith;
unitType = UnitTypes.wraith;
produceTime = 700;
size = 2;
consumes.power(0.5f);
@ -1679,7 +1679,7 @@ public class Blocks implements ContentList{
ghoulFactory = new UnitFactory("ghoul-factory"){{
requirements(Category.units, ItemStack.with(Items.titanium, 75, Items.lead, 65, Items.silicon, 110));
type = UnitTypes.ghoul;
unitType = UnitTypes.ghoul;
produceTime = 1150;
size = 3;
consumes.power(1.2f);
@ -1688,7 +1688,7 @@ public class Blocks implements ContentList{
revenantFactory = new UnitFactory("revenant-factory"){{
requirements(Category.units, ItemStack.with(Items.plastanium, 50, Items.titanium, 150, Items.lead, 150, Items.silicon, 200));
type = UnitTypes.revenant;
unitType = UnitTypes.revenant;
produceTime = 2000;
size = 4;
consumes.power(3f);
@ -1697,7 +1697,7 @@ public class Blocks implements ContentList{
daggerFactory = new UnitFactory("dagger-factory"){{
requirements(Category.units, ItemStack.with(Items.lead, 55, Items.silicon, 35));
type = UnitTypes.dagger;
unitType = UnitTypes.dagger;
produceTime = 850;
size = 2;
consumes.power(0.5f);
@ -1706,7 +1706,7 @@ public class Blocks implements ContentList{
crawlerFactory = new UnitFactory("crawler-factory"){{
requirements(Category.units, ItemStack.with(Items.lead, 45, Items.silicon, 30));
type = UnitTypes.crawler;
unitType = UnitTypes.crawler;
produceTime = 300;
size = 2;
maxSpawn = 6;
@ -1716,7 +1716,7 @@ public class Blocks implements ContentList{
titanFactory = new UnitFactory("titan-factory"){{
requirements(Category.units, ItemStack.with(Items.graphite, 50, Items.lead, 50, Items.silicon, 45));
type = UnitTypes.titan;
unitType = UnitTypes.titan;
produceTime = 1050;
size = 3;
consumes.power(0.60f);
@ -1725,7 +1725,7 @@ public class Blocks implements ContentList{
fortressFactory = new UnitFactory("fortress-factory"){{
requirements(Category.units, ItemStack.with(Items.thorium, 40, Items.lead, 110, Items.silicon, 75));
type = UnitTypes.fortress;
unitType = UnitTypes.fortress;
produceTime = 2000;
size = 3;
maxSpawn = 3;

View File

@ -112,7 +112,11 @@ public class ContentLoader{
try{
callable.accept(content);
}catch(Throwable e){
mods.handleError(e, content.mod);
if(content.mod != null){
mods.handleError(e, content.mod);
}else{
throw new RuntimeException(e);
}
}
}
}

View File

@ -2,8 +2,7 @@ package io.anuke.mindustry.entities;
import io.anuke.annotations.Annotations.Struct;
import io.anuke.arc.*;
import io.anuke.arc.collection.GridBits;
import io.anuke.arc.collection.IntQueue;
import io.anuke.arc.collection.*;
import io.anuke.arc.function.*;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.math.Mathf;
@ -32,6 +31,7 @@ public class Damage{
private static Vector2 tr = new Vector2();
private static GridBits bits = new GridBits(30, 30);
private static IntQueue propagation = new IntQueue();
private static IntSet collidedBlocks = new IntSet();
/** Creates a dynamic explosion based on specified parameters. */
public static void dynamicExplosion(float x, float y, float flammability, float explosiveness, float power, float radius, Color color){
@ -88,11 +88,13 @@ public class Damage{
* Only enemies of the specified team are damaged.
*/
public static void collideLine(Bullet hitter, Team team, Effect effect, float x, float y, float angle, float length, boolean large){
collidedBlocks.clear();
tr.trns(angle, length);
IntPositionConsumer collider = (cx, cy) -> {
Tile tile = world.ltile(cx, cy);
if(tile != null && tile.entity != null && tile.getTeamID() != team.ordinal() && tile.entity.collide(hitter)){
if(tile != null && !collidedBlocks.contains(tile.pos()) && tile.entity != null && tile.getTeamID() != team.ordinal() && tile.entity.collide(hitter)){
tile.entity.collision(hitter);
collidedBlocks.add(tile.pos());
hitter.getBulletType().hit(hitter, tile.worldx(), tile.worldy());
}
};

View File

@ -49,7 +49,7 @@ public class ContentDisplay{
for(BlockStat stat : map.keys()){
table.table(inset -> {
inset.left();
inset.add("[LIGHT_GRAY]" + stat.localized() + ":[] ");
inset.add("[LIGHT_GRAY]" + stat.localized() + ":[] ").left();
Array<StatValue> arr = map.get(stat);
for(StatValue value : arr){
value.display(inset);

View File

@ -11,6 +11,7 @@ import io.anuke.mindustry.type.*;
import io.anuke.mindustry.world.*;
import io.anuke.mindustry.world.consumers.*;
import io.anuke.mindustry.world.meta.*;
import io.anuke.mindustry.world.meta.values.*;
import static io.anuke.mindustry.Vars.tilesize;
@ -31,9 +32,7 @@ public class CooledTurret extends Turret{
public void setStats(){
super.setStats();
float maxUsed = consumes.<ConsumeLiquidBase>get(ConsumeType.liquid).amount;
stats.add(BlockStat.boostEffect, 1f + maxUsed * coolantMultiplier, StatUnit.timesSpeed);
stats.add(BlockStat.booster, new BoosterListValue(reload, consumes.<ConsumeLiquidBase>get(ConsumeType.liquid).amount, coolantMultiplier, true, l -> consumes.liquidfilters.get(l.id)));
}
@Override

View File

@ -1,17 +1,15 @@
package io.anuke.mindustry.world.blocks.defense.turrets;
import io.anuke.arc.math.Angles;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.util.Time;
import io.anuke.mindustry.entities.Effects;
import io.anuke.mindustry.entities.type.Bullet;
import io.anuke.mindustry.entities.bullet.BulletType;
import io.anuke.mindustry.entities.type.TileEntity;
import io.anuke.mindustry.type.Liquid;
import io.anuke.mindustry.world.Tile;
import io.anuke.arc.math.*;
import io.anuke.arc.util.*;
import io.anuke.mindustry.entities.*;
import io.anuke.mindustry.entities.bullet.*;
import io.anuke.mindustry.entities.type.*;
import io.anuke.mindustry.type.*;
import io.anuke.mindustry.world.*;
import io.anuke.mindustry.world.consumers.*;
import io.anuke.mindustry.world.meta.BlockStat;
import io.anuke.mindustry.world.meta.StatUnit;
import io.anuke.mindustry.world.meta.*;
import io.anuke.mindustry.world.meta.values.*;
import static io.anuke.mindustry.Vars.tilesize;
@ -24,13 +22,15 @@ public class LaserTurret extends PowerTurret{
canOverdrive = false;
consumes.add(new ConsumeLiquidFilter(liquid -> liquid.temperature <= 0.5f && liquid.flammability < 0.1f, 0.01f)).update(false);
coolantMultiplier = 1f;
}
@Override
public void setStats(){
super.setStats();
stats.remove(BlockStat.boostEffect);
stats.remove(BlockStat.booster);
stats.add(BlockStat.input, new BoosterListValue(reload, consumes.<ConsumeLiquidBase>get(ConsumeType.liquid).amount, coolantMultiplier, false, l -> consumes.liquidfilters.get(l.id)));
stats.remove(BlockStat.damage);
//damages every 5 ticks, at least in meltdown's case
stats.add(BlockStat.damage, shootType.damage * 60f / 5f, StatUnit.perSecond);
@ -74,7 +74,7 @@ public class LaserTurret extends PowerTurret{
Liquid liquid = entity.liquids.current();
float maxUsed = consumes.<ConsumeLiquidBase>get(ConsumeType.liquid).amount;
float used = baseReloadSpeed(tile) * (tile.isEnemyCheat() ? maxUsed : Math.min(entity.liquids.get(liquid), maxUsed * Time.delta()));
float used = baseReloadSpeed(tile) * (tile.isEnemyCheat() ? maxUsed : Math.min(entity.liquids.get(liquid), maxUsed * Time.delta())) * liquid.heatCapacity * coolantMultiplier;
entity.reload += used;
entity.liquids.remove(liquid, used);

View File

@ -27,7 +27,7 @@ import java.io.*;
import static io.anuke.mindustry.Vars.*;
public class UnitFactory extends Block{
protected UnitType type;
protected UnitType unitType;
protected float produceTime = 1000f;
protected float launchVelocity = 0f;
protected TextureRegion topRegion;
@ -57,7 +57,7 @@ public class UnitFactory extends Block{
Effects.effect(Fx.producesmoke, tile.drawx(), tile.drawy());
if(!net.client()){
BaseUnit unit = factory.type.create(tile.getTeam());
BaseUnit unit = factory.unitType.create(tile.getTeam());
unit.setSpawner(tile);
unit.set(tile.drawx() + Mathf.range(4), tile.drawy() + Mathf.range(4));
unit.add();
@ -122,7 +122,7 @@ public class UnitFactory extends Block{
@Override
public void draw(Tile tile){
UnitFactoryEntity entity = tile.entity();
TextureRegion region = type.icon(Cicon.full);
TextureRegion region = unitType.icon(Cicon.full);
Draw.rect(name, tile.drawx(), tile.drawy());
@ -170,7 +170,7 @@ public class UnitFactory extends Block{
entity.buildTime = 0f;
Call.onUnitFactorySpawn(tile, entity.spawned + 1);
useContent(tile, type);
useContent(tile, unitType);
entity.cons.trigger();
}

View File

@ -0,0 +1,56 @@
package io.anuke.mindustry.world.meta.values;
import io.anuke.arc.*;
import io.anuke.arc.function.*;
import io.anuke.arc.scene.ui.layout.*;
import io.anuke.arc.util.*;
import io.anuke.mindustry.game.*;
import io.anuke.mindustry.gen.*;
import io.anuke.mindustry.type.*;
import io.anuke.mindustry.world.meta.*;
import static io.anuke.mindustry.Vars.content;
public class BoosterListValue implements StatValue{
protected float reload, maxUsed, multiplier;
protected boolean baseReload;
protected Predicate<Liquid> filter;
public BoosterListValue(float reload, float maxUsed, float multiplier, boolean baseReload, Predicate<Liquid> filter){
this.reload = reload;
this.maxUsed = maxUsed;
this.baseReload = baseReload;
this.multiplier = multiplier;
this.filter = filter;
}
@Override
public void display(Table table){
table.row();
table.table(c -> {
for(Liquid liquid : content.liquids()){
if(!filter.test(liquid)) continue;
c.addImage(liquid.icon(Cicon.medium)).size(3 * 8).padRight(4).right().top();
c.add(liquid.localizedName()).padRight(10).left().top();
c.table(Tex.underline, bt -> {
bt.left().defaults().padRight(3).left();
float reloadRate = (baseReload ? 1f : 0f) + maxUsed * multiplier * liquid.heatCapacity;
float standardReload = baseReload ? reload : reload / (maxUsed * multiplier * 0.4f);
float result = standardReload / (reload / reloadRate);
bt.add(Core.bundle.format("bullet.reload", Strings.fixed(result, 1)));
}).left().padTop(-9);
c.row();
}
}).colspan(table.getColumns());
table.row();
}
void sep(Table table, String text){
table.row();
table.add(text);
}
}

View File

@ -32,7 +32,7 @@ public class DirectConsumerTests extends PowerTestFixture{
void testUnitFactory(int siliconAmount, int leadAmount, float producedPower, float requestedPower, float expectedSatisfaction){
Tile consumerTile = createFakeTile(0, 0, new UnitFactory("fakefactory"){{
type = UnitTypes.spirit;
unitType = UnitTypes.spirit;
produceTime = 60;
consumes.power(requestedPower);
consumes.items(new ItemStack(Items.silicon, 30), new ItemStack(Items.lead, 30));