1 package cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages;
2
3
4 import java.util.*;import javax.vecmath.*;import cz.cuni.amis.pogamut.base.communication.messages.*;import cz.cuni.amis.pogamut.base.communication.worldview.*;import cz.cuni.amis.pogamut.base.communication.worldview.event.*;import cz.cuni.amis.pogamut.base.communication.worldview.object.*;import cz.cuni.amis.pogamut.multi.communication.worldview.object.*;import cz.cuni.amis.pogamut.base.communication.translator.event.*;import cz.cuni.amis.pogamut.multi.communication.translator.event.*;import cz.cuni.amis.pogamut.base3d.worldview.object.*;import cz.cuni.amis.pogamut.base3d.worldview.object.event.*;import cz.cuni.amis.pogamut.ut2004.communication.messages.*;import cz.cuni.amis.pogamut.ut2004.communication.worldview.objects.*;import cz.cuni.amis.pogamut.ut2004multi.communication.worldview.objects.*;import cz.cuni.amis.pogamut.ut2004.communication.translator.itemdescriptor.*;import cz.cuni.amis.pogamut.ut2004.communication.messages.ItemType.Category;import cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId;import cz.cuni.amis.utils.exception.*;import cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result;import cz.cuni.amis.utils.SafeEquals;import cz.cuni.amis.pogamut.base.agent.*;import cz.cuni.amis.pogamut.multi.agent.*;import cz.cuni.amis.pogamut.multi.communication.worldview.property.*;import cz.cuni.amis.pogamut.ut2004multi.communication.worldview.property.*;import cz.cuni.amis.utils.token.*;import cz.cuni.amis.utils.*;
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 public class NavPointSharedImpl
28 extends
29 NavPointShared
30 {
31
32
33
34 public NavPointSharedImpl(NavPointSharedImpl source) {
35
36 this.Id = source.
37 getId()
38 ;
39
40 this.myLocation = source.myLocation;
41
42 this.myVelocity = source.myVelocity;
43
44 this.myItemSpawned = source.myItemSpawned;
45
46 this.myDoorOpened = source.myDoorOpened;
47
48 }
49
50 public NavPointSharedImpl(WorldObjectId objectId, Collection<ISharedProperty> properties) {
51 this.Id = (UnrealId)objectId;
52 NullCheck.check(this.Id, "objectId");
53
54 if (properties.size() != 4) {
55 throw new PogamutException("Not enough properties passed to the constructor.", NavPointSharedImpl.class);
56 }
57
58
59 for ( ISharedProperty property : properties ) {
60 PropertyId pId = property.getPropertyId();
61 if ( !objectId.equals( property.getObjectId() )) {
62
63 throw new PogamutException("Trying to create a NavPointSharedImpl with different WorldObjectId properties : " +
64 this.Id.getStringId() + " / " + property.getObjectId().getStringId() , this);
65 }
66 if (!NavPointShared.SharedPropertyTokens.contains(pId.getPropertyToken())) {
67
68 throw new PogamutException("Trying to create a NavPointSharedImpl with invalid property (invalid property token): " +
69 this.Id.getStringId() + " / " + property.getPropertyId().getPropertyToken().getToken() , this);
70 }
71 propertyMap.put(property.getPropertyId(), property);
72
73
74 if (pId.getPropertyToken().getToken().equals("Location"))
75 {
76 this.myLocation = (LocationProperty)property;
77 }
78
79 if (pId.getPropertyToken().getToken().equals("Velocity"))
80 {
81 this.myVelocity = (VelocityProperty)property;
82 }
83
84 if (pId.getPropertyToken().getToken().equals("ItemSpawned"))
85 {
86 this.myItemSpawned = (BooleanProperty)property;
87 }
88
89 if (pId.getPropertyToken().getToken().equals("DoorOpened"))
90 {
91 this.myDoorOpened = (BooleanProperty)property;
92 }
93
94 }
95 }
96
97
98 @Override
99 public void setSimTime(long SimTime) {
100 super.setSimTime(SimTime);
101 }
102
103 @Override
104 public
105 NavPointSharedImpl clone() {
106 return new
107 NavPointSharedImpl(this);
108 }
109
110
111
112
113
114 protected HashMap<PropertyId, ISharedProperty> propertyMap = new HashMap<PropertyId, ISharedProperty>(
115 4
116 );
117
118 @Override
119 public ISharedProperty getProperty(PropertyId id) {
120 return propertyMap.get(id);
121 }
122
123 @Override
124 public Map<PropertyId, ISharedProperty> getProperties() {
125 return propertyMap;
126 }
127
128
129
130
131
132
133
134
135
136 protected
137 UnrealId Id =
138 null;
139
140
141
142
143
144
145 public UnrealId getId()
146 {
147 return Id;
148 }
149
150
151
152
153
154 protected
155 LocationProperty
156 myLocation
157 = null;
158
159
160
161
162
163 public Location getLocation()
164 {
165 return myLocation.getValue();
166 }
167
168
169
170
171
172
173
174
175 protected
176 VelocityProperty
177 myVelocity
178 = null;
179
180
181
182
183
184
185
186
187 public Velocity getVelocity()
188 {
189 return myVelocity.getValue();
190 }
191
192
193
194
195
196
197
198 protected
199 BooleanProperty
200 myItemSpawned
201 = null;
202
203
204
205
206
207
208
209 public boolean isItemSpawned()
210 {
211 return myItemSpawned.getValue();
212 }
213
214
215
216
217
218
219
220 protected
221 BooleanProperty
222 myDoorOpened
223 = null;
224
225
226
227
228
229
230
231 public boolean isDoorOpened()
232 {
233 return myDoorOpened.getValue();
234 }
235
236
237
238 public static class NavPointSharedUpdate
239 implements ISharedWorldObjectUpdatedEvent
240 {
241
242 private NavPointShared object;
243 private long time;
244 private ITeamId teamId;
245
246 public NavPointSharedUpdate
247 (NavPointShared data, long time, ITeamId teamId)
248 {
249 this.object = data;
250 this.time = time;
251 this.teamId = teamId;
252 }
253
254
255
256
257 @Override
258 public long getSimTime() {
259 return this.time;
260 }
261
262 @Override
263 public WorldObjectId getId() {
264 return object.getId();
265 }
266
267 @Override
268 public ITeamId getTeamId() {
269 return teamId;
270 }
271
272 @Override
273 public Class getCompositeObjectClass()
274 {
275 return object.getCompositeClass();
276 }
277
278 @Override
279 public Collection<ISharedPropertyUpdatedEvent> getPropertyEvents() {
280 LinkedList<ISharedPropertyUpdatedEvent> events = new LinkedList<ISharedPropertyUpdatedEvent>();
281
282 for ( ISharedProperty property : object.getProperties().values() )
283 {
284 if ( property != null)
285 {
286 events.push( property.createUpdateEvent(time, teamId) );
287 }
288 }
289 return events;
290 }
291
292 }
293
294
295
296 public String toString() {
297 return
298 super.toString() + "[" +
299
300 "Id = " + String.valueOf(getId()
301 ) + " | " +
302
303 "Location = " + String.valueOf(getLocation()
304 ) + " | " +
305
306 "Velocity = " + String.valueOf(getVelocity()
307 ) + " | " +
308
309 "ItemSpawned = " + String.valueOf(isItemSpawned()
310 ) + " | " +
311
312 "DoorOpened = " + String.valueOf(isDoorOpened()
313 ) + " | " +
314
315 "]";
316 }
317
318
319 public String toHtmlString() {
320 return super.toString() + "[<br/>" +
321
322 "<b>Id</b> = " + String.valueOf(getId()
323 ) + " <br/> " +
324
325 "<b>Location</b> = " + String.valueOf(getLocation()
326 ) + " <br/> " +
327
328 "<b>Velocity</b> = " + String.valueOf(getVelocity()
329 ) + " <br/> " +
330
331 "<b>ItemSpawned</b> = " + String.valueOf(isItemSpawned()
332 ) + " <br/> " +
333
334 "<b>DoorOpened</b> = " + String.valueOf(isDoorOpened()
335 ) + " <br/> " +
336
337 "<br/>]";
338 }
339
340
341
342
343
344
345
346
347
348
349 }
350