diff options
| author | Fuwn <[email protected]> | 2026-02-12 22:33:32 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-02-12 22:33:32 -0800 |
| commit | c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch) | |
| tree | df9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/console/Stair.java | |
| download | worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip | |
Initial commit
Diffstat (limited to 'NET/worlds/console/Stair.java')
| -rw-r--r-- | NET/worlds/console/Stair.java | 194 |
1 files changed, 194 insertions, 0 deletions
diff --git a/NET/worlds/console/Stair.java b/NET/worlds/console/Stair.java new file mode 100644 index 0000000..c4380d9 --- /dev/null +++ b/NET/worlds/console/Stair.java @@ -0,0 +1,194 @@ +package NET.worlds.console; + +import NET.worlds.scape.Material; +import NET.worlds.scape.NoSuchPropertyException; +import NET.worlds.scape.Point3; +import NET.worlds.scape.Point3Temp; +import NET.worlds.scape.Portal; +import NET.worlds.scape.Property; +import NET.worlds.scape.Rect; +import NET.worlds.scape.Restorer; +import NET.worlds.scape.Room; +import NET.worlds.scape.RoomEnvironment; +import NET.worlds.scape.Saver; +import NET.worlds.scape.TooNewException; +import NET.worlds.scape.World; +import java.io.IOException; + +public class Stair extends Room { + public Portal bottom; + public Portal top; + private int _lengthwise; + static final int PLUSX = 0; + static final int PLUSY = 1; + static final int MINUSX = 2; + static final int MINUSY = 3; + private float _length; + private float _width; + private float _rise; + private static Object classCookie = new Object(); + + public Stair( + World world, + String name, + float width, + float length, + float rise, + float ceilingz, + int numsteps, + Material riser, + Material tread, + Material left, + Material right, + Material head, + Material ceiling + ) { + super(world, name); + this._lengthwise = 1; + this._length = length; + this._width = width; + this._rise = rise; + RoomEnvironment env = this.getEnvironment(); + env.add(Rect.ceiling(0.0F, 0.0F, ceilingz, width, length, ceiling)); + float lowerz = ceilingz - rise; + env.add(new Rect(-0.1F, 0.0F, 0.0F, -0.1F, length, ceilingz, left)); + env.add(new Rect(width + 0.1F, length, 0.0F, width + 0.1F, 0.0F, ceilingz, right)); + env.add(new Rect(width, 0.0F, lowerz, 0.0F, 0.0F, ceilingz, head)); + this.bottom = new Portal(width, 0.0F, 0.0F, 0.0F, 0.0F, lowerz); + this.top = new Portal(0.0F, length, rise, width, length, ceilingz); + float dy = length / numsteps; + float dz = rise / numsteps; + + for (int i = 0; i < numsteps; i++) { + Rect w = new Rect(0.0F, i * dy, i * dz, width, i * dy, (i + 1) * dz, riser); + w.setTileSize(dz, dz); + env.add(w); + } + + for (int i = 0; i < numsteps; i++) { + Rect w = Rect.floor(0.0F, i * dy, (i + 1) * dz, width, (i + 1) * dy, tread); + w.setTileSize(dy, dy); + env.add(w); + } + + env.add(this.bottom); + env.add(this.top); + } + + public Stair() { + } + + void setLength(float len) { + this._length = len; + } + + void setRise(float r) { + this._rise = r; + } + + void setLengthwise(int lw) { + this._lengthwise = lw; + } + + @Override + public float floorHeight(float x, float y, float z) { + float dist = 0.0F; + switch (this._lengthwise) { + case 0: + dist = x; + break; + case 1: + dist = y; + break; + case 2: + dist = this._length - x; + break; + case 3: + dist = this._length - y; + break; + default: + assert false; + } + + return dist / this._length * this._rise; + } + + public Point3 surfaceNormal(float x, float y) { + Point3 A = new Point3(this._width, 0.0F, 0.0F); + Point3Temp B = Point3Temp.make(0.0F, this._length, this._rise); + A.cross(B); + A.normalize(); + return A; + } + + @Override + public void saveState(Saver s) throws IOException { + s.saveVersion(1, classCookie); + super.saveState(s); + s.saveFloat(this._length); + s.saveFloat(this._rise); + s.saveInt(this._lengthwise); + s.save(this.bottom); + s.save(this.top); + } + + @Override + public void restoreState(Restorer r) throws IOException, TooNewException { + switch (r.restoreVersion(classCookie)) { + case 0: + super.restoreState(r); + this._length = r.restoreFloat(); + this._rise = r.restoreFloat(); + this.bottom = (Portal)r.restore(); + this.top = (Portal)r.restore(); + this.setLengthwise(1); + break; + case 1: + super.restoreState(r); + this._length = r.restoreFloat(); + this._rise = r.restoreFloat(); + this._lengthwise = r.restoreInt(); + this.bottom = (Portal)r.restore(); + this.top = (Portal)r.restore(); + break; + default: + throw new TooNewException(); + } + } + + void superRestoreState(Restorer r) throws IOException, TooNewException { + super.restoreState(r); + } + + @Override + public Object properties(int index, int offset, int mode, Object value) throws NoSuchPropertyException { + Object ret = null; + switch (index - offset) { + case 0: + if (mode == 0) { + ret = new Property(this, index, "Length"); + } else if (mode == 1) { + ret = new Float(this._length); + } + break; + case 1: + if (mode == 0) { + ret = new Property(this, index, "Rise"); + } else if (mode == 1) { + ret = new Float(this._rise); + } + break; + case 2: + if (mode == 0) { + ret = new Property(this, index, "Direction"); + } else if (mode == 1) { + ret = new Integer(this._lengthwise); + } + break; + default: + ret = super.properties(index, offset + 3, mode, value); + } + + return ret; + } +} |