diff --git a/src/com/bytezone/diskbrowser/wizardry/MazeLevel.java b/src/com/bytezone/diskbrowser/wizardry/MazeLevel.java index 6078d20..6ab0476 100755 --- a/src/com/bytezone/diskbrowser/wizardry/MazeLevel.java +++ b/src/com/bytezone/diskbrowser/wizardry/MazeLevel.java @@ -127,17 +127,23 @@ class MazeLevel extends AbstractFile for (MazeAddress address : messageList) { Message message = getMessage (address.row); - text.append (String.format ("%nMessage: %04X (%d)%n", address.row, address.row)); - text.append (message.getText ()); - text.append ("\n"); + if (message != null) + { + text.append (String.format ("%nMessage: %04X (%d)%n", address.row, address.row)); + text.append (message.getText ()); + text.append ("\n"); + } } for (MazeAddress address : monsterList) { Monster monster = getMonster (address.column); - text.append (String.format ("%nMonster: %04X%n", address.column)); - text.append (monster.getText ()); - text.append ("\n"); + if (monster != null) + { + text.append (String.format ("%nMonster: %04X%n", address.column)); + text.append (monster.getText ()); + text.append ("\n"); + } } return text.toString (); diff --git a/src/com/bytezone/diskbrowser/wizardry/Monster.java b/src/com/bytezone/diskbrowser/wizardry/Monster.java index 1d57f6f..53911e1 100755 --- a/src/com/bytezone/diskbrowser/wizardry/Monster.java +++ b/src/com/bytezone/diskbrowser/wizardry/Monster.java @@ -46,16 +46,16 @@ class Monster extends AbstractFile implements Comparable "Animal", "Were", "Undead", "Demon", "Insect", "Enchanted" }; private static int[] experience = - { 55, 235, 415, 230, 380, 620, 840, 520, 550, 350, // 00-09 - 475, 515, 920, 600, 735, 520, 795, 780, 990, 795, // 10-19 - 1360, 1320, 1275, 680, 960, 600, 755, 1120, 2075, 870, // 20-29 - 960, 1120, 1120, 2435, 1080, 2280, 975, 875, 1135, 1200, // 30-39 - 620, 740, 1460, 1245, 960, 1405, 1040, 1220, 1520, 1000, // 40-49 - 960, 2340, 2160, 2395, 790, 1140, 1235, 1790, 1720, 2240, // 50-59 - 1475, 1540, 1720, 1900, 1240, 1220, 1020, 20435, 5100, 3515, // 60-69 - 2115, 2920, 2060, 2140, 1400, 1640, 1280, 4450, 42840, 3300, // 70-79 - 40875, 5000, 3300, 2395, 1935, 1600, 3330, 44090, 40840, 5200, // 80-89 - 4155, 3000, 9200, 3160, 7460, 7320, 15880, 1600, 2200, 1000, 1900 // 90-100 + { 55, 235, 415, 230, 380, 620, 840, 520, 550, 350, // 00-09 + 475, 515, 920, 600, 735, 520, 795, 780, 990, 795, // 10-19 + 1360, 1320, 1275, 680, 960, 600, 755, 1120, 2075, 870, // 20-29 + 960, 1120, 1120, 2435, 1080, 2280, 975, 875, 1135, 1200, // 30-39 + 620, 740, 1460, 1245, 960, 1405, 1040, 1220, 1520, 1000, // 40-49 + 960, 2340, 2160, 2395, 790, 1140, 1235, 1790, 1720, 2240, // 50-59 + 1475, 1540, 1720, 1900, 1240, 1220, 1020, 20435, 5100, 3515, // 60-69 + 2115, 2920, 2060, 2140, 1400, 1640, 1280, 4450, 42840, 3300, // 70-79 + 40875, 5000, 3300, 2395, 1935, 1600, 3330, 44090, 40840, 5200, // 80-89 + 4155, 3000, 9200, 3160, 7460, 7320, 15880, 1600, 2200, 1000, 1900 // 90-100 }; public Monster (String name, byte[] buffer, List rewards, diff --git a/src/com/bytezone/diskbrowser/wizardry/Wiz4Image.java b/src/com/bytezone/diskbrowser/wizardry/Wiz4Image.java index 0d27116..f8d081c 100644 --- a/src/com/bytezone/diskbrowser/wizardry/Wiz4Image.java +++ b/src/com/bytezone/diskbrowser/wizardry/Wiz4Image.java @@ -5,7 +5,7 @@ import java.awt.image.DataBuffer; public class Wiz4Image extends AbstractImage { - public Wiz4Image (String name, byte[] buffer, int rows, int cols) // 5, 6 + public Wiz4Image (String name, byte[] buffer, int offset, int rows, int cols) // 5, 6 { super (name, buffer); @@ -18,7 +18,7 @@ public class Wiz4Image extends AbstractImage for (int line = 0; line < 8; line++) for (int col = 0; col < cols; col++) { - byte b = buffer[row * rowSize + col * 8 + line]; + byte b = buffer[offset + row * rowSize + col * 8 + line]; for (int bit = 0; bit < 7; bit++) { if ((b & 0x01) == 0x01) diff --git a/src/com/bytezone/diskbrowser/wizardry/Wiz4Monsters.java b/src/com/bytezone/diskbrowser/wizardry/Wiz4Monsters.java new file mode 100644 index 0000000..02ee14e --- /dev/null +++ b/src/com/bytezone/diskbrowser/wizardry/Wiz4Monsters.java @@ -0,0 +1,52 @@ +package com.bytezone.diskbrowser.wizardry; + +import java.util.ArrayList; +import java.util.List; + +import com.bytezone.diskbrowser.applefile.AbstractFile; +import com.bytezone.diskbrowser.utilities.HexFormatter; + +public class Wiz4Monsters extends AbstractFile +{ + final List images = new ArrayList (); + final List blocks = new ArrayList (); + + public Wiz4Monsters (String name, byte[] buffer) + { + super (name, buffer); + + int count = 0; + for (int block = 0; block < 24; block++) + { + int ptr = block * 512; + for (int pic = 0; pic < 2; pic++) + { + byte[] data = new byte[240]; + System.arraycopy (buffer, ptr + pic * 256, data, 0, data.length); + Wiz4Image image = new Wiz4Image ("Image " + count++, data, 0, 5, 6); + images.add (image); + blocks.add (block); + } + } + } + + @Override + public String getText () + { + StringBuilder text = new StringBuilder (); + + int count = 1; + for (int block = 0; block < 24; block++) + { + int ptr = block * 512; + for (int pic = 0; pic < 2; pic++) + { + text.append (String.format ("%3d : %s%n", count, + HexFormatter.getHexString (buffer, ptr + pic * 256, 240))); + count++; + } + } + + return text.toString (); + } +} \ No newline at end of file diff --git a/src/com/bytezone/diskbrowser/wizardry/Wiz5Monsters.java b/src/com/bytezone/diskbrowser/wizardry/Wiz5Monsters.java index 73af41d..be6508a 100644 --- a/src/com/bytezone/diskbrowser/wizardry/Wiz5Monsters.java +++ b/src/com/bytezone/diskbrowser/wizardry/Wiz5Monsters.java @@ -9,20 +9,40 @@ import com.bytezone.diskbrowser.utilities.HexFormatter; public class Wiz5Monsters extends AbstractFile { - List images = new ArrayList (); + List monsters = new ArrayList (); public Wiz5Monsters (String name, byte[] buffer) { super (name, buffer); - for (int i = 0; i < 10; i++) + int ptr = 0; + Monster monster = null; + + while (buffer[ptr] != 0) { - int ptr = buffer[i] * 512; - byte[] data = new byte[512]; - System.arraycopy (buffer, ptr, data, 0, data.length); - Wiz4Image image = new Wiz4Image ("Image " + i, data, 10, 6); // no good - images.add (image); + int val1 = buffer[ptr] & 0xFF; + int val2 = Utility.getWord (buffer, ptr * 2 + 256); + int offset = val1 * 512 + val2; + + if (monster != null) + fillMonster (offset, monster, ptr); + + monster = new Monster (); + monster.offset = offset; // don't know the length yet + monsters.add (monster); + + ptr++; } + + fillMonster (buffer.length, monster, ptr); + } + + private void fillMonster (int offset, Monster monster, int ptr) + { + int len = offset - monster.offset; + monster.buffer = new byte[len]; + System.arraycopy (buffer, monster.offset, monster.buffer, 0, len); + monster.image = new Wiz4Image ("Image " + ptr, monster.buffer, 3, 10, 6); } @Override @@ -30,17 +50,22 @@ public class Wiz5Monsters extends AbstractFile { StringBuilder text = new StringBuilder (); - int ptr = 0; - while (buffer[ptr] != 0) - { - int val1 = buffer[ptr] & 0xFF; - int val2 = Utility.getWord (buffer, ptr * 2 + 256); - text.append (String.format ("%3d %02X %04X :", ptr, val1, val2)); - String line = HexFormatter.getHexString (buffer, val1 * 512, 512); - text.append (line); - text.append ("\n"); - ptr++; - } + int count = 0; + for (Monster monster : monsters) + text.append (String.format ("%02X : %02X %04X : %s%n", ++count, + monster.offset / 512, monster.offset % 512, + HexFormatter.getHexString (buffer, monster.offset, monster.buffer.length))); + + if (text.length () > 0) + text.deleteCharAt (text.length () - 1); + return text.toString (); } + + class Monster + { + int offset; + Wiz4Image image; + byte[] buffer; + } } \ No newline at end of file diff --git a/src/com/bytezone/diskbrowser/wizardry/Wizardry4BootDisk.java b/src/com/bytezone/diskbrowser/wizardry/Wizardry4BootDisk.java index 41c42ea..c305075 100644 --- a/src/com/bytezone/diskbrowser/wizardry/Wizardry4BootDisk.java +++ b/src/com/bytezone/diskbrowser/wizardry/Wizardry4BootDisk.java @@ -117,7 +117,6 @@ public class Wizardry4BootDisk extends PascalDisk fileEntry = (FileEntry) monstersNode.getUserObject (); if (fileEntry != null) { - fileEntry.setFile (null); monstersNode.setAllowsChildren (true); linkMonsterImages4 (monstersNode, fileEntry); } @@ -128,20 +127,45 @@ public class Wizardry4BootDisk extends PascalDisk fileEntry = (FileEntry) monstersNode.getUserObject (); if (fileEntry != null) { - Wiz5Monsters w5monsters = - new Wiz5Monsters ("monsters", fileEntry.getDataSource ().buffer); - fileEntry.setFile (w5monsters); monstersNode.setAllowsChildren (true); - for (Wiz4Image image : w5monsters.images) - { - List monsterBlocks = new ArrayList (); - // monsterBlocks.add (pictureBlocks.get (block)); - addToNode (image, monstersNode, monsterBlocks); - } + linkMonsterImages5 (monstersNode, fileEntry); } } } + private void linkMonsterImages4 (DefaultMutableTreeNode monstersNode, + FileEntry fileEntry) + { + fileEntry.setFile (null); + List pictureBlocks = fileEntry.getSectors (); + + Wiz4Monsters w4monsters = + new Wiz4Monsters ("monsters", fileEntry.getDataSource ().buffer); + fileEntry.setFile (w4monsters); + int count = 0; + for (Wiz4Image image : w4monsters.images) + { + List monsterBlocks = new ArrayList (); + monsterBlocks.add (pictureBlocks.get (w4monsters.blocks.get (count++))); + addToNode (image, monstersNode, monsterBlocks); + } + } + + private void linkMonsterImages5 (DefaultMutableTreeNode monstersNode, + FileEntry fileEntry) + { + Wiz5Monsters w5monsters = + new Wiz5Monsters ("monsters", fileEntry.getDataSource ().buffer); + fileEntry.setFile (w5monsters); + for (Wiz5Monsters.Monster monster : w5monsters.monsters) + { + Wiz4Image image = monster.image; + List monsterBlocks = new ArrayList (); + // monsterBlocks.add (pictureBlocks.get (block)); + addToNode (image, monstersNode, monsterBlocks); + } + } + private void linkMazeLevels4 (DefaultMutableTreeNode scenarioNode, FileEntry fileEntry) { ScenarioData mazeData = scenarioHeader.data.get (Header.MAZE_AREA); @@ -282,28 +306,6 @@ public class Wizardry4BootDisk extends PascalDisk afs.setSectors (allOracleBlocks); } - private void linkMonsterImages4 (DefaultMutableTreeNode monstersNode, - FileEntry fileEntry) - { - byte[] pictureBuffer = fileEntry.getDataSource ().buffer; - List pictureBlocks = fileEntry.getSectors (); - - int count = 0; - for (int block = 0; block < 24; block++) - { - int ptr = block * 512; - for (int pic = 0; pic < 2; pic++) - { - byte[] buffer = new byte[240]; - System.arraycopy (pictureBuffer, ptr + pic * 256, buffer, 0, buffer.length); - Wiz4Image image = new Wiz4Image ("Image " + count++, buffer, 5, 6); - List monsterBlocks = new ArrayList (); - monsterBlocks.add (pictureBlocks.get (block)); - addToNode (image, monstersNode, monsterBlocks); - } - } - } - private void addToNode (AbstractFile af, DefaultMutableTreeNode node, List blocks) {