Prechádzať zdrojové kódy

Just Another Useless Commit: world dimensions unhardcoded and can be set from config.
Geodata and pathnode files validity check.

_DS_ 15 rokov pred
rodič
commit
c0f2701d61

+ 8 - 0
L2_GameServer/java/com/l2jserver/Config.java

@@ -432,6 +432,10 @@ public final class Config
 	public static boolean GRIDS_ALWAYS_ON;
 	public static int GRID_NEIGHBOR_TURNON_TIME;
 	public static int GRID_NEIGHBOR_TURNOFF_TIME;
+	public static int WORLD_X_MIN;
+	public static int WORLD_X_MAX;
+	public static int WORLD_Y_MIN;
+	public static int WORLD_Y_MAX;
 	public static int GEODATA;
 	public static boolean GEODATA_CELLFINDING;
 	public static boolean FORCE_GEODATA;
@@ -1637,6 +1641,10 @@ public final class Config
 					GRIDS_ALWAYS_ON = Boolean.parseBoolean(General.getProperty("GridsAlwaysOn", "False"));
 					GRID_NEIGHBOR_TURNON_TIME = Integer.parseInt(General.getProperty("GridNeighborTurnOnTime", "1"));
 					GRID_NEIGHBOR_TURNOFF_TIME = Integer.parseInt(General.getProperty("GridNeighborTurnOffTime", "90"));
+					WORLD_X_MIN = Integer.parseInt(General.getProperty("WorldXMin", "11"));
+					WORLD_X_MAX = Integer.parseInt(General.getProperty("WorldXMax", "26"));
+					WORLD_Y_MIN = Integer.parseInt(General.getProperty("WorldYMin", "10"));
+					WORLD_Y_MAX = Integer.parseInt(General.getProperty("WorldYMax", "26"));
 					GEODATA = Integer.parseInt(General.getProperty("GeoData", "0"));
 					GEODATA_CELLFINDING = Boolean.parseBoolean(General.getProperty("CellPathFinding", "False"));
 					FORCE_GEODATA = Boolean.parseBoolean(General.getProperty("ForceGeodata", "True"));

+ 8 - 3
L2_GameServer/java/com/l2jserver/gameserver/GeoEngine.java

@@ -223,8 +223,8 @@ public class GeoEngine extends GeoData
 		int by = getBlock(gy);
 		int cx = getCell(gx);
 		int cy = getCell(gy);
-		int rx = (gx >> 11) + 10;
-		int ry = (gy >> 11) + 10;
+		int rx = (gx >> 11) + Config.WORLD_X_MIN;
+		int ry = (gy >> 11) + Config.WORLD_X_MAX;
 		String out = rx + ";" + ry + ";" + bx + ";" + by + ";" + cx + ";" + cy + ";" + gm.getZ() + ";" + comment + "\n";
 		try
 		{
@@ -701,6 +701,11 @@ public class GeoEngine extends GeoData
 	
 	public static boolean loadGeodataFile(byte rx, byte ry)
 	{
+		if (rx < Config.WORLD_X_MIN || rx > Config.WORLD_X_MAX || ry < Config.WORLD_Y_MIN || ry > Config.WORLD_Y_MAX)
+		{
+			_log.warning("Failed to Load GeoFile: invalid region " + rx +","+ ry + "\n");
+			return false;
+		}
 		String fname = "./data/geodata/" + rx + "_" + ry + ".l2j";
 		short regionoffset = (short) ((rx << 5) + ry);
 		_log.info("Geo Engine: - Loading: " + fname + " -> region offset: " + regionoffset + "X: " + rx + " Y: " + ry);
@@ -781,7 +786,7 @@ public class GeoEngine extends GeoData
 	{
 		int rx = x >> 11; // =/(256 * 8)
 		int ry = y >> 11;
-		return (short) (((rx + 10) << 5) + (ry + 10));
+		return (short) (((rx + Config.WORLD_X_MIN) << 5) + (ry + Config.WORLD_Y_MIN));
 	}
 	
 	/**

+ 9 - 6
L2_GameServer/java/com/l2jserver/gameserver/model/L2World.java

@@ -39,7 +39,7 @@ import javolution.util.FastMap;
 public final class L2World
 {
 	private static Logger _log = Logger.getLogger(L2World.class.getName());
-	
+
 	/*
 	* biteshift, defines number of regions
 	* note, shifting by 15 will result in regions corresponding to map tiles
@@ -48,11 +48,14 @@ public final class L2World
 	public static final int SHIFT_BY = 12;
 	
 	/** Map dimensions */
-	public static final int MAP_MIN_X = -327680;
-	public static final int MAP_MAX_X = 229376;
-	public static final int MAP_MIN_Y = -262144;
-	public static final int MAP_MAX_Y = 294912;
-	
+	public static final int MAP_MIN_X = (Config.WORLD_X_MIN - 20) << 15;
+	public static final int MAP_MAX_X = (Config.WORLD_X_MAX - 19) << 15;
+	public static final int MAP_MIN_Y = (Config.WORLD_Y_MIN - 18) << 15;
+	public static final int MAP_MAX_Y = (Config.WORLD_Y_MAX - 17) << 15;
+
+	public static final int WORLD_SIZE_X = Config.WORLD_X_MAX - Config.WORLD_X_MIN + 1;
+	public static final int WORLD_SIZE_Y = Config.WORLD_Y_MAX - Config.WORLD_Y_MIN + 1;
+
 	/** calculated offset used so top left region is 0,0 */
 	public static final int OFFSET_X = Math.abs(MAP_MIN_X >> SHIFT_BY);
 	public static final int OFFSET_Y = Math.abs(MAP_MIN_Y >> SHIFT_BY);

+ 2 - 2
L2_GameServer/java/com/l2jserver/gameserver/pathfinding/PathFinding.java

@@ -412,12 +412,12 @@ public abstract class PathFinding
 	
 	public byte getRegionX(int node_pos)
 	{
-		return (byte) ((node_pos >> 8) + 10);
+		return (byte) ((node_pos >> 8) + Config.WORLD_X_MIN);
 	}
 	
 	public byte getRegionY(int node_pos)
 	{
-		return (byte) ((node_pos >> 8) + 10);
+		return (byte) ((node_pos >> 8) + Config.WORLD_Y_MIN);
 	}
 	
 	public short getRegionOffset(byte rx, byte ry)

+ 5 - 0
L2_GameServer/java/com/l2jserver/gameserver/pathfinding/geonodes/GeoPathFinding.java

@@ -304,6 +304,11 @@ public class GeoPathFinding extends PathFinding
 	
 	private void LoadPathNodeFile(byte rx, byte ry)
 	{
+		if (rx < Config.WORLD_X_MIN || rx > Config.WORLD_X_MAX || ry < Config.WORLD_Y_MIN || ry > Config.WORLD_Y_MAX)
+		{
+			_log.warning("Failed to Load PathNode File: invalid region " + rx +","+ ry + "\n");
+			return;
+		}
 		String fname = "./data/pathnode/" + rx + "_" + ry + ".pn";
 		short regionoffset = getRegionOffset(rx, ry);
 		_log.info("PathFinding Engine: - Loading: " + fname + " -> region offset: " + regionoffset + "X: " + rx + " Y: " + ry);

+ 10 - 0
L2_GameServer/java/config/General.properties

@@ -300,6 +300,16 @@ GridNeighborTurnOnTime = 1
 GridNeighborTurnOffTime = 90
 
 
+# ---------------------------------------------------------------------------
+# World dimensions
+# ---------------------------------------------------------------------------
+# Min and max world regions (including)
+# Default: X:11-26, Y:10-26
+WorldXMin = 11
+WorldXMax = 26
+WorldYMin = 10
+WorldYMax = 26
+
 # ---------------------------------------------------------------------------
 # Geodata
 # ---------------------------------------------------------------------------