Index: branches/ai/src/ai/ai_engine.cc
===================================================================
--- branches/ai/src/ai/ai_engine.cc	(revision 10135)
+++ branches/ai/src/ai/ai_engine.cc	(revision 10137)
@@ -1,4 +1,2 @@
-
-
 /*
    orxonox - the future of 3D-vertical-scrollers
@@ -12,9 +10,8 @@
 
    ### File Specific:
-   main-programmer: Patrick Boenzli
+   main-programmer: Thomas Fahrni
    co-programmer:
 */
 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_AI
-
 #include "ai_engine.h"
 #include "debug.h"
@@ -22,47 +19,29 @@
 AIEngine* AIEngine::singletonRef = NULL;
 
-AIEngine::AIEngine(){
-	for(int i=0; i < maxTeams; i++ )teams[i]=NULL;
+void AIEngine::tick(float dt)
+{
+	std::map<int,AITeam*>::iterator it;
+	for (it= teams.begin(); it!= teams.end(); it++ )
+		it->second->process(dt);
 }
 
-AITeam* AIEngine::getTeam(int teamNumber)
+void AIEngine::addAI(int teamNumber, int swarmNumber, AIModule* aiModule)
 {
-	if(teamNumber>maxTeams || teamNumber<0)return NULL;
-	return teams[teamNumber];
+	std::pair<std::map<int,AITeam*>::iterator,bool> p;
+	AITeam* newTeam=new AITeam();
+	p=teams.insert(std::make_pair(teamNumber,newTeam));
+	if(!p.second)delete newTeam;
+	p.first->second->addAI(swarmNumber, aiModule);
 }
 
-AITeam* AIEngine::getCreateTeam(int teamNumber)
+void AIEngine::removeAI(int teamNumber, int swarmNumber, AIModule* aiModule)
 {
-	if(teamNumber>maxTeams || teamNumber<0)return NULL;
-	if(teams[teamNumber]==NULL)teams[teamNumber]=new AITeam();
-	return teams[teamNumber];
+	std::map<int,AITeam*>::iterator it = teams.find(swarmNumber);
+	if(it==teams.end())return;
+	it->second->removeAI(swarmNumber,aiModule);
+	if(it->second->getTeamSize()==0){
+		delete it->second;
+		teams.erase(it);
+	}
 }
 
-
-void AIEngine::addTeam(int teamNumber)
-{
-	if(teamNumber>maxTeams || teamNumber<0)return;
-	teams[teamNumber]=new AITeam();
-}
-
-
-void AIEngine::removeTeam(int teamNumber)
-{
-	if(teamNumber>maxTeams || teamNumber<0)return;
-	teams[teamNumber]=NULL;
-}
-
-
-void AIEngine::tick(float dt)
-{
-	for(int i=0; i < maxTeams; i++ )
-		if(teams[i]!=NULL)teams[i]->process(dt);
-}
-
-
-void AIEngine::rebuildAIVector(){
-	//AIVector.clear();
-
-	//for(int i=0; i < maxTeams; i++ )
-		//if(teams[i]!=NULL)AIVector.push_back(teams[i]);
-}
Index: branches/ai/src/ai/ai_engine.h
===================================================================
--- branches/ai/src/ai/ai_engine.h	(revision 10135)
+++ branches/ai/src/ai/ai_engine.h	(revision 10137)
@@ -14,20 +14,11 @@
 
    void tick(float dt);
-
-	void addTeam(int teamNumber);
-	void removeTeam(int teamNumber);
-	AITeam* getTeam(int teamNumber);
-	AITeam* getCreateTeam(int teamNumber);
-
+	void addAI(int teamNumber, int swarmNumber, AIModule* aiModule);
+	void removeAI(int teamNumber, int swarmNumber, AIModule* aiModule);
+	
  private:
-	void rebuildAIVector();
-
-	std::vector<AIModule*> AIVector;
-
-	static const int maxTeams=32;
-	AITeam* teams[32];
-	AIEngine();
-
+	AIEngine(){}
 	static AIEngine* singletonRef;
+	std::map<int,AITeam*> teams;
 };
 
Index: branches/ai/src/ai/ai_swarm.cc
===================================================================
--- branches/ai/src/ai/ai_swarm.cc	(revision 10135)
+++ branches/ai/src/ai/ai_swarm.cc	(revision 10137)
@@ -1,4 +1,2 @@
-
-
 /*
    orxonox - the future of 3D-vertical-scrollers
@@ -16,41 +14,28 @@
 */
 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_AI
-
 #include "ai_swarm.h"
-
+#include "debug.h"
 
 void AISwarm::process(float dt)
 {
-	Vector swarmCenter;
-
-	for(unsigned int i=0;i<swarmMembers.size();i++){
-		//swarmCenter=swarmCenter+swarmMembers.at(i)->getPosition();
-	}
-	swarmCenter=swarmCenter/swarmMembers.size();
-
-	for(unsigned int i=0;i<swarmMembers.size();i++)
-		swarmMembers.at(i)->process(dt);
+	std::set<AIModule*>::iterator it;
+	for (it= swarmMembers.begin(); it!= swarmMembers.end(); it++ )
+		(*it)->process(dt);
 }
 
-
-void AISwarm::addToSwarm(AIModule* newMember)
+void AISwarm::addAI(AIModule* aiModule)
 {
-	swarmMembers.push_back(newMember);
+	swarmMembers.insert(aiModule);
 }
 
