Search in sources :

Example 1 with MindVision

use of com.watabou.pixeldungeon.actors.buffs.MindVision in project pixel-dungeon by watabou.

the class Level method updateFieldOfView.

public boolean[] updateFieldOfView(Char c) {
    int cx = c.pos % WIDTH;
    int cy = c.pos / WIDTH;
    boolean sighted = c.buff(Blindness.class) == null && c.buff(Shadows.class) == null && c.isAlive();
    if (sighted) {
        ShadowCaster.castShadow(cx, cy, fieldOfView, c.viewDistance);
    } else {
        Arrays.fill(fieldOfView, false);
    }
    int sense = 1;
    if (c.isAlive()) {
        for (Buff b : c.buffs(MindVision.class)) {
            sense = Math.max(((MindVision) b).distance, sense);
        }
    }
    if ((sighted && sense > 1) || !sighted) {
        int ax = Math.max(0, cx - sense);
        int bx = Math.min(cx + sense, WIDTH - 1);
        int ay = Math.max(0, cy - sense);
        int by = Math.min(cy + sense, HEIGHT - 1);
        int len = bx - ax + 1;
        int pos = ax + ay * WIDTH;
        for (int y = ay; y <= by; y++, pos += WIDTH) {
            Arrays.fill(fieldOfView, pos, pos + len, true);
        }
        for (int i = 0; i < LENGTH; i++) {
            fieldOfView[i] &= discoverable[i];
        }
    }
    if (c.isAlive()) {
        if (c.buff(MindVision.class) != null) {
            for (Mob mob : mobs) {
                int p = mob.pos;
                fieldOfView[p] = true;
                fieldOfView[p + 1] = true;
                fieldOfView[p - 1] = true;
                fieldOfView[p + WIDTH + 1] = true;
                fieldOfView[p + WIDTH - 1] = true;
                fieldOfView[p - WIDTH + 1] = true;
                fieldOfView[p - WIDTH - 1] = true;
                fieldOfView[p + WIDTH] = true;
                fieldOfView[p - WIDTH] = true;
            }
        } else if (c == Dungeon.hero && ((Hero) c).heroClass == HeroClass.HUNTRESS) {
            for (Mob mob : mobs) {
                int p = mob.pos;
                if (distance(c.pos, p) == 2) {
                    fieldOfView[p] = true;
                    fieldOfView[p + 1] = true;
                    fieldOfView[p - 1] = true;
                    fieldOfView[p + WIDTH + 1] = true;
                    fieldOfView[p + WIDTH - 1] = true;
                    fieldOfView[p - WIDTH + 1] = true;
                    fieldOfView[p - WIDTH - 1] = true;
                    fieldOfView[p + WIDTH] = true;
                    fieldOfView[p - WIDTH] = true;
                }
            }
        }
        if (c.buff(Awareness.class) != null) {
            for (Heap heap : heaps.values()) {
                int p = heap.pos;
                fieldOfView[p] = true;
                fieldOfView[p + 1] = true;
                fieldOfView[p - 1] = true;
                fieldOfView[p + WIDTH + 1] = true;
                fieldOfView[p + WIDTH - 1] = true;
                fieldOfView[p - WIDTH + 1] = true;
                fieldOfView[p - WIDTH - 1] = true;
                fieldOfView[p + WIDTH] = true;
                fieldOfView[p - WIDTH] = true;
            }
        }
    }
    return fieldOfView;
}
Also used : Shadows(com.watabou.pixeldungeon.actors.buffs.Shadows) Mob(com.watabou.pixeldungeon.actors.mobs.Mob) Awareness(com.watabou.pixeldungeon.actors.buffs.Awareness) Blindness(com.watabou.pixeldungeon.actors.buffs.Blindness) Buff(com.watabou.pixeldungeon.actors.buffs.Buff) MindVision(com.watabou.pixeldungeon.actors.buffs.MindVision) Heap(com.watabou.pixeldungeon.items.Heap)

Aggregations

Awareness (com.watabou.pixeldungeon.actors.buffs.Awareness)1 Blindness (com.watabou.pixeldungeon.actors.buffs.Blindness)1 Buff (com.watabou.pixeldungeon.actors.buffs.Buff)1 MindVision (com.watabou.pixeldungeon.actors.buffs.MindVision)1 Shadows (com.watabou.pixeldungeon.actors.buffs.Shadows)1 Mob (com.watabou.pixeldungeon.actors.mobs.Mob)1 Heap (com.watabou.pixeldungeon.items.Heap)1