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=abstract] BEGIN
13  		
14  		// --- IMPORTS FROM extra/code/java/javapart/classcategory[@name=local]+classtype[@name=abstract] END
15      
16   		/**
17           *  
18              				Abstract definition of the local part of the GameBots2004 message VEH.  
19              			
20           *
21           *  <p></p><p></p>
22           *  Complete message documentation:               
23           *  
24  		Synchronous message. Holds vehicles we see. Id for vehicles doesn't work, so 
25  		this message is without Id. We can join vehicles by ENTER command if we are 
26  		close enough - ussually 100 ut units or less. Note: Vehicle support is 
27  		in aplha testing right now.
28  	
29           */
30   	public abstract class VehicleLocal 
31    						extends InfoMessage
32    						implements ILocalWorldObject
33    						
34  	    		,ILocalGBViewable
35  	    {
36   	
37      	
38      	
39      	/**
40      	 * Parameter-less contructor for the message.
41      	 */
42  		public VehicleLocal()
43  		{
44  		}
45  		
46  				// abstract definition of the local-part of the message, no more constructors is needed
47  			
48  	   		
49  			protected long SimTime;
50  				
51  			/**
52  			 * Simulation time in MILLI SECONDS !!!
53  			 */	
54  			@Override
55  			public long getSimTime() {
56  				return SimTime;
57  			}
58  						
59  			/**
60  			 * Used by Yylex to slip correct time of the object or programmatically.
61  			 */
62  			protected void setSimTime(long SimTime) {
63  				this.SimTime = SimTime;
64  			}
65  	   	
66  	    			
67  	    				@Override
68  		    			public abstract 
69  		    			VehicleLocal clone();
70  		    			
71  						@Override
72  						public Class getCompositeClass() {
73  							return Vehicle.class;
74  						}
75  	
76  						
77  		    			
78   		/**
79           * Unique Id of the vehicle or vehicle part. 
80           */
81          public abstract UnrealId getId()
82   	;
83  		    			
84   		/**
85           * 
86              If the vehicle is in the field of view of the bot.
87           
88           */
89          public abstract boolean isVisible()
90   	;
91  		    			
92      	
93      	
94      	
95      	public VehicleLocal getLocal() {
96  			return this;
97      	}
98  		public ISharedWorldObject getShared() {
99  		 	throw new UnsupportedOperationException("Could not return LOCAL");
100 		}
101 		public IStaticWorldObject getStatic() {
102 		    throw new UnsupportedOperationException("Could not return LOCAL");
103 		}
104  	
105  		
106 		 	@Override
107 			public ILocalWorldObjectUpdatedEvent createDisappearEvent() {
108 				return new ObjectDisappeared(this, getSimTime());
109 			}
110 			
111 			public static class ObjectDisappeared implements ILocalWorldObjectUpdatedEvent
112 			{
113 				
114 				public ObjectDisappeared(VehicleLocal obj, long time) {
115 					this.obj = obj;
116 					this.time = time;
117 				}
118 				
119 				private VehicleLocal obj;
120 				private long time;
121 		
122 				@Override
123 				public WorldObjectId getId() {
124 					return obj.getId();
125 				}
126 		
127 		        /**
128 		         * Simulation time in MILLI SECONDS !!!
129 		         */
130 				@Override
131 				public long getSimTime() {
132 					return time;
133 				}
134 		
135 				@Override
136 				public IWorldObjectUpdateResult<ILocalWorldObject> update(ILocalWorldObject obj) 
137 				{
138 					if (obj == null) {
139 						throw new PogamutException("Can't 'disappear' null!", this);
140 					}
141 					if (!(obj instanceof VehicleLocalImpl)) {
142 						throw new PogamutException("Can't update different class than VehicleLocalImpl, got class " + obj.getClass().getSimpleName() + "!", this);
143 					}
144 					VehicleLocalImpl toUpdate = (VehicleLocalImpl)obj;
145 					if (toUpdate.Visible) {
146 						toUpdate.Visible = false;
147 						return new IWorldObjectUpdateResult.WorldObjectUpdateResult(IWorldObjectUpdateResult.Result.UPDATED, obj);
148 					} else {
149 						return new IWorldObjectUpdateResult.WorldObjectUpdateResult(IWorldObjectUpdateResult.Result.SAME, obj);
150 					}	
151 				}
152 				
153 			}
154 	
155 		
156  		
157  	    public String toString() {
158             return
159             	super.toString() + "[" +
160             	
161 		              			"Id = " + String.valueOf(getId()
162  	) + " | " + 
163 		              		
164 		              			"Visible = " + String.valueOf(isVisible()
165  	) + " | " + 
166 		              		
167 				"]";           		
168         }
169  	
170  		
171  		public String toHtmlString() {
172  			return super.toString() + "[<br/>" +
173             	
174 		              			"<b>Id</b> = " + String.valueOf(getId()
175  	) + " <br/> " + 
176 		              		
177 		              			"<b>Visible</b> = " + String.valueOf(isVisible()
178  	) + " <br/> " + 
179 		              		
180 				"<br/>]";     
181 		}
182  	
183  		
184  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
185         	
186 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
187 		
188 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=local+classtype[@name=abstract]) ---
189 	        
190 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=local+classtype[@name=abstract]) ---        	            	
191  	
192 		}
193