Search in sources :

Example 6 with Block

use of io.anuke.mindustry.world.Block in project Mindustry by Anuken.

the class Save13 method read.

@Override
public void read(DataInputStream stream) throws IOException {
    /*long loadTime = */
    stream.readLong();
    // general state
    byte mode = stream.readByte();
    byte mapid = stream.readByte();
    int wave = stream.readInt();
    float wavetime = stream.readFloat();
    float playerx = stream.readFloat();
    float playery = stream.readFloat();
    int playerhealth = stream.readInt();
    Vars.player.x = playerx;
    Vars.player.y = playery;
    Vars.player.health = playerhealth;
    state.mode = GameMode.values()[mode];
    Core.camera.position.set(playerx, playery, 0);
    // weapons
    control.upgrades().getWeapons().clear();
    control.upgrades().getWeapons().add(Weapon.blaster);
    Vars.player.weaponLeft = Vars.player.weaponRight = Weapon.blaster;
    int weapons = stream.readByte();
    for (int i = 0; i < weapons; i++) {
        control.upgrades().addWeapon((Weapon) Upgrade.getByID(stream.readByte()));
    }
    ui.hudfrag.updateWeapons();
    // inventory
    int totalItems = stream.readByte();
    Arrays.fill(state.inventory.getItems(), 0);
    for (int i = 0; i < totalItems; i++) {
        Item item = Item.getByID(stream.readByte());
        int amount = stream.readInt();
        state.inventory.getItems()[item.id] = amount;
    }
    ui.hudfrag.updateItems();
    // enemies
    Entities.clear();
    int enemies = stream.readInt();
    Array<Enemy> enemiesToUpdate = new Array<>();
    for (int i = 0; i < enemies; i++) {
        byte type = stream.readByte();
        int lane = stream.readByte();
        float x = stream.readFloat();
        float y = stream.readFloat();
        byte tier = stream.readByte();
        int health = stream.readShort();
        try {
            Enemy enemy = new Enemy(EnemyType.getByID(type));
            enemy.lane = lane;
            enemy.health = health;
            enemy.x = x;
            enemy.y = y;
            enemy.tier = tier;
            enemy.add(enemyGroup);
            enemiesToUpdate.add(enemy);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    state.enemies = enemies;
    state.wave = wave;
    state.wavetime = wavetime;
    if (!android)
        Vars.player.add();
    // map
    int seed = stream.readInt();
    world.loadMap(world.maps().getMap(mapid), seed);
    renderer.clearTiles();
    for (Enemy enemy : enemiesToUpdate) {
        enemy.node = -2;
    }
    int rocks = stream.readInt();
    for (int x = 0; x < world.width(); x++) {
        for (int y = 0; y < world.height(); y++) {
            Tile tile = world.tile(x, y);
            // remove breakables like rocks
            if (tile.breakable()) {
                world.tile(x, y).setBlock(Blocks.air);
            }
        }
    }
    for (int i = 0; i < rocks; i++) {
        int pos = stream.readInt();
        Tile tile = world.tile(pos % world.width(), pos / world.width());
        Block result = WorldGenerator.rocks.get(tile.floor());
        if (result != null)
            tile.setBlock(result);
    }
    int tiles = stream.readInt();
    for (int i = 0; i < tiles; i++) {
        int pos = stream.readInt();
        int blockid = stream.readInt();
        Tile tile = world.tile(pos % world.width(), pos / world.width());
        tile.setBlock(BlockLoader.getByOldID(blockid));
        if (blockid == Blocks.blockpart.id) {
            tile.link = stream.readByte();
        }
        if (tile.entity != null) {
            byte rotation = stream.readByte();
            short health = stream.readShort();
            int items = stream.readByte();
            tile.entity.health = health;
            tile.setRotation(rotation);
            for (int j = 0; j < items; j++) {
                int itemid = stream.readByte();
                int itemamount = stream.readInt();
                tile.entity.items[itemid] = itemamount;
            }
            tile.entity.read(stream);
        }
    }
}
Also used : Array(com.badlogic.gdx.utils.Array) Item(io.anuke.mindustry.resource.Item) Enemy(io.anuke.mindustry.entities.enemies.Enemy) Tile(io.anuke.mindustry.world.Tile) Block(io.anuke.mindustry.world.Block) IOException(java.io.IOException)

Example 7 with Block

use of io.anuke.mindustry.world.Block in project Mindustry by Anuken.

the class Save14 method read.

@Override
public void read(DataInputStream stream) throws IOException {
    /*long loadTime = */
    stream.readLong();
    // general state
    byte mode = stream.readByte();
    byte mapid = stream.readByte();
    int wave = stream.readInt();
    float wavetime = stream.readFloat();
    // block header
    int blocksize = stream.readInt();
    IntMap<Block> map = new IntMap<>();
    for (int i = 0; i < blocksize; i++) {
        String name = readString(stream);
        int id = stream.readShort();
        map.put(id, Block.getByName(name));
    }
    float playerx = stream.readFloat();
    float playery = stream.readFloat();
    int playerhealth = stream.readInt();
    Vars.player.x = playerx;
    Vars.player.y = playery;
    Vars.player.health = playerhealth;
    state.mode = GameMode.values()[mode];
    Core.camera.position.set(playerx, playery, 0);
    // weapons
    control.upgrades().getWeapons().clear();
    control.upgrades().getWeapons().add(Weapon.blaster);
    Vars.player.weaponLeft = Vars.player.weaponRight = Weapon.blaster;
    int weapons = stream.readByte();
    for (int i = 0; i < weapons; i++) {
        control.upgrades().addWeapon((Weapon) Upgrade.getByID(stream.readByte()));
    }
    ui.hudfrag.updateWeapons();
    // inventory
    int totalItems = stream.readByte();
    Arrays.fill(state.inventory.getItems(), 0);
    for (int i = 0; i < totalItems; i++) {
        Item item = Item.getByID(stream.readByte());
        int amount = stream.readInt();
        state.inventory.getItems()[item.id] = amount;
    }
    ui.hudfrag.updateItems();
    // enemies
    Entities.clear();
    int enemies = stream.readInt();
    Array<Enemy> enemiesToUpdate = new Array<>();
    for (int i = 0; i < enemies; i++) {
        byte type = stream.readByte();
        int lane = stream.readByte();
        float x = stream.readFloat();
        float y = stream.readFloat();
        byte tier = stream.readByte();
        int health = stream.readShort();
        try {
            Enemy enemy = new Enemy(EnemyType.getByID(type));
            enemy.lane = lane;
            enemy.health = health;
            enemy.x = x;
            enemy.y = y;
            enemy.tier = tier;
            enemy.add(enemyGroup);
            enemiesToUpdate.add(enemy);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    state.enemies = enemies;
    state.wave = wave;
    state.wavetime = wavetime;
    if (!android)
        Vars.player.add();
    // map
    int seed = stream.readInt();
    world.loadMap(world.maps().getMap(mapid), seed);
    renderer.clearTiles();
    for (Enemy enemy : enemiesToUpdate) {
        enemy.node = -2;
    }
    int rocks = stream.readInt();
    for (int x = 0; x < world.width(); x++) {
        for (int y = 0; y < world.height(); y++) {
            Tile tile = world.tile(x, y);
            // remove breakables like rocks
            if (tile.breakable()) {
                world.tile(x, y).setBlock(Blocks.air);
            }
        }
    }
    for (int i = 0; i < rocks; i++) {
        int pos = stream.readInt();
        Tile tile = world.tile(pos % world.width(), pos / world.width());
        if (tile == null)
            continue;
        Block result = WorldGenerator.rocks.get(tile.floor());
        if (result != null)
            tile.setBlock(result);
    }
    int tiles = stream.readInt();
    for (int i = 0; i < tiles; i++) {
        int pos = stream.readInt();
        int blockid = stream.readInt();
        Tile tile = world.tile(pos % world.width(), pos / world.width());
        tile.setBlock(map.get(blockid));
        if (blockid == Blocks.blockpart.id) {
            tile.link = stream.readByte();
        }
        if (tile.entity != null) {
            byte rotation = stream.readByte();
            short health = stream.readShort();
            int items = stream.readByte();
            tile.entity.health = health;
            tile.setRotation(rotation);
            for (int j = 0; j < items; j++) {
                int itemid = stream.readByte();
                int itemamount = stream.readInt();
                tile.entity.items[itemid] = itemamount;
            }
            tile.entity.read(stream);
        }
    }
}
Also used : Tile(io.anuke.mindustry.world.Tile) IOException(java.io.IOException) Array(com.badlogic.gdx.utils.Array) Item(io.anuke.mindustry.resource.Item) Enemy(io.anuke.mindustry.entities.enemies.Enemy) IntMap(com.badlogic.gdx.utils.IntMap) Block(io.anuke.mindustry.world.Block)

Example 8 with Block

use of io.anuke.mindustry.world.Block in project Mindustry by Anuken.

the class Save15 method read.

@Override
public void read(DataInputStream stream) throws IOException {
    /*long loadTime = */
    stream.readLong();
    // general state
    byte mode = stream.readByte();
    byte mapid = stream.readByte();
    int wave = stream.readInt();
    float wavetime = stream.readFloat();
    byte difficulty = stream.readByte();
    state.difficulty = Difficulty.values()[difficulty];
    // block header
    int blocksize = stream.readInt();
    IntMap<Block> map = new IntMap<>();
    for (int i = 0; i < blocksize; i++) {
        String name = readString(stream);
        int id = stream.readShort();
        map.put(id, Block.getByName(name));
    }
    float playerx = stream.readFloat();
    float playery = stream.readFloat();
    int playerhealth = stream.readInt();
    if (!headless) {
        player.x = playerx;
        player.y = playery;
        player.health = playerhealth;
        state.mode = GameMode.values()[mode];
        Core.camera.position.set(playerx, playery, 0);
        // weapons
        control.upgrades().getWeapons().clear();
        control.upgrades().getWeapons().add(Weapon.blaster);
        player.weaponLeft = player.weaponRight = Weapon.blaster;
        int weapons = stream.readByte();
        for (int i = 0; i < weapons; i++) {
            control.upgrades().addWeapon((Weapon) Upgrade.getByID(stream.readByte()));
        }
        ui.hudfrag.updateWeapons();
    } else {
        byte b = stream.readByte();
        for (int i = 0; i < b; i++) stream.readByte();
    }
    // inventory
    int totalItems = stream.readByte();
    Arrays.fill(state.inventory.getItems(), 0);
    for (int i = 0; i < totalItems; i++) {
        Item item = Item.getByID(stream.readByte());
        int amount = stream.readInt();
        state.inventory.getItems()[item.id] = amount;
    }
    if (!headless)
        ui.hudfrag.updateItems();
    // enemies
    int enemies = stream.readInt();
    Array<Enemy> enemiesToUpdate = new Array<>();
    for (int i = 0; i < enemies; i++) {
        byte type = stream.readByte();
        int lane = stream.readByte();
        float x = stream.readFloat();
        float y = stream.readFloat();
        byte tier = stream.readByte();
        int health = stream.readShort();
        try {
            Enemy enemy = new Enemy(EnemyType.getByID(type));
            enemy.lane = lane;
            enemy.health = health;
            enemy.x = x;
            enemy.y = y;
            enemy.tier = tier;
            enemy.add(enemyGroup);
            enemiesToUpdate.add(enemy);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    state.enemies = enemies;
    state.wave = wave;
    state.wavetime = wavetime;
    if (!android && !headless)
        player.add();
    // map
    int seed = stream.readInt();
    world.loadMap(world.maps().getMap(mapid), seed);
    if (!headless)
        renderer.clearTiles();
    for (Enemy enemy : enemiesToUpdate) {
        enemy.node = -2;
    }
    int rocks = stream.readInt();
    for (int x = 0; x < world.width(); x++) {
        for (int y = 0; y < world.height(); y++) {
            Tile tile = world.tile(x, y);
            // remove breakables like rocks
            if (tile.breakable()) {
                world.tile(x, y).setBlock(Blocks.air);
            }
        }
    }
    for (int i = 0; i < rocks; i++) {
        int pos = stream.readInt();
        Tile tile = world.tile(pos % world.width(), pos / world.width());
        if (tile == null)
            continue;
        Block result = WorldGenerator.rocks.get(tile.floor());
        if (result != null)
            tile.setBlock(result);
    }
    int tiles = stream.readInt();
    for (int i = 0; i < tiles; i++) {
        int pos = stream.readInt();
        int blockid = stream.readInt();
        Tile tile = world.tile(pos % world.width(), pos / world.width());
        tile.setBlock(map.get(blockid));
        if (blockid == Blocks.blockpart.id) {
            tile.link = stream.readByte();
        }
        if (tile.entity != null) {
            byte rotation = stream.readByte();
            short health = stream.readShort();
            int items = stream.readByte();
            tile.entity.health = health;
            tile.setRotation(rotation);
            for (int j = 0; j < items; j++) {
                int itemid = stream.readByte();
                int itemamount = stream.readInt();
                tile.entity.items[itemid] = itemamount;
            }
            tile.entity.read(stream);
        }
    }
}
Also used : Tile(io.anuke.mindustry.world.Tile) IOException(java.io.IOException) Array(com.badlogic.gdx.utils.Array) Item(io.anuke.mindustry.resource.Item) Enemy(io.anuke.mindustry.entities.enemies.Enemy) IntMap(com.badlogic.gdx.utils.IntMap) Block(io.anuke.mindustry.world.Block)

Example 9 with Block

use of io.anuke.mindustry.world.Block in project Mindustry by Anuken.

the class InputHandler method validBreak.

public boolean validBreak(int x, int y) {
    if (control.tutorial().active()) {
        if (control.tutorial().showBlock()) {
            GridPoint2 point = control.tutorial().getPlacePoint();
            int rotation = control.tutorial().getPlaceRotation();
            Block block = control.tutorial().getPlaceBlock();
            if (block != Blocks.air || point.x != x - world.getCore().x || point.y != y - world.getCore().y || (rotation != -1 && rotation != this.rotation)) {
                return false;
            }
        } else {
            return false;
        }
    }
    return Placement.validBreak(x, y);
}
Also used : Block(io.anuke.mindustry.world.Block) GridPoint2(com.badlogic.gdx.math.GridPoint2)

Example 10 with Block

use of io.anuke.mindustry.world.Block in project Mindustry by Anuken.

the class Save14 method write.

@Override
public void write(DataOutputStream stream) throws IOException {
    // --META--
    // version id
    stream.writeInt(version);
    // last saved
    stream.writeLong(TimeUtils.millis());
    // --GENERAL STATE--
    // gamemode
    stream.writeByte(state.mode.ordinal());
    // map ID
    stream.writeByte(world.getMap().id);
    // wave
    stream.writeInt(state.wave);
    // wave countdown
    stream.writeFloat(state.wavetime);
    // --BLOCK HEADER--
    stream.writeInt(Block.getAllBlocks().size);
    for (int i = 0; i < Block.getAllBlocks().size; i++) {
        Block block = Block.getAllBlocks().get(i);
        writeString(stream, block.name);
        stream.writeShort(block.id);
    }
    // player x/y
    stream.writeFloat(Vars.player.x);
    stream.writeFloat(Vars.player.y);
    // player health
    stream.writeInt(Vars.player.health);
    // amount of weapons
    stream.writeByte(control.upgrades().getWeapons().size - 1);
    // start at 1, because the first weapon is always the starter - ignore that
    for (int i = 1; i < control.upgrades().getWeapons().size; i++) {
        // weapon ordinal
        stream.writeByte(control.upgrades().getWeapons().get(i).id);
    }
    // --INVENTORY--
    int l = state.inventory.getItems().length;
    int itemsize = 0;
    for (int i = 0; i < l; i++) {
        if (state.inventory.getItems()[i] > 0) {
            itemsize++;
        }
    }
    // amount of items
    stream.writeByte(itemsize);
    for (int i = 0; i < l; i++) {
        if (state.inventory.getItems()[i] > 0) {
            // item ID
            stream.writeByte(i);
            // item amount
            stream.writeInt(state.inventory.getItems()[i]);
        }
    }
    // --ENEMIES--
    EntityContainer<Enemy> enemies = enemyGroup.all();
    // enemy amount
    stream.writeInt(enemies.size());
    for (int i = 0; i < enemies.size(); i++) {
        Enemy enemy = enemies.get(i);
        // type
        stream.writeByte(enemy.type.id);
        // lane
        stream.writeByte(enemy.lane);
        // x
        stream.writeFloat(enemy.x);
        // y
        stream.writeFloat(enemy.y);
        // tier
        stream.writeByte(enemy.tier);
        // health
        stream.writeShort(enemy.health);
    }
    // --MAP DATA--
    // seed
    stream.writeInt(world.getSeed());
    int totalblocks = 0;
    int totalrocks = 0;
    for (int x = 0; x < world.width(); x++) {
        for (int y = 0; y < world.height(); y++) {
            Tile tile = world.tile(x, y);
            if (tile.breakable()) {
                if (tile.block() instanceof Rock) {
                    totalrocks++;
                } else {
                    totalblocks++;
                }
            }
        }
    }
    // amount of rocks
    stream.writeInt(totalrocks);
    // write all rocks
    for (int x = 0; x < world.width(); x++) {
        for (int y = 0; y < world.height(); y++) {
            Tile tile = world.tile(x, y);
            if (tile.block() instanceof Rock) {
                stream.writeInt(tile.packedPosition());
            }
        }
    }
    // write all blocks
    stream.writeInt(totalblocks);
    for (int x = 0; x < world.width(); x++) {
        for (int y = 0; y < world.height(); y++) {
            Tile tile = world.tile(x, y);
            if (tile.breakable() && !(tile.block() instanceof Rock)) {
                // tile pos
                stream.writeInt(x + y * world.width());
                // block ID
                stream.writeInt(tile.block().id);
                if (tile.block() instanceof BlockPart)
                    stream.writeByte(tile.link);
                if (tile.entity != null) {
                    // rotation
                    stream.writeByte(tile.getRotation());
                    // health
                    stream.writeShort((short) tile.entity.health);
                    byte amount = 0;
                    for (int i = 0; i < tile.entity.items.length; i++) {
                        if (tile.entity.items[i] > 0)
                            amount++;
                    }
                    // amount of items
                    stream.writeByte(amount);
                    for (int i = 0; i < tile.entity.items.length; i++) {
                        if (tile.entity.items[i] > 0) {
                            // item ID
                            stream.writeByte(i);
                            // item amount
                            stream.writeInt(tile.entity.items[i]);
                        }
                    }
                    tile.entity.write(stream);
                }
            }
        }
    }
}
Also used : BlockPart(io.anuke.mindustry.world.blocks.types.BlockPart) Rock(io.anuke.mindustry.world.blocks.types.Rock) Enemy(io.anuke.mindustry.entities.enemies.Enemy) Block(io.anuke.mindustry.world.Block) Tile(io.anuke.mindustry.world.Tile)

Aggregations

Block (io.anuke.mindustry.world.Block)16 Tile (io.anuke.mindustry.world.Tile)6 Enemy (io.anuke.mindustry.entities.enemies.Enemy)5 Array (com.badlogic.gdx.utils.Array)3 Item (io.anuke.mindustry.resource.Item)3 BlockPair (io.anuke.mindustry.world.ColorMapper.BlockPair)3 IOException (java.io.IOException)3 GridPoint2 (com.badlogic.gdx.math.GridPoint2)2 IntMap (com.badlogic.gdx.utils.IntMap)2 BlockPart (io.anuke.mindustry.world.blocks.types.BlockPart)2 Rock (io.anuke.mindustry.world.blocks.types.Rock)2 StaticBlock (io.anuke.mindustry.world.blocks.types.StaticBlock)2 Pixmap (com.badlogic.gdx.graphics.Pixmap)1 Rectangle (com.badlogic.gdx.math.Rectangle)1 SpawnPoint (io.anuke.mindustry.game.SpawnPoint)1 Layer (io.anuke.mindustry.world.Layer)1 Floor (io.anuke.mindustry.world.blocks.types.Floor)1 SolidEntity (io.anuke.ucore.entities.SolidEntity)1 Table (io.anuke.ucore.scene.ui.layout.Table)1