This commit is contained in:
Simon 2018-11-27 16:02:21 -05:00
parent 54ed05b86c
commit 3776070689
18 changed files with 36 additions and 88 deletions

View File

@ -21,8 +21,7 @@ import java.util.*;
public class Cubot extends GameObject implements Updatable, ControllableUnit, MessageReceiver,
Attackable, Rechargeable, HardwareHost {
private static final char MAP_INFO = 0x0080;
private static final char MAP_INFO = 0x0200;
/**
* Hit points

View File

@ -107,8 +107,8 @@ public class CubotLidar extends CubotHardwareModule {
//Write map data to the location specified by register X
int i = getCpu().getRegisterSet().getRegister("X").getValue();
for (int y = 0; y < cubot.getWorld().getWorldSize(); y++) {
for (int x = 0; x < cubot.getWorld().getWorldSize(); x++) {
for (int x = 0; x < cubot.getWorld().getWorldSize(); x++) {
for (int y = 0; y < cubot.getWorld().getWorldSize(); y++) {
getCpu().getMemory().set(i++, mapInfo[x][y]);
}
}

View File

@ -16,6 +16,7 @@ import java.util.ArrayList;
*/
public class ElectricBox extends GameObject implements Updatable, Attackable {
private static final char MAP_INFO = 0x0301;
/**
* Hit points
*/
@ -98,7 +99,7 @@ public class ElectricBox extends GameObject implements Updatable, Attackable {
@Override
public char getMapInfo() {
return Obstacle.MAP_INFO;
return MAP_INFO;
}
/**

View File

@ -15,7 +15,7 @@ import java.util.List;
*/
public class Factory extends Structure implements Updatable {
private static final int MAP_INFO = 0x0200;
private static final int MAP_INFO = 0x0401;
/**
* Maximum number of NonPlayerCharacters assigned to this Factory

View File

@ -12,7 +12,6 @@ public class HarvesterNPC extends NonPlayerCharacter {
public static final int MAX_HEALTH = GameServer.INSTANCE.getConfig().getInt("harvester_hp_max");
public static final int HEAL_RATE = GameServer.INSTANCE.getConfig().getInt("harvester_regen");
public HarvesterNPC() {
setTask(new HarvestTask());

View File

@ -15,7 +15,7 @@ import java.util.ArrayList;
*/
public abstract class NonPlayerCharacter extends GameObject implements Updatable, Attackable {
private static final int MAP_INFO = 0x0040;
private static final char MAP_INFO = 0x0501;
/**
* Maximum distance to travel from its factory, in Worlds

View File

@ -10,7 +10,7 @@ import org.json.simple.JSONObject;
*/
public class Obstacle extends GameObject implements Attackable {
public static final int MAP_INFO = 0x0400;
public static final int MAP_INFO = 0x0701;
/**
* Style of the obstacle. Will tell the client which sprite to display

View File

@ -17,7 +17,7 @@ public class Portal extends Structure implements Enterable {
*/
private Location destination;
public static final int MAP_INFO = 0x0020;
public static final int MAP_INFO = 0x0801;
public Portal() {
super(1, 1);

View File

@ -12,7 +12,7 @@ import java.util.ArrayList;
public class RadioTower extends Structure implements MessageReceiver, Updatable {
private static final int MAP_INFO = 0x1000;
private static final int MAP_INFO = 0x0901;
public static final int MAX_RANGE = GameServer.INSTANCE.getConfig().getInt("radio_tower_range");

View File

@ -12,7 +12,7 @@ import java.util.Arrays;
public class VaultDoor extends Structure implements MessageReceiver, Enterable, Updatable {
private static final int MAP_INFO = 0x0800;
private static final int MAP_INFO = 0x0B00;
/**
* Password to open the vault door

View File

@ -29,9 +29,7 @@ public class VaultExitPortal extends Portal {
@Override
public boolean enter(GameObject object) {
//TODO: Trigger vault complete event instead
return super.enter(object);
}
}

View File

@ -8,7 +8,7 @@ import org.json.simple.JSONObject;
public class BiomassBlob extends GameObject implements InventoryHolder {
private static final char MAP_INFO = 0x4000;
private static final char MAP_INFO = 0x0101;
/**
* Yield of the blob, in biomass units

View File

@ -9,10 +9,11 @@ import net.simon987.server.game.objects.Radioactive;
public class RadioactiveObstacle extends GameObject implements Radioactive, Enterable {
private final static int corruptionBlockSize = GameServer.INSTANCE.getConfig().getInt("radioactive_obstacle_corruption_block_size");
private final static int MAP_INFO = 0x0A01; //10
@Override
public char getMapInfo() {
return 0;
return MAP_INFO;
}
@Override

View File

@ -4,11 +4,13 @@ import net.simon987.server.game.item.Item;
import org.bson.Document;
import org.json.simple.JSONObject;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
public class ItemsContainer extends GameObject implements InventoryHolder {
private static final char MAP_INFO = 0x0240;
private static final char MAP_INFO = 0x0601;
private final List<Item> items;
private int containerCapacity;

View File

@ -126,7 +126,7 @@ public class TileMap implements JSONSerialisable, MongoSerializable {
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
terrain.add(tiles[y][x].getId());
terrain.add(tiles[x][y].getId());
}
}

View File

@ -25,11 +25,6 @@ public class World implements MongoSerializable {
*/
private int worldSize;
//TODO: This info should be pulled from the Tile class
private static final char INFO_BLOCKED = 0x8000;
private static final char INFO_IRON = 0x0200;
private static final char INFO_COPPER = 0x0100;
private int x;
private int y;
@ -115,20 +110,6 @@ public class World implements MongoSerializable {
return matchingObjects;
}
public ArrayList<GameObject> findObjects(int mapInfo) {
ArrayList<GameObject> matchingObjects = new ArrayList<>(2);
for (GameObject obj : gameObjects.values()) {
if ((obj.getMapInfo() & mapInfo) == mapInfo) {
matchingObjects.add(obj);
}
}
return matchingObjects;
}
public ArrayList<GameObject> findGameObjects(String type) {
ArrayList<GameObject> matchingObjects = new ArrayList<>(2);
@ -209,11 +190,13 @@ public class World implements MongoSerializable {
@Override
public String toString() {
StringBuilder str = new StringBuilder("World (" + x + ", " + y + ")\n");
StringBuilder str = new StringBuilder(String.format("World (%04X, %04X)\n", x, y));
for (int x = 0; x < worldSize; x++) {
for (int y = 0; y < worldSize; y++) {
str.append(tileMap.getTileIdAt(x, y)).append(" ");
char[][] mapInfo = getMapInfo();
for (int y = 0; y < worldSize; y++) {
for (int x = 0; x < worldSize; x++) {
str.append(String.format("%04X ", (int) mapInfo[x][y]));
}
str.append("\n");
}
@ -251,40 +234,30 @@ public class World implements MongoSerializable {
* Get a binary representation of the map as an array of 16-bit bit fields, one word for each
* tile.
* <p>
* todo Performance cache this?
* Each tile is represented as such: <code>OOOOOOOOTTTTTTTB</code> where O is the object,
* T the tile and B if the tile is blocked or not
*/
public char[][] getMapInfo() {
char[][] mapInfo = new char[worldSize][worldSize];
//Tile
for (int y = 0; y < worldSize; y++) {
for (int x = 0; x < worldSize; x++) {
for (int x = 0; x < worldSize; x++) {
for (int y = 0; y < worldSize; y++) {
Tile tile = tileMap.getTileAt(x, y);
if (tileMap.getTileIdAt(x, y) == TilePlain.ID) {
mapInfo[x][y] = 0;
} else if (tileMap.getTileAt(x, y).isBlocked()) {
mapInfo[x][y] = INFO_BLOCKED;
//TODO: Tiles should have their .getMapInfo() method
} else if (tileMap.getTileIdAt(x, y) == TileCopper.ID) {
mapInfo[x][y] = INFO_COPPER;
} else if (tileMap.getTileIdAt(x, y) == TileIron.ID) {
mapInfo[x][y] = INFO_IRON;
}
mapInfo[x][y] = (char) (tile.isBlocked() ? 1 : 0);
mapInfo[x][y] |= (char) (tile.getId() << 1);
}
}
//Objects
for (GameObject obj : gameObjects.values()) {
//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()] |= obj.getMapInfo();
}
return mapInfo;
}
/**
@ -412,31 +385,6 @@ public class World implements MongoSerializable {
return neighbouringWorlds;
}
//Unused
// public ArrayList<World> getNeighbouringExistingWorlds(){
// ArrayList<World> neighbouringWorlds = new ArrayList<>();
//
// if (universe == null){
// return neighbouringWorlds;
// }
//
// for (int dx=-1; dx<=+1; dx+=2){
// World nw = universe.getWorld(x+dx,y,false);
// if (nw != null){
// neighbouringWorlds.add(nw);
// }
// }
// for (int dy=-1; dy<=+1; dy+=2){
// World nw = universe.getWorld(x,y+dy,false);
// if (nw != null){
// neighbouringWorlds.add(nw);
// }
// }
//
// return neighbouringWorlds;
// }
public boolean canUnload(){
return updatable==0;
}

View File

@ -1640,7 +1640,7 @@ var World = (function () {
}
for (var x = 0; x < size; x++) {
for (var y = 0; y < size; y++) {
var tile = Tile.createTile(terrain[y * size + x], x, y);
var tile = Tile.createTile(terrain[x * size + y], x, y);
this.tiles.push(tile);
mar.isoGroup.add(tile);
}

View File

@ -292,7 +292,7 @@ class World {
for (let x = 0; x < size; x++) {
for (let y = 0; y < size; y++) {
let tile: Tile = Tile.createTile(terrain[y * size + x], x, y);
let tile: Tile = Tile.createTile(terrain[x * size + y], x, y);
this.tiles.push(tile);
mar.isoGroup.add(tile);