Index: /code/branches/campaignHS15/data/levels/AITest.oxw
===================================================================
--- /code/branches/campaignHS15/data/levels/AITest.oxw	(revision 10837)
+++ /code/branches/campaignHS15/data/levels/AITest.oxw	(revision 10838)
@@ -32,6 +32,6 @@
 
     <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0"/>
-    <SpawnPoint team=0 position="-1000,-1000,-1000" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff />
-    >
+    <TeamSpawnPoint team=1 position="-1000,-1000,-1000" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff />
+    
 <!-- 
     <?lua
@@ -52,42 +52,51 @@
  
     
-    <SpaceShip position="4000, 1500, -1000" lookat="0,0,0">
+    <SpaceShip position="4000, 1500, -1000" lookat="0,0,0" team=0>
       <templates>
         <Template link=spaceshipassff />
       </templates>
       <controller>
-        <DivisionController team=1 formationMode="wall" action="FIGHT">
+        <DivisionController formationMode="wall" action="PROTECT" protect="FUCK" team=0>
         </DivisionController>
       </controller>
     </SpaceShip>
-    <SpaceShip position="4000 ,1500, -1600 " lookat="0,0,0">
+    <SpaceShip position="4000 ,1500, -1600 " lookat="0,0,0" team=0>
       <templates>
         <Template link=spaceshipassff />
       </templates>
       <controller>
-        <WingmanController team=1>
+        <WingmanController >
         </WingmanController>
       </controller>
     </SpaceShip>
-    <SpaceShip position="4000, 1500, -2200" lookat="0,0,0">
+    <SpaceShip position="4000, 1500, -2200" lookat="0,0,0" team=0>
       <templates>
         <Template link=spaceshipassff />
       </templates>
       <controller>
-        <WingmanController team=1>
+        <WingmanController >
         </WingmanController>
       </controller>
     </SpaceShip>
-    <SpaceShip position="4000, 1500, -2800 " lookat="0,0,0">
+    <SpaceShip position="4000, 1500, -2800 " lookat="0,0,0" team=0>
       <templates>
         <Template link=spaceshipassff />
       </templates>
       <controller>
-        <SectionController team=1>
+        <SectionController >
+        </SectionController>
+      </controller>
+    </SpaceShip>
+    <SpaceShip position="-4000, 1500, -2800 " lookat="0,0,0" team=0 name="FUCK">
+      <templates>
+        <Template link=spaceshipassff />
+      </templates>
+      <controller>
+        <SectionController>
         </SectionController>
       </controller>
     </SpaceShip>
     
-    <SpaceShip position="-4000, 1500, -5000" lookat="0,0,0">
+    <!-- <SpaceShip position="-4000, 1500, -5000" lookat="0,0,0">
       <templates>
         <Template link=spaceshipassff />
@@ -124,5 +133,5 @@
         </SectionController>
       </controller>
-    </SpaceShip>
+    </SpaceShip> -->
 
     
Index: /code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc
===================================================================
--- /code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc	(revision 10837)
+++ /code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc	(revision 10838)
@@ -38,8 +38,15 @@
 
 #include "Scene.h"
-#include <OgreRay.h>
-#include <OgreSceneQuery.h>
-#include <OgreCamera.h>
-#include <OgreSceneManager.h>
+
+#include "worldentities/pawns/TeamBaseMatchBase.h"
+#include "gametypes/TeamDeathmatch.h"
+#include "gametypes/Dynamicmatch.h"
+#include "gametypes/Mission.h"
+#include "gametypes/Gametype.h"
+#include "controllers/WaypointPatrolController.h"
+#include "controllers/NewHumanController.h"
+#include "controllers/DroneController.h"
+
+
 namespace orxonox
 {
@@ -51,6 +58,4 @@
     CommonController::CommonController( Context* context ): Controller( context )
     {
-
-       
         this->action_ = Action::FLY;
         this->stopLookingAtTarget();
@@ -70,5 +75,31 @@
         XMLPortParam( CommonController, "formationMode", setFormationModeXML, getFormationModeXML,  xmlelement, mode );
         XMLPortParam( CommonController, "action", setActionXML, getActionXML,  xmlelement, mode );
-
+        XMLPortParam ( CommonController, "protect", setProtectXML, getProtectXML,  xmlelement, mode );
+        //XMLPortParam ( CommonController, "enemy", setEnemyXML, getEnemyXML,  xmlelement, mode );
+    }
+    void CommonController::setProtectXML( std::string val )
+    {
+        for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
+        {
+            if ((*itP)->getName() == val)
+            {
+                this->setProtect (static_cast<ControllableEntity*>(*itP));
+            }
+        }
+    }
+    std::string CommonController::getProtectXML ()
+    {
+        if (!this->getProtect())
+            return "noProtectWasSet";
+        return this->getProtect()->getName();
+    }
+
+    void CommonController::setProtect (ControllableEntity* protect)
+    {
+        this->protect_ = protect;
+    }
+    ControllableEntity* CommonController::getProtect ()
+    {
+        return this->protect_;
     }
     void CommonController::setActionXML( std::string val)
@@ -205,8 +236,8 @@
         Pawn* closestTarget = 0;
         float minDistance =  std::numeric_limits<float>::infinity();
-        
+        Gametype* gt = this->getGametype();
         for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
         {
-            if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP)) )
+            if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP), gt) )
                 continue;
 
