Search in sources :

Example 1 with SpawnPoint

use of io.anuke.mindustry.game.SpawnPoint in project Mindustry by Anuken.

the class Placement method validPlace.

public static boolean validPlace(int x, int y, Block type) {
    for (int i = 0; i < world.getSpawns().size; i++) {
        SpawnPoint spawn = world.getSpawns().get(i);
        if (Vector2.dst(x * tilesize, y * tilesize, spawn.start.worldx(), spawn.start.worldy()) < enemyspawnspace) {
            return false;
        }
    }
    Recipe recipe = Recipes.getByResult(type);
    if (recipe == null || !state.inventory.hasItems(recipe.requirements)) {
        return false;
    }
    rect.setSize(type.width * tilesize, type.height * tilesize);
    Vector2 offset = type.getPlaceOffset();
    rect.setCenter(offset.x + x * tilesize, offset.y + y * tilesize);
    synchronized (Entities.entityLock) {
        for (SolidEntity e : Entities.getNearby(enemyGroup, x * tilesize, y * tilesize, tilesize * 2f)) {
            // not sure why this happens?
            if (e == null)
                continue;
            Rectangle rect = e.hitbox.getRect(e.x, e.y);
            if (Placement.rect.overlaps(rect)) {
                return false;
            }
        }
    }
    if (type.solid || type.solidifes) {
        for (Player player : playerGroup.all()) {
            if (!player.isAndroid && rect.overlaps(player.hitbox.getRect(player.x, player.y))) {
                return false;
            }
        }
    }
    Tile tile = world.tile(x, y);
    if (tile == null || (isSpawnPoint(tile) && (type.solidifes || type.solid)))
        return false;
    if (type.isMultiblock()) {
        int offsetx = -(type.width - 1) / 2;
        int offsety = -(type.height - 1) / 2;
        for (int dx = 0; dx < type.width; dx++) {
            for (int dy = 0; dy < type.height; dy++) {
                Tile other = world.tile(x + dx + offsetx, y + dy + offsety);
                if (other == null || (other.block() != Blocks.air && !other.block().alwaysReplace) || isSpawnPoint(other)) {
                    return false;
                }
            }
        }
        return true;
    } else {
        return tile.block() != type && (type.canReplace(tile.block()) || tile.block().alwaysReplace) && tile.block().isMultiblock() == type.isMultiblock() || tile.block() == Blocks.air;
    }
}
Also used : Player(io.anuke.mindustry.entities.Player) SolidEntity(io.anuke.ucore.entities.SolidEntity) Recipe(io.anuke.mindustry.resource.Recipe) Vector2(com.badlogic.gdx.math.Vector2) Rectangle(com.badlogic.gdx.math.Rectangle) SpawnPoint(io.anuke.mindustry.game.SpawnPoint) SpawnPoint(io.anuke.mindustry.game.SpawnPoint)

Example 2 with SpawnPoint

use of io.anuke.mindustry.game.SpawnPoint in project Mindustry by Anuken.

the class Renderer method drawOverlay.

