Index: branches/ai/src/ai/movement_module.cc
===================================================================
--- branches/ai/src/ai/movement_module.cc	(revision 10158)
+++ 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;
+
 }
 
