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;
|
|
|
|
public RoomTileState state = RoomTileState.OPEN;
|
|
|
|
|
|
|
|
private double stackHeight = 0;
|
|
|
|
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 movementPanelty;
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (stackHeight >= 0)
|
|
|
|
{
|
|
|
|
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
|
|
|
{
|
|
|
|
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;
|
2018-11-17 14:28:00 +01:00
|
|
|
|
|
|
|
if (this.state == RoomTileState.INVALID)
|
|
|
|
{
|
|
|
|
this.allowStack = false;
|
|
|
|
}
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public short relativeHeight()
|
|
|
|
{
|
2018-11-17 14:28:00 +01:00
|
|
|
if (this.state == RoomTileState.INVALID || !allowStack)
|
2018-07-06 15:30:00 +02:00
|
|
|
{
|
|
|
|
return Short.MAX_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (short) (this.stackHeight * 256.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@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 boolean isDiagonally()
|
|
|
|
{
|
|
|
|
return this.diagonally;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void isDiagonally(boolean isDiagonally)
|
|
|
|
{
|
|
|
|
this.diagonally = isDiagonally;
|
|
|
|
}
|
|
|
|
|
|
|
|
public RoomTile getPrevious()
|
|
|
|
{
|
|
|
|
return this.previous;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setPrevious(RoomTile previous)
|
|
|
|
{
|
|
|
|
this.previous = previous;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setMovementPanelty(short movementPanelty)
|
|
|
|
{
|
|
|
|
this.movementPanelty = movementPanelty;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getfCosts()
|
|
|
|
{
|
|
|
|
return this.gCosts + this.hCosts;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getgCosts()
|
|
|
|
{
|
|
|
|
return this.gCosts;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setgCosts(short gCosts)
|
|
|
|
{
|
|
|
|
this.gCosts = (short)(gCosts + this.movementPanelty);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setgCosts(RoomTile previousRoomTile, int basicCost)
|
|
|
|
{
|
|
|
|
setgCosts((short)(previousRoomTile.getgCosts() + basicCost));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setgCosts(RoomTile previousRoomTile)
|
|
|
|
{
|
|
|
|
setgCosts(previousRoomTile, this.diagonally ? RoomLayout.DIAGONALMOVEMENTCOST : RoomLayout.BASICMOVEMENTCOST);
|
|
|
|
}
|
|
|
|
|
|
|
|
public int calculategCosts(RoomTile previousRoomTile)
|
|
|
|
{
|
|
|
|
if (this.diagonally)
|
|
|
|
{
|
|
|
|
return previousRoomTile.getgCosts() + 14 + this.movementPanelty;
|
|
|
|
}
|
|
|
|
|
|
|
|
return previousRoomTile.getgCosts() + 10 + this.movementPanelty;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int calculategCosts(RoomTile previousRoomTile, int movementCost)
|
|
|
|
{
|
|
|
|
return previousRoomTile.getgCosts() + movementCost + this.movementPanelty;
|
|
|
|
}
|
|
|
|
|
|
|
|
int gethCosts()
|
|
|
|
{
|
|
|
|
return this.hCosts;
|
|
|
|
}
|
|
|
|
|
|
|
|
void sethCosts(short hCosts)
|
|
|
|
{
|
|
|
|
this.hCosts = hCosts;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|