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=shared]+classtype[@name=impl] BEGIN
13  		
14  		// --- IMPORTS FROM extra/code/java/javapart/classcategory[@name=shared]+classtype[@name=impl] END
15      
16   		/**
17           *  
18              				Implementation of the shared part of the GameBots2004 message INITED.  
19              			
20           *
21           *  <p></p><p></p>
22           *  Complete message documentation:               
23           *  
24  		Asynchronous message. Sent after succesfull init command (so usually just once). 
25  		Holds many attributes of the bots like speed, id starting and max health, etc.
26  		Some attributes are not used due to GameBots mechanics.
27  	
28           */
29   	public class InitedMessageSharedImpl 
30    						extends
31    						InitedMessageShared
32  	    {
33   	
34      
35      	
36      	public InitedMessageSharedImpl(InitedMessageSharedImpl source) {
37  			
38  		}
39  		
40  		public InitedMessageSharedImpl(WorldObjectId objectId, Collection<ISharedProperty> properties) {
41  			this.Id = (UnrealId)objectId;
42  			NullCheck.check(this.Id, "objectId");
43  		
44  			if (properties.size() != 0) {
45  				throw new PogamutException("Not enough properties passed to the constructor.", InitedMessageSharedImpl.class);
46  			}
47  		
48  			//we have to do some checking in this one to know that we get all properties required
49  			for ( ISharedProperty property : properties ) {
50  				PropertyId pId = property.getPropertyId();
51  				if ( !objectId.equals( property.getObjectId() )) {
52  					//properties for different objects
53  					throw new PogamutException("Trying to create a InitedMessageSharedImpl with different WorldObjectId properties : " + 
54  											    this.Id.getStringId() + " / " + property.getObjectId().getStringId() , this);
55  				}
56  				if (!InitedMessageShared.SharedPropertyTokens.contains(pId.getPropertyToken())) {
57  				// property that does not belong here
58  				throw new PogamutException("Trying to create a InitedMessageSharedImpl with invalid property (invalid property token): " + 
59  					this.Id.getStringId() + " / " + property.getPropertyId().getPropertyToken().getToken() , this);
60  				}
61  				propertyMap.put(property.getPropertyId(), property);
62  				
63  				
64  			}
65  		}
66      
67  						
68  						private UnrealId Id = cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.InitedMessage.InitedMessageId;
69  						
70  						public UnrealId getId() {
71  							return Id;
72  						}
73  					
74     				
75     				@Override
76     				public void setSimTime(long SimTime) {
77  					super.setSimTime(SimTime);
78  				}
79     			
80  	    				@Override
81  	    				public 
82  	    				InitedMessageSharedImpl clone() {
83  	    					return new 
84  	    					InitedMessageSharedImpl(this);
85  	    				}
86  	    				
87  	    				
88  		
89  		
90  		
91  		protected HashMap<PropertyId, ISharedProperty> propertyMap = new HashMap<PropertyId, ISharedProperty>(
92  			0
93  		);
94  		
95  		@Override
96  		public ISharedProperty getProperty(PropertyId id) {
97  			return propertyMap.get(id);
98  		}
99  
100 		@Override
101 		public Map<PropertyId, ISharedProperty> getProperties() {
102 			return propertyMap;
103 		}
104 	
105 		
106 		
107     	
108     	
109     	public static class InitedMessageSharedUpdate
110      implements ISharedWorldObjectUpdatedEvent
111 		{
112 	
113 			private InitedMessageShared object;
114 			private long time;
115 			private ITeamId teamId;
116 			
117 			public InitedMessageSharedUpdate
118     (InitedMessageShared data, long time, ITeamId teamId)
119 			{
120 				this.object = data;
121 				this.time = time;
122 				this.teamId = teamId;
123 			}
124 			
125 			/**
126 			 * Simulation time in MILLI SECONDS !!!
127 			 */
128 			@Override
129 			public long getSimTime() {
130 				return this.time;
131 			}
132 	
133 			@Override
134 			public WorldObjectId getId() {
135 				return object.getId();
136 			}
137 	
138 			@Override
139 			public ITeamId getTeamId() {
140 				return teamId;
141 			}
142 			
143 			@Override
144 			public Class getCompositeObjectClass()
145 			{
146 				return object.getCompositeClass();
147 			}
148 	
149 			@Override
150 			public Collection<ISharedPropertyUpdatedEvent> getPropertyEvents() {
151 				LinkedList<ISharedPropertyUpdatedEvent> events = new LinkedList<ISharedPropertyUpdatedEvent>();
152 				
153 				for ( ISharedProperty property : object.getProperties().values() )
154 				{
155 					if ( property != null)
156 					{
157 						events.push( property.createUpdateEvent(time, teamId) );
158 					}
159 				}
160 				return events;
161 			}
162 			
163 		}
164 	
165     
166  		
167  	    public String toString() {
168             return
169             	super.toString() + "[" +
170             	
171 				"]";           		
172         }
173  	
174  		
175  		public String toHtmlString() {
176  			return super.toString() + "[<br/>" +
177             	
178 				"<br/>]";     
179 		}
180  	
181  		
182  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
183         	
184 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
185 		
186 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=shared+classtype[@name=impl]) ---
187 	        
188 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=shared+classtype[@name=impl]) ---        	            	
189  	
190 		}
191