Index: /branches/ai/src/ai/ai_team.cc
===================================================================
--- /branches/ai/src/ai/ai_team.cc	(revision 10248)
+++ /branches/ai/src/ai/ai_team.cc	(revision 10249)
@@ -17,5 +17,9 @@
 #include "swarm_gorel.h"
 #include "swarm_module.h"
+#include "swarm_wait.h"
 #include "debug.h"
+#include "player.h"
+#include "playable.h"
+#include "state.h"
 
 void AITeam::process(float dt)
@@ -25,14 +29,52 @@
 	
 		if(it->second->taskDone()){
-			std::cout << "Task Done!\n";
+			std::cout << "Swarm Task Complete!\n";
+					
+			if(enemyList->size()==0){
+				changeSwarmModule(it, new SwarmWait);
+				it->second->orderMaxTime(2);	//sleep 2 seconds..
+				it->second->process(dt);
+				continue;
+			}
+			
+			Vector position=it->second->getPosition();
+			Vector newPosition;
+			WorldEntity* target=enemyList->at(0);
+			
+			//check if enemy is the player..
+			bool isPlayer=(State::getPlayer()->getPlayable()==target);
+			float speed;
+			
+			//find new Position
+			if(isPlayer){
+				float x=(target->getAbsCoor()).x;
+				float z=(target->getAbsCoor()).z;
+				int zNorm=(position.z>z)?1:-1;
+				
+				if(x+100 > position.x && x+20 < position.x){
+					newPosition=Vector(0,0,zNorm*80);		//just go away
+					speed=80;
+				}else if(x+100 < position.x){
+					newPosition=Vector(80,0,zNorm*30);	//attack
+					speed=70;
+				}else{
+					zNorm=1-2*(rand()%2); //-1 or 1
+					newPosition=Vector(200,0,zNorm*80);	//go to attack position
+					speed=100;
+				}
+			}else{
+			
+			}
+
 			changeSwarmModule(it, new SwarmGoRel);
 		
 			if(enemyList->size()>0){
 				it->second->setEnemyList(enemyList);
-				it->second->orderRelObject(enemyList->at(0));
-				it->second->orderRelPos(Vector(60,0,0));
-				it->second->orderSpeed(50);
-				it->second->orderView(Vector(0,0,1));
-				it->second->orderMaxTime(5);
+				it->second->orderRelObject(target);
+				it->second->orderRelPos(newPosition);
+				it->second->orderSpeed(speed);
+				//it->second->orderView(Vector(0,0,1));
+				it->second->orderMaxTime((rand()%6)+5); //5-10
+				//it->second->newOrder();
 			}
 		}
Index: /branches/ai/src/ai/swarm_gorel.cc
===================================================================
--- /branches/ai/src/ai/swarm_gorel.cc	(revision 10248)
+++ /branches/ai/src/ai/swarm_gorel.cc	(revision 10249)
@@ -28,6 +28,7 @@
 	}
 	averageRadius=averageRadius/members.size();
-	aMax=1000/averageRadius;
-	vMax=1000/averageRadius;
+	aMax=500/averageRadius;
+	vMax=500/averageRadius;
+	viewChangeMax=90/averageRadius;
 	
 	//load correct ai-module..
@@ -36,4 +37,6 @@
 	}
 	
+	//get swarm position..
+	//position=this->getPosition();
 }
 
@@ -42,5 +45,5 @@
 	std::map<WorldEntity*,AIModule*>::iterator it;
 
-	Vector swarmPosition=this->getPosition();
+	//Vector swarmPosition=this->getPosition();
 	Vector correction=Vector(0,0,0);
 	Vector destination;