@@ -669,9 +700,113 @@
         return ( entity1->getPosition() - entity2->getPosition() ).length();
     }
-    bool CommonController::sameTeam (ControllableEntity* entity1, ControllableEntity* entity2)
-    {
-        if (!entity1 || !entity2)
+    bool CommonController::sameTeam (ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype)
+    {
+        /*if (!entity1 || !entity2)
             return false;
-        return entity1->getTeam() == entity2->getTeam();
+        return entity1->getTeam() == entity2->getTeam();*/
+        if (entity1 == entity2)
+            return true;
+
+        int team1 = entity1->getTeam();
+        int team2 = entity2->getTeam();
+
+        Controller* controller = 0;
+        if (entity1->getController())
+            controller = entity1->getController();
+        else
+            controller = entity1->getXMLController();
+        if (controller)
+        {
+            CommonController* ac = orxonox_cast<CommonController*>(controller);
+            if (ac)
+                team1 = ac->getTeam();
+        }
+
+        if (entity2->getController())
+            controller = entity2->getController();
+        else
+            controller = entity2->getXMLController();
+        if (controller)
+        {
+            CommonController* ac = orxonox_cast<CommonController*>(controller);
+            if (ac)
+                team2 = ac->getTeam();
+        }
+
+        TeamGametype* tdm = orxonox_cast<TeamGametype*>(gametype);
+        if (tdm)
+        {
+            if (entity1->getPlayer())
+                team1 = tdm->getTeam(entity1->getPlayer());
+
+            if (entity2->getPlayer())
+                team2 = tdm->getTeam(entity2->getPlayer());
+        }
+
+        TeamBaseMatchBase* base = 0;
+        base = orxonox_cast<TeamBaseMatchBase*>(entity1);
+        if (base)
+        {
+            switch (base->getState())
+            {
+                case BaseState::ControlTeam1:
+                    team1 = 0;
+                    break;
+                case BaseState::ControlTeam2:
+                    team1 = 1;
+                    break;
+                case BaseState::Uncontrolled:
+                default:
+                    team1 = -1;
+            }
+        }
+        base = orxonox_cast<TeamBaseMatchBase*>(entity2);
+        if (base)
+        {
+            switch (base->getState())
+            {
+                case BaseState::ControlTeam1:
+                    team2 = 0;
+                    break;
+                case BaseState::ControlTeam2:
+                    team2 = 1;
+                    break;
+                case BaseState::Uncontrolled:
+                default:
+                    team2 = -1;
+            }
+        }
+
+        DroneController* droneController = 0;
+        droneController = orxonox_cast<DroneController*>(entity1->getController());
+        if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity2)
+            return true;
+        droneController = orxonox_cast<DroneController*>(entity2->getController());
+        if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity1)
+            return true;
+        DroneController* droneController1 = orxonox_cast<DroneController*>(entity1->getController());
+        DroneController* droneController2 = orxonox_cast<DroneController*>(entity2->getController());
+        if (droneController1 && droneController2 && droneController1->getOwner() == droneController2->getOwner())
+            return true;
+
+        Dynamicmatch* dynamic = orxonox_cast<Dynamicmatch*>(gametype);
+        if (dynamic)
+        {
+            if (dynamic->notEnoughPigs||dynamic->notEnoughKillers||dynamic->notEnoughChasers) {return false;}
+
+            if (entity1->getPlayer())
+                team1 = dynamic->getParty(entity1->getPlayer());
+
+            if (entity2->getPlayer())
+                team2 = dynamic->getParty(entity2->getPlayer());
+
+            if (team1 ==-1 ||team2 ==-1 ) {return false;}
+            else if (team1 == dynamic->chaser && team2 != dynamic->chaser) {return false;}
+            else if (team1 == dynamic->piggy && team2 == dynamic->chaser) {return false;}
+            else if (team1 == dynamic->killer && team2 == dynamic->chaser) {return false;}
+            else return true;
+        }
+
+        return (team1 == team2 && team1 != -1);
     }
     void CommonController::doFire() 
Index: /code/branches/campaignHS15/src/orxonox/controllers/CommonController.h
===================================================================
--- /code/branches/campaignHS15/src/orxonox/controllers/CommonController.h	(revision 10837)
+++ /code/branches/campaignHS15/src/orxonox/controllers/CommonController.h	(revision 10838)
@@ -103,4 +103,10 @@
                         { return this->rank_; }
                 //----[/Rank data]----
