mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-13 01:07:30 +07:00
Added direct core-vault chaining
This commit is contained in:
@ -481,6 +481,7 @@ bar.powerbalance = Power: {0}/s
|
||||
bar.poweramount = Power: {0}
|
||||
bar.poweroutput = Power Output: {0}
|
||||
bar.items = Items: {0}
|
||||
bar.capacity = Capacity: {0}
|
||||
bar.liquid = Liquid
|
||||
bar.heat = Heat
|
||||
bar.power = Power
|
||||
|
@ -207,14 +207,12 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
||||
if(other == null) continue;
|
||||
if(other.entity == null || !(other.interactable(tile.getTeam()))) continue;
|
||||
|
||||
other.block().onProximityUpdate(other);
|
||||
|
||||
tmpTiles.add(other);
|
||||
|
||||
//add this tile to proximity of nearby tiles
|
||||
if(!other.entity.proximity.contains(tile, true)){
|
||||
other.entity.proximity.add(tile);
|
||||
}
|
||||
|
||||
tmpTiles.add(other);
|
||||
}
|
||||
|
||||
//using a set to prevent duplicates
|
||||
@ -224,6 +222,10 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
||||
|
||||
block.onProximityAdded(tile);
|
||||
block.onProximityUpdate(tile);
|
||||
|
||||
for(Tile other : tmpTiles){
|
||||
other.block().onProximityUpdate(other);
|
||||
}
|
||||
}
|
||||
|
||||
public Array<Tile> proximity(){
|
||||
|
@ -47,6 +47,6 @@ public class ThermalGenerator extends PowerGenerator{
|
||||
@Override
|
||||
public boolean canPlaceOn(Tile tile){
|
||||
//make sure there's heat at this location
|
||||
return tile.getLinkedTilesAs(this, tempTiles).sum(other -> other.floor().attributes.get(Attribute.heat)) > 0.01f;
|
||||
return tile.getLinkedTilesAs(this, tempTiles).sumf(other -> other.floor().attributes.get(Attribute.heat)) > 0.01f;
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,11 @@ package io.anuke.mindustry.world.blocks.storage;
|
||||
import io.anuke.annotations.Annotations.*;
|
||||
import io.anuke.arc.*;
|
||||
import io.anuke.arc.collection.*;
|
||||
import io.anuke.arc.collection.ObjectSet.*;
|
||||
import io.anuke.arc.function.*;
|
||||
import io.anuke.arc.graphics.g2d.*;
|
||||
import io.anuke.arc.math.*;
|
||||
import io.anuke.arc.math.geom.*;
|
||||
import io.anuke.mindustry.content.*;
|
||||
import io.anuke.mindustry.entities.*;
|
||||
import io.anuke.mindustry.entities.traits.*;
|
||||
@ -12,9 +16,11 @@ import io.anuke.mindustry.game.EventType.*;
|
||||
import io.anuke.mindustry.gen.*;
|
||||
import io.anuke.mindustry.graphics.*;
|
||||
import io.anuke.mindustry.type.*;
|
||||
import io.anuke.mindustry.ui.*;
|
||||
import io.anuke.mindustry.world.*;
|
||||
import io.anuke.mindustry.world.blocks.*;
|
||||
import io.anuke.mindustry.world.meta.*;
|
||||
import io.anuke.mindustry.world.modules.*;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
@ -46,19 +52,80 @@ public class CoreBlock extends StorageBlock{
|
||||
entity.spawnPlayer = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
||||
bars.add("capacity", e ->
|
||||
new Bar(
|
||||
() -> Core.bundle.format("bar.capacity", ui.formatAmount(((CoreEntity)e).storageCapacity)),
|
||||
() -> Pal.items,
|
||||
() -> e.items.total() / (float)(((CoreEntity)e).storageCapacity * content.items().count(i -> i.type == ItemType.material))
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
return tile.entity.items.get(item) < getMaximumAccepted(tile, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaximumAccepted(Tile tile, Item item){
|
||||
return item.type == ItemType.material ? itemCapacity * state.teams.get(tile.getTeam()).cores.size : 0;
|
||||
CoreEntity entity = tile.entity();
|
||||
return item.type == ItemType.material ? entity.storageCapacity : entity.storageCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProximityUpdate(Tile tile){
|
||||
CoreEntity entity = tile.entity();
|
||||
|
||||
for(Tile other : state.teams.get(tile.getTeam()).cores){
|
||||
if(other != tile){
|
||||
tile.entity.items = other.entity.items;
|
||||
entity.items = other.entity.items;
|
||||
}
|
||||
}
|
||||
state.teams.get(tile.getTeam()).cores.add(tile);
|
||||
|
||||
entity.storageCapacity = entity.proximity().sum(e -> isContainer(e) ? e.block().itemCapacity : 0);
|
||||
entity.proximity().each(this::isContainer, t -> {
|
||||
t.entity.items = entity.items;
|
||||
t.<StorageBlockEntity>entity().linkedCore = tile;
|
||||
});
|
||||
|
||||
for(Tile other : state.teams.get(tile.getTeam()).cores){
|
||||
entity.storageCapacity += other.block().itemCapacity;
|
||||
}
|
||||
|
||||
for(Item item : content.items()){
|
||||
entity.items.set(item, Math.min(entity.items.get(item), entity.storageCapacity));
|
||||
}
|
||||
|
||||
for(Tile other : state.teams.get(tile.getTeam()).cores){
|
||||
CoreEntity oe = other.entity();
|
||||
oe.storageCapacity = entity.storageCapacity;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawSelect(Tile tile){
|
||||
Lines.stroke(1f, Pal.accent);
|
||||
Consumer<Tile> outline = t -> {
|
||||
for(int i = 0; i < 4; i++){
|
||||
Point2 p = Geometry.d8edge[i];
|
||||
float offset = -Math.max(t.block().size - 1, 0) / 2f * tilesize;
|
||||
Draw.rect("block-select", t.drawx() + offset * p.x, t.drawy() + offset * p.y, i * 90);
|
||||
}
|
||||
};
|
||||
if(tile.entity.proximity().contains(e -> isContainer(e) && e.entity.items == tile.entity.items)){
|
||||
outline.accept(tile);
|
||||
}
|
||||
tile.entity.proximity().each(e -> isContainer(e) && e.entity.items == tile.entity.items, outline);
|
||||
Draw.reset();
|
||||
}
|
||||
|
||||
|
||||
public boolean isContainer(Tile tile){
|
||||
return tile.entity instanceof StorageBlockEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -68,12 +135,28 @@ public class CoreBlock extends StorageBlock{
|
||||
|
||||
@Override
|
||||
public void removed(Tile tile){
|
||||
int total = tile.entity.proximity().count(e -> e.entity.items == tile.entity.items);
|
||||
float fract = 1f / total / state.teams.get(tile.getTeam()).cores.size;
|
||||
|
||||
tile.entity.proximity().each(e -> isContainer(e) && e.entity.items == tile.entity.items, t -> {
|
||||
StorageBlockEntity ent = (StorageBlockEntity)t.entity;
|
||||
ent.linkedCore = null;
|
||||
ent.items = new ItemModule();
|
||||
for(Item item : content.items()){
|
||||
ent.items.set(item, (int)(fract * tile.entity.items.get(item)));
|
||||
}
|
||||
});
|
||||
|
||||
state.teams.get(tile.getTeam()).cores.remove(tile);
|
||||
|
||||
int max = itemCapacity * state.teams.get(tile.getTeam()).cores.size;
|
||||
for(Item item : content.items()){
|
||||
tile.entity.items.set(item, Math.min(tile.entity.items.get(item), max));
|
||||
}
|
||||
|
||||
for(Tile other : new ObjectSetIterator<>(state.teams.get(tile.getTeam()).cores)){
|
||||
other.block().onProximityUpdate(other);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -141,6 +224,7 @@ public class CoreBlock extends StorageBlock{
|
||||
protected float progress;
|
||||
protected float time;
|
||||
protected float heat;
|
||||
protected int storageCapacity;
|
||||
|
||||
@Override
|
||||
public boolean hasUnit(Unit unit){
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.anuke.mindustry.world.blocks.storage;
|
||||
|
||||
import io.anuke.annotations.Annotations.*;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
@ -14,7 +15,8 @@ public abstract class StorageBlock extends Block{
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
return tile.entity.items.get(item) < getMaximumAccepted(tile, item);
|
||||
StorageBlockEntity entity = tile.entity();
|
||||
return entity.linkedCore != null ? entity.linkedCore.block().acceptItem(item, entity.linkedCore, source) : tile.entity.items.get(item) < getMaximumAccepted(tile, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -22,6 +24,14 @@ public abstract class StorageBlock extends Block{
|
||||
return itemCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawSelect(Tile tile){
|
||||
StorageBlockEntity entity = tile.entity();
|
||||
if(entity.linkedCore != null){
|
||||
entity.linkedCore.block().drawSelect(entity.linkedCore);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean outputsItems(){
|
||||
return false;
|
||||
@ -58,4 +68,13 @@ public abstract class StorageBlock extends Block{
|
||||
return entity.items.has(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity newEntity(){
|
||||
return new StorageBlockEntity();
|
||||
}
|
||||
|
||||
public class StorageBlockEntity extends TileEntity{
|
||||
protected @Nullable Tile linkedCore;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user