30 Commits

Author SHA1 Message Date
Khalid Ali
4e5d6e97c7 Merge 2ee98a8439 into ac374f5b52 2024-11-22 07:04:21 +00:00
ac374f5b52 Merge pull request #247 from nekojanai/remove-dead-uri
Remove dead URI muchassemblyrequired.com
2024-10-23 20:37:03 -04:00
nekojanai
d01eac646f Update README.md
The website muchassemblyrequired.com no longer points to anything related to this repo.

I suggest also removing the URI from the description.
2024-10-23 20:53:42 +02:00
35b48ddd95 Merge pull request #243 from mavlushechka/master
Update installation guide on Arch Linux
2022-05-01 14:11:43 -04:00
Mavlon
5a0c5b6911 Update installation guide on Arch Linux
Change the package manager from pacman to yay which installs mongodb.

Beginning with January 2019 mongodb package is not available in the official Arch repositories and can't be installed using pacman. Instead of pacman you can use yay to compile mongodb or install prebuilt mongodb-bin. To compile mongodb you should have 260 GB available on your hard disk, so mongodb-bin is easier to install.

As a result, guide is now correct for Arch Linux users.
2022-05-01 16:41:52 +05:00
a85e672eb9 Update docker-compose.yml 2021-03-20 09:59:13 -04:00
053d3e35ec Merge pull request #238 from simon987/dependabot/maven/Server/junit-junit-4.13.1
Bump junit from 4.12 to 4.13.1 in /Server
2020-10-28 21:29:13 -04:00
dependabot[bot]
35140cc834 Bump junit from 4.12 to 4.13.1 in /Server
Bumps [junit](https://github.com/junit-team/junit4) from 4.12 to 4.13.1.
- [Release notes](https://github.com/junit-team/junit4/releases)
- [Changelog](https://github.com/junit-team/junit4/blob/main/doc/ReleaseNotes4.12.md)
- [Commits](https://github.com/junit-team/junit4/compare/r4.12...r4.13.1)

Signed-off-by: dependabot[bot] <support@github.com>
2020-10-13 04:57:43 +00:00
6a9c656e66 Merge pull request #237 from helloausrine/master
DOC: Improvements
2020-10-03 18:58:01 -04:00
helloausrine
d07a59607f Update README.md 2020-10-03 18:10:38 +10:00
Khalid Ali
2ee98a8439 Added getCount() method to World 2020-09-18 10:07:57 -04:00
Khalid Ali
a92256008c Added Radioactive Obstacle to map with WorldCreationListener 2020-09-17 23:47:19 -04:00
Khalid Ali
678b56c2dd Add RadioactiveWorldUtils and refactor spacing in WorldUtils 2020-09-17 23:20:39 -04:00
Khalid Ali
3b12e2aeca Set unique HWID 2020-09-17 22:56:06 -04:00
Khalid Ali
0c3a3f06f0 Add Beta and Gamma particles; added suggestions 2020-09-17 10:47:18 -04:00
Khalid Ali
2aeca6c9ce Small cleanup 2020-09-16 21:13:08 -04:00
Khalid Ali
3c16bd3f30 Implement RadiationDetector's handleInterrupt 2020-09-16 21:10:39 -04:00
Khalid Ali
a3c4c33300 Add getAlphaCounts() to Radioactive interface 2020-09-16 20:37:18 -04:00
Khalid Ali
72ea92ffb3 Add Euclidean Distance calculation method from coords 2020-09-16 20:13:33 -04:00
Khalid Ali
f526f369c4 Add getTiles() to calculate tiles between two coords 2020-09-16 20:03:06 -04:00
Khalid Ali
e97770f860 Skeleton setup + Tuple Impl 2020-09-16 18:45:12 -04:00
cd9e555e86 Merge pull request #226 from kevinramharak/fix-client-size-console-buffer-update
fix faulty object property name
2020-07-27 13:06:32 -04:00
Kevin Ramharak
7c0187f514 fix faulty object property name 2020-07-27 17:25:05 +02:00
ac27250f98 Merge pull request #225 from simon987/dependabot/maven/Server/org.springframework.security-spring-security-core-5.1.11.RELEASE
Bump spring-security-core from 5.1.5.RELEASE to 5.1.11.RELEASE in /Server
2020-06-15 16:10:53 -04:00
dependabot[bot]
84f59a5fa2 Bump spring-security-core in /Server
Bumps [spring-security-core](https://github.com/spring-projects/spring-security) from 5.1.5.RELEASE to 5.1.11.RELEASE.
- [Release notes](https://github.com/spring-projects/spring-security/releases)
- [Commits](https://github.com/spring-projects/spring-security/compare/5.1.5.RELEASE...5.1.11.RELEASE)

Signed-off-by: dependabot[bot] <support@github.com>
2020-06-15 19:36:46 +00:00
a0193621a8 Remove jenkins folder 2020-05-29 18:34:14 -04:00
922162660f Update footer.vm 2020-02-19 22:38:36 -05:00
014dab49da Merge pull request #221 from OrdoFlammae/radioactivecloud
Added Radioactive Cloud object.
2019-11-28 13:11:57 -05:00
Ordo Flammae
4c81937edc Added Radioactive Cloud object. 2019-11-27 19:35:49 -06:00
2597b558e6 Update slack link in play page 2019-11-08 10:10:17 -05:00
17 changed files with 404 additions and 125 deletions

View File

@@ -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
//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 = 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++;
@@ -57,7 +49,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;
} }
} }

View File

@@ -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;
}
}

View File

@@ -1,4 +1,32 @@
package net.simon987.pluginradioactivecloud; package net.simon987.pluginradioactivecloud;
public class RadioactiveCloud { import net.simon987.server.GameServer;
import net.simon987.server.game.objects.ControllableUnit;
import net.simon987.server.game.objects.Enterable;
import net.simon987.server.game.objects.GameObject;
import net.simon987.server.game.objects.Radioactive;
public class RadioactiveCloud extends GameObject implements Radioactive, Enterable {
private final static int CORRUPTION_BLOCK_SIZE =
GameServer.INSTANCE.getConfig().getInt("radioactive_cloud_corruption_block_size");
/**
* Called when an object attempts to walk directly into a Enterable object
*
* @param object The game object that attempted to enter
* @return true if successful, false to block the object
*/
@Override
public boolean enter(GameObject object) {
if (object instanceof ControllableUnit) {
((ControllableUnit) object).getCpu().getMemory().corrupt(CORRUPTION_BLOCK_SIZE);
}
return true;
}
@Override
public char getMapInfo() {
return 0;
}
} }

View File

@@ -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;
}
}

