diff options
| author | Fuwn <[email protected]> | 2021-05-03 16:38:41 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-05-03 16:38:41 -0700 |
| commit | e1e781bb2135ef78592226f1a3eaba4925702f1f (patch) | |
| tree | 8a5b590463ed413e1c6eabb719130e701b95ca63 /NET/worlds/scape/GravityAction.java | |
| download | worlds.jar-main.tar.xz worlds.jar-main.zip | |
Diffstat (limited to 'NET/worlds/scape/GravityAction.java')
| -rw-r--r-- | NET/worlds/scape/GravityAction.java | 241 |
1 files changed, 241 insertions, 0 deletions
diff --git a/NET/worlds/scape/GravityAction.java b/NET/worlds/scape/GravityAction.java new file mode 100644 index 0000000..d5af521 --- /dev/null +++ b/NET/worlds/scape/GravityAction.java @@ -0,0 +1,241 @@ +/* */ package NET.worlds.scape; +/* */ +/* */ import NET.worlds.core.Std; +/* */ import java.io.IOException; +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public class GravityAction +/* */ extends Action +/* */ { +/* 20 */ public float cycleTime = 0.0F; +/* */ int startTime; +/* 22 */ public int force = 300; +/* 23 */ public float xDest = 0.0F; +/* 24 */ public float yDest = 0.0F; +/* 25 */ public float zDest = 0.0F; +/* */ +/* */ static final float epsilon = 2.0F; +/* */ int lastFrameTime; +/* 29 */ float initialDistance = 0.0F; +/* */ +/* */ Point3 initialPoint; +/* 32 */ protected boolean gravityEnd = true; +/* */ +/* */ +/* */ +/* */ public void startGravity() +/* */ { +/* 38 */ this.startTime = Std.getRealTime(); +/* */ +/* 40 */ this.gravityEnd = false; +/* 41 */ this.lastFrameTime = 0; +/* */ } +/* */ +/* */ +/* */ +/* */ private float distance(float tx, float ty, float tz, float cx, float cy, float cz) +/* */ { +/* 48 */ float dx = tx - cx; +/* 49 */ float dy = ty - cy; +/* 50 */ float dz = tz - cz; +/* */ +/* 52 */ float dist = (float)Math.sqrt(dx * dx + dy * dy + dz * dz); +/* */ +/* 54 */ return dist; +/* */ } +/* */ +/* */ public void doGravity(Pilot pilotObject, WObject o) +/* */ { +/* 59 */ int currentFrameTime = Std.getRealTime(); +/* */ +/* 61 */ float r = distance(pilotObject.getX(), pilotObject.getY(), +/* 62 */ pilotObject.getZ(), o.getX(), o.getY(), o.getZ()); +/* 63 */ if (this.lastFrameTime == 0) { +/* 64 */ this.lastFrameTime = currentFrameTime; +/* */ } +/* 66 */ float distanceTraveled = distance(this.initialPoint.x, this.initialPoint.y, +/* 67 */ this.initialPoint.z, pilotObject.getX(), pilotObject.getY(), +/* 68 */ pilotObject.getZ()); +/* */ +/* */ +/* */ +/* */ +/* 73 */ this.initialDistance = distance(this.initialPoint.x, this.initialPoint.y, +/* 74 */ this.initialPoint.z, o.getX(), o.getY(), o.getZ()); +/* */ +/* 76 */ if ((r > 2.0F) && (distanceTraveled <= this.initialDistance)) { +/* 77 */ float dx = o.getX() - pilotObject.getX(); +/* 78 */ if (dx != 0.0D) { +/* 79 */ float new_dx = (currentFrameTime - this.lastFrameTime) * this.force * dx / ( +/* 80 */ r * r); +/* 81 */ if (Math.abs(new_dx) < Math.abs(dx)) { +/* 82 */ dx = new_dx; +/* */ } +/* */ } +/* 85 */ float dy = o.getY() - pilotObject.getY(); +/* 86 */ if (dy != 0.0D) { +/* 87 */ float new_dy = (currentFrameTime - this.lastFrameTime) * this.force * dy / ( +/* 88 */ r * r); +/* 89 */ if (Math.abs(new_dy) < Math.abs(dy)) { +/* 90 */ dy = new_dy; +/* */ } +/* */ } +/* 93 */ float dz = o.getZ() - pilotObject.getZ(); +/* 94 */ if (dz != 0.0D) { +/* 95 */ float new_dz = (currentFrameTime - this.lastFrameTime) * this.force * dz / ( +/* 96 */ r * r); +/* 97 */ if (Math.abs(new_dz) < Math.abs(dz)) { +/* 98 */ dz = new_dz; +/* */ } +/* */ } +/* */ +/* 102 */ pilotObject.moveBy(dx, dy, dz); +/* */ +/* */ } +/* */ else +/* */ { +/* */ +/* 108 */ pilotObject.moveTo(o.getX(), o.getY(), o.getZ()); +/* 109 */ this.gravityEnd = true; +/* */ } +/* */ +/* 112 */ this.lastFrameTime = currentFrameTime; +/* */ } +/* */ +/* */ public Persister trigger(Event e, Persister seqID) +/* */ { +/* 117 */ Object owner = getOwner(); +/* 118 */ if ((owner == null) || (!(owner instanceof WObject))) { +/* 119 */ return null; +/* */ } +/* 121 */ WObject o = (WObject)owner; +/* */ +/* 123 */ Pilot pilot = Pilot.getActive(); +/* 124 */ if (pilot == null) { +/* 125 */ return null; +/* */ } +/* */ +/* 128 */ if (pilot.getRoom() != o.getRoom()) { +/* 129 */ if ((this.gravityEnd) && ((pilot instanceof HoloPilot))) { +/* 130 */ HoloPilot hp = (HoloPilot)pilot; +/* 131 */ hp.returnSmoothDriver(); +/* */ } +/* 133 */ return null; +/* */ } +/* */ +/* 136 */ if (this.gravityEnd) { +/* 137 */ startGravity(); +/* 138 */ if ((pilot instanceof HoloPilot)) { +/* 139 */ HoloPilot hp = (HoloPilot)pilot; +/* 140 */ hp.removeSmoothDriver(); +/* */ +/* 142 */ this.initialPoint = new Point3(pilot.getPosition()); +/* 143 */ this.initialDistance = distance(this.initialPoint.x, this.initialPoint.y, +/* 144 */ this.initialPoint.z, o.getX(), o.getY(), o.getZ()); +/* */ } +/* */ } +/* */ +/* */ +/* 149 */ doGravity(pilot, o); +/* */ +/* 151 */ if (this.gravityEnd) { +/* 152 */ if ((pilot instanceof HoloPilot)) { +/* 153 */ HoloPilot hp = (HoloPilot)pilot; +/* 154 */ hp.returnSmoothDriver(); +/* */ } +/* 156 */ return null; +/* */ } +/* */ +/* 159 */ return this; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ public Object properties(int index, int offset, int mode, Object value) +/* */ throws NoSuchPropertyException +/* */ { +/* 168 */ Object ret = null; +/* 169 */ switch (index - offset) { +/* */ case 0: +/* 171 */ if (mode == 0) { +/* 172 */ ret = IntegerPropertyEditor.make(new Property(this, index, +/* 173 */ "Force")); +/* 174 */ } else if (mode == 1) { +/* 175 */ ret = new Integer(this.force); +/* 176 */ } else if (mode == 2) +/* 177 */ this.force = ((Integer)value).intValue(); +/* 178 */ break; +/* */ default: +/* 180 */ ret = super.properties(index, offset + 1, mode, value); +/* */ } +/* 182 */ return ret; +/* */ } +/* */ +/* */ public String toString() +/* */ { +/* 187 */ return super.toString() + "[Force " + this.force + "]"; +/* */ } +/* */ +/* 190 */ private static Object classCookie = new Object(); +/* */ +/* */ public void saveState(Saver s) throws IOException +/* */ { +/* 194 */ s.saveVersion(4, classCookie); +/* 195 */ super.saveState(s); +/* 196 */ s.saveInt(this.force); +/* */ } +/* */ +/* */ public void restoreState(Restorer r) throws IOException, TooNewException +/* */ { +/* 201 */ switch (r.restoreVersion(classCookie)) { +/* */ case 0: +/* 203 */ super.restoreState(r); +/* 204 */ r.restore(); +/* 205 */ this.cycleTime = r.restoreFloat(); +/* 206 */ this.force = r.restoreInt(); +/* 207 */ break; +/* */ case 1: +/* 209 */ super.restoreState(r); +/* 210 */ this.cycleTime = r.restoreFloat(); +/* 211 */ this.force = r.restoreInt(); +/* 212 */ break; +/* */ case 2: +/* 214 */ super.restoreState(r); +/* 215 */ this.cycleTime = r.restoreFloat(); +/* 216 */ this.force = r.restoreInt(); +/* 217 */ this.xDest = r.restoreFloat(); +/* 218 */ this.yDest = r.restoreFloat(); +/* 219 */ break; +/* */ case 3: +/* 221 */ super.restoreState(r); +/* 222 */ this.force = r.restoreInt(); +/* 223 */ this.xDest = r.restoreFloat(); +/* 224 */ this.yDest = r.restoreFloat(); +/* 225 */ this.zDest = r.restoreFloat(); +/* 226 */ break; +/* */ case 4: +/* 228 */ super.restoreState(r); +/* 229 */ this.force = r.restoreInt(); +/* 230 */ break; +/* */ default: +/* 232 */ throw new TooNewException(); +/* */ } +/* */ } +/* */ } + + +/* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\GravityAction.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 0.7.1 + */
\ No newline at end of file |