From 2c7e3211b36a4561ff4989c35d10d306f0a41a57 Mon Sep 17 00:00:00 2001 From: thedaneeffect Date: Thu, 5 Jan 2023 22:30:07 -0500 Subject: [PATCH] Refactored: CollisionMap Renamed: LocType#prefetch Renamed: NPCType#options Renamed: NPCType#scaleZ Renamed: NPCType#scaleXY Renamed: NPCType#lightAttenuation Renamed: NPCType#lightAmbient Renamed: Random things in NPCType Renamed: OnDemand#prefetch Renamed: PlayerEntity#transmogrify Renamed: SceneBuilder#prefetchLocs Organized: SceneBuilder#addLoc Constants: SceneOccluder --- src/main/java/CollisionMap.java | 469 ++++++++++++++ src/main/java/Game.java | 143 ++--- src/main/java/LocType.java | 6 +- src/main/java/NPCType.java | 144 +++-- src/main/java/ObjType.java | 341 +++++----- src/main/java/OnDemand.java | 2 +- src/main/java/PathingEntity.java | 2 +- src/main/java/PlayerEntity.java | 75 +-- src/main/java/Scene.java | 20 +- src/main/java/SceneBuilder.java | 895 ++++++++++++++------------- src/main/java/SceneCollisionMap.java | 523 ---------------- src/main/java/SceneOccluder.java | 13 + src/main/java/SeqType.java | 32 +- src/main/java/VarbitType.java | 16 +- src/main/java/VarpType.java | 30 +- 15 files changed, 1379 insertions(+), 1332 deletions(-) create mode 100644 src/main/java/CollisionMap.java delete mode 100644 src/main/java/SceneCollisionMap.java diff --git a/src/main/java/CollisionMap.java b/src/main/java/CollisionMap.java new file mode 100644 index 0000000..db18c15 --- /dev/null +++ b/src/main/java/CollisionMap.java @@ -0,0 +1,469 @@ +// Decompiled by Jad v1.5.8f. Copyright 2001 Pavel Kouznetsov. +// Jad home page: http://www.kpdus.com/jad.html +// Decompiler options: packimports(3) + +public class CollisionMap { + + public static final int FLAG_BLOCK_ENTITY_NW = 0x1; + public static final int FLAG_BLOCK_ENTITY_N = 0x2; + public static final int FLAG_BLOCK_ENTITY_NE = 0x4; + public static final int FLAG_BLOCK_ENTITY_E = 0x8; + public static final int FLAG_BLOCK_ENTITY_SE = 0x10; + public static final int FLAG_BLOCK_ENTITY_S = 0x20; + public static final int FLAG_BLOCK_ENTITY_SW = 0x40; + public static final int FLAG_BLOCK_ENTITY_W = 0x80; + public static final int FLAG_BLOCK_ENTITY = 0x100; + public static final int FLAG_BLOCK_PROJECTILE_NW = 0x200; + public static final int FLAG_BLOCK_PROJECTILE_N = 0x400; + public static final int FLAG_BLOCK_PROJECTILE_NE = 0x800; + public static final int FLAG_BLOCK_PROJECTILE_E = 0x1000; + public static final int FLAG_BLOCK_PROJECTILE_SE = 0x2000; + public static final int FLAG_BLOCK_PROJECTILE_S = 0x4000; + public static final int FLAG_BLOCK_PROJECTILE_SW = 0x8000; + public static final int FLAG_BLOCK_PROJECTILE_W = 0x10000; + public static final int FLAG_BLOCK_PROJECTILE = 0x20000; + public static final int FLAG_UNINITIALIZED = 0x1000000; + public static final int FLAG_CLOSED = 0xFFFFFF; + + public final int sizeX; + public final int sizeZ; + public final int[][] flags; + + public CollisionMap(int sizeX, int sizeZ) { + this.sizeX = sizeX; + this.sizeZ = sizeZ; + flags = new int[this.sizeX][this.sizeZ]; + reset(); + } + + public void reset() { + for (int x = 0; x < sizeX; x++) { + for (int z = 0; z < sizeZ; z++) { + if ((x == 0) || (z == 0) || (x == (sizeX - 1)) || (z == (sizeZ - 1))) { + flags[x][z] = FLAG_CLOSED; + } else { + flags[x][z] = FLAG_UNINITIALIZED; + } + } + } + } + + public void addWall(int x, int z, int type, int rotation, boolean projectiles) { + if (type == 0) { + if (rotation == 0) { + add(x, z, FLAG_BLOCK_ENTITY_W); + add(x - 1, z, FLAG_BLOCK_ENTITY_E); + } else if (rotation == 1) { + add(x, z, FLAG_BLOCK_ENTITY_N); + add(x, z + 1, FLAG_BLOCK_ENTITY_S); + } else if (rotation == 2) { + add(x, z, FLAG_BLOCK_ENTITY_E); + add(x + 1, z, FLAG_BLOCK_ENTITY_W); + } else if (rotation == 3) { + add(x, z, FLAG_BLOCK_ENTITY_S); + add(x, z - 1, FLAG_BLOCK_ENTITY_N); + } + } else if ((type == 1) || (type == 3)) { + if (rotation == 0) { + add(x, z, FLAG_BLOCK_ENTITY_NW); + add(x - 1, z + 1, FLAG_BLOCK_ENTITY_SE); + } else if (rotation == 1) { + add(x, z, FLAG_BLOCK_ENTITY_NE); + add(x + 1, z + 1, FLAG_BLOCK_ENTITY_SW); + } else if (rotation == 2) { + add(x, z, FLAG_BLOCK_ENTITY_SE); + add(x + 1, z - 1, FLAG_BLOCK_ENTITY_NW); + } else if (rotation == 3) { + add(x, z, FLAG_BLOCK_ENTITY_SW); + add(x - 1, z - 1, FLAG_BLOCK_ENTITY_NE); + } + } else if (type == 2) { + if (rotation == 0) { + add(x, z, FLAG_BLOCK_ENTITY_W|FLAG_BLOCK_ENTITY_N); + add(x - 1, z, FLAG_BLOCK_ENTITY_E); + add(x, z + 1, FLAG_BLOCK_ENTITY_S); + } else if (rotation == 1) { + add(x, z, FLAG_BLOCK_ENTITY_E|FLAG_BLOCK_ENTITY_N); + add(x, z + 1, FLAG_BLOCK_ENTITY_S); + add(x + 1, z, FLAG_BLOCK_ENTITY_W); + } else if (rotation == 2) { + add(x, z, FLAG_BLOCK_ENTITY_E|FLAG_BLOCK_ENTITY_S); + add(x + 1, z, FLAG_BLOCK_ENTITY_W); + add(x, z - 1, FLAG_BLOCK_ENTITY_N); + } else if (rotation == 3) { + add(x, z, FLAG_BLOCK_ENTITY_W|FLAG_BLOCK_ENTITY_S); + add(x, z - 1, FLAG_BLOCK_ENTITY_N); + add(x - 1, z, FLAG_BLOCK_ENTITY_E); + } + } + + if (projectiles) { + if (type == 0) { + if (rotation == 0) { + add(x, z, FLAG_BLOCK_PROJECTILE_W); + add(x - 1, z, FLAG_BLOCK_PROJECTILE_E); + } else if (rotation == 1) { + add(x, z, FLAG_BLOCK_PROJECTILE_N); + add(x, z + 1, FLAG_BLOCK_PROJECTILE_S); + } else if (rotation == 2) { + add(x, z, FLAG_BLOCK_PROJECTILE_E); + add(x + 1, z, FLAG_BLOCK_PROJECTILE_W); + } else if (rotation == 3) { + add(x, z, FLAG_BLOCK_PROJECTILE_S); + add(x, z - 1, FLAG_BLOCK_PROJECTILE_N); + } + } else if ((type == 1) || (type == 3)) { + if (rotation == 0) { + add(x, z, FLAG_BLOCK_PROJECTILE_NW); + add(x - 1, z + 1, FLAG_BLOCK_PROJECTILE_SE); + } else if (rotation == 1) { + add(x, z, FLAG_BLOCK_PROJECTILE_NE); + add(x + 1, z + 1, FLAG_BLOCK_PROJECTILE_SW); + } else if (rotation == 2) { + add(x, z, FLAG_BLOCK_PROJECTILE_SE); + add(x + 1, z - 1, FLAG_BLOCK_PROJECTILE_NW); + } else if (rotation == 3) { + add(x, z, FLAG_BLOCK_PROJECTILE_SW); + add(x - 1, z - 1, FLAG_BLOCK_PROJECTILE_NE); + } + } else if (type == 2) { + if (rotation == 0) { + add(x, z, FLAG_BLOCK_PROJECTILE_W|FLAG_BLOCK_PROJECTILE_N); + add(x - 1, z, FLAG_BLOCK_PROJECTILE_E); + add(x, z + 1, FLAG_BLOCK_PROJECTILE_S); + } else if (rotation == 1) { + add(x, z, FLAG_BLOCK_PROJECTILE_E|FLAG_BLOCK_PROJECTILE_N); + add(x, z + 1, FLAG_BLOCK_PROJECTILE_S); + add(x + 1, z, FLAG_BLOCK_PROJECTILE_W); + } else if (rotation == 2) { + add(x, z, FLAG_BLOCK_PROJECTILE_E|FLAG_BLOCK_PROJECTILE_S); + add(x + 1, z, FLAG_BLOCK_PROJECTILE_W); + add(x, z - 1, FLAG_BLOCK_PROJECTILE_N); + } else if (rotation == 3) { + add(x, z, FLAG_BLOCK_PROJECTILE_W|FLAG_BLOCK_PROJECTILE_S); + add(x, z - 1, FLAG_BLOCK_PROJECTILE_N); + add(x - 1, z, FLAG_BLOCK_PROJECTILE_E); + } + } + } + } + + public void add(boolean blocksProjectiles, int sizeX, int sizeZ, int x, int z, int rotation) { + int flags = FLAG_BLOCK_ENTITY; + + if (blocksProjectiles) { + flags += FLAG_BLOCK_PROJECTILE; + } + + if ((rotation == 1) || (rotation == 3)) { + int tmp = sizeX; + sizeX = sizeZ; + sizeZ = tmp; + } + + for (int tx = x; tx < (x + sizeX); tx++) { + if ((tx >= 0) && (tx < this.sizeX)) { + for (int tz = z; tz < (z + sizeZ); tz++) { + if ((tz >= 0) && (tz < this.sizeZ)) { + add(tx, tz, flags); + } + } + } + } + } + + public void addSolid(int x, int z) { + flags[x][z] |= FLAG_UNINITIALIZED; + } + + public void add(int x, int z, int flags) { + this.flags[x][z] |= flags; + } + + public void remove(int x, int z, int rotation, int type, boolean projectiles) { + if (type == 0) { + if (rotation == 0) { + remove(x, z, FLAG_BLOCK_ENTITY_W); + remove(x - 1, z, FLAG_BLOCK_ENTITY_E); + } else if (rotation == 1) { + remove(x, z, FLAG_BLOCK_ENTITY_N); + remove(x, z + 1, FLAG_BLOCK_ENTITY_S); + } else if (rotation == 2) { + remove(x, z, FLAG_BLOCK_ENTITY_E); + remove(x + 1, z, FLAG_BLOCK_ENTITY_W); + } else if (rotation == 3) { + remove(x, z, FLAG_BLOCK_ENTITY_S); + remove(x, z - 1, FLAG_BLOCK_ENTITY_N); + } + } else if ((type == 1) || (type == 3)) { + if (rotation == 0) { + remove(x, z, FLAG_BLOCK_ENTITY_NW); + remove(x - 1, z + 1, FLAG_BLOCK_ENTITY_SE); + } else if (rotation == 1) { + remove(x, z, FLAG_BLOCK_ENTITY_NE); + remove(x + 1, z + 1, FLAG_BLOCK_ENTITY_SW); + } else if (rotation == 2) { + remove(x, z, FLAG_BLOCK_ENTITY_SE); + remove(x + 1, z - 1, FLAG_BLOCK_ENTITY_NW); + } else if (rotation == 3) { + remove(x, z, FLAG_BLOCK_ENTITY_SW); + remove(x - 1, z - 1, FLAG_BLOCK_ENTITY_NE); + } + } else if (type == 2) { + if (rotation == 0) { + remove(x, z, FLAG_BLOCK_ENTITY_W|FLAG_BLOCK_ENTITY_N); + remove(x - 1, z, FLAG_BLOCK_ENTITY_E); + remove(x, z + 1, FLAG_BLOCK_ENTITY_S); + } else if (rotation == 1) { + remove(x, z, FLAG_BLOCK_ENTITY_E|FLAG_BLOCK_ENTITY_N); + remove(x, z + 1, FLAG_BLOCK_ENTITY_S); + remove(x + 1, z, FLAG_BLOCK_ENTITY_W); + } else if (rotation == 2) { + remove(x, z, FLAG_BLOCK_ENTITY_E|FLAG_BLOCK_ENTITY_S); + remove(x + 1, z, FLAG_BLOCK_ENTITY_W); + remove(x, z - 1, FLAG_BLOCK_ENTITY_N); + } else if (rotation == 3) { + remove(x, z, FLAG_BLOCK_ENTITY_W|FLAG_BLOCK_ENTITY_S); + remove(x, z - 1, FLAG_BLOCK_ENTITY_N); + remove(x - 1, z, FLAG_BLOCK_ENTITY_E); + } + } + if (projectiles) { + if (type == 0) { + if (rotation == 0) { + remove(x, z, FLAG_BLOCK_PROJECTILE_W); + remove(x - 1, z, FLAG_BLOCK_PROJECTILE_E); + } else if (rotation == 1) { + remove(x, z, FLAG_BLOCK_PROJECTILE_N); + remove(x, z + 1, FLAG_BLOCK_PROJECTILE_S); + } else if (rotation == 2) { + remove(x, z, FLAG_BLOCK_PROJECTILE_E); + remove(x + 1, z, FLAG_BLOCK_PROJECTILE_W); + } else if (rotation == 3) { + remove(x, z, FLAG_BLOCK_PROJECTILE_S); + remove(x, z - 1, FLAG_BLOCK_PROJECTILE_N); + } + } else if ((type == 1) || (type == 3)) { + if (rotation == 0) { + remove(x, z, FLAG_BLOCK_PROJECTILE_NW); + remove(x - 1, z + 1, FLAG_BLOCK_PROJECTILE_SE); + } else if (rotation == 1) { + remove(x, z, FLAG_BLOCK_PROJECTILE_NE); + remove(x + 1, z + 1, FLAG_BLOCK_PROJECTILE_SW); + } else if (rotation == 2) { + remove(x, z, FLAG_BLOCK_PROJECTILE_SE); + remove(x + 1, z - 1, FLAG_BLOCK_PROJECTILE_NW); + } else if (rotation == 3) { + remove(x, z, FLAG_BLOCK_PROJECTILE_SW); + remove(x - 1, z - 1, FLAG_BLOCK_PROJECTILE_NE); + } + } else if (type == 2) { + if (rotation == 0) { + remove(x, z, FLAG_BLOCK_PROJECTILE_W|FLAG_BLOCK_PROJECTILE_N); + remove(x - 1, z, FLAG_BLOCK_PROJECTILE_E); + remove(x, z + 1, FLAG_BLOCK_PROJECTILE_S); + } else if (rotation == 1) { + remove(x, z, FLAG_BLOCK_PROJECTILE_E|FLAG_BLOCK_PROJECTILE_N); + remove(x, z + 1, FLAG_BLOCK_PROJECTILE_S); + remove(x + 1, z, FLAG_BLOCK_PROJECTILE_W); + } else if (rotation == 2) { + remove(x, z, FLAG_BLOCK_PROJECTILE_E|FLAG_BLOCK_PROJECTILE_S); + remove(x + 1, z, FLAG_BLOCK_PROJECTILE_W); + remove(x, z - 1, FLAG_BLOCK_PROJECTILE_N); + } else if (rotation == 3) { + remove(x, z, FLAG_BLOCK_PROJECTILE_W|FLAG_BLOCK_PROJECTILE_S); + remove(x, z - 1, FLAG_BLOCK_PROJECTILE_N); + remove(x - 1, z, FLAG_BLOCK_PROJECTILE_E); + } + } + } + } + + public void remove(int rotation, int sizeX, int x0, int z0, int sizeZ, boolean projectiles) { + int flags = FLAG_BLOCK_ENTITY; + + if (projectiles) { + flags += FLAG_BLOCK_PROJECTILE; + } + + if ((rotation == 1) || (rotation == 3)) { + int tmp = sizeX; + sizeX = sizeZ; + sizeZ = tmp; + } + for (int x = x0; x < (x0 + sizeX); x++) { + if ((x >= 0) && (x < this.sizeX)) { + for (int z = z0; z < (z0 + sizeZ); z++) { + if ((z >= 0) && (z < this.sizeZ)) { + remove(x, z, flags); + } + } + } + } + } + + public void remove(int x, int z, int flags) { + this.flags[x][z] &= 0xffffff - flags; + } + + public void removeSolid(int x, int z) { + flags[x][z] &= 0xdfffff; + } + + public boolean reachedDestination(int sx, int sz, int dx, int dz, int rotation, int type) { + if ((sx == dx) && (sz == dz)) { + return true; + } + + if (type == 0) { + if (rotation == 0) { + if ((sx == (dx - 1)) && (sz == dz)) { + return true; + } else if ((sx == dx) && (sz == (dz + 1)) && ((flags[sx][sz] & 0x1280120) == 0)) { + return true; + } else { + return (sx == dx) && (sz == (dz - 1)) && ((flags[sx][sz] & 0x1280102) == 0); + } + } else if (rotation == 1) { + if ((sx == dx) && (sz == (dz + 1))) { + return true; + } else if ((sx == (dx - 1)) && (sz == dz) && ((flags[sx][sz] & 0x1280108) == 0)) { + return true; + } else { + return (sx == (dx + 1)) && (sz == dz) && ((flags[sx][sz] & 0x1280180) == 0); + } + } else if (rotation == 2) { + if ((sx == (dx + 1)) && (sz == dz)) { + return true; + } else if ((sx == dx) && (sz == (dz + 1)) && ((flags[sx][sz] & 0x1280120) == 0)) { + return true; + } else { + return (sx == dx) && (sz == (dz - 1)) && ((flags[sx][sz] & 0x1280102) == 0); + } + } else if (rotation == 3) { + if ((sx == dx) && (sz == (dz - 1))) { + return true; + } else if ((sx == (dx - 1)) && (sz == dz) && ((flags[sx][sz] & 0x1280108) == 0)) { + return true; + } else { + return (sx == (dx + 1)) && (sz == dz) && ((flags[sx][sz] & 0x1280180) == 0); + } + } + } else if (type == 2) { + if (rotation == 0) { + if ((sx == (dx - 1)) && (sz == dz)) { + return true; + } else if ((sx == dx) && (sz == (dz + 1))) { + return true; + } else if ((sx == (dx + 1)) && (sz == dz) && ((flags[sx][sz] & 0x1280180) == 0)) { + return true; + } else { + return (sx == dx) && (sz == (dz - 1)) && ((flags[sx][sz] & 0x1280102) == 0); + } + } else if (rotation == 1) { + if ((sx == (dx - 1)) && (sz == dz) && ((flags[sx][sz] & 0x1280108) == 0)) { + return true; + } else if ((sx == dx) && (sz == (dz + 1))) { + return true; + } else if ((sx == (dx + 1)) && (sz == dz)) { + return true; + } else { + return (sx == dx) && (sz == (dz - 1)) && ((flags[sx][sz] & 0x1280102) == 0); + } + } else if (rotation == 2) { + if ((sx == (dx - 1)) && (sz == dz) && ((flags[sx][sz] & 0x1280108) == 0)) { + return true; + } else if ((sx == dx) && (sz == (dz + 1)) && ((flags[sx][sz] & 0x1280120) == 0)) { + return true; + } else if ((sx == (dx + 1)) && (sz == dz)) { + return true; + } else { + return (sx == dx) && (sz == (dz - 1)); + } + } else if (rotation == 3) { + if ((sx == (dx - 1)) && (sz == dz)) { + return true; + } else if ((sx == dx) && (sz == (dz + 1)) && ((flags[sx][sz] & 0x1280120) == 0)) { + return true; + } else if ((sx == (dx + 1)) && (sz == dz) && ((flags[sx][sz] & 0x1280180) == 0)) { + return true; + } else { + return (sx == dx) && (sz == (dz - 1)); + } + } + } else if (type == 9) { + if ((sx == dx) && (sz == (dz + 1)) && ((flags[sx][sz] & FLAG_BLOCK_ENTITY_S) == 0)) { + return true; + } else if ((sx == dx) && (sz == (dz - 1)) && ((flags[sx][sz] & FLAG_BLOCK_ENTITY_N) == 0)) { + return true; + } else if ((sx == (dx - 1)) && (sz == dz) && ((flags[sx][sz] & FLAG_BLOCK_ENTITY_E) == 0)) { + return true; + } + return (sx == (dx + 1)) && (sz == dz) && ((flags[sx][sz] & FLAG_BLOCK_ENTITY_W) == 0); + } + return false; + } + + public boolean reachedWall(int sx, int sz, int dx, int dz, int type, int rotation) { + if ((sx == dx) && (sz == dz)) { + return true; + } + if ((type == 6) || (type == 7)) { + if (type == 7) { + rotation = (rotation + 2) & 3; + } + if (rotation == 0) { + if ((sx == (dx + 1)) && (sz == dz) && ((flags[sx][sz] & FLAG_BLOCK_ENTITY_W) == 0)) { + return true; + } else { + return (sx == dx) && (sz == (dz - 1)) && ((flags[sx][sz] & FLAG_BLOCK_ENTITY_N) == 0); + } + } else if (rotation == 1) { + if ((sx == (dx - 1)) && (sz == dz) && ((flags[sx][sz] & FLAG_BLOCK_ENTITY_E) == 0)) { + return true; + } else { + return (sx == dx) && (sz == (dz - 1)) && ((flags[sx][sz] & FLAG_BLOCK_ENTITY_N) == 0); + } + } else if (rotation == 2) { + if ((sx == (dx - 1)) && (sz == dz) && ((flags[sx][sz] & FLAG_BLOCK_ENTITY_E) == 0)) { + return true; + } else { + return (sx == dx) && (sz == (dz + 1)) && ((flags[sx][sz] & FLAG_BLOCK_ENTITY_S) == 0); + } + } else if (rotation == 3) { + if ((sx == (dx + 1)) && (sz == dz) && ((flags[sx][sz] & FLAG_BLOCK_ENTITY_W) == 0)) { + return true; + } else { + return (sx == dx) && (sz == (dz + 1)) && ((flags[sx][sz] & FLAG_BLOCK_ENTITY_S) == 0); + } + } + } else if (type == 8) { + if ((sx == dx) && (sz == (dz + 1)) && ((flags[sx][sz] & FLAG_BLOCK_ENTITY_S) == 0)) { + return true; + } else if ((sx == dx) && (sz == (dz - 1)) && ((flags[sx][sz] & FLAG_BLOCK_ENTITY_N) == 0)) { + return true; + } else if ((sx == (dx - 1)) && (sz == dz) && ((flags[sx][sz] & FLAG_BLOCK_ENTITY_E) == 0)) { + return true; + } + return (sx == (dx + 1)) && (sz == dz) && ((flags[sx][sz] & FLAG_BLOCK_ENTITY_W) == 0); + } + return false; + } + + public boolean reachedLoc(int srcX, int srcZ, int dstX, int dstZ, int dstSizeX, int dstSizeZ, int interactionSides) { + int maxX = (dstX + dstSizeX) - 1; + int maxZ = (dstZ + dstSizeZ) - 1; + + if ((srcX >= dstX) && (srcX <= maxX) && (srcZ >= dstZ) && (srcZ <= maxZ)) { + return true; + } else if ((srcX == (dstX - 1)) && (srcZ >= dstZ) && (srcZ <= maxZ) && ((this.flags[srcX][srcZ] & FLAG_BLOCK_ENTITY_E) == 0) && ((interactionSides & 8) == 0)) { + return true; + } else if ((srcX == (maxX + 1)) && (srcZ >= dstZ) && (srcZ <= maxZ) && ((this.flags[srcX][srcZ] & FLAG_BLOCK_ENTITY_W) == 0) && ((interactionSides & 2) == 0)) { + return true; + } else if ((srcZ == (dstZ - 1)) && (srcX >= dstX) && (srcX <= maxX) && ((this.flags[srcX][srcZ] & FLAG_BLOCK_ENTITY_N) == 0) && ((interactionSides & 4) == 0)) { + return true; + } + return (srcZ == (maxZ + 1)) && (srcX >= dstX) && (srcX <= maxX) && ((this.flags[srcX][srcZ] & FLAG_BLOCK_ENTITY_S) == 0) && ((interactionSides & 1) == 0); + } + +} diff --git a/src/main/java/Game.java b/src/main/java/Game.java index fd1a4a6..40eaf87 100644 --- a/src/main/java/Game.java +++ b/src/main/java/Game.java @@ -607,7 +607,7 @@ public class Game extends GameShell { public int chatbackInputType; public int song; public boolean songFading = true; - public SceneCollisionMap[] levelCollisionMap = new SceneCollisionMap[4]; + public CollisionMap[] levelCollisionMap = new CollisionMap[4]; public boolean redrawPrivacySettings = false; public int[] sceneMapIndex; public int[] sceneMapLandFile; @@ -735,7 +735,7 @@ public class Game extends GameShell { scene = new Scene(104, 104, levelHeightmap, 4); for (int level = 0; level < 4; level++) { - levelCollisionMap[level] = new SceneCollisionMap(104, 104); + levelCollisionMap[level] = new CollisionMap(104, 104); } imageMinimap = new Image24(512, 512); @@ -1785,11 +1785,11 @@ public class Game extends GameShell { if ((mapX == minMapX) || (mapX == maxMapX) || (mapZ == minMapZ) || (mapZ == maxMapZ)) { int mapFile = ondemand.getMapFile(0, mapX, mapZ); if (mapFile != -1) { - ondemand.method560(mapFile, 3); + ondemand.prefetch(mapFile, 3); } int locFile = ondemand.getMapFile(1, mapX, mapZ); if (locFile != -1) { - ondemand.method560(locFile, 3); + ondemand.prefetch(locFile, 3); } } } @@ -2068,7 +2068,7 @@ public class Game extends GameShell { bitset += 0x80000000; } - scene.pushTemporary(npc, currentLevel, npc.x, npc.z, getHeightmapY(currentLevel, npc.x, npc.z), npc.yaw, bitset, npc.needsForwardDrawPadding, ((npc.size - 1) * 64) + 60); + scene.addTemporary(npc, currentLevel, npc.x, npc.z, getHeightmapY(currentLevel, npc.x, npc.z), npc.yaw, bitset, npc.needsForwardDrawPadding, ((npc.size - 1) * 64) + 60); } } @@ -3225,7 +3225,7 @@ public class Game extends GameShell { if ((player.locModel != null) && (loopCycle >= player.locStartCycle) && (loopCycle < player.locStopCycle)) { player.lowmem = false; player.y = getHeightmapY(currentLevel, player.x, player.z); - scene.pushTemporary(player, currentLevel, player.minSceneTileX, player.minSceneTileZ, player.maxSceneTileX, player.maxSceneTileZ, player.x, player.z, player.y, player.yaw, index); + scene.addTemporary(player, currentLevel, player.minSceneTileX, player.minSceneTileZ, player.maxSceneTileX, player.maxSceneTileZ, player.x, player.z, player.y, player.yaw, index); continue; } @@ -3237,7 +3237,7 @@ public class Game extends GameShell { } player.y = getHeightmapY(currentLevel, player.x, player.z); - scene.pushTemporary(player, currentLevel, player.x, player.z, player.y, player.yaw, index, player.needsForwardDrawPadding, 60); + scene.addTemporary(player, currentLevel, player.x, player.z, player.y, player.yaw, index, player.needsForwardDrawPadding, 60); } } @@ -3894,7 +3894,7 @@ public class Game extends GameShell { } } proj.update(delta); - scene.pushTemporary(proj, currentLevel, (int) proj.x, (int) proj.z, (int) proj.y, proj.yaw, -1, false, 60); + scene.addTemporary(proj, currentLevel, (int) proj.x, (int) proj.z, (int) proj.y, proj.yaw, -1, false, 60); } } } @@ -4020,7 +4020,7 @@ public class Game extends GameShell { } } } while ((request.store != 93) || !ondemand.method564(request.file)); - SceneBuilder.method173(new Buffer(request.data), ondemand); + SceneBuilder.prefetchLocs(new Buffer(request.data), ondemand); } while (true); } @@ -5984,8 +5984,8 @@ public class Game extends GameShell { } } else { for (int option = 4; option >= 0; option--) { - if ((type.groundOptions != null) && (type.groundOptions[option] != null)) { - menuOption[menuSize] = type.groundOptions[option] + " @lre@" + type.name; + if ((type.options != null) && (type.options[option] != null)) { + menuOption[menuSize] = type.options[option] + " @lre@" + type.name; if (option == 0) { menuAction[menuSize] = 652; @@ -7400,17 +7400,17 @@ public class Game extends GameShell { } if (locType != 0) { - if (((locType < 5) || (locType == 10)) && levelCollisionMap[currentLevel].method219(x, z, dx, dz, locAngle, locType - 1)) { + if (((locType < 5) || (locType == 10)) && levelCollisionMap[currentLevel].reachedDestination(x, z, dx, dz, locAngle, locType - 1)) { arrived = true; break; } - if ((locType < 10) && levelCollisionMap[currentLevel].method220(x, z, dx, dz, locType - 1, locAngle)) { + if ((locType < 10) && levelCollisionMap[currentLevel].reachedWall(x, z, dx, dz, locType - 1, locAngle)) { arrived = true; break; } } - if ((locWidth != 0) && (locLength != 0) && levelCollisionMap[currentLevel].method221(x, z, dx, dz, locWidth, locLength, locInteractionFlags)) { + if ((locWidth != 0) && (locLength != 0) && levelCollisionMap[currentLevel].reachedLoc(x, z, dx, dz, locWidth, locLength, locInteractionFlags)) { arrived = true; break; } @@ -7758,10 +7758,10 @@ public class Game extends GameShell { menuSize++; } } else { - if (type.op != null) { + if (type.options != null) { for (int option = 4; option >= 0; option--) { - if ((type.op[option] != null) && !type.op[option].equalsIgnoreCase("attack")) { - menuOption[menuSize] = type.op[option] + " @yel@" + text; + if ((type.options[option] != null) && !type.options[option].equalsIgnoreCase("attack")) { + menuOption[menuSize] = type.options[option] + " @yel@" + text; if (option == 0) { menuAction[menuSize] = 20; @@ -7782,15 +7782,15 @@ public class Game extends GameShell { } } } - if (type.op != null) { + if (type.options != null) { for (int option = 4; option >= 0; option--) { - if ((type.op[option] != null) && type.op[option].equalsIgnoreCase("attack")) { + if ((type.options[option] != null) && type.options[option].equalsIgnoreCase("attack")) { int offset = 0; if (type.level > localPlayer.combatLevel) { offset = 2000; } - menuOption[menuSize] = type.op[option] + " @yel@" + text; + menuOption[menuSize] = type.options[option] + " @yel@" + text; if (option == 0) { menuAction[menuSize] = 20 + offset; @@ -8565,7 +8565,7 @@ public class Game extends GameShell { if (chatInterfaceID == -1) { chatInterface.scrollPosition = chatScrollHeight - chatScrollOffset - 77; - + if ((super.mouseX > 448) && (super.mouseX < 560) && (super.mouseY > 332)) { handleScrollInput(463, 77, super.mouseX - 17, super.mouseY - 357, chatInterface, 0, false, chatScrollHeight); } @@ -8818,7 +8818,7 @@ public class Game extends GameShell { if (anim.seqComplete) { anim.unlink(); } else { - scene.pushTemporary(anim, anim.level, anim.x, anim.z, anim.y, 0, -1, false, 60); + scene.addTemporary(anim, anim.level, anim.x, anim.z, anim.y, 0, -1, false, 60); } } } @@ -9898,43 +9898,43 @@ public class Game extends GameShell { int arith = 0; do { - int op = script[pos++]; - int reg = 0; + int opcode = script[pos++]; + int register = 0; byte nextArithmetic = 0; - if (op == 0) { + if (opcode == 0) { return acc; - } else if (op == 1) { // load_skill_level {skill} - reg = skillLevel[script[pos++]]; - } else if (op == 2) { // load_skill_base_level {skill} - reg = skillBaseLevel[script[pos++]]; - } else if (op == 3) { // load_skill_exp {skill} - reg = skillExperience[script[pos++]]; - } else if (op == 4) {// load_inv_count {interface id} {obj id} + } else if (opcode == 1) { // load_skill_level {skill} + register = skillLevel[script[pos++]]; + } else if (opcode == 2) { // load_skill_base_level {skill} + register = skillBaseLevel[script[pos++]]; + } else if (opcode == 3) { // load_skill_exp {skill} + register = skillExperience[script[pos++]]; + } else if (opcode == 4) {// load_inv_count {interface id} {obj id} IfType inventory = IfType.instances[script[pos++]]; int objID = script[pos++]; if ((objID >= 0) && (objID < ObjType.count) && (!ObjType.get(objID).members || members)) { for (int slot = 0; slot < inventory.inventorySlotObjID.length; slot++) { if (inventory.inventorySlotObjID[slot] == (objID + 1)) { - reg += inventory.inventorySlotObjCount[slot]; + register += inventory.inventorySlotObjCount[slot]; } } } - } else if (op == 5) { // load_var {id} - reg = varps[script[pos++]]; - } else if (op == 6) { // load_next_level_xp {skill} - reg = levelExperience[skillBaseLevel[script[pos++]] - 1]; - } else if (op == 7) { - reg = (varps[script[pos++]] * 100) / 46875; - } else if (op == 8) { // load_combat_level - reg = localPlayer.combatLevel; - } else if (op == 9) { // load_total_level + } else if (opcode == 5) { // load_var {id} + register = varps[script[pos++]]; + } else if (opcode == 6) { // load_next_level_xp {skill} + register = levelExperience[skillBaseLevel[script[pos++]] - 1]; + } else if (opcode == 7) { + register = (varps[script[pos++]] * 100) / 46875; + } else if (opcode == 8) { // load_combat_level + register = localPlayer.combatLevel; + } else if (opcode == 9) { // load_total_level for (int skill = 0; skill < Skill.COUNT; skill++) { if (Skill.ENABLED[skill]) { - reg += skillBaseLevel[skill]; + register += skillBaseLevel[skill]; } } - } else if (op == 10) {// load_inv_contains {interface id} {obj id} + } else if (opcode == 10) {// load_inv_contains {interface id} {obj id} IfType c = IfType.instances[script[pos++]]; int objID = script[pos++] + 1; if ((objID >= 0) && (objID < ObjType.count) && (!ObjType.get(objID).members || members)) { @@ -9942,48 +9942,48 @@ public class Game extends GameShell { if (c.inventorySlotObjID[slot] != objID) { continue; } - reg = 999999999; + register = 999999999; break; } } - } else if (op == 11) { // load_energy - reg = energy; - } else if (op == 12) { // load_weight - reg = weightCarried; - } else if (op == 13) {// load_bool {varp} {bit: 0..31} + } else if (opcode == 11) { // load_energy + register = energy; + } else if (opcode == 12) { // load_weight + register = weightCarried; + } else if (opcode == 13) {// load_bool {varp} {bit: 0..31} int varp = varps[script[pos++]]; int bit = script[pos++]; - reg = ((varp & (1 << bit)) == 0) ? 0 : 1; - } else if (op == 14) {// load_varbit {varbit} + register = ((varp & (1 << bit)) == 0) ? 0 : 1; + } else if (opcode == 14) {// load_varbit {varbit} VarbitType varbit = VarbitType.instances[script[pos++]]; int lsb = varbit.lsb; - reg = (varps[varbit.varp] >> lsb) & BITMASK[varbit.msb - lsb]; - } else if (op == 15) { // sub + register = (varps[varbit.varp] >> lsb) & BITMASK[varbit.msb - lsb]; + } else if (opcode == 15) { // sub nextArithmetic = 1; - } else if (op == 16) { // div + } else if (opcode == 16) { // div nextArithmetic = 2; - } else if (op == 17) { // mul + } else if (opcode == 17) { // mul nextArithmetic = 3; - } else if (op == 18) { // load_world_x - reg = (localPlayer.x >> 7) + sceneBaseTileX; - } else if (op == 19) { // load_world_z - reg = (localPlayer.z >> 7) + sceneBaseTileZ; - } else if (op == 20) { // load {value} - reg = script[pos++]; + } else if (opcode == 18) { // load_world_x + register = (localPlayer.x >> 7) + sceneBaseTileX; + } else if (opcode == 19) { // load_world_z + register = (localPlayer.z >> 7) + sceneBaseTileZ; + } else if (opcode == 20) { // load {value} + register = script[pos++]; } if (nextArithmetic == 0) { if (arith == 0) { - acc += reg; + acc += register; } if (arith == 1) { - acc -= reg; + acc -= register; } - if ((arith == 2) && (reg != 0)) { - acc /= reg; + if ((arith == 2) && (register != 0)) { + acc /= register; } if (arith == 3) { - acc *= reg; + acc *= register; } arith = 0; } else { @@ -11164,7 +11164,7 @@ public class Game extends GameShell { scene.removeWall(x, level, z); LocType type = LocType.get(otherID); if (type.solid) { - levelCollisionMap[level].remove(otherRotation, otherKind, type.blocksProjectiles, x, z); + levelCollisionMap[level].remove(x, z, otherRotation, otherKind, type.blocksProjectiles); } } @@ -11188,8 +11188,9 @@ public class Game extends GameShell { if (classID == 3) { scene.removeGroundDecoration(level, x, z); LocType type = LocType.get(otherID); + if (type.solid && type.interactable) { - levelCollisionMap[level].method218(z, x); + levelCollisionMap[level].removeSolid(x, z); } } } @@ -11656,10 +11657,10 @@ public class Game extends GameShell { IfType iface = IfType.instances[interfaceID]; iface.modelCategory = 3; - if (localPlayer.npcType == null) { + if (localPlayer.transmogrify == null) { iface.modelID = (localPlayer.colors[0] << 25) + (localPlayer.colors[4] << 20) + (localPlayer.appearances[0] << 15) + (localPlayer.appearances[8] << 10) + (localPlayer.appearances[11] << 5) + localPlayer.appearances[1]; } else { - iface.modelID = (int) (0x12345678L + localPlayer.npcType.uid); + iface.modelID = (int) (0x12345678L + localPlayer.transmogrify.uid); } } diff --git a/src/main/java/LocType.java b/src/main/java/LocType.java index 33b54e6..20ea881 100644 --- a/src/main/java/LocType.java +++ b/src/main/java/LocType.java @@ -153,12 +153,12 @@ public class LocType { overrideTypeIDs = null; } - public void method574(OnDemand onDemand) { + public void prefetch(OnDemand onDemand) { if (modelIDs == null) { return; } - for (int k : modelIDs) { - onDemand.method560(k & 0xffff, 0); + for (int modelID : modelIDs) { + onDemand.prefetch(modelID & 0xffff, 0); } } diff --git a/src/main/java/NPCType.java b/src/main/java/NPCType.java index 4d337e1..46c7a3c 100644 --- a/src/main/java/NPCType.java +++ b/src/main/java/NPCType.java @@ -62,7 +62,7 @@ public class NPCType { public int varpID = -1; public int level = -1; public String name; - public String[] op; + public String[] options; public int seqWalkID = -1; public byte size = 1; public int[] colorDst; @@ -75,14 +75,14 @@ public class NPCType { public int turnSpeed = 32; public int seqTurnLeftID = -1; public boolean interactable = true; - public int anInt85; - public int anInt86 = 128; + public int lightAmbient; + public int scaleZ = 128; public boolean showOnMinimap = true; public int[] overrides; public byte[] desc; public int unusedInt1 = -1; - public int anInt91 = 128; - public int anInt92; + public int scaleXY = 128; + public int lightAttenuation; /** * Causes the npc to render on top of other npcs. */ @@ -206,123 +206,131 @@ public class NPCType { } model.createLabelReferences(); - model.calculateNormals(64 + anInt85, 850 + anInt92, -30, -50, -30, true); + model.calculateNormals(64 + lightAmbient, 850 + lightAttenuation, -30, -50, -30, true); modelCache.put(uid, model); } - Model model_1 = Model.EMPTY; - model_1.set(model, SeqTransform.isNull(primaryTransformID) & SeqTransform.isNull(secondaryTransformID)); + Model tmp = Model.EMPTY; + tmp.set(model, SeqTransform.isNull(primaryTransformID) & SeqTransform.isNull(secondaryTransformID)); if ((primaryTransformID != -1) && (secondaryTransformID != -1)) { - model_1.applyTransforms(primaryTransformID, secondaryTransformID, seqMask); + tmp.applyTransforms(primaryTransformID, secondaryTransformID, seqMask); } else if (primaryTransformID != -1) { - model_1.applyTransform(primaryTransformID); + tmp.applyTransform(primaryTransformID); } - if ((anInt91 != 128) || (anInt86 != 128)) { - model_1.scale(anInt91, anInt91, anInt86); + if ((scaleXY != 128) || (scaleZ != 128)) { + tmp.scale(scaleXY, scaleXY, scaleZ); } - model_1.calculateBoundsCylinder(); - model_1.labelFaces = null; - model_1.labelVertices = null; + + tmp.calculateBoundsCylinder(); + tmp.labelFaces = null; + tmp.labelVertices = null; if (size == 1) { - model_1.pickable = true; + tmp.pickable = true; } - return model_1; + + return tmp; } public void read(Buffer buffer) { do { - int i = buffer.read8U(); - if (i == 0) { + int opcode = buffer.read8U(); + + if (opcode == 0) { return; } - if (i == 1) { - int j = buffer.read8U(); - modelIDs = new int[j]; - for (int j1 = 0; j1 < j; j1++) { - modelIDs[j1] = buffer.read16U(); + + if (opcode == 1) { + int modelCount = buffer.read8U(); + modelIDs = new int[modelCount]; + for (int i = 0; i < modelCount; i++) { + modelIDs[i] = buffer.read16U(); } - } else if (i == 2) { + } else if (opcode == 2) { name = buffer.readString(); - } else if (i == 3) { + } else if (opcode == 3) { desc = buffer.readStringRaw(); - } else if (i == 12) { + } else if (opcode == 12) { size = buffer.read(); - } else if (i == 13) { + } else if (opcode == 13) { seqStandID = buffer.read16U(); - } else if (i == 14) { + } else if (opcode == 14) { seqWalkID = buffer.read16U(); - } else if (i == 17) { + } else if (opcode == 17) { seqWalkID = buffer.read16U(); seqTurnAroundID = buffer.read16U(); seqTurnLeftID = buffer.read16U(); seqTurnRightID = buffer.read16U(); - } else if ((i >= 30) && (i < 40)) { - if (op == null) { - op = new String[5]; + } else if ((opcode >= 30) && (opcode < 40)) { + if (options == null) { + options = new String[5]; } - op[i - 30] = buffer.readString(); - if (op[i - 30].equalsIgnoreCase("hidden")) { - op[i - 30] = null; + options[opcode - 30] = buffer.readString(); + if (options[opcode - 30].equalsIgnoreCase("hidden")) { + options[opcode - 30] = null; } - } else if (i == 40) { - int k = buffer.read8U(); - colorSrc = new int[k]; - colorDst = new int[k]; - for (int k1 = 0; k1 < k; k1++) { - colorSrc[k1] = buffer.read16U(); - colorDst[k1] = buffer.read16U(); + } else if (opcode == 40) { + int recolorCount = buffer.read8U(); + colorSrc = new int[recolorCount]; + colorDst = new int[recolorCount]; + for (int i = 0; i < recolorCount; i++) { + colorSrc[i] = buffer.read16U(); + colorDst[i] = buffer.read16U(); } - } else if (i == 60) { + } else if (opcode == 60) { int l = buffer.read8U(); headModelIDs = new int[l]; for (int l1 = 0; l1 < l; l1++) { headModelIDs[l1] = buffer.read16U(); } - } else if (i == 90) { + } else if (opcode == 90) { unusedInt2 = buffer.read16U(); - } else if (i == 91) { + } else if (opcode == 91) { unusedInt0 = buffer.read16U(); - } else if (i == 92) { + } else if (opcode == 92) { unusedInt1 = buffer.read16U(); - } else if (i == 93) { + } else if (opcode == 93) { showOnMinimap = false; - } else if (i == 95) { + } else if (opcode == 95) { level = buffer.read16U(); - } else if (i == 97) { - anInt91 = buffer.read16U(); - } else if (i == 98) { - anInt86 = buffer.read16U(); - } else if (i == 99) { + } else if (opcode == 97) { + scaleXY = buffer.read16U(); + } else if (opcode == 98) { + scaleZ = buffer.read16U(); + } else if (opcode == 99) { important = true; - } else if (i == 100) { - anInt85 = buffer.read(); - } else if (i == 101) { - anInt92 = buffer.read() * 5; - } else if (i == 102) { + } else if (opcode == 100) { + lightAmbient = buffer.read(); + } else if (opcode == 101) { + lightAttenuation = buffer.read() * 5; + } else if (opcode == 102) { headicon = buffer.read16U(); - } else if (i == 103) { + } else if (opcode == 103) { turnSpeed = buffer.read16U(); - } else if (i == 106) { + } else if (opcode == 106) { varbitID = buffer.read16U(); + if (varbitID == 65535) { varbitID = -1; } varpID = buffer.read16U(); + if (varpID == 65535) { varpID = -1; } - int i1 = buffer.read8U(); - overrides = new int[i1 + 1]; - for (int i2 = 0; i2 <= i1; i2++) { - overrides[i2] = buffer.read16U(); - if (overrides[i2] == 65535) { - overrides[i2] = -1; + + int overrideCount = buffer.read8U(); + overrides = new int[overrideCount + 1]; + + for (int i = 0; i <= overrideCount; i++) { + overrides[i] = buffer.read16U(); + if (overrides[i] == 65535) { + overrides[i] = -1; } } - } else if (i == 107) { + } else if (opcode == 107) { interactable = false; } } while (true); diff --git a/src/main/java/ObjType.java b/src/main/java/ObjType.java index a680567..4d36a69 100644 --- a/src/main/java/ObjType.java +++ b/src/main/java/ObjType.java @@ -29,10 +29,10 @@ public class ObjType { Buffer idx = new Buffer(archive.read("obj.idx")); count = idx.read16U(); typeOffset = new int[count]; - int i = 2; + int offset = 2; for (int j = 0; j < count; j++) { - typeOffset[j] = i; - i += idx.read16U(); + typeOffset[j] = offset; + offset += idx.read16U(); } cached = new ObjType[10]; for (int k = 0; k < 10; k++) { @@ -58,7 +58,7 @@ public class ObjType { if (!Game.members && type.members) { type.name = "Members Object"; type.examine = "Login to a members' server to use this object.".getBytes(); - type.groundOptions = null; + type.options = null; type.inventoryOptions = null; type.team = 0; } @@ -81,15 +81,15 @@ public class ObjType { ObjType type = get(id); - if (type.stackIDs == null) { + if (type.stackID == null) { amount = -1; } if (amount > 1) { int newID = -1; for (int j1 = 0; j1 < 10; j1++) { - if ((amount >= type.stackAmount[j1]) && (type.stackAmount[j1] != 0)) { - newID = type.stackIDs[j1]; + if ((amount >= type.stackCount[j1]) && (type.stackCount[j1] != 0)) { + newID = type.stackID[j1]; } } if (newID != -1) { @@ -234,37 +234,37 @@ public class ObjType { public int id = -1; public int[] dstColor; public boolean members; - public int femaleModelId2; + public int femaleModelID2; public int certificateID; - public int femaleModelId1; - public int maleModelId0; - public int maleHeadModelId1; + public int femaleModelID1; + public int maleModelID0; + public int maleHeadModelID1; public int scaleX; - public String[] groundOptions; + public String[] options; public int iconOffsetX; public String name; - public int femaleHeadModel1; + public int femaleHeadModelID1; public int modelID; - public int maleHeadModelId0; + public int maleHeadModelID0; public boolean stackable; public byte[] examine; public int linkedID; public int iconZoom; public int lightAttenuation; - public int maleModelId2; - public int maleModelId1; + public int maleModelID2; + public int maleModelID1; public String[] inventoryOptions; public int iconPitch; public int scaleY; public int scaleZ; - public int[] stackIDs; + public int[] stackID; public int iconOffsetY; public int lightAmbient; - public int femaleHeadModel0; + public int femaleHeadModelID0; public int iconYaw; public int unusedInt; - public int femaleModelId0; - public int[] stackAmount; + public int femaleModelID0; + public int[] stackCount; public int team; public int iconRoll; public byte maleOffsetY; @@ -273,36 +273,45 @@ public class ObjType { } public boolean validateHeadModel(int gender) { - int m0 = maleHeadModelId0; - int m1 = maleHeadModelId1; + int modelID0 = maleHeadModelID0; + int modelID1 = maleHeadModelID1; + if (gender == 1) { - m0 = femaleHeadModel0; - m1 = femaleHeadModel1; + modelID0 = femaleHeadModelID0; + modelID1 = femaleHeadModelID1; } - if (m0 == -1) { + + if (modelID0 == -1) { return true; } - boolean valid = Model.validate(m0); - if ((m1 != -1) && !Model.validate(m1)) { + + boolean valid = Model.validate(modelID0); + + if ((modelID1 != -1) && !Model.validate(modelID1)) { valid = false; } return valid; } public Model getHeadModel(int gender) { - int m0 = maleHeadModelId0; - int m1 = maleHeadModelId1; + int modelID0 = maleHeadModelID0; + int modelID1 = maleHeadModelID1; + if (gender == 1) { - m0 = femaleHeadModel0; - m1 = femaleHeadModel1; + modelID0 = femaleHeadModelID0; + modelID1 = femaleHeadModelID1; } - if (m0 == -1) { + + if (modelID0 == -1) { return null; } - Model model = Model.tryGet(m0); - if (m1 != -1) { - model = new Model(2, new Model[]{model, Model.tryGet(m1)}); + + Model model = Model.tryGet(modelID0); + + if (modelID1 != -1) { + model = new Model(2, new Model[]{model, Model.tryGet(modelID1)}); } + if (srcColor != null) { for (int i = 0; i < srcColor.length; i++) { model.recolor(srcColor[i], dstColor[i]); @@ -312,49 +321,55 @@ public class ObjType { } public boolean validateWornModel(int gender) { - int m0 = maleModelId0; - int m1 = maleModelId1; - int m2 = maleModelId2; + int modelID0 = maleModelID0; + int modelID1 = maleModelID1; + int modelID2 = maleModelID2; + if (gender == 1) { - m0 = femaleModelId0; - m1 = femaleModelId1; - m2 = femaleModelId2; + modelID0 = femaleModelID0; + modelID1 = femaleModelID1; + modelID2 = femaleModelID2; } - if (m0 == -1) { + + if (modelID0 == -1) { return true; } - boolean valid = Model.validate(m0); - if ((m1 != -1) && !Model.validate(m1)) { + + boolean valid = Model.validate(modelID0); + + if ((modelID1 != -1) && !Model.validate(modelID1)) { valid = false; } - if ((m2 != -1) && !Model.validate(m2)) { + + if ((modelID2 != -1) && !Model.validate(modelID2)) { valid = false; } + return valid; } public Model getWornModel(int gender) { - int m0 = maleModelId0; - int m1 = maleModelId1; - int m2 = maleModelId2; + int modelID0 = maleModelID0; + int modelID1 = maleModelID1; + int modelID2 = maleModelID2; if (gender == 1) { - m0 = femaleModelId0; - m1 = femaleModelId1; - m2 = femaleModelId2; + modelID0 = femaleModelID0; + modelID1 = femaleModelID1; + modelID2 = femaleModelID2; } - if (m0 == -1) { + if (modelID0 == -1) { return null; } - Model model = Model.tryGet(m0); + Model model = Model.tryGet(modelID0); - if (m1 != -1) { - if (m2 != -1) { - model = new Model(3, new Model[]{model, Model.tryGet(m1), Model.tryGet(m2)}); + if (modelID1 != -1) { + if (modelID2 != -1) { + model = new Model(3, new Model[]{model, Model.tryGet(modelID1), Model.tryGet(modelID2)}); } else { - model = new Model(2, new Model[]{model, Model.tryGet(m1)}); + model = new Model(2, new Model[]{model, Model.tryGet(modelID1)}); } } @@ -367,8 +382,8 @@ public class ObjType { } if (srcColor != null) { - for (int i1 = 0; i1 < srcColor.length; i1++) { - model.recolor(srcColor[i1], dstColor[i1]); + for (int i = 0; i < srcColor.length; i++) { + model.recolor(srcColor[i], dstColor[i]); } } @@ -391,22 +406,22 @@ public class ObjType { stackable = false; cost = 1; members = false; - groundOptions = null; + options = null; inventoryOptions = null; - maleModelId0 = -1; - maleModelId1 = -1; + maleModelID0 = -1; + maleModelID1 = -1; maleOffsetY = 0; - femaleModelId0 = -1; - femaleModelId1 = -1; + femaleModelID0 = -1; + femaleModelID1 = -1; femaleOffsetY = 0; - maleModelId2 = -1; - femaleModelId2 = -1; - maleHeadModelId0 = -1; - maleHeadModelId1 = -1; - femaleHeadModel0 = -1; - femaleHeadModel1 = -1; - stackIDs = null; - stackAmount = null; + maleModelID2 = -1; + femaleModelID2 = -1; + maleHeadModelID0 = -1; + maleHeadModelID1 = -1; + femaleHeadModelID0 = -1; + femaleHeadModelID1 = -1; + stackID = null; + stackCount = null; linkedID = -1; certificateID = -1; scaleX = 128; @@ -432,25 +447,30 @@ public class ObjType { name = linked.name; members = linked.members; cost = linked.cost; + String s = "a"; char c = linked.name.charAt(0); + if ((c == 'A') || (c == 'E') || (c == 'I') || (c == 'O') || (c == 'U')) { s = "an"; } + examine = ("Swap this note at any bank for " + s + " " + linked.name + ".").getBytes(); stackable = true; } - public Model getModel(int amount) { - if ((stackIDs != null) && (amount > 1)) { - int newID = -1; - for (int k = 0; k < 10; k++) { - if ((amount >= stackAmount[k]) && (stackAmount[k] != 0)) { - newID = stackIDs[k]; + public Model getModel(int count) { + if ((stackID != null) && (count > 1)) { + int id = -1; + + for (int i = 0; i < 10; i++) { + if ((count >= stackCount[i]) && (stackCount[i] != 0)) { + id = stackID[i]; } } - if (newID != -1) { - return get(newID).getModel(1); + + if (id != -1) { + return get(id).getModel(1); } } @@ -471,8 +491,8 @@ public class ObjType { } if (srcColor != null) { - for (int l = 0; l < srcColor.length; l++) { - model.recolor(srcColor[l], dstColor[l]); + for (int i = 0; i < srcColor.length; i++) { + model.recolor(srcColor[i], dstColor[i]); } } @@ -482,25 +502,30 @@ public class ObjType { return model; } - public Model getUnlitModel(int amount) { - if ((stackIDs != null) && (amount > 1)) { - int j = -1; - for (int k = 0; k < 10; k++) { - if ((amount >= stackAmount[k]) && (stackAmount[k] != 0)) { - j = stackIDs[k]; + public Model getUnlitModel(int count) { + if ((stackID != null) && (count > 1)) { + int id = -1; + + for (int i = 0; i < 10; i++) { + if ((count >= stackCount[i]) && (stackCount[i] != 0)) { + id = stackID[i]; } } - if (j != -1) { - return get(j).getUnlitModel(1); + + if (id != -1) { + return get(id).getUnlitModel(1); } } + Model model = Model.tryGet(modelID); + if (model == null) { return null; } + if (srcColor != null) { - for (int l = 0; l < srcColor.length; l++) { - model.recolor(srcColor[l], dstColor[l]); + for (int i = 0; i < srcColor.length; i++) { + model.recolor(srcColor[i], dstColor[i]); } } return model; @@ -508,107 +533,111 @@ public class ObjType { public void read(Buffer buffer) { do { - int i = buffer.read8U(); - if (i == 0) { + int opcode = buffer.read8U(); + + if (opcode == 0) { return; } - if (i == 1) { + + if (opcode == 1) { modelID = buffer.read16U(); - } else if (i == 2) { + } else if (opcode == 2) { name = buffer.readString(); - } else if (i == 3) { + } else if (opcode == 3) { examine = buffer.readStringRaw(); - } else if (i == 4) { + } else if (opcode == 4) { iconZoom = buffer.read16U(); - } else if (i == 5) { + } else if (opcode == 5) { iconPitch = buffer.read16U(); - } else if (i == 6) { + } else if (opcode == 6) { iconYaw = buffer.read16U(); - } else if (i == 7) { + } else if (opcode == 7) { iconOffsetX = buffer.read16U(); if (iconOffsetX > 32767) { iconOffsetX -= 0x10000; } - } else if (i == 8) { + } else if (opcode == 8) { iconOffsetY = buffer.read16U(); if (iconOffsetY > 32767) { iconOffsetY -= 0x10000; } - } else if (i == 10) { + } else if (opcode == 10) { unusedInt = buffer.read16U(); - } else if (i == 11) { + } else if (opcode == 11) { stackable = true; - } else if (i == 12) { + } else if (opcode == 12) { cost = buffer.read32(); - } else if (i == 16) { + } else if (opcode == 16) { members = true; - } else if (i == 23) { - maleModelId0 = buffer.read16U(); + } else if (opcode == 23) { + maleModelID0 = buffer.read16U(); maleOffsetY = buffer.read(); - } else if (i == 24) { - maleModelId1 = buffer.read16U(); - } else if (i == 25) { - femaleModelId0 = buffer.read16U(); + } else if (opcode == 24) { + maleModelID1 = buffer.read16U(); + } else if (opcode == 25) { + femaleModelID0 = buffer.read16U(); femaleOffsetY = buffer.read(); - } else if (i == 26) { - femaleModelId1 = buffer.read16U(); - } else if ((i >= 30) && (i < 35)) { - if (groundOptions == null) { - groundOptions = new String[5]; + } else if (opcode == 26) { + femaleModelID1 = buffer.read16U(); + } else if ((opcode >= 30) && (opcode < 35)) { + if (options == null) { + options = new String[5]; } - groundOptions[i - 30] = buffer.readString(); - if (groundOptions[i - 30].equalsIgnoreCase("hidden")) { - groundOptions[i - 30] = null; + + options[opcode - 30] = buffer.readString(); + + if (options[opcode - 30].equalsIgnoreCase("hidden")) { + options[opcode - 30] = null; } - } else if ((i >= 35) && (i < 40)) { + } else if ((opcode >= 35) && (opcode < 40)) { if (inventoryOptions == null) { inventoryOptions = new String[5]; } - inventoryOptions[i - 35] = buffer.readString(); - } else if (i == 40) { - int j = buffer.read8U(); - srcColor = new int[j]; - dstColor = new int[j]; - for (int k = 0; k < j; k++) { - srcColor[k] = buffer.read16U(); - dstColor[k] = buffer.read16U(); + inventoryOptions[opcode - 35] = buffer.readString(); + } else if (opcode == 40) { + int recolorCount = buffer.read8U(); + srcColor = new int[recolorCount]; + dstColor = new int[recolorCount]; + for (int i = 0; i < recolorCount; i++) { + srcColor[i] = buffer.read16U(); + dstColor[i] = buffer.read16U(); } - } else if (i == 78) { - maleModelId2 = buffer.read16U(); - } else if (i == 79) { - femaleModelId2 = buffer.read16U(); - } else if (i == 90) { - maleHeadModelId0 = buffer.read16U(); - } else if (i == 91) { - femaleHeadModel0 = buffer.read16U(); - } else if (i == 92) { - maleHeadModelId1 = buffer.read16U(); - } else if (i == 93) { - femaleHeadModel1 = buffer.read16U(); - } else if (i == 95) { + } else if (opcode == 78) { + maleModelID2 = buffer.read16U(); + } else if (opcode == 79) { + femaleModelID2 = buffer.read16U(); + } else if (opcode == 90) { + maleHeadModelID0 = buffer.read16U(); + } else if (opcode == 91) { + femaleHeadModelID0 = buffer.read16U(); + } else if (opcode == 92) { + maleHeadModelID1 = buffer.read16U(); + } else if (opcode == 93) { + femaleHeadModelID1 = buffer.read16U(); + } else if (opcode == 95) { iconRoll = buffer.read16U(); - } else if (i == 97) { + } else if (opcode == 97) { linkedID = buffer.read16U(); - } else if (i == 98) { + } else if (opcode == 98) { certificateID = buffer.read16U(); - } else if ((i >= 100) && (i < 110)) { - if (stackIDs == null) { - stackIDs = new int[10]; - stackAmount = new int[10]; + } else if ((opcode >= 100) && (opcode < 110)) { + if (stackID == null) { + stackID = new int[10]; + stackCount = new int[10]; } - stackIDs[i - 100] = buffer.read16U(); - stackAmount[i - 100] = buffer.read16U(); - } else if (i == 110) { + stackID[opcode - 100] = buffer.read16U(); + stackCount[opcode - 100] = buffer.read16U(); + } else if (opcode == 110) { scaleX = buffer.read16U(); - } else if (i == 111) { + } else if (opcode == 111) { scaleZ = buffer.read16U(); - } else if (i == 112) { + } else if (opcode == 112) { scaleY = buffer.read16U(); - } else if (i == 113) { + } else if (opcode == 113) { lightAmbient = buffer.read(); - } else if (i == 114) { + } else if (opcode == 114) { lightAttenuation = buffer.read() * 5; - } else if (i == 115) { + } else if (opcode == 115) { team = buffer.read8U(); } } while (true); diff --git a/src/main/java/OnDemand.java b/src/main/java/OnDemand.java index 2e16fa4..f896ea8 100644 --- a/src/main/java/OnDemand.java +++ b/src/main/java/OnDemand.java @@ -471,7 +471,7 @@ public class OnDemand implements Runnable { } } - public void method560(int file, int store) { + public void prefetch(int file, int store) { if (game.filestores[0] == null) { return; } diff --git a/src/main/java/PathingEntity.java b/src/main/java/PathingEntity.java index 8136a12..a5d97b5 100644 --- a/src/main/java/PathingEntity.java +++ b/src/main/java/PathingEntity.java @@ -44,7 +44,7 @@ public class PathingEntity extends Entity { public int targetTileZ; public int size = 1; /** - * Passed to {@link Scene#pushTemporary(Entity, int, int, int, int, int, int, boolean, int)} to provide an additional + * Passed to {@link Scene#addTemporary(Entity, int, int, int, int, int, int, boolean, int)} to provide an additional * tile worth of draw padding ahead of this entity for things like animations that extend past the normal boundary. */ public boolean needsForwardDrawPadding = false; diff --git a/src/main/java/PlayerEntity.java b/src/main/java/PlayerEntity.java index eda5d26..a2803de 100644 --- a/src/main/java/PlayerEntity.java +++ b/src/main/java/PlayerEntity.java @@ -10,7 +10,7 @@ public class PlayerEntity extends PathingEntity { public final int[] colors = new int[5]; public final int[] appearances = new int[12]; public long modelUID = -1L; - public NPCType npcType; + public NPCType transmogrify; public boolean lowmem = false; public int team; public int gender; @@ -79,34 +79,34 @@ public class PlayerEntity extends PathingEntity { } if ((Game.loopCycle >= locStartCycle) && (Game.loopCycle < locStopCycle)) { - Model model1 = this.locModel; - model1.translate(locOffsetX - super.x, locOffsetY - y, locOffsetZ - super.z); + Model locModel = this.locModel; + locModel.translate(locOffsetX - super.x, locOffsetY - y, locOffsetZ - super.z); if (super.dstYaw == 512) { - model1.rotateY90(); - model1.rotateY90(); - model1.rotateY90(); + locModel.rotateY90(); + locModel.rotateY90(); + locModel.rotateY90(); } else if (super.dstYaw == 1024) { - model1.rotateY90(); - model1.rotateY90(); + locModel.rotateY90(); + locModel.rotateY90(); } else if (super.dstYaw == 1536) { - model1.rotateY90(); + locModel.rotateY90(); } - model = new Model(2, -819, new Model[]{model, model1}); + model = new Model(2, -819, new Model[]{model, locModel}); if (super.dstYaw == 512) { - model1.rotateY90(); + locModel.rotateY90(); } else if (super.dstYaw == 1024) { - model1.rotateY90(); - model1.rotateY90(); + locModel.rotateY90(); + locModel.rotateY90(); } else if (super.dstYaw == 1536) { - model1.rotateY90(); - model1.rotateY90(); - model1.rotateY90(); + locModel.rotateY90(); + locModel.rotateY90(); + locModel.rotateY90(); } - model1.translate(super.x - locOffsetX, y - locOffsetY, super.z - locOffsetZ); + locModel.translate(super.x - locOffsetX, y - locOffsetY, super.z - locOffsetZ); } } @@ -118,7 +118,7 @@ public class PlayerEntity extends PathingEntity { buffer.position = 0; gender = buffer.read8U(); headicons = buffer.read8U(); - npcType = null; + transmogrify = null; team = 0; for (int part = 0; part < 12; part++) { @@ -133,7 +133,7 @@ public class PlayerEntity extends PathingEntity { appearances[part] = (msb << 8) + lsb; if ((part == 0) && (appearances[0] == 65535)) { - npcType = NPCType.get(buffer.read16U()); + transmogrify = NPCType.get(buffer.read16U()); break; } @@ -216,14 +216,14 @@ public class PlayerEntity extends PathingEntity { } public Model getSequencedModel() { - if (npcType != null) { + if (transmogrify != null) { int transformID = -1; if ((super.primarySeqID >= 0) && (super.primarySeqDelay == 0)) { transformID = SeqType.instances[super.primarySeqID].transformIDs[super.primarySeqFrame]; } else if (super.secondarySeqID >= 0) { transformID = SeqType.instances[super.secondarySeqID].transformIDs[super.secondarySeqFrame]; } - return npcType.getSequencedModel(-1, transformID, null); + return transmogrify.getSequencedModel(-1, transformID, null); } long hashCode = this.appearanceHashcode; @@ -338,19 +338,19 @@ public class PlayerEntity extends PathingEntity { return model; } - Model animated = Model.EMPTY; - animated.set(model, SeqTransform.isNull(primaryTransformID) & SeqTransform.isNull(secondaryTransformID)); + Model tmp = Model.EMPTY; + tmp.set(model, SeqTransform.isNull(primaryTransformID) & SeqTransform.isNull(secondaryTransformID)); if ((primaryTransformID != -1) && (secondaryTransformID != -1)) { - animated.applyTransforms(primaryTransformID, secondaryTransformID, SeqType.instances[super.primarySeqID].mask); + tmp.applyTransforms(primaryTransformID, secondaryTransformID, SeqType.instances[super.primarySeqID].mask); } else if (primaryTransformID != -1) { - animated.applyTransform(primaryTransformID); + tmp.applyTransform(primaryTransformID); } - animated.calculateBoundsCylinder(); - animated.labelFaces = null; - animated.labelVertices = null; - return animated; + tmp.calculateBoundsCylinder(); + tmp.labelFaces = null; + tmp.labelVertices = null; + return tmp; } @Override @@ -363,8 +363,8 @@ public class PlayerEntity extends PathingEntity { return null; } - if (npcType != null) { - return npcType.getUnlitHeadModel(); + if (transmogrify != null) { + return transmogrify.getUnlitHeadModel(); } boolean invalid = false; @@ -403,15 +403,18 @@ public class PlayerEntity extends PathingEntity { } } } + Model model = new Model(modelCount, models); - for (int j1 = 0; j1 < 5; j1++) { - if (colors[j1] != 0) { - model.recolor(Game.designPartColor[j1][0], Game.designPartColor[j1][colors[j1]]); - if (j1 == 1) { - model.recolor(Game.designHairColor[0], Game.designHairColor[colors[j1]]); + + for (int part = 0; part < 5; part++) { + if (colors[part] != 0) { + model.recolor(Game.designPartColor[part][0], Game.designPartColor[part][colors[part]]); + if (part == 1) { + model.recolor(Game.designHairColor[0], Game.designHairColor[colors[part]]); } } } + return model; } diff --git a/src/main/java/Scene.java b/src/main/java/Scene.java index 28158bb..d68d47d 100644 --- a/src/main/java/Scene.java +++ b/src/main/java/Scene.java @@ -490,17 +490,17 @@ public class Scene { levelTiles[level][tileX][tileZ].wallDecoration = deco; } - public boolean push(Entity entity, int level, int tileX, int tileZ, int y, int width, int length, int yaw, int bitset, byte info) { + public boolean add(Entity entity, int level, int tileX, int tileZ, int y, int width, int length, int yaw, int bitset, byte info) { if (entity == null) { return true; } else { int sceneX = (tileX * 128) + (64 * width); int sceneZ = (tileZ * 128) + (64 * length); - return push(entity, level, tileX, tileZ, width, length, sceneX, sceneZ, y, yaw, bitset, info, false); + return add(entity, level, tileX, tileZ, width, length, sceneX, sceneZ, y, yaw, bitset, info, false); } } - public boolean pushTemporary(Entity entity, int level, int x, int z, int y, int yaw, int bitset, boolean forwardPadding, int padding) { + public boolean addTemporary(Entity entity, int level, int x, int z, int y, int yaw, int bitset, boolean forwardPadding, int padding) { if (entity == null) { return true; } @@ -529,18 +529,18 @@ public class Scene { z0 /= 128; x1 /= 128; z1 /= 128; - return push(entity, level, x0, z0, (x1 - x0) + 1, (z1 - z0) + 1, x, z, y, yaw, bitset, (byte) 0, true); + return add(entity, level, x0, z0, (x1 - x0) + 1, (z1 - z0) + 1, x, z, y, yaw, bitset, (byte) 0, true); } - public boolean pushTemporary(Entity entity, int level, int minTileX, int minTileZ, int maxTileX, int maxTileZ, int x, int z, int y, int yaw, int bitset) { + public boolean addTemporary(Entity entity, int level, int minTileX, int minTileZ, int maxTileX, int maxTileZ, int x, int z, int y, int yaw, int bitset) { if (entity == null) { return true; } else { - return push(entity, level, minTileX, minTileZ, (maxTileX - minTileX) + 1, (maxTileZ - minTileZ) + 1, x, z, y, yaw, bitset, (byte) 0, true); + return add(entity, level, minTileX, minTileZ, (maxTileX - minTileX) + 1, (maxTileZ - minTileZ) + 1, x, z, y, yaw, bitset, (byte) 0, true); } } - public boolean push(Entity entity, int level, int tileX, int tileZ, int tileSizeX, int tileSizeZ, int x, int z, int y, int yaw, int bitset, byte info, boolean temporary) { + public boolean add(Entity entity, int level, int tileX, int tileZ, int tileSizeX, int tileSizeZ, int x, int z, int y, int yaw, int bitset, byte info, boolean temporary) { for (int tx = tileX; tx < (tileX + tileSizeX); tx++) { for (int tz = tileZ; tz < (tileZ + tileSizeZ); tz++) { if ((tx < 0) || (tz < 0) || (tx >= maxTileX) || (tz >= maxTileZ)) { @@ -2079,7 +2079,7 @@ public class Scene { for (int i = 0; i < count; i++) { SceneOccluder occluder = occluders[i]; - if (occluder.type == 1) { + if (occluder.type == SceneOccluder.TYPE_WALL_X) { int x = (occluder.minTileX - eyeTileX) + 25; if ((x < 0) || (x > 50)) { @@ -2134,7 +2134,7 @@ public class Scene { continue; } - if (occluder.type == 2) { + if (occluder.type == SceneOccluder.TYPE_WALL_Z) { int distanceMinTileZ = (occluder.minTileZ - eyeTileZ) + 25; if ((distanceMinTileZ < 0) || (distanceMinTileZ > 50)) { @@ -2184,7 +2184,7 @@ public class Scene { occluder.maxDeltaY = ((occluder.maxY - eyeY) << 10) / deltaMinZ; activeOccluders[activeOccluderCount++] = occluder; activeWallOccluderCount++; - } else if (occluder.type == 4) { + } else if (occluder.type == SceneOccluder.TYPE_GROUND) { int deltaMaxY = occluder.minY - eyeY; if (deltaMaxY <= 128) { diff --git a/src/main/java/SceneBuilder.java b/src/main/java/SceneBuilder.java index e1ac02d..8c090ee 100644 --- a/src/main/java/SceneBuilder.java +++ b/src/main/java/SceneBuilder.java @@ -31,19 +31,22 @@ public class SceneBuilder { return value; } - public static void method173(Buffer buffer, OnDemand onDemand) { - int i_110_ = -1; + public static void prefetchLocs(Buffer buffer, OnDemand onDemand) { + int locID = -1; + for (; ; ) { - int i_111_ = buffer.readSmartU(); - if (i_111_ == 0) { + int deltaID = buffer.readSmartU(); + + if (deltaID == 0) { break; } - i_110_ += i_111_; - LocType type = LocType.get(i_110_); - type.method574(onDemand); + + locID += deltaID; + LocType type = LocType.get(locID); + type.prefetch(onDemand); + for (; ; ) { - int i_112_ = buffer.readSmartU(); - if (i_112_ == 0) { + if (buffer.readSmartU() == 0) { break; } buffer.read8U(); @@ -99,6 +102,7 @@ public class SceneBuilder { if (hsl == -1) { return 12345678; } + lightness = (lightness * (hsl & 0x7f)) / 128; if (lightness < 2) { @@ -106,10 +110,11 @@ public class SceneBuilder { } else if (lightness > 126) { lightness = 126; } + return (hsl & 0xff80) + lightness; } - public static void addLoc(Scene scene, int rotation, int z, int kind, int tileLevel, SceneCollisionMap collision, int[][][] levelHeightmap, int x, int locID, int level) { + public static void addLoc(Scene scene, int rotation, int z, int kind, int tileLevel, CollisionMap collision, int[][][] levelHeightmap, int x, int locID, int level) { int heightSW = levelHeightmap[tileLevel][x][z]; int heightSE = levelHeightmap[tileLevel][x + 1][z]; int heightNE = levelHeightmap[tileLevel][x + 1][z + 1]; @@ -179,7 +184,7 @@ public class SceneBuilder { } } - private static void addGroundDecoration(Scene scene, int rotation, int z, SceneCollisionMap collision, int x, int locID, int level, int heightSW, int heightSE, int heightNE, int heightNW, int y, LocType loc, int bitset, byte info) { + private static void addGroundDecoration(Scene scene, int rotation, int z, CollisionMap collision, int x, int locID, int level, int heightSW, int heightSE, int heightNE, int heightNW, int y, LocType loc, int bitset, byte info) { Entity entity; if ((loc.seqID == -1) && (loc.overrideTypeIDs == null)) { @@ -191,11 +196,11 @@ public class SceneBuilder { scene.addGroundDecoration(entity, level, x, z, y, bitset, info); if (loc.solid && loc.interactable) { - collision.addSolid(z, x); + collision.addSolid(x, z); } } - private static void addLoc(Scene scene, int rotation, int z, int kind, SceneCollisionMap collision, int x, int locID, int level, int heightSW, int heightSE, int heightNE, int heightNW, int y, LocType loc, int bitset, byte info) { + private static void addLoc(Scene scene, int rotation, int z, int kind, CollisionMap collision, int x, int locID, int level, int heightSW, int heightSE, int heightNE, int heightNW, int y, LocType loc, int bitset, byte info) { Entity entity; if ((loc.seqID == -1) && (loc.overrideTypeIDs == null)) { @@ -222,14 +227,14 @@ public class SceneBuilder { length = loc.sizeZ; } - scene.push(entity, level, x, z, y, width, length, angle, bitset, info); + scene.add(entity, level, x, z, y, width, length, angle, bitset, info); } if (loc.solid) { collision.add(loc.blocksProjectiles, loc.sizeX, loc.sizeZ, x, z, rotation); } } - private static void addWall(Scene scene, int rotation, int z, int kind, SceneCollisionMap collision, int x, int locID, int level, int heightSW, int heightSE, int heightNE, int heightNW, int y, LocType loc, int bitset, byte info) { + private static void addWall(Scene scene, int rotation, int z, int kind, CollisionMap collision, int x, int locID, int level, int heightSW, int heightSE, int heightNE, int heightNW, int y, LocType loc, int bitset, byte info) { Entity entity; if ((loc.seqID == -1) && (loc.overrideTypeIDs == null)) { @@ -241,11 +246,11 @@ public class SceneBuilder { scene.setWall(Scene.ROTATION_WALL_TYPE[rotation], entity, 0, null, level, x, z, y, bitset, info); if (loc.solid) { - collision.addWall(z, rotation, x, kind, loc.blocksProjectiles); + collision.addWall(x, z, kind, rotation, loc.blocksProjectiles); } } - private static void addDiagonalWallCorner(Scene scene, int rotation, int z, int kind, SceneCollisionMap collision, int x, int locID, int level, int heightSW, int heightSE, int heightNE, int heightNW, int y, LocType loc, int bitset, byte info) { + private static void addDiagonalWallCorner(Scene scene, int rotation, int z, int kind, CollisionMap collision, int x, int locID, int level, int heightSW, int heightSE, int heightNE, int heightNW, int y, LocType loc, int bitset, byte info) { Entity entity; if ((loc.seqID == -1) && (loc.overrideTypeIDs == null)) { @@ -257,11 +262,11 @@ public class SceneBuilder { scene.setWall(Scene.ROTATION_WALL_CORNER_TYPE[rotation], entity, 0, null, level, x, z, y, bitset, info); if (loc.solid) { - collision.addWall(z, rotation, x, kind, loc.blocksProjectiles); + collision.addWall(x, z, kind, rotation, loc.blocksProjectiles); } } - private static void addFullWallCorner(Scene scene, int rotation, int z, int kind, SceneCollisionMap collision, int x, int locID, int level, int heightSW, int heightSE, int heightNE, int heightNW, int y, LocType loc, int bitset, byte info) { + private static void addFullWallCorner(Scene scene, int rotation, int z, int kind, CollisionMap collision, int x, int locID, int level, int heightSW, int heightSE, int heightNE, int heightNW, int y, LocType loc, int bitset, byte info) { int nextRotation = (rotation + 1) & 0x3; Entity locA; Entity locB; @@ -277,11 +282,11 @@ public class SceneBuilder { scene.setWall(Scene.ROTATION_WALL_TYPE[rotation], locA, Scene.ROTATION_WALL_TYPE[nextRotation], locB, level, x, z, y, bitset, info); if (loc.solid) { - collision.addWall(z, rotation, x, kind, loc.blocksProjectiles); + collision.addWall(x, z, kind, rotation, loc.blocksProjectiles); } } - private static void addWallCorner(Scene scene, int rotation, int z, int kind, SceneCollisionMap collision, int x, int locID, int level, int heightSW, int heightSE, int heightNE, int heightNW, int y, LocType loc, int bitset, byte info) { + private static void addWallCorner(Scene scene, int rotation, int z, int kind, CollisionMap collision, int x, int locID, int level, int heightSW, int heightSE, int heightNE, int heightNW, int y, LocType loc, int bitset, byte info) { Entity entity; if ((loc.seqID == -1) && (loc.overrideTypeIDs == null)) { @@ -293,23 +298,7 @@ public class SceneBuilder { scene.setWall(Scene.ROTATION_WALL_CORNER_TYPE[rotation], entity, 0, null, level, x, z, y, bitset, info); if (loc.solid) { - collision.addWall(z, rotation, x, kind, loc.blocksProjectiles); - } - } - - private static void addDiagonalWall(Scene scene, int rotation, int z, int kind, SceneCollisionMap collision, int x, int locID, int level, int heightSW, int heightSE, int heightNE, int heightNW, int y, LocType loc, int bitset, byte info) { - Entity entity; - - if ((loc.seqID == -1) && (loc.overrideTypeIDs == null)) { - entity = loc.getModel(kind, rotation, heightSW, heightSE, heightNE, heightNW, -1); - } else { - entity = new LocEntity(locID, rotation, kind, heightSE, heightNE, heightSW, heightNW, loc.seqID, true); - } - - scene.push(entity, level, x, z, y, 1, 1, 0, bitset, info); - - if (loc.solid) { - collision.add(loc.blocksProjectiles, loc.sizeX, loc.sizeZ, x, z, rotation); + collision.addWall(x, z, kind, rotation, loc.blocksProjectiles); } } @@ -325,6 +314,22 @@ public class SceneBuilder { scene.setWallDecoration(Scene.ROTATION_WALL_TYPE[rotation], entity, level, x, z, y, rotation * 512, 0, 0, bitset, info); } + private static void addDiagonalWall(Scene scene, int rotation, int z, int kind, CollisionMap collision, int x, int locID, int level, int heightSW, int heightSE, int heightNE, int heightNW, int y, LocType loc, int bitset, byte info) { + Entity entity; + + if ((loc.seqID == -1) && (loc.overrideTypeIDs == null)) { + entity = loc.getModel(kind, rotation, heightSW, heightSE, heightNE, heightNW, -1); + } else { + entity = new LocEntity(locID, rotation, kind, heightSE, heightNE, heightSW, heightNW, loc.seqID, true); + } + + scene.add(entity, level, x, z, y, 1, 1, 0, bitset, info); + + if (loc.solid) { + collision.add(loc.blocksProjectiles, loc.sizeX, loc.sizeZ, x, z, rotation); + } + } + private static void addWallDecorationOutside(Scene scene, int rotation, int z, int x, int locID, int level, int heightSW, int heightSE, int heightNE, int heightNW, int y, LocType loc, int bitset, byte info) { int padding = 16; int wallBitset = scene.getWallBitset(level, x, z); @@ -359,14 +364,14 @@ public class SceneBuilder { int locID = -1; for (; ; ) { - int idDelta = buffer.readSmartU(); - if (idDelta == 0) { + int deltaID = buffer.readSmartU(); + if (deltaID == 0) { break; } - locID += idDelta; + locID += deltaID; - int coordinate = 0; + int pos = 0; boolean skip = false; // this loop is for the same Loc ID. @@ -377,16 +382,16 @@ public class SceneBuilder { } buffer.read8U(); } else { - int coordinateDelta = buffer.readSmartU(); + int deltaPos = buffer.readSmartU(); - if (coordinateDelta == 0) { + if (deltaPos == 0) { break; } - coordinate += coordinateDelta - 1; + pos += deltaPos - 1; - int z = coordinate & 0x3f; - int x = (coordinate >> 6) & 0x3f; + int z = pos & 0x3f; + int x = (pos >> 6) & 0x3f; int kind = buffer.read8U() >> 2; int localX = x + originX; @@ -443,7 +448,7 @@ public class SceneBuilder { blendMagnitude = new int[this.maxTileZ]; } - public void build(SceneCollisionMap[] levelCollisionMaps, Scene scene) { + public void build(CollisionMap[] levelCollisionMaps, Scene scene) { applyBlockFlags(levelCollisionMaps); randomize(); @@ -459,26 +464,23 @@ public class SceneBuilder { buildOccluders(); } - private void applyBlockFlags(SceneCollisionMap[] levelCollisionMaps) { + private void applyBlockFlags(CollisionMap[] levelCollisionMaps) { for (int level = 0; level < 4; level++) { for (int x = 0; x < 104; x++) { for (int z = 0; z < 104; z++) { - // solid? - if ((levelTileFlags[level][x][z] & 0x1) != 1) { - continue; + // solid + if ((levelTileFlags[level][x][z] & 0x1) == 1) { + int trueLevel = level; + + // bridge + if ((levelTileFlags[1][x][z] & 0x2) == 2) { + trueLevel--; + } + + if (trueLevel >= 0) { + levelCollisionMaps[trueLevel].addSolid(x, z); + } } - - int trueLevel = level; - - // bridge - if ((levelTileFlags[1][x][z] & 0x2) == 2) { - trueLevel--; - } - - if (trueLevel >= 0) { - levelCollisionMaps[trueLevel].addSolid(z, x); - } - } } } @@ -697,10 +699,10 @@ public class SceneBuilder { int dx = levelHeightmap[level][x + 1][z] - levelHeightmap[level][x - 1][z]; int dz = levelHeightmap[level][x][z + 1] - levelHeightmap[level][x][z - 1]; int len = (int) Math.sqrt((dx * dx) + 65536 + (dz * dz)); - int nx = (dx << 8) / len; - int ny = 65536 / len; - int nz = (dz << 8) / len; - int light = lightAmbient + (((lightX * nx) + (lightY * ny) + (lightZ * nz)) / lightMagnitude); + int normalX = (dx << 8) / len; + int normalY = 65536 / len; + int normalZ = (dz << 8) / len; + int light = lightAmbient + (((lightX * normalX) + (lightY * normalY) + (lightZ * normalZ)) / lightMagnitude); int shade = (shademap[x - 1][z] >> 2) + (shademap[x + 1][z] >> 3) + (shademap[x][z - 1] >> 2) + (shademap[x][z + 1] >> 3) + (shademap[x][z] >> 1); levelLightmap[x][z] = light - shade; } @@ -722,26 +724,133 @@ public class SceneBuilder { int wall1 = 0b010; // this flag is set by walls with rotation 1 or 3 int floor = 0b100; // this flag is set by floors which are flat - for (int top = 0; top < 4; top++) { - if (top > 0) { + for (int topLevel = 0; topLevel < 4; topLevel++) { + if (topLevel > 0) { wall0 <<= 3; wall1 <<= 3; floor <<= 3; } - for (int level = 0; level <= top; level++) { + for (int level = 0; level <= topLevel; level++) { for (int tileZ = 0; tileZ <= maxTileZ; tileZ++) { for (int tileX = 0; tileX <= maxTileX; tileX++) { - buildWallOccluders0(wall0, top, level, tileX, tileZ); - buildWallOccluders1(wall1, top, level, tileX, tileZ); - buildFloorOccluders(floor, top, level, tileX, tileZ); + buildWallOccludersX(wall0, topLevel, level, tileX, tileZ); + buildWallOccludersZ(wall1, topLevel, level, tileX, tileZ); + buildFloorOccluders(floor, topLevel, level, tileX, tileZ); } } } } } - private void buildFloorOccluders(int floor, int top, int level, int tileX, int tileZ) { + private void buildWallOccludersX(int wall0, int topLevel, int level, int tileX, int tileZ) { + if ((levelOccludemap[level][tileX][tileZ] & wall0) != 0) { + int minTileZ = tileZ; + int maxTileZ = tileZ; + int minLevel = level; + int maxLevel = level; + + for (/**/; minTileZ > 0; minTileZ--) { + if ((levelOccludemap[level][tileX][minTileZ - 1] & wall0) == 0) { + break; + } + } + + for (/**/; maxTileZ < this.maxTileZ; maxTileZ++) { + if ((levelOccludemap[level][tileX][maxTileZ + 1] & wall0) == 0) { + break; + } + } + + find_min_level: + for (/**/; minLevel > 0; minLevel--) { + for (int z = minTileZ; z <= maxTileZ; z++) { + if ((levelOccludemap[minLevel - 1][tileX][z] & wall0) == 0) { + break find_min_level; + } + } + } + + find_max_level: + for (/**/; maxLevel < topLevel; maxLevel++) { + for (int z = minTileZ; z <= maxTileZ; z++) { + if ((levelOccludemap[maxLevel + 1][tileX][z] & wall0) == 0) { + break find_max_level; + } + } + } + + int area = ((maxLevel + 1) - minLevel) * ((maxTileZ - minTileZ) + 1); + + if (area >= 2) { + int minY = levelHeightmap[maxLevel][tileX][minTileZ] - 240; + int maxY = levelHeightmap[minLevel][tileX][minTileZ]; + + Scene.addOccluder(topLevel, tileX * 128, minY, minTileZ * 128, tileX * 128, maxY, (maxTileZ * 128) + 128, SceneOccluder.TYPE_WALL_X); + + for (int l = minLevel; l <= maxLevel; l++) { + for (int z = minTileZ; z <= maxTileZ; z++) { + levelOccludemap[l][tileX][z] &= ~wall0; + } + } + } + } + } + + private void buildWallOccludersZ(int wall1, int topLevel, int level, int tileX, int tileZ) { + if ((levelOccludemap[level][tileX][tileZ] & wall1) != 0) { + int minTileX = tileX; + int maxTileX = tileX; + int minLevel = level; + int maxLevel = level; + + for (/**/; minTileX > 0; minTileX--) { + if ((levelOccludemap[level][minTileX - 1][tileZ] & wall1) == 0) { + break; + } + } + for (/**/; maxTileX < this.maxTileX; maxTileX++) { + if ((levelOccludemap[level][maxTileX + 1][tileZ] & wall1) == 0) { + break; + } + } + + find_min_level: + for (/**/; minLevel > 0; minLevel--) { + for (int x = minTileX; x <= maxTileX; x++) { + if ((levelOccludemap[minLevel - 1][x][tileZ] & wall1) == 0) { + break find_min_level; + } + } + } + + find_max_level: + for (/**/; maxLevel < topLevel; maxLevel++) { + for (int x = minTileX; x <= maxTileX; x++) { + if ((levelOccludemap[maxLevel + 1][x][tileZ] & wall1) == 0) { + break find_max_level; + } + } + } + + int area = ((maxLevel + 1) - minLevel) * ((maxTileX - minTileX) + 1); + + if (area >= 2) { + int minY = levelHeightmap[maxLevel][minTileX][tileZ] - 240; + int maxY = levelHeightmap[minLevel][minTileX][tileZ]; + + Scene.addOccluder(topLevel, minTileX * 128, minY, tileZ * 128, (maxTileX * 128) + 128, maxY, tileZ * 128, SceneOccluder.TYPE_WALL_Z); + + for (int l = minLevel; l <= maxLevel; l++) { + for (int x = minTileX; x <= maxTileX; x++) { + levelOccludemap[l][x][tileZ] &= ~wall1; + } + } + } + } + } + + private void buildFloorOccluders(int floor, int topLevel, int level, int tileX, int tileZ) { if ((levelOccludemap[level][tileX][tileZ] & floor) != 0) { int minTileX = tileX; int maxTileX = tileX; @@ -780,7 +889,7 @@ public class SceneBuilder { if ((((maxTileX - minTileX) + 1) * ((maxTileZ - minTileZ) + 1)) >= 4) { int y = levelHeightmap[level][minTileX][minTileZ]; - Scene.addOccluder(top, minTileX * 128, y, minTileZ * 128, (maxTileX * 128) + 128, y, (maxTileZ * 128) + 128, 4); + Scene.addOccluder(topLevel, minTileX * 128, y, minTileZ * 128, (maxTileX * 128) + 128, y, (maxTileZ * 128) + 128, SceneOccluder.TYPE_GROUND); for (int x = minTileX; x <= maxTileX; x++) { for (int z = minTileZ; z <= maxTileZ; z++) { @@ -791,113 +900,6 @@ public class SceneBuilder { } } - private void buildWallOccluders1(int wall1, int top, int level, int tileX, int tileZ) { - if ((levelOccludemap[level][tileX][tileZ] & wall1) != 0) { - int minTileX = tileX; - int maxTileX = tileX; - int minLevel = level; - int maxLevel = level; - - for (/**/; minTileX > 0; minTileX--) { - if ((levelOccludemap[level][minTileX - 1][tileZ] & wall1) == 0) { - break; - } - } - for (/**/; maxTileX < this.maxTileX; maxTileX++) { - if ((levelOccludemap[level][maxTileX + 1][tileZ] & wall1) == 0) { - break; - } - } - - find_min_level: - for (/**/; minLevel > 0; minLevel--) { - for (int x = minTileX; x <= maxTileX; x++) { - if ((levelOccludemap[minLevel - 1][x][tileZ] & wall1) == 0) { - break find_min_level; - } - } - } - - find_max_level: - for (/**/; maxLevel < top; maxLevel++) { - for (int x = minTileX; x <= maxTileX; x++) { - if ((levelOccludemap[maxLevel + 1][x][tileZ] & wall1) == 0) { - break find_max_level; - } - } - } - - int area = ((maxLevel + 1) - minLevel) * ((maxTileX - minTileX) + 1); - - if (area >= 2) { - int minY = levelHeightmap[maxLevel][minTileX][tileZ] - 240; - int maxY = levelHeightmap[minLevel][minTileX][tileZ]; - - Scene.addOccluder(top, minTileX * 128, minY, tileZ * 128, (maxTileX * 128) + 128, maxY, tileZ * 128, 2); - - for (int l = minLevel; l <= maxLevel; l++) { - for (int x = minTileX; x <= maxTileX; x++) { - levelOccludemap[l][x][tileZ] &= ~wall1; - } - } - } - } - } - - private void buildWallOccluders0(int wall0, int top, int level, int tileX, int tileZ) { - if ((levelOccludemap[level][tileX][tileZ] & wall0) != 0) { - int minTileZ = tileZ; - int maxTileZ = tileZ; - int minLevel = level; - int maxLevel = level; - - for (/**/; minTileZ > 0; minTileZ--) { - if ((levelOccludemap[level][tileX][minTileZ - 1] & wall0) == 0) { - break; - } - } - - for (/**/; maxTileZ < this.maxTileZ; maxTileZ++) { - if ((levelOccludemap[level][tileX][maxTileZ + 1] & wall0) == 0) { - break; - } - } - - find_min_level: - for (/**/; minLevel > 0; minLevel--) { - for (int z = minTileZ; z <= maxTileZ; z++) { - if ((levelOccludemap[minLevel - 1][tileX][z] & wall0) == 0) { - break find_min_level; - } - } - } - - find_max_level: - for (/**/; maxLevel < top; maxLevel++) { - for (int z = minTileZ; z <= maxTileZ; z++) { - if ((levelOccludemap[maxLevel + 1][tileX][z] & wall0) == 0) { - break find_max_level; - } - } - } - - int area = ((maxLevel + 1) - minLevel) * ((maxTileZ - minTileZ) + 1); - - if (area >= 2) { - int minY = levelHeightmap[maxLevel][tileX][minTileZ] - 240; - int maxY = levelHeightmap[minLevel][tileX][minTileZ]; - - Scene.addOccluder(top, tileX * 128, minY, minTileZ * 128, tileX * 128, maxY, (maxTileZ * 128) + 128, 1); - - for (int l = minLevel; l <= maxLevel; l++) { - for (int z = minTileZ; z <= maxTileZ; z++) { - levelOccludemap[l][tileX][z] &= ~wall0; - } - } - } - } - } - /** * Flattens the perimeter of the provided area. * @param tileX the area x. @@ -933,18 +935,21 @@ public class SceneBuilder { } } - public void addLoc(Scene scene, SceneCollisionMap collision, int locID, int kind, int rotation, int level, int x, int z) { + public void addLoc(Scene scene, CollisionMap collision, int locID, int kind, int rotation, int level, int x, int z) { if (lowmem && ((levelTileFlags[0][x][z] & 0x2) == 0) && (((levelTileFlags[level][x][z] & 0x10) != 0) || (getDrawLevel(level, x, z) != SceneBuilder.level))) { return; } + if (level < minLevel) { minLevel = level; } + int heightmapSW = levelHeightmap[level][x][z]; int heightmapSE = levelHeightmap[level][x + 1][z]; int heightmapNE = levelHeightmap[level][x + 1][z + 1]; int heightmapNW = levelHeightmap[level][x][z + 1]; int heightmapAverage = (heightmapSW + heightmapSE + heightmapNE + heightmapNW) >> 2; + LocType type = LocType.get(locID); int bitset = x + (z << 7) + (locID << 14) + 0x40000000; @@ -955,241 +960,21 @@ public class SceneBuilder { byte info = (byte) ((rotation << 6) + kind); if (kind == 22) { - if (!lowmem || type.interactable || type.important) { - Entity entity; - - if ((type.seqID == -1) && (type.overrideTypeIDs == null)) { - entity = type.getModel(22, rotation, heightmapSW, heightmapSE, heightmapNE, heightmapNW, -1); - } else { - entity = new LocEntity(locID, rotation, 22, heightmapSE, heightmapNE, heightmapSW, heightmapNW, type.seqID, true); - } - - scene.addGroundDecoration(entity, level, x, z, heightmapAverage, bitset, info); - - if (type.solid && type.interactable && (collision != null)) { - collision.addSolid(z, x); - } - } + addGroundDecoration(scene, collision, locID, rotation, level, x, z, heightmapSW, heightmapSE, heightmapNE, heightmapNW, heightmapAverage, type, bitset, info); } else if ((kind == 10) || (kind == 11)) { - Entity entity; - - if ((type.seqID == -1) && (type.overrideTypeIDs == null)) { - entity = type.getModel(10, rotation, heightmapSW, heightmapSE, heightmapNE, heightmapNW, -1); - } else { - entity = new LocEntity(locID, rotation, 10, heightmapSE, heightmapNE, heightmapSW, heightmapNW, type.seqID, true); - } - - if (entity != null) { - int yaw = 0; - - if (kind == 11) { - yaw += 256; - } - - int width; - int height; - - if ((rotation == 1) || (rotation == 3)) { - width = type.sizeZ; - height = type.sizeX; - } else { - width = type.sizeX; - height = type.sizeZ; - } - - if (scene.push(entity, level, x, z, heightmapAverage, width, height, yaw, bitset, info) && type.castShadow) { - Model model; - - if (entity instanceof Model) { - model = (Model) entity; - } else { - model = type.getModel(10, rotation, heightmapSW, heightmapSE, heightmapNE, heightmapNW, -1); - } - - if (model != null) { - for (int dx = 0; dx <= width; dx++) { - for (int dz = 0; dz <= height; dz++) { - int shade = model.radius / 4; - - if (shade > 30) { - shade = 30; - } - - if (shade > levelShademap[level][x + dx][z + dz]) { - levelShademap[level][x + dx][z + dz] = (byte) shade; - } - } - } - } - } - } - - if (type.solid && (collision != null)) { - collision.add(type.blocksProjectiles, type.sizeX, type.sizeZ, x, z, rotation); - } + addLoc(scene, collision, locID, kind, rotation, level, x, z, heightmapSW, heightmapSE, heightmapNE, heightmapNW, heightmapAverage, type, bitset, info); } else if (kind >= 12) { - Entity entity; - - if ((type.seqID == -1) && (type.overrideTypeIDs == null)) { - entity = type.getModel(kind, rotation, heightmapSW, heightmapSE, heightmapNE, heightmapNW, -1); - } else { - entity = new LocEntity(locID, rotation, kind, heightmapSE, heightmapNE, heightmapSW, heightmapNW, type.seqID, true); - } - - scene.push(entity, level, x, z, heightmapAverage, 1, 1, 0, bitset, info); - - if ((kind >= 12) && (kind <= 17) && (kind != 13) && (level > 0)) { - levelOccludemap[level][x][z] |= 0b100_100_100_100; - } - - if (type.solid && (collision != null)) { - collision.add(type.blocksProjectiles, type.sizeX, type.sizeZ, x, z, rotation); - } + addRoof(scene, collision, locID, kind, rotation, level, x, z, heightmapSW, heightmapSE, heightmapNE, heightmapNW, heightmapAverage, type, bitset, info); } else if (kind == 0) { - Entity entity; - - if ((type.seqID == -1) && (type.overrideTypeIDs == null)) { - entity = type.getModel(0, rotation, heightmapSW, heightmapSE, heightmapNE, heightmapNW, -1); - } else { - entity = new LocEntity(locID, rotation, 0, heightmapSE, heightmapNE, heightmapSW, heightmapNW, type.seqID, true); - } - - scene.setWall(Scene.ROTATION_WALL_TYPE[rotation], entity, 0, null, level, x, z, heightmapAverage, bitset, info); - - if (rotation == 0) { - if (type.castShadow) { - levelShademap[level][x][z] = (byte) 50; - levelShademap[level][x][z + 1] = (byte) 50; - } - if (type.occludes) { - levelOccludemap[level][x][z] |= 0b001_001_001_001; - } - } else if (rotation == 1) { - if (type.castShadow) { - levelShademap[level][x][z + 1] = (byte) 50; - levelShademap[level][x + 1][z + 1] = (byte) 50; - } - if (type.occludes) { - levelOccludemap[level][x][z + 1] |= 0b010_010_010_010; - } - } else if (rotation == 2) { - if (type.castShadow) { - levelShademap[level][x + 1][z] = (byte) 50; - levelShademap[level][x + 1][z + 1] = (byte) 50; - } - if (type.occludes) { - levelOccludemap[level][x + 1][z] |= 0b001_001_001_001; - } - } else if (rotation == 3) { - if (type.castShadow) { - levelShademap[level][x][z] = (byte) 50; - levelShademap[level][x + 1][z] = (byte) 50; - } - if (type.occludes) { - levelOccludemap[level][x][z] |= 0b010_010_010_010; - } - } - - if (type.solid && (collision != null)) { - collision.addWall(z, rotation, x, kind, type.blocksProjectiles); - } - - if (type.decorationPadding != 16) { - scene.setWallDecorationOffset(level, x, z, type.decorationPadding); - } + addWall(scene, collision, locID, kind, rotation, level, x, z, heightmapSW, heightmapSE, heightmapNE, heightmapNW, heightmapAverage, type, bitset, info); } else if (kind == 1) { - Entity entity; - - if ((type.seqID == -1) && (type.overrideTypeIDs == null)) { - entity = type.getModel(1, rotation, heightmapSW, heightmapSE, heightmapNE, heightmapNW, -1); - } else { - entity = new LocEntity(locID, rotation, 1, heightmapSE, heightmapNE, heightmapSW, heightmapNW, type.seqID, true); - } - - scene.setWall(Scene.ROTATION_WALL_CORNER_TYPE[rotation], entity, 0, null, level, x, z, heightmapAverage, bitset, info); - - if (type.castShadow) { - if (rotation == 0) { - levelShademap[level][x][z + 1] = (byte) 50; - } else if (rotation == 1) { - levelShademap[level][x + 1][z + 1] = (byte) 50; - } else if (rotation == 2) { - levelShademap[level][x + 1][z] = (byte) 50; - } else if (rotation == 3) { - levelShademap[level][x][z] = (byte) 50; - } - } - - if (type.solid && (collision != null)) { - collision.addWall(z, rotation, x, kind, type.blocksProjectiles); - } + addDiagonalWallCorner(scene, collision, locID, kind, rotation, level, x, z, heightmapSW, heightmapSE, heightmapNE, heightmapNW, heightmapAverage, type, bitset, info); } else if (kind == 2) { - int nextRotation = (rotation + 1) & 0x3; - Entity entityA; - Entity entityB; - if ((type.seqID == -1) && (type.overrideTypeIDs == null)) { - entityA = type.getModel(2, 4 + rotation, heightmapSW, heightmapSE, heightmapNE, heightmapNW, -1); - entityB = type.getModel(2, nextRotation, heightmapSW, heightmapSE, heightmapNE, heightmapNW, -1); - } else { - entityA = new LocEntity(locID, 4 + rotation, 2, heightmapSE, heightmapNE, heightmapSW, heightmapNW, type.seqID, true); - entityB = new LocEntity(locID, nextRotation, 2, heightmapSE, heightmapNE, heightmapSW, heightmapNW, type.seqID, true); - } - scene.setWall(Scene.ROTATION_WALL_TYPE[rotation], entityA, Scene.ROTATION_WALL_TYPE[nextRotation], entityB, level, x, z, heightmapAverage, bitset, info); - - if (type.occludes) { - if (rotation == 0) { - levelOccludemap[level][x][z] |= 0b001_001_001_001; - levelOccludemap[level][x][z + 1] |= 0b010_010_010_010; - } else if (rotation == 1) { - levelOccludemap[level][x][z + 1] |= 0b010_010_010_010; - levelOccludemap[level][x + 1][z] |= 0b001_001_001_001; - } else if (rotation == 2) { - levelOccludemap[level][x + 1][z] |= 0b001_001_001_001; - levelOccludemap[level][x][z] |= 0b010_010_010_010; - } else if (rotation == 3) { - levelOccludemap[level][x][z] |= 0b010_010_010_010; - levelOccludemap[level][x][z] |= 0b001_001_001_001; - } - } - if (type.solid && (collision != null)) { - collision.addWall(z, rotation, x, kind, type.blocksProjectiles); - } - if (type.decorationPadding != 16) { - scene.setWallDecorationOffset(level, x, z, type.decorationPadding); - } + addFullWall(scene, collision, locID, kind, rotation, level, x, z, heightmapSW, heightmapSE, heightmapNE, heightmapNW, heightmapAverage, type, bitset, info); } else if (kind == 3) { - Entity entity; - if ((type.seqID == -1) && (type.overrideTypeIDs == null)) { - entity = type.getModel(3, rotation, heightmapSW, heightmapSE, heightmapNE, heightmapNW, -1); - } else { - entity = new LocEntity(locID, rotation, 3, heightmapSE, heightmapNE, heightmapSW, heightmapNW, type.seqID, true); - } - scene.setWall(Scene.ROTATION_WALL_CORNER_TYPE[rotation], entity, 0, null, level, x, z, heightmapAverage, bitset, info); - if (type.castShadow) { - if (rotation == 0) { - levelShademap[level][x][z + 1] = (byte) 50; - } else if (rotation == 1) { - levelShademap[level][x + 1][z + 1] = (byte) 50; - } else if (rotation == 2) { - levelShademap[level][x + 1][z] = (byte) 50; - } else if (rotation == 3) { - levelShademap[level][x][z] = (byte) 50; - } - } - if (type.solid && (collision != null)) { - collision.addWall(z, rotation, x, kind, type.blocksProjectiles); - } + addWallCorner(scene, collision, locID, kind, rotation, level, x, z, heightmapSW, heightmapSE, heightmapNE, heightmapNW, heightmapAverage, type, bitset, info); } else if (kind == 9) { - Entity entity; - if ((type.seqID == -1) && (type.overrideTypeIDs == null)) { - entity = type.getModel(kind, rotation, heightmapSW, heightmapSE, heightmapNE, heightmapNW, -1); - } else { - entity = new LocEntity(locID, rotation, kind, heightmapSE, heightmapNE, heightmapSW, heightmapNW, type.seqID, true); - } - scene.push(entity, level, x, z, heightmapAverage, 1, 1, 0, bitset, info); - if (type.solid && (collision != null)) { - collision.add(type.blocksProjectiles, type.sizeX, type.sizeZ, x, z, rotation); - } + addDiagonalWall(scene, collision, locID, kind, rotation, level, x, z, heightmapSW, heightmapSE, heightmapNE, heightmapNW, heightmapAverage, type, bitset, info); } else { if (type.adjustToTerrain) { if (rotation == 1) { @@ -1228,14 +1013,276 @@ public class SceneBuilder { } } - private static void addDiagonalWallDecorationBoth(int z, Scene scene, int level, int x, int locID, int rotation, int heightmapSW, int heightmapSE, int heightmapNE, int heightmapNW, int heightmapAverage, LocType type, int bitset, byte info) { + private static void addGroundDecoration(Scene scene, CollisionMap collision, int locID, int rotation, int level, int x, int z, int heightmapSW, int heightmapSE, int heightmapNE, int heightmapNW, int heightmapAverage, LocType type, int bitset, byte info) { + if (!lowmem || type.interactable || type.important) { + Entity entity; + + if ((type.seqID == -1) && (type.overrideTypeIDs == null)) { + entity = type.getModel(22, rotation, heightmapSW, heightmapSE, heightmapNE, heightmapNW, -1); + } else { + entity = new LocEntity(locID, rotation, 22, heightmapSE, heightmapNE, heightmapSW, heightmapNW, type.seqID, true); + } + + scene.addGroundDecoration(entity, level, x, z, heightmapAverage, bitset, info); + + if (type.solid && type.interactable && (collision != null)) { + collision.addSolid(x, z); + } + } + } + + private void addLoc(Scene scene, CollisionMap collision, int locID, int kind, int rotation, int level, int x, int z, int heightmapSW, int heightmapSE, int heightmapNE, int heightmapNW, int heightmapAverage, LocType type, int bitset, byte info) { + Entity entity; + + if ((type.seqID == -1) && (type.overrideTypeIDs == null)) { + entity = type.getModel(10, rotation, heightmapSW, heightmapSE, heightmapNE, heightmapNW, -1); + } else { + entity = new LocEntity(locID, rotation, 10, heightmapSE, heightmapNE, heightmapSW, heightmapNW, type.seqID, true); + } + + if (entity != null) { + int yaw = 0; + + if (kind == 11) { + yaw += 256; + } + + int width; + int height; + + if ((rotation == 1) || (rotation == 3)) { + width = type.sizeZ; + height = type.sizeX; + } else { + width = type.sizeX; + height = type.sizeZ; + } + + if (scene.add(entity, level, x, z, heightmapAverage, width, height, yaw, bitset, info) && type.castShadow) { + Model model; + + if (entity instanceof Model) { + model = (Model) entity; + } else { + model = type.getModel(10, rotation, heightmapSW, heightmapSE, heightmapNE, heightmapNW, -1); + } + + if (model != null) { + for (int dx = 0; dx <= width; dx++) { + for (int dz = 0; dz <= height; dz++) { + int shade = model.radius / 4; + + if (shade > 30) { + shade = 30; + } + + if (shade > levelShademap[level][x + dx][z + dz]) { + levelShademap[level][x + dx][z + dz] = (byte) shade; + } + } + } + } + } + } + + if (type.solid && (collision != null)) { + collision.add(type.blocksProjectiles, type.sizeX, type.sizeZ, x, z, rotation); + } + } + + private void addRoof(Scene scene, CollisionMap collision, int locID, int kind, int rotation, int level, int x, int z, int heightmapSW, int heightmapSE, int heightmapNE, int heightmapNW, int heightmapAverage, LocType type, int bitset, byte info) { + Entity entity; + + if ((type.seqID == -1) && (type.overrideTypeIDs == null)) { + entity = type.getModel(kind, rotation, heightmapSW, heightmapSE, heightmapNE, heightmapNW, -1); + } else { + entity = new LocEntity(locID, rotation, kind, heightmapSE, heightmapNE, heightmapSW, heightmapNW, type.seqID, true); + } + + scene.add(entity, level, x, z, heightmapAverage, 1, 1, 0, bitset, info); + + if ((kind >= 12) && (kind <= 17) && (kind != 13) && (level > 0)) { + levelOccludemap[level][x][z] |= 0b100_100_100_100; + } + + if (type.solid && (collision != null)) { + collision.add(type.blocksProjectiles, type.sizeX, type.sizeZ, x, z, rotation); + } + } + + private void addWall(Scene scene, CollisionMap collision, int locID, int kind, int rotation, int level, int x, int z, int heightmapSW, int heightmapSE, int heightmapNE, int heightmapNW, int heightmapAverage, LocType type, int bitset, byte info) { + Entity entity; + + if ((type.seqID == -1) && (type.overrideTypeIDs == null)) { + entity = type.getModel(0, rotation, heightmapSW, heightmapSE, heightmapNE, heightmapNW, -1); + } else { + entity = new LocEntity(locID, rotation, 0, heightmapSE, heightmapNE, heightmapSW, heightmapNW, type.seqID, true); + } + + scene.setWall(Scene.ROTATION_WALL_TYPE[rotation], entity, 0, null, level, x, z, heightmapAverage, bitset, info); + + if (rotation == 0) { + if (type.castShadow) { + levelShademap[level][x][z] = (byte) 50; + levelShademap[level][x][z + 1] = (byte) 50; + } + if (type.occludes) { + levelOccludemap[level][x][z] |= 0b001_001_001_001; + } + } else if (rotation == 1) { + if (type.castShadow) { + levelShademap[level][x][z + 1] = (byte) 50; + levelShademap[level][x + 1][z + 1] = (byte) 50; + } + if (type.occludes) { + levelOccludemap[level][x][z + 1] |= 0b010_010_010_010; + } + } else if (rotation == 2) { + if (type.castShadow) { + levelShademap[level][x + 1][z] = (byte) 50; + levelShademap[level][x + 1][z + 1] = (byte) 50; + } + if (type.occludes) { + levelOccludemap[level][x + 1][z] |= 0b001_001_001_001; + } + } else if (rotation == 3) { + if (type.castShadow) { + levelShademap[level][x][z] = (byte) 50; + levelShademap[level][x + 1][z] = (byte) 50; + } + if (type.occludes) { + levelOccludemap[level][x][z] |= 0b010_010_010_010; + } + } + + if (type.solid && (collision != null)) { + collision.addWall(x, z, kind, rotation, type.blocksProjectiles); + } + + if (type.decorationPadding != 16) { + scene.setWallDecorationOffset(level, x, z, type.decorationPadding); + } + } + + private void addDiagonalWallCorner(Scene scene, CollisionMap collision, int locID, int kind, int rotation, int level, int x, int z, int heightmapSW, int heightmapSE, int heightmapNE, int heightmapNW, int heightmapAverage, LocType type, int bitset, byte info) { + Entity entity; + + if ((type.seqID == -1) && (type.overrideTypeIDs == null)) { + entity = type.getModel(1, rotation, heightmapSW, heightmapSE, heightmapNE, heightmapNW, -1); + } else { + entity = new LocEntity(locID, rotation, 1, heightmapSE, heightmapNE, heightmapSW, heightmapNW, type.seqID, true); + } + + scene.setWall(Scene.ROTATION_WALL_CORNER_TYPE[rotation], entity, 0, null, level, x, z, heightmapAverage, bitset, info); + + if (type.castShadow) { + if (rotation == 0) { + levelShademap[level][x][z + 1] = (byte) 50; + } else if (rotation == 1) { + levelShademap[level][x + 1][z + 1] = (byte) 50; + } else if (rotation == 2) { + levelShademap[level][x + 1][z] = (byte) 50; + } else if (rotation == 3) { + levelShademap[level][x][z] = (byte) 50; + } + } + + if (type.solid && (collision != null)) { + collision.addWall(x, z, kind, rotation, type.blocksProjectiles); + } + } + + private void addFullWall(Scene scene, CollisionMap collision, int locID, int kind, int rotation, int level, int x, int z, int heightmapSW, int heightmapSE, int heightmapNE, int heightmapNW, int heightmapAverage, LocType type, int bitset, byte info) { + int nextRotation = (rotation + 1) & 0x3; + Entity entityA; + Entity entityB; + + if ((type.seqID == -1) && (type.overrideTypeIDs == null)) { + entityA = type.getModel(2, 4 + rotation, heightmapSW, heightmapSE, heightmapNE, heightmapNW, -1); + entityB = type.getModel(2, nextRotation, heightmapSW, heightmapSE, heightmapNE, heightmapNW, -1); + } else { + entityA = new LocEntity(locID, 4 + rotation, 2, heightmapSE, heightmapNE, heightmapSW, heightmapNW, type.seqID, true); + entityB = new LocEntity(locID, nextRotation, 2, heightmapSE, heightmapNE, heightmapSW, heightmapNW, type.seqID, true); + } + + scene.setWall(Scene.ROTATION_WALL_TYPE[rotation], entityA, Scene.ROTATION_WALL_TYPE[nextRotation], entityB, level, x, z, heightmapAverage, bitset, info); + + if (type.occludes) { + if (rotation == 0) { + levelOccludemap[level][x][z] |= 0b001_001_001_001; + levelOccludemap[level][x][z + 1] |= 0b010_010_010_010; + } else if (rotation == 1) { + levelOccludemap[level][x][z + 1] |= 0b010_010_010_010; + levelOccludemap[level][x + 1][z] |= 0b001_001_001_001; + } else if (rotation == 2) { + levelOccludemap[level][x + 1][z] |= 0b001_001_001_001; + levelOccludemap[level][x][z] |= 0b010_010_010_010; + } else if (rotation == 3) { + levelOccludemap[level][x][z] |= 0b010_010_010_010; + levelOccludemap[level][x][z] |= 0b001_001_001_001; + } + } + + if (type.solid && (collision != null)) { + collision.addWall(x, z, kind, rotation, type.blocksProjectiles); + } + + if (type.decorationPadding != 16) { + scene.setWallDecorationOffset(level, x, z, type.decorationPadding); + } + } + + private void addWallCorner(Scene scene, CollisionMap collision, int locID, int kind, int rotation, int level, int x, int z, int heightmapSW, int heightmapSE, int heightmapNE, int heightmapNW, int heightmapAverage, LocType type, int bitset, byte info) { + Entity entity; + + if ((type.seqID == -1) && (type.overrideTypeIDs == null)) { + entity = type.getModel(3, rotation, heightmapSW, heightmapSE, heightmapNE, heightmapNW, -1); + } else { + entity = new LocEntity(locID, rotation, 3, heightmapSE, heightmapNE, heightmapSW, heightmapNW, type.seqID, true); + } + + scene.setWall(Scene.ROTATION_WALL_CORNER_TYPE[rotation], entity, 0, null, level, x, z, heightmapAverage, bitset, info); + + if (type.castShadow) { + if (rotation == 0) { + levelShademap[level][x][z + 1] = (byte) 50; + } else if (rotation == 1) { + levelShademap[level][x + 1][z + 1] = (byte) 50; + } else if (rotation == 2) { + levelShademap[level][x + 1][z] = (byte) 50; + } else if (rotation == 3) { + levelShademap[level][x][z] = (byte) 50; + } + } + + if (type.solid && (collision != null)) { + collision.addWall(x, z, kind, rotation, type.blocksProjectiles); + } + } + + private static void addDiagonalWall(Scene scene, CollisionMap collision, int locID, int kind, int rotation, int level, int x, int z, int heightmapSW, int heightmapSE, int heightmapNE, int heightmapNW, int heightmapAverage, LocType type, int bitset, byte info) { + Entity entity; + + if ((type.seqID == -1) && (type.overrideTypeIDs == null)) { + entity = type.getModel(kind, rotation, heightmapSW, heightmapSE, heightmapNE, heightmapNW, -1); + } else { + entity = new LocEntity(locID, rotation, kind, heightmapSE, heightmapNE, heightmapSW, heightmapNW, type.seqID, true); + } + scene.add(entity, level, x, z, heightmapAverage, 1, 1, 0, bitset, info); + + if (type.solid && (collision != null)) { + collision.add(type.blocksProjectiles, type.sizeX, type.sizeZ, x, z, rotation); + } + } + + private static void addDiagonalWallDecorationInside(int z, Scene scene, int level, int x, int locID, int rotation, int heightmapSW, int heightmapSE, int heightmapNE, int heightmapNW, int heightmapAverage, LocType type, int bitset, byte info) { Entity entity; if ((type.seqID == -1) && (type.overrideTypeIDs == null)) { entity = type.getModel(4, 0, heightmapSW, heightmapSE, heightmapNE, heightmapNW, -1); } else { entity = new LocEntity(locID, 0, 4, heightmapSE, heightmapNE, heightmapSW, heightmapNW, type.seqID, true); } - scene.setWallDecoration(0x300, entity, level, x, z, heightmapAverage, rotation, 0, 0, bitset, info); + scene.setWallDecoration(0x100, entity, level, x, z, heightmapAverage, rotation, 0, 0, bitset, info); } private static void addDiagonalWallDecorationOutside(int z, Scene scene, int level, int x, int locID, int rotation, int heightmapSW, int heightmapSE, int heightmapNE, int heightmapNW, int heightmapAverage, LocType type, int bitset, byte info) { @@ -1248,14 +1295,14 @@ public class SceneBuilder { scene.setWallDecoration(0x200, entity, level, x, z, heightmapAverage, rotation, 0, 0, bitset, info); } - private static void addDiagonalWallDecorationInside(int z, Scene scene, int level, int x, int locID, int rotation, int heightmapSW, int heightmapSE, int heightmapNE, int heightmapNW, int heightmapAverage, LocType type, int bitset, byte info) { + private static void addDiagonalWallDecorationBoth(int z, Scene scene, int level, int x, int locID, int rotation, int heightmapSW, int heightmapSE, int heightmapNE, int heightmapNW, int heightmapAverage, LocType type, int bitset, byte info) { Entity entity; if ((type.seqID == -1) && (type.overrideTypeIDs == null)) { entity = type.getModel(4, 0, heightmapSW, heightmapSE, heightmapNE, heightmapNW, -1); } else { entity = new LocEntity(locID, 0, 4, heightmapSE, heightmapNE, heightmapSW, heightmapNW, type.seqID, true); } - scene.setWallDecoration(0x100, entity, level, x, z, heightmapAverage, rotation, 0, 0, bitset, info); + scene.setWallDecoration(0x300, entity, level, x, z, heightmapAverage, rotation, 0, 0, bitset, info); } public int decimateHSL(int hue, int saturation, int lightness) { @@ -1274,11 +1321,11 @@ public class SceneBuilder { return ((hue / 4) << 10) + ((saturation / 32) << 7) + (lightness / 2); } - public void readChunkTiles(SceneCollisionMap[] collisionMaps, byte[] data, int chunkX, int chunkZ, int mapLevel, int chunkRotation, int originX, int originZ, int level) { + public void readChunkTiles(CollisionMap[] collisionMaps, byte[] data, int chunkX, int chunkZ, int mapLevel, int chunkRotation, int originX, int originZ, int level) { for (int dx = 0; dx < 8; dx++) { for (int dz = 0; dz < 8; dz++) { if (((originX + dx) > 0) && ((originX + dx) < 103) && ((originZ + dz) > 0) && ((originZ + dz) < 103)) { - collisionMaps[level].flags[originX + dx][originZ + dz] &= ~0x1000000; + collisionMaps[level].flags[originX + dx][originZ + dz] &= ~CollisionMap.FLAG_UNINITIALIZED; } } } @@ -1296,12 +1343,12 @@ public class SceneBuilder { } } - public void readTiles(byte[] data, int offsetZ, int offsetX, int originX, int originZ, SceneCollisionMap[] collisionMaps) { + public void readTiles(byte[] data, int offsetZ, int offsetX, int originX, int originZ, CollisionMap[] collisionMaps) { for (int level = 0; level < 4; level++) { for (int x = 0; x < 64; x++) { for (int z = 0; z < 64; z++) { if (((offsetX + x) > 0) && ((offsetX + x) < 103) && ((offsetZ + z) > 0) && ((offsetZ + z) < 103)) { - collisionMaps[level].flags[offsetX + x][offsetZ + z] &= ~0x1000000; + collisionMaps[level].flags[offsetX + x][offsetZ + z] &= ~CollisionMap.FLAG_UNINITIALIZED; } } } @@ -1387,7 +1434,7 @@ public class SceneBuilder { return level; } - public void readChunkLocs(SceneCollisionMap[] collisionMaps, Scene scene, int mapLevel, int mapRotation, int mapChunkX, int mapChunkZ, int originX, int originZ, byte[] data, int level) { + public void readChunkLocs(CollisionMap[] collisionMaps, Scene scene, int mapLevel, int mapRotation, int mapChunkX, int mapChunkZ, int originX, int originZ, byte[] data, int level) { Buffer in = new Buffer(data); int locID = -1; @@ -1436,7 +1483,7 @@ public class SceneBuilder { collisionLevel--; } - SceneCollisionMap collisionMap = null; + CollisionMap collisionMap = null; if (collisionLevel >= 0) { collisionMap = collisionMaps[collisionLevel]; @@ -1473,7 +1520,7 @@ public class SceneBuilder { return (hsl & 0xff80) + scalar; } - public void readLocs(SceneCollisionMap[] collisionMaps, Scene scene, int originX, int originZ, byte[] data) { + public void readLocs(CollisionMap[] collisionMaps, Scene scene, int originX, int originZ, byte[] data) { Buffer in = new Buffer(data); int locID = -1; for (; ; ) { @@ -1510,7 +1557,7 @@ public class SceneBuilder { collisionLevel--; } - SceneCollisionMap collisionMap = null; + CollisionMap collisionMap = null; if (collisionLevel >= 0) { collisionMap = collisionMaps[collisionLevel]; diff --git a/src/main/java/SceneCollisionMap.java b/src/main/java/SceneCollisionMap.java deleted file mode 100644 index d47171b..0000000 --- a/src/main/java/SceneCollisionMap.java +++ /dev/null @@ -1,523 +0,0 @@ -// Decompiled by Jad v1.5.8f. Copyright 2001 Pavel Kouznetsov. -// Jad home page: http://www.kpdus.com/jad.html -// Decompiler options: packimports(3) - -public class SceneCollisionMap { - - public final int anInt290 = 0; - public final int anInt291 = 0; - public final int anInt292; - public final int anInt293; - public final int[][] flags; - - public SceneCollisionMap(int i, int j) { - anInt292 = i; - anInt293 = j; - flags = new int[anInt292][anInt293]; - reset(); - } - - public void reset() { - for (int i = 0; i < anInt292; i++) { - for (int j = 0; j < anInt293; j++) { - if ((i == 0) || (j == 0) || (i == (anInt292 - 1)) || (j == (anInt293 - 1))) { - flags[i][j] = 0xffffff; - } else { - flags[i][j] = 0x1000000; - } - } - } - } - - public void addWall(int i, int rotation, int k, int kind, boolean blocksProjectiles) { - if (kind == 0) { - if (rotation == 0) { - add(k, i, 128); - add(k - 1, i, 8); - } - if (rotation == 1) { - add(k, i, 2); - add(k, i + 1, 32); - } - if (rotation == 2) { - add(k, i, 8); - add(k + 1, i, 128); - } - if (rotation == 3) { - add(k, i, 32); - add(k, i - 1, 2); - } - } - if ((kind == 1) || (kind == 3)) { - if (rotation == 0) { - add(k, i, 1); - add(k - 1, i + 1, 16); - } - if (rotation == 1) { - add(k, i, 4); - add(k + 1, i + 1, 64); - } - if (rotation == 2) { - add(k, i, 16); - add(k + 1, i - 1, 1); - } - if (rotation == 3) { - add(k, i, 64); - add(k - 1, i - 1, 4); - } - } - if (kind == 2) { - if (rotation == 0) { - add(k, i, 130); - add(k - 1, i, 8); - add(k, i + 1, 32); - } - if (rotation == 1) { - add(k, i, 10); - add(k, i + 1, 32); - add(k + 1, i, 128); - } - if (rotation == 2) { - add(k, i, 40); - add(k + 1, i, 128); - add(k, i - 1, 2); - } - if (rotation == 3) { - add(k, i, 160); - add(k, i - 1, 2); - add(k - 1, i, 8); - } - } - if (blocksProjectiles) { - if (kind == 0) { - if (rotation == 0) { - add(k, i, 0x10000); - add(k - 1, i, 4096); - } - if (rotation == 1) { - add(k, i, 1024); - add(k, i + 1, 16384); - } - if (rotation == 2) { - add(k, i, 4096); - add(k + 1, i, 0x10000); - } - if (rotation == 3) { - add(k, i, 16384); - add(k, i - 1, 1024); - } - } - if ((kind == 1) || (kind == 3)) { - if (rotation == 0) { - add(k, i, 512); - add(k - 1, i + 1, 8192); - } - if (rotation == 1) { - add(k, i, 2048); - add(k + 1, i + 1, 32768); - } - if (rotation == 2) { - add(k, i, 8192); - add(k + 1, i - 1, 512); - } - if (rotation == 3) { - add(k, i, 32768); - add(k - 1, i - 1, 2048); - } - } - if (kind == 2) { - if (rotation == 0) { - add(k, i, 0x10400); - add(k - 1, i, 4096); - add(k, i + 1, 16384); - } - if (rotation == 1) { - add(k, i, 5120); - add(k, i + 1, 16384); - add(k + 1, i, 0x10000); - } - if (rotation == 2) { - add(k, i, 20480); - add(k + 1, i, 0x10000); - add(k, i - 1, 1024); - } - if (rotation == 3) { - add(k, i, 0x14000); - add(k, i - 1, 1024); - add(k - 1, i, 4096); - } - } - } - } - - public void add(boolean blocksProjectiles, int width, int length, int x, int z, int rotation) { - int flags = 256; - - if (blocksProjectiles) { - flags += 0x20000; - } - - if ((rotation == 1) || (rotation == 3)) { - int tmp = width; - width = length; - length = tmp; - } - - for (int tx = x; tx < (x + width); tx++) { - if ((tx >= 0) && (tx < anInt292)) { - for (int tz = z; tz < (z + length); tz++) { - if ((tz >= 0) && (tz < anInt293)) { - add(tx, tz, flags); - } - } - } - } - } - - public void addSolid(int z, int x) { - flags[x][z] |= 0x200000; - } - - public void add(int x, int z, int k) { - flags[x][z] |= k; - } - - public void remove(int i, int j, boolean flag, int k, int l) { - if (j == 0) { - if (i == 0) { - method217(128, k, l); - method217(8, k - 1, l); - } - if (i == 1) { - method217(2, k, l); - method217(32, k, l + 1); - } - if (i == 2) { - method217(8, k, l); - method217(128, k + 1, l); - } - if (i == 3) { - method217(32, k, l); - method217(2, k, l - 1); - } - } - if ((j == 1) || (j == 3)) { - if (i == 0) { - method217(1, k, l); - method217(16, k - 1, l + 1); - } - if (i == 1) { - method217(4, k, l); - method217(64, k + 1, l + 1); - } - if (i == 2) { - method217(16, k, l); - method217(1, k + 1, l - 1); - } - if (i == 3) { - method217(64, k, l); - method217(4, k - 1, l - 1); - } - } - if (j == 2) { - if (i == 0) { - method217(130, k, l); - method217(8, k - 1, l); - method217(32, k, l + 1); - } - if (i == 1) { - method217(10, k, l); - method217(32, k, l + 1); - method217(128, k + 1, l); - } - if (i == 2) { - method217(40, k, l); - method217(128, k + 1, l); - method217(2, k, l - 1); - } - if (i == 3) { - method217(160, k, l); - method217(2, k, l - 1); - method217(8, k - 1, l); - } - } - if (flag) { - if (j == 0) { - if (i == 0) { - method217(0x10000, k, l); - method217(4096, k - 1, l); - } - if (i == 1) { - method217(1024, k, l); - method217(16384, k, l + 1); - } - if (i == 2) { - method217(4096, k, l); - method217(0x10000, k + 1, l); - } - if (i == 3) { - method217(16384, k, l); - method217(1024, k, l - 1); - } - } - if ((j == 1) || (j == 3)) { - if (i == 0) { - method217(512, k, l); - method217(8192, k - 1, l + 1); - } - if (i == 1) { - method217(2048, k, l); - method217(32768, k + 1, l + 1); - } - if (i == 2) { - method217(8192, k, l); - method217(512, k + 1, l - 1); - } - if (i == 3) { - method217(32768, k, l); - method217(2048, k - 1, l - 1); - } - } - if (j == 2) { - if (i == 0) { - method217(0x10400, k, l); - method217(4096, k - 1, l); - method217(16384, k, l + 1); - } - if (i == 1) { - method217(5120, k, l); - method217(16384, k, l + 1); - method217(0x10000, k + 1, l); - } - if (i == 2) { - method217(20480, k, l); - method217(0x10000, k + 1, l); - method217(1024, k, l - 1); - } - if (i == 3) { - method217(0x14000, k, l); - method217(1024, k, l - 1); - method217(4096, k - 1, l); - } - } - } - } - - public void remove(int rotation, int width, int x0, int z0, int length, boolean flag) { - int flags = 256; - if (flag) { - flags += 0x20000; - } - if ((rotation == 1) || (rotation == 3)) { - int tmp = width; - width = length; - length = tmp; - } - for (int x = x0; x < (x0 + width); x++) { - if ((x >= 0) && (x < anInt292)) { - for (int z = z0; z < (z0 + length); z++) { - if ((z >= 0) && (z < anInt293)) { - method217(flags, x, z); - } - } - } - } - } - - public void method217(int flag, int x, int z) { - flags[x][z] &= 0xffffff - flag; - } - - public void method218(int j, int k) { - flags[k][j] &= 0xdfffff; - } - - public boolean method219(int sx, int sz, int dx, int dz, int locAngle, int locType) { - if ((sx == dx) && (sz == dz)) { - return true; - } - if (locType == 0) { - if (locAngle == 0) { - if ((sx == (dx - 1)) && (sz == dz)) { - return true; - } - if ((sx == dx) && (sz == (dz + 1)) && ((flags[sx][sz] & 0x1280120) == 0)) { - return true; - } - if ((sx == dx) && (sz == (dz - 1)) && ((flags[sx][sz] & 0x1280102) == 0)) { - return true; - } - } else if (locAngle == 1) { - if ((sx == dx) && (sz == (dz + 1))) { - return true; - } - if ((sx == (dx - 1)) && (sz == dz) && ((flags[sx][sz] & 0x1280108) == 0)) { - return true; - } - if ((sx == (dx + 1)) && (sz == dz) && ((flags[sx][sz] & 0x1280180) == 0)) { - return true; - } - } else if (locAngle == 2) { - if ((sx == (dx + 1)) && (sz == dz)) { - return true; - } - if ((sx == dx) && (sz == (dz + 1)) && ((flags[sx][sz] & 0x1280120) == 0)) { - return true; - } - if ((sx == dx) && (sz == (dz - 1)) && ((flags[sx][sz] & 0x1280102) == 0)) { - return true; - } - } else if (locAngle == 3) { - if ((sx == dx) && (sz == (dz - 1))) { - return true; - } - if ((sx == (dx - 1)) && (sz == dz) && ((flags[sx][sz] & 0x1280108) == 0)) { - return true; - } - if ((sx == (dx + 1)) && (sz == dz) && ((flags[sx][sz] & 0x1280180) == 0)) { - return true; - } - } - } - if (locType == 2) { - if (locAngle == 0) { - if ((sx == (dx - 1)) && (sz == dz)) { - return true; - } - if ((sx == dx) && (sz == (dz + 1))) { - return true; - } - if ((sx == (dx + 1)) && (sz == dz) && ((flags[sx][sz] & 0x1280180) == 0)) { - return true; - } - if ((sx == dx) && (sz == (dz - 1)) && ((flags[sx][sz] & 0x1280102) == 0)) { - return true; - } - } else if (locAngle == 1) { - if ((sx == (dx - 1)) && (sz == dz) && ((flags[sx][sz] & 0x1280108) == 0)) { - return true; - } - if ((sx == dx) && (sz == (dz + 1))) { - return true; - } - if ((sx == (dx + 1)) && (sz == dz)) { - return true; - } - if ((sx == dx) && (sz == (dz - 1)) && ((flags[sx][sz] & 0x1280102) == 0)) { - return true; - } - } else if (locAngle == 2) { - if ((sx == (dx - 1)) && (sz == dz) && ((flags[sx][sz] & 0x1280108) == 0)) { - return true; - } - if ((sx == dx) && (sz == (dz + 1)) && ((flags[sx][sz] & 0x1280120) == 0)) { - return true; - } - if ((sx == (dx + 1)) && (sz == dz)) { - return true; - } - if ((sx == dx) && (sz == (dz - 1))) { - return true; - } - } else if (locAngle == 3) { - if ((sx == (dx - 1)) && (sz == dz)) { - return true; - } - if ((sx == dx) && (sz == (dz + 1)) && ((flags[sx][sz] & 0x1280120) == 0)) { - return true; - } - if ((sx == (dx + 1)) && (sz == dz) && ((flags[sx][sz] & 0x1280180) == 0)) { - return true; - } - if ((sx == dx) && (sz == (dz - 1))) { - return true; - } - } - } - if (locType == 9) { - if ((sx == dx) && (sz == (dz + 1)) && ((flags[sx][sz] & 0x20) == 0)) { - return true; - } - if ((sx == dx) && (sz == (dz - 1)) && ((flags[sx][sz] & 2) == 0)) { - return true; - } - if ((sx == (dx - 1)) && (sz == dz) && ((flags[sx][sz] & 8) == 0)) { - return true; - } - return (sx == (dx + 1)) && (sz == dz) && ((flags[sx][sz] & 0x80) == 0); - } - return false; - } - - public boolean method220(int sx, int sz, int dx, int dz, int locType, int locAngle) { - if ((sx == dx) && (sz == dz)) { - return true; - } - if ((locType == 6) || (locType == 7)) { - if (locType == 7) { - locAngle = (locAngle + 2) & 3; - } - if (locAngle == 0) { - if ((sx == (dx + 1)) && (sz == dz) && ((flags[sx][sz] & 0x80) == 0)) { - return true; - } - if ((sx == dx) && (sz == (dz - 1)) && ((flags[sx][sz] & 2) == 0)) { - return true; - } - } else if (locAngle == 1) { - if ((sx == (dx - 1)) && (sz == dz) && ((flags[sx][sz] & 8) == 0)) { - return true; - } - if ((sx == dx) && (sz == (dz - 1)) && ((flags[sx][sz] & 2) == 0)) { - return true; - } - } else if (locAngle == 2) { - if ((sx == (dx - 1)) && (sz == dz) && ((flags[sx][sz] & 8) == 0)) { - return true; - } - if ((sx == dx) && (sz == (dz + 1)) && ((flags[sx][sz] & 0x20) == 0)) { - return true; - } - } else if (locAngle == 3) { - if ((sx == (dx + 1)) && (sz == dz) && ((flags[sx][sz] & 0x80) == 0)) { - return true; - } - if ((sx == dx) && (sz == (dz + 1)) && ((flags[sx][sz] & 0x20) == 0)) { - return true; - } - } - } - if (locType == 8) { - if ((sx == dx) && (sz == (dz + 1)) && ((flags[sx][sz] & 0x20) == 0)) { - return true; - } - if ((sx == dx) && (sz == (dz - 1)) && ((flags[sx][sz] & 2) == 0)) { - return true; - } - if ((sx == (dx - 1)) && (sz == dz) && ((flags[sx][sz] & 8) == 0)) { - return true; - } - return (sx == (dx + 1)) && (sz == dz) && ((flags[sx][sz] & 0x80) == 0); - } - return false; - } - - public boolean method221(int x, int z, int dx, int dz, int locWidth, int locLength, int locInteractionFlags) { - int x1 = (dx + locWidth) - 1; - int z1 = (dz + locLength) - 1; - if ((x >= dx) && (x <= x1) && (z >= dz) && (z <= z1)) { - return true; - } - if ((x == (dx - 1)) && (z >= dz) && (z <= z1) && ((this.flags[x - anInt290][z - anInt291] & 8) == 0) && ((locInteractionFlags & 8) == 0)) { - return true; - } - if ((x == (x1 + 1)) && (z >= dz) && (z <= z1) && ((this.flags[x - anInt290][z - anInt291] & 0x80) == 0) && ((locInteractionFlags & 2) == 0)) { - return true; - } - if ((z == (dz - 1)) && (x >= dx) && (x <= x1) && ((this.flags[x - anInt290][z - anInt291] & 2) == 0) && ((locInteractionFlags & 4) == 0)) { - return true; - } - return (z == (z1 + 1)) && (x >= dx) && (x <= x1) && ((this.flags[x - anInt290][z - anInt291] & 0x20) == 0) && ((locInteractionFlags & 1) == 0); - } - -} diff --git a/src/main/java/SceneOccluder.java b/src/main/java/SceneOccluder.java index 42626f6..dad8fae 100644 --- a/src/main/java/SceneOccluder.java +++ b/src/main/java/SceneOccluder.java @@ -4,6 +4,19 @@ public class SceneOccluder { + /** + * A wall occluder which runs along the X axis. + */ + public static final int TYPE_WALL_X = 1; + /** + * A wall occluder which runs along the Z axis. + */ + public static final int TYPE_WALL_Z = 2; + /** + * A ground occluder which covers the XZ plane. + */ + public static final int TYPE_GROUND = 4; + public int minTileX; public int maxTileX; public int minTileZ; diff --git a/src/main/java/SeqType.java b/src/main/java/SeqType.java index 6ebd649..fe883fb 100644 --- a/src/main/java/SeqType.java +++ b/src/main/java/SeqType.java @@ -58,7 +58,7 @@ public class SeqType { /** * Adds additional space to the render bounds. - * @see Scene#pushTemporary(Entity, int, int, int, int, int, int, boolean, int) + * @see Scene#addTemporary(Entity, int, int, int, int, int, int, boolean, int) */ public boolean forwardRenderPadding = false; @@ -131,10 +131,10 @@ public class SeqType { public void load(Buffer buffer) { do { - int op = buffer.read8U(); - if (op == 0) { + int opcode = buffer.read8U(); + if (opcode == 0) { break; - } else if (op == 1) { + } else if (opcode == 1) { frameCount = buffer.read8U(); transformIDs = new int[frameCount]; auxiliaryTransformIDs = new int[frameCount]; @@ -147,35 +147,35 @@ public class SeqType { } frameDuration[f] = buffer.read16U(); } - } else if (op == 2) { + } else if (opcode == 2) { loopFrameCount = buffer.read16U(); - } else if (op == 3) { + } else if (opcode == 3) { int count = buffer.read8U(); mask = new int[count + 1]; for (int l = 0; l < count; l++) { mask[l] = buffer.read8U(); } mask[count] = 9999999; - } else if (op == 4) { + } else if (opcode == 4) { forwardRenderPadding = true; - } else if (op == 5) { + } else if (opcode == 5) { priority = buffer.read8U(); - } else if (op == 6) { + } else if (opcode == 6) { rightHandOverride = buffer.read16U(); - } else if (op == 7) { + } else if (opcode == 7) { leftHandOverride = buffer.read16U(); - } else if (op == 8) { + } else if (opcode == 8) { loopCount = buffer.read8U(); - } else if (op == 9) { + } else if (opcode == 9) { moveStyle = buffer.read8U(); - } else if (op == 10) { + } else if (opcode == 10) { idleStyle = buffer.read8U(); - } else if (op == 11) { + } else if (opcode == 11) { replayStyle = buffer.read8U(); - } else if (op == 12) { + } else if (opcode == 12) { unusedInt = buffer.read32(); } else { - System.out.println("Error unrecognised seq config code: " + op); + System.out.println("Error unrecognised seq config code: " + opcode); } } while (true); diff --git a/src/main/java/VarbitType.java b/src/main/java/VarbitType.java index 7bf13fb..fa59a66 100644 --- a/src/main/java/VarbitType.java +++ b/src/main/java/VarbitType.java @@ -49,23 +49,23 @@ public class VarbitType { public void read(Buffer buffer) { do { - int op = buffer.read8U(); - if (op == 0) { + int opcode = buffer.read8U(); + if (opcode == 0) { return; - } else if (op == 1) { + } else if (opcode == 1) { varp = buffer.read16U(); lsb = buffer.read8U(); msb = buffer.read8U(); - } else if (op == 10) { + } else if (opcode == 10) { unusedString = buffer.readString(); - } else if (op == 2) { + } else if (opcode == 2) { unusedBool = true; - } else if (op == 3) { + } else if (opcode == 3) { unusedInt0 = buffer.read32(); - } else if (op == 4) { + } else if (opcode == 4) { unusedInt1 = buffer.read32(); } else { - System.out.println("Error unrecognised config code: " + op); + System.out.println("Error unrecognised config code: " + opcode); } } while (true); } diff --git a/src/main/java/VarpType.java b/src/main/java/VarpType.java index 83b7065..a18287f 100644 --- a/src/main/java/VarpType.java +++ b/src/main/java/VarpType.java @@ -49,37 +49,37 @@ public class VarpType { public void read(Buffer buffer, int i) { do { - int op = buffer.read8U(); - if (op == 0) { + int opcode = buffer.read8U(); + if (opcode == 0) { return; - } else if (op == 1) { + } else if (opcode == 1) { unusedInt0 = buffer.read8U(); - } else if (op == 2) { + } else if (opcode == 2) { unusedInt1 = buffer.read8U(); - } else if (op == 3) { + } else if (opcode == 3) { unusedBool0 = true; anIntArray703[anInt702++] = i; - } else if (op == 4) { + } else if (opcode == 4) { unusedBool1 = false; - } else if (op == 5) { + } else if (opcode == 5) { type = buffer.read16U(); - } else if (op == 6) { + } else if (opcode == 6) { unusedBool2 = true; - } else if (op == 7) { + } else if (opcode == 7) { unusedInt2 = buffer.read32(); - } else if (op == 8) { + } else if (opcode == 8) { unusedInt3 = 1; unusedBool3 = true; - } else if (op == 10) { + } else if (opcode == 10) { unusedString = buffer.readString(); - } else if (op == 11) { + } else if (opcode == 11) { unusedBool3 = true; - } else if (op == 12) { + } else if (opcode == 12) { unusedInt4 = buffer.read32(); - } else if (op == 13) { + } else if (opcode == 13) { unusedInt3 = 2; } else { - System.out.println("Error unrecognised config code: " + op); + System.out.println("Error unrecognised config code: " + opcode); } } while (true); }