New power node system / Volatile generators / Drone crash fix

This commit is contained in:
Anuken
2018-07-01 10:24:14 -04:00
parent b2c99fd0fd
commit 7177e0a576
7 changed files with 62 additions and 17 deletions

View File

@@ -15,7 +15,7 @@ public class PowerBlocks extends BlockList implements ContentList {
combustionGenerator = new BurnerGenerator("combustion-generator") {{
powerOutput = 0.06f;
powerCapacity = 40f;
itemDuration = 50f;
itemDuration = 40f;
}};
thermalGenerator = new LiquidHeatGenerator("thermal-generator") {{
@@ -29,7 +29,7 @@ public class PowerBlocks extends BlockList implements ContentList {
turbineGenerator = new TurbineGenerator("turbine-generator") {{
powerOutput = 0.15f;
powerCapacity = 40f;
itemDuration = 40f;
itemDuration = 30f;
size = 2;
}};

View File

@@ -9,6 +9,7 @@ import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.entities.Units;
import io.anuke.mindustry.entities.effect.ItemDrop;
import io.anuke.mindustry.entities.traits.BuilderTrait;
import io.anuke.mindustry.entities.traits.TargetTrait;
import io.anuke.mindustry.entities.units.BaseUnit;
import io.anuke.mindustry.entities.units.FlyingUnit;
import io.anuke.mindustry.entities.units.UnitState;
@@ -151,13 +152,15 @@ public class Drone extends FlyingUnit implements BuilderTrait {
public void drawOver() {
trail.draw(Palette.lightTrail, Palette.lightTrail, 3f);
if(target instanceof TileEntity && state.is(repair)){
TargetTrait entity = target;
if(entity instanceof TileEntity && state.is(repair)){
float len = 5f;
Draw.color(Color.BLACK, Color.WHITE, 0.95f + Mathf.absin(Timers.time(), 0.8f, 0.05f));
Shapes.laser("beam", "beam-end",
x + Angles.trnsx(rotation, len),
y + Angles.trnsy(rotation, len),
target.getX(), target.getY());
entity.getX(), entity.getY());
Draw.color();
}

View File

@@ -35,5 +35,8 @@ public class PowerModule extends BlockModule{
@Override
public void read(DataInput stream) throws IOException{
amount = stream.readFloat();
if(Float.isNaN(amount)){
amount = 0f;
}
}
}

View File

@@ -19,11 +19,14 @@ import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import static io.anuke.mindustry.Vars.tilesize;
public abstract class ItemGenerator extends PowerGenerator {
protected float minItemEfficiency = 0.2f;
protected float powerOutput;
protected float itemDuration = 70f;
protected Effect generateEffect = BlockFx.generatespark;
protected Effect generateEffect = BlockFx.generatespark, explodeEffect =
BlockFx.generatespark;
protected Color heatColor = Color.valueOf("ff9b59");
public ItemGenerator(String name) {
@@ -77,14 +80,20 @@ public abstract class ItemGenerator extends PowerGenerator {
entity.generateTime -= 1f/itemDuration*mfract;
entity.power.amount += maxPower;
entity.generateTime = Mathf.clamp(entity.generateTime);
if(Mathf.chance(Timers.delta() * 0.06 * Mathf.clamp(entity.explosiveness - 0.25f))){
entity.damage(Mathf.random(8f));
Effects.effect(explodeEffect, tile.worldx() + Mathf.range(size * tilesize/2f), tile.worldy() + Mathf.range(size * tilesize/2f));
}
}
if(entity.generateTime <= 0f && entity.items.totalItems() > 0){
Effects.effect(generateEffect, tile.worldx() + Mathf.range(3f), tile.worldy() + Mathf.range(3f));
Effects.effect(generateEffect, tile.worldx() + Mathf.range(size * tilesize/2f), tile.worldy() + Mathf.range(size * tilesize/2f));
for(int i = 0; i < entity.items.items.length; i ++){
if(entity.items.items[i] > 0){
entity.items.items[i] --;
entity.efficiency = getItemEfficiency(Item.getByID(i));
entity.explosiveness = Item.getByID(i).explosiveness;
break;
}
}
@@ -104,6 +113,7 @@ public abstract class ItemGenerator extends PowerGenerator {
public static class ItemGeneratorEntity extends GeneratorEntity{
public float efficiency;
public float explosiveness;
@Override
public void write(DataOutputStream stream) throws IOException {

View File

@@ -11,6 +11,8 @@ import io.anuke.ucore.core.Timers;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.util.Mathf;
import static io.anuke.mindustry.Vars.tilesize;
public abstract class ItemLiquidGenerator extends ItemGenerator {
protected float minLiquidEfficiency = 0.2f;
protected float powerPerLiquid = 0.13f;
@@ -55,6 +57,11 @@ public abstract class ItemLiquidGenerator extends ItemGenerator {
entity.generateTime -= 1f / itemDuration * mfract;
entity.power.amount += maxPower;
entity.generateTime = Mathf.clamp(entity.generateTime);
if(Mathf.chance(Timers.delta() * 0.06 * Mathf.clamp(entity.explosiveness - 0.25f))){
entity.damage(Mathf.random(8f));
Effects.effect(explodeEffect, tile.worldx() + Mathf.range(size * tilesize/2f), tile.worldy() + Mathf.range(size * tilesize/2f));
}
}
if (entity.generateTime <= 0f && entity.items.totalItems() > 0) {
@@ -63,6 +70,7 @@ public abstract class ItemLiquidGenerator extends ItemGenerator {
if (entity.items.items[i] > 0) {
entity.items.items[i]--;
entity.efficiency = getItemEfficiency(Item.getByID(i));
entity.explosiveness = Item.getByID(i).explosiveness;
break;
}
}

View File

@@ -17,6 +17,12 @@ public class PowerDistributor extends PowerBlock {
TileEntity entity = tile.entity;
int sources = 0;
if(entity == null) return;
if(Float.isNaN(entity.power.amount)){
entity.power.amount = 0f;
}
for(GridPoint2 point : Edges.getEdges(size)){
Tile target = tile.getNearby(point);
if(target != null && target.block().hasPower &&

View File

@@ -83,11 +83,13 @@ public class PowerNode extends PowerBlock{
DistributorEntity entity = tile.entity();
other = other.target();
Tile result = other;
if(linkValid(tile, other)){
if(linked(tile, other)){
CallBlocks.unlinkPowerDistributors(null, tile, other);
threads.run(() -> CallBlocks.unlinkPowerDistributors(null, tile, result));
}else if(entity.links.size < maxNodes){
CallBlocks.linkPowerDistributors(null, tile, other);
threads.run(() -> CallBlocks.linkPowerDistributors(null, tile, result));
}
return false;
}
@@ -188,13 +190,21 @@ public class PowerNode extends PowerBlock{
}
protected boolean shouldDistribute(Tile tile, Tile other) {
return other.entity.power.amount / other.block().powerCapacity <= tile.entity.power.amount / powerCapacity;
}
protected boolean shouldLeechPower(Tile tile, Tile other){
return !(other.block() instanceof PowerNode)
|| other.entity.power.amount / other.block().powerCapacity < tile.entity.power.amount / powerCapacity;
&& other.entity.power.amount / other.block().powerCapacity > tile.entity.power.amount / powerCapacity;
}
protected void distributeLaserPower(Tile tile){
DistributorEntity entity = tile.entity();
if(Float.isNaN(entity.power.amount)){
entity.power.amount = 0f;
}
int targets = 0;
//validate everything first.
@@ -203,8 +213,8 @@ public class PowerNode extends PowerBlock{
if(!linkValid(tile, target)) {
entity.links.removeIndex(i);
i --;
}else if(shouldDistribute(tile, target)){
targets ++;
}else if(shouldDistribute(tile, target)) {
targets++;
}
}
@@ -212,11 +222,17 @@ public class PowerNode extends PowerBlock{
for(int i = 0; i < entity.links.size; i ++){
Tile target = world.tile(entity.links.get(i));
if(!shouldDistribute(tile, target)) continue;
if(shouldDistribute(tile, target)) {
float transmit = Math.min(result * Timers.delta(), entity.power.amount);
if(target.block().acceptPower(target, tile, transmit)){
entity.power.amount -= target.block().addPower(target, transmit);
float transmit = Math.min(result * Timers.delta(), entity.power.amount);
if (target.block().acceptPower(target, tile, transmit)) {
entity.power.amount -= target.block().addPower(target, transmit);
}
}else if(shouldLeechPower(tile, target)){
float diff = (target.entity.power.amount / target.block().powerCapacity - tile.entity.power.amount / powerCapacity)/1.4f;
float transmit = Math.min(Math.min(target.block().powerCapacity * diff, target.entity.power.amount), powerCapacity - tile.entity.power.amount);
entity.power.amount += transmit;
target.entity.power.amount -= transmit;
}
}
}
@@ -226,8 +242,7 @@ public class PowerNode extends PowerBlock{
}
protected boolean linkValid(Tile tile, Tile link){
if(!(tile != link && link != null && link.block().hasPower)
|| link.block() instanceof PowerGenerator) return false;
if(!(tile != link && link != null && link.block().hasPower)) return false;
if(link.block() instanceof PowerNode){
DistributorEntity oe = link.entity();