Search in sources :

Example 11 with Enemy

use of io.anuke.mindustry.entities.enemies.Enemy 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)

Example 12 with Enemy

use of io.anuke.mindustry.entities.enemies.Enemy in project Mindustry by Anuken.

the class Save15 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);
    stream.writeByte(state.difficulty.ordinal());
    // --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);
    }
    if (!headless) {
        // player x/y
        stream.writeFloat(player.x);
        stream.writeFloat(player.y);
        // player health
        stream.writeInt(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);
        }
    } else {
        stream.writeFloat(world.getSpawnX());
        stream.writeFloat(world.getSpawnY());
        stream.writeInt(150);
        stream.writeByte(0);
    }
    // --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 != null && 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 != null && 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 != null && 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)

Example 13 with Enemy

use of io.anuke.mindustry.entities.enemies.Enemy in project Mindustry by Anuken.

the class DebugFragment method build.

@Override
public void build() {
    new table() {

        {
            visible(() -> debug);
            atop().aright();
            new table("pane") {

                {
                    defaults().fillX();
                    new label("Debug");
                    row();
                    new button("noclip", "toggle", () -> noclip = !noclip);
                    row();
                    new button("hideplayer", "toggle", () -> showPlayer = !showPlayer);
                    row();
                    new button("blocks", "toggle", () -> showBlockDebug = !showBlockDebug);
                    row();
                    new button("paths", "toggle", () -> showPaths = !showPaths);
                    row();
                    new button("wave", () -> state.wavetime = 0f);
                    row();
                    new button("time 0", () -> Timers.resetTime(0f));
                    row();
                    new button("time max", () -> Timers.resetTime(1080000 - 60 * 10));
                    row();
                    new button("clear", () -> {
                        enemyGroup.clear();
                        state.enemies = 0;
                        netClient.clearRecieved();
                    });
                    row();
                    new button("spawn", () -> {
                        new Enemy(EnemyTypes.healer).set(player.x, player.y).add();
                    });
                    row();
                }
            }.end();
            row();
        }
    }.end();
    new table() {

        {
            visible(() -> console);
            atop().aleft();
            new table("pane") {

                {
                    defaults().fillX();
                    ScrollPane pane = new ScrollPane(new Label(DebugFragment::debugInfo), "clear");
                    add(pane);
                    row();
                    new button("dump", () -> {
                        try {
                            FileHandle file = Gdx.files.local("packet-dump.txt");
                            file.writeString("--INFO--\n", false);
                            file.writeString(debugInfo(), true);
                            file.writeString("--LOG--\n\n", true);
                            file.writeString(log.toString(), true);
                        } catch (Exception e) {
                            ui.showError("Error dumping log.");
                        }
                    });
                }
            }.end();
        }
    }.end();
    new table() {

        {
            visible(() -> console);
            atop();
            Table table = new Table("pane");
            table.label(() -> log.toString());
            ScrollPane pane = new ScrollPane(table, "clear");
            get().add(pane);
        }
    }.end();
}
Also used : io.anuke.ucore.scene.builders.button(io.anuke.ucore.scene.builders.button) Table(io.anuke.ucore.scene.ui.layout.Table) ScrollPane(io.anuke.ucore.scene.ui.ScrollPane) FileHandle(com.badlogic.gdx.files.FileHandle) Enemy(io.anuke.mindustry.entities.enemies.Enemy) Label(io.anuke.ucore.scene.ui.Label) io.anuke.ucore.scene.builders.label(io.anuke.ucore.scene.builders.label) io.anuke.ucore.scene.builders.table(io.anuke.ucore.scene.builders.table)

Example 14 with Enemy

use of io.anuke.mindustry.entities.enemies.Enemy in project Mindustry by Anuken.

the class Pathfind method remakePath.

/**
 *Re-calculate paths for all enemies. Runs when a path changes while moving.
 */
private void remakePath() {
    for (int i = 0; i < enemyGroup.size(); i++) {
        Enemy enemy = enemyGroup.all().get(i);
        enemy.node = -1;
    }
    resetPaths();
}
Also used : Enemy(io.anuke.mindustry.entities.enemies.Enemy) SpawnPoint(io.anuke.mindustry.game.SpawnPoint)

Example 15 with Enemy

use of io.anuke.mindustry.entities.enemies.Enemy in project Mindustry by Anuken.

the class Logic method runWave.

public void runWave() {
    if (state.lastUpdated < state.wave + 1) {
        world.pathfinder().resetPaths();
        state.lastUpdated = state.wave + 1;
    }
    for (EnemySpawn spawn : spawns) {
        Array<SpawnPoint> spawns = world.getSpawns();
        for (int lane = 0; lane < spawns.size; lane++) {
            int fl = lane;
            Tile tile = spawns.get(lane).start;
            int spawnamount = spawn.evaluate(state.wave, lane);
            for (int i = 0; i < spawnamount; i++) {
                float range = 12f;
                Timers.runTask(i * 5f, () -> {
                    Enemy enemy = new Enemy(spawn.type);
                    enemy.set(tile.worldx() + Mathf.range(range), tile.worldy() + Mathf.range(range));
                    enemy.lane = fl;
                    enemy.tier = spawn.tier(state.wave, fl);
                    enemy.add();
                    Effects.effect(Fx.spawn, enemy);
                    state.enemies++;
                });
            }
        }
    }
    state.wave++;
    state.wavetime = wavespace * state.difficulty.timeScaling;
    state.extrawavetime = maxwavespace * state.difficulty.maxTimeScaling;
    Events.fire(WaveEvent.class);
}
Also used : EnemySpawn(io.anuke.mindustry.game.EnemySpawn) Enemy(io.anuke.mindustry.entities.enemies.Enemy) Tile(io.anuke.mindustry.world.Tile) SpawnPoint(io.anuke.mindustry.game.SpawnPoint) SpawnPoint(io.anuke.mindustry.game.SpawnPoint)

Aggregations

Enemy (io.anuke.mindustry.entities.enemies.Enemy)20 Tile (io.anuke.mindustry.world.Tile)10 Block (io.anuke.mindustry.world.Block)5 Array (com.badlogic.gdx.utils.Array)4 SpawnPoint (io.anuke.mindustry.game.SpawnPoint)4 Item (io.anuke.mindustry.resource.Item)4 IOException (java.io.IOException)4 BlockPart (io.anuke.mindustry.world.blocks.types.BlockPart)3 Rock (io.anuke.mindustry.world.blocks.types.Rock)3 IntMap (com.badlogic.gdx.utils.IntMap)2 FileHandle (com.badlogic.gdx.files.FileHandle)1 Interpolation (com.badlogic.gdx.math.Interpolation)1 Vector2 (com.badlogic.gdx.math.Vector2)1 Player (io.anuke.mindustry.entities.Player)1 EnemySpawn (io.anuke.mindustry.game.EnemySpawn)1 InputHandler (io.anuke.mindustry.input.InputHandler)1 ToolFragment (io.anuke.mindustry.ui.fragments.ToolFragment)1 BlockBar (io.anuke.mindustry.world.BlockBar)1 BlockPair (io.anuke.mindustry.world.ColorMapper.BlockPair)1 ShieldBlock (io.anuke.mindustry.world.blocks.types.defense.ShieldBlock)1