2
0
Эх сурвалжийг харах

Reworking of the inner-area generation

RedstoneFuture 2 жил өмнө
parent
commit
48cd50e0ca

+ 21 - 16
missilewars-plugin/src/main/java/de/butzlabben/missilewars/game/Game.java

@@ -714,33 +714,38 @@ public class Game {
     }
 
     private void createInnerGameArea() {
-
-        // If both spawn points are on the X coordinate, the "length" of the Inner Game-Area 
-        // is the distance on X and the "width" of the Inner Game-Area is the width of the 
-        // (major) GameArea. Otherwise, it is the other way around. It is therefore 
-        // independent of the rotation of the GameArea.
         
+        // Depending on the rotation of the (major) Game-Area, the spawn points 
+        // of both teams are primarily on the X or Z axis opposite each other.
+        // The Inner Game-Area is a copy of the (major) Game-Area, with the X or Z 
+        // axis going only to spawn. The X or Z distance is thus reduced.
+        // So this algorithm allows the spawn points to face each other even if 
+        // they are offset.
+
+        int x1, x2, z1, z2;
         Location position1, position2;
-        int spawnPos1, spawnPos2;
         
-        if (team1.getSpawn().getBlockX() == team2.getSpawn().getBlockX()) {
+        if (gameArea.getDirection() == GameArea.Direction.NORTH_SOUTH) {
             
-            spawnPos1 = team1.getSpawn().getBlockZ();
-            spawnPos2 = team2.getSpawn().getBlockZ();
+            x1 = gameArea.getMinX();
+            x2 = gameArea.getMaxX();
             
-            position1 = new Location(gameArea.getWorld(), gameArea.getMinX(), gameArea.getMinY(), spawnPos1);
-            position2 = new Location(gameArea.getWorld(), gameArea.getMaxX(), gameArea.getMaxY(), spawnPos2);
+            z1 = team1.getSpawn().getBlockZ();
+            z2 = team2.getSpawn().getBlockZ();
             
         } else {
-
-            spawnPos1 = team1.getSpawn().getBlockX();
-            spawnPos2 = team2.getSpawn().getBlockX();
             
-            position1 = new Location(gameArea.getWorld(), spawnPos1, gameArea.getMinY(), gameArea.getMinZ());
-            position2 = new Location(gameArea.getWorld(), spawnPos2, gameArea.getMaxY(), gameArea.getMaxZ());
+            z1 = gameArea.getMinZ();
+            z2 = gameArea.getMaxZ();
+            
+            x1 = team1.getSpawn().getBlockX();
+            x2 = team2.getSpawn().getBlockX();
             
         }
         
+        position1 = new Location(gameArea.getWorld(), x1, gameArea.getMinY(), z1);
+        position2 = new Location(gameArea.getWorld(), x2, gameArea.getMaxY(), z2);
+
         innerGameArea = new GameArea(position1, position2);
     }
 

+ 53 - 1
missilewars-plugin/src/main/java/de/butzlabben/missilewars/util/geometry/GameArea.java

@@ -33,6 +33,8 @@ public class GameArea {
     private int minX, minY, minZ;
     private int maxX, maxY, maxZ;
 
+    private Direction direction;
+    
     /**
      * This method creates a new GameArena object.
      *
@@ -111,10 +113,12 @@ public class GameArea {
      * This method calculates and saves the MIN and MAX positions 
      * according to the current values. The assigned MIN and MAX 
      * information can be used to later compare the GameArea more 
-     * easily with current live positions/areas.
+     * easily with current live positions/areas. In addition, the 
+     * area direction is calculated afterwards.
      */
     private void initialize() {
 
+        // Calculation of min & max X coordinate:
         if (position1.getBlockX() < position2.getBlockX()) {
             minX = position1.getBlockX();
             maxX = position2.getBlockX();
@@ -123,6 +127,7 @@ public class GameArea {
             minX = position2.getBlockX();
         }
 
+        // Calculation of min & max Y coordinate:
         if (position1.getBlockY() < position2.getBlockY()) {
             minY = position1.getBlockY();
             maxY = position2.getBlockY();
@@ -131,6 +136,7 @@ public class GameArea {
             minY = position2.getBlockY();
         }
 
+        // Calculation of min & max Z coordinate:
         if (position1.getBlockZ() < position2.getBlockZ()) {
             minZ = position1.getBlockZ();
             maxZ = position2.getBlockZ();
@@ -138,6 +144,13 @@ public class GameArea {
             maxZ = position1.getBlockZ();
             minZ = position2.getBlockZ();
         }
+
+        // Calculation of area direction:
+        if (getXSize() < getZSize()) {
+            direction = Direction.NORTH_SOUTH;
+        } else {
+            direction = Direction.EAST_WEST;
+        }
     }
 
     public AreaConfiguration getAreaConfiguration() {
@@ -146,4 +159,43 @@ public class GameArea {
         return newAreaConfig;
     }
 
+    /**
+     * This method defines the horizontal direction / rotation of the 
+     * area based on the alignment of the team spawn points.
+     * 
+     * NORTH-SOUTH = primarily along the Z axis
+     * EAST-WEST = primarily along the X axis
+     */
+    public enum Direction {
+        NORTH_SOUTH,
+        EAST_WEST
+    }
+
+    /**
+     * This method returns the arena length along the X coordinate.
+     * 
+     * @return (Integer) the X size
+     */
+    public int getXSize() {
+        return maxX - minX;
+    }
+
+    /**
+     * This method returns the arena length along the Y coordinate.
+     *
+     * @return (Integer) the Y size
+     */
+    public int getYSize() {
+        return maxY - minY;
+    }
+
+    /**
+     * This method returns the arena length along the Z coordinate.
+     *
+     * @return (Integer) the Z size
+     */
+    public int getZSize() {
+        return maxZ - minZ;
+    }
+    
 }