View File

@@ -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);
}
}
}

View File

@@ -1,10 +1,9 @@
### [Official website](https://muchassemblyrequired.com) # Much-Assembly-Required
[![CodeFactor](https://www.codefactor.io/repository/github/simon987/much-assembly-required/badge)](https://www.codefactor.io/repository/github/simon987/much-assembly-required) [![CodeFactor](https://www.codefactor.io/repository/github/simon987/much-assembly-required/badge)](https://www.codefactor.io/repository/github/simon987/much-assembly-required)
[![Build Status](https://ci.simon987.net/buildStatus/icon?job=Much-Assembly-Required)](https://ci.simon987.net/job/Much-Assembly-Required/) [![Build Status](https://ci.simon987.net/buildStatus/icon?job=Much-Assembly-Required)](https://ci.simon987.net/job/Much-Assembly-Required/)
Program the 8086-like microprocessor of a robot in a grid-based multiplayer world. The game is web based so no installation is required. **Much Assembly Required** allows you to program the 8086-like microprocessor of a robot in a grid-based multiplayer world. The game is web based so no installation is required. In its current state, players can walk around the game universe and collect Biomass blobs and Iron/copper ore using the online code editor.
In its current state, players can walk around the game universe and collect Biomass blobs & Iron/copper ore using the online code editor.
![screenshot from 2017-11-12 13-01-43](https://user-images.githubusercontent.com/7120851/32701793-e5d07e98-c7a9-11e7-9931-f8db7b287994.png) ![screenshot from 2017-11-12 13-01-43](https://user-images.githubusercontent.com/7120851/32701793-e5d07e98-c7a9-11e7-9931-f8db7b287994.png)
@@ -24,13 +23,14 @@ sudo apt install git maven openjdk-8-jdk mongodb
On Arch: On Arch:
``` bash ``` bash
sudo pacman -S git maven mongodb jdk8-opendjk sudo pacman -S git maven jdk8-opendjk
yay -S mongodb-bin
# Don't forget to start mongodb # Don't forget to start mongodb
sudo systemctl start mongodb.service sudo systemctl start mongodb.service
``` ```
*If needed, visit [troubleshooting mongodb](https://wiki.archlinux.org/index.php/MongoDB#Troubleshooting).* *If needed, visit [yay installation](https://github.com/Jguer/yay#installation) and [troubleshooting mongodb](https://wiki.archlinux.org/index.php/MongoDB#Troubleshooting).*
**Deploying server** **Deploying server**
@@ -51,12 +51,12 @@ java -jar server-1.4a.jar
Installation instructions: Installation instructions:
1. Download the JDK from [here](http://www.oracle.com/technetwork/java/javase/downloads/index.html). 1. Download the JDK from [here](http://www.oracle.com/technetwork/java/javase/downloads/index.html).
Install the JDK and update your PATH and JAVA_HOME enviroment variables. Install the JDK and update your PATH and JAVA_HOME environment variables.
2. Download Maven from [here](https://maven.apache.org/). 2. Download Maven from [here](https://maven.apache.org/).
Install Maven (following the README) and update your PATH enviroment variable. Install Maven (following the README) and update your PATH environment variable.
3. Download Mongo DB Community from [here](https://www.mongodb.com/download-center#community). 3. Download Mongo DB Community from [here](https://www.mongodb.com/download-center#community).
Install Mongo DB following the instructions [here](https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/). Install Mongo DB following the instructions [here](https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/).
Update your PATH enviroment variable. Update your PATH environment variable.
Building instructions: Building instructions:
```batch ```batch

View File

@@ -92,7 +92,7 @@
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>4.12</version> <version>4.13.1</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
@@ -114,7 +114,7 @@
<dependency> <dependency>
<groupId>org.springframework.security</groupId> <groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId> <artifactId>spring-security-core</artifactId>
<version>5.1.5.RELEASE</version> <version>5.1.11.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.sparkjava</groupId> <groupId>com.sparkjava</groupId>

View File

@@ -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));
}
} }

View File

@@ -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();
@@ -70,8 +71,8 @@ public class World implements MongoSerializable {
/** /**
* Computes the world's unique id from its coordinates. * Computes the world's unique id from its coordinates.
* *
* @param x the x coordinate of the world * @param x the x coordinate of the world
* @param y the y coordinate of the world * @param y the y coordinate of the world
* *
* @return long * @return long
*/ */
@@ -84,7 +85,7 @@ public class World implements MongoSerializable {
* *
* @return long * @return long
*/ */
public String getId(){ public String getId() {
return World.idFromCoordinates(x, y, dimension); return World.idFromCoordinates(x, y, dimension);
} }
@@ -136,22 +137,22 @@ 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() {
//Dispatch update event // Dispatch update event
GameEvent event = new WorldUpdateEvent(this); GameEvent event = new WorldUpdateEvent(this);
GameServer.INSTANCE.getEventDispatcher().dispatch(event); //Ignore cancellation GameServer.INSTANCE.getEventDispatcher().dispatch(event); // Ignore cancellation
for (GameObject object : gameObjects.values()) { for (GameObject object : gameObjects.values()) {
//Clean up dead objects // Clean up dead objects
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();
} }
@@ -182,7 +183,7 @@ public class World implements MongoSerializable {
dbObject.put("size", worldSize); dbObject.put("size", worldSize);
dbObject.put("updatable", updatable); dbObject.put("updatable", updatable);
dbObject.put("shouldUpdate",shouldUpdate()); dbObject.put("shouldUpdate", shouldUpdate());
return dbObject; return dbObject;
} }
@@ -231,17 +232,17 @@ 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() {
char[][] mapInfo = new char[worldSize][worldSize]; char[][] mapInfo = new char[worldSize][worldSize];
//Tile // Tile
for (int x = 0; x < worldSize; x++) { for (int x = 0; x < worldSize; x++) {
for (int y = 0; y < worldSize; y++) { for (int y = 0; y < worldSize; y++) {
Tile tile = tileMap.getTileAt(x, y); Tile tile = tileMap.getTileAt(x, y);
@@ -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
*/ */
@@ -277,7 +278,7 @@ public class World implements MongoSerializable {
while (true) { while (true) {
counter++; counter++;
//Prevent infinite loop // Prevent infinite loop
if (counter >= 1000) { if (counter >= 1000) {
return null; return null;
} }
@@ -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,29 +355,28 @@ 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) {
this.universe = universe; this.universe = universe;
} }
private ArrayList<World> getNeighbouringLoadedWorlds() { private ArrayList<World> getNeighbouringLoadedWorlds() {
ArrayList<World> neighbouringWorlds = new ArrayList<>(); ArrayList<World> neighbouringWorlds = new ArrayList<>();
if (universe == null){ if (universe == null) {
return neighbouringWorlds; return neighbouringWorlds;
} }
for (int dx=-1; dx<=+1; dx+=2){ for (int dx = -1; dx <= +1; dx += 2) {
World nw = universe.getLoadedWorld(x + dx, y, dimension); World nw = universe.getLoadedWorld(x + dx, y, dimension);
if (nw != null){ if (nw != null) {
neighbouringWorlds.add(nw); neighbouringWorlds.add(nw);
} }
} }
for (int dy=-1; dy<=+1; dy+=2){ for (int dy = -1; dy <= +1; dy += 2) {
World nw = universe.getLoadedWorld(x, y + dy, dimension); World nw = universe.getLoadedWorld(x, y + dy, dimension);
if (nw != null){ if (nw != null) {
neighbouringWorlds.add(nw); neighbouringWorlds.add(nw);
} }
} }
@@ -385,14 +384,14 @@ public class World implements MongoSerializable {
return neighbouringWorlds; return neighbouringWorlds;
} }
public boolean canUnload(){ public boolean canUnload() {
return updatable==0; return updatable == 0;
} }
public boolean shouldUnload(){ public boolean shouldUnload() {
boolean res = canUnload(); boolean res = canUnload();
for (World nw : getNeighbouringLoadedWorlds() ){ for (World nw : getNeighbouringLoadedWorlds()) {
res &= nw.canUnload(); res &= nw.canUnload();
} }
@@ -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
@@ -412,12 +429,12 @@ public class World implements MongoSerializable {
*/ */
public Point getRandomTileWithAdjacent(int n, int tile) { public Point getRandomTileWithAdjacent(int n, int tile) {
int counter = 0; int counter = 0;
int[] xPositions = {1, 0, -1, 0, 1, -1, 1, -1}; int[] xPositions = { 1, 0, -1, 0, 1, -1, 1, -1 };
int[] yPositions = {0, 1, 0, -1, 1, 1, -1, -1}; int[] yPositions = { 0, 1, 0, -1, 1, 1, -1, -1 };
while (true) { while (true) {
counter++; counter++;
//Prevent infinite loop // Prevent infinite loop
if (counter >= 2500) { if (counter >= 2500) {
return null; return null;
} }
@@ -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++;
} }
} }

View File

@@ -93,6 +93,9 @@ electric_box_damage=5
electric_box_energy_given=70 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
min_radioactive_obstacle_count=0
max_radioactive_obstacle_count=1
#SecretKey #SecretKey
secret_key=<your_secret_key> secret_key=<your_secret_key>

View File

@@ -1,5 +1,5 @@
<div class="container"> <div class="container">
<span class="text-muted">©2019 Simon Fortier</span> <span class="text-muted">©2020 simon987</span>
</div> </div>
<script src="js/popper.min.js"></script> <script src="js/popper.min.js"></script>

View File

@@ -32,10 +32,10 @@
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link regular-screen" target="_blank" <a class="nav-link regular-screen" target="_blank"
href="https://join.slack.com/t/muchassemblyrequired/shared_invite/enQtMjY3Mjc1OTUwNjEwLTkyOTIwOTA5OGY4MDVlMGI4NzM5YzlhMWJiMGY1OWE2NjUxODQ1NWQ1YTcxMTA1NGZkYzNjYzMyM2E1ODdmNzg"><i href="https://join.slack.com/t/muchassemblyrequired/shared_invite/enQtMjY3Mjc1OTUwNjEwLWRjMjRkZTg2N2EyNWRjN2YyMDc0YzIyMTUyYzFiNTBmMTU3OGQ1ZjA0MWY0M2IyYjUxZTA4NjRkMWVkNDk2NzY"><i
class="mi">chat</i> Slack</a> class="mi">chat</i> Slack</a>
<a class="nav-link small-screen" target="_blank" <a class="nav-link small-screen" target="_blank"
href="https://join.slack.com/t/muchassemblyrequired/shared_invite/enQtMjY3Mjc1OTUwNjEwLTkyOTIwOTA5OGY4MDVlMGI4NzM5YzlhMWJiMGY1OWE2NjUxODQ1NWQ1YTcxMTA1NGZkYzNjYzMyM2E1ODdmNzg"><i href="https://join.slack.com/t/muchassemblyrequired/shared_invite/enQtMjY3Mjc1OTUwNjEwLWRjMjRkZTg2N2EyNWRjN2YyMDc0YzIyMTUyYzFiNTBmMTU3OGQ1ZjA0MWY0M2IyYjUxZTA4NjRkMWVkNDk2NzY"><i
class="mi">chat</i></a> class="mi">chat</i></a>
</li> </li>
<li class="nav-item"> <li class="nav-item">

View File

@@ -84,7 +84,7 @@ class TickListener implements MessageListener {
} }
//Update console screen //Update console screen
if (message.c != undefined) { if (message.console_message_buffer != undefined) {
mar.client.consoleScreen.handleConsoleBufferUpdate( mar.client.consoleScreen.handleConsoleBufferUpdate(
message.console_message_buffer, message.console_message_buffer,
message.console_mode as ConsoleMode); message.console_mode as ConsoleMode);

View File

@@ -19,7 +19,7 @@ services:
- ./data/db:/data/db - ./data/db:/data/db
ports: ports:
- 27017:27017 - 27017:27017
command: mongod --smallfiles --logpath=/dev/null --port 27017 command: mongod --logpath=/dev/null --port 27017
healthcheck: healthcheck:
test: echo 'db.stats().ok' | mongo localhost:27017/mar --quiet test: echo 'db.stats().ok' | mongo localhost:27017/mar --quiet
interval: 2s interval: 2s

33
jenkins/Jenkinsfile vendored
View File

@@ -1,33 +0,0 @@
def remote = [:]
remote.name = 'remote'
remote.host = env.DEPLOY_HOST
remote.user = env.DEPLOY_USER
remote.identityFile = '/var/lib/jenkins/.ssh/id_rsa'
remote.knownHosts = '/var/lib/jenkins/.ssh/known_hosts'
remote.allowAnyHosts = true
remote.retryCount = 3
remote.retryWaitSec = 3
logLevel = 'FINER'
remote.port = 2299
pipeline {
agent any
stages {
stage('Build') {
steps {
sh './jenkins/build.sh'
//stash includes: 'target/', name: 'target'
}
}
stage('Deploy') {
steps {
//unstash 'target'
sshCommand remote: remote, command: 'rm -rf mar/target mar/deploy.sh'
sshPut remote: remote, from: 'target', into: 'mar'
sshPut remote: remote, from: 'jenkins/deploy.sh', into: 'mar/deploy.sh'
sshCommand remote: remote, command: 'chmod +x mar/deploy.sh && ./mar/deploy.sh'
}
}
}
}

View File

@@ -1,3 +0,0 @@
#!/usr/bin/env bash
mvn package

View File

@@ -1,13 +0,0 @@
#!/usr/bin/env bash
export MARROOT="mar"
screen -S mar -X quit
echo "Starting MAR"
cp ${MARROOT}/marConfig.properties ${MARROOT}/target/config.properties
cp -r ${MARROOT}/marCerts/ ${MARROOT}/target/certificates
screen -S mar -d -m bash -c "cd ${MARROOT}/target && java -jar server-*.jar"
sleep 1
screen -list