Implemented multiblock output, broke router chaining
This commit is contained in:
BIN
core/assets-raw/sprites/blocks/vault.png
Normal file
BIN
core/assets-raw/sprites/blocks/vault.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 296 B |
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
Before Width: | Height: | Size: 81 KiB After Width: | Height: | Size: 85 KiB |
@@ -1,7 +1,7 @@
|
|||||||
#Autogenerated file. Do not modify.
|
#Autogenerated file. Do not modify.
|
||||||
#Wed Feb 28 23:04:20 EST 2018
|
#Thu Mar 01 23:34:49 EST 2018
|
||||||
version=release
|
version=release
|
||||||
androidBuildCode=315
|
androidBuildCode=317
|
||||||
name=Mindustry
|
name=Mindustry
|
||||||
code=3.4
|
code=3.4
|
||||||
build=custom build
|
build=custom build
|
||||||
|
|||||||
@@ -186,7 +186,9 @@ public class NetworkIO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(tile.entity != null){
|
if(tile.entity != null){
|
||||||
stream.writeShort(tile.getPackedData());
|
stream.writeByte(tile.getRotation());
|
||||||
|
stream.writeByte(tile.getDump());
|
||||||
|
stream.writeByte(tile.getExtra());
|
||||||
stream.writeShort((short)tile.entity.health); //health
|
stream.writeShort((short)tile.entity.health); //health
|
||||||
|
|
||||||
//items
|
//items
|
||||||
@@ -317,11 +319,12 @@ public class NetworkIO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(tile.entity != null){
|
if(tile.entity != null){
|
||||||
short data = stream.readShort();
|
tile.setRotation(stream.readByte());
|
||||||
|
tile.setDump(stream.readByte());
|
||||||
|
tile.setExtra(stream.readByte());
|
||||||
short health = stream.readShort();
|
short health = stream.readShort();
|
||||||
|
|
||||||
tile.entity.health = health;
|
tile.entity.health = health;
|
||||||
tile.setPackedData(data);
|
|
||||||
|
|
||||||
for(int j = 0; j < tile.entity.items.length; j ++){
|
for(int j = 0; j < tile.entity.items.length; j ++){
|
||||||
tile.entity.items[j] = stream.readInt();
|
tile.entity.items[j] = stream.readInt();
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ public class Recipes {
|
|||||||
new Recipe(distribution, DistributionBlocks.steelconveyor, stack(Item.steel, 1)),
|
new Recipe(distribution, DistributionBlocks.steelconveyor, stack(Item.steel, 1)),
|
||||||
new Recipe(distribution, DistributionBlocks.pulseconveyor, stack(Item.dirium, 1)),
|
new Recipe(distribution, DistributionBlocks.pulseconveyor, stack(Item.dirium, 1)),
|
||||||
new Recipe(distribution, DistributionBlocks.router, stack(Item.stone, 2)),
|
new Recipe(distribution, DistributionBlocks.router, stack(Item.stone, 2)),
|
||||||
|
new Recipe(distribution, DistributionBlocks.vault, stack(Item.iron, 8)),
|
||||||
new Recipe(distribution, DistributionBlocks.junction, stack(Item.iron, 2)),
|
new Recipe(distribution, DistributionBlocks.junction, stack(Item.iron, 2)),
|
||||||
new Recipe(distribution, DistributionBlocks.tunnel, stack(Item.iron, 2)),
|
new Recipe(distribution, DistributionBlocks.tunnel, stack(Item.iron, 2)),
|
||||||
new Recipe(distribution, DistributionBlocks.sorter, stack(Item.steel, 2)),
|
new Recipe(distribution, DistributionBlocks.sorter, stack(Item.steel, 2)),
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package io.anuke.mindustry.world;
|
|||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
|
import com.badlogic.gdx.math.GridPoint2;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
import com.badlogic.gdx.utils.Array;
|
import com.badlogic.gdx.utils.Array;
|
||||||
import com.badlogic.gdx.utils.ObjectMap;
|
import com.badlogic.gdx.utils.ObjectMap;
|
||||||
@@ -182,61 +183,52 @@ public class Block{
|
|||||||
* Tries to put this item into a nearby container, if there are no available
|
* Tries to put this item into a nearby container, if there are no available
|
||||||
* containers, it gets added to the block's inventory.*/
|
* containers, it gets added to the block's inventory.*/
|
||||||
public void offloadNear(Tile tile, Item item){
|
public void offloadNear(Tile tile, Item item){
|
||||||
if(Net.client() && syncBlockState){
|
GridPoint2[] nearby = Edges.getEdges(width);
|
||||||
handleItem(item, tile, tile);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
byte i = tile.getDump();
|
for(int j = 0; j < nearby.length; j ++){
|
||||||
byte pdump = (byte)(i % 4);
|
Tile other = tile.getNearby(nearby[j]);
|
||||||
|
Tile in = tile.getNearby(Edges.getInsideEdges(width)[j]);
|
||||||
for(int j = 0; j < 4; j ++){
|
if(other != null && other.block().acceptItem(item, other, in)){
|
||||||
Tile other = tile.getNearby(i);
|
other.block().handleItem(item, other, in);
|
||||||
if(other != null && other.block().acceptItem(item, other, tile)){
|
|
||||||
other.block().handleItem(item, other, tile);
|
|
||||||
tile.setDump((byte)((i+1)%4));
|
|
||||||
if(Net.server() && syncBlockState) NetEvents.handleTransfer(tile, i, item);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
i %= 4;
|
|
||||||
}
|
}
|
||||||
tile.setDump(pdump);
|
|
||||||
handleItem(item, tile, tile);
|
handleItem(item, tile, tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Try dumping any item near the tile. */
|
/**Try dumping any item near the tile.*/
|
||||||
protected boolean tryDump(Tile tile){
|
protected boolean tryDump(Tile tile){
|
||||||
return tryDump(tile, -1, null);
|
return tryDump(tile, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**Try dumping a specific item near the tile.*/
|
||||||
* Try dumping any item near the tile. -1 = any direction
|
protected boolean tryDump(Tile tile, Item todump){
|
||||||
*/
|
GridPoint2[] nearby = Edges.getEdges(width);
|
||||||
protected boolean tryDump(Tile tile, int direction, Item todump){
|
byte i = (byte)(tile.getDump() % nearby.length);
|
||||||
if(Net.client() && syncBlockState) return false;
|
|
||||||
|
|
||||||
int i = tile.getDump()%4;
|
for(int j = 0; j < nearby.length; j ++){
|
||||||
|
Tile other;
|
||||||
|
Tile in;
|
||||||
|
|
||||||
for(int j = 0; j < 4; j ++){
|
for(Item item : Item.getAllItems()){
|
||||||
Tile other = tile.getNearby(i);
|
other = tile.getNearby(nearby[i]);
|
||||||
|
in = tile.getNearby(Edges.getInsideEdges(width)[i]);
|
||||||
|
|
||||||
if(i == direction || direction == -1){
|
if(todump != null && item != todump) continue;
|
||||||
for(Item item : Item.getAllItems()){
|
|
||||||
|
|
||||||
if(todump != null && item != todump) continue;
|
if(tile.entity.hasItem(item) && other != null && other.block().acceptItem(item, other, in)){
|
||||||
|
other.block().handleItem(item, other, in);
|
||||||
if(tile.entity.hasItem(item) && other != null && other.block().acceptItem(item, other, tile)){
|
tile.entity.removeItem(item, 1);
|
||||||
other.block().handleItem(item, other, tile);
|
i = (byte)((i + 1) % nearby.length);
|
||||||
tile.entity.removeItem(item, 1);
|
tile.setDump(i);
|
||||||
tile.setDump((byte)((i+1)%4));
|
return true;
|
||||||
if(Net.server() && syncBlockState) NetEvents.handleTransfer(tile, (byte)i, item);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
i %= 4;
|
|
||||||
|
i = (byte)((i + 1) % nearby.length);
|
||||||
|
tile.setDump(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import java.util.Arrays;
|
|||||||
public class Edges {
|
public class Edges {
|
||||||
private static final int maxSize = 11;
|
private static final int maxSize = 11;
|
||||||
private static GridPoint2[][] edges = new GridPoint2[maxSize][0];
|
private static GridPoint2[][] edges = new GridPoint2[maxSize][0];
|
||||||
|
private static GridPoint2[][] edgeInside = new GridPoint2[maxSize][0];
|
||||||
|
private static GridPoint2[][] inside = new GridPoint2[maxSize][0];
|
||||||
|
|
||||||
static{
|
static{
|
||||||
|
|
||||||
@@ -30,16 +32,30 @@ public class Edges {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Arrays.sort(edges[i], (e1, e2) -> Float.compare(Mathf.atan2(e1.x, e1.y), Mathf.atan2(e2.x, e2.y)));
|
Arrays.sort(edges[i], (e1, e2) -> Float.compare(Mathf.atan2(e1.x, e1.y), Mathf.atan2(e2.x, e2.y)));
|
||||||
|
|
||||||
|
edgeInside[i] = new GridPoint2[edges[i].length];
|
||||||
|
|
||||||
|
for(int j = 0; j < edges[i].length; j ++){
|
||||||
|
GridPoint2 point = edges[i][j];
|
||||||
|
edgeInside[i][j] = new GridPoint2(Mathf.clamp(point.x, -(int)((i)/2f), (int)(i/2f + 0.5f)),
|
||||||
|
Mathf.clamp(point.y, -(int)((i)/2f), (int)(i/2f + 0.5f)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GridPoint2[] getEdges(int size){
|
public static synchronized GridPoint2[] getEdges(int size){
|
||||||
if(size < 0 || size > maxSize) throw new RuntimeException("Block size must be between 0 and " + maxSize);
|
if(size < 0 || size > maxSize) throw new RuntimeException("Block size must be between 0 and " + maxSize);
|
||||||
|
|
||||||
return edges[size - 1];
|
return edges[size - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getEdgeAmount(int size){
|
public static synchronized GridPoint2[] getInsideEdges(int size){
|
||||||
|
if(size < 0 || size > maxSize) throw new RuntimeException("Block size must be between 0 and " + maxSize);
|
||||||
|
|
||||||
|
return edgeInside[size - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized int getEdgeAmount(int size){
|
||||||
return getEdges(size).length;
|
return getEdges(size).length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,10 @@ public class DistributionBlocks{
|
|||||||
|
|
||||||
}},
|
}},
|
||||||
|
|
||||||
|
vault = new Router("vault"){{
|
||||||
|
width = height = 2;
|
||||||
|
}},
|
||||||
|
|
||||||
junction = new Junction("junction"){{
|
junction = new Junction("junction"){{
|
||||||
|
|
||||||
}},
|
}},
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import io.anuke.mindustry.world.Block;
|
|||||||
import io.anuke.mindustry.world.BlockBar;
|
import io.anuke.mindustry.world.BlockBar;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.ucore.core.Timers;
|
import io.anuke.ucore.core.Timers;
|
||||||
import io.anuke.ucore.util.Mathf;
|
|
||||||
|
|
||||||
public class Router extends Block{
|
public class Router extends Block{
|
||||||
protected final int timerDump = timers++;
|
protected final int timerDump = timers++;
|
||||||
@@ -34,19 +33,11 @@ public class Router extends Block{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(Tile tile){
|
public void update(Tile tile){
|
||||||
tile.setRotation((byte)Mathf.mod(tile.getRotation(), 4));
|
|
||||||
|
|
||||||
int iterations = Math.max(1, (int) (Timers.delta() + 0.4f));
|
int iterations = Math.max(1, (int) (Timers.delta() + 0.4f));
|
||||||
|
|
||||||
for(int i = 0; i < iterations; i ++) {
|
for(int i = 0; i < iterations; i ++) {
|
||||||
|
|
||||||
if (tile.entity.totalItems() > 0) {
|
if (tile.entity.totalItems() > 0) {
|
||||||
if (tile.getExtra() != tile.getRotation()
|
tryDump(tile);
|
||||||
|| Mathf.chance(0.35)) { //sometimes dump backwards at a 0.35 chance... this somehow works?
|
|
||||||
tryDump(tile, tile.getRotation(), null);
|
|
||||||
}
|
|
||||||
|
|
||||||
tile.setRotation((byte) ((tile.getRotation() + 1) % 4));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ public class LiquidCrafter extends LiquidBlock{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(entity.timer.get(timerDump, 15)){
|
if(entity.timer.get(timerDump, 15)){
|
||||||
tryDump(tile, -1, output);
|
tryDump(tile, output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ public class PowerSmelter extends PowerBlock {
|
|||||||
PowerSmelterEntity entity = tile.entity();
|
PowerSmelterEntity entity = tile.entity();
|
||||||
|
|
||||||
if(entity.timer.get(timerDump, 5) && entity.hasItem(result)){
|
if(entity.timer.get(timerDump, 5) && entity.hasItem(result)){
|
||||||
tryDump(tile, -1, result);
|
tryDump(tile, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
float used = powerDrain * Timers.delta();
|
float used = powerDrain * Timers.delta();
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public class Smelter extends Block{
|
|||||||
CrafterEntity entity = tile.entity();
|
CrafterEntity entity = tile.entity();
|
||||||
|
|
||||||
if(entity.timer.get(timerDump, 5) && entity.hasItem(result)){
|
if(entity.timer.get(timerDump, 5) && entity.hasItem(result)){
|
||||||
tryDump(tile, -1, result);
|
tryDump(tile, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
//add fuel
|
//add fuel
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import io.anuke.mindustry.world.Block;
|
|||||||
import io.anuke.mindustry.world.BlockBar;
|
import io.anuke.mindustry.world.BlockBar;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.ucore.core.Timers;
|
import io.anuke.ucore.core.Timers;
|
||||||
import io.anuke.ucore.util.Mathf;
|
|
||||||
|
|
||||||
public class Vault extends Block {
|
public class Vault extends Block {
|
||||||
public int capacity;
|
public int capacity;
|
||||||
@@ -27,21 +26,11 @@ public class Vault extends Block {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(Tile tile){
|
public void update(Tile tile){
|
||||||
tile.setRotation((byte) Mathf.mod(tile.getRotation(), 4));
|
|
||||||
|
|
||||||
int iterations = Math.max(1, (int) (Timers.delta() + 0.4f));
|
int iterations = Math.max(1, (int) (Timers.delta() + 0.4f));
|
||||||
|
|
||||||
for(int i = 0; i < iterations; i ++) {
|
for(int i = 0; i < iterations; i ++) {
|
||||||
|
if (tile.entity.totalItems() > 0) { //TODO only output to the right blocks
|
||||||
if(!canOutput(tile, tile.getNearby(tile.getRotation()))){
|
tryDump(tile);
|
||||||
tile.setRotation((byte) ((tile.getRotation() + 1) % 4));
|
|
||||||
}else if (tile.entity.totalItems() > 0) {
|
|
||||||
if (tile.getExtra() != tile.getRotation()
|
|
||||||
|| Mathf.chance(0.35)) { //sometimes dump backwards at a 0.35 chance... this somehow works?
|
|
||||||
tryDump(tile, tile.getRotation(), null);
|
|
||||||
}
|
|
||||||
|
|
||||||
tile.setRotation((byte) ((tile.getRotation() + 1) % 4));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user