Cleanup part 1 (#213)

* Clean up part 1

- Removed lots of dead code
- Removed unncessary files not in use
- Cleaned up small bits of code
- Removed a few warnings
- Server.java ---> GameEngine.java
- Constants.java ---> GameConstants.java

* Cape Dye

Rewrote cape dying

* Packaging

- redone ----> com.rebotted

* PacketSender/clean up

- ActionSender ---> PacketSender
- Moved many more packets to packetsender
- Cleaned up more dead code

* Merge Client/Player

- Merged Client.java with Player.java (both were doing same thing so redundant to have both)
- Removed some more dead code
- Tidy a few small things up

* Quests/more clean up

- Removed more dead code
- Made quests static in order to clean them up a bit

* More cleanup

- Removed some more of the dead quest code
- Correcting naming of some of the shop variables
This commit is contained in:
Mr Extremez
2019-11-25 12:08:56 -05:00
committed by Daniel Ginovker
parent 3d1ae1b288
commit d876a923b9
379 changed files with 80684 additions and 83170 deletions
@@ -0,0 +1,95 @@
package com.rebotted.world.clip;
public class ByteStream {
private final byte[] buffer;
private int offset;
public ByteStream(byte[] buffer) {
this.buffer = buffer;
offset = 0;
}
public void skip(int length) {
offset += length;
}
public void setOffset(int position) {
offset = position;
}
public void setOffset(long position) {
offset = (int) position;
}
public int length() {
return buffer.length;
}
public byte getByte() {
return buffer[offset++];
}
public int getUByte() {
return buffer[offset++] & 0xff;
}
public int getShort() {
int val = (getByte() << 8) + getByte();
if (val > 32767) {
val -= 0x10000;
}
return val;
}
public int getUShort() {
return (getUByte() << 8) + getUByte();
}
public int getInt() {
return (getUByte() << 24) + (getUByte() << 16) + (getUByte() << 8)
+ getUByte();
}
public long getLong() {
return (getUByte() << 56) + (getUByte() << 48) + (getUByte() << 40)
+ (getUByte() << 32) + (getUByte() << 24) + (getUByte() << 16)
+ (getUByte() << 8) + getUByte();
}
public int getUSmart() {
int i = buffer[offset] & 0xff;
if (i < 128) {
return getUByte();
} else {
return getUShort() - 32768;
}
}
public String getNString() {
int i = offset;
while (buffer[offset++] != 0) {
;
}
return new String(buffer, i, offset - i - 1);
}
public byte[] getBytes() {
int i = offset;
while (buffer[offset++] != 10) {
;
}
byte abyte0[] = new byte[offset - i - 1];
System.arraycopy(buffer, i, abyte0, i - i, offset - 1 - i);
return abyte0;
}
public byte[] read(int length) {
byte[] b = new byte[length];
for (int i = 0; i < length; i++) {
b[i] = buffer[offset++];
}
return b;
}
}
@@ -0,0 +1,102 @@
package com.rebotted.world.clip;
public final class ByteStreamExt {
public void skip(int length) {
currentOffset += length;
}
public ByteStreamExt(byte abyte0[]) {
buffer = abyte0;
currentOffset = 0;
}
public int readUnsignedByte() {
return buffer[currentOffset++] & 0xff;
}
public byte readSignedByte() {
return buffer[currentOffset++];
}
public int readUnsignedWord() {
currentOffset += 2;
return ((buffer[currentOffset - 2] & 0xff) << 8)
+ (buffer[currentOffset - 1] & 0xff);
}
public int readSignedWord() {
currentOffset += 2;
int i = ((buffer[currentOffset - 2] & 0xff) << 8)
+ (buffer[currentOffset - 1] & 0xff);
if (i > 32767) {
i -= 0x10000;
}
return i;
}
public int read3Bytes() {
currentOffset += 3;
return ((buffer[currentOffset - 3] & 0xff) << 16)
+ ((buffer[currentOffset - 2] & 0xff) << 8)
+ (buffer[currentOffset - 1] & 0xff);
}
public int readR3Bytes() {
currentOffset += 3;
return ((buffer[currentOffset - 1] & 0xff) << 16)
+ ((buffer[currentOffset - 2] & 0xff) << 8)
+ (buffer[currentOffset - 3] & 0xff);
}
public int readDWord() {
currentOffset += 4;
return ((buffer[currentOffset - 4] & 0xff) << 24)
+ ((buffer[currentOffset - 3] & 0xff) << 16)
+ ((buffer[currentOffset - 2] & 0xff) << 8)
+ (buffer[currentOffset - 1] & 0xff);
}
public long readQWord() {
long l = readDWord() & 0xffffffffL;
long l1 = readDWord() & 0xffffffffL;
return (l << 32) + l1;
}
public String readString() {
int i = currentOffset;
while (buffer[currentOffset++] != 10) {
;
}
return new String(buffer, i, currentOffset - i - 1);
}
public String readNewString() {
int i = currentOffset;
while (buffer[currentOffset++] != 0) {
;
}
return new String(buffer, i, currentOffset - i - 1);
}
public byte[] readBytes() {
int i = currentOffset;
while (buffer[currentOffset++] != 10) {
;
}
byte abyte0[] = new byte[currentOffset - i - 1];
System.arraycopy(buffer, i, abyte0, i - i, currentOffset - 1 - i);
return abyte0;
}
public void readBytes(int i, int j, byte abyte0[]) {
for (int l = j; l < j + i; l++) {
abyte0[l] = buffer[currentOffset++];
}
}
public byte buffer[];
public int currentOffset;
// removed useless static initializer
}
@@ -0,0 +1,35 @@
package com.rebotted.world.clip;
public class MemoryArchive {
private final ByteStream cache;
private final ByteStream index;
private static final int INDEX_DATA_CHUNK_SIZE = 12;
public MemoryArchive(ByteStream cache, ByteStream index) {
this.cache = cache;
this.index = index;
}
public byte[] get(int dataIndex) {
try {
if (index.length() < dataIndex * INDEX_DATA_CHUNK_SIZE) {
return null;
}
index.setOffset(dataIndex * INDEX_DATA_CHUNK_SIZE);
long fileOffset = index.getLong();
int fileSize = index.getInt();
cache.setOffset(fileOffset);
byte[] buffer = cache.read(fileSize);
return buffer;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public int contentSize() {
return index.length() / 12;
}
}
@@ -0,0 +1,316 @@
package com.rebotted.world.clip;
public final class ObjectDef {
public static ObjectDef getObjectDef(int i) {
for (int j = 0; j < 20; j++) {
if (cache[j].type == i) {
return cache[j];
}
}
cacheIndex = (cacheIndex + 1) % 20;
ObjectDef class46 = cache[cacheIndex];
class46.type = i;
class46.setDefaults();
byte[] buffer = archive.get(i);
if (buffer != null && buffer.length > 0) {
class46.readValues(new ByteStreamExt(buffer));
}
return class46;
}
private void setDefaults() {
anIntArray773 = null;
anIntArray776 = null;
name = null;
description = null;
modifiedModelColors = null;
originalModelColors = null;
anInt744 = 1;
anInt761 = 1;
aBoolean767 = true;
aBoolean757 = true;
hasActions = false;
aBoolean762 = false;
aBoolean764 = false;
anInt781 = -1;
anInt775 = 16;
actions = null;
anInt746 = -1;
anInt758 = -1;
aBoolean779 = true;
anInt768 = 0;
aBoolean736 = false;
anInt774 = -1;
anInt749 = -1;
childrenIDs = null;
}
public static void loadConfig() {
archive = new MemoryArchive(new ByteStream(getBuffer("loc.dat")),
new ByteStream(getBuffer("loc.idx")));
cache = new ObjectDef[20];
for (int k = 0; k < 20; k++) {
cache[k] = new ObjectDef();
}
System.out.println("[ObjectDef] DONE LOADING OBJECT CONFIGURATION");
}
public static byte[] getBuffer(String s) {
try {
java.io.File f = new java.io.File("./data/world/object/" + s);
if (!f.exists()) {
return null;
}
byte[] buffer = new byte[(int) f.length()];
java.io.DataInputStream dis = new java.io.DataInputStream(
new java.io.FileInputStream(f));
dis.readFully(buffer);
dis.close();
return buffer;
} catch (Exception e) {
}
return null;
}
private void readValues(ByteStreamExt stream) {
int flag = -1;
do {
int type = stream.readUnsignedByte();
if (type == 0) {
break;
}
if (type == 1) {
int len = stream.readUnsignedByte();
if (len > 0) {
if (anIntArray773 == null || lowMem) {
anIntArray776 = new int[len];
anIntArray773 = new int[len];
for (int k1 = 0; k1 < len; k1++) {
anIntArray773[k1] = stream.readUnsignedWord();
anIntArray776[k1] = stream.readUnsignedByte();
}
} else {
stream.currentOffset += len * 3;
}
}
} else if (type == 2) {
name = stream.readNewString();
} else if (type == 5) {
int len = stream.readUnsignedByte();
if (len > 0) {
if (anIntArray773 == null || lowMem) {
anIntArray776 = null;
anIntArray773 = new int[len];
for (int l1 = 0; l1 < len; l1++) {
anIntArray773[l1] = stream.readUnsignedWord();
}
} else {
stream.currentOffset += len * 2;
}
}
} else if (type == 14) {
anInt744 = stream.readUnsignedByte();
} else if (type == 15) {
anInt761 = stream.readUnsignedByte();
} else if (type == 17) {
aBoolean767 = false;
} else if (type == 18) {
aBoolean757 = false;
} else if (type == 19) {
hasActions = stream.readUnsignedByte() == 1;
} else if (type == 21) {
aBoolean762 = true;
} else if (type == 22) {
} else if (type == 23) {
aBoolean764 = true;
} else if (type == 24) {
anInt781 = stream.readUnsignedWord();
if (anInt781 == 65535) {
anInt781 = -1;
}
} else if (type == 27) {
continue;
} else if (type == 28) {
anInt775 = stream.readUnsignedByte();
} else if (type == 29) {
stream.readSignedByte();
} else if (type == 39) {
stream.readSignedByte();
} else if (type >= 30 && type < 39) {
if (actions == null) {
actions = new String[5];
}
actions[type - 30] = stream.readNewString();
hasActions = true;
if (actions[type - 30].equalsIgnoreCase("hidden")) {
actions[type - 30] = null;
}
} else if (type == 40) {
int i1 = stream.readUnsignedByte();
modifiedModelColors = new int[i1];
originalModelColors = new int[i1];
for (int i2 = 0; i2 < i1; i2++) {
modifiedModelColors[i2] = stream.readUnsignedWord();
originalModelColors[i2] = stream.readUnsignedWord();
}
} else if (type == 41) {
int l = stream.readUnsignedByte();
stream.skip(l * 4);
} else if (type == 42) {
int l = stream.readUnsignedByte();
stream.skip(l);
} else if (type == 60) {
anInt746 = stream.readUnsignedWord();
} else if (type == 62) {
} else if (type == 64) {
aBoolean779 = false;
} else if (type == 65) {
stream.readUnsignedWord();
} else if (type == 66) {
stream.readUnsignedWord();
} else if (type == 67) {
stream.readUnsignedWord();
} else if (type == 68) {
anInt758 = stream.readUnsignedWord();
} else if (type == 69) {
anInt768 = stream.readUnsignedByte();
} else if (type == 70) {
stream.readSignedWord();
} else if (type == 71) {
stream.readSignedWord();
} else if (type == 72) {
stream.readSignedWord();
} else if (type == 73) {
aBoolean736 = true;
} else if (type == 74) {
} else if (type == 75) {
stream.readUnsignedByte();
} else if (type == 77 || type == 92) {
anInt774 = stream.readUnsignedWord();
if (anInt774 == 65535) {
anInt774 = -1;
}
anInt749 = stream.readUnsignedWord();
if (anInt749 == 65535) {
anInt749 = -1;
}
int endChild = -1;
if (type == 92) {
endChild = stream.readUnsignedWord();
if (endChild == 65535) {
endChild = -1;
}
}
int j1 = stream.readUnsignedByte();
childrenIDs = new int[j1 + 2];
for (int j2 = 0; j2 <= j1; j2++) {
childrenIDs[j2] = stream.readUnsignedWord();
if (childrenIDs[j2] == 65535) {
childrenIDs[j2] = -1;
}
}
childrenIDs[j1 + 1] = endChild;
} else if (type == 78) {
stream.skip(3);
} else if (type == 79) {
stream.skip(5);
int l = stream.readUnsignedByte();
stream.skip(l * 2);
} else if (type == 81) {
stream.skip(1);
} else if (type == 82 || type == 88 || type == 89 || type == 90
|| type == 91 || type == 94 || type == 95 || type == 96
|| type == 97) {
continue;
} else if (type == 93) {
stream.skip(2);
} else if (type == 249) {
int l = stream.readUnsignedByte();
for (int ii = 0; ii < l; ii++) {
boolean b = stream.readUnsignedByte() == 1;
stream.skip(3);
if (b) {
stream.readNewString();
} else {
stream.skip(4);
}
}
} else {
System.out.println("Unknown config: " + type);
}
} while (true);
if (flag == -1) {
hasActions = anIntArray773 != null
&& (anIntArray776 == null || anIntArray776[0] == 10);
if (actions != null) {
hasActions = true;
}
}
}
private ObjectDef() {
type = -1;
}
public boolean hasActions() {
return hasActions;
}
public boolean hasName() {
return name != null && name.length() > 1;
}
public boolean solid() {
return aBoolean779;
}
public int xLength() {
return anInt744;
}
public int yLength() {
return anInt761;
}
public boolean aBoolean767() {
return aBoolean767;
}
public boolean isUnshootable() {
return aBoolean757;
}
public boolean aBoolean736;
public String name;
public int anInt744;
public int anInt746;
private int[] originalModelColors;
public int anInt749;
public static boolean lowMem;
public int type;
public boolean aBoolean757;
public int anInt758;
public int childrenIDs[];
public int anInt761;
public boolean aBoolean762;
public boolean aBoolean764;
public boolean aBoolean767;
public int anInt768;
private static int cacheIndex;
private int[] anIntArray773;
public int anInt774;
public int anInt775;
private int[] anIntArray776;
public byte description[];
public boolean hasActions;
public boolean aBoolean779;
public int anInt781;
private static ObjectDef[] cache;
private int[] modifiedModelColors;
public String actions[];
private static MemoryArchive archive;
}
@@ -0,0 +1,416 @@
package com.rebotted.world.clip;
import java.util.LinkedList;
import com.rebotted.game.players.Client;
import com.rebotted.game.players.Player;
import com.rebotted.util.Misc;
public class PathFinder {
private static final PathFinder pathFinder = new PathFinder();
public static PathFinder getPathFinder() {
return pathFinder;
}
public void findRoute(Player player, int destX, int destY, boolean moveNear,
int xLength, int yLength) {
if (destX == player.getLocalX() && destY == player.getLocalY() && !moveNear) {
player.getPacketSender().sendMessage("ERROR!");
return;
}
destX = destX - 8 * player.getMapRegionX();
destY = destY - 8 * player.getMapRegionY();
int[][] via = new int[104][104];
int[][] cost = new int[104][104];
LinkedList<Integer> tileQueueX = new LinkedList<Integer>();
LinkedList<Integer> tileQueueY = new LinkedList<Integer>();
for (int xx = 0; xx < 104; xx++) {
for (int yy = 0; yy < 104; yy++) {
cost[xx][yy] = 99999999;
}
}
int curX = player.getLocalX();
int curY = player.getLocalY();
via[curX][curY] = 99;
cost[curX][curY] = 0;
int tail = 0;
tileQueueX.add(curX);
tileQueueY.add(curY);
boolean foundPath = false;
int pathLength = 4000;
while (tail != tileQueueX.size() && tileQueueX.size() < pathLength) {
curX = tileQueueX.get(tail);
curY = tileQueueY.get(tail);
int curAbsX = player.getMapRegionX() * 8 + curX;
int curAbsY = player.getMapRegionY() * 8 + curY;
if (curX == destX && curY == destY) {
foundPath = true;
break;
}
tail = (tail + 1) % pathLength;
int thisCost = cost[curX][curY] + 1;
if (curY > 0
&& via[curX][curY - 1] == 0
&& (Region.getClipping(curAbsX, curAbsY - 1, player.heightLevel) & 0x1280102) == 0) {
tileQueueX.add(curX);
tileQueueY.add(curY - 1);
via[curX][curY - 1] = 1;
cost[curX][curY - 1] = thisCost;
}
if (curX > 0
&& via[curX - 1][curY] == 0
&& (Region.getClipping(curAbsX - 1, curAbsY, player.heightLevel) & 0x1280108) == 0) {
tileQueueX.add(curX - 1);
tileQueueY.add(curY);
via[curX - 1][curY] = 2;
cost[curX - 1][curY] = thisCost;
}
if (curY < 104 - 1
&& via[curX][curY + 1] == 0
&& (Region.getClipping(curAbsX, curAbsY + 1, player.heightLevel) & 0x1280120) == 0) {
tileQueueX.add(curX);
tileQueueY.add(curY + 1);
via[curX][curY + 1] = 4;
cost[curX][curY + 1] = thisCost;
}
if (curX < 104 - 1
&& via[curX + 1][curY] == 0
&& (Region.getClipping(curAbsX + 1, curAbsY, player.heightLevel) & 0x1280180) == 0) {
tileQueueX.add(curX + 1);
tileQueueY.add(curY);
via[curX + 1][curY] = 8;
cost[curX + 1][curY] = thisCost;
}
if (curX > 0
&& curY > 0
&& via[curX - 1][curY - 1] == 0
&& (Region.getClipping(curAbsX - 1, curAbsY - 1,
player.heightLevel) & 0x128010e) == 0
&& (Region.getClipping(curAbsX - 1, curAbsY, player.heightLevel) & 0x1280108) == 0
&& (Region.getClipping(curAbsX, curAbsY - 1, player.heightLevel) & 0x1280102) == 0) {
tileQueueX.add(curX - 1);
tileQueueY.add(curY - 1);
via[curX - 1][curY - 1] = 3;
cost[curX - 1][curY - 1] = thisCost;
}
if (curX > 0
&& curY < 104 - 1
&& via[curX - 1][curY + 1] == 0
&& (Region.getClipping(curAbsX - 1, curAbsY + 1,
player.heightLevel) & 0x1280138) == 0
&& (Region.getClipping(curAbsX - 1, curAbsY, player.heightLevel) & 0x1280108) == 0
&& (Region.getClipping(curAbsX, curAbsY + 1, player.heightLevel) & 0x1280120) == 0) {
tileQueueX.add(curX - 1);
tileQueueY.add(curY + 1);
via[curX - 1][curY + 1] = 6;
cost[curX - 1][curY + 1] = thisCost;
}
if (curX < 104 - 1
&& curY > 0
&& via[curX + 1][curY - 1] == 0
&& (Region.getClipping(curAbsX + 1, curAbsY - 1,
player.heightLevel) & 0x1280183) == 0
&& (Region.getClipping(curAbsX + 1, curAbsY, player.heightLevel) & 0x1280180) == 0
&& (Region.getClipping(curAbsX, curAbsY - 1, player.heightLevel) & 0x1280102) == 0) {
tileQueueX.add(curX + 1);
tileQueueY.add(curY - 1);
via[curX + 1][curY - 1] = 9;
cost[curX + 1][curY - 1] = thisCost;
}
if (curX < 104 - 1
&& curY < 104 - 1
&& via[curX + 1][curY + 1] == 0
&& (Region.getClipping(curAbsX + 1, curAbsY + 1,
player.heightLevel) & 0x12801e0) == 0
&& (Region.getClipping(curAbsX + 1, curAbsY, player.heightLevel) & 0x1280180) == 0
&& (Region.getClipping(curAbsX, curAbsY + 1, player.heightLevel) & 0x1280120) == 0) {
tileQueueX.add(curX + 1);
tileQueueY.add(curY + 1);
via[curX + 1][curY + 1] = 12;
cost[curX + 1][curY + 1] = thisCost;
}
}
if (!foundPath) {
if (moveNear) {
int i_223_ = 1000;
int thisCost = 100;
int i_225_ = 10;
for (int x = destX - i_225_; x <= destX + i_225_; x++) {
for (int y = destY - i_225_; y <= destY + i_225_; y++) {
if (x >= 0 && y >= 0 && x < 104 && y < 104
&& cost[x][y] < 100) {
int i_228_ = 0;
if (x < destX) {
i_228_ = destX - x;
} else if (x > destX + xLength - 1) {
i_228_ = x - (destX + xLength - 1);
}
int i_229_ = 0;
if (y < destY) {
i_229_ = destY - y;
} else if (y > destY + yLength - 1) {
i_229_ = y - (destY + yLength - 1);
}
int i_230_ = i_228_ * i_228_ + i_229_ * i_229_;
if (i_230_ < i_223_ || i_230_ == i_223_
&& cost[x][y] < thisCost) {
i_223_ = i_230_;
thisCost = cost[x][y];
curX = x;
curY = y;
}
}
}
}
if (i_223_ == 1000) {
return;
}
} else {
return;
}
}
tail = 0;
tileQueueX.set(tail, curX);
tileQueueY.set(tail++, curY);
int l5;
for (int j5 = l5 = via[curX][curY]; curX != player.getLocalX()
|| curY != player.getLocalY(); j5 = via[curX][curY]) {
if (j5 != l5) {
l5 = j5;
tileQueueX.set(tail, curX);
tileQueueY.set(tail++, curY);
}
if ((j5 & 2) != 0) {
curX++;
} else if ((j5 & 8) != 0) {
curX--;
}
if ((j5 & 1) != 0) {
curY++;
} else if ((j5 & 4) != 0) {
curY--;
}
}
player.resetWalkingQueue();
int size = tail--;
int pathX = player.getMapRegionX() * 8 + tileQueueX.get(tail);
int pathY = player.getMapRegionY() * 8 + tileQueueY.get(tail);
player.addToWalkingQueue(localize(pathX, player.getMapRegionX()),
localize(pathY, player.getMapRegionY()));
for (int i = 1; i < size; i++) {
tail--;
pathX = player.getMapRegionX() * 8 + tileQueueX.get(tail);
pathY = player.getMapRegionY() * 8 + tileQueueY.get(tail);
player.addToWalkingQueue(localize(pathX, player.getMapRegionX()),
localize(pathY, player.getMapRegionY()));
}
}
public int getRegionCoordinate(int x) {
return (x >> 3) - 6;
}
public int getLocalCoordinate(int x) {
return x - 8 * getRegionCoordinate(x);
}
public boolean accessible(int x, int y, int heightLevel, int destX, int destY) {
destX = destX - 8 * getRegionCoordinate(x);
destY = destY - 8 * getRegionCoordinate(y);
int[][] via = new int[104][104];
int[][] cost = new int[104][104];
LinkedList<Integer> tileQueueX = new LinkedList<Integer>();
LinkedList<Integer> tileQueueY = new LinkedList<Integer>();
for (int xx = 0; xx < 104; xx++) {
for (int yy = 0; yy < 104; yy++) {
cost[xx][yy] = 99999999;
}
}
int curX = getLocalCoordinate(x);
int curY = getLocalCoordinate(y);
via[curX][curY] = 99;
cost[curX][curY] = 0;
int tail = 0;
tileQueueX.add(curX);
tileQueueY.add(curY);
boolean foundPath = false;
int pathLength = 4000;
while (tail != tileQueueX.size() && tileQueueX.size() < pathLength) {
curX = tileQueueX.get(tail);
curY = tileQueueY.get(tail);
int curAbsX = getRegionCoordinate(x) * 8 + curX;
int curAbsY = getRegionCoordinate(y) * 8 + curY;
if (curX == destX && curY == destY) {
foundPath = true;
break;
}
tail = (tail + 1) % pathLength;
int thisCost = cost[curX][curY] + 1;
if (curY > 0
&& via[curX][curY - 1] == 0
&& (Region.getClipping(curAbsX, curAbsY - 1, heightLevel) & 0x1280102) == 0) {
tileQueueX.add(curX);
tileQueueY.add(curY - 1);
via[curX][curY - 1] = 1;
cost[curX][curY - 1] = thisCost;
}
if (curX > 0
&& via[curX - 1][curY] == 0
&& (Region.getClipping(curAbsX - 1, curAbsY, heightLevel) & 0x1280108) == 0) {
tileQueueX.add(curX - 1);
tileQueueY.add(curY);
via[curX - 1][curY] = 2;
cost[curX - 1][curY] = thisCost;
}
if (curY < 104 - 1
&& via[curX][curY + 1] == 0
&& (Region.getClipping(curAbsX, curAbsY + 1, heightLevel) & 0x1280120) == 0) {
tileQueueX.add(curX);
tileQueueY.add(curY + 1);
via[curX][curY + 1] = 4;
cost[curX][curY + 1] = thisCost;
}
if (curX < 104 - 1
&& via[curX + 1][curY] == 0
&& (Region.getClipping(curAbsX + 1, curAbsY, heightLevel) & 0x1280180) == 0) {
tileQueueX.add(curX + 1);
tileQueueY.add(curY);
via[curX + 1][curY] = 8;
cost[curX + 1][curY] = thisCost;
}
if (curX > 0
&& curY > 0
&& via[curX - 1][curY - 1] == 0
&& (Region.getClipping(curAbsX - 1, curAbsY - 1,
heightLevel) & 0x128010e) == 0
&& (Region.getClipping(curAbsX - 1, curAbsY, heightLevel) & 0x1280108) == 0
&& (Region.getClipping(curAbsX, curAbsY - 1, heightLevel) & 0x1280102) == 0) {
tileQueueX.add(curX - 1);
tileQueueY.add(curY - 1);
via[curX - 1][curY - 1] = 3;
cost[curX - 1][curY - 1] = thisCost;
}
if (curX > 0
&& curY < 104 - 1
&& via[curX - 1][curY + 1] == 0
&& (Region.getClipping(curAbsX - 1, curAbsY + 1,
heightLevel) & 0x1280138) == 0
&& (Region.getClipping(curAbsX - 1, curAbsY, heightLevel) & 0x1280108) == 0
&& (Region.getClipping(curAbsX, curAbsY + 1, heightLevel) & 0x1280120) == 0) {
tileQueueX.add(curX - 1);
tileQueueY.add(curY + 1);
via[curX - 1][curY + 1] = 6;
cost[curX - 1][curY + 1] = thisCost;
}
if (curX < 104 - 1
&& curY > 0
&& via[curX + 1][curY - 1] == 0
&& (Region.getClipping(curAbsX + 1, curAbsY - 1,
heightLevel) & 0x1280183) == 0
&& (Region.getClipping(curAbsX + 1, curAbsY, heightLevel) & 0x1280180) == 0
&& (Region.getClipping(curAbsX, curAbsY - 1, heightLevel) & 0x1280102) == 0) {
tileQueueX.add(curX + 1);
tileQueueY.add(curY - 1);
via[curX + 1][curY - 1] = 9;
cost[curX + 1][curY - 1] = thisCost;
}
if (curX < 104 - 1
&& curY < 104 - 1
&& via[curX + 1][curY + 1] == 0
&& (Region.getClipping(curAbsX + 1, curAbsY + 1,
heightLevel) & 0x12801e0) == 0
&& (Region.getClipping(curAbsX + 1, curAbsY, heightLevel) & 0x1280180) == 0
&& (Region.getClipping(curAbsX, curAbsY + 1, heightLevel) & 0x1280120) == 0) {
tileQueueX.add(curX + 1);
tileQueueY.add(curY + 1);
via[curX + 1][curY + 1] = 12;
cost[curX + 1][curY + 1] = thisCost;
}
}
return foundPath;
}
public static boolean isProjectilePathClear(int x0, int y0, int z, int x1, int y1) {
int deltaX = x1 - x0;
int deltaY = y1 - y0;
double error = 0;
final double deltaError = Math.abs(
(deltaY) / (deltaX == 0
? ((double) deltaY)
: ((double) deltaX)));
int x = x0;
int y = y0;
int pX = x;
int pY = y;
boolean incrX = x0 < x1;
boolean incrY = y0 < y1;
while (true) {
if (x != x1) {
x += (incrX ? 1 : -1);
}
if (y != y1) {
error += deltaError;
if (error >= 0.5) {
y += (incrY ? 1 : -1);
error -= 1;
}
}
if (!shootable(x, y, z, pX, pY)) {
return false;
}
if (incrX && incrY
&& x >= x1 && y >= y1) {
break;
} else if (!incrX && !incrY
&& x <= x1 && y <= y1) {
break;
} else if (!incrX && incrY
&& x <= x1 && y >= y1) {
break;
} else if (incrX && !incrY
&& x >= x1 && y <= y1) {
break;
}
pX = x;
pY = y;
}
return true;
}
private static boolean shootable(int x, int y, int z, int px, int py) {
if (x == px && y == py) {
return true;
}
int[] delta1 = Misc.delta(x, y, px, py);
int[] delta2 = Misc.delta(px, py, x, y);
int dir = Misc.directionFromDelta(delta1[0], delta1[1]);
int dir2 = Misc.directionFromDelta(delta2[0], delta2[1]);
if (dir == -1 || dir2 == -1) {
return false;
}
return Region.canMove(x, y, z, dir) && Region.canMove(px, py, z, dir2)
|| Region.canShoot(x, y, z, dir) && Region.canShoot(px, py, z, dir2);
}
public int localize(int x, int mapRegion) {
return x - 8 * mapRegion;
}
}
@@ -0,0 +1,826 @@
package com.rebotted.world.clip;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.zip.GZIPInputStream;
import com.rebotted.game.objects.Objects;
public class Region {
private ArrayList<Objects> realObjects = new ArrayList<Objects>();
public static Region getRegion(int x, int y) {
int regionX = x >> 3;
int regionY = y >> 3;
int regionId = (regionX / 8 << 8) + regionY / 8;
for (Region region : regions) {
if (region.id() == regionId) {
return region;
}
}
return null;
}
public static Objects getObject(int id, int x, int y, int z) {
Region r = getRegion(x, y);
if (r == null)
return null;
for (Objects o : r.realObjects) {
if (o.objectId == id) {
if (o.objectX == x && o.objectY == y && o.objectHeight == z) {
return o;
}
}
}
return null;
}
public static boolean objectExists(int id, int x, int y, int z) {
Region r = getRegion(x, y);
if (r == null)
return false;
for (Objects o : r.realObjects) {
if (o.objectId == id) {
if (o.objectX == x && o.objectY == y && o.objectHeight == z) {
return true;
}
}
}
return false;
}
private void addClip(int x, int y, int height, int shift) {
int regionAbsX = (id >> 8) * 64;
int regionAbsY = (id & 0xff) * 64;
if (clips[height] == null) {
clips[height] = new int[64][64];
}
clips[height][x - regionAbsX][y - regionAbsY] |= shift;
}
private void addProjectileClip(int x, int y, int height, int shift) {
int regionAbsX = (id >> 8) * 64;
int regionAbsY = (id & 0xff) * 64;
if (projectileClips[height] == null) {
projectileClips[height] = new int[64][64];
}
projectileClips[height][x - regionAbsX][y - regionAbsY] |= shift;
}
public static boolean canMove(int x, int y, int z, int direction) {
if (direction == 6) {
if ((Region.getClipping(x, y - 1, z) & 0x1280102) == 0) {
return true;
}
} else if (direction == 3) {
if ((Region.getClipping(x - 1, y, z) & 0x1280108) == 0) {
return true;
}
} else if (direction == 1) {
if ((Region.getClipping(x, y + 1, z) & 0x1280120) == 0) {
return true;
}
} else if (direction == 4) {
if ((Region.getClipping(x + 1, y, z) & 0x1280180) == 0) {
return true;
}
} else if (direction == 5) {
if ((Region.getClipping(x - 1, y - 1, z) & 0x128010e) == 0
&& (Region.getClipping(x - 1, y, z) & 0x1280108) == 0
&& (Region.getClipping(x, y - 1, z) & 0x1280102) == 0) {
return true;
}
} else if (direction == 0) {
if ((Region.getClipping(x - 1, y + 1, z) & 0x1280138) == 0
&& (Region.getClipping(x - 1, y, z) & 0x1280108) == 0
&& (Region.getClipping(x, y + 1, z) & 0x1280120) == 0) {
return true;
}
} else if (direction == 7) {
if ((Region.getClipping(x + 1, y - 1, z) & 0x1280183) == 0
&& (Region.getClipping(x + 1, y, z) & 0x1280180) == 0
&& (Region.getClipping(x, y - 1, z) & 0x1280102) == 0) {
return true;
}
} else if (direction == 2) {
if ((Region.getClipping(x + 1, y + 1, z) & 0x12801e0) == 0
&& (Region.getClipping(x + 1, y, z) & 0x1280180) == 0
&& (Region.getClipping(x, y + 1, z) & 0x1280120) == 0) {
return true;
}
} else if (direction == -1) {
throw new IllegalArgumentException("Invalid direction: " + direction);
}
return false;
}
public static boolean canShoot(int x, int y, int z, int direction) {
if (direction == 0) {
return !projectileBlockedNorthWest(x, y, z) && !projectileBlockedNorth(x, y, z)
&& !projectileBlockedWest(x, y, z);
} else if (direction == 1) {
return !projectileBlockedNorth(x, y, z);
} else if (direction == 2) {
return !projectileBlockedNorthEast(x, y, z) && !projectileBlockedNorth(x, y, z)
&& !projectileBlockedEast(x, y, z);
} else if (direction == 3) {
return !projectileBlockedWest(x, y, z);
} else if (direction == 4) {
return !projectileBlockedEast(x, y, z);
} else if (direction == 5) {
return !projectileBlockedSouthWest(x, y, z) && !projectileBlockedSouth(x, y, z)
&& !projectileBlockedWest(x, y, z);
} else if (direction == 6) {
return !projectileBlockedSouth(x, y, z);
} else if (direction == 7) {
return !projectileBlockedSouthEast(x, y, z) && !projectileBlockedSouth(x, y, z)
&& !projectileBlockedEast(x, y, z);
}
return false;
}
public static boolean projectileBlockedNorth(int x, int y, int z) {
return (getProjectileClipping(x, y + 1, z) & 0x1280120) != 0;
}
public static boolean projectileBlockedEast(int x, int y, int z) {
return (getProjectileClipping(x + 1, y, z) & 0x1280180) != 0;
}
public static boolean projectileBlockedSouth(int x, int y, int z) {
return (getProjectileClipping(x, y - 1, z) & 0x1280102) != 0;
}
public static boolean projectileBlockedWest(int x, int y, int z) {
return (getProjectileClipping(x - 1, y, z) & 0x1280108) != 0;
}
public static boolean projectileBlockedNorthEast(int x, int y, int z) {
return (getProjectileClipping(x + 1, y + 1, z) & 0x12801e0) != 0;
}
public static boolean projectileBlockedNorthWest(int x, int y, int z) {
return (getProjectileClipping(x - 1, y + 1, z) & 0x1280138) != 0;
}
public static boolean projectileBlockedSouthEast(int x, int y, int z) {
return (getProjectileClipping(x + 1, y - 1, z) & 0x1280183) != 0;
}
public static boolean projectileBlockedSouthWest(int x, int y, int z) {
return (getProjectileClipping(x - 1, y - 1, z) & 0x128010e) != 0;
}
public static boolean canMove(int startX, int startY, int endX, int endY, int height, int xLength, int yLength) {
int diffX = endX - startX;
int diffY = endY - startY;
int max = Math.max(Math.abs(diffX), Math.abs(diffY));
for (int ii = 0; ii < max; ii++) {
int currentX = endX - diffX;
int currentY = endY - diffY;
for (int i = 0; i < xLength; i++) {
for (int i2 = 0; i2 < yLength; i2++)
if (diffX < 0 && diffY < 0) {
if ((getClipping((currentX + i) - 1,
(currentY + i2) - 1, height) & 0x128010e) != 0
|| (getClipping((currentX + i) - 1, currentY
+ i2, height) & 0x1280108) != 0
|| (getClipping(currentX + i,
(currentY + i2) - 1, height) & 0x1280102) != 0)
return false;
} else if (diffX > 0 && diffY > 0) {
if ((getClipping(currentX + i + 1, currentY + i2 + 1,
height) & 0x12801e0) != 0
|| (getClipping(currentX + i + 1,
currentY + i2, height) & 0x1280180) != 0
|| (getClipping(currentX + i,
currentY + i2 + 1, height) & 0x1280120) != 0)
return false;
} else if (diffX < 0 && diffY > 0) {
if ((getClipping((currentX + i) - 1, currentY + i2 + 1,
height) & 0x1280138) != 0
|| (getClipping((currentX + i) - 1, currentY
+ i2, height) & 0x1280108) != 0
|| (getClipping(currentX + i,
currentY + i2 + 1, height) & 0x1280120) != 0)
return false;
} else if (diffX > 0 && diffY < 0) {
if ((getClipping(currentX + i + 1, (currentY + i2) - 1,
height) & 0x1280183) != 0
|| (getClipping(currentX + i + 1,
currentY + i2, height) & 0x1280180) != 0
|| (getClipping(currentX + i,
(currentY + i2) - 1, height) & 0x1280102) != 0)
return false;
} else if (diffX > 0 && diffY == 0) {
if ((getClipping(currentX + i + 1, currentY + i2,
height) & 0x1280180) != 0)
return false;
} else if (diffX < 0 && diffY == 0) {
if ((getClipping((currentX + i) - 1, currentY + i2,
height) & 0x1280108) != 0)
return false;
} else if (diffX == 0 && diffY > 0) {
if ((getClipping(currentX + i, currentY + i2 + 1,
height) & 0x1280120) != 0)
return false;
} else if (diffX == 0
&& diffY < 0
&& (getClipping(currentX + i, (currentY + i2) - 1,
height) & 0x1280102) != 0)
return false;
}
if (diffX < 0)
diffX++;
else if (diffX > 0)
diffX--;
if (diffY < 0)
diffY++;
else if (diffY > 0)
diffY--;
}
return true;
}
private int getClip(int x, int y, int height) {
int regionAbsX = (id >> 8) * 64;
int regionAbsY = (id & 0xff) * 64;
if (clips[height] == null) {
return 0;
}
return clips[height][x - regionAbsX][y - regionAbsY];
}
private int getProjectileClip(int x, int y, int height) {
int regionAbsX = (id >> 8) * 64;
int regionAbsY = (id & 0xff) * 64;
if (projectileClips[height] == null) {
return 0;
}
return projectileClips[height][x - regionAbsX][y - regionAbsY];
}
private static void addClipping(int x, int y, int height, int shift) {
int regionX = x >> 3;
int regionY = y >> 3;
int regionId = (regionX / 8 << 8) + regionY / 8;
for (Region r : regions) {
if (r.id() == regionId) {
r.addClip(x, y, height, shift);
break;
}
}
}
private static void addProjectileClipping(int x, int y, int height, int shift) {
int regionX = x >> 3;
int regionY = y >> 3;
int regionId = (regionX / 8 << 8) + regionY / 8;
for (Region r : regions) {
if (r.id() == regionId) {
r.addProjectileClip(x, y, height, shift);
break;
}
}
}
private static Region[] regions;
private final int id;
private final int[][][] clips = new int[4][][];
private final int[][][] projectileClips = new int[4][][];
private boolean members = false;
public Region(int id, boolean members) {
this.id = id;
this.members = members;
}
public int id() {
return id;
}
public boolean members() {
return members;
}
public static boolean isMembers(int x, int y, int height) {
if (x >= 3272 && x <= 3320 && y >= 2752 && y <= 2809) {
return false;
}
if (x >= 2640 && x <= 2677 && y >= 2638 && y <= 2679) {
return false;
}
int regionX = x >> 3;
int regionY = y >> 3;
int regionId = (regionX / 8 << 8) + regionY / 8;
for (Region r : regions) {
if (r.id() == regionId) {
return r.members();
}
}
return false;
}
private static void addClippingForVariableObject(int x, int y, int height,
int type, int direction, boolean flag) {
if (type == 0) {
if (direction == 0) {
addClipping(x, y, height, 128);
addClipping(x - 1, y, height, 8);
} else if (direction == 1) {
addClipping(x, y, height, 2);
addClipping(x, y + 1, height, 32);
} else if (direction == 2) {
addClipping(x, y, height, 8);
addClipping(x + 1, y, height, 128);
} else if (direction == 3) {
addClipping(x, y, height, 32);
addClipping(x, y - 1, height, 2);
}
} else if (type == 1 || type == 3) {
if (direction == 0) {
addClipping(x, y, height, 1);
addClipping(x - 1, y, height, 16);
} else if (direction == 1) {
addClipping(x, y, height, 4);
addClipping(x + 1, y + 1, height, 64);
} else if (direction == 2) {
addClipping(x, y, height, 16);
addClipping(x + 1, y - 1, height, 1);
} else if (direction == 3) {
addClipping(x, y, height, 64);
addClipping(x - 1, y - 1, height, 4);
}
} else if (type == 2) {
if (direction == 0) {
addClipping(x, y, height, 130);
addClipping(x - 1, y, height, 8);
addClipping(x, y + 1, height, 32);
} else if (direction == 1) {
addClipping(x, y, height, 10);
addClipping(x, y + 1, height, 32);
addClipping(x + 1, y, height, 128);
} else if (direction == 2) {
addClipping(x, y, height, 40);
addClipping(x + 1, y, height, 128);
addClipping(x, y - 1, height, 2);
} else if (direction == 3) {
addClipping(x, y, height, 160);
addClipping(x, y - 1, height, 2);
addClipping(x - 1, y, height, 8);
}
}
if (flag) {
if (type == 0) {
if (direction == 0) {
addClipping(x, y, height, 65536);
addClipping(x - 1, y, height, 4096);
} else if (direction == 1) {
addClipping(x, y, height, 1024);
addClipping(x, y + 1, height, 16384);
} else if (direction == 2) {
addClipping(x, y, height, 4096);
addClipping(x + 1, y, height, 65536);
} else if (direction == 3) {
addClipping(x, y, height, 16384);
addClipping(x, y - 1, height, 1024);
}
}
if (type == 1 || type == 3) {
if (direction == 0) {
addClipping(x, y, height, 512);
addClipping(x - 1, y + 1, height, 8192);
} else if (direction == 1) {
addClipping(x, y, height, 2048);
addClipping(x + 1, y + 1, height, 32768);
} else if (direction == 2) {
addClipping(x, y, height, 8192);
addClipping(x + 1, y + 1, height, 512);
} else if (direction == 3) {
addClipping(x, y, height, 32768);
addClipping(x - 1, y - 1, height, 2048);
}
} else if (type == 2) {
if (direction == 0) {
addClipping(x, y, height, 66560);
addClipping(x - 1, y, height, 4096);
addClipping(x, y + 1, height, 16384);
} else if (direction == 1) {
addClipping(x, y, height, 5120);
addClipping(x, y + 1, height, 16384);
addClipping(x + 1, y, height, 65536);
} else if (direction == 2) {
addClipping(x, y, height, 20480);
addClipping(x + 1, y, height, 65536);
addClipping(x, y - 1, height, 1024);
} else if (direction == 3) {
addClipping(x, y, height, 81920);
addClipping(x, y - 1, height, 1024);
addClipping(x - 1, y, height, 4096);
}
}
}
}
private static void addProjectileClippingForVariableObject(int x, int y, int height,
int type, int direction, boolean flag) {
if (type == 0) {
if (direction == 0) {
addProjectileClipping(x, y, height, 128);
addProjectileClipping(x - 1, y, height, 8);
} else if (direction == 1) {
addProjectileClipping(x, y, height, 2);
addProjectileClipping(x, y + 1, height, 32);
} else if (direction == 2) {
addProjectileClipping(x, y, height, 8);
addProjectileClipping(x + 1, y, height, 128);
} else if (direction == 3) {
addProjectileClipping(x, y, height, 32);
addProjectileClipping(x, y - 1, height, 2);
}
} else if (type == 1 || type == 3) {
if (direction == 0) {
addProjectileClipping(x, y, height, 1);
addProjectileClipping(x - 1, y, height, 16);
} else if (direction == 1) {
addProjectileClipping(x, y, height, 4);
addProjectileClipping(x + 1, y + 1, height, 64);
} else if (direction == 2) {
addProjectileClipping(x, y, height, 16);
addProjectileClipping(x + 1, y - 1, height, 1);
} else if (direction == 3) {
addProjectileClipping(x, y, height, 64);
addProjectileClipping(x - 1, y - 1, height, 4);
}
} else if (type == 2) {
if (direction == 0) {
addProjectileClipping(x, y, height, 130);
addProjectileClipping(x - 1, y, height, 8);
addProjectileClipping(x, y + 1, height, 32);
} else if (direction == 1) {
addProjectileClipping(x, y, height, 10);
addProjectileClipping(x, y + 1, height, 32);
addProjectileClipping(x + 1, y, height, 128);
} else if (direction == 2) {
addProjectileClipping(x, y, height, 40);
addProjectileClipping(x + 1, y, height, 128);
addProjectileClipping(x, y - 1, height, 2);
} else if (direction == 3) {
addProjectileClipping(x, y, height, 160);
addProjectileClipping(x, y - 1, height, 2);
addProjectileClipping(x - 1, y, height, 8);
}
}
if (flag) {
if (type == 0) {
if (direction == 0) {
addProjectileClipping(x, y, height, 65536);
addProjectileClipping(x - 1, y, height, 4096);
} else if (direction == 1) {
addProjectileClipping(x, y, height, 1024);
addProjectileClipping(x, y + 1, height, 16384);
} else if (direction == 2) {
addProjectileClipping(x, y, height, 4096);
addProjectileClipping(x + 1, y, height, 65536);
} else if (direction == 3) {
addProjectileClipping(x, y, height, 16384);
addProjectileClipping(x, y - 1, height, 1024);
}
}
if (type == 1 || type == 3) {
if (direction == 0) {
addProjectileClipping(x, y, height, 512);
addProjectileClipping(x - 1, y + 1, height, 8192);
} else if (direction == 1) {
addProjectileClipping(x, y, height, 2048);
addProjectileClipping(x + 1, y + 1, height, 32768);
} else if (direction == 2) {
addProjectileClipping(x, y, height, 8192);
addProjectileClipping(x + 1, y + 1, height, 512);
} else if (direction == 3) {
addProjectileClipping(x, y, height, 32768);
addProjectileClipping(x - 1, y - 1, height, 2048);
}
} else if (type == 2) {
if (direction == 0) {
addProjectileClipping(x, y, height, 66560);
addProjectileClipping(x - 1, y, height, 4096);
addProjectileClipping(x, y + 1, height, 16384);
} else if (direction == 1) {
addProjectileClipping(x, y, height, 5120);
addProjectileClipping(x, y + 1, height, 16384);
addProjectileClipping(x + 1, y, height, 65536);
} else if (direction == 2) {
addProjectileClipping(x, y, height, 20480);
addProjectileClipping(x + 1, y, height, 65536);
addProjectileClipping(x, y - 1, height, 1024);
} else if (direction == 3) {
addProjectileClipping(x, y, height, 81920);
addProjectileClipping(x, y - 1, height, 1024);
addProjectileClipping(x - 1, y, height, 4096);
}
}
}
}
private static void addClippingForSolidObject(int x, int y, int height,
int xLength, int yLength, boolean flag) {
int clipping = 256;
if (flag) {
clipping += 0x20000;
}
for (int i = x; i < x + xLength; i++) {
for (int i2 = y; i2 < y + yLength; i2++) {
addClipping(i, i2, height, clipping);
}
}
}
private static void addProjectileClippingForSolidObject(int x, int y, int height,
int xLength, int yLength, boolean flag) {
int clipping = 256;
if (flag) {
clipping += 0x20000;
}
for (int i = x; i < x + xLength; i++) {
for (int i2 = y; i2 < y + yLength; i2++) {
addProjectileClipping(i, i2, height, clipping);
}
}
}
public static void addObject(int objectId, int x, int y, int height, int type, int direction, boolean startUp) {
if (ObjectDef.getObjectDef(objectId) == null) {
}
int xLength;
int yLength;
if (direction != 1 && direction != 3) {
xLength = ObjectDef.getObjectDef(objectId).xLength();
yLength = ObjectDef.getObjectDef(objectId).yLength();
} else {
xLength = ObjectDef.getObjectDef(objectId).yLength();
yLength = ObjectDef.getObjectDef(objectId).xLength();
}
if (type == 22) {
if (ObjectDef.getObjectDef(objectId).hasActions()
&& ObjectDef.getObjectDef(objectId).aBoolean767()) {
addClipping(x, y, height, 0x200000);
if (ObjectDef.getObjectDef(objectId).isUnshootable()) {
addProjectileClipping(x, y, height, 0x200000);
}
}
} else if (type >= 9) {
if (ObjectDef.getObjectDef(objectId).aBoolean767()) {
addClippingForSolidObject(x, y, height, xLength, yLength,
ObjectDef.getObjectDef(objectId).solid());
if (ObjectDef.getObjectDef(objectId).isUnshootable()) {
addProjectileClippingForSolidObject(x, y, height, xLength, yLength,
ObjectDef.getObjectDef(objectId).solid());
}
}
} else if (type >= 0 && type <= 3) {
if (ObjectDef.getObjectDef(objectId).aBoolean767()) {
addClippingForVariableObject(x, y, height, type, direction,
ObjectDef.getObjectDef(objectId).solid());
if (ObjectDef.getObjectDef(objectId).isUnshootable()) {
addProjectileClippingForVariableObject(x, y, height, type, direction, ObjectDef.getObjectDef(objectId).solid());
}
}
}
Region r = getRegion(x, y);
if (r != null) {
if (startUp)
r.realObjects.add(new Objects(objectId, x, y, height, direction, type, 0));
else if (!objectExists(objectId, x, y, height))
r.realObjects.add(new Objects(objectId, x, y, height, direction, type, 0));
}
}
public static int getClipping(int x, int y, int height) {
if (height > 3) {
height = 0;
}
int regionX = x >> 3;
int regionY = y >> 3;
int regionId = (regionX / 8 << 8) + regionY / 8;
for (Region r : regions) {
if (r.id() == regionId) {
return r.getClip(x, y, height);
}
}
return 0;
}
public static int getProjectileClipping(int x, int y, int height) {
if (height > 3) {
height = 0;
}
int regionX = x >> 3;
int regionY = y >> 3;
int regionId = (regionX / 8 << 8) + regionY / 8;
for (Region r : regions) {
if (r.id() == regionId) {
return r.getProjectileClip(x, y, height);
}
}
return 0;
}
public static boolean getClipping(int x, int y, int height, int moveTypeX,
int moveTypeY) {
try {
if (height > 3) {
height = 0;
}
int checkX = x + moveTypeX;
int checkY = y + moveTypeY;
if (moveTypeX == -1 && moveTypeY == 0) {
return (getClipping(x, y, height) & 0x1280108) == 0;
} else if (moveTypeX == 1 && moveTypeY == 0) {
return (getClipping(x, y, height) & 0x1280180) == 0;
} else if (moveTypeX == 0 && moveTypeY == -1) {
return (getClipping(x, y, height) & 0x1280102) == 0;
} else if (moveTypeX == 0 && moveTypeY == 1) {
return (getClipping(x, y, height) & 0x1280120) == 0;
} else if (moveTypeX == -1 && moveTypeY == -1) {
return (getClipping(x, y, height) & 0x128010e) == 0
&& (getClipping(checkX - 1, checkY, height) & 0x1280108) == 0
&& (getClipping(checkX - 1, checkY, height) & 0x1280102) == 0;
} else if (moveTypeX == 1 && moveTypeY == -1) {
return (getClipping(x, y, height) & 0x1280183) == 0
&& (getClipping(checkX + 1, checkY, height) & 0x1280180) == 0
&& (getClipping(checkX, checkY - 1, height) & 0x1280102) == 0;
} else if (moveTypeX == -1 && moveTypeY == 1) {
return (getClipping(x, y, height) & 0x1280138) == 0
&& (getClipping(checkX - 1, checkY, height) & 0x1280108) == 0
&& (getClipping(checkX, checkY + 1, height) & 0x1280120) == 0;
} else if (moveTypeX == 1 && moveTypeY == 1) {
return (getClipping(x, y, height) & 0x12801e0) == 0
&& (getClipping(checkX + 1, checkY, height) & 0x1280180) == 0
&& (getClipping(checkX, checkY + 1, height) & 0x1280120) == 0;
} else {
System.out.println("[FATAL ERROR]: At getClipping: " + x + ", "
+ y + ", " + height + ", " + moveTypeX + ", "
+ moveTypeY);
return false;
}
} catch (Exception e) {
return true;
}
}
public static void load() {
try {
File f = new File("./data/world/map_index");
byte[] buffer = new byte[(int) f.length()];
DataInputStream dis = new DataInputStream(new FileInputStream(f));
dis.readFully(buffer);
dis.close();
ByteStream in = new ByteStream(buffer);
int size = in.length() / 7;
regions = new Region[size];
int[] regionIds = new int[size];
int[] mapGroundFileIds = new int[size];
int[] mapObjectsFileIds = new int[size];
boolean[] isMembers = new boolean[size];
for (int i = 0; i < size; i++) {
regionIds[i] = in.getUShort();
mapGroundFileIds[i] = in.getUShort();
mapObjectsFileIds[i] = in.getUShort();
isMembers[i] = in.getUByte() == 0;
}
for (int i = 0; i < size; i++) {
regions[i] = new Region(regionIds[i], isMembers[i]);
}
for (int i = 0; i < size; i++) {
byte[] file1 = getBuffer(new File("./data/world/map/"
+ mapObjectsFileIds[i] + ".gz"));
byte[] file2 = getBuffer(new File("./data/world/map/"
+ mapGroundFileIds[i] + ".gz"));
if (file1 == null || file2 == null) {
continue;
}
try {
loadMaps(regionIds[i], new ByteStream(file1),
new ByteStream(file2));
} catch (Exception e) {
System.out.println("Error loading map region: "
+ regionIds[i]);
}
}
System.out.println("[Region] DONE LOADING REGION CONFIGURATIONS");
} catch (Exception e) {
e.printStackTrace();
}
}
private static void loadMaps(int regionId, ByteStream str1, ByteStream str2) {
int absX = (regionId >> 8) * 64;
int absY = (regionId & 0xff) * 64;
int[][][] someArray = new int[4][64][64];
for (int i = 0; i < 4; i++) {
for (int i2 = 0; i2 < 64; i2++) {
for (int i3 = 0; i3 < 64; i3++) {
while (true) {
int v = str2.getUByte();
if (v == 0) {
break;
} else if (v == 1) {
str2.skip(1);
break;
} else if (v <= 49) {
str2.skip(1);
} else if (v <= 81) {
someArray[i][i2][i3] = v - 49;
}
}
}
}
}
for (int i = 0; i < 4; i++) {
for (int i2 = 0; i2 < 64; i2++) {
for (int i3 = 0; i3 < 64; i3++) {
if ((someArray[i][i2][i3] & 1) == 1) {
int height = i;
if ((someArray[1][i2][i3] & 2) == 2) {
height--;
}
if (height >= 0 && height <= 3) {
addClipping(absX + i2, absY + i3, height, 0x200000);
}
}
}
}
}
int objectId = -1;
int incr;
while ((incr = str1.getUSmart()) != 0) {
objectId += incr;
int location = 0;
int incr2;
while ((incr2 = str1.getUSmart()) != 0) {
location += incr2 - 1;
int localX = location >> 6 & 0x3f;
int localY = location & 0x3f;
int height = location >> 12;
int objectData = str1.getUByte();
int type = objectData >> 2;
int direction = objectData & 0x3;
if (localX < 0 || localX >= 64 || localY < 0 || localY >= 64) {
continue;
}
if ((someArray[1][localX][localY] & 2) == 2) {
height--;
}
if (height >= 0 && height <= 3) {
addObject(objectId, absX + localX, absY + localY, height,
type, direction, false);
}
}
}
}
public static byte[] getBuffer(File f) throws Exception {
if (!f.exists()) {
return null;
}
byte[] buffer = new byte[(int) f.length()];
DataInputStream dis = new DataInputStream(new FileInputStream(f));
dis.readFully(buffer);
dis.close();
byte[] gzipInputBuffer = new byte[999999];
int bufferlength = 0;
GZIPInputStream gzip = new GZIPInputStream(new ByteArrayInputStream(
buffer));
do {
if (bufferlength == gzipInputBuffer.length) {
System.out
.println("Error inflating data.\nGZIP buffer overflow.");
break;
}
int readByte = gzip.read(gzipInputBuffer, bufferlength,
gzipInputBuffer.length - bufferlength);
if (readByte == -1) {
break;
}
bufferlength += readByte;
} while (true);
byte[] inflated = new byte[bufferlength];
System.arraycopy(gzipInputBuffer, 0, inflated, 0, bufferlength);
buffer = inflated;
if (buffer.length < 10) {
return null;
}
return buffer;
}
}