1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
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();
}
}
|