Search in sources :

Example 11 with BaseMap

use of objects.BaseMap in project ultimate-java by pantinor.

the class TestJaxb method findStartsForDungeons.

// @Test
public void findStartsForDungeons() 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.getType() != MapType.dungeon) {
            continue;
        }
        InputStream is = new FileInputStream("assets/data/" + map.getFname());
        byte[] bytes = IOUtils.toByteArray(is);
        int pos = 0;
        int i = 0;
        for (int y = 0; y < DUNGEON_MAP; y++) {
            for (int x = 0; x < DUNGEON_MAP; x++) {
                int index = bytes[pos] & 0xff;
                pos++;
                DungeonTile tile = DungeonTile.getTileByValue(index);
                if (tile == DungeonTile.LADDER_UP || tile == DungeonTile.LADDER_UP_DOWN) {
                    System.out.println(map.getFname() + " x=" + x + " y=" + y);
                }
            }
        }
    }
}
Also used : MapSet(objects.MapSet) LittleEndianDataInputStream(com.google.common.io.LittleEndianDataInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) TileSet(objects.TileSet) BaseMap(objects.BaseMap) FileInputStream(java.io.FileInputStream) DungeonTile(ultima.Constants.DungeonTile)

Example 12 with BaseMap

use of objects.BaseMap in project ultimate-java by pantinor.

the class AndiusMapTmxConvert method create.

@Override
public void create() {
    try {
        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);
        // load the atlas and determine the tile indexes per tilemap position
        FileHandle f = new FileHandle("assets/tilemaps/latest-atlas.txt");
        TextureAtlasData atlas = new TextureAtlasData(f, f.parent(), false);
        int png_grid_width = 24;
        Tile[] mapTileIds = new Tile[png_grid_width * Constants.tilePixelWidth + 1];
        for (Region r : atlas.getRegions()) {
            int x = r.left / r.width;
            int y = r.top / r.height;
            int i = x + (y * png_grid_width) + 1;
            mapTileIds[i] = ts.getTileByName(r.name);
        }
        BaseMap world = Constants.Maps.WORLD.getMap();
        Utils.setMapTiles(world, ts);
        Tile[] tiles = world.getTiles();
        String tmxFName = "tmx/andius/world.tmx";
        WorldFormatter c = new WorldFormatter(world.getWidth(), world.getHeight(), tiles, world.getPortals(), world.getMoongates());
        FileUtils.writeStringToFile(new File(tmxFName), c.toString());
        System.out.printf("Wrote: %s\n", tmxFName);
        for (BaseMap map : ms.getMaps()) {
            if (!map.getFname().endsWith("ult")) {
                continue;
            }
            FileInputStream is = new FileInputStream("assets/data/" + map.getFname());
            byte[] bytes = IOUtils.toByteArray(is);
            tiles = new Tile[map.getWidth() * map.getHeight()];
            int pos = 0;
            for (int y = 0; y < map.getHeight(); y++) {
                for (int x = 0; x < map.getWidth(); x++) {
                    // convert a byte to an unsigned int value
                    int index = bytes[pos] & 0xff;
                    pos++;
                    Tile tile = ts.getTileByIndex(index);
                    if (tile == null) {
                        System.out.println("Tile index cannot be found: " + index + " using index 129 for black space.");
                        tile = ts.getTileByIndex(129);
                    }
                    tiles[x + y * map.getWidth()] = tile;
                }
            }
            tmxFName = String.format("tmx/andius/%s.tmx", map.getCity().getName().replace(" ", "").toLowerCase());
            if (map.getFname().equals("lcb_2.ult")) {
                tmxFName = "tmx/andius/britannia2.tmx";
            }
            Formatter fmtter = new Formatter(map.getWidth(), map.getHeight(), tiles);
            FileUtils.writeStringToFile(new File(tmxFName), fmtter.toString());
            System.out.printf("Wrote: %s\n", tmxFName);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.out.println("DONE");
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) Tile(objects.Tile) JAXBContext(javax.xml.bind.JAXBContext) TileSet(objects.TileSet) BaseMap(objects.BaseMap) FileInputStream(java.io.FileInputStream) TextureAtlasData(com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData) MapSet(objects.MapSet) Region(com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Region) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File)

Example 13 with BaseMap

