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  		public PlayerStaticImpl(
99  			UnrealId Id
100 		) {
101 			
102 					this.Id = Id;
103 				
104 		}
105     
106     	/**
107 		 * Cloning constructor from the full message.
108 		 *
109 		 * @param original
110 		 */
111 		public PlayerStaticImpl(Player original) {		
112 			
113 					this.Id = original.getId()
114  	;
115 				
116 			this.SimTime = original.getSimTime();			
117 		}
118 		
119 		/**
120 		 * Cloning constructor from the full message.
121 		 *
122 		 * @param original
123 		 */
124 		public PlayerStaticImpl(PlayerStaticImpl original) {		
125 			
126 					this.Id = original.getId()
127  	;
128 				
129 			this.SimTime = original.getSimTime();
130 		}
131 		
132 			/**
133 			 * Cloning constructor from the message part.
134 			 *
135 			 * @param original
136 			 */
137 			public PlayerStaticImpl(PlayerStatic original) {
138 				
139 						this.Id = original.getId()
140  	;
141 					
142 			}
143 		
144    				
145    				@Override
146    				public void setSimTime(long SimTime) {
147 					super.setSimTime(SimTime);
148 				}
149    			
150 	    				@Override
151 	    				public 
152 	    				PlayerStaticImpl clone() {
153 	    					return new 
154 	    					PlayerStaticImpl(this);
155 	    				}
156 	    				
157 	    				
158     	
159 	    /**
160          * Unique Id of the player. 
161          */
162         protected
163          UnrealId Id =
164        	null;
165 	
166  		/**
167          * Unique Id of the player. 
168          */
169         public  UnrealId getId()
170  	 {
171 				    					return Id;
172 				    				}
173 				    			
174     	
175     	
176     	public static class PlayerStaticUpdate
177      implements IStaticWorldObjectUpdatedEvent
178 		{
179 			
180 			private PlayerStatic data;
181 			private long time;
182 			
183 			public PlayerStaticUpdate
184     (PlayerStatic source, long time)
185 			{
186 				this.data = source;
187 				this.time = time;
188 			}
189 			
190 			/**
191 			 * Simulation time in MILLI SECONDS !!!
192 			 */
193 			@Override
194 			public long getSimTime() {
195 				return time;
196 			}
197 	
198 			@Override
199 			public WorldObjectId getId() {
200 				return data.getId();
201 			}
202 			
203 			@Override
204 			public IWorldObjectUpdateResult<IStaticWorldObject> update(
205 					IStaticWorldObject object) {
206 				if ( object == null)
207 				{
208 					data = new PlayerStaticImpl(data);
209 					return new IWorldObjectUpdateResult.WorldObjectUpdateResult<IStaticWorldObject>(IWorldObjectUpdateResult.Result.CREATED, data);
210 				}
211 				//since static objects can't be updated, we'll just check that the object stays the same
212 				if ( object instanceof PlayerStaticImpl)
213 				{
214 					PlayerStaticImpl orig = (PlayerStaticImpl)object;
215 					//since these errors usually mean error in gamebots, we will just print an error message
216 					if ( data.isDifferentFrom(orig) )
217 					{
218 						//data.isDifferentFrom(orig);
219 						//throw new PogamutException("Trying to modify static object " + this.data.getId().toString() , this);
220 						System.out.println("!!!!!ERROR!!!!!! in static object modification. Object class : PlayerStaticImpl to see which property was different see !!!!PROPERTY UPDATE ERROR!!!!");
221 					}
222 					return new IWorldObjectUpdateResult.WorldObjectUpdateResult<IStaticWorldObject>(IWorldObjectUpdateResult.Result.SAME, data);
223 				}				
224 				throw new PogamutException("Unexpected object type for update, PlayerStaticImpl expected not class " + object.getClass().getSimpleName() + ".", this);
225 			}
226 		}
227 	
228     
229  		
230  		@Override
231  		public boolean isDifferentFrom(IStaticWorldObject other)
232  		{
233  			if (other == null) //early fail
234  			{
235  				return true;
236  			}
237  			else if (other == this) //early out
238  			{
239  				return false;
240  			}
241  			else
242  			{
243  				PlayerStatic obj = (PlayerStatic) other;
244 
245  				
246  						if ( !(
247  	 			AdvancedEquals.equalsOrNull(this.getId()
248  	, obj.getId()
249  	)
250  	 		) )
251 						{
252 							System.out.println("!!!!!PROPERTY UPDATE ERROR!!!! on property Id on object class PlayerStatic");
253 							return true;
254 						}
255  					
256  			}
257  			return false;
258  		}
259  	 
260  		
261  	    public String toString() {
262             return
263             	super.toString() + "[" +
264             	
265 		              			"Id = " + String.valueOf(getId()
266  	) + " | " + 
267 		              		
268 				"]";           		
269         }
270  	
271  		
272  		public String toHtmlString() {
273  			return super.toString() + "[<br/>" +
274             	
275 		              			"<b>Id</b> = " + String.valueOf(getId()
276  	) + " <br/> " + 
277 		              		
278 				"<br/>]";     
279 		}
280  	
281  		
282  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
283         	
284 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
285 		
286 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=static+classtype[@name=impl]) ---
287 	        
288 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=static+classtype[@name=impl]) ---        	            	
289  	
290 		}
291