Commit ade0882c authored by Sir Beormin's avatar Sir Beormin
Browse files

Adding methods to H4CombatObjectParser to parse some unknown data. Refactoring code.

parent 85a7c127
......@@ -22,7 +22,7 @@ public class H4CombatObjectParser {
private final String mFileName;
private final byte[] data;
private static final int NAME_OFFSET = 16;
public short getNumImages() {
return mNumImages;
}
......@@ -72,9 +72,9 @@ public class H4CombatObjectParser {
}
private void parseData(ByteBuffer buffer) throws Exception {
buffer.position(this.getOffsetOfFirstImage());
buffer.position(this.getOffsetOfFirstImage());
this.mNumImages = countImages(buffer);
for (int i = 0; i < this.mNumImages; i++) {
H4ImageParser image = new H4ImageParser(buffer);
this.mImageNames.add(image.getImageName());
......@@ -104,63 +104,95 @@ public class H4CombatObjectParser {
return count;
}
public int getFormat() {
return Util.convertToShort(new byte[] { this.data[0], this.data[1] });
public short getFormat() {
return Util.convertToShort(new byte[]{this.data[0], this.data[1]});
}
public int getAreaHeight() {
return Util.complement(this.data[2]);
return Util.complement(this.data[2]);
}
public int getAreaWidth() {
return Util.complement(this.data[3]);
return Util.complement(this.data[3]);
}
/**
* This is used to determine if a character can see above an object and hit a target.
* This is used to determine if a character can see above an object and hit
* a target.
*
* @return The elevation value.
*/
public int getElevation() {
return Util.complement(this.data[4]);
return Util.complement(this.data[4]);
}
public boolean isPassable() {
return this.data[7] == 0;
return this.data[7] == 0;
}
private int getNameLength() {
return Util.convertToShort(new byte[] { this.data[NAME_OFFSET - 2], this.data[NAME_OFFSET - 1] });
private short getNameLength() {
return Util.convertToShort(new byte[]{this.data[NAME_OFFSET - 2], this.data[NAME_OFFSET - 1]});
}
public String getName() {
if (this.getFormat() == 0) {
return null;
}
byte[] nameBytes = Arrays.copyOfRange(this.data, NAME_OFFSET, NAME_OFFSET + this.getNameLength());
return new String(nameBytes, StandardCharsets.US_ASCII);
}
private int getUnknown() {
int offsetAfterName = NAME_OFFSET + this.getNameLength();
return Util.convertToShort(Arrays.copyOfRange(this.data, offsetAfterName, offsetAfterName + 2));
}
if (this.getFormat() == 0) {
return null;
}
byte[] nameBytes = Arrays.copyOfRange(this.data, NAME_OFFSET, NAME_OFFSET + this.getNameLength());
return new String(nameBytes, StandardCharsets.US_ASCII);
}
// TODO: combat objects are generated randomly in every battle. And to achieve
// the desired random distribution of the obstacles, they are classified somehow, and
// their frequency is also predetermined. The table.combat_obstacles.txt might just
// serve as a database for that, but the combat objects themselves also contain
// various flags describing what they are. These should be deciphered.
private short getUnknown1() {
int offsetAfterName = NAME_OFFSET + this.getNameLength();
return Util.convertToShort(Arrays.copyOfRange(this.data, offsetAfterName, offsetAfterName + 2));
}
private boolean getUnknown2() {
// isProtrudingObstacle() ??? (not a crack!)
return this.data[8] == 1;
}
private boolean getUnknown3() {
// isCommonRock() ???
return this.data[9] == 1;
}
private boolean isPlant() {
return this.data[10] == 1;
}
private boolean getUnknown4() {
// isCommonRock() ???
return this.data[11] == 1;
}
private short getUnknown5() {
int offsetAfterName = NAME_OFFSET + this.getNameLength();
return Util.convertToShort(Arrays.copyOfRange(this.data, offsetAfterName + 2, offsetAfterName + 4));
}
private int getOffsetOfFirstImage() throws Exception {
// this is a very hacky way of determining where the first image starts
if (this.getFormat() == 2) {
int unknown = this.getUnknown();
switch (unknown) {
case 2:
return NAME_OFFSET + this.getNameLength() + 4;
case 3:
return NAME_OFFSET + this.getNameLength() + 10;
default:
throw new Exception("Unknown was: " + Integer.toString(unknown));
// this is a very hacky way of determining where the first image starts
if (this.getFormat() == 2) {
short unknown1 = this.getUnknown1();
switch (unknown1) {
case 2:
return NAME_OFFSET + this.getNameLength() + 4;
case 3:
return NAME_OFFSET + this.getNameLength() + 10;
default:
throw new Exception("Unknown was: " + Integer.toString(unknown1));
}
}
// in this case it's combat_object.flight.*
return 10;
}
// in this case it's combat_object.flight.*
return 10;
}
}
\ No newline at end of file
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment