Index: /branches/ai/src/ai/ai_module.h
===================================================================
--- /branches/ai/src/ai/ai_module.h	(revision 10176)
+++ /branches/ai/src/ai/ai_module.h	(revision 10177)
@@ -10,19 +10,27 @@
    virtual ~AIModule(){}
    virtual void process(float dt){}
-	
+
    void setDifficulty(int newDifficulty);
 	inline void setEnemyList(std::vector<WorldEntity*>* enemyList){this->enemyList=enemyList;}
 	inline Vector getPosition(){return myWorldEntity->getAbsCoor();}
-	inline Vector getMovement(){return this->movement;}
+	inline Vector getMovement(){return movement;}
 	inline void setDestination(Vector destination){this->destination=destination;}
 	inline void setDestinationMovement(Vector destinationMovement){this->destinationMovement=destinationMovement;}
-	
+	inline void setWeight(int weight){this->weight=weight;}
+	inline void setTarget(WorldEntity* target){this->target=target;}
+
  protected:
    NPC2* myNPC;
 	WorldEntity* myWorldEntity;
 	std::vector<WorldEntity*>* enemyList;
+
 	Vector destination;
 	Vector destinationMovement;
 	Vector movement;
+
+	float weight;
+	float speedMax;
+
+	WorldEntity* target;
 };
 
Index: /branches/ai/src/ai/ai_swarm.cc
===================================================================
--- /branches/ai/src/ai/ai_swarm.cc	(revision 10176)
+++ /branches/ai/src/ai/ai_swarm.cc	(revision 10177)
@@ -18,26 +18,44 @@
 #include <stdio.h>
 
+AISwarm::AISwarm()
+{
+	tickCount=0;
+	randomFreq=100;
+}
+
+
 void AISwarm::process(float dt)
 {
+	if(tickCount>=randomFreq && movement.len()<60){
+		tickCount=0;
+		int x = (rand()%141)+10;				//10-150
+		int z = (rand()%241)-120;			//-120-120
+		randomVector=Vector(x,0,z);
+
+		std::cout << "change to: ||" << randomVector.x << "   ==" << randomVector.z << "\n";
+	}
+	tickCount++;
+
+
 	std::set<AIModule*>::iterator it;
 	Vector swarmPosition=this->getPosition();
 	//std::cout << swarmPosition.x << " " << swarmPosition.z << "\n";
-	
+
 	float aMax=70.0f;
 	float vMax=1000.0f;
-	
-	Vector correction=(destination-swarmPosition)-movement;
+
+	Vector correction=(destination+randomVector-swarmPosition)-movement;
 	correction.y=0;
-	
+
 	float correctionLen=correction.len();
 	if(correctionLen>aMax*dt)correction=correction/correctionLen*aMax*dt;
-	
+
 	//std::cout << angleRad(correction,movement) << "\n";
 	movement+=correction;
-	
+
 	float movementLen=movement.len();
 	if(movementLen>vMax)movement=movement/movementLen*vMax;
-	
-	
+
+
 	for (it= swarmMembers.begin(); it!= swarmMembers.end(); it++ ){
 		(*it)->setDestination(swarmPosition);
@@ -48,8 +66,10 @@
 }
 
+
 void AISwarm::addAI(AIModule* aiModule)
 {
 	swarmMembers.insert(aiModule);
 }
+
 
 void AISwarm::removeAI(AIModule* aiModule)
@@ -59,4 +79,5 @@
 	delete (*it);
 }
+
 
 Vector AISwarm::getPosition()
Index: /branches/ai/src/ai/ai_swarm.h
===================================================================
--- /branches/ai/src/ai/ai_swarm.h	(revision 10176)
+++ /branches/ai/src/ai/ai_swarm.h	(revision 10177)
@@ -8,5 +8,5 @@
 class AISwarm{
 	public:
-		AISwarm(){}
+		AISwarm();
 		~AISwarm(){}
 		void process(float dt);
@@ -22,4 +22,7 @@
 		std::vector<WorldEntity*>* enemyList;
 		std::set<AIModule*> swarmMembers;
+		int tickCount;
+		int randomFreq;
+		Vector randomVector;
 };
 
