Behaviors and libraries

From AI Wiki

Jump to: navigation, search

In the previous section about moving we've already briefly touched on how you can specify multiple behaviors in your Iams. This section expands on that a little bit. Let's first look a little closer at the XML file that decribed the surverying behavior previously. For your convenience it has been duplicated below:

 	<bean id="classpath" class="com.avatar_reality.blue_mars.iam.ClassPathBean">
		<property name="jarList">

<bean id="SpawnLocation" class="">

		<constructor-arg index="0" value="3458"/>
		<constructor-arg index="1" value="1918"/>
		<constructor-arg index="2" value="31"/>
	<bean id="IamTownMap" class="">
		<constructor-arg index="0" value="maps/IamTown/mymap.txt"/>

	<bean id="SurveyingBehavior" class="com.avatar_reality.blue_mars.iam.behavior.implementations.SurveyingBehavior" scope="prototype">
		<property name="mapFileName" value="maps/IamTown/mymap.txt"/>
 	<bean id="FollowingBehavior" class="com.avatar_reality.blue_mars.iam.behavior.implementations.FollowingBehavior" scope="prototype"/>

	<bean id="miam" class="com.avatar_reality.blue_mars.iam.framework.IamBot">
		<property name="spawnLocation">
			<ref bean="SpawnLocation"/>
		<property name="loginName" value=""/>
		<property name="password" value="bot123"/>
		<property name="cityName" value="AR_IamTown"/>
		<property name="map">
			<ref bean="IamTownMap"/>
 		<property name="genderString" value="Male"/>
		<property name="name" value="Mr. Inspector"/>
		<property name="isMonitored" value="true"/>
		<property name="behaviorList">
				<ref bean="SurveyingBehavior"/>
				<ref bean="FollowingBehavior"/>

This time pay special attention to the line that says <property name="jar" value="file:IamLibrary.jar"/> What this does is it tells the Iam framework to dynamically load a library before it lets Spring assemble the Iams. In Java libraries are stored in a .JAR file. It stands for Java ARchive. But actually it's just a zip file with a different suffix. The file: part just before the name of the library tells the framework that the library is stored as a local file. This is because it's also possible to use a http: prefix to indicated the library must be downloaded from a completely different place somewhere on the Internet.

No source!

You may have noticed that no source-code was included with the Iam Library. This is not because we want to guard it closely and keep it secret. All the behaviors in the library are actually very simple and could be programmed by any skilled programmer in a matter of a few hours. The source code was not included because you don't need it. All you need to know is what the behaviors are called and what they do. And then you can assemble an Iam simply by specifying in the XML file the class-names of the behaviors and the library in which they reside. This means you can exchange behaviors with other developers (or at some point maybe even sell them) without having to disclose the source-code. And since they can be downloaded from anywhere on the internet, you don't even actually need to give them the class-files. The only requirement that must be fulfilled is that the behavior class is an extension of the com.avatar_reality.blue_mars.iam.framework.behavior.AbstractBehavior class.

Personal tools