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