View Javadoc

1   package cz.cuni.amis.pogamut.usar2004.communication.messages.usarinfomessages;
2   
3   import java.util.*;
4   import cz.cuni.amis.pogamut.base.communication.worldview.event.*;
5   import cz.cuni.amis.pogamut.base.communication.translator.event.*;
6   import cz.cuni.amis.pogamut.usar2004.communication.messages.*;
7   import cz.cuni.amis.pogamut.usar2004.communication.messages.datatypes.*;
8   
9   /**
10   *
11   * When we connect to USARSim, we can send this command before spawning any
12   * robot: GETSTARTPOSES.
13   *
14   * We will receive a string like this one: NFO {StartPoses 3} {BlueGoal
15   * -2.55,-0.00,-0.19 0.00,-0.03,-0.01 MiddleField 0.01,- 0.00,-0.19
16   * 0.00,0.00,0.00 YellowGoal 2.57,-0.01,-0.19 0.00,0.00,3.13}
17   *
18   * The syntax of this string doesn't follow strictly the USARSim standard.
19   *
20   * NFO message is also issued after connecting to the USARSIM server. And it
21   * contains information about the level.
22   *
23   * Corresponding GameBots message is NFO.
24   *
25   */
26  public class NfoMessage extends GBEvent implements IWorldEvent, IWorldChangeEvent
27  {
28      public NfoMessage(double TimeLimit, String Level, String GameType, int StartPoseCount)
29      {
30          this.TimeLimit = TimeLimit;
31          this.Level = Level;
32          this.GameType = GameType;
33          this.StartPoseCount = StartPoseCount;
34      }
35      /**
36       * Example how the message looks like - used during parser tests.
37       */
38      public static final String PROTOTYPE = "NFO {TimeLimit 0} {Level text} {GameType text} {StartPoseCount 0}";
39      /////// Properties Info
40  //        /**
41  //        Timestamp form the GameBots. */
42  //        protected double Time = 0;
43  //        
44  //        public double getTime() {
45  //            return Time;
46  //        }
47      protected String GameType = null;
48  
49      /**
50       * Initial NFO message recieved from the server will provide information
51       * such as Game Type.
52       *
53       * @return Returns a Unreal type of current game.
54       */
55      public String getGameType()
56      {
57          return GameType;
58      }
59      protected String Level = null;
60  
61      /**
62       * Initial NFO message recieved from the server will provide information
63       * such as Level Name.
64       *
65       * @return Returns name of current map.
66       */
67      public String getLevel()
68      {
69          return Level;
70      }
71      protected double TimeLimit = 0;
72  
73      /**
74       * Initial NFO message recieved from the server will provide information
75       * such as Time Limit.
76       *
77       * @return Returns the time limit for current map.
78       */
79      public double getTimeLimit()
80      {
81          return TimeLimit;
82      }
83      protected int StartPoseCount = 0;
84  
85      /**
86       * StartPoseCount is the number of starting positions available. For every
87       * starting position you'll be able to receive it's tag, location and
88       * orientation:
89       *
90       * @return Returns number of availible start positions.
91       */
92      public int getStartPoseCount()
93      {
94          return StartPoseCount;
95      }
96      protected List<StartPose> StartPoses = new ArrayList<StartPose>();
97  
98      /**
99       * GETSTARTPOSES will cause receipt of the NFO message with potencial
100      * Locations for spawning a robot.
101      *
102      * @return Returns list of possible starting positions.
103      */
104     public List<StartPose> getStartPoses()
105     {
106         return StartPoses;
107     }
108 
109     /**
110      * Cloning constructor.
111      */
112     public NfoMessage(NfoMessage original)
113     {
114         this.TimeLimit = original.TimeLimit;
115         this.GameType = original.GameType;
116         this.Level = original.Level;
117         this.StartPoseCount = original.StartPoseCount;
118         this.StartPoses.addAll(original.StartPoses);
119     }
120 
121     /**
122      * Used by Yylex to create empty message then to fill it's protected fields
123      * (Yylex is in the same package).
124      */
125     public NfoMessage()
126     {
127     }
128 
129     @Override
130     public String toString()
131     {
132         StringBuilder buf = new StringBuilder();
133 
134         buf.append(super.toString() + " | "
135                 + "TimeLimit = "
136                 + String.valueOf(TimeLimit) + " | "
137                 + "GameType = "
138                 + String.valueOf(GameType) + " | "
139                 + "Level = "
140                 + String.valueOf(Level) + " | "
141                 + "StartPoseCount = "
142                 + String.valueOf(StartPoseCount) + " | ");
143 
144         if(!StartPoses.isEmpty())
145         {
146             for(StartPose startPose : StartPoses)
147             {
148                 buf.append("Name").append(" = ").append(startPose.getName()).append(" ");
149                 buf.append("Position").append(" = ").append(startPose.getPosition().toString()).append(" ");
150                 buf.append("Orientation").append(" = ").append(startPose.getPosition().toString()).append(" ");
151             }
152             buf.append(" | ");
153         }
154 
155 
156         return buf.toString();
157 
158     }
159 
160     /**
161      * Gets all properties and values to create a HTML formated string;
162      *
163      * @return Returns all properties in HTML format
164      */
165     public String toHtmlString()
166     {
167         StringBuilder buf = new StringBuilder();
168         buf.append(super.toString()
169                 + "<b>TimeLimit</b> : "
170                 + String.valueOf(TimeLimit)
171                 + " <br/> "
172                 + "<b>GameType</b> : "
173                 + String.valueOf(GameType)
174                 + " <br/> "
175                 + "<b>Level</b> : "
176                 + String.valueOf(Level)
177                 + " <br/> "
178                 + "<b>StartPoseCount</b> : "
179                 + String.valueOf(StartPoseCount)
180                 + " <br/> ");
181         if(!StartPoses.isEmpty())
182         {
183             for(StartPose startPose : StartPoses)
184             {
185                 buf.append("<b>").append("Name").append("</b> : ").append(startPose.getName()).append(" <br/> ");
186                 buf.append("<b>").append("Position").append("</b> : ").append(startPose.getPosition()).append(" <br/> ");
187                 buf.append("<b>").append("Orientation").append("</b> : ").append(startPose.getOrientation()).append(" <br/> ");
188             }
189         }
190         return buf.toString();
191     }
192 }