View Javadoc

1   package cz.cuni.amis.pogamut.usar2004.communication.messages.usarinfomessages;
2   
3   import cz.cuni.amis.pogamut.base.communication.worldview.event.*;
4   import cz.cuni.amis.pogamut.base.communication.translator.event.*;
5   import cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId;
6   import cz.cuni.amis.pogamut.usar2004.communication.messages.GBEvent;
7   
8   /**
9    *
10   * This bot has died.
11   *
12   * Corresponding GameBots message is DIE.
13   *
14   */
15  public class KillMessage extends GBEvent implements IWorldEvent, IWorldChangeEvent
16  {
17      /**
18       * Creates new instance of command KillMessage.
19       *
20       * @param Killer Unique Id of player that killed our bot if any (may have
21       * walked off a ledge).
22       *
23       * @param DamageType A string describing what kind of damage killed the bot.
24       * @param DeathString String describing this type of death.
25       * @param WeaponName Name of the weapon that caused this damage.
26       * @param Flaming If this damage is causing our bot to burn. TODO
27       * @param CausedByWorld If this damage was caused by world - falling into
28       * lava, or falling down.
29       * @param DirectDamage If the damage is direct. TODO
30       * @param BulletHit If this damage was caused by bullet.
31       * @param VehicleHit If this damage was caused by vehicle running over us.
32       *
33       */
34      public KillMessage(UnrealId Killer, String DamageType, String DeathString, String WeaponName, boolean Flaming, boolean CausedByWorld, boolean DirectDamage, boolean BulletHit, boolean VehicleHit)
35      {
36          this.Killer = Killer;
37          this.DamageType = DamageType;
38          this.DeathString = DeathString;
39          this.WeaponName = WeaponName;
40          this.Flaming = Flaming;
41          this.CausedByWorld = CausedByWorld;
42          this.DirectDamage = DirectDamage;
43          this.BulletHit = BulletHit;
44          this.VehicleHit = VehicleHit;
45      }
46      /**
47       * Example how the message looks like - used during parser tests.
48       */
49      public static final String PROTOTYPE = "DIE {Killer unreal_id} {DamageType text} {DeathString text} {WeaponName text} {Flaming False} {CausedByWorld False} {DirectDamage False} {BulletHit False} {VehicleHit False}";
50      /////// Properties BEGIN
51      /**
52       *
53       * Unique Id of player that killed our bot if any (may have walked off a
54       * ledge).
55       */
56      protected UnrealId Killer =
57              null;
58  
59      /**
60       *
61       * Unique Id of player that killed our bot if any (may have walked off a
62       * ledge).
63       */
64      public UnrealId getKiller()
65      {
66          return Killer;
67      }
68      /**
69       *
70       * A string describing what kind of damage killed the bot.
71       */
72      protected String DamageType =
73              null;
74  
75      /**
76       *
77       * A string describing what kind of damage killed the bot.
78       */
79      public String getDamageType()
80      {
81          return DamageType;
82      }
83      /**
84       *
85       * String describing this type of death.
86       */
87      protected String DeathString =
88              null;
89  
90      /**
91       *
92       * String describing this type of death.
93       */
94      public String getDeathString()
95      {
96          return DeathString;
97      }
98      /**
99       *
100      * Name of the weapon that caused this damage.
101      */
102     protected String WeaponName =
103             null;
104 
105     /**
106      *
107      * Name of the weapon that caused this damage.
108      */
109     public String getWeaponName()
110     {
111         return WeaponName;
112     }
113     /**
114      *
115      * If this damage is causing our bot to burn. TODO
116      */
117     protected boolean Flaming =
118             false;
119 
120     /**
121      *
122      * If this damage is causing our bot to burn. TODO
123      */
124     public boolean isFlaming()
125     {
126         return Flaming;
127     }
128     /**
129      *
130      * If this damage was caused by world - falling into lava, or falling down.
131      */
132     protected boolean CausedByWorld =
133             false;
134 
135     /**
136      *
137      * If this damage was caused by world - falling into lava, or falling down.
138      */
139     public boolean isCausedByWorld()
140     {
141         return CausedByWorld;
142     }
143     /**
144      *
145      * If the damage is direct. TODO
146      */
147     protected boolean DirectDamage =
148             false;
149 
150     /**
151      *
152      * If the damage is direct. TODO
153      */
154     public boolean isDirectDamage()
155     {
156         return DirectDamage;
157     }
158     /**
159      *
160      * If this damage was caused by bullet.
161      */
162     protected boolean BulletHit =
163             false;
164 
165     /**
166      *
167      * If this damage was caused by bullet.
168      */
169     public boolean isBulletHit()
170     {
171         return BulletHit;
172     }
173     /**
174      *
175      * If this damage was caused by vehicle running over us.
176      */
177     protected boolean VehicleHit =
178             false;
179 
180     /**
181      *
182      * If this damage was caused by vehicle running over us.
183      */
184     public boolean isVehicleHit()
185     {
186         return VehicleHit;
187     }
188 
189     /////// Properties END
190     /////// Extra Java code BEGIN
191     /////// Additional code from xslt BEGIN
192     public long getSimTime()
193     {
194         // NOT IMPLEMENTED FOR UDK
195         return 0;
196     }
197 
198     /////// Additional code from xslt END
199     /////// Extra Java from XML BEGIN
200     /////// Extra Java from XML END
201     /////// Extra Java code END
202     /**
203      * Cloning constructor.
204      */
205     public KillMessage(KillMessage original)
206     {
207         this.Killer = original.Killer;
208         this.DamageType = original.DamageType;
209         this.DeathString = original.DeathString;
210         this.WeaponName = original.WeaponName;
211         this.Flaming = original.Flaming;
212         this.CausedByWorld = original.CausedByWorld;
213         this.DirectDamage = original.DirectDamage;
214         this.BulletHit = original.BulletHit;
215         this.VehicleHit = original.VehicleHit;
216     }
217 
218     /**
219      * Used by Yylex to create empty message then to fill it's protected fields
220      * (Yylex is in the same package).
221      */
222     public KillMessage()
223     {
224     }
225 
226     @Override
227     public String toString()
228     {
229         StringBuilder buf = new StringBuilder();
230         buf.append(super.toString() + " | "
231                 + "Killer = "
232                 + String.valueOf(Killer) + " | "
233                 + "DamageType = "
234                 + String.valueOf(DamageType) + " | "
235                 + "DeathString = "
236                 + String.valueOf(DeathString) + " | "
237                 + "WeaponName = "
238                 + String.valueOf(WeaponName) + " | "
239                 + "Flaming = "
240                 + String.valueOf(Flaming) + " | "
241                 + "CausedByWorld = "
242                 + String.valueOf(CausedByWorld) + " | "
243                 + "DirectDamage = "
244                 + String.valueOf(DirectDamage) + " | "
245                 + "BulletHit = "
246                 + String.valueOf(BulletHit) + " | "
247                 + "VehicleHit = "
248                 + String.valueOf(VehicleHit) + " | "
249                 + "");
250         return buf.toString();
251 
252     }
253 
254     /**
255      * Gets all properties and values to create a HTML formated string;
256      *
257      * @return Returns all properties in HTML format
258      */
259     public String toHtmlString()
260     {
261         StringBuilder buf = new StringBuilder();
262         buf.append(super.toString()
263                 + "<b>Killer</b> : "
264                 + String.valueOf(Killer)
265                 + " <br/> "
266                 + "<b>DamageType</b> : "
267                 + String.valueOf(DamageType)
268                 + " <br/> "
269                 + "<b>DeathString</b> : "
270                 + String.valueOf(DeathString)
271                 + " <br/> "
272                 + "<b>WeaponName</b> : "
273                 + String.valueOf(WeaponName)
274                 + " <br/> "
275                 + "<b>Flaming</b> : "
276                 + String.valueOf(Flaming)
277                 + " <br/> "
278                 + "<b>CausedByWorld</b> : "
279                 + String.valueOf(CausedByWorld)
280                 + " <br/> "
281                 + "<b>DirectDamage</b> : "
282                 + String.valueOf(DirectDamage)
283                 + " <br/> "
284                 + "<b>BulletHit</b> : "
285                 + String.valueOf(BulletHit)
286                 + " <br/> "
287                 + "<b>VehicleHit</b> : "
288                 + String.valueOf(VehicleHit)
289                 + " <br/> "
290                 + "");
291         return buf.toString();
292     }
293 }