+                //----[Protect data]----
+                    void setProtectXML( std::string val );
+                    std::string getProtectXML ();
+                    void setProtect (ControllableEntity* protect);
+                    ControllableEntity* getProtect ();
+                //----[/Protect data]----
             //----[/XML data]----
 
@@ -124,5 +130,5 @@
                 float randomInRange(float a, float b);
                 static float distance(ControllableEntity* entity1, ControllableEntity* entity2);
-                static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2);
+                static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gt);
                 static bool isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle ) ;
 
@@ -168,11 +174,14 @@
                 bool bHasTargetOrientation_;
                 Quaternion targetOrientation_;
-                // Vector3 destination_;
-                // bool bHasDestination;
+                
+                Vector3 destination_;
+                bool bHasDestination;
             //----[/where-to-fly information]----
-            
+            //----[protect information]----
+                WeakPtr<ControllableEntity> protect_;
+            //----[/protect information]----
             //----[who-to-kill information]----
                 WeakPtr<ControllableEntity> target_;
-                //WeakPtr<ControllableEntity> objectiveTarget_;
+                WeakPtr<ControllableEntity> enemy_;
 
                 bool bHasPositionOfTarget_;
Index: /code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
===================================================================
--- /code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc	(revision 10837)
+++ /code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc	(revision 10838)
@@ -133,5 +133,8 @@
         else if (this->action_ == Action::PROTECT)
         {
-
+            if (this->getProtect())
+            {
+                orxout(internal_error) << "PROTECT FOUND" << endl;
+            }
         }
 
Index: /code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc
===================================================================
--- /code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc	(revision 10837)
+++ /code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc	(revision 10838)
@@ -168,9 +168,9 @@
                     //----new target should be close to division's target----
                     Vector3 divisionTargetPosition = this->myDivisionLeader_->getTarget()->getWorldPosition();
-                    
+                    Gametype* gt = this->getGametype();
                     for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
                     {
                         //----is enemy?----
-                        if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP)) )
+                        if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP), gt) )
                             continue;           
                         //----in range?----
Index: /code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc
===================================================================
--- /code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc	(revision 10837)
+++ /code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc	(revision 10838)
@@ -135,5 +135,5 @@
         CommonController* closestLeader = 0;
         float minDistance =  std::numeric_limits<float>::infinity();
-
+        Gametype* gt = this->getGametype();
         for (ObjectList<CommonController>::iterator it = ObjectList<CommonController>::begin(); it; ++it)
         {
@@ -145,5 +145,5 @@
             
             //----same team?----
-            if ( !CommonController::sameTeam (this->getControllableEntity(), (it)->getControllableEntity()) )
+            if ( !CommonController::sameTeam (this->getControllableEntity(), (it)->getControllableEntity(), gt) )
                 continue;
             
Index: /code/branches/campaignHS15/src/orxonox/worldentities/SpawnPoint.h
===================================================================
--- /code/branches/campaignHS15/src/orxonox/worldentities/SpawnPoint.h	(revision 10837)
+++ /code/branches/campaignHS15/src/orxonox/worldentities/SpawnPoint.h	(revision 10838)
@@ -55,5 +55,5 @@
                 { return this->template_; }
 
-            Pawn* spawn();
+            virtual Pawn* spawn();
             void spawn(ControllableEntity* entity);
 
Index: /code/branches/campaignHS15/src/orxonox/worldentities/TeamSpawnPoint.cc
===================================================================
--- /code/branches/campaignHS15/src/orxonox/worldentities/TeamSpawnPoint.cc	(revision 10837)
+++ /code/branches/campaignHS15/src/orxonox/worldentities/TeamSpawnPoint.cc	(revision 10838)
@@ -49,3 +49,9 @@
         XMLPortParam(TeamSpawnPoint, "team", setTeamNumber, getTeamNumber, xmlelement, mode).defaultValues(0);
     }
+    Pawn* TeamSpawnPoint::spawn()
+    {
+        Pawn* entity = SpawnPoint::spawn();
+        static_cast<ControllableEntity*>(entity)->setTeam (this->teamNumber_);
+        return entity;
+    }
 }
Index: /code/branches/campaignHS15/src/orxonox/worldentities/TeamSpawnPoint.h
===================================================================
--- /code/branches/campaignHS15/src/orxonox/worldentities/TeamSpawnPoint.h	(revision 10837)
+++ /code/branches/campaignHS15/src/orxonox/worldentities/TeamSpawnPoint.h	(revision 10838)
@@ -49,7 +49,8 @@
             unsigned int getTeamNumber() const
                 { return this->teamNumber_; }
+            virtual Pawn* spawn();
 
         private:
-            unsigned int teamNumber_;
+            int teamNumber_;
     };
 }
