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(); } }