void drawOverlay() {
    // draw tutorial placement point
    if (world.getMap().name.equals("tutorial") && control.tutorial().showBlock()) {
        int x = world.getCore().x + control.tutorial().getPlacePoint().x;
        int y = world.getCore().y + control.tutorial().getPlacePoint().y;
        int rot = control.tutorial().getPlaceRotation();
        Lines.stroke(1f);
        Draw.color(Color.YELLOW);
        Lines.square(x * tilesize, y * tilesize, tilesize / 2f + Mathf.sin(Timers.time(), 4f, 1f));
        Draw.color(Color.ORANGE);
        Lines.stroke(2f);
        if (rot != -1) {
            Lines.lineAngle(x * tilesize, y * tilesize, rot * 90, 6);
        }
        Draw.reset();
    }
    // draw config selected block
    if (ui.configfrag.isShown()) {
        Tile tile = ui.configfrag.getSelectedTile();
        Draw.color(Colors.get("accent"));
        Lines.stroke(1f);
        Lines.square(tile.drawx(), tile.drawy(), tile.block().width * tilesize / 2f + 1f);
        Draw.reset();
    }
    int tilex = control.input().getBlockX();
    int tiley = control.input().getBlockY();
    if (android) {
        Vector2 vec = Graphics.world(Gdx.input.getX(0), Gdx.input.getY(0));
        tilex = Mathf.scl2(vec.x, tilesize);
        tiley = Mathf.scl2(vec.y, tilesize);
    }
    InputHandler input = control.input();
    // draw placement box
    if ((input.recipe != null && state.inventory.hasItems(input.recipe.requirements) && (!ui.hasMouse() || android) && control.input().drawPlace())) {
        input.placeMode.draw(control.input().getBlockX(), control.input().getBlockY(), control.input().getBlockEndX(), control.input().getBlockEndY());
        Lines.stroke(1f);
        Draw.color(Color.SCARLET);
        for (SpawnPoint spawn : world.getSpawns()) {
            Lines.dashCircle(spawn.start.worldx(), spawn.start.worldy(), enemyspawnspace);
        }
        if (world.getCore() != null) {
            Draw.color(Color.LIME);
            Lines.poly(world.getSpawnX(), world.getSpawnY(), 4, 6f, Timers.time() * 2f);
        }
        if (input.breakMode == PlaceMode.holdDelete)
            input.breakMode.draw(tilex, tiley, 0, 0);
    } else if (input.breakMode.delete && control.input().drawPlace() && (input.recipe == null || !state.inventory.hasItems(input.recipe.requirements)) && (input.placeMode.delete || input.breakMode.both || !android)) {
        if (input.breakMode == PlaceMode.holdDelete)
            input.breakMode.draw(tilex, tiley, 0, 0);
        else
            input.breakMode.draw(control.input().getBlockX(), control.input().getBlockY(), control.input().getBlockEndX(), control.input().getBlockEndY());
    }
    if (ui.toolfrag.confirming) {
        ToolFragment t = ui.toolfrag;
        PlaceMode.areaDelete.draw(t.px, t.py, t.px2, t.py2);
    }
    Draw.reset();
    // draw selected block bars and info
    if (input.recipe == null && !ui.hasMouse()) {
        Tile tile = world.tileWorld(Graphics.mouseWorld().x, Graphics.mouseWorld().y);
        if (tile != null && tile.block() != Blocks.air) {
            Tile target = tile;
            if (tile.isLinked())
                target = tile.getLinked();
            if (showBlockDebug && target.entity != null) {
                Draw.color(Color.RED);
                Lines.crect(target.drawx(), target.drawy(), target.block().width * tilesize, target.block().height * tilesize);
                Vector2 v = new Vector2();
                Draw.tcolor(Color.YELLOW);
                Draw.tscl(0.25f);
                Array<Object> arr = target.block().getDebugInfo(target);
                StringBuilder result = new StringBuilder();
                for (int i = 0; i < arr.size / 2; i++) {
                    result.append(arr.get(i * 2));
                    result.append(": ");
                    result.append(arr.get(i * 2 + 1));
                    result.append("\n");
                }
                Draw.textc(result.toString(), target.drawx(), target.drawy(), v);
                Draw.color(0f, 0f, 0f, 0.5f);
                Fill.rect(target.drawx(), target.drawy(), v.x, v.y);
                Draw.textc(result.toString(), target.drawx(), target.drawy(), v);
                Draw.tscl(fontscale);
                Draw.reset();
            }
            if (Inputs.keyDown("block_info") && target.block().fullDescription != null) {
                Draw.color(Colors.get("accent"));
                Lines.crect(target.drawx(), target.drawy(), target.block().width * tilesize, target.block().height * tilesize);
                Draw.color();
            }
            if (target.entity != null) {
                int bot = 0, top = 0;
                for (BlockBar bar : target.block().bars) {
                    float offset = Mathf.sign(bar.top) * (target.block().height / 2f * tilesize + 3f + 4f * ((bar.top ? top : bot))) + (bar.top ? -1f : 0f);
                    float value = bar.value.get(target);
                    if (MathUtils.isEqual(value, -1f))
                        continue;
                    drawBar(bar.color, target.drawx(), target.drawy() + offset, value);
                    if (bar.top)
                        top++;
                    else
                        bot++;
                }
            }
            target.block().drawSelect(target);
        }
    }
    if ((!debug || showUI) && Settings.getBool("healthbars")) {
        // draw entity health bars
        for (Enemy entity : enemyGroup.all()) {
            drawHealth(entity);
        }
        for (Player player : playerGroup.all()) {
            if (!player.isDead() && !player.isAndroid)
                drawHealth(player);
        }
    }
}
Also used : InputHandler(io.anuke.mindustry.input.InputHandler) Player(io.anuke.mindustry.entities.Player) Tile(io.anuke.mindustry.world.Tile) SpawnPoint(io.anuke.mindustry.game.SpawnPoint) ToolFragment(io.anuke.mindustry.ui.fragments.ToolFragment) Vector2(com.badlogic.gdx.math.Vector2) Enemy(io.anuke.mindustry.entities.enemies.Enemy) BlockBar(io.anuke.mindustry.world.BlockBar) SpawnPoint(io.anuke.mindustry.game.SpawnPoint)

