/*
 * Decompiled with CFR 0.152.
 */
import java.util.Vector;

public abstract class fs
extends gm {
    private final Vector a = new Vector(32, 32);
    private int b = -1;

    public final boolean d(gm gm2) {
        return this.a(gm2, this.m());
    }

    public void a(gm gm2) {
    }

    public fs(int n, int n2, int n3, int n4) {
        super(n, n2, n3, n4);
    }

    public fs() {
    }

    public final void o() {
        this.i(null);
    }

    public final boolean e(gm gm2) {
        return this.d(gm2);
    }

    public final boolean g(int n) {
        return this.b_(n);
    }

    public final int g(gm gm2) {
        return this.a.indexOf(gm2);
    }

    public final gm h(int n) {
        return (gm)this.a.elementAt(n);
    }

    public final gm n() {
        return (gm)this.a.lastElement();
    }

    public final int m() {
        return this.a.size();
    }

    public int r_() {
        return 0;
    }

    public int f() {
        return 0;
    }

    public boolean b() {
        return false;
    }

    public final boolean k() {
        return this.j();
    }

    public final boolean j() {
        if (!this.l()) {
            return false;
        }
        while (this.l()) {
            this.b_(this.m() - 1);
        }
        return true;
    }

    public final boolean l() {
        return this.m() != 0;
    }

    public int g() {
        if (this.b()) {
            return super.g();
        }
        return 500;
    }

    public final boolean h(gm gm2) {
        return gm2 != null && gm2.v == this;
    }

    public final boolean f(gm gm2) {
        int n;
        if (gm2 != null && gm2.v == this && (n = this.g(gm2)) != -1) {
            return this.b_(n);
        }
        return false;
    }

    public int c(int n, int n2) {
        n = n != 1 ? (n != 2 ? -1 : n2 + 1) : n2 - 1;
        if (n >= 0 && n < this.m()) {
            return n;
        }
        return -1;
    }

    public final void b(gh gh2) {
        gm gm2;
        if (!this.b() && (gm2 = this.q()) != null) {
            gm2.b(gh2);
            gh2.a += gm2.p + this.r_();
            gh2.b += gm2.q + this.f();
            return;
        }
        super.b(gh2);
    }

    public final gm r() {
        if (this.t_()) {
            gm gm2 = this.q();
            if (gm2 != null) {
                return gm2.r();
            }
            return this;
        }
        return null;
    }

    public final gm q() {
        if (this.b != -1) {
            return this.h(this.b);
        }
        return null;
    }

    public final void p() {
        super.p();
        if (this.b != -1) {
            this.h(this.b).p();
            this.b = -1;
        }
    }

    public final void i(gm gm2) {
        super.o();
        int n = this.g(gm2);
        if (n != this.b) {
            if (n != -1) {
                gm2.a(true);
            }
            if (this.b != -1) {
                this.h(this.b).p();
                this.b = -1;
            }
            this.b = n;
        }
    }

    public void c_(int n) {
        int n2 = this.m();
        for (int i = 0; i < n2; ++i) {
            this.h(i).c_(n);
        }
    }

    public void b(ht ht2, int n, int n2) {
        int n3 = this.r_();
        int n4 = this.f();
        if (n3 != 0 || n4 != 0) {
            ht2.a(n3, n4);
        }
        int n5 = this.m();
        for (int i = 0; i < n5; ++i) {
            this.h(i).a(ht2, n, n2);
        }
        if (n3 != 0 || n4 != 0) {
            ht2.a(-n3, -n4);
        }
    }

    public int a(pb pb2) {
        int n;
        block2: {
            int n2 = this.m();
            for (int i = 0; i < n2; ++i) {
                gm gm2 = this.h(i);
                if (!gm2.x() || (n = gm2.a(pb2)) == -1) {
                    continue;
                }
                break block2;
            }
            return -1;
        }
        return n;
    }

    public int a(nj nj2, int n, int n2) {
        int n3;
        block3: {
            block4: {
                block2: {
                    gm gm2;
                    if (!this.t_() || !this.g(n -= this.p, n2 -= this.q)) break block2;
                    n3 = this.b(nj2, n, n2);
                    if (n3 != -1) break block3;
                    n -= this.r_();
                    if (this.b != -1 && (gm2 = this.h(this.b)).t_() && (n = gm2.a(nj2, n, n2 -= this.f())) != -1 || (n = this.a(nj2)) != -1) break block4;
                }
                return -1;
            }
            return n;
        }
        return n3;
    }

    public boolean b_(int n) {
        gm gm2 = this.h(n);
        if (gm2 != null && gm2.v == this) {
            if (n != this.b) {
                gm2.a(true);
            }
            gm2.t();
            gm2.v = null;
            gm2.t();
            this.a.removeElementAt(n);
            if (n != this.b) {
                if (this.b != -1 && n < this.b) {
                    --this.b;
                    return true;
                }
            } else {
                this.b = -1;
            }
            return true;
        }
        return false;
    }

    public boolean a(gm gm2, int n) {
        if (gm2 != null && gm2.v != this) {
            boolean bl2;
            if (gm2.v != null) {
                fs fs2 = gm2.v;
                gm2.v.f(gm2);
                fs2.t();
            }
            if (!(bl2 = this.y().r().g() < gm2.r().g())) {
                gm2.p();
            } else {
                this.i(null);
            }
            gm2.v = this;
            this.a.insertElementAt(gm2, n);
            gm2.t();
            if (!bl2) {
                if (this.b != -1 && n <= this.b) {
                    ++this.b;
                }
                return true;
            }
            this.b = n;
            return true;
        }
        return false;
    }

    public final boolean a(int n, gh gh2, boolean bl2) {
        if (this.b()) {
            return super.a(n, gh2, bl2);
        }
        int n2 = this.b;
        if (n2 == -1) {
            n2 = this.m();
            n2 = n2 > 0 ? (n != 1 && n != 3 ? 0 : --n2) : -1;
        }
        while (n2 != -1) {
            gm gm2 = this.h(n2);
            if (!gm2.a(n, gh2, bl2)) {
                n2 = this.c(n, n2);
                continue;
            }
            if (gh2 != null) {
                gh2.a += gm2.p;
                gh2.b += gm2.q;
            }
            return true;
        }
        return false;
    }

    public final boolean a(int n, int n2, int[] nArray, boolean bl2, boolean bl3) {
        gm gm2;
        if (this.b()) {
            return super.a(n, n2, nArray, bl2, bl3);
        }
        int n3 = Integer.MAX_VALUE;
        int n4 = Integer.MAX_VALUE;
        int n5 = Integer.MAX_VALUE;
        int n6 = -1;
        int n7 = n - this.r_();
        n2 -= this.f();
        int n8 = this.m();
        for (int i = 0; i < n8; ++i) {
            gm2 = this.h(i);
            if (!gm2.a(n7 - gm2.p, n2 - gm2.q, nArray, false, bl3)) continue;
            int n9 = nArray[0];
            n = nArray[1];
            int n10 = n9 * n9 + n * n;
            if (n10 < n4) {
                n6 = i;
                n3 = n9;
                n4 = n10;
            } else {
                n = n5;
            }
            n5 = n;
            if (n10 == 0) break;
        }
        if (n6 != -1) {
            nArray[0] = n3;
            nArray[1] = n5;
            if (bl2) {
                gm2 = this.h(n6);
                gm2.a(n7 - gm2.p, n2 - gm2.q, nArray, bl2, bl3);
            }
            return true;
        }
        return false;
    }
}

