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
28
29
30 public abstract class Vehicle
31 extends
32 InfoMessage
33 implements IWorldEvent, IWorldChangeEvent, ICompositeWorldObject
34
35 ,ILocated
36 ,ILocomotive
37 ,IRotable
38 ,IGBViewable
39 {
40
41
42 public static final String PROTOTYPE =
43 "VEH {Id unreal_id} {Rotation 0,0,0} {Location 0,0,0} {Velocity 0,0,0} {Visible False} {Team 0} {Health 0} {Armor 0} {Driver unreal_id} {TeamLocked False} {Type text} ";
44
45
46
47
48
49
50 public Vehicle()
51 {
52 }
53
54
55
56
57 protected long SimTime;
58
59
60
61
62 @Override
63 public long getSimTime() {
64 return SimTime;
65 }
66
67
68
69
70 protected void setSimTime(long SimTime) {
71 this.SimTime = SimTime;
72 }
73
74
75
76
77 public abstract UnrealId getId()
78 ;
79
80
81
82
83
84
85 public abstract Rotation getRotation()
86 ;
87
88
89
90
91
92
93 public abstract Location getLocation()
94 ;
95
96
97
98
99
100
101
102 public abstract Velocity getVelocity()
103 ;
104
105
106
107
108
109
110 public abstract boolean isVisible()
111 ;
112
113
114
115
116
117
118
119 public abstract Integer getTeam()
120 ;
121
122
123
124
125
126
127 public abstract Integer getHealth()
128 ;
129
130
131
132
133
134
135 public abstract Integer getArmor()
136 ;
137
138
139
140
141 public abstract UnrealId getDriver()
142 ;
143
144
145
146
147
148
149 public abstract boolean isTeamLocked()
150 ;
151
152
153
154
155
156
157 public abstract String getType()
158 ;
159
160 @Override
161 public IWorldObjectUpdatedEvent createDisappearEvent() {
162 return new ObjectDisappeared(this, getSimTime());
163 }
164
165 public static class ObjectDisappeared implements IWorldObjectUpdatedEvent
166 {
167
168 public ObjectDisappeared(Vehicle obj, long time) {
169 this.obj = obj;
170 this.time = time;
171 }
172
173 private Vehicle obj;
174 private long time;
175
176 @Override
177 public WorldObjectId getId() {
178 return obj.getId();
179 }
180
181
182
183
184 @Override
185 public long getSimTime() {
186 return time;
187 }
188
189 @Override
190 public IWorldObjectUpdateResult<IWorldObject> update(IWorldObject obj) {
191 if (obj == null) {
192 throw new PogamutException("Can't 'disappear' null!", this);
193 }
194 if (!(obj instanceof VehicleMessage)) {
195 throw new PogamutException("Can't update different class than VehicleMessage, got class " + obj.getClass().getSimpleName() + "!", this);
196 }
197 VehicleMessage toUpdate = (VehicleMessage)obj;
198 if (toUpdate.Visible) {
199 toUpdate.Visible = false;
200 return new IWorldObjectUpdateResult.WorldObjectUpdateResult(IWorldObjectUpdateResult.Result.UPDATED, obj);
201 } else {
202 return new IWorldObjectUpdateResult.WorldObjectUpdateResult(IWorldObjectUpdateResult.Result.SAME, obj);
203 }
204 }
205
206 }
207
208
209
210 public static class VehicleUpdate
211 extends GBObjectUpdate implements ICompositeWorldObjectUpdatedEvent, IGBWorldObjectEvent {
212 private Vehicle object;
213 private long time;
214 private ITeamId teamId;
215
216 public VehicleUpdate
217 (Vehicle source, long eventTime, ITeamId teamId) {
218 this.object = source;
219 this.time = eventTime;
220 this.teamId = teamId;
221 }
222
223
224
225
226 @Override
227 public long getSimTime() {
228 return time;
229 }
230
231 @Override
232 public IWorldObject getObject() {
233 return object;
234 }
235
236 @Override
237 public WorldObjectId getId() {
238 return object.getId();
239 }
240
241 @Override
242 public ILocalWorldObjectUpdatedEvent getLocalEvent() {
243 return new VehicleLocalImpl.VehicleLocalUpdate
244 ((VehicleLocal)object.getLocal(), time);
245 }
246
247 @Override
248 public ISharedWorldObjectUpdatedEvent getSharedEvent() {
249 return new VehicleSharedImpl.VehicleSharedUpdate
250 ((VehicleShared)object.getShared(), time, teamId);
251 }
252
253 @Override
254 public IStaticWorldObjectUpdatedEvent getStaticEvent() {
255 return new VehicleStaticImpl.VehicleStaticUpdate
256 ((VehicleStatic)object.getStatic(), time);
257 }
258
259 }
260
261
262 public String toString() {
263 return
264 super.toString() + "[" +
265
266 "Id = " + String.valueOf(getId()
267 ) + " | " +
268
269 "Rotation = " + String.valueOf(getRotation()
270 ) + " | " +
271
272 "Location = " + String.valueOf(getLocation()
273 ) + " | " +
274
275 "Velocity = " + String.valueOf(getVelocity()
276 ) + " | " +
277
278 "Visible = " + String.valueOf(isVisible()
279 ) + " | " +
280
281 "Team = " + String.valueOf(getTeam()
282 ) + " | " +
283
284 "Health = " + String.valueOf(getHealth()
285 ) + " | " +
286
287 "Armor = " + String.valueOf(getArmor()
288 ) + " | " +
289
290 "Driver = " + String.valueOf(getDriver()
291 ) + " | " +
292
293 "TeamLocked = " + String.valueOf(isTeamLocked()
294 ) + " | " +
295
296 "Type = " + String.valueOf(getType()
297 ) + " | " +
298
299 "]";
300 }
301
302
303 public String toHtmlString() {
304 return super.toString() + "[<br/>" +
305
306 "<b>Id</b> = " + String.valueOf(getId()
307 ) + " <br/> " +
308
309 "<b>Rotation</b> = " + String.valueOf(getRotation()
310 ) + " <br/> " +
311
312 "<b>Location</b> = " + String.valueOf(getLocation()
313 ) + " <br/> " +
314
315 "<b>Velocity</b> = " + String.valueOf(getVelocity()
316 ) + " <br/> " +
317
318 "<b>Visible</b> = " + String.valueOf(isVisible()
319 ) + " <br/> " +
320
321 "<b>Team</b> = " + String.valueOf(getTeam()
322 ) + " <br/> " +
323
324 "<b>Health</b> = " + String.valueOf(getHealth()
325 ) + " <br/> " +
326
327 "<b>Armor</b> = " + String.valueOf(getArmor()
328 ) + " <br/> " +
329
330 "<b>Driver</b> = " + String.valueOf(getDriver()
331 ) + " <br/> " +
332
333 "<b>TeamLocked</b> = " + String.valueOf(isTeamLocked()
334 ) + " <br/> " +
335
336 "<b>Type</b> = " + String.valueOf(getType()
337 ) + " <br/> " +
338
339 "<br/>]";
340 }
341
342 public String toJsonLiteral() {
343 return "Vehicle(null, "
344
345 + ")";
346 }
347
348
349
350
351
352
353
354
355
356
357 }
358