use of objects.BaseMap in project ultimate-java by pantinor.
the class GameScreen method keyUp.
@Override
public boolean keyUp(int keycode) {
context.setLastCommandTime(System.currentTimeMillis());
Vector3 v = getCurrentMapCoords();
Tile ct = context.getCurrentMap().getTile(v);
if (keycode == Keys.UP) {
if (context.getTransportContext() == TransportContext.SHIP && avatarDirection + 1 != Direction.NORTH.getVal()) {
avatarDirection = Direction.NORTH.getVal() - 1;
finishTurn((int) v.x, (int) v.y);
return false;
}
if (!preMove(v, Direction.NORTH)) {
return false;
}
if (newMapPixelCoords.y + tilePixelHeight >= context.getCurrentMap().getHeight() * tilePixelHeight) {
newMapPixelCoords.y = 0;
postMove(Direction.NORTH, (int) v.x, context.getCurrentMap().getHeight() - 1);
} else {
newMapPixelCoords.y = newMapPixelCoords.y + tilePixelHeight;
postMove(Direction.NORTH, (int) v.x, (int) v.y - 1);
}
avatarDirection = Direction.NORTH.getVal() - 1;
} else if (keycode == Keys.RIGHT) {
if (context.getTransportContext() == TransportContext.SHIP && avatarDirection + 1 != Direction.EAST.getVal()) {
avatarDirection = Direction.EAST.getVal() - 1;
finishTurn((int) v.x, (int) v.y);
return false;
}
if (!preMove(v, Direction.EAST)) {
return false;
}
if (newMapPixelCoords.x + tilePixelWidth >= context.getCurrentMap().getWidth() * tilePixelWidth) {
newMapPixelCoords.x = 0;
postMove(Direction.EAST, 0, (int) v.y);
} else {
newMapPixelCoords.x = newMapPixelCoords.x + tilePixelWidth;
postMove(Direction.EAST, (int) v.x + 1, (int) v.y);
}
avatarDirection = Direction.EAST.getVal() - 1;
} else if (keycode == Keys.LEFT) {
if (context.getTransportContext() == TransportContext.SHIP && avatarDirection + 1 != Direction.WEST.getVal()) {
avatarDirection = Direction.WEST.getVal() - 1;
finishTurn((int) v.x, (int) v.y);
return false;
}
if (!preMove(v, Direction.WEST)) {
return false;
}
if (newMapPixelCoords.x - tilePixelWidth < 0) {
newMapPixelCoords.x = (context.getCurrentMap().getWidth() - 1) * tilePixelWidth;
postMove(Direction.WEST, context.getCurrentMap().getWidth() - 1, (int) v.y);
} else {
newMapPixelCoords.x = newMapPixelCoords.x - tilePixelWidth;
postMove(Direction.WEST, (int) v.x - 1, (int) v.y);
}
avatarDirection = Direction.WEST.getVal() - 1;
} else if (keycode == Keys.DOWN) {
if (context.getTransportContext() == TransportContext.SHIP && avatarDirection + 1 != Direction.SOUTH.getVal()) {
avatarDirection = Direction.SOUTH.getVal() - 1;
finishTurn((int) v.x, (int) v.y);
return false;
}
if (!preMove(v, Direction.SOUTH)) {
return false;
}
if (newMapPixelCoords.y - tilePixelHeight < 0) {
newMapPixelCoords.y = (context.getCurrentMap().getHeight() - 1) * tilePixelHeight;
postMove(Direction.SOUTH, (int) v.x, 0);
} else {
newMapPixelCoords.y = newMapPixelCoords.y - tilePixelHeight;
postMove(Direction.SOUTH, (int) v.x, (int) v.y + 1);
}
avatarDirection = Direction.SOUTH.getVal() - 1;
} else if (keycode == Keys.F && context.getTransportContext() == TransportContext.SHIP) {
log("Fire Cannon > ");
ShipInputAdapter sia = new ShipInputAdapter(v);
Gdx.input.setInputProcessor(sia);
return false;
} else if (keycode == Keys.H) {
CombatScreen.holeUp(Maps.WORLD, (int) v.x, (int) v.y, this, context, Ultima4.creatures, Ultima4.standardAtlas, false);
return false;
} else if (keycode == Keys.K || keycode == Keys.D) {
if (context.getCurrentMap().getId() == Maps.WORLD.getId()) {
if (keycode == Keys.K && context.getTransportContext() == TransportContext.BALLOON) {
context.getParty().getSaveGame().balloonstate = 1;
log("Klimb altitude");
} else if (keycode == Keys.D && context.getTransportContext() == TransportContext.BALLOON) {
if (ct.getRule().has(TileAttrib.canlandballoon)) {
context.getParty().getSaveGame().balloonstate = 0;
renderer.getFOV().calculateFOV(context.getCurrentMap().getShadownMap(), (int) v.x, (int) v.y, 17f);
log("Land balloon");
} else {
log("Not here!");
}
}
} else {
Portal p = context.getCurrentMap().getPortal(v.x, v.y, 0);
if (p != null) {
loadNextMap(Maps.get(p.getDestmapid()), p.getStartx(), p.getStarty());
log(p.getMessage());
return false;
}
}
} else if (keycode == Keys.E) {
if (context.getTransportContext() == TransportContext.BALLOON) {
log("Only on foot!");
return false;
}
Portal p = context.getCurrentMap().getPortal(v.x, v.y, 0);
if (p != null) {
if (Maps.get(p.getDestmapid()).getMap().getType() == MapType.shrine) {
Virtue virtue = Virtue.get(Maps.get(p.getDestmapid()).getId() - 25);
if (context.getParty().canEnterShrine(virtue)) {
loadNextMap(Maps.get(p.getDestmapid()), p.getStartx(), p.getStarty());
} else {
log("Thou dost not bear the rune of entry!");
log("A strange force keeps you out!");
}
} else {
Maps dest = Maps.get(p.getDestmapid());
if (dest == Maps.ABYSS) {
if ((context.getParty().getSaveGame().items & Item.CANDLE_USED.getLoc()) == 0 || (context.getParty().getSaveGame().items & Item.BELL_USED.getLoc()) == 0 || (context.getParty().getSaveGame().items & Item.BOOK_USED.getLoc()) == 0) {
log("A strange force keeps you out!");
return false;
}
}
if (p.getDestmapid() != context.getCurrentMap().getId()) {
loadNextMap(dest, p.getStartx(), p.getStarty());
} else {
newMapPixelCoords = getMapPixelCoords(p.getStartx(), p.getStarty());
recalcFOV(context.getCurrentMap(), p.getStartx(), p.getStarty());
}
return false;
}
}
} else if (keycode == Keys.Q) {
if (context.getCurrentMap().getId() == Maps.WORLD.getId() && context.getParty().getSaveGame().balloonstate == 0) {
context.saveGame(v.x, v.y, 0, null, Maps.WORLD);
log("Saved Game.");
} else {
log("Cannot save here!");
}
} else if (keycode == Keys.L) {
if (context.getCurrentMap().getId() == Maps.WORLD.getId()) {
if (context.getParty().getSaveGame().sextants >= 1) {
log("Locate position with sextant");
log(String.format("Latitude: %s' %s\"", (char) ((int) v.y / 16 + 'A'), (char) ((int) v.y % 16 + 'A')));
log(String.format("Longitude: %s' %s\"", (char) ((int) v.x / 16 + 'A'), (char) ((int) v.x % 16 + 'A')));
} else {
log("Locate position with what?");
}
} else {
log("Not here!");
}
} else if (keycode == Keys.N) {
log("New Order:");
log("exhange #:");
NewOrderInputAdapter noia = new NewOrderInputAdapter(this);
Gdx.input.setInputProcessor(noia);
return false;
} else if (keycode == Keys.S) {
BaseMap bm = context.getCurrentMap();
ItemMapLabels l = bm.searchLocation(this, context.getParty(), (int) v.x, (int) v.y, 0);
if (l != null) {
log("You found " + l.getDesc() + ".");
} else {
log("Nothing here!");
}
} else if (keycode == Keys.M) {
mainGame.setScreen(new MixtureScreen(mainGame, this, Ultima4.skin, context.getParty()));
} else if (keycode == Keys.B) {
board((int) v.x, (int) v.y);
} else if (keycode == Keys.X) {
if (context.getTransportContext() == TransportContext.SHIP) {
Tile st = Ultima4.baseTileSet.getTileByName("ship");
Drawable ship = new Drawable(context.getCurrentMap(), (int) v.x, (int) v.y, st, Ultima4.standardAtlas);
ship.setX(newMapPixelCoords.x);
ship.setY(newMapPixelCoords.y);
mapObjectsStage.addActor(ship);
} else if (context.getTransportContext() == TransportContext.HORSE) {
Creature cr = Ultima4.creatures.getInstance(CreatureType.horse, Ultima4.standardAtlas);
cr.currentX = (int) v.x;
cr.currentY = (int) v.y;
context.getCurrentMap().addCreature(cr);
} else if (context.getTransportContext() == TransportContext.BALLOON) {
if (context.getParty().getSaveGame().balloonstate == 0) {
addBalloonActor((int) v.x, (int) v.y);
context.getParty().getSaveGame().balloonx = (int) v.x;
context.getParty().getSaveGame().balloony = (int) v.y;
} else {
log("Thou must land first!");
return false;
}
}
context.getParty().setTransport(Ultima4.baseTileSet.getTileByIndex(0x1f));
mainAvatar = avatarAnim;
} else if (keycode == Keys.P) {
peerGem();
} else if (keycode == Keys.U) {
log("Use Item:");
log("");
ItemInputAdapter iia = new ItemInputAdapter(this);
Gdx.input.setInputProcessor(iia);
return false;
} else if (keycode == Keys.T || keycode == Keys.O || keycode == Keys.J || keycode == Keys.L || keycode == Keys.A || keycode == Keys.G || keycode == Keys.R || keycode == Keys.W) {
Gdx.input.setInputProcessor(sip);
sip.setinitialKeyCode(keycode, context.getCurrentMap(), (int) v.x, (int) v.y);
return false;
} else if (keycode == Keys.C) {
log("Cast Spell: ");
log("Who casts (1-8): ");
Gdx.input.setInputProcessor(new SpellInputProcessor(this, context, stage, (int) v.x, (int) v.y, null));
return false;
} else if (keycode == Keys.Z) {
showZstats = showZstats + 1;
if (showZstats >= STATS_PLAYER1 && showZstats <= STATS_PLAYER8) {
if (showZstats > context.getParty().getMembers().size()) {
showZstats = STATS_WEAPONS;
}
}
if (showZstats > STATS_SPELLS) {
showZstats = STATS_NONE;
}
} else if (keycode == Keys.ESCAPE) {
mainGame.setScreen(new BookScreen(mainGame, this, Ultima4.skin));
} else if (keycode == Keys.SPACE) {
log("Pass");
}
finishTurn((int) v.x, (int) v.y);
return false;
}
use of objects.BaseMap in project ultimate-java by pantinor.
the class SpellUtil method spellBlink.
public static void spellBlink(BaseScreen screen, Direction dir) {
if (screen.scType == ScreenType.MAIN) {
GameScreen gameScreen = (GameScreen) screen;
BaseMap bm = screen.context.getCurrentMap();
Vector3 v = gameScreen.getCurrentMapCoords();
int x = (int) v.x;
int y = (int) v.y;
/*
* Blink doesn't work near the mouth of the abyss
* Note: This means you can teleport to Hythloth from the top of the
* map, and that you can teleport to the abyss from the left edge of
* the map, Unfortunately, this matches the bugs in the game.
*/
if (bm.getId() != Maps.WORLD.getId() || (x >= 192 && y >= 192)) {
return;
}
int distance = 0;
int diff = 0;
Direction reverseDir = Direction.reverse(dir);
/* figure out what numbers we're working with */
int var = (dir.getMask() & (Direction.WEST.getMask() | Direction.EAST.getMask())) > 0 ? x : y;
/* find the distance we are going to move */
distance = (var) % 0x10;
if (dir == Direction.EAST || dir == Direction.SOUTH) {
distance = 0x10 - distance;
}
/* see if we move another 16 spaces over */
diff = 0x10 - distance;
if ((diff > 0) && (Utils.rand.nextInt(diff * diff) > distance)) {
distance += 0x10;
}
/* test our distance, and see if it works */
for (int i = 0; i < distance; i++) {
if (dir == Direction.NORTH) {
y--;
}
if (dir == Direction.SOUTH) {
y++;
}
if (dir == Direction.WEST) {
x--;
}
if (dir == Direction.EAST) {
x++;
}
}
int i = distance;
/* begin walking backward until you find a valid spot */
while ((i-- > 0) && bm.getTile(x, y) != null && bm.getTile(x, y).getRule().has(TileAttrib.unwalkable)) {
if (reverseDir == Direction.NORTH) {
y--;
}
if (reverseDir == Direction.SOUTH) {
y++;
}
if (reverseDir == Direction.WEST) {
x--;
}
if (reverseDir == Direction.EAST) {
x++;
}
}
if (bm.getTile(x, y) != null && !bm.getTile(x, y).getRule().has(TileAttrib.unwalkable)) {
/* we didn't move! */
if (x == (int) v.x && y == (int) v.y) {
screen.log("Failed to blink!");
}
gameScreen.newMapPixelCoords = gameScreen.getMapPixelCoords(x, y);
gameScreen.recalcFOV(bm, x, y);
} else {
screen.log("Failed to blink!");
}
} else {
screen.log("Outdoors only!");
}
}
use of objects.BaseMap in project ultimate-java by pantinor.
the class SpellUtil method spellGate.
public static void spellGate(BaseScreen screen, int phase) {
if (screen.scType == ScreenType.MAIN) {
GameScreen gsc = (GameScreen) screen;
for (Moongate g : gsc.context.getCurrentMap().getMoongates()) {
if (g.getPhase() == phase) {
Vector3 dest = new Vector3(g.getX(), g.getY(), 0);
gsc.newMapPixelCoords = gsc.getMapPixelCoords((int) dest.x, (int) dest.y);
BaseMap bm = gsc.context.getCurrentMap();
gsc.recalcFOV(bm, (int) dest.x, (int) dest.y);
break;
}
}
}
}
use of objects.BaseMap in project ultimate-java by pantinor.
the class TestJaxb method testMaps.
// @Test
public void testMaps() throws Exception {
TileSet baseTileSet = (TileSet) Utils.loadXml("tileset-base.xml", TileSet.class);
baseTileSet.setMaps();
MapSet maps = (MapSet) Utils.loadXml("maps.xml", MapSet.class);
maps.init(baseTileSet);
for (BaseMap map : maps.getMaps()) {
if (map.getCity() == null || map.getCity().getTlk_fname() == null) {
continue;
}
String fname = "D:\\xu4\\ULTIMA4\\" + map.getCity().getTlk_fname();
System.out.println("D:\\xu4\\tools\\tlkconv.exe --toxml " + fname + " " + "D:\\work\\ultima-java\\target\\" + map.getCity().getTlk_fname() + ".xml");
}
}
use of objects.BaseMap in project ultimate-java by pantinor.
the class TestJaxb method testMapShadows.
// @Test
public void testMapShadows() throws Exception {
File file2 = new File("assets/xml/tileset-base.xml");
JAXBContext jaxbContext = JAXBContext.newInstance(TileSet.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
TileSet ts = (TileSet) jaxbUnmarshaller.unmarshal(file2);
ts.setMaps();
File file3 = new File("assets/xml/maps.xml");
jaxbContext = JAXBContext.newInstance(MapSet.class);
jaxbUnmarshaller = jaxbContext.createUnmarshaller();
MapSet ms = (MapSet) jaxbUnmarshaller.unmarshal(file3);
ms.init(ts);
BaseMap m = Maps.BRITAIN.getMap();
int startx = 2;
int starty = 4;
long t = System.currentTimeMillis();
SpreadFOV fov = new SpreadFOV(32, 32, true);
float[][] lightMap = fov.calculateFOV(m.getShadownMap(), startx, starty, 20);
for (int y = 0; y < 32; y++) {
for (int x = 0; x < 32; x++) {
if (startx == x && starty == y) {
System.out.print("_");
} else {
// System.out.print(lightMap[x][y] <= 0?"X":" ");
System.out.print(lightMap[x][y]);
}
}
System.out.println("");
}
System.out.println("testLOS2 time: " + (System.currentTimeMillis() - t));
}
Aggregations