2018-07-06 15:30:00 +02:00
|
|
|
package com.eu.habbo.habbohotel.rooms;
|
|
|
|
|
|
|
|
public class RoomTile
|
|
|
|
{
|
|
|
|
public final short x;
|
|
|
|
public final short y;
|
|
|
|
public final short z;
|
2019-03-18 02:22:00 +01:00
|
|
|
public RoomTileState state;
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-03-18 02:22:00 +01:00
|
|
|
private double stackHeight;
|
2018-07-06 15:30:00 +02:00
|
|
|
private boolean allowStack = true;
|
|
|
|
|
2018-07-08 23:32:00 +02:00
|
|
|
|
2018-07-06 15:30:00 +02:00
|
|
|
private RoomTile previous = null;
|
|
|
|
private boolean diagonally;
|
|
|
|
private short gCosts;
|
|
|
|
private short hCosts;
|
|
|
|
|
2018-07-08 23:32:00 +02:00
|
|
|
|
2018-11-17 14:28:00 +01:00
|
|
|
public RoomTile(short x, short y, short z, RoomTileState state, boolean allowStack)
|
2018-07-06 15:30:00 +02:00
|
|
|
{
|
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
|
|
|
this.z = z;
|
|
|
|
this.stackHeight = z;
|
|
|
|
this.state = state;
|
2018-11-17 14:28:00 +01:00
|
|
|
this.setAllowStack(allowStack);
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public RoomTile(RoomTile tile)
|
|
|
|
{
|
|
|
|
this.x = tile.x;
|
|
|
|
this.y = tile.y;
|
|
|
|
this.z = tile.z;
|
|
|
|
this.stackHeight = tile.stackHeight;
|
|
|
|
this.state = tile.state;
|
|
|
|
this.allowStack = tile.allowStack;
|
|
|
|
this.diagonally = tile.diagonally;
|
|
|
|
this.gCosts = tile.gCosts;
|
|
|
|
this.hCosts = tile.hCosts;
|
|
|
|
|
2018-11-17 14:28:00 +01:00
|
|
|
if (this.state == RoomTileState.INVALID)
|
2018-07-06 15:30:00 +02:00
|
|
|
{
|
|
|
|
this.allowStack = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public double getStackHeight()
|
|
|
|
{
|
|
|
|
return this.stackHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setStackHeight(double stackHeight)
|
|
|
|
{
|
2018-12-22 11:39:00 +01:00
|
|
|
if (this.state == RoomTileState.INVALID)
|
|
|
|
{
|
|
|
|
this.stackHeight = Short.MAX_VALUE;
|
|
|
|
this.allowStack = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stackHeight >= 0 && stackHeight != Short.MAX_VALUE)
|
2018-07-06 15:30:00 +02:00
|
|
|
{
|
|
|
|
this.stackHeight = stackHeight;
|
|
|
|
this.allowStack = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.allowStack = false;
|
|
|
|
this.stackHeight = this.z;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-17 14:28:00 +01:00
|
|
|
public boolean getAllowStack()
|
2018-07-06 15:30:00 +02:00
|
|
|
{
|
2018-12-22 11:39:00 +01:00
|
|
|
if (this.state == RoomTileState.INVALID)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.allowStack;
|
|
|
|
}
|
|
|
|
|
2018-11-17 14:28:00 +01:00
|
|
|
public void setAllowStack(boolean allowStack)
|
2018-07-06 15:30:00 +02:00
|
|
|
{
|
|
|
|
this.allowStack = allowStack;
|
|
|
|
}
|
|
|
|
|
|
|
|
public short relativeHeight()
|
|
|
|
{
|
2019-03-18 02:22:00 +01:00
|
|
|
if (this.state == RoomTileState.INVALID)
|
2018-07-06 15:30:00 +02:00
|
|
|
{
|
|
|
|
return Short.MAX_VALUE;
|
|
|
|
}
|
2019-03-18 02:22:00 +01:00
|
|
|
else if (!this.allowStack && (this.state == RoomTileState.BLOCKED || this.state == RoomTileState.SIT))
|
|
|
|
{
|
|
|
|
return 64 * 256;
|
|
|
|
}
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-03-18 02:22:00 +01:00
|
|
|
return this.allowStack ? (short) (this.getStackHeight() * 256.0) : 64 * 256;
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object o)
|
|
|
|
{
|
|
|
|
return o instanceof RoomTile &&
|
|
|
|
((RoomTile) o).x == this.x &&
|
|
|
|
((RoomTile) o).y == this.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
public RoomTile copy()
|
|
|
|
{
|
|
|
|
return new RoomTile(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public double distance(RoomTile roomTile)
|
|
|
|
{
|
|
|
|
double x = this.x - roomTile.x;
|
|
|
|
double y = this.y - roomTile.y;
|
|
|
|
return Math.sqrt(x * x + y * y);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void isDiagonally(boolean isDiagonally)
|
|
|
|
{
|
|
|
|
this.diagonally = isDiagonally;
|
|
|
|
}
|
|
|
|
|
|
|
|
public RoomTile getPrevious()
|
|
|
|
{
|
|
|
|
return this.previous;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setPrevious(RoomTile previous)
|
|
|
|
{
|
|
|
|
this.previous = previous;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getfCosts()
|
|
|
|
{
|
|
|
|
return this.gCosts + this.hCosts;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getgCosts()
|
|
|
|
{
|
|
|
|
return this.gCosts;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setgCosts(short gCosts)
|
|
|
|
{
|
2019-03-18 02:22:00 +01:00
|
|
|
this.gCosts = gCosts;
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void setgCosts(RoomTile previousRoomTile, int basicCost)
|
|
|
|
{
|
2019-03-18 02:22:00 +01:00
|
|
|
this.setgCosts((short)(previousRoomTile.getgCosts() + basicCost));
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setgCosts(RoomTile previousRoomTile)
|
|
|
|
{
|
2019-03-18 02:22:00 +01:00
|
|
|
this.setgCosts(previousRoomTile, this.diagonally ? RoomLayout.DIAGONALMOVEMENTCOST : RoomLayout.BASICMOVEMENTCOST);
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public int calculategCosts(RoomTile previousRoomTile)
|
|
|
|
{
|
|
|
|
if (this.diagonally)
|
|
|
|
{
|
2019-03-18 02:22:00 +01:00
|
|
|
return previousRoomTile.getgCosts() + 14;
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
2019-03-18 02:22:00 +01:00
|
|
|
return previousRoomTile.getgCosts() + 10;
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void sethCosts(RoomTile parent)
|
|
|
|
{
|
|
|
|
this.hCosts = (short)((Math.abs(this.x - parent.x) + Math.abs(this.y - parent.y)) * (parent.diagonally ? RoomLayout.DIAGONALMOVEMENTCOST : RoomLayout.BASICMOVEMENTCOST));
|
|
|
|
}
|
|
|
|
|
|
|
|
public String toString()
|
|
|
|
{
|
|
|
|
return "RoomTile (" + this.x + ", " + this.y + ", " + this.z + "): h: " + this.hCosts + " g: " + this.gCosts + " f: " + this.getfCosts();
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isWalkable()
|
|
|
|
{
|
2018-11-17 14:28:00 +01:00
|
|
|
return this.state == RoomTileState.OPEN;
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
2018-11-17 14:28:00 +01:00
|
|
|
public RoomTileState getState()
|
2018-07-06 15:30:00 +02:00
|
|
|
{
|
2018-11-17 14:28:00 +01:00
|
|
|
return this.state;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setState(RoomTileState state)
|
|
|
|
{
|
|
|
|
this.state = state;
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean is(short x, short y)
|
|
|
|
{
|
|
|
|
return this.x == x && this.y == y;
|
|
|
|
}
|
|
|
|
}
|