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);
}
}
}
}
}
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);
}
}
}
}
}
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();
}
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();
}
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);
}
Aggregations