use of objects.BaseMap in project ultimate-java by pantinor.

the class VendorTest method printVendors.

// @Test
public void printVendors() throws Exception {
    File file2 = new File("target/classes/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("target/classes/xml/maps.xml");
    jaxbContext = JAXBContext.newInstance(MapSet.class);
    jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    MapSet ms = (MapSet) jaxbUnmarshaller.unmarshal(file3);
    ms.init(ts);
    ArrayList<Holder> tm = new ArrayList<>();
    for (BaseMap map : ms.getMaps()) {
        if (map.getCity() == null) {
            continue;
        }
        for (Person p : map.getCity().getPeople()) {
            if (p != null && p.getRole() != null && p.getRole().getInventoryType() != null) {
                tm.add(new Holder(p.getRole().getInventoryType(), p, Maps.get(map.getId())));
                System.out.println("type=\"" + p.getRole().getInventoryType() + "\" personId=\"" + p.getId() + "\" " + Maps.get(map.getId()));
            }
        }
    }
    Collections.sort(tm, new MyComparator());
    for (Holder h : tm) {
    // System.out.println("type=\"" +h.t+ "\" personId=\"" + h.p.getId() + "\" " + h.map);
    }
}
Also used : MapSet(objects.MapSet) ArrayList(java.util.ArrayList) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File) TileSet(objects.TileSet) Person(objects.Person) BaseMap(objects.BaseMap)

Example 14 with BaseMap

use of objects.BaseMap in project ultimate-java by pantinor.

the class WorldMapTmxConvert method create.

@Override
public void create() {
    try {
        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 map = Maps.WORLD.getMap();
        Utils.setMapTiles(map, ts);
        Tile[] tiles = map.getTiles();
        // load the atlas and determine the tile indexes per tilemap position
        FileHandle f = new FileHandle("assets/tilemaps/latest-atlas.txt");
        TextureAtlasData atlas = new TextureAtlasData(f, f.parent(), false);
        int png_grid_width = 24;
        Tile[] mapTileIds = new Tile[png_grid_width * Constants.tilePixelWidth + 1];
        for (Region r : atlas.getRegions()) {
            int x = r.left / r.width;
            int y = r.top / r.height;
            int i = x + (y * png_grid_width) + 1;
            mapTileIds[i] = ts.getTileByName(r.name);
        }
        // map layer
        StringBuilder data = new StringBuilder();
        int count = 1;
        int total = 1;
        for (int i = 0; i < tiles.length; i++) {
            Tile t = tiles[i];
            data.append(findTileId(mapTileIds, t.getName())).append(",");
            count++;
            total++;
            if (count > 256) {
                data.append("\n");
                count = 1;
            }
        }
        String dl = data.toString();
        dl = dl.substring(0, dl.length() - 2);
        // portal layer
        List<Portal> portals = map.getPortals();
        StringBuilder portalBuffer = new StringBuilder();
        // set map tile id per dest map type
        for (Portal p : portals) {
            BaseMap destMap = Maps.get(p.getDestmapid()).getMap();
            p.setName(Constants.Maps.get(p.getDestmapid()).toString());
            String ttype = destMap.getCity() == null ? destMap.getType().toString() : destMap.getCity().getType();
            p.setMapTileId(findTileId(mapTileIds, ttype));
        }
        if (portals != null) {
            for (int y = 0; y < map.getHeight(); y++) {
                for (int x = 0; x < map.getWidth(); x++) {
                    Portal p = findPortalAtCoords(portals, x, y);
                    if (p == null) {
                        portalBuffer.append("0,");
                    } else {
                        portalBuffer.append(p.getMapTileId() + ",");
                    }
                }
                portalBuffer.append("\n");
            }
        }
        String pl = portalBuffer.toString();
        pl = pl.substring(0, pl.length() - 2);
        // moongate layer
        List<Moongate> moongates = map.getMoongates();
        StringBuilder moongateBuffer = new StringBuilder();
        // set map tile id per dest map type
        for (Moongate m : moongates) {
            m.setMapTileId(findTileId(mapTileIds, "moongate"));
        }
        if (moongates != null) {
            for (int y = 0; y < map.getHeight(); y++) {
                for (int x = 0; x < map.getWidth(); x++) {
                    Moongate p = findMoongateAtCoords(moongates, x, y);
                    if (p == null) {
                        moongateBuffer.append("0,");
                    } else {
                        moongateBuffer.append(p.getMapTileId()).append(",");
                    }
                }
                moongateBuffer.append("\n");
            }
        }
        String ml = moongateBuffer.toString();
        ml = ml.substring(0, ml.length() - 2);
        Formatter c = new Formatter(map.getFname(), "latest.png", map.getWidth(), map.getHeight(), Constants.tilePixelWidth, Constants.tilePixelWidth, dl, pl, ml, portals, moongates, map.getLabels());
        FileUtils.writeStringToFile(new File("tmx/map_" + map.getId() + "_World.tmx"), c.toString());
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.out.println("DONE");
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) Tile(objects.Tile) JAXBContext(javax.xml.bind.JAXBContext) TileSet(objects.TileSet) BaseMap(objects.BaseMap) TextureAtlasData(com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData) MapSet(objects.MapSet) Region(com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Region) Portal(objects.Portal) Moongate(objects.Moongate) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File)

Example 15 with BaseMap

use of objects.BaseMap in project ultimate-java by pantinor.

the class DungeonScreen method enterRoom.

public void enterRoom(RoomLocater loc, Direction entryDir) {
    if (loc == null) {
        return;
    }
    Maps contextMap = Maps.get(dngMap.getId());
    TiledMap tiledMap = new DungeonRoomTiledMapLoader(loc.room, entryDir, Ultima4.standardAtlas).load();
    BaseMap baseMap = new BaseMap();
    baseMap.setTiles(loc.room.tiles);
    baseMap.setWidth(11);
    baseMap.setHeight(11);
    baseMap.setType(MapType.dungeon);
    baseMap.setPortals(dngMap.getMap().getPortals(loc.x, loc.y, loc.z));
    CombatScreen sc = new CombatScreen(this, context, contextMap, baseMap, tiledMap, null, Ultima4.creatures, Ultima4.standardAtlas);
    if (loc.room.hasAltar) {
        sc.log("The Altar Room of " + loc.room.altarRoomVirtue.toString());
    }
    MapLayer mLayer = tiledMap.getLayers().get("Monster Positions");
    Iterator<MapObject> iter = mLayer.getObjects().iterator();
    while (iter.hasNext()) {
        MapObject obj = iter.next();
        int tile = (Integer) obj.getProperties().get("tile");
        int startX = (Integer) obj.getProperties().get("startX");
        int startY = (Integer) obj.getProperties().get("startY");
        if (tile == 0) {
            continue;
        }
        Tile t = Ultima4.baseTileSet.getTileByIndex(tile);
        Creature c = Ultima4.creatures.getInstance(CreatureType.get(t.getName()), Ultima4.standardAtlas);
        c.currentX = startX;
        c.currentY = startY;
        c.currentPos = sc.getMapPixelCoords(startX, startY);
        baseMap.addCreature(c);
    }
    mainGame.setScreen(sc);
}
Also used : DungeonRoomTiledMapLoader(util.DungeonRoomTiledMapLoader) Creature(objects.Creature) MapLayer(com.badlogic.gdx.maps.MapLayer) Tile(objects.Tile) TiledMap(com.badlogic.gdx.maps.tiled.TiledMap) MapObject(com.badlogic.gdx.maps.MapObject) BaseMap(objects.BaseMap)

Aggregations

BaseMap (objects.BaseMap)17 MapSet (objects.MapSet)10 TileSet (objects.TileSet)10 File (java.io.File)7 JAXBContext (javax.xml.bind.JAXBContext)7 Unmarshaller (javax.xml.bind.Unmarshaller)7 Tile (objects.Tile)7 FileHandle (com.badlogic.gdx.files.FileHandle)5 TextureAtlasData (com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData)5 Region (com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Region)5 FileInputStream (java.io.FileInputStream)4 Vector3 (com.badlogic.gdx.math.Vector3)3 InputStream (java.io.InputStream)3 Person (objects.Person)3 Portal (objects.Portal)3 TiledMap (com.badlogic.gdx.maps.tiled.TiledMap)2 ArrayList (java.util.ArrayList)2 Creature (objects.Creature)2 Drawable (objects.Drawable)2 Moongate (objects.Moongate)2