Skip to content

Commit

Permalink
Bug fix for maps size>2048
Browse files Browse the repository at this point in the history
  • Loading branch information
Garrett92 committed Aug 11, 2017
1 parent 18743c2 commit 03178a8
Show file tree
Hide file tree
Showing 6 changed files with 255 additions and 140 deletions.
38 changes: 20 additions & 18 deletions src/com/imraginbro/wurm/mapgen/MapBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,25 +173,27 @@ private void generateImageTile(final int imageTileX, final int imageTileY) {

private void drawBridges(BufferedImage imageTile, int imageTileX, int imageTileY) throws SQLException {
if (propertiesManager.gen_map_bridges) {
final int minX = (imageTileX * 256);
final int minY = (imageTileY * 256);
final int maxX = minX + 256;
final int maxY = minY + 256;
Graphics2D imageTileGraphics = imageTile.createGraphics();
Tile thisTile = Tiles.getTile(9);
Color tileColor = thisTile.getColor();
imageTileGraphics.setColor(tileColor);
Statement statement = dbhandler.getZonesConnection().createStatement();
ResultSet resultSet = statement.executeQuery("SELECT TILEX, TILEY FROM BRIDGEPARTS WHERE TILEX >= "+minX+" AND TILEY >= "+minY+" AND TILEX < "+maxX+" AND TILEY < "+maxY+";");
while (resultSet.next()) {
int tileX = resultSet.getInt("TILEX");
int tileY = resultSet.getInt("TILEY");
imageTileGraphics.fillRect((tileX - minX), (tileY - minY), 1, 1);
bridgeTileCount++;
if (dbhandler.checkZonesConnection()) {
final int minX = (imageTileX * 256);
final int minY = (imageTileY * 256);
final int maxX = minX + 256;
final int maxY = minY + 256;
Graphics2D imageTileGraphics = imageTile.createGraphics();
Tile thisTile = Tiles.getTile(9);
Color tileColor = thisTile.getColor();
imageTileGraphics.setColor(tileColor);
Statement statement = dbhandler.getZonesConnection().createStatement();
ResultSet resultSet = statement.executeQuery("SELECT TILEX, TILEY FROM BRIDGEPARTS WHERE TILEX >= "+minX+" AND TILEY >= "+minY+" AND TILEX < "+maxX+" AND TILEY < "+maxY+";");
while (resultSet.next()) {
int tileX = resultSet.getInt("TILEX");
int tileY = resultSet.getInt("TILEY");
imageTileGraphics.fillRect((tileX - minX), (tileY - minY), 1, 1);
bridgeTileCount++;
}
resultSet.close();
statement.close();
imageTileGraphics.dispose();
}
resultSet.close();
statement.close();
imageTileGraphics.dispose();
}
}

Expand Down
215 changes: 111 additions & 104 deletions src/com/imraginbro/wurm/mapgen/filegen/FileGeneration.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.sql.SQLException;
import java.sql.Statement;
import java.text.DecimalFormat;
import java.util.ArrayList;

import com.imraginbro.wurm.mapgen.MapBuilder;
import com.wurmonline.mesh.MeshIO;
Expand Down Expand Up @@ -38,18 +39,18 @@ public void generateStructuresFile() throws IOException, SQLException {

System.out.println("Writing structures.js file...");
BufferedWriter bw = new BufferedWriter(new FileWriter(MapBuilder.propertiesManager.saveLocation.getAbsolutePath() + separator + "includes" + separator + "structures.js", false));

System.out.println("Loading structures from wurmzones.db...");

Statement statement = MapBuilder.dbhandler.getZonesConnection().createStatement();
ResultSet resultSet = statement.executeQuery("SELECT WURMID FROM STRUCTURES WHERE FINISHED='1';");
bw.append("function getStructures() {" + newLine);
bw.append("\tvar structureBorders = [];" + newLine);

bw.append("function getStructures() {" + newLine
+ "\tvar structureBorders = [];" + newLine);
int count = 0;
while (resultSet.next()) {
long structureID = resultSet.getLong("WURMID");
Structure structure = new Structure(MapBuilder.dbhandler, structureID);
Structure structure = new Structure(structureID);
bw.append("\tstructureBorders.push(L.polygon(["
+ "xy("+structure.getMinX()+","+structure.getMinY()+"),"
+ "xy("+structure.getMaxX()+","+structure.getMinY()+"),"
Expand All @@ -60,10 +61,14 @@ public void generateStructuresFile() throws IOException, SQLException {
+ "<i>Created by " + structure.getOwnerName() + "</i></div>\"));" + newLine);
count++;
}
System.out.println("Added " + count + " structures to structures.js...");
bw.append("\treturn structureBorders;" + newLine);
bw.append("}");

resultSet.close();
statement.close();

bw.append("\treturn structureBorders;" + newLine + "}");
bw.close();

System.out.println("Added " + count + " structures to structures.js...");
}

public void generateGuardTowersFile() throws IOException, SQLException {
Expand All @@ -74,87 +79,83 @@ public void generateGuardTowersFile() throws IOException, SQLException {

System.out.println("Writing guardtowers.js file...");
BufferedWriter bw = new BufferedWriter(new FileWriter(MapBuilder.propertiesManager.saveLocation.getAbsolutePath() + separator + "includes" + separator + "guardtowers.js", false));
StringBuilder deedBordersString = new StringBuilder();
StringBuilder deedMarkersString = new StringBuilder();

StringBuilder GTBordersString = new StringBuilder();
StringBuilder GTMarkersString = new StringBuilder();

System.out.println("Loading guard towers from wurmitems.db...");
Statement statement = MapBuilder.dbhandler.getItemsConnection().createStatement();
ResultSet resultSet = statement.executeQuery("SELECT * FROM ITEMS WHERE (TEMPLATEID='384' OR TEMPLATEID='430' OR TEMPLATEID='528' OR TEMPLATEID='638' OR TEMPLATEID='996') AND CREATIONSTATE='0';");

deedBordersString.append("function getGuardTowerBorders() {" + newLine);
deedBordersString.append("\tvar guardTowerBorders = [];" + newLine);
ResultSet resultSet = statement.executeQuery("SELECT * FROM ITEMS WHERE "
+ "(TEMPLATEID='384' OR TEMPLATEID='430' OR TEMPLATEID='528' OR TEMPLATEID='638' OR TEMPLATEID='996') AND CREATIONSTATE='0';");

deedMarkersString.append("function getGuardTowers() {" + newLine);
deedMarkersString.append("\tvar guardTower = [];" + newLine);
ArrayList<GuardTower> guardTowers = new ArrayList<GuardTower>();

int count = 0;
while (resultSet.next()) {


int x = (int) Math.floor(resultSet.getInt("POSX")/4);
int y = (int) Math.floor(resultSet.getInt("POSY")/4);
float ql = resultSet.getFloat("QUALITYLEVEL");
float dmg = resultSet.getFloat("DAMAGE");
long ownerID = resultSet.getLong("LASTOWNERID");
Statement nameStatement = MapBuilder.dbhandler.getPlayersConnection().createStatement();
ResultSet nameRes = nameStatement.executeQuery("SELECT NAME FROM PLAYERS WHERE WURMID='" + ownerID + "';");
String pname = "";
if (nameRes.next()) {
pname = nameRes.getString("NAME");
}
nameStatement.close();


deedBordersString.append("\tguardTowerBorders.push(L.polygon([");
deedBordersString.append("xy("+(x-50)+","+(y-50)+"),");
deedBordersString.append("xy("+(x+51)+","+(y-50)+"),");
deedBordersString.append("xy("+(x+51)+","+(y+51)+"),");
deedBordersString.append("xy("+(x-50)+","+(y+51)+")]");
deedBordersString.append(", {color:'red',fillOpacity:0.1,weight:1}));" + newLine);

deedMarkersString.append("\tguardTower.push(L.marker(");
deedMarkersString.append("xy("+(x+0.5)+","+(y+0.5)+"),");
deedMarkersString.append("{icon: guardTowerIcon})");
DecimalFormat f = new DecimalFormat("0.00");
deedMarkersString.append(".bindPopup(\"<div align='center'><b>Guard Tower</b><br><i>Created by " + pname + "</i></div><br><b>QL:</b> " + f.format(ql) + "<br><b>DMG:</b> " + f.format(dmg) + "\"));" + newLine);
guardTowers.add(new GuardTower(resultSet.getLong("LASTOWNERID"),
(int) Math.floor(resultSet.getInt("POSX")/4),
(int) Math.floor(resultSet.getInt("POSY")/4),
resultSet.getFloat("QUALITYLEVEL"), resultSet.getFloat("DAMAGE")));
}

count++;
resultSet.close();
statement.close();

GTBordersString.append("function getGuardTowerBorders() {" + newLine
+ "\tvar guardTowerBorders = [];" + newLine);
GTMarkersString.append("function getGuardTowers() {" + newLine
+ "\tvar guardTower = [];" + newLine);

final DecimalFormat f = new DecimalFormat("0.00");
for (int i = 0; i < guardTowers.size(); i++) {
final GuardTower gt = guardTowers.get(i);
GTBordersString.append("\tguardTowerBorders.push(L.polygon(["
+ "xy("+(gt.getMinX())+","+(gt.getMinY())+"),"
+ "xy("+(gt.getMaxX()+1)+","+(gt.getMinY())+"),"
+ "xy("+(gt.getMaxX()+1)+","+(gt.getMaxY()+1)+"),"
+ "xy("+(gt.getMinX())+","+(gt.getMaxY()+1)+")]"
+ ", {color:'red',fillOpacity:0.1,weight:1}));" + newLine);
GTMarkersString.append("\tguardTower.push(L.marker("
+ "xy("+(gt.getX()+0.5)+","+(gt.getY()+0.5)+"),"
+ "{icon: guardTowerIcon})"
+ ".bindPopup(\"<div align='center'><b>Guard Tower</b><br>"
+ "<i>Created by " + gt.getOwnerName() + "</i></div><br>"
+ "<b>QL:</b> " + f.format(gt.getQL()) + "<br>"
+ "<b>DMG:</b> " + f.format(gt.getDMG()) + "\"));" + newLine);
}
System.out.println("Added " + count + " guard towers to guardtowers.js...");

deedBordersString.append("\treturn guardTowerBorders;" + newLine);
deedBordersString.append("}" + newLine + newLine);

deedMarkersString.append("\treturn guardTower;" + newLine);
deedMarkersString.append("}");

bw.append(deedBordersString);
bw.append(deedMarkersString);


GTBordersString.append("\treturn guardTowerBorders;" + newLine + "}" + newLine + newLine);
GTMarkersString.append("\treturn guardTower;" + newLine + "}");

bw.append(GTBordersString);
bw.append(GTMarkersString);
bw.close();

System.out.println("Added " + guardTowers.size() + " guard towers to guardtowers.js...");
}

public void generateDeedsFile() throws IOException, SQLException {
if (!MapBuilder.propertiesManager.showDeeds || !MapBuilder.dbhandler.checkZonesConnection()) {
System.out.println("Skipping deeds.js generation.");
return;
}

System.out.println("Writing deeds.js file...");
BufferedWriter bw = new BufferedWriter(new FileWriter(MapBuilder.propertiesManager.saveLocation.getAbsolutePath() + separator + "includes" + separator + "deeds.js", false));
String deedBordersString = "";
String deedMarkersString = "";
String mainDeedString = "";

StringBuilder mainDeedString = new StringBuilder();
StringBuilder deedBordersString = new StringBuilder();
StringBuilder deedMarkersString = new StringBuilder();

System.out.println("Loading deeds from wurmzones.db...");

Statement statement = MapBuilder.dbhandler.getZonesConnection().createStatement();
ResultSet resultSet = statement.executeQuery("SELECT * FROM VILLAGES WHERE DISBANDED=0;");

mainDeedString += ("function setViewOnMainDeed(map) {" + newLine);

deedBordersString += ("function deedBorders() {" + newLine);
deedBordersString += ("\tvar deedBorders = [];" + newLine);

deedMarkersString += ("function deedMarkers() {" + newLine);
deedMarkersString += ("\tvar deedMarkers = [];" + newLine);
mainDeedString.append("function setViewOnMainDeed(map) {" + newLine);
deedBordersString.append("function deedBorders() {" + newLine
+ "\tvar deedBorders = [];" + newLine);
deedMarkersString.append("function deedMarkers() {" + newLine
+ "\tvar deedMarkers = [];" + newLine);

double mainX = 0;
double mainY = 0;
Expand All @@ -167,65 +168,71 @@ public void generateDeedsFile() throws IOException, SQLException {
int ey = resultSet.getInt("ENDY");
double x = (sx + ex + 1) / 2;
double y = (sy + ey + 1) / 2;
deedBordersString += ("\tdeedBorders.push(L.polygon([");
deedBordersString += ("xy("+sx+","+sy+"),");
deedBordersString += ("xy("+(ex+1)+","+sy+"),");
deedBordersString += ("xy("+(ex+1)+","+(ey+1)+"),");
deedBordersString += ("xy("+sx+","+(ey+1)+")]");

deedBordersString.append("\tdeedBorders.push(L.polygon(["
+ "xy("+sx+","+sy+"),"
+ "xy("+(ex+1)+","+sy+"),"
+ "xy("+(ex+1)+","+(ey+1)+"),"
+ "xy("+sx+","+(ey+1)+")]");

boolean perm = resultSet.getBoolean("PERMANENT");

if (perm) {
deedBordersString += (", {color:'orange',fillOpacity:0,weight:1})");
deedBordersString.append(", {color:'orange',fillOpacity:0,weight:1})");
if (mainX == 0 && mainY == 0) {
mainX = x;
mainY = y;
mainDeedString += ("\tmap.setView(xy("+mainX+","+mainY+"), config.mapMaxZoom-1)" + newLine);
mainDeedString.append("\tmap.setView(xy("+mainX+","+mainY+"), config.mapMaxZoom-1)" + newLine);
}
} else {
deedBordersString += (", {color:'white',fillOpacity:0,weight:1})");
deedBordersString.append(", {color:'white',fillOpacity:0,weight:1})");
}
deedBordersString += (".bindPopup(\"" + resultSet.getString("NAME") + "\"));" + newLine);
deedBordersString.append(".bindPopup(\"" + resultSet.getString("NAME") + "\"));" + newLine);

String firstLetter = resultSet.getString("NAME").substring(0, 1).toLowerCase();
deedMarkersString += ("\tdeedMarkers.push(L.marker(");
deedMarkersString += ("xy("+(x+0.5)+","+(y+0.5)+"),");
deedMarkersString.append("\tdeedMarkers.push(L.marker("
+ "xy("+(x+0.5)+","+(y+0.5)+"),");
if (perm) {
deedMarkersString += ("{icon: mainIcon})");
deedMarkersString.append("{icon: mainIcon})");
} else {
deedMarkersString += ("{icon: letter_"+firstLetter+"Icon})");
deedMarkersString.append("{icon: letter_"+firstLetter+"Icon})");
}
deedMarkersString += (".bindPopup(\""+resultSet.getString("NAME")+"\"));" + newLine);
deedMarkersString.append(".bindPopup(\""+resultSet.getString("NAME")+"\"));" + newLine);
count++;
}
System.out.println("Added "+count+" deeds to deeds.js...");
deedBordersString += ("\treturn deedBorders;" + newLine);
deedBordersString += ("}" + newLine + newLine);
deedMarkersString += ("\treturn deedMarkers;" + newLine);
deedMarkersString += ("}");
mainDeedString += ("}" + newLine + newLine);

resultSet.close();
statement.close();

mainDeedString.append("}" + newLine + newLine);
deedBordersString.append("\treturn deedBorders;" + newLine + "}" + newLine + newLine);
deedMarkersString.append("\treturn deedMarkers;" + newLine + "}");

bw.append(mainDeedString);
bw.append(deedBordersString);
bw.append(deedMarkersString);

bw.close();

System.out.println("Added "+count+" deeds to deeds.js...");
}

public void generateConfigFile() throws IOException {
System.out.println("Writing config.js file...");
BufferedWriter bw = new BufferedWriter(new FileWriter(MapBuilder.propertiesManager.saveLocation.getAbsolutePath() + separator + "includes" + separator + "config.js", false));
bw.append("function Config() {}" + newLine);
bw.append("var config = new Config();" + newLine);
bw.append("config.nativeZoom = "+html_nativeZoom+";" + newLine);
bw.append("config.mapMinZoom = "+html_mapMinZoom+";" + newLine);
bw.append("config.mapMaxZoom = "+html_mapMaxZoom+";" + newLine);
bw.append("config.actualMapSize = "+html_actualMapSize+";" + newLine);
bw.append("config.maxMapSize = "+html_maxMapSize+";" + newLine);
bw.append("" + newLine);
bw.append("var xyMulitiplier = (config.actualMapSize / 256);" + newLine);
bw.append("" + newLine);
bw.append("var yx = L.latLng;" + newLine);
bw.append("var xy = function(x, y) {" + newLine);
bw.append("\treturn yx(-(y / xyMulitiplier), (x / xyMulitiplier));" + newLine);
bw.append("};");
bw.append("function Config() {}" + newLine
+ "var config = new Config();" + newLine
+ "config.nativeZoom = "+html_nativeZoom+";" + newLine
+ "config.mapMinZoom = "+html_mapMinZoom+";" + newLine
+ "config.mapMaxZoom = "+html_mapMaxZoom+";" + newLine
+ "config.actualMapSize = "+html_actualMapSize+";" + newLine
+ "config.maxMapSize = "+html_maxMapSize+";" + newLine
+ newLine
+ "var xyMulitiplier = (config.actualMapSize / 256);" + newLine
+ newLine
+ "var yx = L.latLng;" + newLine
+ "var xy = function(x, y) {" + newLine
+ "\treturn yx(-(y / xyMulitiplier), (x / xyMulitiplier));" + newLine
+ "};");
bw.close();
}

Expand All @@ -245,7 +252,7 @@ public void setHTMLvars(MeshIO map) {
html_mapMaxZoom = count;
count++;
}
html_mapMinZoom = 1;
html_mapMinZoom = (html_mapMaxZoom - 5);
}

}
3 changes: 3 additions & 0 deletions src/com/imraginbro/wurm/mapgen/filegen/FileManagement.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ public void makeTempCopies() {
new File(MapBuilder.propertiesManager.saveLocation.getAbsolutePath() + separator + "tmp").mkdirs();
for (int i = 0; i < fileBackupArray.length; i++) {
final File old = fileBackupArray[i];
if (!old.exists()) {
continue;
}
System.out.println("Creating a temp copy of "+old.getName()+"...");
try {
copyFile(old, new File(MapBuilder.propertiesManager.saveLocation.getAbsolutePath() + separator + "tmp" + separator + old.getName()));
Expand Down
Loading

0 comments on commit 03178a8

Please sign in to comment.