View Javadoc

1   package cz.cuni.amis.pogamut.usar2004.communication.messages.usarcommands;
2   
3   import cz.cuni.amis.pogamut.base.communication.messages.*;
4   import cz.cuni.amis.pogamut.base3d.worldview.object.*;
5   import cz.cuni.amis.pogamut.usar2004.communication.messages.datatypes.CustomTypes.*;
6   
7   /**
8    *
9    * Message you'll send at the beginning of the communication to create a robot
10   * in the game. You must send this message before you can have a character to
11   * play in the game.
12   *
13   * Corresponding GameBots command is INIT.
14   *
15   */
16  public class Initialize extends CommandMessage
17  {
18      public Initialize(String ClassName, String Name, Location Location, Rotation Rotation, String Skin, String Team)
19      {
20          this.ClassName = ClassName;
21          this.Name = Name;
22          this.Location = Location;
23          this.Rotation = Rotation;
24          this.Skin = Skin;
25          this.Team = Team;
26      }
27  
28      public Initialize(String ClassName, String Name, Location Location, Rotation Rotation)
29      {
30          this.ClassName = ClassName;
31          this.Name = Name;
32          this.Location = Location;
33          this.Rotation = Rotation;
34      }
35  
36      public Initialize(String ClassName, String Name, String StringLocation, String Skin, String Team)
37      {
38          this.ClassName = ClassName;
39          this.Name = Name;
40          this.StartPosition = StringLocation;
41          this.Skin = Skin;
42          this.Team = Team;
43      }
44  
45      public Initialize(String ClassName, String Name, String StringLocation)
46      {
47          this.ClassName = ClassName;
48          this.Name = Name;
49          this.StartPosition = StringLocation;
50      }
51  
52      /**
53       * <p></p>WARNING: this is empty-command constructor, you have to use
54       * setters to fill it up!
55       */
56      public Initialize()
57      {
58      }
59      /////// Properties BEGIN
60      /*
61       * the class name of the 67robot. It can be USARBot.ATRVJr, USARBot.Zerg,
62       * USARBot.P2AT, USARBot.P2DX, USARBot.Hummer, and any other robots built by
63       * the user.
64       */
65      protected String ClassName = null;
66  
67      public String getClassName()
68      {
69          return ClassName;
70      }
71  
72      public Initialize setClassName(String ClassName)
73      {
74          this.ClassName = ClassName;
75          return this;
76      }
77      /**
78       * Robot name.
79       */
80      protected String Name = null;
81  
82      public String getName()
83      {
84          return Name;
85      }
86  
87      public Initialize setName(String Name)
88      {
89          this.Name = Name;
90          return this;
91      }
92      /*
93       * the start position of the robot in meters from the world origin. For
94       * different arenas, we need different positions. The recommended positions
95       * are listed on Table 2 for the USAR arenas. Recommended start locations
96       * for worlds are given in a text file that is included with the world
97       * download. Worlds are available in the “maps” file release area on
98       * sourceforge.
99       */
100     protected Location Location = null;
101 
102     public Location getLocation()
103     {
104         return Location;
105     }
106 
107     public Initialize setLocation(Location Location)
108     {
109         this.Location = Location;
110         return this;
111     }
112     //user can set the location by string which he can get from the STARTPOSES command(for example {Location RobotStart1}) -- misleading: use {Start StartPosition} to propperly use String Location INIT
113     protected String StartPosition = null;
114 
115     public String getStartPosition()
116     {
117         return StartPosition;
118     }
119     protected Rotation Rotation = null;
120 
121     public Rotation getRotation()
122     {
123         return Rotation;
124     }
125 
126     public Initialize setRotation(Rotation Rotation)
127     {
128         this.Rotation = Rotation;
129         return this;
130     }
131     //ADDED for full support of init command!
132     //Skin can be RED or BLUE for example ERS supports skins
133     protected String Skin = null;
134 
135     public String getSkin()
136     {
137         return Skin;
138     }
139     protected String Team = null;
140 
141     public String getTeam()
142     {
143         return Team;
144     }
145 
146     /////// Properties END
147     /////// Extra Java code BEGIN
148     /////// Additional code from xslt BEGIN
149     /////// Additional code from xslt END
150     /////// Extra Java from XML BEGIN
151     /////// Extra Java from XML END
152     /////// Extra Java code END
153     /**
154      * Cloning constructor.
155      */
156     public Initialize(Initialize original)
157     {
158         this.Name = original.Name;
159         this.Location = original.Location;
160         this.ClassName = original.ClassName;
161         this.StartPosition = original.StartPosition;
162         this.Skin = original.Skin;
163         this.Team = original.Team;
164         this.Rotation = original.Rotation;
165     }
166 
167     @Override
168     public String toString()
169     {
170         return toMessage();
171 
172     }
173 
174     public String toHtmlString()
175     {
176         return super.toString()
177                 + "<b>ClassName</b> : "
178                 + String.valueOf(ClassName)
179                 + " <br/> "
180                 + "<b>Name</b> : "
181                 + String.valueOf(Name)
182                 + " <br/> "
183                 + "<b>Location</b> : "
184                 + String.valueOf(Location)
185                 + " <br/> "
186                 + "<b>Start</b> : "
187                 + String.valueOf(StartPosition)
188                 + " <br/> "
189                 + "<b>Skin</b> : "
190                 + String.valueOf(Skin)
191                 + " <br/> "
192                 + "<b>Team</b> : "
193                 + String.valueOf(Team)
194                 + " <br/> "
195                 + "<b>Rotation</b> : "
196                 + String.valueOf(Rotation)
197                 + " <br/> "
198                 + "";
199     }
200 
201     public String toMessage()
202     {
203 
204         StringBuilder buf = new StringBuilder();
205         buf.append("INIT");
206         if(ClassName != null)
207         {
208             buf.append(" {ClassName ").append(ClassName).append("}");
209         }
210 
211         if(Name != null)
212         {
213             buf.append(" {Name ").append(Name).append("}");
214         }
215 
216         if(Location != null)
217         {
218             buf.append(" {Location ").append(Location.getX()).append(",").append(Location.getY()).append(",").append(Location.getZ()).append("}");
219         }
220 
221         if(StartPosition != null)
222         {
223             buf.append(" {Start ").append(StartPosition).append("}");
224         }
225 
226         if(Rotation != null)
227         {
228             buf.append(" {Rotation ").append(Rotation.getRoll()).append(",").append(Rotation.getPitch()).append(",").append(Rotation.getYaw()).append("}");
229         }
230 
231         if(Skin != null)
232         {
233             buf.append(" {Skin ").append(Skin).append("}");
234         }
235 
236         if(Team != null)
237         {
238             buf.append(" {Team ").append(Team).append("}");
239         }
240         return buf.toString();
241     }
242 }