mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-11 03:08:38 +07:00
Crashy storage graph implementation
This commit is contained in:
parent
4668a6d8c0
commit
80f5b4c3b7
@ -322,9 +322,9 @@ public class BlockFx extends FxList implements ContentList{
|
||||
});
|
||||
|
||||
shieldBreak = new Effect(40, e -> {
|
||||
Draw.color(Color.WHITE);
|
||||
Draw.color(Palette.accent);
|
||||
Lines.stroke(3f * e.fout());
|
||||
Lines.poly(e.x, e.y, 6, e.rotation, 90);
|
||||
Lines.poly(e.x, e.y, 6, e.rotation + e.fin(), 90);
|
||||
Draw.reset();
|
||||
});
|
||||
}
|
||||
|
@ -96,12 +96,6 @@ public class FogRenderer implements Disposable{
|
||||
}));
|
||||
}
|
||||
|
||||
public void setLoadingOffset(int x, int y){
|
||||
isOffseted = true;
|
||||
offsettedX = x;
|
||||
offsettedY = y;
|
||||
}
|
||||
|
||||
public void writeFog(){
|
||||
if(buffer == null) return;
|
||||
|
||||
|
@ -7,9 +7,11 @@ import io.anuke.mindustry.content.fx.BulletFx;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.traits.AbsorbTrait;
|
||||
import io.anuke.mindustry.graphics.Palette;
|
||||
import io.anuke.mindustry.world.BarType;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquidFilter;
|
||||
import io.anuke.mindustry.world.meta.BlockBar;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
@ -68,6 +70,13 @@ public class ForceProjector extends Block {
|
||||
stats.add(BlockStat.powerDamage, powerDamage, StatUnit.powerUnits);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBars(){
|
||||
super.setBars();
|
||||
|
||||
bars.add(new BlockBar(BarType.heat, true, tile -> tile.<ForceEntity>entity().buildup / breakage));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
ForceEntity entity = tile.entity();
|
||||
@ -91,7 +100,7 @@ public class ForceProjector extends Block {
|
||||
}
|
||||
|
||||
if(!entity.cons.valid() && !cheat){
|
||||
entity.warmup = Mathf.lerpDelta(entity.warmup, 0f, 0.1f);
|
||||
entity.warmup = Mathf.lerpDelta(entity.warmup, 0f, 0.15f);
|
||||
if(entity.warmup <= 0.09f){
|
||||
entity.broken = true;
|
||||
}
|
||||
@ -136,6 +145,10 @@ public class ForceProjector extends Block {
|
||||
float hit = trait.getShieldDamage()*powerDamage;
|
||||
entity.hit = 1f;
|
||||
entity.power.amount -= Math.min(hit, entity.power.amount);
|
||||
|
||||
if(entity.power.amount <= 0.0001f){
|
||||
entity.buildup += trait.getShieldDamage() * entity.warmup*2f;
|
||||
}
|
||||
entity.buildup += trait.getShieldDamage() * entity.warmup;
|
||||
}
|
||||
});
|
||||
|
@ -45,6 +45,7 @@ public class PhaseWeaver extends PowerSmelter{
|
||||
Shaders.build.region = weaveRegion;
|
||||
Shaders.build.progress = progress;
|
||||
Shaders.build.color.set(Palette.accent);
|
||||
Shaders.build.color.a = entity.heat;
|
||||
Shaders.build.time = -entity.time / 10f;
|
||||
|
||||
Graphics.shader(Shaders.build, false);
|
||||
@ -53,6 +54,7 @@ public class PhaseWeaver extends PowerSmelter{
|
||||
Graphics.shader();
|
||||
|
||||
Draw.color(Palette.accent);
|
||||
Draw.alpha(entity.heat);
|
||||
|
||||
Lines.lineAngleCenter(
|
||||
tile.drawx() + Mathf.sin(entity.time, 6f, Vars.tilesize / 3f * size),
|
||||
|
@ -242,7 +242,7 @@ public class CoreBlock extends StorageBlock{
|
||||
return new CoreEntity();
|
||||
}
|
||||
|
||||
public class CoreEntity extends TileEntity implements SpawnerTrait{
|
||||
public class CoreEntity extends StorageEntity implements SpawnerTrait{
|
||||
public Unit currentUnit;
|
||||
int droneID = -1;
|
||||
boolean solid = true;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.anuke.mindustry.world.blocks.storage;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
@ -17,6 +18,42 @@ public abstract class StorageBlock extends Block{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProximityUpdate(Tile tile){
|
||||
super.onProximityUpdate(tile);
|
||||
StorageEntity entity = tile.entity();
|
||||
entity.graph.add(tile);
|
||||
|
||||
for(Tile prox : tile.entity.proximity()){
|
||||
if(prox.block() instanceof StorageBlock){
|
||||
StorageEntity other = prox.entity();
|
||||
entity.graph.merge(other.graph);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removed(Tile tile){
|
||||
super.removed(tile);
|
||||
StorageEntity entity = tile.entity();
|
||||
entity.graph.remove(tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity newEntity(){
|
||||
return new StorageEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Array<Object> getDebugInfo(Tile tile){
|
||||
Array<Object> arr = super.getDebugInfo(tile);
|
||||
|
||||
StorageEntity entity = tile.entity();
|
||||
arr.addAll("storage graph", entity.graph.getID());
|
||||
|
||||
return arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an item and returns it. If item is not null, it should return the item.
|
||||
* Returns null if no items are there.
|
||||
@ -48,4 +85,8 @@ public abstract class StorageBlock extends Block{
|
||||
return entity.items.has(item);
|
||||
}
|
||||
}
|
||||
|
||||
public class StorageEntity extends TileEntity{
|
||||
public StorageGraph graph = new StorageGraph();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,79 @@
|
||||
package io.anuke.mindustry.world.blocks.storage;
|
||||
|
||||
import com.badlogic.gdx.utils.IntSet;
|
||||
import com.badlogic.gdx.utils.ObjectSet;
|
||||
import com.badlogic.gdx.utils.Queue;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.storage.StorageBlock.StorageEntity;
|
||||
|
||||
public class StorageGraph{
|
||||
private static IntSet closedSet = new IntSet();
|
||||
private static Queue<Tile> queue = new Queue<>();
|
||||
private static int lastID;
|
||||
|
||||
private ObjectSet<Tile> tiles = new ObjectSet<>();
|
||||
private int cores;
|
||||
private int id = lastID++;
|
||||
|
||||
public void add(Tile tile){
|
||||
if(tiles.add(tile) && tile.block() instanceof CoreBlock){
|
||||
cores ++;
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(Tile tile){
|
||||
for(Tile other : tiles){
|
||||
other.<StorageEntity>entity().graph = null;
|
||||
}
|
||||
|
||||
if(tiles.remove(tile) && tile.block() instanceof CoreBlock){
|
||||
cores --;
|
||||
}
|
||||
|
||||
cores = 0;
|
||||
|
||||
for(Tile other : tile.entity.proximity()){
|
||||
if(other.block() instanceof StorageBlock){
|
||||
reflow(tile, other);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void reflow(Tile base, Tile tile){
|
||||
queue.clear();
|
||||
queue.addLast(tile);
|
||||
closedSet.clear();
|
||||
while(queue.size > 0){
|
||||
Tile child = queue.removeFirst();
|
||||
StorageEntity entity = child.entity();
|
||||
entity.graph = this;
|
||||
add(child);
|
||||
for(Tile next : child.entity.proximity()){
|
||||
if(next != base && next.block() instanceof StorageBlock && next.<StorageEntity>entity().graph == null && !closedSet.contains(next.packedPosition())){
|
||||
queue.addLast(next);
|
||||
closedSet.add(next.packedPosition());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void merge(StorageGraph other){
|
||||
if(this == other) return;
|
||||
|
||||
for(Tile tile : other.tiles){
|
||||
StorageEntity e = tile.entity();
|
||||
e.graph = this;
|
||||
}
|
||||
|
||||
tiles.addAll(other.tiles);
|
||||
cores += other.cores;
|
||||
}
|
||||
|
||||
public boolean hasCores(){
|
||||
return cores > 0;
|
||||
}
|
||||
|
||||
public int getID(){
|
||||
return id;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user