mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2024-12-26 21:30:09 +00:00
added character parties
This commit is contained in:
parent
ca11e8ee68
commit
a633e28ed3
37
src/com/bytezone/diskbrowser/wizardry/CharacterParty.java
Normal file
37
src/com/bytezone/diskbrowser/wizardry/CharacterParty.java
Normal 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 ();
|
||||
}
|
||||
}
|
@ -1,7 +1,5 @@
|
||||
package com.bytezone.diskbrowser.wizardry;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.bytezone.diskbrowser.applefile.AbstractFile;
|
||||
import com.bytezone.diskbrowser.utilities.HexFormatter;
|
||||
import com.bytezone.diskbrowser.utilities.Utility;
|
||||
@ -12,7 +10,7 @@ public class CharacterV4 extends AbstractFile
|
||||
{
|
||||
int id;
|
||||
int nextCharacterId;
|
||||
String slogan = "";
|
||||
CharacterParty party;
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
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 ();
|
||||
int nextCharacterId = this.nextCharacterId;
|
||||
this.party = party;
|
||||
}
|
||||
|
||||
while (nextCharacterId != id)
|
||||
{
|
||||
CharacterV4 nextCharacter = characters.get (nextCharacterId);
|
||||
|
||||
if (!nextCharacter.slogan.isEmpty ()) // this group has been processed already
|
||||
return;
|
||||
|
||||
text += nextCharacter.getPartialSlogan ();
|
||||
nextCharacterId = nextCharacter.nextCharacterId;
|
||||
}
|
||||
|
||||
slogan = text.replace ("\\", " - ");
|
||||
// ---------------------------------------------------------------------------------//
|
||||
boolean isInParty ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return party != null;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@ -61,10 +52,14 @@ public class CharacterV4 extends AbstractFile
|
||||
|
||||
text.append (String.format ("Id ............. %3d%n", id));
|
||||
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 (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 ();
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ public class Wizardry4BootDisk extends PascalDisk
|
||||
private final int version;
|
||||
|
||||
private List<CharacterV4> characters = new ArrayList<> ();
|
||||
private List<CharacterParty> parties = new ArrayList<> ();
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public Wizardry4BootDisk (AppleDisk[] dataDisks)
|
||||
@ -96,6 +97,7 @@ public class Wizardry4BootDisk extends PascalDisk
|
||||
scenarioNode.setAllowsChildren (true);
|
||||
scenarioHeader = new Header (scenarioNode, this);
|
||||
linkCharacters4 (scenarioNode, fileEntry);
|
||||
linkParties ();
|
||||
linkMazeLevels4 (scenarioNode, fileEntry);
|
||||
linkMonstersV4 (scenarioNode, fileEntry);
|
||||
linkItemsV4 (scenarioNode, fileEntry);
|
||||
@ -164,22 +166,50 @@ public class Wizardry4BootDisk extends PascalDisk
|
||||
CharacterV4 c = new CharacterV4 (name, out, i);
|
||||
characters.add (c);
|
||||
|
||||
List<DiskAddress> characterBlocks = new ArrayList<> ();
|
||||
DiskAddress da = blocks.get (ptr / 512);
|
||||
characterBlocks.add (da);
|
||||
addToNode (c, charactersNode, characterBlocks);
|
||||
if (!name.isEmpty ())
|
||||
{
|
||||
List<DiskAddress> characterBlocks = new ArrayList<> ();
|
||||
DiskAddress da = blocks.get (ptr / 512);
|
||||
characterBlocks.add (da);
|
||||
addToNode (c, charactersNode, characterBlocks);
|
||||
|
||||
if (!allCharacterBlocks.contains (da))
|
||||
allCharacterBlocks.add (da);
|
||||
if (!allCharacterBlocks.contains (da))
|
||||
allCharacterBlocks.add (da);
|
||||
}
|
||||
|
||||
ptr += sd.totalBlocks;
|
||||
}
|
||||
|
||||
DefaultAppleFileSource afs = (DefaultAppleFileSource) charactersNode.getUserObject ();
|
||||
afs.setSectors (allCharacterBlocks);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void linkParties ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
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);
|
||||
|
||||
for (int j = 0; j < 4; j++)
|
||||
for (int j = 0; j < monsterNames.length; j++)
|
||||
monsterNames[j] = messageBlock.getMessageLine (i * 4 + 13000 + j);
|
||||
|
||||
MonsterV4 monster = new MonsterV4 (monsterNames, out, i);
|
||||
@ -242,7 +272,7 @@ public class Wizardry4BootDisk extends PascalDisk
|
||||
{
|
||||
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);
|
||||
if (itemNames[j] == null)
|
||||
|
Loading…
Reference in New Issue
Block a user