View Javadoc

1   package cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages;
2    		
3    		// --- IMPORTS FROM /messages/settings/javasettings/javaimport BEGIN
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   		// --- IMPORTS FROM /messages/settings/javasettings/javaimport END
6   		
7   		
8   		// --- IMPORTS FROM extra/code/java/javapart/classcategory[@name='all'] BEGIN
9   				
10  		// --- IMPORTS FROM extra/code/java/javapart/classcategory[@name='all'] END
11  		
12  		// --- IMPORTS FROM extra/code/java/javapart/classcategory[@name=base]+classtype[@name=abstract] BEGIN
13  		
14  		// --- IMPORTS FROM extra/code/java/javapart/classcategory[@name=base]+classtype[@name=abstract] END
15      
16   		/**
17           *  
18              				Abstract definition of the GameBots2004 message FLG.  
19              			
20           *
21           *  <p></p><p></p>
22           *  Complete message documentation:               
23           *  
24  		Synchronous message. FlagInfo contains all info about the flag
25  		in the CTF game mode. Is not sent in other game types.
26  	
27           */
28   	public abstract class FlagInfo   
29    				extends 
30    				InfoMessage
31    						implements IWorldEvent, IWorldChangeEvent, ICompositeWorldObject
32    						
33  	    		,IGBViewable
34  	    {
35   	
36      	/** Example how the message looks like - used during parser tests. */
37      	public static final String PROTOTYPE =
38      		"FLG {Id unreal_id}  {Location 0,0,0}  {Holder unreal_id}  {Team 0}  {Visible False}  {State text} ";
39      
40      	
41      	
42      	/**
43      	 * Parameter-less contructor for the message.
44      	 */
45  		public FlagInfo()
46  		{
47  		}
48  	
49  				// abstract message, it does not have any more constructors				
50  			
51  	   		
52  			protected long SimTime;
53  				
54  			/**
55  			 * Simulation time in MILLI SECONDS !!!
56  			 */	
57  			@Override
58  			public long getSimTime() {
59  				return SimTime;
60  			}
61  						
62  			/**
63  			 * Used by Yylex to slip correct time of the object or programmatically.
64  			 */
65  			protected void setSimTime(long SimTime) {
66  				this.SimTime = SimTime;
67  			}
68  	   	
69   		/**
70           * 
71  			An unique Id for this flag, assigned by the game.
72  		 
73           */
74          public abstract UnrealId getId()
75   	;
76  		    			
77   		/**
78           * 
79  			An absolute location of the flag (Sent if we can actually
80  			see the flag).
81  		 
82           */
83          public abstract Location getLocation()
84   	;
85  		    			
86   		/**
87           * 
88  			Id of player/bot holding the flag. (Sent if we can actually
89  			see the flag and the flag is being carried, or if the flag
90  			is being carried by us).
91  		 
92           */
93          public abstract UnrealId getHolder()
94   	;
95  		    			
96   		/**
97           * The owner team of this flag. 
98           */
99          public abstract Integer getTeam()
100  	;
101 		    			
102  		/**
103          * True if the bot can see the flag. 
104          */
105         public abstract boolean isVisible()
106  	;
107 		    			
108  		/**
109          * 
110 			Represents the state the flag is in. Can be "Held",
111 			"Dropped" or "Home" (note that the first letter does not have to be in upper case!).
112 		 
113          */
114         public abstract String getState()
115  	;
116 		    			
117 		 	@Override
118 			public IWorldObjectUpdatedEvent createDisappearEvent() {
119 				return new ObjectDisappeared(this, getSimTime());
120 			}
121 			
122 			public static class ObjectDisappeared implements IWorldObjectUpdatedEvent
123 			{
124 				
125 				public ObjectDisappeared(FlagInfo obj, long time) {
126 					this.obj = obj;
127 					this.time = time;
128 				}
129 				
130 				private FlagInfo obj;
131 				private long time;
132 		
133 				@Override
134 				public WorldObjectId getId() {
135 					return obj.getId();
136 				}
137 		
138 		        /**
139 		         * Simulation time in MILLI SECONDS !!!
140 		         */
141 				@Override
142 				public long getSimTime() {
143 					return time;
144 				}
145 		
146 				@Override
147 				public IWorldObjectUpdateResult<IWorldObject> update(IWorldObject obj) {
148 					if (obj == null) {
149 						throw new PogamutException("Can't 'disappear' null!", this);
150 					}
151 					if (!(obj instanceof FlagInfoMessage)) {
152 						throw new PogamutException("Can't update different class than FlagInfoMessage, got class " + obj.getClass().getSimpleName() + "!", this);
153 					}
154 					FlagInfoMessage toUpdate = (FlagInfoMessage)obj;
155 					if (toUpdate.Visible) {
156 						toUpdate.Visible = false;
157 						return new IWorldObjectUpdateResult.WorldObjectUpdateResult(IWorldObjectUpdateResult.Result.UPDATED, obj);
158 					} else {
159 						return new IWorldObjectUpdateResult.WorldObjectUpdateResult(IWorldObjectUpdateResult.Result.SAME, obj);
160 					}
161 				}
162 		
163 			}
164 	
165 		
166     	
167     	public static class FlagInfoUpdate
168      extends GBObjectUpdate implements ICompositeWorldObjectUpdatedEvent, IGBWorldObjectEvent {	
169 			private FlagInfo object;
170 			private long time;
171 			private ITeamId teamId;
172 			
173 			public FlagInfoUpdate
174     (FlagInfo source, long eventTime, ITeamId teamId) {
175 				this.object = source;
176 				this.time = eventTime;
177 				this.teamId = teamId;
178 			}
179 			
180 			/**
181 			 * Simulation time in MILLI SECONDS !!!
182 			 */ 
183 			@Override
184 			public long getSimTime() {
185 				return time;
186 			}
187 	
188 			@Override
189 			public IWorldObject getObject() {
190 				return object;
191 			}
192 	
193 			@Override
194 			public WorldObjectId getId() {
195 				return object.getId();
196 			}
197 	
198 			@Override
199 			public ILocalWorldObjectUpdatedEvent getLocalEvent() {
200 				return new FlagInfoLocalImpl.FlagInfoLocalUpdate
201     ((FlagInfoLocal)object.getLocal(), time);
202 			}
203 	
204 			@Override
205 			public ISharedWorldObjectUpdatedEvent getSharedEvent() {
206 				return new FlagInfoSharedImpl.FlagInfoSharedUpdate
207     ((FlagInfoShared)object.getShared(), time, teamId);
208 			}
209 	
210 			@Override
211 			public IStaticWorldObjectUpdatedEvent getStaticEvent() {
212 				return new FlagInfoStaticImpl.FlagInfoStaticUpdate
213     ((FlagInfoStatic)object.getStatic(), time);
214 			}
215 			
216 		}
217     
218  		
219  	    public String toString() {
220             return
221             	super.toString() + "[" +
222             	
223 		              			"Id = " + String.valueOf(getId()
224  	) + " | " + 
225 		              		
226 		              			"Location = " + String.valueOf(getLocation()
227  	) + " | " + 
228 		              		
229 		              			"Holder = " + String.valueOf(getHolder()
230  	) + " | " + 
231 		              		
232 		              			"Team = " + String.valueOf(getTeam()
233  	) + " | " + 
234 		              		
235 		              			"Visible = " + String.valueOf(isVisible()
236  	) + " | " + 
237 		              		
238 		              			"State = " + String.valueOf(getState()
239  	) + " | " + 
240 		              		
241 				"]";           		
242         }
243  	
244  		
245  		public String toHtmlString() {
246  			return super.toString() + "[<br/>" +
247             	
248 		              			"<b>Id</b> = " + String.valueOf(getId()
249  	) + " <br/> " + 
250 		              		
251 		              			"<b>Location</b> = " + String.valueOf(getLocation()
252  	) + " <br/> " + 
253 		              		
254 		              			"<b>Holder</b> = " + String.valueOf(getHolder()
255  	) + " <br/> " + 
256 		              		
257 		              			"<b>Team</b> = " + String.valueOf(getTeam()
258  	) + " <br/> " + 
259 		              		
260 		              			"<b>Visible</b> = " + String.valueOf(isVisible()
261  	) + " <br/> " + 
262 		              		
263 		              			"<b>State</b> = " + String.valueOf(getState()
264  	) + " <br/> " + 
265 		              		
266 				"<br/>]";     
267 		}
268  	
269  	    public String toJsonLiteral() {
270             return "flaginfo( "
271             		+
272 									(getId()
273  	 == null ? "null" :
274 										"\"" + getId()
275  	.getStringId() + "\"" 
276 									)
277 								+ ", " + 
278 								    (getLocation()
279  	 == null ? "null" :
280 										"[" + getLocation()
281  	.getX() + ", " + getLocation()
282  	.getY() + ", " + getLocation()
283  	.getZ() + "]" 
284 									)
285 								+ ", " + 
286 									(getHolder()
287  	 == null ? "null" :
288 										"\"" + getHolder()
289  	.getStringId() + "\"" 
290 									)
291 								+ ", " + 
292 								    String.valueOf(getTeam()
293  	)									
294 								+ ", " + 
295 								    String.valueOf(isVisible()
296  	)									
297 								+ ", " + 
298 									(getState()
299  	 == null ? "null" :
300 										"\"" + getState()
301  	 + "\"" 
302 									)
303 								
304                    + ")";
305         }
306  	
307  		
308  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
309         	
310 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
311 		
312 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=base+classtype[@name=abstract]) ---
313 	        
314 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=base+classtype[@name=abstract]) ---        	            	
315  	
316 		}
317