Added basic Radio Tower functionality #32

Keypress buffer is cleared on code upload
This commit is contained in:
simon
2017-12-29 21:49:42 -05:00
parent 5afa767b4a
commit ef7f573256
15 changed files with 391 additions and 12 deletions

View File

@@ -0,0 +1,84 @@
package net.simon987.cubotplugin;
import net.simon987.server.GameServer;
import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.assembly.Status;
import net.simon987.server.game.GameObject;
import net.simon987.server.game.Programmable;
import org.json.simple.JSONObject;
import java.awt.*;
import java.util.ArrayList;
public class ComPort extends CpuHardware {
public static final char HWID = 0xD;
public static final int DEFAULT_ADDRESS = 0xD;
private Cubot cubot;
private static final int POLL = 1;
private static final int OUT = 2;
public ComPort(Cubot cubot) {
this.cubot = cubot;
}
private static final int MESSAGE_LENGTH = 8;
@Override
public void handleInterrupt(Status status) {
int a = getCpu().getRegisterSet().getRegister("A").getValue();
if (a == POLL) {
/* No-op */
} else if (a == OUT) {
//Get object directly in front of the Cubot
Point frontTile = cubot.getFrontTile();
ArrayList<GameObject> objects = cubot.getWorld().getGameObjectsAt(frontTile.x, frontTile.y);
if (objects.size() > 0 && objects.get(0) instanceof Programmable) {
int x = getCpu().getRegisterSet().getRegister("X").getValue();
if (x + MESSAGE_LENGTH >= getCpu().getMemory().getWords().length) {
//todo set interrupt ?
getCpu().getStatus().setErrorFlag(true);
} else {
//Get MESSAGE_LENGTH-word message pointed by X
char[] message = new char[MESSAGE_LENGTH];
System.arraycopy(getCpu().getMemory().getWords(), x, message, 0, MESSAGE_LENGTH);
//Send it to the Programmable object
((Programmable) objects.get(0)).sendMessage(message);
}
}
}
}
@Override
public char getId() {
return HWID;
}
@Override
public JSONObject serialise() {
JSONObject json = new JSONObject();
json.put("hwid", (int) HWID);
json.put("cubot", cubot.getObjectId());
return json;
}
public static ComPort deserialize(JSONObject json) {
return new ComPort((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((int) (long) json.get("cubot")));
}
}

View File

@@ -225,4 +225,9 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit {
HEX,
STRING
}
@Override
public void setAction(Action action) {
currentAction = action;
}
}

View File

@@ -62,8 +62,6 @@ public class CubotLaser extends CpuHardware {
}
}
}
} else {
System.out.println("\n\n\n\n\n It did it");
}

View File

@@ -58,6 +58,8 @@ public class CubotPlugin extends ServerPlugin implements GameObjectDeserializer,
return CubotBattery.deserialize(hwJson);
case CubotFloppyDrive.HWID:
return CubotFloppyDrive.deserialize(hwJson);
case ComPort.HWID:
return ComPort.deserialize(hwJson);
}
return null;

View File

@@ -5,7 +5,6 @@ import net.simon987.server.assembly.CPU;
import net.simon987.server.event.CpuInitialisationEvent;
import net.simon987.server.event.GameEvent;
import net.simon987.server.event.GameEventListener;
import net.simon987.server.logging.LogManager;
import net.simon987.server.user.User;
public class CpuInitialisationListener implements GameEventListener {
@@ -16,7 +15,7 @@ public class CpuInitialisationListener implements GameEventListener {
@Override
public void handle(GameEvent event) {
LogManager.LOGGER.fine("(Plugin) Handled CPU Initialisation event (Cubot Plugin)");
//LogManager.LOGGER.fine("(Plugin) Handled CPU Initialisation event (Cubot Plugin)");
CPU cpu = (CPU) event.getSource();
User user = ((CpuInitialisationEvent) event).getUser();
@@ -39,6 +38,8 @@ public class CpuInitialisationListener implements GameEventListener {
batteryHw.setCpu(cpu);
CubotFloppyDrive floppyHw = new CubotFloppyDrive((Cubot) user.getControlledUnit());
floppyHw.setCpu(cpu);
ComPort comPortHw = new ComPort((Cubot) user.getControlledUnit());
comPortHw.setCpu(cpu);
cpu.attachHardware(legHw, CubotLeg.DEFAULT_ADDRESS);
cpu.attachHardware(laserHw, CubotLaser.DEFAULT_ADDRESS);
@@ -50,5 +51,6 @@ public class CpuInitialisationListener implements GameEventListener {
cpu.attachHardware(emoteHw, CubotHologram.DEFAULT_ADDRESS);
cpu.attachHardware(batteryHw, CubotBattery.DEFAULT_ADDRESS);
cpu.attachHardware(floppyHw, CubotFloppyDrive.DEFAULT_ADDRESS);
cpu.attachHardware(comPortHw, ComPort.DEFAULT_ADDRESS);
}
}