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=static]+classtype[@name=impl] BEGIN
13  		
14  		// --- IMPORTS FROM extra/code/java/javapart/classcategory[@name=static]+classtype[@name=impl] END
15      
16   		/**
17           *  
18              				Implementation of the static part of the GameBots2004 message PLR.  
19              			
20           *
21           *  <p></p><p></p>
22           *  Complete message documentation:               
23           *  
24  		Synchronous message. Contains information about other players in
25  		the game, like their current velocity, position, weapon and
26  		reachability. Only reports those players that are visible.
27  		(within field of view and not occluded).
28  	
29           */
30   	public class PlayerStaticImpl 
31    						extends
32    						PlayerStatic
33  	    {
34   	
35      	
36      	
37      	/**
38      	 * Parameter-less contructor for the message.
39      	 */
40  		public PlayerStaticImpl()
41  		{
42  		}
43  	
44      	
45      	
46      	
47      	/**
48  		 * Creates new instance of the message Player.
49  		 * 
50  		Synchronous message. Contains information about other players in
51  		the game, like their current velocity, position, weapon and
52  		reachability. Only reports those players that are visible.
53  		(within field of view and not occluded).
54  	
55  		 * Corresponding GameBots message
56  		 *   (static part)
57  		 *   is
58  		 *   PLR.
59  		 * 
60   	  	 * 
61  		 *   
62  		 *     @param Id Unique Id of the player.
63  		 *   
64  		 * 
65  		 *   
66  		 * 
67  		 *   
68  		 * 
69  		 *   
70  		 * 
71  		 *   
72  		 * 
73  		 *   
74  		 * 
75  		 *   
76  		 * 
77  		 *   
78  		 * 
79  		 *   
80  		 * 
81  		 *   
82  		 * 
83  		 *   
84  		 * 
85  		 *   
86  		 * 
87  		 *   
88  		 * 
89  		 *   
90  		 * 
91  		 *   
92  		 * 
93  		 *   
94  		 * 
95  		 *   
96  		 * 
97  		 *   
98  		 * 
99  		 */
100 		public PlayerStaticImpl(
101 			UnrealId Id
102 		) {
103 			
104 					this.Id = Id;
105 				
106 		}
107     
108     	/**
109 		 * Cloning constructor from the full message.
110 		 *
111 		 * @param original
112 		 */
113 		public PlayerStaticImpl(Player original) {		
114 			
115 					this.Id = original.getId()
116  	;
117 				
118 			this.SimTime = original.getSimTime();			
119 		}
120 		
121 		/**
122 		 * Cloning constructor from the full message.
123 		 *
124 		 * @param original
125 		 */
126 		public PlayerStaticImpl(PlayerStaticImpl original) {		
127 			
128 					this.Id = original.getId()
129  	;
130 				
131 			this.SimTime = original.getSimTime();
132 		}
133 		
134 			/**
135 			 * Cloning constructor from the message part.
136 			 *
137 			 * @param original
138 			 */
139 			public PlayerStaticImpl(PlayerStatic original) {
140 				
141 						this.Id = original.getId()
142  	;
143 					
144 			}
145 		
146    				
147    				@Override
148    				public void setSimTime(long SimTime) {
149 					super.setSimTime(SimTime);
150 				}
151    			
152 	    				@Override
153 	    				public 
154 	    				PlayerStaticImpl clone() {
155 	    					return new 
156 	    					PlayerStaticImpl(this);
157 	    				}
158 	    				
159 	    				
160     	
161 	    /**
162          * Unique Id of the player. 
163          */
164         protected
165          UnrealId Id =
166        	null;
167 	
168  		/**
169          * Unique Id of the player. 
170          */
171         public  UnrealId getId()
172  	 {
173 				    					return Id;
174 				    				}
175 				    			
176     	
177     	
178     	public static class PlayerStaticUpdate
179      implements IStaticWorldObjectUpdatedEvent
180 		{
181 			
182 			private PlayerStatic data;
183 			private long time;
184 			
185 			public PlayerStaticUpdate
186     (PlayerStatic source, long time)
187 			{
188 				this.data = source;
189 				this.time = time;
190 			}
191 			
192 			/**
193 			 * Simulation time in MILLI SECONDS !!!
194 			 */
195 			@Override
196 			public long getSimTime() {
197 				return time;
198 			}
199 	
200 			@Override
201 			public WorldObjectId getId() {
202 				return data.getId();
203 			}
204 			
205 			@Override
206 			public IWorldObjectUpdateResult<IStaticWorldObject> update(
207 					IStaticWorldObject object) {
208 				if ( object == null)
209 				{
210 					data = new PlayerStaticImpl(data);
211 					return new IWorldObjectUpdateResult.WorldObjectUpdateResult<IStaticWorldObject>(IWorldObjectUpdateResult.Result.CREATED, data);
212 				}
213 				//since static objects can't be updated, we'll just check that the object stays the same
214 				if ( object instanceof PlayerStaticImpl)
215 				{
216 					PlayerStaticImpl orig = (PlayerStaticImpl)object;
217 					//since these errors usually mean error in gamebots, we will just print an error message
218 					if ( data.isDifferentFrom(orig) )
219 					{
220 						//data.isDifferentFrom(orig);
221 						//throw new PogamutException("Trying to modify static object " + this.data.getId().toString() , this);
222 						System.out.println("!!!!!ERROR!!!!!! in static object modification. Object class : PlayerStaticImpl to see which property was different see !!!!PROPERTY UPDATE ERROR!!!!");
223 					}
224 					return new IWorldObjectUpdateResult.WorldObjectUpdateResult<IStaticWorldObject>(IWorldObjectUpdateResult.Result.SAME, data);
225 				}				
226 				throw new PogamutException("Unexpected object type for update, PlayerStaticImpl expected not class " + object.getClass().getSimpleName() + ".", this);
227 			}
228 		}
229 	
230     
231  		
232  		@Override
233  		public boolean isDifferentFrom(IStaticWorldObject other)
234  		{
235  			if (other == null) //early fail
236  			{
237  				return true;
238  			}
239  			else if (other == this) //early out
240  			{
241  				return false;
242  			}
243  			else
244  			{
245  				PlayerStatic obj = (PlayerStatic) other;
246 
247  				
248  						if ( !(
249  	 			AdvancedEquals.equalsOrNull(this.getId()
250  	, obj.getId()
251  	)
252  	 		) )
253 						{
254 							System.out.println("!!!!!PROPERTY UPDATE ERROR!!!! on property Id on object class PlayerStatic");
255 							return true;
256 						}
257  					
258  			}
259  			return false;
260  		}
261  	 
262  		
263  	    public String toString() {
264             return
265             	super.toString() + "[" +
266             	
267 		              			"Id = " + String.valueOf(getId()
268  	) + " | " + 
269 		              		
270 				"]";           		
271         }
272  	
273  		
274  		public String toHtmlString() {
275  			return super.toString() + "[<br/>" +
276             	
277 		              			"<b>Id</b> = " + String.valueOf(getId()
278  	) + " <br/> " + 
279 		              		
280 				"<br/>]";     
281 		}
282  	
283  		
284  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
285         	
286 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
287 		
288 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=static+classtype[@name=impl]) ---
289 	        
290 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=static+classtype[@name=impl]) ---        	            	
291  	
292 		}
293