Search in sources :

Example 1 with BlockPair

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

the class MapFilter method process.

public Pixmap process(Pixmap pixmap) {
    if (prefs.get("terrain").enabled) {
        for (int x = 0; x < pixmap.getWidth(); x++) {
            for (int y = 0; y < pixmap.getHeight(); y++) {
                float dist = Vector2.dst((float) x / pixmap.getWidth(), (float) y / pixmap.getHeight(), 0.5f, 0.5f) * 2f;
                double noise = sim.octaveNoise2D(6, 0.6, 1 / 180.0, x, y + 9999) / (prefs.get("circle").enabled ? 1.7 : 1f) + dist / 10f;
                if (dist > 0.8) {
                    noise += 2 * (dist - 0.8);
                }
                Block block = noise > 0.6 ? Blocks.stoneblock : Blocks.stone;
                pixmap.drawPixel(x, y, ColorMapper.getColor(block));
            }
        }
    }
    Pixmap src = Pixmaps.copy(pixmap);
    for (int x = 0; x < pixmap.getWidth(); x++) {
        for (int y = 0; y < pixmap.getHeight(); y++) {
            int dx = 0, dy = 0;
            if (prefs.get("distort").enabled) {
                double intensity = 12;
                double scale = 80;
                double octaves = 4;
                double falloff = 0.6;
                double nx = (sim.octaveNoise2D(octaves, falloff, 1 / scale, x, y) - 0.5f) * intensity;
                double ny = (sim.octaveNoise2D(octaves, falloff, 1 / scale, x, y + 99999) - 0.5f) * intensity;
                dx = (int) nx;
                dy = (int) ny;
            }
            int pix = src.getPixel(x + dx, y + dy);
            BlockPair pair = ColorMapper.get(pix);
            Block block = pair == null ? null : pair.wall == Blocks.air ? pair.floor : pair.wall;
            if (block == null)
                continue;
            boolean floor = block instanceof Floor;
            double noise = sim.octaveNoise2D(4, 0.6, 1 / 170.0, x, y) + sim.octaveNoise2D(1, 1.0, 1 / 5.0, x, y) / 18.0;
            double nwater = sim.octaveNoise2D(1, 1.0, 1 / 130.0, x, y);
            noise += nwater / 5.0;
            double noil = sim.octaveNoise2D(1, 1.0, 1 / 150.0, x + 9999, y) + sim.octaveNoise2D(1, 1.0, 1 / 2.0, x, y) / 290.0;
            if (!floor || prefs.get("replace").enabled) {
                if (prefs.get("allgrass").enabled) {
                    block = floor ? Blocks.grass : Blocks.grassblock;
                } else if (prefs.get("allsnow").enabled) {
                    block = floor ? Blocks.snow : Blocks.snowblock;
                } else if (prefs.get("allsand").enabled) {
                    block = floor ? Blocks.sand : Blocks.sandblock;
                } else if (prefs.get("replace").enabled) {
                    block = floor ? Blocks.stone : Blocks.stoneblock;
                }
                if (noise > 0.7 && prefs.get("grass").enabled) {
                    block = floor ? Blocks.grass : Blocks.grassblock;
                }
                if (noise > 0.7 && prefs.get("blackstone").enabled) {
                    block = floor ? Blocks.blackstone : Blocks.blackstoneblock;
                }
                if (noise > 0.7 && prefs.get("sand").enabled) {
                    block = floor ? Blocks.sand : Blocks.sandblock;
                }
                if (noise > 0.8 && prefs.get("stone").enabled) {
                    block = floor ? Blocks.stone : Blocks.stoneblock;
                }
            }
            if (floor) {
                if (nwater > 0.93 && prefs.get("water").enabled) {
                    block = Blocks.water;
                    if (nwater > 0.943) {
                        block = Blocks.deepwater;
                    }
                }
                if (noil > 0.95 && prefs.get("oil").enabled) {
                    block = Blocks.dirt;
                    if (noil > 0.955) {
                        block = Blocks.oil;
                    }
                }
            }
            if (floor && prefs.get("lavariver").enabled) {
                double lava = rid.getValue(x, y, 1 / 100f);
                double t = 0.6;
                if (lava > t) {
                    block = Blocks.lava;
                } else if (lava > t - 0.2) {
                    block = Blocks.blackstone;
                }
            }
            if (floor && prefs.get("slavariver").enabled) {
                double lava = rid.getValue(x, y, 1 / 40f);
                double t = 0.7;
                if (lava > t) {
                    block = Blocks.lava;
                } else if (lava > t - 0.3) {
                    block = Blocks.blackstone;
                }
            }
            if (floor && prefs.get("oilriver").enabled) {
                double lava = rid3.getValue(x, y, 1 / 100f);
                double t = 0.9;
                if (lava > t) {
                    block = Blocks.oil;
                } else if (lava > t - 0.2) {
                    block = Blocks.dirt;
                }
            }
            if (floor && prefs.get("river").enabled) {
                double riv = rid2.getValue(x, y, 1 / 140f);
                double t = 0.4;
                if (riv > t + 0.1) {
                    block = Blocks.deepwater;
                } else if (riv > t) {
                    block = Blocks.water;
                } else if (riv > t - 0.2) {
                    block = Blocks.grass;
                }
            }
            if (floor && prefs.get("iceriver").enabled) {
                double riv = rid2.getValue(x, y, 1 / 140f);
                double t = 0.4;
                if (riv > t + 0.1) {
                    block = Blocks.ice;
                } else if (riv > t) {
                    block = Blocks.ice;
                } else if (riv > t - 0.2) {
                    block = Blocks.snow;
                }
            }
            pixmap.drawPixel(x, y, ColorMapper.getColor(block));
        }
    }
    src.dispose();
    return pixmap;
}
Also used : Floor(io.anuke.mindustry.world.blocks.types.Floor) BlockPair(io.anuke.mindustry.world.ColorMapper.BlockPair) Block(io.anuke.mindustry.world.Block) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Example 2 with BlockPair

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