-
-void AISwarm::removeFromSwarm(AIModule* member)
+void AISwarm::removeAI(AIModule* aiModule)
 {
-	std::vector<AIModule*>::iterator it = this->swarmMembers.begin();
-	for(; it < this->swarmMembers.end(); it++) {
-
-// 	for(unsigned int i=0;i<swarmMembers.size();i++){
-		if(*it==member){
-			swarmMembers.erase(it);
-			return;
-		}
-	}
+	std::set<AIModule*>::iterator it=swarmMembers.find(aiModule);
+	if(it==swarmMembers.end())return;
+	delete (*it);
 }
 
-
-
+int AISwarm::getSwarmSize()
+{
+	return swarmMembers.size();
+}
Index: branches/ai/src/ai/ai_swarm.h
===================================================================
--- branches/ai/src/ai/ai_swarm.h	(revision 10135)
+++ branches/ai/src/ai/ai_swarm.h	(revision 10137)
@@ -9,11 +9,12 @@
 class AISwarm{
 	public:
-		AISwarm(){};
-		~AISwarm(){};
+		AISwarm(){}
+		~AISwarm(){}
 		void process(float dt);
-		void addToSwarm(AIModule* newMember);
-		void removeFromSwarm(AIModule* member);
+		void addAI(AIModule* newMember);
+		void removeAI(AIModule* oldMember);
+		int getSwarmSize();
 	private:
-		std::vector<AIModule*> swarmMembers;
+		std::set<AIModule*> swarmMembers;
 };
 
Index: branches/ai/src/ai/ai_team.cc
===================================================================
--- branches/ai/src/ai/ai_team.cc	(revision 10135)
+++ branches/ai/src/ai/ai_team.cc	(revision 10137)
@@ -1,4 +1,2 @@
-
-
 /*
    orxonox - the future of 3D-vertical-scrollers
@@ -16,47 +14,36 @@
 */
 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_AI
-
 #include "ai_team.h"
-
-AITeam::AITeam(){
-	for(int i=0; i < maxSwarms; i++ )swarms[i]=NULL;
-}
-
-
-AISwarm* AITeam::getSwarm(int swarmNumber)
-{
-	if(swarmNumber>maxSwarms || swarmNumber<0)return NULL;
-	return swarms[swarmNumber];
-}
-
-
-AISwarm* AITeam::getCreateSwarm(int swarmNumber)
-{
-	if(swarmNumber>maxSwarms || swarmNumber<0)return NULL;
-	if(swarms[swarmNumber]==NULL)swarms[swarmNumber]=new AISwarm();
-	return swarms[swarmNumber];
-}
-
-
-void AITeam::addSwarm(int swarmNumber)
-{
-	if(swarmNumber>maxSwarms || swarmNumber<0)return;
-	swarms[swarmNumber]=new AISwarm();
-}
-
-
-void AITeam::removeSwarm(int swarmNumber)
-{
-	if(swarmNumber>maxSwarms || swarmNumber<0)return;
-	swarms[swarmNumber]=NULL;
-}
-
+#include "debug.h"
 
 void AITeam::process(float dt)
 {
-	for(int i=0; i < maxSwarms; i++ ){
-		if(swarms[i]!=NULL)swarms[i]->process(dt);
+	std::map<int,AISwarm*>::iterator it;
+	for (it= swarms.begin(); it!= swarms.end(); it++ )
+		it->second->process(dt);
+}
+
+void AITeam::addAI(int swarmNumber, AIModule* aiModule)
+{
+	std::pair<std::map<int,AISwarm*>::iterator,bool> p;
+	AISwarm* newSwarm=new AISwarm();
+	p=swarms.insert(std::make_pair(swarmNumber,newSwarm));
+	if(!p.second)delete newSwarm;
+	p.first->second->addAI(aiModule);
+}
+
+void AITeam::removeAI(int swarmNumber, AIModule* aiModule)
+{
+	std::map<int,AISwarm*>::iterator it = swarms.find(swarmNumber);
+	if(it==swarms.end())return;
+	it->second->removeAI(aiModule);
+	if(it->second->getSwarmSize()==0){
+		delete it->second;
+		swarms.erase(it);
 	}
 }
 
-
+int AITeam::getTeamSize()
+{
+	return swarms.size();
+}
Index: branches/ai/src/ai/ai_team.h
===================================================================
--- branches/ai/src/ai/ai_team.h	(revision 10135)
+++ branches/ai/src/ai/ai_team.h	(revision 10137)
@@ -7,16 +7,13 @@
 class AITeam{
  public:
-	~AITeam(){};
-	AITeam();
+	~AITeam(){}
+ 	AITeam(){}
    void process(float dt);
-
-	void addSwarm(int swarmNumber);
-	void removeSwarm(int swarmNumber);
-	AISwarm* getSwarm(int swarmNumber);
-	AISwarm* getCreateSwarm(int swarmNumber);
-
+	void addAI(int swarmNumber, AIModule* aiModule);
+	void removeAI(int swarmNumber, AIModule* aiModule);
+	int getTeamSize();
+	
  private:
-	AISwarm* swarms[32];
-	static const int maxSwarms=32;
+	std::map<int,AISwarm*> swarms;
 };
 
