summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/TwoWayPortal.java
blob: c9c3b0c001b3f6ecaf709c03f8de5498c210c246 (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
package NET.worlds.scape;

import java.io.IOException;

public class TwoWayPortal extends Portal {
   private static Object classCookie = new Object();

   public TwoWayPortal(String targetRoom, float llx, float lly, float llz, float urx, float ury, float urz) {
      super(llx, lly, llz, urx, ury, urz);
      this.setFarSideInfo(null, targetRoom, null);
   }

   public TwoWayPortal() {
   }

   @Override
   public void saveState(Saver s) throws IOException {
      s.saveVersion(0, classCookie);
      super.saveState(s);
   }

   @Override
   public void restoreState(Restorer r) throws IOException, TooNewException {
      int vers = r.restoreVersion(classCookie);
      switch (vers) {
         case 0:
            super.restoreState(r);
            return;
         default:
            throw new TooNewException();
      }
   }

   @Override
   public void detach() throws ClassCastException {
      super.detach();
      Portal p = this.farSide();
      if (p != null) {
         p.detach();
      }
   }

   @Override
   public void reset(boolean showmessage) {
      super.reset(showmessage);
      if (this.farSideRoom() != null) {
         Portal p = this.farSide();
         if (p != null) {
            if (p.isActive()) {
               return;
            }

            p.detach();
            this.bidisconnect();
         }

         Point3Temp left = this.getWorldPosition();
         Point3Temp right = this.getFarCorner();
         p = new Portal(right.x, right.y, left.z, left.x, left.y, right.z);
         this.farSideRoom().add(p);
         this.biconnect(p);
      }
   }
}