Index: /branches/ai/src/ai/ai_team.cc
===================================================================
--- /branches/ai/src/ai/ai_team.cc	(revision 10176)
+++ /branches/ai/src/ai/ai_team.cc	(revision 10177)
@@ -19,15 +19,7 @@
 void AITeam::process(float dt)
 {
-	//int x;
-	//int z;
-	//Vector random;
-	
 	std::map<int,AISwarm*>::iterator it;
 	for (it= swarms.begin(); it!= swarms.end(); it++ ){
-	
-		//x = 20*(rand()%10 + 1)-100;
-		//z = 20*(rand()%10 + 1)-100;
-		//random=Vector(x,0,z);
-		
+
 		it->second->setEnemyList(enemyList);
 		if(enemyList->size()>0)
@@ -36,4 +28,5 @@
 	}
 }
+
 
 void AITeam::addAI(int swarmNumber, AIModule* aiModule)
@@ -45,4 +38,5 @@
 	p.first->second->addAI(aiModule);
 }
+
 
 void AITeam::removeAI(int swarmNumber, AIModule* aiModule)
Index: /branches/ai/src/ai/ai_team.h
===================================================================
--- /branches/ai/src/ai/ai_team.h	(revision 10176)
+++ /branches/ai/src/ai/ai_team.h	(revision 10177)
@@ -8,7 +8,7 @@
  public:
 	~AITeam(){}
- 	AITeam(){}
- 	std::vector<WorldEntity*>* getEnemyList();
-   void process(float dt);
+	AITeam(){}
+	std::vector<WorldEntity*>* getEnemyList();
+	void process(float dt);
 	void addAI(int swarmNumber, AIModule* aiModule);
 	void removeAI(int swarmNumber, AIModule* aiModule);
@@ -16,5 +16,5 @@
 	inline void setEnemyList(std::vector<WorldEntity*>* enemyList){this->enemyList=enemyList;}
  private:
- 	std::vector<WorldEntity*>* enemyList;
+	std::vector<WorldEntity*>* enemyList;
 	std::map<int,AISwarm*> swarms;
 };
Index: /branches/ai/src/ai/movement_module.cc
===================================================================
--- /branches/ai/src/ai/movement_module.cc	(revision 10176)
+++ /branches/ai/src/ai/movement_module.cc	(revision 10177)
@@ -28,38 +28,24 @@
 SHELL_COMMAND(setDistanceToNPC, MovementModule, setDistanceToNPC);
 SHELL_COMMAND(setMaxAccleartion, MovementModule, setMaxAccleartion);
+SHELL_COMMAND(setTestValue, MovementModule, setTestValue);
+SHELL_COMMAND(setTestValue2, MovementModule, setTestValue2);
 
 float MovementModule::distanceToPlayer=15;
 float MovementModule::distanceToNPC=2;
-float MovementModule::maxAccleration=200.0f;
+float MovementModule::maxAccleration=300.0f;
+float MovementModule::testValue=2;
+float MovementModule::testValue2=40;
 
 void MovementModule::setDistanceToPlayer(float newValue){ distanceToPlayer=newValue; }
 void MovementModule::setDistanceToNPC(float newValue){ distanceToNPC=newValue; }
 void MovementModule::setMaxAccleartion(float newValue){ maxAccleration=newValue; }
+void MovementModule::setTestValue(float newValue){ testValue=newValue; }
+void MovementModule::setTestValue2(float newValue){ testValue2=newValue; }
 
