Reverted buffers / Added Dexapnow's fixed zone maps [untested]

This commit is contained in:
Anuken 2019-06-07 14:07:32 -04:00
parent 4458ae042e
commit c8ce195522
10 changed files with 76 additions and 78 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -83,7 +83,7 @@ public class MapPlayDialog extends FloatingDialog{
cont.add(sdif); cont.add(sdif);
cont.row(); cont.row();
cont.add(new BorderImage(map.texture, 3f)).size(250f).get().setScaling(Scaling.fit); cont.add(new BorderImage(map.texture, 3f)).size(mobile && !Core.graphics.isPortrait() ? 150f : 250f).get().setScaling(Scaling.fit);
buttons.clearChildren(); buttons.clearChildren();
addCloseButton(); addCloseButton();

View File

@ -103,6 +103,8 @@ public class Block extends BlockStorage{
public float buildCost; public float buildCost;
/** Whether this block is visible and can currently be built. */ /** Whether this block is visible and can currently be built. */
public BooleanProvider buildVisibility = () -> false; public BooleanProvider buildVisibility = () -> false;
/** Whether this block has instant transfer.*/
public boolean instantTransfer = false;
public boolean alwaysUnlocked = false; public boolean alwaysUnlocked = false;
protected TextureRegion[] cacheRegions = {}; protected TextureRegion[] cacheRegions = {};

View File

@ -24,6 +24,7 @@ public class Junction extends Block{
super(name); super(name);
update = true; update = true;
solid = true; solid = true;
instantTransfer = true;
group = BlockGroup.transportation; group = BlockGroup.transportation;
} }

View File

@ -1,22 +1,16 @@
package io.anuke.mindustry.world.blocks.distribution; package io.anuke.mindustry.world.blocks.distribution;
import io.anuke.arc.math.Mathf; import io.anuke.arc.math.Mathf;
import io.anuke.arc.util.Time;
import io.anuke.mindustry.entities.type.TileEntity; import io.anuke.mindustry.entities.type.TileEntity;
import io.anuke.mindustry.entities.type.Unit;
import io.anuke.mindustry.type.Item; import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.*;
import io.anuke.mindustry.world.DirectionalItemBuffer;
import io.anuke.mindustry.world.Edges;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.meta.BlockGroup; import io.anuke.mindustry.world.meta.BlockGroup;
import java.io.DataInput; import java.io.*;
import java.io.DataOutput;
import java.io.IOException;
public class OverflowGate extends Block{ public class OverflowGate extends Block{
protected int bufferCapacity = 10; protected float speed = 8f;
protected float speed = 45f;
public OverflowGate(String name){ public OverflowGate(String name){
super(name); super(name);
@ -27,22 +21,38 @@ public class OverflowGate extends Block{
} }
@Override @Override
public int acceptStack(Item item, int amount, Tile tile, Unit source){ public boolean outputsItems(){
return 0; return true;
} }
@Override
public int removeStack(Tile tile, Item item, int amount){
OverflowGateEntity entity = tile.entity();
int result = super.removeStack(tile, item, amount);
if(result != 0 && item == entity.lastItem){
entity.lastItem = null;
}
return result;
}
@Override @Override
public void update(Tile tile){ public void update(Tile tile){
OverflowGateEntity entity = tile.entity(); OverflowGateEntity entity = tile.entity();
for(int i = 0; i < 4; i++){ if(entity.lastItem == null && entity.items.total() > 0){
Item item = entity.buffer.poll(i); entity.items.clear();
if(item != null){ }
Tile other = getTileTarget(tile, item, tile.getNearby(i), true);
if(other != null && other.block().acceptItem(item, other, tile)){ if(entity.lastItem != null){
other.block().handleItem(item, other, tile); entity.time += 1f / speed * Time.delta();
entity.buffer.remove(i); Tile target = getTileTarget(tile, entity.lastItem, entity.lastInput, false);
}
if(target != null && (entity.time >= 1f)){
getTileTarget(tile, entity.lastItem, entity.lastInput, true);
target.block().handleItem(entity.lastItem, target, Edges.getFacingEdge(tile, target));
entity.items.remove(entity.lastItem, 1);
entity.lastItem = null;
} }
} }
} }
@ -50,16 +60,17 @@ public class OverflowGate extends Block{
@Override @Override
public boolean acceptItem(Item item, Tile tile, Tile source){ public boolean acceptItem(Item item, Tile tile, Tile source){
OverflowGateEntity entity = tile.entity(); OverflowGateEntity entity = tile.entity();
return entity.buffer.accepts(tile.relativeTo(source.x, source.y));
return tile.getTeam() == source.getTeam() && entity.lastItem == null && entity.items.total() == 0;
} }
@Override @Override
public void handleItem(Item item, Tile tile, Tile source){ public void handleItem(Item item, Tile tile, Tile source){
OverflowGateEntity entity = tile.entity(); OverflowGateEntity entity = tile.entity();
int buffer = tile.relativeTo(source.x, source.y); entity.items.add(item, 1);
if(entity.buffer.accepts(buffer)){ entity.lastItem = item;
entity.buffer.accept(buffer, item); entity.time = 0f;
} entity.lastInput = source;
} }
Tile getTileTarget(Tile tile, Item item, Tile src, boolean flip){ Tile getTileTarget(Tile tile, Item item, Tile src, boolean flip){
@ -86,10 +97,10 @@ public class OverflowGate extends Block{
}else{ }else{
if(tile.rotation() == 0){ if(tile.rotation() == 0){
to = a; to = a;
if(flip) tile.rotation((byte)1); if(flip) tile.rotation((byte) 1);
}else{ }else{
to = b; to = b;
if(flip) tile.rotation((byte)0); if(flip) tile.rotation((byte) 0);
} }
} }
} }
@ -103,24 +114,25 @@ public class OverflowGate extends Block{
} }
public class OverflowGateEntity extends TileEntity{ public class OverflowGateEntity extends TileEntity{
DirectionalItemBuffer buffer = new DirectionalItemBuffer(bufferCapacity, speed); Item lastItem;
Tile lastInput;
float time;
@Override @Override
public byte version(){ public byte version(){
return 1; return 2;
} }
@Override @Override
public void write(DataOutput stream) throws IOException{ public void write(DataOutput stream) throws IOException{
super.write(stream); super.write(stream);
buffer.write(stream);
} }
@Override @Override
public void read(DataInput stream, byte revision) throws IOException{ public void read(DataInput stream, byte revision) throws IOException{
super.read(stream, revision); super.read(stream, revision);
if(revision == 1){ if(revision == 1){
buffer.read(stream); new DirectionalItemBuffer(25, 0f).read(stream);
} }
} }
} }

View File

@ -5,9 +5,7 @@ import io.anuke.arc.Core;
import io.anuke.arc.graphics.g2d.Draw; import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.math.Mathf; import io.anuke.arc.math.Mathf;
import io.anuke.arc.scene.ui.layout.Table; import io.anuke.arc.scene.ui.layout.Table;
import io.anuke.mindustry.entities.type.Player; import io.anuke.mindustry.entities.type.*;
import io.anuke.mindustry.entities.type.TileEntity;
import io.anuke.mindustry.entities.type.Unit;
import io.anuke.mindustry.gen.Call; import io.anuke.mindustry.gen.Call;
import io.anuke.mindustry.type.Item; import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.world.*; import io.anuke.mindustry.world.*;
@ -21,22 +19,15 @@ import static io.anuke.mindustry.Vars.content;
public class Sorter extends Block{ public class Sorter extends Block{
private static Item lastItem; private static Item lastItem;
protected int bufferCapacity = 20;
protected float speed = 45f;
public Sorter(String name){ public Sorter(String name){
super(name); super(name);
update = true; update = true;
solid = true; solid = true;
instantTransfer = true;
group = BlockGroup.transportation; group = BlockGroup.transportation;
configurable = true; configurable = true;
} }
@Override
public int acceptStack(Item item, int amount, Tile tile, Unit source){
return 0;
}
@Override @Override
public boolean outputsItems(){ public boolean outputsItems(){
return true; return true;
@ -63,42 +54,28 @@ public class Sorter extends Block{
if(entity.sortItem == null) return; if(entity.sortItem == null) return;
Draw.color(entity.sortItem.color); Draw.color(entity.sortItem.color);
Draw.rect("center", tile.worldx(), tile.worldy()); Draw.rect("blank", tile.worldx(), tile.worldy(), 4f, 4f);
Draw.color(); Draw.color();
} }
@Override
public void update(Tile tile){
SorterEntity entity = tile.entity();
for(int i = 0; i < 4; i++){
Item item = entity.buffer.poll(i);
if(item != null){
Tile other = getTileTarget(item, tile, tile.getNearby(i), true);
if(other != null && other.block().acceptItem(item, other, tile)){
other.block().handleItem(item, other, tile);
entity.buffer.remove(i);
}
}
}
}
@Override @Override
public boolean acceptItem(Item item, Tile tile, Tile source){ public boolean acceptItem(Item item, Tile tile, Tile source){
SorterEntity entity = tile.entity(); Tile to = getTileTarget(item, tile, source, false);
return entity.buffer.accepts(tile.relativeTo(source.x, source.y));
return to != null && to.block().acceptItem(item, to, tile);
} }
@Override @Override
public void handleItem(Item item, Tile tile, Tile source){ public void handleItem(Item item, Tile tile, Tile source){
SorterEntity entity = tile.entity(); Tile to = getTileTarget(item, tile, source, true);
int buffer = tile.relativeTo(source.x, source.y);
if(entity.buffer.accepts(buffer)){ to.block().handleItem(item, to, tile);
entity.buffer.accept(buffer, item); }
}
boolean isSame(Tile tile, Tile other){
return other != null && other.block() == this && other.<SorterEntity>entity().sortItem == tile.<SorterEntity>entity().sortItem;
} }
@Nullable
Tile getTileTarget(Item item, Tile dest, Tile source, boolean flip){ Tile getTileTarget(Item item, Tile dest, Tile source, boolean flip){
SorterEntity entity = dest.entity(); SorterEntity entity = dest.entity();
@ -107,12 +84,18 @@ public class Sorter extends Block{
Tile to; Tile to;
if(item == entity.sortItem){ if(item == entity.sortItem){
//prevent 3-chains
if(isSame(dest, source) && isSame(dest, dest.getNearby(dir))){
return null;
}
to = dest.getNearby(dir); to = dest.getNearby(dir);
}else{ }else{
Tile a = dest.getNearby(Mathf.mod(dir - 1, 4)); Tile a = dest.getNearby(Mathf.mod(dir - 1, 4));
Tile b = dest.getNearby(Mathf.mod(dir + 1, 4)); Tile b = dest.getNearby(Mathf.mod(dir + 1, 4));
boolean ac = a != null && a.block().acceptItem(item, a, dest); boolean ac = a != null && !(a.block().instantTransfer && source.block().instantTransfer) &&
boolean bc = b != null && b.block().acceptItem(item, b, dest); a.block().acceptItem(item, a, dest);
boolean bc = b != null && !(b.block().instantTransfer && source.block().instantTransfer) &&
b.block().acceptItem(item, b, dest);
if(ac && !bc){ if(ac && !bc){
to = a; to = a;
@ -123,10 +106,12 @@ public class Sorter extends Block{
}else{ }else{
if(dest.rotation() == 0){ if(dest.rotation() == 0){
to = a; to = a;
if(flip) dest.rotation((byte)1); if(flip)
dest.rotation((byte)1);
}else{ }else{
to = b; to = b;
if(flip) dest.rotation((byte)0); if(flip)
dest.rotation((byte)0);
} }
} }
} }
@ -148,20 +133,18 @@ public class Sorter extends Block{
return new SorterEntity(); return new SorterEntity();
} }
public class SorterEntity extends TileEntity{ public class SorterEntity extends TileEntity{
DirectionalItemBuffer buffer = new DirectionalItemBuffer(bufferCapacity, speed);
Item sortItem; Item sortItem;
@Override @Override
public byte version(){ public byte version(){
return 1; return 2;
} }
@Override @Override
public void write(DataOutput stream) throws IOException{ public void write(DataOutput stream) throws IOException{
super.write(stream); super.write(stream);
stream.writeShort(sortItem == null ? -1 : sortItem.id);
buffer.write(stream);
} }
@Override @Override
@ -169,7 +152,7 @@ public class Sorter extends Block{
super.read(stream, revision); super.read(stream, revision);
sortItem = content.item(stream.readShort()); sortItem = content.item(stream.readShort());
if(revision == 1){ if(revision == 1){
buffer.read(stream); new ItemBuffer(20, 45f).read(stream);
} }
} }
} }

View File

@ -157,7 +157,7 @@ public class ServerControl implements ApplicationListener{
? "[YELLOW]The " + event.winner.name() + " team is victorious![]" : "[SCARLET]Game over![]") ? "[YELLOW]The " + event.winner.name() + " team is victorious![]" : "[SCARLET]Game over![]")
+ "\nNext selected map:[accent] " + map.name() + "[]" + "\nNext selected map:[accent] " + map.name() + "[]"
+ (map.tags.containsKey("author") && !map.tags.get("author").trim().isEmpty() ? " by[accent] " + map.author() + "[]" : "") + "." + + (map.tags.containsKey("author") && !map.tags.get("author").trim().isEmpty() ? " by[accent] " + map.author() + "[]" : "") + "." +
"\nNew game begins in " + roundExtraTime + " seconds."); "\nNew game begins in " + roundExtraTime + "[] seconds.");
info("Selected next map to be {0}.", map.name()); info("Selected next map to be {0}.", map.name());