mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-04-19 18:46:43 +00:00
Add RadioactiveWorldUtils and refactor spacing in WorldUtils
This commit is contained in:
parent
3b12e2aeca
commit
678b56c2dd
@ -20,8 +20,9 @@ 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
|
||||||
//set the desired amount of blobs to the plain tile count
|
// of blobs,
|
||||||
|
// set the desired amount of blobs to the plain tile count
|
||||||
TileMap m = world.getTileMap();
|
TileMap m = world.getTileMap();
|
||||||
int plainCount = 0;
|
int plainCount = 0;
|
||||||
for (int y = 0; y < world.getWorldSize(); y++) {
|
for (int y = 0; y < world.getWorldSize(); y++) {
|
||||||
@ -37,16 +38,15 @@ public class WorldUtils {
|
|||||||
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++;
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ public class WorldUtils {
|
|||||||
|
|
||||||
for (BiomassBlob biomassBlob : biomassBlobs) {
|
for (BiomassBlob biomassBlob : biomassBlobs) {
|
||||||
if (biomassBlob.getX() == p.x && biomassBlob.getY() == p.y) {
|
if (biomassBlob.getX() == p.x && biomassBlob.getY() == p.y) {
|
||||||
//There is already a blob here
|
// There is already a blob here
|
||||||
continue outerLoop;
|
continue outerLoop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,77 @@
|
|||||||
|
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 biomass blobs 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 = 0;
|
||||||
|
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 (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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user