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=local]+classtype[@name=impl] BEGIN
13  		
14  		// --- IMPORTS FROM extra/code/java/javapart/classcategory[@name=local]+classtype[@name=impl] END
15      
16   		/**
17           *  
18              				Implementation of the local part of the GameBots2004 message ALIVE.  
19              			
20           *
21           *  <p></p><p></p>
22           *  Complete message documentation:               
23           *  
24  		Synchronous message. Alive message are for confirmation, that
25  		the connection is still working. They are sent periodically with
26  		usual period of one second (this can change depending on the
27  		configuration of ControlServer)
28  	
29           */
30   	public class AliveMessageLocalImpl 
31    						extends
32    						AliveMessageLocal
33  	    {
34   	
35      	
36      	
37      	/**
38      	 * Parameter-less contructor for the message.
39      	 */
40  		public AliveMessageLocalImpl()
41  		{
42  		}
43  	
44      	/**
45  		 * Cloning constructor from the full message.
46  		 *
47  		 * @param original
48  		 */
49  		public AliveMessageLocalImpl(AliveMessage original) {		
50  			
51  					this.Time = original.getTime()
52   	;
53  				
54  			this.SimTime = original.getSimTime();			
55  		}
56  		
57  		/**
58  		 * Cloning constructor from the full message.
59  		 *
60  		 * @param original
61  		 */
62  		public AliveMessageLocalImpl(AliveMessageLocalImpl original) {		
63  			
64  					this.Time = original.getTime()
65   	;
66  				
67  			this.SimTime = original.getSimTime();
68  		}
69  		
70  			/**
71  			 * Cloning constructor from the message part.
72  			 *
73  			 * @param original
74  			 */
75  			public AliveMessageLocalImpl(AliveMessageLocal original) {
76  				
77  						this.Time = original.getTime()
78   	;
79  					
80  			}
81  		
82  						
83  						public UnrealId getId() {						
84  							return cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.AliveMessage.AliveMessageId;
85  						}
86  					
87     				
88     				@Override
89     				public void setSimTime(long SimTime) {
90  					super.setSimTime(SimTime);
91  				}
92     			
93  	    				@Override
94  	    				public 
95  	    				AliveMessageLocalImpl clone() {
96  	    					return new 
97  	    					AliveMessageLocalImpl(this);
98  	    				}
99  	    				
100 	    				
101     	
102 	    /**
103          * 
104 			Game time when this message was send.
105 		 
106          */
107         protected
108          double Time =
109        	0;
110 	
111  		/**
112          * 
113 			Game time when this message was send.
114 		 
115          */
116         public  double getTime()
117  	 {
118 				    					return Time;
119 				    				}
120 				    			
121     	
122     	
123     	
124     	
125     	public AliveMessageLocalImpl getLocal() {
126 			return this;
127     	}
128 		public ISharedWorldObject getShared() {
129 		 	throw new UnsupportedOperationException("Could not return LOCAL as SHARED");
130 		}
131 		public IStaticWorldObject getStatic() {
132 		    throw new UnsupportedOperationException("Could not return LOCAL as STATIC");
133 		}
134  	
135 		public static class AliveMessageLocalUpdate
136      implements ILocalWorldObjectUpdatedEvent, IGBWorldObjectEvent
137 		{
138 			protected long time;
139 			
140 			protected AliveMessageLocal data = null; //contains object data for this update
141 			
142 			public AliveMessageLocalUpdate
143     (AliveMessageLocal moverLocal, long time)
144 			{
145 				this.data = moverLocal;
146 				this.time = time;
147 			}
148 			
149 			@Override
150 			public IWorldObjectUpdateResult<ILocalWorldObject> update(
151 					ILocalWorldObject object) 
152 			{
153 				if ( object == null)
154 				{
155 					data = new AliveMessageLocalImpl(data); //we always return Impl object
156 					return new IWorldObjectUpdateResult.WorldObjectUpdateResult<ILocalWorldObject>(IWorldObjectUpdateResult.Result.CREATED, data);
157 				}
158 				if ( object instanceof AliveMessageLocalImpl )
159 				{
160 					AliveMessageLocalImpl toUpdate = (AliveMessageLocalImpl)object;
161 					
162 					boolean updated = false;
163 					
164 					// UPDATING LOCAL PROPERTIES
165 					
166 				if (toUpdate.Time != data.getTime()
167  	) {
168 				    toUpdate.Time=data.getTime()
169  	;
170 					updated = true;
171 				}
172 			
173 					
174 					data = toUpdate; //the updating has finished
175 					
176 					if ( updated )
177 					{
178 						toUpdate.SimTime = this.time;
179 						return new IWorldObjectUpdateResult.WorldObjectUpdateResult<ILocalWorldObject>(IWorldObjectUpdateResult.Result.UPDATED, data);
180 					}
181 					
182 					return new IWorldObjectUpdateResult.WorldObjectUpdateResult<ILocalWorldObject>(IWorldObjectUpdateResult.Result.SAME, data);
183 				}
184 				throw new PogamutException("Unsupported object type for update. Expected AliveMessageLocalImpl for object " + object.getId() +", not object of class " + object.getClass().getSimpleName() + ".", this);
185 			}
186 	
187 			/**
188 			 * Simulation time in MILLI SECONDS !!!
189 			 */
190 			@Override
191 			public long getSimTime() {
192 				return this.time;
193 			}
194 	
195 			@Override
196 			public IWorldObject getObject() {
197 				return data;
198 			}
199 	
200 			@Override
201 			public WorldObjectId getId() {
202 				return data.getId();
203 			}
204 			
205 		}	
206  	
207  		
208  	    public String toString() {
209             return
210             	super.toString() + "[" +
211             	
212 		              			"Time = " + String.valueOf(getTime()
213  	) + " | " + 
214 		              		
215 				"]";           		
216         }
217  	
218  		
219  		public String toHtmlString() {
220  			return super.toString() + "[<br/>" +
221             	
222 		              			"<b>Time</b> = " + String.valueOf(getTime()
223  	) + " <br/> " + 
224 		              		
225 				"<br/>]";     
226 		}
227  	
228  		
229  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
230         	
231 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
232 		
233 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=local+classtype[@name=impl]) ---
234 	        
235 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=local+classtype[@name=impl]) ---        	            	
236  	
237 		}
238