added character parties

This commit is contained in:
Denis Molony 2022-05-29 10:43:10 +10:00
parent ca11e8ee68
commit a633e28ed3
3 changed files with 90 additions and 28 deletions

View File

@ -0,0 +1,37 @@
package com.bytezone.diskbrowser.wizardry;
import java.util.ArrayList;
import java.util.List;
// -----------------------------------------------------------------------------------//
public class CharacterParty
// -----------------------------------------------------------------------------------//
{
List<CharacterV4> characters = new ArrayList<> ();
String slogan = "";
// ---------------------------------------------------------------------------------//
void add (CharacterV4 character)
// ---------------------------------------------------------------------------------//
{
characters.add (character);
slogan += character.getPartialSlogan ();
character.setParty (this);
}
// ---------------------------------------------------------------------------------//
@Override
public String toString ()
// ---------------------------------------------------------------------------------//
{
StringBuilder text = new StringBuilder ();
text.append (slogan.replace ("\\", " - "));
text.append ("\n");
for (CharacterV4 character : characters)
text.append (String.format (" %3d %s%n", character.id, character.getName ()));
return text.toString ();
}
}

View File

@ -1,7 +1,5 @@
package com.bytezone.diskbrowser.wizardry; package com.bytezone.diskbrowser.wizardry;
import java.util.List;
import com.bytezone.diskbrowser.applefile.AbstractFile; import com.bytezone.diskbrowser.applefile.AbstractFile;
import com.bytezone.diskbrowser.utilities.HexFormatter; import com.bytezone.diskbrowser.utilities.HexFormatter;
import com.bytezone.diskbrowser.utilities.Utility; import com.bytezone.diskbrowser.utilities.Utility;
@ -12,7 +10,7 @@ public class CharacterV4 extends AbstractFile
{ {
int id; int id;
int nextCharacterId; int nextCharacterId;
String slogan = ""; CharacterParty party;
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
CharacterV4 (String name, byte[] buffer, int id) CharacterV4 (String name, byte[] buffer, int id)
@ -25,24 +23,17 @@ public class CharacterV4 extends AbstractFile
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
void link (List<CharacterV4> characters) void setParty (CharacterParty party)
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
String text = getPartialSlogan (); this.party = party;
int nextCharacterId = this.nextCharacterId; }
while (nextCharacterId != id) // ---------------------------------------------------------------------------------//
{ boolean isInParty ()
CharacterV4 nextCharacter = characters.get (nextCharacterId); // ---------------------------------------------------------------------------------//
{
if (!nextCharacter.slogan.isEmpty ()) // this group has been processed already return party != null;
return;
text += nextCharacter.getPartialSlogan ();
nextCharacterId = nextCharacter.nextCharacterId;
}
slogan = text.replace ("\\", " - ");
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
@ -61,10 +52,14 @@ public class CharacterV4 extends AbstractFile
text.append (String.format ("Id ............. %3d%n", id)); text.append (String.format ("Id ............. %3d%n", id));
text.append (String.format ("Name ........... %s%n", name)); text.append (String.format ("Name ........... %s%n", name));
text.append (String.format ("Slogan ......... %s%n", slogan)); // text.append (String.format ("Slogan ......... %s%n", slogan));
text.append (String.format ("Next ........... %d%n%n", nextCharacterId)); text.append (String.format ("Next ........... %d%n%n", nextCharacterId));
text.append (HexFormatter.format (buffer, 1, buffer[0] & 0xFF)); text.append (HexFormatter.format (buffer, 1, buffer[0] & 0xFF));
text.append ("\n\n");
if (!party.slogan.isEmpty () || party.characters.size () > 1)
text.append (party);
return text.toString (); return text.toString ();
} }

View File