@@ -48,5 +51,5 @@
 	if(taskRelObject!=NULL && taskMaxTime>0){
 		destination=taskRelObject->getAbsCoor()+taskRelPos;
-		correction=(destination-swarmPosition)-view*speed;
+		correction=(destination-position)-view*speed;
 		correction.y=0;
 		taskMaxTime-=dt;
@@ -64,11 +67,24 @@
 	if(movementLen>vMax)movement=movement/movementLen*vMax;
 	
-	speed=movement.len();
-	view=movement.getNormalized();
+	float newSpeed=movement.len();
+	Vector newView=movement.getNormalized();
+	
+	if((newSpeed<=taskSpeed && speed>=taskSpeed)||(newSpeed>=taskSpeed && speed<=taskSpeed)){
+		newSpeed=taskSpeed;
+	}else if((newSpeed>speed && speed<taskSpeed) || (newSpeed < speed && speed < taskSpeed)){
+		newSpeed=taskSpeed;
+	}
+	
+	if(angleDeg(view,newView)>viewChangeMax){
+		std::cout << "alarm\n";
+	}
+	speed=newSpeed;
+	view=newView;
+	position=position+view*speed*dt;
 
 	//tell orders to swarm-members...
 	for (it= members.begin(); it!= members.end(); it++ ){
-		it->second->setDestination(swarmPosition);
-		it->second->setDestinationMovement(movement);
+		it->second->setDestination(position);
+		it->second->setDestinationMovement(view*speed);
 		it->second->process(dt);
 	}
@@ -76,6 +92,6 @@
 	//check if destination reached
 	if(!taskComplete){
-		swarmPosition=this->getPosition();
-		if((destination-swarmPosition).len()<10)taskComplete=true;
+		//swarmPosition=this->getPosition();
+		if((destination-position).len()<10)taskComplete=true;
 	}
 }
Index: /branches/ai/src/ai/swarm_gorel.h
===================================================================
--- /branches/ai/src/ai/swarm_gorel.h	(revision 10248)
+++ /branches/ai/src/ai/swarm_gorel.h	(revision 10249)
@@ -17,4 +17,5 @@
 		float vMax;
 		float aMax;
+		float viewChangeMax;
 };
 
Index: /branches/ai/src/ai/swarm_module.cc
===================================================================
--- /branches/ai/src/ai/swarm_module.cc	(revision 10248)
+++ /branches/ai/src/ai/swarm_module.cc	(revision 10249)
@@ -44,5 +44,5 @@
 }
 
-Vector SwarmModule::getPosition()
+Vector SwarmModule::getSwarmPosition()
 {
 	Vector center=Vector(0,0,0);
@@ -76,4 +76,5 @@
 	this->view=other->getView();
 	this->enemys=other->getEnemyList();
+	this->position=other->getPosition();
 	
 	this->initialize();
Index: /branches/ai/src/ai/swarm_module.h
===================================================================
--- /branches/ai/src/ai/swarm_module.h	(revision 10248)
+++ /branches/ai/src/ai/swarm_module.h	(revision 10249)
@@ -19,4 +19,5 @@
 	inline void setEnemyList(std::vector<WorldEntity*>* enemys){this->enemys=enemys;}	
 	
+	inline void newOrder(){this->taskComplete=false;}
 	inline void orderRelPos(Vector taskRelPos){this->taskRelPos=taskRelPos;}
 	inline void orderAbsPos(Vector taskAbsPos){this->taskAbsPos=taskAbsPos;}
@@ -26,5 +27,6 @@
 	inline void orderMaxTime(float taskMaxTime){this->taskMaxTime=taskMaxTime;}
 
-	Vector getPosition();
+	Vector getSwarmPosition();
+	inline Vector getPosition(){return position;}
 	inline float getSpeed(){return speed;}
 	inline Vector getView(){return view;}
@@ -45,4 +47,5 @@
 	
 	Vector view;
+	Vector position;
 	float speed;
 	
Index: /branches/ai/src/ai/swarm_wait.h
===================================================================
--- /branches/ai/src/ai/swarm_wait.h	(revision 10248)
+++ /branches/ai/src/ai/swarm_wait.h	(revision 10249)
@@ -8,5 +8,5 @@
 class SwarmWait : public SwarmModule{
 	public:
-		SwarmWait();
+		SwarmWait(){}
 		virtual ~SwarmWait(){}
 		virtual void process(float dt);
