Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ project(":core") {
api "org.apache.commons:commons-compress:1.20"
api "net.nikr:dds:1.0.0"
api files(fileTree(dir:'../jars', includes: ['*.jar']))

testImplementation "org.junit.jupiter:junit-jupiter-api:5.10.2"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.10.2"
}

test {
useJUnitPlatform()
}
}

Expand Down
11 changes: 9 additions & 2 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@

sourceCompatibility = 1.17

sourceSets.main.java.srcDirs = [ "src/" ]

sourceSets {
main {
java.srcDirs = [ "src/" ]
}
test {
java.srcDirs = [ "test/" ]
resources.srcDirs = [ "test/resources" ]
}
}

eclipse.project {
name = appName + "-core"
Expand Down
50 changes: 36 additions & 14 deletions core/src/com/etheller/warsmash/parsers/w3x/w3e/Corner.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/**
* A tile corner.
* https://github.com/ChiefOfGxBxL/WC3MapSpecification/blob/master/Terrain/12.md
*/
public class Corner {
private float groundHeight;
Expand Down Expand Up @@ -42,21 +43,32 @@ public Corner(final Corner other) {
this.layerHeight = other.layerHeight;
}

public void load(final LittleEndianDataInputStream stream) throws IOException {
public void load(final LittleEndianDataInputStream stream, int version) throws IOException {
this.groundHeight = (stream.readShort() - 8192) / (float) 512;

final short waterAndEdge = stream.readShort();
this.waterHeight = ((waterAndEdge & 0x3FFF) - 8192) / (float) 512;
this.mapEdge = waterAndEdge & 0x4000;

final short textureAndFlags = ParseUtils.readUInt8(stream);
if (version >= 12) {
final int textureAndFlags = ParseUtils.readUInt16(stream);

this.ramp = textureAndFlags & 0b00010000;
this.blight = textureAndFlags & 0b00100000;
this.water = textureAndFlags & 0b01000000;
this.boundary = textureAndFlags & 0b10000000;
this.ramp = textureAndFlags & 0b00000000_01000000;
this.blight = textureAndFlags & 0b00000000_10000000;
this.water = textureAndFlags & 0b00000001_00000000;
this.boundary = textureAndFlags & 0b00000010_00000000;

this.groundTexture = textureAndFlags & 0b00001111;
this.groundTexture = textureAndFlags & 0b00111111;
} else {
final short textureAndFlags = ParseUtils.readUInt8(stream);

this.ramp = textureAndFlags & 0b00010000;
this.blight = textureAndFlags & 0b00100000;
this.water = textureAndFlags & 0b01000000;
this.boundary = textureAndFlags & 0b10000000;

this.groundTexture = textureAndFlags & 0b00001111;
}

final short variation = ParseUtils.readUInt8(stream);

Expand All @@ -70,16 +82,26 @@ public void load(final LittleEndianDataInputStream stream) throws IOException {

}

public void save(final LittleEndianDataOutputStream stream) throws IOException {
public void save(final LittleEndianDataOutputStream stream, int version) throws IOException {
stream.writeShort((short) ((this.groundHeight * 512f) + 8192f));
final int mapEdgeWrite = (this.mapEdge != 0) ? 0x4000 : 0;
stream.writeShort((short) ((int) ((this.waterHeight * 512f) + 8192f) | (mapEdgeWrite)));
final int rampWrite = (this.ramp != 0) ? 0b00010000 : 0;
final int blightWrite = (this.blight != 0) ? 0b00100000 : 0;
final int waterWrite = (this.water != 0) ? 0b01000000 : 0;
final int boundaryWrite = (this.boundary != 0) ? 0b10000000 : 0;
ParseUtils.writeUInt8(stream,
(short) ((rampWrite) | (blightWrite) | (waterWrite) | (boundaryWrite) | this.groundTexture));
int rampWrite = (this.ramp != 0) ? 0b00010000 : 0;
int blightWrite = (this.blight != 0) ? 0b00100000 : 0;
int waterWrite = (this.water != 0) ? 0b01000000 : 0;
int boundaryWrite = (this.boundary != 0) ? 0b10000000 : 0;
if (version >= 12) {
rampWrite <<= 2;
blightWrite <<= 2;
waterWrite <<= 2;
boundaryWrite <<= 2;

ParseUtils.writeUInt16(stream,
(int) ((rampWrite) | (blightWrite) | (waterWrite) | (boundaryWrite) | this.groundTexture));
} else {
ParseUtils.writeUInt8(stream,
(short) ((rampWrite) | (blightWrite) | (waterWrite) | (boundaryWrite) | this.groundTexture));
}
ParseUtils.writeUInt8(stream, (short) ((this.cliffVariation << 5) | this.groundVariation));
ParseUtils.writeUInt8(stream, (short) ((this.cliffTexture << 4) + this.layerHeight));
}
Expand Down
10 changes: 3 additions & 7 deletions core/src/com/etheller/warsmash/parsers/w3x/w3e/War3MapW3e.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

/**
* war3map.w3e - the environment file.
* https://github.com/ChiefOfGxBxL/WC3MapSpecification/blob/master/Terrain/12.md
*/
public class War3MapW3e {
private static final War3ID MAGIC_NUMBER = War3ID.fromString("W3E!");
Expand Down Expand Up @@ -57,7 +58,7 @@ private boolean load(final LittleEndianDataInputStream stream) throws IOExceptio
for (int column = 0, columns = this.mapSize[0]; column < columns; column++) {
final Corner corner = new Corner();

corner.load(stream);
corner.load(stream, this.version);

this.corners[row][column] = corner;
}
Expand Down Expand Up @@ -88,16 +89,11 @@ public void save(final LittleEndianDataOutputStream stream) throws IOException {

for (final Corner[] row : this.corners) {
for (final Corner corner : row) {
corner.save(stream);
corner.save(stream, this.version);
}
}
}

public int getByteLength() {
return 37 + (this.groundTiles.size() * 4) + (this.cliffTiles.size() * 4)
+ (this.mapSize[0] * this.mapSize[1] * 7);
}

public int getVersion() {
return this.version;
}
Expand Down
12 changes: 6 additions & 6 deletions core/src/com/etheller/warsmash/parsers/w3x/w3i/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ public void load(final LittleEndianDataInputStream stream, final int version) th
ParseUtils.readFloatArray(stream, this.startLocation);
this.allyLowPriorities = ParseUtils.readUInt32(stream);
this.allyHighPriorities = ParseUtils.readUInt32(stream);
if (version > 30) {
if (version >= 31) {
this.enemyLowPrioritiesFlags = ParseUtils.readUInt32(stream);
this.enemyHighPrioritiesFlags = ParseUtils.readUInt32(stream);
}
}

public void save(final LittleEndianDataOutputStream stream) throws IOException {
public void save(final LittleEndianDataOutputStream stream, int version) throws IOException {
ParseUtils.writeUInt32(stream, this.id);
stream.writeInt(this.type);
stream.writeInt(this.race);
Expand All @@ -45,10 +45,10 @@ public void save(final LittleEndianDataOutputStream stream) throws IOException {
ParseUtils.writeFloatArray(stream, this.startLocation);
ParseUtils.writeUInt32(stream, this.allyLowPriorities);
ParseUtils.writeUInt32(stream, this.allyHighPriorities);
}

public int getByteLength() {
return 33 + this.name.length();
if (version >= 31) {
ParseUtils.writeUInt32(stream, this.enemyLowPrioritiesFlags);
ParseUtils.writeUInt32(stream, this.enemyHighPrioritiesFlags);
}
}

public int getId() {
Expand Down
Loading