Example 3 with SpawnPoint

use of io.anuke.mindustry.game.SpawnPoint in project Mindustry by Anuken.

the class BlockRenderer method drawPaths.

void drawPaths() {
    Draw.color(Color.RED);
    for (SpawnPoint point : world.getSpawns()) {
        if (point.pathTiles != null) {
            for (int i = 1; i < point.pathTiles.length; i++) {
                Lines.line(point.pathTiles[i - 1].worldx(), point.pathTiles[i - 1].worldy(), point.pathTiles[i].worldx(), point.pathTiles[i].worldy());
                Lines.circle(point.pathTiles[i - 1].worldx(), point.pathTiles[i - 1].worldy(), 6f);
            }
        }
    }
    Draw.reset();
}
Also used : SpawnPoint(io.anuke.mindustry.game.SpawnPoint) SpawnPoint(io.anuke.mindustry.game.SpawnPoint)

Example 4 with SpawnPoint

use of io.anuke.mindustry.game.SpawnPoint in project Mindustry by Anuken.

the class Pathfind method benchmark.

// 1300-1500ms, usually 1400 unoptimized on Caldera
/**
 *Benchmark pathfinding speed. Debugging stuff.
 */
public void benchmark() {
    SpawnPoint point = world.getSpawns().first();
    int amount = 100;
    // warmup
    for (int i = 0; i < 100; i++) {
        point.finder.searchNodePath(point.start, world.getCore(), state.difficulty.heuristic, point.path);
        point.path.clear();
    }
    Timers.mark();
    for (int i = 0; i < amount; i++) {
        point.finder.searchNodePath(point.start, world.getCore(), state.difficulty.heuristic, point.path);
        point.path.clear();
    }
    Log.info("Time elapsed: {0}ms\nAverage MS per path: {1}", Timers.elapsed(), Timers.elapsed() / amount);
}
Also used : SpawnPoint(io.anuke.mindustry.game.SpawnPoint) SpawnPoint(io.anuke.mindustry.game.SpawnPoint)

Example 5 with SpawnPoint

use of io.anuke.mindustry.game.SpawnPoint in project Mindustry by Anuken.

the class Pathfind method update.

/**
 *Update the pathfinders and continue calculating the path if it hasn't been calculated yet.
 *  This method is run each frame.
 */
public void update() {
    // go through each spawnpoint, and if it's not found a path yet, update it
    for (int i = 0; i < world.getSpawns().size; i++) {
        SpawnPoint point = world.getSpawns().get(i);
        if (point.request == null || point.finder == null) {
            continue;
        }
        if (!point.request.pathFound) {
            try {
                if (point.finder.search(point.request, maxTime)) {
                    smoother.smoothPath(point.path);
                    point.pathTiles = point.path.nodes.toArray(Tile.class);
                    point.finder = null;
                }
            } catch (ArrayIndexOutOfBoundsException e) {
                // no path
                point.request.pathFound = true;
            }
        }
    }
}
Also used : Tile(io.anuke.mindustry.world.Tile) SpawnPoint(io.anuke.mindustry.game.SpawnPoint) SpawnPoint(io.anuke.mindustry.game.SpawnPoint)

Aggregations

SpawnPoint (io.anuke.mindustry.game.SpawnPoint)7 Enemy (io.anuke.mindustry.entities.enemies.Enemy)3 Tile (io.anuke.mindustry.world.Tile)3 Vector2 (com.badlogic.gdx.math.Vector2)2 Player (io.anuke.mindustry.entities.Player)2 Rectangle (com.badlogic.gdx.math.Rectangle)1 EnemySpawn (io.anuke.mindustry.game.EnemySpawn)1 InputHandler (io.anuke.mindustry.input.InputHandler)1 Recipe (io.anuke.mindustry.resource.Recipe)1 ToolFragment (io.anuke.mindustry.ui.fragments.ToolFragment)1 BlockBar (io.anuke.mindustry.world.BlockBar)1 BlockPair (io.anuke.mindustry.world.ColorMapper.BlockPair)1 SolidEntity (io.anuke.ucore.entities.SolidEntity)1