1
0
mirror of https://github.com/Anuken/Mindustry.git synced 2024-11-09 11:37:57 +03:00

Removed link byte, replaced with rotation

This commit is contained in:
Anuken 2019-04-12 15:30:34 -04:00
parent 46c3b35028
commit 9ebb4c7d12
9 changed files with 64 additions and 47 deletions

View File

@ -305,7 +305,11 @@ public class World implements ApplicationListener{
}
public void setBlock(Tile tile, Block block, Team team){
tile.setBlock(block, team);
setBlock(tile, block, team, 0);
}
public void setBlock(Tile tile, Block block, Team team, int rotation){
tile.setBlock(block, team, rotation);
if(block.isMultiblock()){
int offsetx = -(block.size - 1) / 2;
int offsety = -(block.size - 1) / 2;

View File

@ -45,7 +45,7 @@ public class EditorTile extends Tile{
@Override
public void setBlock(Block type){
Block previous = wall;
Block previous = block;
if(previous == type) return;
super.setBlock(type);
op(TileOp.get(x, y, (byte)OpType.block.ordinal(), previous.id, type.id));
@ -84,8 +84,8 @@ public class EditorTile extends Tile{
protected void changed(){
entity = null;
if(wall == null){
wall = Blocks.air;
if(block == null){
block = Blocks.air;
}
if(floor == null){

View File

@ -19,7 +19,7 @@ public enum EditorTool{
byte link = tile.getLinkByte();
if(tile.block() instanceof BlockPart && link != 0){
if(tile.isLinked()){
x -= (Pack.leftByte(link) - 8);
y -= (Pack.rightByte(link) - 8);
@ -27,7 +27,7 @@ public enum EditorTool{
}
//do not.
if(tile.block() instanceof BlockPart){
if(tile.isLinked()){
return;
}

View File

@ -167,7 +167,7 @@ public class MapIO{
stream.writeByte(tile.getBlockID());
if(tile.block() instanceof BlockPart){
stream.writeByte(tile.link);
stream.writeByte(tile.getLinkByte());
}else if(tile.entity != null){
stream.writeByte(Pack.byteByte(tile.getTeamID(), tile.getRotation())); //team + rotation
stream.writeShort(/*(short)tile.entity.health*/tile.block().health); //health
@ -293,7 +293,7 @@ public class MapIO{
tile.setBlock(block);
if(block == Blocks.part){
tile.link = stream.readByte();
tile.setLinkByte(stream.readByte());
}else if(tile.entity != null){
byte tr = stream.readByte();
short health = stream.readShort();

View File

@ -67,7 +67,7 @@ public abstract class SaveFileVersion{
stream.writeByte(tile.getBlockID());
if(tile.block() == Blocks.part){
stream.writeByte(tile.link);
stream.writeByte(tile.getLinkByte());
}else if(tile.entity != null){
stream.writeByte(Pack.byteByte(tile.getTeamID(), tile.getRotation())); //team + rotation
stream.writeShort((short)tile.entity.health); //health
@ -136,7 +136,7 @@ public abstract class SaveFileVersion{
tile.setBlock(block);
if(block == Blocks.part){
tile.link = stream.readByte();
tile.setLinkByte(stream.readByte());
}else if(tile.entity != null){
byte tr = stream.readByte();
short health = stream.readShort();

View File

@ -16,13 +16,7 @@ import io.anuke.mindustry.world.modules.*;
import static io.anuke.mindustry.Vars.*;
public class Tile implements Position, TargetTrait{
/**
* The coordinates of the core tile this is linked to, in the form of two bytes packed into one.
* This is relative to the block it is linked to; negate coords to find the link.
*/
public byte link = 0;
/** Tile traversal cost. */
public byte cost = 1;
/** Weight of [ground] units on this tile. */
@ -30,7 +24,7 @@ public class Tile implements Position, TargetTrait{
/** Tile entity, usually null. */
public TileEntity entity;
public short x, y;
protected Block wall;
protected Block block;
protected Floor floor;
/** Rotation, 0-3. Also used to store offload location, in which case it can be any number. */
private byte rotation;
@ -42,20 +36,20 @@ public class Tile implements Position, TargetTrait{
public Tile(int x, int y){
this.x = (short)x;
this.y = (short)y;
wall = floor = (Floor)Blocks.air;
block = floor = (Floor)Blocks.air;
}
public Tile(int x, int y, byte floor, byte wall){
public Tile(int x, int y, byte floor, byte block){
this(x, y);
this.floor = (Floor)content.block(floor);
this.wall = content.block(wall);
this.block = content.block(block);
changed();
}
public Tile(int x, int y, byte floor, byte wall, byte rotation, byte team){
public Tile(int x, int y, byte floor, byte block, byte rotation, byte team){
this(x, y);
this.floor = (Floor)content.block(floor);
this.wall = content.block(wall);
this.block = content.block(block);
this.rotation = rotation;
changed();
this.team = team;
@ -67,7 +61,7 @@ public class Tile implements Position, TargetTrait{
}
public byte getBlockID(){
return wall.id;
return block.id;
}
public byte getFloorID(){
@ -133,7 +127,7 @@ public class Tile implements Position, TargetTrait{
}
public Block block(){
return wall;
return block;
}
public Floor overlay(){
@ -142,7 +136,7 @@ public class Tile implements Position, TargetTrait{
@SuppressWarnings("unchecked")
public <T extends Block> T cblock(){
return (T)wall;
return (T)block;
}
@Override
@ -158,27 +152,35 @@ public class Tile implements Position, TargetTrait{
return team;
}
public void setBlock(Block type, Team team, int rotation){
preChanged();
this.block = type;
this.team = (byte)team.ordinal();
this.rotation = 0;
this.rotation = (byte)Mathf.mod(rotation, 4);
changed();
}
public void setBlock(Block type, int rotation){
preChanged();
if(rotation < 0) rotation = (-rotation + 2);
this.wall = type;
this.link = 0;
setRotation((byte)(rotation % 4));
this.block = type;
this.rotation = 0;
this.rotation = (byte)Mathf.mod(rotation, 4);
changed();
}
public void setBlock(Block type, Team team){
preChanged();
this.wall = type;
this.block = type;
this.team = (byte)team.ordinal();
this.link = 0;
this.rotation = 0;
changed();
}
public void setBlock(Block type){
preChanged();
this.wall = type;
this.link = 0;
this.block = type;
this.rotation = 0;
changed();
}
@ -241,7 +243,7 @@ public class Tile implements Position, TargetTrait{
public boolean breakable(){
Block block = block();
if(link == 0){
if(!isLinked()){
return (block.destructible || block.breakable || block.update);
}else{
return getLinked() != this && getLinked().getLinked() == null && getLinked().breakable();
@ -253,21 +255,21 @@ public class Tile implements Position, TargetTrait{
}
public boolean isLinked(){
return link != 0;
return block == Blocks.part;
}
public byte getLinkByte(){
return link;
return rotation;
}
public void setLinkByte(byte b){
this.link = b;
this.rotation = b;
}
/** Sets this to a linked tile, which sets the block to a part. dx and dy can only be -8-7. */
public void setLinked(byte dx, byte dy){
setBlock(Blocks.part);
link = Pack.byteByte((byte)(dx + 8), (byte)(dy + 8));
rotation = Pack.byteByte((byte)(dx + 8), (byte)(dy + 8));
}
/**
@ -315,12 +317,10 @@ public class Tile implements Position, TargetTrait{
/** Returns the block the multiblock is linked to, or null if it is not linked to any block. */
public Tile getLinked(){
if(link == 0){
if(!isLinked()){
return null;
}else{
byte dx = Pack.leftByte(link);
byte dy = Pack.rightByte(link);
return world.tile(x - (dx - 8), y - (dy - 8));
return world.tile(x + linkX(rotation), y + linkY(rotation));
}
}
@ -449,7 +449,7 @@ public class Tile implements Position, TargetTrait{
@Override
public boolean isDead(){
return false; //tiles never die
return entity == null;
}
@Override
@ -483,6 +483,16 @@ public class Tile implements Position, TargetTrait{
Block floor = floor();
return floor.name + ":" + block.name + ":" + content.block(overlay) + "[" + x + "," + y + "] " + "entity=" + (entity == null ? "null" : (entity.getClass())) +
(link != 0 ? " link=[" + (Pack.leftByte(link) - 8) + ", " + (Pack.rightByte(link) - 8) + "]" : "");
(isLinked() ? " link=[" + linkX(rotation) + ", " + linkY(rotation) + "]" : "");
}
/**Returns the relative X from a link byte.*/
public static int linkX(byte value){
return -((byte)((value >> 4) & (byte)0x0F) - 8);
}
/**Returns the relative Y from a link byte.*/
public static int linkY(byte value){
return -((byte)(value & 0x0F) - 8);
}
}

View File

@ -51,8 +51,7 @@ public class BuildBlock extends Block{
public static void onConstructFinish(Tile tile, Block block, int builderID, byte rotation, Team team){
if(tile == null) return;
float healthf = tile.entity == null ? 1f : tile.entity.healthf();
tile.setRotation(rotation);
world.setBlock(tile, block, team);
world.setBlock(tile, block, team, rotation);
if(tile.entity != null){
tile.entity.health = block.health * healthf;
}

View File

@ -167,6 +167,10 @@ public class Conveyor extends Block{
public void unitOn(Tile tile, Unit unit){
ConveyorEntity entity = tile.entity();
if(entity.clogHeat > 0.5f){
return;
}
entity.noSleep();
float speed = this.speed * tilesize / 2.4f;

View File

@ -81,7 +81,7 @@ public class PowerTestFixture{
// Since this part shall not be part of the test and would require more work anyway, we manually set the block and floor
// through reflections and then simulate part of what the changed() method does.
Field field = Tile.class.getDeclaredField("wall");
Field field = Tile.class.getDeclaredField("block");
field.setAccessible(true);
field.set(tile, block);