@ -28,6 +28,7 @@ public class Wizardry4BootDisk extends PascalDisk
private final int version; private final int version;
private List<CharacterV4> characters = new ArrayList<> (); private List<CharacterV4> characters = new ArrayList<> ();
private List<CharacterParty> parties = new ArrayList<> ();
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
public Wizardry4BootDisk (AppleDisk[] dataDisks) public Wizardry4BootDisk (AppleDisk[] dataDisks)
@ -96,6 +97,7 @@ public class Wizardry4BootDisk extends PascalDisk
scenarioNode.setAllowsChildren (true); scenarioNode.setAllowsChildren (true);
scenarioHeader = new Header (scenarioNode, this); scenarioHeader = new Header (scenarioNode, this);
linkCharacters4 (scenarioNode, fileEntry); linkCharacters4 (scenarioNode, fileEntry);
linkParties ();
linkMazeLevels4 (scenarioNode, fileEntry); linkMazeLevels4 (scenarioNode, fileEntry);
linkMonstersV4 (scenarioNode, fileEntry); linkMonstersV4 (scenarioNode, fileEntry);
linkItemsV4 (scenarioNode, fileEntry); linkItemsV4 (scenarioNode, fileEntry);
@ -164,22 +166,50 @@ public class Wizardry4BootDisk extends PascalDisk
CharacterV4 c = new CharacterV4 (name, out, i); CharacterV4 c = new CharacterV4 (name, out, i);
characters.add (c); characters.add (c);
List<DiskAddress> characterBlocks = new ArrayList<> (); if (!name.isEmpty ())
DiskAddress da = blocks.get (ptr / 512); {
characterBlocks.add (da); List<DiskAddress> characterBlocks = new ArrayList<> ();
addToNode (c, charactersNode, characterBlocks); DiskAddress da = blocks.get (ptr / 512);
characterBlocks.add (da);
addToNode (c, charactersNode, characterBlocks);
if (!allCharacterBlocks.contains (da)) if (!allCharacterBlocks.contains (da))
allCharacterBlocks.add (da); allCharacterBlocks.add (da);
}
ptr += sd.totalBlocks; ptr += sd.totalBlocks;
} }
DefaultAppleFileSource afs = (DefaultAppleFileSource) charactersNode.getUserObject (); DefaultAppleFileSource afs = (DefaultAppleFileSource) charactersNode.getUserObject ();
afs.setSectors (allCharacterBlocks); afs.setSectors (allCharacterBlocks);
}
// ---------------------------------------------------------------------------------//
private void linkParties ()
// ---------------------------------------------------------------------------------//
{
for (CharacterV4 character : characters) for (CharacterV4 character : characters)
character.link (characters); {
if (character.isInParty () || character.getName ().isEmpty ())
continue;
CharacterParty party = new CharacterParty ();
parties.add (party);
link (character, party);
}
}
// ---------------------------------------------------------------------------------//
private void link (CharacterV4 character, CharacterParty party)
// ---------------------------------------------------------------------------------//
{
if (character.isInParty ())
return;
party.add (character);
if (character.nextCharacterId > 0)
link (characters.get (character.nextCharacterId), party);
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
@ -202,7 +232,7 @@ public class Wizardry4BootDisk extends PascalDisk
{ {
byte[] out = huffman.decodeMessage (buffer, ptr, sd.totalBlocks); byte[] out = huffman.decodeMessage (buffer, ptr, sd.totalBlocks);
for (int j = 0; j < 4; j++) for (int j = 0; j < monsterNames.length; j++)
monsterNames[j] = messageBlock.getMessageLine (i * 4 + 13000 + j); monsterNames[j] = messageBlock.getMessageLine (i * 4 + 13000 + j);
MonsterV4 monster = new MonsterV4 (monsterNames, out, i); MonsterV4 monster = new MonsterV4 (monsterNames, out, i);
@ -242,7 +272,7 @@ public class Wizardry4BootDisk extends PascalDisk
{ {
byte[] out = huffman.decodeMessage (buffer, ptr, sd.totalBlocks); byte[] out = huffman.decodeMessage (buffer, ptr, sd.totalBlocks);
for (int j = 0; j < 2; j++) for (int j = 0; j < itemNames.length; j++)
{ {
itemNames[j] = messageBlock.getMessageLine (i * 2 + 14000 + j); itemNames[j] = messageBlock.getMessageLine (i * 2 + 14000 + j);
if (itemNames[j] == null) if (itemNames[j] == null)