View Javadoc

1   package cz.cuni.amis.pogamut.defcon.communication.messages.infos;
2   
3   import cz.cuni.amis.pogamut.base.communication.worldview.object.IWorldObject;
4   import cz.cuni.amis.pogamut.base.communication.worldview.object.WorldObjectId;
5   import cz.cuni.amis.pogamut.defcon.communication.messages.Updatable;
6   import cz.cuni.amis.pogamut.defcon.consts.UnitType;
7   
8   
9   /**
10   * World object message of arbitrary world that is run in the same JVM.
11   *
12   * @author Jimmy
13   * @author Black_Hand
14   */
15  public abstract class DefConObject implements IWorldObject {
16      /**
17       * Private id of the world object, exposed via getId() method.
18       */
19      private WorldObjectId id;
20  
21      /**
22       * Type of the world object, exposed via getType() method.
23       */
24      private UnitType type;
25  
26      /**
27       * Time when the object was last updated. Exposed via getLastSeenTime().
28       */
29      @Updatable
30      private double time;
31  
32      /**
33       * DOCUMENT ME!
34       */
35      private boolean destroyed = false;
36  
37  /**
38       * Creates new object with specified id and time
39       *
40       * @param id id set to the object
41       * @param type type of the unit
42       * @param time time set to the object
43       */
44      public DefConObject(int id, UnitType type, double time) {
45          this.id = WorldObjectId.get(id);
46          this.type = type;
47          this.time = time;
48      }
49  
50  /**
51       * Creates a new DefConObject object.
52       *
53       * @param original DOCUMENT ME!
54       */
55      public DefConObject(DefConObject original) {
56          this.id = original.getId();
57          this.type = original.type;
58          this.time = original.time;
59      }
60  
61      /**
62       * Returns ID of the object.
63       *
64       * @return ID
65       */
66      @Override
67      public WorldObjectId getId() {
68          return id;
69      }
70  
71      /**
72       * Returns type of this object.
73       *
74       * @return type
75       */
76      public UnitType getType() {
77          return type;
78      }
79  
80      /**
81       * Returns the time of the last update of the object.
82       *
83       * @return time
84       */
85      public double getLastSeenTime() {
86          return time;
87      }
88  
89      /**
90       * Sets the last-seen-time of the object.
91       *
92       * @param time
93       */
94      protected void setLastSeenTime(double time) {
95          this.time = time;
96      }
97  
98      /**
99       * DOCUMENT ME!
100      *
101      * @return DOCUMENT ME!
102      */
103     @Override
104     public long getSimTime() {
105         return (long) time;
106     }
107 
108     /**
109      * Returns update-event for the current object.
110      *
111      * @return update-event
112      */
113     public DefConObjectUpdate createUpdateEvent() {
114         return new DefConObjectUpdate(this);
115     }
116 
117     /**
118      * Returns update-event for the current object.
119      *
120      * @return update-event
121      */
122     public DefConObjectUpdate createDestroyedEvent() {
123         destroyed = true;
124 
125         return createUpdateEvent();
126     }
127 
128     /**
129      * DOCUMENT ME!
130      *
131      * @return DOCUMENT ME!
132      */
133     public boolean getDestroyed() {
134         return destroyed;
135     }
136 
137     /**
138      * DOCUMENT ME!
139      *
140      * @return DOCUMENT ME!
141      */
142     public String getStringizedFields() {
143         return "id: " + id.toString() + "; type: " + type.toString() + "; time: " + time;
144     }
145 }