-
-
-
-
-
-// std::vector<Vector>	MovementModule::hidingPoint;
-// std::vector<float>	MovementModule::hidingPointSize;
-//
-// std::vector<NPC2*> MovementModule::npcList;
-// std::vector<Vector> MovementModule::npcPosition;
-// std::vector<float> MovementModule::npcRadius;
-// std::vector<int> MovementModule::npcSwarm;
-// std::vector<int> MovementModule::npcTeam;
-//
-// Vector MovementModule::playerPosition;
-// Vector MovementModule::playerMovement;
-// float MovementModule::playerRadius;
-//
-// std::vector<Vector> MovementModule::swarmCenter;
-// std::vector<int> MovementModule::swarmMemberCount;
-//
-//
-//
-//
-//
+MovementModule::MovementModule()
+{
+	tickCount=0;
+	randomFreq=100;
+}
 
 
@@ -82,78 +68,25 @@
 
 
-
-
-// void MovementModule::collectInformation(float dt)
-// {
-// 	//return if already processed..
-// 	if(dt==this->oldDT)return;
-// 	this->oldDT=dt;
-//
-//
-// 	//clear old Information..
-// 	hidingPoint.clear();
-// 	hidingPointSize.clear();
-//
-// 	npcList.clear();
-// 	npcPosition.clear();
-// 	npcRadius.clear();
-// 	npcSwarm.clear();
-// 	npcTeam.clear();
-//
-// 	swarmCenter.clear();
-// 	swarmMemberCount.clear();
-//
-//
-// 	//get all NPCs..
-// 	for(ObjectList<NPC2>::const_iterator it = NPC2::objectList().begin(); it != NPC2::objectList().end(); ++it)
-// 	{
-// 		npcList.push_back(*it);
-// 		npcRadius.push_back(getRadius(*it));
-// 		npcPosition.push_back((*it)->getAbsCoor());
-// 		npcSwarm.push_back((*it)->swarm);
-// 		npcTeam.push_back((*it)->team);
-// 	}
-//
-//
-// 	//Swarm Information
-// 	unsigned int tmpSwarm;
-// 	for(unsigned int i=0;i<npcList.size();i++){
-// 		tmpSwarm = npcSwarm.at(i);
-// 		if(tmpSwarm > swarmMemberCount.size()){
-// 			//swarmMemberCount.insert(swarmMemberCount.size(), tmpSwarm - swarmMemberCount.size(), 0);
-// 			//swarmCenter.insert(swarmCenter.size(), tmpSwarm - swarmCenter.size(), Vector(0,0,0));
-// 		}
-// 		//swarmMemberCount.at(tmpSwarm)++;
-// 		//swarmCenter.at(tmpSwarm)=swarmCenter.at(tmpSwarm)+npcPosition.at(i);
-// 	}
-// 	for(unsigned int i=0;i<swarmCenter.size();i++){
-// 		//swarmCenter.at(i)=swarmCenter.at(i)/swarmMemberCount.at(i);
-// 	}
-//
-//
-// 	//get information about Player
-// 	Player* pl = State::getPlayer();
-// 	if( pl != NULL){
-// 		playerPosition = pl->getPlayable()->getAbsCoor();
-// 		playerRadius=getRadius( pl->getPlayable() );
-// 		//PRINTF(0)("Player Radius: %f\n",playerRadius);
-// 	}
-//
-//
-// 	//calculate hiding Points..
-//
-// }
-
-
 void MovementModule::process(float dt)
 {
 	if(myNPC == NULL)return;
 
-	//get information about Player
+	Vector tmpVector;
+	float tmpFloat;
+	Vector npcCollision;
+	Vector playerCollision;
+	bool autoRotate=true;
+	target=enemyList->at(0);
+
+	weight=1;
+	speedMax=1000.0f;
+
+
+	//get information about player
 	Player* pl = State::getPlayer();
 	if( pl == NULL)return;
 	Vector playerPosition = pl->getPlayable()->getAbsCoor();
 	float playerRadius=getRadius( pl->getPlayable() );
-	
+
 
 	//get information about myself
@@ -162,21 +95,7 @@
 
 
+	//anti player collision
 	Vector vectorToPlayer = playerPosition - myPosition;
 
-	Vector tmpVector;
-	float tmpFloat;
-	
-	Vector npcCollision;
-	Vector playerCollision;
-
-
-
-	//float a=200.0f;
-	float vMax=200.0f;
-	//float maxAccleration=300.0f;
-	//float safetyDistance=2.0f;
-
-
-	//Anti Player Collision
 	tmpFloat=vectorToPlayer.len()-playerRadius-myRadius-distanceToPlayer;
 	if(tmpFloat<0.1)tmpFloat=0.1;
@@ -184,5 +103,5 @@
 
 
-	//Anti NPC Collision
+	//anti NPC collision
 	for(ObjectList<WorldEntity>::const_iterator it = WorldEntity::objectList().begin(); it != WorldEntity::objectList().end(); ++it)
 	{
@@ -199,5 +118,16 @@
 
 
+	//random movement
+	//randomFreq=testValue2;
+	if(++tickCount>=randomFreq && movement.len()<60){
+		tickCount=0;
+		int x = (rand()%101)-50;			//-50-50
+		int z = (rand()%101)-50;			//-50-50
+		randomVector=Vector(x,0,z);
+		randomFreq=(rand()%81)+70;			//70-150 Ticks
+	}
 
+
+	//calculate correction vector
 	Vector vectorToDestination=destination-myPosition;
 
@@ -205,29 +135,41 @@
 								+	npcCollision*50*3
 								+	Vector(0,0,0)
-								+	destinationMovement*2//-myMovement
-								+	(vectorToDestination-myMovement)*3;
+								+	destinationMovement*2//-movement
+								+	(vectorToDestination-movement)*3;
+
+	if(movement.len()<testValue2){
+	//if(testValue2){
+		correction=correction + randomVector * testValue;
+		autoRotate=false;
+	}
 
 	correction.y=0;
+
+
+	//limit accleration
 	float correctionLen=correction.len();
 	if(correctionLen>maxAccleration*dt)correction=correction/correctionLen*maxAccleration*dt;
-	myMovement+=correction;
+	movement+=correction;
 
-	float movementLen=myMovement.len();
-	if(movementLen>vMax)myMovement/movementLen*vMax;
 
-	//Move NPC...
-	myNPC->shiftCoor(myMovement * dt);
+	//limit speed
+	float movementLen=movement.len();
+	if(movementLen>speedMax)movement=movement/movementLen*speedMax;
 
-	//Rotate NPC
-	Vector view = myMovement;
-	//if(vectorToPlayer.dot(v)<0){
-	//	view = v.cross( Vector(0,1,0) ).getNormalized();
-	//}else{
-	view = myMovement.cross( Vector(0,1,0) ).getNormalized();
-	//}
-	//if(dist<keepDist)view=view*-1;
-	//myNPC->setAbsDir( Quaternion( view, Vector(0,1,0)));
+
+	//move NPC...
+	myNPC->shiftCoor(movement * dt);
+
+
+	//rotate NPC
+	Vector view;
+	if(autoRotate){
+		view = movement.cross( Vector(0,1,0) ).getNormalized();
+	}else{
+		view = target->getAbsCoor()-myPosition;
+		view = view.cross( Vector(0,1,0) ).getNormalized();
+	}
 	myNPC->setAbsDirSoft( Quaternion( view, Vector(0,1,0)),3);
-	movement=myMovement;
+
 }
 
Index: /branches/ai/src/ai/movement_module.h
===================================================================
--- /branches/ai/src/ai/movement_module.h	(revision 10176)
+++ /branches/ai/src/ai/movement_module.h	(revision 10177)
@@ -13,5 +13,5 @@
 
 	public:
-		MovementModule() {}
+		MovementModule();
 		inline MovementModule(NPC2* object){ this->myNPC=object; this->myWorldEntity=(WorldEntity*)object;}
 		virtual ~MovementModule(){}
@@ -21,18 +21,8 @@
 		static void setDistanceToNPC(float newValue);
 		static void setMaxAccleartion(float newValue);
-//
+		static void setTestValue(float newValue);
+		static void setTestValue2(float newValue);
+
 	private:
-
-// 	static std::vector<NPC2*> npcList;
-// 	static std::vector<Vector> npcPosition;
-// 	static std::vector<float> npcRadius;
-// 	static std::vector<int> npcSwarm;
-// 	static std::vector<int> npcTeam;
-//
-// 	static Vector playerPosition;
-// 	static Vector playerMovement;
-// 	static float playerRadius;
-
-
 		Vector myMovement;
 		float myMaxAccleration;
@@ -44,4 +34,10 @@
 		static float distanceToPlayer;
 		static float distanceToNPC;
+		static float testValue;
+		static float testValue2;
+
+		int tickCount;
+		int randomFreq;
+		Vector randomVector;
 };
 
