Skip to content

Commit 51cf71e

Browse files
committed
feat(mapview): Showing multi and f2p map zones
1 parent 2449a81 commit 51cf71e

File tree

5 files changed

+145
-10
lines changed

5 files changed

+145
-10
lines changed

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,9 @@ build/
66

77
loader/src/main/java/sig.java
88
loader/src/main/java/sign/signlink.java
9+
10+
mapview/src/main/java/sig.java
11+
12+
/worldmap.jag
13+
/*.png
14+
/*.raw

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,9 @@ Thanks to these individuals' projects for shedding light on some things - this w
3535
## Running
3636

3737
Because there are multiple entry points, instead of `gradle run` you have to execute `gradle client:run` or `gradle mapview:run` else it will launch both sequentially.
38+
39+
### Mapview Applet
40+
41+
1. Copy worldmap.jag to the root folder.
42+
2. Run `gradle mapSig --args="worldmap.jag"`
43+
3. Run `gradle mapview:run`

mapview/src/main/java/mapview.java

+128-5
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,17 @@
1717
@OriginalClass("mapview!mapview")
1818
public final class mapview extends GameShell {
1919

20-
// 2005 mapview applet features
2120
private static final boolean shouldDrawBorders = false;
2221
private static final boolean shouldDrawLabels = true;
2322

23+
private static final boolean showMultiZones = false;
24+
private static final boolean showFreeZones = false;
25+
26+
private boolean[][] objTiles;
27+
private boolean[][] npcTiles;
28+
private boolean[][] multiTiles;
29+
private boolean[][] freeTiles;
30+
2431
// overworld
2532
private final short startX = 3200;
2633
private final short startZ = 3200;
@@ -72,10 +79,6 @@ public final class mapview extends GameShell {
7279
@OriginalMember(owner = "mapview!mapview", name = "U", descriptor = "[[B")
7380
private byte[][] locMapscenes;
7481

75-
private boolean[][] objTiles;
76-
77-
private boolean[][] npcTiles;
78-
7982
@OriginalMember(owner = "mapview!mapview", name = "X", descriptor = "Lmapview!j;")
8083
private PixFont b12;
8184

@@ -312,6 +315,20 @@ protected void load() {
312315
this.npcTiles = new boolean[this.sizeX][this.sizeZ];
313316
this.readNpcData(npcData, this.npcTiles);
314317

318+
try {
319+
byte[] multiData = worldmap.read("multi.dat", null);
320+
this.multiTiles = new boolean[this.sizeX][this.sizeZ];
321+
this.readMultiData(multiData, this.multiTiles);
322+
} catch (Exception ex) {
323+
}
324+
325+
try {
326+
byte[] freeData = worldmap.read("free.dat", null);
327+
this.freeTiles = new boolean[this.sizeX][this.sizeZ];
328+
this.readFreeData(freeData, this.freeTiles);
329+
} catch (Exception ex) {
330+
}
331+
315332
try {
316333
for (int i = 0; i < 50; i++) {
317334
this.imageMapscene[i] = new Pix8(worldmap, "mapscene", i);
@@ -445,6 +462,48 @@ private void readNpcData(byte[] data, boolean[][] npcs) {
445462
}
446463
}
447464

465+
private void readMultiData(byte[] data, boolean[][] multimap) {
466+
int pos = 0;
467+
while (pos < data.length) {
468+
int mx = (data[pos++] & 0xFF) * 64 - this.originX;
469+
int mz = (data[pos++] & 0xFF) * 64 - this.originZ;
470+
471+
if (mx > 0 && mz > 0 && mx + 64 < this.sizeX && mz + 64 < this.sizeZ) {
472+
for (int x = 0; x < 64; x++) {
473+
boolean[] map = multimap[x + mx];
474+
int zIndex = this.sizeZ - mz - 1;
475+
476+
for (int z = -64; z < 0; z++) {
477+
map[zIndex--] = data[pos++] == 1;
478+
}
479+
}
480+
} else {
481+
pos += 4096;
482+
}
483+
}
484+
}
485+
486+
private void readFreeData(byte[] data, boolean[][] freemap) {
487+
int pos = 0;
488+
while (pos < data.length) {
489+
int mx = (data[pos++] & 0xFF) * 64 - this.originX;
490+
int mz = (data[pos++] & 0xFF) * 64 - this.originZ;
491+
492+
if (mx > 0 && mz > 0 && mx + 64 < this.sizeX && mz + 64 < this.sizeZ) {
493+
for (int x = 0; x < 64; x++) {
494+
boolean[] map = freemap[x + mx];
495+
int zIndex = this.sizeZ - mz - 1;
496+
497+
for (int z = -64; z < 0; z++) {
498+
map[zIndex--] = data[pos++] == 1;
499+
}
500+
}
501+
} else {
502+
pos += 4096;
503+
}
504+
}
505+
}
506+
448507
@OriginalMember(owner = "mapview!mapview", name = "a", descriptor = "([B[[B)V")
449508
private void readUnderlayData(@OriginalArg(0) byte[] data, @OriginalArg(1) byte[][] underlays) {
450509
@Pc(3) int pos = 0;
@@ -614,6 +673,8 @@ protected void unload() {
614673
this.locMapscenes = null;
615674
this.objTiles = null;
616675
this.npcTiles = null;
676+
this.multiTiles = null;
677+
this.freeTiles = null;
617678
this.imageMapscene = null;
618679
this.imageMapfunction = null;
619680
this.imageMapdot0 = null;
@@ -1187,6 +1248,68 @@ private void drawMap(@OriginalArg(0) int left, @OriginalArg(1) int top, @Origina
11871248
}
11881249
}
11891250

1251+
if (showMultiZones) {
1252+
for (int x = 0; x < visibleX; x++) {
1253+
int startX = widthRatio * x >> 16;
1254+
int endX = widthRatio * (x + 1) >> 16;
1255+
int lengthX = endX - startX;
1256+
if (lengthX <= 0) {
1257+
continue;
1258+
}
1259+
1260+
startX += widthOffset;
1261+
endX += widthOffset;
1262+
1263+
boolean[] multi = this.multiTiles[x + left];
1264+
for (int y = 0; y < visibleY; y++) {
1265+
int startY = heightRatio * y >> 16;
1266+
int endY = heightRatio * (y + 1) >> 16;
1267+
int lengthY = endY - startY;
1268+
if (lengthY <= 0) {
1269+
continue;
1270+
}
1271+
1272+
startY += heightOffset;
1273+
endY += heightOffset;
1274+
1275+
if (multi[y + top]) {
1276+
Pix2D.fillRectTrans(startX, startY, lengthX, lengthY, 0xff0000, 96);
1277+
}
1278+
}
1279+
}
1280+
}
1281+
1282+
if (showFreeZones) {
1283+
for (int x = 0; x < visibleX; x++) {
1284+
int startX = widthRatio * x >> 16;
1285+
int endX = widthRatio * (x + 1) >> 16;
1286+
int lengthX = endX - startX;
1287+
if (lengthX <= 0) {
1288+
continue;
1289+
}
1290+
1291+
startX += widthOffset;
1292+
endX += widthOffset;
1293+
1294+
boolean[] free = this.freeTiles[x + left];
1295+
for (int y = 0; y < visibleY; y++) {
1296+
int startY = heightRatio * y >> 16;
1297+
int endY = heightRatio * (y + 1) >> 16;
1298+
int lengthY = endY - startY;
1299+
if (lengthY <= 0) {
1300+
continue;
1301+
}
1302+
1303+
startY += heightOffset;
1304+
endY += heightOffset;
1305+
1306+
if (free[y + top]) {
1307+
Pix2D.fillRectTrans(startX, startY, lengthX, lengthY, 0x00ff00, 96);
1308+
}
1309+
}
1310+
}
1311+
}
1312+
11901313
for (int i = 0; i < visibleMapFunctionCount; i++) {
11911314
this.imageMapfunction[this.visibleMapFunctions[i]].draw(this.visibleMapFunctionsX[i] - 7, this.visibleMapFunctionsY[i] - 7);
11921315
}

mapview/src/main/java/sig.java

-5
This file was deleted.

tools/build.gradle

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ tasks.register('sig', JavaExec) {
1717
args = ['client/build/libs/client.jar']
1818
}
1919

20+
tasks.register('mapSig', JavaExec) {
21+
classpath = sourceSets.main.runtimeClasspath
22+
mainClass = 'lostcity.tools.MapviewSig'
23+
}
24+
2025
tasks.register('removeAnnotations', JavaExec) {
2126
classpath = sourceSets.main.runtimeClasspath
2227
mainClass = 'lostcity.tools.RemoveAnnotations'

0 commit comments

Comments
 (0)