the class MapEditorDialog method updateSelectedBlock.

public void updateSelectedBlock() {
    Block block = editor.getDrawBlock();
    int i = 0;
    for (BlockPair pair : ColorMapper.getPairs()) {
        if (pair.wall == block || (pair.wall == Blocks.air && pair.floor == block)) {
            blockgroup.getButtons().get(i).setChecked(true);
            break;
        }
        i++;
    }
}
Also used : BlockPair(io.anuke.mindustry.world.ColorMapper.BlockPair) Block(io.anuke.mindustry.world.Block)

Example 3 with BlockPair

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

the class MapEditorDialog method addBlockSelection.

private void addBlockSelection(Table table) {
    Table content = new Table();
    pane = new ScrollPane(content, "volume");
    pane.setScrollingDisabled(true, false);
    pane.setFadeScrollBars(false);
    pane.setOverscroll(true, false);
    ButtonGroup<ImageButton> group = new ButtonGroup<>();
    blockgroup = group;
    int i = 0;
    for (BlockPair pair : ColorMapper.getPairs()) {
        Block block = pair.wall == Blocks.air ? pair.floor : pair.wall;
        ImageButton button = new ImageButton(Draw.hasRegion(block.name) ? Draw.region(block.name) : Draw.region(block.name + "1"), "toggle");
        button.clicked(() -> editor.setDrawBlock(block));
        button.resizeImage(8 * 4f);
        group.add(button);
        content.add(button).pad(4f).size(53f, 58f);
        if (i++ % 2 == 1) {
            content.row();
        }
    }
    group.getButtons().get(2).setChecked(true);
    Table extra = new Table("button");
    extra.labelWrap(() -> editor.getDrawBlock().formalName).width(180f).center();
    table.add(extra).padBottom(-6).growX();
    table.row();
    table.add(pane).growY().fillX();
}
Also used : Table(io.anuke.ucore.scene.ui.layout.Table) BlockPair(io.anuke.mindustry.world.ColorMapper.BlockPair) Block(io.anuke.mindustry.world.Block)

Example 4 with BlockPair

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

the class WorldGenerator method generate.

/**
 *Returns the core (starting) block. Should fill spawns with the correct spawnpoints.
 */
public static Tile generate(Pixmap pixmap, Tile[][] tiles, Array<SpawnPoint> spawns) {
    Noise.setSeed(world.getSeed());
    Tile core = null;
    for (int x = 0; x < pixmap.getWidth(); x++) {
        for (int y = 0; y < pixmap.getHeight(); y++) {
            Block floor = Blocks.stone;
            Block block = Blocks.air;
            int color = pixmap.getPixel(x, pixmap.getHeight() - 1 - y);
            BlockPair pair = ColorMapper.get(color);
            if (pair != null) {
                block = pair.wall;
                floor = pair.floor;
            }
            if (block == SpecialBlocks.playerSpawn) {
                block = Blocks.air;
                core = world.tile(x, y);
            } else if (block == SpecialBlocks.enemySpawn) {
                block = Blocks.air;
                spawns.add(new SpawnPoint(tiles[x][y]));
            }
            if (block == Blocks.air && Mathf.chance(0.025) && rocks.containsKey(floor)) {
                block = rocks.get(floor);
            }
            if (world.getMap().oreGen && (floor == Blocks.stone || floor == Blocks.grass || floor == Blocks.blackstone || floor == Blocks.snow || floor == Blocks.sand)) {
                if (Noise.nnoise(x, y, 8, 1) > 0.21) {
                    floor = Blocks.iron;
                }
                if (Noise.nnoise(x, y, 6, 1) > 0.237) {
                    floor = Blocks.coal;
                }
                if (Noise.nnoise(x + 9999, y + 9999, 8, 1) > 0.27) {
                    floor = Blocks.titanium;
                }
                if (Noise.nnoise(x + 99999, y + 99999, 7, 1) > 0.259) {
                    floor = Blocks.uranium;
                }
            }
            if (color == Hue.rgb(Color.PURPLE)) {
                if (!Vars.android)
                    new Enemy(EnemyTypes.target).set(x * tilesize, y * tilesize).add();
                floor = Blocks.stone;
            }
            tiles[x][y].setBlock(block, 0);
            tiles[x][y].setFloor(floor);
        }
    }
    for (int x = 0; x < pixmap.getWidth(); x++) {
        for (int y = 0; y < pixmap.getHeight(); y++) {
            tiles[x][y].updateOcclusion();
        }
    }
    return core;
}
Also used : BlockPair(io.anuke.mindustry.world.ColorMapper.BlockPair) Enemy(io.anuke.mindustry.entities.enemies.Enemy) SpawnPoint(io.anuke.mindustry.game.SpawnPoint) SpawnPoint(io.anuke.mindustry.game.SpawnPoint)

Aggregations

BlockPair (io.anuke.mindustry.world.ColorMapper.BlockPair)4 Block (io.anuke.mindustry.world.Block)3 Pixmap (com.badlogic.gdx.graphics.Pixmap)1 Enemy (io.anuke.mindustry.entities.enemies.Enemy)1 SpawnPoint (io.anuke.mindustry.game.SpawnPoint)1 Floor (io.anuke.mindustry.world.blocks.types.Floor)1 Table (io.anuke.ucore.scene.ui.layout.Table)1