refactoring

This commit is contained in:
Denis Molony 2016-09-18 20:06:26 +10:00
parent c573e86f2b
commit f76720ef60
6 changed files with 153 additions and 68 deletions

View File

@ -127,17 +127,23 @@ class MazeLevel extends AbstractFile
for (MazeAddress address : messageList) for (MazeAddress address : messageList)
{ {
Message message = getMessage (address.row); Message message = getMessage (address.row);
text.append (String.format ("%nMessage: %04X (%d)%n", address.row, address.row)); if (message != null)
text.append (message.getText ()); {
text.append ("\n"); text.append (String.format ("%nMessage: %04X (%d)%n", address.row, address.row));
text.append (message.getText ());
text.append ("\n");
}
} }
for (MazeAddress address : monsterList) for (MazeAddress address : monsterList)
{ {
Monster monster = getMonster (address.column); Monster monster = getMonster (address.column);
text.append (String.format ("%nMonster: %04X%n", address.column)); if (monster != null)
text.append (monster.getText ()); {
text.append ("\n"); text.append (String.format ("%nMonster: %04X%n", address.column));
text.append (monster.getText ());
text.append ("\n");
}
} }
return text.toString (); return text.toString ();

View File

@ -46,16 +46,16 @@ class Monster extends AbstractFile implements Comparable<Monster>
"Animal", "Were", "Undead", "Demon", "Insect", "Enchanted" }; "Animal", "Were", "Undead", "Demon", "Insect", "Enchanted" };
private static int[] experience = private static int[] experience =
{ 55, 235, 415, 230, 380, 620, 840, 520, 550, 350, // 00-09 { 55, 235, 415, 230, 380, 620, 840, 520, 550, 350, // 00-09
475, 515, 920, 600, 735, 520, 795, 780, 990, 795, // 10-19 475, 515, 920, 600, 735, 520, 795, 780, 990, 795, // 10-19
1360, 1320, 1275, 680, 960, 600, 755, 1120, 2075, 870, // 20-29 1360, 1320, 1275, 680, 960, 600, 755, 1120, 2075, 870, // 20-29
960, 1120, 1120, 2435, 1080, 2280, 975, 875, 1135, 1200, // 30-39 960, 1120, 1120, 2435, 1080, 2280, 975, 875, 1135, 1200, // 30-39
620, 740, 1460, 1245, 960, 1405, 1040, 1220, 1520, 1000, // 40-49 620, 740, 1460, 1245, 960, 1405, 1040, 1220, 1520, 1000, // 40-49
960, 2340, 2160, 2395, 790, 1140, 1235, 1790, 1720, 2240, // 50-59 960, 2340, 2160, 2395, 790, 1140, 1235, 1790, 1720, 2240, // 50-59
1475, 1540, 1720, 1900, 1240, 1220, 1020, 20435, 5100, 3515, // 60-69 1475, 1540, 1720, 1900, 1240, 1220, 1020, 20435, 5100, 3515, // 60-69
2115, 2920, 2060, 2140, 1400, 1640, 1280, 4450, 42840, 3300, // 70-79 2115, 2920, 2060, 2140, 1400, 1640, 1280, 4450, 42840, 3300, // 70-79
40875, 5000, 3300, 2395, 1935, 1600, 3330, 44090, 40840, 5200, // 80-89 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 4155, 3000, 9200, 3160, 7460, 7320, 15880, 1600, 2200, 1000, 1900 // 90-100
}; };
public Monster (String name, byte[] buffer, List<Reward> rewards, public Monster (String name, byte[] buffer, List<Reward> rewards,

View File

@ -5,7 +5,7 @@ import java.awt.image.DataBuffer;
public class Wiz4Image extends AbstractImage 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); super (name, buffer);
@ -18,7 +18,7 @@ public class Wiz4Image extends AbstractImage
for (int line = 0; line < 8; line++) for (int line = 0; line < 8; line++)
for (int col = 0; col < cols; col++) 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++) for (int bit = 0; bit < 7; bit++)
{ {
if ((b & 0x01) == 0x01) if ((b & 0x01) == 0x01)

View File

@ -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<Wiz4Image> images = new ArrayList<Wiz4Image> ();
final List<Integer> blocks = new ArrayList<Integer> ();
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 ();
}
}

View File

