summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/GravityAction.java
blob: d5af521803ddee913bee4a94be5dadeb396783ca (plain) (blame)
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
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
 */