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/scape/WrStaircase.java | |
| download | worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip | |
Initial commit
Diffstat (limited to 'NET/worlds/scape/WrStaircase.java')
| -rw-r--r-- | NET/worlds/scape/WrStaircase.java | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/NET/worlds/scape/WrStaircase.java b/NET/worlds/scape/WrStaircase.java new file mode 100644 index 0000000..78ee4bc --- /dev/null +++ b/NET/worlds/scape/WrStaircase.java @@ -0,0 +1,137 @@ +package NET.worlds.scape; + +import java.io.IOException; + +public class WrStaircase extends Room { + private static final float epsilon = 0.01F; + public Portal portal1; + public Portal portal2; + private float dzByLength; + + public WrStaircase( + World world, + String name, + float length, + float width, + float pWidth, + float pHeight, + float dz, + float lintelZ, + int numSteps, + Material riser, + Material tread, + Material left, + Material right, + Material doorpost, + Material lintel, + Material ceiling + ) { + super(world, name); + if (pWidth > width) { + System.out.println("WrStaircase: portal too wide; reducing."); + pWidth = width; + } + + if (length < 0.0F) { + System.out.println("WrStaircase: length must be positive; inverting."); + length = -length; + } + + if (width < 0.0F) { + System.out.println("WrStaircase: width must be positive; inverting."); + width = -width; + } + + if (pWidth < 0.0F) { + System.out.println("WrStaircase: portal width must be positive; inverting."); + pWidth = -pWidth; + } + + if (pHeight < 0.0F) { + System.out.println("WrStaircase: portal height must be positive; inverting."); + pHeight = -pHeight; + } + + if (lintelZ < 0.0F) { + System.out.println("WrStaircase: lintel height must be positive; ignoring."); + lintelZ = 0.0F; + } + + if (numSteps < 2) { + System.out.println("WrStaircase: must have at least 2 steps."); + numSteps = 2; + } + + RoomEnvironment env = this.getEnvironment(); + float postX = (width - pWidth) / 2.0F; + float bottom = Math.min(dz, 0.0F); + float ceilingHeight = Math.max(dz, 0.0F) + pHeight + lintelZ; + this.dzByLength = dz / length; + this.portal1 = new Portal(width - postX, 0.0F, 0.0F, postX, 0.0F, pHeight); + this.portal2 = new Portal(postX, length, dz, width - postX, length, dz + pHeight); + env.add(this.portal1); + env.add(this.portal2); + float stepWidth = length / numSteps; + float stepHeight = dz / numSteps; + + for (int i = 1; i <= numSteps; i++) { + Rect w = new Rect(0.0F, i * stepWidth, (i - 1) * stepHeight, width, i * stepWidth, i * stepHeight - 0.01F, riser); + w.setTileSize(stepHeight, stepHeight); + env.add(w); + } + + for (int i = 0; i < numSteps; i++) { + Rect w = Rect.floor(0.0F, i * stepWidth, i * stepHeight, width, (i + 1) * stepWidth - 0.01F, tread); + w.setTileSize(Math.abs(stepWidth), Math.abs(stepWidth)); + env.add(w); + } + + if (ceilingHeight > pHeight) { + env.add(new Rect(width, 0.0F, pHeight, 0.0F, 0.0F, ceilingHeight - 0.01F, lintel)); + } + + if (ceilingHeight > dz + pHeight) { + env.add(new Rect(0.0F, length, dz + pHeight, width, length, ceilingHeight - 0.01F, lintel)); + } + + if (width > pWidth) { + env.add(new Rect(width, 0.0F, 0.0F, width - postX, 0.0F, pHeight, doorpost)); + env.add(new Rect(postX, 0.0F, 0.0F, 0.0F, 0.0F, pHeight, doorpost)); + env.add(new Rect(0.0F, length, dz, postX, length, dz + pHeight, doorpost)); + env.add(new Rect(width - postX, length, dz, width, length, dz + pHeight, doorpost)); + } + + env.add(Rect.ceiling(0.0F, 0.0F, ceilingHeight, width, length, ceiling)); + env.add(new Rect(-0.01F, 0.0F, bottom, -0.01F, length, ceilingHeight, left)); + env.add(new Rect(width + 0.01F, length, bottom, width + 0.01F, 0.0F, ceilingHeight, right)); + } + + public WrStaircase() { + } + + @Override + public float floorHeight(float x, float y, float z) { + return y * this.dzByLength; + } + + @Override + public Point3 surfaceNormal(float x, float y, float z) { + Point3 A = new Point3(1.0F, 0.0F, 0.0F); + Point3Temp B = Point3Temp.make(0.0F, 1.0F, this.dzByLength); + A.cross(B); + A.normalize(); + return A; + } + + @Override + public void saveState(Saver s) throws IOException { + super.saveState(s); + s.saveFloat(this.dzByLength); + } + + @Override + public void restoreState(Restorer r) throws IOException, TooNewException { + super.restoreState(r); + this.dzByLength = r.restoreFloat(); + } +} |