@ -9,20 +9,40 @@ import com.bytezone.diskbrowser.utilities.HexFormatter;
public class Wiz5Monsters extends AbstractFile public class Wiz5Monsters extends AbstractFile
{ {
List<Wiz4Image> images = new ArrayList<Wiz4Image> (); List<Monster> monsters = new ArrayList<Monster> ();
public Wiz5Monsters (String name, byte[] buffer) public Wiz5Monsters (String name, byte[] buffer)
{ {
super (name, 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; int val1 = buffer[ptr] & 0xFF;
byte[] data = new byte[512]; int val2 = Utility.getWord (buffer, ptr * 2 + 256);
System.arraycopy (buffer, ptr, data, 0, data.length); int offset = val1 * 512 + val2;
Wiz4Image image = new Wiz4Image ("Image " + i, data, 10, 6); // no good
images.add (image); 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 @Override
@ -30,17 +50,22 @@ public class Wiz5Monsters extends AbstractFile
{ {
StringBuilder text = new StringBuilder (); StringBuilder text = new StringBuilder ();
int ptr = 0; int count = 0;
while (buffer[ptr] != 0) for (Monster monster : monsters)
{ text.append (String.format ("%02X : %02X %04X : %s%n", ++count,
int val1 = buffer[ptr] & 0xFF; monster.offset / 512, monster.offset % 512,
int val2 = Utility.getWord (buffer, ptr * 2 + 256); HexFormatter.getHexString (buffer, monster.offset, monster.buffer.length)));
text.append (String.format ("%3d %02X %04X :", ptr, val1, val2));
String line = HexFormatter.getHexString (buffer, val1 * 512, 512); if (text.length () > 0)
text.append (line); text.deleteCharAt (text.length () - 1);
text.append ("\n");
ptr++;
}
return text.toString (); return text.toString ();
} }
class Monster
{
int offset;
Wiz4Image image;
byte[] buffer;
}
} }

View File

@ -117,7 +117,6 @@ public class Wizardry4BootDisk extends PascalDisk
fileEntry = (FileEntry) monstersNode.getUserObject (); fileEntry = (FileEntry) monstersNode.getUserObject ();
if (fileEntry != null) if (fileEntry != null)
{ {
fileEntry.setFile (null);
monstersNode.setAllowsChildren (true); monstersNode.setAllowsChildren (true);
linkMonsterImages4 (monstersNode, fileEntry); linkMonsterImages4 (monstersNode, fileEntry);
} }
@ -128,20 +127,45 @@ public class Wizardry4BootDisk extends PascalDisk
fileEntry = (FileEntry) monstersNode.getUserObject (); fileEntry = (FileEntry) monstersNode.getUserObject ();
if (fileEntry != null) if (fileEntry != null)
{ {
Wiz5Monsters w5monsters =
new Wiz5Monsters ("monsters", fileEntry.getDataSource ().buffer);
fileEntry.setFile (w5monsters);
monstersNode.setAllowsChildren (true); monstersNode.setAllowsChildren (true);
for (Wiz4Image image : w5monsters.images) linkMonsterImages5 (monstersNode, fileEntry);
{
List<DiskAddress> monsterBlocks = new ArrayList<DiskAddress> ();
// monsterBlocks.add (pictureBlocks.get (block));
addToNode (image, monstersNode, monsterBlocks);
}
} }
} }
} }
private void linkMonsterImages4 (DefaultMutableTreeNode monstersNode,
FileEntry fileEntry)
{
fileEntry.setFile (null);
List<DiskAddress> pictureBlocks = fileEntry.getSectors ();
Wiz4Monsters w4monsters =
new Wiz4Monsters ("monsters", fileEntry.getDataSource ().buffer);
fileEntry.setFile (w4monsters);
int count = 0;
for (Wiz4Image image : w4monsters.images)
{
List<DiskAddress> monsterBlocks = new ArrayList<DiskAddress> ();
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<DiskAddress> monsterBlocks = new ArrayList<DiskAddress> ();
// monsterBlocks.add (pictureBlocks.get (block));
addToNode (image, monstersNode, monsterBlocks);
}
}
private void linkMazeLevels4 (DefaultMutableTreeNode scenarioNode, FileEntry fileEntry) private void linkMazeLevels4 (DefaultMutableTreeNode scenarioNode, FileEntry fileEntry)
{ {
ScenarioData mazeData = scenarioHeader.data.get (Header.MAZE_AREA); ScenarioData mazeData = scenarioHeader.data.get (Header.MAZE_AREA);
@ -282,28 +306,6 @@ public class Wizardry4BootDisk extends PascalDisk
afs.setSectors (allOracleBlocks); afs.setSectors (allOracleBlocks);
} }
private void linkMonsterImages4 (DefaultMutableTreeNode monstersNode,
FileEntry fileEntry)
{
byte[] pictureBuffer = fileEntry.getDataSource ().buffer;
List<DiskAddress> 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<DiskAddress> monsterBlocks = new ArrayList<DiskAddress> ();
monsterBlocks.add (pictureBlocks.get (block));
addToNode (image, monstersNode, monsterBlocks);
}
}
}
private void addToNode (AbstractFile af, DefaultMutableTreeNode node, private void addToNode (AbstractFile af, DefaultMutableTreeNode node,
List<DiskAddress> blocks) List<DiskAddress> blocks)
{ {