summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/AnimatingDoor.java
blob: 9007d0b6a6eceb91af66ce2210f99e34f8629377 (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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
/*     */ package NET.worlds.scape;
/*     */ 
/*     */ import NET.worlds.core.Std;
/*     */ import NET.worlds.network.URL;
/*     */ import java.io.IOException;
/*     */ import java.net.MalformedURLException;
/*     */ import java.util.StringTokenizer;
/*     */ import java.util.Vector;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class AnimatingDoor
/*     */   extends Portal
/*     */   implements FrameHandler
/*     */ {
/*     */   public AnimatingDoor()
/*     */   {
/*  36 */     this.flags |= 0x40040;
/*     */   }
/*     */   
/*     */ 
/*  40 */   public String frameList = "";
/*  41 */   protected transient Material[] frames = null;
/*  42 */   float perFrame = 100.0F;
/*     */   
/*     */   private URL openSound;
/*     */   
/*     */   private URL closeSound;
/*     */   private transient float state;
/*     */   private transient int lastUpdate;
/*     */   private transient boolean wasSameRoom;
/*  50 */   private transient int lastFrame = -1;
/*     */   
/*  52 */   private Point3 start = new Point3(-0.5F, -1.0F, 0.0F);
/*  53 */   private Point3 end = new Point3(1.5F, 0.0F, 1.0F);
/*     */   
/*     */ 
/*     */ 
/*     */   public void detach()
/*     */   {
/*  59 */     if (this.frames != null) {
/*  60 */       int i = this.frames.length;
/*  61 */       do { this.frames[i].setKeepLoaded(false);i--;
/*  60 */       } while (i >= 0);
/*     */       
/*  62 */       this.frames = null;
/*     */     }
/*  64 */     super.detach();
/*     */   }
/*     */   
/*     */   public boolean handle(FrameEvent e)
/*     */   {
/*  69 */     Pilot pilot = Pilot.getActive();
/*  70 */     Room pilotRoom = pilot.getRoom();
/*  71 */     boolean sameRoom = pilotRoom == getRoom();
/*  72 */     boolean inRange = false;
/*  73 */     Point3Temp pos = pilot.getPosition();
/*     */     
/*  75 */     if (sameRoom)
/*     */     {
/*  77 */       BoundBoxTemp bbt = BoundBoxTemp.make(
/*  78 */         Point3Temp.make(this.start).times(this), 
/*  79 */         Point3Temp.make(this.end).times(this));
/*     */       
/*  81 */       inRange = bbt.contains(pos);
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*  92 */     Portal far = farSide();
/*  93 */     if ((far != null) && ((far instanceof AnimatingDoor))) {
/*  94 */       AnimatingDoor afar = (AnimatingDoor)far;
/*     */       
/*     */ 
/*  97 */       if (!inRange) {
/*  98 */         Room farRoom = afar.getRoom();
/*  99 */         if (farRoom == null) {
/* 100 */           animate(sameRoom, inRange);
/* 101 */           return true;
/*     */         }
/*     */         
/* 104 */         if (afar.getRoom() == pilotRoom) {
/* 105 */           if (!sameRoom)
/*     */           {
/*     */ 
/* 108 */             return true;
/*     */           }
/*     */           
/*     */ 
/* 112 */           BoundBoxTemp bbt = BoundBoxTemp.make(
/* 113 */             Point3Temp.make(afar.start).times(afar), 
/* 114 */             Point3Temp.make(afar.end).times(afar));
/*     */           
/* 116 */           inRange = bbt.contains(pos);
/*     */         }
/*     */       }
/*     */       
/* 120 */       afar.animate(sameRoom, inRange);
/*     */     }
/*     */     
/* 123 */     animate(sameRoom, inRange);
/*     */     
/* 125 */     return true;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   private void animate(boolean sameRoom, boolean inRange)
/*     */   {
/* 133 */     int now = Std.getFastTime();
/* 134 */     float oldState = this.state;
/*     */     
/*     */ 
/* 137 */     if (this.frames == null) {
/* 138 */       this.frames = namesToMaterialArray(this, this.frameList);
/* 139 */       this.lastFrame = -1;
/*     */     }
/*     */     
/* 142 */     int numMovingFrames = this.frames.length - 2;
/* 143 */     boolean wasSameRoom = this.wasSameRoom;
/* 144 */     this.wasSameRoom = sameRoom;
/*     */     
/* 146 */     if (!sameRoom)
/*     */     {
/* 148 */       this.state = 0.0F;
/* 149 */     } else if (!wasSameRoom)
/*     */     {
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 156 */       this.state = (inRange ? 1.0F : 0.0F);
/* 157 */     } else if (this.state == 0.0F) {
/* 158 */       if (!inRange) {
/* 159 */         return;
/*     */       }
/*     */       
/*     */ 
/*     */ 
/* 164 */       this.state = 1.0E-4F;
/* 165 */     } else if (this.state == 1.0F) {
/* 166 */       if (inRange) {
/* 167 */         return;
/*     */       }
/*     */       
/* 170 */       playSound(this.closeSound);
/*     */       
/* 172 */       this.state = 0.999F;
/*     */     } else {
/* 174 */       if ((this.state == 1.0E-4F) && (inRange)) {
/* 175 */         if (active())
/*     */         {
/* 177 */           playSound(this.openSound);
/* 178 */           this.state = 2.0E-4F;
/*     */         }
/*     */         else {
/* 181 */           this.lastUpdate = now;
/*     */         }
/*     */       }
/*     */       
/*     */ 
/*     */ 
/* 187 */       float totalTime = numMovingFrames * this.perFrame;
/* 188 */       if ((totalTime > 0.0F) && (now != this.lastUpdate)) {
/* 189 */         float distMoved = (now - this.lastUpdate) / totalTime;
/* 190 */         if (inRange) {
/* 191 */           if (this.state += distMoved >= 1.0F) {
/* 192 */             this.state = 1.0F;
/*     */           }
/* 194 */         } else if (this.state -= distMoved <= 0.0F) {
/* 195 */           this.state = 0.0F;
/*     */         }
/*     */       }
/*     */     }
/*     */     
/* 200 */     if ((oldState != 0.0F) && (this.state == 0.0F))
/*     */     {
/* 202 */       this.flags |= 0x40000;
/* 203 */       reset();
/* 204 */     } else if ((oldState == 0.0F) && (this.state != 0.0F))
/*     */     {
/* 206 */       this.flags &= 0xFFFBFFFF;
/* 207 */       reset();
/*     */       
/*     */ 
/* 210 */       triggerLoad();
/*     */     }
/*     */     
/* 213 */     this.lastUpdate = now;
/*     */     
/*     */ 
/* 216 */     int frame = 0;
/*     */     
/* 218 */     if (numMovingFrames >= 0) {
/* 219 */       if (this.state <= 2.0E-4F) {
/* 220 */         frame = 0;
/* 221 */       } else if (this.state == 1.0F) {
/* 222 */         frame = numMovingFrames + 1;
/*     */       } else
/* 224 */         frame = 1 + (int)(this.state * numMovingFrames);
/* 225 */     } else if (numMovingFrames == -2) {
/* 226 */       return;
/*     */     }
/* 228 */     setFrame(frame);
/*     */   }
/*     */   
/*     */   private void setFrame(int frame) {
/* 232 */     if ((frame != this.lastFrame) && (this.frames != null) && (this.frames.length > frame))
/*     */     {
/* 234 */       setMaterial(this.frames[frame]);
/* 235 */       this.lastFrame = frame;
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */   private void playSound(URL url)
/*     */   {
/* 242 */     if ((url == null) || (getRoom() != Pilot.getActive().getRoom())) {
/* 243 */       return;
/*     */     }
/* 245 */     WavSoundPlayer wavPlayer = new WavSoundPlayer(null);
/* 246 */     wavPlayer.open(1.0F, 0.0F, false, false);
/* 247 */     wavPlayer.start(url);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static Material[] namesToMaterialArray(SuperRoot base, String str)
/*     */   {
/* 257 */     Vector<String> v = new Vector();
/* 258 */     StringTokenizer st = new StringTokenizer(str);
/* 259 */     while (st.hasMoreTokens()) {
/* 260 */       v.addElement(st.nextToken());
/*     */     }
/*     */     
/* 263 */     int count = v.size();
/*     */     
/* 265 */     Material[] mats = new Material[count];
/* 266 */     int i = count;
/* 267 */     do { String s = (String)v.elementAt(i);
/*     */       URL url;
/*     */       try {
/* 270 */         url = new URL(base, s);
/*     */       } catch (MalformedURLException e) { URL url;
/* 272 */         url = URL.make("error:\"" + s + '"');
/*     */       }
/* 274 */       mats[i] = new Material(url);
/*     */       
/*     */ 
/*     */ 
/* 278 */       mats[i].setKeepLoaded(true);i--;
/* 266 */     } while (i >= 0);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 281 */     return mats;
/*     */   }
/*     */   
/*     */ 
/*     */   public Object properties(int index, int offset, int mode, Object value)
/*     */     throws NoSuchPropertyException
/*     */   {
/* 288 */     Object ret = null;
/* 289 */     switch (index - offset) {
/*     */     case 0: 
/* 291 */       if (mode == 0) {
/* 292 */         ret = StringPropertyEditor.make(
/* 293 */           new Property(this, index, "Frame List"));
/* 294 */       } else if (mode == 1) {
/* 295 */         ret = this.frameList;
/* 296 */       } else if (mode == 2) {
/* 297 */         this.frameList = ((String)value).toString().trim();
/* 298 */         this.frames = null;
/*     */       }
/* 300 */       break;
/*     */     case 1: 
/* 302 */       if (mode == 0) {
/* 303 */         ret = Point3PropertyEditor.make(new Property(this, index, 
/* 304 */           "Start"));
/* 305 */       } else if (mode == 1) {
/* 306 */         ret = new Point3(this.start);
/* 307 */       } else if (mode == 2)
/* 308 */         this.start = ((Point3)value);
/* 309 */       break;
/*     */     case 2: 
/* 311 */       if (mode == 0) {
/* 312 */         ret = Point3PropertyEditor.make(new Property(this, index, 
/* 313 */           "End"));
/* 314 */       } else if (mode == 1) {
/* 315 */         ret = new Point3(this.end);
/* 316 */       } else if (mode == 2)
/* 317 */         this.end = ((Point3)value);
/* 318 */       break;
/*     */     case 3: 
/* 320 */       if (mode == 0) {
/* 321 */         ret = FloatPropertyEditor.make(
/* 322 */           new Property(this, index, "Time Per Frame"));
/* 323 */       } else if (mode == 1) {
/* 324 */         ret = new Float(this.perFrame);
/* 325 */       } else if (mode == 2)
/* 326 */         this.perFrame = ((Float)value).floatValue();
/* 327 */       break;
/*     */     case 4: 
/* 329 */       if (mode == 0) {
/* 330 */         ret = URLPropertyEditor.make(
/* 331 */           new Property(this, index, "Open Sound URL")
/* 332 */           .allowSetNull(), 
/* 333 */           "wav;mid;ram;ra;rm");
/* 334 */       } else if (mode == 1) {
/* 335 */         ret = this.openSound;
/* 336 */       } else if (mode == 2)
/* 337 */         this.openSound = ((URL)value);
/* 338 */       break;
/*     */     case 5: 
/* 340 */       if (mode == 0) {
/* 341 */         ret = URLPropertyEditor.make(
/* 342 */           new Property(this, index, "Close Sound URL")
/* 343 */           .allowSetNull(), 
/* 344 */           "wav;mid;ram;ra;rm");
/* 345 */       } else if (mode == 1) {
/* 346 */         ret = this.closeSound;
/* 347 */       } else if (mode == 2)
/* 348 */         this.closeSound = ((URL)value);
/* 349 */       break;
/*     */     default: 
/* 351 */       ret = super.properties(index, offset + 6, mode, value);
/*     */     }
/* 353 */     return ret;
/*     */   }
/*     */   
/*     */ 
/* 357 */   private static Object classCookie = new Object();
/*     */   
/*     */   public void saveState(Saver s) throws IOException
/*     */   {
/* 361 */     setFrame(0);
/*     */     
/* 363 */     s.saveVersion(0, classCookie);
/* 364 */     int f = this.flags;
/* 365 */     this.flags |= 0x40000;
/* 366 */     super.saveState(s);
/* 367 */     this.flags = f;
/*     */     
/* 369 */     s.saveString(this.frameList);
/* 370 */     s.saveFloat(this.perFrame);
/* 371 */     s.save(this.start);
/* 372 */     s.save(this.end);
/* 373 */     URL.save(s, this.openSound);
/* 374 */     URL.save(s, this.closeSound);
/*     */   }
/*     */   
/*     */   public void restoreState(Restorer r) throws IOException, TooNewException {
/* 378 */     switch (r.restoreVersion(classCookie)) {
/*     */     case 0: 
/* 380 */       super.restoreState(r);
/* 381 */       this.frameList = r.restoreString();
/* 382 */       this.perFrame = r.restoreFloat();
/* 383 */       this.start = ((Point3)r.restore());
/* 384 */       this.end = ((Point3)r.restore());
/* 385 */       this.openSound = URL.restore(r);
/* 386 */       this.closeSound = URL.restore(r);
/* 387 */       break;
/*     */     
/*     */     default: 
/* 390 */       throw new TooNewException();
/*     */     }
/*     */   }
/*     */ }


/* Location:              C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\AnimatingDoor.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */