linking messages to maps

This commit is contained in:
Denis Molony 2016-08-24 00:14:04 +10:00
parent cca29c3bcd
commit a6cc3529de
5 changed files with 84 additions and 35 deletions

View File

@ -8,21 +8,25 @@ import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;
import com.bytezone.common.Utility;
import com.bytezone.diskbrowser.applefile.AbstractFile;
import com.bytezone.diskbrowser.utilities.HexFormatter;
public class MazeGridV5 extends AbstractFile
{
private final MessageBlock messageBlock;
List<MazeGrid> grids = new ArrayList<MazeGrid> ();
int minX = 9999;
int minY = 9999;
int maxX = 0;
int maxY = 0;
public MazeGridV5 (String name, byte[] buffer)
public MazeGridV5 (String name, byte[] buffer, MessageBlock messageBlock)
{
super (name, buffer);
this.messageBlock = messageBlock;
for (int i = 0; i < 16; i++)
{
MazeCell[][] grid = new MazeCell[8][8];
@ -123,6 +127,28 @@ public class MazeGridV5 extends AbstractFile
return cell;
}
@Override
public String getHexDump ()
{
StringBuilder text = new StringBuilder (super.getHexDump ());
text.append ("\n\n");
text.append (HexFormatter.format (buffer, 0x550, 0x80));
text.append ("\n\n");
for (int i = 0; i < 128; i += 2)
{
int msg = Utility.getWord (buffer, 0x550 + i);
if (msg >= 15000)
{
String message = messageBlock.getMessageText (msg);
text.append (String.format ("%4d %04X %s%n", i, msg, message));
}
}
return text.toString ();
}
private class MazeGrid
{
MazeCell[][] grid;

View File

@ -26,7 +26,6 @@ class MazeLevel extends AbstractFile
@Override
public String getHexDump ()
{
// StringBuilder text = new StringBuilder (super.getHexDump ());
StringBuilder text = new StringBuilder ();
text.append ("West walls/doors\n\n");

View File

@ -36,6 +36,17 @@ public class MessageBlock extends AbstractFile implements Iterable<MessageDataBl
}
}
public String getMessageText (int messageNo)
{
for (int i = 0; i < messageDataBlocks.size (); i++)
{
MessageDataBlock messageDataBlock = messageDataBlocks.get (i);
if (messageDataBlock.firstMessageNo > messageNo)
return messageDataBlocks.get (i - 1).getText (messageNo);
}
return null;
}
public byte[] getMessage (int messageNo)
{
for (int i = 0; i < messageDataBlocks.size (); i++)

View File

@ -80,6 +80,18 @@ public class MessageDataBlock extends AbstractFile
return null;
}
String getText (int messageNo)
{
for (Message message : messages)
if (message.msgNo == messageNo)
{
byte[] returnMessage = new byte[message.length];
System.arraycopy (buffer, message.offset, returnMessage, 0, message.length);
return huffman.decodeMessage (returnMessage);
}
return "*** not found ***";
}
@Override
public String getText ()
{

View File

@ -54,6 +54,35 @@ public class Wizardry4BootDisk extends PascalDisk
fileEntry.getDataSource ();
}
DefaultMutableTreeNode huffNode = findNode (currentRoot, "ASCII.HUFF");
fileEntry = (FileEntry) huffNode.getUserObject ();
if (fileEntry != null)
{
byte[] buffer = fileEntry.getDataSource ().buffer;
huffman = new Huffman ("Huffman tree", buffer);
fileEntry.setFile (huffman);
}
DefaultMutableTreeNode messagesNode = findNode (currentRoot, "ASCII.KRN");
fileEntry = (FileEntry) messagesNode.getUserObject ();
if (fileEntry != null)
{
messageBlock = new MessageBlock (fileEntry.getDataSource ().buffer, huffman);
fileEntry.setFile (messageBlock);
messagesNode.setAllowsChildren (true);
List<DiskAddress> blocks = fileEntry.getSectors ();
int count = 0;
for (MessageDataBlock mdb : messageBlock)
{
List<DiskAddress> messageBlocks = new ArrayList<DiskAddress> ();
messageBlocks.add (blocks.get (count++));
addToNode (mdb, messagesNode, messageBlocks);
}
}
if (version == 4)
{
DefaultMutableTreeNode scenarioNode = findNode (currentRoot, "SCENARIO.DATA");
@ -107,35 +136,6 @@ public class Wizardry4BootDisk extends PascalDisk
}
}
}
DefaultMutableTreeNode huffNode = findNode (currentRoot, "ASCII.HUFF");
fileEntry = (FileEntry) huffNode.getUserObject ();
if (fileEntry != null)
{
byte[] buffer = fileEntry.getDataSource ().buffer;
huffman = new Huffman ("Huffman tree", buffer);
fileEntry.setFile (huffman);
}
DefaultMutableTreeNode messagesNode = findNode (currentRoot, "ASCII.KRN");
fileEntry = (FileEntry) messagesNode.getUserObject ();
if (fileEntry != null)
{
messageBlock = new MessageBlock (fileEntry.getDataSource ().buffer, huffman);
fileEntry.setFile (messageBlock);
messagesNode.setAllowsChildren (true);
List<DiskAddress> blocks = fileEntry.getSectors ();
int count = 0;
for (MessageDataBlock mdb : messageBlock)
{
List<DiskAddress> messageBlocks = new ArrayList<DiskAddress> ();
messageBlocks.add (blocks.get (count++));
addToNode (mdb, messagesNode, messageBlocks);
}
}
}
private void linkMazeLevels4 (DefaultMutableTreeNode scenarioNode, FileEntry fileEntry)
@ -170,10 +170,11 @@ public class Wizardry4BootDisk extends PascalDisk
int base = 0x1800;
for (int i = 0; i < 8; i++)
{
int offset = base + i * 1024;
byte[] data = new byte[1024];
System.arraycopy (buffer, offset, data, 0, data.length);
MazeGridV5 grid = new MazeGridV5 ("Maze level " + (i + 1), data);
int offset = base + i * 0x400;
byte[] data = new byte[2048];
System.arraycopy (buffer, offset, data, 0, 1024);
System.arraycopy (buffer, offset + 8192, data, 1024, 1024);
MazeGridV5 grid = new MazeGridV5 ("Maze level " + (i + 1), data, messageBlock);
List<DiskAddress> mazeBlocks = new ArrayList<DiskAddress> ();
addToNode (grid, mazeNode, mazeBlocks);