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=shared]+classtype[@name=impl] BEGIN
13  		
14  		// --- IMPORTS FROM extra/code/java/javapart/classcategory[@name=shared]+classtype[@name=impl] END
15      
16   		/**
17           *  
18              				Implementation of the shared part of the GameBots2004 message NFO.  
19              			
20           *
21           *  <p></p><p></p>
22           *  Complete message documentation:               
23           *  
24  		Asynchronous message. Sent as response to READY command.
25  		Information about the game. What type of game is it going to be,
26  		number of teams, maximum size of teams etc.
27  	
28           */
29   	public class GameInfoSharedImpl 
30    						extends
31    						GameInfoShared
32  	    {
33   	
34      
35      	
36      	public GameInfoSharedImpl(GameInfoSharedImpl source) {
37  			
38  				this.myWeaponStay = source.myWeaponStay;
39  			
40  				this.myTimeLimit = source.myTimeLimit;
41  			
42  				this.myFragLimit = source.myFragLimit;
43  			
44  				this.myGoalTeamScore = source.myGoalTeamScore;
45  			
46  				this.myMaxTeamSize = source.myMaxTeamSize;
47  			
48  				this.myGamePaused = source.myGamePaused;
49  			
50  				this.myBotsPaused = source.myBotsPaused;
51  			
52  		}
53  		
54  		public GameInfoSharedImpl(WorldObjectId objectId, Collection<ISharedProperty> properties) {
55  			this.Id = (UnrealId)objectId;
56  			NullCheck.check(this.Id, "objectId");
57  		
58  			if (properties.size() != 7) {
59  				throw new PogamutException("Not enough properties passed to the constructor.", GameInfoSharedImpl.class);
60  			}
61  		
62  			//we have to do some checking in this one to know that we get all properties required
63  			for ( ISharedProperty property : properties ) {
64  				PropertyId pId = property.getPropertyId();
65  				if ( !objectId.equals( property.getObjectId() )) {
66  					//properties for different objects
67  					throw new PogamutException("Trying to create a GameInfoSharedImpl with different WorldObjectId properties : " + 
68  											    this.Id.getStringId() + " / " + property.getObjectId().getStringId() , this);
69  				}
70  				if (!GameInfoShared.SharedPropertyTokens.contains(pId.getPropertyToken())) {
71  				// property that does not belong here
72  				throw new PogamutException("Trying to create a GameInfoSharedImpl with invalid property (invalid property token): " + 
73  					this.Id.getStringId() + " / " + property.getPropertyId().getPropertyToken().getToken() , this);
74  				}
75  				propertyMap.put(property.getPropertyId(), property);
76  				
77  				
78  					if (pId.getPropertyToken().getToken().equals("WeaponStay"))
79  					{
80  						this.myWeaponStay = (BooleanProperty)property;
81  					}
82  				
83  					if (pId.getPropertyToken().getToken().equals("TimeLimit"))
84  					{
85  						this.myTimeLimit = (DoubleProperty)property;
86  					}
87  				
88  					if (pId.getPropertyToken().getToken().equals("FragLimit"))
89  					{
90  						this.myFragLimit = (IntProperty)property;
91  					}
92  				
93  					if (pId.getPropertyToken().getToken().equals("GoalTeamScore"))
94  					{
95  						this.myGoalTeamScore = (LongProperty)property;
96  					}
97  				
98  					if (pId.getPropertyToken().getToken().equals("MaxTeamSize"))
99  					{
100 						this.myMaxTeamSize = (IntProperty)property;
101 					}
102 				
103 					if (pId.getPropertyToken().getToken().equals("GamePaused"))
104 					{
105 						this.myGamePaused = (BooleanProperty)property;
106 					}
107 				
108 					if (pId.getPropertyToken().getToken().equals("BotsPaused"))
109 					{
110 						this.myBotsPaused = (BooleanProperty)property;
111 					}
112 				
113 			}
114 		}
115     
116 						
117 						private UnrealId Id = cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo.GameInfoId;
118 						
119 						public UnrealId getId() {
120 							return Id;
121 						}
122 					
123    				
124    				@Override
125    				public void setSimTime(long SimTime) {
126 					super.setSimTime(SimTime);
127 				}
128    			
129 	    				@Override
130 	    				public 
131 	    				GameInfoSharedImpl clone() {
132 	    					return new 
133 	    					GameInfoSharedImpl(this);
134 	    				}
135 	    				
136 	    				
137 		
138 		
139 		
140 		protected HashMap<PropertyId, ISharedProperty> propertyMap = new HashMap<PropertyId, ISharedProperty>(
141 			7
142 		);
143 		
144 		@Override
145 		public ISharedProperty getProperty(PropertyId id) {
146 			return propertyMap.get(id);
147 		}
148 
149 		@Override
150 		public Map<PropertyId, ISharedProperty> getProperties() {
151 			return propertyMap;
152 		}
153 	
154 		
155 		
156     	
157 	    /**
158          * 
159 			If true respawned weapons will stay on the ground after picked up (but bot cannot pickup same weapon twice).
160 		 
161          */
162         protected
163          BooleanProperty 
164         myWeaponStay
165 					= null;
166 					
167 					
168  		/**
169          * 
170 			If true respawned weapons will stay on the ground after picked up (but bot cannot pickup same weapon twice).
171 		 
172          */
173         public  boolean isWeaponStay()
174  	 {
175 			  			return myWeaponStay.getValue();
176 			  		}
177 				
178     	
179 	    /**
180          * 
181 			Maximum time game will last (if tied at end may goe to
182 			"sudden death overtime" - depends on the game type).
183 		 
184          */
185         protected
186          DoubleProperty 
187         myTimeLimit
188 					= null;
189 					
190 					
191  		/**
192          * 
193 			Maximum time game will last (if tied at end may goe to
194 			"sudden death overtime" - depends on the game type).
195 		 
196          */
197         public  double getTimeLimit()
198  	 {
199 			  			return myTimeLimit.getValue();
200 			  		}
201 				
202     	
203 	    /**
204          * 
205 			Number of kills needed to win game (BotDeathMatch only).
206 		 
207          */
208         protected
209          IntProperty 
210         myFragLimit
211 					= null;
212 					
213 					
214  		/**
215          * 
216 			Number of kills needed to win game (BotDeathMatch only).
217 		 
218          */
219         public  int getFragLimit()
220  	 {
221 			  			return myFragLimit.getValue();
222 			  		}
223 				
224     	
225 	    /**
226          * 
227 			Number of points a team needs to win the game (BotTeamGame,
228 			BotCTFGame, BotDoubleDomination).
229 		 
230          */
231         protected
232          LongProperty 
233         myGoalTeamScore
234 					= null;
235 					
236 					
237  		/**
238          * 
239 			Number of points a team needs to win the game (BotTeamGame,
240 			BotCTFGame, BotDoubleDomination).
241 		 
242          */
243         public  long getGoalTeamScore()
244  	 {
245 			  			return myGoalTeamScore.getValue();
246 			  		}
247 				
248     	
249 	    /**
250          * 
251 			Max number of players per side (BotTeamGame, BotCTFGame,
252 			BotDoubleDomination).
253 		 
254          */
255         protected
256          IntProperty 
257         myMaxTeamSize
258 					= null;
259 					
260 					
261  		/**
262          * 
263 			Max number of players per side (BotTeamGame, BotCTFGame,
264 			BotDoubleDomination).
265 		 
266          */
267         public  int getMaxTeamSize()
268  	 {
269 			  			return myMaxTeamSize.getValue();
270 			  		}
271 				
272     	
273 	    /**
274          * 
275 			If the game is paused - nobody can move.
276 		 
277          */
278         protected
279          BooleanProperty 
280         myGamePaused
281 					= null;
282 					
283 					
284  		/**
285          * 
286 			If the game is paused - nobody can move.
287 		 
288          */
289         public  boolean isGamePaused()
290  	 {
291 			  			return myGamePaused.getValue();
292 			  		}
293 				
294     	
295 	    /**
296          * 
297 			If the game is paused just for bots - human controlled
298 			players can normally move.
299 		 
300          */
301         protected
302          BooleanProperty 
303         myBotsPaused
304 					= null;
305 					
306 					
307  		/**
308          * 
309 			If the game is paused just for bots - human controlled
310 			players can normally move.
311 		 
312          */
313         public  boolean isBotsPaused()
314  	 {
315 			  			return myBotsPaused.getValue();
316 			  		}
317 				
318     	
319     	
320     	public static class GameInfoSharedUpdate
321      implements ISharedWorldObjectUpdatedEvent
322 		{
323 	
324 			private GameInfoShared object;
325 			private long time;
326 			private ITeamId teamId;
327 			
328 			public GameInfoSharedUpdate
329     (GameInfoShared data, long time, ITeamId teamId)
330 			{
331 				this.object = data;
332 				this.time = time;
333 				this.teamId = teamId;
334 			}
335 			
336 			/**
337 			 * Simulation time in MILLI SECONDS !!!
338 			 */
339 			@Override
340 			public long getSimTime() {
341 				return this.time;
342 			}
343 	
344 			@Override
345 			public WorldObjectId getId() {
346 				return object.getId();
347 			}
348 	
349 			@Override
350 			public ITeamId getTeamId() {
351 				return teamId;
352 			}
353 			
354 			@Override
355 			public Class getCompositeObjectClass()
356 			{
357 				return object.getCompositeClass();
358 			}
359 	
360 			@Override
361 			public Collection<ISharedPropertyUpdatedEvent> getPropertyEvents() {
362 				LinkedList<ISharedPropertyUpdatedEvent> events = new LinkedList<ISharedPropertyUpdatedEvent>();
363 				
364 				for ( ISharedProperty property : object.getProperties().values() )
365 				{
366 					if ( property != null)
367 					{
368 						events.push( property.createUpdateEvent(time, teamId) );
369 					}
370 				}
371 				return events;
372 			}
373 			
374 		}
375 	
376     
377  		
378  	    public String toString() {
379             return
380             	super.toString() + "[" +
381             	
382 		              			"WeaponStay = " + String.valueOf(isWeaponStay()
383  	) + " | " + 
384 		              		
385 		              			"TimeLimit = " + String.valueOf(getTimeLimit()
386  	) + " | " + 
387 		              		
388 		              			"FragLimit = " + String.valueOf(getFragLimit()
389  	) + " | " + 
390 		              		
391 		              			"GoalTeamScore = " + String.valueOf(getGoalTeamScore()
392  	) + " | " + 
393 		              		
394 		              			"MaxTeamSize = " + String.valueOf(getMaxTeamSize()
395  	) + " | " + 
396 		              		
397 		              			"GamePaused = " + String.valueOf(isGamePaused()
398  	) + " | " + 
399 		              		
400 		              			"BotsPaused = " + String.valueOf(isBotsPaused()
401  	) + " | " + 
402 		              		
403 				"]";           		
404         }
405  	
406  		
407  		public String toHtmlString() {
408  			return super.toString() + "[<br/>" +
409             	
410 		              			"<b>WeaponStay</b> = " + String.valueOf(isWeaponStay()
411  	) + " <br/> " + 
412 		              		
413 		              			"<b>TimeLimit</b> = " + String.valueOf(getTimeLimit()
414  	) + " <br/> " + 
415 		              		
416 		              			"<b>FragLimit</b> = " + String.valueOf(getFragLimit()
417  	) + " <br/> " + 
418 		              		
419 		              			"<b>GoalTeamScore</b> = " + String.valueOf(getGoalTeamScore()
420  	) + " <br/> " + 
421 		              		
422 		              			"<b>MaxTeamSize</b> = " + String.valueOf(getMaxTeamSize()
423  	) + " <br/> " + 
424 		              		
425 		              			"<b>GamePaused</b> = " + String.valueOf(isGamePaused()
426  	) + " <br/> " + 
427 		              		
428 		              			"<b>BotsPaused</b> = " + String.valueOf(isBotsPaused()
429  	) + " <br/> " + 
430 		              		
431 				"<br/>]";     
432 		}
433  	
434  		
435  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
436         	
437 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
438 		
439 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=shared+classtype[@name=impl]) ---
440 	        
441 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=shared+classtype[@name=impl]) ---        	            	
442  	
443 		}
444