mirror of
				https://github.com/simon987/Much-Assembly-Required.git
				synced 2025-10-31 16:26:51 +00:00 
			
		
		
		
	Compare commits
	
		
			14 Commits
		
	
	
		
			714fdff60c
			...
			4e5d6e97c7
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 4e5d6e97c7 | ||
| ac374f5b52 | |||
|  | d01eac646f | ||
|  | 2ee98a8439 | ||
|  | a92256008c | ||
|  | 678b56c2dd | ||
|  | 3b12e2aeca | ||
|  | 0c3a3f06f0 | ||
|  | 2aeca6c9ce | ||
|  | 3c16bd3f30 | ||
|  | a3c4c33300 | ||
|  | 72ea92ffb3 | ||
|  | f526f369c4 | ||
|  | e97770f860 | 
| @ -20,33 +20,25 @@ public class WorldUtils { | |||||||
|         int blobCount = random.nextInt(maxCount - minCount) + minCount; |         int blobCount = random.nextInt(maxCount - minCount) + minCount; | ||||||
|         ArrayList<BiomassBlob> biomassBlobs = new ArrayList<>(blobCount); |         ArrayList<BiomassBlob> biomassBlobs = new ArrayList<>(blobCount); | ||||||
| 
 | 
 | ||||||
|         //Count number of plain tiles. If there is less plain tiles than desired amount of blobs, |         // Count number of plain tiles. If there is less plain tiles than desired amount | ||||||
|  |         // of blobs, | ||||||
|         // set the desired amount of blobs to the plain tile count |         // set the desired amount of blobs to the plain tile count | ||||||
|         TileMap m = world.getTileMap(); |         TileMap m = world.getTileMap(); | ||||||
|         int plainCount = 0; |         int plainCount = world.getCount(TilePlain.ID); | ||||||
|         for (int y = 0; y < world.getWorldSize(); y++) { |  | ||||||
|             for (int x = 0; x < world.getWorldSize(); x++) { |  | ||||||
| 
 |  | ||||||
|                 if (m.getTileIdAt(x, y) == TilePlain.ID) { |  | ||||||
|                     plainCount++; |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
| 
 | 
 | ||||||
|         if (blobCount > plainCount) { |         if (blobCount > plainCount) { | ||||||
|             blobCount = plainCount; |             blobCount = plainCount; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         outerLoop: |         outerLoop: for (int i = 0; i < blobCount; i++) { | ||||||
|         for (int i = 0; i < blobCount; i++) { |  | ||||||
| 
 | 
 | ||||||
|             Point p = m.getRandomTile(TilePlain.ID); |             Point p = m.getRandomTile(TilePlain.ID); | ||||||
|             if (p != null) { |             if (p != null) { | ||||||
| 
 | 
 | ||||||
|                 // Don't block worlds |                 // Don't block worlds | ||||||
|                 int counter = 0; |                 int counter = 0; | ||||||
|                 while (p.x == 0 || p.y == 0 || p.x == world.getWorldSize() - 1 || p.y == world.getWorldSize() - 1 || |                 while (p.x == 0 || p.y == 0 || p.x == world.getWorldSize() - 1 || p.y == world.getWorldSize() - 1 | ||||||
|                         world.getGameObjectsAt(p.x, p.y).size() != 0) { |                         || world.getGameObjectsAt(p.x, p.y).size() != 0) { | ||||||
|                     p = m.getRandomTile(TilePlain.ID); |                     p = m.getRandomTile(TilePlain.ID); | ||||||
|                     counter++; |                     counter++; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -0,0 +1,176 @@ | |||||||
|  | package net.simon987.pluginradioactivecloud; | ||||||
|  | 
 | ||||||
|  | import java.util.ArrayList; | ||||||
|  | 
 | ||||||
|  | import org.bson.Document; | ||||||
|  | import net.simon987.server.assembly.HardwareModule; | ||||||
|  | import net.simon987.server.assembly.Status; | ||||||
|  | import net.simon987.server.game.objects.ControllableUnit; | ||||||
|  | import net.simon987.server.game.objects.GameObject; | ||||||
|  | import net.simon987.server.game.objects.Radioactive; | ||||||
|  | 
 | ||||||
|  | public class RadiationDetector extends HardwareModule { | ||||||
|  | 
 | ||||||
|  |   /** | ||||||
|  |    * Should be unique and same as HWID | ||||||
|  |    */ | ||||||
|  |   public static final int DEFAULT_ADDRESS = 0x000E; | ||||||
|  | 
 | ||||||
|  |   /** | ||||||
|  |    * Hardware ID (Should be unique) | ||||||
|  |    */ | ||||||
|  |   public static final char HWID = 0x000E; | ||||||
|  | 
 | ||||||
|  |   /** | ||||||
|  |    * Radiation Constants | ||||||
|  |    */ | ||||||
|  |   private static final int ALPHA_BLOCKED_VALUE = 5; | ||||||
|  |   private static final int BETA_BLOCKED_VALUE = 2; | ||||||
|  |   private static final int GAMMA_BLOCKED_VALUE = 1; | ||||||
|  | 
 | ||||||
|  |   /** | ||||||
|  |    * Helper class for getTiles | ||||||
|  |    */ | ||||||
|  |   private class Tuple { | ||||||
|  |     public final int x; | ||||||
|  |     public final int y; | ||||||
|  | 
 | ||||||
|  |     public Tuple(int x, int y) { | ||||||
|  |       this.x = x; | ||||||
|  |       this.y = y; | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   /** | ||||||
|  |    * Finds the tiles between the two tiles located at the given coordinates. The | ||||||
|  |    * tiles located at the coordinates are not included in the list. | ||||||
|  |    *  | ||||||
|  |    * @param x0 x-coordinate of first point | ||||||
|  |    * @param y0 y-coordinate of first point | ||||||
|  |    * @param x1 x-coordinate of second point | ||||||
|  |    * @param y1 y-coordinate of second point | ||||||
|  |    * @return List of tile coordinates. An empty list indicates tiles are next to | ||||||
|  |    *         each other. | ||||||
|  |    */ | ||||||
|  |   public ArrayList<Tuple> getTiles(int x0, int y0, int x1, int y1) { | ||||||
|  | 
 | ||||||
|  |     ArrayList<Tuple> ret = new ArrayList<>(); | ||||||
|  |     double slope; | ||||||
|  |     if (x1 > x0) { | ||||||
|  |       slope = (y1 - y0) / (double) (x1 - x0); | ||||||
|  |     } else { | ||||||
|  |       slope = (y0 - y1) / (double) (x0 - x1); | ||||||
|  | 
 | ||||||
|  |       // Swap values so that x0 < x1. This preps the following code where y is | ||||||
|  |       // determined by adding a step value (1) to x0 till it reaches x1. | ||||||
|  |       int tmp = x1; | ||||||
|  |       x1 = x0; | ||||||
|  |       x0 = tmp; | ||||||
|  | 
 | ||||||
|  |       tmp = y1; | ||||||
|  |       y1 = y0; | ||||||
|  |       y0 = tmp; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     // If slope is zero or undefined, return tiles directly along the | ||||||
|  |     // appropriate cardinal direction. | ||||||
|  |     if (x0 == x1) { | ||||||
|  |       int smaller = Math.min(y0, y1); | ||||||
|  |       int larger = Math.max(y0, y1); | ||||||
|  |       System.out.printf("%d %d", smaller, larger); | ||||||
|  |       for (int i = smaller + 1; i < larger; i++) { | ||||||
|  |         ret.add(new Tuple(x0, i)); | ||||||
|  |       } | ||||||
|  |     } else if (y0 == y1) { | ||||||
|  |       int smaller = Math.min(x0, x1); | ||||||
|  |       int larger = Math.max(x0, x1); | ||||||
|  |       for (int i = smaller + 1; i < larger; i++) { | ||||||
|  |         ret.add(new Tuple(i, y0)); | ||||||
|  |       } | ||||||
|  |     } else { | ||||||
|  |       // Find all coordinates with 0.1 step | ||||||
|  |       int lastX = x0; | ||||||
|  |       int lastY = y0; | ||||||
|  |       for (int i = x0 * 10; i < x1 * 10; i += 1) { | ||||||
|  |         if (i / 10 != lastX || (int) (slope * i / 10) != lastY) { | ||||||
|  |           // Update last values | ||||||
|  |           lastX = i / 10; | ||||||
|  |           lastY = (int) (slope * i / 10); | ||||||
|  | 
 | ||||||
|  |           // Add new values to array | ||||||
|  |           ret.add(new Tuple(lastX, lastY)); | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     return ret; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   /** | ||||||
|  |    * Finds the Euclidean Distance between two coordinates. | ||||||
|  |    *  | ||||||
|  |    * @param x0 x-coordinate of first point | ||||||
|  |    * @param y0 y-coordinate of first point | ||||||
|  |    * @param x1 x-coordinate of second point | ||||||
|  |    * @param y1 y-coordinate of second point | ||||||
|  |    * @return distance between two points | ||||||
|  |    */ | ||||||
|  |   public double getDistanceOfCoords(int x0, int y0, int x1, int y1) { | ||||||
|  |     return Math.sqrt(Math.pow(x1 - x0, 2) + Math.pow(y1 - y0, 2)); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   public RadiationDetector(ControllableUnit unit) { | ||||||
|  |     super(null, unit); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   public RadiationDetector(Document document, ControllableUnit cubot) { | ||||||
|  |     super(document, cubot); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   @Override | ||||||
|  |   public void handleInterrupt(Status status) { | ||||||
|  | 
 | ||||||
|  |     // Find all game entities in world | ||||||
|  |     ArrayList<GameObject> entities = new ArrayList<>(unit.getWorld().getGameObjects()); | ||||||
|  | 
 | ||||||
|  |     // Check for alpha particles by finding Radioactive entities | ||||||
|  |     int alphaParticles = 0; | ||||||
|  |     int betaParticles = 0; | ||||||
|  |     int gammaParticles = 0; | ||||||
|  |     for (GameObject entity : entities) { | ||||||
|  |       if (entity instanceof Radioactive) { | ||||||
|  |         // Calculate distance between object and cubot | ||||||
|  |         double pathLength = getDistanceOfCoords(unit.getX(), unit.getY(), entity.getX(), entity.getY()); | ||||||
|  |         alphaParticles += ((Radioactive) entity).getAlphaCounts(pathLength); | ||||||
|  |         betaParticles += ((Radioactive) entity).getBetaCounts(pathLength); | ||||||
|  |         gammaParticles += ((Radioactive) entity).getGammaCounts(pathLength); | ||||||
|  | 
 | ||||||
|  |         // Get all tiles in between cubot and Radioactive entity | ||||||
|  |         ArrayList<Tuple> tiles = getTiles(unit.getX(), unit.getY(), entity.getX(), entity.getY()); | ||||||
|  |         for (Tuple tup : tiles) { | ||||||
|  |           // If intermediary tile is blocked, reduce alphaParticles by 5 | ||||||
|  |           if (unit.getWorld().isTileBlocked(tup.x, tup.y)) { | ||||||
|  |             alphaParticles -= ALPHA_BLOCKED_VALUE; | ||||||
|  |             betaParticles -= BETA_BLOCKED_VALUE; | ||||||
|  |             gammaParticles -= GAMMA_BLOCKED_VALUE; | ||||||
|  |           } | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     // Save Alpha Radioactive Particles to register A | ||||||
|  |     getCpu().getRegisterSet().getRegister("A").setValue(alphaParticles); | ||||||
|  | 
 | ||||||
|  |     // Save Beta Radioactive Particles to register B | ||||||
|  |     getCpu().getRegisterSet().getRegister("B").setValue(betaParticles); | ||||||
|  | 
 | ||||||
|  |     // Save Gamma Radioactive Particles to register C | ||||||
|  |     getCpu().getRegisterSet().getRegister("C").setValue(gammaParticles); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   @Override | ||||||
|  |   public char getId() { | ||||||
|  |     return HWID; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  | } | ||||||
| @ -0,0 +1,69 @@ | |||||||
|  | package net.simon987.pluginradioactivecloud; | ||||||
|  | 
 | ||||||
|  | import net.simon987.server.game.world.TileMap; | ||||||
|  | import net.simon987.server.game.world.TilePlain; | ||||||
|  | import net.simon987.server.game.world.World; | ||||||
|  | import org.bson.types.ObjectId; | ||||||
|  | 
 | ||||||
|  | import java.awt.*; | ||||||
|  | import java.util.ArrayList; | ||||||
|  | import java.util.Random; | ||||||
|  | 
 | ||||||
|  | public class RadioactiveWorldUtils { | ||||||
|  | 
 | ||||||
|  |   /** | ||||||
|  |    * Generate a list of radioactive obstacles for a world | ||||||
|  |    */ | ||||||
|  |   public static ArrayList<RadioactiveObstacle> generateRadioactiveObstacles(World world, int minCount, int maxCount) { | ||||||
|  | 
 | ||||||
|  |     Random random = new Random(); | ||||||
|  |     int radioactiveObjCount = random.nextInt(maxCount - minCount) + minCount; | ||||||
|  |     ArrayList<RadioactiveObstacle> radioactiveObstacles = new ArrayList<>(radioactiveObjCount); | ||||||
|  | 
 | ||||||
|  |     // Count number of plain tiles. If there is less plain tiles than desired amount | ||||||
|  |     // of radioactive objects, set the desired amount of radioactive objects to the | ||||||
|  |     // plain tile count | ||||||
|  |     TileMap m = world.getTileMap(); | ||||||
|  |     int plainCount = world.getCount(TilePlain.ID); | ||||||
|  | 
 | ||||||
|  |     if (radioactiveObjCount > plainCount) { | ||||||
|  |       radioactiveObjCount = plainCount; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     outerLoop: for (int i = 0; i < radioactiveObjCount; i++) { | ||||||
|  | 
 | ||||||
|  |       Point p = m.getRandomTile(TilePlain.ID); | ||||||
|  |       if (p != null) { | ||||||
|  | 
 | ||||||
|  |         // Don't block worlds | ||||||
|  |         int counter = 0; | ||||||
|  |         while (p.x == 0 || p.y == 0 || p.x == world.getWorldSize() - 1 || p.y == world.getWorldSize() - 1 | ||||||
|  |             || world.getGameObjectsAt(p.x, p.y).size() != 0) { | ||||||
|  |           p = m.getRandomTile(TilePlain.ID); | ||||||
|  |           counter++; | ||||||
|  | 
 | ||||||
|  |           if (counter > 25) { | ||||||
|  |             continue outerLoop; | ||||||
|  |           } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         for (RadioactiveObstacle radioactiveObstacle : radioactiveObstacles) { | ||||||
|  |           if (radioactiveObstacle.getX() == p.x && radioactiveObstacle.getY() == p.y) { | ||||||
|  |             // There is already a blob here | ||||||
|  |             continue outerLoop; | ||||||
|  |           } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         RadioactiveObstacle radioactiveObstacle = new RadioactiveObstacle(); | ||||||
|  |         radioactiveObstacle.setObjectId(new ObjectId()); | ||||||
|  |         radioactiveObstacle.setX(p.x); | ||||||
|  |         radioactiveObstacle.setY(p.y); | ||||||
|  |         radioactiveObstacle.setWorld(world); | ||||||
|  | 
 | ||||||
|  |         radioactiveObstacles.add(radioactiveObstacle); | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     return radioactiveObstacles; | ||||||
|  |   } | ||||||
|  | } | ||||||
| @ -0,0 +1,32 @@ | |||||||
|  | package net.simon987.pluginradioactivecloud.event; | ||||||
|  | 
 | ||||||
|  | import net.simon987.pluginradioactivecloud.RadioactiveObstacle; | ||||||
|  | import net.simon987.pluginradioactivecloud.RadioactiveWorldUtils; | ||||||
|  | import net.simon987.server.GameServer; | ||||||
|  | import net.simon987.server.event.GameEvent; | ||||||
|  | import net.simon987.server.event.GameEventListener; | ||||||
|  | import net.simon987.server.event.WorldGenerationEvent; | ||||||
|  | 
 | ||||||
|  | import java.util.ArrayList; | ||||||
|  | 
 | ||||||
|  | public class WorldCreationListener implements GameEventListener { | ||||||
|  |     @Override | ||||||
|  |     public Class getListenedEventType() { | ||||||
|  |         return WorldGenerationEvent.class; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void handle(GameEvent event) { | ||||||
|  | 
 | ||||||
|  |         int minCount = GameServer.INSTANCE.getConfig().getInt("min_radioactive_obstacle_count"); | ||||||
|  |         int maxCount = GameServer.INSTANCE.getConfig().getInt("max_radioactive_obstacle_count"); | ||||||
|  | 
 | ||||||
|  |         ArrayList<RadioactiveObstacle> radioactiveObstacles = RadioactiveWorldUtils | ||||||
|  |                 .generateRadioactiveObstacles(((WorldGenerationEvent) event).getWorld(), minCount, maxCount); | ||||||
|  | 
 | ||||||
|  |         for (RadioactiveObstacle radioactiveObstacle : radioactiveObstacles) { | ||||||
|  |             ((WorldGenerationEvent) event).getWorld().addObject(radioactiveObstacle); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -1,4 +1,4 @@ | |||||||
| ### [Official website](https://muchassemblyrequired.com) | # Much-Assembly-Required | ||||||
| 
 | 
 | ||||||
| [](https://www.codefactor.io/repository/github/simon987/much-assembly-required) | [](https://www.codefactor.io/repository/github/simon987/much-assembly-required) | ||||||
| [](https://ci.simon987.net/job/Much-Assembly-Required/) | [](https://ci.simon987.net/job/Much-Assembly-Required/) | ||||||
|  | |||||||
| @ -6,5 +6,15 @@ package net.simon987.server.game.objects; | |||||||
| 
 | 
 | ||||||
| public interface Radioactive { | public interface Radioactive { | ||||||
| 
 | 
 | ||||||
| 
 |   public default int getAlphaCounts(double distance) { | ||||||
|  |     return (int) (1000 * 1.0 / (distance * distance)); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   public default int getBetaCounts(double distance) { | ||||||
|  |     return (int) (2000 * 1.0 / (distance * distance)); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   public default int getGammaCounts(double distance) { | ||||||
|  |     return (int) (5000 * 1.0 / (distance * distance)); | ||||||
|  |   } | ||||||
| } | } | ||||||
|  | |||||||
| @ -61,7 +61,8 @@ public class World implements MongoSerializable { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Check if a tile is blocked, either by a game object or an impassable tile type |      * Check if a tile is blocked, either by a game object or an impassable tile | ||||||
|  |      * type | ||||||
|      */ |      */ | ||||||
|     public boolean isTileBlocked(int x, int y) { |     public boolean isTileBlocked(int x, int y) { | ||||||
|         return getGameObjectsBlockingAt(x, y).size() > 0 || tileMap.getTileAt(x, y).isBlocked(); |         return getGameObjectsBlockingAt(x, y).size() > 0 || tileMap.getTileAt(x, y).isBlocked(); | ||||||
| @ -136,8 +137,7 @@ public class World implements MongoSerializable { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Update this World and its GameObjects |      * Update this World and its GameObjects <br> | ||||||
|      * <br> |  | ||||||
|      * The update is handled by plugins first |      * The update is handled by plugins first | ||||||
|      */ |      */ | ||||||
|     public void update() { |     public void update() { | ||||||
| @ -151,7 +151,8 @@ public class World implements MongoSerializable { | |||||||
|             if (object.isDead()) { |             if (object.isDead()) { | ||||||
|                 if (!object.onDeadCallback()) { |                 if (!object.onDeadCallback()) { | ||||||
|                     removeObject(object); |                     removeObject(object); | ||||||
|                     //LogManager.LOGGER.fine("Removed object " + object + " id: " + object.getObjectId()); |                     // LogManager.LOGGER.fine("Removed object " + object + " id: " + | ||||||
|  |                     // object.getObjectId()); | ||||||
|                 } else if (object instanceof Updatable) { |                 } else if (object instanceof Updatable) { | ||||||
|                     ((Updatable) object).update(); |                     ((Updatable) object).update(); | ||||||
|                 } |                 } | ||||||
| @ -231,11 +232,11 @@ public class World implements MongoSerializable { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Get a binary representation of the map as an array of 16-bit bit fields, one word for each |      * Get a binary representation of the map as an array of 16-bit bit fields, one | ||||||
|      * tile. |      * word for each tile. | ||||||
|      * <p> |      * <p> | ||||||
|      * Each tile is represented as such: <code>OOOOOOOOTTTTTTTB</code> where O is the object, |      * Each tile is represented as such: <code>OOOOOOOOTTTTTTTB</code> where O is | ||||||
|      * T the tile and B if the tile is blocked or not |      * the object, T the tile and B if the tile is blocked or not | ||||||
|      */ |      */ | ||||||
|     public char[][] getMapInfo() { |     public char[][] getMapInfo() { | ||||||
| 
 | 
 | ||||||
| @ -252,7 +253,8 @@ public class World implements MongoSerializable { | |||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         for (GameObject obj : gameObjects.values()) { |         for (GameObject obj : gameObjects.values()) { | ||||||
|             //Overwrite, only the last object on a tile is considered but the blocked bit is kept |             // Overwrite, only the last object on a tile is considered but the blocked bit | ||||||
|  |             // is kept | ||||||
|             mapInfo[obj.getX()][obj.getY()] &= 0x00FE; |             mapInfo[obj.getX()][obj.getY()] &= 0x00FE; | ||||||
|             mapInfo[obj.getX()][obj.getY()] |= obj.getMapInfo(); |             mapInfo[obj.getX()][obj.getY()] |= obj.getMapInfo(); | ||||||
|         } |         } | ||||||
| @ -261,12 +263,11 @@ public class World implements MongoSerializable { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Get a random tile that is empty and passable |      * Get a random tile that is empty and passable The function ensures that a | ||||||
|      * The function ensures that a object spawned there will not be trapped |      * object spawned there will not be trapped and will be able to leave the World | ||||||
|      * and will be able to leave the World |  | ||||||
|      * <br> |      * <br> | ||||||
|      * Note: This function is quite expensive and shouldn't be used |      * Note: This function is quite expensive and shouldn't be used by some | ||||||
|      * by some HardwareModule in its current state |      * HardwareModule in its current state | ||||||
|      * |      * | ||||||
|      * @return random non-blocked tile |      * @return random non-blocked tile | ||||||
|      */ |      */ | ||||||
| @ -318,10 +319,9 @@ public class World implements MongoSerializable { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Get the list of game objects that are exactly at a given location |      * Get the list of game objects that are exactly at a given location <br> | ||||||
|      * <br> |      * Note: Objects like the Factory that are more than 1x1 tiles wide will only be | ||||||
|      * Note: Objects like the Factory that are more than 1x1 tiles wide will only be returned |      * returned when their exact coordinates are specified | ||||||
|      * when their exact coordinates are specified |  | ||||||
|      * |      * | ||||||
|      * @param x X coordinate on the World |      * @param x X coordinate on the World | ||||||
|      * @param y Y coordinate on the World |      * @param y Y coordinate on the World | ||||||
| @ -355,7 +355,6 @@ public class World implements MongoSerializable { | |||||||
|         return worldSize; |         return worldSize; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|     private GameUniverse universe = null; |     private GameUniverse universe = null; | ||||||
| 
 | 
 | ||||||
|     public void setUniverse(GameUniverse universe) { |     public void setUniverse(GameUniverse universe) { | ||||||
| @ -403,6 +402,24 @@ public class World implements MongoSerializable { | |||||||
|         return gameObjects.values(); |         return gameObjects.values(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /** | ||||||
|  |      * Find the number of tiles of a given type on the world. | ||||||
|  |      *  | ||||||
|  |      * @param tileId id of tile | ||||||
|  |      * @return number of occurrences | ||||||
|  |      */ | ||||||
|  |     public int getCount(int tileId) { | ||||||
|  |         int tileCount = 0; | ||||||
|  |         for (int y = 0; y < getWorldSize(); y++) { | ||||||
|  |             for (int x = 0; x < getWorldSize(); x++) { | ||||||
|  |                 if (tileMap.getTileIdAt(x, y) == tileId) { | ||||||
|  |                     tileCount++; | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return tileCount; | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Get a random tile with N adjacent non-blocked tile |      * Get a random tile with N adjacent non-blocked tile | ||||||
| @ -428,7 +445,8 @@ public class World implements MongoSerializable { | |||||||
|                 int adjacentTiles = 0; |                 int adjacentTiles = 0; | ||||||
| 
 | 
 | ||||||
|                 for (int idx = 0; idx < xPositions.length; idx++) { |                 for (int idx = 0; idx < xPositions.length; idx++) { | ||||||
|                     if (tileMap.isInBounds(rTile.x + xPositions[idx], rTile.y + yPositions[idx]) && !isTileBlocked(rTile.x + xPositions[idx], rTile.y + yPositions[idx])) { |                     if (tileMap.isInBounds(rTile.x + xPositions[idx], rTile.y + yPositions[idx]) | ||||||
|  |                             && !isTileBlocked(rTile.x + xPositions[idx], rTile.y + yPositions[idx])) { | ||||||
|                         adjacentTiles++; |                         adjacentTiles++; | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|  | |||||||
| @ -94,6 +94,8 @@ electric_box_energy_given=70 | |||||||
| #RadioactiveObstacle | #RadioactiveObstacle | ||||||
| radioactive_obstacle_corruption_block_size=10 | radioactive_obstacle_corruption_block_size=10 | ||||||
| radioactive_cloud_corruption_block_size=40 | radioactive_cloud_corruption_block_size=40 | ||||||
|  | min_radioactive_obstacle_count=0 | ||||||
|  | max_radioactive_obstacle_count=1 | ||||||
| 
 | 
 | ||||||
| #SecretKey | #SecretKey | ||||||
| secret_key=<your_secret_key> | secret_key=<your_secret_key> | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user