View Javadoc

1   package cz.cuni.amis.pogamut.defcon.communication.messages.infos;
2   
3   import cz.cuni.amis.pogamut.base3d.worldview.object.ILocated;
4   import cz.cuni.amis.pogamut.base3d.worldview.object.IViewable;
5   import cz.cuni.amis.pogamut.defcon.base3d.worldview.object.DefConLocation;
6   import cz.cuni.amis.pogamut.defcon.communication.messages.Updatable;
7   import cz.cuni.amis.pogamut.defcon.consts.UnitType;
8   import cz.cuni.amis.pogamut.multi.communication.worldview.object.ILocalWorldObject;
9   import cz.cuni.amis.pogamut.multi.communication.worldview.object.ISharedWorldObject;
10  import cz.cuni.amis.pogamut.multi.communication.worldview.object.IStaticWorldObject;
11  
12  
13  /**
14   * Viewable version of the {@link DefConObject} - implements {@link IViewable} providing a way
15   * to tell whether the object is visible on the map.
16   *
17   * @author Jimmy
18   * @author Black_Hand
19   */
20  public abstract class DefConViewableObject extends DefConObject implements IViewable, ILocated {
21      /**
22       * Holds the information whether the object is visible on the map.
23       */
24      @Updatable
25      protected boolean visible;
26  
27      /**
28       * Contains location of this object. Exposed via getLocation().
29       */
30      @Updatable
31      protected DefConLocation location;
32  
33      /**
34       * Contains the id of this object's team. Exposed by getTeamId().
35       */
36      @Updatable
37      protected int teamId;
38  
39  /**
40       * Creates new instance of message DefConViewAbleObject with specific id. Example object from
41       * the world.
42       *
43       * @param id
44       * @param type DOCUMENT ME!
45       * @param teamId DOCUMENT ME!
46       * @param location DOCUMENT ME!
47       * @param visible visibility of this object
48       * @param time
49       */
50      public DefConViewableObject(int id, UnitType type, int teamId, DefConLocation location,
51          boolean visible, double time) {
52          super(id, type, time);
53  
54          this.visible = visible;
55          this.teamId = teamId;
56          this.location = new DefConLocation(location);
57      }
58  
59  /**
60       * Creates a new DefConViewableObject object.
61       *
62       * @param original DOCUMENT ME!
63       */
64      public DefConViewableObject(DefConViewableObject original) {
65          super(original);
66  
67          this.visible = original.visible;
68          this.teamId = original.teamId;
69          this.location = new DefConLocation(original.location);
70      }
71  
72      /**
73       * Is the object visible on the DefCon map?
74       *
75       * @return visibility
76       */
77      @Override
78      public boolean isVisible() {
79          return visible;
80      }
81  
82      /**
83       * Sets the visibility of this object.
84       *
85       * @param visible
86       *
87       * @return visibility
88       */
89      protected boolean setVisibility(boolean visible) {
90          return this.visible = visible;
91      }
92  
93      /**
94       * Returns team id of this object.
95       *
96       * @return id
97       */
98      public int getTeamId() {
99          return teamId;
100     }
101 
102     /**
103      * Returns locations of this object.
104      *
105      * @return location
106      */
107     public DefConLocation getLocation() {
108         return location;
109     }
110 
111     /**
112      * DOCUMENT ME!
113      *
114      * @return DOCUMENT ME!
115      */
116     @Override
117     public String getStringizedFields() {
118         return super.getStringizedFields() + "; teamid: " + teamId + "; location: " +
119         location.toString() + "; visible: " + visible;
120     }
121 
122     // TODO: FIX!
123     /**
124      * DOCUMENT ME!
125      *
126      * @return DOCUMENT ME!
127      */
128     @Override
129     public ILocalWorldObject getLocal() {
130         return (ILocalWorldObject) this;
131     }
132 
133     /**
134      * DOCUMENT ME!
135      *
136      * @return DOCUMENT ME!
137      */
138     @Override
139     public ISharedWorldObject getShared() {
140         return (ISharedWorldObject) this;
141     }
142 
143     /**
144      * DOCUMENT ME!
145      *
146      * @return DOCUMENT ME!
147      */
148     @Override
149     public IStaticWorldObject getStatic() {
150         return (IStaticWorldObject) this;
151     }
152 }