Search in sources :

Example 6 with MapSet

use of objects.MapSet 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));
}
Also used : SpreadFOV(util.SpreadFOV) MapSet(objects.MapSet) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File) TileSet(objects.TileSet) BaseMap(objects.BaseMap)

Example 7 with MapSet

use of objects.MapSet 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 8 with MapSet

use of objects.MapSet 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 9 with MapSet

use of objects.MapSet 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 10 with MapSet

use of objects.MapSet 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)

Aggregations

BaseMap (objects.BaseMap)10 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 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 Tile (objects.Tile)5 FileInputStream (java.io.FileInputStream)4 InputStream (java.io.InputStream)3 Person (objects.Person)3 ArrayList (java.util.ArrayList)2 LittleEndianDataInputStream (com.google.common.io.LittleEndianDataInputStream)1 Conversation (objects.Conversation)1 Moongate (objects.Moongate)1 Portal (objects.Portal)1 DungeonTile (ultima.Constants.DungeonTile)1 SpreadFOV (util.SpreadFOV)1