Tile field encapsulation

This commit is contained in:
Anuken 2018-07-27 10:52:14 -04:00
parent 23bd9a989b
commit 01f6904f82
7 changed files with 27 additions and 18 deletions

View File

@ -89,7 +89,7 @@ public class Pathfinder{
}
private boolean passable(Tile tile, Team team){
return (tile.block() == Blocks.air && !tile.floor().isLiquid && tile.cliffs == 0 && !tile.floor().solid && !(tile.floor().isLiquid && (tile.floor().damageTaken > 0 || tile.floor().drownTime > 0)))
return (tile.block() == Blocks.air && !tile.floor().isLiquid && !tile.hasCliffs() && !tile.floor().solid && !(tile.floor().isLiquid && (tile.floor().damageTaken > 0 || tile.floor().drownTime > 0)))
|| (tile.breakable() && (tile.getTeam() != team)) || !tile.solid();
}

View File

@ -179,7 +179,7 @@ public class Puddle extends BaseEntity implements SaveTrait, Poolable, DrawTrait
float deposited = Math.min((amount - maxLiquid / 1.5f) / 4f, 0.3f) * Timers.delta();
for(GridPoint2 point : Geometry.d4){
Tile other = world.tile(tile.x + point.x, tile.y + point.y);
if(other.block() == Blocks.air && other.cliffs == 0){
if(other.block() == Blocks.air && !other.hasCliffs()){
deposit(other, tile, liquid, deposited, generation + 1);
amount -= deposited / 2f; //tweak to speed up/slow down puddle propagation
}

View File

@ -25,9 +25,7 @@ import java.nio.ByteBuffer;
import static io.anuke.mindustry.Vars.*;
/**
* Used for rendering fog of war. A framebuffer is used for this.
*/
/**Used for rendering fog of war. A framebuffer is used for this.*/
public class FogRenderer implements Disposable{
private static final int extraPadding = 3;
private static final int shadowPadding = 1;

View File

@ -127,7 +127,7 @@ public class WorldGenerator{
tile.updateOcclusion();
//fix things on cliffs that shouldn't be
if(tile.block() != Blocks.air && tile.cliffs != 0){
if(tile.block() != Blocks.air && tile.hasCliffs()){
tile.setBlock(Blocks.air);
}
}
@ -158,7 +158,7 @@ public class WorldGenerator{
Tile tile = tiles[x][y];
if(!tile.floor().hasOres || tile.cliffs != 0 || tile.block() != Blocks.air){
if(!tile.floor().hasOres || tile.hasCliffs() || tile.block() != Blocks.air){
continue;
}

View File

@ -154,7 +154,7 @@ public class Build{
for(int dy = 0; dy < type.size; dy++){
Tile other = world.tile(x + dx + offsetx, y + dy + offsety);
if(other == null || (other.block() != Blocks.air && !other.block().alwaysReplace)
|| other.cliffs != 0 || !other.floor().placeableOn ||
|| other.hasCliffs() || !other.floor().placeableOn ||
(tile.floor().liquidDrop != null && !type.floating)){
return false;
}
@ -164,7 +164,7 @@ public class Build{
}else{
return (tile.getTeam() == Team.none || tile.getTeam() == team)
&& (tile.floor().liquidDrop == null || type.floating)
&& tile.floor().placeableOn && tile.cliffs == 0
&& tile.floor().placeableOn && !tile.hasCliffs()
&& ((type.canReplace(tile.block())
&& !(type == tile.block() && rotation == tile.getRotation() && type.rotate)) || tile.block().alwaysReplace || tile.block() == Blocks.air)
&& tile.block().isMultiblock() == type.isMultiblock() && type.canPlaceOn(tile);

View File

@ -29,14 +29,13 @@ public class Tile implements PosTrait, TargetTrait{
* This is relative to the block it is linked to; negate coords to find the link.
*/
public byte link = 0;
public short x, y;
/** Tile traversal cost. */
public byte cost = 1;
/** Position of cliffs around the tile, packed into bits 0-8. */
public byte cliffs;
/** Tile entity, usually null. */
public TileEntity entity;
/** Block ID data. */
public short x, y;
/** Position of cliffs around the tile, packed into bits 0-8. */
private byte cliffs;
private Block wall;
private Floor floor;
/** Rotation, 0-3. Also used to store offload location for routers, in which case it can be any number. */
@ -197,6 +196,18 @@ public class Tile implements PosTrait, TargetTrait{
this.elevation = (byte)elevation;
}
public byte getCliffs(){
return cliffs;
}
public void setCliffs(byte cliffs){
this.cliffs = cliffs;
}
public boolean hasCliffs(){
return getCliffs() != 0;
}
public boolean passable(){
Block block = block();
Block floor = floor();
@ -212,7 +223,7 @@ public class Tile implements PosTrait, TargetTrait{
public boolean solid(){
Block block = block();
Block floor = floor();
return block.solid || cliffs != 0 || (floor.solid && (block == Blocks.air || block.solidifes)) || block.isSolidFor(this)
return block.solid || getCliffs() != 0 || (floor.solid && (block == Blocks.air || block.solidifes)) || block.isSolidFor(this)
|| (isLinked() && getLinked().block().isSolidFor(getLinked()));
}

View File

@ -140,12 +140,12 @@ public class Floor extends Block{
Draw.rect(variantRegions[Mathf.randomSeed(tile.id(), 0, Math.max(0, variantRegions.length - 1))], tile.worldx(), tile.worldy());
if(tile.cliffs != 0 && cliffRegions != null){
if(tile.hasCliffs() && cliffRegions != null){
for(int i = 0; i < 4; i++){
if((tile.cliffs & (1 << i * 2)) != 0){
if((tile.getCliffs() & (1 << i * 2)) != 0){
Draw.colorl(i > 1 ? 0.6f : 1f);
boolean above = (tile.cliffs & (1 << ((i + 1) % 4) * 2)) != 0, below = (tile.cliffs & (1 << (Mathf.mod(i - 1, 4)) * 2)) != 0;
boolean above = (tile.getCliffs() & (1 << ((i + 1) % 4) * 2)) != 0, below = (tile.getCliffs() & (1 << (Mathf.mod(i - 1, 4)) * 2)) != 0;
if(above && below){
Draw.rect(cliffRegions[0], tile.worldx(), tile.worldy(), i * 90);
@ -169,7 +169,7 @@ public class Floor extends Block{
}
protected void drawEdges(Tile tile, boolean sameLayer){
if(!blend || tile.cliffs > 0) return;
if(!blend || tile.getCliffs() > 0) return;
for(int i = 0; i < 8; i++){
int dx = Geometry.d8[i].x, dy = Geometry.d8[i].y;