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