diff --git a/src/com/bytezone/diskbrowser/wizardry/Character.java b/src/com/bytezone/diskbrowser/wizardry/Character.java index 61680bb..d34ced3 100644 --- a/src/com/bytezone/diskbrowser/wizardry/Character.java +++ b/src/com/bytezone/diskbrowser/wizardry/Character.java @@ -26,6 +26,10 @@ public abstract class Character extends AbstractFile public int characterLevel; public int possessionsCount; + public boolean mysteryBit; // first bit in spellsKnown + public final boolean[] spellsKnown = new boolean[50]; + public final int[][] spellAllowance = new int[2][7]; + public enum Race { NORACE, HUMAN, ELF, DWARF, GNOME, HOBBIT @@ -70,6 +74,25 @@ public abstract class Character extends AbstractFile attributes[ptr + 1] = (value & 0x03E0) >>> 5; } + // ---------------------------------------------------------------------------------// + protected void checkKnownSpells (byte[] buffer, int ptr) + // ---------------------------------------------------------------------------------// + { + int bit = 1; // skip first bit + int val = buffer[ptr]; + mysteryBit = (val & 0x01) == 1; + + for (int i = 0; i < spellsKnown.length; i++) + { + if (bit == 8) + { + val = buffer[++ptr]; + bit = 0; + } + spellsKnown[i] = ((val >>> bit++) & 0x01) != 0; + } + } + // ---------------------------------------------------------------------------------// public String getAwardString () // ---------------------------------------------------------------------------------// diff --git a/src/com/bytezone/diskbrowser/wizardry/CharacterV1.java b/src/com/bytezone/diskbrowser/wizardry/CharacterV1.java index 4b655e0..a0d6d7e 100755 --- a/src/com/bytezone/diskbrowser/wizardry/CharacterV1.java +++ b/src/com/bytezone/diskbrowser/wizardry/CharacterV1.java @@ -78,6 +78,8 @@ class CharacterV1 extends Character hpLeft = Utility.getShort (buffer, 134); hpMax = Utility.getShort (buffer, 136); + checkKnownSpells (buffer, 138); + for (int i = 0; i < 7; i++) mageSpells[i] = buffer[146 + i * 2]; @@ -98,16 +100,9 @@ class CharacterV1 extends Character assetValue += baggage.item.getCost (); } - int index = 0; - for (int i = 138; i < 145; i++) - for (int bit = 0; bit < 8; bit++) - { - if (((buffer[i] >>> bit) & 0x01) != 0) - spellBook.add (spellList.get (index)); - - if (++index >= spellList.size ()) - break; - } + for (int i = 0; i < spellsKnown.length; i++) + if (spellsKnown[i]) + spellBook.add (spellList.get (i)); nextLevel = experienceLevels.get (typeInt).getExperiencePoints (characterLevel + 1); } diff --git a/src/com/bytezone/diskbrowser/wizardry/CharacterV4.java b/src/com/bytezone/diskbrowser/wizardry/CharacterV4.java index 2d21924..84e7f13 100644 --- a/src/com/bytezone/diskbrowser/wizardry/CharacterV4.java +++ b/src/com/bytezone/diskbrowser/wizardry/CharacterV4.java @@ -33,10 +33,6 @@ public class CharacterV4 extends Character public final long experience; public final int maxlevac; // max level armour class? - public final boolean mysteryBit; // first bit in spellsKnown - public final boolean[] spellsKnown = new boolean[50]; - public final int[][] spellAllowance = new int[2][7]; - public final int hpCalCmd; public final int healPts; @@ -101,18 +97,7 @@ public class CharacterV4 extends Character hpLeft = Utility.getShort (buffer, 135); hpMax = Utility.getShort (buffer, 137); - mysteryBit = (buffer[139] & 0x01) == 1; - int index = -1; // skip mystery bit - for (int i = 139; i < 146; i++) - for (int bit = 0; bit < 8; bit++) - { - if (((buffer[i] >>> bit) & 0x01) != 0) - if (index >= 0) - spellsKnown[index] = true; - - if (++index >= MAX_SPELLS) - break; - } + checkKnownSpells (buffer, 139); for (int i = 0; i < 7; i++) {